2 * $Id: filter.c,v 1.1 1998/03/31 21:02:14 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.
14 #include <linux/pci.h>
19 filter_init(struct pci_filter *f)
21 f->bus = f->slot = f->func = -1;
22 f->vendor = f->device = -1;
25 /* Slot filter syntax: [[bus]:][slot][.[func]] */
28 filter_parse_slot(struct pci_filter *f, char *str)
30 char *colon = strchr(str, ':');
31 char *dot = strchr((colon ? colon + 1 : str), '.');
39 if (str[0] && strcmp(str, "*"))
41 long int x = strtol(str, &e, 16);
42 if ((e && *e) || (x < 0 || x >= 0xff))
43 return "Invalid bus number";
49 if (mid[0] && strcmp(mid, "*"))
51 long int x = strtol(str, &e, 16);
52 if ((e && *e) || (x < 0 || x >= 0x1f))
53 return "Invalid slot number";
56 if (dot && dot[0] && strcmp(dot, "*"))
58 long int x = strtol(dot, &e, 16);
59 if ((e && *e) || (x < 0 || x >= 7))
60 return "Invalid function number";
66 /* ID filter syntax: [vendor]:[device] */
69 filter_parse_id(struct pci_filter *f, char *str)
77 return "':' expected";
79 if (str[0] && strcmp(str, "*"))
81 long int x = strtol(str, &e, 16);
82 if ((e && *e) || (x < 0 || x >= 0xffff))
83 return "Invalid vendor ID";
86 if (s[0] && strcmp(s, "*"))
88 long int x = strtol(s, &e, 16);
89 if ((e && *e) || (x < 0 || x >= 0xffff))
90 return "Invalid device ID";
97 filter_match(struct pci_filter *f, byte bus, byte devfn, word vendid, word devid)
99 if ((f->bus >= 0 && f->bus != bus) ||
100 (f->slot >= 0 && f->slot != PCI_SLOT(devfn)) ||
101 (f->func >= 0 && f->func != PCI_FUNC(devfn)) ||
102 (f->device >= 0 && f->device != devid) ||
103 (f->vendor >= 0 && f->vendor != vendid))