1995-08-24 09:03:04 +00:00
|
|
|
/*
|
1996-04-18 04:25:17 +00:00
|
|
|
* 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.
|
1995-08-24 09:03:04 +00:00
|
|
|
*/
|
1997-10-06 11:36:08 +00:00
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
1997-11-18 21:08:14 +00:00
|
|
|
"$Id: enabler.c,v 1.9 1997/10/26 04:36:23 nate Exp $";
|
1997-10-06 11:36:08 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <fcntl.h>
|
1995-08-24 09:03:04 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1997-10-06 11:36:08 +00:00
|
|
|
#include <unistd.h>
|
1995-08-24 09:03:04 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
1997-11-18 21:08:14 +00:00
|
|
|
#include <pccard/cardinfo.h>
|
1995-08-24 09:03:04 +00:00
|
|
|
#include <pccard/cis.h>
|
|
|
|
|
1997-10-06 11:36:08 +00:00
|
|
|
static void usage __P((char *));
|
1995-08-24 09:03:04 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
enabler_main(argc, argv)
|
1996-04-10 05:45:39 +00:00
|
|
|
int argc;
|
|
|
|
char *argv[];
|
1995-08-24 09:03:04 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct dev_desc drv;
|
1996-04-10 05:45:39 +00:00
|
|
|
struct mem_desc mem;
|
|
|
|
struct io_desc io;
|
|
|
|
int fd, slot, i, card_addr;
|
|
|
|
char name[32];
|
|
|
|
char *p;
|
1995-08-24 09:03:04 +00:00
|
|
|
|
|
|
|
bzero(&drv, sizeof(drv));
|
|
|
|
if (argc < 3)
|
|
|
|
usage("arg count");
|
|
|
|
slot = atoi(argv[1]);
|
|
|
|
if (slot < 0 || slot >= MAXSLOT)
|
1997-10-06 11:36:08 +00:00
|
|
|
usage("illegal slot number");
|
1995-08-24 09:03:04 +00:00
|
|
|
p = argv[2];
|
|
|
|
while (*p && (*p < '0' || *p > '9'))
|
|
|
|
p++;
|
|
|
|
if (*p == 0)
|
1997-10-06 11:36:08 +00:00
|
|
|
usage("no unit on device name");
|
1995-08-24 09:03:04 +00:00
|
|
|
drv.unit = atoi(p);
|
|
|
|
*p = 0;
|
|
|
|
strcpy(drv.name, argv[2]);
|
|
|
|
argv += 3;
|
|
|
|
argc -= 3;
|
1996-04-10 05:45:39 +00:00
|
|
|
while (argc > 1) {
|
|
|
|
if (strcmp(argv[0], "-m") == 0) {
|
1995-08-24 09:03:04 +00:00
|
|
|
if (argc < 4)
|
1997-10-06 11:36:08 +00:00
|
|
|
usage("memory argument error");
|
1996-04-10 05:45:39 +00:00
|
|
|
if (sscanf(argv[1], "%x", &card_addr) != 1)
|
1997-10-06 11:36:08 +00:00
|
|
|
usage("bad card address");
|
1996-04-10 05:45:39 +00:00
|
|
|
if (sscanf(argv[2], "%lx", &drv.mem) != 1)
|
1997-10-06 11:36:08 +00:00
|
|
|
usage("bad memory address");
|
1996-04-10 05:45:39 +00:00
|
|
|
if (sscanf(argv[3], "%d", &i) != 1)
|
1997-10-06 11:36:08 +00:00
|
|
|
usage("bad memory size");
|
1995-08-24 09:03:04 +00:00
|
|
|
drv.memsize = i * 1024;
|
|
|
|
argc -= 2;
|
|
|
|
argv += 2;
|
1996-04-10 05:45:39 +00:00
|
|
|
} else if (strcmp(argv[0], "-f") == 0) {
|
|
|
|
if (sscanf(argv[1], "%x", &drv.flags) != 1)
|
1997-10-06 11:36:08 +00:00
|
|
|
usage("bad driver flags");
|
1996-04-10 05:45:39 +00:00
|
|
|
} else if (strcmp(argv[0], "-a") == 0) {
|
|
|
|
if (sscanf(argv[1], "%x", &drv.iobase) != 1)
|
1997-10-06 11:36:08 +00:00
|
|
|
usage("bad I/O address");
|
1996-04-10 05:45:39 +00:00
|
|
|
} else if (strcmp(argv[0], "-i") == 0) {
|
|
|
|
if (sscanf(argv[1], "%d", &i) != 1 || i < 1 || i > 15)
|
1997-10-06 11:36:08 +00:00
|
|
|
usage("illegal IRQ");
|
1995-08-24 09:03:04 +00:00
|
|
|
drv.irqmask = 1 << i;
|
1996-04-10 05:45:39 +00:00
|
|
|
}
|
1995-08-24 09:03:04 +00:00
|
|
|
argc -= 2;
|
|
|
|
argv += 2;
|
1996-04-10 05:45:39 +00:00
|
|
|
}
|
1995-08-24 09:03:04 +00:00
|
|
|
if (argc)
|
|
|
|
usage("no parameter for argument");
|
1995-08-25 09:46:01 +00:00
|
|
|
printf("drv %s%d, mem 0x%lx, size %d, io %d, irq 0x%x, flags 0x%x\n",
|
1995-08-24 09:03:04 +00:00
|
|
|
drv.name, drv.unit, drv.mem, drv.memsize, drv.iobase,
|
|
|
|
drv.irqmask, drv.flags);
|
1996-06-17 22:14:19 +00:00
|
|
|
sprintf(name, CARD_DEVICE, slot);
|
1995-08-24 09:03:04 +00:00
|
|
|
fd = open(name, 2);
|
1997-10-06 11:36:08 +00:00
|
|
|
if (fd < 0)
|
|
|
|
err(1, "%s", name);
|
1996-04-10 05:45:39 +00:00
|
|
|
|
|
|
|
/* Map the memory and I/O contexts. */
|
|
|
|
if (drv.mem) {
|
1995-08-24 09:03:04 +00:00
|
|
|
mem.window = 0;
|
1996-04-10 05:45:39 +00:00
|
|
|
mem.flags = MDF_ACTIVE | MDF_16BITS;
|
1995-08-24 09:03:04 +00:00
|
|
|
mem.start = (caddr_t)drv.mem;
|
|
|
|
mem.size = drv.memsize;
|
|
|
|
mem.card = card_addr;
|
1997-10-06 11:36:08 +00:00
|
|
|
if (ioctl(fd, PIOCSMEM, &mem))
|
|
|
|
err(1, "set memory context");
|
1996-04-10 05:45:39 +00:00
|
|
|
}
|
|
|
|
if (drv.iobase) {
|
1995-08-24 09:03:04 +00:00
|
|
|
io.window = 0;
|
1996-04-10 05:45:39 +00:00
|
|
|
io.flags = IODF_ACTIVE | IODF_CS16;
|
1995-08-24 09:03:04 +00:00
|
|
|
io.start = drv.iobase;
|
|
|
|
io.size = 32; /* Blah... */
|
1997-10-06 11:36:08 +00:00
|
|
|
if (ioctl(fd, PIOCSIO, &io))
|
|
|
|
err(1, "set I/O context");
|
1996-04-10 05:45:39 +00:00
|
|
|
}
|
1995-08-24 09:03:04 +00:00
|
|
|
if (ioctl(fd, PIOCSDRV, &drv))
|
1997-10-06 11:36:08 +00:00
|
|
|
warn("set driver");
|
1995-08-24 09:03:04 +00:00
|
|
|
close(fd);
|
1995-08-25 09:46:01 +00:00
|
|
|
return 0;
|
1995-08-24 09:03:04 +00:00
|
|
|
}
|
1996-04-10 05:45:39 +00:00
|
|
|
|
1995-08-24 09:03:04 +00:00
|
|
|
/*
|
|
|
|
* usage - print usage and exit
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
usage(msg)
|
1996-04-10 05:45:39 +00:00
|
|
|
char *msg;
|
1995-08-24 09:03:04 +00:00
|
|
|
{
|
1997-10-06 11:36:08 +00:00
|
|
|
warnx("enabler: %s", msg);
|
1995-08-24 09:03:04 +00:00
|
|
|
fprintf(stderr,
|
1997-10-06 11:36:08 +00:00
|
|
|
"usage: pccardc enabler slot driver [-m addr size] [-a iobase] [-i irq]\n");
|
1995-08-24 09:03:04 +00:00
|
|
|
fprintf(stderr,
|
1997-10-06 11:36:08 +00:00
|
|
|
" -m card addr size : card address (hex), host address (hex) & size (Kb)\n");
|
1995-08-24 09:03:04 +00:00
|
|
|
fprintf(stderr,
|
1997-10-06 11:36:08 +00:00
|
|
|
" -a iobase : I/O port address (hex)\n");
|
1995-08-24 09:03:04 +00:00
|
|
|
fprintf(stderr,
|
1997-10-06 11:36:08 +00:00
|
|
|
" -i irq : interrupt request number (1-15)\n");
|
1995-08-24 09:03:04 +00:00
|
|
|
fprintf(stderr,
|
1997-10-06 11:36:08 +00:00
|
|
|
" Example: enabler 0 ed0 -m 2000 d4000 16 -a 300 -i 3\n");
|
1995-08-24 09:03:04 +00:00
|
|
|
exit(1);
|
|
|
|
}
|