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