source: rtems/c/src/lib/libbsp/powerpc/shared/pci/pcifinddevice.c @ 0943f48d

4.104.114.84.95
Last change on this file since 0943f48d was 0943f48d, checked in by Joel Sherrill <joel.sherrill@…>, on 03/14/05 at 21:43:30

2005-03-14 Joel Sherrill <joel@…>

  • pci/pci.c, pci/pci.h, pci/pcifinddevice.c: Continue PCI API unification. All use pci_find_device(). Also reformat to remove tabs.
  • 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<BusCountPCI(); 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.