byteman  1.3 (Build #225)
Bitstream relocation and manipulation tool
XilinxConfigurationAccessPort.h
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 #ifndef XILINXCONFIGURATIONACCESSPORT_H
18 #define XILINXCONFIGURATIONACCESSPORT_H
19 
20 #include<iostream>
21 #include<cstdint> //uint
22 #include<fstream>
23 #include<algorithm> //replace
24 #include<string>
25 #include<sstream>
26 #include<cstring> //memset
27 
28 #include "XCAP/XCAP.h"
29 
30 #include "../CommonDevice2D.h"
31 #include "../../Common/Endianness.h"
32 
33 #include "../../Common/assert.h"
34 #include "../../Common/FileIO.h"
35 #include "../../Common/str.h"
36 #include "../../../VERSION" // To get byteman version
37 
38 //As indicator for number and types of variables in the template
39 #define FABRIC_TEMPLATE(MAX_SLRS, MAX_ROWS, MAX_COLS, MAX_BRAM_COLS, BLOCKTYPE_MAX, BLOCKTYPE_LOGIC, BLOCKTYPE_BLOCKRAM, WORDS_BEFORE_CLK, WORDS_AT_CLK, WORDS_AFTER_CLK, WORDS_PER_FRAME, FRAMES_PER_BRAM_CONTENT_COLUMN, CLB_PER_CLOCK_REGION, BRAM_PER_CLOCK_REGION, EXTRA_FRAMES_PER_ROW, ENABLE_TOP_BOTTOM, TOP_BOTTOM_BIT_SHIFT, BLOCKTYPE_SHIFT, BLOCKTYPE_MASK, ROWADDRESS_SHIFT, ROWADDRESS_MASK, COLUMNADDRESS_SHIFT, COLUMNADDRESS_MASK, MINORADDRESS_SHIFT, MINORADDRESS_MASK) MAX_SLRS, MAX_ROWS, MAX_COLS, MAX_BRAM_COLS, BLOCKTYPE_MAX, BLOCKTYPE_LOGIC, BLOCKTYPE_BLOCKRAM, WORDS_BEFORE_CLK, WORDS_AT_CLK, WORDS_AFTER_CLK, WORDS_PER_FRAME, FRAMES_PER_BRAM_CONTENT_COLUMN, CLB_PER_CLOCK_REGION, BRAM_PER_CLOCK_REGION, EXTRA_FRAMES_PER_ROW, ENABLE_TOP_BOTTOM, TOP_BOTTOM_BIT_SHIFT, BLOCKTYPE_SHIFT, BLOCKTYPE_MASK, ROWADDRESS_SHIFT, ROWADDRESS_MASK, COLUMNADDRESS_SHIFT, COLUMNADDRESS_MASK, MINORADDRESS_SHIFT, MINORADDRESS_MASK
40 
41 template <int MAX_SLRS,
42  int MAX_ROWS,
43  int MAX_COLS,
44  int MAX_BRAM_COLS,
45  int BLOCKTYPE_MAX,
46  int BLOCKTYPE_LOGIC,
47  int BLOCKTYPE_BLOCKRAM,
48  int WORDS_BEFORE_CLK,
49  int WORDS_AT_CLK,
50  int WORDS_AFTER_CLK,
51  int WORDS_PER_FRAME,
52  int FRAMES_PER_BRAM_CONTENT_COLUMN,
53  int CLB_PER_CLOCK_REGION,
54  int BRAM_PER_CLOCK_REGION,
55  int EXTRA_FRAMES_PER_ROW,
56  int FAR_ENABLE_TOP_BOTTOM_BIT,
57  int FAR_TOP_BOTTOM_BIT_SHIFT,
58  int FAR_BLOCKTYPE_SHIFT,
59  int FAR_BLOCKTYPE_MASK,
60  int FAR_ROWADDRESS_SHIFT,
61  int FAR_ROWADDRESS_MASK,
62  int FAR_COLUMNADDRESS_SHIFT,
63  int FAR_COLUMNADDRESS_MASK,
64  int FAR_MINORADDRESS_SHIFT,
65  int FAR_MINORADDRESS_MASK>
67 {
68  public:
69 //Constructor & deconstructor
71  {
72  bitstreamBegin = nullptr;
77  SLRinfo[0] = {0, 0, 0};
78  numberOfRows = 0;
79  };
80 
82  {
83  if(bitstreamBegin != nullptr)
84  delete bitstreamBegin;
85  };
86 
87 //Type definitions
88  enum class MergeOP
89  {
90  SET, XOR, OR, AND
91  };
92 
94  {
97  int intParam;
100 
101 //Base variables
102  //Output
104 
105  //bitstream meta
106  std::string designName;
107  std::string partName;
108  std::string fileDate;
109  std::string fileTime;
110 
111  //bitstream structure
115  uint32_t* bitstreamBegin;
116  uint32_t* bitstreamCLB[MAX_ROWS][MAX_COLS];
117  uint32_t* bitstreamBRAM[MAX_ROWS][MAX_BRAM_COLS];
118  uint32_t* bitstreamEnd;
119 
120  //resource string parameters
124  int numberOfBRAMCols[MAX_ROWS];
125  int numberOfCols[MAX_ROWS];
128  int numberOfFramesBeforeCol[MAX_ROWS][MAX_COLS];
129  int numberOfBRAMsBeforeCol[MAX_ROWS][MAX_COLS];
130  int numberOfFramesPerRow[MAX_ROWS];
131  int numberOfWordsPerRow[MAX_ROWS];
132 
133  //SLR data and resource string
135  char resourceString[MAX_ROWS][MAX_COLS];
136  struct {
137  uint32_t IDCODE;
139  int rowsInTopHalf, rowsInBottomHalf;//used for xilinx series 7
140  }SLRinfo[MAX_SLRS];
141 
142  //constant arrays defining selected fabric
146 
147 //Base class functions are inlined and included here (this is so to force multiple instances that get optimized for the architectures' constants)
148  #include "XCAP/inlineBlank.h"
149  #include "XCAP/inlineInput.h"
150  #include "XCAP/inlineOutput.h"
151  #include "XCAP/inlineMerge.h"
152  #include "XCAP/inlineParseParams.h"
153  #include "XCAP/inlineCAP.h"
154  #include "XCAP/inlineFAR.h"
155  #include "XCAP/inlineSetFabric.h"
156  #include "XCAP/inlineTest.h"
158  #include "XCAP/inlineAssembly.h"
159  #include "XCAP/inlineChange.h"
160 
161 //Some functions that will need to be implemented by each architecture
162  //get/set device type
163  virtual int getDeviceByIDCODEorThrow(int) = 0;
164  virtual int getDeviceByNameOrThrow(std::string) = 0;
165  virtual int getDeviceByIDCODE(int) = 0;
166  virtual int getDeviceByName(std::string) = 0;
167  virtual void setDevice(int, std::string = "") = 0;
168  virtual void setDeviceByPartNameOrThrow() = 0;
169  virtual void setDeviceByNameOrThrow(std::string) = 0;
170  virtual void setDeviceByIDCODEOrThrow(int) = 0;
171 
172  //initialize resource strings and bitstream buffers
175 
176  // output bitstream
177  virtual void outputBitstreamGlobalHeaderSequence(std::ofstream&, bool, Endianness) = 0;
178  virtual void outputBitstreamGlobalFooterSequence(std::ofstream&, bool, Endianness) = 0;
179 
180  virtual void outputBitstreamSLRHeaderBitstreamSequence(std::ofstream&, int, bool, Endianness) = 0;
181  virtual void outputBitstreamSLRFooterBitstreamSequence(std::ofstream&, int, bool, Endianness) = 0;
182  virtual void outputBitstreamSLRHeaderAfterBitstreamSequence(std::ofstream&, int, bool, Endianness) = 0;
183  virtual void outputBitstreamSLRWrapUpSequence(std::ofstream&, int, bool, Endianness) = 0;
184 
185  virtual void outputBitstreamEmptySLRHeaderSequence(std::ofstream&, int, bool, Endianness) = 0;
186  virtual void outputBitstreamEmptySLRWrapUpSequence(std::ofstream&, int, bool, Endianness) = 0;
187 
188  // Info
189  virtual std::string getFrameType(int, int, int) = 0;
190 
191  protected:
192  private:
193 };
194 
195 #endif //XILINXCONFIGURATIONACCESSPORT_H
Endianness
< Endianness in byteman is represented not only by big/little endian, but also by potential bit swapp...
Definition: Endianness.h:47
@ BE
Big endian ("BE" instead of full-er name, so it does not conflict with linux's reserved endianess wor...
virtual void ensureInitializedBitstreamArrays()=0
virtual void outputBitstreamEmptySLRWrapUpSequence(std::ofstream &, int, bool, Endianness)=0
virtual void outputBitstreamSLRFooterBitstreamSequence(std::ofstream &, int, bool, Endianness)=0
virtual int getDeviceByName(std::string)=0
virtual std::string getFrameType(int, int, int)=0
virtual int getDeviceByNameOrThrow(std::string)=0
virtual void outputBitstreamGlobalHeaderSequence(std::ofstream &, bool, Endianness)=0
uint32_t * bitstreamCLB[MAX_ROWS][MAX_COLS]
std::streamoff headerLocationOfRemainingFileLength
gets set by outputBITheader() and gets used by outputBITheaderLengthField().
virtual int getDeviceByIDCODEorThrow(int)=0
uint32_t * bitstreamBRAM[MAX_ROWS][MAX_BRAM_COLS]
virtual void initializeResourceStringParameters()=0
virtual void outputBitstreamSLRHeaderBitstreamSequence(std::ofstream &, int, bool, Endianness)=0
virtual void setDeviceByNameOrThrow(std::string)=0
virtual void outputBitstreamSLRWrapUpSequence(std::ofstream &, int, bool, Endianness)=0
virtual void outputBitstreamEmptySLRHeaderSequence(std::ofstream &, int, bool, Endianness)=0
virtual void outputBitstreamSLRHeaderAfterBitstreamSequence(std::ofstream &, int, bool, Endianness)=0
virtual void setDeviceByIDCODEOrThrow(int)=0
struct XilinxConfigurationAccessPort::@0 SLRinfo[MAX_SLRS]
std::string initializedResourceStringShortPartName
the partName of currently initialized resource string parameters
virtual void setDeviceByPartNameOrThrow()=0
std::string initializedBitstreamParamsShortPartName
the partName of currently initialized resource string parameters
Endianness loadedBitstreamEndianness
The endianess of the currently loaded bitstream.
std::string initializedBitstreamShortPartName
The partName of currently initialized bitstream buffers.
virtual int getDeviceByIDCODE(int)=0
virtual void setDevice(int, std::string="")=0
virtual void outputBitstreamGlobalFooterSequence(std::ofstream &, bool, Endianness)=0
struct XilinxConfigurationAccessPort::SelectedOptions selectedOptions