2 * Copyright (c) 1995 Andrew McRae. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: src/usr.sbin/pccard/pccardc/enabler.c,v 1.13 1999/08/28 01:17:32 peter Exp $
27 * $DragonFly: src/usr.sbin/pccard/pccardc/Attic/enabler.c,v 1.2 2003/06/17 04:29:59 dillon Exp $
36 #include <sys/ioctl.h>
38 #include <pccard/cardinfo.h>
39 #include <pccard/cis.h>
41 static void usage __P((char *));
44 enabler_main(argc, argv)
51 int fd, slot, i, card_addr;
55 bzero(&drv, sizeof(drv));
59 if (slot < 0 || slot >= MAXSLOT)
60 usage("illegal slot number");
62 while (*p && (*p < '0' || *p > '9'))
65 usage("no unit on device name");
68 strcpy(drv.name, argv[2]);
72 if (strcmp(argv[0], "-m") == 0) {
74 usage("memory argument error");
75 if (sscanf(argv[1], "%x", &card_addr) != 1)
76 usage("bad card address");
77 if (sscanf(argv[2], "%lx", &drv.mem) != 1)
78 usage("bad memory address");
79 if (sscanf(argv[3], "%d", &i) != 1)
80 usage("bad memory size");
81 drv.memsize = i * 1024;
84 } else if (strcmp(argv[0], "-f") == 0) {
85 if (sscanf(argv[1], "%x", &drv.flags) != 1)
86 usage("bad driver flags");
87 } else if (strcmp(argv[0], "-a") == 0) {
88 if (sscanf(argv[1], "%x", &drv.iobase) != 1)
89 usage("bad I/O address");
90 } else if (strcmp(argv[0], "-i") == 0) {
91 if (sscanf(argv[1], "%d", &i) != 1 || i < 1 || i > 15)
99 usage("no parameter for argument");
100 printf("drv %s%d, mem 0x%lx, size %d, io %d, irq 0x%x, flags 0x%x\n",
101 drv.name, drv.unit, drv.mem, drv.memsize, drv.iobase,
102 drv.irqmask, drv.flags);
103 sprintf(name, CARD_DEVICE, slot);
104 fd = open(name, O_RDWR);
108 /* Map the memory and I/O contexts. */
111 mem.flags = MDF_ACTIVE | MDF_16BITS;
112 mem.start = (caddr_t)drv.mem;
113 mem.size = drv.memsize;
114 mem.card = card_addr;
115 if (ioctl(fd, PIOCSMEM, &mem))
116 err(1, "set memory context");
120 io.flags = IODF_ACTIVE | IODF_CS16;
121 io.start = drv.iobase;
122 io.size = 32; /* Blah... */
123 if (ioctl(fd, PIOCSIO, &io))
124 err(1, "set I/O context");
126 if (ioctl(fd, PIOCSDRV, &drv))
133 * usage - print usage and exit
139 fprintf(stderr, "enabler: %s\n", msg);
141 "usage: pccardc enabler slot driver [-m addr size] [-a iobase] [-i irq]\n");
143 " -m card addr size : card address (hex), host address (hex) & size (Kb)\n");
145 " -a iobase : I/O port address (hex)\n");
147 " -i irq : interrupt request number (1-15)\n");
149 " Example: enabler 0 ed0 -m 2000 d4000 16 -a 300 -i 3\n");