1 /* $NetBSD: nmi_mainbus.c,v 1.14 2021/08/07 16:19:07 thorpej Exp $ */ 2 /* 3 * Copyright (c) 2000 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 #include <sys/cdefs.h> 28 __KERNEL_RCSID(0, "$NetBSD: nmi_mainbus.c,v 1.14 2021/08/07 16:19:07 thorpej Exp $"); 29 30 #define _VAX_BUS_DMA_PRIVATE 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/bus.h> 35 #include <sys/cpu.h> 36 #include <sys/device.h> 37 38 #include <machine/nexus.h> 39 #include <machine/sid.h> 40 #include <machine/scb.h> 41 #include <machine/ka88.h> 42 #include <machine/mainbus.h> 43 44 #include "ioconf.h" 45 46 static int 47 nmi_mainbus_print(void *aux, const char *name) 48 { 49 struct nmi_attach_args *na = aux; 50 const char *c; 51 52 if (name) { 53 if (na->na_slot < 10) 54 c = "bi"; 55 else if (na->na_slot < 20) 56 c = "mem"; 57 else 58 c = "cpu"; 59 aprint_normal("%s at %s", c, name); 60 if (na->na_slot < 10) 61 aprint_normal(" slot %d", na->na_slot); 62 if (vax_boardtype == VAX_BTYP_8800 && na->na_slot > 20) 63 aprint_normal(" (%s)", ka88_confdata & KA88_LEFTPRIM ? 64 "right" : "left"); 65 } 66 return UNCONF; 67 } 68 69 static int 70 nmi_mainbus_match(device_t parent, cfdata_t cf, void *aux) 71 { 72 struct mainbus_attach_args * const ma = aux; 73 74 return !strcmp(nmi_cd.cd_name, ma->ma_type); 75 } 76 77 static void 78 nmi_mainbus_attach(device_t parent, device_t self, void *aux) 79 { 80 struct mainbus_attach_args * const ma = aux; 81 struct nmi_attach_args na; 82 int nbia, *r = 0; 83 84 aprint_normal("\n"); 85 86 na.na_iot = ma->ma_iot; 87 na.na_dmat = ma->ma_dmat; 88 89 /* One CPU is always found */ 90 na.na_type = "cpu"; 91 na.na_slot = 20; 92 config_found(self, (void *)&na, nmi_mainbus_print, CFARGS_NONE); 93 94 /* Check for a second one */ 95 if (vax_boardtype == VAX_BTYP_8800) { 96 na.na_type = "cpu"; 97 na.na_slot = 21; 98 config_found(self, (void *)&na, nmi_mainbus_print, CFARGS_NONE); 99 } 100 101 /* One memory adapter is also present */ 102 na.na_type = "mem"; 103 na.na_slot = 10; 104 config_found(self, (void *)&na, nmi_mainbus_print, CFARGS_NONE); 105 106 /* Enable BI interrupts */ 107 mtpr(NICTRL_DEV0|NICTRL_DEV1|NICTRL_MNF, PR_NICTRL); 108 109 /* Search for NBIA/NBIB adapters */ 110 na.na_type = "bi"; 111 for (nbia = 0; nbia < 2; nbia++) { 112 if (r) 113 vax_unmap_physmem((vaddr_t)r, 1); 114 r = (int *)vax_map_physmem(NBIA_REGS(nbia), 1); 115 if (badaddr((void *)r, 4)) 116 continue; 117 na.na_slot = 2 * nbia; 118 if (r[1] & 2) 119 config_found(self, (void *)&na, nmi_mainbus_print, 120 CFARGS_NONE); 121 na.na_slot++; 122 if (r[1] & 4) 123 config_found(self, (void *)&na, nmi_mainbus_print, 124 CFARGS_NONE); 125 } 126 } 127 128 CFATTACH_DECL_NEW(nmi_mainbus, 0, 129 nmi_mainbus_match, nmi_mainbus_attach, NULL, NULL); 130