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