summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-07-20 11:02:28 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-07-20 11:02:28 +0200
commitfa6f305ca2a01d5aac554c899005b26ea367f285 (patch)
tree9ef890515d074f81294355afe24bbc029cf71536 /src
parent949836a663eb652702fee79fd44b9c3f6863f920 (diff)
downloadabaos-fa6f305ca2a01d5aac554c899005b26ea367f285.tar.gz
abaos-fa6f305ca2a01d5aac554c899005b26ea367f285.tar.bz2
detecting single or multi function devices in PCI scan
Diffstat (limited to 'src')
-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 );