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

4.104.115
Last change on this file since ac7af4a was ac7af4a, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/30/09 at 04:37:44

Whitespace removal.

  • Property mode set to 100644
File size: 2.1 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 the mvme5500 board.
10 *
11 */
12
13#define PCI_INVALID_VENDORDEVICEID      0xffffffff
14#define PCI_MULTI_FUNCTION                      0x80
15
16
17#include <bsp/pci.h>
18#include <rtems/bspIo.h>
19#include <bsp.h>
20
21static int BSP_pciDebug=0;
22
23int BSP_pciFindDevicePrint(unsigned short vendorid, unsigned short deviceid,
24                   int instance, int *pbus, int *pdev, int *pfun )
25{
26  int x;
27
28  BSP_pciDebug = 1;
29  x=pci_find_device(vendorid, deviceid, instance, pbus, pdev, pfun );
30  BSP_pciDebug = 0;
31
32  return 0;
33}
34
35int pci_find_device( unsigned short vendorid, unsigned short deviceid,
36                   int instance, int *pbus, int *pdev, int *pfun )
37{
38  unsigned int d;
39  unsigned short s;
40  unsigned char bus,dev,fun,hd;
41
42  for (bus=0; bus<BSP_MAX_PCI_BUS;  bus++) {
43      for (dev=0; dev<PCI_MAX_DEVICES; dev++) {
44          pci_read_config_byte(bus, dev, 0, PCI_HEADER_TYPE, &hd);
45          hd = (hd & PCI_MULTI_FUNCTION ? PCI_MAX_FUNCTIONS : 1);
46          for (fun=0; fun<hd; fun++) {
47              /*
48               * The last devfn id/slot is special; must skip it
49               */
50              if (PCI_MAX_DEVICES-1==dev && PCI_MAX_FUNCTIONS-1 == fun)
51                 break;
52              (void)pci_read_config_dword(bus,dev,fun,PCI_VENDOR_ID,&d);
53              if (PCI_INVALID_VENDORDEVICEID == d)
54                 continue;
55              if (BSP_pciDebug) {
56                 printk("pci_find_device: found 0x%08x at %2d/%2d/%2d ",d,bus,dev,fun);
57                 printk("(Physically: PCI%d  %2d/%2d/%2d)\n",
58                     (bus>= BSP_MAX_PCI_BUS_ON_PCI0)? 1:0,
59                     (bus>= BSP_MAX_PCI_BUS_ON_PCI0)? bus-BSP_MAX_PCI_BUS_ON_PCI0:bus,
60                     dev, fun);
61              }
62
63              (void)pci_read_config_word(bus,dev,fun,PCI_VENDOR_ID,&s);
64              if (vendorid != s)
65                 continue;
66              (void)pci_read_config_word(bus,dev,fun,PCI_DEVICE_ID,&s);
67              if (deviceid == s) {
68                 if (instance--) continue;
69                 *pbus=bus; *pdev=dev; *pfun=fun;
70                 return 0;
71              }
72          }
73      }
74  }  /* end for bus */
75  return -1;
76}
77
78/* eof */
Note: See TracBrowser for help on using the repository browser.