1 /* $NetBSD: timer_sun4.c,v 1.5 2002/11/28 14:18:31 pk Exp $ */ 2 3 /* 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * Copyright (c) 1994 Gordon W. Ross 7 * Copyright (c) 1993 Adam Glass 8 * Copyright (c) 1996 Paul Kranenburg 9 * Copyright (c) 1996 10 * The President and Fellows of Harvard College. All rights reserved. 11 * 12 * This software was developed by the Computer Systems Engineering group 13 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 14 * contributed to Berkeley. 15 * 16 * All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Harvard University. 19 * This product includes software developed by the University of 20 * California, Lawrence Berkeley Laboratory. 21 * 22 * Redistribution and use in source and binary forms, with or without 23 * modification, are permitted provided that the following conditions 24 * are met: 25 * 26 * 1. Redistributions of source code must retain the above copyright 27 * notice, this list of conditions and the following disclaimer. 28 * 2. Redistributions in binary form must reproduce the above copyright 29 * notice, this list of conditions and the following disclaimer in the 30 * documentation and/or other materials provided with the distribution. 31 * 3. All advertising materials mentioning features or use of this software 32 * must display the following acknowledgement: 33 * This product includes software developed by the University of 34 * California, Berkeley and its contributors. 35 * This product includes software developed by Paul Kranenburg. 36 * This product includes software developed by Harvard University. 37 * 4. Neither the name of the University nor the names of its contributors 38 * may be used to endorse or promote products derived from this software 39 * without specific prior written permission. 40 * 41 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * SUCH DAMAGE. 52 * 53 * @(#)clock.c 8.1 (Berkeley) 6/11/93 54 */ 55 56 /* 57 * Sun4/Sun4c timer support. 58 */ 59 60 #include <sys/param.h> 61 #include <sys/kernel.h> 62 #include <sys/device.h> 63 #include <sys/systm.h> 64 65 #include <machine/autoconf.h> 66 #include <machine/bus.h> 67 68 #include <sparc/sparc/vaddrs.h> 69 #include <sparc/sparc/timerreg.h> 70 #include <sparc/sparc/timervar.h> 71 72 #define timerreg4 ((struct timerreg_4 *)TIMERREG_VA) 73 74 /* 75 * Set up the real-time and statistics clocks. 76 * Leave stathz 0 only if no alternative timer is available. 77 * 78 * The frequencies of these clocks must be an even number of microseconds. 79 */ 80 void 81 timer_init_4(void) 82 { 83 84 timerreg4->t_c10.t_limit = tmr_ustolim(tick); 85 timerreg4->t_c14.t_limit = tmr_ustolim(statint); 86 ienab_bis(IE_L14 | IE_L10); 87 } 88 89 /* 90 * Level 10 (clock) interrupts from system counter. 91 */ 92 int 93 clockintr_4(void *cap) 94 { 95 volatile int discard; 96 97 /* read the limit register to clear the interrupt */ 98 discard = timerreg4->t_c10.t_limit; 99 hardclock((struct clockframe *)cap); 100 return (1); 101 } 102 103 /* 104 * Level 14 (stat clock) interrupts from processor counter. 105 */ 106 int 107 statintr_4(void *cap) 108 { 109 volatile int discard; 110 u_long newint; 111 112 /* read the limit register to clear the interrupt */ 113 discard = timerreg4->t_c14.t_limit; 114 115 statclock((struct clockframe *)cap); 116 117 /* 118 * Compute new randomized interval. 119 */ 120 newint = new_interval(); 121 122 /* 123 * The sun4/4c timer has no `non-resetting' register; 124 * use the current counter value to compensate the new 125 * limit value for the number of counter ticks elapsed. 126 */ 127 newint -= tmr_cnttous(timerreg4->t_c14.t_counter); 128 timerreg4->t_c14.t_limit = tmr_ustolim(newint); 129 return (1); 130 } 131 132 #if defined(SUN4) 133 void 134 timerattach_obio_4(struct device *parent, struct device *self, void *aux) 135 { 136 union obio_attach_args *uoba = aux; 137 struct obio4_attach_args *oba = &uoba->uoba_oba4; 138 bus_space_handle_t bh; 139 140 if (bus_space_map2(oba->oba_bustag, 141 oba->oba_paddr, 142 sizeof(struct timerreg_4), 143 BUS_SPACE_MAP_LINEAR, 144 TIMERREG_VA, 145 &bh) != 0) { 146 printf(": can't map registers\n"); 147 return; 148 } 149 150 timerattach(&timerreg4->t_c14.t_counter, &timerreg4->t_c14.t_limit); 151 } 152 #endif /* SUN4 */ 153 154 #if defined(SUN4C) 155 void 156 timerattach_mainbus_4c(struct device *parent, struct device *self, void *aux) 157 { 158 struct mainbus_attach_args *ma = aux; 159 bus_space_handle_t bh; 160 161 /* 162 * This time we ignore any existing virtual address because 163 * we have a fixed virtual address for the timer, to make 164 * microtime() faster. 165 */ 166 if (bus_space_map2(ma->ma_bustag, 167 ma->ma_paddr, 168 sizeof(struct timerreg_4), 169 BUS_SPACE_MAP_LINEAR, 170 TIMERREG_VA, &bh) != 0) { 171 printf(": can't map registers\n"); 172 return; 173 } 174 175 timerattach(&timerreg4->t_c14.t_counter, &timerreg4->t_c14.t_limit); 176 } 177 #endif /* SUN4C */ 178