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