clock.c revision 1.17
1/*	$OpenBSD: clock.c,v 1.17 2002/11/27 21:47:14 mickey Exp $	*/
2
3/*
4 * Copyright (c) 1998,1999 Michael Shalayeff
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *	This product includes software developed by Michael Shalayeff.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF MIND,
27 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/kernel.h>
36#include <sys/time.h>
37
38#include <dev/clock_subr.h>
39
40#include <machine/pdc.h>
41#include <machine/iomod.h>
42#include <machine/psl.h>
43#include <machine/intr.h>
44#include <machine/reg.h>
45#include <machine/cpufunc.h>
46#include <machine/autoconf.h>
47
48#if defined(DDB)
49#include <uvm/uvm_extern.h>
50#include <machine/db_machdep.h>
51#include <ddb/db_sym.h>
52#include <ddb/db_extern.h>
53#endif
54
55void
56cpu_initclocks()
57{
58	CPU_CLOCKUPDATE();
59}
60
61/*
62 * initialize the system time from the time of day clock
63 */
64void
65inittodr(t)
66	time_t t;
67{
68	struct pdc_tod tod PDC_ALIGNMENT;
69	int 	error, tbad = 0;
70
71	if (t < 12*SECYR) {
72		printf ("WARNING: preposterous time in file system");
73		t = 6*SECYR + 186*SECDAY + SECDAY/2;
74		tbad = 1;
75	}
76
77	if ((error = pdc_call((iodcio_t)pdc,
78	    1, PDC_TOD, PDC_TOD_READ, &tod, 0, 0, 0, 0, 0)))
79		printf("clock: failed to fetch (%d)\n", error);
80
81	time.tv_sec = tod.sec;
82	time.tv_usec = tod.usec;
83
84	if (!tbad) {
85		u_long	dt;
86
87		dt = (time.tv_sec < t)?  t - time.tv_sec : time.tv_sec - t;
88
89		if (dt < 2 * SECDAY)
90			return;
91		printf("WARNING: clock %s %ld days",
92		    time.tv_sec < t? "lost" : "gained", dt / SECDAY);
93	}
94
95	printf (" -- CHECK AND RESET THE DATE!\n");
96}
97
98/*
99 * reset the time of day clock to the value in time
100 */
101void
102resettodr()
103{
104	int error;
105
106	if ((error = pdc_call((iodcio_t)pdc, 1, PDC_TOD, PDC_TOD_WRITE,
107	    time.tv_sec, time.tv_usec)))
108		printf("clock: failed to save (%d)\n");
109}
110
111void
112setstatclockrate(newhz)
113	int newhz;
114{
115	/* nothing we can do */
116}
117