source: rtems/cpukit/libpci/pci_find_dev.c @ 358b8543

4.115
Last change on this file since 358b8543 was a31845f7, checked in by Daniel Hellstrom <daniel@…>, on 11/28/11 at 09:11:10

LIBPCI: added PCI layer to cpukit/libpci

  • Property mode set to 100644
File size: 1022 bytes
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/cfg.h>
13
14struct compare_info {
15        int index;
16        uint16_t vendor;
17        uint16_t device;
18};
19
20static int compare_dev_id(struct pci_dev *dev, void *arg)
21{
22        struct compare_info *info = arg;
23
24        if ((dev->vendor != info->vendor) || (dev->device != info->device))
25                return 0;
26        if (info->index-- == 0)
27                return (int)dev;
28        else
29                return 0;
30}
31
32/* Find a Device in PCI device tree located in RAM */
33int pci_find_dev(uint16_t ven, uint16_t dev, int index, struct pci_dev **ppdev)
34{
35        struct compare_info info;
36        int result;
37
38        info.index = index;
39        info.vendor = ven;
40        info.device = dev;
41
42        result = pci_for_each_dev(compare_dev_id, &info);
43        if (ppdev)
44                *ppdev = (struct pci_dev *)result;
45        if (result == 0)
46                return -1;
47        else
48                return 0;
49}
Note: See TracBrowser for help on using the repository browser.