Home | History | Annotate | Line # | Download | only in dev
      1 /*	$NetBSD: clock.c,v 1.1 2014/02/24 07:23:42 skrll Exp $	*/
      2 
      3 /*	$OpenBSD: clock.c,v 1.10 2001/08/31 03:13:42 mickey Exp $	*/
      4 
      5 /*
      6  * Copyright (c) 1998-2003 Michael Shalayeff
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
     22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     28  * THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include <sys/cdefs.h>
     32 __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.1 2014/02/24 07:23:42 skrll Exp $");
     33 
     34 #include <sys/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/kernel.h>
     37 #include <sys/time.h>
     38 #include <sys/timetc.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 #include <hppa/hppa/machdep.h>
     49 
     50 #if defined(DDB)
     51 #include <machine/db_machdep.h>
     52 #include <ddb/db_sym.h>
     53 #include <ddb/db_extern.h>
     54 #endif
     55 
     56 static unsigned get_itimer_count(struct timecounter *);
     57 
     58 void
     59 cpu_initclocks(void)
     60 {
     61 	static struct timecounter tc = {
     62 		.tc_get_timecount = get_itimer_count,
     63 		.tc_name = "itimer",
     64 		.tc_counter_mask = ~0,
     65 		.tc_quality = 100,
     66 	};
     67 
     68 	extern u_int cpu_hzticks;
     69 	u_int time_inval;
     70 
     71 	tc.tc_frequency = cpu_hzticks * hz;
     72 
     73 	/* Start the interval timer. */
     74 	mfctl(CR_ITMR, time_inval);
     75 	mtctl(time_inval + cpu_hzticks, CR_ITMR);
     76 
     77 	tc_init(&tc);
     78 }
     79 
     80 unsigned
     81 get_itimer_count(struct timecounter *tc)
     82 {
     83 	uint32_t val;
     84 
     85 	mfctl(CR_ITMR, val);
     86 
     87 	return val;
     88 }
     89 
     90 int
     91 clock_intr(void *v)
     92 {
     93 	struct clockframe *frame = v;
     94 	extern u_int cpu_hzticks;
     95 	u_int time_inval;
     96 
     97 	/* Restart the interval timer. */
     98 	mfctl(CR_ITMR, time_inval);
     99 	mtctl(time_inval + cpu_hzticks, CR_ITMR);
    100 
    101 	/* printf ("clock int 0x%x @ 0x%x for %p\n", t,
    102 	   CLKF_PC(frame), curproc); */
    103 
    104 	if (!cold)
    105 		hardclock(frame);
    106 
    107 #if 0
    108 	ddb_regs = *frame;
    109 	db_show_regs(NULL, 0, 0, NULL);
    110 #endif
    111 
    112 	/* printf ("clock out 0x%x\n", t); */
    113 
    114 	return 1;
    115 }
    116 
    117 void
    118 setstatclockrate(int newhz)
    119 {
    120 	/* nothing we can do */
    121 }
    122 
    123