Changeset d7034e1 in rtems


Ignore:
Timestamp:
Sep 27, 2004, 10:49:48 PM (15 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
c774850d
Parents:
092fe28e
Message:

2004-09-27 Greg Menke <gregory.menke@…>

PR 608/bsps

  • pci/pcibios.c: BusCountPCI().
Location:
c/src/lib/libbsp/i386/shared
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/i386/shared/ChangeLog

    r092fe28e rd7034e1  
     12004-09-27      Greg Menke <gregory.menke@gsfc.nasa.gov>
     2
     3        PR 608/bsps
     4        * pci/pcibios.c: BusCountPCI().
     5
     6
    172004-04-09      Ralf Corsepius <ralf_corsepius@rtems.org>
    28
  • c/src/lib/libbsp/i386/shared/pci/pcibios.c

    r092fe28e rd7034e1  
    1616/*
    1717 * This is simpliest possible PCI BIOS, it assumes that addressing
    18  * is flat and that stack is big enough
    19  */
     18 * is flat and that stack is big enough
     19 */
     20
    2021
    2122static int pcibInitialized = 0;
     
    2324
    2425/*
    25  * Array to pass data between c and asm parts, at the time of
    26  * writing I am not yet that familiar with extended asm feature
    27  * of gcc. This code is not on performance path, so we can care
    28  * relatively little about performance here
     26 * Array to pass data between c and asm parts, at the time of 
     27 * writing I am not yet that familiar with extended asm feature 
     28 * of gcc. This code is not on performance path, so we can care 
     29 * relatively little about performance here 
    2930 */
    3031static volatile unsigned int pcibExchg[5];
     
    3334
    3435/*
    35  * Detects presense of PCI BIOS, returns
     36 * Detects presense of PCI BIOS, returns 
    3637 * error code
    3738 */
    38 int
     39int 
    3940pcib_init(void)
    4041{
     
    8485  pcibExchg[0] = *(unsigned int *)ucp;
    8586
    86   asm ("    pusha");                  /* Push all registers */
     87  asm ("    pusha");                  /* Push all registers */ 
    8788  asm ("    movl pcibExchg, %edi");   /* Move entry point to esi */
    8889  asm ("    movl $0x49435024, %eax"); /* Move signature to eax */
     
    107108  /* Let us check whether PCI bios is present */
    108109  pcibExchg[0] = pcibEntry;
    109 
     110 
    110111  asm("    pusha");
    111112  asm("    movl pcibExchg, %edi");
     
    133134
    134135  /* Success */
    135 
     136 
    136137  pcibInitialized = 1;
    137138  return PCIB_ERR_SUCCESS;
    138139}
    139140
    140 /*
    141  * Find specified device and return its signature: combination
     141/* 
     142 * Find specified device and return its signature: combination 
    142143 * of bus number, device number and function number
    143144 */
     
    173174}
    174175
    175 /*
    176  * Find specified class code return device signature: combination
     176/* 
     177 * Find specified class code return device signature: combination 
    177178 * of bus number, device number and function number
    178179 */
     
    210211  return PCIB_ERR_SUCCESS;
    211212}
    212 
     213 
    213214#define PCI_MULTI_FUNCTION       0x80
    214215#define PCI_MAX_DEVICES          16
    215216#define PCI_MAX_FUNCTIONS        8
     217
     218#define PCI_VENDOR_ID           0x00    /* 16 bits */
     219#define PCI_DEVICE_ID           0x02    /* 16 bits */
     220#define PCI_CLASS_REVISION      0x08
     221#define PCI_HEADER_TYPE         0x0e 
     222#define PCI_SUBORDINATE_BUS     0x1a
     223
     224#define  PCI_CLASS_BRIDGE_PCI           0x0604
     225
     226static unsigned8 ucBusCount = 0xff;
     227
     228
     229int
     230BusCountPCI()
     231{
     232   if( ucBusCount == 0xff )
     233   {
     234      unsigned char bus,dev,hd;
     235      unsigned int d;
     236      int sig;
     237
     238      ucBusCount = 0;
     239
     240      for(bus=0; bus< 0xff; bus++)
     241      { 
     242         for(dev=0; dev<PCI_MAX_DEVICES; dev++)
     243         {
     244            sig = PCIB_DEVSIG_MAKE(bus,dev,0);
     245            pcib_conf_read32(sig, PCI_VENDOR_ID, &d);
     246
     247            if( d != -1 )
     248            {
     249               pcib_conf_read32(sig, PCI_CLASS_REVISION, &d);
     250               
     251               if( (d >> 16) == PCI_CLASS_BRIDGE_PCI )
     252               {
     253                  pcib_conf_read8(sig, PCI_SUBORDINATE_BUS, &hd);
     254
     255                  if( hd > ucBusCount )
     256                     ucBusCount = hd;
     257               }
     258            }
     259         }
     260         
     261      }
     262
     263      if( ucBusCount == 0 )
     264      {
     265         printk("BusCountPCI() found 0 busses, assuming 1\n");
     266         ucBusCount = 1;
     267      }
     268      else if( ucBusCount == 0xff )
     269      {
     270         printk("BusCountPCI() found 0xff busses, assuming 1\n");
     271         ucBusCount = 1;
     272      }
     273   }                       
     274
     275   return ucBusCount;
     276}
     277
    216278
    217279int
     
    224286   unsigned char bus,dev,fun,hd;
    225287
    226    for (bus=0; bus<BusCountPCI(); bus++)
     288   for (bus=0; bus<BusCountPCI(); bus++) 
    227289   {
    228       for (dev=0; dev<PCI_MAX_DEVICES; dev++)
     290      for (dev=0; dev<PCI_MAX_DEVICES; dev++) 
    229291      {
    230292         sig = PCIB_DEVSIG_MAKE(bus,dev,0);
    231293
    232294         /* pci_read_config_byte(bus,dev,0, PCI_HEADER_TYPE, &hd); */
    233          pcib_conf_read8(sig, 0xe, &hd);
     295         pcib_conf_read8(sig, 0xe, &hd); 
    234296
    235297         hd = (hd & PCI_MULTI_FUNCTION ? PCI_MAX_FUNCTIONS : 1);
    236298
    237299         for (fun=0; fun<hd; fun++) {
    238             /*
     300            /* 
    239301             * The last devfn id/slot is special; must skip it
    240302             */
     
    243305
    244306            /*pci_read_config_dword(bus,dev,fun,PCI_VENDOR_ID,&d); */
    245             pcib_conf_read32(sig, 0, &d);
     307            pcib_conf_read32(sig, 0, &d); 
    246308            if( d == -1 )
    247309               continue;
     
    250312#endif
    251313            /* pci_read_config_word(bus,dev,fun,PCI_VENDOR_ID,&s); */
    252             pcib_conf_read16(sig, 0, &s);
     314            pcib_conf_read16(sig, 0, &s); 
    253315            if (vendorid != s)
    254316               continue;
    255317
    256318            /* pci_read_config_word(bus,dev,fun,PCI_DEVICE_ID,&s); */
    257             pcib_conf_read16(sig, 0x2, &s);
     319            pcib_conf_read16(sig, 0x2, &s); 
    258320            if (deviceid == s) {
    259321               if (instance--) continue;
    260                *pbus=bus;
    261                *pdev=dev;
     322               *pbus=bus; 
     323               *pdev=dev; 
    262324               *pfun=fun;
    263325               return 0;
     
    269331}
    270332
    271 /*
     333
     334 
     335
     336/*
    272337 * Generate Special Cycle
    273338 */
     
    298363  return pcib_convert_err((pcibExchg[0] >> 8) & 0xff);
    299364}
    300 
    301 /*
     365 
     366
     367/*
    302368 * Read byte from config space
    303369 */
     
    335401  return PCIB_ERR_SUCCESS;
    336402}
    337 
    338 /*
     403 
     404
     405/*
    339406 * Read word from config space
    340407 */
     
    372439  return PCIB_ERR_SUCCESS;
    373440}
    374 
    375 /*
     441 
     442
     443/*
    376444 * Read dword from config space
    377445 */
     
    409477  return PCIB_ERR_SUCCESS;
    410478}
    411 
    412 /*
     479 
     480
     481/*
    413482 * Write byte into  config space
    414483 */
     
    441510}
    442511
    443 /*
     512/* 
    444513 * Write word into config space
    445514 */
     
    471540  return pcib_convert_err((pcibExchg[0] >> 8) & 0xff);
    472541}
    473 
    474 /*
     542 
     543
     544
     545/*
    475546 * Write dword into config space
    476547 */
     
    502573  return pcib_convert_err((pcibExchg[0] >> 8) & 0xff);
    503574}
     575 
    504576
    505577static int
     
    523595  return PCIB_ERR_NOFUNC;
    524596}
     597       
     598     
     599
     600
     601 
     602     
     603 
     604
     605
     606
Note: See TracChangeset for help on using the changeset viewer.