1 /* $NetBSD: intio.c,v 1.18 2003/11/17 14:37:59 tsutsui Exp $ */ 2 3 /*- 4 * Copyright (c) 1996, 1998, 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * Autoconfiguration support for hp300 internal i/o space. 41 */ 42 43 #include <sys/cdefs.h> 44 __KERNEL_RCSID(0, "$NetBSD: intio.c,v 1.18 2003/11/17 14:37:59 tsutsui Exp $"); 45 46 #include <sys/param.h> 47 #include <sys/systm.h> 48 #include <sys/device.h> 49 50 #include <machine/hp300spu.h> 51 52 #include <hp300/dev/intioreg.h> 53 #include <hp300/dev/intiovar.h> 54 55 struct intio_softc { 56 struct device sc_dev; 57 struct bus_space_tag sc_tag; 58 }; 59 60 int intiomatch(struct device *, struct cfdata *, void *); 61 void intioattach(struct device *, struct device *, void *); 62 int intioprint(void *, const char *); 63 64 CFATTACH_DECL(intio, sizeof(struct intio_softc), 65 intiomatch, intioattach, NULL, NULL); 66 67 #if defined(HP320) || defined(HP330) || defined(HP340) || defined(HP345) || \ 68 defined(HP350) || defined(HP360) || defined(HP370) || defined(HP375) || \ 69 defined(HP380) || defined(HP385) 70 const struct intio_builtins intio_3xx_builtins[] = { 71 { "rtc", 0x020000, -1}, 72 { "hil", 0x028000, 1}, 73 { "hpib", 0x078000, 3}, 74 { "dma", 0x100000, 1}, 75 { "fb", 0x160000, -1}, 76 }; 77 #define nintio_3xx_builtins \ 78 (sizeof(intio_3xx_builtins) / sizeof(intio_3xx_builtins[0])) 79 #endif 80 81 #if defined(HP400) || defined(HP425) || defined(HP433) 82 const struct intio_builtins intio_4xx_builtins[] = { 83 { "rtc", 0x020000, -1}, 84 { "frodo", 0x01c000, 5}, 85 { "hil", 0x028000, 1}, 86 { "hpib", 0x078000, 3}, 87 { "dma", 0x100000, 1}, 88 }; 89 #define nintio_4xx_builtins \ 90 (sizeof(intio_4xx_builtins) / sizeof(intio_4xx_builtins[0])) 91 #endif 92 93 static int intio_matched = 0; 94 extern caddr_t internalhpib; 95 96 int 97 intiomatch(parent, match, aux) 98 struct device *parent; 99 struct cfdata *match; 100 void *aux; 101 { 102 /* Allow only one instance. */ 103 if (intio_matched) 104 return (0); 105 106 intio_matched = 1; 107 return (1); 108 } 109 110 void 111 intioattach(parent, self, aux) 112 struct device *parent, *self; 113 void *aux; 114 { 115 struct intio_softc *sc = (struct intio_softc *)self; 116 struct intio_attach_args ia; 117 const struct intio_builtins *ib; 118 bus_space_tag_t bst = &sc->sc_tag; 119 int ndevs; 120 int i; 121 122 printf("\n"); 123 124 memset(bst, 0, sizeof(struct bus_space_tag)); 125 bst->bustype = HP300_BUS_SPACE_INTIO; 126 127 switch (machineid) { 128 #if defined(HP320) || defined(HP330) || defined(HP340) || defined(HP345) || \ 129 defined(HP350) || defined(HP360) || defined(HP370) || defined(HP375) || \ 130 defined(HP380) || defined(HP385) 131 case HP_320: 132 case HP_330: 133 case HP_340: 134 case HP_345: 135 case HP_350: 136 case HP_360: 137 case HP_370: 138 case HP_375: 139 case HP_380: 140 case HP_385: 141 ib = intio_3xx_builtins; 142 ndevs = nintio_3xx_builtins; 143 break; 144 #endif 145 #if defined(HP400) || defined(HP425) || defined(HP433) 146 case HP_400: 147 case HP_425: 148 case HP_433: 149 ib = intio_4xx_builtins; 150 ndevs = nintio_4xx_builtins; 151 break; 152 #endif 153 default: 154 return; 155 } 156 157 memset(&ia, 0, sizeof(ia)); 158 159 for (i = 0; i < ndevs; i++) { 160 161 /* 162 * Internal HP-IB doesn't always return a device ID, 163 * so we rely on the sysflags. 164 */ 165 if (ib[i].ib_offset == 0x078000 && !internalhpib) 166 continue; 167 168 strncpy(ia.ia_modname, ib[i].ib_modname, INTIO_MOD_LEN); 169 ia.ia_modname[INTIO_MOD_LEN] = '\0'; 170 ia.ia_bst = bst; 171 ia.ia_iobase = ib[i].ib_offset; 172 ia.ia_addr = (bus_addr_t)(intiobase + ib[i].ib_offset); 173 ia.ia_ipl = ib[i].ib_ipl; 174 config_found(self, &ia, intioprint); 175 } 176 } 177 178 int 179 intioprint(aux, pnp) 180 void *aux; 181 const char *pnp; 182 { 183 struct intio_attach_args *ia = aux; 184 185 if (pnp != NULL) 186 aprint_normal("%s at %s", ia->ia_modname, pnp); 187 if (ia->ia_iobase != 0 && pnp == NULL) { 188 aprint_normal(" addr 0x%lx", INTIOBASE + ia->ia_iobase); 189 if (ia->ia_ipl != -1) 190 aprint_normal(" ipl %d", ia->ia_ipl); 191 } 192 return (UNCONF); 193 } 194