2 * $Id: filter.c,v 1.2 1998/06/08 07:51:45 mj Exp $
4 * Linux PCI Utilities -- Device Filtering
6 * Copyright (c) 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
8 * Can be freely distributed and used under the terms of the GNU GPL.
18 filter_init(struct pci_filter *f)
20 f->bus = f->slot = f->func = -1;
21 f->vendor = f->device = -1;
24 /* Slot filter syntax: [[bus]:][slot][.[func]] */
27 filter_parse_slot(struct pci_filter *f, char *str)
29 char *colon = strchr(str, ':');
30 char *dot = strchr((colon ? colon + 1 : str), '.');
38 if (str[0] && strcmp(str, "*"))
40 long int x = strtol(str, &e, 16);
41 if ((e && *e) || (x < 0 || x >= 0xff))
42 return "Invalid bus number";
48 if (mid[0] && strcmp(mid, "*"))
50 long int x = strtol(mid, &e, 16);
51 if ((e && *e) || (x < 0 || x >= 0x1f))
52 return "Invalid slot number";
55 if (dot && dot[0] && strcmp(dot, "*"))
57 long int x = strtol(dot, &e, 16);
58 if ((e && *e) || (x < 0 || x >= 7))
59 return "Invalid function number";
65 /* ID filter syntax: [vendor]:[device] */
68 filter_parse_id(struct pci_filter *f, char *str)
76 return "':' expected";
78 if (str[0] && strcmp(str, "*"))
80 long int x = strtol(str, &e, 16);
81 if ((e && *e) || (x < 0 || x >= 0xffff))
82 return "Invalid vendor ID";
85 if (s[0] && strcmp(s, "*"))
87 long int x = strtol(s, &e, 16);
88 if ((e && *e) || (x < 0 || x >= 0xffff))
89 return "Invalid device ID";
96 filter_match(struct pci_filter *f, byte bus, byte devfn, word vendid, word devid)
98 if ((f->bus >= 0 && f->bus != bus) ||
99 (f->slot >= 0 && f->slot != PCI_SLOT(devfn)) ||
100 (f->func >= 0 && f->func != PCI_FUNC(devfn)) ||
101 (f->device >= 0 && f->device != devid) ||
102 (f->vendor >= 0 && f->vendor != vendid))