Home | History | Annotate | Line # | Download | only in isa
wdc_isa.c revision 1.37
      1  1.37      fvdl /*	$NetBSD: wdc_isa.c,v 1.37 2003/11/27 23:02:40 fvdl Exp $ */
      2   1.1       cgd 
      3   1.9   mycroft /*-
      4  1.32   mycroft  * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
      5   1.9   mycroft  * All rights reserved.
      6   1.1       cgd  *
      7   1.9   mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8   1.9   mycroft  * by Charles M. Hannum and by Onno van der Linden.
      9   1.1       cgd  *
     10   1.1       cgd  * Redistribution and use in source and binary forms, with or without
     11   1.1       cgd  * modification, are permitted provided that the following conditions
     12   1.1       cgd  * are met:
     13   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     14   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     15   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     17   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     18   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     19   1.1       cgd  *    must display the following acknowledgement:
     20   1.9   mycroft  *        This product includes software developed by the NetBSD
     21   1.9   mycroft  *        Foundation, Inc. and its contributors.
     22   1.9   mycroft  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.9   mycroft  *    contributors may be used to endorse or promote products derived
     24   1.9   mycroft  *    from this software without specific prior written permission.
     25   1.1       cgd  *
     26   1.9   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.9   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.9   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.9   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.9   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.9   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.9   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.9   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.9   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.9   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.9   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1       cgd  */
     38  1.22     lukem 
     39  1.22     lukem #include <sys/cdefs.h>
     40  1.37      fvdl __KERNEL_RCSID(0, "$NetBSD: wdc_isa.c,v 1.37 2003/11/27 23:02:40 fvdl Exp $");
     41   1.1       cgd 
     42   1.1       cgd #include <sys/param.h>
     43   1.1       cgd #include <sys/systm.h>
     44   1.1       cgd #include <sys/device.h>
     45  1.10    bouyer #include <sys/malloc.h>
     46   1.1       cgd 
     47   1.3   mycroft #include <machine/bus.h>
     48   1.1       cgd #include <machine/intr.h>
     49   1.1       cgd 
     50   1.1       cgd #include <dev/isa/isavar.h>
     51   1.1       cgd #include <dev/isa/isadmavar.h>
     52   1.3   mycroft 
     53  1.37      fvdl #include <dev/ic/wdcreg.h>
     54  1.10    bouyer #include <dev/ata/atavar.h>
     55   1.1       cgd #include <dev/ic/wdcvar.h>
     56   1.1       cgd 
     57   1.1       cgd #define	WDC_ISA_REG_NPORTS	8
     58   1.1       cgd #define	WDC_ISA_AUXREG_OFFSET	0x206
     59   1.5  drochner #define	WDC_ISA_AUXREG_NPORTS	1 /* XXX "fdc" owns ports 0x3f7/0x377 */
     60   1.1       cgd 
     61  1.15    bouyer /* options passed via the 'flags' config keyword */
     62  1.20  takemura #define WDC_OPTIONS_32			0x01 /* try to use 32bit data I/O */
     63  1.21       leo #define WDC_OPTIONS_ATA_NOSTREAM	0x04
     64  1.21       leo #define WDC_OPTIONS_ATAPI_NOSTREAM	0x08
     65   1.1       cgd 
     66   1.1       cgd struct wdc_isa_softc {
     67  1.10    bouyer 	struct	wdc_softc sc_wdcdev;
     68  1.30      matt 	struct	channel_softc *wdc_chanlist[1];
     69  1.10    bouyer 	struct	channel_softc wdc_channel;
     70  1.30      matt 	struct	channel_queue wdc_chqueue;
     71   1.7   thorpej 	isa_chipset_tag_t sc_ic;
     72   1.1       cgd 	void	*sc_ih;
     73   1.1       cgd 	int	sc_drq;
     74   1.1       cgd };
     75   1.1       cgd 
     76   1.1       cgd int	wdc_isa_probe	__P((struct device *, struct cfdata *, void *));
     77   1.1       cgd void	wdc_isa_attach	__P((struct device *, struct device *, void *));
     78   1.1       cgd 
     79  1.27   thorpej CFATTACH_DECL(wdc_isa, sizeof(struct wdc_isa_softc),
     80  1.28   thorpej     wdc_isa_probe, wdc_isa_attach, NULL, NULL);
     81   1.1       cgd 
     82  1.29   mycroft #if 0
     83  1.10    bouyer static void	wdc_isa_dma_setup __P((struct wdc_isa_softc *));
     84  1.10    bouyer static int	wdc_isa_dma_init __P((void*, int, int, void *, size_t, int));
     85  1.19    itojun static void 	wdc_isa_dma_start __P((void*, int, int));
     86  1.10    bouyer static int	wdc_isa_dma_finish __P((void*, int, int, int));
     87  1.29   mycroft #endif
     88   1.1       cgd 
     89   1.1       cgd int
     90   1.1       cgd wdc_isa_probe(parent, match, aux)
     91   1.1       cgd 	struct device *parent;
     92   1.1       cgd 	struct cfdata *match;
     93   1.1       cgd 	void *aux;
     94   1.1       cgd {
     95  1.18   thorpej 	struct channel_softc ch;
     96   1.1       cgd 	struct isa_attach_args *ia = aux;
     97  1.37      fvdl 	int result = 0, i;
     98  1.18   thorpej 
     99  1.24   thorpej 	if (ia->ia_nio < 1)
    100  1.24   thorpej 		return (0);
    101  1.24   thorpej 	if (ia->ia_nirq < 1)
    102  1.24   thorpej 		return (0);
    103  1.24   thorpej 
    104  1.24   thorpej 	if (ISA_DIRECT_CONFIG(ia))
    105  1.24   thorpej 		return (0);
    106  1.24   thorpej 
    107  1.24   thorpej 	if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT)
    108  1.24   thorpej 		return (0);
    109  1.24   thorpej 	if (ia->ia_irq[0].ir_irq == ISACF_IRQ_DEFAULT)
    110  1.24   thorpej 		return (0);
    111  1.25  gmcgarry 	if (ia->ia_ndrq > 0 && ia->ia_drq[0].ir_drq == ISACF_DRQ_DEFAULT)
    112  1.25  gmcgarry 		ia->ia_ndrq = 0;
    113  1.24   thorpej 
    114  1.18   thorpej 	memset(&ch, 0, sizeof(ch));
    115   1.1       cgd 
    116  1.10    bouyer 	ch.cmd_iot = ia->ia_iot;
    117  1.24   thorpej 
    118  1.24   thorpej 	if (bus_space_map(ch.cmd_iot, ia->ia_io[0].ir_addr,
    119  1.37      fvdl 	    WDC_ISA_REG_NPORTS, 0, &ch.cmd_baseioh))
    120   1.1       cgd 		goto out;
    121   1.1       cgd 
    122  1.37      fvdl 	for (i = 0; i < WDC_ISA_REG_NPORTS; i++) {
    123  1.37      fvdl 		if (bus_space_subregion(ch.cmd_iot, ch.cmd_baseioh, i,
    124  1.37      fvdl 		    i == 0 ? 4 : 1, &ch.cmd_iohs[i]) != 0)
    125  1.37      fvdl 			goto outunmap;
    126  1.37      fvdl 	}
    127  1.37      fvdl 
    128  1.10    bouyer 	ch.ctl_iot = ia->ia_iot;
    129  1.24   thorpej 	if (bus_space_map(ch.ctl_iot, ia->ia_io[0].ir_addr +
    130  1.24   thorpej 	    WDC_ISA_AUXREG_OFFSET, WDC_ISA_AUXREG_NPORTS, 0, &ch.ctl_ioh))
    131   1.1       cgd 		goto outunmap;
    132   1.1       cgd 
    133  1.10    bouyer 	result = wdcprobe(&ch);
    134   1.1       cgd 	if (result) {
    135  1.24   thorpej 		ia->ia_nio = 1;
    136  1.24   thorpej 		ia->ia_io[0].ir_size = WDC_ISA_REG_NPORTS;
    137  1.24   thorpej 
    138  1.24   thorpej 		ia->ia_nirq = 1;
    139  1.24   thorpej 
    140  1.24   thorpej 		ia->ia_niomem = 0;
    141   1.1       cgd 	}
    142   1.1       cgd 
    143  1.10    bouyer 	bus_space_unmap(ch.ctl_iot, ch.ctl_ioh, WDC_ISA_AUXREG_NPORTS);
    144   1.1       cgd outunmap:
    145  1.37      fvdl 	bus_space_unmap(ch.cmd_iot, ch.cmd_baseioh, WDC_ISA_REG_NPORTS);
    146   1.1       cgd out:
    147   1.1       cgd 	return (result);
    148   1.1       cgd }
    149   1.1       cgd 
    150   1.1       cgd void
    151   1.1       cgd wdc_isa_attach(parent, self, aux)
    152   1.1       cgd 	struct device *parent, *self;
    153   1.1       cgd 	void *aux;
    154   1.1       cgd {
    155   1.4   mycroft 	struct wdc_isa_softc *sc = (void *)self;
    156   1.1       cgd 	struct isa_attach_args *ia = aux;
    157  1.30      matt 	int wdc_cf_flags = self->dv_cfdata->cf_flags;
    158  1.37      fvdl 	int i;
    159   1.4   mycroft 
    160  1.10    bouyer 	sc->wdc_channel.cmd_iot = ia->ia_iot;
    161  1.10    bouyer 	sc->wdc_channel.ctl_iot = ia->ia_iot;
    162   1.7   thorpej 	sc->sc_ic = ia->ia_ic;
    163  1.24   thorpej 	if (bus_space_map(sc->wdc_channel.cmd_iot, ia->ia_io[0].ir_addr,
    164  1.37      fvdl 	    WDC_ISA_REG_NPORTS, 0, &sc->wdc_channel.cmd_baseioh) ||
    165  1.10    bouyer 	    bus_space_map(sc->wdc_channel.ctl_iot,
    166  1.24   thorpej 	      ia->ia_io[0].ir_addr + WDC_ISA_AUXREG_OFFSET,
    167  1.24   thorpej 	      WDC_ISA_AUXREG_NPORTS, 0, &sc->wdc_channel.ctl_ioh)) {
    168  1.30      matt 		printf(": couldn't map registers\n");
    169  1.30      matt 		return;
    170   1.1       cgd 	}
    171  1.37      fvdl 
    172  1.37      fvdl 	for (i = 0; i < WDC_ISA_REG_NPORTS; i++) {
    173  1.37      fvdl 		if (bus_space_subregion(sc->wdc_channel.cmd_iot,
    174  1.37      fvdl 		      sc->wdc_channel.cmd_baseioh, i, i == 0 ? 4 : 1,
    175  1.37      fvdl 		      &sc->wdc_channel.cmd_iohs[i]) != 0) {
    176  1.37      fvdl 			printf(": couldn't subregion registers\n");
    177  1.37      fvdl 			return;
    178  1.37      fvdl 		}
    179  1.37      fvdl 	}
    180  1.37      fvdl 
    181  1.10    bouyer 	sc->wdc_channel.data32iot = sc->wdc_channel.cmd_iot;
    182  1.37      fvdl 	sc->wdc_channel.data32ioh = sc->wdc_channel.cmd_iohs[0];
    183   1.1       cgd 
    184  1.24   thorpej 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
    185  1.24   thorpej 	    IST_EDGE, IPL_BIO, wdcintr, &sc->wdc_channel);
    186   1.1       cgd 
    187  1.29   mycroft #if 0
    188  1.24   thorpej 	if (ia->ia_ndrq > 0 && ia->ia_drq[0].ir_drq != ISACF_DRQ_DEFAULT) {
    189  1.24   thorpej 		sc->sc_drq = ia->ia_drq[0].ir_drq;
    190   1.1       cgd 
    191  1.10    bouyer 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA;
    192  1.10    bouyer 		sc->sc_wdcdev.dma_arg = sc;
    193  1.10    bouyer 		sc->sc_wdcdev.dma_init = wdc_isa_dma_init;
    194  1.10    bouyer 		sc->sc_wdcdev.dma_start = wdc_isa_dma_start;
    195  1.10    bouyer 		sc->sc_wdcdev.dma_finish = wdc_isa_dma_finish;
    196  1.10    bouyer 		wdc_isa_dma_setup(sc);
    197   1.6       cgd 	}
    198  1.29   mycroft #endif
    199  1.15    bouyer 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_PREATA;
    200  1.30      matt 	if (wdc_cf_flags & WDC_OPTIONS_32)
    201  1.15    bouyer 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA32;
    202  1.30      matt 	if (wdc_cf_flags & WDC_OPTIONS_ATA_NOSTREAM)
    203  1.21       leo 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_ATA_NOSTREAM;
    204  1.30      matt 	if (wdc_cf_flags & WDC_OPTIONS_ATAPI_NOSTREAM)
    205  1.21       leo 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_ATAPI_NOSTREAM;
    206  1.30      matt 
    207  1.12    bouyer 	sc->sc_wdcdev.PIO_cap = 0;
    208  1.30      matt 	sc->wdc_chanlist[0] = &sc->wdc_channel;
    209  1.30      matt 	sc->sc_wdcdev.channels = sc->wdc_chanlist;
    210  1.10    bouyer 	sc->sc_wdcdev.nchannels = 1;
    211  1.10    bouyer 	sc->wdc_channel.channel = 0;
    212  1.10    bouyer 	sc->wdc_channel.wdc = &sc->sc_wdcdev;
    213  1.30      matt 	sc->wdc_channel.ch_queue = &sc->wdc_chqueue;
    214  1.30      matt 
    215  1.30      matt 	printf("\n");
    216  1.30      matt 
    217  1.36    bouyer 	wdcattach(&sc->wdc_channel);
    218   1.1       cgd }
    219   1.1       cgd 
    220  1.29   mycroft #if 0
    221   1.1       cgd static void
    222  1.10    bouyer wdc_isa_dma_setup(sc)
    223  1.10    bouyer 	struct wdc_isa_softc *sc;
    224   1.1       cgd {
    225  1.16   thorpej 	bus_size_t maxsize;
    226  1.16   thorpej 
    227  1.16   thorpej 	if ((maxsize = isa_dmamaxsize(sc->sc_ic, sc->sc_drq)) < MAXPHYS) {
    228  1.17   thorpej 		printf("%s: max DMA size %lu is less than required %d\n",
    229  1.17   thorpej 		    sc->sc_wdcdev.sc_dev.dv_xname, (u_long)maxsize, MAXPHYS);
    230  1.31      fvdl 		sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_DMA;
    231  1.31      fvdl 		return;
    232  1.31      fvdl 	}
    233  1.31      fvdl 
    234  1.31      fvdl 	if (isa_drq_alloc(sc->sc_ic, sc->sc_drq) != 0) {
    235  1.31      fvdl 		printf("%s: can't reserve drq %d\n",
    236  1.31      fvdl 		    sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
    237  1.16   thorpej 		sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_DMA;
    238  1.16   thorpej 		return;
    239  1.16   thorpej 	}
    240  1.16   thorpej 
    241   1.7   thorpej 	if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
    242   1.1       cgd 	    MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    243   1.1       cgd 		printf("%s: can't create map for drq %d\n",
    244   1.1       cgd 		    sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
    245  1.10    bouyer 		sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_DMA;
    246   1.1       cgd 	}
    247   1.1       cgd }
    248   1.1       cgd 
    249  1.10    bouyer static int
    250  1.10    bouyer wdc_isa_dma_init(v, channel, drive, databuf, datalen, read)
    251  1.10    bouyer 	void *v;
    252  1.10    bouyer 	void *databuf;
    253  1.10    bouyer 	size_t datalen;
    254   1.1       cgd 	int read;
    255   1.1       cgd {
    256  1.10    bouyer 	struct wdc_isa_softc *sc = v;
    257   1.1       cgd 
    258  1.13   mycroft 	isa_dmastart(sc->sc_ic, sc->sc_drq, databuf, datalen, NULL,
    259  1.13   mycroft 	    (read ? DMAMODE_READ : DMAMODE_WRITE) | DMAMODE_DEMAND,
    260   1.1       cgd 	    BUS_DMA_NOWAIT);
    261  1.10    bouyer 	return 0;
    262   1.1       cgd }
    263   1.1       cgd 
    264   1.1       cgd static void
    265  1.19    itojun wdc_isa_dma_start(v, channel, drive)
    266  1.10    bouyer 	void *v;
    267  1.10    bouyer 	int channel, drive;
    268  1.10    bouyer {
    269  1.10    bouyer 	/* nothing to do */
    270  1.10    bouyer }
    271  1.10    bouyer 
    272  1.10    bouyer static int
    273  1.10    bouyer wdc_isa_dma_finish(v, channel, drive, read)
    274  1.10    bouyer 	void *v;
    275  1.10    bouyer 	int channel, drive;
    276  1.10    bouyer 	int read;
    277   1.1       cgd {
    278  1.10    bouyer 	struct wdc_isa_softc *sc = v;
    279   1.1       cgd 
    280   1.7   thorpej 	isa_dmadone(sc->sc_ic, sc->sc_drq);
    281  1.10    bouyer 	return 0;
    282   1.1       cgd }
    283  1.29   mycroft #endif
    284