1 /* $NetBSD: timer.c,v 1.1 2001/06/13 15:00:26 soda Exp $ */ 2 /* NetBSD: clock.c,v 1.31 2001/05/27 13:53:24 sommerfeld Exp */ 3 4 /* 5 * Copyright (c) 1988 University of Utah. 6 * Copyright (c) 1992, 1993 7 * The Regents of the University of California. All rights reserved. 8 * 9 * This code is derived from software contributed to Berkeley by 10 * the Systems Programming Group of the University of Utah Computer 11 * Science Department and Ralph Campbell. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. All advertising materials mentioning features or use of this software 22 * must display the following acknowledgement: 23 * This product includes software developed by the University of 24 * California, Berkeley and its contributors. 25 * 4. Neither the name of the University nor the names of its contributors 26 * may be used to endorse or promote products derived from this software 27 * without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 * 41 * from: Utah Hdr: clock.c 1.18 91/01/21 42 * 43 * @(#)clock.c 8.1 (Berkeley) 6/10/93 44 */ 45 46 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 47 48 __KERNEL_RCSID(0, "$NetBSD: timer.c,v 1.1 2001/06/13 15:00:26 soda Exp $"); 49 50 #include <sys/param.h> 51 #include <sys/kernel.h> 52 #include <sys/systm.h> 53 54 #include <arc/arc/timervar.h> 55 56 struct device *timerdev; 57 const struct timerfns *timerfns; 58 int timerinitted; 59 60 void 61 timerattach(dev, fns) 62 struct device *dev; 63 const struct timerfns *fns; 64 { 65 66 /* 67 * Just bookkeeping. 68 */ 69 70 if (timerfns != NULL) 71 panic("timerattach: multiple timers"); 72 timerdev = dev; 73 timerfns = fns; 74 } 75 76 /* 77 * Machine-dependent clock routines. 78 */ 79 80 /* 81 * Start the real-time and statistics clocks. Leave stathz 0 since there 82 * are no other timers available. 83 */ 84 void 85 cpu_initclocks() 86 { 87 if (timerfns == NULL) 88 panic("cpu_initclocks: no timer attached"); 89 90 tick = 1000000 / hz; /* number of microseconds between interrupts */ 91 tickfix = 1000000 - (hz * tick); 92 if (tickfix) { 93 int ftp; 94 95 ftp = min(ffs(tickfix), ffs(hz)); 96 tickfix >>= (ftp - 1); 97 tickfixinterval = hz >> (ftp - 1); 98 } 99 100 /* 101 * Get the clock started. 102 */ 103 (*timerfns->tf_init)(timerdev); 104 } 105 106 /* 107 * We assume newhz is either stathz or profhz, and that neither will 108 * change after being set up above. Could recalculate intervals here 109 * but that would be a drag. 110 */ 111 void 112 setstatclockrate(newhz) 113 int newhz; 114 { 115 116 /* nothing we can do */ 117 } 118 119 /* 120 * Wait "n" microseconds. 121 * XXX Should be calibrated with the cycle counter. 122 */ 123 void 124 delay(n) 125 int n; 126 { 127 128 DELAY(n); 129 } 130