source: rtems/c/src/lib/libbsp/sparc/shared/pci/pcifinddevice.c @ 8bbf69e

4.115
Last change on this file since 8bbf69e was 8bbf69e, checked in by Joel Sherrill <joel.sherrill@…>, on 05/16/12 at 21:04:10

pci.h cleanup - Consolidate common defines to cpukit pci.h

+ libbsp/sparc/shared/include/pci.h was largely a copy of

an older version of the cpukit pci.h. Removed much of the
contents and included <rtems/pci.h>.

+ sparc/*/pci*.c - Move to <rtems/pci.h> required updating

to use uint32_t for dword accesses.

+ Rename PCI_MULTI_FUNCTION to PCI_HEADER_TYPE_MULTI_FUNCTION
+ Define PCI_HEADER_TYPE_MULTI_FUNCTION in cpukit pci.h and remove

PCI_MULTI_FUNCTION definitions in C files.

+ Move PCI_INVALID_VENDORDEVICEID definitions from various C files

to cpukit pci.h

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