2005-03-14 Joel Sherrill <joel@OARcorp.com>

* pci/pci.c, pci/pci.h, pci/pcifinddevice.c: Continue PCI API
	unification. All use pci_find_device(). Also reformat to remove tabs.
This commit is contained in:
Joel Sherrill
2005-03-14 21:43:30 +00:00
parent 48e329fbd6
commit 0943f48db1
4 changed files with 471 additions and 464 deletions

View File

@@ -1,3 +1,8 @@
2005-03-14 Joel Sherrill <joel@OARcorp.com>
* pci/pci.c, pci/pci.h, pci/pcifinddevice.c: Continue PCI API
unification. All use pci_find_device(). Also reformat to remove tabs.
2005-03-04 Joel Sherrill <joel@OARcorp.com> 2005-03-04 Joel Sherrill <joel@OARcorp.com>
* pci/pci.c, pci/pcifinddevice.c, startup/bspstart.c: Make PCI * pci/pci.c, pci/pcifinddevice.c, startup/bspstart.c: Make PCI

View File

@@ -43,9 +43,13 @@
unsigned char ucMaxPCIBus; unsigned char ucMaxPCIBus;
static int static int
indirect_pci_read_config_byte(unsigned char bus, unsigned char slot, indirect_pci_read_config_byte(
unsigned char bus,
unsigned char slot,
unsigned char function, unsigned char function,
unsigned char offset, unsigned char *val) { unsigned char offset,
unsigned char *val
) {
out_be32((unsigned int*) pci.pci_config_addr, out_be32((unsigned int*) pci.pci_config_addr,
0x80|(bus<<8)|(PCI_DEVFN(slot,function)<<16)|((offset&~3)<<24)); 0x80|(bus<<8)|(PCI_DEVFN(slot,function)<<16)|((offset&~3)<<24));
*val = in_8(pci.pci_config_data + (offset&3)); *val = in_8(pci.pci_config_data + (offset&3));
@@ -53,11 +57,17 @@ indirect_pci_read_config_byte(unsigned char bus, unsigned char slot,
} }
static int static int
indirect_pci_read_config_word(unsigned char bus, unsigned char slot, indirect_pci_read_config_word(
unsigned char bus,
unsigned char slot,
unsigned char function, unsigned char function,
unsigned char offset, unsigned short *val) { unsigned char offset,
unsigned short *val
) {
*val = 0xffff; *val = 0xffff;
if (offset&1) return PCIBIOS_BAD_REGISTER_NUMBER; if (offset&1)
return PCIBIOS_BAD_REGISTER_NUMBER;
out_be32((unsigned int*) pci.pci_config_addr, out_be32((unsigned int*) pci.pci_config_addr,
0x80|(bus<<8)|(PCI_DEVFN(slot,function)<<16)|((offset&~3)<<24)); 0x80|(bus<<8)|(PCI_DEVFN(slot,function)<<16)|((offset&~3)<<24));
*val = in_le16((volatile unsigned short *)(pci.pci_config_data + (offset&3))); *val = in_le16((volatile unsigned short *)(pci.pci_config_data + (offset&3)));
@@ -65,11 +75,17 @@ indirect_pci_read_config_word(unsigned char bus, unsigned char slot,
} }
static int static int
indirect_pci_read_config_dword(unsigned char bus, unsigned char slot, indirect_pci_read_config_dword(
unsigned char bus,
unsigned char slot,
unsigned char function, unsigned char function,
unsigned char offset, unsigned int *val) { unsigned char offset,
unsigned int *val
) {
*val = 0xffffffff; *val = 0xffffffff;
if (offset&3) return PCIBIOS_BAD_REGISTER_NUMBER; if (offset&3)
return PCIBIOS_BAD_REGISTER_NUMBER;
out_be32((unsigned int*) pci.pci_config_addr, out_be32((unsigned int*) pci.pci_config_addr,
0x80|(bus<<8)|(PCI_DEVFN(slot,function)<<16)|(offset<<24)); 0x80|(bus<<8)|(PCI_DEVFN(slot,function)<<16)|(offset<<24));
*val = in_le32((volatile unsigned int *)pci.pci_config_data); *val = in_le32((volatile unsigned int *)pci.pci_config_data);
@@ -77,9 +93,13 @@ indirect_pci_read_config_dword(unsigned char bus, unsigned char slot,
} }
static int static int
indirect_pci_write_config_byte(unsigned char bus, unsigned char slot, indirect_pci_write_config_byte(
unsigned char bus,
unsigned char slot,
unsigned char function, unsigned char function,
unsigned char offset, unsigned char val) { unsigned char offset,
unsigned char val
) {
out_be32((unsigned int*) pci.pci_config_addr, out_be32((unsigned int*) pci.pci_config_addr,
0x80|(bus<<8)|(PCI_DEVFN(slot,function)<<16)|((offset&~3)<<24)); 0x80|(bus<<8)|(PCI_DEVFN(slot,function)<<16)|((offset&~3)<<24));
out_8(pci.pci_config_data + (offset&3), val); out_8(pci.pci_config_data + (offset&3), val);
@@ -87,10 +107,16 @@ indirect_pci_write_config_byte(unsigned char bus, unsigned char slot,
} }
static int static int
indirect_pci_write_config_word(unsigned char bus, unsigned char slot, indirect_pci_write_config_word(
unsigned char bus,
unsigned char slot,
unsigned char function, unsigned char function,
unsigned char offset, unsigned short val) { unsigned char offset,
if (offset&1) return PCIBIOS_BAD_REGISTER_NUMBER; unsigned short val
) {
if (offset&1)
return PCIBIOS_BAD_REGISTER_NUMBER;
out_be32((unsigned int*) pci.pci_config_addr, out_be32((unsigned int*) pci.pci_config_addr,
0x80|(bus<<8)|(PCI_DEVFN(slot,function)<<16)|((offset&~3)<<24)); 0x80|(bus<<8)|(PCI_DEVFN(slot,function)<<16)|((offset&~3)<<24));
out_le16((volatile unsigned short *)(pci.pci_config_data + (offset&3)), val); out_le16((volatile unsigned short *)(pci.pci_config_data + (offset&3)), val);
@@ -98,10 +124,15 @@ indirect_pci_write_config_word(unsigned char bus, unsigned char slot,
} }
static int static int
indirect_pci_write_config_dword(unsigned char bus, unsigned char slot, indirect_pci_write_config_dword(
unsigned char bus,
unsigned char slot,
unsigned char function, unsigned char function,
unsigned char offset, unsigned int val) { unsigned char offset,
if (offset&3) return PCIBIOS_BAD_REGISTER_NUMBER; unsigned int val
) {
if (offset&3)
return PCIBIOS_BAD_REGISTER_NUMBER;
out_be32((unsigned int*) pci.pci_config_addr, out_be32((unsigned int*) pci.pci_config_addr,
0x80|(bus<<8)|(PCI_DEVFN(slot,function)<<16)|(offset<<24)); 0x80|(bus<<8)|(PCI_DEVFN(slot,function)<<16)|(offset<<24));
out_le32((volatile unsigned int *)pci.pci_config_data, val); out_le32((volatile unsigned int *)pci.pci_config_data, val);
@@ -117,14 +148,20 @@ const pci_config_access_functions pci_indirect_functions = {
indirect_pci_write_config_dword indirect_pci_write_config_dword
}; };
pci_config BSP_pci_configuration = {(volatile unsigned char*)PCI_CONFIG_ADDR, pci_config BSP_pci_configuration = {
(volatile unsigned char*)PCI_CONFIG_ADDR,
(volatile unsigned char*)PCI_CONFIG_DATA, (volatile unsigned char*)PCI_CONFIG_DATA,
&pci_indirect_functions}; &pci_indirect_functions
};
static int static int
direct_pci_read_config_byte(unsigned char bus, unsigned char slot, direct_pci_read_config_byte(
unsigned char bus,
unsigned char slot,
unsigned char function, unsigned char function,
unsigned char offset, unsigned char *val) { unsigned char offset,
unsigned char *val
) {
if (bus != 0 || (1<<slot & 0xff8007fe)) { if (bus != 0 || (1<<slot & 0xff8007fe)) {
*val=0xff; *val=0xff;
return PCIBIOS_DEVICE_NOT_FOUND; return PCIBIOS_DEVICE_NOT_FOUND;
@@ -135,14 +172,19 @@ direct_pci_read_config_byte(unsigned char bus, unsigned char slot,
} }
static int static int
direct_pci_read_config_word(unsigned char bus, unsigned char slot, direct_pci_read_config_word(
unsigned char bus,
unsigned char slot,
unsigned char function, unsigned char function,
unsigned char offset, unsigned short *val) { unsigned char offset,
unsigned short *val
) {
*val = 0xffff; *val = 0xffff;
if (offset&1) return PCIBIOS_BAD_REGISTER_NUMBER; if (offset&1)
if (bus != 0 || (1<<slot & 0xff8007fe)) { return PCIBIOS_BAD_REGISTER_NUMBER;
if (bus != 0 || (1<<slot & 0xff8007fe))
return PCIBIOS_DEVICE_NOT_FOUND; return PCIBIOS_DEVICE_NOT_FOUND;
}
*val=in_le16((volatile unsigned short *) *val=in_le16((volatile unsigned short *)
(pci.pci_config_data + ((1<<slot)&~1) (pci.pci_config_data + ((1<<slot)&~1)
+ (function<<8) + offset)); + (function<<8) + offset));
@@ -150,14 +192,19 @@ direct_pci_read_config_word(unsigned char bus, unsigned char slot,
} }
static int static int
direct_pci_read_config_dword(unsigned char bus, unsigned char slot, direct_pci_read_config_dword(
unsigned char bus,
unsigned char slot,
unsigned char function, unsigned char function,
unsigned char offset, unsigned int *val) { unsigned char offset,
unsigned int *val
) {
*val = 0xffffffff; *val = 0xffffffff;
if (offset&3) return PCIBIOS_BAD_REGISTER_NUMBER; if (offset&3)
if (bus != 0 || (1<<slot & 0xff8007fe)) { return PCIBIOS_BAD_REGISTER_NUMBER;
if (bus != 0 || (1<<slot & 0xff8007fe))
return PCIBIOS_DEVICE_NOT_FOUND; return PCIBIOS_DEVICE_NOT_FOUND;
}
*val=in_le32((volatile unsigned int *) *val=in_le32((volatile unsigned int *)
(pci.pci_config_data + ((1<<slot)&~1) (pci.pci_config_data + ((1<<slot)&~1)
+ (function<<8) + offset)); + (function<<8) + offset));
@@ -165,12 +212,16 @@ direct_pci_read_config_dword(unsigned char bus, unsigned char slot,
} }
static int static int
direct_pci_write_config_byte(unsigned char bus, unsigned char slot, direct_pci_write_config_byte(
unsigned char bus,
unsigned char slot,
unsigned char function, unsigned char function,
unsigned char offset, unsigned char val) { unsigned char offset,
if (bus != 0 || (1<<slot & 0xff8007fe)) { unsigned char val
) {
if (bus != 0 || (1<<slot & 0xff8007fe))
return PCIBIOS_DEVICE_NOT_FOUND; return PCIBIOS_DEVICE_NOT_FOUND;
}
out_8(pci.pci_config_data + ((1<<slot)&~1) out_8(pci.pci_config_data + ((1<<slot)&~1)
+ (function<<8) + offset, + (function<<8) + offset,
val); val);
@@ -178,13 +229,18 @@ direct_pci_write_config_byte(unsigned char bus, unsigned char slot,
} }
static int static int
direct_pci_write_config_word(unsigned char bus, unsigned char slot, direct_pci_write_config_word(
unsigned char bus,
unsigned char slot,
unsigned char function, unsigned char function,
unsigned char offset, unsigned short val) { unsigned char offset,
if (offset&1) return PCIBIOS_BAD_REGISTER_NUMBER; unsigned short val
if (bus != 0 || (1<<slot & 0xff8007fe)) { ) {
if (offset&1)
return PCIBIOS_BAD_REGISTER_NUMBER;
if (bus != 0 || (1<<slot & 0xff8007fe))
return PCIBIOS_DEVICE_NOT_FOUND; return PCIBIOS_DEVICE_NOT_FOUND;
}
out_le16((volatile unsigned short *) out_le16((volatile unsigned short *)
(pci.pci_config_data + ((1<<slot)&~1) (pci.pci_config_data + ((1<<slot)&~1)
+ (function<<8) + offset), + (function<<8) + offset),
@@ -193,13 +249,18 @@ direct_pci_write_config_word(unsigned char bus, unsigned char slot,
} }
static int static int
direct_pci_write_config_dword(unsigned char bus, unsigned char slot, direct_pci_write_config_dword(
unsigned char bus,
unsigned char slot,
unsigned char function, unsigned char function,
unsigned char offset, unsigned int val) { unsigned char offset,
if (offset&3) return PCIBIOS_BAD_REGISTER_NUMBER; unsigned int val
if (bus != 0 || (1<<slot & 0xff8007fe)) { ) {
if (offset&3)
return PCIBIOS_BAD_REGISTER_NUMBER;
if (bus != 0 || (1<<slot & 0xff8007fe))
return PCIBIOS_DEVICE_NOT_FOUND; return PCIBIOS_DEVICE_NOT_FOUND;
}
out_le32((volatile unsigned int *) out_le32((volatile unsigned int *)
(pci.pci_config_data + ((1<<slot)&~1) (pci.pci_config_data + ((1<<slot)&~1)
+ (function<<8) + offset), + (function<<8) + offset),
@@ -217,7 +278,8 @@ const pci_config_access_functions pci_direct_functions = {
}; };
#define PRINT_MSG() \ #define PRINT_MSG() \
printk("pci : Device %d:%02x routed to interrupt_line %d\n", pbus, pslot, int_name ) printk("pci : Device %d:%02x routed to interrupt_line %d\n", \
pbus, pslot, int_name )
/* /*
** Validate a test interrupt name and print a warning if its not one of ** Validate a test interrupt name and print a warning if its not one of
@@ -229,41 +291,39 @@ static int test_intname(
int pslot, int pslot,
int int_pin, int int_pin,
int int_name int int_name
) ) {
{
int j, k; int j, k;
int _nopin= -1, _noname= -1; int _nopin= -1, _noname= -1;
for(j=0; row->pin_route[j].pin > -1; j++) for (j=0; row->pin_route[j].pin > -1; j++) {
{ if ( row->pin_route[j].pin == int_pin ) {
if( row->pin_route[j].pin == int_pin )
{
_nopin = 0; _nopin = 0;
for(k=0; k<4 && row->pin_route[j].int_name[k] > -1; k++ ) for (k=0; k<4 && row->pin_route[j].int_name[k] > -1; k++ ) {
{ if ( row->pin_route[j].int_name[k] == int_name ) {
if( row->pin_route[j].int_name[k] == int_name ){ _noname=0; break; } _noname=0; break;
}
} }
break; break;
} }
} }
if( _nopin ) if ( _nopin ) {
{ printk("pci : Device %d:%02x supplied a bogus interrupt_pin %d\n",
printk("pci : Device %d:%02x supplied a bogus interrupt_pin %d\n", pbus, pslot, int_pin ); pbus, pslot, int_pin );
return -1; return -1;
} } else {
else if ( _noname )
{ printk("pci : Device %d:%02x supplied a suspicious interrupt_line %d,"
if( _noname ) " using it anyway\n", pbus, pslot, int_name );
printk("pci : Device %d:%02x supplied a suspicious interrupt_line %d, using it anyway\n", pbus, pslot, int_name );
} }
return 0; return 0;
} }
struct pcibridge struct pcibridge
{ {
int bus,slot; int bus;
int slot;
}; };
static int FindPCIbridge( int mybus, struct pcibridge *pb ) static int FindPCIbridge( int mybus, struct pcibridge *pb )
@@ -272,28 +332,25 @@ static int FindPCIbridge( int mybus, struct pcibridge *pb )
uint8_t bussec, buspri; uint8_t bussec, buspri;
uint16_t devid, vendorid, dclass; uint16_t devid, vendorid, dclass;
for(pbus=0; pbus< BusCountPCI(); pbus++) for(pbus=0; pbus< BusCountPCI(); pbus++) {
{ for(pslot=0; pslot< PCI_MAX_DEVICES; pslot++) {
for(pslot=0; pslot< PCI_MAX_DEVICES; pslot++)
{
pci_read_config_word(pbus, pslot, 0, PCI_DEVICE_ID, &devid); pci_read_config_word(pbus, pslot, 0, PCI_DEVICE_ID, &devid);
if( devid == 0xffff ) continue; if ( devid == 0xffff ) continue;
pci_read_config_word(pbus, pslot, 0, PCI_DEVICE_ID, &vendorid); pci_read_config_word(pbus, pslot, 0, PCI_DEVICE_ID, &vendorid);
if( vendorid == 0xffff ) continue; if ( vendorid == 0xffff ) continue;
pci_read_config_word(pbus, pslot, 0, PCI_CLASS_DEVICE, &dclass); pci_read_config_word(pbus, pslot, 0, PCI_CLASS_DEVICE, &dclass);
if( dclass == PCI_CLASS_BRIDGE_PCI ) if ( dclass == PCI_CLASS_BRIDGE_PCI ) {
{
pci_read_config_byte(pbus, pslot, 0, PCI_PRIMARY_BUS, &buspri); pci_read_config_byte(pbus, pslot, 0, PCI_PRIMARY_BUS, &buspri);
pci_read_config_byte(pbus, pslot, 0, PCI_SECONDARY_BUS, &bussec); pci_read_config_byte(pbus, pslot, 0, PCI_SECONDARY_BUS, &bussec);
#if 0 #if 0
printk("pci : Found bridge at %d:%d, mybus %d, pribus %d, secbus %d ", pbus, pslot, mybus, buspri, bussec ); printk("pci : Found bridge at %d:%d, mybus %d, pribus %d, secbus %d ",
pbus, pslot, mybus, buspri, bussec );
#endif #endif
if( bussec == mybus ) if ( bussec == mybus ) {
{
#if 0 #if 0
printk("match\n"); printk("match\n");
#endif #endif
@@ -320,17 +377,15 @@ void FixupPCI( const struct _int_map *bspmap, int (*swizzler)(int,int) )
int ismatch, i, j, pbus, pslot, int_pin, int_name; int ismatch, i, j, pbus, pslot, int_pin, int_name;
/* /*
** If the device has a non-zero INTERRUPT_PIN, assign a bsp-specific * If the device has a non-zero INTERRUPT_PIN, assign a bsp-specific
** INTERRUPT_NAME if one isn't already in place. Then, drivers can * INTERRUPT_NAME if one isn't already in place. Then, drivers can
** trivially use INTERRUPT_NAME to hook up with devices. * trivially use INTERRUPT_NAME to hook up with devices.
*/ */
for(pbus=0; pbus< BusCountPCI(); pbus++) for (pbus=0; pbus< BusCountPCI(); pbus++) {
{ for (pslot=0; pslot< PCI_MAX_DEVICES; pslot++) {
for(pslot=0; pslot< PCI_MAX_DEVICES; pslot++)
{
pci_read_config_word(pbus, pslot, 0, PCI_DEVICE_ID, &devid); pci_read_config_word(pbus, pslot, 0, PCI_DEVICE_ID, &devid);
if( devid == 0xffff ) continue; if ( devid == 0xffff ) continue;
/* got a device */ /* got a device */
@@ -340,7 +395,8 @@ void FixupPCI( const struct _int_map *bspmap, int (*swizzler)(int,int) )
pci_read_config_byte( pbus, pslot, 0, PCI_INTERRUPT_LINE, &cvalue); pci_read_config_byte( pbus, pslot, 0, PCI_INTERRUPT_LINE, &cvalue);
int_name = cvalue; int_name = cvalue;
/* printk("pci : device %d:%02x devid %04x, intpin %d, intline %d\n", pbus, pslot, devid, int_pin, int_name ); */ /* printk("pci : device %d:%02x devid %04x, intpin %d, intline %d\n",
pbus, pslot, devid, int_pin, int_name ); */
#if 0 #if 0
{ {
@@ -354,165 +410,143 @@ void FixupPCI( const struct _int_map *bspmap, int (*swizzler)(int,int) )
pci_read_config_byte(pbus,pslot,0,PCI_CACHE_LINE_SIZE, &csize ); pci_read_config_byte(pbus,pslot,0,PCI_CACHE_LINE_SIZE, &csize );
printk("pci : device %d:%02x cmd %04X, stat %04X, latency %d, sec_latency %d, clsize %d\n", pbus, pslot, printk("pci : device %d:%02x cmd %04X, stat %04X, latency %d, "
cmd, " sec_latency %d, clsize %d\n", pbus, pslot, cmd, stat,
stat, lat, seclat, csize);
lat,
seclat,
csize);
} }
#endif #endif
if( int_pin > 0 ) if ( int_pin > 0 ) {
{
ismatch = 0; ismatch = 0;
/* /*
** first run thru the bspmap table and see if we have an explicit configuration * first run thru the bspmap table and see if we have an
* explicit configuration
*/ */
for(i=0; bspmap[i].bus > -1; i++) for (i=0; bspmap[i].bus > -1; i++) {
{ if ( bspmap[i].bus == pbus && bspmap[i].slot == pslot ) {
if( bspmap[i].bus == pbus && bspmap[i].slot == pslot )
{
ismatch = -1; ismatch = -1;
/* we have a record in the table that gives specific /* we have a record in the table that gives specific
* pins and interrupts for devices in this slot */ * pins and interrupts for devices in this slot */
if( int_name == 255 ) if ( int_name == 255 ) {
{ /* find the vector associated with whatever pin the
/* find the vector associated with whatever pin the device gives us */ * device gives us
for( int_name=-1, j=0; bspmap[i].pin_route[j].pin > -1; j++ ) */
{ for ( int_name=-1, j=0; bspmap[i].pin_route[j].pin > -1; j++ ) {
if( bspmap[i].pin_route[j].pin == int_pin ) if ( bspmap[i].pin_route[j].pin == int_pin ) {
{
int_name = bspmap[i].pin_route[j].int_name[0]; int_name = bspmap[i].pin_route[j].int_name[0];
break; break;
} }
} }
if( int_name == -1 ) if ( int_name == -1 ) {
{ printk("pci : Unable to resolve device %d:%d w/ swizzled int "
printk("pci : Unable to resolve device %d:%d w/ swizzled int pin %i to an interrupt_line.\n", pbus, pslot, int_pin ); "pin %i to an interrupt_line.\n", pbus, pslot, int_pin );
} } else {
else
{
PRINT_MSG(); PRINT_MSG();
pci_write_config_byte(pbus,pslot,0,PCI_INTERRUPT_LINE,(cvalue= int_name, cvalue)); pci_write_config_byte( pbus,pslot,0,
PCI_INTERRUPT_LINE,(cvalue= int_name, cvalue));
} }
} } else {
else
{
test_intname( &bspmap[i],pbus,pslot,int_pin,int_name); test_intname( &bspmap[i],pbus,pslot,int_pin,int_name);
} }
break; break;
} }
} }
if( !ismatch ) if ( !ismatch ) {
{
/* /*
** no match, which means we're on a bus someplace. Work * no match, which means we're on a bus someplace. Work
** backwards from it to one of our defined busses, * backwards from it to one of our defined busses,
** swizzling thru each bridge on the way. * swizzling thru each bridge on the way.
*/ */
/* keep pbus, pslot pointed to the device being /* keep pbus, pslot pointed to the device being
configured while we track down the bridges using * configured while we track down the bridges using
tbus,tslot. We keep searching the routing table because * tbus,tslot. We keep searching the routing table because
we may end up finding our bridge in it */ * we may end up finding our bridge in it
*/
int tbus= pbus, tslot= pslot; int tbus= pbus, tslot= pslot;
for(;;) for (;;) {
{ for (i=0; bspmap[i].bus > -1; i++) {
if ( bspmap[i].bus == tbus &&
for(i=0; bspmap[i].bus > -1; i++) (bspmap[i].slot == tslot || bspmap[i].slot == -1) ) {
{
if( bspmap[i].bus == tbus && (bspmap[i].slot == tslot || bspmap[i].slot == -1) )
{
ismatch = -1; ismatch = -1;
/* found a record for this bus, so swizzle the /* found a record for this bus, so swizzle the
* int_pin which we then use to find the * int_pin which we then use to find the
* interrupt_name. * interrupt_name.
*/ */
if( int_name == 255 ) if ( int_name == 255 ) {
{
/* /*
** FIXME. I can't believe this little hack * FIXME. I can't believe this little hack
** is right. It does not yield an error in * is right. It does not yield an error in
** convienently simple situations. * convienently simple situations.
*/ */
if( tbus ) int_pin = (*swizzler)(tslot,int_pin); if ( tbus ) int_pin = (*swizzler)(tslot,int_pin);
/* /*
** int_pin points to the interrupt channel * int_pin points to the interrupt channel
** this card ends up delivering interrupts * this card ends up delivering interrupts
** on. Find the int_name servicing it. * on. Find the int_name servicing it.
*/ */
for( int_name=-1, j=0; bspmap[i].pin_route[j].pin > -1; j++ ) for (int_name=-1, j=0; bspmap[i].pin_route[j].pin > -1; j++){
{ if ( bspmap[i].pin_route[j].pin == int_pin ) {
if( bspmap[i].pin_route[j].pin == int_pin )
{
int_name = bspmap[i].pin_route[j].int_name[0]; int_name = bspmap[i].pin_route[j].int_name[0];
break; break;
} }
} }
if( int_name == -1 )
{ if ( int_name == -1 ) {
printk("pci : Unable to resolve device %d:%d w/ swizzled int pin %i to an interrupt_line.\n", pbus, pslot, int_pin ); printk("pci : Unable to resolve device %d:%d w/ swizzled "
} "int pin %i to an interrupt_line.\n",
else pbus, pslot, int_pin );
{ } else {
PRINT_MSG(); PRINT_MSG();
pci_write_config_byte(pbus,pslot,0,PCI_INTERRUPT_LINE,(cvalue= int_name, cvalue)); pci_write_config_byte(pbus,pslot,0,
PCI_INTERRUPT_LINE,(cvalue=int_name, cvalue));
} }
} } else {
else
{
test_intname(&bspmap[i],pbus,pslot,int_pin,int_name); test_intname(&bspmap[i],pbus,pslot,int_pin,int_name);
} }
goto donesearch; goto donesearch;
} }
} }
if( !ismatch ) if ( !ismatch ) {
{
struct pcibridge pb; struct pcibridge pb;
/* /*
** Haven't found our bus in the int map, so work * Haven't found our bus in the int map, so work
** upwards thru the bridges till we find it. * upwards thru the bridges till we find it.
*/ */
if( FindPCIbridge( tbus, &pb )== 0 ) if ( FindPCIbridge( tbus, &pb )== 0 ) {
{
int_pin = (*swizzler)(tslot,int_pin); int_pin = (*swizzler)(tslot,int_pin);
/* our next bridge up is on pb.bus, pb.slot- now /* our next bridge up is on pb.bus, pb.slot- now
** instead of pointing to the device we're * instead of pointing to the device we're
** trying to configure, we move from bridge to * trying to configure, we move from bridge to
** bridge. * bridge.
*/ */
tbus = pb.bus; tbus = pb.bus;
tslot = pb.slot; tslot = pb.slot;
} } else {
else printk("pci : No bridge from bus %i towards root found\n",
{ tbus );
printk("pci : No bridge from bus %i towards root found\n", tbus );
goto donesearch; goto donesearch;
} }
} }
} }
} }
donesearch: donesearch:
if( !ismatch && int_pin != 0 && int_name == 255 ) if ( !ismatch && int_pin != 0 && int_name == 255 ) {
{ printk("pci : Unable to match device %d:%d with an int "
printk("pci : Unable to match device %d:%d with an int routing table entry\n", pbus, pslot ); "routing table entry\n", pbus, pslot );
} }
} }
} }
} }
@@ -521,7 +555,7 @@ void FixupPCI( const struct _int_map *bspmap, int (*swizzler)(int,int) )
/* /*
* This routine determines the maximum bus number in the system * This routine determines the maximum bus number in the system
*/ */
void pci_initialize() int pci_initialize()
{ {
extern void detect_host_bridge(); extern void detect_host_bridge();
unsigned char ucSlotNumber, ucFnNumber, ucNumFuncs; unsigned char ucSlotNumber, ucFnNumber, ucNumFuncs;
@@ -534,66 +568,41 @@ void pci_initialize()
/* /*
* Scan PCI bus 0 looking for PCI-PCI bridges * Scan PCI bus 0 looking for PCI-PCI bridges
*/ */
for(ucSlotNumber=0;ucSlotNumber<PCI_MAX_DEVICES;ucSlotNumber++) { for (ucSlotNumber=0;ucSlotNumber<PCI_MAX_DEVICES;ucSlotNumber++) {
(void)pci_read_config_dword(0, pci_read_config_dword(0, ucSlotNumber, 0, PCI_VENDOR_ID, &ulDeviceID);
ucSlotNumber, if (ulDeviceID==PCI_INVALID_VENDORDEVICEID) {
0, /* This slot is empty */
PCI_VENDOR_ID,
&ulDeviceID);
if(ulDeviceID==PCI_INVALID_VENDORDEVICEID) {
/*
* This slot is empty
*/
continue; continue;
} }
(void)pci_read_config_byte(0, pci_read_config_byte(0, ucSlotNumber, 0, PCI_HEADER_TYPE, &ucHeader);
ucSlotNumber, if (ucHeader&PCI_MULTI_FUNCTION) {
0,
PCI_HEADER_TYPE,
&ucHeader);
if(ucHeader&PCI_MULTI_FUNCTION) {
ucNumFuncs=PCI_MAX_FUNCTIONS; ucNumFuncs=PCI_MAX_FUNCTIONS;
} } else {
else {
ucNumFuncs=1; ucNumFuncs=1;
} }
for(ucFnNumber=0;ucFnNumber<ucNumFuncs;ucFnNumber++) { for (ucFnNumber=0;ucFnNumber<ucNumFuncs;ucFnNumber++) {
(void)pci_read_config_dword(0, pci_read_config_dword(0, ucSlotNumber, ucFnNumber,
ucSlotNumber, PCI_VENDOR_ID, &ulDeviceID);
ucFnNumber, if (ulDeviceID==PCI_INVALID_VENDORDEVICEID) {
PCI_VENDOR_ID, /* This slot/function is empty */
&ulDeviceID);
if(ulDeviceID==PCI_INVALID_VENDORDEVICEID) {
/*
* This slot/function is empty
*/
continue; continue;
} }
/* /* This slot/function has a device fitted. */
* This slot/function has a device fitted. pci_read_config_dword(0, ucSlotNumber, ucFnNumber,
*/ PCI_CLASS_REVISION, &ulClass);
(void)pci_read_config_dword(0,
ucSlotNumber,
ucFnNumber,
PCI_CLASS_REVISION,
&ulClass);
ulClass >>= 16; ulClass >>= 16;
if (ulClass == PCI_CLASS_BRIDGE_PCI) { if (ulClass == PCI_CLASS_BRIDGE_PCI) {
/* /* We have found a PCI-PCI bridge */
* We have found a PCI-PCI bridge pci_read_config_byte(0, ucSlotNumber, ucFnNumber,
*/ PCI_SUBORDINATE_BUS, &ucMaxSubordinate);
(void)pci_read_config_byte(0, if (ucMaxSubordinate>ucMaxPCIBus) {
ucSlotNumber,
ucFnNumber,
PCI_SUBORDINATE_BUS,
&ucMaxSubordinate);
if(ucMaxSubordinate>ucMaxPCIBus) {
ucMaxPCIBus=ucMaxSubordinate; ucMaxPCIBus=ucMaxSubordinate;
} }
} }
} }
} }
return PCIB_ERR_SUCCESS;
} }
/* /*
@@ -601,5 +610,5 @@ void pci_initialize()
*/ */
unsigned char BusCountPCI() unsigned char BusCountPCI()
{ {
return(ucMaxPCIBus+1); return (ucMaxPCIBus+1);
} }

View File

@@ -32,14 +32,4 @@ struct _int_map
void FixupPCI( const struct _int_map *, int (*swizzler)(int,int) ); void FixupPCI( const struct _int_map *, int (*swizzler)(int,int) );
/* scan for a specific device */
/* find a particular PCI device
* (currently, only bus0 is scanned for device/fun0)
*
* RETURNS: zero on success, bus/dev/fun in *pbus / *pdev / *pfun
*/
int
BSP_pciFindDevice(unsigned short vendorid, unsigned short deviceid,
int instance, int *pbus, int *pdev, int *pfun);
#endif /* BSP_POWERPC_PCI_H */ #endif /* BSP_POWERPC_PCI_H */

View File

@@ -14,9 +14,14 @@
#include <rtems/bspIo.h> #include <rtems/bspIo.h>
int int
pci_find_by_devid( unsigned short vendorid, unsigned short deviceid, pci_find_device(
int instance, int *pbus, int *pdev, int *pfun ) unsigned short vendorid,
{ unsigned short deviceid,
int instance,
int *pbus,
int *pdev,
int *pfun
) {
unsigned int d; unsigned int d;
unsigned short s; unsigned short s;
unsigned char bus,dev,fun,hd; unsigned char bus,dev,fun,hd;
@@ -53,5 +58,3 @@ pci_find_by_devid( unsigned short vendorid, unsigned short deviceid,
} }
return -1; return -1;
} }
/* eof */