]>
git.ipfire.org Git - thirdparty/pciutils.git/blob - lib/filter.c
2 * The 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
->domain
= f
->bus
= f
->slot
= f
->func
= -1;
18 f
->vendor
= f
->device
= -1;
21 /* Slot filter syntax: [[[domain]:][bus]:][slot][.[func]] */
24 pci_filter_parse_slot(struct pci_filter
*f
, char *str
)
26 char *colon
= strrchr(str
, ':');
27 char *dot
= strchr((colon
? colon
+ 1 : str
), '.');
29 char *e
, *bus
, *colon2
;
35 colon2
= strchr(str
, ':');
40 if (str
[0] && strcmp(str
, "*"))
42 long int x
= strtol(str
, &e
, 16);
43 if ((e
&& *e
) || (x
< 0 || x
> 0xffff))
44 return "Invalid domain number";
50 if (bus
[0] && strcmp(bus
, "*"))
52 long int x
= strtol(bus
, &e
, 16);
53 if ((e
&& *e
) || (x
< 0 || x
> 0xff))
54 return "Invalid bus number";
60 if (mid
[0] && strcmp(mid
, "*"))
62 long int x
= strtol(mid
, &e
, 16);
63 if ((e
&& *e
) || (x
< 0 || x
> 0x1f))
64 return "Invalid slot number";
67 if (dot
&& dot
[0] && strcmp(dot
, "*"))
69 long int x
= strtol(dot
, &e
, 16);
70 if ((e
&& *e
) || (x
< 0 || x
> 7))
71 return "Invalid function number";
77 /* ID filter syntax: [vendor]:[device] */
80 pci_filter_parse_id(struct pci_filter
*f
, char *str
)
88 return "':' expected";
90 if (str
[0] && strcmp(str
, "*"))
92 long int x
= strtol(str
, &e
, 16);
93 if ((e
&& *e
) || (x
< 0 || x
> 0xffff))
94 return "Invalid vendor ID";
97 if (s
[0] && strcmp(s
, "*"))
99 long int x
= strtol(s
, &e
, 16);
100 if ((e
&& *e
) || (x
< 0 || x
> 0xffff))
101 return "Invalid device ID";
108 pci_filter_match(struct pci_filter
*f
, struct pci_dev
*d
)
110 if ((f
->domain
>= 0 && f
->domain
!= d
->domain
) ||
111 (f
->bus
>= 0 && f
->bus
!= d
->bus
) ||
112 (f
->slot
>= 0 && f
->slot
!= d
->dev
) ||
113 (f
->func
>= 0 && f
->func
!= d
->func
))
115 if (f
->device
>= 0 || f
->vendor
>= 0)
117 pci_fill_info_v32(d
, PCI_FILL_IDENT
);
118 if ((f
->device
>= 0 && f
->device
!= d
->device_id
) ||
119 (f
->vendor
>= 0 && f
->vendor
!= d
->vendor_id
))