From owner-freebsd-mobile Fri Dec 31 10:38:41 1999 Delivered-To: freebsd-mobile@freebsd.org Received: from alpo.whistle.com (alpo.whistle.com [207.76.204.38]) by hub.freebsd.org (Postfix) with ESMTP id A885114ECD for ; Fri, 31 Dec 1999 10:38:35 -0800 (PST) (envelope-from ambrisko@whistle.com) Received: from whistle.com (crab.whistle.com [207.76.205.112]) by alpo.whistle.com (8.9.1a/8.9.1) with ESMTP id KAA06247; Fri, 31 Dec 1999 10:38:34 -0800 (PST) Received: (from ambrisko@localhost) by whistle.com (8.9.1/8.9.1) id KAA44694; Fri, 31 Dec 1999 10:38:18 -0800 (PST) (envelope-from ambrisko) From: Doug Ambrisko Message-Id: <199912311838.KAA44694@whistle.com> Subject: Re: [ATA/PC-Card,4-current] Patches to ata driver for PC-Card In-Reply-To: <199912310657.PAA09097@lavender.yy.cs.keio.ac.jp> from MIHIRA Sanpei Yoshiro at "Dec 31, 99 03:57:11 pm" To: sanpei@sanpei.org (MIHIRA Sanpei Yoshiro) Date: Fri, 31 Dec 1999 10:38:18 -0800 (PST) Cc: freebsd-mobile@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL29 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-mobile@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org MIHIRA Sanpei Yoshiro writes: | I tested two ATAPI/ATA-PC-Cards with Doug Ambrisko's new | ATA/PC-Card patch which was posted this FreeBSD-mobile mailing list. | | PC-Card patch for new ATA driver | http://www.freebsd.org/cgi/getmsg.cgi?fetch=235552+0+/usr/local/www/db/text/1999/freebsd-mobile/19991031.freebsd-mobile | | First, ``I-O Data'' 16bit IDE interface card with Portable CD-ROM | is fine and I can mount CD-ROM without trouble. | | Second, 32MBytes Compact Flash PC-Card has problem. | - probe/attach OK | - fdisk ad4 OK | - mount -t msdos NG | (I think this problem is not related to ATA/PC-Card driver, I will | fdisk and re-format it) That's encouraging, Warner told me the flash card he had didn't work. I should have one next week to play with. I forget in what way it didn't work. | I added pccard.conf entry and probe-messages at the bottom of this mail. | | Thanks Doug, and I hope to add detach code to ATA/PC-Card. BTW Warner cleaned up my initial version and I've attached it at the end. It had some junk in it left over from when I modified the ata driver to work with pccard stuff before the pccard stuff was converted to new bus. However, I'm glad to see it still worked for you. If you are looking at how to do the attach & detach we need to look at how to probe and then free up devices for a controller. I was hoping Soren might provide some insight. Maybe Warner can provide some direction? Currently how I deal with pccard controllers being added is to call ad_drvinit and atapi_init. However, these are not really designed as proper interfaces to call since they where designed to be called via SYSINIT. So the assumption is that all controllers have been probed and then later in the boot process the devices on all controllers are searched. So the first side effect of my calling ad_drvinit and atapi_init is that it would re probe my internal devices (so I get 2 names for a the same disk ad0 & ad1 and acd0 & adc1). To get around this I added a "probed" flag to the controller softc structure. It would be better if devices could be probed as part of the controller probe. Then maybe as the controller is removed those devices could be removed. This also implies a complexity in how devices are named and device names are reclaimed. I guess worst case the ATA_STATIC_ID option could be used initially. I guess we could look to cam and see how they deal with adding devices. I hate to have device ad45 after swaping several cards around with different devices. I know Soren has worked on the issue of hot swapping disks but I haven't seen any technical discussion or code to deal with it. However, this may or may not help us with controllers coming and going. Question, could this be accomplished via newbus in a simple way? I need to revisit the code since I did this several months ago and things may have changed a little. BTW the reason I did this a long time ago was to use an external CD-RW on my laptop. I also tried a Microtec Zip drive and external hard drive and they both worked. Doug A. Index: ata-all.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/sys/dev/ata/ata-all.c,v retrieving revision 1.33 diff -u -r1.33 ata-all.c --- ata-all.c 1999/12/07 22:07:18 1.33 +++ ata-all.c 1999/12/11 07:54:27 @@ -70,6 +70,8 @@ #include #include +#include "card.h" + /* misc defines */ #if SMP == 0 #define isa_apic_irq(x) x @@ -81,6 +83,14 @@ 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)); +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); @@ -178,6 +188,84 @@ 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, 1, RF_ACTIVE); + + if (!port) + return (ENOMEM); + + /* don't worry about conflict since PCCard code should have checked + already */ + + lun = 0; + 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); + + if (res) { + isa_set_portsize(dev, res); /* XXX tsk isa specific */ + *(int *)device_get_softc(dev) = lun; + return 0; + } + return ENXIO; +} + +static int +ata_pccard_attach(dev) + device_t dev; +{ + int status; + + status = ata_isaattach(dev); + 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) @@ -458,6 +546,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\n", Index: ata-all.h =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/sys/dev/ata/ata-all.h,v retrieving revision 1.15 diff -u -r1.15 ata-all.h --- ata-all.h 1999/11/24 21:40:02 1.15 +++ ata-all.h 1999/12/11 07:54:27 @@ -167,6 +167,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: /home/imp/FreeBSD/CVS/src/sys/dev/ata/ata-disk.c,v retrieving revision 1.43 diff -u -r1.43 ata-disk.c --- ata-disk.c 1999/12/08 12:08:46 1.43 +++ ata-disk.c 1999/12/11 07:54:27 @@ -83,7 +83,7 @@ static void ad_start(struct ad_softc *); static void ad_timeout(struct ad_request *); static int8_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; @@ -139,6 +139,8 @@ /* now, run through atadevices and look for ATA disks */ for (ctlr=0; ctlrprobed & 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)) { @@ -708,7 +710,7 @@ return '?'; } -static void +void ad_drvinit(void) { fakewd_cdevsw = ad_cdevsw; Index: atapi-all.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/sys/dev/ata/atapi-all.c,v retrieving revision 1.24 diff -u -r1.24 atapi-all.c --- atapi-all.c 1999/12/07 22:25:23 1.24 +++ atapi-all.c 1999/12/11 07:54:27 @@ -56,7 +56,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 *); @@ -113,6 +113,8 @@ /* now, run through atadevices and look for ATAPI devices */ for (ctlr=0; ctlrprobed & 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)) { @@ -779,7 +781,7 @@ return -1; } -static void +void atapi_init(void) { /* register callback for when interrupts are enabled */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-mobile" in the body of the message