2 * Linux PCI Library -- Device Filtering
4 * Copyright (c) 1998--2003 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
15 pci_filter_init(struct pci_access *a UNUSED, struct pci_filter *f)
17 f->bus = f->slot = f->func = -1;
18 f->vendor = f->device = -1;
21 /* Slot filter syntax: [[bus]:][slot][.[func]] */
24 pci_filter_parse_slot(struct pci_filter *f, char *str)
26 char *colon = strchr(str, ':');
27 char *dot = strchr((colon ? colon + 1 : str), '.');
35 if (str[0] && strcmp(str, "*"))
37 long int x = strtol(str, &e, 16);
38 if ((e && *e) || (x < 0 || x > 0xff))
39 return "Invalid bus number";
45 if (mid[0] && strcmp(mid, "*"))
47 long int x = strtol(mid, &e, 16);
48 if ((e && *e) || (x < 0 || x > 0x1f))
49 return "Invalid slot number";
52 if (dot && dot[0] && strcmp(dot, "*"))
54 long int x = strtol(dot, &e, 16);
55 if ((e && *e) || (x < 0 || x > 7))
56 return "Invalid function number";
62 /* ID filter syntax: [vendor]:[device] */
65 pci_filter_parse_id(struct pci_filter *f, char *str)
73 return "':' expected";
75 if (str[0] && strcmp(str, "*"))
77 long int x = strtol(str, &e, 16);
78 if ((e && *e) || (x < 0 || x >= 0xffff))
79 return "Invalid vendor ID";
82 if (s[0] && strcmp(s, "*"))
84 long int x = strtol(s, &e, 16);
85 if ((e && *e) || (x < 0 || x >= 0xffff))
86 return "Invalid device ID";
93 pci_filter_match(struct pci_filter *f, struct pci_dev *d)
95 if ((f->bus >= 0 && f->bus != d->bus) ||
96 (f->slot >= 0 && f->slot != d->dev) ||
97 (f->func >= 0 && f->func != d->func))
99 if (f->device >= 0 || f->vendor >= 0)
101 pci_fill_info(d, PCI_FILL_IDENT);
102 if ((f->device >= 0 && f->device != d->device_id) ||
103 (f->vendor >= 0 && f->vendor != d->vendor_id))