diff --git a/usr.sbin/pccard/pccardd/Makefile b/usr.sbin/pccard/pccardd/Makefile deleted file mode 100644 index b7fae27df8bc..000000000000 --- a/usr.sbin/pccard/pccardd/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# Makefile for pccardd -# $FreeBSD$ - -.PATH: ${.CURDIR}/../pccardc - -PROG= pccardd -MAN= pccard.conf.5 pccardd.8 -SRCS= pccardd.c cardd.c file.c util.c readcis.c printcis.c server.c - -CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../pccardc - -DPADD= ${LIBUTIL} -LDADD= -lutil - -.include diff --git a/usr.sbin/pccard/pccardd/cardd.c b/usr.sbin/pccard/pccardd/cardd.c deleted file mode 100644 index c91ecd259d3d..000000000000 --- a/usr.sbin/pccard/pccardd/cardd.c +++ /dev/null @@ -1,1025 +0,0 @@ -/* - * Copyright (c) 1995 Andrew McRae. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "cardd.h" - -static struct card_config *assign_driver(struct slot *, struct card *); -static int assign_io(struct slot *); -static int setup_slot(struct slot *); -static void card_inserted(struct slot *); -static void card_removed(struct slot *); -static void pr_cmd(struct cmd *); -static void read_ether(struct slot *); -static void read_ether_attr2(struct slot *sp); - -struct slot *slots; - -/* - * Dump configuration file data. - */ -void -dump_config_file(void) -{ - struct card *cp; - struct card_config *confp; - - for (cp = cards; cp; cp = cp->next) { - printf("Card manuf %s, vers %s\n", cp->manuf, cp->version); - printf("Configuration entries:\n"); - for (confp = cp->config; confp; confp = confp->next) { - printf("\tIndex code = "); - switch (confp->index_type) { - case DEFAULT_INDEX: - printf("default"); - break; - case AUTO_INDEX: - printf("auto"); - break; - default: - printf("0x%x", confp->index); - break; - } - printf(", driver name = %s\n", confp->driver->name); - } - if (cp->insert) { - printf("Insert commands are:\n"); - pr_cmd(cp->insert); - } - if (cp->remove) { - printf("Remove commands are:\n"); - pr_cmd(cp->remove); - } - } - fflush(stdout); -} - -static void -pr_cmd(struct cmd *cp) -{ - while (cp) { - printf("\t%s\n", cp->line); - cp = cp->next; - } -} - -/* - * readslots - read all the PCMCIA slots, and build - * a list of the slots. - */ -struct slot * -readslots(void) -{ - char name[128]; - int i, fd; - struct slot *sp; - - slots = NULL; - for (i = 0; i < MAXSLOT; i++) { - sprintf(name, CARD_DEVICE, i); - fd = open(name, O_RDWR); - if (fd < 0) - continue; - sp = xmalloc(sizeof(*sp)); - sp->fd = fd; - sp->name = newstr(name); - sp->slot = i; - - /* Check to see if the controller memory has been set up. */ - if (slots == 0) { - unsigned long mem = 0; - - if (ioctl(fd, PIOCRWMEM, &mem)) - logerr("ioctl (PIOCRWMEM)"); -#ifdef DEBUG - logmsg("mem=0x%x\n", mem); -#endif - if (mem == 0) { - mem = alloc_memory(4 * 1024); - if (mem == 0) - die("can't allocate memory for " - "controller access"); - if (ioctl(fd, PIOCRWMEM, &mem)) - logerr("ioctl (PIOCRWMEM)"); - } - } - sp->next = slots; - slots = sp; - slot_change(sp); - } - return (slots); -} - -/* - * slot_change - Card status has changed. - * read new state and process. - */ -void -slot_change(struct slot *sp) -{ - struct slotstate state; - - if (ioctl(sp->fd, PIOCGSTATE, &state)) { - logerr("ioctl (PIOCGSTATE)"); - return; - } - switch (state.state) { - case empty: - case inactive: - case noslot: - /* Debounce potentially incorrectly reported removals */ - if (state.laststate == filled || state.laststate == suspend) - card_removed(sp); - break; - case filled: - /* KLUDGE: if we were suspended, remove card */ - if (state.laststate == suspend) - card_removed(sp); - card_inserted(sp); - break; - case suspend: - /* ignored */ - break; - } - sp->state = state.state; - stat_changed(sp); -} - -/* - * card_removed - card has been removed from slot. - * Execute the remove commands, and clear the slot's state. - * Execute the device commands, then the driver commands - * and then the card commands. This is the reverse - * order to the insertion commands - */ -void -card_removed(struct slot *sp) -{ - struct card *cp; - struct allocblk *sio; - int in_use = 0; - - if (sp->config && sp->config->driver && sp->card) - logmsg("%s%d: %s removed.", sp->config->driver->kernel, - sp->config->driver->unit, sp->card->logstr); - if (sp->cis) - freecis(sp->cis); - if (sp->config) { - if (sp->config->inuse && sp->config->driver->inuse) - in_use = 1; - sp->config->inuse = 0; - sp->config->driver->inuse = 0; - } - if ((cp = sp->card) != 0 && in_use) - execute(cp->remove, sp); - sp->cis = 0; - sp->config = 0; - /* release io */ - if (sp->flags & IO_ASSIGNED) - for (sio = &sp->io; sio; sio = sio->next) - if (sio->addr && sio->size) - bit_nset(io_avail, sio->addr, sio->addr + sio->size - 1); - /* release irq */ - if (sp->flags & IRQ_ASSIGNED) - if (sp->irq >= 1 && sp->irq <= 15) - pool_irq[sp->irq] = 1; -} - -/* CIS string comparison */ - -#define REGCOMP_FLAGS (REG_EXTENDED | REG_NOSUB) -#define REGEXEC_FLAGS (0) - -static int -cis_strcmp(char *db, char *cis) -{ - int res, err; - char buf[256]; - regex_t rx; - char * p; - size_t n; - - if (!db || !cis) { - return -1; - } - n = strlen(db); - if (n > 2 && db[0] == '/' && db[n-1] == '/') { - /* matching by regex */ - db++; - } else { - /* otherwise, matching by strncmp() */ - if (n != strlen(cis)) { - return -1; - } - - return strncmp(db, cis, n); - } - p = xmalloc(n); - strncpy(p + 1, db, n-2); - *p = '^'; - db = p; - if ((err = regcomp(&rx, p, REGCOMP_FLAGS))) { - regerror(err, &rx, buf, sizeof buf); - logmsg("Warning: REGEX error for\"%s\" -- %s\n", p, buf); - regfree(&rx); - free(p); - return -1; - } - res = regexec(&rx, cis, 0, NULL, REGEXEC_FLAGS); - regfree(&rx); - free(p); - return res; -} - -/* - * card_inserted - Card has been inserted; - * - Read the CIS - * - match the card type. - * - Match the driver and allocate a driver instance. - * - Allocate I/O ports, memory and IRQ. - * - Set up the slot. - * - assign the driver (if failed, then terminate). - * - Run the card commands. - * - Run the driver commands - * - Run the device commands - */ -void -card_inserted(struct slot *sp) -{ - struct card *cp; - int err; - - usleep(pccard_init_sleep); - sp->cis = readcis(sp->fd); - if (sp->cis == 0) { - logmsg("Error reading CIS on %s\n", sp->name); - return; - } -#if 0 - dumpcis(sp->cis); -#endif - for (cp = cards; cp; cp = cp->next) { - switch (cp->deftype) { - case DT_VERS: - if (cis_strcmp(cp->manuf, sp->cis->manuf) == 0 && - cis_strcmp(cp->version, sp->cis->vers) == 0) { - if (cp->add_info1 != NULL && - cis_strcmp(cp->add_info1, sp->cis->add_info1) != 0) { - break; - } - if (cp->add_info2 != NULL && - cis_strcmp(cp->add_info2, sp->cis->add_info2) != 0) { - break; - } - - logmsg("Card \"%s\"(\"%s\") " - "[%s] [%s] " - "matched \"%s\" (\"%s\") " - "[%s] [%s] ", - sp->cis->manuf, sp->cis->vers, - sp->cis->add_info1, sp->cis->add_info2, - cp->manuf, cp->version, - cp->add_info1, cp->add_info2); - goto escape; - } - break; - case DT_FUNC: - if (cp->func_id == sp->cis->func_id1) { - logmsg("Card \"%s\"(\"%s\") " - "[%s] [%s] " - "has function ID %d\n", - sp->cis->manuf, sp->cis->vers, - sp->cis->add_info1, sp->cis->add_info2, - cp->func_id); - goto escape; - } - break; - default: - logmsg("Unknown deftype %d\n", cp->deftype); - die("cardd.c:card_inserted()"); - } - } -escape: - sp->card = cp; -#if 0 - reset_slot(sp); -#endif - if (cp == 0) { - logmsg("No card in database for \"%s\"(\"%s\")", - sp->cis->manuf, sp->cis->vers); - return; - } - /* - * Copy CIS_MANUF_ID and CIS_FUNC_EXT from "struct cis" - * to "struct slot" - */ - if (sp->cis->lan_nid && sp->cis->lan_nid[0] == sizeof(sp->eaddr)) { - bcopy(sp->cis->lan_nid + 1, sp->eaddr, sizeof(sp->eaddr)); - sp->flags |= EADDR_CONFIGED; - } else { - bzero(sp->eaddr, sizeof(sp->eaddr)); - } - if (sp->cis->manufacturer && sp->cis->product) { - sp->manufacturer = sp->cis->manufacturer; - sp->product = sp->cis->product; - sp->prodext = sp->cis->prodext; /* For xe driver */ - } else { - sp->manufacturer = 0; - sp->product = 0; - sp->prodext = 0; - } - if (sp->cis->manuf) - strlcpy(sp->manufstr, sp->cis->manuf, sizeof(sp->manufstr)); - if (sp->cis->vers) - strlcpy(sp->versstr, sp->cis->vers, sizeof(sp->versstr)); - if (sp->cis->add_info1) - strlcpy(sp->cis3str, sp->cis->add_info1, sizeof(sp->cis3str)); - if (sp->cis->add_info2) - strlcpy(sp->cis4str, sp->cis->add_info2, sizeof(sp->cis4str)); - - if (cp->ether) { - struct ether *e = 0; - e = cp->ether; - switch (e->type) { - case ETHTYPE_ATTR2: - read_ether_attr2(sp); - break; - default: - read_ether(sp); - break; - } - } - if ((sp->config = assign_driver(sp, cp)) == NULL) - return; - if ((err = assign_io(sp))) { - char *reason; - - switch (err) { - case -1: - reason = "specified CIS was not found"; - break; - case -2: - reason = "memory block allocation failed"; - break; - case -3: - reason = "I/O block allocation failed"; - break; - case -4: - reason = "requires more than one memory window"; - break; - default: - reason = "Unknown"; - break; - } - logmsg("Resource allocation failure for \"%s\"(\"%s\") " - "[%s] [%s]; Reason %s\n", - sp->cis->manuf, sp->cis->vers, - sp->cis->add_info1, sp->cis->add_info2, reason); - return; - } - - /* - * - * Once assigned, set up the I/O & mem contexts, set up the - * windows, and then attach the driver. - */ - if (setup_slot(sp)) - execute(cp->insert, sp); -#if 0 - else - reset_slot(sp); -#endif -} - -/* - * read_ether - read ethernet address from card. Offset is - * the offset into the attribute memory of the card. - */ -static void -read_ether(struct slot *sp) -{ - unsigned char net_addr[12]; - int flags = MDF_ATTR; /* attribute memory */ - - ioctl(sp->fd, PIOCRWFLAG, &flags); - lseek(sp->fd, (off_t)sp->card->ether->value, SEEK_SET); - if (read(sp->fd, net_addr, sizeof(net_addr)) != sizeof(net_addr)) { - logerr("read err on net addr"); - return; - } - sp->eaddr[0] = net_addr[0]; - sp->eaddr[1] = net_addr[2]; - sp->eaddr[2] = net_addr[4]; - sp->eaddr[3] = net_addr[6]; - sp->eaddr[4] = net_addr[8]; - sp->eaddr[5] = net_addr[10]; - logmsg("Ether=%02x:%02x:%02x:%02x:%02x:%02x\n", - sp->eaddr[0], sp->eaddr[1], sp->eaddr[2], - sp->eaddr[3], sp->eaddr[4], sp->eaddr[5]); - sp->flags |= EADDR_CONFIGED; -} - -/* - * Megahertz X-Jack Ethernet uses unique way to get/set MAC - * address of the card. - */ -static void -read_ether_attr2(struct slot *sp) -{ - int i; - char *hexaddr; - - hexaddr = sp->cis->add_info2; - for (i = 0; i < 6; i++) - sp->eaddr[i] = 0; - if (!hexaddr) - return; - if (strlen(hexaddr) != 12) - return; - for (i = 0; i < 12; i++) - if (!isxdigit(hexaddr[i])) - return; - for (i = 0; i < 6; i++) { - u_int d; - char s[3]; - s[0] = hexaddr[i * 2]; - s[1] = hexaddr[i * 2 + 1]; - s[2] = '\0'; - if (!sscanf(s, "%x", &d)) { - int j; - for (j = 0; j < 6; j++) - sp->eaddr[j] = 0; - return; - } - sp->eaddr[i] = (u_char)d; - } - sp->flags |= EADDR_CONFIGED; -} - - -/* - * assign_driver - Assign driver to card. - * First, see if an existing driver is already setup. - */ -static struct card_config * -assign_driver(struct slot *sp, struct card *cp) -{ - struct driver *drvp; - struct card_config *conf; - struct pccard_resource res; - int i; - int irqmin, irqmax; - - for (conf = cp->config; conf; conf = conf->next) - if (conf->inuse == 0 && conf->driver->card == cp && - conf->driver->config == conf && - conf->driver->inuse == 0) { - if (debug_level > 0) { - logmsg("Found existing driver (%s) for %s\n", - conf->driver->name, cp->manuf); - } - conf->driver->inuse = 1; - conf->inuse = 1; - return (conf); - } - /* - * New driver must be allocated. Find the first configuration - * not in use. - */ - for (conf = cp->config; conf; conf = conf->next) - if (conf->inuse == 0 && conf->driver->inuse/*card*/ == 0) - break; - if (conf == 0) { - logmsg("No free configuration for card %s", cp->manuf); - return (NULL); - } - /* - * Now we have a free driver and a matching configuration. - * Before assigning and allocating everything, check to - * see if a device class can be allocated to this. - */ - drvp = conf->driver; - - /* If none available, then we can't use this card. */ - if (drvp->inuse) { - logmsg("Driver already being used for %s", cp->manuf); - return (NULL); - } - - /* - * Allocate a free IRQ if none has been specified. When we're - * sharing interrupts (cardbus bridge case), then we'll use what - * the kernel tells us to use, reguardless of what the user - * configured. Asking the kernel for IRQ 0 is our way of asking - * if we should use a shared interrupt. - */ - res.type = SYS_RES_IRQ; - res.size = 1; - if (conf->irq == 0) { - irqmin = 1; - irqmax = 15; - } else { - irqmin = irqmax = conf->irq; - conf->irq = 0; /* Make sure we get it. */ - } - res.min = 0; - res.max = 0; - if (ioctl(sp->fd, PIOCSRESOURCE, &res) < 0) - err(1, "ioctl (PIOCSRESOURCE)"); - if (res.resource_addr != ~0ul) { - conf->irq = res.resource_addr; - pool_irq[conf->irq] = 0; - } else { - for (i = irqmin; i <= irqmax; i++) { - /* - * Skip irqs not in the pool. - */ - if (pool_irq[i] == 0) - continue; - /* - * -I forces us to use the interrupt, so use it. - */ - if (!use_kern_irq) { - conf->irq = i; - pool_irq[i] = 0; - break; - } - /* - * Ask the kernel if we have a free irq. - */ - res.min = i; - res.max = i; - if (ioctl(sp->fd, PIOCSRESOURCE, &res) < 0) - err(1, "ioctl (PIOCSRESOURCE)"); - if (res.resource_addr == ~0ul) - continue; - /* - * res.resource_addr might be the kernel's - * better idea than i, so we have to check to - * see if that's in use too. If not, mark it - * in use and break out of the loop. I'm not - * sure this can happen when IRQ 0 above fails, - * but the test is cheap enough. - */ - if (pool_irq[res.resource_addr] == 0) - continue; - conf->irq = res.resource_addr; - pool_irq[conf->irq] = 0; - break; - } - } - if (conf->irq == 0) { - logmsg("Failed to allocate IRQ for %s\n", cp->manuf); - return (NULL); - } - drvp->card = cp; - drvp->config = conf; - drvp->inuse = 1; - conf->inuse = 1; - return (conf); -} - -/* - * Auto select config index - */ -static struct cis_config * -assign_card_index(struct slot *sp, struct cis * cis) -{ - struct cis_config *cp; - struct cis_ioblk *cio; - struct pccard_resource res; - int i; - - res.type = SYS_RES_IOPORT; - for (cp = cis->conf; cp; cp = cp->next) { - if (!cp->iospace || !cp->io) - continue; - for (cio = cp->io; cio; cio = cio->next) { - res.size = cio->size; - res.min = cio->addr; - res.max = res.min + cio->size - 1; - if (ioctl(sp->fd, PIOCSRESOURCE, &res) < 0) - err(1, "ioctl (PIOCSRESOURCE)"); - if (res.resource_addr != cio->addr) - goto next; - for (i = cio->addr; i < cio->addr + cio->size - 1; i++) - if (!bit_test(io_avail, i)) - goto next; - } - return cp; /* found */ - next:; - } - return cis->def_config; -} - -/* - * assign_io - Allocate resources to slot matching the - * configuration index selected. - */ -static int -assign_io(struct slot *sp) -{ - struct cis *cis; - struct cis_config *cisconf, *defconf; - - cis = sp->cis; - defconf = cis->def_config; - switch (sp->config->index_type) { - case DEFAULT_INDEX: /* default */ - cisconf = defconf; - sp->config->index = cisconf->id; - break; - case AUTO_INDEX: /* auto */ - cisconf = assign_card_index(sp, cis); - if (cisconf) - sp->config->index = cisconf->id; - break; - default: /* normal, use index value */ - for (cisconf = cis->conf; cisconf; cisconf = cisconf->next) - if (cisconf->id == sp->config->index) - break; - } - - if (cisconf == 0) { - logmsg("Config id %d not present in this card", - sp->config->index); - return (-1); - } - sp->card_config = cisconf; - - /* - * Found a matching configuration. Now look at the I/O, memory and IRQ - * to create the desired parameters. Look at memory first. - */ - - /* Skip ed cards in PIO mode */ - if ((strncmp(sp->config->driver->name, "ed", 2) == 0) && - (sp->config->flags & 0x10)) - goto memskip; - - if (cisconf->memspace || (defconf && defconf->memspace)) { - struct cis_memblk *mp; - - mp = cisconf->mem; - /* - * Currently we do not handle the presence of multiple windows. - * Then again neither does the interface to the kernel! - * See setup_slot() and readcis.c:cis_conf() - */ - if (cisconf->memwins > 1) { - logmsg("Card requires %d memory windows.", - cisconf->memwins); - return (-4); - } - - if (!cisconf->memspace) - mp = defconf->mem; - sp->mem.size = mp->length; - sp->mem.cardaddr = mp->address; - - /* For now, we allocate our own memory from the pool. */ - sp->mem.addr = sp->config->driver->mem; - /* - * Host memory address is required. Allocate one - * from our pool. - */ - if (sp->mem.size && sp->mem.addr == 0) { - sp->mem.addr = alloc_memory(mp->length); - if (sp->mem.addr == 0) - return (-2); - sp->config->driver->mem = sp->mem.addr; - } - /* Driver specific set up */ - if (strncmp(sp->config->driver->name, "ed", 2) == 0) { - sp->mem.cardaddr = 0x4000; - sp->mem.flags = MDF_ACTIVE | MDF_16BITS; - } else { - sp->mem.flags = MDF_ACTIVE | MDF_16BITS; - } - - if (sp->mem.flags & MDF_ACTIVE) - sp->flags |= MEM_ASSIGNED; - if (debug_level > 0) { - logmsg("Using mem addr 0x%x, size %d, card addr 0x%x, flags 0x%x\n", - sp->mem.addr, sp->mem.size, sp->mem.cardaddr, - sp->mem.flags); - } - } -memskip: - - /* Now look at I/O. */ - bzero(&sp->io, sizeof(sp->io)); - if (cisconf->iospace || (defconf && defconf->iospace) - || sp->card->iosize) { - struct cis_config *cp; - struct cis_ioblk *cio; - struct allocblk *sio; - int x, xmax; - int iosize; - - cp = cisconf; - if (!cisconf->iospace) - cp = defconf; - iosize = sp->card->iosize; - - /* iosize auto */ - if (iosize < 0) { - if (cp->io) - iosize = cp->io->size; - else - iosize = 1 << cp->io_addr; - } - - /* - * If # of I/O lines decoded == 10, then card does its - * own decoding. - * - * If an I/O block exists, then use it. - * If no address (but a length) is available, allocate - * from the pool. - */ - cio = cp->io; - sio = &(sp->io); - xmax = 1; - if (iosize == 0 && cio) - xmax = cisconf->io_blks; - for (x = 0; x < xmax; x++) { - if (iosize) { - sio->addr = 0; - sio->size = iosize; - } else if (cio) { - sio->addr = cio->addr; - sio->size = cio->size; - } else { - /* - * No I/O block, assume the address lines - * decode gives the size. - */ - sio->size = 1 << cp->io_addr; - } - if (sio->addr == 0) { - struct pccard_resource res; - int i, j; - - res.type = SYS_RES_IOPORT; - res.size = sio->size; - - for (i = 0; i < IOPORTS; i++) { - j = bit_fns(io_avail, IOPORTS, i, - sio->size, sio->size); - if ((j & (sio->size - 1)) != 0) - continue; - res.min = j; - res.max = j + sio->size - 1; - if (ioctl(sp->fd, PIOCSRESOURCE, &res) < 0) - err(1, "ioctl (PIOCSRESOURCE)"); - if (res.resource_addr == j) - break; - } - if (j < 0) { - return (-3); - } else { - sio->addr = j; - } - } - bit_nclear(io_avail, sio->addr, - sio->addr + sio->size - 1); - sp->flags |= IO_ASSIGNED; - - /* Set up the size to take into account the decode lines. */ - sio->cardaddr = cp->io_addr; - switch (cp->io_bus) { - case 0: - break; - case 1: - sio->flags = IODF_WS; - break; - case 2: - sio->flags = IODF_WS | IODF_CS16; - break; - case 3: - sio->flags = IODF_WS | IODF_CS16 | IODF_16BIT; - break; - } - if (debug_level > 0) { - logmsg("Using I/O addr 0x%x, size %d\n", - sio->addr, sio->size); - } - if (cio && cio->next) { - sio->next = xmalloc(sizeof(*sio)); - sio = sio->next; - cio = cio->next; - } - } - } - sp->irq = sp->config->irq; - sp->flags |= IRQ_ASSIGNED; - return (0); -} - -/* - * setup_slot - Allocate the I/O and memory contexts - * return true if completed OK. - */ -static int -setup_slot(struct slot *sp) -{ - struct mem_desc mem; - struct io_desc io; - struct dev_desc drv; - struct driver *drvp = sp->config->driver; - struct allocblk *sio; - char *p; - char c; - off_t offs; - int rw_flags; - int iowin; - - memset(&io, 0, sizeof io); - memset(&drv, 0, sizeof drv); - offs = sp->cis->reg_addr; - rw_flags = MDF_ATTR; - ioctl(sp->fd, PIOCRWFLAG, &rw_flags); -#if RESET_MAY_BE_HARMFUL - lseek(sp->fd, offs, SEEK_SET); - c = 0x80; - write(sp->fd, &c, sizeof(c)); - usleep(sp->card->reset_time * 1000); - lseek(sp->fd, offs, SEEK_SET); - c = 0x00; - write(sp->fd, &c, sizeof(c)); - usleep(sp->card->reset_time * 1000); -#endif - lseek(sp->fd, offs, SEEK_SET); - c = sp->config->index; - c |= 0x40; - write(sp->fd, &c, sizeof(c)); - if (debug_level > 0) { - logmsg("Setting config reg at offs 0x%lx to 0x%x, " - "Reset time = %d ms\n", (unsigned long)offs, c, - sp->card->reset_time); - } - usleep(pccard_init_sleep); - usleep(sp->card->reset_time * 1000); - - /* If other config registers exist, set them up. */ - if (sp->cis->ccrs & 2) { - /* CCSR */ - c = 0; - if (sp->cis->def_config && sp->cis->def_config->misc_valid && - (sp->cis->def_config->misc & 0x8)) - c |= 0x08; - if (sp->card_config->io_bus == 1) - c |= 0x20; - lseek(sp->fd, offs + 2, SEEK_SET); - write(sp->fd, &c, sizeof(c)); - } - if (sp->flags & MEM_ASSIGNED) { - mem.window = 0; - mem.flags = sp->mem.flags; - mem.start = (caddr_t) sp->mem.addr; - mem.card = sp->mem.cardaddr; - mem.size = sp->mem.size; - if (ioctl(sp->fd, PIOCSMEM, &mem)) { - logerr("ioctl (PIOCSMEM)"); - return (0); - } - } - if (sp->flags & IO_ASSIGNED) { - for (iowin = 0, sio = &(sp->io); iowin <= 1; iowin++) { - io.window = iowin; - if (sio->size) { - io.flags = sio->flags; - io.start = sio->addr; - io.size = sio->size; - } -#if 0 - io.start = sp->io.addr & ~((1 << sp->io.cardaddr) - 1); - io.size = 1 << sp->io.cardaddr; - if (io.start < 0x100) { - io.start = 0x100; - io.size = 0x300; - } -#endif - if (debug_level > 0) { - logmsg("Assigning I/O window %d, start 0x%x, " - "size 0x%x flags 0x%x\n", io.window, io.start, - io.size, io.flags); - } - io.flags |= IODF_ACTIVE; - if (ioctl(sp->fd, PIOCSIO, &io)) { - logerr("ioctl (PIOCSIO)"); - return (0); - } - if (ioctl(sp->fd, PIOCGIO, &io)) - { - logerr("ioctl (PIOCGIO)"); - return(0); - } - if (io.start != sio->addr){ - logmsg("I/O base address changed from 0x%x to 0x%x\n", - sio->addr, io.start); - sio->addr = io.start; - } - if (sio->next) - sio = sio->next; - else - break; - } - } - strcpy(drv.name, drvp->kernel); - drv.unit = drvp->unit; - drv.irqmask = 1 << sp->irq; - drv.flags = sp->config->flags; - if (sp->flags & MEM_ASSIGNED) { - drv.mem = sp->mem.addr; - drv.memsize = sp->mem.size; - } else { - drv.mem = 0; - drv.memsize = 0; - } - if (sp->flags & IO_ASSIGNED) - drv.iobase = sp->io.addr; - else - drv.iobase = 0; - drv.iosize = sp->io.size; - if (debug_level > 0) { - logmsg("Assign %s%d, io 0x%x-0x%x, mem 0x%lx, %d bytes, " - "irq %d, flags %x\n", drv.name, drv.unit, drv.iobase, - drv.iobase + sp->io.size - 1, drv.mem, drv.memsize, - sp->irq, drv.flags); - } - /* - * Copy CIS_MANUF_ID from "struct slot" to "struct dev_desc" - * This means moving CIS_MANUF_ID to kernel driver area. - */ - drv.manufacturer = sp->manufacturer; - drv.product = sp->product; - drv.prodext = sp->prodext; - strlcpy(drv.manufstr, sp->manufstr, sizeof(drv.manufstr)); - strlcpy(drv.versstr, sp->versstr, sizeof(drv.versstr)); - strlcpy(drv.cis3str, sp->cis3str, sizeof(drv.cis3str)); - strlcpy(drv.cis4str, sp->cis4str, sizeof(drv.cis4str)); - /* - * If the driver fails to be connected to the device, - * then it may mean that the driver did not recognise it. - */ - memcpy(drv.misc, sp->eaddr, 6); - if (ioctl(sp->fd, PIOCSDRV, &drv)) { - logmsg("driver allocation failed for %s(%s): %s", - sp->card->manuf, sp->card->version, strerror(errno)); - return (0); - } - drv.name[sizeof(drv.name) - 1] = '\0'; - if (strncmp(drv.name, drvp->kernel, sizeof(drv.name))) { - drvp->kernel = newstr(drv.name); - p = drvp->kernel; - while (*p++) - if (*p >= '0' && *p <= '9') { - drvp->unit = atoi(p); - *p = '\0'; - break; - } - } - logmsg("%s%d: %s inserted.", sp->config->driver->kernel, - sp->config->driver->unit, sp->card->logstr); - return (1); -} diff --git a/usr.sbin/pccard/pccardd/cardd.h b/usr.sbin/pccard/pccardd/cardd.h deleted file mode 100644 index ab7a0e1b4ea7..000000000000 --- a/usr.sbin/pccard/pccardd/cardd.h +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 1995 Andrew McRae. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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$ - * - * Common include file for PCMCIA daemon - */ -#include - -#include -#include - -#include "readcis.h" - -#ifndef EXTERN -#define EXTERN extern -#endif - -struct cmd { - struct cmd *next; - char *line; /* Command line */ - int macro; /* Contains macros */ -}; - -struct card_config { - struct card_config *next; - unsigned char index_type; - unsigned char index; - struct driver *driver; - int irq; - int flags; - char inuse; -}; - -struct ether { - struct ether *next; - int type; - int value; -}; - -#define ETHTYPE_GENERIC 0 -#define ETHTYPE_ATTR2 1 - -struct card { - struct card *next; - char *manuf; - char *version; - char *add_info1; - char *add_info2; - u_char func_id; - int deftype; - struct ether *ether; /* For net cards, ether at offset */ - int reset_time; /* Reset time */ - int iosize; /* I/O window size (ignore location) */ - struct card_config *config; /* List of configs */ - struct cmd *insert; /* Insert commands */ - struct cmd *remove; /* Remove commands */ - char *logstr; /* String for logger */ -}; - -struct driver { - struct driver *next; - char *name; - char *kernel; /* Kernel driver base name */ - int unit; /* Unit of driver */ - /* - * The rest of the structure is allocated dynamically. - * Once allocated, it stays allocated. - */ - struct card *card; /* Current card, if any */ - struct card_config *config; /* Config back ptr */ - unsigned int mem; /* Allocated host address (if any) */ - int inuse; -}; - -/* - * Defines one allocation block i.e a starting address - * and size. Used for either memory or I/O ports - */ -struct allocblk { - struct allocblk *next; - int addr; /* Address */ - int size; /* Size */ - int flags; /* Flags for block */ - int cardaddr; /* Card address */ -}; -/* - * Slot structure - data held for each slot. - */ -struct slot { - struct slot *next; - int fd; - int mask; - int slot; - char *name; - enum cardstate state; - struct cis *cis; - struct card *card; /* Current card */ - struct card_config *config; /* Current configuration */ - struct cis_config *card_config; - char devname[16]; - u_int manufacturer; - u_int product; - u_int prodext; - unsigned char eaddr[6]; /* If any */ - char manufstr[DEV_MAX_CIS_LEN]; - char versstr[DEV_MAX_CIS_LEN]; - char cis3str[DEV_MAX_CIS_LEN]; - char cis4str[DEV_MAX_CIS_LEN]; - struct allocblk io; /* I/O block spec */ - struct allocblk mem; /* Memory block spec */ - int irq; /* Irq value */ - int flags; /* Resource assignment flags */ -}; - -/* - * Slot resource assignment/configuration flags - */ -#define IO_ASSIGNED 0x1 -#define MEM_ASSIGNED 0x2 -#define IRQ_ASSIGNED 0x4 -#define EADDR_CONFIGED 0x8 -#define WL_CONFIGED 0x10 -#define AFLAGS (IO_ASSIGNED | MEM_ASSIGNED | IRQ_ASSIGNED) -#define CFLAGS (EADDR_CONFIGED | WL_CONFIGED) - -EXTERN struct slot *slots, *current_slot; -EXTERN int slen; - -EXTERN struct allocblk *pool_ioblks; /* I/O blocks in the pool */ -EXTERN struct allocblk *pool_mem; /* Memory in the pool */ -EXTERN int pool_irq[16]; /* IRQ allocations */ -EXTERN int irq_init[16]; /* initial IRQ allocations */ -EXTERN struct driver *drivers; /* List of drivers */ -EXTERN struct card *cards; -EXTERN struct card *last_card; -EXTERN bitstr_t *mem_avail; -EXTERN bitstr_t *mem_init; -EXTERN bitstr_t *io_avail; -EXTERN bitstr_t *io_init; -EXTERN int pccard_init_sleep; /* Time to sleep on init */ -EXTERN int use_kern_irq; -EXTERN int debug_level; - -/* cardd.c functions */ -void dump_config_file(void); -struct slot *readslots(void); -void slot_change(struct slot *); - -/* util.c functions */ -unsigned long alloc_memory(int); -int bit_fns(bitstr_t *, int, int, int, int); -void die(char *); -void execute(struct cmd *, struct slot *); -void logmsg(const char *, ...); -void log_setup(void); -void logerr(char *); -char *newstr(); -void reset_slot(struct slot *); -void *xmalloc(int); - -/* file.c functions */ -void readfile(char *); - -/* server.c functions */ -void set_socket(int); -void stat_changed(struct slot *); -void process_client(void); - -#define IOPORTS 0x1000 /* allow most of the low ports */ -#define MEMUNIT 0x1000 -#define MEMSTART 0xA0000 -#define MEMEND 0x100000 -#define MEMBLKS ((MEMEND-MEMSTART)/MEMUNIT) -#define MEM2BIT(x) (((x)-MEMSTART)/MEMUNIT) -#define BIT2MEM(x) (((x)*MEMUNIT)+MEMSTART) - -#define MAXINCLUDES 10 -#define MAXERRORS 10 - -/* - * Config index types - */ -#define NORMAL_INDEX 0 -#define DEFAULT_INDEX 1 -#define AUTO_INDEX 2 - -#define DT_VERS 0 -#define DT_FUNC 1 diff --git a/usr.sbin/pccard/pccardd/file.c b/usr.sbin/pccard/pccardd/file.c deleted file mode 100644 index 93ad066d2f8b..000000000000 --- a/usr.sbin/pccard/pccardd/file.c +++ /dev/null @@ -1,1096 +0,0 @@ -/* - * Copyright (c) 1995 Andrew McRae. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include -#include -#include -#include -#include "cardd.h" - -static FILE *in; -static int includes = 0; -static struct { - FILE *filep; - char *filename; - int lineno; -} configfiles[MAXINCLUDES] = {{NULL, NULL, 0}, }; - -static int pushc, pusht; -static int lineno; -static char *filename; - -static char *keys[] = { - "__EOF__", /* 1 */ - "io", /* 2 */ - "irq", /* 3 */ - "memory", /* 4 */ - "card", /* 5 */ - "device", /* 6 */ - "config", /* 7 */ - "reset", /* 8 */ - "ether", /* 9 */ - "insert", /* 10 */ - "remove", /* 11 */ - "iosize", /* 12 */ - "debuglevel", /* 13 */ - "include", /* 14 */ - "function", /* 15 */ - "logstr", /* 16 */ - 0 -}; - -#define KWD_EOF 1 -#define KWD_IO 2 -#define KWD_IRQ 3 -#define KWD_MEMORY 4 -#define KWD_CARD 5 -#define KWD_DEVICE 6 -#define KWD_CONFIG 7 -#define KWD_RESET 8 -#define KWD_ETHER 9 -#define KWD_INSERT 10 -#define KWD_REMOVE 11 -#define KWD_IOSIZE 12 -#define KWD_DEBUGLEVEL 13 -#define KWD_INCLUDE 14 -#define KWD_FUNCTION 15 -#define KWD_LOGSTR 16 - -/* for keyword compatibility with PAO/plain FreeBSD */ -static struct { - char *alias; - u_int key; -} key_aliases[] = { - {"generic", KWD_FUNCTION}, - {0, 0} -}; - -struct flags { - char *name; - int mask; -}; - -extern int doverbose; - -static void parsefile(void); -static char *getline(void); -static char *next_tok(void); -static int num_tok(void); -static void error(char *); -static int keyword(char *); -static int irq_tok(int); -static int config_tok(unsigned char *); -static int func_tok(void); -static int debuglevel_tok(int); -static struct allocblk *ioblk_tok(int); -static struct allocblk *memblk_tok(int); -static struct driver *new_driver(char *); -static int iosize_tok(void); -static void file_include(char *); - -static void addcmd(struct cmd **); -static void parse_card(int); - -static void -delete_card(struct card *cp) -{ - struct ether *etherp, *ether_next; - struct card_config *configp, *config_next; - struct cmd *cmdp, *cmd_next; - - /* free strings */ - free(cp->manuf); - free(cp->version); - free(cp->add_info1); - free(cp->add_info2); - free(cp->logstr); - - /* free structures */ - for (etherp = cp->ether; etherp; etherp = ether_next) { - ether_next = etherp->next; - free(etherp); - } - for (configp = cp->config; configp; configp = config_next) { - config_next = configp->next; - free(configp); - } - for (cmdp = cp->insert; cmdp; cmdp = cmd_next) { - cmd_next = cmdp->next; - free(cmdp->line); - free(cmdp); - } - for (cmdp = cp->remove; cmdp; cmdp = cmd_next) { - cmd_next = cmdp->next; - free(cmdp->line); - free(cmdp); - } - free(cp); -} - -/* - * Read a file and parse the pcmcia configuration data. - * After parsing, verify the links. - */ -void -readfile(char *name) -{ - int i, inuse; - struct card *cp, *card_next; - struct card *genericp, *tail_gp; - struct card_config *configp; - - /* delete all card configuration data before we proceed */ - genericp = 0; - cp = cards; - cards = last_card = 0; - while (cp) { - card_next = cp->next; - - /* check whether this card is in use */ - inuse = 0; - for (configp = cp->config; configp; configp = configp->next) { - if (configp->inuse) { - inuse = 1; - break; - } - } - - /* - * don't delete entry in use for consistency. - * leave normal entry in the cards list, - * insert generic entry into the list after re-loading config files. - */ - if (inuse == 1) { - cp->next = 0; /* unchain from the cards list */ - switch (cp->deftype) { - case DT_VERS: - /* don't delete this entry for consistency */ - if (debug_level >= 1) { - logmsg("Card \"%s\"(\"%s\") is in use, " - "can't change configuration\n", - cp->manuf, cp->version); - } - /* add this to the card list */ - if (!last_card) { - cards = last_card = cp; - } else { - last_card->next = cp; - last_card = cp; - } - break; - - case DT_FUNC: - /* generic entry must be inserted to the list later */ - if (debug_level >= 1) { - logmsg("Generic entry is in use, " - "can't change configuration\n"); - } - cp->next = genericp; - genericp = cp; - break; - } - } else { - delete_card(cp); - } - - cp = card_next; - } - - for (i = 0; i < MAXINCLUDES; i++) { - if (configfiles[i].filep) { - fclose(configfiles[i].filep); - configfiles[i].filep = NULL; - if (i > 0) { - free(configfiles[i].filename); - } - } - } - in = fopen(name, "r"); - if (in == 0) { - logerr(name); - die("readfile"); - } - includes = 0; - configfiles[includes].filep = in; - filename = configfiles[includes].filename = name; - - parsefile(); - for (cp = cards; cp; cp = cp->next) { - if (cp->config == 0) - logmsg("warning: card %s(%s) has no valid configuration\n", - cp->manuf, cp->version); - } - - /* insert generic entries in use into the top of generic entries */ - if (genericp) { - /* search tail of generic entries in use */ - for (tail_gp = genericp; tail_gp->next; tail_gp = tail_gp->next) - ; - - /* - * if the top of cards list is generic entry, - * insert generic entries in use before it. - */ - if (cards && cards->deftype == DT_FUNC) { - tail_gp->next = cards; - cards = genericp; - goto generic_done; - } - - /* search top of generic entries */ - for (cp = cards; cp; cp = cp->next) { - if (cp->next && cp->next->deftype == DT_FUNC) { - break; - } - } - - /* - * if we have generic entry in the cards list, - * insert generic entries in use into there. - */ - if (cp) { - tail_gp->next = cp->next; - cp->next = genericp; - goto generic_done; - } - - /* - * otherwise we don't have generic entries in - * cards list, just add them to the list. - */ - if (!last_card) { - cards = genericp; - } else { - last_card->next = genericp; - last_card = tail_gp; - } -generic_done:; - } - - /* save the initial state of resource pool */ - bcopy(io_avail, io_init, bitstr_size(IOPORTS)); - bcopy(mem_avail, mem_init, bitstr_size(MEMBLKS)); - bcopy(pool_irq, irq_init, sizeof(pool_irq)); -} - -static void -parsefile(void) -{ - int i; - int errors = 0; - struct allocblk *bp, *next; - char *incl; - - pushc = 0; - lineno = 1; - for (;;) - switch (keyword(next_tok())) { - case KWD_EOF: - /* EOF */ - return; - case KWD_IO: - /* override reserved I/O blocks */ - bit_nclear(io_avail, 0, IOPORTS-1); - for (bp = pool_ioblks; bp; bp = next) { - next = bp->next; - free(bp); - } - pool_ioblks = NULL; - - while ((bp = ioblk_tok(0)) != 0) { - if (bp->size == 0 || bp->addr == 0) { - free(bp); - continue; - } - bit_nset(io_avail, bp->addr, - bp->addr + bp->size - 1); - bp->next = pool_ioblks; - pool_ioblks = bp; - } - pusht = 1; - break; - case KWD_IRQ: - /* override reserved irqs */ - bzero(pool_irq, sizeof(pool_irq)); - while ((i = irq_tok(0)) > 0) - pool_irq[i] = 1; - pusht = 1; - break; - case KWD_MEMORY: - /* override reserved memory blocks. */ - bit_nclear(mem_avail, 0, MEMBLKS-1); - for (bp = pool_mem; bp; bp = next) { - next = bp->next; - free(bp); - } - pool_mem = NULL; - - while ((bp = memblk_tok(0)) != 0) { - if (bp->size == 0 || bp->addr == 0) { - free(bp); - continue; - } - bit_nset(mem_avail, MEM2BIT(bp->addr), - MEM2BIT(bp->addr + bp->size) - 1); - bp->next = pool_mem; - pool_mem = bp; - } - pusht = 1; - break; - case KWD_CARD: - /* Card definition. */ - parse_card(DT_VERS); - break; - case KWD_FUNCTION: - /* Function definition. */ - parse_card(DT_FUNC); - break; - case KWD_DEBUGLEVEL: - i = debuglevel_tok(0); - if (i > 0) - debug_level = i; - break; - case KWD_INCLUDE: - incl = newstr(next_tok()); - file_include(incl); - break; - default: - error("syntax error"); - pusht = 0; - if (errors++ >= MAXERRORS) { - error("too many errors, giving up"); - return; - } - break; - } -} - -/* - * Parse a card definition. - */ -static void -parse_card(int deftype) -{ - char *man, *vers, *tmp; - char *add_info; - unsigned char index_type; - struct card *cp; - int i, iosize; - struct card_config *confp, *lastp; - struct ether *ether; - - confp = 0; - cp = xmalloc(sizeof(*cp)); - cp->deftype = deftype; - switch (deftype) { - case DT_VERS: - man = newstr(next_tok()); - vers = newstr(next_tok()); - add_info = newstr(next_tok()); - if (keyword(add_info)) { - pusht = 1; - free(add_info); - cp->add_info1 = NULL; - cp->add_info2 = NULL; - } else { - cp->add_info1 = add_info; - add_info = newstr(next_tok()); - if (keyword(add_info)) { - pusht = 1; - free(add_info); - cp->add_info2 = NULL; - } else { - cp->add_info2 = add_info; - } - } - cp->manuf = man; - cp->version = vers; - cp->logstr = NULL; - asprintf(&cp->logstr, "%s (%s)", man, vers); - cp->func_id = 0; - break; - case DT_FUNC: - cp->manuf = NULL; - cp->version = NULL; - cp->logstr = NULL; - cp->func_id = (u_char) func_tok(); - break; - default: - fprintf(stderr, "parse_card: unknown deftype %d\n", deftype); - exit(1); - } - cp->reset_time = 50; - cp->next = 0; - if (!last_card) { - cards = last_card = cp; - } else { - last_card->next = cp; - last_card = cp; - } - for (;;) { - switch (keyword(next_tok())) { - case KWD_CONFIG: - /* config */ - i = config_tok(&index_type); - if (i == -1) { - error("illegal card config index"); - break; - } - confp = xmalloc(sizeof(*confp)); - man = next_tok(); - confp->driver = new_driver(man); - confp->irq = irq_tok(1); - confp->flags = num_tok(); - if (confp->flags == -1) { - pusht = 1; - confp->flags = 0; - } - if (confp->irq < 0 || confp->irq > 15) { - error("illegal card IRQ value"); - break; - } - confp->index = i & 0x3F; - confp->index_type = index_type; - - /* - * If no valid driver for this config, then do not save - * this configuration entry. - */ - if (confp->driver) { - if (cp->config == 0) - cp->config = confp; - else { - for (lastp = cp->config; lastp->next; - lastp = lastp->next); - lastp->next = confp; - } - } else - free(confp); - break; - case KWD_RESET: - /* reset */ - i = num_tok(); - if (i == -1) { - error("illegal card reset time"); - break; - } - cp->reset_time = i; - break; - case KWD_ETHER: - /* ether */ - ether = xmalloc(sizeof(*ether)); - ether->type = ETHTYPE_GENERIC; - tmp = next_tok(); - if (strcmp("attr2", tmp) == 0) - ether->type = ETHTYPE_ATTR2; - else { - pusht = 1; - ether->value = num_tok(); - if (ether->value == -1) { - error("illegal ether address offset"); - free(ether); - break; - } - } - ether->next = cp->ether; - cp->ether = ether; - break; - case KWD_INSERT: - /* insert */ - addcmd(&cp->insert); - break; - case KWD_REMOVE: - /* remove */ - addcmd(&cp->remove); - break; - case KWD_IOSIZE: - /* iosize */ - iosize = iosize_tok(); - if (!iosize) { - error("Illegal cardio arguments"); - break; - } - if (!confp) { - error("iosize should be placed after config"); - break; - } - cp->iosize = iosize; - break; - case KWD_LOGSTR: - free(cp->logstr); - cp->logstr = newstr(next_tok()); - break; - default: - pusht = 1; - return; - } - } -} - -/* - * Generate a new driver structure. If one exists, use - * that one after confirming the correct class. - */ -static struct driver * -new_driver(char *name) -{ - struct driver *drvp; - char *p; - - for (drvp = drivers; drvp; drvp = drvp->next) - if (strcmp(drvp->name, name) == 0) - return (drvp); - drvp = xmalloc(sizeof(*drvp)); - drvp->next = drivers; - drivers = drvp; - drvp->name = newstr(name); - drvp->kernel = newstr(name); - drvp->unit = -1; - p = drvp->kernel; - while (*p++) - if (*p >= '0' && *p <= '9') { - drvp->unit = atoi(p); - *p = 0; - break; - } -#ifdef DEBUG - printf("Drv %s%d created\n", drvp->kernel, drvp->unit); -#endif - return (drvp); -} - - -/* - * Parse one I/O block. - */ -static struct allocblk * -ioblk_tok(int force) -{ - struct allocblk *io; - int i, j; - - /* ignore the keyword to allow separete blocks in multiple lines */ - if (keyword(next_tok()) != KWD_IO) { - pusht = 1; - } - - if ((i = num_tok()) >= 0) { - if (strcmp("-", next_tok()) || (j = num_tok()) < 0 || j < i) { - error("I/O block format error"); - return (0); - } - io = xmalloc(sizeof(*io)); - io->addr = i; - io->size = j - i + 1; - if (j > IOPORTS) { - error("I/O port out of range"); - if (force) { - free(io); - io = 0; - } else - io->addr = io->size = 0; - } - return (io); - } - if (force) - error("illegal or missing I/O block spec"); - return (0); -} - -/* - * Parse a memory block. - */ -static struct allocblk * -memblk_tok(int force) -{ - struct allocblk *mem; - int i, j; - - /* ignore the keyword to allow separete blocks in multiple lines */ - if (keyword(next_tok()) != KWD_MEMORY) { - pusht = 1; - } - - if ((i = num_tok()) >= 0) { - if ((j = num_tok()) < 0) - error("illegal memory block"); - else { - mem = xmalloc(sizeof(*mem)); - mem->addr = i & ~(MEMUNIT - 1); - mem->size = (j + MEMUNIT - 1) & ~(MEMUNIT - 1); - if (i < MEMSTART || (i + j) > MEMEND) { - error("memory address out of range"); - if (force) { - free(mem); - mem = 0; - } else - mem->addr = mem->size = 0; - } - return (mem); - } - } - if (force) - error("illegal or missing memory block spec"); - return (0); -} - -/* - * IRQ token. Must be number > 0 && < 16. - * If force is set, IRQ must exist, and can also be '?' or 'any'. - */ -static int -irq_tok(int force) -{ - int i; - - /* ignore the keyword to allow separete blocks in multiple lines */ - if (keyword(next_tok()) != KWD_IRQ) { - pusht = 1; - } - - if (strcmp("?", next_tok()) == 0 && force) - return (0); - /* old PAO syntax -- people are still using it! */ - if (strcmp("any", next_tok()) == 0 && force) - return (0); - pusht = 1; - i = num_tok(); - if (i > 0 && i < 16) - return (i); - if (force) - error("illegal IRQ value"); - return (-1); -} - -/* - * Config index token - */ -static int -config_tok(unsigned char *index_type) -{ - if (strcmp("default", next_tok()) == 0) { - *index_type = DEFAULT_INDEX; - return 0; - } - pusht = 1; - if (strcmp("auto", next_tok()) == 0) { - *index_type = AUTO_INDEX; - return 0; - } - pusht = 1; - *index_type = NORMAL_INDEX; - return num_tok(); -} -/* - * Function ID token - */ -static int -func_tok(void) -{ - if (strcmp("serial", next_tok()) == 0) - return 2; - pusht = 1; - if (strcmp("fixed_disk", next_tok()) == 0) - return 4; - pusht = 1; - return num_tok(); -} - - -/* - * debuglevel token. Must be between 0 and 9. - */ -static int -debuglevel_tok(int force) -{ - int i; - - i = num_tok(); - if (i >= 0 && i <= 9) - return (i); - return (-1); -} - -/* - * iosize token - * iosize {|auto} - */ -static int -iosize_tok(void) -{ - int iosize = 0; - if (strcmp("auto", next_tok()) == 0) - iosize = -1; /* wildcard */ - else { - pusht = 1; - iosize = num_tok(); - if (iosize == -1) - return 0; - } -#ifdef DEBUG - if (doverbose) - printf("iosize: size=%x\n", iosize); -#endif - return iosize; -} - - -/* - * search the table for a match. - */ -static int -keyword(char *str) -{ - char **s; - int i = 1; - - for (s = keys; *s; s++, i++) - if (strcmp(*s, str) == 0) - return (i); - - /* search keyword aliases too */ - for (i = 0; key_aliases[i].key ; i++) - if (strcmp(key_aliases[i].alias, str) == 0) - return (key_aliases[i].key); - - return (0); -} - -/* - * addcmd - Append the command line to the list of - * commands. - */ -static void -addcmd(struct cmd **cp) -{ - struct cmd *ncp; - char *s = getline(); - - if (*s) { - ncp = xmalloc(sizeof(*ncp)); - ncp->line = s; - while (*cp) - cp = &(*cp)->next; - *cp = ncp; - } - -} - -static void -error(char *msg) -{ - pusht = 1; - logmsg("%s: %s at line %d, near %s\n", - filename, msg, lineno, next_tok()); - pusht = 1; -} - -static int last_char; - -static int -get(void) -{ - int c; - - if (pushc) - c = pushc; - else - c = getc(in); - pushc = 0; - while (c == '\\') { - c = getc(in); - switch (c) { - case '#': - return (last_char = c); - case '\n': - lineno++; - c = getc(in); - continue; - } - pushc = c; - return ('\\'); - } - if (c == '\n') - lineno++; - if (c == '#') - while (((c = get()) != '\n') && (c != EOF)); - return (last_char = c); -} - -/* - * num_tok - expecting a number token. If not a number, - * return -1. - * Handles octal (who uses octal anymore?) - * hex - * decimal - * Looks for a 'k' at the end of decimal numbers - * and multiplies by 1024. - */ -static int -num_tok(void) -{ - char *s = next_tok(), c; - int val = 0, base; - - base = 10; - c = *s++; - if (c == '0') { - base = 8; - c = *s++; - if (c == '\0') return 0; - else if (c == 'x' || c == 'X') { - c = *s++; - base = 16; - } - } - do { - switch (c) { - case 'k': - case 'K': - if (val && base == 10 && *s == 0) - return (val * 1024); - return (-1); - default: - return (-1); - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - val = val * base + c - '0'; - break; - - case '8': - case '9': - if (base == 8) - return (-1); - else - val = val * base + c - '0'; - break; - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - if (base == 16) - val = val * base + c - 'a' + 10; - else - return (-1); - break; - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - if (base == 16) - val = val * base + c - 'A' + 10; - else - return (-1); - break; - } - } while ((c = *s++) != 0); - return (val); -} - -static char *_next_tok(void); - -static char * -next_tok(void) -{ - char *s = _next_tok(); -#if 0 - printf("Tok = %s\n", s); -#endif - return (s); -} - -/* - * get one token. Handles string quoting etc. - */ -static char * -_next_tok(void) -{ - static char buf[1024]; - char *p = buf, instr = 0; - int c; - - if (pusht) { - pusht = 0; - return (buf); - } - for (;;) { - c = get(); - switch (c) { - default: - *p++ = c; - break; - case '"': - if (instr) { - *p++ = 0; - return (buf); - } - instr = 1; - break; - case '\n': - if (instr) { - error("unterminated string"); - break; - } - case ' ': - case '\t': - /* Eat whitespace unless in a string. */ - if (!instr) { - if (p != buf) { - *p++ = 0; - return (buf); - } - } else - *p++ = c; - break; - case '-': - case '?': - case '*': - /* Special characters that are tokens on their own. */ - if (instr) - *p++ = c; - else { - if (p != buf) - pushc = c; - else - *p++ = c; - *p++ = 0; - return (buf); - } - break; - case EOF: - if (includes) { - fclose(in); - /* go back to previous config file */ - includes--; - in = configfiles[includes].filep; - filename = configfiles[includes].filename; - lineno = configfiles[includes].lineno; - return _next_tok(); /* recursive */ - } - if (p != buf) { - *p++ = 0; - return (buf); - } - strcpy(buf, "__EOF__"); - return (buf); - } - } -} - -/* - * get the rest of the line. If the - * last character scanned was a newline, then - * return an empty line. If this isn't checked, then - * a getline may incorrectly return the next line. - */ -static char * -getline(void) -{ - char buf[1024], *p = buf; - int c, i = 0; - - if (last_char == '\n') - return (newstr("")); - do { - c = get(); - } while (c == ' ' || c == '\t'); - for (; c != '\n' && c != EOF; c = get()) - if (i++ < sizeof(buf) - 10) - *p++ = c; - *p = 0; - return (newstr(buf)); -} - -/* - * Include configuration file - */ -static void -file_include(char *incl) -{ - int i, included; - FILE *fp; - - /* check nesting overflow */ - if (includes >= MAXINCLUDES) { - if (debug_level >= 1) { - logmsg("%s: include nesting overflow " - "at line %d, near %s\n", filename, lineno, incl); - } - free(incl); - goto out; - } - - /* check recursive inclusion */ - for (i = 0, included = 0; i <= includes; i++) { - if (strcmp(incl, configfiles[i].filename) == 0) { - included = 1; - break; - } - } - if (included == 1) { - if (debug_level >= 1) { - logmsg("%s: can't include the same file twice " - "at line %d, near %s\n", filename, lineno, incl); - } - free(incl); - goto out; - } - - if (!(fp = fopen(incl, "r"))) { - if (debug_level >= 1) { - logmsg("%s: can't open include file " - "at line %d, near %s\n", filename, lineno, incl); - } - free(incl); - goto out; - } - - /* save line number of the current config file */ - configfiles[includes].lineno = lineno; - lineno = 1; - - /* now we start parsing new config file */ - includes++; - in = configfiles[includes].filep = fp; - filename = configfiles[includes].filename = incl; -out: - return; -} diff --git a/usr.sbin/pccard/pccardd/pccard.conf.5 b/usr.sbin/pccard/pccardd/pccard.conf.5 deleted file mode 100644 index c3d496dd9b46..000000000000 --- a/usr.sbin/pccard/pccardd/pccard.conf.5 +++ /dev/null @@ -1,312 +0,0 @@ -.\" -.\" Copyright (c) 1994 Andrew McRae. 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. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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$ -.\" -.Dd November 2, 1994 -.Dt PCCARD.CONF 5 -.Os -.Sh NAME -.Nm pccard.conf -.Nd -.Xr pccardd 8 -configuration file -.Sh DESCRIPTION -The -.Nm -file is the configuration file for the -.Xr pccardd 8 -PC-CARD slot management daemon. -It provides information to allow card -identification, and the matching of drivers (along -with driver resources) to the PC-CARD cards. -.Pp -There are four basic elements within the configuration file; -An optional -.Em "resource pool" -preceding the other sections, -and one or more -.Em "card identifiers" , -and -.Em "device instances" . -The latter two may appear in any order, and may be -interspersed as desired. -.Pp -The -.Pa /etc/pccard.conf -file is included from the file -.Pa /etc/defaults/pccard.conf , -which contains the default resource pool settings and -pccard identifiers database. -The user specific configuration can be specified in -.Pa /etc/pccard.conf -when the user wishes to override these defaults and/or -add additional entries. -.Pp -Each PC-CARD card contains configuration tuples that provide -the manufacturer and card version; these are used -to identify the card specification in the configuration -file, and from this find a driver that can be used to -interface to the particular card. -There is a many-to-one mapping -between cards to drivers i.e a single driver may interface to -multiple types of cards. -To aid this, card parameters may be -specified separately from the driver to initialize the card or -extract (in the case of a network card) an Ethernet address. -.Pp -Once a driver is allocated to a card, it stays -allocated to that particular card. -However, multiple instances of the same type of driver can be -configured, so that if two cards are plugged in that map to a -similar type of driver, other driver instances of the same name -can be configured. -.Pp -The -.Em insert -and -.Em remove -commands allow a shell command line to be executed. -The command to be executed is the rest of the line after -the keyword. -The line can be continued using a backslash. -A simple -macro substitution allows the current kernel device name -.Em ( $device ) -and -network card Ethernet address -.Em ( $ether ) -to be inserted into the command line. -.Xr pccardd 8 -uses the -.Xr system 3 -subroutine to execute the command line. -.Pp -.Xr pccardd 8 -will use syslog to announce the insertion and removal of cards. -It uses either the string set by the -.Em logstr -command, or the manufacturer and card version strings if none has -been set. -.Pp -Numeric values may be expressed as octal, hex or decimal. -If a decimal number has -.Em k -or -.Em K -appended to it, the value is multiplied by 1024. -Names may be -quoted using double quotes if spaces are required. -A hash character comments out the rest of the line. -.Ss "Resource pool" -The (optional) section specifies a pool of system resources -such as ISA bus memory address space, Input/Output ports and -interrupt request numbers. -This resource pool is used -to allocate address space and interrupt numbers dynamically -according to the requirements specified in each driver -description. -.Pp -The syntax of the resources is as follows: -.Pp -.Dl io Ar start - end ... -.Dl memory Ar address size ... -.Dl irq Ar irq-number ... -.Pp -Each of the statements define I/O, memory or IRQ -blocks that can be used to allocate to drivers when -they are initialized. -.Pp -The syntax of the debuglevel parameter: -.Pp -.Dl debuglevel Ar level -.Pp -Multiple lines of any of the above statements may be -present to allow separate blocks of each resource to be -defined. -.Ss "Card Identifiers" -The syntax for card identifiers is: -.Pp -.Dl card Ar manufacturer version [ add_info1 [ add_info2 ]] -.Dl config Ar index driver interrupt [ flags ] -.Dl ether Ar offset -.Dl reset Ar time -.Dl iosize Ar size -.Dl memsize Ar size -.Dl insert Ar command -.Dl remove Ar command -.Dl logstr Ar string -.Pp -The first line is mandatory; -the latter statements are optional and can appear in -any order. -There may be multiple -.Em config -lines. -The -.Em card -parameters are the Manufacturer name, card version and -additional information add_info1, add_info2 that -is used to match the values from the card's CIS memory. -These parameters can be described in extended regular expression -.Xr regex 3 -if the string is enclosed by '/' like "/.*/". -Each of the expressions is evaluated with a character '^' at top. -.Pp -The -.Em config -parameters select the particular card's configuration index -from the range available in the card's CIS, the driver that -is to be associated with this configuration, and the interrupt -level (if any) to be assigned. -An optional set of flags may -be assigned. -In -.Ar index , -specify either -.Dq auto -or -.Dq default -or the range available in the card's CIS. -.Dq auto -allows to allocate resources automatically with information -from the CIS and status of using I/O resources. -.Pp -The optional -.Em ether -keyword is used when network cards have their physical Ethernet address -located within the attribute memory of the card. -The parameter of this -statement indicates the offset within the attribute memory of the -Ethernet address. -This value can be used within insert/remove -commands using the -.Em $ether -macro. -.Pp -The optional -.Em reset -keyword specifies reset duration at a card insertion in -.Ar time -milliseconds. -Default is 100msec. -.Pp -.Em iosize -and -.Em memsize -keywords are used with cards whose resources such as I/O ports and -shared memory block are not specified in the CIS tuple. -.Pp -The -.Em insert -and -.Em remove -sections allow shell commands to be specified that are executed -when the card is inserted or removed. -Multiple -.Em insert -and -.Em remove -commands are allowed, and they are executed in the order they -are listed. -.Pp -The -.Em logstr -command allows the user to set the string to be logged when this card is -inserted or removed. -If -.Em logstr -is not specified, then the manufacturer and -card version strings from the CIS are used to synthesize the string issued. -.Ss "Wildcard entries" -Following two wildcard entries of card identifiers are available -for generic type of the cards: -.Pp -.Dl generic serial -.Dl generic fixed_disk -.Pp -The keyword -.Em serial -matches -.Dq Functional ID: Serial port/modem -and -.Em fixed_disk -matches -.Dq Fixed disk card . -The syntax is the same as for -.Em "card identifiers" -but uses -.Dq generic -instead of -.Dq card -in the first line. -These are defined at the bottom of -.Nm -so unmatched cards use the generic entries. -The alias -.Dq function -can be used instead of -.Dq generic , -this is supported due to historical reasons. -.Sh FILES -.Bl -tag -width /etc/defaults/pccard.conf -compact -.It Pa /etc/defaults/pccard.conf -The -.Xr pccardd 8 -default configuration file. -.It Pa /etc/pccard.conf -The -user configuration file. -.El -.Sh EXAMPLES -A typical configuration file may look like this: -.Bd -literal -# -# Sample configuration file. -# -# Pool parameters. -# -io 0x280 - 0x2F0 0x300 - 0x360 -irq 5 6 8 9 10 15 -memory 0xd4000 96k -memory 0xc4000 32k -# -# Card database. -# -card "RPTI LTD." "EP400" # NE2000 clone - ether 0x110 - config 0x21 "ed0" 5 - insert ifconfig $device physical $ether - insert ifconfig $device bean - remove ifconfig $device down - -card "XYZZY" "FAX/1.0" - config 0x30 "sio1" 11 - insert echo start getty - remove echo stop getty - -.Ed -.Sh SEE ALSO -.Xr pccardd 8 diff --git a/usr.sbin/pccard/pccardd/pccardd.8 b/usr.sbin/pccard/pccardd/pccardd.8 deleted file mode 100644 index 105552ba28ee..000000000000 --- a/usr.sbin/pccard/pccardd/pccardd.8 +++ /dev/null @@ -1,190 +0,0 @@ -.\" -.\" Copyright (c) 1994 Andrew McRae. 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. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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$ -.\" -.Dd November 1, 1994 -.Dt PCCARDD 8 -.Os -.Sh NAME -.Nm pccardd -.Nd PC-CARD (PCMCIA) management daemon -.Sh SYNOPSIS -.Nm -.Op Fl d -.Op Fl v -.Op Fl x -.Op Fl z -.Op Fl i Ar IRQ -.Op Fl I -.Op Fl f Ar configfile -.Op Fl s Ar socket -.Sh DESCRIPTION -The -.Nm -utility is normally started at boot time, and manages the insertion -and removal of PC-CARD cards. -.Pp -When started, -.Nm -will read the configuration file (default name -.Pa /etc/defaults/pccard.conf -which includes -.Pa /etc/pccard.conf -as the user configuration file) -and scans the available PC-CARD slots for cards. -The -.Nm -utility then waits for -.Em "card events" , -such as the insertion of a new card or the removal -of a card. -.Pp -When a card is inserted, the following -actions are taken: -.Bl -enum -.It -The kernel driver detects the card insertion and applies -power to the card. -.It -The -.Nm -utility reads the -.Em CIS -data from the attribute memory of the card, and uses -the manufacturer name and card version to match -the card description in the configuration file. -.It -Once matched, a driver is allocated. -.It -Once a free driver and device instance is located, -.Nm -will (if required) allocate resources such as an ISA memory -block and Input/Output ports from a common pool. -.It -The PC-CARD slot is configured with the I/O and memory -contexts allocated, and the kernel driver is attached to -this card. -.It -If the attach succeeds, then specific shell commands -may be executed to configure the device, such as -.Xr ifconfig 8 -to set up a network interface. -Separate commands may be specified -for each card, driver or device, and are executed in that order. -.El -.Pp -When -.Nm -detects that a card has been removed, the following sequence occurs: -.Bl -enum -.It -The shell commands associated with card removal are executed. -These -are intended to reset any device associated with the removed card. -Separate commands may exist for card, driver and device instances. -.It -The PC-CARD slot resources are freed. -.El -.Pp -Once a card/driver instance is configured, the resources -bound to that instance are remembered, and if the card is removed -and reinserted, the same driver is allocated. -The reasons are mostly historical. -.Pp -SIGHUP causes -.Nm -to reload the configuration files. -.Pp -The start options understood by -.Nm -are: -.Bl -tag -width Ds -.It Fl d -Do not run as a daemon, but run in the foreground and -display error messages. -.It Fl v -After reading the configuration file, print out a summary -of it. -.It Fl x -Exits immediately after the cards have been probed and attached. -This is primarily useful in embedded applications where it is -desirable to use -.Nm -to start PC-CARD devices but prohibitive memory-wise to leave the -.Nm -process running. -.It Fl z -Delays running as a daemon until after the cards have been probed and attached. -.It Fl I -Do not get a list of free IRQs from kernel. -.It Fl i Ar IRQ -Configures an available IRQ. -It overrides the "irq" line in -.Pa /etc/defaults/pccard.conf -and -.Pa /etc/pccard.conf . -.It Fl f Ar configfile -Specifies a different configuration file to be used -in placed of the default file -.Pa /etc/defaults/pccard.conf . -The file format is detailed in -.Xr pccard.conf 5 , -and lists the PC-CARD cards recognized by -.Nm , -and the kernel drivers and devices that are used to -interface to the card. -.It Fl s Ar socket -Specifies a path to a control socket. -The default is -.Pa /var/tmp/.pccardd . -.El -.Sh FILES -.Bl -tag -width /etc/defaults/pccard.conf -compact -.It Pa /etc/defaults/pccard.conf -default configuration file -.It Pa /etc/pccard.conf -user configuration file -.It Pa /var/tmp/.pccardd -default control socket -.It Pa /var/run/pccardd.pid -process id of the currently running -.Nm -.El -.Sh SEE ALSO -.Xr pccard.conf 5 , -.Xr ifconfig 8 -.Sh AUTHORS -Developed by -.An Andrew McRae Aq andrew@mega.com.au . -.Sh BUGS -The -.Nm -utility can set up card parameters, but cannot guarantee that -particular drivers can work with the card. -.Pp -Removing cards may cause problems if system resources -have been associated with the card, such as network -mounted file systems. diff --git a/usr.sbin/pccard/pccardd/pccardd.c b/usr.sbin/pccard/pccardd/pccardd.c deleted file mode 100644 index 11d07166b302..000000000000 --- a/usr.sbin/pccard/pccardd/pccardd.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (c) 1995 Andrew McRae. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define EXTERN -#include "cardd.h" - -char *config_file = "/etc/defaults/pccard.conf"; -static char *pid_file = "/var/run/pccardd.pid"; - -/* - * pathname of UNIX-domain socket - */ -static char *socket_name = "/var/tmp/.pccardd"; -static char *sock = 0; -static int server_sock; - -/* SIGHUP signal handler */ -static void -restart(void) -{ - bitstr_t bit_decl(io_inuse, IOPORTS); - bitstr_t bit_decl(mem_inuse, MEMBLKS); - int irq_inuse[16]; - int i; - struct sockaddr_un sun; - - bit_nclear(io_inuse, 0, IOPORTS-1); - bit_nclear(mem_inuse, 0, MEMBLKS-1); - bzero(irq_inuse, sizeof(irq_inuse)); - - /* compare the initial and current state of resource pool */ - for (i = 0; i < IOPORTS; i++) { - if (bit_test(io_init, i) == 1 && bit_test(io_avail, i) == 0) { - if (debug_level >= 1) { - logmsg("io 0x%x seems to be in use\n", i); - } - bit_set(io_inuse, i); - } - } - for (i = 0; i < MEMBLKS; i++) { - if (bit_test(mem_init, i) == 1 && bit_test(mem_avail, i) == 0) { - if (debug_level >= 1) { - logmsg("mem 0x%x seems to be in use\n", i); - } - bit_set(mem_inuse, i); - } - } - for (i = 0; i < 16; i++) { - if (irq_init[i] == 1 && pool_irq[i] == 0) { - if (debug_level >= 1) { - logmsg("irq %d seems to be in use\n", i); - } - irq_inuse[i] = 1; - } - } - - readfile(config_file); - - /* reflect used resources to managed resource pool */ - for (i = 0; i < IOPORTS; i++) { - if (bit_test(io_inuse, i) == 1) { - bit_clear(io_avail, i); - } - } - for (i = 0; i < MEMBLKS; i++) { - if (bit_test(mem_inuse, i) == 1) { - bit_clear(mem_avail, i); - } - } - for (i = 0; i < 16; i++) { - if (irq_inuse[i] == 1) { - pool_irq[i] = 0; - } - } - close(server_sock); - if ((server_sock = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0) - die("socket failed"); - bzero(&sun, sizeof(sun)); - sun.sun_family = AF_UNIX; - if (sock) { - socket_name = sock; - } - strcpy(sun.sun_path, socket_name); - slen = SUN_LEN(&sun); - (void)unlink(socket_name); - if (bind(server_sock, (struct sockaddr *) & sun, slen) < 0) - die("bind failed"); - chown(socket_name, 0, 5); /* XXX - root.operator */ - chmod(socket_name, 0660); - set_socket(server_sock); -} - -/* SIGTERM/SIGINT signal handler */ -static void -term(int sig) -{ - logmsg("pccardd terminated: signal %d received", sig); - (void)unlink(pid_file); - exit(0); -} - -static void -write_pid() -{ - FILE *fp = fopen(pid_file, "w"); - - if (fp) { - fprintf(fp, "%d\n", getpid()); - fclose(fp); - } -} - -int doverbose = 0; -/* - * mainline code for cardd - */ -int -main(int argc, char *argv[]) -{ - struct slot *sp; - int count, dodebug = 0; - int probeonly = 0; - int delay = 0; - int irq_arg[16]; - int irq_specified = 0; - int i; - struct sockaddr_un sun; -#define COM_OPTS ":Idf:i:s:vxz" - - bzero(irq_arg, sizeof(irq_arg)); - use_kern_irq = 1; - debug_level = 0; - pccard_init_sleep = 5000000; - cards = last_card = 0; - while ((count = getopt(argc, argv, COM_OPTS)) != -1) { - switch (count) { - case 'I': - use_kern_irq = 0; - break; - case 'd': - setbuf(stdout, 0); - setbuf(stderr, 0); - dodebug = 1; - break; - case 'v': - doverbose = 1; - break; - case 'f': - config_file = optarg; - break; - case 'i': - /* configure available irq */ - if (sscanf(optarg, "%d", &i) != 1) { - fprintf(stderr, "%s: -i number\n", argv[0]); - exit(1); - } - irq_arg[i] = 1; - irq_specified = 1; - break; - case 's': - sock = optarg; - break; - case 'x': - probeonly = 1; - break; - case 'z': - delay = 1; - break; - case ':': - die("no config file argument"); - break; - case '?': - die("illegal option"); - break; - } - } -#ifdef DEBUG - dodebug = 1; -#endif - io_avail = bit_alloc(IOPORTS); /* Only supports ISA ports */ - io_init = bit_alloc(IOPORTS); - - /* Mem allocation done in MEMUNIT units. */ - mem_avail = bit_alloc(MEMBLKS); - mem_init = bit_alloc(MEMBLKS); - readfile(config_file); - if (irq_specified) { - bcopy(irq_arg, pool_irq, sizeof(irq_arg)); - bcopy(irq_arg, irq_init, sizeof(irq_arg)); - } - if (doverbose) - dump_config_file(); - log_setup(); - if (!dodebug && !delay && !probeonly) - if (daemon(0, 0)) - die("fork failed"); - slots = readslots(); - if (slots == 0) - die("no PC-CARD slots"); - if (probeonly) - exit(0); - if (delay) - if (daemon(0, 0)) - die("fork failed"); - logmsg("pccardd started", NULL); - write_pid(); - - if ((server_sock = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0) - die("socket failed"); - bzero(&sun, sizeof(sun)); - sun.sun_family = AF_UNIX; - if (sock) { - socket_name = sock; - } - strcpy(sun.sun_path, socket_name); - slen = SUN_LEN(&sun); - (void)unlink(socket_name); - if (bind(server_sock, (struct sockaddr *) & sun, slen) < 0) - die("bind failed"); - chown(socket_name, 0, 5); /* XXX - root.operator */ - chmod(socket_name, 0660); - set_socket(server_sock); - - (void)signal(SIGINT, dodebug ? term : SIG_IGN); - (void)signal(SIGTERM, term); - (void)signal(SIGHUP, (void (*)(int))restart); - - for (;;) { - fd_set rmask, emask; - FD_ZERO(&emask); - FD_ZERO(&rmask); - for (sp = slots; sp; sp = sp->next) - FD_SET(sp->fd, &emask); - FD_SET(server_sock, &rmask); - count = select(32, &rmask, 0, &emask, 0); - if (count == -1) { - logerr("select"); - continue; - } - if (count) { - for (sp = slots; sp; sp = sp->next) - if (FD_ISSET(sp->fd, &emask)) - slot_change(sp); - if (FD_ISSET(server_sock, &rmask)) - process_client(); - } - } -} diff --git a/usr.sbin/pccard/pccardd/server.c b/usr.sbin/pccard/pccardd/server.c deleted file mode 100644 index 8c6177eff4c2..000000000000 --- a/usr.sbin/pccard/pccardd/server.c +++ /dev/null @@ -1,188 +0,0 @@ -/* - * pccardd UNIX-domain socket interface - * Copyright (C) 1996 by Tatsumi Hosokawa - * - * $Id: server.c,v 1.3 1999/02/07 08:02:44 kuriyama Exp $ - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cardd.h" - -static void -cardnum(char *buf) -{ - int i = 0; - struct slot *sp; - - for (sp = slots; sp; sp = sp->next) - i++; - if (i > MAXSLOT) - i = MAXSLOT; - sprintf(buf, "%2d", i); -} - -static struct slot * -find_slot(int slot) -{ - struct slot *sp; - - /* Search the list until we find the slot or get to the end */ - for (sp = slots; sp && sp->slot != slot; sp = sp->next) - continue; - - return ( sp ); -} - -static void -cardname(char *buf, int slot) -{ - struct slot *sp; - char *manuf, *vers, *drv, *stat; - - /* Look for the slot */ - if ( (sp = find_slot(slot)) == NULL) - return; - - /* Fill in the information in the buff */ - if (sp->cis) { - - manuf = sp->cis->manuf; - vers = sp->cis->vers; - if (sp->config && sp->config->driver && - sp->config->driver->name) - drv = sp->config->driver->name; - else - drv = ""; - } else - manuf = vers = drv = ""; - - switch (sp->state) { - case empty: - stat = "0"; - break; - case filled: - stat = "1"; - break; - case inactive: - stat = "2"; - break; - default: - stat = "9"; - } - sprintf(buf, "%d~%s~%s~%s~%s", slot, manuf, vers, drv, stat); -} - -static void -cardpwr(int slot, int pwon) -{ - struct slot *sp; - - /* Look for the slot */ - if ( (sp = find_slot(slot)) == NULL) - return; - - if (ioctl(sp->fd, PIOCSVIR, &pwon) < 0) - logerr("invaild arguments for cardpwr"); -} - -static int sock = 0; -static int slen = 0; -static struct sockaddr_un sun; - -void -set_socket(int s) -{ - sock = s; -} - -void -stat_changed(struct slot *sp) -{ - int len; - char buf[512]; - - if (!slen) - return; - - cardname(buf, sp->slot); - len = strlen(buf); - if (sendto(sock, buf, len, 0, (struct sockaddr *) & sun, slen) != len) { - logerr("sendto failed"); - slen = 0; - } -} - -void -process_client(void) -{ - char buf[512], obuf[512]; - int len; - int snum; - - if (!sock) - return; - slen = sizeof(sun); - len = recvfrom(sock, buf, sizeof(buf), - 0, (struct sockaddr *)&sun, &slen); - if (len < 0) - logerr("recvfrom failed"); - buf[len] = '\0'; - obuf[0] = '\0'; - switch (buf[0]) { /* Protocol implementation */ - case 'S': /* How many slots? */ - cardnum(obuf); - break; - case 'N': /* Card name request */ - sscanf(buf + 1, "%d", &snum); - if (snum >= 0 && snum <= MAXSLOT) - cardname(obuf, snum); - else - logerr("Illegal slot requests for N command"); - break; - case 'P': /* Virtual insertion request */ - sscanf(buf + 1, "%d", &snum); - if (snum >= 0 && snum <= MAXSLOT) { - logmsg("slot %d: spring has come", snum); - cardpwr(snum, 1); - } else - logerr("Illegal slot requests for P command"); - break; - case 'Q': /* Virtual removal request */ - sscanf(buf + 1, "%d", &snum); - if (snum >= 0 && snum <= MAXSLOT) { - logmsg("slot %d: hibernation", snum); - cardpwr(snum, 0); - } else - logerr("Illegal slot requests for Q command"); - break; - default: - logerr("Unknown control message from socket"); - break; - } - len = strlen(obuf); - if (len) { - if (sendto(sock, obuf, len, 0, (struct sockaddr *)&sun, slen) - != len) { - logerr("sendto failed"); - slen = 0; - } - } else if (sendto(sock, 0, 0, 0, (struct sockaddr *)&sun, slen) - != len) { - logerr("sendto failed"); - slen = 0; - } -} diff --git a/usr.sbin/pccard/pccardd/util.c b/usr.sbin/pccard/pccardd/util.c deleted file mode 100644 index 8f9a48df3b7c..000000000000 --- a/usr.sbin/pccard/pccardd/util.c +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright (c) 1995 Andrew McRae. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -/* - * Code cleanup, bug-fix and extension - * by: - * Tatsumi Hosokawa - * Nate Williams - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef SYSINSTALL -#include -#endif -#include "cardd.h" - -static int do_log = 0; - -void -log_setup(void) -{ -#ifndef SYSINSTALL - do_log = 1; - openlog("pccardd", LOG_PID, LOG_DAEMON); -#endif -} - -void -logmsg(const char *fmt, ...) -{ - va_list ap; - char s[256]; - - va_start(ap, fmt); - vsnprintf(s, 256, fmt, ap); - - if (do_log) - syslog(LOG_ERR, "%s", s); - else { -#ifdef SYSINSTALL - dialog_clear(); - msgConfirm(s); -#else - warnx("%s", s); -#endif - } -} - -void -logerr(char *msg) -{ - if (do_log) - syslog(LOG_ERR, "%s: %m", msg); - else { -#ifdef SYSINSTALL - dialog_clear(); - msgConfirm(msg); -#else - warn("%s", msg); -#endif - } -} - -/* - * Deliver last will and testament, and die. - */ -void -die(char *msg) -{ - if (do_log) - syslog(LOG_CRIT, "fatal error: %s", msg); - else { -#ifdef SYSINSTALL - char s[256]; - - sprintf(s, "cardd fatal error: %s\n", msg); - dialog_clear(); - msgConfirm(s); -#else - warnx("fatal error: %s", msg); -#endif - } - closelog(); - exit(1); -} - -void * -xmalloc(int sz) -{ - void *p; - - p = malloc(sz); - if (p) - bzero(p, sz); - else - die("malloc failed"); - return (p); -} - -char * -newstr(char *p) -{ - char *s; - - s = strdup(p); - if (s == 0) - die("strdup failed"); - return (s); -} - -/* - * Find contiguous bit string (all set) of at - * least count number. - */ -int -bit_fns(bitstr_t *nm, int nbits, int min, int count, int step) -{ - int i, j; - int found = 0; - - for (i = min; i < nbits; i += step) - for (j = i, found = 0; j < nbits; j++) - if (bit_test(nm, j)) { - if (++found == count) - return i; - } else - break; - return (-1); -} - -/* - * Allocate a block of memory and return the address. - */ -unsigned long -alloc_memory(int size) -{ - int i; - - i = bit_fns(mem_avail, MEMBLKS, 0, size / MEMUNIT + (size % MEMUNIT != 0), 1); - if (i < 0) - return (0); - bit_nclear(mem_avail, i, i + size / MEMUNIT + (size % MEMUNIT != 0) - 1); - return (BIT2MEM(i)); -} - -/* - * reset_slot - Power has been applied to the card. - * Now reset the card. - */ -void -reset_slot(struct slot *sp) -{ - char c; - off_t offs; - struct mem_desc mem; - struct io_desc io; - int rw_flags; - - rw_flags = MDF_ATTR; - ioctl(sp->fd, PIOCRWFLAG, &rw_flags); -#ifdef DEBUG - printf("Resetting card, writing 0x80 to offs 0x%x\n", - sp->cis->reg_addr); -#endif - offs = sp->cis->reg_addr; - lseek(sp->fd, offs, SEEK_SET); - c = 0x80; - write(sp->fd, &c, sizeof(c)); - usleep(10 * 1000); - c = 0; - lseek(sp->fd, offs, SEEK_SET); - write(sp->fd, &c, sizeof(c)); - - /* Reset all the memory and I/O windows. */ - bzero((caddr_t) & mem, sizeof(mem)); - bzero((caddr_t) & io, sizeof(io)); - for (mem.window = 0; mem.window < NUM_MEM_WINDOWS; mem.window++) - ioctl(sp->fd, PIOCSMEM, &mem); - for (io.window = 0; io.window < NUM_IO_WINDOWS; io.window++) - ioctl(sp->fd, PIOCSIO, &io); -} - -/* - * execute - Execute the command strings. - * For the current slot (if any) perform macro - * substitutions. - */ -void -execute(struct cmd *cmdp, struct slot *sp) -{ - char cmd[1024]; - char *p, *cp, *lp; - - for (; cmdp; cmdp = cmdp->next) { - cp = cmd; - lp = cmdp->line; - if (*lp == 0) - continue; - while ((p = strchr(lp, '$')) != 0) { - /* copy over preceding string. */ - while (lp != p) - *cp++ = *lp++; - /* stringify ethernet address and place here. */ - if (strncmp(p, "$ether", 6) == 0) { - sprintf(cp, "%x:%x:%x:%x:%x:%x", - sp->eaddr[0], - sp->eaddr[1], - sp->eaddr[2], - sp->eaddr[3], - sp->eaddr[4], - sp->eaddr[5]); - while (*++cp) - continue; - lp += 6; - } else - /* replace device name */ - if (strncmp(p, "$device", 7) == 0) { - sprintf(cp, "%s%d", - sp->config->driver->kernel, - sp->config->driver->unit); - while (*cp) - cp++; - lp += 7; - } else - /* Copy the `$' and rescan. */ - *cp++ = *lp++; - } - /* No more replacements. Copy rest of string. */ - while ((*cp++ = *lp++) != 0) - continue; -#ifdef DEBUG - fprintf(stderr, "Executing [%s]\n", cmd); -#endif - system(cmd); - } -}