Home | History | Annotate | Line # | Download | only in pnpbios
      1  1.35   thorpej /*	$NetBSD: pciide_pnpbios.c,v 1.35 2023/12/20 15:00:08 thorpej Exp $	*/
      2   1.2   thorpej 
      3   1.1     soren /*
      4   1.1     soren  * Copyright (c) 1999 Soren S. Jorvang.  All rights reserved.
      5   1.1     soren  *
      6   1.1     soren  * Redistribution and use in source and binary forms, with or without
      7   1.1     soren  * modification, are permitted provided that the following conditions
      8   1.1     soren  * are met:
      9   1.1     soren  * 1. Redistributions of source code must retain the above copyright
     10   1.1     soren  *    notice, this list of conditions, and the following disclaimer.
     11   1.1     soren  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1     soren  *    notice, this list of conditions and the following disclaimer in the
     13   1.1     soren  *    documentation and/or other materials provided with the distribution.
     14   1.1     soren  *
     15   1.1     soren  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16   1.1     soren  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17   1.1     soren  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18   1.1     soren  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19   1.1     soren  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20   1.1     soren  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21   1.1     soren  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22   1.1     soren  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23   1.1     soren  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24   1.1     soren  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25   1.1     soren  * SUCH DAMAGE.
     26   1.1     soren  */
     27   1.1     soren 
     28   1.1     soren /*
     29   1.1     soren  * Handle the weird "almost PCI" IDE on Toshiba Porteges.
     30   1.1     soren  */
     31   1.4     lukem 
     32   1.4     lukem #include <sys/cdefs.h>
     33  1.35   thorpej __KERNEL_RCSID(0, "$NetBSD: pciide_pnpbios.c,v 1.35 2023/12/20 15:00:08 thorpej Exp $");
     34   1.1     soren 
     35   1.1     soren #include <sys/param.h>
     36   1.1     soren #include <sys/systm.h>
     37   1.1     soren #include <sys/device.h>
     38   1.1     soren 
     39  1.27    dyoung #include <sys/bus.h>
     40   1.1     soren 
     41  1.11  christos #include <dev/ic/wdcreg.h>
     42   1.1     soren #include <dev/isa/isavar.h>
     43   1.1     soren #include <dev/isa/isadmavar.h>
     44   1.1     soren 
     45   1.1     soren #include <i386/pnpbios/pnpbiosvar.h>
     46   1.1     soren 
     47   1.1     soren #include <dev/pci/pcireg.h>
     48   1.1     soren #include <dev/pci/pcivar.h>
     49   1.1     soren #include <dev/pci/pcidevs.h>
     50   1.1     soren 
     51   1.1     soren #include <dev/pci/pciidereg.h>
     52   1.1     soren #include <dev/pci/pciidevar.h>
     53   1.1     soren 
     54  1.25      cube static int	pciide_pnpbios_match(device_t, cfdata_t, void *);
     55  1.25      cube static void	pciide_pnpbios_attach(device_t, device_t, void *);
     56   1.1     soren 
     57   1.1     soren extern void	pciide_channel_dma_setup(struct pciide_channel *);
     58   1.1     soren extern int	pciide_dma_init(void *, int, int, void *, size_t, int);
     59   1.3     soren extern void	pciide_dma_start(void *, int, int);
     60   1.1     soren extern int	pciide_dma_finish(void *, int, int, int);
     61   1.1     soren extern int	pciide_compat_intr (void *);
     62   1.1     soren 
     63  1.25      cube CFATTACH_DECL_NEW(pciide_pnpbios, sizeof(struct pciide_softc),
     64   1.7   thorpej     pciide_pnpbios_match, pciide_pnpbios_attach, NULL, NULL);
     65   1.1     soren 
     66   1.1     soren int
     67  1.25      cube pciide_pnpbios_match(device_t parent, cfdata_t match, void *aux)
     68   1.1     soren {
     69   1.1     soren 	struct pnpbiosdev_attach_args *aa = aux;
     70   1.1     soren 
     71   1.1     soren 	if (strcmp(aa->idstr, "TOS7300") == 0)
     72   1.1     soren 		return 1;
     73   1.1     soren 
     74   1.1     soren 	return 0;
     75   1.1     soren }
     76   1.1     soren 
     77   1.1     soren void
     78  1.25      cube pciide_pnpbios_attach(device_t parent, device_t self, void *aux)
     79   1.1     soren {
     80  1.25      cube 	struct pciide_softc *sc = device_private(self);
     81   1.1     soren 	struct pnpbiosdev_attach_args *aa = aux;
     82   1.1     soren 	struct pciide_channel *cp;
     83  1.17   thorpej 	struct ata_channel *wdc_cp;
     84  1.17   thorpej 	struct wdc_regs *wdr;
     85   1.1     soren 	bus_space_tag_t compat_iot;
     86  1.11  christos 	bus_space_handle_t cmd_baseioh, ctl_ioh;
     87  1.22    bouyer 	int i, drive, size;
     88  1.26    cegger 	uint8_t idedma_ctl;
     89   1.1     soren 
     90  1.25      cube 	sc->sc_wdcdev.sc_atac.atac_dev = self;
     91  1.25      cube 
     92  1.22    bouyer 	aprint_naive(": disk controller\n");
     93  1.22    bouyer 	aprint_normal("\n");
     94   1.2   thorpej 	pnpbios_print_devres(self, aa);
     95   1.2   thorpej 
     96  1.25      cube 	aprint_normal_dev(self, "Toshiba Extended IDE Controller\n");
     97   1.1     soren 
     98   1.1     soren 	if (pnpbios_io_map(aa->pbt, aa->resc, 2, &sc->sc_dma_iot,
     99   1.1     soren 	    &sc->sc_dma_ioh) != 0) {
    100  1.25      cube 		aprint_error_dev(self, "unable to map DMA registers\n");
    101   1.1     soren 		return;
    102   1.1     soren 	}
    103   1.1     soren 	if (pnpbios_io_map(aa->pbt, aa->resc, 0, &compat_iot,
    104  1.11  christos 	    &cmd_baseioh) != 0) {
    105  1.25      cube 		aprint_error_dev(self, "unable to map command registers\n");
    106   1.1     soren 		return;
    107   1.1     soren 	}
    108   1.1     soren 	if (pnpbios_io_map(aa->pbt, aa->resc, 1, &compat_iot,
    109   1.1     soren 	    &ctl_ioh) != 0) {
    110  1.25      cube 		aprint_error_dev(self, "unable to map control register\n");
    111   1.1     soren 		return;
    112   1.1     soren 	}
    113   1.1     soren 
    114   1.1     soren 	sc->sc_dmat = &pci_bus_dma_tag;
    115   1.1     soren 
    116  1.22    bouyer 	cp = &sc->pciide_channels[0];
    117  1.22    bouyer 	sc->wdc_chanarray[0] = &cp->ata_channel;
    118  1.22    bouyer 	cp->ata_channel.ch_channel = 0;
    119  1.22    bouyer 	cp->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    120  1.22    bouyer 
    121   1.1     soren 	sc->sc_dma_ok = 1;
    122  1.22    bouyer 	for (i = 0; i < IDEDMA_NREGS; i++) {
    123  1.22    bouyer 		size = 4;
    124  1.22    bouyer 		if (size > (IDEDMA_SCH_OFFSET - i))
    125  1.22    bouyer 			size = IDEDMA_SCH_OFFSET - i;
    126  1.22    bouyer 		if (bus_space_subregion(sc->sc_dma_iot, sc->sc_dma_ioh,
    127  1.22    bouyer 		    i, size, &cp->dma_iohs[i]) != 0) {
    128  1.25      cube 			aprint_error_dev(self, "can't subregion offset %d "
    129  1.25      cube 			    "size %lu", i, (u_long)size);
    130  1.22    bouyer 			return;
    131  1.22    bouyer 		}
    132  1.22    bouyer 	}
    133  1.22    bouyer 	sc->sc_dma_maxsegsz = IDEDMA_BYTE_COUNT_MAX;
    134  1.22    bouyer 	sc->sc_dma_boundary = IDEDMA_BYTE_COUNT_ALIGN;
    135   1.1     soren 	sc->sc_wdcdev.dma_arg = sc;
    136   1.1     soren 	sc->sc_wdcdev.dma_init = pciide_dma_init;
    137   1.1     soren 	sc->sc_wdcdev.dma_start = pciide_dma_start;
    138   1.1     soren 	sc->sc_wdcdev.dma_finish = pciide_dma_finish;
    139  1.22    bouyer 	sc->sc_wdcdev.irqack = pciide_irqack;
    140  1.22    bouyer 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
    141  1.19   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    142  1.19   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    143  1.30    bouyer 	sc->sc_wdcdev.wdc_maxdrives = 2;
    144  1.19   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    145  1.22    bouyer 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    146  1.22    bouyer 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 0;		/* XXX */
    147  1.22    bouyer 	sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;	/* XXX */
    148   1.1     soren 
    149  1.17   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    150  1.17   thorpej 
    151  1.17   thorpej 	wdc_cp = &cp->ata_channel;
    152  1.18   thorpej 	wdr = CHAN_TO_WDC_REGS(wdc_cp);
    153  1.17   thorpej 	wdr->cmd_iot = compat_iot;
    154  1.17   thorpej 	wdr->cmd_baseioh = cmd_baseioh;
    155  1.11  christos 
    156  1.11  christos 	for (i = 0; i < WDC_NREG; i++) {
    157  1.17   thorpej 		if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh, i,
    158  1.17   thorpej 		    i == 0 ? 4 : 1, &wdr->cmd_iohs[i]) != 0) {
    159  1.25      cube 			    aprint_error_dev(self, "unable to subregion "
    160  1.25      cube 				"control register\n");
    161  1.11  christos 			    return;
    162  1.11  christos 		}
    163  1.11  christos 	}
    164  1.32  jdolecek 	wdc_init_shadow_regs(wdr);
    165  1.11  christos 
    166  1.17   thorpej 	wdr->ctl_iot = wdr->data32iot = compat_iot;
    167  1.17   thorpej 	wdr->ctl_ioh = wdr->data32ioh = ctl_ioh;
    168   1.1     soren 
    169   1.1     soren 	cp->compat = 1;
    170   1.1     soren 
    171   1.1     soren 	cp->ih = pnpbios_intr_establish(aa->pbt, aa->resc, 0, IPL_BIO,
    172   1.1     soren 					pciide_compat_intr, cp);
    173   1.1     soren 
    174  1.10    bouyer 	wdcattach(wdc_cp);
    175   1.8   mycroft 
    176  1.22    bouyer 	idedma_ctl = 0;
    177  1.30    bouyer 	for (drive = 0; drive < cp->ata_channel.ch_ndrives; drive++) {
    178  1.22    bouyer 		/*
    179  1.22    bouyer 		 * we have not probed the drives yet,
    180  1.34   msaitoh 		 * allocate resources for all of them.
    181  1.22    bouyer 		 */
    182  1.22    bouyer 		if (pciide_dma_table_setup(sc, 0, drive) != 0) {
    183  1.22    bouyer 			/* Abort DMA setup */
    184  1.22    bouyer 			aprint_error(
    185  1.22    bouyer 			    "%s:%d:%d: can't allocate DMA maps, "
    186  1.22    bouyer 			    "using PIO transfers\n",
    187  1.25      cube 			    device_xname(self), 0, drive);
    188  1.22    bouyer 			sc->sc_dma_ok = 0;
    189  1.22    bouyer 			sc->sc_wdcdev.sc_atac.atac_cap &= ~ATAC_CAP_DMA;
    190  1.22    bouyer 			sc->sc_wdcdev.irqack = NULL;
    191  1.22    bouyer 			idedma_ctl = 0;
    192  1.22    bouyer 			break;
    193  1.22    bouyer 		}
    194  1.22    bouyer 		idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    195  1.22    bouyer 	}
    196  1.22    bouyer 	if (idedma_ctl != 0) {
    197  1.22    bouyer 		/* Add software bits in status register */
    198  1.22    bouyer 		bus_space_write_1(sc->sc_dma_iot,
    199  1.22    bouyer 		    cp->dma_iohs[IDEDMA_CTL], 0, idedma_ctl);
    200  1.22    bouyer 	}
    201   1.1     soren }
    202