Restore compatibility with version before introduction of PCI domains.

PCI selectors with 2 or 3 elements behave exactly as before (i.e. the
domain is 0 and in the 2 element case, the function is also 0).
The form with 4 selector elements works as in the previous revision
and provides the PCI domain number as the left-most selector element.

This change allows old scripts (which used the 2 or 3 selector element
formats) to be kept. Without this patch, the 3 element form was parsed
as starting with a domain number (and the function was assumed to be 0),
with this patch, the domain is assumed to be 0 (and the last value is
used as the function number).

The man page is updated to describe the new selector semantics.

Approved by:	re (Ken Smith)
This commit is contained in:
Stefan Eßer 2007-10-04 22:18:53 +00:00
parent 358904bf9d
commit d23a84a0a8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=172447
2 changed files with 22 additions and 18 deletions

View File

@ -142,10 +142,12 @@ except for
require a
.Ar selector
of the form
.Li pci Ns Va domain Ns \&: Ns Va bus Ns \&: Ns Va device
(optionally followed by
.Li \&: Ns Va function ) .
A final colon may be appended and
.Li pci Ns Va domain Ns \&: Ns Va bus Ns \&: Ns Va device Ns \&: \
Ns Va function Ns ,
.Li pci Ns Va bus Ns \&: Ns Va device Ns \&: Ns Va function Ns , or
.Li pci Ns Va bus Ns \&: Ns Va device Ns .
In case of an abrigded form, omitted selector components are assumed to be 0.
An optional leading device name followed by @ and an optional final colon
will be ignored; this is so that the first column in the output of
.Nm
.Fl l

View File

@ -486,6 +486,8 @@ getsel(const char *str)
char *ep = strchr(str, '@');
char *epbase;
struct pcisel sel;
unsigned long selarr[4];
int i;
if (ep == NULL)
ep = (char *)str;
@ -496,21 +498,21 @@ getsel(const char *str)
if (strncmp(ep, "pci", 3) == 0) {
ep += 3;
sel.pc_domain = strtoul(ep, &ep, 0);
if (!ep || *ep++ != ':')
errx(1, "cannot parse selector %s", str);
sel.pc_bus = strtoul(ep, &ep, 0);
if (!ep || *ep++ != ':')
errx(1, "cannot parse selector %s", str);
sel.pc_dev = strtoul(ep, &ep, 0);
if (!ep || *ep != ':') {
i = 0;
do {
selarr[i++] = strtoul(ep, &ep, 10);
} while (*ep == ':' && *++ep != '\0' && i < 4);
if (i > 2)
sel.pc_func = selarr[--i];
else
sel.pc_func = 0;
} else {
ep++;
sel.pc_func = strtoul(ep, &ep, 0);
}
if (*ep == ':')
ep++;
sel.pc_dev = selarr[--i];
sel.pc_bus = selarr[--i];
if (i > 0)
sel.pc_domain = selarr[--i];
else
sel.pc_domain = 0;
}
if (*ep != '\x0' || ep == epbase)
errx(1, "cannot parse selector %s", str);