1 1.19 andvar /* $NetBSD: plumiobus.c,v 1.19 2022/01/24 09:14:37 andvar Exp $ */ 2 1.1 uch 3 1.4 uch /*- 4 1.4 uch * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. 5 1.1 uch * All rights reserved. 6 1.1 uch * 7 1.4 uch * This code is derived from software contributed to The NetBSD Foundation 8 1.4 uch * by UCHIYAMA Yasushi. 9 1.4 uch * 10 1.1 uch * Redistribution and use in source and binary forms, with or without 11 1.1 uch * modification, are permitted provided that the following conditions 12 1.1 uch * are met: 13 1.1 uch * 1. Redistributions of source code must retain the above copyright 14 1.1 uch * notice, this list of conditions and the following disclaimer. 15 1.4 uch * 2. Redistributions in binary form must reproduce the above copyright 16 1.4 uch * notice, this list of conditions and the following disclaimer in the 17 1.4 uch * documentation and/or other materials provided with the distribution. 18 1.1 uch * 19 1.4 uch * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.4 uch * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.4 uch * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.4 uch * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.4 uch * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.4 uch * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.4 uch * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.4 uch * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.4 uch * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.4 uch * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.4 uch * POSSIBILITY OF SUCH DAMAGE. 30 1.1 uch */ 31 1.9 lukem 32 1.9 lukem #include <sys/cdefs.h> 33 1.19 andvar __KERNEL_RCSID(0, "$NetBSD: plumiobus.c,v 1.19 2022/01/24 09:14:37 andvar Exp $"); 34 1.4 uch 35 1.3 uch #define PLUMIOBUSDEBUG 36 1.1 uch 37 1.1 uch #include <sys/param.h> 38 1.1 uch #include <sys/systm.h> 39 1.1 uch #include <sys/device.h> 40 1.16 thorpej #include <sys/kmem.h> 41 1.1 uch 42 1.1 uch #include <machine/bus.h> 43 1.1 uch #include <machine/intr.h> 44 1.1 uch 45 1.1 uch #include <hpcmips/tx/tx39var.h> 46 1.1 uch #include <hpcmips/dev/plumvar.h> 47 1.1 uch #include <hpcmips/dev/plumicuvar.h> 48 1.1 uch #include <hpcmips/dev/plumpowervar.h> 49 1.1 uch #include <hpcmips/dev/plumiobusreg.h> 50 1.1 uch #include <hpcmips/dev/plumiobusvar.h> 51 1.1 uch 52 1.1 uch #include "locators.h" 53 1.1 uch 54 1.3 uch #ifdef PLUMIOBUSDEBUG 55 1.3 uch int plumiobus_debug = 0; 56 1.3 uch #define DPRINTF(arg) if (plumiobus_debug) printf arg; 57 1.3 uch #define DPRINTFN(n, arg) if (plumiobus_debug > (n)) printf arg; 58 1.3 uch #else 59 1.3 uch #define DPRINTF(arg) 60 1.3 uch #define DPRINTFN(n, arg) 61 1.3 uch #endif 62 1.3 uch 63 1.14 chs int plumiobus_match(device_t, cfdata_t, void *); 64 1.14 chs void plumiobus_attach(device_t, device_t, void *); 65 1.4 uch int plumiobus_print(void *, const char *); 66 1.14 chs int plumiobus_search(device_t, cfdata_t , const int *, void *); 67 1.1 uch 68 1.1 uch struct plumisa_resource { 69 1.1 uch int pr_irq; 70 1.1 uch bus_space_tag_t pr_iot; 71 1.1 uch int pr_enabled; 72 1.1 uch }; 73 1.1 uch 74 1.1 uch struct plumiobus_softc { 75 1.1 uch plum_chipset_tag_t sc_pc; 76 1.1 uch bus_space_tag_t sc_regt; 77 1.1 uch bus_space_handle_t sc_regh; 78 1.1 uch bus_space_tag_t sc_iot; 79 1.1 uch bus_space_handle_t sc_ioh; 80 1.1 uch struct plumisa_resource sc_isa[PLUM_IOBUS_IO5CSMAX]; 81 1.1 uch }; 82 1.1 uch 83 1.14 chs CFATTACH_DECL_NEW(plumiobus, sizeof(struct plumiobus_softc), 84 1.8 thorpej plumiobus_match, plumiobus_attach, NULL, NULL); 85 1.1 uch 86 1.4 uch bus_space_tag_t __plumiobus_subregion(bus_space_tag_t, bus_addr_t, 87 1.4 uch bus_size_t); 88 1.3 uch #ifdef PLUMIOBUSDEBUG 89 1.4 uch void plumiobus_dump(struct plumiobus_softc *); 90 1.3 uch #endif 91 1.1 uch 92 1.1 uch int 93 1.14 chs plumiobus_match(device_t parent, cfdata_t cf, void *aux) 94 1.1 uch { 95 1.4 uch 96 1.3 uch return (1); 97 1.1 uch } 98 1.1 uch 99 1.1 uch void 100 1.14 chs plumiobus_attach(device_t parent, device_t self, void *aux) 101 1.1 uch { 102 1.1 uch struct plum_attach_args *pa = aux; 103 1.14 chs struct plumiobus_softc *sc = device_private(self); 104 1.1 uch struct plumisa_resource *pr; 105 1.1 uch 106 1.1 uch sc->sc_pc = pa->pa_pc; 107 1.1 uch sc->sc_regt = pa->pa_regt; 108 1.1 uch sc->sc_iot = pa->pa_iot; 109 1.1 uch 110 1.1 uch if (bus_space_map(sc->sc_regt, PLUM_IOBUS_REGBASE, 111 1.4 uch PLUM_IOBUS_REGSIZE, 0, &sc->sc_regh)) { 112 1.1 uch printf(": register map failed.\n"); 113 1.1 uch return; 114 1.1 uch } 115 1.1 uch printf("\n"); 116 1.2 uch plum_power_establish(sc->sc_pc, PLUM_PWR_IO5); 117 1.2 uch 118 1.1 uch /* Address space <-> IRQ mapping */ 119 1.1 uch pr = &sc->sc_isa[IO5CS0]; 120 1.1 uch pr->pr_irq = PLUM_INT_EXT5IO0; 121 1.1 uch pr->pr_iot = __plumiobus_subregion( 122 1.1 uch sc->sc_iot, 123 1.1 uch PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS0BASE, 124 1.1 uch PLUM_IOBUS_IO5SIZE); 125 1.1 uch 126 1.1 uch pr = &sc->sc_isa[IO5CS1]; 127 1.1 uch pr->pr_irq = PLUM_INT_EXT5IO1; 128 1.1 uch pr->pr_iot = __plumiobus_subregion( 129 1.1 uch sc->sc_iot, 130 1.1 uch PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS1BASE, 131 1.1 uch PLUM_IOBUS_IO5SIZE); 132 1.1 uch 133 1.1 uch pr = &sc->sc_isa[IO5CS2]; 134 1.1 uch pr->pr_irq = PLUM_INT_EXT5IO2; 135 1.1 uch pr->pr_iot = __plumiobus_subregion( 136 1.1 uch sc->sc_iot, 137 1.1 uch PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS2BASE, 138 1.1 uch PLUM_IOBUS_IO5SIZE); 139 1.1 uch 140 1.1 uch pr = &sc->sc_isa[IO5CS3]; 141 1.1 uch pr->pr_irq = PLUM_INT_EXT5IO3; 142 1.1 uch pr->pr_iot = __plumiobus_subregion( 143 1.1 uch sc->sc_iot, 144 1.1 uch PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS3BASE, 145 1.1 uch PLUM_IOBUS_IO5SIZE); 146 1.1 uch 147 1.1 uch pr = &sc->sc_isa[IO5CS4]; 148 1.1 uch pr->pr_irq = PLUM_INT_EXT3IO0; /* XXX */ 149 1.1 uch pr->pr_iot = __plumiobus_subregion( 150 1.1 uch sc->sc_iot, 151 1.1 uch PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS4BASE, 152 1.1 uch PLUM_IOBUS_IO5SIZE); 153 1.1 uch 154 1.1 uch 155 1.1 uch pr = &sc->sc_isa[IO5NCS]; 156 1.1 uch pr->pr_irq = PLUM_INT_EXT3IO1; 157 1.1 uch pr->pr_iot = __plumiobus_subregion( 158 1.1 uch sc->sc_iot, 159 1.1 uch PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS5BASE, 160 1.1 uch PLUM_IOBUS_IO5SIZE); 161 1.1 uch 162 1.3 uch #ifdef PLUMIOBUSDEBUG 163 1.1 uch plumiobus_dump(sc); 164 1.3 uch #endif 165 1.2 uch 166 1.17 thorpej config_search(self, NULL, 167 1.18 thorpej CFARGS(.search = plumiobus_search)); 168 1.1 uch } 169 1.1 uch 170 1.1 uch /* XXX something kludge */ 171 1.1 uch bus_space_tag_t 172 1.4 uch __plumiobus_subregion(bus_space_tag_t t, bus_addr_t ofs, bus_size_t size) 173 1.1 uch { 174 1.1 uch struct hpcmips_bus_space *hbs; 175 1.1 uch 176 1.16 thorpej hbs = kmem_alloc(sizeof(*hbs), KM_SLEEP); 177 1.1 uch *hbs = *t; 178 1.1 uch hbs->t_base += ofs; 179 1.1 uch hbs->t_size = size; 180 1.1 uch 181 1.3 uch return (hbs); 182 1.1 uch } 183 1.1 uch 184 1.1 uch int 185 1.14 chs plumiobus_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux) 186 1.1 uch { 187 1.14 chs struct plumiobus_softc *sc = device_private(parent); 188 1.1 uch struct plumiobus_attach_args pba; 189 1.1 uch int slot; 190 1.1 uch 191 1.1 uch /* Disallow wildcarded IO5CS slot */ 192 1.1 uch if (cf->cf_loc[PLUMIOBUSIFCF_SLOT] == PLUMIOBUSIFCF_SLOT_DEFAULT) { 193 1.1 uch printf("plumiobus_search: wildcarded slot, skipping\n"); 194 1.3 uch return (0); 195 1.1 uch } 196 1.1 uch slot = pba.pba_slot = cf->cf_loc[PLUMIOBUSIFCF_SLOT]; 197 1.1 uch 198 1.1 uch pba.pba_pc = sc->sc_pc; 199 1.1 uch pba.pba_iot = sc->sc_isa[slot].pr_iot; 200 1.1 uch pba.pba_irq = sc->sc_isa[slot].pr_irq; 201 1.1 uch pba.pba_busname = "plumisab"; 202 1.1 uch 203 1.1 uch if (!(sc->sc_isa[slot].pr_enabled) && /* not attached slot */ 204 1.17 thorpej config_probe(parent, cf, &pba)) { 205 1.18 thorpej config_attach(parent, cf, &pba, plumiobus_print, CFARGS_NONE); 206 1.1 uch sc->sc_isa[slot].pr_enabled = 1; 207 1.1 uch } 208 1.1 uch 209 1.3 uch return (0); 210 1.1 uch } 211 1.1 uch 212 1.1 uch int 213 1.4 uch plumiobus_print(void *aux, const char *pnp) 214 1.1 uch { 215 1.4 uch 216 1.3 uch return (pnp ? QUIET : UNCONF); 217 1.1 uch } 218 1.1 uch 219 1.3 uch #ifdef PLUMIOBUSDEBUG 220 1.1 uch void 221 1.4 uch plumiobus_dump(struct plumiobus_softc *sc) 222 1.1 uch { 223 1.1 uch bus_space_tag_t regt = sc->sc_regt; 224 1.1 uch bus_space_handle_t regh = sc->sc_regh; 225 1.1 uch plumreg_t reg; 226 1.1 uch int i, wait; 227 1.1 uch 228 1.1 uch reg = plum_conf_read(regt, regh, PLUM_IOBUS_IOXBSZ_REG); 229 1.1 uch printf("8bit port:"); 230 1.1 uch for (i = 0; i < 6; i++) { 231 1.1 uch if (reg & (1 << i)) { 232 1.1 uch printf(" IO5CS%d", i); 233 1.1 uch } 234 1.1 uch } 235 1.1 uch printf("\n"); 236 1.1 uch 237 1.1 uch reg = PLUM_IOBUS_IOXCCNT_MASK & 238 1.4 uch plum_conf_read(regt, regh, PLUM_IOBUS_IOXCCNT_REG); 239 1.19 andvar printf(" # of wait to become from the access beginning: %d clock\n", 240 1.4 uch reg + 1); 241 1.1 uch reg = plum_conf_read(regt, regh, PLUM_IOBUS_IOXACNT_REG); 242 1.1 uch printf(" # of wait in access clock: "); 243 1.1 uch for (i = 0; i < 5; i++) { 244 1.1 uch wait = (reg >> (i * PLUM_IOBUS_IOXACNT_SHIFT)) 245 1.4 uch & PLUM_IOBUS_IOXACNT_MASK; 246 1.1 uch printf("[CS%d:%d] ", i, wait + 1); 247 1.1 uch } 248 1.1 uch printf("\n"); 249 1.1 uch 250 1.1 uch reg = PLUM_IOBUS_IOXSCNT_MASK & 251 1.4 uch plum_conf_read(regt, regh, PLUM_IOBUS_IOXSCNT_REG); 252 1.1 uch printf(" # of wait during access by I/O bus : %d clock\n", reg + 1); 253 1.1 uch 254 1.1 uch reg = plum_conf_read(regt, regh, PLUM_IOBUS_IDEMODE_REG); 255 1.1 uch if (reg & PLUM_IOBUS_IDEMODE) { 256 1.1 uch printf("IO5CS3,4 IDE mode\n"); 257 1.1 uch } 258 1.1 uch } 259 1.3 uch #endif /* PLUMIOBUSDEBUG */ 260