Index: head/stand/common/pnp.c =================================================================== --- head/stand/common/pnp.c (revision 328778) +++ head/stand/common/pnp.c (revision 328779) @@ -1,236 +1,186 @@ /* * mjs copyright * */ #include __FBSDID("$FreeBSD$"); /* * "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 #include #include -#ifdef BOOT_FORTH -#include "ficl.h" -#endif static struct pnpinfo_stql pnp_devices; static int pnp_devices_initted = 0; static void pnp_discard(void); /* * Perform complete enumeration sweep */ COMMAND_SET(pnpscan, "pnpscan", "scan for PnP devices", pnp_scan); static int pnp_scan(int argc, char *argv[]) { struct pnpinfo *pi; int hdlr; int verbose; int ch; if (pnp_devices_initted == 0) { STAILQ_INIT(&pnp_devices); pnp_devices_initted = 1; } verbose = 0; optind = 1; optreset = 1; 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); } } /* forget anything we think we knew */ pnp_discard(); /* iterate over all of the handlers */ for (hdlr = 0; pnphandlers[hdlr] != NULL; hdlr++) { if (verbose) printf("Probing %s...\n", pnphandlers[hdlr]->pp_name); pnphandlers[hdlr]->pp_enumerate(); } if (verbose) { pager_open(); if (pager_output("PNP scan summary:\n")) goto out; STAILQ_FOREACH(pi, &pnp_devices, pi_link) { pager_output(STAILQ_FIRST(&pi->pi_ident)->id_ident); /* first ident should be canonical */ if (pi->pi_desc != NULL) { pager_output(" : "); pager_output(pi->pi_desc); } if (pager_output("\n")) break; } out: pager_close(); } return(CMD_OK); } /* * Throw away anything we think we know about PnP devices. */ static void pnp_discard(void) { struct pnpinfo *pi; while (STAILQ_FIRST(&pnp_devices) != NULL) { pi = STAILQ_FIRST(&pnp_devices); STAILQ_REMOVE_HEAD(&pnp_devices, pi_link); pnp_freeinfo(pi); } } /* * Add a unique identifier to (pi) */ void pnp_addident(struct pnpinfo *pi, char *ident) { struct pnpident *id; STAILQ_FOREACH(id, &pi->pi_ident, id_link) 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; 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; while (!STAILQ_EMPTY(&pi->pi_ident)) { id = STAILQ_FIRST(&pi->pi_ident); STAILQ_REMOVE_HEAD(&pi->pi_ident, id_link); free(id->id_ident); free(id); } 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); } /* * 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); } - -#ifdef BOOT_FORTH -void -ficlPnpdevices(FICL_VM *pVM) -{ - static int pnp_devices_initted = 0; -#if FICL_ROBUST > 1 - vmCheckStack(pVM, 0, 1); -#endif - - if(!pnp_devices_initted) { - STAILQ_INIT(&pnp_devices); - pnp_devices_initted = 1; - } - - stackPushPtr(pVM->pStack, &pnp_devices); - - return; -} - -void -ficlPnphandlers(FICL_VM *pVM) -{ -#if FICL_ROBUST > 1 - vmCheckStack(pVM, 0, 1); -#endif - - stackPushPtr(pVM->pStack, pnphandlers); - - return; -} - -/* - * Glue function to add the appropriate forth words to access pnp BIOS - * functionality. - */ -static void ficlCompilePnp(FICL_SYSTEM *pSys) -{ - FICL_DICT *dp = pSys->dp; - assert (dp); - - dictAppendWord(dp, "pnpdevices",ficlPnpdevices, FW_DEFAULT); - dictAppendWord(dp, "pnphandlers",ficlPnphandlers, FW_DEFAULT); -} - -FICL_COMPILE_SET(ficlCompilePnp); -#endif Index: head/stand/forth/pnp.4th =================================================================== --- head/stand/forth/pnp.4th (revision 328778) +++ head/stand/forth/pnp.4th (nonexistent) @@ -1,205 +0,0 @@ -\ Copyright (c) 2000 Daniel C. Sobral -\ All rights reserved. -\ -\ Redistribution and use in source and binary forms, with or without -\ modification, are permitted provided that the following conditions -\ are met: -\ 1. Redistributions of source code must retain the above copyright -\ notice, this list of conditions and the following disclaimer. -\ 2. Redistributions in binary form must reproduce the above copyright -\ notice, this list of conditions and the following disclaimer in the -\ documentation and/or other materials provided with the distribution. -\ -\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -\ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -\ SUCH DAMAGE. -\ -\ $FreeBSD$ - - -\ The following pnp code is used in pnp.4th and pnp.c -structure: STAILQ_HEAD - ptr stqh_first \ type* - ptr stqh_last \ type** -;structure - -structure: STAILQ_ENTRY - ptr stqe_next \ type* -;structure - -structure: pnphandler - ptr pnph.name - ptr pnph.enumerate -;structure - -structure: pnpident - ptr pnpid.ident \ char* - sizeof STAILQ_ENTRY cells member: pnpid.link \ pnpident -;structure - -structure: pnpinfo \ sync with stand/common/bootstrap.h - ptr pnpi.desc - int pnpi.revision - ptr pnpi.module \ (char*) module args - int pnpi.argc - ptr pnpi.argv - ptr pnpi.handler \ pnphandler - sizeof STAILQ_HEAD member: pnpi.ident \ pnpident - sizeof STAILQ_ENTRY member: pnpi.link \ pnpinfo -;structure -\ end of pnp support - -pnpdevices drop - -: enumerate - pnphandlers begin - dup @ - while - ." Probing " dup @ pnph.name @ dup strlen type ." ..." cr - 0 over @ pnph.enumerate @ ccall drop - cell+ - repeat -; - -: summary - ." PNP scan summary:" cr - pnpdevices stqh_first @ - begin - dup - while - dup pnpi.ident stqh_first @ pnpid.ident @ dup strlen type - dup pnpi.desc @ ?dup if - ." : " - dup strlen type - then - cr - pnpi.link stqe_next @ - repeat - drop -; - -: compare-pnpid ( addr addr' -- flag ) - begin - over c@ over c@ <> if drop drop false exit then - over c@ over c@ and - while - char+ swap char+ swap - repeat - c@ swap c@ or 0= -; - -: search-pnpid ( id -- flag ) - >r - pnpdevices stqh_first @ - begin ( pnpinfo ) - dup - while - dup pnpi.ident stqh_first @ - begin ( pnpinfo pnpident ) - dup pnpid.ident @ r@ compare-pnpid - if - r> drop - \ XXX Temporary debugging message - ." Found " pnpid.ident @ dup strlen type - pnpi.desc @ ?dup if - ." : " dup strlen type - then cr - \ drop drop - true - exit - then - pnpid.link stqe_next @ - ?dup 0= - until - pnpi.link stqe_next @ - repeat - r> drop - drop - false -; - -: skip-space ( addr -- addr' ) - begin - dup c@ bl = - over c@ 9 = or - while - char+ - repeat -; - -: skip-to-space ( addr -- addr' ) - begin - dup c@ bl <> - over c@ 9 <> and - over c@ and - while - char+ - repeat -; - -: premature-end? ( addr -- addr flag ) - postpone dup postpone c@ postpone 0= - postpone if postpone exit postpone then -; immediate - -0 value filename -0 value timestamp -0 value id - -only forth also support-functions - -: (load) load ; - -: check-pnpid ( -- ) - line_buffer .addr @ - \ Search for filename - skip-space premature-end? - dup to filename - \ Search for end of filename - skip-to-space premature-end? - 0 over c! char+ - \ Search for timestamp - skip-space premature-end? - dup to timestamp - skip-to-space premature-end? - 0 over c! char+ - \ Search for ids - begin - skip-space premature-end? - dup to id - skip-to-space dup c@ >r - 0 over c! char+ - id search-pnpid if - filename dup strlen 1 ['] (load) catch if - drop drop drop - ." Error loading " filename dup strlen type cr - then - r> drop exit - then - r> 0= - until -; - -: load-pnp - 0 to end_of_file? - reset_line_reading - s" /boot/pnpid.conf" O_RDONLY fopen fd ! - fd @ -1 <> if - begin - end_of_file? 0= - while - read_line - check-pnpid - repeat - fd @ fclose - then -; - Property changes on: head/stand/forth/pnp.4th ___________________________________________________________________ Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property