Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev Clean up attach of wd/atapibus:



details:   https://anonhg.NetBSD.org/src/rev/f3934ea15bac
branches:  trunk
changeset: 518637:f3934ea15bac
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sun Dec 02 22:44:32 2001 +0000

description:
Clean up attach of wd/atapibus:
kill ata_atapi_attach. Change atapibus to use a struct scsipi_channel instead
of ata_atapi_attach as attach arch. Create a ata_device, compatible with
scsipi_channel, to attach wd.

diffstat:

 sys/dev/ata/atavar.h        |  20 +---------------
 sys/dev/ata/wd.c            |  20 ++++++++--------
 sys/dev/ata/wdvar.h         |  26 ++++++++++++++++++++-
 sys/dev/ic/wdc.c            |  56 ++++++++++++++++----------------------------
 sys/dev/scsipi/atapi_wdc.c  |  17 ++++--------
 sys/dev/scsipi/atapiconf.c  |  39 +++++++++++++++----------------
 sys/dev/scsipi/atapiconf.h  |   7 ++---
 sys/dev/scsipi/scsiconf.c   |   6 ++--
 sys/dev/scsipi/scsipiconf.h |  14 +++++-----
 sys/dev/usb/umassbus.c      |  23 +++++------------
 sys/dev/usb/umassbus.h      |   6 +----
 11 files changed, 103 insertions(+), 131 deletions(-)

diffs (truncated from 600 to 300 lines):

diff -r 49bcbea124e7 -r f3934ea15bac sys/dev/ata/atavar.h
--- a/sys/dev/ata/atavar.h      Sun Dec 02 22:43:44 2001 +0000
+++ b/sys/dev/ata/atavar.h      Sun Dec 02 22:44:32 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atavar.h,v 1.20 2001/12/01 00:00:30 bouyer Exp $       */
+/*     $NetBSD: atavar.h,v 1.21 2001/12/02 22:44:32 bouyer Exp $       */
 
 /*
  * Copyright (c) 1998 Manuel Bouyer.
@@ -91,24 +91,6 @@
     void* chnl_softc; /* channel softc */
 };
 
-/* ATA/ATAPI common attachement datas */
-/*
- * XXX Small hack alert
- * NOTE:  The first field of struct ata_atapi_attach is shared with 
- * dev/scspi/scsipiconf.h's struct scsipi_channel.  This allows
- * atapibus and scsibus to attach to the same device.
- */
-struct ata_atapi_attach {
-    u_int8_t aa_type; /* Type of device */
-/*#define T_SCSI 0*/
-#define T_ATAPI 1
-#define T_ATA 2
-    u_int8_t aa_channel; /* controller's channel */
-    u_int8_t aa_openings; /* Number of simultaneous commands possible */
-    struct ata_drive_datas *aa_drv_data;
-    void *aa_bus_private; /* infos specifics to this bus */
-};
-
 /* User config flags that force (or disable) the use of a mode */
 #define ATA_CONFIG_PIO_MODES   0x0007
 #define ATA_CONFIG_PIO_SET     0x0008
diff -r 49bcbea124e7 -r f3934ea15bac sys/dev/ata/wd.c
--- a/sys/dev/ata/wd.c  Sun Dec 02 22:43:44 2001 +0000
+++ b/sys/dev/ata/wd.c  Sun Dec 02 22:44:32 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wd.c,v 1.215 2001/11/13 12:53:09 lukem Exp $ */
+/*     $NetBSD: wd.c,v 1.216 2001/12/02 22:44:32 bouyer Exp $ */
 
 /*
  * Copyright (c) 1998 Manuel Bouyer.  All rights reserved.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.215 2001/11/13 12:53:09 lukem Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.216 2001/12/02 22:44:32 bouyer Exp $");
 
 #ifndef WDCDEBUG
 #define WDCDEBUG
@@ -235,19 +235,19 @@
 
        void *aux;
 {
-       struct ata_atapi_attach *aa_link = aux;
+       struct ata_device *adev = aux;
 
-       if (aa_link == NULL)
+       if (adev == NULL)
                return 0;
-       if (aa_link->aa_type != T_ATA)
+       if (adev->adev_bustype->bustype_type != SCSIPI_BUSTYPE_ATA)
                return 0;
 
        if (match->cf_loc[ATACF_CHANNEL] != ATACF_CHANNEL_DEFAULT &&
-           match->cf_loc[ATACF_CHANNEL] != aa_link->aa_channel)
+           match->cf_loc[ATACF_CHANNEL] != adev->adev_channel)
                return 0;
 
        if (match->cf_loc[ATACF_DRIVE] != ATACF_DRIVE_DEFAULT &&
-           match->cf_loc[ATACF_DRIVE] != aa_link->aa_drv_data->drive)
+           match->cf_loc[ATACF_DRIVE] != adev->adev_drv_data->drive)
                return 0;
        return 1;
 }
@@ -258,7 +258,7 @@
        void *aux;
 {
        struct wd_softc *wd = (void *)self;
-       struct ata_atapi_attach *aa_link= aux;
+       struct ata_device *adev= aux;
        int i, blank;
        char buf[41], pbuf[9], c, *p, *q;
        WDCDEBUG_PRINT(("wdattach\n"), DEBUG_FUNCS | DEBUG_PROBE);
@@ -266,8 +266,8 @@
        callout_init(&wd->sc_restart_ch);
        BUFQ_INIT(&wd->sc_q);
 
-       wd->openings = aa_link->aa_openings;
-       wd->drvp = aa_link->aa_drv_data;;
+       wd->openings = adev->adev_openings;
+       wd->drvp = adev->adev_drv_data;;
        wd->wdc_softc = parent;
        /* give back our softc to our caller */
        wd->drvp->drv_softc = &wd->sc_dev;
