1 /* $NetBSD: sbi.c,v 1.40 2021/08/07 16:19:07 thorpej Exp $ */ 2 /* 3 * Copyright (c) 1994 Ludd, University of Lule}, Sweden. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 /* 28 * ABus code added by Johnny Billquist 2010 29 */ 30 31 /* 32 * Still to do: Write all SBI error handling. 33 */ 34 35 #include <sys/cdefs.h> 36 __KERNEL_RCSID(0, "$NetBSD: sbi.c,v 1.40 2021/08/07 16:19:07 thorpej Exp $"); 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/bus.h> 41 #include <sys/cpu.h> 42 #include <sys/device.h> 43 44 #include <machine/sid.h> 45 #include <machine/nexus.h> 46 #include <machine/mainbus.h> 47 #include <machine/ioa.h> 48 49 static int sbi_print(void *, const char *); 50 #if VAX780 || VAXANY 51 static int sbi_mainbus_match(device_t, cfdata_t, void *); 52 static void sbi_mainbus_attach(device_t, device_t, void*); 53 #endif 54 #if VAX8600 || VAXANY 55 static int sbi_abus_match(device_t, cfdata_t, void *); 56 static void sbi_abus_attach(device_t, device_t, void*); 57 #endif 58 59 int 60 sbi_print(void *aux, const char *name) 61 { 62 struct sbi_attach_args *sa = aux; 63 bool unsupp = false; 64 65 if (name) { 66 switch (sa->sa_type) { 67 case NEX_MBA: 68 aprint_naive("mba at %s", name); 69 aprint_normal("mba at %s", name); 70 break; 71 case NEX_CI: 72 aprint_naive("ci at %s", name); 73 aprint_normal("ci at %s", name); 74 unsupp = true; 75 break; 76 default: 77 aprint_naive("unknown device 0x%x at %s", 78 sa->sa_type, name); 79 aprint_normal("unknown device 0x%x at %s", 80 sa->sa_type, name); 81 unsupp = true; 82 } 83 } 84 aprint_naive(" tr%d", sa->sa_nexnum); 85 aprint_normal(" tr%d", sa->sa_nexnum); 86 return (unsupp ? UNSUPP : UNCONF); 87 } 88 89 #if VAX780 || VAXANY 90 int 91 sbi_mainbus_match(device_t parent, cfdata_t cf, void *aux) 92 { 93 struct mainbus_attach_args * const ma = aux; 94 95 return !strcmp("sbi", ma->ma_type); 96 } 97 98 void 99 sbi_mainbus_attach(device_t parent, device_t self, void *aux) 100 { 101 struct mainbus_attach_args * const ma = aux; 102 struct sbi_attach_args sa; 103 u_int nexnum; 104 105 aprint_naive("\n"); 106 aprint_normal("\n"); 107 108 sa.sa_iot = ma->ma_iot; 109 sa.sa_dmat = ma->ma_dmat; 110 111 #define NEXPAGES (sizeof(struct nexus) / VAX_NBPG) 112 sa.sa_sbinum = 0; 113 114 for (nexnum = 0; nexnum < NNEXSBI; nexnum++) { 115 struct nexus *nexusP = 0; 116 volatile int tmp; 117 118 nexusP = (struct nexus *)vax_map_physmem((paddr_t)(NEX780) + 119 sizeof(struct nexus) * nexnum, NEXPAGES); 120 if (badaddr((void *)nexusP, 4)) { 121 vax_unmap_physmem((vaddr_t)nexusP, NEXPAGES); 122 } else { 123 tmp = nexusP->nexcsr.nex_csr; /* no byte reads */ 124 sa.sa_type = tmp & 255; 125 126 sa.sa_nexnum = nexnum; 127 sa.sa_ioh = (vaddr_t)nexusP; 128 sa.sa_base = (bus_addr_t)NEX780; 129 config_found(self, (void*)&sa, sbi_print, CFARGS_NONE); 130 } 131 } 132 } 133 134 CFATTACH_DECL_NEW(sbi_mainbus, 0, 135 sbi_mainbus_match, sbi_mainbus_attach, NULL, NULL); 136 137 #endif 138 139 #if VAX8600 || VAXANY 140 int 141 sbi_abus_match(device_t parent, cfdata_t cf, void *aux) 142 { 143 struct abus_attach_args * const aa = aux; 144 145 return ((aa->aa_type & IOA_TYPMSK) == IOA_SBIA); 146 } 147 148 void 149 sbi_abus_attach(device_t parent, device_t self, void *aux) 150 { 151 struct abus_attach_args * const aa = aux; 152 struct sbi_attach_args sa; 153 u_int nexnum, minnex; 154 155 aprint_naive(": SBIA Rev. %d, base address %#x\n", aa->aa_type & 0xf, (unsigned int)aa->aa_base); 156 aprint_normal(": SBIA Rev. %d, base address %#x\n", aa->aa_type & 0xf, (unsigned int)aa->aa_base); 157 158 sa.sa_iot = aa->aa_iot; 159 sa.sa_dmat = aa->aa_dmat; 160 sa.sa_base = aa->aa_base; 161 162 #define NEXPAGES (sizeof(struct nexus) / VAX_NBPG) 163 minnex = aa->aa_num * NNEXSBI; 164 sa.sa_sbinum = aa->aa_num; 165 166 for (nexnum = minnex; nexnum < minnex + NNEXSBI; nexnum++) { 167 struct nexus *nexusP = 0; 168 volatile int tmp; 169 170 nexusP = (struct nexus *)vax_map_physmem(sa.sa_base + 171 sizeof(struct nexus) * nexnum, NEXPAGES); 172 if (badaddr((void *)nexusP, 4)) { 173 vax_unmap_physmem((vaddr_t)nexusP, NEXPAGES); 174 } else { 175 tmp = nexusP->nexcsr.nex_csr; /* no byte reads */ 176 sa.sa_type = tmp & 255; 177 178 sa.sa_nexnum = nexnum; 179 sa.sa_ioh = (vaddr_t)nexusP; 180 config_found(self, (void*)&sa, sbi_print, CFARGS_NONE); 181 } 182 } 183 } 184 185 186 CFATTACH_DECL_NEW(sbi_abus, 0, 187 sbi_abus_match, sbi_abus_attach, NULL, NULL); 188 189 #endif 190