source: rtems/c/src/lib/libbsp/powerpc/mvme5500/pci/pcifinddevice.c @ f8e0327

4.104.114.84.95
Last change on this file since f8e0327 was 7be6ad9, checked in by Eric Norum <WENorum@…>, on 10/20/04 at 15:21:05

Add MVME550 BSP

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/* pcifinddevice.c
2 *
3 * Copyright 2001,  Till Straumann <strauman@slac.stanford.edu>
4 *
5 * find a particular PCI device
6 * (we assume, the firmware configured the PCI bus[es] for us)
7 *
8 *
9 * Kate Feng <feng1@bnl.gov>, modified it to support
10 * the mvme5500 board and provided glues to Till's vmeUniverse.c.
11 *
12 */
13
14#define PCI_INVALID_VENDORDEVICEID      0xffffffff
15#define PCI_MULTI_FUNCTION                      0x80
16
17/*#define PCI_DEBUG*/
18
19#include <bsp/pci.h>
20#include <rtems/bspIo.h>
21
22int BSP_PCIxFindDevice(unsigned short vendorid, unsigned short deviceid,
23     int instance, int pciNum, int *pbus, int *pdev, int *pfun )
24{
25  unsigned int d;
26  unsigned short s;
27  unsigned char bus,dev,fun,hd;
28
29  for (bus=0; bus<2; bus++) {
30      for (dev=0; dev<PCI_MAX_DEVICES; dev++) {
31          PCIx_read_config_byte(pciNum, bus, dev, 0, PCI0_HEADER_TYPE, &hd);
32          hd = (hd & PCI_MULTI_FUNCTION ? PCI_MAX_FUNCTIONS : 1);
33          for (fun=0; fun<hd; fun++) {
34              /*
35               * The last devfn id/slot is special; must skip it
36               */
37              if (PCI_MAX_DEVICES-1==dev && PCI_MAX_FUNCTIONS-1 == fun)
38                 break;
39              (void)PCIx_read_config_dword(pciNum, bus,dev,fun,PCI0_VENDOR_ID,&d);
40              if (PCI_INVALID_VENDORDEVICEID == d)
41                 continue;
42#ifdef PCI_DEBUG
43              printk("BSP_pciFindDevice: found 0x%08x at %d/%d/%d\n",d,bus,dev,fun);
44#endif
45              (void)PCIx_read_config_word(pciNum, bus,dev,fun,PCI0_VENDOR_ID,&s);
46              if (vendorid != s)
47                 continue;
48              (void)PCIx_read_config_word(pciNum, bus,dev,fun,PCI0_DEVICE_ID,&s);
49              if (deviceid == s) {
50                 if (instance--) continue;
51                 *pbus=bus; *pdev=dev; *pfun=fun;
52                 return 0;
53              }
54          }
55      }
56  }  /* end for bus */
57  return -1;
58}
59
60int BSP_pciFindDevice( unsigned short vendorid, unsigned short deviceid,
61                   int instance, int *pbus, int *pdev, int *pfun )
62{
63  return(BSP_PCIxFindDevice(vendorid,deviceid,instance,0,pbus,pdev,pfun));
64}
65
66/* eof */
Note: See TracBrowser for help on using the repository browser.