diff -r 49bcbea124e7 -r f3934ea15bac sys/dev/ata/wdvar.h
--- a/sys/dev/ata/wdvar.h       Sun Dec 02 22:43:44 2001 +0000
+++ b/sys/dev/ata/wdvar.h       Sun Dec 02 22:44:32 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wdvar.h,v 1.7 2001/07/08 18:06:45 wiz Exp $    */
+/*     $NetBSD: wdvar.h,v 1.8 2001/12/02 22:44:33 bouyer Exp $ */
 
 /*
  * Copyright (c) 1998 Manuel Bouyer.
@@ -61,6 +61,30 @@
     daddr_t badsect[127];    /* 126 plus trailing -1 marker */
 };
 
+/*
+ * ata_bustype. The first field has to be compatible with scsipi_bustype,
+ * as it's used for autoconfig by both ata and atapi drivers
+ */
+  
+struct ata_bustype {
+       int bustype_type;       /* symbolic name of type */
+};
+/* bustype_type */
+/* #define SCSIPI_BUSTYPE_SCSI 0 */
+/* #define SCSIPI_BUSTYPE_ATAPI        1 */
+#define SCSIPI_BUSTYPE_ATA     2
+
+/*
+ * describe an ATA device. Has to be compatible with scsipi_channel, so start
+ * with a pointer to ata_bustype
+ */
+struct ata_device {
+       const struct ata_bustype *adev_bustype;
+       int adev_channel;
+       int adev_openings;
+       struct ata_drive_datas *adev_drv_data;
+};
+
 int wdc_ata_bio __P((struct ata_drive_datas*, struct ata_bio*)); 
 
 void wddone __P((void *));
diff -r 49bcbea124e7 -r f3934ea15bac sys/dev/ic/wdc.c
--- a/sys/dev/ic/wdc.c  Sun Dec 02 22:43:44 2001 +0000
+++ b/sys/dev/ic/wdc.c  Sun Dec 02 22:44:32 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wdc.c,v 1.101 2001/11/14 20:18:11 bouyer Exp $ */
+/*     $NetBSD: wdc.c,v 1.102 2001/12/02 22:44:33 bouyer Exp $ */
 
 
 /*
@@ -72,7 +72,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.101 2001/11/14 20:18:11 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.102 2001/12/02 22:44:33 bouyer Exp $");
 
 #ifndef WDCDEBUG
 #define WDCDEBUG
@@ -99,6 +99,7 @@
 #define bus_space_read_multi_stream_4  bus_space_read_multi_4
 #endif /* __BUS_SPACE_HAS_STREAM_METHODS */
 
+#include <dev/ata/wdvar.h>
 #include <dev/ata/atavar.h>
 #include <dev/ata/atareg.h>
 #include <dev/ic/wdcreg.h>
@@ -115,6 +116,8 @@
 
 struct pool wdc_xfer_pool;
 
+const struct ata_bustype wdc_ata_bustype = {SCSIPI_BUSTYPE_ATA};
+
 static void  __wdcerror          __P((struct channel_softc*, char *));
 static int   __wdcwait_reset  __P((struct channel_softc *, int));
 void  __wdccommand_done __P((struct channel_softc *, struct wdc_xfer *));
@@ -143,23 +146,11 @@
        void *aux;
        const char *pnp;
 {
-       struct ata_atapi_attach *aa_link = aux;
+       struct ata_device *adev = aux;
        if (pnp)
                printf("drive at %s", pnp);
-       printf(" channel %d drive %d", aa_link->aa_channel,
-           aa_link->aa_drv_data->drive);
-       return (UNCONF);
-}
-
-int
-atapiprint(aux, pnp)
-       void *aux;
-       const char *pnp;
-{
-       struct ata_atapi_attach *aa_link = aux;
-       if (pnp)
-               printf("atapibus at %s", pnp);
-       printf(" channel %d", aa_link->aa_channel);
+       printf(" channel %d drive %d", adev->adev_channel,
+           adev->adev_drv_data->drive);
        return (UNCONF);
 }
 
