Lines Matching +full:sys +full:- +full:clock +full:- +full:req +full:- +full:active +full:- +full:high
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
36 #include <sys/cdefs.h>
38 * Routines to handle clock hardware.
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/bus.h>
52 #include <sys/lock.h>
53 #include <sys/kdb.h>
54 #include <sys/mutex.h>
55 #include <sys/proc.h>
56 #include <sys/kernel.h>
57 #include <sys/module.h>
58 #include <sys/rman.h>
59 #include <sys/sched.h>
60 #include <sys/smp.h>
61 #include <sys/sysctl.h>
62 #include <sys/timeet.h>
63 #include <sys/timetc.h>
65 #include <machine/clock.h>
111 static int timer0_period = -2;
129 /* Init the clock lock */ in clock_init()
131 /* Init the clock in order to use DELAY */ in clock_init()
141 if (i8254_timecounter && sc->period != 0) { in clkintr()
153 if (sc->et.et_active && sc->mode != MODE_STOP) in clkintr()
154 sc->et.et_event_cb(&sc->et, sc->et.et_arg); in clkintr()
167 return (-1); in timer_spkr_acquire()
173 * knew the rate. Use of splclock() limits glitches to 10-100us, in timer_spkr_acquire()
188 return (-1); in timer_spkr_release()
210 int high, low; in getit() local
218 high = inb(TIMER_CNTR0); in getit()
221 return ((high << 8) | low); in getit()
254 * However, if ddb is active then use a fake counter since reading in i8254_delay()
265 n -= 0; /* XXX actually guess no initial overhead */ in i8254_delay()
279 ticks_left = ((u_int)n * 39099 + (1 << 15) - 1) >> 15; in i8254_delay()
282 * Don't bother using fixed point, although gcc-2.7.2 in i8254_delay()
294 tick = prev_tick - 1; in i8254_delay()
303 delta = prev_tick - tick; in i8254_delay()
316 ticks_left -= delta; in i8254_delay()
336 new_count = -1; in set_i8254_freq()
344 timer0_period = (mode == MODE_PERIODIC) ? new_count : -1; in set_i8254_freq()
385 timer0_period = -2; in i8254_restore()
389 set_i8254_freq(attimer_sc->mode, attimer_sc->period); in i8254_restore()
447 error = sysctl_handle_int(oidp, &freq, 0, req); in sysctl_machdep_i8254_freq()
448 if (error == 0 && req->newptr != NULL) { in sysctl_machdep_i8254_freq()
451 set_i8254_freq(attimer_sc->mode, attimer_sc->period); in sysctl_machdep_i8254_freq()
452 attimer_sc->tc.tc_frequency = freq; in sysctl_machdep_i8254_freq()
468 device_t dev = (device_t)tc->tc_priv; in i8254_get_timecount()
472 u_int high, low; in i8254_get_timecount() local
474 if (sc->period == 0) in i8254_get_timecount()
475 return (i8254_max_count - getit()); in i8254_get_timecount()
488 high = inb(TIMER_CNTR0); in i8254_get_timecount()
489 count = i8254_max_count - ((high << 8) | low); in i8254_get_timecount()
507 device_t dev = (device_t)et->et_priv; in attimer_start()
511 sc->mode = MODE_PERIODIC; in attimer_start()
512 sc->period = period; in attimer_start()
514 sc->mode = MODE_ONESHOT; in attimer_start()
515 sc->period = first; in attimer_start()
517 if (!sc->intr_en) { in attimer_start()
518 i8254_intsrc->is_pic->pic_enable_source(i8254_intsrc); in attimer_start()
519 sc->intr_en = 1; in attimer_start()
521 set_i8254_freq(sc->mode, sc->period); in attimer_start()
528 device_t dev = (device_t)et->et_priv; in attimer_stop()
531 sc->mode = MODE_STOP; in attimer_stop()
532 sc->period = 0; in attimer_stop()
533 set_i8254_freq(sc->mode, sc->period); in attimer_stop()
552 /* ENOENT means no PnP-ID, device is hinted. */ in attimer_probe()
569 if (!(sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, in attimer_attach()
570 &sc->port_rid, IO_TIMER1, IO_TIMER1 + 3, 4, RF_ACTIVE))) in attimer_attach()
574 i8254_pending = i8254_intsrc->is_pic->pic_source_pending; in attimer_attach()
579 sc->tc.tc_get_timecount = i8254_get_timecount; in attimer_attach()
580 sc->tc.tc_counter_mask = 0xffff; in attimer_attach()
581 sc->tc.tc_frequency = i8254_freq; in attimer_attach()
582 sc->tc.tc_name = "i8254"; in attimer_attach()
583 sc->tc.tc_quality = 0; in attimer_attach()
584 sc->tc.tc_priv = dev; in attimer_attach()
585 tc_init(&sc->tc); in attimer_attach()
588 "clock", &i) != 0 || i != 0) { in attimer_attach()
589 sc->intr_rid = 0; in attimer_attach()
590 while (bus_get_resource(dev, SYS_RES_IRQ, sc->intr_rid, in attimer_attach()
592 sc->intr_rid++; in attimer_attach()
593 if (!(sc->intr_res = bus_alloc_resource(dev, SYS_RES_IRQ, in attimer_attach()
594 &sc->intr_rid, 0, 0, 1, RF_ACTIVE))) { in attimer_attach()
599 i8254_intsrc->is_handlers++; in attimer_attach()
600 if ((bus_setup_intr(dev, sc->intr_res, in attimer_attach()
603 sc, &sc->intr_handler))) { in attimer_attach()
605 i8254_intsrc->is_handlers--; in attimer_attach()
608 i8254_intsrc->is_handlers--; in attimer_attach()
609 i8254_intsrc->is_pic->pic_enable_intr(i8254_intsrc); in attimer_attach()
610 sc->et.et_name = "i8254"; in attimer_attach()
611 sc->et.et_flags = ET_FLAGS_PERIODIC; in attimer_attach()
613 sc->et.et_flags |= ET_FLAGS_ONESHOT; in attimer_attach()
614 sc->et.et_quality = 100; in attimer_attach()
615 sc->et.et_frequency = i8254_freq; in attimer_attach()
616 sc->et.et_min_period = (0x0002LLU << 32) / i8254_freq; in attimer_attach()
617 sc->et.et_max_period = (0xfffeLLU << 32) / i8254_freq; in attimer_attach()
618 sc->et.et_start = attimer_start; in attimer_attach()
619 sc->et.et_stop = attimer_stop; in attimer_attach()
620 sc->et.et_priv = dev; in attimer_attach()
621 et_register(&sc->et); in attimer_attach()