1995-08-24 08:56:20 +00:00
|
|
|
/*
|
|
|
|
* pccard.c - Interface code for PC-CARD controllers.
|
|
|
|
*
|
|
|
|
* June 1995, Andrew McRae (andrew@mega.com.au)
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*
|
2001-05-25 18:03:07 +00:00
|
|
|
* Copyright (c) 2001 M. Warner Losh. All rights reserved.
|
1995-08-24 08:56:20 +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.
|
1998-01-02 13:35:06 +00:00
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1995-08-24 08:56:20 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-12 04:46:43 +00:00
|
|
|
#define OBSOLETE_IN_6
|
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
#include <sys/param.h>
|
2001-03-26 08:05:20 +00:00
|
|
|
#include <sys/types.h>
|
1995-08-24 08:56:20 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.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>
|
1997-01-13 21:51:13 +00:00
|
|
|
#include <sys/uio.h>
|
1997-09-14 03:19:42 +00:00
|
|
|
#include <sys/poll.h>
|
1999-09-06 06:34:44 +00:00
|
|
|
#include <sys/bus.h>
|
2001-09-13 08:26:55 +00:00
|
|
|
#include <sys/proc.h>
|
1999-09-06 06:34:44 +00:00
|
|
|
#include <machine/bus.h>
|
1995-11-09 20:44:36 +00:00
|
|
|
|
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>
|
1999-09-06 06:34:44 +00:00
|
|
|
#include <pccard/pccard_nbk.h>
|
1995-11-14 20:49:24 +00:00
|
|
|
|
1996-06-25 20:31:01 +00:00
|
|
|
#include <machine/md_var.h>
|
1996-06-05 05:30:09 +00:00
|
|
|
|
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 *);
|
|
|
|
static void disable_slot(struct slot *);
|
2000-02-21 06:52:20 +00:00
|
|
|
static void disable_slot_to(struct slot *);
|
1996-04-23 16:03:08 +00:00
|
|
|
static void power_off_slot(void *);
|
|
|
|
|
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.
|
2001-07-06 05:52:59 +00:00
|
|
|
*
|
|
|
|
* Now that we have different bus attachments, we should really
|
|
|
|
* use a better algorythm to allocate memory.
|
1995-08-24 08:56:20 +00:00
|
|
|
*/
|
|
|
|
static unsigned long pccard_mem; /* Physical memory */
|
|
|
|
static unsigned char *pccard_kmem; /* Kernel virtual address */
|
2001-03-26 08:05:20 +00:00
|
|
|
static struct resource *pccard_mem_res;
|
|
|
|
static int pccard_mem_rid;
|
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
|
|
|
|
2003-02-28 05:56:06 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
1995-12-08 11:19:42 +00:00
|
|
|
#define CDEV_MAJOR 50
|
2003-02-28 05:56:06 +00:00
|
|
|
#else
|
|
|
|
#define CDEV_MAJOR MAJOR_AUTO
|
|
|
|
#endif
|
1999-05-30 16:53:49 +00:00
|
|
|
static struct cdevsw crd_cdevsw = {
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = crdopen,
|
|
|
|
.d_close = crdclose,
|
|
|
|
.d_read = crdread,
|
|
|
|
.d_write = crdwrite,
|
|
|
|
.d_ioctl = crdioctl,
|
|
|
|
.d_poll = crdpoll,
|
|
|
|
.d_name = "crd",
|
|
|
|
.d_maj = CDEV_MAJOR,
|
1999-05-30 16:53:49 +00:00
|
|
|
};
|
1995-12-08 11:19:42 +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;
|
1999-10-25 02:41:58 +00:00
|
|
|
int s;
|
1996-04-23 16:03:08 +00:00
|
|
|
|
2000-04-25 06:07:27 +00:00
|
|
|
/*
|
1999-10-25 02:41:58 +00:00
|
|
|
* The following will generate an interrupt. So, to hold off
|
|
|
|
* the interrupt unitl after disable runs so that we can get rid
|
2000-04-25 06:07:27 +00:00
|
|
|
* rid of the interrupt before it becomes unsafe to touch the
|
1999-10-25 02:41:58 +00:00
|
|
|
* device.
|
2001-07-09 16:06:06 +00:00
|
|
|
*
|
|
|
|
* XXX In current, the spl stuff is a nop.
|
1999-10-25 02:41:58 +00:00
|
|
|
*/
|
|
|
|
s = splhigh();
|
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);
|
1999-10-25 02:41:58 +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
|
|
|
{
|
1999-09-06 06:34:44 +00:00
|
|
|
device_t pccarddev;
|
1999-12-01 07:38:54 +00:00
|
|
|
device_t *kids;
|
|
|
|
int nkids;
|
1995-11-09 20:44:36 +00:00
|
|
|
int i;
|
1999-12-01 07:38:54 +00:00
|
|
|
int ret;
|
1999-09-06 06:34:44 +00:00
|
|
|
|
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...
|
|
|
|
*/
|
2001-05-14 06:04:29 +00:00
|
|
|
pccarddev = slt->dev;
|
1999-12-01 07:38:54 +00:00
|
|
|
device_get_children(pccarddev, &kids, &nkids);
|
|
|
|
for (i = 0; i < nkids; i++) {
|
|
|
|
if ((ret = device_delete_child(pccarddev, kids[i])) != 0)
|
1999-12-02 19:51:34 +00:00
|
|
|
printf("pccard: delete of %s failed: %d\n",
|
|
|
|
device_get_nameunit(kids[i]), ret);
|
1999-12-01 07:38:54 +00:00
|
|
|
}
|
1999-12-02 19:51:34 +00:00
|
|
|
free(kids, M_TEMP);
|
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-08-24 08:56:20 +00:00
|
|
|
}
|
|
|
|
|
1999-12-01 07:38:54 +00:00
|
|
|
static void
|
2000-02-21 06:52:20 +00:00
|
|
|
disable_slot_to(struct slot *slt)
|
1999-12-01 07:38:54 +00:00
|
|
|
{
|
2000-01-13 06:32:33 +00:00
|
|
|
disable_slot(slt);
|
2001-07-27 07:21:42 +00:00
|
|
|
if (slt->state == empty)
|
|
|
|
printf("pccard: card removed, slot %d\n", slt->slotnum);
|
|
|
|
else
|
|
|
|
printf("pccard: card deactivated, slot %d\n", slt->slotnum);
|
1999-12-01 07:38:54 +00:00
|
|
|
pccard_remove_beep();
|
|
|
|
selwakeup(&slt->selp);
|
|
|
|
}
|
|
|
|
|
1995-08-24 08:56:20 +00:00
|
|
|
/*
|
2001-05-13 01:44:27 +00:00
|
|
|
* pccard_init_slot - Initialize the slot controller and attach various
|
|
|
|
* things to it. We also make the device for it. We create the device that
|
|
|
|
* will be exported to devfs.
|
1995-08-24 08:56:20 +00:00
|
|
|
*/
|
|
|
|
struct slot *
|
2001-05-13 01:44:27 +00:00
|
|
|
pccard_init_slot(device_t dev, struct slot_ctrl *ctrl)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
2001-05-13 01:44:27 +00:00
|
|
|
int slotno;
|
|
|
|
struct slot *slt;
|
|
|
|
|
|
|
|
slt = PCCARD_DEVICE2SOFTC(dev);
|
|
|
|
slotno = device_get_unit(dev);
|
|
|
|
slt->dev = dev;
|
|
|
|
slt->d = make_dev(&crd_cdevsw, slotno, 0, 0, 0600, "card%d", slotno);
|
|
|
|
slt->d->si_drv1 = slt;
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->ctrl = ctrl;
|
|
|
|
slt->slotnum = slotno;
|
1997-10-26 02:55:31 +00:00
|
|
|
callout_handle_init(&slt->insert_ch);
|
|
|
|
callout_handle_init(&slt->poff_ch);
|
2001-05-13 01:44:27 +00:00
|
|
|
|
2001-05-14 06:15: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
|
|
|
/*
|
|
|
|
* 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;
|
1999-09-06 06:34:44 +00:00
|
|
|
device_t pccarddev;
|
1999-10-15 17:29:21 +00:00
|
|
|
int err, irq = 0;
|
1999-10-25 02:41:58 +00:00
|
|
|
device_t child;
|
2001-09-13 08:26:55 +00:00
|
|
|
device_t *devs;
|
|
|
|
int count;
|
1995-08-24 08:56:20 +00:00
|
|
|
|
2001-05-14 06:04:29 +00:00
|
|
|
pccarddev = slt->dev;
|
2001-09-13 08:26:55 +00:00
|
|
|
err = device_get_children(pccarddev, &devs, &count);
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
free(devs, M_TEMP);
|
|
|
|
if (count) {
|
|
|
|
device_printf(pccarddev,
|
|
|
|
"Can not attach more than one child.\n");
|
|
|
|
return (EIO);
|
|
|
|
}
|
1999-10-25 02:41:58 +00:00
|
|
|
irq = ffs(desc->irqmask) - 1;
|
2000-10-29 16:29:05 +00:00
|
|
|
MALLOC(devi, struct pccard_devinfo *, sizeof(*devi), M_DEVBUF,
|
2003-02-19 05:47:46 +00:00
|
|
|
M_WAITOK | M_ZERO);
|
1999-10-25 02:41:58 +00:00
|
|
|
strcpy(devi->name, desc->name);
|
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->slt = slt;
|
|
|
|
bcopy(desc->misc, devi->misc, sizeof(desc->misc));
|
2002-07-22 06:46:10 +00:00
|
|
|
strcpy(devi->manufstr, desc->manufstr);
|
|
|
|
strcpy(devi->versstr, desc->versstr);
|
2003-04-23 23:39:21 +00:00
|
|
|
strcpy(devi->cis3str, desc->cis3str);
|
|
|
|
strcpy(devi->cis4str, desc->cis4str);
|
2002-02-20 14:42:36 +00:00
|
|
|
devi->manufacturer = desc->manufacturer;
|
|
|
|
devi->product = desc->product;
|
|
|
|
devi->prodext = desc->prodext;
|
1999-10-25 02:41:58 +00:00
|
|
|
resource_list_init(&devi->resources);
|
1999-12-08 07:55:20 +00:00
|
|
|
child = device_add_child(pccarddev, devi->name, desc->unit);
|
2001-11-02 17:31:01 +00:00
|
|
|
if (child == NULL) {
|
2001-11-02 21:26:07 +00:00
|
|
|
if (desc->unit != -1)
|
|
|
|
device_printf(pccarddev,
|
|
|
|
"Unit %d failed for %s, try a different unit\n",
|
|
|
|
desc->unit, devi->name);
|
|
|
|
else
|
|
|
|
device_printf(pccarddev,
|
|
|
|
"No units available for %s. Impossible?\n",
|
|
|
|
devi->name);
|
2001-11-02 17:31:01 +00:00
|
|
|
return (EIO);
|
|
|
|
}
|
1999-10-25 23:17:24 +00:00
|
|
|
device_set_flags(child, desc->flags);
|
1999-12-03 08:41:24 +00:00
|
|
|
device_set_ivars(child, devi);
|
2001-07-30 00:03:58 +00:00
|
|
|
if (bootverbose) {
|
2002-09-13 16:23:41 +00:00
|
|
|
device_printf(pccarddev, "Assigning %s:",
|
|
|
|
device_get_nameunit(child));
|
|
|
|
if (desc->iobase)
|
|
|
|
printf(" io 0x%x-0x%x",
|
|
|
|
desc->iobase, desc->iobase + desc->iosize - 1);
|
|
|
|
if (irq)
|
|
|
|
printf(" irq %d", irq);
|
|
|
|
if (desc->mem)
|
|
|
|
printf(" mem 0x%lx-0x%lx", desc->mem,
|
|
|
|
desc->mem + desc->memsize - 1);
|
|
|
|
printf(" flags 0x%x\n", desc->flags);
|
2001-07-30 00:03:58 +00:00
|
|
|
}
|
1999-10-25 23:17:24 +00:00
|
|
|
err = bus_set_resource(child, SYS_RES_IOPORT, 0, desc->iobase,
|
|
|
|
desc->iosize);
|
|
|
|
if (err)
|
|
|
|
goto err;
|
|
|
|
if (irq)
|
|
|
|
err = bus_set_resource(child, SYS_RES_IRQ, 0, irq, 1);
|
2000-04-25 06:07:27 +00:00
|
|
|
if (err)
|
1999-10-25 23:17:24 +00:00
|
|
|
goto err;
|
|
|
|
if (desc->memsize) {
|
2000-04-25 06:07:27 +00:00
|
|
|
err = bus_set_resource(child, SYS_RES_MEMORY, 0, desc->mem,
|
1999-10-25 23:17:24 +00:00
|
|
|
desc->memsize);
|
2000-04-25 06:07:27 +00:00
|
|
|
if (err)
|
1999-10-25 23:17:24 +00:00
|
|
|
goto err;
|
|
|
|
}
|
1999-10-25 02:41:58 +00:00
|
|
|
err = device_probe_and_attach(child);
|
2000-10-26 19:45:42 +00:00
|
|
|
/*
|
|
|
|
* XXX We unwisely assume that the detach code won't run while the
|
|
|
|
* XXX the attach code is attaching. Someone should put some
|
|
|
|
* XXX interlock code. This can happen if probe/attach takes a while
|
|
|
|
* XXX and the user ejects the card, which causes the detach
|
|
|
|
* XXX function to be called.
|
|
|
|
*/
|
|
|
|
strncpy(desc->name, device_get_nameunit(child), sizeof(desc->name));
|
|
|
|
desc->name[sizeof(desc->name) - 1] = '\0';
|
1999-10-25 23:17:24 +00:00
|
|
|
err:
|
1999-10-25 02:41:58 +00:00
|
|
|
if (err)
|
|
|
|
device_delete_child(pccarddev, child);
|
1999-10-25 23:17:24 +00:00
|
|
|
return (err);
|
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;
|
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);
|
2002-06-23 01:55:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable 5V to the card so that the CIS can be read. Well,
|
|
|
|
* enable the most natural voltage so that the CIS can be read.
|
|
|
|
*/
|
|
|
|
slt->pwr.vcc = -1;
|
|
|
|
slt->pwr.vpp = -1;
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->ctrl->power(slt);
|
1997-10-23 22:54:47 +00:00
|
|
|
|
1999-09-06 06:34:44 +00:00
|
|
|
printf("pccard: card inserted, slot %d\n", slt->slotnum);
|
2001-03-20 18:10:19 +00:00
|
|
|
pccard_insert_beep();
|
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:
|
2001-07-27 07:21:42 +00:00
|
|
|
case card_deactivated:
|
2000-08-20 16:16:57 +00:00
|
|
|
if (slt->state == filled || slt->state == inactive) {
|
2001-07-27 07:21:42 +00:00
|
|
|
if (event == card_removed)
|
|
|
|
slt->state = empty;
|
|
|
|
else
|
|
|
|
slt->state = inactive;
|
2000-02-21 06:52:20 +00:00
|
|
|
disable_slot_to(slt);
|
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);
|
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
|
|
|
|
1996-06-05 05:30:09 +00:00
|
|
|
/*
|
|
|
|
* Device driver interface.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
2001-11-12 05:35:27 +00:00
|
|
|
crdopen(dev_t dev, int oflags, int devtype, d_thread_t *td)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
2001-05-13 01:44:27 +00:00
|
|
|
struct slot *slt = PCCARD_DEV2SOFTC(dev);
|
1995-08-24 08:56:20 +00:00
|
|
|
|
2001-05-13 01:44:27 +00:00
|
|
|
if (slt == NULL)
|
2001-05-14 06:15:24 +00:00
|
|
|
return (ENXIO);
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt->rwmem == 0)
|
|
|
|
slt->rwmem = MDF_ATTR;
|
2001-05-14 06:15:24 +00:00
|
|
|
return (0);
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
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
|
2001-11-12 05:35:27 +00:00
|
|
|
crdclose(dev_t dev, int fflag, int devtype, d_thread_t *td)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
2001-05-14 06:15:24 +00:00
|
|
|
return (0);
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2001-05-13 01:44:27 +00:00
|
|
|
struct slot *slt = PCCARD_DEV2SOFTC(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)
|
2001-05-14 06:15:24 +00:00
|
|
|
return (ENXIO);
|
1995-08-24 08:56:20 +00:00
|
|
|
if (pccard_mem == 0)
|
2001-05-14 06:15:24 +00:00
|
|
|
return (ENOMEM);
|
2002-09-08 22:18:06 +00:00
|
|
|
for (win = slt->ctrl->maxmem - 1; win >= 0; win--)
|
1997-10-26 04:36:24 +00:00
|
|
|
if ((slt->mem[win].flags & MDF_ACTIVE) == 0)
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
2002-09-08 22:18:06 +00:00
|
|
|
if (win < 0)
|
2001-05-14 06:15:24 +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;
|
2001-07-01 23:40:19 +00:00
|
|
|
mp->flags = slt->rwmem | MDF_ACTIVE;
|
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;
|
1999-01-27 23:45:44 +00:00
|
|
|
if ((error = slt->ctrl->mapmem(slt, win)) != 0)
|
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
|
|
|
|
2001-05-14 06:15:24 +00:00
|
|
|
return (error);
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2001-05-13 01:44:27 +00:00
|
|
|
struct slot *slt = PCCARD_DEV2SOFTC(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)
|
2001-05-14 06:15:24 +00:00
|
|
|
return (ENXIO);
|
1995-08-24 08:56:20 +00:00
|
|
|
if (pccard_mem == 0)
|
2001-05-14 06:15:24 +00:00
|
|
|
return (ENOMEM);
|
2002-09-08 22:18:06 +00:00
|
|
|
for (win = slt->ctrl->maxmem - 1; win >= 0; win--)
|
1999-10-25 02:41:58 +00:00
|
|
|
if ((slt->mem[win].flags & MDF_ACTIVE) == 0)
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
2002-09-08 22:18:06 +00:00
|
|
|
if (win < 0)
|
2001-05-14 06:15:24 +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;
|
2001-06-04 03:13:45 +00:00
|
|
|
mp->flags = slt->rwmem | MDF_ACTIVE;
|
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;
|
1999-01-27 23:45:44 +00:00
|
|
|
if ((error = slt->ctrl->mapmem(slt, win)) != 0)
|
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
|
|
|
|
2001-05-14 06:15:24 +00:00
|
|
|
return (error);
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
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
|
2001-11-12 05:35:27 +00:00
|
|
|
crdioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, d_thread_t *td)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
2001-05-14 06:04:29 +00:00
|
|
|
u_int32_t addr;
|
|
|
|
int err;
|
|
|
|
struct io_desc *ip;
|
1995-11-09 20:44:36 +00:00
|
|
|
struct mem_desc *mp;
|
2001-05-14 06:04:29 +00:00
|
|
|
device_t pccarddev;
|
|
|
|
int pwval;
|
|
|
|
int s;
|
|
|
|
struct slot *slt = PCCARD_DEV2SOFTC(dev);
|
2003-04-23 23:39:21 +00:00
|
|
|
/*XXX*/#if __FreeBSD_version < 5000000 /* 4.x compatibility only. */
|
|
|
|
struct dev_desc d;
|
|
|
|
struct dev_desc_old *odp;
|
|
|
|
/*XXX*/#endif
|
1995-08-24 08:56:20 +00:00
|
|
|
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt == 0 && cmd != PIOCRWMEM)
|
2001-05-14 06:15:24 +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)
|
2001-05-14 06:15:24 +00:00
|
|
|
return (slt->ctrl->ioctl(slt, cmd, data));
|
|
|
|
return (ENOTTY);
|
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;
|
1999-10-25 02:41:58 +00:00
|
|
|
((struct slotstate *)data)->irqs = 0;
|
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)
|
2001-05-14 06:15:24 +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:
|
2002-04-01 21:31:13 +00:00
|
|
|
if (suser(td))
|
2001-05-14 06:15:24 +00:00
|
|
|
return (EPERM);
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt->state != filled)
|
2001-05-14 06:15:24 +00:00
|
|
|
return (ENXIO);
|
1995-08-24 08:56:20 +00:00
|
|
|
s = ((struct mem_desc *)data)->window;
|
1997-10-26 04:36:24 +00:00
|
|
|
if (s < 0 || s >= slt->ctrl->maxmem)
|
2001-05-14 06:15:24 +00:00
|
|
|
return (EINVAL);
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->mem[s] = *((struct mem_desc *)data);
|
2001-05-14 06:15:24 +00:00
|
|
|
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)
|
2001-05-14 06:15:24 +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:
|
2002-04-01 21:31:13 +00:00
|
|
|
if (suser(td))
|
2001-05-14 06:15:24 +00:00
|
|
|
return (EPERM);
|
1997-10-26 04:36:24 +00:00
|
|
|
if (slt->state != filled)
|
2001-05-14 06:15:24 +00:00
|
|
|
return (ENXIO);
|
1995-08-24 08:56:20 +00:00
|
|
|
s = ((struct io_desc *)data)->window;
|
1997-10-26 04:36:24 +00:00
|
|
|
if (s < 0 || s >= slt->ctrl->maxio)
|
2001-05-14 06:15:24 +00:00
|
|
|
return (EINVAL);
|
1997-10-26 04:36:24 +00:00
|
|
|
slt->io[s] = *((struct io_desc *)data);
|
1999-10-25 02:41:58 +00:00
|
|
|
/* XXX Don't actually map */
|
2001-05-14 06:15:24 +00:00
|
|
|
return (0);
|
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) {
|
2001-03-26 08:05:20 +00:00
|
|
|
*(unsigned long *)data = pccard_mem;
|
1995-08-24 08:56:20 +00:00
|
|
|
break;
|
1995-11-09 20:44:36 +00:00
|
|
|
}
|
2002-04-01 21:31:13 +00:00
|
|
|
if (suser(td))
|
2001-05-14 06:15:24 +00:00
|
|
|
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 (*(unsigned long *)data & (PCCARD_MEMSIZE-1))
|
2001-05-14 06:15:24 +00:00
|
|
|
return (EINVAL);
|
2001-05-14 06:04:29 +00:00
|
|
|
pccarddev = PCCARD_DEV2SOFTC(dev)->dev;
|
2001-03-26 08:05:20 +00:00
|
|
|
pccard_mem_rid = 0;
|
|
|
|
addr = *(unsigned long *)data;
|
|
|
|
if (pccard_mem_res)
|
2001-05-14 06:04:29 +00:00
|
|
|
bus_release_resource(pccarddev, SYS_RES_MEMORY,
|
2001-03-26 08:05:20 +00:00
|
|
|
pccard_mem_rid, pccard_mem_res);
|
2001-05-14 06:04:29 +00:00
|
|
|
pccard_mem_res = bus_alloc_resource(pccarddev, SYS_RES_MEMORY,
|
2001-03-26 08:05:20 +00:00
|
|
|
&pccard_mem_rid, addr, addr, PCCARD_MEMSIZE,
|
|
|
|
RF_ACTIVE | rman_make_alignment_flags(PCCARD_MEMSIZE));
|
|
|
|
if (pccard_mem_res == NULL)
|
2001-05-14 06:15:24 +00:00
|
|
|
return (EINVAL);
|
2001-03-26 08:05:20 +00:00
|
|
|
pccard_mem = rman_get_start(pccard_mem_res);
|
|
|
|
pccard_kmem = rman_get_virtual(pccard_mem_res);
|
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;
|
2001-05-14 06:15:24 +00:00
|
|
|
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:
|
2002-04-01 21:31:13 +00:00
|
|
|
if (suser(td))
|
2001-05-14 06:15:24 +00:00
|
|
|
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();
|
2001-05-14 06:15:24 +00:00
|
|
|
return (err);
|
2003-04-23 23:39:21 +00:00
|
|
|
/***/#if __FreeBSD_version < 5000000 /* 4.x compatibility only. */
|
|
|
|
case PIOCSDRVOLD:
|
|
|
|
if (suser(td))
|
|
|
|
return (EPERM);
|
|
|
|
odp = (struct dev_desc_old *) data;
|
|
|
|
strlcpy(d.name, odp->name, sizeof(d.name));
|
|
|
|
d.unit = odp->unit;
|
|
|
|
d.mem = odp->mem;
|
|
|
|
d.memsize = odp->memsize;
|
|
|
|
d.iobase = odp->iobase;
|
|
|
|
d.iosize = odp->iosize;
|
|
|
|
d.irqmask = odp->irqmask;
|
|
|
|
d.flags = odp->flags;
|
|
|
|
memcpy(d.misc, odp->misc, sizeof(odp->misc));
|
|
|
|
strlcpy(d.manufstr, odp->manufstr, sizeof(d.manufstr));
|
|
|
|
strlcpy(d.versstr, odp->versstr, sizeof(d.versstr));
|
|
|
|
*d.cis3str = '\0';
|
|
|
|
*d.cis4str = '\0';
|
|
|
|
d.manufacturer = odp->manufacturer;
|
|
|
|
d.product = odp->product;
|
|
|
|
d.prodext = odp->prodext;
|
|
|
|
err = allocate_driver(slt, &d);
|
|
|
|
if (!err)
|
|
|
|
pccard_success_beep();
|
|
|
|
else
|
|
|
|
pccard_failure_beep();
|
|
|
|
return (err);
|
|
|
|
/***/#endif
|
1999-12-02 05:46:22 +00:00
|
|
|
/*
|
|
|
|
* Virtual removal/insertion
|
|
|
|
*/
|
|
|
|
case PIOCSVIR:
|
|
|
|
pwval = *(int *)data;
|
|
|
|
if (!pwval) {
|
|
|
|
if (slt->state != filled)
|
2001-05-14 06:15:24 +00:00
|
|
|
return (EINVAL);
|
2001-07-27 07:21:42 +00:00
|
|
|
pccard_event(slt, card_deactivated);
|
1999-12-02 05:46:22 +00:00
|
|
|
} else {
|
2000-08-20 16:16:57 +00:00
|
|
|
if (slt->state != empty && slt->state != inactive)
|
2001-05-14 06:15:24 +00:00
|
|
|
return (EINVAL);
|
2000-08-20 16:16:57 +00:00
|
|
|
pccard_event(slt, card_inserted);
|
1999-12-02 05:46:22 +00:00
|
|
|
}
|
|
|
|
break;
|
1999-02-13 11:32:00 +00:00
|
|
|
case PIOCSBEEP:
|
|
|
|
if (pccard_beep_select(*(int *)data)) {
|
2001-05-14 06:15:24 +00:00
|
|
|
return (EINVAL);
|
1999-02-13 11:32:00 +00:00
|
|
|
}
|
|
|
|
break;
|
1997-10-23 22:54:47 +00:00
|
|
|
}
|
2001-05-14 06:15:24 +00:00
|
|
|
return (0);
|
1995-08-24 08:56:20 +00:00
|
|
|
}
|
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
|
2001-11-12 05:35:27 +00:00
|
|
|
crdpoll(dev_t dev, int events, d_thread_t *td)
|
1995-08-24 08:56:20 +00:00
|
|
|
{
|
2001-05-13 01:44:27 +00:00
|
|
|
int revents = 0;
|
|
|
|
int s;
|
|
|
|
struct slot *slt = PCCARD_DEV2SOFTC(dev);
|
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)
|
2001-09-12 08:38:13 +00:00
|
|
|
selrecord(td, &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
|
|
|
|
1999-12-08 07:55:20 +00:00
|
|
|
/*
|
|
|
|
* APM hooks for suspending and resuming.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
pccard_suspend(device_t dev)
|
|
|
|
{
|
2001-05-13 01:44:27 +00:00
|
|
|
struct slot *slt = PCCARD_DEVICE2SOFTC(dev);
|
1999-12-08 07:55:20 +00:00
|
|
|
|
|
|
|
/* This code stolen from pccard_event:card_removed */
|
|
|
|
if (slt->state == filled) {
|
2001-07-27 07:21:42 +00:00
|
|
|
int s = splhigh(); /* nop on current */
|
1999-12-08 07:55:20 +00:00
|
|
|
disable_slot(slt);
|
2001-07-27 07:21:42 +00:00
|
|
|
slt->laststate = suspend; /* for pccardd */
|
|
|
|
slt->state = empty;
|
1999-12-08 07:55:20 +00:00
|
|
|
splx(s);
|
|
|
|
printf("pccard: card disabled, slot %d\n", slt->slotnum);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
slt->ctrl->disable(slt);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pccard_resume(device_t dev)
|
|
|
|
{
|
2001-05-13 01:44:27 +00:00
|
|
|
struct slot *slt = PCCARD_DEVICE2SOFTC(dev);
|
1999-12-08 07:55:20 +00:00
|
|
|
|
2001-07-27 07:21:42 +00:00
|
|
|
slt->ctrl->resume(slt);
|
2001-07-27 07:47:35 +00:00
|
|
|
return (0);
|
1999-12-08 07:55:20 +00:00
|
|
|
}
|