Introduce subdevices interface.

This commit is contained in:
Maxim Poliakovski 2020-03-14 15:39:34 +01:00
parent d53400ebae
commit 14156dd32b
5 changed files with 50 additions and 13 deletions

View File

@ -29,6 +29,7 @@ add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:cpu_ppc>
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:devices>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:loguru>)
add_custom_command(

View File

@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <iostream>
#include "macio.h"
#include "viacuda.h"
#include "machines/machinebase.h"
/** Heathrow Mac I/O device emulation.
@ -36,6 +37,8 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow")
{
this->viacuda = new ViaCuda();
this->nvram = new NVram();
gMachineObj->add_subdevice("ViaCuda", this->viacuda);
}
HeathrowIC::~HeathrowIC()

View File

@ -13,6 +13,7 @@ MachineBase::MachineBase(std::string name)
/* initialize internal maps */
this->comp_map.clear();
this->subdev_map.clear();
this->aliases.clear();
}
@ -22,9 +23,11 @@ MachineBase::~MachineBase()
delete it->second;
}
this->comp_map.clear();
this->aliases.clear();
this->subdev_map.clear();
}
bool MachineBase::add_component(std::string name, HWCompType type, HWComponent *dev_obj)
bool MachineBase::add_component(std::string name, HWComponent *dev_obj)
{
if (this->comp_map.count(name)) {
LOG_F(ERROR, "Component %s already exists!", name.c_str());
@ -36,9 +39,21 @@ bool MachineBase::add_component(std::string name, HWCompType type, HWComponent *
return true;
}
void MachineBase::add_alias(std::string name, std::string alias, HWCompType type)
bool MachineBase::add_subdevice(std::string name, HWComponent *dev_obj)
{
this->aliases[alias] = name;
if (this->subdev_map.count(name)) {
LOG_F(ERROR, "Subdevice %s already exists!", name.c_str());
return false;
}
this->subdev_map[name] = dev_obj;
return true;
}
void MachineBase::add_alias(std::string name, std::string alias)
{
this->aliases[alias] = name;
}
HWComponent *MachineBase::get_comp_by_name(std::string name)
@ -49,6 +64,10 @@ HWComponent *MachineBase::get_comp_by_name(std::string name)
if (this->comp_map.count(name)) {
return this->comp_map[name];
}
if (this->subdev_map.count(name)) {
return this->subdev_map[name];
} else {
return NULL;
}
@ -67,8 +86,21 @@ HWComponent *MachineBase::get_comp_by_type(HWCompType type)
}
}
if (!found)
return NULL;
if (found) {
return this->get_comp_by_name(comp_name);
}
return this->get_comp_by_name(comp_name);
for(auto it = this->subdev_map.begin(); it != this->subdev_map.end(); it++) {
if (it->second->supports_type(type)) {
comp_name = it->first;
found = true;
break;
}
}
if (found) {
return this->get_comp_by_name(comp_name);
} else {
return NULL;
}
}

View File

@ -38,14 +38,16 @@ public:
MachineBase(std::string name);
~MachineBase();
bool add_component(std::string name, HWCompType type, HWComponent *dev_obj);
void add_alias(std::string name, std::string alias, HWCompType type);
bool add_component(std::string name, HWComponent *dev_obj);
bool add_subdevice(std::string name, HWComponent *dev_obj);
void add_alias(std::string name, std::string alias);
HWComponent *get_comp_by_name(std::string name);
HWComponent *get_comp_by_type(HWCompType type);
private:
std::string name;
std::map<std::string, HWComponent *>comp_map;
std::map<std::string, HWComponent *>subdev_map;
std::map<std::string, std::string> aliases;
};

View File

@ -45,20 +45,19 @@ int create_gossamer()
gMachineObj.reset(new MachineBase("Gossamer"));
/* register MPC106 aka Grackle as memory controller and PCI host */
gMachineObj->add_component("Grackle", HWCompType::MEM_CTRL, new MPC106);
gMachineObj->add_alias("Grackle", "PCI_Host", HWCompType::PCI_HOST);
gMachineObj->add_component("Grackle", new MPC106);
gMachineObj->add_alias("Grackle", "PCI_Host");
/* get raw pointer to MPC106 object */
MPC106 *grackle_obj = dynamic_cast<MPC106 *>(gMachineObj->get_comp_by_name("Grackle"));
/* add the machine ID register */
gMachineObj->add_component("MachineID", HWCompType::MMIO_DEV,
new GossamerID(0x3d8c));
gMachineObj->add_component("MachineID", new GossamerID(0x3d8c));
grackle_obj->add_mmio_region(0xFF000004, 4096,
dynamic_cast<MMIODevice *>(gMachineObj->get_comp_by_name("MachineID")));
/* add the Heathrow I/O controller */
gMachineObj->add_component("Heathrow", HWCompType::MMIO_DEV, new HeathrowIC);
gMachineObj->add_component("Heathrow", new HeathrowIC);
grackle_obj->pci_register_device(16,
dynamic_cast<PCIDevice *>(gMachineObj->get_comp_by_name("Heathrow")));