summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys/pccard/pccard.c62
-rw-r--r--sys/pccard/pccard_nbk.c18
-rw-r--r--sys/pccard/pcic.c115
-rw-r--r--sys/pccard/slot.h7
4 files changed, 100 insertions, 102 deletions
diff --git a/sys/pccard/pccard.c b/sys/pccard/pccard.c
index f5f15bf..c317b02 100644
--- a/sys/pccard/pccard.c
+++ b/sys/pccard/pccard.c
@@ -68,8 +68,6 @@ static void disable_slot(struct slot *);
static void disable_slot_to(struct slot *);
static void power_off_slot(void *);
-static struct slot *pccard_slots[MAXSLOT]; /* slot entries */
-
/*
* The driver interface for read/write uses a block
* of memory in the ISA I/O memory space allocated via
@@ -172,31 +170,26 @@ disable_slot_to(struct slot *slt)
}
/*
- * 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.
+ * 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.
*/
struct slot *
-pccard_alloc_slot(struct slot_ctrl *ctrl)
+pccard_init_slot(device_t dev, struct slot_ctrl *ctrl)
{
- struct slot *slt;
- int slotno;
-
- for (slotno = 0; slotno < MAXSLOT; slotno++)
- if (pccard_slots[slotno] == 0)
- break;
- if (slotno == MAXSLOT)
- return(0);
-
- MALLOC(slt, struct slot *, sizeof(*slt), M_DEVBUF, M_WAITOK | M_ZERO);
- make_dev(&crd_cdevsw, slotno, 0, 0, 0600, "card%d", slotno);
+ 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;
slt->ctrl = ctrl;
slt->slotnum = slotno;
- pccard_slots[slotno] = slt;
callout_handle_init(&slt->insert_ch);
callout_handle_init(&slt->poff_ch);
+
return(slt);
}
@@ -326,12 +319,9 @@ pccard_event(struct slot *slt, enum card_event event)
static int
crdopen(dev_t dev, int oflags, int devtype, struct proc *p)
{
- struct slot *slt;
+ struct slot *slt = PCCARD_DEV2SOFTC(dev);
- if (minor(dev) >= MAXSLOT)
- return(ENXIO);
- slt = pccard_slots[minor(dev)];
- if (slt == 0)
+ if (slt == NULL)
return(ENXIO);
if (slt->rwmem == 0)
slt->rwmem = MDF_ATTR;
@@ -355,7 +345,7 @@ crdclose(dev_t dev, int fflag, int devtype, struct proc *p)
static int
crdread(dev_t dev, struct uio *uio, int ioflag)
{
- struct slot *slt = pccard_slots[minor(dev)];
+ struct slot *slt = PCCARD_DEV2SOFTC(dev);
struct mem_desc *mp, oldmap;
unsigned char *p;
unsigned int offs;
@@ -401,7 +391,7 @@ crdread(dev_t dev, struct uio *uio, int ioflag)
static int
crdwrite(dev_t dev, struct uio *uio, int ioflag)
{
- struct slot *slt = pccard_slots[minor(dev)];
+ struct slot *slt = PCCARD_DEV2SOFTC(dev);
struct mem_desc *mp, oldmap;
unsigned char *p;
unsigned int offs;
@@ -489,7 +479,7 @@ crdioctl_sresource(dev_t dev, caddr_t data)
static int
crdioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct proc *p)
{
- struct slot *slt = pccard_slots[minor(dev)];
+ struct slot *slt = PCCARD_DEV2SOFTC(dev);
struct mem_desc *mp;
struct io_desc *ip;
device_t pcicdev;
@@ -662,9 +652,9 @@ crdioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct proc *p)
static int
crdpoll(dev_t dev, int events, struct proc *p)
{
- int s;
- struct slot *slt = pccard_slots[minor(dev)];
- int revents = 0;
+ int revents = 0;
+ int s;
+ struct slot *slt = PCCARD_DEV2SOFTC(dev);
if (events & (POLLIN | POLLRDNORM))
revents |= events & (POLLIN | POLLRDNORM);
@@ -687,19 +677,13 @@ crdpoll(dev_t dev, int events, struct proc *p)
return (revents);
}
-static struct slot *
-pccard_dev2slot(device_t dev)
-{
- return pccard_slots[device_get_unit(dev)];
-}
-
/*
* APM hooks for suspending and resuming.
*/
int
pccard_suspend(device_t dev)
{
- struct slot *slt = pccard_dev2slot(dev);
+ struct slot *slt = PCCARD_DEVICE2SOFTC(dev);
/* This code stolen from pccard_event:card_removed */
if (slt->state == filled) {
@@ -722,7 +706,7 @@ pccard_suspend(device_t dev)
int
pccard_resume(device_t dev)
{
- struct slot *slt = pccard_dev2slot(dev);
+ struct slot *slt = PCCARD_DEVICE2SOFTC(dev);
if (pcic_resume_reset)
slt->ctrl->resume(slt);
diff --git a/sys/pccard/pccard_nbk.c b/sys/pccard/pccard_nbk.c
index 34333d0..6155d86 100644
--- a/sys/pccard/pccard_nbk.c
+++ b/sys/pccard/pccard_nbk.c
@@ -108,8 +108,14 @@ pccard_compat_do_attach(device_t bus, device_t dev)
static int
pccard_probe(device_t dev)
{
- device_set_desc(dev, "PC Card bus -- kludge version");
- return 0;
+ device_set_desc(dev, "PC Card bus (classic)");
+ return (0);
+}
+
+static int
+pccard_attach(device_t dev)
+{
+ return (0);
}
static void
@@ -362,7 +368,7 @@ pccard_product_lookup(device_t dev, const struct pccard_product *tab,
static device_method_t pccard_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, pccard_probe),
- DEVMETHOD(device_attach, bus_generic_attach),
+ DEVMETHOD(device_attach, pccard_attach),
DEVMETHOD(device_shutdown, bus_generic_shutdown),
DEVMETHOD(device_suspend, pccard_suspend),
DEVMETHOD(device_resume, pccard_resume),
@@ -398,10 +404,10 @@ static device_method_t pccard_methods[] = {
static driver_t pccard_driver = {
"pccard",
pccard_methods,
- 1, /* no softc */
+ sizeof(struct slot)
};
DRIVER_MODULE(pccard, pcic, pccard_driver, pccard_devclass, 0, 0);
-DRIVER_MODULE(pccard, pc98pcic, pccard_driver, pccard_devclass, 0, 0);
-DRIVER_MODULE(pccard, cbb, pccard_driver, pccard_devclass, 0, 0);
+DRIVER_MODULE(pccard, mecia, pccard_driver, pccard_devclass, 0, 0);
+DRIVER_MODULE(pccard, tcic, pccard_driver, pccard_devclass, 0, 0);
MODULE_VERSION(pccard, 1);
diff --git a/sys/pccard/pcic.c b/sys/pccard/pcic.c
index 7453b38..20c6bf4 100644
--- a/sys/pccard/pcic.c
+++ b/sys/pccard/pcic.c
@@ -128,26 +128,23 @@ static char *bridges[] =
"Vadem 469",
"Ricoh RF5C396",
"IBM KING PCMCIA Controller",
- "PC-98 Original"
+ "PC-98 MECIA Controller"
};
/*
- * Internal inline functions for accessing the PCIC.
- */
-/*
* Read a register from the PCIC.
*/
-static __inline unsigned char
+static unsigned char
getb1(struct pcic_slot *sp, int reg)
{
outb(sp->index, sp->offset + reg);
- return inb(sp->data);
+ return (inb(sp->data));
}
/*
* Write a register on the PCIC
*/
-static __inline void
+static void
putb1(struct pcic_slot *sp, int reg, unsigned char val)
{
outb(sp->index, sp->offset + reg);
@@ -232,7 +229,7 @@ pcic_memory(struct slot *slt, int win)
putw(sp, reg+2, 0);
putw(sp, reg+4, 0);
}
- return(0);
+ return (0);
}
/*
@@ -300,7 +297,7 @@ pcic_io(struct slot *slt, int win)
putw(sp, reg, 0);
putw(sp, reg + 2, 0);
}
- return(0);
+ return (0);
}
/*
@@ -317,7 +314,6 @@ static int
pcic_probe(device_t dev)
{
int slotnum, validslots = 0;
- struct slot *slt;
struct pcic_slot *sp;
unsigned char c;
int error;
@@ -351,7 +347,7 @@ pcic_probe(device_t dev)
if (!r) {
if (bootverbose)
device_printf(dev, "Cannot get I/O range\n");
- return ENOMEM;
+ return (ENOMEM);
}
sp = &pcic_slots[validunits * PCIC_CARD_SLOTS];
@@ -467,11 +463,7 @@ pcic_probe(device_t dev)
*/
validslots++;
sp->slotnum = slotnum + validunits * PCIC_CARD_SLOTS;
- slt = pccard_alloc_slot(&cinfo);
- if (slt == 0)
- continue;
- slt->cdata = sp;
- sp->slt = slt;
+ sp->slt = (struct slot *) 1;
/*
* Modem cards send the speaker audio (dialing noises)
* to the host's speaker. Cirrus Logic PCIC chips must
@@ -506,14 +498,12 @@ pcic_probe(device_t dev)
cinfo.maxio = 2; /* fake for UE2212 LAN card */
#endif
validslots++;
- slt = pccard_alloc_slot(&cinfo);
- slt->cdata = sp;
- sp->slt = slt;
+ sp->slt = (struct slot *) 1;
/* XXX need to allocated the port resources */
device_set_desc(dev, "MECIA PC98 Original PCMCIA Controller");
}
#endif /* PC98 */
- return(validslots ? 0 : ENXIO);
+ return (validslots ? 0 : ENXIO);
}
static void
@@ -527,28 +517,43 @@ do_mgt_irq(struct pcic_slot *sp, int irq)
static int
pcic_attach(device_t dev)
{
- void *ih;
- int rid;
+ int error;
+ int irq;
+ int i;
+ void *ih;
+ device_t kid;
struct resource *r;
- int irq;
- int error;
+ int rid;
+ struct slot *slt;
struct pcic_slot *sp;
- int i;
- int stat;
+ int stat;
SET_UNIT(dev, validunits);
sp = &pcic_slots[GET_UNIT(dev) * PCIC_CARD_SLOTS];
for (i = 0; i < PCIC_CARD_SLOTS; i++, sp++) {
- if (sp->slt)
- device_add_child(dev, NULL, -1);
+ if (!sp->slt)
+ continue;
+ sp->slt = 0;
+ kid = device_add_child(dev, NULL, -1);
+ if (kid == NULL) {
+ device_printf(dev, "Can't add pccard bus slot %d", i);
+ return (ENXIO);
+ }
+ device_probe_and_attach(kid);
+ slt = pccard_init_slot(kid, &cinfo);
+ if (slt == 0) {
+ device_printf(dev, "Can't get pccard info slot %d", i);
+ return (ENXIO);
+ }
+ slt->cdata = sp;
+ sp->slt = slt;
}
validunits++;
rid = 0;
r = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
- if (!r) {
- return ENXIO;
- }
+ if (!r)
+ return (ENXIO);
irq = bus_get_resource_start(dev, SYS_RES_IRQ, 0);
if (irq == 0) {
@@ -575,7 +580,7 @@ pcic_attach(device_t dev)
pcicintr, (void *) GET_UNIT(dev), &ih);
if (error) {
bus_release_resource(dev, SYS_RES_IRQ, rid, r);
- return error;
+ return (error);
}
irq = rman_get_start(r);
device_printf(dev, "management irq %d\n", irq);
@@ -636,7 +641,7 @@ pcic_ioctl(struct slot *slt, int cmd, caddr_t data)
switch(cmd) {
default:
- return(ENOTTY);
+ return (ENOTTY);
/*
* Get/set PCIC registers
*/
@@ -649,7 +654,7 @@ pcic_ioctl(struct slot *slt, int cmd, caddr_t data)
((struct pcic_reg *)data)->value);
break;
}
- return(0);
+ return (0);
}
/*
@@ -675,7 +680,7 @@ pcic_power(struct slot *slt)
case PCIC_I82365:
switch(slt->pwr.vpp) {
default:
- return(EINVAL);
+ return (EINVAL);
case 0:
break;
case 50:
@@ -688,7 +693,7 @@ pcic_power(struct slot *slt)
}
switch(slt->pwr.vcc) {
default:
- return(EINVAL);
+ return (EINVAL);
case 0:
break;
case 33:
@@ -737,7 +742,7 @@ pcic_power(struct slot *slt)
slt->pwr.vpp = 0;
return (pcic_power(slt));
}
- return(0);
+ return (0);
}
/*
@@ -911,7 +916,7 @@ pcic98_memory(struct slot *slt, int win)
printf(
"sys_addr must be 0xda000. requested address = %p\n",
mp->start);
- return(EINVAL);
+ return (EINVAL);
}
/* omajinai ??? */
@@ -953,7 +958,7 @@ pcic98_memory(struct slot *slt, int win)
outw(PCIC98_REG_PAGOFS, reg_pagofs);
#endif
}
- return 0;
+ return (0);
}
static int
@@ -968,8 +973,8 @@ pcic98_io(struct slot *slt, int win)
/* ignore for UE2212 */
printf(
"pcic98:Illegal PCIC I/O window(%d) request! Ignored.\n", win);
-/* return(EINVAL);*/
- return 0;
+/* return (EINVAL);*/
+ return (0);
}
if (ip->flags & IODF_ACTIVE) {
@@ -1017,7 +1022,7 @@ pcic98_io(struct slot *slt, int win)
outb(PCIC98_REG2, inb(PCIC98_REG2) & (~PCIC98_MAPIO));
pcic98_mode = 0;
}
- return 0;
+ return (0);
}
static int
@@ -1028,7 +1033,7 @@ pcic98_power(struct slot *slt)
reg = inb(PCIC98_REG7) & (~PCIC98_VPP12V);
switch(slt->pwr.vpp) {
default:
- return(EINVAL);
+ return (EINVAL);
case 50:
break;
case 120:
@@ -1041,7 +1046,7 @@ pcic98_power(struct slot *slt)
reg = inb(PCIC98_REG2) & (~PCIC98_VCC3P3V);
switch(slt->pwr.vcc) {
default:
- return(EINVAL);
+ return (EINVAL);
case 33:
reg |= PCIC98_VCC3P3V;
break;
@@ -1050,7 +1055,7 @@ pcic98_power(struct slot *slt)
}
outb(PCIC98_REG2, reg);
DELAY(100*1000);
- return 0;
+ return (0);
}
static void
@@ -1141,7 +1146,7 @@ pcic_activate_resource(device_t dev, device_t child, int type, int rid,
ip->size = rman_get_end(r) - rman_get_start(r) + 1;
err = cinfo.mapio(devi->slt, rid);
if (err)
- return err;
+ return (err);
break;
}
case SYS_RES_IRQ:
@@ -1154,21 +1159,21 @@ pcic_activate_resource(device_t dev, device_t child, int type, int rid,
case SYS_RES_MEMORY: {
struct mem_desc *mp;
if (rid >= NUM_MEM_WINDOWS)
- return EINVAL;
+ return (EINVAL);
mp = &devi->slt->mem[rid];
mp->flags |= MDF_ACTIVE;
mp->start = (caddr_t) rman_get_start(r);
mp->size = rman_get_end(r) - rman_get_start(r) + 1;
err = cinfo.mapmem(devi->slt, rid);
if (err)
- return err;
+ return (err);
break;
}
default:
break;
}
err = bus_generic_activate_resource(dev, child, type, rid, r);
- return err;
+ return (err);
}
static int
@@ -1183,9 +1188,8 @@ pcic_deactivate_resource(device_t dev, device_t child, int type, int rid,
struct io_desc *ip = &devi->slt->io[rid];
ip->flags &= ~IODF_ACTIVE;
err = cinfo.mapio(devi->slt, rid);
- if (err) {
- return err;
- }
+ if (err)
+ return (err);
break;
}
case SYS_RES_IRQ:
@@ -1194,16 +1198,15 @@ pcic_deactivate_resource(device_t dev, device_t child, int type, int rid,
struct mem_desc *mp = &devi->slt->mem[rid];
mp->flags &= ~(MDF_ACTIVE | MDF_ATTR);
err = cinfo.mapmem(devi->slt, rid);
- if (err) {
- return err;
- }
+ if (err)
+ return (err);
break;
}
default:
break;
}
err = bus_generic_deactivate_resource(dev, child, type, rid, r);
- return err;
+ return (err);
}
static int
diff --git a/sys/pccard/slot.h b/sys/pccard/slot.h
index 0b95444..c8034e5 100644
--- a/sys/pccard/slot.h
+++ b/sys/pccard/slot.h
@@ -120,11 +120,16 @@ struct slot {
struct slot_ctrl *ctrl; /* Per-controller data */
void *cdata; /* Controller specific data */
int pwr_off_pending;/* Power status of slot */
+ device_t dev; /* Config system device. */
+ dev_t d; /* fs device */
};
+#define PCCARD_DEVICE2SOFTC(d) ((struct slot *) device_get_softc(d))
+#define PCCARD_DEV2SOFTC(d) ((struct slot *) (d)->si_drv1)
+
enum card_event { card_removed, card_inserted };
-struct slot *pccard_alloc_slot(struct slot_ctrl *);
+struct slot *pccard_init_slot(device_t, struct slot_ctrl *);
void pccard_event(struct slot *, enum card_event);
int pccard_suspend(device_t);
int pccard_resume(device_t);
OpenPOWER on IntegriCloud