Kernel/PCI: Remove Address from enumeration callback

If we need that address, we can always get it from the DeviceIdentifier.
This commit is contained in:
Liav A 2021-09-23 11:05:00 +03:00 committed by Andreas Kling
parent a411a44fda
commit 9d9d57056e
Notes: sideshowbarker 2024-07-18 03:21:06 +09:00
13 changed files with 27 additions and 30 deletions

View file

@ -17,7 +17,7 @@ u8 read8(Address address, u32 field) { return Access::the().read8_field(address,
u16 read16(Address address, u32 field) { return Access::the().read16_field(address, field); }
u32 read32(Address address, u32 field) { return Access::the().read32_field(address, field); }
void enumerate(Function<void(Address, DeviceIdentifier const&)> callback)
void enumerate(Function<void(DeviceIdentifier const&)> callback)
{
Access::the().fast_enumerate(callback);
}

View file

@ -19,7 +19,7 @@ u32 read32(Address address, u32 field);
HardwareID get_hardware_id(PCI::Address);
bool is_io_space_enabled(Address);
void enumerate(Function<void(Address, DeviceIdentifier const&)> callback);
void enumerate(Function<void(DeviceIdentifier const&)> callback);
void enable_interrupt_line(Address);
void disable_interrupt_line(Address);
void raw_access(Address, u32, size_t, u32);

View file

@ -425,12 +425,12 @@ UNMAP_AFTER_INIT void Access::enumerate_bus(int type, u8 bus, bool recursive)
enumerate_device(type, bus, device, recursive);
}
void Access::fast_enumerate(Function<void(Address, DeviceIdentifier const&)>& callback) const
void Access::fast_enumerate(Function<void(DeviceIdentifier const&)>& callback) const
{
MutexLocker locker(m_scan_lock);
VERIFY(!m_device_identifiers.is_empty());
for (auto& device_identifier : m_device_identifiers) {
callback(device_identifier.address(), device_identifier);
callback(device_identifier);
}
}

View file

@ -25,7 +25,7 @@ public:
static bool initialize_for_memory_access(PhysicalAddress mcfg_table);
static bool initialize_for_io_access();
void fast_enumerate(Function<void(Address, DeviceIdentifier const&)>&) const;
void fast_enumerate(Function<void(DeviceIdentifier const&)>&) const;
void rescan_hardware();
static Access& the();

View file

@ -56,8 +56,8 @@ UNMAP_AFTER_INIT void initialize()
PCI::PCIBusSysFSDirectory::initialize();
PCI::enumerate([&](const Address& address, DeviceIdentifier const& device_identifier) {
dmesgln("{} {}", address, device_identifier.hardware_id());
PCI::enumerate([&](DeviceIdentifier const& device_identifier) {
dmesgln("{} {}", device_identifier.address(), device_identifier.hardware_id());
});
}

View file

@ -41,8 +41,8 @@ UNMAP_AFTER_INIT void PCIBusSysFSDirectory::initialize()
UNMAP_AFTER_INIT PCIBusSysFSDirectory::PCIBusSysFSDirectory()
: SysFSDirectory("pci", SysFSComponentRegistry::the().buses_directory())
{
PCI::enumerate([&](const Address& address, DeviceIdentifier const&) {
auto pci_device = PCI::PCIDeviceSysFSDirectory::create(*this, address);
PCI::enumerate([&](DeviceIdentifier const& device_identifier) {
auto pci_device = PCI::PCIDeviceSysFSDirectory::create(*this, device_identifier.address());
m_components.append(pci_device);
});
}

View file

@ -27,7 +27,7 @@ UNMAP_AFTER_INIT void USBManagement::enumerate_controllers()
if (kernel_command_line().disable_usb())
return;
PCI::enumerate([this](PCI::Address const& address, PCI::DeviceIdentifier const& device_identifier) {
PCI::enumerate([this](PCI::DeviceIdentifier const& device_identifier) {
if (!(device_identifier.class_code().value() == 0xc && device_identifier.subclass_code().value() == 0x3))
return;
if (device_identifier.prog_if().value() == 0x0) {
@ -41,21 +41,21 @@ UNMAP_AFTER_INIT void USBManagement::enumerate_controllers()
}
if (device_identifier.prog_if().value() == 0x10) {
dmesgln("USBManagement: OHCI controller found at {} is not currently supported.", address);
dmesgln("USBManagement: OHCI controller found at {} is not currently supported.", device_identifier.address());
return;
}
if (device_identifier.prog_if().value() == 0x20) {
dmesgln("USBManagement: EHCI controller found at {} is not currently supported.", address);
dmesgln("USBManagement: EHCI controller found at {} is not currently supported.", device_identifier.address());
return;
}
if (device_identifier.prog_if().value() == 0x30) {
dmesgln("USBManagement: xHCI controller found at {} is not currently supported.", address);
dmesgln("USBManagement: xHCI controller found at {} is not currently supported.", device_identifier.address());
return;
}
dmesgln("USBManagement: Unknown/unsupported controller at {} with programming interface 0x{:02x}", address, device_identifier.prog_if().value());
dmesgln("USBManagement: Unknown/unsupported controller at {} with programming interface 0x{:02x}", device_identifier.address(), device_identifier.prog_if().value());
});
}

View file

@ -18,7 +18,7 @@ UNMAP_AFTER_INIT void detect()
{
if (kernel_command_line().disable_virtio())
return;
PCI::enumerate([&](const PCI::Address&, PCI::DeviceIdentifier const& device_identifier) {
PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) {
if (device_identifier.hardware_id().is_null())
return;
// TODO: We should also be checking that the device_id is in between 0x1000 - 0x107F inclusive

View file

@ -15,15 +15,12 @@ static SerialDevice* s_the = nullptr;
UNMAP_AFTER_INIT void PCISerialDevice::detect()
{
size_t current_device_minor = 68;
PCI::enumerate([&](const PCI::Address& address, PCI::DeviceIdentifier const& device_identifier) {
if (address.is_null())
return;
PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) {
for (auto& board_definition : board_definitions) {
if (board_definition.device_id != device_identifier.hardware_id())
continue;
auto bar_base = PCI::get_BAR(address, board_definition.pci_bar) & ~1;
auto bar_base = PCI::get_BAR(device_identifier.address(), board_definition.pci_bar) & ~1;
auto port_base = IOAddress(bar_base + board_definition.first_offset);
for (size_t i = 0; i < board_definition.port_count; i++) {
auto serial_device = new SerialDevice(port_base.offset(board_definition.port_size * i), current_device_minor++);
@ -36,7 +33,7 @@ UNMAP_AFTER_INIT void PCISerialDevice::detect()
// NOTE: We intentionally leak the reference to serial_device here, as it is eternal
}
dmesgln("PCISerialDevice: Found {} @ {}", board_definition.name, address);
dmesgln("PCISerialDevice: Found {} @ {}", board_definition.name, device_identifier.address());
return;
}
});

View file

@ -614,12 +614,12 @@ private:
virtual KResult try_generate(KBufferBuilder& builder) override
{
JsonArraySerializer array { builder };
PCI::enumerate([&array](PCI::Address address, PCI::DeviceIdentifier const& device_identifier) {
PCI::enumerate([&array](PCI::DeviceIdentifier const& device_identifier) {
auto obj = array.add_object();
obj.add("domain", address.domain());
obj.add("bus", address.bus());
obj.add("device", address.device());
obj.add("function", address.function());
obj.add("domain", device_identifier.address().domain());
obj.add("bus", device_identifier.address().bus());
obj.add("device", device_identifier.address().device());
obj.add("function", device_identifier.address().function());
obj.add("vendor_id", device_identifier.hardware_id().vendor_id);
obj.add("device_id", device_identifier.hardware_id().device_id);
obj.add("revision_id", device_identifier.revision_id().value());

View file

@ -179,7 +179,7 @@ UNMAP_AFTER_INIT bool GraphicsManagement::initialize()
dbgln("Forcing no initialization of framebuffer devices");
}
PCI::enumerate([&](const PCI::Address&, PCI::DeviceIdentifier const& device_identifier) {
PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) {
// Note: Each graphics controller will try to set its native screen resolution
// upon creation. Later on, if we don't want to have framebuffer devices, a
// framebuffer console will take the control instead.

View file

@ -91,7 +91,7 @@ UNMAP_AFTER_INIT RefPtr<NetworkAdapter> NetworkingManagement::determine_network_
bool NetworkingManagement::initialize()
{
if (!kernel_command_line().is_physical_networking_disabled()) {
PCI::enumerate([&](const PCI::Address&, PCI::DeviceIdentifier const& device_identifier) {
PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) {
// Note: PCI class 2 is the class of Network devices
if (device_identifier.class_code().value() != 0x02)
return;

View file

@ -44,13 +44,13 @@ UNMAP_AFTER_INIT void StorageManagement::enumerate_controllers(bool force_pio)
VERIFY(m_controllers.is_empty());
if (!kernel_command_line().disable_physical_storage()) {
if (kernel_command_line().is_ide_enabled()) {
PCI::enumerate([&](const PCI::Address&, PCI::DeviceIdentifier const& device_identifier) {
PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) {
if (device_identifier.class_code().value() == PCI_MASS_STORAGE_CLASS_ID && device_identifier.subclass_code().value() == PCI_IDE_CTRL_SUBCLASS_ID) {
m_controllers.append(IDEController::initialize(device_identifier, force_pio));
}
});
}
PCI::enumerate([&](const PCI::Address&, PCI::DeviceIdentifier const& device_identifier) {
PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) {
if (device_identifier.class_code().value() == PCI_MASS_STORAGE_CLASS_ID && device_identifier.subclass_code().value() == PCI_SATA_CTRL_SUBCLASS_ID && device_identifier.prog_if().value() == PCI_AHCI_IF_PROGIF) {
m_controllers.append(AHCIController::initialize(device_identifier));
}