1 /* $NetBSD: clock.c,v 1.14 2023/02/03 23:13:01 tsutsui Exp $ */ 2 /* 3 * Copyright (c) 1998 Darrin B. Jewell 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #include <sys/cdefs.h> 28 __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.14 2023/02/03 23:13:01 tsutsui Exp $"); 29 30 #include <sys/param.h> 31 #include <sys/systm.h> 32 #include <sys/kernel.h> 33 #include <sys/tty.h> 34 #include <sys/device.h> 35 36 #include <machine/psl.h> 37 #include <machine/bus.h> 38 #include <machine/cpu.h> 39 40 #include <next68k/dev/clockreg.h> 41 #include <next68k/dev/intiovar.h> 42 43 #include <next68k/next68k/rtc.h> 44 #include <next68k/next68k/isr.h> 45 46 /* @@@ This is pretty bogus and will need fixing once 47 * things are working better. 48 * -- jewell@mit.edu 49 */ 50 51 int clock_intr(void *); 52 53 int 54 clock_intr(void *arg) 55 { 56 volatile struct timer_reg *timer; 57 int whilecount = 0; 58 59 if (!INTR_OCCURRED(NEXT_I_TIMER)) { 60 return 0; 61 } 62 63 do { 64 static int in_hardclock = 0; 65 int s; 66 67 timer = (volatile struct timer_reg *)IIOV(NEXT_P_TIMER); 68 timer->csr |= TIMER_REG_UPDATE; 69 70 if (!in_hardclock) { 71 in_hardclock = 1; 72 s = splclock (); 73 hardclock(arg); 74 splx(s); 75 in_hardclock = 0; 76 } 77 if (whilecount++ > 10) 78 panic ("whilecount"); 79 } while (INTR_OCCURRED(NEXT_I_TIMER)); 80 return 1; 81 } 82 83 /* 84 * Set up the real-time and statistics clocks. Leave stathz 0 only 85 * if no alternative timer is available. 86 * 87 * The frequencies of these clocks must be an even number of microseconds. 88 */ 89 void 90 cpu_initclocks(void) 91 { 92 int s, cnt; 93 volatile struct timer_reg *timer; 94 95 rtc_init(); 96 hz = 100; 97 s = splclock(); 98 timer = (volatile struct timer_reg *)IIOV(NEXT_P_TIMER); 99 cnt = 1000000/hz; /* usec timer */ 100 timer->csr = 0; 101 timer->msb = (cnt >> 8); 102 timer->lsb = cnt; 103 timer->csr = TIMER_REG_ENABLE|TIMER_REG_UPDATE; 104 isrlink_autovec(clock_intr, NULL, NEXT_I_IPL(NEXT_I_TIMER), 0, NULL); 105 INTR_ENABLE(NEXT_I_TIMER); 106 splx(s); 107 } 108 109 110 void 111 setstatclockrate(int newhz) 112 { 113 114 /* XXX should we do something here? XXX */ 115 } 116 117 /* 118 * @@@ update this to use the usec timer 119 * Darrin B Jewell <jewell@mit.edu> Sun Feb 8 05:01:02 1998 120 * XXX: Well, there is no more microtime. But if there is a hardware 121 * timer of any sort, it could be added. ENODOCS. gdamore. 122 */ 123 124