source: rtems/cpukit/libpci/pci_find.c @ 76b9c31

5
Last change on this file since 76b9c31 was e53daed, checked in by Daniel Hellstrom <daniel@…>, on 04/09/15 at 14:09:42

LIBPCI: updated license to rtems.org

  • Property mode set to 100644
File size: 1.0 KB
Line 
1/*  PCI Help function, Find a PCI device by VENDOR/DEVICE ID
2 *
3 *  COPYRIGHT (c) 2010 Cobham Gaisler AB.
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.org/license/LICENSE.
8 */
9
10#include <pci.h>
11#include <pci/access.h>
12
13struct compare_info {
14        int index;
15        uint16_t vendor;
16        uint16_t device;
17};
18
19static int compare_dev_id(pci_dev_t pcidev, void *arg)
20{
21        struct compare_info *info = arg;
22        uint16_t vid, did;
23
24        pci_cfg_r16(pcidev, PCIR_VENDOR, &vid);
25        pci_cfg_r16(pcidev, PCIR_DEVICE, &did);
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 */
35int 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.