summaryrefslogtreecommitdiffstats
path: root/drivers/pci/helper.c
blob: cd21631e3d36918deb70e11ac4176a517564830a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * $Id$
 *
 * drivers/pci/helper.c
 *
 * Copyright 1999 Jeff Garzik <jgarzik@mandrakesoft.com>
 * This software is free.  See the file COPYING for licensing details.
 *
 */

#include <linux/kernel.h>
#include <linux/pci.h>


int pci_simple_probe (const struct pci_simple_probe_entry *list,
		      size_t match_limit, pci_simple_probe_callback cb,
		      void *drvr_data)
{
	struct pci_dev *dev;
	const struct pci_simple_probe_entry *ent;
	size_t matches = 0;
	unsigned short vendor, device;
	int rc;

	if (!list || !cb)
		return -1;

	dev = pci_find_device (PCI_ANY_ID, PCI_ANY_ID, NULL);
	while (dev) {
		ent = list;
		while (ent->vendor && ent->device) {
			vendor = ent->vendor;
			device = ent->device;

			if (((vendor != 0xFFFF) &&
			     (vendor != dev->vendor)) ||
			    ((device != 0xFFFF) &&
			     (device != dev->device))) {
			     	ent++;
				continue;
			}
			    
			if (((ent->subsys_vendor) &&
			     (ent->subsys_vendor != dev->subsystem_vendor)) ||
			    ((ent->subsys_device) &&
			     (ent->subsys_device != dev->subsystem_device))) {
			     	ent++;
				continue;
			}
			    
			rc = (* cb) (dev, matches, ent, drvr_data);
			if (rc < 0)
				return rc;

			matches++;

			if (match_limit && match_limit == matches)
				return matches;

			break; /* stop list search on first match */
		}

		dev = pci_find_device (PCI_ANY_ID, PCI_ANY_ID, dev);
	}

	return matches;
}