Annotation of sys/arch/sparc/sparc/auxreg.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: auxreg.c,v 1.14 2007/07/01 19:07:46 miod Exp $ */
! 2: /* $NetBSD: auxreg.c,v 1.21 1997/05/24 20:15:59 pk Exp $ */
! 3:
! 4: /*
! 5: * Copyright (c) 1992, 1993
! 6: * The Regents of the University of California. All rights reserved.
! 7: *
! 8: * This software was developed by the Computer Systems Engineering group
! 9: * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
! 10: * contributed to Berkeley.
! 11: *
! 12: * All advertising materials mentioning features or use of this software
! 13: * must display the following acknowledgement:
! 14: * This product includes software developed by the University of
! 15: * California, Lawrence Berkeley Laboratory.
! 16: *
! 17: * Redistribution and use in source and binary forms, with or without
! 18: * modification, are permitted provided that the following conditions
! 19: * are met:
! 20: * 1. Redistributions of source code must retain the above copyright
! 21: * notice, this list of conditions and the following disclaimer.
! 22: * 2. Redistributions in binary form must reproduce the above copyright
! 23: * notice, this list of conditions and the following disclaimer in the
! 24: * documentation and/or other materials provided with the distribution.
! 25: * 3. Neither the name of the University nor the names of its contributors
! 26: * may be used to endorse or promote products derived from this software
! 27: * without specific prior written permission.
! 28: *
! 29: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 30: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 31: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 32: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 33: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 34: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 35: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 36: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 37: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 38: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 39: * SUCH DAMAGE.
! 40: *
! 41: * @(#)auxreg.c 8.1 (Berkeley) 6/11/93
! 42: */
! 43:
! 44: #include <sys/param.h>
! 45: #include <sys/systm.h>
! 46: #include <sys/device.h>
! 47: #include <sys/kernel.h>
! 48: #include <sys/timeout.h>
! 49:
! 50: #include <uvm/uvm_param.h>
! 51:
! 52: #include <machine/autoconf.h>
! 53:
! 54: #include <sparc/sparc/vaddrs.h>
! 55: #include <sparc/sparc/auxioreg.h>
! 56:
! 57: static int auxregmatch(struct device *, void *, void *);
! 58: static void auxregattach(struct device *, struct device *, void *);
! 59:
! 60: struct cfattach auxreg_ca = {
! 61: sizeof(struct device), auxregmatch, auxregattach
! 62: };
! 63:
! 64: struct cfdriver auxreg_cd = {
! 65: 0, "auxreg", DV_DULL
! 66: };
! 67:
! 68: volatile u_char *auxio_reg; /* Copy of AUXIO_REG */
! 69: u_char auxio_regval;
! 70:
! 71: #ifdef SUN4M /* Tadpole SPARCbook */
! 72: volatile u_char *sb_auxio_reg;
! 73: volatile u_char *sb_auxio2_reg;
! 74: #endif
! 75:
! 76: extern int sparc_led_blink; /* from machdep */
! 77: struct timeout sparc_led_to;
! 78:
! 79: void
! 80: led_blink(zero)
! 81: void *zero;
! 82: {
! 83: int s;
! 84:
! 85: /* Don't do anything if there's no auxreg, ok? */
! 86: if (auxio_reg == NULL)
! 87: return;
! 88:
! 89: if (!sparc_led_blink) {
! 90: /* If blink has been disabled, make sure it goes back on... */
! 91: s = splhigh();
! 92: LED_ON;
! 93: splx(s);
! 94:
! 95: return;
! 96: }
! 97:
! 98: s = splhigh();
! 99: LED_FLIP;
! 100: splx(s);
! 101: /*
! 102: * Blink rate is:
! 103: * full cycle every second if completely idle (loadav = 0)
! 104: * full cycle every 2 seconds if loadav = 1
! 105: * full cycle every 3 seconds if loadav = 2
! 106: * etc.
! 107: */
! 108: s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
! 109:
! 110: timeout_add(&sparc_led_to, s);
! 111: }
! 112:
! 113: /*
! 114: * The OPENPROM calls this "auxiliary-io".
! 115: * We also need to match the "auxio2" register on Tadpole SPARCbooks.
! 116: */
! 117: static int
! 118: auxregmatch(struct device *parent, void *cf, void *aux)
! 119: {
! 120: struct confargs *ca = aux;
! 121:
! 122: switch (cputyp) {
! 123: case CPU_SUN4:
! 124: default:
! 125: return (0);
! 126: case CPU_SUN4C:
! 127: return (strcmp("auxiliary-io", ca->ca_ra.ra_name) == 0);
! 128: case CPU_SUN4M:
! 129: return (strcmp("auxio", ca->ca_ra.ra_name) == 0 ||
! 130: strcmp("auxio2", ca->ca_ra.ra_name) == 0);
! 131: }
! 132: }
! 133:
! 134: /* ARGSUSED */
! 135: static void
! 136: auxregattach(struct device *parent, struct device *self, void *aux)
! 137: {
! 138: struct confargs *ca = aux;
! 139: struct romaux *ra = &ca->ca_ra;
! 140: #ifdef SUN4M
! 141: volatile u_char **regp;
! 142:
! 143: if (CPU_ISSUN4M && strncmp("Tadpole", mainbus_model, 7) == 0) {
! 144: if (strcmp("auxio", ra->ra_name) == 0)
! 145: regp = &sb_auxio_reg;
! 146: else
! 147: regp = &sb_auxio2_reg;
! 148: if (*regp == NULL)
! 149: *regp = mapiodev(ra->ra_reg, 0, sizeof(char));
! 150: } else
! 151: #endif
! 152: if (auxio_reg == NULL) {
! 153: (void)mapdev(ra->ra_reg, AUXREG_VA, 0, sizeof(long));
! 154: if (CPU_ISSUN4M) {
! 155: auxio_reg = AUXIO4M_REG;
! 156: auxio_regval = *AUXIO4M_REG | AUXIO4M_MB1;
! 157: } else {
! 158: auxio_reg = AUXIO4C_REG;
! 159: auxio_regval = *AUXIO4C_REG | AUXIO4C_FEJ | AUXIO4C_MB1;
! 160: }
! 161:
! 162: timeout_set(&sparc_led_to, led_blink, NULL);
! 163: /* In case it's initialized to true... */
! 164: if (sparc_led_blink)
! 165: led_blink((caddr_t)0);
! 166: }
! 167:
! 168: printf("\n");
! 169: }
! 170:
! 171: unsigned int
! 172: auxregbisc(int bis, int bic)
! 173: {
! 174: int s;
! 175:
! 176: #ifdef DIAGNOSTIC
! 177: if (auxio_reg == NULL)
! 178: /*
! 179: * Not all machines have an `aux' register; devices that
! 180: * depend on it should not get configured if it's absent.
! 181: */
! 182: panic("no aux register");
! 183: #endif
! 184:
! 185: s = splhigh();
! 186: auxio_regval = (auxio_regval | bis) & ~bic;
! 187: *auxio_reg = auxio_regval;
! 188: splx(s);
! 189: return (auxio_regval);
! 190: }
! 191:
! 192: #ifdef SUN4M
! 193: unsigned int
! 194: sb_auxregbisc(int isreg2, int bis, int bic)
! 195: {
! 196: int s;
! 197: volatile u_char *auxreg;
! 198: u_char aux;
! 199:
! 200: auxreg = isreg2 ? sb_auxio2_reg : sb_auxio_reg;
! 201: if (auxreg == NULL)
! 202: return (0);
! 203:
! 204: s = splhigh();
! 205: aux = (*auxreg | bis) & ~bic;
! 206: *auxreg = aux;
! 207: splx(s);
! 208: return (aux);
! 209: }
! 210: #endif
CVSweb