Home | History | Annotate | Line # | Download | only in hpc
hpc.c revision 1.1
      1  1.1  thorpej /*	$NetBSD: hpc.c,v 1.1 2001/05/11 03:11:20 thorpej Exp $	*/
      2  1.1  thorpej 
      3  1.1  thorpej /*
      4  1.1  thorpej  * Copyright (c) 2000 Soren S. Jorvang
      5  1.1  thorpej  * Copyright (c) 2001 Rafal K. Boni
      6  1.1  thorpej  * All rights reserved.
      7  1.1  thorpej  *
      8  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
      9  1.1  thorpej  * modification, are permitted provided that the following conditions
     10  1.1  thorpej  * are met:
     11  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     12  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     13  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     16  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     17  1.1  thorpej  *    must display the following acknowledgement:
     18  1.1  thorpej  *          This product includes software developed for the
     19  1.1  thorpej  *          NetBSD Project.  See http://www.netbsd.org/ for
     20  1.1  thorpej  *          information about NetBSD.
     21  1.1  thorpej  * 4. The name of the author may not be used to endorse or promote products
     22  1.1  thorpej  *    derived from this software without specific prior written permission.
     23  1.1  thorpej  *
     24  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25  1.1  thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26  1.1  thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27  1.1  thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28  1.1  thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29  1.1  thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30  1.1  thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31  1.1  thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32  1.1  thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33  1.1  thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34  1.1  thorpej  */
     35  1.1  thorpej 
     36  1.1  thorpej #include <sys/param.h>
     37  1.1  thorpej #include <sys/systm.h>
     38  1.1  thorpej #include <sys/device.h>
     39  1.1  thorpej #include <sys/reboot.h>
     40  1.1  thorpej 
     41  1.1  thorpej #include <machine/machtype.h>
     42  1.1  thorpej 
     43  1.1  thorpej #include <sgimips/gio/gioreg.h>
     44  1.1  thorpej #include <sgimips/gio/giovar.h>
     45  1.1  thorpej 
     46  1.1  thorpej #include <sgimips/hpc/hpcvar.h>
     47  1.1  thorpej #include <sgimips/hpc/hpcreg.h>
     48  1.1  thorpej #include <sgimips/hpc/iocreg.h>
     49  1.1  thorpej 
     50  1.1  thorpej #include "locators.h"
     51  1.1  thorpej 
     52  1.1  thorpej struct hpc_softc {
     53  1.1  thorpej 	struct device 		sc_dev;
     54  1.1  thorpej 
     55  1.1  thorpej 	bus_addr_t		sc_base;
     56  1.1  thorpej 
     57  1.1  thorpej 	bus_space_tag_t		sc_ct;
     58  1.1  thorpej 	bus_space_handle_t	sc_ch;
     59  1.1  thorpej };
     60  1.1  thorpej 
     61  1.1  thorpej extern int mach_type;		/* IPxx type */
     62  1.1  thorpej extern int mach_subtype;	/* subtype: eg., Guiness/Fullhouse for IP22 */
     63  1.1  thorpej extern int mach_boardrev;	/* machine board revision, in case it matters */
     64  1.1  thorpej 
     65  1.1  thorpej static int	hpc_match(struct device *, struct cfdata *, void *);
     66  1.1  thorpej static void	hpc_attach(struct device *, struct device *, void *);
     67  1.1  thorpej static int	hpc_print(void *, const char *);
     68  1.1  thorpej static int	hpc_search(struct device *, struct cfdata *, void *);
     69  1.1  thorpej 
     70  1.1  thorpej static int	hpc_power_intr(void *);
     71  1.1  thorpej 
     72  1.1  thorpej struct cfattach hpc_ca = {
     73  1.1  thorpej         sizeof(struct hpc_softc), hpc_match, hpc_attach
     74  1.1  thorpej };
     75  1.1  thorpej 
     76  1.1  thorpej static int
     77  1.1  thorpej hpc_match(parent, match, aux)
     78  1.1  thorpej 	struct device *parent;
     79  1.1  thorpej 	struct cfdata *match;
     80  1.1  thorpej 	void *aux;
     81  1.1  thorpej {
     82  1.1  thorpej 	struct gio_attach_args* ga = aux;
     83  1.1  thorpej 
     84  1.1  thorpej 	/* Make sure it's actually there and readable */
     85  1.1  thorpej 	if (badaddr((void*)MIPS_PHYS_TO_KSEG1(ga->ga_addr), sizeof(u_int32_t)))
     86  1.1  thorpej 		return 0;
     87  1.1  thorpej 
     88  1.1  thorpej         return 1;
     89  1.1  thorpej }
     90  1.1  thorpej 
     91  1.1  thorpej static void
     92  1.1  thorpej hpc_attach(parent, self, aux)
     93  1.1  thorpej 	struct device *parent;
     94  1.1  thorpej 	struct device *self;
     95  1.1  thorpej 	void *aux;
     96  1.1  thorpej {
     97  1.1  thorpej 	struct hpc_softc *sc = (struct hpc_softc *)self;
     98  1.1  thorpej 	struct gio_attach_args* ga = aux;
     99  1.1  thorpej 	struct hpc_attach_args ha;
    100  1.1  thorpej 
    101  1.1  thorpej 	/*
    102  1.1  thorpej 	 * XXX
    103  1.1  thorpej 	 */
    104  1.1  thorpej 	printf("\n");
    105  1.1  thorpej 
    106  1.1  thorpej 	sc->sc_ct = 1;
    107  1.1  thorpej 	sc->sc_ch = ga->ga_ioh;
    108  1.1  thorpej 
    109  1.1  thorpej 	sc->sc_base = ga->ga_addr;
    110  1.1  thorpej 	config_search(hpc_search, self, &ha);
    111  1.1  thorpej 
    112  1.1  thorpej 	/*
    113  1.1  thorpej 	 * XXXrkb: only true for first HPC, but didn't know where else to
    114  1.1  thorpej 	 * shove it (ip22_intr is too early).  I suppose I should request
    115  1.1  thorpej 	 * a post-config callback or something, but where?
    116  1.1  thorpej 	 */
    117  1.1  thorpej 	cpu_intr_establish(9, IPL_NONE, hpc_power_intr, sc);
    118  1.1  thorpej }
    119  1.1  thorpej 
    120  1.1  thorpej static int
    121  1.1  thorpej hpc_print(aux, name)
    122  1.1  thorpej 	void *aux;
    123  1.1  thorpej 	const char *name;
    124  1.1  thorpej {
    125  1.1  thorpej 	struct hpc_attach_args *ha = aux;
    126  1.1  thorpej 
    127  1.1  thorpej 	if (name != 0)
    128  1.1  thorpej 		return QUIET;
    129  1.1  thorpej 
    130  1.1  thorpej 	if (ha->ha_offset != HPCCF_OFFSET_DEFAULT)
    131  1.1  thorpej 		printf(" offset 0x%lx", ha->ha_offset);
    132  1.1  thorpej 
    133  1.1  thorpej 	return UNCONF;
    134  1.1  thorpej }
    135  1.1  thorpej 
    136  1.1  thorpej static int
    137  1.1  thorpej hpc_search(parent, cf, aux)
    138  1.1  thorpej 	struct device *parent;
    139  1.1  thorpej 	struct cfdata *cf;
    140  1.1  thorpej 	void *aux;
    141  1.1  thorpej {
    142  1.1  thorpej 	struct hpc_attach_args *haa = aux;
    143  1.1  thorpej 	struct hpc_softc *sc = (struct hpc_softc *)parent;
    144  1.1  thorpej 
    145  1.1  thorpej 	do {
    146  1.1  thorpej 		haa->ha_offset = cf->cf_loc[HPCCF_OFFSET];
    147  1.1  thorpej 
    148  1.1  thorpej 		haa->ha_iot = 1;
    149  1.1  thorpej 		haa->ha_ioh = MIPS_PHYS_TO_KSEG1(sc->sc_base);
    150  1.1  thorpej 		if ((*cf->cf_attach->ca_match)(parent, cf, haa) > 0)
    151  1.1  thorpej 			config_attach(parent, cf, haa, hpc_print);
    152  1.1  thorpej 	} while (cf->cf_fstate == FSTATE_STAR);
    153  1.1  thorpej 
    154  1.1  thorpej 	return 0;
    155  1.1  thorpej }
    156  1.1  thorpej 
    157  1.1  thorpej static int
    158  1.1  thorpej hpc_power_intr(void * arg)
    159  1.1  thorpej {
    160  1.1  thorpej 	u_int32_t pwr_reg;
    161  1.1  thorpej 
    162  1.1  thorpej 	pwr_reg = *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850));
    163  1.1  thorpej 	*((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850)) = pwr_reg;
    164  1.1  thorpej 
    165  1.1  thorpej 	printf("hpc_power_intr: panel reg = %08x\n", pwr_reg);
    166  1.1  thorpej 
    167  1.1  thorpej 	if (pwr_reg & 2)
    168  1.1  thorpej 	    cpu_reboot(RB_HALT, NULL);
    169  1.1  thorpej 
    170  1.1  thorpej 	return 1;
    171  1.1  thorpej }
    172  1.1  thorpej 
    173