4.115
Line | |
---|
1 | /* PCI Help function, Find a PCI device by VENDOR/DEVICE ID |
---|
2 | * |
---|
3 | * COPYRIGHT (c) 2010. |
---|
4 | * Cobham Gaisler AB. |
---|
5 | * |
---|
6 | * The license and distribution terms for this file may be |
---|
7 | * found in the file LICENSE in this distribution or at |
---|
8 | * http://www.rtems.com/license/LICENSE. |
---|
9 | */ |
---|
10 | |
---|
11 | #include <pci.h> |
---|
12 | #include <pci/access.h> |
---|
13 | |
---|
14 | struct compare_info { |
---|
15 | int index; |
---|
16 | uint16_t vendor; |
---|
17 | uint16_t device; |
---|
18 | }; |
---|
19 | |
---|
20 | static int compare_dev_id(pci_dev_t pcidev, void *arg) |
---|
21 | { |
---|
22 | struct compare_info *info = arg; |
---|
23 | uint16_t vid, did; |
---|
24 | |
---|
25 | pci_cfg_r16(pcidev, PCI_VENDOR_ID, &vid); |
---|
26 | pci_cfg_r16(pcidev, PCI_DEVICE_ID, &did); |
---|
27 | if ((vid != info->vendor) || (did != info->device)) |
---|
28 | return 0; |
---|
29 | if (info->index-- == 0) |
---|
30 | return pcidev; |
---|
31 | else |
---|
32 | return 0; |
---|
33 | } |
---|
34 | |
---|
35 | /* Find a Device in PCI configuration space */ |
---|
36 | int pci_find(uint16_t ven, uint16_t dev, int index, pci_dev_t *pdev) |
---|
37 | { |
---|
38 | struct compare_info info; |
---|
39 | int result; |
---|
40 | |
---|
41 | info.index = index; |
---|
42 | info.vendor = ven; |
---|
43 | info.device = dev; |
---|
44 | |
---|
45 | result = pci_for_each(compare_dev_id, &info); |
---|
46 | if (pdev) |
---|
47 | *pdev = (pci_dev_t)result; |
---|
48 | if (result == 0) |
---|
49 | return -1; |
---|
50 | else |
---|
51 | return 0; |
---|
52 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.