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

4.104.114.84.95
Last change on this file since ee732739 was ee732739, checked in by Joel Sherrill <joel.sherrill@…>, on 09/13/07 at 14:26:24

2007-09-07 Kate Feng <feng1@…>

  • ChangeLog?, Makefile.am, README, README.booting, README.irq, preinstall.am, GT64260/MVME5500I2C.c, include/bsp.h, irq/irq.c, irq/irq.h, irq/irq_init.c, pci/detect_host_bridge.c, pci/pci.c, pci/pci_interface.c, pci/pcifinddevice.c, start/preload.S, startup/bspclean.c, startup/bspstart.c, startup/pgtbl_activate.c, startup/reboot.c, vectors/bspException.h, vectors/exceptionhandler.c: Merge my improvements in this BSP including a new network driver for the 1GHz NIC.
  • network/if_100MHz/GT64260eth.c, network/if_100MHz/GT64260eth.h, network/if_100MHz/GT64260ethreg.h, network/if_100MHz/Makefile.am, network/if_1GHz/Makefile.am, network/if_1GHz/POSSIBLEBUG, network/if_1GHz/if_wm.c, network/if_1GHz/if_wmreg.h, network/if_1GHz/pci_map.c, network/if_1GHz/pcireg.h: New files.
  • 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
21int 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.