From dc9d1b4b1f3e8cf61a451f2d9475d61bf42a242a Mon Sep 17 00:00:00 2001 From: Janik Schlemminger Date: Tue, 15 Jul 2014 14:35:13 +0200 Subject: [PATCH] address decoder simplified --- .../resources/configs/amconfigs/am_wideio.xml | 4 +- dram/src/common/xmlAddressdecoder.cpp | 120 +++--------------- dram/src/common/xmlAddressdecoder.h | 43 ++----- dram/src/simulation/Arbiter.h | 5 +- 4 files changed, 33 insertions(+), 139 deletions(-) diff --git a/dram/resources/configs/amconfigs/am_wideio.xml b/dram/resources/configs/amconfigs/am_wideio.xml index 24eb2a9d..fc29d918 100755 --- a/dram/resources/configs/amconfigs/am_wideio.xml +++ b/dram/resources/configs/amconfigs/am_wideio.xml @@ -11,10 +11,10 @@ --> - + - + diff --git a/dram/src/common/xmlAddressdecoder.cpp b/dram/src/common/xmlAddressdecoder.cpp index dbacde12..1c19a64d 100644 --- a/dram/src/common/xmlAddressdecoder.cpp +++ b/dram/src/common/xmlAddressdecoder.cpp @@ -9,113 +9,31 @@ string xmlAddressDecoder::addressConfigURI = ""; xmlAddressDecoder::xmlAddressDecoder(string addressConfigURI) { - doc = new XMLDocument(); - loadXML(addressConfigURI,*doc); - addressmap = doc->FirstChildElement("dramconfig")->FirstChildElement("addressmap"); - int from; - int to; + tinyxml2::XMLDocument doc; - // get channel: - // TiXmlElement* channel = addressmap->FirstChildElement("channel"); - // - // - // from = getAttribute(channel, "from"); - // to = getAttribute(channel, "to"); - // - // channelShift = from; - // channelMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - // channelSize = pow(2.0, to - from + 1.0); + loadXML(addressConfigURI, doc); + tinyxml2::XMLElement* addressmap = doc.FirstChildElement("dramconfig")->FirstChildElement("addressmap"); - // get row: - XMLElement* row = addressmap->FirstChildElement("row"); - row->QueryIntAttribute("from",&from); - row->QueryIntAttribute("to",&to); + for(XMLElement* child = addressmap->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) + { + int from; + int to; - rowShift = from; - rowMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - rowSize = pow(2.0, to - from + 1.0); - - // get bank: - XMLElement* bank = addressmap->FirstChildElement("bank"); - - bank->QueryIntAttribute("from",&from); - bank->QueryIntAttribute("to",&to); - - bankShift = from; - bankMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - bankSize = pow(2.0, to - from + 1.0); - - // get colum: - XMLElement* colum = addressmap->FirstChildElement("colum"); - - colum->QueryIntAttribute("from",&from); - colum->QueryIntAttribute("to",&to); - - columShift = from; - columMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - columSize = pow(2.0, to - from + 1.0); - - // get bytes: - // TiXmlElement* bytes = addressmap->FirstChildElement("bytes"); - // - // from = getAttribute(bytes, "from"); - // to = getAttribute(bytes, "to"); - - // bytesShift = from; - // bytesMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - // bytesSize = pow(2.0, to - from + 1.0); + child->QueryAttribute("from", &from); + child->QueryAttribute("to", &to); + shifts[child->Name()] = from; + masks[child->Name()] = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); + } } -xmlAddressDecoder::~xmlAddressDecoder() +DecodedAddress xmlAddressDecoder::decodeAddress(sc_dt::uint64 addr) { - delete doc; -} - -void xmlAddressDecoder::getNode(unsigned int addr, node * n) -{ - n->channel = 0; - n->row = (addr & rowMask) >> rowShift; - n->bank = (addr & bankMask) >> bankShift; - n->colum = (addr & columMask) >> columShift; -} - -void xmlAddressDecoder::getBRC(unsigned int addr, unsigned int &bank, unsigned int &row, - unsigned int &colum) -{ - row = (addr & rowMask) >> rowShift; - bank = (addr & bankMask) >> bankShift; - colum = (addr & columMask) >> columShift; -} - -void xmlAddressDecoder::getCBRC(unsigned int addr, unsigned int &channel, unsigned int &bank, - unsigned int &row, unsigned int &colum) -{ - channel = (addr & channelMask) >> channelShift; - getBRC(addr, bank, row, colum); -} -void xmlAddressDecoder::getC(unsigned int addr, unsigned int &channel) -{ - channel = (addr & channelMask) >> channelShift; -} - -unsigned int xmlAddressDecoder::getNumberOfBanks() -{ - return bankSize; -} - -unsigned int xmlAddressDecoder::getNumberOfRowsPerBank() -{ - return rowSize; -} - -unsigned int xmlAddressDecoder::getNumberOfColumsPerRow() -{ - return columSize; -} - -unsigned int xmlAddressDecoder::getNumberOfBytesPerColumn() -{ - return 1; + DecodedAddress n; + n.channel = 0; + n.row = (addr & masks["row"]) >> shifts["row"]; + n.bank = (addr & masks["bank"]) >> shifts["bank"]; + n.column = (addr & masks["column"]) >> shifts["column"]; + return n; } diff --git a/dram/src/common/xmlAddressdecoder.h b/dram/src/common/xmlAddressdecoder.h index f6fa9e2a..3cd3d6fe 100755 --- a/dram/src/common/xmlAddressdecoder.h +++ b/dram/src/common/xmlAddressdecoder.h @@ -18,17 +18,20 @@ #include #include #include +#include #include "third_party/tinyxml2.h" -struct node +struct DecodedAddress { + DecodedAddress():channel(0),rank(0),bankgroup(0),row(0),bank(0),column(0),bytes(0){} unsigned int channel; + unsigned int rank; + unsigned int bankgroup; unsigned int row; unsigned int bank; - unsigned int colum; - tlm::tlm_command command; - tlm::tlm_phase phase; + unsigned int column; + unsigned int bytes; }; class xmlAddressDecoder @@ -43,39 +46,13 @@ public: return decoder; } - void getNode(unsigned int addr, node * n); - void getBRC(unsigned int addr, unsigned int &bank, unsigned int &row, unsigned int &colum); - void getCBRC(unsigned int addr, unsigned int &channel, unsigned int &bank, unsigned int &row, unsigned int &colum); - void getC(unsigned int addr, unsigned int &channel); - unsigned int getNumberOfBanks(); - unsigned int getNumberOfRowsPerBank(); - unsigned int getNumberOfColumsPerRow(); - unsigned int getNumberOfBytesPerColumn(); + DecodedAddress decodeAddress(sc_dt::uint64 addr); private: xmlAddressDecoder(std::string URI); - ~xmlAddressDecoder(); - unsigned int channelMask; - unsigned int rowMask; - unsigned int bankMask; - unsigned int columMask; - unsigned int bytesMask; - - unsigned int channelShift; - unsigned int rowShift; - unsigned int bankShift; - unsigned int columShift; - unsigned int bytesShift; - - unsigned int channelSize; - unsigned int bankSize; - unsigned int rowSize; - unsigned int columSize; - unsigned int bytesSize; - - tinyxml2::XMLDocument * doc; - tinyxml2::XMLElement* addressmap; + std::map masks; + std::map shifts; }; #endif diff --git a/dram/src/simulation/Arbiter.h b/dram/src/simulation/Arbiter.h index 813845cd..fb0d66c8 100644 --- a/dram/src/simulation/Arbiter.h +++ b/dram/src/simulation/Arbiter.h @@ -135,10 +135,9 @@ private: void appendDramExtension(int socketId, tlm_generic_payload& payload) { unsigned int burstlength = payload.get_streaming_width(); - node n; - xmlAddressDecoder::getInstance().getNode(static_cast(payload.get_address()), &n); + DecodedAddress n = xmlAddressDecoder::getInstance().decodeAddress(payload.get_address()); Bank bank(n.bank); - DramExtension* extension = new DramExtension(Thread(socketId+1), Channel(n.channel), bank, bank.getBankGroup(), Row(n.row), Column(n.colum),burstlength); + DramExtension* extension = new DramExtension(Thread(socketId+1), Channel(n.channel), bank, bank.getBankGroup(), Row(n.row), Column(n.column),burstlength); payload.set_auto_extension(extension); } };