1 1.35 thorpej /* $NetBSD: pcc.c,v 1.35 2021/08/07 16:19:00 thorpej Exp $ */ 2 1.10 thorpej 3 1.31 chuck /* 4 1.10 thorpej * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. 5 1.10 thorpej * All rights reserved. 6 1.10 thorpej * 7 1.10 thorpej * This code is derived from software contributed to The NetBSD Foundation 8 1.13 scw * by Jason R. Thorpe and Steve C. Woodford. 9 1.10 thorpej * 10 1.10 thorpej * Redistribution and use in source and binary forms, with or without 11 1.10 thorpej * modification, are permitted provided that the following conditions 12 1.10 thorpej * are met: 13 1.10 thorpej * 1. Redistributions of source code must retain the above copyright 14 1.10 thorpej * notice, this list of conditions and the following disclaimer. 15 1.10 thorpej * 2. Redistributions in binary form must reproduce the above copyright 16 1.10 thorpej * notice, this list of conditions and the following disclaimer in the 17 1.10 thorpej * documentation and/or other materials provided with the distribution. 18 1.10 thorpej * 19 1.10 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.10 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.10 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.10 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.10 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.10 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.10 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.10 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.10 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.10 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.10 thorpej * POSSIBILITY OF SUCH DAMAGE. 30 1.10 thorpej */ 31 1.1 chuck 32 1.1 chuck /* 33 1.1 chuck * Copyright (c) 1995 Charles D. Cranor 34 1.1 chuck * All rights reserved. 35 1.1 chuck * 36 1.1 chuck * Redistribution and use in source and binary forms, with or without 37 1.1 chuck * modification, are permitted provided that the following conditions 38 1.1 chuck * are met: 39 1.1 chuck * 1. Redistributions of source code must retain the above copyright 40 1.1 chuck * notice, this list of conditions and the following disclaimer. 41 1.1 chuck * 2. Redistributions in binary form must reproduce the above copyright 42 1.1 chuck * notice, this list of conditions and the following disclaimer in the 43 1.1 chuck * documentation and/or other materials provided with the distribution. 44 1.1 chuck * 45 1.1 chuck * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 46 1.1 chuck * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 47 1.1 chuck * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 48 1.1 chuck * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 49 1.1 chuck * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 50 1.1 chuck * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 51 1.1 chuck * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 52 1.1 chuck * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 53 1.1 chuck * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 54 1.1 chuck * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 55 1.1 chuck */ 56 1.1 chuck 57 1.1 chuck /* 58 1.1 chuck * peripheral channel controller 59 1.1 chuck */ 60 1.25 lukem 61 1.25 lukem #include <sys/cdefs.h> 62 1.35 thorpej __KERNEL_RCSID(0, "$NetBSD: pcc.c,v 1.35 2021/08/07 16:19:00 thorpej Exp $"); 63 1.12 scw 64 1.1 chuck #include <sys/param.h> 65 1.13 scw #include <sys/kernel.h> 66 1.1 chuck #include <sys/systm.h> 67 1.1 chuck #include <sys/device.h> 68 1.14 scw #include <sys/kcore.h> 69 1.13 scw 70 1.1 chuck #include <machine/cpu.h> 71 1.13 scw #include <machine/bus.h> 72 1.3 chuck 73 1.13 scw #include <mvme68k/dev/mainbus.h> 74 1.1 chuck #include <mvme68k/dev/pccreg.h> 75 1.3 chuck #include <mvme68k/dev/pccvar.h> 76 1.1 chuck 77 1.29 tsutsui #include "ioconf.h" 78 1.29 tsutsui 79 1.1 chuck /* 80 1.13 scw * Autoconfiguration stuff for the PCC chip on mvme147 81 1.1 chuck */ 82 1.1 chuck 83 1.32 chs void pccattach(device_t, device_t, void *); 84 1.32 chs int pccmatch(device_t, cfdata_t, void *); 85 1.29 tsutsui int pccprint(void *, const char *); 86 1.1 chuck 87 1.32 chs CFATTACH_DECL_NEW(pcc, sizeof(struct pcc_softc), 88 1.22 thorpej pccmatch, pccattach, NULL, NULL); 89 1.2 thorpej 90 1.29 tsutsui static int pccintr(void *); 91 1.29 tsutsui static int pccsoftintr(void *); 92 1.28 ad #ifdef notyet 93 1.29 tsutsui static void pccsoftintrassert(void); 94 1.28 ad #endif 95 1.3 chuck 96 1.1 chuck /* 97 1.13 scw * Structure used to describe a device for autoconfiguration purposes. 98 1.1 chuck */ 99 1.13 scw struct pcc_device { 100 1.26 scw const char *pcc_name; /* name of device (e.g. "clock") */ 101 1.13 scw bus_addr_t pcc_offset; /* offset from PCC base */ 102 1.13 scw }; 103 1.1 chuck 104 1.3 chuck /* 105 1.3 chuck * Devices that live on the PCC, attached in this order. 106 1.3 chuck */ 107 1.26 scw static const struct pcc_device pcc_devices[] = { 108 1.20 scw {"clock", 0}, 109 1.13 scw {"zsc", PCC_ZS0_OFF}, 110 1.13 scw {"zsc", PCC_ZS1_OFF}, 111 1.13 scw {"le", PCC_LE_OFF}, 112 1.13 scw {"wdsc", PCC_WDSC_OFF}, 113 1.13 scw {"lpt", PCC_LPT_OFF}, 114 1.13 scw {"vmepcc", PCC_VME_OFF}, 115 1.13 scw {NULL, 0}, 116 1.13 scw }; 117 1.13 scw 118 1.13 scw static int pcc_vec2intctrl[] = { 119 1.13 scw PCCREG_ACFAIL_INTR_CTRL,/* PCCV_ACFAIL */ 120 1.13 scw PCCREG_BUSERR_INTR_CTRL,/* PCCV_BERR */ 121 1.13 scw PCCREG_ABORT_INTR_CTRL, /* PCCV_ABORT */ 122 1.13 scw PCCREG_SERIAL_INTR_CTRL,/* PCCV_ZS */ 123 1.13 scw PCCREG_LANCE_INTR_CTRL, /* PCCV_LE */ 124 1.13 scw PCCREG_SCSI_INTR_CTRL, /* PCCV_SCSI */ 125 1.13 scw PCCREG_DMA_INTR_CTRL, /* PCCV_DMA */ 126 1.13 scw PCCREG_PRNT_INTR_CTRL, /* PCCV_PRINTER */ 127 1.13 scw PCCREG_TMR1_INTR_CTRL, /* PCCV_TIMER1 */ 128 1.13 scw PCCREG_TMR2_INTR_CTRL, /* PCCV_TIMER2 */ 129 1.13 scw PCCREG_SOFT1_INTR_CTRL, /* PCCV_SOFT1 */ 130 1.13 scw PCCREG_SOFT2_INTR_CTRL /* PCCV_SOFT2 */ 131 1.3 chuck }; 132 1.1 chuck 133 1.14 scw extern phys_ram_seg_t mem_clusters[]; 134 1.13 scw struct pcc_softc *sys_pcc; 135 1.13 scw 136 1.14 scw /* The base address of the MVME147 from the VMEbus */ 137 1.14 scw bus_addr_t pcc_slave_base_addr; 138 1.14 scw 139 1.14 scw 140 1.13 scw /* ARGSUSED */ 141 1.1 chuck int 142 1.32 chs pccmatch(device_t parent, cfdata_t cf, void *aux) 143 1.1 chuck { 144 1.13 scw struct mainbus_attach_args *ma; 145 1.13 scw 146 1.32 chs ma = aux; 147 1.3 chuck 148 1.3 chuck /* Only attach one PCC. */ 149 1.3 chuck if (sys_pcc) 150 1.29 tsutsui return 0; 151 1.1 chuck 152 1.29 tsutsui return strcmp(ma->ma_name, pcc_cd.cd_name) == 0; 153 1.1 chuck } 154 1.1 chuck 155 1.13 scw /* ARGSUSED */ 156 1.1 chuck void 157 1.32 chs pccattach(device_t parent, device_t self, void *aux) 158 1.1 chuck { 159 1.13 scw struct mainbus_attach_args *ma; 160 1.3 chuck struct pcc_attach_args npa; 161 1.13 scw struct pcc_softc *sc; 162 1.29 tsutsui uint8_t reg; 163 1.6 thorpej int i; 164 1.1 chuck 165 1.32 chs ma = aux; 166 1.33 chs sc = sys_pcc = device_private(self); 167 1.1 chuck 168 1.13 scw /* Get a handle to the PCC's registers. */ 169 1.13 scw sc->sc_bust = ma->ma_bust; 170 1.20 scw bus_space_map(sc->sc_bust, ma->ma_offset, PCCREG_SIZE, 0, &sc->sc_bush); 171 1.1 chuck 172 1.13 scw /* Tell the chip the base interrupt vector */ 173 1.13 scw pcc_reg_write(sc, PCCREG_VECTOR_BASE, PCC_VECBASE); 174 1.1 chuck 175 1.8 christos printf(": Peripheral Channel Controller, " 176 1.13 scw "rev %d, vecbase 0x%x\n", pcc_reg_read(sc, PCCREG_REVISION), 177 1.13 scw pcc_reg_read(sc, PCCREG_VECTOR_BASE)); 178 1.3 chuck 179 1.18 scw evcnt_attach_dynamic(&sc->sc_evcnt, EVCNT_TYPE_INTR, 180 1.18 scw isrlink_evcnt(7), "nmi", "abort sw"); 181 1.18 scw 182 1.13 scw /* Hook up interrupt handler for abort button, and enable it */ 183 1.18 scw pccintr_establish(PCCV_ABORT, pccintr, 7, NULL, &sc->sc_evcnt); 184 1.13 scw pcc_reg_write(sc, PCCREG_ABORT_INTR_CTRL, 185 1.13 scw PCC_ABORT_IEN | PCC_ABORT_ACK); 186 1.3 chuck 187 1.19 scw /* 188 1.19 scw * Install a handler for Software Interrupt 1 189 1.19 scw * and arrange to schedule soft interrupts on demand. 190 1.19 scw */ 191 1.19 scw pccintr_establish(PCCV_SOFT1, pccsoftintr, 1, sc, &sc->sc_evcnt); 192 1.28 ad #ifdef notyet 193 1.19 scw _softintr_chipset_assert = pccsoftintrassert; 194 1.28 ad #endif 195 1.19 scw 196 1.3 chuck /* Make sure the global interrupt line is hot. */ 197 1.13 scw reg = pcc_reg_read(sc, PCCREG_GENERAL_CONTROL) | PCC_GENCR_IEN; 198 1.13 scw pcc_reg_write(sc, PCCREG_GENERAL_CONTROL, reg); 199 1.14 scw 200 1.14 scw /* 201 1.14 scw * Calculate the board's VMEbus slave base address, for the 202 1.14 scw * benefit of the VMEchip driver. 203 1.14 scw * (Weird that this register is in the PCC ...) 204 1.14 scw */ 205 1.14 scw reg = pcc_reg_read(sc, PCCREG_SLAVE_BASE_ADDR) & PCC_SLAVE_BASE_MASK; 206 1.14 scw pcc_slave_base_addr = (bus_addr_t)reg * mem_clusters[0].size; 207 1.3 chuck 208 1.3 chuck /* 209 1.3 chuck * Attach configured children. 210 1.3 chuck */ 211 1.15 scw npa._pa_base = ma->ma_offset; 212 1.3 chuck for (i = 0; pcc_devices[i].pcc_name != NULL; ++i) { 213 1.3 chuck /* 214 1.3 chuck * Note that IPL is filled in by match function. 215 1.3 chuck */ 216 1.3 chuck npa.pa_name = pcc_devices[i].pcc_name; 217 1.3 chuck npa.pa_ipl = -1; 218 1.13 scw npa.pa_dmat = ma->ma_dmat; 219 1.13 scw npa.pa_bust = ma->ma_bust; 220 1.13 scw npa.pa_offset = pcc_devices[i].pcc_offset + ma->ma_offset; 221 1.3 chuck 222 1.3 chuck /* Attach the device if configured. */ 223 1.35 thorpej (void)config_found(self, &npa, pccprint, CFARGS_NONE); 224 1.3 chuck } 225 1.1 chuck } 226 1.1 chuck 227 1.1 chuck int 228 1.29 tsutsui pccprint(void *aux, const char *cp) 229 1.1 chuck { 230 1.13 scw struct pcc_attach_args *pa; 231 1.13 scw 232 1.13 scw pa = aux; 233 1.3 chuck 234 1.3 chuck if (cp) 235 1.23 thorpej aprint_normal("%s at %s", pa->pa_name, cp); 236 1.3 chuck 237 1.23 thorpej aprint_normal(" offset 0x%lx", pa->pa_offset - pa->_pa_base); 238 1.3 chuck if (pa->pa_ipl != -1) 239 1.23 thorpej aprint_normal(" ipl %d", pa->pa_ipl); 240 1.1 chuck 241 1.29 tsutsui return UNCONF; 242 1.1 chuck } 243 1.1 chuck 244 1.1 chuck /* 245 1.1 chuck * pccintr_establish: establish pcc interrupt 246 1.1 chuck */ 247 1.3 chuck void 248 1.29 tsutsui pccintr_establish(int pccvec, int (*hand)(void *), int lvl, void *arg, 249 1.29 tsutsui struct evcnt *evcnt) 250 1.1 chuck { 251 1.3 chuck 252 1.13 scw #ifdef DEBUG 253 1.13 scw if (pccvec < 0 || pccvec >= PCC_NVEC) { 254 1.8 christos printf("pcc: illegal vector offset: 0x%x\n", pccvec); 255 1.1 chuck panic("pccintr_establish"); 256 1.1 chuck } 257 1.13 scw if (lvl < 1 || lvl > 7) { 258 1.8 christos printf("pcc: illegal interrupt level: %d\n", lvl); 259 1.1 chuck panic("pccintr_establish"); 260 1.1 chuck } 261 1.13 scw #endif 262 1.1 chuck 263 1.18 scw isrlink_vectored(hand, arg, lvl, pccvec + PCC_VECBASE, evcnt); 264 1.3 chuck } 265 1.3 chuck 266 1.3 chuck void 267 1.29 tsutsui pccintr_disestablish(int pccvec) 268 1.3 chuck { 269 1.3 chuck 270 1.13 scw #ifdef DEBUG 271 1.13 scw if (pccvec < 0 || pccvec >= PCC_NVEC) { 272 1.8 christos printf("pcc: illegal vector offset: 0x%x\n", pccvec); 273 1.13 scw panic("pccintr_disestablish"); 274 1.3 chuck } 275 1.13 scw #endif 276 1.3 chuck 277 1.13 scw /* Disable the interrupt */ 278 1.13 scw pcc_reg_write(sys_pcc, pcc_vec2intctrl[pccvec], PCC_ICLEAR); 279 1.3 chuck isrunlink_vectored(pccvec + PCC_VECBASE); 280 1.3 chuck } 281 1.3 chuck 282 1.3 chuck /* 283 1.3 chuck * Handle NMI from abort switch. 284 1.3 chuck */ 285 1.13 scw static int 286 1.29 tsutsui pccintr(void *frame) 287 1.3 chuck { 288 1.3 chuck 289 1.3 chuck /* XXX wait until button pops out */ 290 1.13 scw pcc_reg_write(sys_pcc, PCCREG_ABORT_INTR_CTRL, 291 1.13 scw PCC_ABORT_IEN | PCC_ABORT_ACK); 292 1.13 scw 293 1.29 tsutsui return nmihand(frame); 294 1.19 scw } 295 1.19 scw 296 1.28 ad #ifdef notyet 297 1.19 scw static void 298 1.19 scw pccsoftintrassert(void) 299 1.19 scw { 300 1.19 scw 301 1.19 scw /* Request a software interrupt at ipl 1 */ 302 1.19 scw pcc_reg_write(sys_pcc, PCCREG_SOFT1_INTR_CTRL, 1 | PCC_IENABLE); 303 1.19 scw } 304 1.28 ad #endif 305 1.19 scw 306 1.19 scw /* 307 1.24 wiz * Handle PCC soft interrupt #1 308 1.19 scw */ 309 1.19 scw static int 310 1.29 tsutsui pccsoftintr(void *arg) 311 1.19 scw { 312 1.19 scw struct pcc_softc *sc = arg; 313 1.19 scw 314 1.19 scw /* Clear the interrupt */ 315 1.19 scw pcc_reg_write(sc, PCCREG_SOFT1_INTR_CTRL, 0); 316 1.19 scw 317 1.28 ad #ifdef notyet 318 1.19 scw /* Call the soft interrupt dispatcher */ 319 1.19 scw softintr_dispatch(); 320 1.28 ad #endif 321 1.19 scw 322 1.29 tsutsui return 1; 323 1.1 chuck } 324