diff options
author | Jason Wright <jason@cvs.openbsd.org> | 2004-10-01 18:18:50 +0000 |
---|---|---|
committer | Jason Wright <jason@cvs.openbsd.org> | 2004-10-01 18:18:50 +0000 |
commit | 07f253751fdc947b9c4695a8e03c54642df44fea (patch) | |
tree | cb49a0bcf38166dd0f1313d3aa51d7a7ce6a97e4 /sys | |
parent | 9a47a1174cb544bd7c4ab22a11f4144ef6340ab6 (diff) |
add a blink_led API (shaves ~1k from GENERIC) rather than have the same
logic in 3 files. Devices register a function to be called to turn the
led on and off based on load average. (Note: rerun config and make depend)
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/sparc64/conf/files.sparc64 | 8 | ||||
-rw-r--r-- | sys/arch/sparc64/dev/auxio.c | 44 | ||||
-rw-r--r-- | sys/arch/sparc64/dev/auxiovar.h | 11 | ||||
-rw-r--r-- | sys/arch/sparc64/dev/clkbrd.c | 43 | ||||
-rw-r--r-- | sys/arch/sparc64/dev/clkbrdvar.h | 6 | ||||
-rw-r--r-- | sys/arch/sparc64/dev/fhc.c | 43 | ||||
-rw-r--r-- | sys/arch/sparc64/dev/fhcvar.h | 6 | ||||
-rw-r--r-- | sys/arch/sparc64/include/cpu.h | 10 | ||||
-rw-r--r-- | sys/arch/sparc64/sparc64/machdep.c | 91 |
9 files changed, 102 insertions, 160 deletions
diff --git a/sys/arch/sparc64/conf/files.sparc64 b/sys/arch/sparc64/conf/files.sparc64 index 796a91b3045..8d1567bd262 100644 --- a/sys/arch/sparc64/conf/files.sparc64 +++ b/sys/arch/sparc64/conf/files.sparc64 @@ -1,4 +1,4 @@ -# $OpenBSD: files.sparc64,v 1.53 2004/09/28 02:06:36 jason Exp $ +# $OpenBSD: files.sparc64,v 1.54 2004/10/01 18:18:48 jason Exp $ # $NetBSD: files.sparc64,v 1.50 2001/08/10 20:53:50 eeh Exp $ # maxpartitions must be first item in files.${ARCH} @@ -22,7 +22,7 @@ file arch/sparc64/dev/central.c central define fhc {} device fhc -file arch/sparc64/dev/fhc.c fhc needs-flag +file arch/sparc64/dev/fhc.c fhc attach fhc at central with fhc_central file arch/sparc64/dev/fhc_central.c fhc_central @@ -32,7 +32,7 @@ file arch/sparc64/dev/fhc_mainbus.c fhc_mainbus device clkbrd attach clkbrd at fhc -file arch/sparc64/dev/clkbrd.c clkbrd needs-flag +file arch/sparc64/dev/clkbrd.c clkbrd device pcons attach pcons at mainbus @@ -133,7 +133,7 @@ file arch/sparc64/sparc64/cpu.c device auxio attach auxio at ebus with auxio_ebus attach auxio at sbus with auxio_sbus -file arch/sparc64/dev/auxio.c auxio needs-flag +file arch/sparc64/dev/auxio.c auxio device beeper attach beeper at ebus diff --git a/sys/arch/sparc64/dev/auxio.c b/sys/arch/sparc64/dev/auxio.c index 1e33b7298be..daf8ee3bbe5 100644 --- a/sys/arch/sparc64/dev/auxio.c +++ b/sys/arch/sparc64/dev/auxio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auxio.c,v 1.5 2003/02/17 01:29:19 henric Exp $ */ +/* $OpenBSD: auxio.c,v 1.6 2004/10/01 18:18:49 jason Exp $ */ /* $NetBSD: auxio.c,v 1.1 2000/04/15 03:08:13 mrg Exp $ */ /* @@ -72,7 +72,7 @@ struct cfdriver auxio_cd = { NULL, "auxio", DV_DULL }; -extern int sparc_led_blink; +void auxio_led_blink(void *, int); int auxio_ebus_match(parent, cf, aux) @@ -93,8 +93,6 @@ auxio_ebus_attach(parent, self, aux) struct auxio_softc *sc = (struct auxio_softc *)self; struct ebus_attach_args *ea = aux; - timeout_set(&sc->sc_to, auxio_led_blink, sc); - if (ea->ea_nregs < 1 || ea->ea_nvaddrs < 1) { printf(": no registers??\n"); return; @@ -156,8 +154,6 @@ auxio_sbus_attach(parent, self, aux) struct auxio_softc *sc = (struct auxio_softc *)self; struct sbus_attach_args *sa = aux; - timeout_set(&sc->sc_to, auxio_led_blink, sc); - sc->sc_tag = sa->sa_bustag; if (sa->sa_nreg < 1 || sa->sa_npromvaddrs < 1) { @@ -185,27 +181,18 @@ void auxio_attach_common(sc) struct auxio_softc *sc; { - if (sparc_led_blink) - auxio_led_blink(sc); + sc->sc_blink.bl_func = auxio_led_blink; + sc->sc_blink.bl_arg = sc; + blink_led_register(&sc->sc_blink); printf("\n"); } void -auxio_led_blink(vsc) - void *vsc; +auxio_led_blink(void *vsc, int on) { struct auxio_softc *sc = vsc; u_int32_t led; - int i, s; - - if (sc == NULL) { - for (i = 0; i < auxio_cd.cd_ndevs; i++) { - sc = auxio_cd.cd_devs[i]; - if (sc != NULL) - auxio_led_blink(sc); - } - return; - } + int s; s = splhigh(); @@ -214,10 +201,10 @@ auxio_led_blink(vsc) else led = bus_space_read_1(sc->sc_tag, sc->sc_led, 0); - if (!sparc_led_blink) + if (on) led |= AUXIO_LED_LED; else - led ^= AUXIO_LED_LED; + led &= ~AUXIO_LED_LED; if (sc->sc_flags & AUXIO_EBUS) bus_space_write_4(sc->sc_tag, sc->sc_led, 0, htole32(led)); @@ -225,17 +212,4 @@ auxio_led_blink(vsc) bus_space_write_1(sc->sc_tag, sc->sc_led, 0, led); splx(s); - - if (!sparc_led_blink) - return; - - /* - * Blink rate is: - * full cycle every second if completely idle (loadav = 0) - * full cycle every 2 seconds if loadav = 1 - * full cycle every 3 seconds if loadav = 2 - * etc. - */ - s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1)); - timeout_add(&sc->sc_to, s); } diff --git a/sys/arch/sparc64/dev/auxiovar.h b/sys/arch/sparc64/dev/auxiovar.h index 56189a83e3b..2bfc1973f53 100644 --- a/sys/arch/sparc64/dev/auxiovar.h +++ b/sys/arch/sparc64/dev/auxiovar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: auxiovar.h,v 1.5 2003/02/10 10:02:59 jason Exp $ */ +/* $OpenBSD: auxiovar.h,v 1.6 2004/10/01 18:18:49 jason Exp $ */ /* $NetBSD: auxiovar.h,v 1.4 2000/04/15 03:08:13 mrg Exp $ */ /* @@ -51,12 +51,5 @@ struct auxio_softc { #define AUXIO_LEDONLY 0x1 #define AUXIO_EBUS 0x2 #define AUXIO_SBUS 0x4 - struct timeout sc_to; + struct blink_led sc_blink; }; - -/* - * XXX: old interfaces. we set auxio_reg the first auxio we attach. - */ -#ifndef _LOCORE -void auxio_led_blink(void *); -#endif diff --git a/sys/arch/sparc64/dev/clkbrd.c b/sys/arch/sparc64/dev/clkbrd.c index 79d9823f208..559449e4cd8 100644 --- a/sys/arch/sparc64/dev/clkbrd.c +++ b/sys/arch/sparc64/dev/clkbrd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clkbrd.c,v 1.4 2004/09/29 17:43:33 jason Exp $ */ +/* $OpenBSD: clkbrd.c,v 1.5 2004/10/01 18:18:49 jason Exp $ */ /* * Copyright (c) 2004 Jason L. Wright (jason@thought.net) @@ -43,10 +43,9 @@ #include <sparc64/dev/clkbrdreg.h> #include <sparc64/dev/clkbrdvar.h> -extern int sparc_led_blink; - int clkbrd_match(struct device *, void *, void *); void clkbrd_attach(struct device *, struct device *, void *); +void clkbrd_led_blink(void *, int); struct cfattach clkbrd_ca = { sizeof(struct clkbrd_softc), clkbrd_match, clkbrd_attach @@ -80,8 +79,6 @@ clkbrd_attach(parent, self, aux) sc->sc_bt = fa->fa_bustag; - timeout_set(&sc->sc_to, clkbrd_led_blink, sc); - if (fa->fa_nreg < 2) { printf(": no registers\n"); return; @@ -123,43 +120,25 @@ clkbrd_attach(parent, self, aux) printf(": %d slots\n", slots); - if (sparc_led_blink) - clkbrd_led_blink(sc); + sc->sc_blink.bl_func = clkbrd_led_blink; + sc->sc_blink.bl_arg = sc; + blink_led_register(&sc->sc_blink); } void -clkbrd_led_blink(void *vsc) +clkbrd_led_blink(void *vsc, int on) { struct clkbrd_softc *sc = vsc; - int i, s; + int s; u_int8_t r; - if (sc == NULL) { - for (i = 0; i < clkbrd_cd.cd_ndevs; i++) { - sc = clkbrd_cd.cd_devs[i]; - if (sc != NULL) - clkbrd_led_blink(sc); - } - return; - } - s = splhigh(); r = bus_space_read_1(sc->sc_bt, sc->sc_creg, CLK_CTRL); - r ^= CLK_CTRL_RLED; + if (on) + r |= CLK_CTRL_RLED; + else + r &= ~CLK_CTRL_RLED; bus_space_write_1(sc->sc_bt, sc->sc_creg, CLK_CTRL, r); bus_space_read_1(sc->sc_bt, sc->sc_creg, CLK_CTRL); splx(s); - - if (!sparc_led_blink) - return; - - /* - * Blink rate is: - * full cycle every second if completely idle (loadav = 0) - * full cycle every 2 seconds if loadav = 1 - * full cycle every 3 seconds if loadav = 2 - * etc. - */ - s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1)); - timeout_add(&sc->sc_to, s); } diff --git a/sys/arch/sparc64/dev/clkbrdvar.h b/sys/arch/sparc64/dev/clkbrdvar.h index 9a31aa07af0..37c45db15a3 100644 --- a/sys/arch/sparc64/dev/clkbrdvar.h +++ b/sys/arch/sparc64/dev/clkbrdvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: clkbrdvar.h,v 1.1 2004/09/28 02:06:36 jason Exp $ */ +/* $OpenBSD: clkbrdvar.h,v 1.2 2004/10/01 18:18:49 jason Exp $ */ /* * Copyright (c) 2004 Jason L. Wright (jason@thought.net) @@ -33,7 +33,5 @@ struct clkbrd_softc { bus_space_handle_t sc_vreg; int sc_node; int sc_has_vreg; - struct timeout sc_to; + struct blink_led sc_blink; }; - -void clkbrd_led_blink(void *); diff --git a/sys/arch/sparc64/dev/fhc.c b/sys/arch/sparc64/dev/fhc.c index 868d36fe8fb..970099f9ba6 100644 --- a/sys/arch/sparc64/dev/fhc.c +++ b/sys/arch/sparc64/dev/fhc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fhc.c,v 1.11 2004/09/28 18:37:43 jason Exp $ */ +/* $OpenBSD: fhc.c,v 1.12 2004/10/01 18:18:49 jason Exp $ */ /* * Copyright (c) 2004 Jason L. Wright (jason@thought.net) @@ -49,8 +49,6 @@ struct cfdriver fhc_cd = { int fhc_print(void *, const char *); -extern int sparc_led_blink; - bus_space_tag_t fhc_alloc_bus_tag(struct fhc_softc *); int _fhc_bus_map(bus_space_tag_t, bus_space_tag_t, bus_addr_t, bus_size_t, int, bus_space_handle_t *); @@ -59,6 +57,7 @@ void *fhc_intr_establish(bus_space_tag_t, bus_space_tag_t, int, int, int, bus_space_handle_t *fhc_find_intr_handle(struct fhc_softc *, int); bus_space_handle_t *fhc_try_intr_handle(struct fhc_softc *, bus_space_handle_t *, bus_size_t, int); +void fhc_led_blink(void *, int); void fhc_attach(struct fhc_softc *sc) @@ -69,8 +68,6 @@ fhc_attach(struct fhc_softc *sc) printf(" board %d: %s\n", sc->sc_board, getpropstring(sc->sc_node, "board-model")); - timeout_set(&sc->sc_to, fhc_led_blink, sc); - sc->sc_cbt = fhc_alloc_bus_tag(sc); sc->sc_ign = sc->sc_board << 1; @@ -129,8 +126,9 @@ fhc_attach(struct fhc_softc *sc) free(fa.fa_promvaddrs, M_DEVBUF); } - if (sparc_led_blink) - fhc_led_blink(sc); + sc->sc_blink.bl_func = fhc_led_blink; + sc->sc_blink.bl_arg = sc; + blink_led_register(&sc->sc_blink); } int @@ -309,39 +307,20 @@ fhc_intr_establish(bus_space_tag_t t, bus_space_tag_t t0, int ihandle, } void -fhc_led_blink(void *vsc) +fhc_led_blink(void *vsc, int on) { struct fhc_softc *sc = vsc; - int i, s; + int s; u_int32_t r; - if (sc == NULL) { - for (i = 0; i < fhc_cd.cd_ndevs; i++) { - sc = fhc_cd.cd_devs[i]; - if (sc != NULL) - fhc_led_blink(sc); - } - return; - } - s = splhigh(); r = bus_space_read_4(sc->sc_bt, sc->sc_preg, FHC_P_CTRL); - r ^= FHC_P_CTRL_RLED; + if (on) + r |= FHC_P_CTRL_RLED; + else + r &= ~FHC_P_CTRL_RLED; r &= ~(FHC_P_CTRL_AOFF | FHC_P_CTRL_BOFF | FHC_P_CTRL_SLINE); bus_space_write_4(sc->sc_bt, sc->sc_preg, FHC_P_CTRL, r); bus_space_read_4(sc->sc_bt, sc->sc_preg, FHC_P_CTRL); splx(s); - - if (!sparc_led_blink) - return; - - /* - * Blink rate is: - * full cycle every second if completely idle (loadav = 0) - * full cycle every 2 seconds if loadav = 1 - * full cycle every 3 seconds if loadav = 2 - * etc. - */ - s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1)); - timeout_add(&sc->sc_to, s); } diff --git a/sys/arch/sparc64/dev/fhcvar.h b/sys/arch/sparc64/dev/fhcvar.h index 2e2eb92e51a..2cffb3e3f5c 100644 --- a/sys/arch/sparc64/dev/fhcvar.h +++ b/sys/arch/sparc64/dev/fhcvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fhcvar.h,v 1.7 2004/09/28 18:37:43 jason Exp $ */ +/* $OpenBSD: fhcvar.h,v 1.8 2004/10/01 18:18:49 jason Exp $ */ /* * Copyright (c) 2004 Jason L. Wright (jason@thought.net). @@ -50,13 +50,13 @@ struct fhc_softc { bus_space_tag_t sc_cbt; int sc_nrange; struct fhc_range *sc_range; - struct timeout sc_to; bus_space_handle_t sc_preg; /* internal regs */ bus_space_handle_t sc_ireg; /* ign regs */ bus_space_handle_t sc_freg; /* fanfail regs */ bus_space_handle_t sc_sreg; /* system regs */ bus_space_handle_t sc_ureg; /* uart regs */ bus_space_handle_t sc_treg; /* tod regs */ + struct blink_led sc_blink; }; void fhc_attach(struct fhc_softc *); @@ -76,5 +76,3 @@ struct fhc_attach_args { #define fhc_bus_map(t, slot, offset, sz, flags, hp) \ bus_space_map(t, BUS_ADDR(slot, offset), sz, flags, hp) - -void fhc_led_blink(void *); diff --git a/sys/arch/sparc64/include/cpu.h b/sys/arch/sparc64/include/cpu.h index 4d5530e0753..29fc31eebad 100644 --- a/sys/arch/sparc64/include/cpu.h +++ b/sys/arch/sparc64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.29 2004/08/09 10:13:21 miod Exp $ */ +/* $OpenBSD: cpu.h,v 1.30 2004/10/01 18:18:49 jason Exp $ */ /* $NetBSD: cpu.h,v 1.28 2001/06/14 22:56:58 thorpej Exp $ */ /* @@ -279,5 +279,13 @@ extern struct trapvec *trapbase; /* the 256 vectors */ extern void wzero(void *, u_int); extern void wcopy(const void *, void *, u_int); +struct blink_led { + void (*bl_func)(void *, int); + void *bl_arg; + SLIST_ENTRY(blink_led) bl_next; +}; + +extern void blink_led_register(struct blink_led *); + #endif /* _KERNEL */ #endif /* _CPU_H_ */ diff --git a/sys/arch/sparc64/sparc64/machdep.c b/sys/arch/sparc64/sparc64/machdep.c index 8a9996a2b76..74b73f9c4ea 100644 --- a/sys/arch/sparc64/sparc64/machdep.c +++ b/sys/arch/sparc64/sparc64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.72 2004/09/28 02:06:36 jason Exp $ */ +/* $OpenBSD: machdep.c,v 1.73 2004/10/01 18:18:49 jason Exp $ */ /* $NetBSD: machdep.c,v 1.108 2001/07/24 19:30:14 eeh Exp $ */ /*- @@ -78,10 +78,6 @@ * @(#)machdep.c 8.6 (Berkeley) 1/14/94 */ -#include "auxio.h" -#include "fhc.h" -#include "clkbrd.h" - #include <sys/param.h> #include <sys/extent.h> #include <sys/signal.h> @@ -196,21 +192,7 @@ int physmem; u_long _randseed; extern caddr_t msgbufaddr; -#if (NAUXIO > 0) || (NFHC > 0) || (NCLKBRD > 0) int sparc_led_blink; -#endif - -#if NAUXIO > 0 -#include <sparc64/dev/auxiovar.h> -#endif - -#if NFHC > 0 -#include <sparc64/dev/fhcvar.h> -#endif - -#if NCLKBRD > 0 -#include <sparc64/dev/clkbrdvar.h> -#endif #ifdef APERTURE #ifdef INSECURE @@ -237,6 +219,7 @@ extern int64_t cecclast; */ int safepri = 0; +void blink_led_timeout(void *); caddr_t allocsys(caddr_t); void dumpsys(void); void stackdump(void); @@ -519,9 +502,7 @@ cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) size_t newlen; struct proc *p; { -#if NAUXIO > 0 int oldval, ret; -#endif u_int chosen; char bootargs[256]; char *cp = NULL; @@ -558,30 +539,15 @@ cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) return (ENOENT); return (sysctl_rdstring(oldp, oldlenp, newp, cp)); case CPU_LED_BLINK: -#if (NAUXIO > 0) || (NFHC > 0) || (NCLKBRD > 0) oldval = sparc_led_blink; ret = sysctl_int(oldp, oldlenp, newp, newlen, &sparc_led_blink); - /* - * If we were false and are now true, call auxio_led_blink(). - * auxio_led_blink() will catch the other case itself. + * If we were false and are now true, call start the timer. */ - if (!oldval && sparc_led_blink > oldval) { -#if NAUXIO > 0 - auxio_led_blink(NULL); -#endif -#if NFHC > 0 - fhc_led_blink(NULL); -#endif -#if NCLKBRD > 0 - clkbrd_led_blink(NULL); -#endif - } + if (!oldval && sparc_led_blink > oldval) + blink_led_timeout(NULL); return (ret); -#else - return (EOPNOTSUPP); -#endif case CPU_ALLOWAPERTURE: #ifdef APERTURE if (securelevel > 0) @@ -2254,3 +2220,50 @@ bus_space_assert(bus_space_tag_t t, const bus_space_handle_t *h, bus_size_t o, } #endif /* BUS_SPACE_DEBUG */ + +struct blink_led_softc { + SLIST_HEAD(, blink_led) bls_head; + int bls_on; + struct timeout bls_to; +} blink_sc = { SLIST_HEAD_INITIALIZER(bls_head), 0 }; + +void +blink_led_register(struct blink_led *l) +{ + if (SLIST_EMPTY(&blink_sc.bls_head)) { + timeout_set(&blink_sc.bls_to, blink_led_timeout, &blink_sc); + blink_sc.bls_on = 0; + if (sparc_led_blink) + timeout_add(&blink_sc.bls_to, 1); + } + SLIST_INSERT_HEAD(&blink_sc.bls_head, l, bl_next); +} + +void +blink_led_timeout(void *vsc) +{ + struct blink_led_softc *sc = &blink_sc; + struct blink_led *l; + int t; + + if (SLIST_EMPTY(&sc->bls_head)) + return; + + SLIST_FOREACH(l, &sc->bls_head, bl_next) { + (*l->bl_func)(l->bl_arg, sc->bls_on); + } + sc->bls_on = !sc->bls_on; + + if (!sparc_led_blink) + return; + + /* + * Blink rate is: + * full cycle every second if completely idle (loadav = 0) + * full cycle every 2 seconds if loadav = 1 + * full cycle every 3 seconds if loadav = 2 + * etc. + */ + t = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1)); + timeout_add(&sc->bls_to, t); +} |