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 | |
---|
16 | int |
---|
17 | pci_find_by_devid( unsigned short vendorid, unsigned short deviceid, |
---|
18 | int instance, int *pbus, int *pdev, int *pfun ) |
---|
19 | { |
---|
20 | unsigned int d; |
---|
21 | unsigned short s; |
---|
22 | unsigned char bus,dev,fun,hd; |
---|
23 | |
---|
24 | for (bus=0; bus<BusCountPCI(); bus++) { |
---|
25 | for (dev=0; dev<PCI_MAX_DEVICES; dev++) { |
---|
26 | |
---|
27 | pci_read_config_byte(bus,dev,0, PCI_HEADER_TYPE, &hd); |
---|
28 | hd = (hd & PCI_MULTI_FUNCTION ? PCI_MAX_FUNCTIONS : 1); |
---|
29 | |
---|
30 | for (fun=0; fun<hd; fun++) { |
---|
31 | /* |
---|
32 | * The last devfn id/slot is special; must skip it |
---|
33 | */ |
---|
34 | if (PCI_MAX_DEVICES-1==dev && PCI_MAX_FUNCTIONS-1 == fun) |
---|
35 | break; |
---|
36 | (void)pci_read_config_dword(bus,dev,fun,PCI_VENDOR_ID,&d); |
---|
37 | if (PCI_INVALID_VENDORDEVICEID == d) |
---|
38 | continue; |
---|
39 | #ifdef PCI_DEBUG |
---|
40 | printk("pci_find_by_devid: found 0x%08x at %d/%d/%d\n",d,bus,dev,fun); |
---|
41 | #endif |
---|
42 | (void) pci_read_config_word(bus,dev,fun,PCI_VENDOR_ID,&s); |
---|
43 | if (vendorid != s) |
---|
44 | continue; |
---|
45 | (void) pci_read_config_word(bus,dev,fun,PCI_DEVICE_ID,&s); |
---|
46 | if (deviceid == s) { |
---|
47 | if (instance--) continue; |
---|
48 | *pbus=bus; *pdev=dev; *pfun=fun; |
---|
49 | return 0; |
---|
50 | } |
---|
51 | } |
---|
52 | } |
---|
53 | } |
---|
54 | return -1; |
---|
55 | } |
---|
56 | |
---|
57 | /* eof */ |
---|