mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-05 23:23:13 +00:00
2004-09-27 Greg Menke <gregory.menke@gsfc.nasa.gov>
PR 608/bsps * pci/pcibios.c: BusCountPCI().
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
2004-09-27 Greg Menke <gregory.menke@gsfc.nasa.gov>
|
||||||
|
|
||||||
|
PR 608/bsps
|
||||||
|
* pci/pcibios.c: BusCountPCI().
|
||||||
|
|
||||||
|
|
||||||
2004-04-09 Ralf Corsepius <ralf_corsepius@rtems.org>
|
2004-04-09 Ralf Corsepius <ralf_corsepius@rtems.org>
|
||||||
|
|
||||||
* irq/irq_asm.S: Include <rtems/asm.h> instead of <asm.h>.
|
* irq/irq_asm.S: Include <rtems/asm.h> instead of <asm.h>.
|
||||||
|
|||||||
@@ -15,27 +15,28 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* This is simpliest possible PCI BIOS, it assumes that addressing
|
* 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 int pcibInitialized = 0;
|
||||||
static unsigned int pcibEntry;
|
static unsigned int pcibEntry;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Array to pass data between c and asm parts, at the time of
|
* Array to pass data between c and asm parts, at the time of
|
||||||
* writing I am not yet that familiar with extended asm feature
|
* writing I am not yet that familiar with extended asm feature
|
||||||
* of gcc. This code is not on performance path, so we can care
|
* of gcc. This code is not on performance path, so we can care
|
||||||
* relatively little about performance here
|
* relatively little about performance here
|
||||||
*/
|
*/
|
||||||
static volatile unsigned int pcibExchg[5];
|
static volatile unsigned int pcibExchg[5];
|
||||||
|
|
||||||
static int pcib_convert_err(int err);
|
static int pcib_convert_err(int err);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Detects presense of PCI BIOS, returns
|
* Detects presense of PCI BIOS, returns
|
||||||
* error code
|
* error code
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
pcib_init(void)
|
pcib_init(void)
|
||||||
{
|
{
|
||||||
unsigned char *ucp;
|
unsigned char *ucp;
|
||||||
@@ -83,7 +84,7 @@ pcib_init(void)
|
|||||||
|
|
||||||
pcibExchg[0] = *(unsigned int *)ucp;
|
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 pcibExchg, %edi"); /* Move entry point to esi */
|
||||||
asm (" movl $0x49435024, %eax"); /* Move signature to eax */
|
asm (" movl $0x49435024, %eax"); /* Move signature to eax */
|
||||||
asm (" xorl %ebx, %ebx"); /* Zero ebx */
|
asm (" xorl %ebx, %ebx"); /* Zero ebx */
|
||||||
@@ -106,7 +107,7 @@ pcib_init(void)
|
|||||||
|
|
||||||
/* Let us check whether PCI bios is present */
|
/* Let us check whether PCI bios is present */
|
||||||
pcibExchg[0] = pcibEntry;
|
pcibExchg[0] = pcibEntry;
|
||||||
|
|
||||||
asm(" pusha");
|
asm(" pusha");
|
||||||
asm(" movl pcibExchg, %edi");
|
asm(" movl pcibExchg, %edi");
|
||||||
asm(" movb $0xb1, %ah");
|
asm(" movb $0xb1, %ah");
|
||||||
@@ -132,13 +133,13 @@ pcib_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Success */
|
/* Success */
|
||||||
|
|
||||||
pcibInitialized = 1;
|
pcibInitialized = 1;
|
||||||
return PCIB_ERR_SUCCESS;
|
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
|
* of bus number, device number and function number
|
||||||
*/
|
*/
|
||||||
int
|
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);
|
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
|
* of bus number, device number and function number
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@@ -209,11 +210,72 @@ pcib_find_by_class(int classCode, int idx, int *sig)
|
|||||||
|
|
||||||
return PCIB_ERR_SUCCESS;
|
return PCIB_ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PCI_MULTI_FUNCTION 0x80
|
#define PCI_MULTI_FUNCTION 0x80
|
||||||
#define PCI_MAX_DEVICES 16
|
#define PCI_MAX_DEVICES 16
|
||||||
#define PCI_MAX_FUNCTIONS 8
|
#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<PCI_MAX_DEVICES; dev++)
|
||||||
|
{
|
||||||
|
sig = PCIB_DEVSIG_MAKE(bus,dev,0);
|
||||||
|
pcib_conf_read32(sig, PCI_VENDOR_ID, &d);
|
||||||
|
|
||||||
|
if( d != -1 )
|
||||||
|
{
|
||||||
|
pcib_conf_read32(sig, PCI_CLASS_REVISION, &d);
|
||||||
|
|
||||||
|
if( (d >> 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
|
int
|
||||||
BSP_pciFindDevice( unsigned short vendorid, unsigned short deviceid,
|
BSP_pciFindDevice( unsigned short vendorid, unsigned short deviceid,
|
||||||
int instance, int *pbus, int *pdev, int *pfun )
|
int instance, int *pbus, int *pdev, int *pfun )
|
||||||
@@ -223,42 +285,42 @@ BSP_pciFindDevice( unsigned short vendorid, unsigned short deviceid,
|
|||||||
unsigned short s;
|
unsigned short s;
|
||||||
unsigned char bus,dev,fun,hd;
|
unsigned char bus,dev,fun,hd;
|
||||||
|
|
||||||
for (bus=0; bus<BusCountPCI(); bus++)
|
for (bus=0; bus<BusCountPCI(); bus++)
|
||||||
{
|
{
|
||||||
for (dev=0; dev<PCI_MAX_DEVICES; dev++)
|
for (dev=0; dev<PCI_MAX_DEVICES; dev++)
|
||||||
{
|
{
|
||||||
sig = PCIB_DEVSIG_MAKE(bus,dev,0);
|
sig = PCIB_DEVSIG_MAKE(bus,dev,0);
|
||||||
|
|
||||||
/* pci_read_config_byte(bus,dev,0, PCI_HEADER_TYPE, &hd); */
|
/* pci_read_config_byte(bus,dev,0, PCI_HEADER_TYPE, &hd); */
|
||||||
pcib_conf_read8(sig, 0xe, &hd);
|
pcib_conf_read8(sig, 0xe, &hd);
|
||||||
|
|
||||||
hd = (hd & PCI_MULTI_FUNCTION ? PCI_MAX_FUNCTIONS : 1);
|
hd = (hd & PCI_MULTI_FUNCTION ? PCI_MAX_FUNCTIONS : 1);
|
||||||
|
|
||||||
for (fun=0; fun<hd; fun++) {
|
for (fun=0; fun<hd; fun++) {
|
||||||
/*
|
/*
|
||||||
* The last devfn id/slot is special; must skip it
|
* The last devfn id/slot is special; must skip it
|
||||||
*/
|
*/
|
||||||
if( PCI_MAX_DEVICES-1 == dev && PCI_MAX_FUNCTIONS-1 == fun )
|
if( PCI_MAX_DEVICES-1 == dev && PCI_MAX_FUNCTIONS-1 == fun )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*pci_read_config_dword(bus,dev,fun,PCI_VENDOR_ID,&d); */
|
/*pci_read_config_dword(bus,dev,fun,PCI_VENDOR_ID,&d); */
|
||||||
pcib_conf_read32(sig, 0, &d);
|
pcib_conf_read32(sig, 0, &d);
|
||||||
if( d == -1 )
|
if( d == -1 )
|
||||||
continue;
|
continue;
|
||||||
#ifdef PCI_DEBUG
|
#ifdef PCI_DEBUG
|
||||||
printk("BSP_pciFindDevice: found 0x%08x at %d/%d/%d\n",d,bus,dev,fun);
|
printk("BSP_pciFindDevice: found 0x%08x at %d/%d/%d\n",d,bus,dev,fun);
|
||||||
#endif
|
#endif
|
||||||
/* pci_read_config_word(bus,dev,fun,PCI_VENDOR_ID,&s); */
|
/* pci_read_config_word(bus,dev,fun,PCI_VENDOR_ID,&s); */
|
||||||
pcib_conf_read16(sig, 0, &s);
|
pcib_conf_read16(sig, 0, &s);
|
||||||
if (vendorid != s)
|
if (vendorid != s)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* pci_read_config_word(bus,dev,fun,PCI_DEVICE_ID,&s); */
|
/* pci_read_config_word(bus,dev,fun,PCI_DEVICE_ID,&s); */
|
||||||
pcib_conf_read16(sig, 0x2, &s);
|
pcib_conf_read16(sig, 0x2, &s);
|
||||||
if (deviceid == s) {
|
if (deviceid == s) {
|
||||||
if (instance--) continue;
|
if (instance--) continue;
|
||||||
*pbus=bus;
|
*pbus=bus;
|
||||||
*pdev=dev;
|
*pdev=dev;
|
||||||
*pfun=fun;
|
*pfun=fun;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -268,7 +330,10 @@ BSP_pciFindDevice( unsigned short vendorid, unsigned short deviceid,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
* Generate Special Cycle
|
* Generate Special Cycle
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@@ -297,8 +362,9 @@ pcib_special_cycle(int busNo, int data)
|
|||||||
|
|
||||||
return pcib_convert_err((pcibExchg[0] >> 8) & 0xff);
|
return pcib_convert_err((pcibExchg[0] >> 8) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read byte from config space
|
* Read byte from config space
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@@ -334,8 +400,9 @@ pcib_conf_read8(int sig, int off, unsigned char *data)
|
|||||||
|
|
||||||
return PCIB_ERR_SUCCESS;
|
return PCIB_ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read word from config space
|
* Read word from config space
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@@ -371,8 +438,9 @@ pcib_conf_read16(int sig, int off, unsigned short *data)
|
|||||||
|
|
||||||
return PCIB_ERR_SUCCESS;
|
return PCIB_ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read dword from config space
|
* Read dword from config space
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@@ -408,8 +476,9 @@ pcib_conf_read32(int sig, int off, unsigned int *data)
|
|||||||
|
|
||||||
return PCIB_ERR_SUCCESS;
|
return PCIB_ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write byte into config space
|
* Write byte into config space
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@@ -440,7 +509,7 @@ pcib_conf_write8(int sig, int off, unsigned int data)
|
|||||||
return pcib_convert_err((pcibExchg[0] >> 8) & 0xff);
|
return pcib_convert_err((pcibExchg[0] >> 8) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write word into config space
|
* Write word into config space
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@@ -470,8 +539,10 @@ pcib_conf_write16(int sig, int off, unsigned int data)
|
|||||||
|
|
||||||
return pcib_convert_err((pcibExchg[0] >> 8) & 0xff);
|
return pcib_convert_err((pcibExchg[0] >> 8) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
/*
|
||||||
* Write dword into config space
|
* Write dword into config space
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@@ -501,6 +572,7 @@ pcib_conf_write32(int sig, int off, unsigned int data)
|
|||||||
|
|
||||||
return pcib_convert_err((pcibExchg[0] >> 8) & 0xff);
|
return pcib_convert_err((pcibExchg[0] >> 8) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pcib_convert_err(int err)
|
pcib_convert_err(int err)
|
||||||
@@ -522,3 +594,13 @@ pcib_convert_err(int err)
|
|||||||
}
|
}
|
||||||
return PCIB_ERR_NOFUNC;
|
return PCIB_ERR_NOFUNC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user