]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/timer-hpet.cpp
update
[l4.git] / kernel / fiasco / src / kern / timer-hpet.cpp
1 INTERFACE [hpet_timer]:
2
3 class Irq_base;
4
5 EXTENSION class Timer
6 {
7   static Irq_base *irq;
8   static int hpet_irq;
9 };
10
11 IMPLEMENTATION [hpet_timer]:
12
13 #include "config.h"
14 #include "cpu.h"
15 #include "hpet.h"
16 #include "irq_chip.h"
17 #include "irq_pin.h"
18 #include "logdefs.h"
19 #include "pit.h"
20 #include "std_macros.h"
21
22 #include <cstdio>
23
24 Irq_base *Timer::irq;
25 int Timer::hpet_irq;
26
27 IMPLEMENT
28 void
29 Timer::init()
30 {
31   hpet_irq = -1;
32   if (!Hpet::init())
33     return;
34
35   hpet_irq = Hpet::int_num();
36   if (hpet_irq == 0 && Hpet::int_avail(2))
37     hpet_irq = 2;
38
39   if (Config::scheduler_one_shot)
40     {
41       // tbd
42     }
43   else
44     {
45       // setup hpet for periodic here
46     }
47
48   if (!Config::scheduler_one_shot)
49     // from now we can save energy in getchar()
50     Config::getchar_does_hlt_works_ok = Config::hlt_works_ok;
51
52   static Irq_base ib;
53   Irq_chip::hw_chip->setup(&ib, hpet_irq);
54   irq = &ib;
55
56   Hpet::enable();
57   Hpet::dump();
58
59   printf("Using HPET timer on IRQ %d (%s Mode) for scheduling\n",
60          hpet_irq,
61          Config::scheduler_one_shot ? "One-Shot" : "Periodic");
62 }
63
64 IMPLEMENT inline int Timer::irq_line() { return hpet_irq; }
65
66 IMPLEMENT inline NEEDS["irq_pin.h"]
67 void
68 Timer::acknowledge()
69 {
70   irq->pin()->ack();
71 }
72
73 IMPLEMENT inline NEEDS["hpet.h", "irq_pin.h"]
74 void
75 Timer::enable()
76 {
77   irq->pin()->unmask();
78   Hpet::enable_timer();
79 }
80
81 IMPLEMENT inline NEEDS["hpet.h", "irq_pin.h"]
82 void
83 Timer::disable()
84 {
85   Hpet::disable_timer();
86   irq->pin()->mask();
87 }
88
89 static
90 void
91 Timer::update_one_shot(Unsigned64 /*wakeup*/)
92 {
93 }
94
95 IMPLEMENT inline
96 void
97 Timer::update_timer(Unsigned64 /*wakeup*/)
98 {
99 }