1 1.12 thorpej /* $NetBSD: pcctwo_68k.c,v 1.12 2024/01/19 03:59:47 thorpej Exp $ */ 2 1.1 scw 3 1.1 scw /*- 4 1.1 scw * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc. 5 1.1 scw * All rights reserved. 6 1.1 scw * 7 1.1 scw * This code is derived from software contributed to The NetBSD Foundation 8 1.1 scw * by Steve C. Woodford. 9 1.1 scw * 10 1.1 scw * Redistribution and use in source and binary forms, with or without 11 1.1 scw * modification, are permitted provided that the following conditions 12 1.1 scw * are met: 13 1.1 scw * 1. Redistributions of source code must retain the above copyright 14 1.1 scw * notice, this list of conditions and the following disclaimer. 15 1.1 scw * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 scw * notice, this list of conditions and the following disclaimer in the 17 1.1 scw * documentation and/or other materials provided with the distribution. 18 1.1 scw * 19 1.1 scw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 scw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 scw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 scw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 scw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 scw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 scw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 scw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 scw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 scw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 scw * POSSIBILITY OF SUCH DAMAGE. 30 1.1 scw */ 31 1.1 scw 32 1.1 scw /* 33 1.1 scw * PCCchip2 and MCchip Mvme68k Front End Driver 34 1.1 scw */ 35 1.4 lukem 36 1.4 lukem #include <sys/cdefs.h> 37 1.12 thorpej __KERNEL_RCSID(0, "$NetBSD: pcctwo_68k.c,v 1.12 2024/01/19 03:59:47 thorpej Exp $"); 38 1.12 thorpej 39 1.12 thorpej #include "opt_mvmeconf.h" 40 1.1 scw 41 1.1 scw #include <sys/param.h> 42 1.1 scw #include <sys/kernel.h> 43 1.1 scw #include <sys/systm.h> 44 1.1 scw #include <sys/device.h> 45 1.1 scw 46 1.1 scw #include <machine/cpu.h> 47 1.1 scw #include <machine/bus.h> 48 1.1 scw 49 1.1 scw #include <mvme68k/dev/mainbus.h> 50 1.1 scw #include <mvme68k/mvme68k/isr.h> 51 1.1 scw 52 1.1 scw #include <dev/mvme/pcctworeg.h> 53 1.1 scw #include <dev/mvme/pcctwovar.h> 54 1.1 scw 55 1.8 tsutsui #include "ioconf.h" 56 1.8 tsutsui 57 1.1 scw /* 58 1.1 scw * Autoconfiguration stuff. 59 1.1 scw */ 60 1.10 chs void pcctwoattach(device_t, device_t, void *); 61 1.10 chs int pcctwomatch(device_t, cfdata_t, void *); 62 1.1 scw 63 1.10 chs CFATTACH_DECL_NEW(pcctwo, sizeof(struct pcctwo_softc), 64 1.3 thorpej pcctwomatch, pcctwoattach, NULL, NULL); 65 1.1 scw 66 1.1 scw 67 1.1 scw #if defined(MVME167) || defined(MVME177) 68 1.1 scw /* 69 1.1 scw * Devices that live on the PCCchip2, attached in this order. 70 1.1 scw */ 71 1.5 scw static const struct pcctwo_device pcctwo_devices[] = { 72 1.1 scw {"clock", 0}, 73 1.1 scw {"clmpcc", PCCTWO_SCC_OFF}, 74 1.1 scw {"ie", PCCTWO_IE_OFF}, 75 1.1 scw {"osiop", PCCTWO_NCRSC_OFF}, 76 1.1 scw {"lpt", PCCTWO_LPT_OFF}, 77 1.1 scw {NULL, 0} 78 1.1 scw }; 79 1.1 scw 80 1.1 scw static int pcctwo_vec2icsr_1x7[] = { 81 1.1 scw VEC2ICSR(PCC2REG_PRT_BUSY_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR), 82 1.1 scw VEC2ICSR(PCC2REG_PRT_PE_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR), 83 1.1 scw VEC2ICSR(PCC2REG_PRT_SEL_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR), 84 1.1 scw VEC2ICSR(PCC2REG_PRT_FAULT_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR), 85 1.1 scw VEC2ICSR(PCC2REG_PRT_ACK_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR), 86 1.1 scw VEC2ICSR(PCC2REG_SCSI_ICSR, 0), 87 1.1 scw VEC2ICSR(PCC2REG_ETH_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR), 88 1.1 scw VEC2ICSR(PCC2REG_ETH_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR), 89 1.1 scw VEC2ICSR(PCC2REG_TIMER2_ICSR, PCCTWO_ICR_ICLR), 90 1.1 scw VEC2ICSR(PCC2REG_TIMER1_ICSR, PCCTWO_ICR_ICLR), 91 1.1 scw VEC2ICSR(PCC2REG_GPIO_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR), 92 1.1 scw -1, 93 1.1 scw VEC2ICSR(PCC2REG_SCC_RX_ICSR, 0), 94 1.1 scw VEC2ICSR(PCC2REG_SCC_MODEM_ICSR, 0), 95 1.1 scw VEC2ICSR(PCC2REG_SCC_TX_ICSR, 0), 96 1.1 scw VEC2ICSR(PCC2REG_SCC_RX_ICSR, 0) 97 1.1 scw }; 98 1.1 scw #endif 99 1.1 scw 100 1.1 scw #if defined(MVME162) || defined(MVME172) 101 1.1 scw /* 102 1.1 scw * Devices that live on the MCchip, attached in this order. 103 1.1 scw */ 104 1.5 scw static const struct pcctwo_device mcchip_devices[] = { 105 1.1 scw {"clock", 0}, 106 1.1 scw {"zsc", MCCHIP_ZS0_OFF}, 107 1.1 scw {"zsc", MCCHIP_ZS1_OFF}, 108 1.1 scw {"ie", PCCTWO_IE_OFF}, 109 1.1 scw {"osiop", PCCTWO_NCRSC_OFF}, 110 1.1 scw {NULL, 0} 111 1.1 scw }; 112 1.1 scw 113 1.1 scw static int pcctwo_vec2icsr_1x2[] = { 114 1.1 scw -1, 115 1.1 scw -1, 116 1.1 scw -1, 117 1.1 scw VEC2ICSR(MCCHIPREG_TIMER4_ICSR, PCCTWO_ICR_ICLR), 118 1.1 scw VEC2ICSR(MCCHIPREG_TIMER3_ICSR, PCCTWO_ICR_ICLR), 119 1.1 scw VEC2ICSR(PCC2REG_SCSI_ICSR, 0), 120 1.1 scw VEC2ICSR(PCC2REG_ETH_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR), 121 1.1 scw VEC2ICSR(PCC2REG_ETH_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR), 122 1.1 scw VEC2ICSR(PCC2REG_TIMER2_ICSR, PCCTWO_ICR_ICLR), 123 1.1 scw VEC2ICSR(PCC2REG_TIMER1_ICSR, PCCTWO_ICR_ICLR), 124 1.1 scw -1, 125 1.1 scw VEC2ICSR(MCCHIPREG_PARERR_ICSR, PCCTWO_ICR_ICLR), 126 1.1 scw VEC2ICSR(MCCHIPREG_SCC_ICSR, 0), 127 1.1 scw VEC2ICSR(MCCHIPREG_SCC_ICSR, 0), 128 1.1 scw VEC2ICSR(MCCHIPREG_ABORT_ICSR, PCCTWO_ICR_ICLR), 129 1.1 scw -1 130 1.1 scw }; 131 1.1 scw 132 1.1 scw static int pcctwoabortintr(void *); 133 1.1 scw void pcctwosoftintrinit(void); 134 1.1 scw static int pcctwosoftintr(void *); 135 1.7 ad #ifdef notyet 136 1.1 scw static void pcctwosoftintrassert(void); 137 1.1 scw #endif 138 1.7 ad #endif 139 1.1 scw 140 1.1 scw static void pcctwoisrlink(void *, int (*)(void *), void *, 141 1.1 scw int, int, struct evcnt *); 142 1.1 scw static void pcctwoisrunlink(void *, int); 143 1.1 scw static struct evcnt *pcctwoisrevcnt(void *, int); 144 1.1 scw 145 1.1 scw 146 1.1 scw /* ARGSUSED */ 147 1.1 scw int 148 1.10 chs pcctwomatch(device_t parent, cfdata_t cf, void *aux) 149 1.1 scw { 150 1.1 scw struct mainbus_attach_args *ma; 151 1.1 scw bus_space_handle_t bh; 152 1.8 tsutsui uint8_t cid; 153 1.1 scw 154 1.10 chs ma = aux; 155 1.1 scw 156 1.1 scw /* There can be only one. */ 157 1.1 scw if (sys_pcctwo || strcmp(ma->ma_name, pcctwo_cd.cd_name)) 158 1.8 tsutsui return 0; 159 1.1 scw 160 1.1 scw /* 161 1.1 scw * Grab the Chip's ID 162 1.1 scw */ 163 1.1 scw bus_space_map(ma->ma_bust, PCCTWO_REG_OFF + ma->ma_offset, 164 1.1 scw PCC2REG_SIZE, 0, &bh); 165 1.1 scw cid = bus_space_read_1(ma->ma_bust, bh, PCC2REG_CHIP_ID); 166 1.1 scw bus_space_unmap(ma->ma_bust, bh, PCC2REG_SIZE); 167 1.1 scw 168 1.1 scw #if defined(MVME167) || defined(MVME177) 169 1.1 scw if ((machineid == MVME_167 || machineid == MVME_177) && 170 1.1 scw cid == PCCTWO_CHIP_ID_PCC2) 171 1.8 tsutsui return 1; 172 1.1 scw #endif 173 1.1 scw #if defined(MVME162) || defined(MVME172) 174 1.1 scw if ((machineid == MVME_162 || machineid == MVME_172) && 175 1.1 scw cid == PCCTWO_CHIP_ID_MCCHIP) 176 1.8 tsutsui return 1; 177 1.1 scw #endif 178 1.1 scw 179 1.8 tsutsui return 0; 180 1.1 scw } 181 1.1 scw 182 1.1 scw /* ARGSUSED */ 183 1.1 scw void 184 1.10 chs pcctwoattach(device_t parent, device_t self, void *aux) 185 1.1 scw { 186 1.1 scw struct mainbus_attach_args *ma; 187 1.1 scw struct pcctwo_softc *sc; 188 1.5 scw const struct pcctwo_device *pd = NULL; 189 1.8 tsutsui uint8_t cid; 190 1.1 scw 191 1.10 chs sc = sys_pcctwo = device_private(self); 192 1.11 martin sc->sc_dev = self; 193 1.10 chs ma = aux; 194 1.1 scw 195 1.1 scw /* Get a handle to the PCCChip2's registers */ 196 1.1 scw sc->sc_bust = ma->ma_bust; 197 1.1 scw sc->sc_dmat = ma->ma_dmat; 198 1.1 scw bus_space_map(sc->sc_bust, PCCTWO_REG_OFF + ma->ma_offset, 199 1.1 scw PCC2REG_SIZE, 0, &sc->sc_bush); 200 1.1 scw 201 1.1 scw sc->sc_vecbase = PCCTWO_VECBASE; 202 1.1 scw sc->sc_isrlink = pcctwoisrlink; 203 1.1 scw sc->sc_isrevcnt = pcctwoisrevcnt; 204 1.1 scw sc->sc_isrunlink = pcctwoisrunlink; 205 1.1 scw 206 1.1 scw cid = pcc2_reg_read(sc, PCC2REG_CHIP_ID); 207 1.1 scw 208 1.1 scw #if defined(MVME167) || defined(MVME177) 209 1.1 scw if (cid == PCCTWO_CHIP_ID_PCC2) { 210 1.1 scw pd = pcctwo_devices; 211 1.1 scw sc->sc_vec2icsr = pcctwo_vec2icsr_1x7; 212 1.1 scw } 213 1.1 scw #endif 214 1.1 scw #if defined(MVME162) || defined(MVME172) 215 1.1 scw if (cid == PCCTWO_CHIP_ID_MCCHIP) { 216 1.1 scw pd = mcchip_devices; 217 1.1 scw sc->sc_vec2icsr = pcctwo_vec2icsr_1x2; 218 1.1 scw } 219 1.1 scw #endif 220 1.1 scw 221 1.1 scw /* Finish initialisation in common code */ 222 1.1 scw pcctwo_init(sc, pd, ma->ma_offset); 223 1.1 scw 224 1.1 scw #if defined(MVME162) || defined(MVME172) 225 1.1 scw if (cid == PCCTWO_CHIP_ID_MCCHIP) { 226 1.1 scw evcnt_attach_dynamic(&sc->sc_evcnt, EVCNT_TYPE_INTR, 227 1.1 scw isrlink_evcnt(7), "nmi", "abort sw"); 228 1.1 scw pcctwointr_establish(MCCHIPV_ABORT, pcctwoabortintr, 7, NULL, 229 1.1 scw &sc->sc_evcnt); 230 1.1 scw } 231 1.1 scw #endif 232 1.1 scw } 233 1.1 scw 234 1.1 scw /* ARGSUSED */ 235 1.1 scw static void 236 1.8 tsutsui pcctwoisrlink(void *cookie, int (*fn)(void *), void *arg, int ipl, int vec, 237 1.8 tsutsui struct evcnt *evcnt) 238 1.1 scw { 239 1.1 scw 240 1.1 scw isrlink_vectored(fn, arg, ipl, vec, evcnt); 241 1.1 scw } 242 1.1 scw 243 1.1 scw /* ARGSUSED */ 244 1.1 scw static void 245 1.8 tsutsui pcctwoisrunlink(void *cookie, int vec) 246 1.1 scw { 247 1.1 scw 248 1.1 scw isrunlink_vectored(vec); 249 1.1 scw } 250 1.1 scw 251 1.1 scw /* ARGSUSED */ 252 1.1 scw static struct evcnt * 253 1.8 tsutsui pcctwoisrevcnt(void *cookie, int ipl) 254 1.1 scw { 255 1.1 scw 256 1.8 tsutsui return isrlink_evcnt(ipl); 257 1.1 scw } 258 1.1 scw 259 1.1 scw #if defined(MVME162) || defined(MVME172) 260 1.1 scw static int 261 1.1 scw pcctwoabortintr(void *frame) 262 1.1 scw { 263 1.1 scw 264 1.1 scw pcc2_reg_write(sys_pcctwo, MCCHIPREG_ABORT_ICSR, PCCTWO_ICR_ICLR | 265 1.1 scw pcc2_reg_read(sys_pcctwo, MCCHIPREG_ABORT_ICSR)); 266 1.1 scw 267 1.8 tsutsui return nmihand(frame); 268 1.1 scw } 269 1.1 scw 270 1.1 scw void 271 1.1 scw pcctwosoftintrinit(void) 272 1.1 scw { 273 1.1 scw 274 1.1 scw /* 275 1.1 scw * Since the VMEChip2 is normally used to generate 276 1.1 scw * software interrupts to the CPU, we have to deal 277 1.1 scw * with 162/172 boards which have the "No VMEChip2" 278 1.1 scw * build option. 279 1.1 scw * 280 1.1 scw * When such a board is found, the VMEChip2 probe code 281 1.1 scw * calls this function to implement software interrupts 282 1.1 scw * the hard way; using tick timer 4 ... 283 1.1 scw */ 284 1.1 scw pcctwointr_establish(MCCHIPV_TIMER4, pcctwosoftintr, 285 1.1 scw 1, sys_pcctwo, &sys_pcctwo->sc_evcnt); 286 1.1 scw pcc2_reg_write(sys_pcctwo, MCCHIPREG_TIMER4_CTRL, 0); 287 1.1 scw pcc2_reg_write32(sys_pcctwo, MCCHIPREG_TIMER4_COMP, 1); 288 1.1 scw pcc2_reg_write32(sys_pcctwo, MCCHIPREG_TIMER4_CNTR, 0); 289 1.7 ad #ifdef notyet 290 1.1 scw _softintr_chipset_assert = pcctwosoftintrassert; 291 1.7 ad #endif 292 1.1 scw } 293 1.1 scw 294 1.1 scw static int 295 1.1 scw pcctwosoftintr(void *arg) 296 1.1 scw { 297 1.1 scw struct pcctwo_softc *sc = arg; 298 1.1 scw 299 1.1 scw pcc2_reg_write32(sc, MCCHIPREG_TIMER4_CNTR, 0); 300 1.1 scw pcc2_reg_write(sc, MCCHIPREG_TIMER4_CTRL, 0); 301 1.1 scw pcc2_reg_write(sc, MCCHIPREG_TIMER4_ICSR, 302 1.1 scw PCCTWO_ICR_ICLR | PCCTWO_ICR_IEN | 1); 303 1.1 scw 304 1.7 ad #ifdef notyet 305 1.1 scw softintr_dispatch(); 306 1.7 ad #endif 307 1.1 scw 308 1.8 tsutsui return 1; 309 1.1 scw } 310 1.1 scw 311 1.7 ad #ifdef notyet 312 1.1 scw static void 313 1.1 scw pcctwosoftintrassert(void) 314 1.1 scw { 315 1.1 scw 316 1.1 scw /* 317 1.1 scw * Schedule a timer interrupt to happen in ~1uS. 318 1.1 scw * This is more than adequate on any available m68k platform 319 1.1 scw * for simulating software interrupts. 320 1.1 scw */ 321 1.1 scw pcc2_reg_write(sys_pcctwo, MCCHIPREG_TIMER4_CTRL, PCCTWO_TT_CTRL_CEN); 322 1.1 scw } 323 1.1 scw #endif 324 1.7 ad #endif 325