diff --git a/src/arch/i386/core/pci_io.c b/src/arch/i386/core/pci_io.c index a272b447..2f3a9ac0 100644 --- a/src/arch/i386/core/pci_io.c +++ b/src/arch/i386/core/pci_io.c @@ -21,8 +21,9 @@ /* Macros for direct PCI access */ #define CONFIG_ADDRESS 0xcf8 #define CONFIG_DATA 0xcfc -#define CONFIG_CMD( pci, where ) \ - ( 0x80000000 | (pci->busdevfn << 8) | (where & ~3) ) +#define CONFIG_CMD( pci, where ) \ + ( 0x80000000 | ( pci->bus << 16 ) | ( pci->devfn << 8 ) | \ + ( where & ~3 ) ) /* Signatures for PCI BIOS */ #define BIOS_SIG(a,b,c,d) ( ( a<<0 ) + ( b<<8 ) + ( c<<16 ) + ( d<<24 ) ) @@ -343,8 +344,9 @@ INIT_FN ( INIT_PCIBIOS, find_pcibios32, NULL, NULL ); "=S" ( discard_S ), "=D" ( discard_D ) \ : "a" ( ( PCIBIOS_PCI_FUNCTION_ID << 8 ) \ + command ), \ - "b" ( pci->busdevfn ), "c" ( value ), \ - "D" ( where ), "S" ( pcibios32_entry ) \ + "b" ( ( pci->bus << 8 ) | pci->devfn ), \ + "c" ( value ), "D" ( where ), \ + "S" ( pcibios32_entry ) \ : "edx", "ebp" ); \ \ ( ret >> 8 ); \ diff --git a/src/arch/i386/prefix/select_pci.c b/src/arch/i386/prefix/select_pci.c deleted file mode 100644 index 691b461c..00000000 --- a/src/arch/i386/prefix/select_pci.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "dev.h" -#include -#include "registers.h" - -/* - * Register a device as the default PCI boot device. This code is - * called by the PCI ROM prefix. - * - * Do not move this code to drivers/bus/pci.c, because it is - * i386-specific, and don't merge it with select_isapnp.c, because - * that would cause linker symbol pollution. - * - */ -void i386_select_pci_device ( struct i386_all_regs *ix86 ) { - /* - * PCI BIOS passes busdevfn in %ax - * - */ - union { - struct bus_loc bus_loc; - struct pci_loc pci_loc; - } u; - - /* Select PCI bus and specified busdevfn as first boot device */ - memset ( &u, 0, sizeof ( u ) ); - u.pci_loc.busdevfn = ix86->regs.ax; - select_device ( &dev, &pci_driver, &u.bus_loc ); -} diff --git a/src/core/btext.c b/src/core/btext.c index 2a2972e9..1ab5405d 100644 --- a/src/core/btext.c +++ b/src/core/btext.c @@ -408,7 +408,7 @@ static void btext_init(void) #warning "pci_find_device_x no longer exists; use find_pci_device instead" /* pci_find_device_x(0x1002, 0x4752, 0, &dev); */ - if(dev.vendor_id==0) return; // no fb + if(dev.vendor==0) return; // no fb frame_buffer = (uint32_t)dev.membase; #else diff --git a/src/drivers/bus/pci.c b/src/drivers/bus/pci.c index 6352e56b..853dda64 100644 --- a/src/drivers/bus/pci.c +++ b/src/drivers/bus/pci.c @@ -1,367 +1,339 @@ -#include "stdint.h" -#include "string.h" -#include "console.h" -#include "nic.h" +/* + * Copyright (C) 2006 Michael Brown . + * + * Based in part on pci.c from Etherboot 5.4, by Ken Yap and David + * Munro, in turn based on the Linux kernel's PCI implementation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include +#include +#include #include -/* - * pci_io.c may know how many buses we have, in which case it can - * overwrite this value. +/** @file + * + * PCI bus + * + */ + +static struct pci_driver pci_drivers[0] __table_start ( pci_drivers ); +static struct pci_driver pci_drivers_end[0] __table_end ( pci_drivers ); + +static void pcibus_remove ( struct root_device *rootdev ); + +/** + * Maximum PCI bus number + * + * Architecture-specific code may know how many buses we have, in + * which case it can overwrite this value. * */ unsigned int pci_max_bus = 0xff; -/* - * Increment a bus_loc structure to the next possible PCI location. - * Leave the structure zeroed and return 0 if there are no more valid - * locations. +/** + * Read PCI BAR * + * @v pci PCI device + * @v reg PCI register number + * @ret bar Base address register + * + * Reads the specified PCI base address register, including the flags + * portion. 64-bit BARs will be handled automatically. If the value + * of the 64-bit BAR exceeds the size of an unsigned long (i.e. if the + * high dword is non-zero on a 32-bit platform), then the value + * returned will be zero plus the flags for a 64-bit BAR. Unreachable + * 64-bit BARs are therefore returned as uninitialised 64-bit BARs. */ -static int pci_next_location ( struct bus_loc *bus_loc ) { - struct pci_loc *pci_loc = ( struct pci_loc * ) bus_loc; - - /* - * Ensure that there is sufficient space in the shared bus - * structures for a struct pci_loc and a struct - * pci_dev, as mandated by bus.h. - * - */ - BUS_LOC_CHECK ( struct pci_loc ); - BUS_DEV_CHECK ( struct pci_device ); +static unsigned long pci_bar ( struct pci_device *pci, unsigned int reg ) { + uint32_t low; + uint32_t high; - return ( ++pci_loc->busdevfn ); -} - -/* - * Fill in parameters (vendor & device ids, class, membase etc.) for a - * PCI device based on bus & devfn. - * - * Returns 1 if a device was found, 0 for no device present. - * - */ -static int pci_fill_device ( struct bus_dev *bus_dev, - struct bus_loc *bus_loc ) { - struct pci_loc *pci_loc = ( struct pci_loc * ) bus_loc; - struct pci_device *pci = ( struct pci_device * ) bus_dev; - uint16_t busdevfn = pci_loc->busdevfn; - static struct { - uint16_t busdevfn0; - int is_present; - } cache = { 0, 1 }; - uint32_t l; - int reg; - - /* Store busdevfn in struct pci_device and set default values */ - pci->busdevfn = busdevfn; - pci->name = "?"; - - /* Check bus is within range */ - if ( PCI_BUS ( busdevfn ) > pci_max_bus ) { - return 0; - } - - /* Check to see if we've cached the result that this is a - * non-zero function on a non-existent card. This is done to - * increase scan speed by a factor of 8. - */ - if ( ( PCI_FUNC ( busdevfn ) != 0 ) && - ( PCI_FN0 ( busdevfn ) == cache.busdevfn0 ) && - ( ! cache.is_present ) ) { - return 0; - } - - /* Check to see if there's anything physically present. - */ - pci_read_config_dword ( pci, PCI_VENDOR_ID, &l ); - /* some broken boards return 0 if a slot is empty: */ - if ( ( l == 0xffffffff ) || ( l == 0x00000000 ) ) { - if ( PCI_FUNC ( busdevfn ) == 0 ) { - /* Don't look for subsequent functions if the - * card itself is not present. - */ - cache.busdevfn0 = busdevfn; - cache.is_present = 0; - } - return 0; - } - pci->vendor_id = l & 0xffff; - pci->device_id = ( l >> 16 ) & 0xffff; - - /* Check that we're not a duplicate function on a - * non-multifunction device. - */ - if ( PCI_FUNC ( busdevfn ) != 0 ) { - uint8_t header_type; - - pci->busdevfn &= PCI_FN0 ( busdevfn ); - pci_read_config_byte ( pci, PCI_HEADER_TYPE, &header_type ); - pci->busdevfn = busdevfn; - - if ( ! ( header_type & 0x80 ) ) { - return 0; - } - } - - /* Get device class */ - pci_read_config_word ( pci, PCI_SUBCLASS_CODE, &pci->class ); - - /* Get revision */ - pci_read_config_byte ( pci, PCI_REVISION, &pci->revision ); - - /* Get the "membase" */ - pci_read_config_dword ( pci, PCI_BASE_ADDRESS_1, &pci->membase ); - - /* Get the "ioaddr" */ - pci->ioaddr = 0; - for ( reg = PCI_BASE_ADDRESS_0; reg <= PCI_BASE_ADDRESS_5; reg += 4 ) { - pci_read_config_dword ( pci, reg, &pci->ioaddr ); - if ( pci->ioaddr & PCI_BASE_ADDRESS_SPACE_IO ) { - pci->ioaddr &= PCI_BASE_ADDRESS_IO_MASK; - if ( pci->ioaddr ) { - break; + pci_read_config_dword ( pci, reg, &low ); + if ( ( low & (PCI_BASE_ADDRESS_SPACE|PCI_BASE_ADDRESS_MEM_TYPE_MASK) ) + == (PCI_BASE_ADDRESS_SPACE_MEMORY|PCI_BASE_ADDRESS_MEM_TYPE_64) ){ + pci_read_config_dword ( pci, reg + 4, &high ); + if ( high ) { + if ( sizeof ( unsigned long ) > sizeof ( uint32_t ) ) { + return ( ( ( uint64_t ) high << 32 ) | low ); + } else { + DBG ( "Unhandled 64-bit BAR %08x%08x\n", + high, low ); + return PCI_BASE_ADDRESS_MEM_TYPE_64; } } - pci->ioaddr = 0; } - - /* Get the irq */ - pci_read_config_byte ( pci, PCI_INTERRUPT_PIN, &pci->irq ); - if ( pci->irq ) { - pci_read_config_byte ( pci, PCI_INTERRUPT_LINE, &pci->irq ); - } - - DBG ( "PCI found device %hhx:%hhx.%d Class %hx: %hx:%hx (rev %hhx)\n", - PCI_BUS ( pci->busdevfn ), PCI_DEV ( pci->busdevfn ), - PCI_FUNC ( pci->busdevfn ), pci->class, pci->vendor_id, - pci->device_id, pci->revision ); - - return 1; + return low; } -/* - * Test whether or not a driver is capable of driving the device. +/** + * Find the start of a PCI BAR * + * @v pci PCI device + * @v reg PCI register number + * @ret start BAR start address + * + * Reads the specified PCI base address register, and returns the + * address portion of the BAR (i.e. without the flags). + * + * If the address exceeds the size of an unsigned long (i.e. if a + * 64-bit BAR has a non-zero high dword on a 32-bit machine), the + * return value will be zero. */ -static int pci_check_driver ( struct bus_dev *bus_dev, - struct device_driver *device_driver ) { - struct pci_device *pci = ( struct pci_device * ) bus_dev; - struct pci_driver *pci_driver - = ( struct pci_driver * ) device_driver->bus_driver_info; - unsigned int i; +unsigned long pci_bar_start ( struct pci_device *pci, unsigned int reg ) { + unsigned long bar; - /* If driver has a class, and class matches, use it */ - if ( pci_driver->class && - ( pci_driver->class == pci->class ) ) { - DBG ( "PCI driver %s matches class %hx\n", - device_driver->name, pci_driver->class ); - pci->name = device_driver->name; - return 1; + bar = pci_bar ( pci, reg ); + if ( (bar & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY ){ + return ( bar & PCI_BASE_ADDRESS_MEM_MASK ); + } else { + return ( bar & PCI_BASE_ADDRESS_IO_MASK ); } - - /* If any of driver's IDs match, use it */ - for ( i = 0 ; i < pci_driver->id_count; i++ ) { - struct pci_id *id = &pci_driver->ids[i]; - - if ( ( pci->vendor_id == id->vendor_id ) && - ( pci->device_id == id->device_id ) ) { - DBG ( "PCI driver %s device %s matches ID %hx:%hx\n", - device_driver->name, id->name, - id->vendor_id, id->device_id ); - pci->name = id->name; - return 1; +} + +/** + * Read membase and ioaddr for a PCI device + * + * @v pci PCI device + * + * This scans through all PCI BARs on the specified device. The first + * valid memory BAR is recorded as pci_device::membase, and the first + * valid IO BAR is recorded as pci_device::ioaddr. + * + * 64-bit BARs are handled automatically. On a 32-bit platform, if a + * 64-bit BAR has a non-zero high dword, it will be regarded as + * invalid. + */ +static void pci_read_bases ( struct pci_device *pci ) { + unsigned long bar; + int reg; + + for ( reg = PCI_BASE_ADDRESS_0; reg <= PCI_BASE_ADDRESS_5; reg += 4 ) { + bar = pci_bar ( pci, reg ); + if ( bar & PCI_BASE_ADDRESS_SPACE_IO ) { + if ( ! pci->ioaddr ) + pci->ioaddr = + ( bar & PCI_BASE_ADDRESS_IO_MASK ); + } else { + if ( ! pci->membase ) + pci->membase = + ( bar & PCI_BASE_ADDRESS_MEM_MASK ); + /* Skip next BAR if 64-bit */ + if ( bar & PCI_BASE_ADDRESS_MEM_TYPE_64 ) + reg += 4; } } - - return 0; } -/* - * Describe a PCI device +/** + * Enable PCI device * - */ -static char * pci_describe_device ( struct bus_dev *bus_dev ) { - struct pci_device *pci = ( struct pci_device * ) bus_dev; - static char pci_description[] = "PCI 00:00.0"; - - sprintf ( pci_description + 4, "%hhx:%hhx.%d", - PCI_BUS ( pci->busdevfn ), PCI_DEV ( pci->busdevfn ), - PCI_FUNC ( pci->busdevfn ) ); - return pci_description; -} - -/* - * Name a PCI device + * @v pci PCI device * - */ -static const char * pci_name_device ( struct bus_dev *bus_dev ) { - struct pci_device *pci = ( struct pci_device * ) bus_dev; - - return pci->name; -} - -/* - * PCI bus operations table - * - */ -struct bus_driver pci_driver __bus_driver = { - .name = "PCI", - .next_location = pci_next_location, - .fill_device = pci_fill_device, - .check_driver = pci_check_driver, - .describe_device = pci_describe_device, - .name_device = pci_name_device, -}; - -/* * Set device to be a busmaster in case BIOS neglected to do so. Also * adjust PCI latency timer to a reasonable value, 32. */ void adjust_pci_device ( struct pci_device *pci ) { - unsigned short new_command, pci_command; - unsigned char pci_latency; + unsigned short new_command, pci_command; + unsigned char pci_latency; pci_read_config_word ( pci, PCI_COMMAND, &pci_command ); new_command = pci_command | PCI_COMMAND_MASTER | PCI_COMMAND_IO; if ( pci_command != new_command ) { - DBG ( "PCI BIOS has not enabled device %hhx:%hhx.%d! " - "Updating PCI command %hX->%hX\n", - PCI_BUS ( pci->busdevfn ), PCI_DEV ( pci->busdevfn ), - PCI_FUNC ( pci->busdevfn ), pci_command, new_command ); + DBG ( "PCI BIOS has not enabled device %02x:%02x.%x! " + "Updating PCI command %04x->%04x\n", pci->bus, + PCI_SLOT ( pci->devfn ), PCI_FUNC ( pci->devfn ), + pci_command, new_command ); pci_write_config_word ( pci, PCI_COMMAND, new_command ); } + pci_read_config_byte ( pci, PCI_LATENCY_TIMER, &pci_latency); if ( pci_latency < 32 ) { - DBG ( "PCI device %hhx:%hhx.%d latency timer is " - "unreasonably low at %d. Setting to 32.\n", - PCI_BUS ( pci->busdevfn ), PCI_DEV ( pci->busdevfn ), - PCI_FUNC ( pci->busdevfn ), pci_latency ); + DBG ( "PCI device %02x:%02x.%x latency timer is unreasonably " + "low at %d. Setting to 32.\n", pci->bus, + PCI_SLOT ( pci->devfn ), PCI_FUNC ( pci->devfn ), + pci_latency ); pci_write_config_byte ( pci, PCI_LATENCY_TIMER, 32); } } -/* - * Find the start of a pci resource. +/** + * Register PCI device + * + * @v pci PCI device + * @ret rc Return status code + * + * Searches for a driver for the PCI device. If a driver is found, + * its probe() routine is called, and the device is added to the + * device hierarchy. */ -unsigned long pci_bar_start ( struct pci_device *pci, unsigned int index ) { - uint32_t lo, hi; - unsigned long bar; +static int register_pcidev ( struct pci_device *pci ) { + struct pci_driver *driver; + struct pci_device_id *id; + unsigned int i; + int rc; - pci_read_config_dword ( pci, index, &lo ); - if ( lo & PCI_BASE_ADDRESS_SPACE_IO ) { - bar = lo & PCI_BASE_ADDRESS_IO_MASK; - } else { - bar = 0; - if ( ( lo & PCI_BASE_ADDRESS_MEM_TYPE_MASK ) == - PCI_BASE_ADDRESS_MEM_TYPE_64) { - pci_read_config_dword ( pci, index + 4, &hi ); - if ( hi ) { -#if ULONG_MAX > 0xffffffff - bar = hi; - bar <<= 32; -#else - printf ( "Unhandled 64bit BAR %08x:%08x\n", - hi, lo ); - return -1UL; -#endif + DBG ( "Registering PCI device %02x:%02x.%x (%04x:%04x mem %lx " + "io %lx irq %d)\n", pci->bus, PCI_SLOT ( pci->devfn ), + PCI_FUNC ( pci->devfn ), pci->vendor, pci->device, + pci->membase, pci->ioaddr, pci->irq ); + + for ( driver = pci_drivers ; driver < pci_drivers_end ; driver++ ) { + for ( i = 0 ; i < driver->id_count ; i++ ) { + id = &driver->ids[i]; + if ( ( id->vendor != pci->vendor ) || + ( id->device != pci->device ) ) + continue; + pci->driver = driver; + pci->name = id->name; + DBG ( "...using driver %s\n", pci->name ); + if ( ( rc = driver->probe ( pci, id ) ) != 0 ) { + DBG ( "......probe failed\n" ); + continue; } + list_add ( &pci->dev.siblings, + &pci->dev.parent->children ); + return 0; } - bar |= lo & PCI_BASE_ADDRESS_MEM_MASK; } - return bar + pci_bus_base ( pci ); -} -/* - * Find the size of a pci resource. - */ -unsigned long pci_bar_size ( struct pci_device *pci, unsigned int bar ) { - uint32_t start, size; - - /* Save the original bar */ - pci_read_config_dword ( pci, bar, &start ); - /* Compute which bits can be set */ - pci_write_config_dword ( pci, bar, ~0 ); - pci_read_config_dword ( pci, bar, &size ); - /* Restore the original size */ - pci_write_config_dword ( pci, bar, start ); - /* Find the significant bits */ - if ( start & PCI_BASE_ADDRESS_SPACE_IO ) { - size &= PCI_BASE_ADDRESS_IO_MASK; - } else { - size &= PCI_BASE_ADDRESS_MEM_MASK; - } - /* Find the lowest bit set */ - size = size & ~( size - 1 ); - return size; + DBG ( "...no driver found\n" ); + return -ENOTTY; } /** - * pci_find_capability - query for devices' capabilities - * @pci: PCI device to query - * @cap: capability code + * Unregister a PCI device * - * Tell if a device supports a given PCI capability. - * Returns the address of the requested capability structure within the - * device's PCI configuration space or 0 in case the device does not - * support it. Possible values for @cap: + * @v pci PCI device * - * %PCI_CAP_ID_PM Power Management - * - * %PCI_CAP_ID_AGP Accelerated Graphics Port - * - * %PCI_CAP_ID_VPD Vital Product Data - * - * %PCI_CAP_ID_SLOTID Slot Identification - * - * %PCI_CAP_ID_MSI Message Signalled Interrupts - * - * %PCI_CAP_ID_CHSWP CompactPCI HotSwap + * Calls the device's driver's remove() routine, and removes the + * device from the device hierarchy. */ -int pci_find_capability ( struct pci_device *pci, int cap ) { - uint16_t status; - uint8_t pos, id; - uint8_t hdr_type; - int ttl = 48; +static void unregister_pcidev ( struct pci_device *pci ) { + pci->driver->remove ( pci ); + list_del ( &pci->dev.siblings ); + DBG ( "Unregistered PCI device %02x:%02x.%x\n", pci->bus, + PCI_SLOT ( pci->devfn ), PCI_FUNC ( pci->devfn ) ); +} - pci_read_config_word ( pci, PCI_STATUS, &status ); - if ( ! ( status & PCI_STATUS_CAP_LIST ) ) - return 0; +/** + * Probe PCI root bus + * + * @v rootdev PCI bus root device + * + * Scans the PCI bus for devices and registers all devices it can + * find. + */ +static int pcibus_probe ( struct root_device *rootdev ) { + struct pci_device *pci = NULL; + unsigned int bus; + unsigned int devfn; + uint8_t hdrtype; + uint32_t tmp; + int rc; - pci_read_config_byte ( pci, PCI_HEADER_TYPE, &hdr_type ); - switch ( hdr_type & 0x7F ) { - case PCI_HEADER_TYPE_NORMAL: - case PCI_HEADER_TYPE_BRIDGE: - default: - pci_read_config_byte ( pci, PCI_CAPABILITY_LIST, &pos ); - break; - case PCI_HEADER_TYPE_CARDBUS: - pci_read_config_byte ( pci, PCI_CB_CAPABILITY_LIST, &pos ); - break; - } - while ( ttl-- && pos >= 0x40 ) { - pos &= ~3; - pci_read_config_byte ( pci, pos + PCI_CAP_LIST_ID, &id ); - DBG ( "PCI Capability: %d\n", id ); - if ( id == 0xff ) - break; - if ( id == cap ) - return pos; - pci_read_config_byte ( pci, pos + PCI_CAP_LIST_NEXT, &pos ); + for ( bus = 0 ; bus <= pci_max_bus ; bus++ ) { + for ( devfn = 0 ; devfn <= 0xff ; devfn++ ) { + + /* Allocate struct pci_device */ + if ( ! pci ) + pci = malloc ( sizeof ( *pci ) ); + if ( ! pci ) { + rc = -ENOMEM; + goto err; + } + memset ( pci, 0, sizeof ( *pci ) ); + pci->bus = bus; + pci->devfn = devfn; + + /* Skip all but the first function on + * non-multifunction cards + */ + if ( PCI_FUNC ( devfn ) == 0 ) { + pci_read_config_byte ( pci, PCI_HEADER_TYPE, + &hdrtype ); + } else if ( ! ( hdrtype & 0x80 ) ) { + continue; + } + + /* Check for physical device presence */ + pci_read_config_dword ( pci, PCI_VENDOR_ID, &tmp ); + if ( ( tmp == 0xffffffff ) || ( tmp == 0 ) ) + continue; + + /* Populate struct pci_device */ + pci->vendor = ( tmp & 0xffff ); + pci->device = ( tmp >> 16 ); + pci_read_config_dword ( pci, PCI_REVISION, &tmp ); + pci->class = ( tmp >> 8 ); + pci_read_config_byte ( pci, PCI_INTERRUPT_LINE, + &pci->irq ); + pci_read_bases ( pci ); + INIT_LIST_HEAD ( &pci->dev.children ); + pci->dev.parent = &rootdev->dev; + + /* Look for a driver */ + if ( register_pcidev ( pci ) == 0 ) { + /* pcidev registered, we can drop our ref */ + pci = NULL; + } else { + /* Not registered; re-use struct pci_device */ + } + } } + + free ( pci ); return 0; + + err: + free ( pci ); + pcibus_remove ( rootdev ); + return rc; } -/* - * Fill in a nic structure +/** + * Remove PCI root bus * + * @v rootdev PCI bus root device */ -void pci_fill_nic ( struct nic *nic, struct pci_device *pci ) { +static void pcibus_remove ( struct root_device *rootdev ) { + struct pci_device *pci; + struct pci_device *tmp; - /* Fill in ioaddr and irqno */ - nic->ioaddr = pci->ioaddr; - nic->irqno = pci->irq; - - /* Fill in DHCP device ID structure */ - nic->dhcp_dev_id.bus_type = PCI_BUS_TYPE; - nic->dhcp_dev_id.vendor_id = htons ( pci->vendor_id ); - nic->dhcp_dev_id.device_id = htons ( pci->device_id ); + list_for_each_entry_safe ( pci, tmp, &rootdev->dev.children, + dev.siblings ) { + unregister_pcidev ( pci ); + free ( pci ); + } } + +/** PCI bus root device driver */ +static struct root_driver pci_root_driver = { + .probe = pcibus_probe, + .remove = pcibus_remove, +}; + +/** PCI bus root device */ +struct root_device pci_root_device __root_device = { + .name = "PCI", + .driver = &pci_root_driver, + .dev = { + .children = LIST_HEAD_INIT ( pci_root_device.dev.children ), + }, +}; diff --git a/src/drivers/bus/pciextra.c b/src/drivers/bus/pciextra.c new file mode 100644 index 00000000..4603bcb9 --- /dev/null +++ b/src/drivers/bus/pciextra.c @@ -0,0 +1,79 @@ +#include +#include + +/** + * Look for a PCI capability + * + * @v pci PCI device to query + * @v cap Capability code + * @ret address Address of capability, or 0 if not found + * + * Determine whether or not a device supports a given PCI capability. + * Returns the address of the requested capability structure within + * the device's PCI configuration space, or 0 if the device does not + * support it. + */ +int pci_find_capability ( struct pci_device *pci, int cap ) { + uint16_t status; + uint8_t pos, id; + uint8_t hdr_type; + int ttl = 48; + + pci_read_config_word ( pci, PCI_STATUS, &status ); + if ( ! ( status & PCI_STATUS_CAP_LIST ) ) + return 0; + + pci_read_config_byte ( pci, PCI_HEADER_TYPE, &hdr_type ); + switch ( hdr_type & 0x7F ) { + case PCI_HEADER_TYPE_NORMAL: + case PCI_HEADER_TYPE_BRIDGE: + default: + pci_read_config_byte ( pci, PCI_CAPABILITY_LIST, &pos ); + break; + case PCI_HEADER_TYPE_CARDBUS: + pci_read_config_byte ( pci, PCI_CB_CAPABILITY_LIST, &pos ); + break; + } + while ( ttl-- && pos >= 0x40 ) { + pos &= ~3; + pci_read_config_byte ( pci, pos + PCI_CAP_LIST_ID, &id ); + DBG ( "PCI Capability: %d\n", id ); + if ( id == 0xff ) + break; + if ( id == cap ) + return pos; + pci_read_config_byte ( pci, pos + PCI_CAP_LIST_NEXT, &pos ); + } + return 0; +} + +/** + * Find the size of a PCI BAR + * + * @v pci PCI device + * @v reg PCI register number + * @ret size BAR size + * + * It should not be necessary for any Etherboot code to call this + * function. + */ +unsigned long pci_bar_size ( struct pci_device *pci, unsigned int reg ) { + uint32_t start, size; + + /* Save the original bar */ + pci_read_config_dword ( pci, reg, &start ); + /* Compute which bits can be set */ + pci_write_config_dword ( pci, reg, ~0 ); + pci_read_config_dword ( pci, reg, &size ); + /* Restore the original size */ + pci_write_config_dword ( pci, reg, start ); + /* Find the significant bits */ + if ( start & PCI_BASE_ADDRESS_SPACE_IO ) { + size &= PCI_BASE_ADDRESS_IO_MASK; + } else { + size &= PCI_BASE_ADDRESS_MEM_MASK; + } + /* Find the lowest bit set */ + size = size & ~( size - 1 ); + return size; +} diff --git a/src/drivers/net/3c595.c b/src/drivers/net/3c595.c index b6f531d1..8db1285e 100644 --- a/src/drivers/net/3c595.c +++ b/src/drivers/net/3c595.c @@ -522,7 +522,7 @@ static struct nic_operations t595_operations = { }; -static struct pci_id t595_nics[] = { +static struct pci_device_id t595_nics[] = { PCI_ROM(0x10b7, 0x5900, "3c590", "3Com590"), /* Vortex 10Mbps */ PCI_ROM(0x10b7, 0x5950, "3c595", "3Com595"), /* Vortex 100baseTx */ PCI_ROM(0x10b7, 0x5951, "3c595-1", "3Com595"), /* Vortex 100baseT4 */ diff --git a/src/drivers/net/3c90x.c b/src/drivers/net/3c90x.c index 54dcc40d..0fb79a49 100644 --- a/src/drivers/net/3c90x.c +++ b/src/drivers/net/3c90x.c @@ -719,7 +719,7 @@ static int a3c90x_probe ( struct nic *nic, struct pci_device *pci ) { nic->ioaddr = pci->ioaddr; nic->irqno = 0; - INF_3C90X.is3c556 = (pci->device_id == 0x6055); + INF_3C90X.is3c556 = (pci->device == 0x6055); INF_3C90X.IOAddr = pci->ioaddr & ~3; INF_3C90X.CurrentWindow = 255; switch (a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, 0x03)) @@ -984,7 +984,7 @@ static struct nic_operations a3c90x_operations = { }; -static struct pci_id a3c90x_nics[] = { +static struct pci_device_id a3c90x_nics[] = { /* Original 90x revisions: */ PCI_ROM(0x10b7, 0x6055, "3c556", "3C556"), /* Huricane */ PCI_ROM(0x10b7, 0x9000, "3c905-tpo", "3Com900-TPO"), /* 10 Base TPO */ diff --git a/src/drivers/net/amd8111e.c b/src/drivers/net/amd8111e.c index e3b93dc5..7702a350 100644 --- a/src/drivers/net/amd8111e.c +++ b/src/drivers/net/amd8111e.c @@ -671,7 +671,7 @@ static int amd8111e_probe(struct nic *nic, struct pci_device *pdev) return 1; } -static struct pci_id amd8111e_nics[] = { +static struct pci_device_id amd8111e_nics[] = { PCI_ROM(0x1022, 0x7462, "amd8111e", "AMD8111E"), }; diff --git a/src/drivers/net/davicom.c b/src/drivers/net/davicom.c index 0f1a78cc..0931d13f 100644 --- a/src/drivers/net/davicom.c +++ b/src/drivers/net/davicom.c @@ -662,8 +662,8 @@ static int davicom_probe ( struct nic *nic, struct pci_device *pci ) { if (pci->ioaddr == 0) return 0; - vendor = pci->vendor_id; - dev_id = pci->device_id; + vendor = pci->vendor; + dev_id = pci->device; ioaddr = pci->ioaddr; pci_fill_nic ( nic, pci ); @@ -703,7 +703,7 @@ static struct nic_operations davicom_operations = { }; -static struct pci_id davicom_nics[] = { +static struct pci_device_id davicom_nics[] = { PCI_ROM(0x1282, 0x9100, "davicom9100", "Davicom 9100"), PCI_ROM(0x1282, 0x9102, "davicom9102", "Davicom 9102"), PCI_ROM(0x1282, 0x9009, "davicom9009", "Davicom 9009"), diff --git a/src/drivers/net/dmfe.c b/src/drivers/net/dmfe.c index 4cfb69bd..4c822724 100644 --- a/src/drivers/net/dmfe.c +++ b/src/drivers/net/dmfe.c @@ -457,7 +457,7 @@ static int dmfe_probe ( struct nic *nic, struct pci_device *pci ) { BASE = pci->ioaddr; printf("dmfe.c: Found %s Vendor=0x%hX Device=0x%hX\n", - pci->name, pci->vendor_id, pci->device_id); + pci->name, pci->vendor, pci->device); /* Read Chip revision */ pci_read_config_dword(pci, PCI_REVISION_ID, &dev_rev); @@ -466,7 +466,7 @@ static int dmfe_probe ( struct nic *nic, struct pci_device *pci ) { /* point to private storage */ db = &dfx; - db->chip_id = ((u32) pci->device_id << 16) | pci->vendor_id; + db->chip_id = ((u32) pci->device << 16) | pci->vendor; BASE = pci_bar_start(pci, PCI_BASE_ADDRESS_0); db->chip_revision = dev_rev; @@ -1205,7 +1205,7 @@ static struct nic_operations dmfe_operations = { }; -static struct pci_id dmfe_nics[] = { +static struct pci_device_id dmfe_nics[] = { PCI_ROM(0x1282, 0x9100, "dmfe9100", "Davicom 9100"), PCI_ROM(0x1282, 0x9102, "dmfe9102", "Davicom 9102"), PCI_ROM(0x1282, 0x9009, "dmfe9009", "Davicom 9009"), diff --git a/src/drivers/net/e1000.c b/src/drivers/net/e1000.c index a13a7271..b9f9d8f9 100644 --- a/src/drivers/net/e1000.c +++ b/src/drivers/net/e1000.c @@ -3707,7 +3707,7 @@ static struct nic_operations e1000_operations = { }; -static struct pci_id e1000_nics[] = { +static struct pci_device_id e1000_nics[] = { PCI_ROM(0x8086, 0x1000, "e1000-82542", "Intel EtherExpressPro1000"), PCI_ROM(0x8086, 0x1001, "e1000-82543gc-fiber", "Intel EtherExpressPro1000 82543GC Fiber"), PCI_ROM(0x8086, 0x1004, "e1000-82543gc-copper", "Intel EtherExpressPro1000 82543GC Copper"), diff --git a/src/drivers/net/eepro100.c b/src/drivers/net/eepro100.c index 27576a61..c1ff2e76 100644 --- a/src/drivers/net/eepro100.c +++ b/src/drivers/net/eepro100.c @@ -791,7 +791,7 @@ static struct nic_operations eepro100_operations = { }; -static struct pci_id eepro100_nics[] = { +static struct pci_device_id eepro100_nics[] = { PCI_ROM(0x8086, 0x1029, "id1029", "Intel EtherExpressPro100 ID1029"), PCI_ROM(0x8086, 0x1030, "id1030", "Intel EtherExpressPro100 ID1030"), PCI_ROM(0x8086, 0x1031, "82801cam", "Intel 82801CAM (ICH3) Chipset Ethernet Controller"), diff --git a/src/drivers/net/epic100.c b/src/drivers/net/epic100.c index babcf6b3..32f2dff4 100644 --- a/src/drivers/net/epic100.c +++ b/src/drivers/net/epic100.c @@ -517,7 +517,7 @@ static struct nic_operations epic100_operations = { }; -static struct pci_id epic100_nics[] = { +static struct pci_device_id epic100_nics[] = { PCI_ROM(0x10b8, 0x0005, "epic100", "SMC EtherPowerII"), /* SMC 83c170 EPIC/100 */ PCI_ROM(0x10b8, 0x0006, "smc-83c175", "SMC EPIC/C 83c175"), }; diff --git a/src/drivers/net/etherfabric.c b/src/drivers/net/etherfabric.c index 05239d68..307070f0 100644 --- a/src/drivers/net/etherfabric.c +++ b/src/drivers/net/etherfabric.c @@ -2975,7 +2975,7 @@ static int etherfabric_probe ( struct dev *dev, struct pci_device *pci ) { memset ( &efab_buffers, 0, sizeof ( efab_buffers ) ); /* Hook in appropriate operations table. Do this early. */ - if ( pci->device_id == EF1002_DEVID ) { + if ( pci->device == EF1002_DEVID ) { efab.op = &ef1002_operations; } else { efab.op = &falcon_operations; @@ -3021,7 +3021,7 @@ static int etherfabric_probe ( struct dev *dev, struct pci_device *pci ) { return 1; } -static struct pci_id etherfabric_nics[] = { +static struct pci_device_id etherfabric_nics[] = { PCI_ROM(0x1924, 0xC101, "ef1002", "EtherFabric EF1002"), PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon"), }; diff --git a/src/drivers/net/forcedeth.c b/src/drivers/net/forcedeth.c index 08ddbcd9..a60749c7 100644 --- a/src/drivers/net/forcedeth.c +++ b/src/drivers/net/forcedeth.c @@ -1245,7 +1245,7 @@ static int forcedeth_probe ( struct nic *nic, struct pci_device *pci ) { return 0; printf("forcedeth.c: Found %s, vendor=0x%hX, device=0x%hX\n", - pci->name, pci->vendor_id, pci->device_id); + pci->name, pci->vendor, pci->device); pci_fill_nic ( nic, pci ); @@ -1263,9 +1263,9 @@ static int forcedeth_probe ( struct nic *nic, struct pci_device *pci ) { return 0; /* handle different descriptor versions */ - if (pci->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_1 || - pci->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_2 || - pci->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_3) + if (pci->device == PCI_DEVICE_ID_NVIDIA_NVENET_1 || + pci->device == PCI_DEVICE_ID_NVIDIA_NVENET_2 || + pci->device == PCI_DEVICE_ID_NVIDIA_NVENET_3) np->desc_ver = DESC_VER_1; else np->desc_ver = DESC_VER_2; @@ -1316,7 +1316,7 @@ static int forcedeth_probe ( struct nic *nic, struct pci_device *pci ) { np->tx_flags = NV_TX2_LASTPACKET | NV_TX2_VALID; } - switch (pci->device_id) { + switch (pci->device) { case 0x01C3: // nforce // DEV_IRQMASK_1|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, np->irqmask = NVREG_IRQMASK_WANTED_2 | NVREG_IRQ_TIMER; @@ -1406,7 +1406,7 @@ static int forcedeth_probe ( struct nic *nic, struct pci_device *pci ) { return 1; } -static struct pci_id forcedeth_nics[] = { +static struct pci_device_id forcedeth_nics[] = { PCI_ROM(0x10de, 0x01C3, "nforce", "nForce NVENET_1 Ethernet Controller"), PCI_ROM(0x10de, 0x0066, "nforce2", "nForce NVENET_2 Ethernet Controller"), PCI_ROM(0x10de, 0x00D6, "nforce3", "nForce NVENET_3 Ethernet Controller"), diff --git a/src/drivers/net/mtd80x.c b/src/drivers/net/mtd80x.c index 21db5640..925da9bf 100644 --- a/src/drivers/net/mtd80x.c +++ b/src/drivers/net/mtd80x.c @@ -653,7 +653,7 @@ static struct nic_operations mtd_operations = { }; -static struct pci_id mtd80x_nics[] = { +static struct pci_device_id mtd80x_nics[] = { PCI_ROM(0x1516, 0x0800, "MTD800", "Myson MTD800"), PCI_ROM(0x1516, 0x0803, "MTD803", "Surecom EP-320X"), PCI_ROM(0x1516, 0x0891, "MTD891", "Myson MTD891"), @@ -676,7 +676,7 @@ static int mtd_probe ( struct nic *nic, struct pci_device *pci ) { adjust_pci_device(pci); mtdx.nic_name = pci->name; - mtdx.dev_id = pci->device_id; + mtdx.dev_id = pci->device; mtdx.ioaddr = nic->ioaddr; /* read ethernet id */ diff --git a/src/drivers/net/natsemi.c b/src/drivers/net/natsemi.c index 951195f1..c34d611f 100644 --- a/src/drivers/net/natsemi.c +++ b/src/drivers/net/natsemi.c @@ -259,8 +259,8 @@ natsemi_probe ( struct nic *nic, struct pci_device *pci ) { nic->ioaddr = pci->ioaddr; ioaddr = pci->ioaddr; - vendor = pci->vendor_id; - dev_id = pci->device_id; + vendor = pci->vendor; + dev_id = pci->device; nic_name = pci->name; /* natsemi has a non-standard PM control register @@ -770,7 +770,7 @@ static struct nic_operations natsemi_operations = { }; -static struct pci_id natsemi_nics[] = { +static struct pci_device_id natsemi_nics[] = { PCI_ROM(0x100b, 0x0020, "dp83815", "DP83815"), }; diff --git a/src/drivers/net/ns83820.c b/src/drivers/net/ns83820.c index 30bf0c1c..2f26b71b 100755 --- a/src/drivers/net/ns83820.c +++ b/src/drivers/net/ns83820.c @@ -800,7 +800,7 @@ static struct nic_operations ns83820_operations = { }; -static struct pci_id ns83820_nics[] = { +static struct pci_device_id ns83820_nics[] = { PCI_ROM(0x100b, 0x0022, "ns83820", "National Semiconductor 83820"), }; @@ -822,7 +822,7 @@ static int ns83820_probe ( struct nic *nic, struct pci_device *pci ) { return 0; printf("ns83820.c: Found %s, vendor=0x%hX, device=0x%hX\n", - pci->name, pci->vendor_id, pci->device_id); + pci->name, pci->vendor, pci->device); /* point to private storage */ ns = &nsx; diff --git a/src/drivers/net/ns8390.c b/src/drivers/net/ns8390.c index 9c091216..af99d139 100644 --- a/src/drivers/net/ns8390.c +++ b/src/drivers/net/ns8390.c @@ -991,7 +991,7 @@ ISA_ROM("ne","NE1000/2000 and clones"); #endif #ifdef INCLUDE_NS8390 -static struct pci_id nepci_nics[] = { +static struct pci_device_id nepci_nics[] = { /* A few NE2000 PCI clones, list not exhaustive */ PCI_ROM(0x10ec, 0x8029, "rtl8029", "Realtek 8029"), PCI_ROM(0x1186, 0x0300, "dlink-528", "D-Link DE-528"), diff --git a/src/drivers/net/pcnet32.c b/src/drivers/net/pcnet32.c index 74fea5a9..51efe39e 100644 --- a/src/drivers/net/pcnet32.c +++ b/src/drivers/net/pcnet32.c @@ -680,7 +680,7 @@ static int pcnet32_probe ( struct nic *nic, struct pci_device *pci ) { /* BASE is used throughout to address the card */ ioaddr = pci->ioaddr; printf("pcnet32.c: Found %s, Vendor=0x%hX Device=0x%hX\n", - pci->name, pci->vendor_id, pci->device_id); + pci->name, pci->vendor, pci->device); nic->irqno = 0; pci_fill_nic ( nic, pci ); @@ -1000,7 +1000,7 @@ static struct nic_operations pcnet32_operations = { }; -static struct pci_id pcnet32_nics[] = { +static struct pci_device_id pcnet32_nics[] = { PCI_ROM(0x1022, 0x2000, "pcnet32", "AMD PCnet/PCI"), PCI_ROM(0x1022, 0x2625, "pcnetfastiii", "AMD PCNet FAST III"), PCI_ROM(0x1022, 0x2001, "amdhomepna", "AMD PCnet/HomePNA"), diff --git a/src/drivers/net/pnic.c b/src/drivers/net/pnic.c index d4b19778..18f7b93b 100644 --- a/src/drivers/net/pnic.c +++ b/src/drivers/net/pnic.c @@ -199,13 +199,17 @@ static void pnic_remove ( struct pci_device *pci ) { /************************************************************************** PROBE - Look for an adapter, this routine's visible to the outside ***************************************************************************/ -static int pnic_probe ( struct pci_device *pci ) { +static int pnic_probe ( struct pci_device *pci, + const struct pci_device_id *id __unused ) { struct net_device *netdev; struct pnic *pnic; uint16_t api_version; uint16_t status; int rc; + /* Fix up PCI device */ + adjust_pci_device ( pci ); + /* Allocate net device */ netdev = alloc_etherdev ( sizeof ( *pnic ) ); if ( ! netdev ) { @@ -248,32 +252,14 @@ static int pnic_probe ( struct pci_device *pci ) { return rc; } -static struct pci_id pnic_nics[] = { +static struct pci_device_id pnic_nics[] = { /* genrules.pl doesn't let us use macros for PCI IDs...*/ PCI_ROM ( 0xfefe, 0xefef, "pnic", "Bochs Pseudo NIC Adaptor" ), }; -static struct pci_driver pnic_driver = { +struct pci_driver pnic_driver __pci_driver = { .ids = pnic_nics, .id_count = ( sizeof ( pnic_nics ) / sizeof ( pnic_nics[0] ) ), - .class = PCI_NO_CLASS, - // .probe = pnic_probe, - // .remove = pnic_remove, + .probe = pnic_probe, + .remove = pnic_remove, }; - -// PCI_DRIVER ( pnic_driver ); - - -static int pnic_hack_probe ( void *dummy, struct pci_device *pci ) { - return ( pnic_probe ( pci ) == 0 ); -} - -static void pnic_hack_disable ( void *dummy, struct pci_device *pci ) { - pnic_remove ( pci ); -} - -#include "dev.h" -extern struct type_driver test_driver; - -DRIVER ( "PNIC", test_driver, pci_driver, pnic_driver, - pnic_hack_probe, pnic_hack_disable ); diff --git a/src/drivers/net/prism2_pci.c b/src/drivers/net/prism2_pci.c index f0dd9f12..90295cde 100644 --- a/src/drivers/net/prism2_pci.c +++ b/src/drivers/net/prism2_pci.c @@ -39,7 +39,7 @@ static void prism2_pci_disable ( struct nic *nic, prism2_disable ( nic ); } -static struct pci_id prism2_pci_nics[] = { +static struct pci_device_id prism2_pci_nics[] = { PCI_ROM(0x1260, 0x3873, "prism2_pci", "Harris Semiconductor Prism2.5 clone"), PCI_ROM(0x1260, 0x3873, "hwp01170", "ActionTec HWP01170"), PCI_ROM(0x1260, 0x3873, "dwl520", "DLink DWL-520"), diff --git a/src/drivers/net/prism2_plx.c b/src/drivers/net/prism2_plx.c index 64432c87..616903cf 100644 --- a/src/drivers/net/prism2_plx.c +++ b/src/drivers/net/prism2_plx.c @@ -95,7 +95,7 @@ static void prism2_plx_disable ( struct nic *nic, prism2_disable ( nic ); } -static struct pci_id prism2_plx_nics[] = { +static struct pci_device_id prism2_plx_nics[] = { PCI_ROM(0x1385, 0x4100, "ma301", "Netgear MA301"), PCI_ROM(0x10b7, 0x7770, "3c-airconnect", "3Com AirConnect"), PCI_ROM(0x111a, 0x1023, "ss1023", "Siemens SpeedStream SS1023"), diff --git a/src/drivers/net/r8169.c b/src/drivers/net/r8169.c index c11b8271..0efcb35d 100644 --- a/src/drivers/net/r8169.c +++ b/src/drivers/net/r8169.c @@ -868,7 +868,7 @@ static struct nic_operations r8169_operations = { }; -static struct pci_id r8169_nics[] = { +static struct pci_device_id r8169_nics[] = { PCI_ROM(0x10ec, 0x8169, "r8169", "RealTek RTL8169 Gigabit Ethernet"), PCI_ROM(0x16ec, 0x0116, "usr-r8169", "US Robotics RTL8169 Gigabit Ethernet"), PCI_ROM(0x1186, 0x4300, "dlink-r8169", "D-Link RTL8169 Gigabit Ethernet"), @@ -890,7 +890,7 @@ static int r8169_probe ( struct nic *nic, struct pci_device *pci ) { int option = -1, Cap10_100 = 0, Cap1000 = 0; printf("r8169.c: Found %s, Vendor=%hX Device=%hX\n", - pci->name, pci->vendor_id, pci->device_id); + pci->name, pci->vendor, pci->device); board_idx++; diff --git a/src/drivers/net/rtl8139.c b/src/drivers/net/rtl8139.c index 9a155048..c4baa13f 100644 --- a/src/drivers/net/rtl8139.c +++ b/src/drivers/net/rtl8139.c @@ -528,7 +528,7 @@ static struct nic_operations rtl_operations = { }; -static struct pci_id rtl8139_nics[] = { +static struct pci_device_id rtl8139_nics[] = { PCI_ROM(0x10ec, 0x8129, "rtl8129", "Realtek 8129"), PCI_ROM(0x10ec, 0x8139, "rtl8139", "Realtek 8139"), PCI_ROM(0x10ec, 0x8138, "rtl8139b", "Realtek 8139B"), diff --git a/src/drivers/net/sis900.c b/src/drivers/net/sis900.c index 1a79b1d4..c6b53d81 100644 --- a/src/drivers/net/sis900.c +++ b/src/drivers/net/sis900.c @@ -121,18 +121,20 @@ static struct mii_phy { // PCI to ISA bridge for SIS640E access -static struct pci_id pci_isa_bridge_list[] = { - { 0x1039, 0x0008, - "SIS 85C503/5513 PCI to ISA bridge"}, +static struct pci_device_id pci_isa_bridge_list[] = { + { .vendor = 0x1039, .device = 0x0008, + .name = "SIS 85C503/5513 PCI to ISA bridge"}, }; PCI_DRIVER ( sis_bridge_pci_driver, pci_isa_bridge_list, PCI_NO_CLASS ); +#if 0 static struct device_driver sis_bridge_driver = { .name = "SIS ISA bridge", .bus_driver = &pci_driver, .bus_driver_info = ( struct bus_driver_info * ) &sis_bridge_pci_driver, }; +#endif /* Function Prototypes */ @@ -254,10 +256,12 @@ static int sis630e_get_mac_addr(struct pci_device * pci_dev __unused, struct nic struct pci_device isa_bridge; } u; +#if 0 /* find PCI to ISA bridge */ memset(&bus_loc, 0, sizeof(bus_loc)); if ( ! find_by_driver ( &bus_loc, &u.bus_dev, &sis_bridge_driver, 0 ) ) return 0; +#endif pci_read_config_byte(&u.isa_bridge, 0x48, ®); pci_write_config_byte(&u.isa_bridge, 0x48, reg | 0x40); @@ -337,8 +341,8 @@ static int sis900_probe ( struct nic *nic, struct pci_device *pci ) { pci_fill_nic ( nic, pci ); nic->ioaddr = pci->ioaddr; ioaddr = pci->ioaddr; - vendor = pci->vendor_id; - dev_id = pci->device_id; + vendor = pci->vendor; + dev_id = pci->device; /* wakeup chip */ pci_write_config_dword(pci, 0x40, 0x00000000); @@ -1266,7 +1270,7 @@ static struct nic_operations sis900_operations = { .irq = sis900_irq, }; -static struct pci_id sis900_nics[] = { +static struct pci_device_id sis900_nics[] = { PCI_ROM(0x1039, 0x0900, "sis900", "SIS900"), PCI_ROM(0x1039, 0x7016, "sis7016", "SIS7016"), }; diff --git a/src/drivers/net/skel.c b/src/drivers/net/skel.c index e05239b6..882a38e5 100644 --- a/src/drivers/net/skel.c +++ b/src/drivers/net/skel.c @@ -218,7 +218,7 @@ static void skel_pci_disable ( struct nic *nic __unused, */ } -static struct pci_id skel_pci_nics[] = { +static struct pci_device_id skel_pci_nics[] = { PCI_ROM ( 0x0000, 0x0000, "skel-pci", "Skeleton PCI Adapter" ), }; diff --git a/src/drivers/net/sundance.c b/src/drivers/net/sundance.c index 9c660b9b..d3cb7506 100644 --- a/src/drivers/net/sundance.c +++ b/src/drivers/net/sundance.c @@ -590,7 +590,7 @@ static int sundance_probe ( struct nic *nic, struct pci_device *pci ) { /* BASE is used throughout to address the card */ BASE = pci->ioaddr; printf(" sundance.c: Found %s Vendor=0x%hX Device=0x%hX\n", - pci->name, pci->vendor_id, pci->device_id); + pci->name, pci->vendor, pci->device); /* Get the MAC Address by reading the EEPROM */ for (i = 0; i < 3; i++) { @@ -873,7 +873,7 @@ static void set_rx_mode(struct nic *nic __unused) return; } -static struct pci_id sundance_nics[] = { +static struct pci_device_id sundance_nics[] = { PCI_ROM(0x13f0, 0x0201, "sundance", "ST201 Sundance 'Alta' based Adaptor"), PCI_ROM(0x1186, 0x1002, "dfe530txs", "D-Link DFE530TXS (Sundance ST201 Alta)"), }; diff --git a/src/drivers/net/tg3.c b/src/drivers/net/tg3.c index cad3bdff..6aad8718 100644 --- a/src/drivers/net/tg3.c +++ b/src/drivers/net/tg3.c @@ -2852,9 +2852,9 @@ static int tg3_get_invariants(struct tg3 *tp) if (((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) && ((grc_misc_cfg == 0x8000) || (grc_misc_cfg == 0x4000))) || ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && - (tp->pdev->vendor_id == PCI_VENDOR_ID_BROADCOM) && - ((tp->pdev->device_id == PCI_DEVICE_ID_TIGON3_5901) || - (tp->pdev->device_id == PCI_DEVICE_ID_TIGON3_5901_2)))) { + (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM) && + ((tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901) || + (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2)))) { tp->tg3_flags |= TG3_FLAG_10_100_ONLY; } @@ -2886,7 +2886,7 @@ static int tg3_get_device_address(struct tg3 *tp) struct nic *nic = tp->nic; uint32_t hi, lo, mac_offset; - if (PCI_FUNC(tp->pdev->busdevfn) == 0) + if (PCI_FUNC(tp->pdev->devfn) == 0) mac_offset = 0x7c; else mac_offset = 0xcc; @@ -3362,7 +3362,7 @@ static int tg3_probe ( struct nic *nic, struct pci_device *pdev ) { } -static struct pci_id tg3_nics[] = { +static struct pci_device_id tg3_nics[] = { PCI_ROM(0x14e4, 0x1644, "tg3-5700", "Broadcom Tigon 3 5700"), PCI_ROM(0x14e4, 0x1645, "tg3-5701", "Broadcom Tigon 3 5701"), PCI_ROM(0x14e4, 0x1646, "tg3-5702", "Broadcom Tigon 3 5702"), diff --git a/src/drivers/net/tlan.c b/src/drivers/net/tlan.c index 25d66d82..bebc07a9 100644 --- a/src/drivers/net/tlan.c +++ b/src/drivers/net/tlan.c @@ -811,7 +811,7 @@ static int tlan_probe ( struct nic *nic, struct pci_device *pci ) { i = 0; chip_idx = -1; while (tlan_pci_tbl[i].name) { - if ((((u32) pci->device_id << 16) | pci->vendor_id) == + if ((((u32) pci->device << 16) | pci->vendor) == (tlan_pci_tbl[i].id.pci & 0xffffffff)) { chip_idx = i; break; @@ -819,8 +819,8 @@ static int tlan_probe ( struct nic *nic, struct pci_device *pci ) { i++; } - priv->vendor_id = pci->vendor_id; - priv->dev_id = pci->device_id; + priv->vendor_id = pci->vendor; + priv->dev_id = pci->device; priv->nic_name = pci->name; priv->eoc = 0; @@ -1704,7 +1704,7 @@ void TLan_PhyMonitor(struct net_device *dev) #endif /* MONITOR */ -static struct pci_id tlan_nics[] = { +static struct pci_device_id tlan_nics[] = { PCI_ROM(0x0e11, 0xae34, "netel10", "Compaq Netelligent 10 T PCI UTP"), PCI_ROM(0x0e11, 0xae32, "netel100","Compaq Netelligent 10/100 TX PCI UTP"), PCI_ROM(0x0e11, 0xae35, "netflex3i", "Compaq Integrated NetFlex-3/P"), diff --git a/src/drivers/net/tulip.c b/src/drivers/net/tulip.c index 7ac02d7b..cebc74cf 100644 --- a/src/drivers/net/tulip.c +++ b/src/drivers/net/tulip.c @@ -1249,8 +1249,8 @@ static int tulip_probe ( struct nic *nic, struct pci_device *pci ) { /* point to private storage */ tp = &tulip_bss.tpx; - tp->vendor_id = pci->vendor_id; - tp->dev_id = pci->device_id; + tp->vendor_id = pci->vendor; + tp->dev_id = pci->device; tp->nic_name = pci->name; tp->if_port = 0; @@ -1275,7 +1275,7 @@ static int tulip_probe ( struct nic *nic, struct pci_device *pci ) { #ifdef TULIP_DEBUG if (tulip_debug > 1) printf ("%s: Looking for Tulip Chip: Vendor=%hX Device=%hX\n", tp->nic_name, - tp->vendor_id, tp->dev_id); + tp->vendor, tp->dev_id); #endif /* Figure out which chip we're dealing with */ @@ -2042,7 +2042,7 @@ static int tulip_check_duplex(struct nic *nic) return 0; } -static struct pci_id tulip_nics[] = { +static struct pci_device_id tulip_nics[] = { PCI_ROM(0x1011, 0x0002, "dc21040", "Digital Tulip"), PCI_ROM(0x1011, 0x0009, "ds21140", "Digital Tulip Fast"), PCI_ROM(0x1011, 0x0014, "dc21041", "Digital Tulip+"), diff --git a/src/drivers/net/via-rhine.c b/src/drivers/net/via-rhine.c index e95d9323..ca3212ad 100644 --- a/src/drivers/net/via-rhine.c +++ b/src/drivers/net/via-rhine.c @@ -966,7 +966,7 @@ rhine_probe ( struct nic *nic, struct pci_device *pci ) { if (!pci->ioaddr) return 0; - rhine_probe1 (nic, pci, pci->ioaddr, pci->device_id, -1); + rhine_probe1 (nic, pci, pci->ioaddr, pci->device, -1); adjust_pci_device ( pci ); rhine_reset (nic); @@ -1412,7 +1412,7 @@ static struct nic_operations rhine_operations = { }; -static struct pci_id rhine_nics[] = { +static struct pci_device_id rhine_nics[] = { PCI_ROM(0x1106, 0x3065, "dlink-530tx", "VIA 6102"), PCI_ROM(0x1106, 0x3106, "via-rhine-6105", "VIA 6105"), PCI_ROM(0x1106, 0x3043, "dlink-530tx-old", "VIA 3043"), /* Rhine-I 86c100a */ diff --git a/src/drivers/net/via-velocity.c b/src/drivers/net/via-velocity.c index c6a15e26..9bb471a2 100644 --- a/src/drivers/net/via-velocity.c +++ b/src/drivers/net/via-velocity.c @@ -676,7 +676,7 @@ static int velocity_probe(struct dev *dev, struct pci_device *pci) struct mac_regs *regs; printf("via-velocity.c: Found %s Vendor=0x%hX Device=0x%hX\n", - pci->name, pci->vendor_id, pci->device_id); + pci->name, pci->vendor, pci->device); /* point to private storage */ vptr = &vptx; @@ -1930,7 +1930,7 @@ int pci_set_power_state(struct pci_device *dev, int state) return 0; } -static struct pci_id velocity_nics[] = { +static struct pci_device_id velocity_nics[] = { PCI_ROM(0x1106, 0x3119, "via-velocity", "VIA Networking Velocity Family Gigabit Ethernet Adapter"), }; diff --git a/src/drivers/net/w89c840.c b/src/drivers/net/w89c840.c index 8d8a6ded..97d8d158 100644 --- a/src/drivers/net/w89c840.c +++ b/src/drivers/net/w89c840.c @@ -609,7 +609,7 @@ static struct nic_operations w89c840_operations = { }; -static struct pci_id w89c840_nics[] = { +static struct pci_device_id w89c840_nics[] = { PCI_ROM(0x1050, 0x0840, "winbond840", "Winbond W89C840F"), PCI_ROM(0x11f6, 0x2011, "compexrl100atx", "Compex RL100ATX"), }; @@ -643,20 +643,20 @@ static int w89c840_probe ( struct nic *nic, struct pci_device *p ) { #define PCI_DEVICE_ID_COMPEX_RL100ATX 0x2011 /* From Matt Hortman */ - if (p->vendor_id == PCI_VENDOR_ID_WINBOND2 - && p->device_id == PCI_DEVICE_ID_WINBOND2_89C840) { + if (p->vendor == PCI_VENDOR_ID_WINBOND2 + && p->device == PCI_DEVICE_ID_WINBOND2_89C840) { /* detected "Winbond W89c840 Fast Ethernet PCI NIC" */ - } else if ( p->vendor_id == PCI_VENDOR_ID_COMPEX - && p->device_id == PCI_DEVICE_ID_COMPEX_RL100ATX) { + } else if ( p->vendor == PCI_VENDOR_ID_COMPEX + && p->device == PCI_DEVICE_ID_COMPEX_RL100ATX) { /* detected "Compex RL100ATX Fast Ethernet PCI NIC" */ } else { /* Gee, guess what? They missed again. */ printf("device ID : %X - is not a Compex RL100ATX NIC.\n", - p->device_id); + p->device); return 0; } diff --git a/src/include/gpxe/pci.h b/src/include/gpxe/pci.h index 4322202c..28fa93c5 100644 --- a/src/include/gpxe/pci.h +++ b/src/include/gpxe/pci.h @@ -1,18 +1,13 @@ -#ifndef _GPXEPCI_H -#define _GPXEPCI_H +#ifndef _GPXE_PCI_H +#define _GPXE_PCI_H /* -** Support for NE2000 PCI clones added David Monro June 1997 -** Generalised for other PCI NICs by Ken Yap July 1997 -** -** Most of this is taken from: -** -** /usr/src/linux/drivers/pci/pci.c -** /usr/src/linux/include/linux/pci.h -** /usr/src/linux/arch/i386/bios32.c -** /usr/src/linux/include/linux/bios32.h -** /usr/src/linux/drivers/net/ne.c -*/ + * Support for NE2000 PCI clones added David Monro June 1997 + * Generalised for other PCI NICs by Ken Yap July 1997 + * PCI support rewritten by Michael Brown 2006 + * + * Most of this is taken from /usr/src/linux/include/linux/pci.h. + */ /* * This program is free software; you can redistribute it and/or @@ -22,10 +17,10 @@ */ #include +#include +#include #include "pci_ids.h" -#define PCI_BUS_TYPE 1 - /* * PCI constants * @@ -87,18 +82,16 @@ #define PCI_BASE_ADDRESS_4 0x20 /* 32 bits */ #define PCI_BASE_ADDRESS_5 0x24 /* 32 bits */ -#define PCI_BASE_ADDRESS_MEM_TYPE_MASK 0x06 +#define PCI_BASE_ADDRESS_SPACE 0x01 /* 0 = memory, 1 = I/O */ +#define PCI_BASE_ADDRESS_SPACE_IO 0x01 +#define PCI_BASE_ADDRESS_SPACE_MEMORY 0x00 + +#define PCI_BASE_ADDRESS_MEM_TYPE_MASK 0x06 #define PCI_BASE_ADDRESS_MEM_TYPE_32 0x00 /* 32 bit address */ #define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02 /* Below 1M [obsolete] */ #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04 /* 64 bit address */ - -#ifndef PCI_BASE_ADDRESS_IO_MASK -#define PCI_BASE_ADDRESS_IO_MASK (~0x03) -#endif -#ifndef PCI_BASE_ADDRESS_MEM_MASK -#define PCI_BASE_ADDRESS_MEM_MASK (~0x0f) -#endif -#define PCI_BASE_ADDRESS_SPACE_IO 0x01 +#define PCI_BASE_ADDRESS_MEM_MASK (~0x0f) +#define PCI_BASE_ADDRESS_IO_MASK (~0x03) #define PCI_ROM_ADDRESS 0x30 /* 32 bits */ #define PCI_ROM_ADDRESS_ENABLE 0x01 /* Write 1 to enable ROM, bits 31..11 are address, @@ -234,90 +227,98 @@ #define PCI_MSI_ADDRESS_HI 8 /* Upper 32 bits (if PCI_MSI_FLAGS_64BIT set) */ #define PCI_MSI_DATA_32 8 /* 16 bits of data for 32-bit devices */ #define PCI_MSI_DATA_64 12 /* 16 bits of data for 64-bit devices */ -/* - * A location on a PCI bus - * - */ -struct pci_loc { - uint16_t busdevfn; + +/** A PCI device ID list entry */ +struct pci_device_id { + /** Name */ + const char *name; + /** PCI vendor ID */ + uint16_t vendor; + /** PCI device ID */ + uint16_t device; }; -/* - * A physical PCI device - * - */ +/** A PCI device */ struct pci_device { - const char * name; - uint32_t membase; /* BAR 1 */ - uint32_t ioaddr; /* first IO BAR */ - uint16_t vendor_id, device_id; - uint16_t class; - uint16_t busdevfn; - uint8_t revision; - uint8_t irq; + /** Generic device */ + struct device dev; + /** Memory base + * + * This is the physical address of the first valid memory BAR. + */ + unsigned long membase; + /** + * I/O address + * + * This is the physical address of the first valid I/O BAR. + */ + unsigned long ioaddr; + /** Vendor ID */ + uint16_t vendor; + /** Device ID */ + uint16_t device; + /** Device class */ + uint32_t class; + /** Interrupt number */ + uint8_t irq; + /** Bus number */ + uint8_t bus; + /** Device and function number */ + uint8_t devfn; + /** Driver for this device */ + struct pci_driver *driver; + /** Driver-private data + * + * Use pci_set_drvdata() and pci_get_drvdata() to access this + * field. + */ void *priv; -}; - -/* - * Useful busdevfn calculations - * - */ -#define PCI_BUS(busdevfn) ( ( uint8_t ) ( ( (busdevfn) >> 8 ) & 0xff ) ) -#define PCI_DEV(busdevfn) ( ( uint8_t ) ( ( (busdevfn) >> 3 ) & 0x1f ) ) -#define PCI_FUNC(busdevfn) ( ( uint8_t ) ( (busdevfn) & 0x07 ) ) -#define PCI_FN0(busdevfn) ( ( uint16_t ) ( (busdevfn) & 0xfff8 ) ) -#define PCI_MAX_BUSDEVFN 0xffff - -/* - * An individual PCI device identified by vendor and device IDs - * - */ -struct pci_id { - unsigned short vendor_id, device_id; + /** Device name */ const char *name; }; +/** A PCI driver */ +struct pci_driver { + /** PCI ID table */ + struct pci_device_id *ids; + /** Number of entries in PCI ID table */ + unsigned int id_count; + /** + * Probe device + * + * @v pci PCI device + * @v id Matching entry in ID table + * @ret rc Return status code + */ + int ( * probe ) ( struct pci_device *pci, + const struct pci_device_id *id ); + /** + * Remove device + * + * @v pci PCI device + */ + void ( * remove ) ( struct pci_device *pci ); +}; + +/** Declare a PCI driver */ +#define __pci_driver __table ( pci_drivers, 01 ) + +#define PCI_DEVFN( slot, func ) ( ( (slot) << 3 ) | (func) ) +#define PCI_SLOT( devfn ) ( ( (devfn) >> 3 ) & 0x1f ) +#define PCI_FUNC( devfn ) ( (devfn) & 0x07 ) + /* * PCI_ROM is used to build up entries in a struct pci_id array. It * is also parsed by parserom.pl to generate Makefile rules and files * for rom-o-matic. */ -#define PCI_ROM( _vendor_id, _device_id, _name, _description ) { \ - .vendor_id = _vendor_id, \ - .device_id = _device_id, \ - .name = _name, \ +#define PCI_ROM( _vendor, _device, _name, _description ) { \ + .vendor = _vendor, \ + .device = _device, \ + .name = _name, \ } -/* - * A PCI driver information table, with a device ID (struct pci_id) - * table and an optional class. - * - * Set the class to something other than PCI_NO_CLASS if the driver - * can handle an entire class of devices. - * - */ -struct pci_driver { - struct pci_id *ids; - unsigned int id_count; - uint16_t class; -}; -#define PCI_NO_CLASS 0 - -/* - * Define a PCI driver. - * - */ -#define PCI_DRIVER( _name, _ids, _class ) \ - static struct pci_driver _name = { \ - .ids = _ids, \ - .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \ - .class = _class, \ - } - -/* - * These are the functions we expect pci_io.c to provide. - * - */ +extern unsigned int pci_max_bus; extern int pci_read_config_byte ( struct pci_device *pci, unsigned int where, uint8_t *value ); extern int pci_write_config_byte ( struct pci_device *pci, unsigned int where, @@ -330,35 +331,29 @@ extern int pci_read_config_dword ( struct pci_device *pci, unsigned int where, uint32_t *value ); extern int pci_write_config_dword ( struct pci_device *pci, unsigned int where, uint32_t value ); -extern unsigned long pci_bus_base ( struct pci_device *pci ); - -/* - * pci_io.c is allowed to overwrite pci_max_bus if it knows what the - * highest bus in the system will be. - * - */ -extern unsigned int pci_max_bus; - -/* - * Functions in pci.c - * - */ extern void adjust_pci_device ( struct pci_device *pci ); extern unsigned long pci_bar_start ( struct pci_device *pci, - unsigned int bar ); -extern unsigned long pci_bar_size ( struct pci_device *pci, unsigned int bar ); + unsigned int reg ); extern int pci_find_capability ( struct pci_device *pci, int capability ); +extern __attribute__ (( deprecated )) unsigned long +pci_bar_size ( struct pci_device *pci, unsigned int reg ); -/* - * PCI bus global definition +/** + * Set PCI driver-private data * + * @v pci PCI device + * @v priv Private data */ -extern struct bus_driver pci_driver; - static inline void pci_set_drvdata ( struct pci_device *pci, void *priv ) { pci->priv = priv; } +/** + * Get PCI driver-private data + * + * @v pci PCI device + * @ret priv Private data + */ static inline void * pci_get_drvdata ( struct pci_device *pci ) { return pci->priv; }