1*95e1ffb1Schristos /* $NetBSD: timerreg.h,v 1.5 2005/12/11 12:19:15 christos Exp $ */ 201e2e698Seeh 301e2e698Seeh /* 401e2e698Seeh * Copyright (c) 1992, 1993 501e2e698Seeh * The Regents of the University of California. All rights reserved. 601e2e698Seeh * 701e2e698Seeh * This software was developed by the Computer Systems Engineering group 801e2e698Seeh * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 901e2e698Seeh * contributed to Berkeley. 1001e2e698Seeh * 1101e2e698Seeh * All advertising materials mentioning features or use of this software 1201e2e698Seeh * must display the following acknowledgement: 1301e2e698Seeh * This product includes software developed by the University of 1401e2e698Seeh * California, Lawrence Berkeley Laboratory. 1501e2e698Seeh * 1601e2e698Seeh * Redistribution and use in source and binary forms, with or without 1701e2e698Seeh * modification, are permitted provided that the following conditions 1801e2e698Seeh * are met: 1901e2e698Seeh * 1. Redistributions of source code must retain the above copyright 2001e2e698Seeh * notice, this list of conditions and the following disclaimer. 2101e2e698Seeh * 2. Redistributions in binary form must reproduce the above copyright 2201e2e698Seeh * notice, this list of conditions and the following disclaimer in the 2301e2e698Seeh * documentation and/or other materials provided with the distribution. 24aad01611Sagc * 3. Neither the name of the University nor the names of its contributors 2501e2e698Seeh * may be used to endorse or promote products derived from this software 2601e2e698Seeh * without specific prior written permission. 2701e2e698Seeh * 2801e2e698Seeh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2901e2e698Seeh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3001e2e698Seeh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3101e2e698Seeh * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3201e2e698Seeh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3301e2e698Seeh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3401e2e698Seeh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3501e2e698Seeh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3601e2e698Seeh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3701e2e698Seeh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3801e2e698Seeh * SUCH DAMAGE. 3901e2e698Seeh * 4001e2e698Seeh * @(#)timerreg.h 8.1 (Berkeley) 6/11/93 4101e2e698Seeh */ 4201e2e698Seeh 4301e2e698Seeh /* 4401e2e698Seeh * Sun-4c counter/timer registers. The timers are implemented within 4501e2e698Seeh * the cache chip (!). The counter and limit fields below could be 4601e2e698Seeh * defined as: 4701e2e698Seeh * 4801e2e698Seeh * struct { 4901e2e698Seeh * u_int t_limit:1, // limit reached 5001e2e698Seeh * t_usec:21, // counter value in microseconds 5101e2e698Seeh * t_mbz:10; // always zero 5201e2e698Seeh * }; 5301e2e698Seeh * 5401e2e698Seeh * but this is more trouble than it is worth. 5501e2e698Seeh * 5601e2e698Seeh * These timers work in a rather peculiar fashion. Most clock counters 5701e2e698Seeh * run to 0 (as, e.g., on the VAX, where the ICR counts up to 0 from a 5801e2e698Seeh * large unsigned number). On the Sun-4c, it counts up to a limit. But 5901e2e698Seeh * for some reason, when it reaches the limit, it resets to 1, not 0. 6001e2e698Seeh * Thus, if the limit is set to 4, the counter counts like this: 6101e2e698Seeh * 6201e2e698Seeh * 1, 2, 3, 1, 2, 3, ... 6301e2e698Seeh * 6401e2e698Seeh * and if we want to divide by N we must set the limit register to N+1. 6501e2e698Seeh * 6601e2e698Seeh * Sun-4m counters/timer registers are similar, with these exceptions: 6701e2e698Seeh * 6801e2e698Seeh * - the limit and counter registers have changed positions.. 6901e2e698Seeh * - both limit and counter registers are 22 bits wide, but 7001e2e698Seeh * they count in 500ns increments (bit 9 being the least 7101e2e698Seeh * significant bit). 7201e2e698Seeh * 7301e2e698Seeh * Note that we still use the `sun4c' masks and shifts to compute 7401e2e698Seeh * the bit pattern, given the tick period in microseconds, resulting 7501e2e698Seeh * in a limit value that is 1 too high. This means that (with HZ=100) 7601e2e698Seeh * the clock will err on the slow side by 500ns/10ms (or 0.00005 %). 7701e2e698Seeh * We dont bother. 7801e2e698Seeh * 7901e2e698Seeh * Sun-4u counters/timer are similar but: 8001e2e698Seeh * 8101e2e698Seeh * - the registers have been shuffled around once again. We need 8201e2e698Seeh * to use offsets from the 3 addresses the ROM provides us. 8301e2e698Seeh * - The counters are 28 bits wide with 1us accuracy. 8401e2e698Seeh * - You can make them do funky things with the limit register 8501e2e698Seeh * - They have standard 64-bit SBUS control registers. 86dcb60405Smrg * 87dcb60405Smrg * There is a problem on the Ultra5 and Ultra10. As the PCI controller 88dcb60405Smrg * doesn't include the timer, there are no `counter-timer' nodes here 89dcb60405Smrg * and so we must use %tick. 9001e2e698Seeh */ 9101e2e698Seeh #ifndef _LOCORE 9201e2e698Seeh struct timer_4 { 9301e2e698Seeh volatile int t_counter; /* counter reg */ 9401e2e698Seeh volatile int t_limit; /* limit reg */ 9501e2e698Seeh }; 9601e2e698Seeh 9701e2e698Seeh struct timerreg_4 { 9801e2e698Seeh struct timer_4 t_c10; /* counter that interrupts at ipl 10 */ 9901e2e698Seeh struct timer_4 t_c14; /* counter that interrupts at ipl 14 */ 10001e2e698Seeh }; 10101e2e698Seeh 10201e2e698Seeh struct timer_4m { /* counter that interrupts at ipl 10 */ 10301e2e698Seeh volatile int t_limit; /* limit register */ 10401e2e698Seeh volatile int t_counter; /* counter register */ 10501e2e698Seeh volatile int t_limit_nr; /* limit reg, non-resetting */ 10601e2e698Seeh volatile int t_reserved; 10701e2e698Seeh volatile int t_cfg; /* a configuration register */ 10801e2e698Seeh /* 10901e2e698Seeh * Note: The SparcClassic manual only defines this one bit 11001e2e698Seeh * I suspect there are more in multi-processor machines. 11101e2e698Seeh */ 11201e2e698Seeh #define TMR_CFG_USER 1 11301e2e698Seeh }; 11401e2e698Seeh 11501e2e698Seeh struct timer_4u { 11601e2e698Seeh volatile int64_t t_count; /* counter reg */ 11701e2e698Seeh volatile int64_t t_limit; /* limit reg */ 11801e2e698Seeh 11901e2e698Seeh #define TMR_LIM_IEN 0x80000000 /* interrupt enable bit */ 12001e2e698Seeh #define TMR_LIM_RELOAD 0x40000000 /* reload counter to 0 */ 12101e2e698Seeh #define TMR_LIM_PERIODIC 0x20000000 /* reset when limit is reached */ 12201e2e698Seeh #define TMR_LIM_MASK 0x1fffffff 12301e2e698Seeh }; 12401e2e698Seeh 12501e2e698Seeh struct timerreg_4u { 12601e2e698Seeh struct timer_4u* t_timer; /* There are two of them */ 12701e2e698Seeh volatile int64_t* t_clrintr; /* There are two of these, too. */ 12801e2e698Seeh volatile int64_t* t_mapintr; /* Same here. */ 12901e2e698Seeh }; 13001e2e698Seeh 13101e2e698Seeh struct counter_4m { /* counter that interrupts at ipl 14 */ 13201e2e698Seeh volatile int t_limit; /* limit register */ 13301e2e698Seeh volatile int t_counter; /* counter register */ 13401e2e698Seeh volatile int t_limit_nr; /* limit reg, non-resetting */ 13501e2e698Seeh volatile int t_ss; /* Start/Stop register */ 13601e2e698Seeh #define TMR_USER_RUN 1 13701e2e698Seeh }; 13801e2e698Seeh 13901e2e698Seeh #endif /* _LOCORE */ 14001e2e698Seeh 14101e2e698Seeh #define TMR_LIMIT 0x80000000 /* counter reached its limit */ 14201e2e698Seeh #define TMR_SHIFT 10 /* shift to obtain microseconds */ 14301e2e698Seeh #define TMR_MASK 0x1fffff /* 21 bits */ 14401e2e698Seeh 14501e2e698Seeh /* Compute a limit that causes the timer to fire every n microseconds. */ 14601e2e698Seeh /* #define tmr_ustolim(n) (((n) + 1) << TMR_SHIFT) */ 14701e2e698Seeh #define tmr_ustolim(n) ((n)) 14801e2e698Seeh 14901e2e698Seeh /*efine TMR_SHIFT4M 9 -* shift to obtain microseconds */ 15001e2e698Seeh /*efine tmr_ustolim(n) (((2*(n)) + 1) << TMR_SHIFT4M)*/ 15101e2e698Seeh 15201e2e698Seeh 15301e2e698Seeh 154