byteman  1.3 (Build #225)
Bitstream relocation and manipulation tool
XilinxUltraScalePlus.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2022 Kristiyan Manev (University of Manchester)
3  *
4  * Licensed under the Apache License, Version 2.0(the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #include<iostream>
18 #include<stdio.h>
19 #include<string>
20 #include<cstring> //memset
21 #include<algorithm> //replace
22 #include<sstream>
23 #include<stdexcept>
24 #include<fstream>
25 
26 #include "XilinxUltraScalePlus.h"
27 #include "../../../Common/str.h"
28 
29 using namespace std;
30 
32 {
33  initFabric();
34 }
35 
37 {
38 }
39 
41  if(initializedResourceStringShortPartName == "")
42  throw runtime_error("The target device needs to be known, before you can manipulate any bitstream!");
43  if(initializedBitstreamParamsShortPartName != initializedResourceStringShortPartName){//The device is changed
44  initializedBitstreamParamsShortPartName = initializedResourceStringShortPartName;
45 
46  for((numberOfCols[0] = 0, numberOfFramesBeforeCol[0][0] = 0, numberOfBRAMCols[0] = 0) ; resourceString[0][numberOfCols[0]] != '\0' ; numberOfCols[0]++){
47  numberOfFramesBeforeCol[0][numberOfCols[0] + 1] = numberOfFramesBeforeCol[0][numberOfCols[0]] + LUT_numberOfFramesForResourceLetter[(uint8_t)resourceString[0][numberOfCols[0]]];
48  numberOfBRAMsBeforeCol[0][numberOfCols[0]] = numberOfBRAMCols[0];
49  if(str::iff::charIs(resourceString[0][numberOfCols[0]], 'A','B','C','1')) //A-C are BlockRAM columns, '1' is empty blockram column
50  numberOfBRAMCols[0]++;
51  }
52  for(int c = numberOfCols[0] + 1 ; c < XUSP_MAX_COLS ; c++){
53  numberOfFramesBeforeCol[0][c] = numberOfFramesBeforeCol[0][c - 1];
54  }
55  for(int c = numberOfCols[0] ; c < XUSP_MAX_COLS ; c++){
56  numberOfBRAMsBeforeCol[0][c] = numberOfBRAMsBeforeCol[0][c - 1];
57  }
58  numberOfFramesPerRow[0] = numberOfFramesBeforeCol[0][numberOfCols[0] + 1];
59  numberOfWordsPerRow[0] = numberOfFramesPerRow[0] * XUSP_WORDS_PER_FRAME;
60 
61  maxNumberOfCols = numberOfCols[0];
62  maxNumberOfBRAMCols = numberOfBRAMCols[0];
63  for(int r = 1 ; r < numberOfRows ; r++){
64  numberOfBRAMCols[r] = numberOfBRAMCols[0];
65  numberOfCols[r] = numberOfCols[0];
66  numberOfFramesPerRow[r] = numberOfFramesPerRow[0];
67  numberOfWordsPerRow[r] = numberOfWordsPerRow[0];
68  for(int c = 0 ; c < XUSP_MAX_COLS ; c++){
69  numberOfFramesBeforeCol[r][c] = numberOfFramesBeforeCol[0][c];
70  }
71  for(int c = 0 ; c < XUSP_MAX_COLS ; c++){
72  numberOfBRAMsBeforeCol[r][c] = numberOfBRAMsBeforeCol[0][c];
73  }
74  }
75  }
76 }
77 
79  if(initializedResourceStringShortPartName == "")
80  throw runtime_error("The target device needs to be known, before you can manipulate any bitstream!");
81  if(initializedBitstreamShortPartName != initializedResourceStringShortPartName){//The device is changed
82  initializedBitstreamShortPartName = initializedResourceStringShortPartName;
83  if(bitstreamBegin != nullptr)
84  delete bitstreamBegin;
85 
86  initializeResourceStringParameters();
87  //Allocate
88  int clbPlaneSize = numberOfRows * numberOfWordsPerRow[0];
89  int bramPlaneSize = numberOfRows * XUSP_WORDS_PER_FRAME * (XUSP_EXTRA_FRAMES_PER_ROW + maxNumberOfBRAMCols * XUSP_FRAMES_PER_BRAM_CONTENT_COLUMN);
90 
91  bitstreamBegin = new uint32_t[clbPlaneSize + bramPlaneSize + 100];
92 
93  //Calc pointers
94  int offset = 0;
95 
96  for(int slr = 0 ; slr < numberOfSLRs ; slr++){
97  for(int r = SLRinfo[slr].fromRow ; r <= SLRinfo[slr].toRow ; r++){
98  for(int c = 0 ; c < numberOfCols[r] ; c++){
99  bitstreamCLB[r][c] = &bitstreamBegin[offset];
100  offset += LUT_numberOfFramesForResourceLetter[(uint8_t)resourceString[r][c]] * XUSP_WORDS_PER_FRAME;
101  }
102  }
103  for(int r = SLRinfo[slr].fromRow ; r <= SLRinfo[slr].toRow ; r++){
104  for(int c = 0 ; c < numberOfBRAMCols[r] ; c++){
105  bitstreamBRAM[r][c] = &bitstreamBegin[offset];
107  }
108  bitstreamBRAM[r][numberOfBRAMCols[r]] = &bitstreamBegin[offset];
110  }
111  }
112  bitstreamEnd = &bitstreamBegin[offset];
113  bitstreamHasValidData = false;
114  log("Reserved " + to_string(clbPlaneSize + bramPlaneSize) + " words for the bitstream buffers of device \"" + partName + "\"");
115  }
116 }
117 
118 string XilinxUltraScalePlus::getFrameType(int blockType, int rowAddress, int columnAddress){
119  if(XUSP_BLOCKTYPE_BLOCKRAM == blockType)
120  return "BlockRAM Contents";
121  else if(XUSP_BLOCKTYPE_LOGIC == blockType)
122  return LUT_typeOfFrameForResourceLetter[(uint8_t)resourceString[rowAddress][columnAddress]];
123  else
124  return "Unknown";
125 }
#define XUSP_WORDS_PER_FRAME
Definition: XUSP_Fabric.h:39
#define XUSP_EXTRA_FRAMES_PER_ROW
Definition: XUSP_Fabric.h:44
#define XUSP_FRAMES_PER_BRAM_CONTENT_COLUMN
Definition: XUSP_Fabric.h:40
#define XUSP_MAX_COLS
Definition: XUSP_Fabric.h:27
#define XUSP_BLOCKTYPE_BLOCKRAM
Definition: XUSP_Fabric.h:34
#define XUSP_BLOCKTYPE_LOGIC
Definition: XUSP_Fabric.h:33
void initializeResourceStringParameters() override
void ensureInitializedBitstreamArrays() override
std::string getFrameType(int, int, int) override
std::string to_string(Endianness e)
Definition: Endianness.h:56
bool charIs(char checkedChar)
Returns false. End of recursion for template.
Definition: iff.h:101