diff --git a/src/libdramsys/DRAMSys/common/dramExtensions.h b/src/libdramsys/DRAMSys/common/dramExtensions.h index 7a8a80c1..b920747b 100644 --- a/src/libdramsys/DRAMSys/common/dramExtensions.h +++ b/src/libdramsys/DRAMSys/common/dramExtensions.h @@ -288,4 +288,18 @@ public: static bool notifyChildTransCompletion(tlm::tlm_generic_payload& trans); }; +class EccExtension : public tlm::tlm_extension +{ +public: + tlm_extension_base* clone() const override + { + return new EccExtension; + } + + void copy_from(tlm_extension_base const &ext) override + { + auto const &cpyFrom = static_cast(ext); + } +}; + #endif // DRAMEXTENSIONS_H diff --git a/src/libdramsys/DRAMSys/controller/Controller.cpp b/src/libdramsys/DRAMSys/controller/Controller.cpp index a1262417..09a5a414 100644 --- a/src/libdramsys/DRAMSys/controller/Controller.cpp +++ b/src/libdramsys/DRAMSys/controller/Controller.cpp @@ -515,7 +515,10 @@ void Controller::manageResponses() tlm_generic_payload* nextTransInRespQueue = respQueue->nextPayload(); if (nextTransInRespQueue != nullptr) { - numberOfBeatsServed += ControllerExtension::getBurstLength(*nextTransInRespQueue); + // Ignore ECC requests + if (nextTransInRespQueue->get_extension() == nullptr) + numberOfBeatsServed += ControllerExtension::getBurstLength(*nextTransInRespQueue); + if (ChildExtension::isChildTrans(*nextTransInRespQueue)) { tlm_generic_payload& parentTrans = ChildExtension::getParentTrans(*nextTransInRespQueue); diff --git a/src/libdramsys/DRAMSys/simulation/AddressDecoder.cpp b/src/libdramsys/DRAMSys/simulation/AddressDecoder.cpp index 2ec633de..7b3de3b2 100644 --- a/src/libdramsys/DRAMSys/simulation/AddressDecoder.cpp +++ b/src/libdramsys/DRAMSys/simulation/AddressDecoder.cpp @@ -37,13 +37,14 @@ */ #include "AddressDecoder.h" +#include "DRAMSys/configuration/Configuration.h" #include #include #include #include -AddressDecoder::AddressDecoder(const Configuration& config, const DRAMSys::Config::AddressMapping& addressMapping) +AddressDecoder::AddressDecoder(const DRAMSys::Config::AddressMapping &addressMapping, const MemSpec &memSpec) { if (const auto &channelBits = addressMapping.CONGEN.CHANNEL_BIT) { @@ -113,8 +114,6 @@ AddressDecoder::AddressDecoder(const Configuration& config, const DRAMSys::Confi SC_REPORT_FATAL("AddressDecoder", "Not all address bits occur exactly once"); } - const MemSpec& memSpec = *config.memSpec; - unsigned highestByteBit = *std::max_element(vByteBits.begin(), vByteBits.end()); for (unsigned bitPosition = 0; bitPosition <= highestByteBit; bitPosition++) @@ -213,6 +212,41 @@ unsigned AddressDecoder::decodeChannel(uint64_t encAddr) const return channel; } +uint64_t AddressDecoder::encodeAddress(DecodedAddress decodedAddress) const +{ + // Convert absoulte addressing for bank, bankgroup to relative + decodedAddress.bankgroup = decodedAddress.bankgroup % bankgroupsPerRank; + decodedAddress.bank = decodedAddress.bank % banksPerGroup; + + uint64_t address = 0; + + for (unsigned i = 0; i < vChannelBits.size(); i++) + address |= ((decodedAddress.channel >> i) & 0x1) << vChannelBits[i]; + + for (unsigned i = 0; i < vRankBits.size(); i++) + address |= ((decodedAddress.rank >> i) & 0x1) << vRankBits[i]; + + for (unsigned i = 0; i < vBankGroupBits.size(); i++) + address |= ((decodedAddress.bankgroup >> i) & 0x1) << vBankGroupBits[i]; + + for (unsigned i = 0; i < vBankBits.size(); i++) + address |= ((decodedAddress.bank >> i) & 0x1) << vBankBits[i]; + + for (unsigned i = 0; i < vRowBits.size(); i++) + address |= ((decodedAddress.row >> i) & 0x1) << vRowBits[i]; + + for (unsigned i = 0; i < vColumnBits.size(); i++) + address |= ((decodedAddress.column >> i) & 0x1) << vColumnBits[i]; + + for (unsigned i = 0; i < vByteBits.size(); i++) + address |= ((decodedAddress.byte >> i) & 0x1) << vByteBits[i]; + + // TODO: XOR encoding + + return address; +} + + void AddressDecoder::print() const { std::cout << headline << std::endl; diff --git a/src/libdramsys/DRAMSys/simulation/AddressDecoder.h b/src/libdramsys/DRAMSys/simulation/AddressDecoder.h index 57f2f324..42a9f0d3 100644 --- a/src/libdramsys/DRAMSys/simulation/AddressDecoder.h +++ b/src/libdramsys/DRAMSys/simulation/AddressDecoder.h @@ -39,9 +39,8 @@ #ifndef ADDRESSDECODER_H #define ADDRESSDECODER_H -#include "DRAMSys/configuration/Configuration.h" - #include "DRAMSys/config/DRAMSysConfiguration.h" +#include "DRAMSys/configuration/Configuration.h" #include #include @@ -69,9 +68,10 @@ struct DecodedAddress class AddressDecoder { public: - AddressDecoder(const Configuration& config, const DRAMSys::Config::AddressMapping& addressMapping); + AddressDecoder(const DRAMSys::Config::AddressMapping &addressMapping, const MemSpec &memSpec); [[nodiscard]] DecodedAddress decodeAddress(uint64_t encAddr) const; [[nodiscard]] unsigned decodeChannel(uint64_t encAddr) const; + [[nodiscard]] uint64_t encodeAddress(DecodedAddress decodedAddress) const; void print() const; private: diff --git a/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp b/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp index 6e32e0b5..25e23c70 100644 --- a/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp +++ b/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp @@ -157,7 +157,7 @@ void DRAMSys::setupDebugManager(NDEBUG_UNUSED(const std::string& traceName)) con void DRAMSys::instantiateModules(const ::DRAMSys::Config::AddressMapping& addressMapping) { - addressDecoder = std::make_unique(config, addressMapping); + addressDecoder = std::make_unique(addressMapping, *config.memSpec); addressDecoder->print(); // Create arbiter diff --git a/src/libdramsys/DRAMSys/simulation/DRAMSys.h b/src/libdramsys/DRAMSys/simulation/DRAMSys.h index cec3a6d9..84343589 100644 --- a/src/libdramsys/DRAMSys/simulation/DRAMSys.h +++ b/src/libdramsys/DRAMSys/simulation/DRAMSys.h @@ -70,6 +70,7 @@ public: const ::DRAMSys::Config::Configuration& configLib); const Configuration& getConfig() const; + const AddressDecoder &getAddressDecoder() const { return *addressDecoder; } protected: DRAMSys(const sc_core::sc_module_name& name, diff --git a/src/libdramsys/DRAMSys/simulation/DRAMSysRecordable.cpp b/src/libdramsys/DRAMSys/simulation/DRAMSysRecordable.cpp index 719c8bff..2309b838 100644 --- a/src/libdramsys/DRAMSys/simulation/DRAMSysRecordable.cpp +++ b/src/libdramsys/DRAMSys/simulation/DRAMSysRecordable.cpp @@ -120,7 +120,7 @@ void DRAMSysRecordable::setupTlmRecorders(const std::string& traceName, void DRAMSysRecordable::instantiateModules(const std::string& traceName, const ::DRAMSys::Config::Configuration& configLib) { - addressDecoder = std::make_unique(config, configLib.addressmapping); + addressDecoder = std::make_unique(configLib.addressmapping, *config.memSpec); addressDecoder->print(); // Create and properly initialize TLM recorders. diff --git a/src/simulator/simulator/player/StlPlayer.cpp b/src/simulator/simulator/player/StlPlayer.cpp index 2fbda317..2b29d794 100644 --- a/src/simulator/simulator/player/StlPlayer.cpp +++ b/src/simulator/simulator/player/StlPlayer.cpp @@ -102,7 +102,7 @@ Request StlPlayer::nextRequest() delay -= sc_core::sc_time_stamp(); } - Request request(std::move(*readoutIt)); + Request request(*readoutIt); request.delay = delay; readoutIt++; diff --git a/tests/tests_dramsys/AddressDecoderConfigs.h b/tests/tests_dramsys/AddressDecoderConfigs.h new file mode 100644 index 00000000..671c24ef --- /dev/null +++ b/tests/tests_dramsys/AddressDecoderConfigs.h @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2022, Technische Universität Kaiserslautern + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Derek Christ + */ + +#pragma once + +#include + +inline constexpr std::string_view memSpecJsonString = R"( +{ + "memspec": { + "memarchitecturespec": { + "burstLength": 16, + "dataRate": 8, + "nbrOfBankGroups": 4, + "nbrOfBanks": 16, + "nbrOfColumns": 1024, + "nbrOfRows": 65536, + "nbrOfRanks": 1, + "nbrOfDevices": 1, + "nbrOfChannels": 1, + "width": 16, + "per2BankOffset": 8 + }, + "memoryId": "JEDEC_1Gbx16_BG_LPDDR5-6400", + "memoryType": "LPDDR5", + "memtimingspec": { + "RCD": 15, + "PPD": 2, + "RPab": 17, + "RPpb": 15, + "RAS": 34, + "RCab": 51, + "RCpb": 48, + "FAW": 16, + "RRD": 4, + "RL": 17, + "WCK2CK": 0, + "WCK2DQO": 1, + "RBTP": 4, + "RPRE": 0, + "RPST": 0, + "WL": 9, + "WCK2DQI": 0, + "WPRE": 0, + "WPST": 0, + "WR": 28, + "WTR_L": 10, + "WTR_S": 5, + "CCDMW": 16, + "REFI": 3124, + "REFIpb": 390, + "RFCab": 224, + "RFCpb": 112, + "RTRS": 1, + "BL_n_min_16": 2, + "BL_n_max_16": 4, + "BL_n_L_16": 4, + "BL_n_S_16": 2, + "BL_n_min_32": 6, + "BL_n_max_32": 8, + "BL_n_L_32": 8, + "BL_n_S_32": 2, + "pbR2act": 6, + "pbR2pbR": 72, + "clkMhz": 800 + } + } +} +)"; + +inline constexpr std::string_view addressMappingJsonString = R"( +{ + "CONGEN": { + "BYTE_BIT": [ + 0 + ], + "COLUMN_BIT": [ + 1, + 2, + 3, + 4, + 9, + 10, + 11, + 12, + 13, + 14 + ], + "BANKGROUP_BIT": [ + 5, + 6 + ], + "BANK_BIT": [ + 7, + 8 + ], + "ROW_BIT": [ + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30 + ] + } +} +)"; diff --git a/tests/tests_dramsys/AddressDecoderTests.cpp b/tests/tests_dramsys/AddressDecoderTests.cpp new file mode 100644 index 00000000..fe9dd24b --- /dev/null +++ b/tests/tests_dramsys/AddressDecoderTests.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2022, Technische Universität Kaiserslautern + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Derek Christ + */ + +#include "AddressDecoderConfigs.h" + +#include + +#include +#include + +class AddressDecoderFixture : public ::testing::Test +{ +protected: + AddressDecoderFixture() : + addressMappingJson(nlohmann::json::parse(addressMappingJsonString)), + memSpecJson(nlohmann::json::parse(memSpecJsonString).at("memspec")), + addressMappingConfig(addressMappingJson.get()), + memSpec(memSpecConfig), + memSpecConfig(memSpecJson.get()), + addressDecoder(addressMappingConfig, memSpec) + { + } + + nlohmann::json addressMappingJson; + nlohmann::json memSpecJson; + + // Configs + DRAMSys::Config::AddressMapping addressMappingConfig; + DRAMSys::Config::MemSpec memSpecConfig; + + MemSpecLPDDR5 memSpec; + AddressDecoder addressDecoder; +}; + +TEST_F(AddressDecoderFixture, Decoding) +{ + uint64_t address = 0x3A59'1474; + auto decodedAddress = addressDecoder.decodeAddress(address); + + unsigned int channel = decodedAddress.channel; + unsigned int rank = decodedAddress.rank; + unsigned int bankgroup = decodedAddress.bankgroup; + unsigned int bank = decodedAddress.bank; + unsigned int row = decodedAddress.row; + unsigned int column = decodedAddress.column; + unsigned int byte = decodedAddress.byte; + + EXPECT_EQ(channel, 0); + EXPECT_EQ(rank, 0); + EXPECT_EQ(bankgroup, 3); + EXPECT_EQ(bank, 12); + EXPECT_EQ(row, 29874); + EXPECT_EQ(column, 170); + EXPECT_EQ(byte, 0); +} + +TEST_F(AddressDecoderFixture, Encoding) +{ + unsigned int channel = 0; + unsigned int rank = 0; + unsigned int bankgroup = 3; + unsigned int bank = 12; + unsigned int row = 29874; + unsigned int column = 170; + unsigned int byte = 0; + + DecodedAddress decodedAddress(channel, rank, bankgroup, bank, row, column, byte); + + uint64_t address = addressDecoder.encodeAddress(decodedAddress); + EXPECT_EQ(address, 0x3A59'1474); +} + +TEST_F(AddressDecoderFixture, DeEncoding) +{ + std::array testAddresses{std::uint64_t(0x3A59'1474), + std::uint64_t(0x0000'0000), + std::uint64_t(0x2FFA'1231), + std::uint64_t(0x0001'FFFF)}; + + for (auto address: testAddresses) + { + DecodedAddress decodedAddress = addressDecoder.decodeAddress(address); + uint64_t encodedAddress = addressDecoder.encodeAddress(decodedAddress); + + EXPECT_EQ(encodedAddress, address); + } +} \ No newline at end of file diff --git a/tests/tests_dramsys/Testfile.h b/tests/tests_dramsys/Testfile.h index 74835a7d..e381048b 100644 --- a/tests/tests_dramsys/Testfile.h +++ b/tests/tests_dramsys/Testfile.h @@ -1,42 +1,43 @@ -///* -// * Copyright (c) 2019, Technische Universität Kaiserslautern -// * All rights reserved. -// * -// * Redistribution and use in source and binary forms, with or without -// * modification, are permitted provided that the following conditions are -// * met: -// * -// * 1. Redistributions of source code must retain the above copyright notice, -// * this list of conditions and the following disclaimer. -// * -// * 2. Redistributions in binary form must reproduce the above copyright -// * notice, this list of conditions and the following disclaimer in the -// * documentation and/or other materials provided with the distribution. -// * -// * 3. Neither the name of the copyright holder nor the names of its -// * contributors may be used to endorse or promote products derived from -// * this software without specific prior written permission. -// * -// * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -// * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -// * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER -// * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -// * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// * -// * Authors: -// * Lukas Steiner -// */ -// -//#include -//#include "../library/src/controller/Command.h" -// -//TEST(testsuite, test) -//{ -// EXPECT_EQ(commandToString(Command::ACT), "ACT"); -//} +/* + * Copyright (c) 2019, Technische Universität Kaiserslautern + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Lukas Steiner + */ + +#include + +#include + +TEST(testsuite, test) +{ + EXPECT_EQ(Command(Command::Type::ACT).toString(), "ACT"); +} diff --git a/tests/tests_dramsys/main.cpp b/tests/tests_dramsys/main.cpp index 1c92c82d..42f2dbbe 100644 --- a/tests/tests_dramsys/main.cpp +++ b/tests/tests_dramsys/main.cpp @@ -35,6 +35,7 @@ #include #include +#include "Testfile.h" int sc_main(int argc, char **argv) {