wdc_mb.c revision 1.2
1/* $NetBSD: wdc_mb.c,v 1.2 1998/08/15 10:11:01 mycroft Exp $ */ 2 3/*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum and by Onno van der Linden. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39#include <sys/types.h> 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/device.h> 43 44#include <machine/cpu.h> 45#include <machine/bus.h> 46#include <machine/iomap.h> 47#include <machine/mfp.h> 48#include <machine/dma.h> 49 50#include <dev/ic/wdcvar.h> 51 52#include <m68k/asm_single.h> 53 54#include <atari/dev/ym2149reg.h> 55#include <atari/atari/device.h> 56 57/* 58 * XXX This code currently doesn't even try to allow 32-bit data port use. 59 */ 60static int claim_hw __P((void *, int)); 61static void free_hw __P((void *)); 62 63struct wdc_mb_softc { 64 struct wdc_softc sc_wdcdev; 65 struct wdc_attachment_data sc_ad; 66 void *sc_ih; 67}; 68 69int wdc_mb_probe __P((struct device *, struct cfdata *, void *)); 70void wdc_mb_attach __P((struct device *, struct device *, void *)); 71 72struct cfattach wdc_mb_ca = { 73 sizeof(struct wdc_mb_softc), wdc_mb_probe, wdc_mb_attach 74}; 75 76int 77wdc_mb_probe(parent, cfp, aux) 78 struct device *parent; 79 struct cfdata *cfp; 80 void *aux; 81{ 82#if 0 /* XXX memset */ 83 struct wdc_attachment_data ad = { 0 }; 84#else /* XXX memset */ 85 struct wdc_attachment_data ad; 86#endif /* XXX memset */ 87 int result = 0; 88 u_char sv_ierb; 89 90#if 0 /* XXX memset */ 91#else /* XXX memset */ 92 bzero(&ad, sizeof ad); 93#endif /* XXX memset */ 94 95 if ((machineid & ATARI_TT) || strcmp("wdc", aux) || cfp->cf_unit != 0) 96 return 0; 97 if (!atari_realconfig) 98 return 0; 99 100 ad.iot = ad.auxiot = mb_alloc_bus_space_tag(); 101 if (ad.iot == NULL) 102 return 0; 103 ad.iot->stride = 2; 104 ad.iot->wo_1 = 1; 105 106 if (bus_space_map(ad.iot, 0xfff00000, 0x40, 0, &ad.ioh)) 107 return 0; 108 if (bus_space_subregion(ad.iot, ad.ioh, 0x38, 1, &ad.auxioh)) 109 return 0; 110 111 /* 112 * Make sure IDE interrupts are disabled during probing. 113 */ 114 sv_ierb = MFP->mf_ierb; 115 MFP->mf_ierb &= ~IB_DINT; 116 117 /* 118 * Make sure that IDE is turned on on the Falcon. 119 */ 120 if (machineid & ATARI_FALCON) 121 ym2149_ser2(0); 122 123 result = wdcprobe(&ad); 124 125 MFP->mf_ierb = sv_ierb; 126 127 bus_space_unmap(ad.iot, ad.ioh, 0x40); 128 mb_free_bus_space_tag(ad.iot); 129 130 return (result); 131} 132 133void 134wdc_mb_attach(parent, self, aux) 135 struct device *parent, *self; 136 void *aux; 137{ 138 struct wdc_mb_softc *sc = (void *)self; 139 140 printf("\n"); 141 142 sc->sc_ad.iot = sc->sc_ad.auxiot = mb_alloc_bus_space_tag(); 143 sc->sc_ad.iot->stride = 2; 144 sc->sc_ad.iot->wo_1 = 1; 145 if (bus_space_map(sc->sc_ad.iot, 0xfff00000, 0x40, 0, 146 &sc->sc_ad.ioh)) { 147 printf("%s: couldn't map registers\n", 148 sc->sc_wdcdev.sc_dev.dv_xname); 149 return; 150 } 151 if (bus_space_subregion(sc->sc_ad.iot, sc->sc_ad.ioh, 0x38, 1, 152 &sc->sc_ad.auxioh)) 153 return; 154 155 /* 156 * Play a nasty trick here. Normally we only manipulate the 157 * interrupt *mask*. However to defeat wd_get_parms(), we 158 * disable the interrupts here using the *enable* register. 159 */ 160 MFP->mf_ierb &= ~IB_DINT; 161 162 /* 163 * XXX: Is this true on all atari's?? 164 */ 165 sc->sc_wdcdev.sc_flags |= WDCF_SINGLE; 166 167 sc->sc_ad.cap |= WDC_CAPABILITY_HWLOCK; 168 sc->sc_ad.claim_hw = &claim_hw; 169 sc->sc_ad.free_hw = &free_hw; 170 171 wdcattach(&sc->sc_wdcdev, &sc->sc_ad); 172 173 /* 174 * Setup & enable disk related interrupts. 175 */ 176 MFP->mf_ierb |= IB_DINT; 177 MFP->mf_iprb &= ~IB_DINT; 178 MFP->mf_imrb |= IB_DINT; 179} 180 181/* 182 * Hardware locking 183 */ 184static int wd_lock; 185 186static int 187claim_hw(softc, maysleep) 188void *softc; 189int maysleep; 190{ 191 void wdcrestart __P((void *)); 192 193 if (wd_lock != DMA_LOCK_GRANT) { 194 if (wd_lock == DMA_LOCK_REQ) { 195 /* 196 * ST_DMA access is being claimed. 197 */ 198 return 0; 199 } 200 if (!st_dmagrab((dma_farg)wdcintr, 201 (dma_farg)(maysleep ? NULL : wdcrestart), softc, 202 &wd_lock, 1)) 203 return 0; 204 } 205 return 1; 206} 207 208static void 209free_hw(softc) 210void *softc; 211{ 212 /* 213 * Flush pending interrupts before giving-up lock 214 */ 215 single_inst_bclr_b(MFP->mf_iprb, IB_DINT); 216 217 /* 218 * Only free the lock on a Falcon. On the Hades, keep it. 219 */ 220/* if (machineid & ATARI_FALCON) */ 221 st_dmafree(softc, &wd_lock); 222} 223