source: rtems/c/src/lib/libbsp/powerpc/shared/pci/pcifinddevice.c @ 548ed3f

4.104.114.84.9
Last change on this file since 548ed3f was 548ed3f, checked in by Jennifer Averett <Jennifer.Averett@…>, on May 4, 2005 at 7:33:46 PM

2005-05-04 Jennifer Averett <jennifer.averett@…>

  • irq/irq_init.c, pci/pci.c, pci/pcifinddevice.c, startup/bspstart.c: Name change to support common PCI interface
  • Property mode set to 100644
File size: 1.5 KB
Line 
1
2/* Author: Till Straumann <strauman@slac.stanford.edu>, 2001 */
3
4/* find a particular PCI device
5 * (we assume, the firmware configured the PCI bus[es] for us)
6 *
7 * $Id$
8 */
9
10#define PCI_INVALID_VENDORDEVICEID  0xffffffff
11#define PCI_MULTI_FUNCTION      0x80
12
13#include <bsp/pci.h>
14#include <rtems/bspIo.h>
15
16int
17pci_find_device(
18  unsigned short vendorid,
19  unsigned short deviceid,
20  int instance,
21  int *pbus,
22  int *pdev,
23  int *pfun
24) {
25   unsigned int d;
26   unsigned short s;
27   unsigned char bus,dev,fun,hd;
28
29   for (bus=0; bus<pci_bus_count(); bus++) {
30     for (dev=0; dev<PCI_MAX_DEVICES; dev++) {
31
32       pci_read_config_byte(bus,dev,0, PCI_HEADER_TYPE, &hd);
33       hd = (hd & PCI_MULTI_FUNCTION ? PCI_MAX_FUNCTIONS : 1);
34
35       for (fun=0; fun<hd; fun++) {
36         /*
37          * The last devfn id/slot is special; must skip it
38          */
39        if (PCI_MAX_DEVICES-1==dev && PCI_MAX_FUNCTIONS-1 == fun)
40          break;
41        (void)pci_read_config_dword(bus,dev,fun,PCI_VENDOR_ID,&d);
42        if (PCI_INVALID_VENDORDEVICEID == d)
43          continue;
44#ifdef PCI_DEBUG
45        printk("pci_find_by_devid: found 0x%08x at %d/%d/%d\n",d,bus,dev,fun);
46#endif
47        (void) pci_read_config_word(bus,dev,fun,PCI_VENDOR_ID,&s);
48        if (vendorid != s)
49          continue;
50        (void) pci_read_config_word(bus,dev,fun,PCI_DEVICE_ID,&s);
51        if (deviceid == s) {
52          if (instance--) continue;
53          *pbus=bus; *pdev=dev; *pfun=fun;
54          return 0;
55        }
56      }
57    }
58  }
59  return -1;
60}
Note: See TracBrowser for help on using the repository browser.