10 * "Plug and Play" functionality.
12 * We use the PnP enumerators to obtain identifiers for installed hardware,
13 * and the contents of a database to determine modules to be loaded to support
19 #include <bootstrap.h>
21 static struct pnpinfo_stql pnp_devices;
22 static int pnp_devices_initted = 0;
24 static void pnp_discard(void);
27 * Perform complete enumeration sweep
30 COMMAND_SET(pnpscan, "pnpscan", "scan for PnP devices", pnp_scan);
33 pnp_scan(int argc, char *argv[])
40 if (pnp_devices_initted == 0) {
41 STAILQ_INIT(&pnp_devices);
42 pnp_devices_initted = 1;
48 while ((ch = getopt(argc, argv, "v")) != -1) {
55 /* getopt has already reported an error */
60 /* forget anything we think we knew */
63 /* iterate over all of the handlers */
64 for (hdlr = 0; pnphandlers[hdlr] != NULL; hdlr++) {
66 printf("Probing %s...\n", pnphandlers[hdlr]->pp_name);
67 pnphandlers[hdlr]->pp_enumerate();
71 if (pager_output("PNP scan summary:\n"))
73 STAILQ_FOREACH(pi, &pnp_devices, pi_link) {
74 pager_output(STAILQ_FIRST(&pi->pi_ident)->id_ident); /* first ident should be canonical */
75 if (pi->pi_desc != NULL) {
77 pager_output(pi->pi_desc);
79 if (pager_output("\n"))
89 * Throw away anything we think we know about PnP devices.
96 while (STAILQ_FIRST(&pnp_devices) != NULL) {
97 pi = STAILQ_FIRST(&pnp_devices);
98 STAILQ_REMOVE_HEAD(&pnp_devices, pi_link);
104 * Add a unique identifier to (pi)
107 pnp_addident(struct pnpinfo *pi, char *ident)
111 STAILQ_FOREACH(id, &pi->pi_ident, id_link)
112 if (!strcmp(id->id_ident, ident))
113 return; /* already have this one */
115 id = malloc(sizeof(struct pnpident));
116 id->id_ident = strdup(ident);
117 STAILQ_INSERT_TAIL(&pi->pi_ident, id, id_link);
121 * Allocate a new pnpinfo struct
128 pi = malloc(sizeof(struct pnpinfo));
129 bzero(pi, sizeof(struct pnpinfo));
130 STAILQ_INIT(&pi->pi_ident);
135 * Release storage held by a pnpinfo struct
138 pnp_freeinfo(struct pnpinfo *pi)
142 while (!STAILQ_EMPTY(&pi->pi_ident)) {
143 id = STAILQ_FIRST(&pi->pi_ident);
144 STAILQ_REMOVE_HEAD(&pi->pi_ident, id_link);
158 * Add a new pnpinfo struct to the list.
161 pnp_addinfo(struct pnpinfo *pi)
163 STAILQ_INSERT_TAIL(&pnp_devices, pi, pi_link);
168 * Format an EISA id as a string in standard ISA PnP format, AAAIIRR
169 * where 'AAA' is the EISA vendor ID, II is the product ID and RR the revision ID.
172 pnp_eisaformat(uint8_t *data)
174 static char idbuf[8];
175 const char hextoascii[] = "0123456789abcdef";
177 idbuf[0] = '@' + ((data[0] & 0x7c) >> 2);
178 idbuf[1] = '@' + (((data[0] & 0x3) << 3) + ((data[1] & 0xe0) >> 5));
179 idbuf[2] = '@' + (data[1] & 0x1f);
180 idbuf[3] = hextoascii[(data[2] >> 4)];
181 idbuf[4] = hextoascii[(data[2] & 0xf)];
182 idbuf[5] = hextoascii[(data[3] >> 4)];
183 idbuf[6] = hextoascii[(data[3] & 0xf)];