8 * "Plug and Play" functionality.
10 * We use the PnP enumerators to obtain identifiers for installed hardware,
11 * and the contents of a database to determine modules to be loaded to support
17 #include <bootstrap.h>
19 static struct pnpinfo_stql pnp_devices;
20 static int pnp_devices_initted = 0;
22 static void pnp_discard(void);
25 * Perform complete enumeration sweep
28 COMMAND_SET(pnpscan, "pnpscan", "scan for PnP devices", pnp_scan);
31 pnp_scan(int argc, char *argv[])
38 if (pnp_devices_initted == 0) {
39 STAILQ_INIT(&pnp_devices);
40 pnp_devices_initted = 1;
46 while ((ch = getopt(argc, argv, "v")) != -1) {
53 /* getopt has already reported an error */
58 /* forget anything we think we knew */
61 /* iterate over all of the handlers */
62 for (hdlr = 0; pnphandlers[hdlr] != NULL; hdlr++) {
64 printf("Probing %s...\n", pnphandlers[hdlr]->pp_name);
65 pnphandlers[hdlr]->pp_enumerate();
69 if (pager_output("PNP scan summary:\n"))
71 STAILQ_FOREACH(pi, &pnp_devices, pi_link) {
72 pager_output(STAILQ_FIRST(&pi->pi_ident)->id_ident); /* first ident should be canonical */
73 if (pi->pi_desc != NULL) {
75 pager_output(pi->pi_desc);
77 if (pager_output("\n"))
87 * Throw away anything we think we know about PnP devices.
94 while (STAILQ_FIRST(&pnp_devices) != NULL) {
95 pi = STAILQ_FIRST(&pnp_devices);
96 STAILQ_REMOVE_HEAD(&pnp_devices, pi_link);
102 * Add a unique identifier to (pi)
105 pnp_addident(struct pnpinfo *pi, char *ident)
109 STAILQ_FOREACH(id, &pi->pi_ident, id_link)
110 if (!strcmp(id->id_ident, ident))
111 return; /* already have this one */
113 id = malloc(sizeof(struct pnpident));
114 id->id_ident = strdup(ident);
115 STAILQ_INSERT_TAIL(&pi->pi_ident, id, id_link);
119 * Allocate a new pnpinfo struct
126 pi = malloc(sizeof(struct pnpinfo));
127 bzero(pi, sizeof(struct pnpinfo));
128 STAILQ_INIT(&pi->pi_ident);
133 * Release storage held by a pnpinfo struct
136 pnp_freeinfo(struct pnpinfo *pi)
140 while (!STAILQ_EMPTY(&pi->pi_ident)) {
141 id = STAILQ_FIRST(&pi->pi_ident);
142 STAILQ_REMOVE_HEAD(&pi->pi_ident, id_link);
156 * Add a new pnpinfo struct to the list.
159 pnp_addinfo(struct pnpinfo *pi)
161 STAILQ_INSERT_TAIL(&pnp_devices, pi, pi_link);
166 * Format an EISA id as a string in standard ISA PnP format, AAAIIRR
167 * where 'AAA' is the EISA vendor ID, II is the product ID and RR the revision ID.
170 pnp_eisaformat(uint8_t *data)
172 static char idbuf[8];
173 const char hextoascii[] = "0123456789abcdef";
175 idbuf[0] = '@' + ((data[0] & 0x7c) >> 2);
176 idbuf[1] = '@' + (((data[0] & 0x3) << 3) + ((data[1] & 0xe0) >> 5));
177 idbuf[2] = '@' + (data[1] & 0x1f);
178 idbuf[3] = hextoascii[(data[2] >> 4)];
179 idbuf[4] = hextoascii[(data[2] & 0xf)];
180 idbuf[5] = hextoascii[(data[3] >> 4)];
181 idbuf[6] = hextoascii[(data[3] & 0xf)];