1 /* $NetBSD: sbi.c,v 1.26 2002/10/02 16:02:36 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 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed at Ludd, University of Lule}. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * Still to do: Write all SBI error handling. 34 */ 35 36 #include <sys/types.h> 37 #include <sys/param.h> 38 #include <sys/device.h> 39 #include <sys/systm.h> 40 41 #include <machine/bus.h> 42 #include <machine/sid.h> 43 #include <machine/cpu.h> 44 #include <machine/nexus.h> 45 46 static int sbi_print(void *, const char *); 47 static int sbi_match(struct device *, struct cfdata *, void *); 48 static int sbi_match_abus(struct device *, struct cfdata *, void *); 49 static void sbi_attach(struct device *, struct device *, void*); 50 51 int 52 sbi_print(void *aux, const char *name) 53 { 54 struct sbi_attach_args *sa = (struct sbi_attach_args *)aux; 55 int unsupp = 0; 56 57 if (name) { 58 switch (sa->sa_type) { 59 case NEX_MBA: 60 printf("mba at %s", name); 61 break; 62 case NEX_CI: 63 printf("ci at %s", name); 64 unsupp++; 65 break; 66 default: 67 printf("unknown device 0x%x at %s", sa->sa_type, name); 68 unsupp++; 69 } 70 } 71 printf(" tr%d", sa->sa_nexnum); 72 return (unsupp ? UNSUPP : UNCONF); 73 } 74 75 int 76 sbi_match_abus(struct device *parent, struct cfdata *cf, void *aux) 77 { 78 struct bp_conf *bp = aux; 79 80 if (bp->num == 0) /* XXX - only one SBI */ 81 return 1; 82 return 0; 83 } 84 85 int 86 sbi_match(struct device *parent, struct cfdata *cf, void *aux) 87 { 88 if (vax_bustype == VAX_SBIBUS) 89 return 1; 90 return 0; 91 } 92 93 void 94 sbi_attach(struct device *parent, struct device *self, void *aux) 95 { 96 struct bp_conf *bp = aux; 97 u_int nexnum, minnex; 98 struct sbi_attach_args sa; 99 100 printf("\n"); 101 102 #define NEXPAGES (sizeof(struct nexus) / VAX_NBPG) 103 if (vax_boardtype == VAX_BTYP_780) { 104 minnex = 0; /* only one SBI */ 105 sa.sa_sbinum = 0; 106 } 107 if (vax_boardtype == VAX_BTYP_790) { 108 minnex = bp->num * NNEXSBI; 109 sa.sa_sbinum = bp->num; 110 } 111 for (nexnum = minnex; nexnum < minnex + NNEXSBI; nexnum++) { 112 struct nexus *nexusP = 0; 113 volatile int tmp; 114 115 nexusP = (struct nexus *)vax_map_physmem((paddr_t)NEXA8600 + 116 sizeof(struct nexus) * nexnum, NEXPAGES); 117 if (badaddr((caddr_t)nexusP, 4)) { 118 vax_unmap_physmem((vaddr_t)nexusP, NEXPAGES); 119 } else { 120 tmp = nexusP->nexcsr.nex_csr; /* no byte reads */ 121 sa.sa_type = tmp & 255; 122 123 sa.sa_nexnum = nexnum; 124 sa.sa_ioh = (vaddr_t)nexusP; 125 config_found(self, (void*)&sa, sbi_print); 126 } 127 } 128 } 129 130 CFATTACH_DECL(sbi_mainbus, sizeof(struct device), 131 sbi_match, sbi_attach, NULL, NULL); 132 133 CFATTACH_DECL(sbi_abus, sizeof(struct device), 134 sbi_match_abus, sbi_attach, NULL, NULL); 135