1998-09-04 02:43:26 +00:00
|
|
|
/*
|
|
|
|
* mjs copyright
|
2000-05-01 17:41:25 +00:00
|
|
|
*
|
1998-09-04 02:43:26 +00:00
|
|
|
*/
|
2003-08-25 23:30:41 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-09-04 02:43:26 +00:00
|
|
|
/*
|
|
|
|
* "Plug and Play" functionality.
|
|
|
|
*
|
|
|
|
* We use the PnP enumerators to obtain identifiers for installed hardware,
|
|
|
|
* and the contents of a database to determine modules to be loaded to support
|
|
|
|
* such hardware.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stand.h>
|
1998-09-14 18:27:06 +00:00
|
|
|
#include <string.h>
|
1998-09-04 02:43:26 +00:00
|
|
|
#include <bootstrap.h>
|
|
|
|
|
2000-09-08 16:51:29 +00:00
|
|
|
struct pnpinfo_stql pnp_devices;
|
1998-10-21 20:07:05 +00:00
|
|
|
static int pnp_devices_initted = 0;
|
1998-09-04 02:43:26 +00:00
|
|
|
|
1998-10-21 20:07:05 +00:00
|
|
|
static void pnp_discard(void);
|
1998-09-04 02:43:26 +00:00
|
|
|
|
|
|
|
/*
|
1999-01-22 23:50:14 +00:00
|
|
|
* Perform complete enumeration sweep
|
1998-09-04 02:43:26 +00:00
|
|
|
*/
|
|
|
|
|
1998-09-14 18:27:06 +00:00
|
|
|
COMMAND_SET(pnpscan, "pnpscan", "scan for PnP devices", pnp_scan);
|
|
|
|
|
1999-01-22 23:50:14 +00:00
|
|
|
static int
|
1998-09-14 18:27:06 +00:00
|
|
|
pnp_scan(int argc, char *argv[])
|
1998-09-04 02:43:26 +00:00
|
|
|
{
|
1998-10-21 20:07:05 +00:00
|
|
|
struct pnpinfo *pi;
|
1998-09-14 18:27:06 +00:00
|
|
|
int hdlr;
|
1998-10-21 20:07:05 +00:00
|
|
|
int verbose;
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
if (pnp_devices_initted == 0) {
|
|
|
|
STAILQ_INIT(&pnp_devices);
|
|
|
|
pnp_devices_initted = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
verbose = 0;
|
|
|
|
optind = 1;
|
1999-01-11 06:41:32 +00:00
|
|
|
optreset = 1;
|
1998-10-21 20:07:05 +00:00
|
|
|
while ((ch = getopt(argc, argv, "v")) != -1) {
|
|
|
|
switch(ch) {
|
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
/* getopt has already reported an error */
|
|
|
|
return(CMD_OK);
|
|
|
|
}
|
|
|
|
}
|
1998-09-04 02:43:26 +00:00
|
|
|
|
|
|
|
/* forget anything we think we knew */
|
1998-10-21 20:07:05 +00:00
|
|
|
pnp_discard();
|
|
|
|
|
1998-09-04 02:43:26 +00:00
|
|
|
/* iterate over all of the handlers */
|
1998-09-14 18:27:06 +00:00
|
|
|
for (hdlr = 0; pnphandlers[hdlr] != NULL; hdlr++) {
|
1999-01-22 23:50:14 +00:00
|
|
|
if (verbose)
|
|
|
|
printf("Probing %s...\n", pnphandlers[hdlr]->pp_name);
|
1998-10-21 20:07:05 +00:00
|
|
|
pnphandlers[hdlr]->pp_enumerate();
|
|
|
|
}
|
|
|
|
if (verbose) {
|
1999-01-22 23:50:14 +00:00
|
|
|
pager_open();
|
|
|
|
pager_output("PNP scan summary:\n");
|
2000-12-30 20:40:16 +00:00
|
|
|
STAILQ_FOREACH(pi, &pnp_devices, pi_link) {
|
|
|
|
pager_output(STAILQ_FIRST(&pi->pi_ident)->id_ident); /* first ident should be canonical */
|
1998-10-21 20:07:05 +00:00
|
|
|
if (pi->pi_desc != NULL) {
|
|
|
|
pager_output(" : ");
|
|
|
|
pager_output(pi->pi_desc);
|
|
|
|
}
|
1998-10-22 20:20:51 +00:00
|
|
|
pager_output("\n");
|
1998-10-21 20:07:05 +00:00
|
|
|
}
|
|
|
|
pager_close();
|
1998-09-04 02:43:26 +00:00
|
|
|
}
|
1998-09-14 18:27:06 +00:00
|
|
|
return(CMD_OK);
|
1998-09-04 02:43:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-01-22 23:50:14 +00:00
|
|
|
* Throw away anything we think we know about PnP devices.
|
1998-09-04 02:43:26 +00:00
|
|
|
*/
|
|
|
|
static void
|
1998-10-21 20:07:05 +00:00
|
|
|
pnp_discard(void)
|
1998-09-04 02:43:26 +00:00
|
|
|
{
|
|
|
|
struct pnpinfo *pi;
|
1998-10-21 20:07:05 +00:00
|
|
|
|
2000-12-30 20:40:16 +00:00
|
|
|
while (STAILQ_FIRST(&pnp_devices) != NULL) {
|
|
|
|
pi = STAILQ_FIRST(&pnp_devices);
|
1998-10-21 20:07:05 +00:00
|
|
|
STAILQ_REMOVE_HEAD(&pnp_devices, pi_link);
|
|
|
|
pnp_freeinfo(pi);
|
1998-09-04 02:43:26 +00:00
|
|
|
}
|
|
|
|
}
|
1998-09-14 18:27:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a unique identifier to (pi)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pnp_addident(struct pnpinfo *pi, char *ident)
|
|
|
|
{
|
1998-10-21 20:07:05 +00:00
|
|
|
struct pnpident *id;
|
|
|
|
|
2000-12-30 20:40:16 +00:00
|
|
|
STAILQ_FOREACH(id, &pi->pi_ident, id_link)
|
1998-10-21 20:07:05 +00:00
|
|
|
if (!strcmp(id->id_ident, ident))
|
|
|
|
return; /* already have this one */
|
|
|
|
|
|
|
|
id = malloc(sizeof(struct pnpident));
|
|
|
|
id->id_ident = strdup(ident);
|
|
|
|
STAILQ_INSERT_TAIL(&pi->pi_ident, id, id_link);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a new pnpinfo struct
|
|
|
|
*/
|
|
|
|
struct pnpinfo *
|
|
|
|
pnp_allocinfo(void)
|
|
|
|
{
|
|
|
|
struct pnpinfo *pi;
|
1998-09-14 18:27:06 +00:00
|
|
|
|
1998-10-21 20:07:05 +00:00
|
|
|
pi = malloc(sizeof(struct pnpinfo));
|
|
|
|
bzero(pi, sizeof(struct pnpinfo));
|
|
|
|
STAILQ_INIT(&pi->pi_ident);
|
|
|
|
return(pi);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release storage held by a pnpinfo struct
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pnp_freeinfo(struct pnpinfo *pi)
|
|
|
|
{
|
|
|
|
struct pnpident *id;
|
|
|
|
|
2000-12-30 20:40:16 +00:00
|
|
|
while (!STAILQ_EMPTY(&pi->pi_ident)) {
|
|
|
|
id = STAILQ_FIRST(&pi->pi_ident);
|
1998-10-21 20:07:05 +00:00
|
|
|
STAILQ_REMOVE_HEAD(&pi->pi_ident, id_link);
|
|
|
|
free(id->id_ident);
|
|
|
|
free(id);
|
1998-09-14 18:27:06 +00:00
|
|
|
}
|
1998-10-21 20:07:05 +00:00
|
|
|
if (pi->pi_desc)
|
|
|
|
free(pi->pi_desc);
|
|
|
|
if (pi->pi_module)
|
|
|
|
free(pi->pi_module);
|
|
|
|
if (pi->pi_argv)
|
|
|
|
free(pi->pi_argv);
|
|
|
|
free(pi);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a new pnpinfo struct to the list.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pnp_addinfo(struct pnpinfo *pi)
|
|
|
|
{
|
|
|
|
STAILQ_INSERT_TAIL(&pnp_devices, pi, pi_link);
|
1998-09-04 02:43:26 +00:00
|
|
|
}
|
|
|
|
|
1998-10-22 20:20:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Format an EISA id as a string in standard ISA PnP format, AAAIIRR
|
|
|
|
* where 'AAA' is the EISA vendor ID, II is the product ID and RR the revision ID.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
pnp_eisaformat(u_int8_t *data)
|
|
|
|
{
|
|
|
|
static char idbuf[8];
|
|
|
|
const char hextoascii[] = "0123456789abcdef";
|
|
|
|
|
|
|
|
idbuf[0] = '@' + ((data[0] & 0x7c) >> 2);
|
|
|
|
idbuf[1] = '@' + (((data[0] & 0x3) << 3) + ((data[1] & 0xe0) >> 5));
|
|
|
|
idbuf[2] = '@' + (data[1] & 0x1f);
|
|
|
|
idbuf[3] = hextoascii[(data[2] >> 4)];
|
|
|
|
idbuf[4] = hextoascii[(data[2] & 0xf)];
|
|
|
|
idbuf[5] = hextoascii[(data[3] >> 4)];
|
|
|
|
idbuf[6] = hextoascii[(data[3] & 0xf)];
|
|
|
|
idbuf[7] = 0;
|
|
|
|
return(idbuf);
|
|
|
|
}
|
|
|
|
|