From owner-freebsd-mobile Thu Feb 10 10:40:46 2000 Delivered-To: freebsd-mobile@freebsd.org Received: from freebsd.dk (freebsd.dk [212.242.42.178]) by builder.freebsd.org (Postfix) with ESMTP id 70B454686 for ; Thu, 10 Feb 2000 10:40:37 -0800 (PST) Received: (from sos@localhost) by freebsd.dk (8.9.3/8.9.1) id TAA39117; Thu, 10 Feb 2000 19:40:04 +0100 (CET) (envelope-from sos) From: Soren Schmidt Message-Id: <200002101840.TAA39117@freebsd.dk> Subject: Re: Update to pccard ata changes (removal support) In-Reply-To: <200002101827.KAA90609@whistle.com> from Doug Ambrisko at "Feb 10, 2000 10:27:07 am" To: ambrisko@whistle.com (Doug Ambrisko) Date: Thu, 10 Feb 2000 19:40:04 +0100 (CET) Cc: imp@village.org, freebsd-mobile@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL54 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-freebsd-mobile@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org It seems Doug Ambrisko wrote: > I have now added removal support to the ata driver for pccard. > > Caveats, the devices increment each time they are inserted and removed. > Also I do not checks for mounted devices etc. yet. I'm not sure what > the details are to deal with this (since as the card is being ripped out > there won't be time to sync the device). So your machine might panic. > I don't know and haven't tested this. I also need to look at the > incrementing device issue. I thought it would be usefull to get this > code out before I start to investigate that. > > I have tested it with my external hard disk, CD-Rom and Zip. They > all seemed to handle it fine. Device accesses to old device names > failed somewhat gracefully (ie. no panic but some error messages). > > Please let me know how it works. Again this is relative to -current. ARGH! this will loose memory allocated in the subdrivers, also inc'ing the device # are a no go, you will run out of softc's... I have thought about this, and when I get a spare hour I'll implement it... However find below my version of your previous patch set, please let me know how it works (I have no way of testing it here)... There are a few other cosmetic changes in there, this is part of the next update, and not all was easily pulled out... Index: ata-all.c =================================================================== RCS file: /home/ncvs/src/sys/dev/ata/ata-all.c,v retrieving revision 1.47 diff -u -r1.47 ata-all.c --- ata-all.c 2000/02/04 10:20:20 1.47 +++ ata-all.c 2000/02/10 16:01:40 @@ -31,6 +31,7 @@ #include "ata.h" #include "apm.h" #include "isa.h" +#include "card.h" #include "pci.h" #include "atadisk.h" #include "atapicd.h" @@ -105,12 +106,11 @@ }; static int -ata_isaprobe(device_t dev) +ata_isa_probe(device_t dev) { struct resource *port; int rid; - int32_t ctlr, res; - int32_t lun; + int32_t ctlr, res, lun; /* Check isapnp ids */ if (ISA_PNP_PROBE(device_get_parent(dev), dev, ata_ids) == ENXIO) @@ -125,13 +125,10 @@ /* check if allready in use by a PCI device */ for (ctlr = 0; ctlr < atanlun; ctlr++) { if (atadevices[ctlr] && atadevices[ctlr]->ioaddr==rman_get_start(port)){ - printf("ata-isa%d: already registered as ata%d\n", - device_get_unit(dev), ctlr); bus_release_resource(dev, SYS_RES_IOPORT, 0, port); return ENXIO; } } - lun = 0; res = ata_probe(rman_get_start(port), rman_get_start(port) + ATA_ALTPORT, 0, dev, &lun); @@ -148,7 +145,7 @@ } static int -ata_isaattach(device_t dev) +ata_isa_attach(device_t dev) { struct resource *port; struct resource *irq; @@ -173,8 +170,8 @@ static device_method_t ata_isa_methods[] = { /* Device interface */ - DEVMETHOD(device_probe, ata_isaprobe), - DEVMETHOD(device_attach, ata_isaattach), + DEVMETHOD(device_probe, ata_isa_probe), + DEVMETHOD(device_attach, ata_isa_attach), { 0, 0 } }; @@ -187,6 +184,88 @@ DRIVER_MODULE(ata, isa, ata_isa_driver, ata_devclass, 0, 0); #endif +#if NCARD > 0 +static int +ata_pccard_probe(device_t dev) +{ + struct resource *port; + int rid; + int32_t res, lun; + + /* Allocate the port range */ + rid = 0; + port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 16, RF_ACTIVE); + if (!port) + return (ENOMEM); + + /* dont have ata_probe() hook into the intr_config chain */ + if (!ata_attach_hook) + ata_attach_hook = (struct intr_config_hook *)-1; + + lun = 0; + res = ata_probe(rman_get_start(port), + rman_get_start(port) + ATA_ALTPORT_PCCARD, 0, dev, &lun); + + if (ata_attach_hook == (struct intr_config_hook *)-1) + ata_attach_hook = NULL; + + bus_release_resource(dev, SYS_RES_IOPORT, rid, port); + + if (res) { + isa_set_portsize(dev, res); + *(int *)device_get_softc(dev) = lun; + atadevices[lun]->flags |= ATA_USE_16BIT; + return 0; + } + return ENXIO; +} + +static int +ata_pccard_attach(device_t dev) +{ + struct resource *port; + struct resource *irq; + void *ih; + int rid; + int status; + + /* Allocate the port range and interrupt */ + rid = 0; + port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE); + if (!port) { + return (ENOMEM); + } + + rid = 0; + irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, RF_ACTIVE); + if (!irq) { + bus_release_resource(dev, SYS_RES_IOPORT, 0, port); + return (ENOMEM); + } + status = bus_setup_intr(dev, irq, INTR_TYPE_BIO, ataintr, + atadevices[*(int *)device_get_softc(dev)], &ih); + if (status) + return status; + ata_attach(dev); + return 0; +} + +static device_method_t ata_pccard_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, ata_pccard_probe), + DEVMETHOD(device_attach, ata_pccard_attach), + { 0, 0 } +}; + +static driver_t ata_pccard_driver = { + "ata", + ata_pccard_methods, + sizeof(int), +}; + +DRIVER_MODULE(ata, pccard, ata_pccard_driver, ata_devclass, 0, 0); +#endif (NCARD > 0) + #if NPCI > 0 static const char * ata_pcimatch(device_t dev) @@ -261,7 +342,7 @@ } static int -ata_pciprobe(device_t dev) +ata_pci_probe(device_t dev) { const char *desc = ata_pcimatch(dev); @@ -274,7 +355,7 @@ } static int -ata_pciattach(device_t dev) +ata_pci_attach(device_t dev) { int unit = device_get_unit(dev); struct ata_softc *scp; @@ -489,8 +570,8 @@ static device_method_t ata_pci_methods[] = { /* Device interface */ - DEVMETHOD(device_probe, ata_pciprobe), - DEVMETHOD(device_attach, ata_pciattach), + DEVMETHOD(device_probe, ata_pci_probe), + DEVMETHOD(device_attach, ata_pci_attach), { 0, 0 } }; @@ -629,6 +710,7 @@ bzero(ata_attach_hook, sizeof(struct intr_config_hook)); ata_attach_hook->ich_func = ata_attach; + ata_attach_hook->ich_arg = NULL; if (config_intrhook_establish(ata_attach_hook) != 0) { ata_printf(scp, -1, "config_intrhook_establish failed\n"); free(ata_attach_hook, M_TEMP); @@ -645,17 +727,19 @@ } void -ata_attach(void *dummy) +ata_attach(void *dev) { int32_t ctlr; /* * run through atadevices[] and look for real ATA & ATAPI devices * using the hints we found in the early probe to avoid probing - * of non-exsistent devices and thereby long delays + * of non-exsistent devices and thereby long delays. + * if dev is !NULL only try that device. */ for (ctlr=0; ctlrdevices & ATA_ATA_SLAVE) if (ata_getparam(atadevices[ctlr], ATA_SLAVE, ATA_C_ATA_IDENTIFY)) atadevices[ctlr]->devices &= ~ATA_ATA_SLAVE; @@ -673,7 +757,8 @@ #if NATADISK > 0 /* now we know whats there, do the real attach, first the ATA disks */ for (ctlr=0; ctlrdevices & ATA_ATA_MASTER) ad_attach(atadevices[ctlr], ATA_MASTER); if (atadevices[ctlr]->devices & ATA_ATA_SLAVE) @@ -683,7 +768,8 @@ #if NATAPICD > 0 || NATAPIFD > 0 || NATAPIST > 0 /* then the atapi devices */ for (ctlr=0; ctlrdevices & ATA_ATAPI_MASTER) atapi_attach(atadevices[ctlr], ATA_MASTER); if (atadevices[ctlr]->devices & ATA_ATAPI_SLAVE) Index: ata-all.h =================================================================== RCS file: /home/ncvs/src/sys/dev/ata/ata-all.h,v retrieving revision 1.23 diff -u -r1.23 ata-all.h --- ata-all.h 2000/01/28 13:35:42 1.23 +++ ata-all.h 2000/02/10 09:33:59 @@ -86,7 +86,8 @@ #define ATA_S_READY 0x40 /* drive ready */ #define ATA_S_BUSY 0x80 /* busy */ -#define ATA_ALTPORT 0x206 /* alternate Status register */ +#define ATA_ALTPORT 0x206 /* alternate status register */ +#define ATA_ALTPORT_PCCARD 0x8 /* for PCCARD its different */ #define ATA_A_IDS 0x02 /* disable interrupts */ #define ATA_A_RESET 0x04 /* RESET controller */ #define ATA_A_4BIT 0x08 /* 4 head bits */ @@ -99,7 +100,6 @@ #define ATA_OP_CONTINUES 0x01 #define ATA_DEV(unit) ((unit == ATA_MASTER) ? 0 : 1) #define ATA_PARAM(scp, unit) scp->dev_param[ATA_DEV(unit)] - /* busmaster DMA related defines */ #define ATA_BM_OFFSET1 0x08 -Søren To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-mobile" in the body of the message