2 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
6 * Distributed under the terms of the NewOS License.
10 #include <boot/stage2.h>
22 #include <arch/timer.h>
24 #include <arch/x86/smp_priv.h>
25 #include <arch/x86/timer.h>
30 # define TRACE(x) dprintf x
35 extern timer_info gPITTimer
;
36 extern timer_info gAPICTimer
;
37 extern timer_info gHPETTimer
;
39 static timer_info
*sTimers
[] = {
46 static timer_info
*sTimer
= NULL
;
49 arch_timer_set_hardware_timer(bigtime_t timeout
)
51 TRACE(("arch_timer_set_hardware_timer: timeout %lld\n", timeout
));
52 sTimer
->set_hardware_timer(timeout
);
57 arch_timer_clear_hardware_timer(void)
59 TRACE(("arch_timer_clear_hardware_timer\n"));
60 sTimer
->clear_hardware_timer();
65 sort_timers(timer_info
*timers
[], int numTimers
)
72 for (i
= 0; i
< numTimers
- 1; i
++) {
74 for (j
= i
+ 1; j
< numTimers
; j
++) {
75 if (timers
[j
]->get_priority() > timers
[max
]->get_priority())
79 tempPtr
= timers
[max
];
80 timers
[max
] = timers
[i
];
86 for (i
= 0; i
< numTimers
; i
++)
87 dprintf(" %s: priority %d\n", timers
[i
]->name
, timers
[i
]->get_priority());
93 arch_init_timer(kernel_args
*args
)
95 // Sort timers by priority
96 sort_timers(sTimers
, (sizeof(sTimers
) / sizeof(sTimers
[0])) - 1);
98 timer_info
*timer
= NULL
;
99 cpu_status state
= disable_interrupts();
101 for (int i
= 0; (timer
= sTimers
[i
]) != NULL
; i
++) {
102 if (timer
->init(args
) == B_OK
)
108 if (sTimer
!= NULL
) {
109 dprintf("arch_init_timer: using %s timer.\n", sTimer
->name
);
111 panic("No system timers were found usable.\n");
114 restore_interrupts(state
);