Date: Thu, 13 Jan 2000 18:13:30 -0500 From: Christopher Masto <chris@netmonger.net> To: Warner Losh <imp@village.org> Cc: Doug Ambrisko <ambrisko@whistle.com>, MIHIRA Sanpei Yoshiro <sanpei@sanpei.org>, freebsd-mobile@FreeBSD.ORG Subject: Re: [ATA/PC-Card,4-current] Patches to ata driver for PC-Card Message-ID: <20000113181330.B25247@netmonger.net> In-Reply-To: <20000113174756.A25247@netmonger.net>; from Christopher Masto on Thu, Jan 13, 2000 at 05:47:56PM -0500 References: <20000102085652.A1662@netmonger.net> <199912310657.PAA09097@lavender.yy.cs.keio.ac.jp> <199912311838.KAA44694@whistle.com> <20000102085652.A1662@netmonger.net> <200001030043.RAA32702@harmony.village.org> <20000113174756.A25247@netmonger.net>
next in thread | previous in thread | raw e-mail | index | archive | help
--9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii On Thu, Jan 13, 2000 at 05:47:56PM -0500, Christopher Masto wrote: > Waah! I finally get a chance to try it and it no longer applies. Next > time somebody does this patch, I would love to see it committed so this > stops happening. Enough of my wining. Adjusted patch attached (it didn't take much). -- Christopher Masto Senior Network Monkey NetMonger Communications chris@netmonger.net info@netmonger.net http://www.netmonger.net Free yourself, free your machine, free the daemon -- http://www.freebsd.org/ --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=ata-patch-new Index: ata-all.c =================================================================== RCS file: /usr/local/ncvs/freebsd/src/sys/dev/ata/ata-all.c,v retrieving revision 1.39 diff -u -r1.39 ata-all.c --- ata-all.c 2000/01/03 20:01:18 1.39 +++ ata-all.c 2000/01/13 23:11:51 @@ -30,6 +30,7 @@ #include "ata.h" #include "apm.h" +#include "card.h" #include "isa.h" #include "pci.h" #include "atadisk.h" @@ -81,6 +82,15 @@ static void ataintr(void *); static int8_t *active2str(int32_t); +#if NCARD > 0 +static int ata_pccard_attach __P((device_t dev)); +static int ata_pccard_detach __P((device_t dev)); +static int ata_pccard_probe __P((device_t dev)); +/* XXX */ +extern void ad_drvinit(void); +extern void atapi_init(void); +#endif /* NCARD > 0 */ + /* local vars */ static int32_t atanlun = 2; struct ata_softc *atadevices[MAXATA]; @@ -107,7 +117,7 @@ /* Check isapnp ids */ if (ISA_PNP_PROBE(device_get_parent(dev), dev, ata_ids) == ENXIO) return (ENXIO); - + /* Allocate the port range */ rid = 0; port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE); @@ -128,7 +138,7 @@ res = ata_probe(rman_get_start(port), rman_get_start(port) + ATA_ALTPORT, 0, dev, &lun); - bus_release_resource(dev, SYS_RES_IOPORT, 0, port); + bus_release_resource(dev, SYS_RES_IOPORT, rid, port); if (res) { isa_set_portsize(dev, res); @@ -144,18 +154,18 @@ struct resource *port; struct resource *irq; void *ih; - int rid; + int prid, irqrid; /* Allocate the port range and interrupt */ - rid = 0; - port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE); + prid = 0; + port = bus_alloc_resource(dev, SYS_RES_IOPORT, &prid, 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); + irqrid = 0; + irq = bus_alloc_resource(dev, SYS_RES_IRQ, &irqrid, 0, ~0, 1, RF_ACTIVE); if (!irq) { - bus_release_resource(dev, SYS_RES_IOPORT, 0, port); + bus_release_resource(dev, SYS_RES_IOPORT, prid, port); return (ENOMEM); } return bus_setup_intr(dev, irq, INTR_TYPE_BIO, ataintr, @@ -178,6 +188,129 @@ DRIVER_MODULE(ata, isa, ata_isa_driver, ata_devclass, 0, 0); #endif +#if NCARD > 0 +static int +ata_pccard_probe(dev) + device_t dev; +{ + struct resource *port; + int rid; + int32_t res; + int32_t lun; + + /* Allocate the port range */ + rid = 0; + port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 16, RF_ACTIVE); + /* XXX 16 shouldn't be hard coded */ + + if (!port) + return (ENOMEM); + + /* don't worry about conflict since PCCard code should have checked + already */ + /* + * XXX ALTPORT not used in pccard XXX + * Here's the i/o map for isa vs pccard + * Offset isa pccard + * DATA 0 0 + * ERROR 1 1 R + * FEATURE 1 1 W + * COUNT 2 2 W + * IREASON 2 2 R + * SECTOR 3 3 + * CYL_LSB 4 4 + * CYL_MSB 5 5 + * DRIVE 6 6 + * CMD 7 7 + * STATUS 7 7 + * ALTSTATUS 206 8 R + * CTLR 206 8 W + * wd_digin 207 9 + */ + lun = 0; + res = ata_probe(rman_get_start(port), + rman_get_start(port) + ATA_ALTPORT_ONE_WINDOW, 0, dev, &lun); + + bus_release_resource(dev, SYS_RES_IOPORT, rid, port); + + if (res) { + *(int *)device_get_softc(dev) = lun; + return 0; + } + return ENXIO; +} + +static int +ata_pccard_attach(dev) + device_t dev; +{ + struct resource *port; + struct resource *irq; + void *ih; + int iorid; + int irqrid; + int status; + int lun; + + lun = *(int *)device_get_softc(dev); + atadevices[lun]->flags |= (ATA_NO_DMA | ATA_16BIT_IO_ONLY); + /* Allocate the port range and interrupt */ + iorid = 0; + port = bus_alloc_resource(dev, SYS_RES_IOPORT, &iorid, 0, ~0, 1, + RF_ACTIVE); + if (!port) { + /* XXX Need to free things ? */ + return (ENOMEM); + } + + irqrid = 0; + irq = bus_alloc_resource(dev, SYS_RES_IRQ, &irqrid, 0, ~0, 1, RF_ACTIVE); + if (!irq) { + /* XXX Need to free things ? */ + bus_release_resource(dev, SYS_RES_IOPORT, iorid, port); + return (ENOMEM); + } + status = bus_setup_intr(dev, irq, INTR_TYPE_BIO, ataintr, atadevices[lun], + &ih); + /* XXX The following really should just scan *THIS* device XXX */ + /* XXX Also, we need to do more than just ad XXX */ + if (status == 0) { + printf("ata_pccard: scan drives\n"); + ad_drvinit(); + printf("ata_pccard: scan ATAPI bus\n"); + atapi_init(); + } + return status; +} + + +static int +ata_pccard_detach(dev) + device_t dev; +{ + printf("I can't be dettached ata\n"); + return EIO; +} + + +static device_method_t ata_pccard_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, ata_pccard_probe), + DEVMETHOD(device_attach, ata_pccard_attach), + DEVMETHOD(device_detach, ata_pccard_detach), + + { 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) @@ -498,6 +631,7 @@ scp->lun = lun; scp->unit = *unit; scp->active = ATA_IDLE; + scp->probed = 0; if (bootverbose) printf("ata%d: iobase=0x%04x altiobase=0x%04x bmaddr=0x%04x\n", Index: ata-all.h =================================================================== RCS file: /usr/local/ncvs/freebsd/src/sys/dev/ata/ata-all.h,v retrieving revision 1.17 diff -u -r1.17 ata-all.h --- ata-all.h 2000/01/03 10:26:54 1.17 +++ ata-all.h 2000/01/13 23:11:51 @@ -87,6 +87,7 @@ #define ATA_S_BUSY 0x80 /* busy */ #define ATA_ALTPORT 0x206 /* alternate Status register */ +#define ATA_ALTPORT_ONE_WINDOW 0x08 /* Alternate port for pccard */ #define ATA_A_IDS 0x02 /* disable interrupts */ #define ATA_A_RESET 0x04 /* RESET controller */ #define ATA_A_4BIT 0x08 /* 4 head bits */ @@ -148,6 +149,8 @@ int32_t flags; /* controller flags */ #define ATA_DMA_ACTIVE 0x01 #define ATA_ATAPI_DMA_RO 0x02 +#define ATA_NO_DMA 0x04 +#define ATA_16BIT_IO_ONLY 0x08 int32_t devices; /* what is present */ #define ATA_ATA_MASTER 0x01 @@ -165,6 +168,9 @@ #define ATA_ACTIVE_ATA 0x3 #define ATA_ACTIVE_ATAPI 0x4 #define ATA_REINITING 0x5 + int32_t probed; /* already probed */ +#define ATA_PROBE 0x1 +#define ATAPI_PROBE 0x2 TAILQ_HEAD(, ad_request) ata_queue; /* head of ATA queue */ TAILQ_HEAD(, atapi_request) atapi_queue; /* head of ATAPI queue */ Index: ata-disk.c =================================================================== RCS file: /usr/local/ncvs/freebsd/src/sys/dev/ata/ata-disk.c,v retrieving revision 1.49 diff -u -r1.49 ata-disk.c --- ata-disk.c 2000/01/07 12:01:00 1.49 +++ ata-disk.c 2000/01/13 23:11:51 @@ -84,7 +84,7 @@ static void ad_start(struct ad_softc *); static void ad_timeout(struct ad_request *); static int32_t ad_version(u_int16_t); -static void ad_drvinit(void); +void ad_drvinit(void); /* internal vars */ static struct intr_config_hook *ad_attach_hook; @@ -140,6 +140,8 @@ /* now, run through atadevices and look for ATA disks */ for (ctlr=0; ctlr<MAXATA; ctlr++) { if (!atadevices[ctlr]) continue; + if (atadevices[ctlr]->probed & ATA_PROBE) continue; + atadevices[ctlr]->probed |= ATA_PROBE; for (dev=0; dev<2; dev++) { if (atadevices[ctlr]->devices & (dev ? ATA_ATA_SLAVE : ATA_ATA_MASTER)) { @@ -498,15 +500,14 @@ printf("ad_transfer: timeout waiting for DRQ"); /* output the data */ -#ifdef ATA_16BIT_ONLY - outsw(adp->controller->ioaddr + ATA_DATA, - (void *)((uintptr_t)request->data + request->donecount), - request->currentsize / sizeof(int16_t)); -#else - outsl(adp->controller->ioaddr + ATA_DATA, - (void *)((uintptr_t)request->data + request->donecount), - request->currentsize / sizeof(int32_t)); -#endif + if (adp->controller->flags & ATA_16BIT_IO_ONLY) + outsw(adp->controller->ioaddr + ATA_DATA, + (void *)((uintptr_t)request->data + request->donecount), + request->currentsize / sizeof(int16_t)); + else + outsl(adp->controller->ioaddr + ATA_DATA, + (void *)((uintptr_t)request->data + request->donecount), + request->currentsize / sizeof(int32_t)); request->bytecount -= request->currentsize; } @@ -589,15 +590,14 @@ } /* data ready, read in */ -#ifdef ATA_16BIT_ONLY - insw(adp->controller->ioaddr + ATA_DATA, - (void *)((uintptr_t)request->data + request->donecount), - request->currentsize / sizeof(int16_t)); -#else - insl(adp->controller->ioaddr + ATA_DATA, - (void *)((uintptr_t)request->data + request->donecount), - request->currentsize / sizeof(int32_t)); -#endif + if (adp->controller->flags & ATA_16BIT_IO_ONLY) + insw(adp->controller->ioaddr + ATA_DATA, + (void *)((uintptr_t)request->data + request->donecount), + request->currentsize / sizeof(int16_t)); + else + insl(adp->controller->ioaddr + ATA_DATA, + (void *)((uintptr_t)request->data + request->donecount), + request->currentsize / sizeof(int32_t)); request->bytecount -= request->currentsize; } @@ -688,7 +688,7 @@ return 0; } -static void +void ad_drvinit(void) { fakewd_cdevsw = ad_cdevsw; Index: atapi-all.c =================================================================== RCS file: /usr/local/ncvs/freebsd/src/sys/dev/ata/atapi-all.c,v retrieving revision 1.33 diff -u -r1.33 atapi-all.c --- atapi-all.c 2000/01/07 15:51:45 1.33 +++ atapi-all.c 2000/01/13 23:11:51 @@ -57,7 +57,7 @@ static int8_t *atapi_cmd2str(u_int8_t); static int8_t *atapi_skey2str(u_int8_t); static int32_t atapi_wait(struct atapi_softc *, u_int8_t); -static void atapi_init(void); +void atapi_init(void); /* extern references */ int32_t acdattach(struct atapi_softc *); @@ -114,6 +114,8 @@ /* now, run through atadevices and look for ATAPI devices */ for (ctlr=0; ctlr<MAXATA; ctlr++) { if (!atadevices[ctlr]) continue; + if (atadevices[ctlr]->probed & ATAPI_PROBE) continue; + atadevices[ctlr]->probed |= ATAPI_PROBE; for (dev=0; dev<2; dev++) { if (atadevices[ctlr]->devices & (dev ? ATA_ATAPI_SLAVE : ATA_ATAPI_MASTER)) { @@ -560,13 +562,12 @@ if (request->bytecount < length) { printf("%s: read data overrun %d/%d\n", request->device->devname, length, request->bytecount); -#ifdef ATA_16BIT_ONLY - insw(request->device->controller->ioaddr + ATA_DATA, - (void *)((uintptr_t)*buffer), request->bytecount/sizeof(int16_t)); -#else - insl(request->device->controller->ioaddr + ATA_DATA, - (void *)((uintptr_t)*buffer), request->bytecount/sizeof(int32_t)); -#endif + if (request->device->controller->flags & ATA_16BIT_IO_ONLY) + insw(request->device->controller->ioaddr + ATA_DATA, + (void *)((uintptr_t)*buffer), request->bytecount/sizeof(int16_t)); + else + insl(request->device->controller->ioaddr + ATA_DATA, + (void *)((uintptr_t)*buffer), request->bytecount/sizeof(int32_t)); for (resid=request->bytecount; resid<length; resid+=sizeof(int16_t)) inw(request->device->controller->ioaddr + ATA_DATA); *buffer += request->bytecount; @@ -592,13 +593,12 @@ if (request->bytecount < length) { printf("%s: write data underrun %d/%d\n", request->device->devname, length, request->bytecount); -#ifdef ATA_16BIT_ONLY - outsw(request->device->controller->ioaddr + ATA_DATA, - (void *)((uintptr_t)*buffer), request->bytecount/sizeof(int16_t)); -#else - outsl(request->device->controller->ioaddr + ATA_DATA, - (void *)((uintptr_t)*buffer), request->bytecount/sizeof(int32_t)); -#endif + if (request->device->controller->flags & ATA_16BIT_IO_ONLY) + outsw(request->device->controller->ioaddr + ATA_DATA, + (void *)((uintptr_t)*buffer), request->bytecount/sizeof(int16_t)); + else + outsl(request->device->controller->ioaddr + ATA_DATA, + (void *)((uintptr_t)*buffer), request->bytecount/sizeof(int32_t)); for (resid=request->bytecount; resid<length; resid+=sizeof(int16_t)) outw(request->device->controller->ioaddr + ATA_DATA, 0); *buffer += request->bytecount; @@ -766,7 +766,7 @@ return -1; } -static void +void atapi_init(void) { /* register callback for when interrupts are enabled */ --9jxsPFA5p3P2qPhR-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-mobile" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000113181330.B25247>