From 5c177cc50f250401a315f3bed0930862c4084aa1 Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Wed, 26 Jan 2022 16:45:21 +0100 Subject: [PATCH] Simplify registration of HW component types. --- devices/common/hwcomponent.h | 39 +++++++++++++++++++++--------------- devices/common/machineid.h | 10 ++------- devices/common/viacuda.cpp | 2 ++ devices/common/viacuda.h | 6 +----- devices/ioctrl/amic.cpp | 3 +++ devices/ioctrl/amic.h | 4 ---- devices/ioctrl/heathrow.cpp | 3 +++ devices/ioctrl/macio.h | 5 ----- devices/memctrl/hmc.cpp | 11 +++------- devices/memctrl/hmc.h | 3 --- devices/memctrl/mpc106.cpp | 12 +++-------- devices/memctrl/mpc106.h | 3 --- devices/memctrl/spdram.h | 5 +---- devices/sound/soundserver.h | 9 ++++----- devices/video/atirage.cpp | 3 +++ devices/video/atirage.h | 4 ---- 16 files changed, 48 insertions(+), 74 deletions(-) diff --git a/devices/common/hwcomponent.h b/devices/common/hwcomponent.h index 8688a57..e4c7a35 100644 --- a/devices/common/hwcomponent.h +++ b/devices/common/hwcomponent.h @@ -22,26 +22,26 @@ along with this program. If not, see . #ifndef HW_COMPONENT_H #define HW_COMPONENT_H +#include #include /** types of different HW components */ -enum HWCompType : int { - UNKNOWN = 0, /* unknown component type */ - MEM_CTRL = 10, /* memory controller */ - ROM = 20, /* read-only memory */ - RAM = 30, /* random access memory */ - MMIO_DEV = 40, /* memory mapped I/O device */ - PCI_HOST = 50, /* PCI host */ - PCI_DEV = 51, /* PCI device */ - I2C_HOST = 60, /* I2C host */ - I2C_DEV = 61, /* I2C device */ - ADB_HOST = 70, /* ADB host */ - ADB_DEV = 71, /* ADB device */ - INT_CTRL = 80, /* interrupt controller */ - SND_SERVER = 100, /* host sound server */ +enum HWCompType { + UNKNOWN = 0ULL, /* unknown component type */ + MEM_CTRL = 1ULL << 0, /* memory controller */ + ROM = 1ULL << 2, /* read-only memory */ + RAM = 1ULL << 3, /* random access memory */ + MMIO_DEV = 1ULL << 4, /* memory mapped I/O device */ + PCI_HOST = 1ULL << 5, /* PCI host */ + PCI_DEV = 1ULL << 6, /* PCI device */ + I2C_HOST = 1ULL << 8, /* I2C host */ + I2C_DEV = 1ULL << 9, /* I2C device */ + ADB_HOST = 1ULL << 12, /* ADB host */ + ADB_DEV = 1ULL << 13, /* ADB device */ + INT_CTRL = 1ULL << 16, /* interrupt controller */ + SND_SERVER = 1ULL << 31, /* host sound server */ }; - /** Abstract base class for HW components. */ class HWComponent { public: @@ -55,7 +55,13 @@ public: this->name = name; }; - virtual bool supports_type(HWCompType type) = 0; + virtual bool supports_type(HWCompType type) { + return !!(this->supported_types & type); + }; + + virtual void supports_types(uint64_t types) { + this->supported_types = types; + }; virtual int device_postinit() { return 0; @@ -63,6 +69,7 @@ public: protected: std::string name; + uint64_t supported_types = HWCompType::UNKNOWN; }; #endif /* HW_COMPONENT_H */ diff --git a/devices/common/machineid.h b/devices/common/machineid.h index b7cc648..e51e353 100644 --- a/devices/common/machineid.h +++ b/devices/common/machineid.h @@ -51,13 +51,10 @@ public: this->id[1] = 0x5A; this->id[2] = (id >> 8) & 0xFF; this->id[3] = id & 0xFF; + supports_types(HWCompType::MMIO_DEV); }; ~NubusMacID() = default; - bool supports_type(HWCompType type) { - return type == HWCompType::MMIO_DEV; - }; - uint32_t read(uint32_t reg_start, uint32_t offset, int size) { return (offset < 4 ? this->id[offset] : 0); }; @@ -80,13 +77,10 @@ class GossamerID : public MMIODevice { public: GossamerID(const uint16_t id) { this->id = id, this->name = "Machine-id"; + supports_types(HWCompType::MMIO_DEV); }; ~GossamerID() = default; - bool supports_type(HWCompType type) { - return type == HWCompType::MMIO_DEV; - }; - uint32_t read(uint32_t reg_start, uint32_t offset, int size) { return ((!offset && size == 2) ? this->id : 0); }; diff --git a/devices/common/viacuda.cpp b/devices/common/viacuda.cpp index 1228bb6..f317706 100644 --- a/devices/common/viacuda.cpp +++ b/devices/common/viacuda.cpp @@ -38,6 +38,8 @@ using namespace std; ViaCuda::ViaCuda() { this->name = "ViaCuda"; + supports_types(HWCompType::ADB_HOST | HWCompType::I2C_HOST); + // VIA reset clears all internal registers to logic 0 // except timers/counters and the shift register // as stated in the 6522 datasheet diff --git a/devices/common/viacuda.h b/devices/common/viacuda.h index 8877ab9..6243c92 100644 --- a/devices/common/viacuda.h +++ b/devices/common/viacuda.h @@ -155,10 +155,6 @@ public: ~ViaCuda() = default; // HWComponent methods - bool supports_type(HWCompType type) { - return (type == HWCompType::ADB_HOST || type == HWCompType::I2C_HOST); - }; - int device_postinit(); uint8_t read(int reg); @@ -170,7 +166,7 @@ private: // VIA virtual HW registers uint8_t via_regs[16]; - float via_clk_dur; // one VIA clock duration = 1,27655 µs + float via_clk_dur; // one VIA clock duration = 1,27655 us // VIA internal state uint8_t _via_ifr; diff --git a/devices/ioctrl/amic.cpp b/devices/ioctrl/amic.cpp index 1cf9cab..d998e0e 100644 --- a/devices/ioctrl/amic.cpp +++ b/devices/ioctrl/amic.cpp @@ -27,6 +27,7 @@ along with this program. If not, see . #include #include #include +#include #include #include #include @@ -47,6 +48,8 @@ AMIC::AMIC() : MMIODevice() { this->name = "Apple Memory-mapped I/O Controller"; + supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL); + // register I/O devices this->scsi = std::unique_ptr (new Sc53C94()); this->escc = std::unique_ptr (new EsccController()); diff --git a/devices/ioctrl/amic.h b/devices/ioctrl/amic.h index e64de24..c4eee6f 100644 --- a/devices/ioctrl/amic.h +++ b/devices/ioctrl/amic.h @@ -143,10 +143,6 @@ public: ~AMIC() = default; // HWComponent methods - bool supports_type(HWCompType type) { - return (type == HWCompType::MMIO_DEV) || (type == HWCompType::INT_CTRL); - }; - int device_postinit(); /* MMIODevice methods */ diff --git a/devices/ioctrl/heathrow.cpp b/devices/ioctrl/heathrow.cpp index 0234c8c..460dcff 100644 --- a/devices/ioctrl/heathrow.cpp +++ b/devices/ioctrl/heathrow.cpp @@ -21,6 +21,7 @@ along with this program. If not, see . #include #include +#include #include #include #include @@ -43,6 +44,8 @@ along with this program. If not, see . using namespace std; HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") { + supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL); + this->nvram = std::unique_ptr (new NVram()); this->viacuda = std::unique_ptr (new ViaCuda()); diff --git a/devices/ioctrl/macio.h b/devices/ioctrl/macio.h index 91200f5..fcbbcc3 100644 --- a/devices/ioctrl/macio.h +++ b/devices/ioctrl/macio.h @@ -52,7 +52,6 @@ along with this program. If not, see . #define MACIO_H #include -#include #include #include #include @@ -98,10 +97,6 @@ public: HeathrowIC(); ~HeathrowIC() = default; - bool supports_type(HWCompType type) { - return (type == HWCompType::MMIO_DEV) || (type == HWCompType::INT_CTRL); - }; - /* PCI device methods */ bool supports_io_space(void) { return false; diff --git a/devices/memctrl/hmc.cpp b/devices/memctrl/hmc.cpp index 6cbcd3c..3909c0f 100644 --- a/devices/memctrl/hmc.cpp +++ b/devices/memctrl/hmc.cpp @@ -24,12 +24,15 @@ along with this program. If not, see . Author: Max Poliakovski */ +#include #include HMC::HMC() : MemCtrlBase() { this->name = "Highspeed Memory Controller"; + supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV); + /* add memory mapped I/O region for the HMC control register */ add_mmio_region(0x50F40000, 0x10000, this); @@ -37,14 +40,6 @@ HMC::HMC() : MemCtrlBase() this->bit_pos = 0; } -bool HMC::supports_type(HWCompType type) { - if (type == HWCompType::MEM_CTRL || type == HWCompType::MMIO_DEV) { - return true; - } else { - return false; - } -} - uint32_t HMC::read(uint32_t reg_start, uint32_t offset, int size) { if (!offset) diff --git a/devices/memctrl/hmc.h b/devices/memctrl/hmc.h index 46b9ce4..19a632f 100644 --- a/devices/memctrl/hmc.h +++ b/devices/memctrl/hmc.h @@ -31,7 +31,6 @@ along with this program. If not, see . #ifndef HMC_H #define HMC_H -#include #include #include @@ -46,8 +45,6 @@ public: HMC(); ~HMC() = default; - bool supports_type(HWCompType type); - /* MMIODevice methods */ uint32_t read(uint32_t reg_start, uint32_t offset, int size); void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size); diff --git a/devices/memctrl/mpc106.cpp b/devices/memctrl/mpc106.cpp index 0a42633..773ac8b 100644 --- a/devices/memctrl/mpc106.cpp +++ b/devices/memctrl/mpc106.cpp @@ -39,6 +39,9 @@ along with this program. If not, see . MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle PCI host bridge") { this->name = "Grackle"; + supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV | + HWCompType::PCI_HOST | HWCompType::PCI_DEV); + /* add PCI/ISA I/O space, 64K for now */ add_mmio_region(0xFE000000, 0x10000, this); @@ -53,15 +56,6 @@ MPC106::~MPC106() { this->pci_0_bus.clear(); } -bool MPC106::supports_type(HWCompType type) { - if (type == HWCompType::MEM_CTRL || type == HWCompType::MMIO_DEV || - type == HWCompType::PCI_HOST || type == HWCompType::PCI_DEV) { - return true; - } else { - return false; - } -} - uint32_t MPC106::read(uint32_t reg_start, uint32_t offset, int size) { uint32_t result; diff --git a/devices/memctrl/mpc106.h b/devices/memctrl/mpc106.h index 8b1e5bc..0aa494a 100644 --- a/devices/memctrl/mpc106.h +++ b/devices/memctrl/mpc106.h @@ -35,7 +35,6 @@ along with this program. If not, see . #ifndef MPC106_H_ #define MPC106_H_ -#include #include #include #include @@ -50,8 +49,6 @@ public: MPC106(); ~MPC106(); - bool supports_type(HWCompType type); - uint32_t read(uint32_t reg_start, uint32_t offset, int size); void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size); diff --git a/devices/memctrl/spdram.h b/devices/memctrl/spdram.h index 2459ad1..e874f42 100644 --- a/devices/memctrl/spdram.h +++ b/devices/memctrl/spdram.h @@ -63,14 +63,11 @@ public: SpdSdram168(uint8_t addr) { this->dev_addr = addr; this->pos = 0; + supports_types(HWCompType::RAM); }; ~SpdSdram168() = default; - bool supports_type(HWCompType type) { - return type == HWCompType::RAM; - }; - void set_capacity(int capacity_megs) { switch (capacity_megs) { case 32: diff --git a/devices/sound/soundserver.h b/devices/sound/soundserver.h index 9d1ef51..c7ead0b 100644 --- a/devices/sound/soundserver.h +++ b/devices/sound/soundserver.h @@ -46,7 +46,10 @@ enum { class SoundServer : public HWComponent { public: - SoundServer() { this->start(); }; + SoundServer() { + supports_types(HWCompType::SND_SERVER); + this->start(); + }; ~SoundServer() { this->shutdown(); }; int start(); @@ -55,10 +58,6 @@ public: int start_out_stream(); void close_out_stream(); - bool supports_type(HWCompType type) { - return type == HWCompType::SND_SERVER; - }; - private: int status; /* server status */ cubeb *cubeb_ctx; diff --git a/devices/video/atirage.cpp b/devices/video/atirage.cpp index b3953a0..bf53094 100644 --- a/devices/video/atirage.cpp +++ b/devices/video/atirage.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 #include @@ -92,6 +93,8 @@ ATIRage::ATIRage(uint16_t dev_id, uint32_t vmem_size_mb) { uint8_t asic_id; + supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV); + this->vram_size = vmem_size_mb << 20; // convert MBs to bytes /* allocate video RAM */ diff --git a/devices/video/atirage.h b/devices/video/atirage.h index 605950c..382f618 100644 --- a/devices/video/atirage.h +++ b/devices/video/atirage.h @@ -203,10 +203,6 @@ public: uint32_t read(uint32_t reg_start, uint32_t offset, int size); void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size); - bool supports_type(HWCompType type) { - return type == HWCompType::MMIO_DEV; - }; - /* PCI device methods */ bool supports_io_space(void) { return true;