From 81965b139d171744e1a0d7a8e9aeace74c8a6103 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Tue, 1 Aug 2017 16:57:04 +0200 Subject: added function pci_enable_bus_mastering to enable DMA transfers on the PCI bus adapted interface of pci_device_get_driver to also take a pointer to the PCI controller the PCI descriptor of a device also contains bus, device and function now --- src/hardware/pci.c | 20 +++++++++++++++++--- src/hardware/pci.h | 7 ++++++- 2 files changed, 23 insertions(+), 4 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 ); +} diff --git a/src/hardware/pci.h b/src/hardware/pci.h index 9bc29bb..ccfd20f 100644 --- a/src/hardware/pci.h +++ b/src/hardware/pci.h @@ -8,6 +8,9 @@ #include "driver.h" typedef struct { + uint16_t bus; + uint16_t device; + uint16_t function; uint16_t vendor_id; uint16_t device_id; uint8_t class_id; @@ -45,6 +48,8 @@ void pci_device_descriptor_init( pci_device_descriptor_t *descriptor, pci_contro void pci_base_address_register_init( pci_base_address_register_t *base_address_register, pci_controller_t *controller, uint16_t bus, uint16_t device, uint16_t function, uint16_t bar ); -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 ); + +void pci_enable_bus_mastering( pci_controller_t *controller, pci_device_descriptor_t *descriptor ); #endif // PCI_H -- cgit v1.2.3-54-g00ecf