1 1.13 thorpej /* $NetBSD: pcctwo.c,v 1.13 2021/08/07 16:19:13 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 Driver 34 1.1 scw */ 35 1.3 lukem 36 1.3 lukem #include <sys/cdefs.h> 37 1.13 thorpej __KERNEL_RCSID(0, "$NetBSD: pcctwo.c,v 1.13 2021/08/07 16:19:13 thorpej Exp $"); 38 1.1 scw 39 1.1 scw #include <sys/param.h> 40 1.1 scw #include <sys/kernel.h> 41 1.1 scw #include <sys/systm.h> 42 1.1 scw #include <sys/device.h> 43 1.1 scw 44 1.7 ad #include <sys/cpu.h> 45 1.7 ad #include <sys/bus.h> 46 1.1 scw 47 1.1 scw #include <dev/mvme/pcctworeg.h> 48 1.1 scw #include <dev/mvme/pcctwovar.h> 49 1.1 scw 50 1.1 scw /* 51 1.1 scw * Global Pointer to the PCCChip2/MCchip soft state, and chip ID 52 1.1 scw */ 53 1.1 scw struct pcctwo_softc *sys_pcctwo; 54 1.1 scw 55 1.1 scw int pcctwoprint(void *, const char *); 56 1.1 scw 57 1.1 scw 58 1.1 scw /* ARGSUSED */ 59 1.1 scw void 60 1.9 dsl pcctwo_init(struct pcctwo_softc *sc, const struct pcctwo_device *pd, int devoff) 61 1.1 scw { 62 1.1 scw struct pcctwo_attach_args npa; 63 1.1 scw u_int8_t cid; 64 1.1 scw 65 1.1 scw /* 66 1.1 scw * Fix up the vector base for PCCChip2 Interrupts 67 1.1 scw */ 68 1.1 scw pcc2_reg_write(sc, PCC2REG_VECTOR_BASE, sc->sc_vecbase); 69 1.1 scw 70 1.1 scw /* 71 1.1 scw * Enable PCCChip2 Interrupts 72 1.1 scw */ 73 1.1 scw pcc2_reg_write(sc, PCC2REG_GENERAL_CONTROL, 74 1.1 scw pcc2_reg_read(sc, PCC2REG_GENERAL_CONTROL) | PCCTWO_GEN_CTRL_MIEN); 75 1.1 scw 76 1.1 scw /* What are we? */ 77 1.1 scw cid = pcc2_reg_read(sc, PCC2REG_CHIP_ID); 78 1.1 scw 79 1.1 scw /* 80 1.1 scw * Announce ourselves to the world in general 81 1.1 scw */ 82 1.1 scw if (cid == PCCTWO_CHIP_ID_PCC2) 83 1.1 scw printf(": Peripheral Channel Controller (PCCchip2), Rev %d\n", 84 1.1 scw pcc2_reg_read(sc, PCC2REG_CHIP_REVISION)); 85 1.1 scw else 86 1.1 scw if (cid == PCCTWO_CHIP_ID_MCCHIP) 87 1.1 scw printf(": Memory Controller ASIC (MCchip), Rev %d\n", 88 1.1 scw pcc2_reg_read(sc, PCC2REG_CHIP_REVISION)); 89 1.1 scw 90 1.1 scw /* 91 1.1 scw * Attach configured children. 92 1.1 scw */ 93 1.1 scw npa._pa_base = devoff; 94 1.1 scw while (pd->pcc_name != NULL) { 95 1.1 scw /* 96 1.1 scw * Note that IPL is filled in by match function. 97 1.1 scw */ 98 1.1 scw npa.pa_name = pd->pcc_name; 99 1.1 scw npa.pa_ipl = -1; 100 1.1 scw npa.pa_dmat = sc->sc_dmat; 101 1.1 scw npa.pa_bust = sc->sc_bust; 102 1.1 scw npa.pa_offset = pd->pcc_offset + devoff; 103 1.1 scw pd++; 104 1.1 scw 105 1.1 scw /* Attach the device if configured. */ 106 1.13 thorpej (void) config_found(sc->sc_dev, &npa, pcctwoprint, CFARGS_NONE); 107 1.1 scw } 108 1.1 scw } 109 1.1 scw 110 1.1 scw int 111 1.9 dsl pcctwoprint(void *aux, const char *cp) 112 1.1 scw { 113 1.1 scw struct pcctwo_attach_args *pa; 114 1.1 scw 115 1.1 scw pa = aux; 116 1.1 scw 117 1.1 scw if (cp) 118 1.2 thorpej aprint_normal("%s at %s", pa->pa_name, cp); 119 1.1 scw 120 1.2 thorpej aprint_normal(" offset 0x%lx", pa->pa_offset - pa->_pa_base); 121 1.1 scw if (pa->pa_ipl != -1) 122 1.2 thorpej aprint_normal(" ipl %d", pa->pa_ipl); 123 1.1 scw 124 1.1 scw return (UNCONF); 125 1.1 scw } 126 1.1 scw 127 1.1 scw /* 128 1.1 scw * pcctwointr_establish: Establish PCCChip2 Interrupt 129 1.1 scw */ 130 1.1 scw void 131 1.10 matt pcctwointr_establish( 132 1.10 matt int vec, 133 1.10 matt int (*hand)(void *), 134 1.10 matt int lvl, 135 1.10 matt void *arg, 136 1.10 matt struct evcnt *evcnt) 137 1.1 scw { 138 1.1 scw int vec2icsr; 139 1.1 scw 140 1.1 scw #ifdef DEBUG 141 1.1 scw if (vec < 0 || vec >= PCCTWOV_MAX) { 142 1.1 scw printf("pcctwo: illegal vector offset: 0x%x\n", vec); 143 1.1 scw panic("pcctwointr_establish"); 144 1.1 scw } 145 1.1 scw if (lvl < 1 || lvl > 7) { 146 1.1 scw printf("pcctwo: illegal interrupt level: %d\n", lvl); 147 1.1 scw panic("pcctwointr_establish"); 148 1.1 scw } 149 1.1 scw if (sys_pcctwo->sc_vec2icsr[vec] == -1) { 150 1.1 scw printf("pcctwo: unsupported vector: %d\n", vec); 151 1.1 scw panic("pcctwointr_establish"); 152 1.1 scw } 153 1.1 scw #endif 154 1.1 scw 155 1.1 scw vec2icsr = sys_pcctwo->sc_vec2icsr[vec]; 156 1.1 scw pcc2_reg_write(sys_pcctwo, VEC2ICSR_REG(vec2icsr), 0); 157 1.1 scw 158 1.1 scw /* Hook the interrupt */ 159 1.1 scw (*sys_pcctwo->sc_isrlink)(sys_pcctwo->sc_isrcookie, hand, arg, 160 1.1 scw lvl, vec + sys_pcctwo->sc_vecbase, evcnt); 161 1.1 scw 162 1.1 scw /* Enable it in hardware */ 163 1.1 scw pcc2_reg_write(sys_pcctwo, VEC2ICSR_REG(vec2icsr), 164 1.1 scw VEC2ICSR_INIT(vec2icsr) | lvl); 165 1.1 scw } 166 1.1 scw 167 1.1 scw void 168 1.9 dsl pcctwointr_disestablish(int vec) 169 1.1 scw { 170 1.1 scw 171 1.1 scw #ifdef DEBUG 172 1.1 scw if (vec < 0 || vec >= PCCTWOV_MAX) { 173 1.1 scw printf("pcctwo: illegal vector offset: 0x%x\n", vec); 174 1.1 scw panic("pcctwointr_disestablish"); 175 1.1 scw } 176 1.1 scw if (sys_pcctwo->sc_vec2icsr[vec] == -1) { 177 1.1 scw printf("pcctwo: unsupported vector: %d\n", vec); 178 1.1 scw panic("pcctwointr_establish"); 179 1.1 scw } 180 1.1 scw #endif 181 1.1 scw 182 1.1 scw /* Disable it in hardware */ 183 1.1 scw pcc2_reg_write(sys_pcctwo, sys_pcctwo->sc_vec2icsr[vec], 0); 184 1.1 scw 185 1.1 scw (*sys_pcctwo->sc_isrunlink)(sys_pcctwo->sc_isrcookie, 186 1.1 scw vec + sys_pcctwo->sc_vecbase); 187 1.1 scw } 188 1.1 scw 189 1.1 scw struct evcnt * 190 1.9 dsl pcctwointr_evcnt(int lev) 191 1.1 scw { 192 1.1 scw 193 1.1 scw return ((*sys_pcctwo->sc_isrevcnt)(sys_pcctwo->sc_isrcookie, lev)); 194 1.1 scw } 195