@@ -295,7 +286,6 @@
        struct channel_softc *chp;
 {
        int channel_flags, ctrl_flags, i, error;
-       struct ata_atapi_attach aa_link;
        struct ataparams params;
        static int inited = 0;
 
@@ -423,32 +413,26 @@
                wdc_atapibus_attach(chp);
 #else
                /*
-                * Fills in a fake aa_link and call config_found, so that
-                * the config machinery will print
-                * "atapibus at xxx not configured"
+                * Fake the autoconfig "not configured" message
                 */
-               memset(&aa_link, 0, sizeof(struct ata_atapi_attach));
-               aa_link.aa_type = T_ATAPI;
-               aa_link.aa_channel = chp->channel;
-               aa_link.aa_openings = 1;
-               aa_link.aa_drv_data = 0;
-               aa_link.aa_bus_private = NULL;
-               chp->atapibus = config_found(&chp->wdc->sc_dev,
-                   (void *)&aa_link, atapiprint);
+               printf("atapibus at %s channel %s not configured\n",
+                   chp->wdc->sc_dev.dv_xname, chp->channel);
+               chp->atapibus = NULL;
 #endif
        }
 
        for (i = 0; i < 2; i++) {
+               struct ata_device adev;
                if ((chp->ch_drive[i].drive_flags &
                    (DRIVE_ATA | DRIVE_OLD)) == 0) {
                        continue;
                }
-               memset(&aa_link, 0, sizeof(struct ata_atapi_attach));
-               aa_link.aa_type = T_ATA;
-               aa_link.aa_channel = chp->channel;
-               aa_link.aa_openings = 1;
-               aa_link.aa_drv_data = &chp->ch_drive[i];
-               if (config_found(&chp->wdc->sc_dev, (void *)&aa_link, wdprint))
+               memset(&adev, 0, sizeof(struct ata_device));
+               adev.adev_bustype = &wdc_ata_bustype;
+               adev.adev_channel = chp->channel;
+               adev.adev_openings = 1;
+               adev.adev_drv_data = &chp->ch_drive[i];
+               if (config_found(&chp->wdc->sc_dev, (void *)&adev, wdprint))
                        wdc_probe_caps(&chp->ch_drive[i]);
        }
 
@@ -583,6 +567,8 @@
                 * Detach our other children.
                 */
                for (j = 0; j < 2; j++) {
+                       if (chp->ch_drive[j].drive_flags & DRIVE_ATAPI)
+                               continue;
                        sc = chp->ch_drive[j].drv_softc;
                        WDCDEBUG_PRINT(("wdcdetach: %s: detaching %s\n",
                            wdc->sc_dev.dv_xname,
diff -r 49bcbea124e7 -r f3934ea15bac sys/dev/scsipi/atapi_wdc.c
--- a/sys/dev/scsipi/atapi_wdc.c        Sun Dec 02 22:43:44 2001 +0000
+++ b/sys/dev/scsipi/atapi_wdc.c        Sun Dec 02 22:44:32 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atapi_wdc.c,v 1.45 2001/12/01 00:00:29 bouyer Exp $    */
+/*     $NetBSD: atapi_wdc.c,v 1.46 2001/12/02 22:44:33 bouyer Exp $    */
 
 /*
  * Copyright (c) 1998 Manuel Bouyer.
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atapi_wdc.c,v 1.45 2001/12/01 00:00:29 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atapi_wdc.c,v 1.46 2001/12/02 22:44:33 bouyer Exp $");
 
 #ifndef WDCDEBUG
 #define WDCDEBUG
@@ -116,7 +116,6 @@
        struct wdc_softc *wdc = chp->wdc;
        struct scsipi_adapter *adapt = &wdc->sc_atapi_adapter._generic;
        struct scsipi_channel *chan = &chp->ch_atapi_channel;
-       struct ata_atapi_attach aa;
 
        /*
         * Fill in the scsipi_adapter.
@@ -143,13 +142,7 @@
        chan->chan_ntargets = 2;
        chan->chan_nluns = 1;
 
-       memset(&aa, 0, sizeof(aa));
-       aa.aa_type = T_ATAPI;
-       aa.aa_channel = chan->chan_channel;
-       aa.aa_openings = chan->chan_openings;
-       aa.aa_drv_data = chp->ch_drive; /* pass the whole array */
-       aa.aa_bus_private = chan;
-       chp->atapibus = config_found(&wdc->sc_dev, &aa, atapiprint);
+       chp->atapibus = config_found(&wdc->sc_dev, chan, atapiprint);
 }
 



Home | Main Index | Thread Index | Old Index