1 1.4 macallan /* $NetBSD: ctl.c,v 1.4 2015/02/18 16:47:58 macallan Exp $ */ 2 1.1 rumble 3 1.1 rumble /* 4 1.1 rumble * Copyright (c) 2009 Stephen M. Rumble 5 1.1 rumble * All rights reserved. 6 1.1 rumble * 7 1.1 rumble * Redistribution and use in source and binary forms, with or without 8 1.1 rumble * modification, are permitted provided that the following conditions 9 1.1 rumble * are met: 10 1.1 rumble * 1. Redistributions of source code must retain the above copyright 11 1.1 rumble * notice, this list of conditions and the following disclaimer. 12 1.1 rumble * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 rumble * notice, this list of conditions and the following disclaimer in the 14 1.1 rumble * documentation and/or other materials provided with the distribution. 15 1.1 rumble * 3. The name of the author may not be used to endorse or promote products 16 1.1 rumble * derived from this software without specific prior written permission. 17 1.1 rumble * 18 1.1 rumble * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 1.1 rumble * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 1.1 rumble * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 1.1 rumble * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 1.1 rumble * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 1.1 rumble * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 1.1 rumble * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 1.1 rumble * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 1.1 rumble * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 1.1 rumble * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 1.1 rumble */ 29 1.1 rumble 30 1.1 rumble #include <sys/cdefs.h> 31 1.4 macallan __KERNEL_RCSID(0, "$NetBSD: ctl.c,v 1.4 2015/02/18 16:47:58 macallan Exp $"); 32 1.1 rumble 33 1.1 rumble #include <sys/param.h> 34 1.1 rumble #include <sys/kernel.h> 35 1.1 rumble #include <sys/device.h> 36 1.1 rumble #include <sys/systm.h> 37 1.1 rumble #include <sys/callout.h> 38 1.1 rumble 39 1.1 rumble #include <machine/cpu.h> 40 1.1 rumble #include <machine/locore.h> 41 1.1 rumble #include <machine/autoconf.h> 42 1.3 dyoung #include <sys/bus.h> 43 1.1 rumble #include <machine/machtype.h> 44 1.1 rumble #include <machine/sysconf.h> 45 1.1 rumble 46 1.1 rumble #include <sgimips/dev/ctlreg.h> 47 1.1 rumble 48 1.1 rumble struct ctl_softc { 49 1.2 matt device_t sc_dev; 50 1.1 rumble 51 1.1 rumble bus_space_tag_t iot; 52 1.1 rumble bus_space_handle_t ioh; 53 1.1 rumble }; 54 1.1 rumble 55 1.2 matt static int ctl_match(device_t, cfdata_t, void *); 56 1.2 matt static void ctl_attach(device_t, device_t, void *); 57 1.1 rumble static void ctl_bus_reset(void); 58 1.2 matt static void ctl_bus_error(vaddr_t, uint32_t, uint32_t); 59 1.1 rumble static void ctl_watchdog_enable(void); 60 1.1 rumble static void ctl_watchdog_disable(void); 61 1.1 rumble static void ctl_watchdog_tickle(void); 62 1.1 rumble 63 1.1 rumble #if defined(BLINK) 64 1.1 rumble static callout_t ctl_blink_ch; 65 1.1 rumble static void ctl_blink(void *); 66 1.1 rumble #endif 67 1.1 rumble 68 1.2 matt CFATTACH_DECL_NEW(ctl, sizeof(struct ctl_softc), 69 1.1 rumble ctl_match, ctl_attach, NULL, NULL); 70 1.1 rumble 71 1.2 matt static struct ctl_softc *csc; 72 1.1 rumble 73 1.1 rumble static int 74 1.2 matt ctl_match(device_t parent, cfdata_t match, void *aux) 75 1.1 rumble { 76 1.2 matt if (csc != NULL) 77 1.2 matt return 0; 78 1.2 matt 79 1.1 rumble /* 80 1.1 rumble * CTL exists on IP6/IP10 systems. 81 1.1 rumble */ 82 1.1 rumble if (mach_type == MACH_SGI_IP6 || mach_type == MACH_SGI_IP10) 83 1.1 rumble return 1; 84 1.1 rumble else 85 1.1 rumble return 0; 86 1.1 rumble } 87 1.1 rumble 88 1.1 rumble static void 89 1.2 matt ctl_attach(device_t parent, device_t self, void *aux) 90 1.1 rumble { 91 1.1 rumble struct mainbus_attach_args *ma = aux; 92 1.2 matt struct ctl_softc * const sc = device_private(self); 93 1.1 rumble 94 1.1 rumble #ifdef BLINK 95 1.1 rumble callout_init(&ctl_blink_ch, 0); 96 1.1 rumble #endif 97 1.1 rumble 98 1.2 matt sc->sc_dev = self; 99 1.2 matt csc = sc; 100 1.2 matt 101 1.4 macallan sc->iot = normal_memt; 102 1.4 macallan if (bus_space_map(sc->iot, ma->ma_addr, 0x10000 /* XXX */, 103 1.2 matt BUS_SPACE_MAP_LINEAR, &sc->ioh)) 104 1.1 rumble panic("ctl_attach: could not allocate memory\n"); 105 1.1 rumble 106 1.1 rumble platform.bus_reset = ctl_bus_reset; 107 1.1 rumble platform.intr5 = ctl_bus_error; 108 1.1 rumble platform.watchdog_enable = ctl_watchdog_enable; 109 1.1 rumble platform.watchdog_disable = ctl_watchdog_disable; 110 1.1 rumble platform.watchdog_reset = ctl_watchdog_tickle; 111 1.1 rumble 112 1.2 matt bus_space_write_2(sc->iot, sc->ioh, CTL_CPUCTRL, 113 1.1 rumble (CTL_CPUCTRL_PARITY | CTL_CPUCTRL_SLAVE)); 114 1.1 rumble 115 1.1 rumble printf("\n"); 116 1.1 rumble 117 1.1 rumble ctl_bus_reset(); 118 1.1 rumble 119 1.1 rumble #if defined(BLINK) 120 1.2 matt ctl_blink(sc); 121 1.1 rumble #endif 122 1.1 rumble } 123 1.1 rumble 124 1.1 rumble static void 125 1.1 rumble ctl_bus_reset(void) 126 1.1 rumble { 127 1.2 matt struct ctl_softc * const sc = csc; 128 1.1 rumble 129 1.2 matt bus_space_read_1(sc->iot, sc->ioh, CTL_LAN_PAR_CLR); 130 1.2 matt bus_space_read_1(sc->iot, sc->ioh, CTL_DMA_PAR_CLR); 131 1.2 matt bus_space_read_1(sc->iot, sc->ioh, CTL_CPU_PAR_CLR); 132 1.2 matt bus_space_read_1(sc->iot, sc->ioh, CTL_VME_PAR_CLR); 133 1.1 rumble } 134 1.1 rumble 135 1.1 rumble static void 136 1.2 matt ctl_bus_error(vaddr_t pc, uint32_t status, uint32_t ipending) 137 1.1 rumble { 138 1.1 rumble 139 1.1 rumble printf("ctl0: bus error\n"); 140 1.1 rumble ctl_bus_reset(); 141 1.1 rumble } 142 1.1 rumble 143 1.1 rumble static void 144 1.1 rumble ctl_watchdog_enable(void) 145 1.1 rumble { 146 1.2 matt struct ctl_softc * const sc = csc; 147 1.1 rumble uint32_t reg; 148 1.1 rumble 149 1.1 rumble /* XXX- doesn't seem to work properly */ 150 1.1 rumble return; 151 1.1 rumble 152 1.2 matt reg = bus_space_read_2(sc->iot, sc->ioh, CTL_CPUCTRL); 153 1.1 rumble reg |= CTL_CPUCTRL_WDOG; 154 1.2 matt bus_space_write_2(sc->iot, sc->ioh, CTL_CPUCTRL, reg); 155 1.1 rumble } 156 1.1 rumble 157 1.1 rumble static void 158 1.1 rumble ctl_watchdog_disable(void) 159 1.1 rumble { 160 1.2 matt struct ctl_softc * const sc = csc; 161 1.1 rumble uint16_t reg; 162 1.1 rumble 163 1.1 rumble /* XXX- doesn't seem to work properly */ 164 1.1 rumble return; 165 1.1 rumble 166 1.2 matt reg = bus_space_read_2(sc->iot, sc->ioh, CTL_CPUCTRL_WDOG); 167 1.1 rumble reg &= ~(CTL_CPUCTRL_WDOG); 168 1.2 matt bus_space_write_2(sc->iot, sc->ioh, CTL_CPUCTRL, reg); 169 1.1 rumble } 170 1.1 rumble 171 1.1 rumble static void 172 1.1 rumble ctl_watchdog_tickle(void) 173 1.1 rumble { 174 1.1 rumble 175 1.1 rumble ctl_watchdog_disable(); 176 1.1 rumble ctl_watchdog_enable(); 177 1.1 rumble } 178 1.1 rumble 179 1.1 rumble #if defined(BLINK) 180 1.1 rumble static void 181 1.2 matt ctl_blink(void *arg) 182 1.1 rumble { 183 1.2 matt struct ctl_softc *sc = arg; 184 1.1 rumble int s, value; 185 1.1 rumble 186 1.1 rumble s = splhigh(); 187 1.1 rumble 188 1.1 rumble value = bus_space_read_1(sc->iot, sc->ioh, CTL_AUX_CPUCTRL); 189 1.1 rumble value ^= CTL_AUX_CPUCTRL_CONSLED; 190 1.1 rumble bus_space_write_1(sc->iot, sc->ioh, CTL_AUX_CPUCTRL, value); 191 1.1 rumble splx(s); 192 1.1 rumble 193 1.1 rumble /* 194 1.1 rumble * Blink rate is: 195 1.1 rumble * full cycle every second if completely idle (loadav = 0) 196 1.1 rumble * full cycle every 2 seconds if loadav = 1 197 1.1 rumble * full cycle every 3 seconds if loadav = 2 198 1.1 rumble * etc. 199 1.1 rumble */ 200 1.2 matt int ticks = ((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1); 201 1.2 matt callout_reset(&ctl_blink_ch, ticks, ctl_blink, sc); 202 1.1 rumble } 203 1.1 rumble #endif 204