Annotation of sys/arch/hppa64/dev/power.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: power.c,v 1.1 2005/04/01 10:40:47 mickey Exp $ */
2:
3: /*
4: * Copyright (c) 2005 Michael Shalayeff
5: * All rights reserved.
6: *
7: * Permission to use, copy, modify, and distribute this software for any
8: * purpose with or without fee is hereby granted, provided that the above
9: * copyright notice and this permission notice appear in all copies.
10: *
11: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15: * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
16: * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17: * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18: */
19:
20: #include <sys/param.h>
21: #include <sys/kernel.h>
22: #include <sys/systm.h>
23: #include <sys/reboot.h>
24: #include <sys/device.h>
25: #include <sys/kthread.h>
26:
27: #include <machine/reg.h>
28: #include <machine/pdc.h>
29: #include <machine/autoconf.h>
30:
31: struct power_softc {
32: struct device sc_dev;
33: void *sc_ih;
34:
35: struct proc *sc_thread;
36: void (*sc_kicker)(void *);
37:
38: int sc_dr_cnt;
39: paddr_t sc_pwr_reg;
40: volatile int sc_interrupted;
41: };
42:
43: int powermatch(struct device *, void *, void *);
44: void powerattach(struct device *, struct device *, void *);
45:
46: struct cfattach power_ca = {
47: sizeof(struct power_softc), powermatch, powerattach
48: };
49:
50: struct cfdriver power_cd = {
51: NULL, "power", DV_DULL
52: };
53:
54: void power_thread_create(void *v);
55: void power_thread_reg(void *v);
56: void power_cold_hook_reg(int);
57: int power_intr(void *);
58:
59: int
60: powermatch(struct device *parent, void *cfdata, void *aux)
61: {
62: struct cfdata *cf = cfdata;
63: struct confargs *ca = aux;
64:
65: if (cf->cf_unit > 0 && !strcmp(ca->ca_name, "power"))
66: return (0);
67:
68: return (1);
69: }
70:
71: void
72: powerattach(struct device *parent, struct device *self, void *aux)
73: {
74: struct power_softc *sc = (struct power_softc *)self;
75: struct confargs *ca = aux;
76:
77: if (ca->ca_hpa) {
78: extern void (*cold_hook)(int);
79:
80: sc->sc_pwr_reg = ca->ca_hpa;
81: cold_hook = power_cold_hook_reg;
82: sc->sc_kicker = power_thread_reg;
83: printf("\n");
84: } else
85: printf(": not available\n");
86:
87: if (ca->ca_irq >= 0)
88: sc->sc_ih = cpu_intr_establish(IPL_CLOCK, ca->ca_irq,
89: power_intr, sc, sc->sc_dev.dv_xname);
90:
91: if (sc->sc_kicker)
92: kthread_create_deferred(power_thread_create, sc);
93: }
94:
95: int
96: power_intr(void *v)
97: {
98: struct power_softc *sc = v;
99:
100: sc->sc_interrupted = 1;
101:
102: return (1);
103: }
104:
105: void
106: power_thread_create(void *v)
107: {
108: struct power_softc *sc = v;
109:
110: if (kthread_create(sc->sc_kicker, sc, &sc->sc_thread,
111: sc->sc_dev.dv_xname))
112: printf("WARNING: failed to create kernel power thread\n");
113: }
114:
115: void
116: power_thread_reg(void *v)
117: {
118: struct power_softc *sc = v;
119: u_int32_t r;
120:
121: for (;;) {
122: __asm __volatile("ldwas 0(%1), %0"
123: : "=&r" (r) : "r" (sc->sc_pwr_reg));
124:
125: if (!(r & 1))
126: boot(RB_POWERDOWN | RB_HALT);
127:
128: tsleep(v, PWAIT, "regpower", 10);
129: }
130: }
131:
132: void
133: power_cold_hook_reg(int on)
134: {
135: extern struct pdc_power_info pdc_power_info; /* machdep.c */
136: int error;
137:
138: if ((error = pdc_call((iodcio_t)pdc, 0, PDC_SOFT_POWER,
139: PDC_SOFT_POWER_ENABLE, &pdc_power_info,
140: on == HPPA_COLD_HOT)))
141: printf("power_cold_hook_reg: failed (%d)\n", error);
142: }
CVSweb