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.
28 static const char rcsid[] =
29 "$FreeBSD: src/usr.sbin/pccard/pccardc/enabler.c,v 1.13 1999/08/28 01:17:32 peter Exp $";
38 #include <sys/ioctl.h>
40 #include <pccard/cardinfo.h>
41 #include <pccard/cis.h>
43 static void usage __P((char *));
46 enabler_main(argc, argv)
53 int fd, slot, i, card_addr;
57 bzero(&drv, sizeof(drv));
61 if (slot < 0 || slot >= MAXSLOT)
62 usage("illegal slot number");
64 while (*p && (*p < '0' || *p > '9'))
67 usage("no unit on device name");
70 strcpy(drv.name, argv[2]);
74 if (strcmp(argv[0], "-m") == 0) {
76 usage("memory argument error");
77 if (sscanf(argv[1], "%x", &card_addr) != 1)
78 usage("bad card address");
79 if (sscanf(argv[2], "%lx", &drv.mem) != 1)
80 usage("bad memory address");
81 if (sscanf(argv[3], "%d", &i) != 1)
82 usage("bad memory size");
83 drv.memsize = i * 1024;
86 } else if (strcmp(argv[0], "-f") == 0) {
87 if (sscanf(argv[1], "%x", &drv.flags) != 1)
88 usage("bad driver flags");
89 } else if (strcmp(argv[0], "-a") == 0) {
90 if (sscanf(argv[1], "%x", &drv.iobase) != 1)
91 usage("bad I/O address");
92 } else if (strcmp(argv[0], "-i") == 0) {
93 if (sscanf(argv[1], "%d", &i) != 1 || i < 1 || i > 15)
101 usage("no parameter for argument");
102 printf("drv %s%d, mem 0x%lx, size %d, io %d, irq 0x%x, flags 0x%x\n",
103 drv.name, drv.unit, drv.mem, drv.memsize, drv.iobase,
104 drv.irqmask, drv.flags);
105 sprintf(name, CARD_DEVICE, slot);
106 fd = open(name, O_RDWR);
110 /* Map the memory and I/O contexts. */
113 mem.flags = MDF_ACTIVE | MDF_16BITS;
114 mem.start = (caddr_t)drv.mem;
115 mem.size = drv.memsize;
116 mem.card = card_addr;
117 if (ioctl(fd, PIOCSMEM, &mem))
118 err(1, "set memory context");
122 io.flags = IODF_ACTIVE | IODF_CS16;
123 io.start = drv.iobase;
124 io.size = 32; /* Blah... */
125 if (ioctl(fd, PIOCSIO, &io))
126 err(1, "set I/O context");
128 if (ioctl(fd, PIOCSDRV, &drv))
135 * usage - print usage and exit
141 fprintf(stderr, "enabler: %s\n", msg);
143 "usage: pccardc enabler slot driver [-m addr size] [-a iobase] [-i irq]\n");
145 " -m card addr size : card address (hex), host address (hex) & size (Kb)\n");
147 " -a iobase : I/O port address (hex)\n");
149 " -i irq : interrupt request number (1-15)\n");
151 " Example: enabler 0 ed0 -m 2000 d4000 16 -a 300 -i 3\n");