]>
git.ipfire.org Git - thirdparty/pciutils.git/blob - lib/filter.c
2 * $Id: filter.c,v 1.1 1999/01/22 21:05:22 mj Exp $
4 * Linux PCI Library -- Device Filtering
6 * Copyright (c) 1998--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
8 * Can be freely distributed and used under the terms of the GNU GPL.
17 pci_filter_init(struct pci_access
* UNUSED a
, struct pci_filter
*f
)
19 f
->bus
= f
->slot
= f
->func
= -1;
20 f
->vendor
= f
->device
= -1;
23 /* Slot filter syntax: [[bus]:][slot][.[func]] */
26 pci_filter_parse_slot(struct pci_filter
*f
, char *str
)
28 char *colon
= strchr(str
, ':');
29 char *dot
= strchr((colon
? colon
+ 1 : str
), '.');
37 if (str
[0] && strcmp(str
, "*"))
39 long int x
= strtol(str
, &e
, 16);
40 if ((e
&& *e
) || (x
< 0 || x
>= 0xff))
41 return "Invalid bus number";
47 if (mid
[0] && strcmp(mid
, "*"))
49 long int x
= strtol(mid
, &e
, 16);
50 if ((e
&& *e
) || (x
< 0 || x
>= 0x1f))
51 return "Invalid slot number";
54 if (dot
&& dot
[0] && strcmp(dot
, "*"))
56 long int x
= strtol(dot
, &e
, 16);
57 if ((e
&& *e
) || (x
< 0 || x
>= 7))
58 return "Invalid function number";
64 /* ID filter syntax: [vendor]:[device] */
67 pci_filter_parse_id(struct pci_filter
*f
, char *str
)
75 return "':' expected";
77 if (str
[0] && strcmp(str
, "*"))
79 long int x
= strtol(str
, &e
, 16);
80 if ((e
&& *e
) || (x
< 0 || x
>= 0xffff))
81 return "Invalid vendor ID";
84 if (s
[0] && strcmp(s
, "*"))
86 long int x
= strtol(s
, &e
, 16);
87 if ((e
&& *e
) || (x
< 0 || x
>= 0xffff))
88 return "Invalid device ID";
95 pci_filter_match(struct pci_filter
*f
, struct pci_dev
*d
)
97 if ((f
->bus
>= 0 && f
->bus
!= d
->bus
) ||
98 (f
->slot
>= 0 && f
->slot
!= d
->dev
) ||
99 (f
->func
>= 0 && f
->func
!= d
->func
))
101 if (f
->device
>= 0 || f
->vendor
>= 0)
103 pci_fill_info(d
, PCI_FILL_IDENT
);
104 if ((f
->device
>= 0 && f
->device
!= d
->device_id
) ||
105 (f
->vendor
>= 0 && f
->vendor
!= d
->vendor_id
))