1 /* $NetBSD: leds.c,v 1.20 2011/02/08 20:20:13 rmind Exp $ */
2
3 /*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1982, 1986, 1990, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * from: Utah $Hdr: machdep.c 1.74 92/12/20$
37 *
38 * @(#)machdep.c 8.10 (Berkeley) 4/20/94
39 */
40
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: leds.c,v 1.20 2011/02/08 20:20:13 rmind Exp $");
43
44 #include <sys/param.h>
45
46 #include <uvm/uvm_extern.h>
47
48 #include <hp300/hp300/leds.h>
49
50 static vaddr_t ledbase; /* kva of LED page */
51 uint8_t *ledaddr; /* actual address of LEDs */
52 static volatile uint8_t currentleds; /* current LED status */
53
54 /*
55 * Map the LED page and setup the KVA to access it.
56 */
57 void
ledinit(void)58 ledinit(void)
59 {
60
61 ledbase = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_VAONLY);
62 pmap_enter(pmap_kernel(), ledbase, (paddr_t)LED_ADDR,
63 VM_PROT_READ|VM_PROT_WRITE, VM_PROT_READ|VM_PROT_WRITE|PMAP_WIRED);
64 pmap_update(pmap_kernel());
65 ledaddr = (uint8_t *)(ledbase | (LED_ADDR & PGOFSET));
66 }
67
68 /*
69 * Do lights:
70 * `ons' is a mask of LEDs to turn on,
71 * `offs' is a mask of LEDs to turn off,
72 * `togs' is a mask of LEDs to toggle.
73 * Note that we don't use splclock/splx for mutual exclusion. They are
74 * expensive and we really don't need to be that precise. Besides, we
75 * would like to be able to profile this routine.
76 */
77 void
ledcontrol(int ons,int offs,int togs)78 ledcontrol(int ons, int offs, int togs)
79 {
80
81 __asm volatile (
82 "orb %1,%0 ;\n"
83 "andb %2,%0 ;\n"
84 "eorb %3,%0"
85 : "=m" (currentleds)
86 : "d" (ons), "d" (~offs), "d" (togs));
87 *ledaddr = ~currentleds;
88 }
89