summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hardware/pci.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/hardware/pci.c b/src/hardware/pci.c
index bba0182..f544d98 100644
--- a/src/hardware/pci.c
+++ b/src/hardware/pci.c
@@ -65,12 +65,24 @@ void pci_controller_write( pci_controller_t *controller, uint16_t bus, uint16_t
port32_write( &controller->data_port, data );
}
+static int get_nof_functions( pci_controller_t *controller, uint16_t bus, uint16_t device )
+{
+ uint8_t data = pci_controller_read( controller, bus, device, 0, PCI_HEADER_TYPE );
+
+ if( data & 0x80 ) {
+ return NOF_FUNCTIONS_PER_DEVICE;
+ } else {
+ return 1;
+ }
+}
+
void pci_controller_scan_and_register( pci_controller_t *controller, driver_manager_t *driver_manager, interrupt_t *interrupt, void *context )
{
for( int bus = 0; bus < NOF_BUSES; bus++ ) {
for( int device = 0; device < NOF_DEVICES_PER_BUS; device++ ) {
- // TODO: detect single/multi function device from header
- for( int function = 0; function < NOF_FUNCTIONS_PER_DEVICE; function++ ) {
+ int nof_functions = get_nof_functions( controller, bus, device );
+
+ for( int function = 0; function < nof_functions; function++ ) {
pci_device_descriptor_t device_descriptor;
pci_device_descriptor_init( &device_descriptor, controller, bus, device, function );