1 1.7 thorpej /* $NetBSD: octeon_iobus.c,v 1.7 2021/08/07 16:18:59 thorpej Exp $ */ 2 1.1 hikaru 3 1.1 hikaru /* 4 1.1 hikaru * Copyright (c) 2007 5 1.1 hikaru * Internet Initiative Japan, Inc. All rights reserved. 6 1.1 hikaru * 7 1.1 hikaru * Redistribution and use in source and binary forms, with or without 8 1.1 hikaru * modification, are permitted provided that the following conditions 9 1.1 hikaru * are met: 10 1.1 hikaru * 1. Redistributions of source code must retain the above copyright 11 1.1 hikaru * notice, this list of conditions and the following disclaimer. 12 1.1 hikaru * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 hikaru * notice, this list of conditions and the following disclaimer in the 14 1.1 hikaru * documentation and/or other materials provided with the distribution. 15 1.1 hikaru * 16 1.1 hikaru * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 1.1 hikaru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 1.1 hikaru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 1.1 hikaru * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 1.1 hikaru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 1.1 hikaru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 1.1 hikaru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 1.1 hikaru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 1.1 hikaru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 1.1 hikaru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 1.1 hikaru * SUCH DAMAGE. 27 1.1 hikaru */ 28 1.1 hikaru 29 1.1 hikaru #include <sys/cdefs.h> 30 1.7 thorpej __KERNEL_RCSID(0, "$NetBSD: octeon_iobus.c,v 1.7 2021/08/07 16:18:59 thorpej Exp $"); 31 1.1 hikaru 32 1.1 hikaru #include "locators.h" 33 1.1 hikaru 34 1.1 hikaru #include <sys/param.h> 35 1.1 hikaru #include <sys/systm.h> 36 1.1 hikaru #include <sys/device.h> 37 1.1 hikaru 38 1.1 hikaru #define _MIPS_BUS_DMA_PRIVATE 39 1.1 hikaru #include <sys/bus.h> 40 1.1 hikaru 41 1.1 hikaru #include <mips/cavium/include/iobusvar.h> 42 1.1 hikaru 43 1.5 jmcneill #include <dev/fdt/fdtvar.h> 44 1.5 jmcneill 45 1.1 hikaru struct iobus_softc { 46 1.1 hikaru device_t sc_dev; 47 1.1 hikaru 48 1.1 hikaru /* XXX load/IOBDMA/store operations */ 49 1.1 hikaru bus_space_handle_t sc_ops_bush; 50 1.1 hikaru }; 51 1.1 hikaru 52 1.4 simonb static int iobus_match(device_t, struct cfdata *, void *); 53 1.4 simonb static void iobus_attach(device_t, device_t, void *); 54 1.4 simonb static int iobus_submatch(device_t, struct cfdata *, const int *, void *); 55 1.4 simonb static int iobus_print(void *, const char *); 56 1.4 simonb static void iobus_init(struct iobus_softc *); 57 1.4 simonb static void iobus_init_map(struct iobus_softc *); 58 1.4 simonb static void iobus_init_local(struct iobus_softc *); 59 1.4 simonb static void iobus_init_local_pow(struct iobus_softc *); 60 1.4 simonb static void iobus_init_local_fpa(struct iobus_softc *); 61 1.1 hikaru 62 1.4 simonb static void iobus_bus_io_init(bus_space_tag_t, void *); 63 1.1 hikaru 64 1.1 hikaru static struct mips_bus_space *iobus_bust; 65 1.1 hikaru static struct mips_bus_dma_tag *iobus_dmat; 66 1.1 hikaru 67 1.1 hikaru void 68 1.1 hikaru iobus_bootstrap(struct octeon_config *mcp) 69 1.1 hikaru { 70 1.1 hikaru iobus_bus_io_init(&mcp->mc_iobus_bust, mcp); 71 1.1 hikaru 72 1.1 hikaru iobus_bust = &mcp->mc_iobus_bust; 73 1.1 hikaru iobus_dmat = &mcp->mc_iobus_dmat; 74 1.1 hikaru } 75 1.1 hikaru 76 1.1 hikaru /* ---- autoconf */ 77 1.1 hikaru 78 1.4 simonb CFATTACH_DECL_NEW(iobus, sizeof(struct iobus_softc), 79 1.4 simonb iobus_match, iobus_attach, NULL, NULL); 80 1.1 hikaru 81 1.1 hikaru static int 82 1.1 hikaru iobus_match(device_t parent, struct cfdata *match, void *aux) 83 1.1 hikaru { 84 1.1 hikaru return 1; 85 1.1 hikaru } 86 1.1 hikaru 87 1.1 hikaru static void 88 1.1 hikaru iobus_attach(device_t parent, device_t self, void *aux) 89 1.1 hikaru { 90 1.1 hikaru struct iobus_softc *sc = device_private(self); 91 1.1 hikaru const struct iobus_dev *dev; 92 1.1 hikaru struct iobus_attach_args aa; 93 1.5 jmcneill const bool fdt_p = fdtbus_get_data() != NULL; 94 1.1 hikaru int i, j; 95 1.1 hikaru 96 1.1 hikaru sc->sc_dev = self; 97 1.1 hikaru 98 1.1 hikaru aprint_normal("\n"); 99 1.1 hikaru 100 1.1 hikaru iobus_init(sc); 101 1.1 hikaru 102 1.4 simonb /* XXX should only attach Octeon 1 and Octeon Plus drivers */ 103 1.1 hikaru for (i = 0; i < (int)iobus_ndevs; i++) { 104 1.1 hikaru dev = iobus_devs[i]; 105 1.1 hikaru for (j = 0; j < dev->nunits; j++) { 106 1.5 jmcneill if (fdt_p && (dev->flags & IOBUS_DEV_FDT) == 0) 107 1.5 jmcneill continue; 108 1.5 jmcneill 109 1.1 hikaru aa.aa_name = dev->name; 110 1.1 hikaru aa.aa_unitno = j; 111 1.1 hikaru aa.aa_unit = &dev->units[j]; 112 1.1 hikaru aa.aa_bust = iobus_bust; 113 1.1 hikaru aa.aa_dmat = iobus_dmat; 114 1.1 hikaru 115 1.6 thorpej config_found(self, &aa, iobus_print, 116 1.7 thorpej CFARGS(.submatch = iobus_submatch)); 117 1.1 hikaru } 118 1.1 hikaru } 119 1.1 hikaru } 120 1.1 hikaru 121 1.1 hikaru static int 122 1.4 simonb iobus_submatch(device_t parent, struct cfdata *cf, const int *ldesc, void *aux) 123 1.1 hikaru { 124 1.4 simonb 125 1.1 hikaru return config_match(parent, cf, aux); 126 1.1 hikaru } 127 1.1 hikaru 128 1.1 hikaru static int 129 1.1 hikaru iobus_print(void *aux, const char *pnp) 130 1.1 hikaru { 131 1.1 hikaru struct iobus_attach_args *aa = aux; 132 1.1 hikaru 133 1.1 hikaru if (pnp) 134 1.1 hikaru aprint_normal("%s at %s", aa->aa_name, pnp); 135 1.1 hikaru 136 1.2 matt aprint_normal(" address 0x%016" PRIx64, aa->aa_unit->addr); 137 1.1 hikaru 138 1.1 hikaru return UNCONF; 139 1.1 hikaru } 140 1.1 hikaru 141 1.1 hikaru /* ---- */ 142 1.1 hikaru 143 1.1 hikaru void 144 1.1 hikaru iobus_init(struct iobus_softc *sc) 145 1.1 hikaru { 146 1.4 simonb 147 1.1 hikaru iobus_init_map(sc); 148 1.1 hikaru iobus_init_local(sc); 149 1.1 hikaru } 150 1.1 hikaru 151 1.1 hikaru void 152 1.1 hikaru iobus_init_map(struct iobus_softc *sc) 153 1.1 hikaru { 154 1.4 simonb 155 1.1 hikaru /* XXX map all ``operations'' space at once */ 156 1.1 hikaru bus_space_map( 157 1.1 hikaru iobus_bust, 158 1.1 hikaru 0x0001280000000000ULL, 159 1.1 hikaru 0x0001800000000000ULL - 0x0001280000000000ULL, 160 1.1 hikaru 0, 161 1.1 hikaru &sc->sc_ops_bush); 162 1.1 hikaru } 163 1.1 hikaru 164 1.1 hikaru void 165 1.1 hikaru iobus_init_local(struct iobus_softc *sc) 166 1.1 hikaru { 167 1.4 simonb 168 1.1 hikaru iobus_init_local_pow(sc); 169 1.1 hikaru iobus_init_local_fpa(sc); 170 1.1 hikaru } 171 1.1 hikaru 172 1.1 hikaru extern struct octeon_config octeon_configuration; 173 1.1 hikaru 174 1.1 hikaru void 175 1.1 hikaru iobus_init_local_pow(struct iobus_softc *sc) 176 1.1 hikaru { 177 1.4 simonb 178 1.3 simonb void octpow_bootstrap(struct octeon_config *); 179 1.1 hikaru 180 1.1 hikaru aprint_normal("%s: initializing POW\n", device_xname(sc->sc_dev)); 181 1.1 hikaru 182 1.3 simonb octpow_bootstrap(&octeon_configuration); 183 1.1 hikaru } 184 1.1 hikaru 185 1.1 hikaru void 186 1.1 hikaru iobus_init_local_fpa(struct iobus_softc *sc) 187 1.1 hikaru { 188 1.4 simonb 189 1.3 simonb void octfpa_bootstrap(struct octeon_config *); 190 1.1 hikaru 191 1.1 hikaru aprint_normal("%s: initializing FPA\n", device_xname(sc->sc_dev)); 192 1.1 hikaru 193 1.3 simonb octfpa_bootstrap(&octeon_configuration); 194 1.1 hikaru } 195 1.1 hikaru 196 1.1 hikaru /* ---- bus_space(9) */ 197 1.1 hikaru 198 1.1 hikaru #define CHIP iobus 199 1.1 hikaru #define CHIP_IO 200 1.1 hikaru #define CHIP_ACCESS_SIZE 8 201 1.1 hikaru 202 1.1 hikaru /* CIU and GPIO NCB type CSRs */ 203 1.1 hikaru #define CHIP_W1_BUS_START(v) 0x0001070000000000ULL 204 1.1 hikaru #define CHIP_W1_BUS_END(v) 0x00010700ffffffffULL 205 1.1 hikaru #define CHIP_W1_SYS_START(v) 0x8001070000000000ULL 206 1.1 hikaru #define CHIP_W1_SYS_END(v) 0x80010700ffffffffULL 207 1.1 hikaru 208 1.1 hikaru /* a number of RSL type CSRs */ 209 1.1 hikaru #define CHIP_W2_BUS_START(v) 0x0001180000000000ULL 210 1.1 hikaru #define CHIP_W2_BUS_END(v) 0x000118ffffffffffULL 211 1.1 hikaru #define CHIP_W2_SYS_START(v) 0x8001180000000000ULL 212 1.1 hikaru #define CHIP_W2_SYS_END(v) 0x800118ffffffffffULL 213 1.1 hikaru 214 1.1 hikaru /* load/IOBDMA/store operations */ 215 1.1 hikaru #define CHIP_W3_BUS_START(v) 0x0001280000000000ULL 216 1.1 hikaru #define CHIP_W3_BUS_END(v) 0x00017fffffffffffULL 217 1.1 hikaru #define CHIP_W3_SYS_START(v) 0x8001280000000000ULL 218 1.1 hikaru #define CHIP_W3_SYS_END(v) 0x80017fffffffffffULL 219 1.1 hikaru 220 1.1 hikaru #include <mips/mips/bus_space_alignstride_chipdep.c> 221