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