00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "torc/bitstream/Virtex4.hpp"
00020 #include <iostream>
00021
00022
00023 #include "torc/architecture/DDB.hpp"
00024 #include "torc/architecture/XilinxDatabaseTypes.hpp"
00025 #include "torc/common/DirectoryTree.hpp"
00026 #include <fstream>
00027
00028
00029 namespace torc {
00030 namespace bitstream {
00031
00032 const char* Virtex4::sPacketTypeName[ePacketTypeCount] = {
00033 "[UNKNOWN TYPE 0]", "TYPE1", "TYPE2", "[UNKNOWN TYPE 3]", "[UNKNOWN TYPE 4]",
00034 "[UNKNOWN TYPE 5]", "[UNKNOWN TYPE 6]", "[UNKNOWN TYPE 7]"
00035 };
00036
00037 const char* Virtex4::sOpcodeName[eOpcodeCount] = {
00038 "NOP", "READ", "WRITE", "RESERVED"
00039 };
00040
00041 const char* Virtex4::sRegisterName[eRegisterCount] = {
00042 "CRC", "FAR", "FDRI", "FDRO", "CMD", "CTL", "MASK", "STAT", "LOUT", "COR", "MFWR", "CBC",
00043 "IDCODE", "AXSS"
00044 };
00045
00046 const char* Virtex4::sCommandName[eCommandCount] = {
00047 "NULL", "WCFG", "MFWR", "LFRM", "RCFG", "START", "RCAP", "RCRC", "AGHIGH", "SWITCH",
00048 "GRESTORE", "SHUTDOWN", "GCAPTURE", "DESYNC"
00049 };
00050
00051 #define VALUES (const char*[])
00052
00053
00054 const Bitstream::Subfield Virtex4::sCOR[] = {
00055 {0x00000007, 0, "GWE_cycle", "GWE_CYCLE", 5,
00056
00057
00058 VALUES{"[UNDEFINED 0]", "2", "3", "4", "5", "6", "[UNDEFINED 6]", "[UNDEFINED 7]", 0}},
00059 {0x00000038, 3, "GTS_cycle", "GTS_CYCLE", 4,
00060
00061
00062 VALUES{"[UNDEFINED 0]", "2", "3", "4", "5", "6", "[UNDEFINED 6]", "[UNDEFINED 7]", 0}},
00063 {0x000001c0, 6, "LCK_cycle", "LOCK_CYCLE", 7,
00064
00065
00066 VALUES{"1", "2", "3", "4", "5", "6", "[UNDEFINED 6]", "NoWait", 0}},
00067 {0x00000E00, 9, "Match_cycle", "MATCH_CYCLE", 7,
00068
00069
00070 VALUES{"1", "2", "3", "4", "5", "6", "[UNDEFINED 6]", "NoWait", 0}},
00071 {0x00007000, 12, "DONE_cycle", "DONE_CYCLE", 3,
00072
00073
00074 VALUES{"[UNDEFINED 0]", "2", "3", "4", "5", "6", "[UNDEFINED 6]", "[UNDEFINED 7]", 0}},
00075 {0x00018000, 15, "StartupClk", "SSCLKSRC", 0,
00076
00077
00078 VALUES{"Cclk", "UserClk", "JtagClk", "JtagClk", 0}},
00079 {0x007e0000, 17, "ConfigRate", "OSCFSEL", 0,
00080
00081
00082 VALUES{
00083 "[UNKNOWN 0]", "[UNKNOWN 1]", "[UNKNOWN 2]", "[UNKNOWN 3]",
00084 "[UNKNOWN 4]", "[UNKNOWN 5]", "[UNKNOWN 6]", "[UNKNOWN 7]",
00085 "[UNKNOWN 8]", "[UNKNOWN 9]", "[UNKNOWN 10]", "[UNKNOWN 11]",
00086 "[UNKNOWN 12]", "[UNKNOWN 13]", "[UNKNOWN 14]", "[UNKNOWN 15]",
00087 "[UNKNOWN 16]", "[UNKNOWN 17]", "[UNKNOWN 18]", "[UNKNOWN 19]",
00088 "[UNKNOWN 20]", "[UNKNOWN 21]", "[UNKNOWN 22]", "[UNKNOWN 23]",
00089 "[UNKNOWN 24]", "[UNKNOWN 25]", "[UNKNOWN 26]", "[UNKNOWN 27]",
00090 "[UNKNOWN 28]", "[UNKNOWN 29]", "[UNKNOWN 30]", "[UNKNOWN 31]",
00091 0}},
00092 {0x00800000, 23, "Capture", "SINGLE", 0,
00093
00094
00095 VALUES{"Continuous", "OneShot", 0}},
00096 {0x01000000, 24, "DriveDone", "DRIVE_DONE", 0,
00097
00098
00099 VALUES{"No", "Yes", 0}},
00100 {0x02000000, 25, "DonePipe", "DONE_PIPE", 0,
00101
00102
00103 VALUES{"No", "Yes", 0}},
00104 {0x10000000, 28, "CRC", "CRC_BYPASS", 0,
00105
00106
00107 VALUES{"Enable", "Disable", 0}},
00108 {0, 0, 0, 0, 0, 0}
00109 };
00110
00111
00112
00113 const Bitstream::Subfield Virtex4::sSTAT[] = {
00114 {0x00000001, 0, "CRC_error", "CRC_ERROR", 0,
00115
00116
00117 VALUES{"No", "Yes", 0}},
00118 {0x00000002, 1, "DecryptorSecuritySet", "PART_SECURED", 0,
00119
00120
00121 VALUES{"No", "Yes", 0}},
00122 {0x00000004, 2, "DCM_locked", "DCM_LOCK", 0,
00123
00124
00125 VALUES{"No", "Yes", 0}},
00126 {0x00000008, 3, "DCI_matched", "DCI_MATCH", 0,
00127
00128
00129 VALUES{"No", "Yes", 0}},
00130 {0x00000010, 4, "StartupFinished", "EOS", 0,
00131
00132
00133 VALUES{"No", "Yes", 0}},
00134 {0x00000020, 5, "GTS_CFG_B", "GTS_CFG_B", 0,
00135
00136
00137 VALUES{"IoDisabled", "IoEnabled", 0}},
00138 {0x00000040, 6, "GWE", "GWE", 0,
00139
00140
00141
00142 VALUES{"WriteDisabled", "WriteEnabled", 0}},
00143 {0x00000080, 7, "GHIGH_B", "GHIGH_B", 0,
00144
00145
00146 VALUES{"InterconnectDisabled", "InterconnectEnabled", 0}},
00147 {0x00000700, 8, "Mode", "MODE", 0,
00148
00149
00150 VALUES{"MasterSerial", "SlaveSelectMap32", "[UNDEFINED 2]", "MasterSelectMap",
00151 "[UNDEFINED 3]", "JTAG", "SlaveSelectMap8", "[UNDEFINED 6]", "SlaveSerial", 0}},
00152 {0x00000800, 11, "INIT_complete", "INIT_COMPLETE", 0,
00153
00154
00155 VALUES{"No", "Yes", 0}},
00156 {0x00001000, 12, "INIT", "INIT", 0,
00157
00158
00159 VALUES{"Deasserted", "Asserted", 0}},
00160 {0x00002000, 13, "DONE_released", "RELEASE_DONE", 0,
00161
00162
00163 VALUES{"DrivenLow", "Released", 0}},
00164 {0x00004000, 14, "DONE", "DONE", 0,
00165
00166
00167 VALUES{"NotDone", "Done", 0}},
00168 {0x00008000, 15, "ID_error", "ID_ERROR", 0,
00169
00170
00171 VALUES{"NoError", "Error", 0}},
00172 {0x00010000, 16, "Decrypt_error", "DEC_ERROR", 0,
00173
00174
00175 VALUES{"NoError", "Error", 0}},
00176
00177
00178
00179
00180 {0, 0, 0, 0, 0, 0}
00181 };
00182
00183
00184 const Bitstream::Subfield Virtex4::sCTL[] = {
00185 {0x00000001, 0, "GTS_USER_B", "GTS_USER_B", 0,
00186
00187
00188 VALUES{"IoDisabled", "IoActive", 0}},
00189 {0x00000008, 3, "Persist", "PERSIST", 0,
00190
00191
00192 VALUES{"No", "Yes", 0}},
00193 {0x00000030, 4, "Security", "SBITS", 0,
00194
00195
00196
00197 VALUES{"None", "Level1", "Level2", "Level2", 0}},
00198 {0x00000100, 8, "GLUTMASK", "GLUTMASK", 0,
00199
00200
00201
00202
00203 VALUES{"Masked", "Dynamic", 0}},
00204 {0x40000000, 30, "ICAP_sel", "ICAP_SEL", 0,
00205
00206
00207 VALUES{"Top", "Bottom", 0}},
00208 {0, 0, 0, 0, 0, 0}
00209 };
00210
00211
00212 const Bitstream::Subfield Virtex4::sMASK[] = {
00213 {0x00000001, 0, "GTS_USER_B", "GTS_USER_B", 0, VALUES{"Protected", "Writable", 0}},
00214 {0x00000008, 3, "Persist", "PERSIST", 0, VALUES{"Protected", "Writable", 0}},
00215 {0x00000080, 4, "Security", "SBITS", 0,
00216 VALUES{"Protected", "[UNKNOWN 1]", "[UNKNOWN 2]", "Writable", 0}},
00217 {0x00000100, 8, "GLUTMASK", "GLUTMASK", 0, VALUES{"Protected", "Writable", 0}},
00218 {0x40000000, 30, "ICAP_sel", "ICAP_SEL", 0, VALUES{"Protected", "Writable", 0}},
00219 {0, 0, 0, 0, 0, 0}
00220 };
00221
00222
00223 uint32_t Virtex4::makeSubfield(ERegister inRegister, const std::string& inSubfield,
00224 const std::string& inSetting) {
00225 const Subfield* subfields;
00226 switch(inRegister) {
00227 case eRegisterCOR: subfields = sCOR; break;
00228 case eRegisterSTAT: subfields = sSTAT; break;
00229 case eRegisterCTL: subfields = sCTL; break;
00230 case eRegisterMASK: subfields = sMASK; break;
00231 default: return 0;
00232 }
00233 for(uint32_t field = 0; subfields[field].mMask != 0; field++) {
00234 const Subfield& subfield = subfields[field];
00235 if(inSubfield != subfield.mBitgenName && inSubfield != subfield.mConfigGuideName)
00236 continue;
00237 const char** ptr = subfield.mValues;
00238 for(uint32_t i = 0; *ptr != 0; i++, ptr++) {
00239 if(inSetting == *ptr) return (i << subfield.mShift) & subfield.mMask;
00240 }
00241 }
00242 return 0;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 #ifndef GENERATE_STATIC_DEVICE_INFO
00258
00259 extern DeviceInfo xc4vfx12;
00260 extern DeviceInfo xc4vfx20;
00261 extern DeviceInfo xc4vfx40;
00262 extern DeviceInfo xc4vfx60;
00263 extern DeviceInfo xc4vfx100;
00264 extern DeviceInfo xc4vfx140;
00265 extern DeviceInfo xc4vlx15;
00266 extern DeviceInfo xc4vlx25;
00267 extern DeviceInfo xc4vlx40;
00268 extern DeviceInfo xc4vlx60;
00269 extern DeviceInfo xc4vlx80;
00270 extern DeviceInfo xc4vlx100;
00271 extern DeviceInfo xc4vlx160;
00272 extern DeviceInfo xc4vlx200;
00273 extern DeviceInfo xc4vsx25;
00274 extern DeviceInfo xc4vsx35;
00275 extern DeviceInfo xc4vsx55;
00276
00277 void Virtex4::initializeDeviceInfo(const std::string& inDeviceName) {
00278 using namespace torc::common;
00279 switch(mDevice) {
00280 if(false) ;
00281 case eXC4VFX12: setDeviceInfo(xc4vfx12); break;
00282 case eXC4VFX20: setDeviceInfo(xc4vfx20); break;
00283 case eXC4VFX40: setDeviceInfo(xc4vfx40); break;
00284 case eXC4VFX60: setDeviceInfo(xc4vfx60); break;
00285 case eXC4VFX100: setDeviceInfo(xc4vfx100); break;
00286 case eXC4VFX140: setDeviceInfo(xc4vfx140); break;
00287 case eXC4VLX15: setDeviceInfo(xc4vlx15); break;
00288 case eXC4VLX25: setDeviceInfo(xc4vlx25); break;
00289 case eXC4VLX40: setDeviceInfo(xc4vlx40); break;
00290 case eXC4VLX60: setDeviceInfo(xc4vlx60); break;
00291 case eXC4VLX80: setDeviceInfo(xc4vlx80); break;
00292 case eXC4VLX100: setDeviceInfo(xc4vlx100); break;
00293 case eXC4VLX160: setDeviceInfo(xc4vlx160); break;
00294 case eXC4VLX200: setDeviceInfo(xc4vlx200); break;
00295 case eXC4VSX25: setDeviceInfo(xc4vsx25); break;
00296 case eXC4VSX35: setDeviceInfo(xc4vsx35); break;
00297 case eXC4VSX55: setDeviceInfo(xc4vsx55); break;
00298 default: break;
00299 }
00300 }
00301
00302 #else
00303
00304 void Virtex4::initializeDeviceInfo(const std::string& inDeviceName) {
00305
00306 typedef torc::architecture::xilinx::TileCount TileCount;
00307 typedef torc::architecture::xilinx::TileRow TileRow;
00308 typedef torc::architecture::xilinx::TileCol TileCol;
00309 typedef torc::architecture::xilinx::TileTypeIndex TileTypeIndex;
00310 typedef torc::architecture::xilinx::TileTypeCount TileTypeCount;
00311
00312
00313 torc::architecture::DDB ddb(inDeviceName);
00314 const torc::architecture::Tiles& tiles = ddb.getTiles();
00315 uint32_t tileCount = tiles.getTileCount();
00316 uint16_t rowCount = tiles.getRowCount();
00317 uint16_t colCount = tiles.getColCount();
00318 ColumnTypeVector columnTypes;
00319
00320
00321 typedef std::map<TileTypeIndex, std::string> TileTypeIndexToName;
00322 typedef std::map<std::string, TileTypeIndex> TileTypeNameToIndex;
00323 TileTypeIndexToName tileTypeIndexToName;
00324 TileTypeNameToIndex tileTypeNameToIndex;
00325 TileTypeCount tileTypeCount = tiles.getTileTypeCount();
00326 for(TileTypeIndex tileTypeIndex(0); tileTypeIndex < tileTypeCount; tileTypeIndex++) {
00327 const std::string tileTypeName = tiles.getTileTypeName(tileTypeIndex);
00328 tileTypeIndexToName[tileTypeIndex] = tileTypeName;
00329 tileTypeNameToIndex[tileTypeName] = tileTypeIndex;
00330 TileTypeNameToColumnType::iterator ttwp = mTileTypeNameToColumnType.find(tileTypeName);
00331 TileTypeNameToColumnType::iterator ttwe = mTileTypeNameToColumnType.end();
00332 if(ttwp != ttwe) mTileTypeIndexToColumnType[tileTypeIndex] = EColumnType(ttwp->second);
00333 }
00334
00335
00336 columnTypes.resize(colCount);
00337 uint32_t frameCount = 0;
00338 for(uint32_t blockType = 0; blockType < eFarBlockTypeCount; blockType++) {
00339 for(TileCol col; col < colCount; col++) {
00340 columnTypes[col] = eColumnTypeEmpty;
00341 TileTypeIndexToColumnType::iterator ttwe = mTileTypeIndexToColumnType.end();
00342 TileTypeIndexToColumnType::iterator ttwp = ttwe;
00343 for(TileRow row; row < rowCount; row++) {
00344
00345 const torc::architecture::TileInfo& tileInfo
00346 = tiles.getTileInfo(tiles.getTileIndex(row, col));
00347 TileTypeIndex tileTypeIndex = tileInfo.getTypeIndex();
00348
00349 ttwp = mTileTypeIndexToColumnType.find(tileTypeIndex);
00350 if(ttwp != ttwe) {
00351 uint32_t width = mColumnDefs[ttwp->second][blockType];
00352 frameCount += width;
00353
00354
00355 columnTypes[col] = static_cast<EColumnType>(ttwp->second);
00356 break;
00357 }
00358 }
00359 }
00360
00361 if(blockType == 2) break;
00362 }
00363
00364 boost::filesystem::path workingPath = torc::common::DirectoryTree::getWorkingPath();
00365 boost::filesystem::path generatedMap = workingPath / (inDeviceName + ".map.csv");
00366 std::fstream tilemapStream(generatedMap.string().c_str(), std::ios::out);
00367 for(TileRow row; row < rowCount; row++) {
00368 for(TileCol col; col < colCount; col++) {
00369 const torc::architecture::TileInfo& tileInfo
00370 = tiles.getTileInfo(tiles.getTileIndex(row, col));
00371 TileTypeIndex tileTypeIndex = tileInfo.getTypeIndex();
00372 tilemapStream << tiles.getTileTypeName(tileTypeIndex);
00373 if(col + 1 < colCount) tilemapStream << ",";
00374 }
00375 tilemapStream << std::endl;
00376 }
00377 tilemapStream.close();
00378
00379
00380 setDeviceInfo(DeviceInfo(tileCount, rowCount, colCount, columnTypes));
00381 }
00382
00383 #endif
00384
00385 void Virtex4::initializeFrameMaps(void) {
00386
00387 bool debug = 0;
00388 uint32_t frameCount = 0;
00389 uint32_t farRowCount = (mDeviceInfo.getRowCount() / 18) >> 1;
00390 uint32_t frameIndex = 0;
00391 for(uint32_t i = 0; i < Virtex4::eFarBlockTypeCount; i++) {
00392 Virtex4::EFarBlockType blockType = Virtex4::EFarBlockType(i);
00393 uint32_t blockFrameIndexBounds = 0;
00394
00395 uint32_t bitIndex = 0;
00396 uint32_t xdlIndex = 0;
00397 mBitColumnIndexes[i].push_back(bitIndex);
00398 mXdlColumnIndexes[i].push_back(xdlIndex);
00399 for(uint32_t half = 0; half < 2; half++) {
00400 for(uint32_t farRow = 0; farRow < farRowCount; farRow++) {
00401
00402 uint32_t farMajor = 0;
00403 typedef torc::common::EncapsulatedInteger<uint16_t> ColumnIndex;
00404 uint16_t finalColumn = mDeviceInfo.getColCount()-1;
00405 uint32_t xdlColumnCount = 0;
00406 uint32_t bitColumnCount = 0;
00407 for(ColumnIndex col; col < mDeviceInfo.getColCount(); col++) {
00408 uint32_t width = mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
00409
00410 for(uint32_t farMinor = 0; farMinor < width; farMinor++) {
00411 Virtex4::FrameAddress far(Virtex4::EFarTopBottom(half), blockType,
00412 farRow, farMajor, farMinor);
00413 mFrameIndexToAddress[frameIndex] = far;
00414 mFrameAddressToIndex[far] = frameIndex;
00415 frameIndex++;
00416 blockFrameIndexBounds++;
00417 }
00418 if(width > 0) farMajor++;
00419 frameCount += width;
00420
00421
00422 if(farRow == 0 && half == 0) {
00423
00424 if(mDeviceInfo.getColumnTypes()[col] != Virtex4::eColumnTypeEmpty) {
00425 mXdlIndexToBitIndex[bitColumnCount] = xdlColumnCount;
00426 bitColumnCount++;
00427 bitIndex += width;
00428 mBitColumnIndexes[i].push_back(bitIndex);
00429 if(col == finalColumn) {
00430 bitIndex += mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
00431 mBitColumnIndexes[i].push_back(bitIndex);
00432 }
00433 }
00434
00435
00436 xdlIndex += width;
00437 mXdlColumnIndexes[i].push_back(xdlIndex);
00438 xdlColumnCount++;
00439 if(col == finalColumn)
00440 {
00441 xdlIndex += mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
00442 mXdlColumnIndexes[i].push_back(xdlIndex);
00443 }
00444 }
00445 }
00446 }
00447 }
00448
00449 mBlockFrameIndexBounds[i] = blockFrameIndexBounds;
00450 if (debug) std::cout << "***Block frame index bounds: " << mBlockFrameIndexBounds[i] << std::endl;
00451 }
00452
00453 if (debug) {
00454 for(uint32_t i = 0; i < Virtex4::eFarBlockTypeCount; i++) {
00455 for(uint32_t j = 0; j < mBitColumnIndexes[i].size(); j++)
00456 std::cout << "Bit Value at index: (" << i << ", " << j << ") : " << mBitColumnIndexes[i][j] << std::endl;
00457 for(uint32_t k = 0; k < mXdlColumnIndexes[i].size(); k++)
00458 std::cout << "Xdl Value at index: (" << i << ", " << k << ") : " << mXdlColumnIndexes[i][k] << std::endl;
00459 }
00460 }
00461 }
00462
00463 void Virtex4::initializeFullFrameBlocks (void) {
00464 boost::shared_array<uint32_t> frameWords;
00465
00466 Virtex4::iterator p = begin();
00467 Virtex4::iterator e = end();
00468 while (p < e) {
00469 const VirtexPacket& packet = *p++;
00470 if (packet.isType2() && packet.isWrite())
00471 frameWords = packet.getWords();
00472 }
00473 uint32_t index = 0;
00474 for (uint32_t i = 0; i < VirtexFrameBlocks::eBlockTypeCount; i++) {
00475
00476 for (uint32_t j = 0; j < mBlockFrameIndexBounds[i]; j++) {
00477 mFrameBlocks.mBlock[i].push_back(VirtexFrameSet::FrameSharedPtr
00478 (new VirtexFrame(getFrameLength(), &frameWords[index])));
00479 index += getFrameLength();
00480 }
00481 }
00482 }
00483
00484 VirtexFrameBlocks Virtex4::getBitstreamFrames (uint32_t blockCount, uint32_t bitCol) {
00485
00486
00487 int32_t bitColumnIndex [blockCount];
00488 int32_t bitColumnBound [blockCount];
00489
00490 for (uint32_t i = 0; i < blockCount; i++) {
00491
00492 bitColumnIndex[i] = mBitColumnIndexes[i][bitCol];
00493
00494 bitColumnBound[i] = mColumnDefs[mDeviceInfo.getColumnTypes()
00495 [mXdlIndexToBitIndex[bitCol]]][i];
00496 }
00497
00498 VirtexFrameBlocks frameBlocks;
00499 for (uint32_t i = 0; i < blockCount; i++) {
00500 int startIndex = bitColumnIndex[i];
00501 for (int j = 0; j < bitColumnBound[i]; j++)
00502 frameBlocks.mBlock[i].push_back(mFrameBlocks.mBlock[i][startIndex+j]);
00503 }
00504 return frameBlocks;
00505 }
00506
00507 VirtexFrameBlocks Virtex4::getXdlFrames (uint32_t blockCount, uint32_t xdlCol) {
00508
00509
00510 int32_t xdlColumnIndex [blockCount];
00511 int32_t xdlColumnBound [blockCount];
00512 for (uint32_t i = 0; i < blockCount; i++) {
00513
00514 xdlColumnIndex[i] = mXdlColumnIndexes[i][xdlCol];
00515
00516 xdlColumnBound[i] = mColumnDefs[mDeviceInfo.getColumnTypes()[xdlCol]][i];
00517 }
00518
00519 VirtexFrameBlocks frameBlocks;
00520 for (uint32_t i = 0; i < blockCount; i++) {
00521 int startIndex = xdlColumnIndex[i];
00522 for (int j = 0; j < xdlColumnBound[i]; j++)
00523 frameBlocks.mBlock[i].push_back(mFrameBlocks.mBlock[i][startIndex+j]);
00524 }
00525 return frameBlocks;
00526 }
00527
00528 }
00529 }