1 /* $NetBSD: xel.c,v 1.19 2026/04/26 10:52:16 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Minoura Makoto. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * TSR Xellent30 driver. 34 * Detect Xellent30, and reserve its I/O area. 35 */ 36 37 #include <sys/cdefs.h> 38 __KERNEL_RCSID(0, "$NetBSD: xel.c,v 1.19 2026/04/26 10:52:16 thorpej Exp $"); 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/kernel.h> 43 #include <sys/device.h> 44 45 #include <machine/cpu.h> 46 #include <machine/bus.h> 47 48 #include <arch/x68k/dev/intiovar.h> 49 50 static paddr_t xel_addr(device_t, cfdata_t, struct intio_attach_args *); 51 static int xel_probe(paddr_t); 52 static int xel_match(device_t, cfdata_t, void *); 53 static void xel_attach(device_t, device_t, void *); 54 55 struct xel_softc { 56 bus_space_tag_t sc_bst; 57 bus_space_handle_t sc_bh; 58 }; 59 60 CFATTACH_DECL_NEW(xel, sizeof(struct xel_softc), 61 xel_match, xel_attach, NULL, NULL); 62 63 static paddr_t xel_addrs[] = { 0xec0000, 0xec4000, 0xec8000, 0xecc000 }; 64 65 #define XEL_MODE_RAM_LOWER 0x00 66 #define XEL_MODE_RAM_HIGHER 0x01 67 #define XEL_MODE_UNMAP_RAM 0x00 68 #define XEL_MODE_MAP_RAM 0x02 69 #define XEL_MODE_MPU_000 0x00 70 #define XEL_MODE_MPU_030 0x04 71 72 #define XEL_RAM_ADDR_LOWER 0xbc0000 73 #define XEL_RAM_ADDR_HIGHER 0xfc0000 74 75 76 static paddr_t 77 xel_addr(device_t parent, cfdata_t match, struct intio_attach_args *ia) 78 { 79 paddr_t addr = 0; 80 81 if (match->cf_addr == INTIOCF_ADDR_DEFAULT) { 82 int i; 83 84 for (i = 0; i < sizeof(xel_addrs)/sizeof(xel_addrs[0]); i++) { 85 if (xel_probe(xel_addrs[i])) { 86 addr = xel_addrs[i]; 87 break; 88 } 89 } 90 } else { 91 if (xel_probe((paddr_t) match->cf_addr)) 92 addr = (paddr_t) match->cf_addr; 93 } 94 95 if (addr) { 96 /* found! */ 97 ia->ia_addr = (int) addr; 98 ia->ia_size = 0x4000; 99 if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY) 100 < 0) 101 return 0; 102 else 103 return addr; 104 } 105 106 return 0; 107 } 108 109 static int 110 xel_probe(paddr_t addr) 111 { 112 u_int32_t b1, b2; 113 volatile u_int16_t *start = (volatile u_int16_t *)IIOV(addr); 114 label_t faultbuf; 115 volatile u_int32_t *sram = (volatile u_int32_t *)IIOV(XEL_RAM_ADDR_HIGHER); 116 117 if (badaddr(start)) 118 return 0; 119 120 nofault = &faultbuf; 121 if (setjmp(&faultbuf)) { 122 nofault = NULL; 123 return 0; 124 } 125 126 b1 = sram[0]; 127 b2 = sram[1]; 128 /* Try to map the Xellent local memory. */ 129 start[0] = XEL_MODE_RAM_HIGHER | XEL_MODE_MAP_RAM | XEL_MODE_MPU_030; 130 131 #if 0 132 /* the contents should be deferent. */ 133 if (b1 == sram[0] && b2 == sram[1]) { 134 nofault = NULL; 135 return 0; 136 } 137 #else 138 /* Try to write to the local memory. */ 139 sram[0] = 0x55555555; 140 sram[1] = 0xaaaaaaaa; 141 if (sram[0] != 0x55555555 || sram[1] != 0xaaaaaaaa) { 142 sram[0] = b1; 143 sram[1] = b2; 144 nofault = NULL; 145 return 0; 146 } 147 sram[0] = 0xaaaaaaaa; 148 sram[1] = 0x55555555; 149 if (sram[0] != 0xaaaaaaaa || sram[1] != 0x55555555) { 150 sram[0] = b1; 151 sram[1] = b2; 152 nofault = NULL; 153 return 0; 154 } 155 sram[0] = b1; 156 sram[1] = b2; 157 #endif 158 159 /* Unmap. */ 160 start[0] = XEL_MODE_UNMAP_RAM | XEL_MODE_MPU_030; 161 162 nofault = NULL; 163 return 1; 164 } 165 166 static int 167 xel_match(device_t parent, cfdata_t match, void *aux) 168 { 169 struct intio_attach_args *ia = aux; 170 171 if (strcmp(ia->ia_name, "xel") != 0) 172 return 0; 173 174 if (xel_addr(parent, match, ia)) { 175 #ifdef DIAGNOSTIC 176 if (cputype != CPU_68030) 177 panic("Non-030 Xellent???"); 178 #endif 179 return 1; 180 } 181 return 0; 182 } 183 184 static void 185 xel_attach(device_t parent, device_t self, void *aux) 186 { 187 struct xel_softc *sc = device_private(self); 188 struct intio_attach_args *ia = aux; 189 cfdata_t cf = device_cfdata(self); 190 paddr_t addr; 191 int r __diagused; 192 193 addr = xel_addr(parent, cf, aux); 194 sc->sc_bst = ia->ia_bst; 195 ia->ia_addr = (int) addr; 196 ia->ia_size = 0x4000; 197 r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE); 198 #ifdef DIAGNOSTIC 199 if (r) 200 panic("IO map for Xellent30 corruption??"); 201 #endif 202 aprint_normal(": Xellent30 MPU Accelerator.\n"); 203 204 return; 205 } 206