mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:12:45 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									a411a44fda
								
							
						
					
					
						commit
						9d9d57056e
					
				
					 13 changed files with 27 additions and 30 deletions
				
			
		|  | @ -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); } | 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); } | 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); |     Access::the().fast_enumerate(callback); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ u32 read32(Address address, u32 field); | ||||||
| 
 | 
 | ||||||
| HardwareID get_hardware_id(PCI::Address); | HardwareID get_hardware_id(PCI::Address); | ||||||
| bool is_io_space_enabled(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 enable_interrupt_line(Address); | ||||||
| void disable_interrupt_line(Address); | void disable_interrupt_line(Address); | ||||||
| void raw_access(Address, u32, size_t, u32); | void raw_access(Address, u32, size_t, u32); | ||||||
|  |  | ||||||
|  | @ -425,12 +425,12 @@ UNMAP_AFTER_INIT void Access::enumerate_bus(int type, u8 bus, bool recursive) | ||||||
|         enumerate_device(type, bus, device, 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); |     MutexLocker locker(m_scan_lock); | ||||||
|     VERIFY(!m_device_identifiers.is_empty()); |     VERIFY(!m_device_identifiers.is_empty()); | ||||||
|     for (auto& device_identifier : m_device_identifiers) { |     for (auto& device_identifier : m_device_identifiers) { | ||||||
|         callback(device_identifier.address(), device_identifier); |         callback(device_identifier); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -25,7 +25,7 @@ public: | ||||||
|     static bool initialize_for_memory_access(PhysicalAddress mcfg_table); |     static bool initialize_for_memory_access(PhysicalAddress mcfg_table); | ||||||
|     static bool initialize_for_io_access(); |     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(); |     void rescan_hardware(); | ||||||
| 
 | 
 | ||||||
|     static Access& the(); |     static Access& the(); | ||||||
|  |  | ||||||
|  | @ -56,8 +56,8 @@ UNMAP_AFTER_INIT void initialize() | ||||||
| 
 | 
 | ||||||
|     PCI::PCIBusSysFSDirectory::initialize(); |     PCI::PCIBusSysFSDirectory::initialize(); | ||||||
| 
 | 
 | ||||||
|     PCI::enumerate([&](const Address& address, DeviceIdentifier const& device_identifier) { |     PCI::enumerate([&](DeviceIdentifier const& device_identifier) { | ||||||
|         dmesgln("{} {}", address, device_identifier.hardware_id()); |         dmesgln("{} {}", device_identifier.address(), device_identifier.hardware_id()); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -41,8 +41,8 @@ UNMAP_AFTER_INIT void PCIBusSysFSDirectory::initialize() | ||||||
| UNMAP_AFTER_INIT PCIBusSysFSDirectory::PCIBusSysFSDirectory() | UNMAP_AFTER_INIT PCIBusSysFSDirectory::PCIBusSysFSDirectory() | ||||||
|     : SysFSDirectory("pci", SysFSComponentRegistry::the().buses_directory()) |     : SysFSDirectory("pci", SysFSComponentRegistry::the().buses_directory()) | ||||||
| { | { | ||||||
|     PCI::enumerate([&](const Address& address, DeviceIdentifier const&) { |     PCI::enumerate([&](DeviceIdentifier const& device_identifier) { | ||||||
|         auto pci_device = PCI::PCIDeviceSysFSDirectory::create(*this, address); |         auto pci_device = PCI::PCIDeviceSysFSDirectory::create(*this, device_identifier.address()); | ||||||
|         m_components.append(pci_device); |         m_components.append(pci_device); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -27,7 +27,7 @@ UNMAP_AFTER_INIT void USBManagement::enumerate_controllers() | ||||||
|     if (kernel_command_line().disable_usb()) |     if (kernel_command_line().disable_usb()) | ||||||
|         return; |         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)) |         if (!(device_identifier.class_code().value() == 0xc && device_identifier.subclass_code().value() == 0x3)) | ||||||
|             return; |             return; | ||||||
|         if (device_identifier.prog_if().value() == 0x0) { |         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) { |         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; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (device_identifier.prog_if().value() == 0x20) { |         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; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (device_identifier.prog_if().value() == 0x30) { |         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; |             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()); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ UNMAP_AFTER_INIT void detect() | ||||||
| { | { | ||||||
|     if (kernel_command_line().disable_virtio()) |     if (kernel_command_line().disable_virtio()) | ||||||
|         return; |         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()) |         if (device_identifier.hardware_id().is_null()) | ||||||
|             return; |             return; | ||||||
|         // TODO: We should also be checking that the device_id is in between 0x1000 - 0x107F inclusive
 |         // TODO: We should also be checking that the device_id is in between 0x1000 - 0x107F inclusive
 | ||||||
|  |  | ||||||
|  | @ -15,15 +15,12 @@ static SerialDevice* s_the = nullptr; | ||||||
| UNMAP_AFTER_INIT void PCISerialDevice::detect() | UNMAP_AFTER_INIT void PCISerialDevice::detect() | ||||||
| { | { | ||||||
|     size_t current_device_minor = 68; |     size_t current_device_minor = 68; | ||||||
|     PCI::enumerate([&](const PCI::Address& address, PCI::DeviceIdentifier const& device_identifier) { |     PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) { | ||||||
|         if (address.is_null()) |  | ||||||
|             return; |  | ||||||
| 
 |  | ||||||
|         for (auto& board_definition : board_definitions) { |         for (auto& board_definition : board_definitions) { | ||||||
|             if (board_definition.device_id != device_identifier.hardware_id()) |             if (board_definition.device_id != device_identifier.hardware_id()) | ||||||
|                 continue; |                 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); |             auto port_base = IOAddress(bar_base + board_definition.first_offset); | ||||||
|             for (size_t i = 0; i < board_definition.port_count; i++) { |             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++); |                 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
 |                 // 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; |             return; | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  | @ -614,12 +614,12 @@ private: | ||||||
|     virtual KResult try_generate(KBufferBuilder& builder) override |     virtual KResult try_generate(KBufferBuilder& builder) override | ||||||
|     { |     { | ||||||
|         JsonArraySerializer array { builder }; |         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(); |             auto obj = array.add_object(); | ||||||
|             obj.add("domain", address.domain()); |             obj.add("domain", device_identifier.address().domain()); | ||||||
|             obj.add("bus", address.bus()); |             obj.add("bus", device_identifier.address().bus()); | ||||||
|             obj.add("device", address.device()); |             obj.add("device", device_identifier.address().device()); | ||||||
|             obj.add("function", address.function()); |             obj.add("function", device_identifier.address().function()); | ||||||
|             obj.add("vendor_id", device_identifier.hardware_id().vendor_id); |             obj.add("vendor_id", device_identifier.hardware_id().vendor_id); | ||||||
|             obj.add("device_id", device_identifier.hardware_id().device_id); |             obj.add("device_id", device_identifier.hardware_id().device_id); | ||||||
|             obj.add("revision_id", device_identifier.revision_id().value()); |             obj.add("revision_id", device_identifier.revision_id().value()); | ||||||
|  |  | ||||||
|  | @ -179,7 +179,7 @@ UNMAP_AFTER_INIT bool GraphicsManagement::initialize() | ||||||
|         dbgln("Forcing no initialization of framebuffer devices"); |         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
 |         // 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
 |         // upon creation. Later on, if we don't want to have framebuffer devices, a
 | ||||||
|         // framebuffer console will take the control instead.
 |         // framebuffer console will take the control instead.
 | ||||||
|  |  | ||||||
|  | @ -91,7 +91,7 @@ UNMAP_AFTER_INIT RefPtr<NetworkAdapter> NetworkingManagement::determine_network_ | ||||||
| bool NetworkingManagement::initialize() | bool NetworkingManagement::initialize() | ||||||
| { | { | ||||||
|     if (!kernel_command_line().is_physical_networking_disabled()) { |     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
 |             // Note: PCI class 2 is the class of Network devices
 | ||||||
|             if (device_identifier.class_code().value() != 0x02) |             if (device_identifier.class_code().value() != 0x02) | ||||||
|                 return; |                 return; | ||||||
|  |  | ||||||
|  | @ -44,13 +44,13 @@ UNMAP_AFTER_INIT void StorageManagement::enumerate_controllers(bool force_pio) | ||||||
|     VERIFY(m_controllers.is_empty()); |     VERIFY(m_controllers.is_empty()); | ||||||
|     if (!kernel_command_line().disable_physical_storage()) { |     if (!kernel_command_line().disable_physical_storage()) { | ||||||
|         if (kernel_command_line().is_ide_enabled()) { |         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) { |                 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)); |                     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) { |             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)); |                 m_controllers.append(AHCIController::initialize(device_identifier)); | ||||||
|             } |             } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Liav A
						Liav A