From fa6f305ca2a01d5aac554c899005b26ea367f285 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 20 Jul 2017 11:02:28 +0200 Subject: detecting single or multi function devices in PCI scan --- src/hardware/pci.c | 16 ++++++++++++++-- 1 file 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 ); -- cgit v1.2.3-54-g00ecf