00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "torc/bitstream/Virtex7.hpp"
00017 #include <iostream>
00018
00019
00020 #include "torc/architecture/DDB.hpp"
00021 #include "torc/architecture/XilinxDatabaseTypes.hpp"
00022 #include "torc/common/DirectoryTree.hpp"
00023 #include <fstream>
00024
00025 namespace torc {
00026 namespace bitstream{
00027
00028 const char* Virtex7::sPacketTypeName[ePacketTypeCount] = {
00029 "[UNKNOWN TYPE 0]", "TYPE1", "TYPE2", "[UNKNOWN TYPE 3]", "[UNKNOWN TYPE 4]",
00030 "[UNKNOWN TYPE 5]", "[UNKNOWN TYPE 6]", "[UNKNOWN TYPE 7]"
00031 };
00032
00033 const char* Virtex7::sOpcodeName[eOpcodeCount] = {
00034 "NOP", "READ", "WRITE", "RESERVED"
00035 };
00036
00037 const char* Virtex7::sRegisterName[eRegisterCount] = {
00038 "CRC", "FAR", "FDRI", "FDRO", "CMD", "CTL0", "MASK", "STAT", "LOUT", "COR0",
00039 "MFWR", "CBC", "IDCODE", "AXSS", "COR1", "[UNKNOWN REG 15]","WBSTAR", "TIMER",
00040 "[UNKNOWN REG 18]","[UNKNOWN REG 19]", "[UNKNOWN REG 20]", "[UNKNOWN REG 21]",
00041 "BOOTSTS", "[UNKNOWN REG 23]", "CTL1"
00042 };
00043
00044 const char* Virtex7::sCommandName[eCommandCount] = {
00045 "NULL", "WCFG", "MFW", "DGHIGH/LFRM", "RCFG", "START", "RCAP", "RCRC",
00046 "AGHIGH", "SWITCH", "GRESTORE", "SHUTDOWN", "GCAPTURE", "DESYNCH", "Reserved",
00047 "IPROG", "CRCC", "LTIMER"
00048 };
00049
00050 #define VALUES (const char*[])
00051
00052
00053 const Bitstream::Subfield Virtex7::sCTL0[] = {
00054 {0x00000001, 0, "GTS_USER_B", "GTS_USER_B", 0,
00055
00056
00057 VALUES{"IoDisabled", "IoAvtive", 0}},
00058 {0x00000008, 3, "Persist", "PERSIST", 0,
00059
00060
00061 VALUES{"No", "Yes", 0}},
00062 {0x00000030, 4, "Security", "SBITS", 0,
00063
00064
00065
00066 VALUES{"None", "Level1", "Level2", "Level2", 0}},
00067 {0x00000040, 6, "Encrypt", "DEC", 0,
00068
00069
00070 VALUES{"No", "Yes", 0}},
00071 {0x00000080, 7, "FARSRC", "FARSRC", 0,
00072
00073
00074 VALUES{"FAR", "EFAR", 0}},
00075 {0x00000100, 8, "GLUTMASK", "GLUTMASK", 0,
00076
00077
00078
00079
00080 VALUES{"Masked", "Dynamic", 0}},
00081 {0x00001000, 12, "OverTempPowerDown", "OverTempPowerDown", 0,
00082
00083
00084 VALUES{"Disable", "Enable", 0}},
00085 {0x40000000, 30, "ICAP_sel", "ICAP_SEL", 0,
00086
00087
00088 VALUES{"Top", "Bottom", 0}},
00089 {0x80000000, 31, "EFUSE_key", "EFUSE_KEY", 0,
00090
00091
00092 VALUES{"No", "Yes", 0}},
00093 {0, 0, 0, 0, 0, 0}
00094 };
00095
00096
00097 const Bitstream::Subfield Virtex7::sMASK0[] = {
00098 {0x00000001, 0, "GTS_USER_B", "GTS_USER_B", 0, VALUES{"Protected", "Writable", 0}},
00099 {0x00000008, 3, "Persist", "PERSIST", 0, VALUES{"Protected", "Writable", 0}},
00100 {0x00000030, 4, "Security", "SBITS", 0,
00101 VALUES{"Protected", "[UNKNOWN 1]", "[UNKNOWN 2]", "Writable", 0}},
00102 {0x00000040, 6, "Encrypt", "DEC", 0, VALUES{"Protected", "Writable", 0}},
00103 {0x00000080, 7, "FARSRC", "FARSRC", 0, VALUES{"Protected", "Writable", 0}},
00104 {0x00000100, 8, "GLUTMASK", "GLUTMASK", 0, VALUES{"Protected", "Writable", 0}},
00105 {0x00001000, 12, "OverTempPowerDown", "OverTempPowerDown", 0,
00106 VALUES{"Protected", "Writable", 0}},
00107 {0x40000000, 30, "ICAP_sel", "ICAP_SEL", 0, VALUES{"Protected", "Writable", 0}},
00108 {0x80000000, 31, "EFUSE_key", "EFUSE_KEY", 0, VALUES{"Protected", "Writable", 0}},
00109 {0, 0, 0, 0, 0, 0}
00110 };
00111
00112
00113 const Bitstream::Subfield Virtex7::sCTL1[] = {
00114 {0, 0, 0, 0, 0, 0}
00115 };
00116
00117
00118
00119 const Bitstream::Subfield Virtex7::sCOR0[] = {
00120 {0x00000007, 0, "GWE_cycle", "GWE_CYCLE", 5,
00121
00122
00123
00124 VALUES{"1", "2", "3", "4", "5", "6", "Done", "Keep", 0}},
00125 {0x00000038, 3, "GTS_cycle", "GTS_CYCLE", 4,
00126
00127
00128
00129 VALUES{"1", "2", "3", "4", "5", "6", "Done", "Keep", 0}},
00130 {0x000001C0, 6, "LCK_cycle", "LOCK_CYCLE", 0,
00131
00132
00133 VALUES{"0", "1", "2", "3", "4", "5", "6", "No Wait", 0}},
00134 {0x00000E00, 9, "Match_cycle", "MATCH_CYCLE", 0,
00135
00136
00137 VALUES{"0", "1", "2", "3", "4", "5", "6", "NoWait", 0}},
00138 {0x00007000, 12, "DONE_cycle", "DONE_CYCLE", 3,
00139
00140
00141 VALUES{"1", "2", "3", "4", "5", "6", "7", "KEEP", 0}},
00142 {0x00018000, 15, "StartupClk", "SSCLKSRC", 0,
00143
00144
00145 VALUES{"Cclk", "UserClk", "JtagClk", "JtagClk", 0}},
00146 {0x007e0000, 17, "ConfigRate", "OSCFSEL", 0,
00147
00148
00149 VALUES{
00150 "[UNKNOWN 0]", "[UNKNOWN 1]", "[UNKNOWN 2]", "[UNKNOWN 3]",
00151 "[UNKNOWN 4]", "[UNKNOWN 5]", "[UNKNOWN 6]", "[UNKNOWN 7]",
00152 "[UNKNOWN 8]", "[UNKNOWN 9]", "[UNKNOWN 10]", "[UNKNOWN 11]",
00153 "[UNKNOWN 12]", "[UNKNOWN 13]", "[UNKNOWN 14]", "[UNKNOWN 15]",
00154 "[UNKNOWN 16]", "[UNKNOWN 17]", "[UNKNOWN 18]", "[UNKNOWN 19]",
00155 "[UNKNOWN 20]", "[UNKNOWN 21]", "[UNKNOWN 22]", "[UNKNOWN 23]",
00156 "[UNKNOWN 24]", "[UNKNOWN 25]", "[UNKNOWN 26]", "[UNKNOWN 27]",
00157 "[UNKNOWN 28]", "[UNKNOWN 29]", "[UNKNOWN 30]", "[UNKNOWN 31]",
00158 0}},
00159 {0x00800000, 23, "Capture", "SINGLE", 0,
00160
00161
00162 VALUES{"Continuous", "OneShot", 0}},
00163 {0x01000000, 24, "DriveDone", "DRIVE_DONE", 0,
00164
00165
00166 VALUES{"No", "Yes", 0}},
00167 {0x02000000, 25, "DonePipe", "DONE_PIPE", 0,
00168
00169
00170 VALUES{"No", "Yes", 0}},
00171 {0x08000000, 27, "DONE_status", "PWRDWN_STAT", 0,
00172
00173
00174 VALUES{"DonePin", "PowerdownPin", 0}},
00175 {0, 0, 0, 0, 0, 0}
00176 };
00177
00178
00179 const Bitstream::Subfield Virtex7::sCOR1[] = {
00180 {0x00000003, 0, "BPI_page_size", "BPI_PAGE_SIZE", 0,
00181
00182
00183 VALUES{"1", "4", "8", "Reserved", 0}},
00184 {0x0000000C, 2, "BPI_1st_read_cycle", "BPI_1ST_READ_CYCLES", 0,
00185
00186
00187 VALUES{"1", "2", "3", "4", 0}},
00188
00189 {0x00000100, 8, "ContinuousReadbackCRC", "RBCRC_EN", 0,
00190
00191
00192 VALUES{"Enabled", "disabled", 0}},
00193
00194 {0x00000200, 9, "InitAsCRCErrorPin", "RBCRC_NO_PIN", 0,
00195
00196
00197 VALUES{"Disabled", "Enabled", 0}},
00198 {0x00018000, 15, "ActionReadbackCRC", "RBCRC_ACTION", 0,
00199
00200
00201 VALUES{"Continue", "Halt", "CorrectAndHalt", "CorrectAndContinue", 0}},
00202 {0x00020000, 17, "PersistDeassertAtDesynch", "PERSIST_DEASSERT_AT_DESYNCH", 0,
00203
00204
00205 VALUES{"Disabled", "Enabled", 0}},
00206 {0, 0, 0, 0, 0, 0}
00207 };
00208
00209
00210 const Bitstream::Subfield Virtex7::sWBSTAR[] = {
00211 {0x40000000, 30, "NextRevisionSelect", "RS[1:0]", 0,
00212
00213 VALUES{"00", "01", "10", "11", 0}},
00214 {0x20000000, 29, "RevisionSelectTristate", "RS_TS_B", 0,
00215
00216 VALUES{"Disabled", "Enabled", 0}},
00217 {0, 0, 0, 0, 0, 0}
00218 };
00219
00220
00221 const Bitstream::Subfield Virtex7::sTIMER[] = {
00222 {0x40000000, 30, "TimerForConfig", "TIMER_CFG_MON", 0,
00223
00224 VALUES{"Disabled", "Enabled", 0}},
00225 {0x80000000, 31, "TimerForUser", "TIMER_USR_MON", 0,
00226
00227 VALUES{"Disabled", "Enabled", 0}},
00228 {0, 0, 0, 0, 0, 0}
00229 };
00230
00231
00232 const Bitstream::Subfield Virtex7::sBOOTSTS[] = {
00233 {0x00000001, 0, "RegisterStatus0", "VALID_0", 0,
00234
00235 VALUES{"Valid", "Invalid", 0}},
00236 {0x00000002, 1, "FallbackStatus0", "FALLBACK_0", 0,
00237
00238
00239 VALUES{"Normal", "Fallback", 0}},
00240 {0x00000004, 2, "InternalTrigger0", "IPROG_0", 0,
00241
00242 VALUES{"External", "Internal", 0}},
00243 {0x00000008, 3, "WatchdogTimeout0", "WTO_ERROR_0", 0,
00244
00245 VALUES{"Valid", "Invalid", 0}},
00246 {0x00000010, 4, "ID_error0", "ID_ERROR_0", 0,
00247
00248 VALUES{"NoError", "Error", 0}},
00249 {0x00000020, 5, "CRC_error0", "CRC_ERROR_0", 0,
00250
00251 VALUES{"NoError", "Error", 0}},
00252 {0x00000040, 6, "BPI_wraparound_error0", "WRAP_ERROR_0", 0,
00253
00254 VALUES{"NoError", "Error", 0}},
00255 {0x00000100, 8, "RegisterStatus1", "VALID_1", 0,
00256
00257 VALUES{"Valid", "Invalid", 0}},
00258 {0x00000200, 9, "FallbackStatus1", "FALLBACK_1", 0,
00259
00260
00261 VALUES{"Normal", "Fallback", 0}},
00262 {0x00000400, 10, "InternalTrigger1", "IPROG_1", 0,
00263
00264 VALUES{"External", "Internal", 0}},
00265 {0x00000800, 11, "WatchdogTimeout1", "WTO_ERROR_1", 0,
00266
00267 VALUES{"Valid", "Invalid", 0}},
00268 {0x00001000, 12, "ID_error1", "ID_ERROR_1", 0,
00269
00270 VALUES{"NoError", "Error", 0}},
00271 {0x00002000, 13, "CRC_error1", "CRC_ERROR_1", 0,
00272
00273 VALUES{"NoError", "Error", 0}},
00274 {0x00004000, 14, "BPI_wraparound_error1", "WRAP_ERROR_1", 0,
00275
00276 VALUES{"NoError", "Error", 0}},
00277 {0, 0, 0, 0, 0, 0}
00278 };
00279
00280
00281 const Bitstream::Subfield Virtex7::sSTAT[] = {
00282 {0x00000001, 0, "CRC_error", "CRC_ERROR", 0,
00283
00284
00285 VALUES{"No", "Yes", 0}},
00286 {0x00000002, 1, "DecryptorSecuritySet", "PART_SECURED", 0,
00287
00288
00289 VALUES{"No", "Yes", 0}},
00290 {0x00000004, 2, "MMCM_locked", "MMCM_LOCK", 0,
00291
00292
00293 VALUES{"No", "Yes", 0}},
00294 {0x00000008, 3, "DCI_matched", "DCI_MATCH", 0,
00295
00296
00297 VALUES{"No", "Yes", 0}},
00298 {0x00000010, 4, "StartupFinished", "EOS", 0,
00299
00300
00301 VALUES{"No", "Yes", 0}},
00302 {0x00000020, 5, "GTS_CFG_B", "GTS_CFG_B", 0,
00303
00304
00305 VALUES{"IoDisabled", "IoEnabled", 0}},
00306 {0x00000040, 6, "GWE", "GWE", 0,
00307
00308
00309
00310 VALUES{"WriteDisabled", "WriteEnabled", 0}},
00311 {0x00000080, 7, "GHIGH_B", "GHIGH_B", 0,
00312
00313
00314 VALUES{"InterconnectDisabled", "InterconnectEnabled", 0}},
00315 {0x00000700, 8, "Mode", "MODE", 0,
00316
00317
00318 VALUES{"MasterSerial", "MasterSPI", "MasterBPI-Up", "MasterBPI-Down",
00319 "MasterSelectMap", "JTAG", "SlaveSelectMap", "SlaveSerial", 0}},
00320 {0x00000800, 11, "INIT_complete", "INIT_COMPLETE", 0,
00321
00322
00323 VALUES{"No", "Yes", 0}},
00324 {0x00000800, 11, "INIT_complete", "INIT_COMPLETE", 0,
00325
00326
00327 VALUES{"No", "Yes", 0}},
00328 {0x00001000, 12, "INIT_B", "INIT_B", 0,
00329
00330
00331 VALUES{"Deasserted", "Asserted", 0}},
00332 {0x00002000, 13, "DONE_released", "RELEASE_DONE", 0,
00333
00334
00335 VALUES{"DrivenLow", "Released", 0}},
00336 {0x00004000, 14, "DONE", "DONE", 0,
00337
00338
00339 VALUES{"NotDone", "Done", 0}},
00340 {0x00008000, 15, "ID_error", "ID_ERROR", 0,
00341
00342
00343 VALUES{"NoError", "Error", 0}},
00344 {0x00010000, 16, "Decrypt_error", "DEC_ERROR", 0,
00345
00346
00347 VALUES{"NoError", "Error", 0}},
00348 {0x001c0000, 18, "StartupState", "STARTUP_STATE", 0,
00349
00350
00351 VALUES{"0", "1", "3", "2", "7", "6", "4", "5", 0}},
00352 {0x06000000, 25, "BusWidth", "BUS_WIDTH", 0,
00353
00354
00355 VALUES{"1", "8", "16", "32", 0}},
00356 {0, 0, 0, 0, 0, 0}
00357 };
00358
00359
00360 uint32_t Virtex7::makeSubfield(ERegister inRegister, const std::string& inSubfield,
00361 const std::string& inSetting) {
00362 const Subfield* subfields;
00363 switch(inRegister) {
00364 case eRegisterCOR0: subfields = sCOR0; break;
00365 case eRegisterCOR1: subfields = sCOR1; break;
00366 case eRegisterSTAT: subfields = sSTAT; break;
00367 case eRegisterCTL0: subfields = sCTL0; break;
00368 case eRegisterCTL1: subfields = sCTL1; break;
00369 case eRegisterMASK: subfields = sMASK0; break;
00370 case eRegisterWBSTAR: subfields = sWBSTAR; break;
00371 case eRegisterTIMER: subfields = sTIMER; break;
00372 case eRegisterBOOTSTS: subfields = sBOOTSTS; break;
00373 default: return 0;
00374 }
00375 for(uint32_t field = 0; subfields[field].mMask != 0; field++){
00376 const Subfield& subfield = subfields[field];
00377 if(inSubfield != subfield.mBitgenName && inSubfield != subfield.mConfigGuideName)
00378 continue;
00379 const char** ptr = subfield.mValues;
00380 for(uint32_t i = 0; *ptr != 0; i++, ptr++){
00381 if(inSetting == *ptr) return (i << subfield.mShift) & subfield.mMask;
00382 }
00383 }
00384 return 0;
00385 }
00386
00387 #define GENERATE_STATIC_DEVICE_INFO
00388 #ifndef GENERATE_STATIC_DEVICE_INFO
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399 #else
00400 void Virtex7::initializeDeviceInfo(const std::string& inDeviceName) {
00401
00402 typedef torc::architecture::xilinx::TileCount TileCount;
00403 typedef torc::architecture::xilinx::TileRow TileRow;
00404 typedef torc::architecture::xilinx::TileCol TileCol;
00405 typedef torc::architecture::xilinx::TileTypeIndex TileTypeIndex;
00406 typedef torc::architecture::xilinx::TileTypeCount TileTypeCount;
00407
00408
00409
00410 torc::architecture::DDB ddb(inDeviceName);
00411 const torc::architecture::Tiles& tiles = ddb.getTiles();
00412 uint32_t tileCount = tiles.getTileCount();
00413 uint16_t rowCount = tiles.getRowCount();
00414 uint16_t colCount = tiles.getColCount();
00415 ColumnTypeVector columnTypes;
00416
00417
00418 typedef std::map<TileTypeIndex, std::string> TileTypeIndexToName;
00419 typedef std::map<std::string, TileTypeIndex> TileTypeNameToIndex;
00420 TileTypeIndexToName tileTypeIndexToName;
00421 TileTypeNameToIndex tileTypeNameToIndex;
00422 TileTypeCount tileTypeCount = tiles.getTileTypeCount();
00423 for(TileTypeIndex tileTypeIndex(0); tileTypeIndex < tileTypeCount; tileTypeIndex++) {
00424 std::cout << "Tile type index " << tileTypeIndex << std::endl;
00425 const std::string tileTypeName = tiles.getTileTypeName(tileTypeIndex);
00426 tileTypeIndexToName[tileTypeIndex] = tileTypeName;
00427 tileTypeNameToIndex[tileTypeName] = tileTypeIndex;
00428 TileTypeNameToColumnType::iterator ttwp = mTileTypeNameToColumnType.find(tileTypeName);
00429 TileTypeNameToColumnType::iterator ttwe = mTileTypeNameToColumnType.end();
00430 if(ttwp != ttwe) mTileTypeIndexToColumnType[tileTypeIndex] = EColumnType(ttwp->second);
00431 }
00432
00433
00434 columnTypes.resize(colCount);
00435 uint32_t frameCount = 0;
00436 for(uint32_t blockType = 0; blockType < Virtex7::eFarBlockTypeCount; blockType++) {
00437 std::cout << "Block type " << blockType << std::endl;
00438 for(TileCol col; col < colCount; col++) {
00439
00440 bool found = false;
00441 (void) found;
00442 columnTypes[col] = eColumnTypeEmpty;
00443 TileTypeIndexToColumnType::iterator ttwe = mTileTypeIndexToColumnType.end();
00444 TileTypeIndexToColumnType::iterator ttwp = ttwe;
00445 for(TileRow row; row < rowCount; row++) {
00446
00447
00448 const torc::architecture::TileInfo& tileInfo
00449 = tiles.getTileInfo(tiles.getTileIndex(row, col));
00450 TileTypeIndex tileTypeIndex = tileInfo.getTypeIndex();
00451
00452 ttwp = mTileTypeIndexToColumnType.find(tileTypeIndex);
00453 if(ttwp != ttwe) {
00454 uint32_t width = mColumnDefs[ttwp->second][blockType];
00455 frameCount += width;
00456
00457
00458 columnTypes[col] = static_cast<EColumnType>(ttwp->second);
00459 found = true;
00460 break;
00461 }
00462 }
00463 }
00464
00465 if(blockType == 2) break;
00466 }
00467
00468
00469 boost::filesystem::path workingPath = torc::common::DirectoryTree::getWorkingPath();
00470 boost::filesystem::path generatedMap = workingPath / (inDeviceName + ".map.csv");
00471 std::fstream tilemapStream(generatedMap.string().c_str(), std::ios::out);
00472 for(TileRow row; row < rowCount; row++) {
00473 for(TileCol col; col < colCount; col++) {
00474
00475 const torc::architecture::TileInfo& tileInfo
00476 = tiles.getTileInfo(tiles.getTileIndex(row, col));
00477 TileTypeIndex tileTypeIndex = tileInfo.getTypeIndex();
00478 tilemapStream << tiles.getTileTypeName(tileTypeIndex);
00479 if(col + 1 < colCount) tilemapStream << ",";
00480 }
00481 tilemapStream << std::endl;
00482 }
00483 tilemapStream.close();
00484
00485
00486 std::cout << "invoking setDeviceInfo()" << std::endl;
00487 setDeviceInfo(DeviceInfo(tileCount, rowCount, colCount, columnTypes));
00488 std::cout << "finished setDeviceInfo()" << std::endl;
00489
00490 }
00491
00492 #endif
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513 }
00514 }