[BACK]Return to clock.c CVS log [TXT][DIR] Up to [local] / sys / arch / luna88k / luna88k

Annotation of sys/arch/luna88k/luna88k/clock.c, Revision 1.1.1.1

1.1       nbrk        1: /* $OpenBSD: clock.c,v 1.6 2006/01/09 21:01:45 miod Exp $ */
                      2: /* $NetBSD: clock.c,v 1.2 2000/01/11 10:29:35 nisimura 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: /* from NetBSD/luna68k sys/arch/luna68k/luna68k/clock.c */
                     47:
                     48: #include <sys/param.h>
                     49: #include <sys/systm.h>
                     50: #include <sys/device.h>
                     51: #include <sys/kernel.h>
                     52: #include <sys/evcount.h>
                     53:
                     54: #include <machine/cpu.h>
                     55:
                     56: #include <dev/clock_subr.h>
                     57: #include <luna88k/luna88k/clockvar.h>
                     58:
                     59: struct device *clockdev;
                     60: const struct clockfns *clockfns;
                     61: struct evcount *clockevc;
                     62: int clockinitted;
                     63:
                     64: void
                     65: clockattach(dev, fns, evc)
                     66:        struct device *dev;
                     67:        const struct clockfns *fns;
                     68:        struct evcount *evc;
                     69: {
                     70:        /*
                     71:         * Just bookkeeping.
                     72:         */
                     73:        if (clockfns != NULL)
                     74:                panic("clockattach: multiple clocks");
                     75:        clockdev = dev;
                     76:        clockfns = fns;
                     77:        clockevc = evc;
                     78: }
                     79:
                     80: /*
                     81:  * Machine-dependent clock routines.
                     82:  *
                     83:  * Startrtclock restarts the real-time clock, which provides
                     84:  * hardclock interrupts to kern_clock.c.
                     85:  *
                     86:  * Inittodr initializes the time of day hardware which provides
                     87:  * date functions.  Its primary function is to use some file
                     88:  * system information in case the hardare clock lost state.
                     89:  *
                     90:  * Resettodr restores the time of day hardware after a time change.
                     91:  */
                     92:
                     93: /*
                     94:  * Start the real-time and statistics clocks. Leave stathz 0 since there
                     95:  * are no other timers available.
                     96:  */
                     97: void
                     98: cpu_initclocks()
                     99: {
                    100:
                    101: #ifdef DIAGNOSTIC
                    102:        if (clockfns == NULL)
                    103:                panic("cpu_initclocks: no clock attached");
                    104: #endif
                    105:
                    106:        tick = 1000000 / hz;    /* number of microseconds between interrupts */
                    107: }
                    108:
                    109: /*
                    110:  * We assume newhz is either stathz or profhz, and that neither will
                    111:  * change after being set up above.  Could recalculate intervals here
                    112:  * but that would be a drag.
                    113:  */
                    114: void
                    115: setstatclockrate(newhz)
                    116:        int newhz;
                    117: {
                    118:        /* nothing we can do */
                    119: }
                    120:
                    121: /*
                    122:  * Initialze the time of day register, based on the time base which is, e.g.
                    123:  * from a filesystem.  Base provides the time to within six months,
                    124:  * and the time of year clock (if any) provides the rest.
                    125:  */
                    126: void
                    127: inittodr(base)
                    128:        time_t base;
                    129: {
                    130:        struct clock_ymdhms dt;
                    131:        time_t deltat;
                    132:        int badbase;
                    133:
                    134:        if (base < 5*SECYR) {
                    135:                printf("WARNING: preposterous time in file system");
                    136:                /* read the system clock anyway */
                    137:                base = 6*SECYR + 186*SECDAY + SECDAY/2;
                    138:                badbase = 1;
                    139:        } else
                    140:                badbase = 0;
                    141:
                    142:        (*clockfns->cf_get)(clockdev, base, &dt);
                    143:        clockinitted = 1;
                    144:        /* simple sanity checks */
                    145:        if (dt.dt_year < 1970 || dt.dt_mon < 1 || dt.dt_mon > 12
                    146:                || dt.dt_day < 1 || dt.dt_day > 31
                    147:                || dt.dt_hour > 23 || dt.dt_min > 59 || dt.dt_sec > 59) {
                    148:                /*
                    149:                 * Believe the time in the file system for lack of
                    150:                 * anything better, resetting the TODR.
                    151:                 */
                    152:                time.tv_sec = base;
                    153:                if (!badbase) {
                    154:                        printf("WARNING: preposterous clock chip time");
                    155:                        resettodr();
                    156:                }
                    157:                goto bad;
                    158:        }
                    159:        /* now have days since Jan 1, 1970; the rest is easy... */
                    160:        time.tv_sec = clock_ymdhms_to_secs(&dt);
                    161:
                    162:        if (!badbase) {
                    163:                /*
                    164:                 * See if we gained/lost two or more days;
                    165:                 * if so, assume something is amiss.
                    166:                 */
                    167:                deltat = time.tv_sec - base;
                    168:                if (deltat < 0)
                    169:                        deltat = -deltat;
                    170:                if (deltat < 2 * SECDAY)
                    171:                        return;
                    172:                printf("WARNING: clock %s %d days",
                    173:                    time.tv_sec < base ? "lost" : "gained",
                    174:                       (int) (deltat / SECDAY));
                    175:        }
                    176: bad:
                    177:        printf(" -- CHECK AND RESET THE DATE!\n");
                    178: }
                    179:
                    180: /*
                    181:  * Reset the TODR based on the time value; used when the TODR
                    182:  * has a preposterous value and also when the time is reset
                    183:  * by the stime system call.  Also called when the TODR goes past
                    184:  * TODRZERO + 100*(SECYEAR+2*SECDAY) (e.g. on Jan 2 just after midnight)
                    185:  * to wrap the TODR around.
                    186:  */
                    187: void
                    188: resettodr()
                    189: {
                    190:        struct clock_ymdhms dt;
                    191:
                    192:        if (!clockinitted)
                    193:                return;
                    194:        clock_secs_to_ymdhms(time.tv_sec, &dt);
                    195:        (*clockfns->cf_set)(clockdev, &dt);
                    196: }
                    197:
                    198: /*
                    199:  * Clock interrupt routine
                    200:  */
                    201: int
                    202: clockintr(void *eframe)
                    203: {
                    204:        extern unsigned int *clock_reg[];
                    205:        int cpu = cpu_number();
                    206:
                    207:        clockevc->ec_count++;
                    208:
                    209:        *clock_reg[cpu] = 0xffffffff;
                    210:        hardclock(eframe);
                    211:        return 1;
                    212: }

CVSweb