mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:17:35 +00:00
Kernel: Detect devices when enumerating the PCI bus
Instead of making each driver to enumerate the PCI bus itself, PCI::Initializer will call detect_devices() to do one enumeration of the bus.
This commit is contained in:
parent
60715695b2
commit
583e9ad372
10 changed files with 64 additions and 50 deletions
|
@ -77,6 +77,11 @@ void PCI::Access::enumerate_slot(int type, u8 bus, u8 slot, Function<void(Addres
|
|||
}
|
||||
}
|
||||
|
||||
PCI::ID PCI::Access::get_id(Address address)
|
||||
{
|
||||
return { read16_field(address, PCI_VENDOR_ID), read16_field(address, PCI_DEVICE_ID) };
|
||||
}
|
||||
|
||||
void PCI::Access::enumerate_bus(int type, u8 bus, Function<void(Address, ID)>& callback)
|
||||
{
|
||||
for (u8 slot = 0; slot < 32; ++slot)
|
||||
|
@ -105,6 +110,11 @@ void enumerate_all(Function<void(Address, ID)> callback)
|
|||
PCI::Access::the().enumerate_all(callback);
|
||||
}
|
||||
|
||||
ID get_id(Address address)
|
||||
{
|
||||
return PCI::Access::the().get_id(address);
|
||||
}
|
||||
|
||||
u8 get_interrupt_line(Address address)
|
||||
{
|
||||
return PCI::Access::the().get_interrupt_line(address);
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
space_size = (~space_size) + 1;
|
||||
return space_size;
|
||||
}
|
||||
|
||||
virtual ID get_id(Address address) final;
|
||||
virtual u8 get_revision_id(Address address) { return read8_field(address, PCI_REVISION_ID); }
|
||||
virtual u8 get_subclass(Address address) { return read8_field(address, PCI_SUBCLASS); }
|
||||
virtual u8 get_class(Address address) { return read8_field(address, PCI_CLASS); }
|
||||
|
|
|
@ -74,6 +74,10 @@ struct ID {
|
|||
{
|
||||
return vendor_id == other.vendor_id && device_id == other.device_id;
|
||||
}
|
||||
bool operator!=(const ID& other) const
|
||||
{
|
||||
return vendor_id != other.vendor_id || device_id != other.device_id;
|
||||
}
|
||||
};
|
||||
|
||||
struct Address {
|
||||
|
@ -156,6 +160,7 @@ struct ChangeableAddress : public Address {
|
|||
}
|
||||
};
|
||||
|
||||
ID get_id(PCI::Address);
|
||||
void enumerate_all(Function<void(Address, ID)> callback);
|
||||
u8 get_interrupt_line(Address);
|
||||
u32 get_BAR0(Address);
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <Kernel/ACPI/ACPIParser.h>
|
||||
#include <Kernel/IO.h>
|
||||
#include <Kernel/KParams.h>
|
||||
#include <Kernel/Net/E1000NetworkAdapter.h>
|
||||
#include <Kernel/Net/RTL8139NetworkAdapter.h>
|
||||
#include <Kernel/PCI/IOAccess.h>
|
||||
#include <Kernel/PCI/Initializer.h>
|
||||
#include <Kernel/PCI/MMIOAccess.h>
|
||||
|
@ -43,11 +45,29 @@ PCI::Initializer& PCI::Initializer::the()
|
|||
void PCI::Initializer::initialize_pci_mmio_access(ACPI_RAW::MCFG& mcfg)
|
||||
{
|
||||
PCI::MMIOAccess::initialize(mcfg);
|
||||
detect_devices();
|
||||
}
|
||||
void PCI::Initializer::initialize_pci_io_access()
|
||||
{
|
||||
PCI::IOAccess::initialize();
|
||||
detect_devices();
|
||||
}
|
||||
|
||||
void PCI::Initializer::detect_devices()
|
||||
{
|
||||
PCI::enumerate_all([&](const PCI::Address& address, PCI::ID id) {
|
||||
kprintf("PCI: device @ %w:%b:%b.%d [%w:%w]\n",
|
||||
address.seg(),
|
||||
address.bus(),
|
||||
address.slot(),
|
||||
address.function(),
|
||||
id.vendor_id,
|
||||
id.device_id);
|
||||
E1000NetworkAdapter::detect(address);
|
||||
RTL8139NetworkAdapter::detect(address);
|
||||
});
|
||||
}
|
||||
|
||||
void PCI::Initializer::test_and_initialize(bool disable_pci_mmio)
|
||||
{
|
||||
if (disable_pci_mmio) {
|
||||
|
@ -129,4 +149,4 @@ void PCI::Initializer::dismiss()
|
|||
|
||||
PCI::Initializer::~Initializer()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,10 +39,11 @@ public:
|
|||
static void dismiss();
|
||||
|
||||
private:
|
||||
void detect_devices();
|
||||
~Initializer();
|
||||
Initializer();
|
||||
bool test_acpi();
|
||||
bool test_pci_io();
|
||||
bool test_pci_mmio();
|
||||
void initialize_pci_mmio_access_after_test();
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue