1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* pccard.c - Interface code for PC-CARD controllers.
|
|
|
|
*
|
|
|
|
* June 1995, Andrew McRae (andrew@mega.com.au)
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* 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.
|
1998-01-02 13:35:06 +00:00
|
|
|
*
|
1998-11-09 09:30:55 +00:00
|
|
|
* $Id: pccard.c,v 1.66 1998/09/24 17:56:31 nate Exp $
|
1995-08-24 08:56:20 +00:00
|
|
|
*/
|
|
|
|
|
1998-01-24 02:54:56 +00:00
|
|
|
#include "opt_devfs.h"
|
1998-09-08 18:09:51 +00:00
|
|
|
#include "opt_pcic.h"
|
1998-01-24 02:54:56 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/malloc.h>
|
1997-04-20 07:21:12 +00:00
|
|
|
#include <sys/sysctl.h>
|
1995-12-08 11:19:42 +00:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#ifdef DEVFS
|
|
|
|
#include <sys/devfsext.h>
|
|
|
|
#endif /*DEVFS*/
|
1997-01-13 21:51:13 +00:00
|
|
|
#include <sys/uio.h>
|
1997-09-14 03:19:42 +00:00
|
|
|
#include <sys/poll.h>
|
1997-10-06 04:32:42 +00:00
|
|
|
#include <sys/interrupt.h>
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
#include <i386/isa/isa_device.h>
|
|
|
|
#include <i386/isa/icu.h>
|
1998-11-09 09:30:55 +00:00
|
|
|
#include <i386/isa/intr_machdep.h>
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1996-04-23 16:03:08 +00:00
|
|
|
#include "apm.h"
|
1997-10-23 22:54:47 +00:00
|
|
|
#if NAPM > 0
|
1996-04-23 16:03:08 +00:00
|
|
|
#include <machine/apm_bios.h>
|
|
|
|
#endif /* NAPM > 0 */
|
|
|
|
|
1997-11-18 21:04:01 +00:00
|
|
|
#include <pccard/cardinfo.h>
|
1995-12-16 00:11:11 +00:00
|
|
|
#include <pccard/driver.h>
|
1995-11-14 20:49:24 +00:00
|
|
|
#include <pccard/slot.h>
|
|
|
|
|
1996-06-25 20:31:01 +00:00
|
|
|
#include <machine/md_var.h>
|
1996-06-05 05:30:09 +00:00
|
|
|
|
1997-10-23 22:54:47 +00:00
|
|
|
/*
|
1997-10-24 15:27:16 +00:00
|
|
|
* XXX We shouldn't be using processor-specific/bus-specific code in
|
|
|
|
* here, but we need the start of the ISA hole (IOM_BEGIN).
|
1997-10-23 22:54:47 +00:00
|
|
|
*/
|
1998-05-05 13:21:08 +00:00
|
|
|
#ifdef PC98
|
|
|
|
#include <pc98/pc98/pc98.h>
|
|
|
|
#else
|
1997-10-24 15:27:16 +00:00
|
|
|
#include <i386/isa/isa.h>
|
1998-05-05 13:21:08 +00:00
|
|
|
#endif
|
1997-10-23 22:54:47 +00:00
|
|
|
|
1997-04-20 07:21:12 +00:00
|
|
|
SYSCTL_NODE(_machdep, OID_AUTO, pccard, CTLFLAG_RW, 0, "pccard");
|
|
|
|
|
|
|
|
static int pcic_resume_reset =
|
1998-09-08 18:09:51 +00:00
|
|
|
#ifdef PCIC_RESUME_RESET /* opt_pcic.h */
|
1997-04-20 07:21:12 +00:00
|
|
|
1;
|
|
|
|
#else
|
|
|
|
0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SYSCTL_INT(_machdep_pccard, OID_AUTO, pcic_resume_reset, CTLFLAG_RW,
|
|
|
|
&pcic_resume_reset, 0, "");
|
1995-08-24 08:56:20 +00:00
|
|
|
|
|
|
|
#define PCCARD_MEMSIZE (4*1024)
|
|
|
|
|
|
|
|
#define MIN(a,b) ((a)<(b)?(a):(b))
|
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
static int allocate_driver(struct slot *, struct dev_desc *);
|
1995-11-09 20:44:36 +00:00
|
|
|
static void inserted(void *);
|
1997-10-26 04:36:24 +00:00
|
|
|
static void unregister_device_interrupt(struct pccard_devinfo *);
|
1995-11-09 20:44:36 +00:00
|
|
|
static void disable_slot(struct slot *);
|
|
|
|
static int invalid_io_memory(unsigned long, int);
|
1997-10-26 04:36:24 +00:00
|
|
|
static struct pccard_device *find_driver(char *);
|
|
|
|
static void remove_device(struct pccard_devinfo *);
|
1998-06-18 15:32:09 +00:00
|
|
|
static inthand2_t slot_irq_handler;
|
1996-04-23 16:03:08 +00:00
|
|
|
static void power_off_slot(void *);
|
|
|
|
|
|
|
|
#if NAPM > 0
|
|
|
|
/*
|
|
|
|
* For the APM stuff, the apmhook structure is kept
|
|
|
|
* separate from the slot structure so that the slot
|
|
|
|
* drivers do not need to know about the hooks (or the
|
|
|
|
* data structures).
|
|
|
|
*/
|
|
|
|
static int slot_suspend(void *arg);
|
|
|
|
static int slot_resume(void *arg);
|
|
|
|
static struct apmhook s_hook[MAXSLOT]; /* APM suspend */
|
|
|
|
static struct apmhook r_hook[MAXSLOT]; /* APM resume */
|
|
|
|
#endif /* NAPM > 0 */
|
1995-08-24 08:56:20 +00:00
|
|
|
|
1995-11-09 20:44:36 +00:00
|
|
|
static struct slot *pccard_slots[MAXSLOT]; /* slot entries */
|
|
|
|
static struct slot *slot_list;
|
|
|
|
static struct slot_ctrl *cont_list;
|
1997-10-26 04:36:24 +00:00
|
|
|
static struct pccard_device *drivers; /* Card drivers */
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* The driver interface for read/write uses a block
|
|
|
|
* of memory in the ISA I/O memory space allocated via
|
|
|
|
* an ioctl setting.
|
|
|
|
*/
|
|
|
|
static unsigned long pccard_mem; /* Physical memory */
|
|
|
|
static unsigned char *pccard_kmem; /* Kernel virtual address */
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static d_open_t crdopen;
|
|
|
|
static d_close_t crdclose;
|
|
|
|
static d_read_t crdread;
|
|
|
|
static d_write_t crdwrite;
|
|
|
|
static d_ioctl_t crdioctl;
|
1997-09-14 03:19:42 +00:00
|
|
|
static d_poll_t crdpoll;
|
1995-12-08 11:19:42 +00:00
|
|
|
|
|
|
|
#define CDEV_MAJOR 50
|
1995-12-08 23:23:00 +00:00
|
|
|
static struct cdevsw crd_cdevsw =
|
1995-12-08 11:19:42 +00:00
|
|
|
{ crdopen, crdclose, crdread, crdwrite, /*50*/
|
|
|
|
crdioctl, nostop, nullreset, nodevtotty,/* pcmcia */
|
1997-09-14 03:19:42 +00:00
|
|
|
crdpoll, nommap, NULL, "crd", NULL, -1 };
|
1995-12-08 11:19:42 +00:00
|
|
|
|
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* pccard_configure - called by autoconf code.
|
|
|
|
* Probes for various PC-CARD controllers, and
|
|
|
|
* initialises data structures to point to the
|
|
|
|
* various slots.
|
|
|
|
*
|
|
|
|
* Each controller indicates the number of slots
|
|
|
|
* that it sees, and these are mapped to a master
|
|
|
|
* slot number accessed via the character device entries.
|
|
|
|
*/
|
|
|
|
void
|
1997-10-26 21:08:42 +00:00
|
|
|
pccard_configure(void)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
1997-10-26 21:08:42 +00:00
|
|
|
struct pccard_device **drivers, *drv;
|
1995-10-21 00:55:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
#include "pcic.h"
|
|
|
|
#if NPCIC > 0
|
|
|
|
pcic_probe();
|
|
|
|
#endif
|
1997-10-26 21:08:42 +00:00
|
|
|
|
|
|
|
drivers = (struct pccard_device **)pccarddrv_set.ls_items;
|
|
|
|
printf("Initializing PC-card drivers:");
|
|
|
|
while ((drv = *drivers++)) {
|
|
|
|
printf(" %s", drv->name);
|
|
|
|
pccard_add_driver(drv);
|
|
|
|
}
|
|
|
|
printf("\n");
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* pccard_add_driver - Add a new driver to the list of
|
|
|
|
* drivers available for allocation.
|
|
|
|
*/
|
|
|
|
void
|
1997-10-26 04:36:24 +00:00
|
|
|
pccard_add_driver(struct pccard_device *drv)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* If already loaded, then reject the driver.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
if (find_driver(drv->name)) {
|
|
|
|
printf("Driver %s already loaded\n", drv->name);
|
1995-08-24 08:56:20 +00:00
|
|
|
return;
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
1997-10-26 04:36:24 +00:00
|
|
|
drv->next = drivers;
|
|
|
|
drivers = drv;
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* pccard_remove_driver - called to unlink driver
|
|
|
|
* from devices. Usually called when drivers are
|
1998-09-08 18:09:51 +00:00
|
|
|
* unloaded from kernel.
|
1995-08-24 08:56:20 +00:00
|
|
|
*/
|
|
|
|
void
|
1997-10-26 04:36:24 +00:00
|
|
|
pccard_remove_driver(struct pccard_device *drv)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt;
|
|
|
|
struct pccard_devinfo *devi, *next;
|
|
|
|
struct pccard_device *drvlist;
|
|
|
|
|
|
|
|
for (slt = slot_list; slt; slt = slt->next)
|
|
|
|
for (devi = slt->devices; devi; devi = next) {
|
|
|
|
next = devi->next;
|
|
|
|
if (devi->drv == drv)
|
|
|
|
remove_device(devi);
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Once all the devices belonging to this driver have been
|
|
|
|
* freed, then remove the driver from the list
|
|
|
|
* of registered drivers.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
if (drivers == drv)
|
|
|
|
drivers = drv->next;
|
1995-08-24 08:56:20 +00:00
|
|
|
else
|
1997-10-26 04:36:24 +00:00
|
|
|
for (drvlist = drivers; drvlist->next; drvlist = drvlist->next)
|
|
|
|
if (drvlist->next == drv) {
|
|
|
|
drvlist->next = drv->next;
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* pccard_remove_controller - Called when the slot
|
|
|
|
* driver is unloaded. The plan is to unload
|
|
|
|
* drivers from the slots, and then remove the
|
|
|
|
* slots from the slot list, and then finally
|
|
|
|
* remove the controller structure. Messy...
|
|
|
|
*/
|
|
|
|
void
|
1997-10-26 04:36:24 +00:00
|
|
|
pccard_remove_controller(struct slot_ctrl *ctrl)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt, *next, *last = 0;
|
1995-11-09 20:44:36 +00:00
|
|
|
struct slot_ctrl *cl;
|
1997-10-26 04:36:24 +00:00
|
|
|
struct pccard_devinfo *devi;
|
1995-08-24 08:56:20 +00:00
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
for (slt = slot_list; slt; slt = next) {
|
|
|
|
next = slt->next;
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* If this slot belongs to this controller,
|
|
|
|
* remove this slot.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt->ctrl == ctrl) {
|
|
|
|
pccard_slots[slt->slotnum] = 0;
|
|
|
|
if (slt->insert_seq)
|
|
|
|
untimeout(inserted, (void *)slt, slt->insert_ch);
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* Unload the drivers attached to this slot.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
while (devi = slt->devices)
|
|
|
|
remove_device(devi);
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* Disable the slot and unlink the slot from the
|
|
|
|
* slot list.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
disable_slot(slt);
|
1995-08-24 08:56:20 +00:00
|
|
|
if (last)
|
|
|
|
last->next = next;
|
|
|
|
else
|
|
|
|
slot_list = next;
|
1996-04-23 16:03:08 +00:00
|
|
|
#if NAPM > 0
|
|
|
|
apm_hook_disestablish(APM_HOOK_SUSPEND,
|
1997-10-26 04:36:24 +00:00
|
|
|
&s_hook[slt->slotnum]);
|
1996-04-23 16:03:08 +00:00
|
|
|
apm_hook_disestablish(APM_HOOK_RESUME,
|
1997-10-26 04:36:24 +00:00
|
|
|
&r_hook[slt->slotnum]);
|
1996-04-23 16:03:08 +00:00
|
|
|
#endif
|
1997-10-26 04:36:24 +00:00
|
|
|
if (ctrl->extra && slt->cdata)
|
|
|
|
FREE(slt->cdata, M_DEVBUF);
|
|
|
|
FREE(slt, M_DEVBUF);
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
1997-10-26 04:36:24 +00:00
|
|
|
* Can't use slot after we have freed it.
|
1995-11-09 20:44:36 +00:00
|
|
|
*/
|
|
|
|
} else {
|
1997-10-26 04:36:24 +00:00
|
|
|
last = slt;
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Unlink controller structure from controller list.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
if (cont_list == ctrl)
|
|
|
|
cont_list = ctrl->next;
|
1995-08-24 08:56:20 +00:00
|
|
|
else
|
|
|
|
for (cl = cont_list; cl->next; cl = cl->next)
|
1997-10-26 04:36:24 +00:00
|
|
|
if (cl->next == ctrl) {
|
|
|
|
cl->next = ctrl->next;
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
|
|
|
|
1996-04-23 16:03:08 +00:00
|
|
|
/*
|
|
|
|
* Power off the slot.
|
|
|
|
* (doing it immediately makes the removal of some cards unstable)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
power_off_slot(void *arg)
|
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt = (struct slot *)arg;
|
1996-04-23 16:03:08 +00:00
|
|
|
|
|
|
|
/* Power off the slot. */
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->pwr_off_pending = 0;
|
|
|
|
slt->ctrl->disable(slt);
|
1996-04-23 16:03:08 +00:00
|
|
|
}
|
|
|
|
|
1997-10-23 22:54:47 +00:00
|
|
|
/*
|
|
|
|
* unregister_device_interrupt - Disable the interrupt generation to
|
|
|
|
* the device driver which is handling it, so we can remove it.
|
|
|
|
*/
|
|
|
|
static void
|
1997-10-26 04:36:24 +00:00
|
|
|
unregister_device_interrupt(struct pccard_devinfo *devi)
|
1997-10-23 22:54:47 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt = devi->slt;
|
1997-10-23 22:54:47 +00:00
|
|
|
int s;
|
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
if (devi->running) {
|
|
|
|
s = splhigh();
|
|
|
|
devi->drv->disable(devi);
|
|
|
|
devi->running = 0;
|
|
|
|
if (devi->isahd.id_irq && --slt->irqref <= 0) {
|
|
|
|
printf("Return IRQ=%d\n",slt->irq);
|
|
|
|
slt->ctrl->mapirq(slt, 0);
|
|
|
|
INTRDIS(1<<slt->irq);
|
|
|
|
unregister_intr(slt->irq, slot_irq_handler);
|
|
|
|
if (devi->drv->imask)
|
|
|
|
INTRUNMASK(*devi->drv->imask,(1<<slt->irq));
|
1997-10-23 22:54:47 +00:00
|
|
|
/* Remove from the PCIC controller imask */
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt->ctrl->imask)
|
|
|
|
INTRUNMASK(*(slt->ctrl->imask), (1<<slt->irq));
|
|
|
|
slt->irq = 0;
|
1997-10-23 22:54:47 +00:00
|
|
|
}
|
1997-10-26 04:36:24 +00:00
|
|
|
splx(s);
|
1997-10-23 22:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* disable_slot - Disables the slot by removing
|
|
|
|
* the power and unmapping the I/O
|
|
|
|
*/
|
|
|
|
static void
|
1997-10-26 04:36:24 +00:00
|
|
|
disable_slot(struct slot *slt)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct pccard_devinfo *devi;
|
1995-11-09 20:44:36 +00:00
|
|
|
int i;
|
|
|
|
/*
|
|
|
|
* Unload all the drivers on this slot. Note we can't
|
1997-10-23 22:54:47 +00:00
|
|
|
* remove the device structures themselves, because this
|
|
|
|
* may be called from the event routine, which is called
|
|
|
|
* from the slot controller's ISR, and removing the structures
|
|
|
|
* shouldn't happen during the middle of some driver activity.
|
1995-11-09 20:44:36 +00:00
|
|
|
*
|
|
|
|
* Note that a race condition is possible here; if a
|
|
|
|
* driver is accessing the device and it is removed, then
|
|
|
|
* all bets are off...
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
for (devi = slt->devices; devi; devi = devi->next)
|
|
|
|
unregister_device_interrupt(devi);
|
1997-10-23 22:54:47 +00:00
|
|
|
|
|
|
|
/* Power off the slot 1/2 second after removal of the card */
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->poff_ch = timeout(power_off_slot, (caddr_t)slt, hz / 2);
|
|
|
|
slt->pwr_off_pending = 1;
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1997-10-23 22:54:47 +00:00
|
|
|
/* De-activate all contexts. */
|
1997-10-26 04:36:24 +00:00
|
|
|
for (i = 0; i < slt->ctrl->maxmem; i++)
|
|
|
|
if (slt->mem[i].flags & MDF_ACTIVE) {
|
|
|
|
slt->mem[i].flags = 0;
|
|
|
|
(void)slt->ctrl->mapmem(slt, i);
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
1997-10-26 04:36:24 +00:00
|
|
|
for (i = 0; i < slt->ctrl->maxio; i++)
|
|
|
|
if (slt->io[i].flags & IODF_ACTIVE) {
|
|
|
|
slt->io[i].flags = 0;
|
|
|
|
(void)slt->ctrl->mapio(slt, i);
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
|
|
|
|
1996-04-23 16:03:08 +00:00
|
|
|
/*
|
1997-10-23 22:54:47 +00:00
|
|
|
* APM hooks for suspending and resuming.
|
1996-04-23 16:03:08 +00:00
|
|
|
*/
|
|
|
|
#if NAPM > 0
|
|
|
|
static int
|
|
|
|
slot_suspend(void *arg)
|
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt = arg;
|
1996-04-23 16:03:08 +00:00
|
|
|
|
1997-10-28 17:51:25 +00:00
|
|
|
/* This code stolen from pccard_event:card_removed */
|
|
|
|
if (slt->state == filled) {
|
|
|
|
int s = splhigh();
|
|
|
|
disable_slot(slt);
|
1998-04-20 15:21:02 +00:00
|
|
|
slt->laststate = filled;
|
1997-10-28 17:51:25 +00:00
|
|
|
slt->state = suspend;
|
|
|
|
splx(s);
|
|
|
|
printf("Card disabled, slot %d\n", slt->slotnum);
|
|
|
|
}
|
1998-09-24 17:56:31 +00:00
|
|
|
/*
|
|
|
|
* Disable any pending timeouts for this slot since we're
|
|
|
|
* powering it down/disabling now.
|
|
|
|
*/
|
|
|
|
untimeout(power_off_slot, (caddr_t)slt, slt->poff_ch);
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->ctrl->disable(slt);
|
1996-04-23 16:03:08 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
slot_resume(void *arg)
|
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt = arg;
|
1996-04-23 16:03:08 +00:00
|
|
|
|
1997-04-20 07:21:12 +00:00
|
|
|
if (pcic_resume_reset)
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->ctrl->resume(slt);
|
1997-10-28 17:51:25 +00:00
|
|
|
/* This code stolen from pccard_event:card_inserted */
|
|
|
|
if (slt->state == suspend) {
|
1998-04-20 15:21:02 +00:00
|
|
|
slt->laststate = suspend;
|
1997-10-26 04:54:16 +00:00
|
|
|
slt->state = empty;
|
|
|
|
slt->insert_seq = 1;
|
1997-10-28 17:51:25 +00:00
|
|
|
slt->insert_ch = timeout(inserted, (void *)slt, hz/4);
|
1997-10-26 04:54:16 +00:00
|
|
|
selwakeup(&slt->selp);
|
|
|
|
}
|
1996-04-23 16:03:08 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif /* NAPM > 0 */
|
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* pccard_alloc_slot - Called from controller probe
|
|
|
|
* routine, this function allocates a new PC-CARD slot
|
|
|
|
* and initialises the data structures using the data provided.
|
|
|
|
* It returns the allocated structure to the probe routine
|
|
|
|
* to allow the controller specific data to be initialised.
|
|
|
|
*/
|
|
|
|
struct slot *
|
1997-10-26 04:36:24 +00:00
|
|
|
pccard_alloc_slot(struct slot_ctrl *ctrl)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt;
|
|
|
|
int slotno;
|
1995-08-24 08:56:20 +00:00
|
|
|
|
|
|
|
for (slotno = 0; slotno < MAXSLOT; slotno++)
|
|
|
|
if (pccard_slots[slotno] == 0)
|
|
|
|
break;
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slotno == MAXSLOT)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(0);
|
1997-10-26 04:36:24 +00:00
|
|
|
|
|
|
|
MALLOC(slt, struct slot *, sizeof(*slt), M_DEVBUF, M_WAITOK);
|
|
|
|
bzero(slt, sizeof(*slt));
|
1996-01-28 10:02:38 +00:00
|
|
|
#ifdef DEVFS
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->devfs_token = devfs_add_devswf(&crd_cdevsw,
|
1998-01-02 13:35:06 +00:00
|
|
|
slotno, DV_CHR, 0, 0, 0600, "card%d", slotno);
|
1996-01-28 10:02:38 +00:00
|
|
|
#endif
|
1997-10-26 04:36:24 +00:00
|
|
|
if (ctrl->extra) {
|
|
|
|
MALLOC(slt->cdata, void *, ctrl->extra, M_DEVBUF, M_WAITOK);
|
|
|
|
bzero(slt->cdata, ctrl->extra);
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->ctrl = ctrl;
|
|
|
|
slt->slotnum = slotno;
|
|
|
|
pccard_slots[slotno] = slt;
|
|
|
|
slt->next = slot_list;
|
|
|
|
slot_list = slt;
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* If this controller hasn't been seen before, then
|
|
|
|
* link it into the list of controllers.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
if (ctrl->slots++ == 0) {
|
|
|
|
ctrl->next = cont_list;
|
|
|
|
cont_list = ctrl;
|
|
|
|
if (ctrl->maxmem > NUM_MEM_WINDOWS)
|
|
|
|
ctrl->maxmem = NUM_MEM_WINDOWS;
|
|
|
|
if (ctrl->maxio > NUM_IO_WINDOWS)
|
|
|
|
ctrl->maxio = NUM_IO_WINDOWS;
|
1995-08-24 08:56:20 +00:00
|
|
|
printf("PC-Card %s (%d mem & %d I/O windows)\n",
|
1997-10-26 04:36:24 +00:00
|
|
|
ctrl->name, ctrl->maxmem, ctrl->maxio);
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
1997-10-26 02:55:31 +00:00
|
|
|
callout_handle_init(&slt->insert_ch);
|
|
|
|
callout_handle_init(&slt->poff_ch);
|
1996-04-23 16:03:08 +00:00
|
|
|
#if NAPM > 0
|
|
|
|
{
|
|
|
|
struct apmhook *ap;
|
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
ap = &s_hook[slt->slotnum];
|
1996-04-23 16:03:08 +00:00
|
|
|
ap->ah_fun = slot_suspend;
|
1997-10-26 04:36:24 +00:00
|
|
|
ap->ah_arg = (void *)slt;
|
|
|
|
ap->ah_name = ctrl->name;
|
1996-04-23 16:03:08 +00:00
|
|
|
ap->ah_order = APM_MID_ORDER;
|
|
|
|
apm_hook_establish(APM_HOOK_SUSPEND, ap);
|
1997-10-26 04:36:24 +00:00
|
|
|
ap = &r_hook[slt->slotnum];
|
1996-04-23 16:03:08 +00:00
|
|
|
ap->ah_fun = slot_resume;
|
1997-10-26 04:36:24 +00:00
|
|
|
ap->ah_arg = (void *)slt;
|
|
|
|
ap->ah_name = ctrl->name;
|
1996-04-23 16:03:08 +00:00
|
|
|
ap->ah_order = APM_MID_ORDER;
|
|
|
|
apm_hook_establish(APM_HOOK_RESUME, ap);
|
|
|
|
}
|
1997-10-23 22:54:47 +00:00
|
|
|
#endif /* NAPM > 0 */
|
1997-10-26 04:36:24 +00:00
|
|
|
return(slt);
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* pccard_alloc_intr - allocate an interrupt from the
|
|
|
|
* free interrupts and return its number. The interrupts
|
|
|
|
* allowed are passed as a mask.
|
|
|
|
*/
|
|
|
|
int
|
1997-01-11 18:23:20 +00:00
|
|
|
pccard_alloc_intr(u_int imask, inthand2_t *hand, int unit,
|
|
|
|
u_int *maskp, u_int *pcic_imask)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
1996-01-28 10:02:38 +00:00
|
|
|
int irq;
|
1995-11-09 20:44:36 +00:00
|
|
|
unsigned int mask;
|
1995-08-24 08:56:20 +00:00
|
|
|
|
1997-10-23 02:25:14 +00:00
|
|
|
for (irq = 1; irq < ICU_LEN; irq++) {
|
1995-08-24 08:56:20 +00:00
|
|
|
mask = 1ul << irq;
|
1995-09-20 07:23:51 +00:00
|
|
|
if (!(mask & imask))
|
|
|
|
continue;
|
1997-11-15 14:20:31 +00:00
|
|
|
INTRMASK(*maskp, mask);
|
1997-10-26 04:36:24 +00:00
|
|
|
if (register_intr(irq, 0, 0, hand, maskp, unit) == 0) {
|
1997-01-11 18:23:20 +00:00
|
|
|
/* add this to the PCIC controller's mask */
|
1997-11-15 14:20:31 +00:00
|
|
|
if (pcic_imask)
|
|
|
|
INTRMASK(*pcic_imask, (1 << irq));
|
|
|
|
update_intr_masks();
|
1997-10-26 04:36:24 +00:00
|
|
|
INTREN(mask);
|
1995-08-24 08:56:20 +00:00
|
|
|
return(irq);
|
|
|
|
}
|
1997-10-26 04:36:24 +00:00
|
|
|
/* No luck, remove from mask again... */
|
1997-11-15 14:20:31 +00:00
|
|
|
INTRUNMASK(*maskp, mask);
|
|
|
|
update_intr_masks();
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
1995-08-24 08:56:20 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* allocate_driver - Create a new device entry for this
|
|
|
|
* slot, and attach a driver to it.
|
|
|
|
*/
|
|
|
|
static int
|
1997-10-26 04:36:24 +00:00
|
|
|
allocate_driver(struct slot *slt, struct dev_desc *desc)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct pccard_devinfo *devi;
|
|
|
|
struct pccard_device *drv;
|
1995-11-09 20:44:36 +00:00
|
|
|
int err, irq = 0, s;
|
1995-08-24 08:56:20 +00:00
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
drv = find_driver(desc->name);
|
|
|
|
if (drv == 0)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(ENXIO);
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* If an instance of this driver is already installed,
|
|
|
|
* but not running, then remove it. If it is running,
|
|
|
|
* then reject the request.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
for (devi = slt->devices; devi; devi = devi->next)
|
|
|
|
if (devi->drv == drv && devi->isahd.id_unit == desc->unit) {
|
|
|
|
if (devi->running)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(EBUSY);
|
1997-10-26 04:36:24 +00:00
|
|
|
remove_device(devi);
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If an interrupt mask has been given, then check it
|
|
|
|
* against the slot interrupt (if one has been allocated).
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
if (desc->irqmask && drv->imask) {
|
|
|
|
if ((slt->ctrl->irqs & desc->irqmask) == 0)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(EINVAL);
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt->irq) {
|
|
|
|
if (((1 << slt->irq) & desc->irqmask) == 0)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(EINVAL);
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->irqref++;
|
|
|
|
irq = slt->irq;
|
1995-11-09 20:44:36 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Attempt to allocate an interrupt.
|
|
|
|
* XXX We lose at the moment if the second
|
|
|
|
* device relies on a different interrupt mask.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
irq = pccard_alloc_intr(desc->irqmask,
|
|
|
|
slot_irq_handler, (int)slt,
|
|
|
|
drv->imask, slt->ctrl->imask);
|
1995-08-24 08:56:20 +00:00
|
|
|
if (irq < 0)
|
|
|
|
return(EINVAL);
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->irq = irq;
|
|
|
|
slt->irqref = 1;
|
|
|
|
slt->ctrl->mapirq(slt, slt->irq);
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
1997-10-26 04:36:24 +00:00
|
|
|
MALLOC(devi, struct pccard_devinfo *, sizeof(*devi), M_DEVBUF, M_WAITOK);
|
|
|
|
bzero(devi, sizeof(*devi));
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* Create an entry for the device under this slot.
|
|
|
|
*/
|
1998-04-09 14:01:13 +00:00
|
|
|
devi->running = 1;
|
1997-10-26 04:36:24 +00:00
|
|
|
devi->drv = drv;
|
|
|
|
devi->slt = slt;
|
|
|
|
devi->isahd.id_irq = irq;
|
|
|
|
devi->isahd.id_unit = desc->unit;
|
|
|
|
devi->isahd.id_msize = desc->memsize;
|
|
|
|
devi->isahd.id_iobase = desc->iobase;
|
|
|
|
bcopy(desc->misc, devi->misc, sizeof(desc->misc));
|
1995-08-24 08:56:20 +00:00
|
|
|
if (irq)
|
1997-10-26 04:36:24 +00:00
|
|
|
devi->isahd.id_irq = 1 << irq;
|
|
|
|
devi->isahd.id_flags = desc->flags;
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* Convert the memory to kernel space.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
if (desc->mem)
|
|
|
|
devi->isahd.id_maddr =
|
1998-08-16 01:21:52 +00:00
|
|
|
(caddr_t)(void *)(uintptr_t)
|
|
|
|
(desc->mem + atdevbase - IOM_BEGIN);
|
1995-08-24 08:56:20 +00:00
|
|
|
else
|
1997-10-26 04:36:24 +00:00
|
|
|
devi->isahd.id_maddr = 0;
|
|
|
|
devi->next = slt->devices;
|
|
|
|
slt->devices = devi;
|
1995-08-24 08:56:20 +00:00
|
|
|
s = splhigh();
|
1997-10-26 04:54:16 +00:00
|
|
|
err = drv->enable(devi);
|
1995-08-24 08:56:20 +00:00
|
|
|
splx(s);
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
1997-10-26 04:36:24 +00:00
|
|
|
* If the enable functions returns no error, then the
|
1995-11-09 20:44:36 +00:00
|
|
|
* device has been successfully installed. If so, then
|
|
|
|
* attach it to the slot, otherwise free it and return
|
1998-04-08 15:00:02 +00:00
|
|
|
* the error. We assume that when we free the device,
|
|
|
|
* it will also set 'running' to off.
|
1995-11-09 20:44:36 +00:00
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
if (err)
|
1997-10-26 04:36:24 +00:00
|
|
|
remove_device(devi);
|
1995-08-24 08:56:20 +00:00
|
|
|
return(err);
|
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
static void
|
1997-10-26 04:36:24 +00:00
|
|
|
remove_device(struct pccard_devinfo *devi)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt = devi->slt;
|
|
|
|
struct pccard_devinfo *list;
|
1995-11-09 20:44:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If an interrupt is enabled on this slot,
|
|
|
|
* then unregister it if no-one else is using it.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
unregister_device_interrupt(devi);
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* Remove from device list on this slot.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt->devices == devi)
|
|
|
|
slt->devices = devi->next;
|
1995-08-24 08:56:20 +00:00
|
|
|
else
|
1997-10-26 04:36:24 +00:00
|
|
|
for (list = slt->devices; list->next; list = list->next)
|
|
|
|
if (list->next == devi) {
|
|
|
|
list->next = devi->next;
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Finally, free the memory space.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
FREE(devi, M_DEVBUF);
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* card insert routine - Called from a timeout to debounce
|
|
|
|
* insertion events.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
inserted(void *arg)
|
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt = arg;
|
1995-08-24 08:56:20 +00:00
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->state = filled;
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* Enable 5V to the card so that the CIS can be read.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->pwr.vcc = 50;
|
|
|
|
slt->pwr.vpp = 0;
|
1997-10-23 22:54:47 +00:00
|
|
|
/*
|
|
|
|
* Disable any pending timeouts for this slot, and explicitly
|
|
|
|
* power it off right now. Then, re-enable the power using
|
|
|
|
* the (possibly new) power settings.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
untimeout(power_off_slot, (caddr_t)slt, slt->poff_ch);
|
|
|
|
power_off_slot(slt);
|
|
|
|
slt->ctrl->power(slt);
|
1997-10-23 22:54:47 +00:00
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
printf("Card inserted, slot %d\n", slt->slotnum);
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* Now start resetting the card.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->ctrl->reset(slt);
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* Card event callback. Called at splhigh to prevent
|
|
|
|
* device interrupts from interceding.
|
|
|
|
*/
|
|
|
|
void
|
1997-10-26 04:36:24 +00:00
|
|
|
pccard_event(struct slot *slt, enum card_event event)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt->insert_seq) {
|
|
|
|
slt->insert_seq = 0;
|
|
|
|
untimeout(inserted, (void *)slt, slt->insert_ch);
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
1997-10-26 04:36:24 +00:00
|
|
|
|
1995-11-09 20:44:36 +00:00
|
|
|
switch(event) {
|
1995-08-24 08:56:20 +00:00
|
|
|
case card_removed:
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* The slot and devices are disabled, but the
|
|
|
|
* data structures are not unlinked.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt->state == filled) {
|
1997-10-23 22:54:47 +00:00
|
|
|
int s = splhigh();
|
1997-10-26 04:36:24 +00:00
|
|
|
disable_slot(slt);
|
|
|
|
slt->state = empty;
|
1995-08-24 08:56:20 +00:00
|
|
|
splx(s);
|
1997-10-26 04:36:24 +00:00
|
|
|
printf("Card removed, slot %d\n", slt->slotnum);
|
1997-10-26 06:06:54 +00:00
|
|
|
pccard_remove_beep();
|
1997-10-26 04:36:24 +00:00
|
|
|
selwakeup(&slt->selp);
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
|
|
|
case card_inserted:
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->insert_seq = 1;
|
|
|
|
slt->insert_ch = timeout(inserted, (void *)slt, hz/4);
|
1997-10-26 06:06:54 +00:00
|
|
|
pccard_remove_beep();
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* slot_irq_handler - Interrupt handler for shared irq devices.
|
|
|
|
*/
|
|
|
|
static void
|
1998-06-18 15:32:09 +00:00
|
|
|
slot_irq_handler(void *arg)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct pccard_devinfo *devi;
|
|
|
|
struct slot *slt = (struct slot *)arg;
|
1995-08-24 08:56:20 +00:00
|
|
|
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* For each device that has the shared interrupt,
|
|
|
|
* call the interrupt handler. If the interrupt was
|
|
|
|
* caught, the handler returns true.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
for (devi = slt->devices; devi; devi = devi->next)
|
|
|
|
if (devi->isahd.id_irq && devi->running &&
|
|
|
|
devi->drv->handler(devi))
|
1995-08-24 08:56:20 +00:00
|
|
|
return;
|
1997-10-23 22:54:47 +00:00
|
|
|
/*
|
|
|
|
* XXX - Should 'debounce' these for drivers that have recently
|
|
|
|
* been removed.
|
|
|
|
*/
|
1997-10-26 04:36:24 +00:00
|
|
|
printf("Slot %d, unfielded interrupt (%d)\n", slt->slotnum, slt->irq);
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1996-06-05 05:30:09 +00:00
|
|
|
/*
|
|
|
|
* Device driver interface.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-08-24 08:56:20 +00:00
|
|
|
crdopen(dev_t dev, int oflags, int devtype, struct proc *p)
|
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt;
|
1995-08-24 08:56:20 +00:00
|
|
|
|
|
|
|
if (minor(dev) >= MAXSLOT)
|
|
|
|
return(ENXIO);
|
1997-10-26 04:36:24 +00:00
|
|
|
slt = pccard_slots[minor(dev)];
|
|
|
|
if (slt == 0)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(ENXIO);
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt->rwmem == 0)
|
|
|
|
slt->rwmem = MDF_ATTR;
|
1995-08-24 08:56:20 +00:00
|
|
|
return(0);
|
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* Close doesn't de-allocate any resources, since
|
|
|
|
* slots may be assigned to drivers already.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-08-24 08:56:20 +00:00
|
|
|
crdclose(dev_t dev, int fflag, int devtype, struct proc *p)
|
|
|
|
{
|
|
|
|
return(0);
|
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* read interface. Map memory at lseek offset,
|
|
|
|
* then transfer to user space.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-08-24 08:56:20 +00:00
|
|
|
crdread(dev_t dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt = pccard_slots[minor(dev)];
|
1995-11-09 20:44:36 +00:00
|
|
|
struct mem_desc *mp, oldmap;
|
1997-10-26 04:36:24 +00:00
|
|
|
unsigned char *p;
|
1995-11-09 20:44:36 +00:00
|
|
|
unsigned int offs;
|
1997-10-26 04:36:24 +00:00
|
|
|
int error = 0, win, count;
|
1995-08-24 08:56:20 +00:00
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt == 0 || slt->state != filled)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(ENXIO);
|
|
|
|
if (pccard_mem == 0)
|
|
|
|
return(ENOMEM);
|
1997-10-26 04:36:24 +00:00
|
|
|
for (win = 0; win < slt->ctrl->maxmem; win++)
|
|
|
|
if ((slt->mem[win].flags & MDF_ACTIVE) == 0)
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
1997-10-26 04:36:24 +00:00
|
|
|
if (win >= slt->ctrl->maxmem)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(EBUSY);
|
1997-10-26 04:36:24 +00:00
|
|
|
mp = &slt->mem[win];
|
1995-08-24 08:56:20 +00:00
|
|
|
oldmap = *mp;
|
1997-10-26 04:36:24 +00:00
|
|
|
mp->flags = slt->rwmem|MDF_ACTIVE;
|
1995-08-24 08:56:20 +00:00
|
|
|
#if 0
|
|
|
|
printf("Rd at offs %d, size %d\n", (int)uio->uio_offset,
|
|
|
|
uio->uio_resid);
|
|
|
|
#endif
|
1995-11-09 20:44:36 +00:00
|
|
|
while (uio->uio_resid && error == 0) {
|
1995-08-24 08:56:20 +00:00
|
|
|
mp->card = uio->uio_offset;
|
|
|
|
mp->size = PCCARD_MEMSIZE;
|
1998-08-16 01:21:52 +00:00
|
|
|
mp->start = (caddr_t)(void *)(uintptr_t)pccard_mem;
|
1997-10-26 04:36:24 +00:00
|
|
|
if (error = slt->ctrl->mapmem(slt, win))
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
|
|
|
offs = (unsigned int)uio->uio_offset & (PCCARD_MEMSIZE - 1);
|
|
|
|
p = pccard_kmem + offs;
|
|
|
|
count = MIN(PCCARD_MEMSIZE - offs, uio->uio_resid);
|
|
|
|
error = uiomove(p, count, uio);
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Restore original map.
|
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
*mp = oldmap;
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->ctrl->mapmem(slt, win);
|
1995-08-24 08:56:20 +00:00
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* crdwrite - Write data to card memory.
|
|
|
|
* Handles wrap around so that only one memory
|
|
|
|
* window is used.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-08-24 08:56:20 +00:00
|
|
|
crdwrite(dev_t dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt = pccard_slots[minor(dev)];
|
1995-11-09 20:44:36 +00:00
|
|
|
struct mem_desc *mp, oldmap;
|
1997-10-26 04:36:24 +00:00
|
|
|
unsigned char *p;
|
1995-11-09 20:44:36 +00:00
|
|
|
unsigned int offs;
|
1997-10-26 04:36:24 +00:00
|
|
|
int error = 0, win, count;
|
1995-08-24 08:56:20 +00:00
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt == 0 || slt->state != filled)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(ENXIO);
|
|
|
|
if (pccard_mem == 0)
|
|
|
|
return(ENOMEM);
|
1997-10-26 04:36:24 +00:00
|
|
|
for (win = 0; win < slt->ctrl->maxmem; win++)
|
|
|
|
if ((slt->mem[win].flags & MDF_ACTIVE)==0)
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
1997-10-26 04:36:24 +00:00
|
|
|
if (win >= slt->ctrl->maxmem)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(EBUSY);
|
1997-10-26 04:36:24 +00:00
|
|
|
mp = &slt->mem[win];
|
1995-08-24 08:56:20 +00:00
|
|
|
oldmap = *mp;
|
1997-10-26 04:36:24 +00:00
|
|
|
mp->flags = slt->rwmem|MDF_ACTIVE;
|
1995-08-24 08:56:20 +00:00
|
|
|
#if 0
|
|
|
|
printf("Wr at offs %d, size %d\n", (int)uio->uio_offset,
|
|
|
|
uio->uio_resid);
|
|
|
|
#endif
|
1995-11-09 20:44:36 +00:00
|
|
|
while (uio->uio_resid && error == 0) {
|
1995-08-24 08:56:20 +00:00
|
|
|
mp->card = uio->uio_offset;
|
|
|
|
mp->size = PCCARD_MEMSIZE;
|
1998-08-16 01:21:52 +00:00
|
|
|
mp->start = (caddr_t)(void *)(uintptr_t)pccard_mem;
|
1997-10-26 04:36:24 +00:00
|
|
|
if (error = slt->ctrl->mapmem(slt, win))
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
|
|
|
offs = (unsigned int)uio->uio_offset & (PCCARD_MEMSIZE - 1);
|
|
|
|
p = pccard_kmem + offs;
|
|
|
|
count = MIN(PCCARD_MEMSIZE - offs, uio->uio_resid);
|
|
|
|
#if 0
|
|
|
|
printf("Writing %d bytes to address 0x%x\n", count, p);
|
|
|
|
#endif
|
|
|
|
error = uiomove(p, count, uio);
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Restore original map.
|
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
*mp = oldmap;
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->ctrl->mapmem(slt, win);
|
1995-08-24 08:56:20 +00:00
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* ioctl calls - allows setting/getting of memory and I/O
|
|
|
|
* descriptors, and assignment of drivers.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1998-06-07 17:13:14 +00:00
|
|
|
crdioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct proc *p)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt = pccard_slots[minor(dev)];
|
1995-11-09 20:44:36 +00:00
|
|
|
struct mem_desc *mp;
|
|
|
|
struct io_desc *ip;
|
1997-10-26 04:36:24 +00:00
|
|
|
int s, err;
|
1995-08-24 08:56:20 +00:00
|
|
|
|
1996-04-23 16:03:08 +00:00
|
|
|
/* beep is disabled until the 1st call of crdioctl() */
|
1997-10-26 06:06:54 +00:00
|
|
|
pccard_beep_select(BEEP_ON);
|
1996-04-23 16:03:08 +00:00
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt == 0 && cmd != PIOCRWMEM)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(ENXIO);
|
1995-11-09 20:44:36 +00:00
|
|
|
switch(cmd) {
|
1995-08-24 08:56:20 +00:00
|
|
|
default:
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt->ctrl->ioctl)
|
|
|
|
return(slt->ctrl->ioctl(slt, cmd, data));
|
1995-08-24 08:56:20 +00:00
|
|
|
return(EINVAL);
|
1997-10-26 04:36:24 +00:00
|
|
|
/*
|
|
|
|
* Get slot state.
|
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
case PIOCGSTATE:
|
|
|
|
s = splhigh();
|
1997-10-26 04:36:24 +00:00
|
|
|
((struct slotstate *)data)->state = slt->state;
|
1998-04-20 15:21:02 +00:00
|
|
|
((struct slotstate *)data)->laststate = slt->laststate;
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->laststate = slt->state;
|
1995-08-24 08:56:20 +00:00
|
|
|
splx(s);
|
1997-10-26 04:36:24 +00:00
|
|
|
((struct slotstate *)data)->maxmem = slt->ctrl->maxmem;
|
|
|
|
((struct slotstate *)data)->maxio = slt->ctrl->maxio;
|
|
|
|
((struct slotstate *)data)->irqs = slt->ctrl->irqs;
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* Get memory context.
|
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
case PIOCGMEM:
|
|
|
|
s = ((struct mem_desc *)data)->window;
|
1997-10-26 04:36:24 +00:00
|
|
|
if (s < 0 || s >= slt->ctrl->maxmem)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(EINVAL);
|
1997-10-26 04:36:24 +00:00
|
|
|
mp = &slt->mem[s];
|
1995-08-24 08:56:20 +00:00
|
|
|
((struct mem_desc *)data)->flags = mp->flags;
|
|
|
|
((struct mem_desc *)data)->start = mp->start;
|
|
|
|
((struct mem_desc *)data)->size = mp->size;
|
|
|
|
((struct mem_desc *)data)->card = mp->card;
|
|
|
|
break;
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* Set memory context. If context already active, then unmap it.
|
|
|
|
* It is hard to see how the parameters can be checked.
|
|
|
|
* At the very least, we only allow root to set the context.
|
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
case PIOCSMEM:
|
|
|
|
if (suser(p->p_ucred, &p->p_acflag))
|
|
|
|
return(EPERM);
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt->state != filled)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(ENXIO);
|
|
|
|
s = ((struct mem_desc *)data)->window;
|
1997-10-26 04:36:24 +00:00
|
|
|
if (s < 0 || s >= slt->ctrl->maxmem)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(EINVAL);
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->mem[s] = *((struct mem_desc *)data);
|
|
|
|
return(slt->ctrl->mapmem(slt, s));
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* Get I/O port context.
|
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
case PIOCGIO:
|
|
|
|
s = ((struct io_desc *)data)->window;
|
1997-10-26 04:36:24 +00:00
|
|
|
if (s < 0 || s >= slt->ctrl->maxio)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(EINVAL);
|
1997-10-26 04:36:24 +00:00
|
|
|
ip = &slt->io[s];
|
1995-08-24 08:56:20 +00:00
|
|
|
((struct io_desc *)data)->flags = ip->flags;
|
|
|
|
((struct io_desc *)data)->start = ip->start;
|
|
|
|
((struct io_desc *)data)->size = ip->size;
|
|
|
|
break;
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* Set I/O port context.
|
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
case PIOCSIO:
|
|
|
|
if (suser(p->p_ucred, &p->p_acflag))
|
|
|
|
return(EPERM);
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt->state != filled)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(ENXIO);
|
|
|
|
s = ((struct io_desc *)data)->window;
|
1997-10-26 04:36:24 +00:00
|
|
|
if (s < 0 || s >= slt->ctrl->maxio)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(EINVAL);
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->io[s] = *((struct io_desc *)data);
|
|
|
|
return(slt->ctrl->mapio(slt, s));
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
1997-10-26 04:36:24 +00:00
|
|
|
* Set memory window flags for read/write interface.
|
1995-11-09 20:44:36 +00:00
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
case PIOCRWFLAG:
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->rwmem = *(int *)data;
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
1997-10-26 04:36:24 +00:00
|
|
|
* Set the memory window to be used for the read/write interface.
|
1995-11-09 20:44:36 +00:00
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
case PIOCRWMEM:
|
1995-11-09 20:44:36 +00:00
|
|
|
if (*(unsigned long *)data == 0) {
|
1995-08-24 08:56:20 +00:00
|
|
|
if (pccard_mem)
|
|
|
|
*(unsigned long *)data = pccard_mem;
|
|
|
|
break;
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
1995-08-24 08:56:20 +00:00
|
|
|
if (suser(p->p_ucred, &p->p_acflag))
|
|
|
|
return(EPERM);
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* Validate the memory by checking it against the I/O
|
|
|
|
* memory range. It must also start on an aligned block size.
|
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
if (invalid_io_memory(*(unsigned long *)data, PCCARD_MEMSIZE))
|
|
|
|
return(EINVAL);
|
|
|
|
if (*(unsigned long *)data & (PCCARD_MEMSIZE-1))
|
|
|
|
return(EINVAL);
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* Map it to kernel VM.
|
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
pccard_mem = *(unsigned long *)data;
|
1998-08-16 01:21:52 +00:00
|
|
|
pccard_kmem =
|
|
|
|
(unsigned char *)(void *)(uintptr_t)
|
|
|
|
(pccard_mem + atdevbase - IOM_BEGIN);
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
1997-10-26 04:36:24 +00:00
|
|
|
* Set power values.
|
1995-11-09 20:44:36 +00:00
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
case PIOCSPOW:
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->pwr = *(struct power *)data;
|
|
|
|
return(slt->ctrl->power(slt));
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
1997-10-26 04:36:24 +00:00
|
|
|
* Allocate a driver to this slot.
|
1995-11-09 20:44:36 +00:00
|
|
|
*/
|
1995-08-24 08:56:20 +00:00
|
|
|
case PIOCSDRV:
|
|
|
|
if (suser(p->p_ucred, &p->p_acflag))
|
|
|
|
return(EPERM);
|
1997-10-26 04:36:24 +00:00
|
|
|
err = allocate_driver(slt, (struct dev_desc *)data);
|
1996-02-21 23:20:21 +00:00
|
|
|
if (!err)
|
1997-10-26 06:06:54 +00:00
|
|
|
pccard_success_beep();
|
1996-02-21 23:20:21 +00:00
|
|
|
else
|
1997-10-26 06:06:54 +00:00
|
|
|
pccard_failure_beep();
|
1996-02-21 23:20:21 +00:00
|
|
|
return err;
|
1997-10-23 22:54:47 +00:00
|
|
|
}
|
1995-08-24 08:56:20 +00:00
|
|
|
return(0);
|
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
1997-09-14 03:19:42 +00:00
|
|
|
* poll - Poll on exceptions will return true
|
1995-08-24 08:56:20 +00:00
|
|
|
* when a change in card status occurs.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1997-09-14 03:19:42 +00:00
|
|
|
crdpoll(dev_t dev, int events, struct proc *p)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
1995-11-09 20:44:36 +00:00
|
|
|
int s;
|
1997-10-26 04:36:24 +00:00
|
|
|
struct slot *slt = pccard_slots[minor(dev)];
|
1997-09-14 03:19:42 +00:00
|
|
|
int revents = 0;
|
1995-08-24 08:56:20 +00:00
|
|
|
|
1997-09-14 03:19:42 +00:00
|
|
|
if (events & (POLLIN | POLLRDNORM))
|
|
|
|
revents |= events & (POLLIN | POLLRDNORM);
|
|
|
|
|
|
|
|
if (events & (POLLOUT | POLLWRNORM))
|
|
|
|
revents |= events & (POLLIN | POLLRDNORM);
|
|
|
|
|
|
|
|
s = splhigh();
|
1995-11-09 20:44:36 +00:00
|
|
|
/*
|
|
|
|
* select for exception - card event.
|
|
|
|
*/
|
1997-09-14 03:19:42 +00:00
|
|
|
if (events & POLLRDBAND)
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt == 0 || slt->laststate != slt->state)
|
1997-09-14 03:19:42 +00:00
|
|
|
revents |= POLLRDBAND;
|
|
|
|
|
|
|
|
if (revents == 0)
|
1997-10-26 04:36:24 +00:00
|
|
|
selrecord(p, &slt->selp);
|
1997-09-14 03:19:42 +00:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return (revents);
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* invalid_io_memory - verify that the ISA I/O memory block
|
|
|
|
* is a valid and unallocated address.
|
|
|
|
* A simple check of the range is done, and then a
|
|
|
|
* search of the current devices is done to check for
|
|
|
|
* overlapping regions.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
invalid_io_memory(unsigned long adr, int size)
|
|
|
|
{
|
1997-10-24 15:27:16 +00:00
|
|
|
/* XXX - What's magic about 0xC0000?? */
|
|
|
|
if (adr < 0xC0000 || (adr+size) > IOM_END)
|
1995-08-24 08:56:20 +00:00
|
|
|
return(1);
|
|
|
|
return(0);
|
|
|
|
}
|
1995-11-09 20:44:36 +00:00
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
static struct pccard_device *
|
1995-08-24 08:56:20 +00:00
|
|
|
find_driver(char *name)
|
|
|
|
{
|
1997-10-26 04:36:24 +00:00
|
|
|
struct pccard_device *drv;
|
1995-08-24 08:56:20 +00:00
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
for (drv = drivers; drv; drv = drv->next)
|
|
|
|
if (strcmp(drv->name, name)==0)
|
|
|
|
return(drv);
|
1995-08-24 08:56:20 +00:00
|
|
|
return(0);
|
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
|
|
|
|
static crd_devsw_installed = 0;
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static void
|
|
|
|
crd_drvinit(void *unused)
|
1995-11-29 10:49:16 +00:00
|
|
|
{
|
|
|
|
dev_t dev;
|
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
if (!crd_devsw_installed) {
|
1995-12-08 11:19:42 +00:00
|
|
|
dev = makedev(CDEV_MAJOR, 0);
|
1997-10-26 04:36:24 +00:00
|
|
|
cdevsw_add(&dev, &crd_cdevsw, NULL);
|
1995-11-29 10:49:16 +00:00
|
|
|
crd_devsw_installed = 1;
|
1997-10-23 22:54:47 +00:00
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SYSINIT(crddev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,crd_drvinit,NULL)
|