summaryrefslogtreecommitdiff
path: root/src/hardware/pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hardware/pci.c')
-rw-r--r--src/hardware/pci.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/hardware/pci.c b/src/hardware/pci.c
index 6b622c1..30eca6f 100644
--- a/src/hardware/pci.c
+++ b/src/hardware/pci.c
@@ -14,6 +14,7 @@
#define PCI_VENDOR_ID 0x00
#define PCI_DEVICE_ID 0x02
+#define PCI_COMMAND 0x04
#define PCI_REVISION 0x08
#define PCI_INTERFACE 0x09
#define PCI_SUBCLASS 0x0A
@@ -22,6 +23,9 @@
#define PCI_BAR_BASE 0x10
#define PCI_INTERRUPT 0x3C
+// commands for PCI_COMMAND register
+#define PCI_COMMAND_ENABLE_BUS_MASTERING 0x0004
+
void pci_controller_init( pci_controller_t *controller )
{
memset( controller, 0, sizeof( pci_controller_t ) );
@@ -116,7 +120,7 @@ void pci_controller_scan_and_register( pci_controller_t *controller, driver_mana
}
}
- driver_t *driver = pci_device_get_driver( &device_descriptor, interrupt, context );
+ driver_t *driver = pci_device_get_driver( controller, &device_descriptor, interrupt, context );
if( driver ) {
driver_manager_add_driver( driver_manager, driver );
}
@@ -129,6 +133,9 @@ void pci_device_descriptor_init( pci_device_descriptor_t *descriptor, pci_contro
{
memset( descriptor, 0, sizeof( pci_device_descriptor_t ) );
+ descriptor->bus = bus;
+ descriptor->device = device;
+ descriptor->function = function;
descriptor->vendor_id = pci_controller_read( controller, bus, device, function, PCI_VENDOR_ID );
descriptor->device_id = pci_controller_read( controller, bus, device, function, PCI_DEVICE_ID );
descriptor->class_id = pci_controller_read( controller, bus, device, function, PCI_CLASS );
@@ -171,7 +178,7 @@ void pci_base_address_register_init( pci_base_address_register_t *base_address_r
}
}
-driver_t *pci_device_get_driver( pci_device_descriptor_t *descriptor, interrupt_t *interrupt, void *context )
+driver_t *pci_device_get_driver( pci_controller_t *pci, pci_device_descriptor_t *descriptor, interrupt_t *interrupt, void *context )
{
driver_t *driver = NULL;
@@ -181,7 +188,7 @@ driver_t *pci_device_get_driver( pci_device_descriptor_t *descriptor, interrupt_
switch( descriptor->device_id ) {
case 0x8139: // RTL8139
driver = (driver_t *)malloc( sizeof( rtl8139_t ) );
- rtl8139_init( (rtl8139_t *)driver, descriptor, interrupt, context );
+ rtl8139_init( (rtl8139_t *)driver, pci, descriptor, interrupt, context );
break;
}
break;
@@ -210,3 +217,10 @@ driver_t *pci_device_get_driver( pci_device_descriptor_t *descriptor, interrupt_
return driver;
}
+
+void pci_enable_bus_mastering( pci_controller_t *controller, pci_device_descriptor_t *descriptor )
+{
+ uint16_t val = pci_controller_read( controller, descriptor->bus, descriptor->device, descriptor->function, PCI_COMMAND );
+ val |= PCI_COMMAND_ENABLE_BUS_MASTERING;
+ pci_controller_write( controller, descriptor->bus, descriptor->device, descriptor->function, PCI_COMMAND, val );
+}