btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / system / kernel / arch / x86 / timers / x86_pit.cpp
bloba9007d124afd3983723f5f772c5101362accb9d7
1 /*
2 * Copyright 2008, Dustin Howett, dustin.howett@gmail.com. All rights reserved.
3 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
4 * Distributed under the terms of the MIT License.
6 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
7 * Distributed under the terms of the NewOS License.
8 */
10 #include <timer.h>
11 #include <arch/x86/timer.h>
13 #include <arch/int.h>
14 #include <arch/cpu.h>
16 #include "pit.h"
18 static bool sPITTimerInitialized = false;
20 struct timer_info gPITTimer = {
21 "PIT",
22 &pit_get_prio,
23 &pit_set_hardware_timer,
24 &pit_clear_hardware_timer,
25 &pit_init
29 static int
30 pit_get_prio(void)
32 return 1;
36 static int32
37 pit_timer_interrupt(void *data)
39 return timer_interrupt();
43 static status_t
44 pit_set_hardware_timer(bigtime_t relativeTimeout)
46 uint16 nextEventClocks;
48 if (relativeTimeout <= 0)
49 nextEventClocks = 2;
50 else if (relativeTimeout < PIT_MAX_TIMER_INTERVAL)
51 nextEventClocks = relativeTimeout * PIT_CLOCK_RATE / 1000000;
52 else
53 nextEventClocks = 0xffff;
55 out8(PIT_SELCH0 | PIT_RWBOTH | PIT_MD_INTON0, PIT_CTRL);
56 out8(nextEventClocks & 0xff, PIT_CNT0);
57 out8((nextEventClocks >> 8) & 0xff, PIT_CNT0);
59 arch_int_enable_io_interrupt(0);
60 return B_OK;
64 static status_t
65 pit_clear_hardware_timer(void)
67 arch_int_disable_io_interrupt(0);
68 return B_OK;
72 static status_t
73 pit_init(struct kernel_args *args)
75 if (sPITTimerInitialized) {
76 return B_OK;
79 install_io_interrupt_handler(0, &pit_timer_interrupt, NULL, 0);
80 pit_clear_hardware_timer();
82 sPITTimerInitialized = true;
84 return B_OK;