1 1.33 tsutsui /* $NetBSD: intio.c,v 1.33 2024/04/30 05:06:08 tsutsui Exp $ */ 2 1.1 thorpej 3 1.1 thorpej /*- 4 1.7 gmcgarry * Copyright (c) 1996, 1998, 2001 The NetBSD Foundation, Inc. 5 1.1 thorpej * All rights reserved. 6 1.1 thorpej * 7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation 8 1.1 thorpej * by Jason R. Thorpe. 9 1.1 thorpej * 10 1.1 thorpej * Redistribution and use in source and binary forms, with or without 11 1.1 thorpej * modification, are permitted provided that the following conditions 12 1.1 thorpej * are met: 13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright 14 1.1 thorpej * notice, this list of conditions and the following disclaimer. 15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the 17 1.1 thorpej * documentation and/or other materials provided with the distribution. 18 1.1 thorpej * 19 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.3 jtc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.3 jtc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE. 30 1.1 thorpej */ 31 1.1 thorpej 32 1.1 thorpej /* 33 1.1 thorpej * Autoconfiguration support for hp300 internal i/o space. 34 1.1 thorpej */ 35 1.1 thorpej 36 1.8 gmcgarry #include <sys/cdefs.h> 37 1.33 tsutsui __KERNEL_RCSID(0, "$NetBSD: intio.c,v 1.33 2024/04/30 05:06:08 tsutsui Exp $"); 38 1.8 gmcgarry 39 1.1 thorpej #include <sys/param.h> 40 1.1 thorpej #include <sys/systm.h> 41 1.18 tsutsui #include <sys/device.h> 42 1.7 gmcgarry 43 1.7 gmcgarry #include <machine/hp300spu.h> 44 1.7 gmcgarry 45 1.18 tsutsui #include <hp300/dev/intioreg.h> 46 1.1 thorpej #include <hp300/dev/intiovar.h> 47 1.1 thorpej 48 1.17 tsutsui struct intio_softc { 49 1.27 tsutsui device_t sc_dev; 50 1.17 tsutsui struct bus_space_tag sc_tag; 51 1.17 tsutsui }; 52 1.17 tsutsui 53 1.27 tsutsui static int intiomatch(device_t, cfdata_t, void *); 54 1.27 tsutsui static void intioattach(device_t, device_t, void *); 55 1.19 thorpej static int intioprint(void *, const char *); 56 1.1 thorpej 57 1.27 tsutsui CFATTACH_DECL_NEW(intio, sizeof(struct intio_softc), 58 1.12 thorpej intiomatch, intioattach, NULL, NULL); 59 1.1 thorpej 60 1.7 gmcgarry #if defined(HP320) || defined(HP330) || defined(HP340) || defined(HP345) || \ 61 1.7 gmcgarry defined(HP350) || defined(HP360) || defined(HP370) || defined(HP375) || \ 62 1.7 gmcgarry defined(HP380) || defined(HP385) 63 1.32 thorpej #define HAVE_INTIO_FB 64 1.7 gmcgarry #endif 65 1.7 gmcgarry 66 1.32 thorpej #if defined(HP382) || defined(HP400) || defined(HP425) || defined(HP433) 67 1.32 thorpej #define HAVE_INTIO_FRODO 68 1.29 tsutsui #endif 69 1.29 tsutsui 70 1.32 thorpej #define INTIO_3xx_BUILTINS \ 71 1.33 tsutsui (__BIT(HP_320) | __BIT(HP_330) | __BIT(HP_340) | \ 72 1.33 tsutsui __BIT(HP_345) | __BIT(HP_345) | __BIT(HP_350) | \ 73 1.33 tsutsui __BIT(HP_360) | __BIT(HP_370) | __BIT(HP_375) | \ 74 1.32 thorpej __BIT(HP_380) | __BIT(HP_385)) 75 1.32 thorpej 76 1.32 thorpej #define INTIO_362_BUILTINS __BIT(HP_362) 77 1.32 thorpej #define INTIO_382_BUILTINS __BIT(HP_382) 78 1.32 thorpej 79 1.32 thorpej #define INTIO_4xx_BUILTINS \ 80 1.32 thorpej (__BIT(HP_400) | __BIT(HP_425) | __BIT(HP_433)) 81 1.32 thorpej 82 1.32 thorpej #define INTIO_ALL_BUILTINS \ 83 1.32 thorpej (INTIO_3xx_BUILTINS | INTIO_362_BUILTINS | \ 84 1.32 thorpej INTIO_382_BUILTINS | INTIO_4xx_BUILTINS) 85 1.32 thorpej 86 1.32 thorpej static const struct intio_builtins intio_builtins[] = { 87 1.32 thorpej { "rtc", RTC_BASE, -1, 88 1.32 thorpej INTIO_ALL_BUILTINS }, 89 1.32 thorpej 90 1.32 thorpej #ifdef HAVE_INTIO_FRODO 91 1.32 thorpej { "frodo", FRODO_BASE, 5, 92 1.32 thorpej INTIO_382_BUILTINS | INTIO_4xx_BUILTINS }, 93 1.25 tsutsui #endif 94 1.25 tsutsui 95 1.32 thorpej { "hil", HIL_BASE, 1, 96 1.32 thorpej INTIO_ALL_BUILTINS }, 97 1.32 thorpej 98 1.32 thorpej { "hpib", HPIB_BASE, 3, 99 1.32 thorpej INTIO_ALL_BUILTINS }, 100 1.32 thorpej 101 1.32 thorpej { "dma", DMA_BASE, 1, 102 1.32 thorpej INTIO_ALL_BUILTINS }, 103 1.32 thorpej 104 1.32 thorpej #ifdef HAVE_INTIO_FB 105 1.32 thorpej { "fb", FB_BASE, -1, 106 1.32 thorpej INTIO_3xx_BUILTINS }, 107 1.32 thorpej #endif 108 1.7 gmcgarry }; 109 1.32 thorpej #define nintio_builtins __arraycount(intio_builtins) 110 1.7 gmcgarry 111 1.7 gmcgarry static int intio_matched = 0; 112 1.26 christos extern void *internalhpib; 113 1.7 gmcgarry 114 1.19 thorpej static int 115 1.27 tsutsui intiomatch(device_t parent, cfdata_t cf, void *aux) 116 1.1 thorpej { 117 1.27 tsutsui 118 1.1 thorpej /* Allow only one instance. */ 119 1.1 thorpej if (intio_matched) 120 1.21 tsutsui return 0; 121 1.1 thorpej 122 1.1 thorpej intio_matched = 1; 123 1.21 tsutsui return 1; 124 1.1 thorpej } 125 1.1 thorpej 126 1.19 thorpej static void 127 1.27 tsutsui intioattach(device_t parent, device_t self, void *aux) 128 1.1 thorpej { 129 1.27 tsutsui struct intio_softc *sc = device_private(self); 130 1.7 gmcgarry struct intio_attach_args ia; 131 1.17 tsutsui bus_space_tag_t bst = &sc->sc_tag; 132 1.32 thorpej const uint32_t spumask = 1U << machineid; 133 1.7 gmcgarry int i; 134 1.1 thorpej 135 1.27 tsutsui sc->sc_dev = self; 136 1.27 tsutsui aprint_normal("\n"); 137 1.1 thorpej 138 1.32 thorpej KASSERT(spumask != 0); 139 1.32 thorpej 140 1.17 tsutsui memset(bst, 0, sizeof(struct bus_space_tag)); 141 1.17 tsutsui bst->bustype = HP300_BUS_SPACE_INTIO; 142 1.17 tsutsui 143 1.32 thorpej memset(&ia, 0, sizeof(ia)); 144 1.7 gmcgarry 145 1.32 thorpej for (i = 0; i < nintio_builtins; i++) { 146 1.7 gmcgarry 147 1.32 thorpej /* 148 1.32 thorpej * If the device doesn't exist on this specific model, 149 1.32 thorpej * skip it. 150 1.32 thorpej */ 151 1.32 thorpej if ((intio_builtins[i].ib_spumask & spumask) == 0) 152 1.32 thorpej continue; 153 1.15 gmcgarry 154 1.15 gmcgarry /* 155 1.15 gmcgarry * Internal HP-IB doesn't always return a device ID, 156 1.15 gmcgarry * so we rely on the sysflags. 157 1.15 gmcgarry */ 158 1.32 thorpej if (intio_builtins[i].ib_offset == HPIB_BASE && !internalhpib) 159 1.15 gmcgarry continue; 160 1.15 gmcgarry 161 1.32 thorpej strlcpy(ia.ia_modname, intio_builtins[i].ib_modname, 162 1.24 tsutsui sizeof(ia.ia_modname)); 163 1.17 tsutsui ia.ia_bst = bst; 164 1.32 thorpej ia.ia_iobase = intio_builtins[i].ib_offset; 165 1.32 thorpej ia.ia_addr = 166 1.32 thorpej (bus_addr_t)(intiobase + intio_builtins[i].ib_offset); 167 1.32 thorpej ia.ia_ipl = intio_builtins[i].ib_ipl; 168 1.31 thorpej config_found(self, &ia, intioprint, CFARGS_NONE); 169 1.7 gmcgarry } 170 1.1 thorpej } 171 1.1 thorpej 172 1.19 thorpej static int 173 1.19 thorpej intioprint(void *aux, const char *pnp) 174 1.1 thorpej { 175 1.1 thorpej struct intio_attach_args *ia = aux; 176 1.1 thorpej 177 1.9 gmcgarry if (pnp != NULL) 178 1.14 thorpej aprint_normal("%s at %s", ia->ia_modname, pnp); 179 1.15 gmcgarry if (ia->ia_iobase != 0 && pnp == NULL) { 180 1.15 gmcgarry aprint_normal(" addr 0x%lx", INTIOBASE + ia->ia_iobase); 181 1.15 gmcgarry if (ia->ia_ipl != -1) 182 1.14 thorpej aprint_normal(" ipl %d", ia->ia_ipl); 183 1.7 gmcgarry } 184 1.21 tsutsui return UNCONF; 185 1.1 thorpej } 186