Source-Changes-HG archive

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

[src/trunk]: src/sys Add rdcide(4), a driver for the IDE controller found in ...



details:   https://anonhg.NetBSD.org/src/rev/16eb2e1083d3
branches:  trunk
changeset: 763790:16eb2e1083d3
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Mon Apr 04 14:33:51 2011 +0000

description:
Add rdcide(4), a driver for the IDE controller found in RDC's
vortex86/PMX-1000 system-on-chip.

diffstat:

 sys/arch/i386/conf/ALL     |    5 +-
 sys/arch/i386/conf/GENERIC |    5 +-
 sys/dev/pci/files.pci      |    7 +-
 sys/dev/pci/pcidevs        |    3 +-
 sys/dev/pci/rdcide.c       |  267 +++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/pci/rdcide_reg.h   |   74 ++++++++++++
 6 files changed, 355 insertions(+), 6 deletions(-)

diffs (truncated from 439 to 300 lines):

diff -r f96f15fc3d66 -r 16eb2e1083d3 sys/arch/i386/conf/ALL
--- a/sys/arch/i386/conf/ALL    Mon Apr 04 14:25:09 2011 +0000
+++ b/sys/arch/i386/conf/ALL    Mon Apr 04 14:33:51 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.301 2011/03/06 17:08:25 bouyer Exp $
+# $NetBSD: ALL,v 1.302 2011/04/04 14:33:51 bouyer Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "ALL-$Revision: 1.301 $"
+#ident                 "ALL-$Revision: 1.302 $"
 
 maxusers       64              # estimated number of users
 
@@ -900,6 +900,7 @@
 pdcide*        at pci? dev ? function ?        # Promise IDE controllers
 pdcsata*       at pci? dev ? function ?        # Promise SATA150 controllers
 rccide*        at pci? dev ? function ?        # ServerWorks IDE controllers
+rdcide*        at pci? dev ? function ?        # RDC PMX-1000 IDE controllers
 satalink*      at pci? dev ? function ?        # SiI SATALink controllers
 schide*        at pci? dev ? function ?        # Intel SCH IDE controllers
 siisata*       at pci? dev ? function ?        # SiI SteelVine controllers
diff -r f96f15fc3d66 -r 16eb2e1083d3 sys/arch/i386/conf/GENERIC
--- a/sys/arch/i386/conf/GENERIC        Mon Apr 04 14:25:09 2011 +0000
+++ b/sys/arch/i386/conf/GENERIC        Mon Apr 04 14:33:51 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.1027 2011/04/01 12:11:16 jruoho Exp $
+# $NetBSD: GENERIC,v 1.1028 2011/04/04 14:33:51 bouyer Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "GENERIC-$Revision: 1.1027 $"
+#ident                 "GENERIC-$Revision: 1.1028 $"
 
 maxusers       64              # estimated number of users
 
@@ -847,6 +847,7 @@
 pdcide*        at pci? dev ? function ?        # Promise IDE controllers
 pdcsata*       at pci? dev ? function ?        # Promise SATA150 controllers
 rccide*        at pci? dev ? function ?        # ServerWorks IDE controllers
+rdcide*        at pci? dev ? function ?        # RDC PMX-1000 IDE controllers
 satalink*      at pci? dev ? function ?        # SiI SATALink controllers
 schide*        at pci? dev ? function ?        # Intel SCH IDE controllers
 siisata*       at pci? dev ? function ?        # SiI SteelVine controllers
diff -r f96f15fc3d66 -r 16eb2e1083d3 sys/dev/pci/files.pci
--- a/sys/dev/pci/files.pci     Mon Apr 04 14:25:09 2011 +0000
+++ b/sys/dev/pci/files.pci     Mon Apr 04 14:33:51 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.pci,v 1.339 2011/02/23 00:35:29 jmcneill Exp $
+#      $NetBSD: files.pci,v 1.340 2011/04/04 14:33:51 bouyer Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -306,6 +306,11 @@
 attach rccide at pci
 file   dev/pci/rccide.c                rccide
 
+# RDC IDE controllers
+device rdcide: ata, ata_dma, ata_udma, pciide_common, wdc_common
+attach rdcide at pci
+file   dev/pci/rdcide.c                rdcide
+
 # ServerWorks SATA controllers
 device svwsata: ata, ata_dma, ata_udma, pciide_common, wdc_common, sata
 attach svwsata at pci
