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