byteman  1.3 (Build #225)
Bitstream relocation and manipulation tool
XilinxUltraScale.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 "XilinxUltraScale.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  for((numberOfCols[0] = 0, numberOfFramesBeforeCol[0][0] = 0, numberOfBRAMCols[0] = 0) ; (uint8_t)resourceString[0][numberOfCols[0]] ; numberOfCols[0]++){
46  numberOfFramesBeforeCol[0][numberOfCols[0] + 1] = numberOfFramesBeforeCol[0][numberOfCols[0]] + LUT_numberOfFramesForResourceLetter[(uint8_t)resourceString[0][numberOfCols[0]]];
47  numberOfBRAMsBeforeCol[0][numberOfCols[0]] = numberOfBRAMCols[0];
48  if(str::iff::charIs(resourceString[0][numberOfCols[0]], 'A','B','C','D','2')) //A-D are BlockRAM columns, '2' is empty blockram column
49  numberOfBRAMCols[0]++;
50  }
51  for(int c = numberOfCols[0] + 1 ; c < XUS_MAX_COLS ; c++){
52  numberOfFramesBeforeCol[0][c] = numberOfFramesBeforeCol[0][c - 1];
53  }
54  for(int c = numberOfCols[0] ; c < XUS_MAX_COLS ; c++){
55  numberOfBRAMsBeforeCol[0][c] = numberOfBRAMsBeforeCol[0][c - 1];
56  }
57  numberOfFramesPerRow[0] = numberOfFramesBeforeCol[0][numberOfCols[0]];
58  numberOfWordsPerRow[0] = numberOfFramesPerRow[0] * XUS_WORDS_PER_FRAME;
59 
60  maxNumberOfCols = numberOfCols[0];
61  maxNumberOfBRAMCols = numberOfBRAMCols[0];
62  for(int r = 1 ; r < numberOfRows ; r++){
63  numberOfBRAMCols[r] = numberOfBRAMCols[0];
64  numberOfCols[r] = numberOfCols[0];
65  numberOfFramesPerRow[r] = numberOfFramesPerRow[0];
66  numberOfWordsPerRow[r] = numberOfWordsPerRow[0];
67  for(int c = 0 ; c < XUS_MAX_COLS ; c++){
68  numberOfFramesBeforeCol[r][c] = numberOfFramesBeforeCol[0][c];
69  }
70  for(int c = 0 ; c < XUS_MAX_COLS ; c++){
71  numberOfBRAMsBeforeCol[r][c] = numberOfBRAMsBeforeCol[0][c];
72  }
73  }
74  }
75 }
76 
78  if(initializedResourceStringShortPartName == "")
79  throw runtime_error("The target device needs to be known, before you can manipulate any bitstream!");
80  if(initializedBitstreamShortPartName != initializedResourceStringShortPartName){//The device is changed
81  initializedBitstreamShortPartName = initializedResourceStringShortPartName;
82  if(bitstreamBegin != nullptr)
83  delete bitstreamBegin;
84  initializeResourceStringParameters();
85  //Allocate
86  int clbPlaneSize = numberOfRows * numberOfWordsPerRow[0];
87  int bramPlaneSize = numberOfRows * XUS_WORDS_PER_FRAME * (XUS_EXTRA_FRAMES_PER_ROW + maxNumberOfBRAMCols * XUS_FRAMES_PER_BRAM_CONTENT_COLUMN);
88 
89  bitstreamBegin = new uint32_t[clbPlaneSize + bramPlaneSize];
90  //Calc pointers
91  int offset = 0;
92 
93  for(int slr = 0 ; slr < numberOfSLRs ; slr++){
94  for(int r = SLRinfo[slr].fromRow ; r <= SLRinfo[slr].toRow ; r++){
95  for(int c = 0 ; c < numberOfCols[r] ; c++){
96  bitstreamCLB[r][c] = &bitstreamBegin[offset];
97  offset += LUT_numberOfFramesForResourceLetter[(uint8_t)resourceString[r][c]] * XUS_WORDS_PER_FRAME;
98  }
99  }
100  for(int r = SLRinfo[slr].fromRow ; r <= SLRinfo[slr].toRow ; r++){
101  for(int c = 0 ; c < numberOfBRAMCols[r] ; c++){
102  bitstreamBRAM[r][c] = &bitstreamBegin[offset];
104  }
105  bitstreamBRAM[r][numberOfBRAMCols[r]] = &bitstreamBegin[offset];
107  }
108  }
109  bitstreamEnd = &bitstreamBegin[offset];
110  bitstreamHasValidData = false;
111 
112  log("Reserved " + to_string(clbPlaneSize + bramPlaneSize) + " words for the bitstream buffers of device \"" + partName + "\"");
113  }
114 }
115 
116 string XilinxUltraScale::getFrameType(int blockType, int rowAddress, int columnAddress){
117  if(XUS_BLOCKTYPE_BLOCKRAM == blockType)
118  return "BlockRAM Contents";
119  else if(XUS_BLOCKTYPE_LOGIC == blockType)
120  return LUT_typeOfFrameForResourceLetter[(uint8_t)resourceString[rowAddress][columnAddress]];
121  else
122  return "Unknown";
123 }
#define XUS_FRAMES_PER_BRAM_CONTENT_COLUMN
Definition: XUS_Fabric.h:41
#define XUS_BLOCKTYPE_BLOCKRAM
Definition: XUS_Fabric.h:35
#define XUS_MAX_COLS
Definition: XUS_Fabric.h:27
#define XUS_WORDS_PER_FRAME
Definition: XUS_Fabric.h:40
#define XUS_EXTRA_FRAMES_PER_ROW
Definition: XUS_Fabric.h:45
#define XUS_BLOCKTYPE_LOGIC
Definition: XUS_Fabric.h:34
virtual ~XilinxUltraScale()
std::string getFrameType(int, int, int) override
void initializeResourceStringParameters() override
void ensureInitializedBitstreamArrays() 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