diff -r f96f15fc3d66 -r 16eb2e1083d3 sys/dev/pci/pcidevs
--- a/sys/dev/pci/pcidevs       Mon Apr 04 14:25:09 2011 +0000
+++ b/sys/dev/pci/pcidevs       Mon Apr 04 14:33:51 2011 +0000
@@ -1,4 +1,4 @@
-$NetBSD: pcidevs,v 1.1068 2011/03/16 23:19:32 matt Exp $
+$NetBSD: pcidevs,v 1.1069 2011/04/04 14:33:51 bouyer Exp $
 
 /*
  * Copyright (c) 1995, 1996 Christopher G. Demetriou
@@ -3915,6 +3915,7 @@
 
 /* RDC Semiconductor products */
 product RDC    R6040           0x6040  RDC R6040 10/100 Ethernet
+product RDC    IDE             0x1011  RDC IDE controller
 
 /* Realtek products */
 product REALTEK RT8029         0x8029  8029 Ethernet
diff -r f96f15fc3d66 -r 16eb2e1083d3 sys/dev/pci/rdcide.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/rdcide.c      Mon Apr 04 14:33:51 2011 +0000
@@ -0,0 +1,267 @@
+/*     $NetBSD: rdcide.c,v 1.1 2011/04/04 14:33:51 bouyer Exp $        */
+
+/*
+ * Copyright (c) 2011 Manuel Bouyer.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: rdcide.c,v 1.1 2011/04/04 14:33:51 bouyer Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+#include <dev/pci/pciidereg.h>
+#include <dev/pci/pciidevar.h>
+#include <dev/pci/rdcide_reg.h>
+
+static void rdcide_chip_map(struct pciide_softc*, struct pci_attach_args *);
+static void rdcide_setup_channel(struct ata_channel *);
+
+static bool rdcide_resume(device_t, const pmf_qual_t *);
+static bool rdcide_suspend(device_t, const pmf_qual_t *);
+static int  rdcide_match(device_t, cfdata_t, void *);
+static void rdcide_attach(device_t, device_t, void *);
+
+static const struct pciide_product_desc pciide_intel_products[] =  {
+       { PCI_PRODUCT_RDC_IDE,
+         0,
+         "RDC IDE controller",
+         rdcide_chip_map,
+       },
+};
+
+CFATTACH_DECL_NEW(rdcide, sizeof(struct pciide_softc),
+    rdcide_match, rdcide_attach, NULL, NULL);
+
+static int
+rdcide_match(device_t parent, cfdata_t match, void *aux)
+{
+       struct pci_attach_args *pa = aux;
+
+       if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_RDC) {
+               if (pciide_lookup_product(pa->pa_id, pciide_intel_products))
+                       return (2);
+       }
+       return (0);
+}
+
+static void
+rdcide_attach(device_t parent, device_t self, void *aux)
+{
+       struct pci_attach_args *pa = aux;
+       struct pciide_softc *sc = device_private(self);
+
+       sc->sc_wdcdev.sc_atac.atac_dev = self;
+
+       pciide_common_attach(sc, pa,
+           pciide_lookup_product(pa->pa_id, pciide_intel_products));
+
+       if (!pmf_device_register(self, rdcide_suspend, rdcide_resume))
+               aprint_error_dev(self, "couldn't establish power handler\n");
+}
+
+static bool
+rdcide_resume(device_t dv, const pmf_qual_t *qual)
+{
+       struct pciide_softc *sc = device_private(dv);
+
+       pci_conf_write(sc->sc_pc, sc->sc_tag, RDCIDE_PATR,
+           sc->sc_pm_reg[0]);
+       pci_conf_write(sc->sc_pc, sc->sc_tag, RDCIDE_PSD1ATR,
+           sc->sc_pm_reg[1]);
+       pci_conf_write(sc->sc_pc, sc->sc_tag, RDCIDE_UDCCR,
+           sc->sc_pm_reg[2]);
+       pci_conf_write(sc->sc_pc, sc->sc_tag, RDCIDE_IIOCR,
+           sc->sc_pm_reg[3]);
+
+       return true;
+}
+
+static bool
+rdcide_suspend(device_t dv, const pmf_qual_t *qual)
+{
+       struct pciide_softc *sc = device_private(dv);
+
+       sc->sc_pm_reg[0] = pci_conf_read(sc->sc_pc, sc->sc_tag,
+           RDCIDE_PATR);
+       sc->sc_pm_reg[1] = pci_conf_read(sc->sc_pc, sc->sc_tag,
+           RDCIDE_PSD1ATR);
+       sc->sc_pm_reg[2] = pci_conf_read(sc->sc_pc, sc->sc_tag,
+           RDCIDE_UDCCR);
+       sc->sc_pm_reg[3] = pci_conf_read(sc->sc_pc, sc->sc_tag,
+           RDCIDE_IIOCR);
+
+       return true;
+}
+
+static void
+rdcide_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
+{
+       struct pciide_channel *cp;
+       int channel;
+       u_int32_t patr;
+       pcireg_t interface = PCI_INTERFACE(pa->pa_class);
+
+       if (pciide_chipen(sc, pa) == 0)
+               return;
+
+       aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
+           "bus-master DMA support present");
+       pciide_mapreg_dma(sc, pa);
+       aprint_verbose("\n");
+       sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
+       if (sc->sc_dma_ok) {
+               sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
+               sc->sc_wdcdev.irqack = pciide_irqack;
+               sc->sc_wdcdev.dma_init = pciide_dma_init;
+       }
+       sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
+       sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
+       sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
+       sc->sc_wdcdev.sc_atac.atac_set_modes = rdcide_setup_channel;
+       sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
+       sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
+
+       ATADEBUG_PRINT(("rdcide_setup_chip: old PATR=0x%x",
+           pci_conf_read(sc->sc_pc, sc->sc_tag, RDCIDE_PATR)),
+           DEBUG_PROBE);
+       ATADEBUG_PRINT((", PSD1ATR=0x%x",
+           pci_conf_read(sc->sc_pc, sc->sc_tag, RDCIDE_PSD1ATR)),
+           DEBUG_PROBE);
+       ATADEBUG_PRINT((", UDCCR 0x%x",
+           pci_conf_read(sc->sc_pc, sc->sc_tag, RDCIDE_UDCCR)),
+           DEBUG_PROBE);
+       ATADEBUG_PRINT((", IIOCR 0x%x",
+           pci_conf_read(sc->sc_pc, sc->sc_tag, RDCIDE_IIOCR)),
+           DEBUG_PROBE);
+       ATADEBUG_PRINT(("\n"), DEBUG_PROBE);
+
+       wdc_allocate_regs(&sc->sc_wdcdev);
+
+       for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
+            channel++) {
+               cp = &sc->pciide_channels[channel];
+               if (pciide_chansetup(sc, channel, interface) == 0)
+                       continue;
+               patr = pci_conf_read(sc->sc_pc, sc->sc_tag, RDCIDE_PATR);
+               if ((patr & RDCIDE_PATR_EN(channel)) == 0) {
+                       aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
+                           "%s channel ignored (disabled)\n", cp->name);
+                       cp->ata_channel.ch_flags |= ATACH_DISABLED;
+                       continue;
+               }
+               pciide_mapchan(pa, cp, interface, pciide_pci_intr);
+       }
+       ATADEBUG_PRINT(("rdcide_setup_chip: PATR=0x%x",
+           pci_conf_read(sc->sc_pc, sc->sc_tag, RDCIDE_PATR)),
+           DEBUG_PROBE);
+       ATADEBUG_PRINT((", PSD1ATR=0x%x",
+           pci_conf_read(sc->sc_pc, sc->sc_tag, RDCIDE_PSD1ATR)),
+           DEBUG_PROBE);
+       ATADEBUG_PRINT((", UDCCR 0x%x",
+           pci_conf_read(sc->sc_pc, sc->sc_tag, RDCIDE_UDCCR)),
+           DEBUG_PROBE);
+       ATADEBUG_PRINT((", IIOCR 0x%x",
+           pci_conf_read(sc->sc_pc, sc->sc_tag, RDCIDE_IIOCR)),
+           DEBUG_PROBE);
+       ATADEBUG_PRINT(("\n"), DEBUG_PROBE);
+
+}
+
+static void
+rdcide_setup_channel(struct ata_channel *chp)
+{
+       u_int8_t drive;
+       u_int32_t patr, psd1atr, udccr, iiocr;
+       struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
+       struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
+       struct ata_drive_datas *drvp = cp->ata_channel.ch_drive;
+
+       patr = pci_conf_read(sc->sc_pc, sc->sc_tag, RDCIDE_PATR);
+       psd1atr = pci_conf_read(sc->sc_pc, sc->sc_tag, RDCIDE_PSD1ATR);
+       udccr = pci_conf_read(sc->sc_pc, sc->sc_tag, RDCIDE_UDCCR);
+       iiocr = pci_conf_read(sc->sc_pc, sc->sc_tag, RDCIDE_IIOCR);
+



Home | Main Index | Thread Index | Old Index