Home | History | Annotate | Line # | Download | only in dev
timer_hb.c revision 1.17
      1 /*	$NetBSD: timer_hb.c,v 1.17 2010/01/28 14:10:54 mbalmer Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: timer_hb.c,v 1.17 2010/01/28 14:10:54 mbalmer Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/kernel.h>
     37 #include <sys/systm.h>
     38 #include <sys/device.h>
     39 #include <sys/intr.h>
     40 
     41 #include <uvm/uvm_extern.h>
     42 
     43 #include <machine/cpu.h>
     44 #include <machine/bus.h>
     45 
     46 #include <dev/clock_subr.h>
     47 
     48 #include <news68k/news68k/isr.h>
     49 #include <news68k/news68k/clockvar.h>
     50 
     51 #include <news68k/dev/hbvar.h>
     52 
     53 #include "ioconf.h"
     54 
     55 /*
     56  * interrupt level for clock
     57  */
     58 
     59 #define TIMER_LEVEL 6
     60 #define TIMER_SIZE 8	/* XXX */
     61 
     62 static int timer_hb_match(device_t, cfdata_t, void *);
     63 static void timer_hb_attach(device_t, device_t, void *);
     64 static void timer_hb_initclocks(int, int);
     65 void clock_intr(struct clockframe *);
     66 
     67 static inline void leds_intr(void);
     68 
     69 extern void _isr_clock(void);	/* locore.s */
     70 
     71 CFATTACH_DECL_NEW(timer_hb, 0,
     72     timer_hb_match, timer_hb_attach, NULL, NULL);
     73 
     74 static volatile uint8_t *ctrl_timer; /* XXX */
     75 
     76 extern volatile u_char *ctrl_led; /* XXX */
     77 
     78 static int
     79 timer_hb_match(device_t parent, cfdata_t cf, void *aux)
     80 {
     81 	struct hb_attach_args *ha = aux;
     82 	static int timer_hb_matched;
     83 
     84 	/* Only one timer, please. */
     85 	if (timer_hb_matched)
     86 		return 0;
     87 
     88 	if (strcmp(ha->ha_name, timer_cd.cd_name))
     89 		return 0;
     90 
     91 	if (ha->ha_ipl == -1)
     92 		ha->ha_ipl = TIMER_LEVEL;
     93 
     94 	ha->ha_size = TIMER_SIZE;
     95 
     96 	timer_hb_matched = 1;
     97 
     98 	return 1;
     99 }
    100 
    101 static void
    102 timer_hb_attach(device_t parent, device_t self, void *aux)
    103 {
    104 	struct hb_attach_args *ha = aux;
    105 
    106 	if (ha->ha_ipl != TIMER_LEVEL)
    107 		panic("clock_hb_attach: wrong interrupt level");
    108 
    109 	ctrl_timer = (uint8_t *)IIOV(ha->ha_address); /* XXX needs bus_space */
    110 
    111 	printf("\n");
    112 
    113 	timer_config(timer_hb_initclocks);
    114 
    115 #if 0 /* XXX this will be done in timer_hb_initclocks() */
    116 	isrlink_custom(ha->ha_ipl, (void *)_isr_clock);
    117 #endif
    118 }
    119 
    120 /*
    121  * Set up the interval timer (enable clock interrupts).
    122  * Leave stathz 0 since there is no secondary clock available.
    123  * Note that clock interrupts MUST STAY DISABLED until here.
    124  */
    125 static void
    126 timer_hb_initclocks(int prof, int stat)
    127 {
    128 	int s;
    129 
    130 	s = splhigh();
    131 
    132 	/* Install isr (in locore.s) that calls clock_intr(). */
    133 	isrlink_custom(TIMER_LEVEL, (void *)_isr_clock);
    134 
    135 	/* enable the clock */
    136 	*ctrl_timer = 1;
    137 	splx(s);
    138 }
    139 
    140 /*
    141  * Clock interrupt handler.
    142  * This is called by the "custom" interrupt handler.
    143  *
    144  * from sun3/sun3x/clock.c -tsutsui
    145  */
    146 void
    147 clock_intr(struct clockframe *cf)
    148 {
    149 #ifdef	LED_IDLE_CHECK
    150 	extern char _Idle[];	/* locore.s */
    151 #endif
    152 
    153 	/* Pulse the clock intr. enable low. */
    154 	*ctrl_timer = 0;
    155 	*ctrl_timer = 1;
    156 	intrcnt[TIMER_LEVEL]++;
    157 
    158 	/* Entertainment! */
    159 #ifdef	LED_IDLE_CHECK
    160 	if (cf.cf_pc == (long)_Idle)
    161 #endif
    162 		leds_intr();
    163 
    164 	/* Call common clock interrupt handler. */
    165 	hardclock(cf);
    166 	uvmexp.intrs++;
    167 }
    168 
    169 /* heartbeat LED */
    170 #define LED0	0x01
    171 #define LED1	0x02
    172 
    173 static inline void
    174 leds_intr(void)
    175 {
    176 	static u_char led_countdown, led_stat;
    177 	u_char i;
    178 
    179 	if (led_countdown) {
    180 		led_countdown--;
    181 		return;
    182 	}
    183 
    184 	i = led_stat ^ LED0;
    185 	*ctrl_led = i;
    186 	led_stat = i;
    187 	led_countdown = hz;
    188 }
    189 
    190