xref: /netbsd-src/sys/dev/mvme/clockvar.h (revision 7cf2991222ea44a8a722cf40f50f32f50785265e)
1*7cf29912Scegger /*	$NetBSD: clockvar.h,v 1.9 2009/05/12 14:38:26 cegger Exp $	*/
28c75e475Sscw 
38c75e475Sscw /*-
48c75e475Sscw  * Copyright (c) 1996, 2002 The NetBSD Foundation, Inc.
58c75e475Sscw  * All rights reserved.
68c75e475Sscw  *
78c75e475Sscw  * This code is derived from software contributed to The NetBSD Foundation
88c75e475Sscw  * by Jason R. Thorpe.
98c75e475Sscw  *
108c75e475Sscw  * Redistribution and use in source and binary forms, with or without
118c75e475Sscw  * modification, are permitted provided that the following conditions
128c75e475Sscw  * are met:
138c75e475Sscw  * 1. Redistributions of source code must retain the above copyright
148c75e475Sscw  *    notice, this list of conditions and the following disclaimer.
158c75e475Sscw  * 2. Redistributions in binary form must reproduce the above copyright
168c75e475Sscw  *    notice, this list of conditions and the following disclaimer in the
178c75e475Sscw  *    documentation and/or other materials provided with the distribution.
188c75e475Sscw  *
198c75e475Sscw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
208c75e475Sscw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
218c75e475Sscw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
228c75e475Sscw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
238c75e475Sscw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
248c75e475Sscw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
258c75e475Sscw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
268c75e475Sscw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
278c75e475Sscw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
288c75e475Sscw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
298c75e475Sscw  * POSSIBILITY OF SUCH DAMAGE.
308c75e475Sscw  */
318c75e475Sscw 
328c75e475Sscw #ifndef _MVME_CLOCKVAR_H
338c75e475Sscw #define _MVME_CLOCKVAR_H
348c75e475Sscw 
358c75e475Sscw #include <dev/clock_subr.h>
368c75e475Sscw 
378c75e475Sscw /*
38db579612Swiz  * Definitions exported to ASIC-specific clock attachment.
398c75e475Sscw  */
408c75e475Sscw 
418c75e475Sscw extern	struct evcnt clock_profcnt;
428c75e475Sscw extern	struct evcnt clock_statcnt;
438c75e475Sscw 
448c75e475Sscw extern	int clock_statvar;
458c75e475Sscw extern	int clock_statmin;
468c75e475Sscw 
478c75e475Sscw struct clock_attach_args {
4818db93c7Sperry 	void			(*ca_initfunc)(void *, int, int);
498c75e475Sscw 	void			*ca_arg;
508c75e475Sscw };
518c75e475Sscw 
52*7cf29912Scegger void	clock_config(device_t, struct clock_attach_args *,
5318db93c7Sperry 			struct evcnt *);
548c75e475Sscw 
558c75e475Sscw /*
568c75e475Sscw  * Macro to compute a new randomized interval.  The intervals are
578c75e475Sscw  * uniformly distributed on [statint - statvar / 2, statint + statvar / 2],
588c75e475Sscw  * and therefore have mean statint, giving a stathz frequency clock.
598c75e475Sscw  *
608c75e475Sscw  * This is gratuitously stolen from sparc/sparc/clock.c
618c75e475Sscw  */
628c75e475Sscw #define CLOCK_NEWINT(statvar, statmin)	({				\
638c75e475Sscw 		u_long r, var = (statvar);				\
648c75e475Sscw 		do { r = random() & (var - 1); } while (r == 0);	\
658c75e475Sscw 		(statmin + r);						\
668c75e475Sscw 	})
678c75e475Sscw 
688c75e475Sscw /*
698c75e475Sscw  * Sun chose the year `68' as their base count, so that
708c75e475Sscw  * cl_year==0 means 1968.
718c75e475Sscw  */
728c75e475Sscw #define YEAR0   1968
738c75e475Sscw 
748c75e475Sscw /*
758c75e475Sscw  * interrupt level for clock
768c75e475Sscw  */
778c75e475Sscw #define CLOCK_LEVEL 5
788c75e475Sscw 
798c75e475Sscw #endif /* _MVME_CLOCKVAR_H */
80