2012-07-31 19:50:31 +04:00
|
|
|
/* $NetBSD: wdc_ofisa.c,v 1.33 2012/07/31 15:50:35 bouyer Exp $ */
|
1998-02-07 03:46:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1997, 1998
|
|
|
|
* Digital Equipment Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software is furnished under license and may be used and
|
|
|
|
* copied only in accordance with the following terms and conditions.
|
|
|
|
* Subject to these conditions, you may download, copy, install,
|
|
|
|
* use, modify and distribute this software in source and/or binary
|
|
|
|
* form. No title or ownership is transferred hereby.
|
|
|
|
*
|
|
|
|
* 1) Any source code used, modified or distributed must reproduce
|
|
|
|
* and retain this copyright notice and list of conditions as
|
|
|
|
* they appear in the source file.
|
|
|
|
*
|
|
|
|
* 2) No right is granted to use any trade name, trademark, or logo of
|
|
|
|
* Digital Equipment Corporation. Neither the "Digital Equipment
|
|
|
|
* Corporation" name nor any trademark or logo of Digital Equipment
|
|
|
|
* Corporation may be used to endorse or promote products derived
|
|
|
|
* from this software without the prior written permission of
|
|
|
|
* Digital Equipment Corporation.
|
|
|
|
*
|
|
|
|
* 3) This software is provided "AS-IS" and any express or implied
|
|
|
|
* warranties, including but not limited to, any implied warranties
|
|
|
|
* of merchantability, fitness for a particular purpose, or
|
|
|
|
* non-infringement are disclaimed. In no event shall DIGITAL be
|
|
|
|
* liable for any damages whatsoever, and in particular, DIGITAL
|
|
|
|
* shall not be liable for special, indirect, consequential, or
|
|
|
|
* incidental damages or damages for lost profits, loss of
|
|
|
|
* revenue or loss of use, whether such damages arise in contract,
|
|
|
|
* negligence, tort, under statute, in equity, at law or otherwise,
|
|
|
|
* even if advised of the possibility of such damage.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OFW Attachment for 'wdc' disk controller driver
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:24:43 +03:00
|
|
|
#include <sys/cdefs.h>
|
2012-07-31 19:50:31 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: wdc_ofisa.c,v 1.33 2012/07/31 15:50:35 bouyer Exp $");
|
2001-11-13 10:24:43 +03:00
|
|
|
|
1998-02-07 03:46:45 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/device.h>
|
1998-03-21 05:06:17 +03:00
|
|
|
#include <sys/systm.h>
|
1998-02-07 03:46:45 +03:00
|
|
|
#include <sys/tty.h>
|
1998-10-12 20:09:10 +04:00
|
|
|
#include <sys/malloc.h>
|
1998-02-07 03:46:45 +03:00
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/intr.h>
|
|
|
|
#include <sys/bus.h>
|
1998-02-07 03:46:45 +03:00
|
|
|
|
|
|
|
#include <dev/ofw/openfirm.h>
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
#include <dev/ofisa/ofisavar.h>
|
|
|
|
|
|
|
|
#include <dev/ic/wdcreg.h> /* ??? */
|
1998-10-12 20:09:10 +04:00
|
|
|
#include <dev/ata/atavar.h>
|
1998-02-07 03:46:45 +03:00
|
|
|
#include <dev/ic/wdcvar.h>
|
|
|
|
|
|
|
|
struct wdc_ofisa_softc {
|
1998-10-12 20:09:10 +04:00
|
|
|
struct wdc_softc sc_wdcdev;
|
2005-02-27 03:26:58 +03:00
|
|
|
struct ata_channel *sc_chanlist[1];
|
2004-08-14 19:08:04 +04:00
|
|
|
struct ata_channel sc_channel;
|
|
|
|
struct ata_queue sc_chqueue;
|
|
|
|
struct wdc_regs wdc_regs;
|
1998-02-07 03:46:45 +03:00
|
|
|
void *sc_ih;
|
|
|
|
};
|
|
|
|
|
2008-03-18 23:46:35 +03:00
|
|
|
static int wdc_ofisa_probe(device_t, cfdata_t, void *);
|
|
|
|
static void wdc_ofisa_attach(device_t, device_t, void *);
|
1998-02-07 03:46:45 +03:00
|
|
|
|
2008-03-18 23:46:35 +03:00
|
|
|
CFATTACH_DECL_NEW(wdc_ofisa, sizeof(struct wdc_ofisa_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
wdc_ofisa_probe, wdc_ofisa_attach, NULL, NULL);
|
1998-02-07 03:46:45 +03:00
|
|
|
|
2004-08-20 03:30:09 +04:00
|
|
|
static int
|
2008-03-18 23:46:35 +03:00
|
|
|
wdc_ofisa_probe(device_t parent, cfdata_t cf, void *aux)
|
1998-02-07 03:46:45 +03:00
|
|
|
{
|
|
|
|
struct ofisa_attach_args *aa = aux;
|
2002-06-08 21:07:53 +04:00
|
|
|
static const char *const compatible_strings[] = { "pnpPNP,600", NULL };
|
1998-02-07 03:46:45 +03:00
|
|
|
int rv = 0;
|
|
|
|
|
1998-03-21 05:06:17 +03:00
|
|
|
if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
|
1998-02-07 03:46:45 +03:00
|
|
|
rv = 5;
|
|
|
|
#ifdef _WDC_OFISA_MD_MATCH
|
|
|
|
if (!rv)
|
|
|
|
rv = wdc_ofisa_md_match(parent, cf, aux);
|
|
|
|
#endif
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2004-08-20 03:30:09 +04:00
|
|
|
static void
|
2008-03-18 23:46:35 +03:00
|
|
|
wdc_ofisa_attach(device_t parent, device_t self, void *aux)
|
1998-02-07 03:46:45 +03:00
|
|
|
{
|
2006-03-29 10:51:47 +04:00
|
|
|
struct wdc_ofisa_softc *sc = device_private(self);
|
2004-08-14 19:08:04 +04:00
|
|
|
struct wdc_regs *wdr;
|
1998-02-07 03:46:45 +03:00
|
|
|
struct ofisa_attach_args *aa = aux;
|
|
|
|
struct ofisa_reg_desc reg[2];
|
|
|
|
struct ofisa_intr_desc intr;
|
|
|
|
int n;
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_handle_t ioh;
|
1998-02-07 03:46:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We're living on an ofw. We have to ask the OFW what our
|
|
|
|
* registers and interrupts properties look like.
|
|
|
|
*
|
|
|
|
* We expect exactly two register regions and one interrupt.
|
|
|
|
*/
|
|
|
|
|
2008-03-18 23:46:35 +03:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_dev = self;
|
2004-08-14 19:08:04 +04:00
|
|
|
sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
|
|
|
|
|
1998-03-21 05:06:17 +03:00
|
|
|
n = ofisa_reg_get(aa->oba.oba_phandle, reg, 2);
|
1998-02-07 03:46:45 +03:00
|
|
|
#ifdef _WDC_OFISA_MD_REG_FIXUP
|
|
|
|
n = wdc_ofisa_md_reg_fixup(parent, self, aux, reg, 2, n);
|
|
|
|
#endif
|
|
|
|
if (n != 2) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error(": error getting register data\n");
|
1998-02-07 03:46:45 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (reg[0].len != 8 || reg[1].len != 2) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error(": weird register size (%lu/%lu, expected 8/2)\n",
|
1998-03-21 05:06:17 +03:00
|
|
|
(unsigned long)reg[0].len, (unsigned long)reg[1].len);
|
1998-02-07 03:46:45 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-03-21 05:06:17 +03:00
|
|
|
n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1);
|
1998-02-07 03:46:45 +03:00
|
|
|
#ifdef _WDC_OFISA_MD_INTR_FIXUP
|
|
|
|
n = wdc_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n);
|
|
|
|
#endif
|
|
|
|
if (n != 1) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error(": error getting interrupt data\n");
|
1998-02-07 03:46:45 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
wdr->cmd_iot = (reg[0].type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
|
|
|
|
wdr->ctl_iot = (reg[1].type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
|
|
|
|
if (bus_space_map(wdr->cmd_iot, reg[0].addr, 8, 0, &ioh) ||
|
|
|
|
bus_space_map(wdr->ctl_iot, reg[1].addr, 1, 0,
|
|
|
|
&wdr->ctl_ioh)) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error(": can't map register spaces\n");
|
1998-02-07 03:46:45 +03:00
|
|
|
return;
|
|
|
|
}
|
2004-08-14 19:08:04 +04:00
|
|
|
wdr->cmd_baseioh = ioh;
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
|
|
|
|
for (n = 0; n < WDC_NREG; n++) {
|
2004-08-14 19:08:04 +04:00
|
|
|
if (bus_space_subregion(wdr->cmd_iot, ioh, n,
|
|
|
|
n == 0 ? 4 : 1, &wdr->cmd_iohs[n]) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error(": can't subregion register space\n");
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1998-02-07 03:46:45 +03:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
sc->sc_ih = isa_intr_establish(aa->ic, intr.irq, intr.share,
|
2004-08-14 19:08:04 +04:00
|
|
|
IPL_BIO, wdcintr, &sc->sc_channel);
|
1998-02-07 03:46:45 +03:00
|
|
|
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_normal("\n");
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
|
2004-08-14 19:08:04 +04:00
|
|
|
sc->sc_chanlist[0] = &sc->sc_channel;
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
|
|
|
|
sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
|
2012-07-31 19:50:31 +04:00
|
|
|
sc->sc_wdcdev.wdc_maxdrives = 2;
|
2004-08-14 19:08:04 +04:00
|
|
|
sc->sc_channel.ch_channel = 0;
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
|
2004-08-14 19:08:04 +04:00
|
|
|
sc->sc_channel.ch_queue = &sc->sc_chqueue;
|
2003-09-20 01:35:56 +04:00
|
|
|
|
2004-08-25 17:06:16 +04:00
|
|
|
wdc_init_shadow_regs(&sc->sc_channel);
|
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
wdcattach(&sc->sc_channel);
|
1998-02-07 03:46:45 +03:00
|
|
|
|
|
|
|
#if 0
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_verbose_dev(self, "registers: ");
|
1998-02-07 03:46:45 +03:00
|
|
|
ofisa_reg_print(reg, 2);
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_verbose("\n");
|
|
|
|
aprint_verbose_dev(self, "interrupts: ");
|
1998-02-07 03:46:45 +03:00
|
|
|
ofisa_intr_print(&intr, 1);
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_verbose("\n");
|
1998-02-07 03:46:45 +03:00
|
|
|
#endif
|
|
|
|
}
|