From 4b2f3cedc7c0263f0664ffea32b5952039a09f78 Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Tue, 29 Mar 2022 01:45:00 +0200 Subject: [PATCH] Make NVRAM a full-fledged HW component. --- devices/common/hwcomponent.h | 1 + devices/common/nvram.cpp | 8 +++++++- devices/common/nvram.h | 10 ++++++---- devices/ioctrl/grandcentral.cpp | 4 +++- devices/ioctrl/heathrow.cpp | 1 + 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/devices/common/hwcomponent.h b/devices/common/hwcomponent.h index 4e2c8fd..6543b1b 100644 --- a/devices/common/hwcomponent.h +++ b/devices/common/hwcomponent.h @@ -29,6 +29,7 @@ along with this program. If not, see . enum HWCompType { UNKNOWN = 0ULL, /* unknown component type */ MEM_CTRL = 1ULL << 0, /* memory controller */ + NVRAM = 1ULL << 1, /* non-volatile random access memory */ ROM = 1ULL << 2, /* read-only memory */ RAM = 1ULL << 3, /* random access memory */ MMIO_DEV = 1ULL << 4, /* memory mapped I/O device */ diff --git a/devices/common/nvram.cpp b/devices/common/nvram.cpp index 8a8a5dc..751e733 100644 --- a/devices/common/nvram.cpp +++ b/devices/common/nvram.cpp @@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include #include #include @@ -35,7 +36,12 @@ using namespace std; /** the signature for NVRAM backing file identification. */ static char NVRAM_FILE_ID[] = "DINGUSPPCNVRAM"; -NVram::NVram(std::string file_name, uint32_t ram_size) { +NVram::NVram(std::string file_name, uint32_t ram_size) +{ + this->name = "NVRAM"; + + supports_types(HWCompType::NVRAM); + this->file_name = file_name; this->ram_size = ram_size; diff --git a/devices/common/nvram.h b/devices/common/nvram.h index b78e89d..8f9f60f 100644 --- a/devices/common/nvram.h +++ b/devices/common/nvram.h @@ -22,6 +22,8 @@ along with this program. If not, see . #ifndef NVRAM_H #define NVRAM_H +#include + #include #include @@ -31,7 +33,7 @@ along with this program. If not, see . automatically saved to and restored from the dedicated file. */ -class NVram { +class NVram : public HWComponent { public: NVram(std::string file_name = "nvram.bin", uint32_t ram_size = 8192); ~NVram(); @@ -40,9 +42,9 @@ public: void write_byte(uint32_t offset, uint8_t value); private: - std::string file_name; /* file name for the backing file. */ - uint16_t ram_size; /* NVRAM size. */ - uint8_t* storage; + std::string file_name; // file name for the backing file + uint16_t ram_size; // NVRAM size + uint8_t* storage; void init(); void save(); diff --git a/devices/ioctrl/grandcentral.cpp b/devices/ioctrl/grandcentral.cpp index 3fcf0de..84a44b3 100644 --- a/devices/ioctrl/grandcentral.cpp +++ b/devices/ioctrl/grandcentral.cpp @@ -49,9 +49,11 @@ GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl() // construct subdevices this->mace = std::unique_ptr (new MaceController(MACE_ID)); this->viacuda = std::unique_ptr (new ViaCuda()); - gMachineObj->add_subdevice("ViaCuda", this->viacuda.get()); this->nvram = std::unique_ptr (new NVram()); + gMachineObj->add_subdevice("ViaCuda", this->viacuda.get()); + gMachineObj->add_subdevice("NVRAM", this->nvram.get()); + // initialize sound chip and its DMA output channel, then wire them together this->awacs = std::unique_ptr (new AwacsScreamer()); this->snd_out_dma = std::unique_ptr (new DMAChannel()); diff --git a/devices/ioctrl/heathrow.cpp b/devices/ioctrl/heathrow.cpp index 0ab9e63..58aae8f 100644 --- a/devices/ioctrl/heathrow.cpp +++ b/devices/ioctrl/heathrow.cpp @@ -60,6 +60,7 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl() }; this->nvram = std::unique_ptr (new NVram()); + gMachineObj->add_subdevice("NVRAM", this->nvram.get()); this->viacuda = std::unique_ptr (new ViaCuda()); gMachineObj->add_subdevice("ViaCuda", this->viacuda.get());