From d7034e1c25a8240a0cc4bed2034c4beb086e9b24 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 27 Sep 2004 22:49:48 +0000 Subject: 2004-09-27 Greg Menke PR 608/bsps * pci/pcibios.c: BusCountPCI(). --- c/src/lib/libbsp/i386/shared/ChangeLog | 6 ++ c/src/lib/libbsp/i386/shared/pci/pcibios.c | 146 ++++++++++++++++++++++------- 2 files changed, 120 insertions(+), 32 deletions(-) diff --git a/c/src/lib/libbsp/i386/shared/ChangeLog b/c/src/lib/libbsp/i386/shared/ChangeLog index 57febd05d2..f355a66934 100644 --- a/c/src/lib/libbsp/i386/shared/ChangeLog +++ b/c/src/lib/libbsp/i386/shared/ChangeLog @@ -1,3 +1,9 @@ +2004-09-27 Greg Menke + + PR 608/bsps + * pci/pcibios.c: BusCountPCI(). + + 2004-04-09 Ralf Corsepius * irq/irq_asm.S: Include instead of . diff --git a/c/src/lib/libbsp/i386/shared/pci/pcibios.c b/c/src/lib/libbsp/i386/shared/pci/pcibios.c index 052be69e23..a62ed4f4bf 100644 --- a/c/src/lib/libbsp/i386/shared/pci/pcibios.c +++ b/c/src/lib/libbsp/i386/shared/pci/pcibios.c @@ -15,27 +15,28 @@ /* * This is simpliest possible PCI BIOS, it assumes that addressing - * is flat and that stack is big enough - */ + * is flat and that stack is big enough + */ + static int pcibInitialized = 0; static unsigned int pcibEntry; /* - * Array to pass data between c and asm parts, at the time of - * writing I am not yet that familiar with extended asm feature - * of gcc. This code is not on performance path, so we can care - * relatively little about performance here + * Array to pass data between c and asm parts, at the time of + * writing I am not yet that familiar with extended asm feature + * of gcc. This code is not on performance path, so we can care + * relatively little about performance here */ static volatile unsigned int pcibExchg[5]; static int pcib_convert_err(int err); /* - * Detects presense of PCI BIOS, returns + * Detects presense of PCI BIOS, returns * error code */ -int +int pcib_init(void) { unsigned char *ucp; @@ -83,7 +84,7 @@ pcib_init(void) pcibExchg[0] = *(unsigned int *)ucp; - asm (" pusha"); /* Push all registers */ + asm (" pusha"); /* Push all registers */ asm (" movl pcibExchg, %edi"); /* Move entry point to esi */ asm (" movl $0x49435024, %eax"); /* Move signature to eax */ asm (" xorl %ebx, %ebx"); /* Zero ebx */ @@ -106,7 +107,7 @@ pcib_init(void) /* Let us check whether PCI bios is present */ pcibExchg[0] = pcibEntry; - + asm(" pusha"); asm(" movl pcibExchg, %edi"); asm(" movb $0xb1, %ah"); @@ -132,13 +133,13 @@ pcib_init(void) } /* Success */ - + pcibInitialized = 1; return PCIB_ERR_SUCCESS; } -/* - * Find specified device and return its signature: combination +/* + * Find specified device and return its signature: combination * of bus number, device number and function number */ int @@ -172,8 +173,8 @@ pcib_find_by_devid(int vendorId, int devId, int idx, int *sig) return pcib_convert_err((pcibExchg[0] >> 8) & 0xff); } -/* - * Find specified class code return device signature: combination +/* + * Find specified class code return device signature: combination * of bus number, device number and function number */ int @@ -209,11 +210,72 @@ pcib_find_by_class(int classCode, int idx, int *sig) return PCIB_ERR_SUCCESS; } - + #define PCI_MULTI_FUNCTION 0x80 #define PCI_MAX_DEVICES 16 #define PCI_MAX_FUNCTIONS 8 +#define PCI_VENDOR_ID 0x00 /* 16 bits */ +#define PCI_DEVICE_ID 0x02 /* 16 bits */ +#define PCI_CLASS_REVISION 0x08 +#define PCI_HEADER_TYPE 0x0e +#define PCI_SUBORDINATE_BUS 0x1a + +#define PCI_CLASS_BRIDGE_PCI 0x0604 + +static unsigned8 ucBusCount = 0xff; + + +int +BusCountPCI() +{ + if( ucBusCount == 0xff ) + { + unsigned char bus,dev,hd; + unsigned int d; + int sig; + + ucBusCount = 0; + + for(bus=0; bus< 0xff; bus++) + { + for(dev=0; dev> 16) == PCI_CLASS_BRIDGE_PCI ) + { + pcib_conf_read8(sig, PCI_SUBORDINATE_BUS, &hd); + + if( hd > ucBusCount ) + ucBusCount = hd; + } + } + } + + } + + if( ucBusCount == 0 ) + { + printk("BusCountPCI() found 0 busses, assuming 1\n"); + ucBusCount = 1; + } + else if( ucBusCount == 0xff ) + { + printk("BusCountPCI() found 0xff busses, assuming 1\n"); + ucBusCount = 1; + } + } + + return ucBusCount; +} + + int BSP_pciFindDevice( unsigned short vendorid, unsigned short deviceid, int instance, int *pbus, int *pdev, int *pfun ) @@ -223,42 +285,42 @@ BSP_pciFindDevice( unsigned short vendorid, unsigned short deviceid, unsigned short s; unsigned char bus,dev,fun,hd; - for (bus=0; bus> 8) & 0xff); } + -/* +/* * Read byte from config space */ int @@ -334,8 +400,9 @@ pcib_conf_read8(int sig, int off, unsigned char *data) return PCIB_ERR_SUCCESS; } + -/* +/* * Read word from config space */ int @@ -371,8 +438,9 @@ pcib_conf_read16(int sig, int off, unsigned short *data) return PCIB_ERR_SUCCESS; } + -/* +/* * Read dword from config space */ int @@ -408,8 +476,9 @@ pcib_conf_read32(int sig, int off, unsigned int *data) return PCIB_ERR_SUCCESS; } + -/* +/* * Write byte into config space */ int @@ -440,7 +509,7 @@ pcib_conf_write8(int sig, int off, unsigned int data) return pcib_convert_err((pcibExchg[0] >> 8) & 0xff); } -/* +/* * Write word into config space */ int @@ -470,8 +539,10 @@ pcib_conf_write16(int sig, int off, unsigned int data) return pcib_convert_err((pcibExchg[0] >> 8) & 0xff); } + -/* + +/* * Write dword into config space */ int @@ -501,6 +572,7 @@ pcib_conf_write32(int sig, int off, unsigned int data) return pcib_convert_err((pcibExchg[0] >> 8) & 0xff); } + static int pcib_convert_err(int err) @@ -522,3 +594,13 @@ pcib_convert_err(int err) } return PCIB_ERR_NOFUNC; } + + + + + + + + + + -- cgit v1.2.3