pcihost: add attach_pci_device method.

This commit is contained in:
Maxim Poliakovski 2022-08-19 18:55:33 +02:00
parent f4c0499078
commit 56c54e4c8c
2 changed files with 52 additions and 1 deletions

View File

@ -1,7 +1,30 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <devices/common/hwcomponent.h>
#include <devices/common/pci/pcidevice.h> #include <devices/common/pci/pcidevice.h>
#include <devices/common/pci/pcihost.h> #include <devices/common/pci/pcihost.h>
#include <devices/memctrl/memctrlbase.h> #include <devices/memctrl/memctrlbase.h>
#include <machines/machinebase.h> #include <machines/machinebase.h>
#include <loguru.hpp>
#include <cinttypes> #include <cinttypes>
@ -29,3 +52,26 @@ bool PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDe
// FIXME: add sanity checks! // FIXME: add sanity checks!
return mem_ctrl->add_mmio_region(start_addr, size, obj); return mem_ctrl->add_mmio_region(start_addr, size, obj);
} }
void PCIHost::attach_pci_device(std::string& dev_name, int slot_id)
{
if (!DeviceRegistry::device_registered(dev_name)) {
LOG_F(WARNING, "PCIHost: specified PCI device %s doesn't exist", dev_name.c_str());
return;
}
// attempt to create device object
auto dev_obj = DeviceRegistry::get_descriptor(dev_name).m_create_func();
if (!dev_obj->supports_type(HWCompType::PCI_DEV)) {
LOG_F(WARNING, "PCIHost: cannot attach non-PCI device %s", dev_name.c_str());
return;
}
// add device to the machine object
gMachineObj->add_device(dev_name, std::move(dev_obj));
// register device with the PCI host
this->pci_register_device(
slot_id, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name(dev_name)));
}

View File

@ -1,6 +1,6 @@
/* /*
DingusPPC - The Experimental PowerPC Macintosh emulator DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium (theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info) (Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@ -22,7 +22,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef PCI_HOST_H #ifndef PCI_HOST_H
#define PCI_HOST_H #define PCI_HOST_H
#include <devices/deviceregistry.h>
#include <cinttypes> #include <cinttypes>
#include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
@ -40,6 +43,8 @@ public:
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj); virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
virtual void attach_pci_device(std::string& dev_name, int slot_id);
protected: protected:
std::unordered_map<int, PCIDevice*> dev_map; std::unordered_map<int, PCIDevice*> dev_map;
std::vector<PCIDevice*> io_space_devs; std::vector<PCIDevice*> io_space_devs;