Check the hw.proto.attach environment variable for devices that
proto(4) should attach to instead of the normal driver. Document the variable.
This commit is contained in:
parent
97cc6870f6
commit
be00e09818
@ -25,7 +25,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd July 3, 2015
|
||||
.Dd July 19, 2015
|
||||
.Dt PROTO 4
|
||||
.Os
|
||||
.\"
|
||||
@ -47,6 +47,12 @@ module at boot time, place the following line in
|
||||
.Bd -literal -offset indent
|
||||
proto_load="YES"
|
||||
.Ed
|
||||
.Pp
|
||||
To have the driver attach to a device instead of its regular driver,
|
||||
mention it in the list of devices assigned to the following loader variable:
|
||||
.Bd -ragged -offset indent
|
||||
hw.proto.attach="desc[,desc]"
|
||||
.Ed
|
||||
.\"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2014 Marcel Moolenaar
|
||||
* Copyright (c) 2014, 2015 Marcel Moolenaar
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -61,6 +61,7 @@ extern char proto_driver_name[];
|
||||
|
||||
int proto_add_resource(struct proto_softc *, int, int, struct resource *);
|
||||
|
||||
int proto_probe(device_t dev, const char *prefix, char ***devnamesp);
|
||||
int proto_attach(device_t dev);
|
||||
int proto_detach(device_t dev);
|
||||
|
||||
|
@ -59,6 +59,9 @@ static driver_t proto_isa_driver = {
|
||||
sizeof(struct proto_softc),
|
||||
};
|
||||
|
||||
static char proto_isa_prefix[] = "isa";
|
||||
static char **proto_isa_devnames;
|
||||
|
||||
static int
|
||||
proto_isa_probe(device_t dev)
|
||||
{
|
||||
@ -77,12 +80,12 @@ proto_isa_probe(device_t dev)
|
||||
return (ENODEV);
|
||||
|
||||
sb = sbuf_new_auto();
|
||||
sbuf_printf(sb, "isa:%#lx", rman_get_start(res));
|
||||
sbuf_printf(sb, "%s:%#lx", proto_isa_prefix, rman_get_start(res));
|
||||
sbuf_finish(sb);
|
||||
device_set_desc_copy(dev, sbuf_data(sb));
|
||||
sbuf_delete(sb);
|
||||
bus_release_resource(dev, type, rid, res);
|
||||
return (BUS_PROBE_HOOVER);
|
||||
return (proto_probe(dev, proto_isa_prefix, &proto_isa_devnames));
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2014 Marcel Moolenaar
|
||||
* Copyright (c) 2014, 2015 Marcel Moolenaar
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -59,6 +59,9 @@ static driver_t proto_pci_driver = {
|
||||
sizeof(struct proto_softc),
|
||||
};
|
||||
|
||||
static char proto_pci_prefix[] = "pci";
|
||||
static char **proto_pci_devnames;
|
||||
|
||||
static int
|
||||
proto_pci_probe(device_t dev)
|
||||
{
|
||||
@ -68,12 +71,12 @@ proto_pci_probe(device_t dev)
|
||||
return (ENXIO);
|
||||
|
||||
sb = sbuf_new_auto();
|
||||
sbuf_printf(sb, "pci%d:%d:%d:%d", pci_get_domain(dev),
|
||||
sbuf_printf(sb, "%s%d:%d:%d:%d", proto_pci_prefix, pci_get_domain(dev),
|
||||
pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev));
|
||||
sbuf_finish(sb);
|
||||
device_set_desc_copy(dev, sbuf_data(sb));
|
||||
sbuf_delete(sb);
|
||||
return (BUS_PROBE_HOOVER);
|
||||
return (proto_probe(dev, proto_pci_prefix, &proto_pci_devnames));
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2014 Marcel Moolenaar
|
||||
* Copyright (c) 2014, 2015 Marcel Moolenaar
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -119,6 +119,62 @@ proto_intr(void *arg)
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
proto_probe(device_t dev, const char *prefix, char ***devnamesp)
|
||||
{
|
||||
char **devnames = *devnamesp;
|
||||
const char *dn, *ep, *ev;
|
||||
size_t pfxlen;
|
||||
int idx, names;
|
||||
|
||||
if (devnames == NULL) {
|
||||
pfxlen = strlen(prefix);
|
||||
names = 1; /* NULL pointer */
|
||||
ev = kern_getenv("hw.proto.attach");
|
||||
if (ev != NULL) {
|
||||
dn = ev;
|
||||
while (*dn != '\0') {
|
||||
ep = dn;
|
||||
while (*ep != ',' && *ep != '\0')
|
||||
ep++;
|
||||
if ((ep - dn) > pfxlen &&
|
||||
strncmp(dn, prefix, pfxlen) == 0)
|
||||
names++;
|
||||
dn = (*ep == ',') ? ep + 1 : ep;
|
||||
}
|
||||
}
|
||||
devnames = malloc(names * sizeof(caddr_t), M_DEVBUF,
|
||||
M_WAITOK | M_ZERO);
|
||||
*devnamesp = devnames;
|
||||
if (ev != NULL) {
|
||||
dn = ev;
|
||||
idx = 0;
|
||||
while (*dn != '\0') {
|
||||
ep = dn;
|
||||
while (*ep != ',' && *ep != '\0')
|
||||
ep++;
|
||||
if ((ep - dn) > pfxlen &&
|
||||
strncmp(dn, prefix, pfxlen) == 0) {
|
||||
devnames[idx] = malloc(ep - dn + 1,
|
||||
M_DEVBUF, M_WAITOK | M_ZERO);
|
||||
memcpy(devnames[idx], dn, ep - dn);
|
||||
idx++;
|
||||
}
|
||||
dn = (*ep == ',') ? ep + 1 : ep;
|
||||
}
|
||||
freeenv(__DECONST(char *, ev));
|
||||
}
|
||||
}
|
||||
|
||||
dn = device_get_desc(dev);
|
||||
while (*devnames != NULL) {
|
||||
if (strcmp(dn, *devnames) == 0)
|
||||
return (BUS_PROBE_SPECIFIC);
|
||||
devnames++;
|
||||
}
|
||||
return (BUS_PROBE_HOOVER);
|
||||
}
|
||||
|
||||
int
|
||||
proto_attach(device_t dev)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user