]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/arm/bsp/omap3/pic-arm-omap3.cpp
Inital import
[l4.git] / kernel / fiasco / src / kern / arm / bsp / omap3 / pic-arm-omap3.cpp
1 INTERFACE [arm && omap3]:
2
3 #include "kmem.h"
4
5 class Irq_base;
6
7 EXTENSION class Pic
8 {
9 public:
10   enum
11   {
12     Multi_irq_pending = 0,
13
14     No_irq_pending = 1023,
15   };
16
17   enum
18   {
19     INTCPS_SYSCONFIG         = Kmem::Intc_map_base + 0x010,
20     INTCPS_SYSSTATUS         = Kmem::Intc_map_base + 0x014,
21     INTCPS_CONTROL           = Kmem::Intc_map_base + 0x048,
22     INTCPS_TRESHOLD          = Kmem::Intc_map_base + 0x068,
23     INTCPS_ITRn_base         = Kmem::Intc_map_base + 0x080,
24     INTCPS_MIRn_base         = Kmem::Intc_map_base + 0x084,
25     INTCPS_MIR_CLEARn_base   = Kmem::Intc_map_base + 0x088,
26     INTCPS_MIR_SETn_base     = Kmem::Intc_map_base + 0x08c,
27     INTCPS_ISR_SETn_base     = Kmem::Intc_map_base + 0x090,
28     INTCPS_ISR_CLEARn_base   = Kmem::Intc_map_base + 0x094,
29     INTCPS_PENDING_IRQn_base = Kmem::Intc_map_base + 0x098,
30     INTCPS_ILRm_base         = Kmem::Intc_map_base + 0x100,
31   };
32 };
33
34
35 //-------------------------------------------------------------------
36 IMPLEMENTATION [arm && omap3]:
37
38 #include <cstring>
39 #include <cstdio>
40
41 #include "boot_info.h"
42 #include "config.h"
43 #include "initcalls.h"
44 #include "io.h"
45 #include "irq.h"
46 #include "irq_chip_generic.h"
47 #include "irq_pin.h"
48 #include "panic.h"
49 #include "vkey.h"
50
51 class Omap3_pin : public Irq_pin
52 {
53 public:
54   explicit Omap3_pin(unsigned irq) { payload()[0] = irq; }
55   unsigned irq() const { return payload()[0]; }
56 };
57
58 PUBLIC
59 void
60 Omap3_pin::unbind_irq()
61 {
62   mask();
63   disable();
64   Irq_chip::hw_chip->free(Irq::self(this), irq());
65   replace<Sw_irq_pin>();
66 }
67
68 PUBLIC
69 void
70 Omap3_pin::do_mask()
71 {
72   assert (cpu_lock.test());
73   Io::write<Mword>(1 << (irq() & 31), Pic::INTCPS_MIR_SETn_base + (irq() & 0xe0));
74 }
75
76 PUBLIC
77 void
78 Omap3_pin::do_mask_and_ack()
79 {
80   assert (cpu_lock.test());
81   __mask();
82   Io::write<Mword>(1 << (irq() & 31), Pic::INTCPS_MIR_SETn_base + (irq() & 0xe0));
83   Io::write<Mword>(1, Pic::INTCPS_CONTROL);
84 }
85
86 PUBLIC
87 void
88 Omap3_pin::ack()
89 {
90   Io::write<Mword>(1, Pic::INTCPS_CONTROL);
91 }
92
93 PUBLIC
94 void
95 Omap3_pin::hit()
96 {
97   Irq::self(this)->Irq::hit();
98 }
99
100 PUBLIC
101 void
102 Omap3_pin::do_unmask()
103 {
104   assert (cpu_lock.test());
105   Io::write<Mword>(1 << (irq() & 31), Pic::INTCPS_MIR_CLEARn_base + (irq() & 0xe0));
106 }
107
108
109 PUBLIC
110 bool
111 Omap3_pin::check_debug_irq()
112 {
113   return !Vkey::check_(irq());
114 }
115
116 PUBLIC
117 void
118 Omap3_pin::set_cpu(unsigned)
119 {
120 }
121
122 // ---
123
124
125 class Irq_chip_arm_x : public Irq_chip_gen
126 {
127 };
128
129 PUBLIC
130 void
131 Irq_chip_arm_x::setup(Irq_base *irq, unsigned irqnum)
132 {
133   if (irqnum < Config::Max_num_dirqs)
134     irq->pin()->replace<Omap3_pin>(irqnum);
135 }
136
137
138 IMPLEMENT FIASCO_INIT
139 void Pic::init()
140 {
141   static Irq_chip_arm_x _ia;
142   Irq_chip::hw_chip = &_ia;
143
144   // Reset
145   Io::write<Mword>(2, INTCPS_SYSCONFIG);
146   while (!Io::read<Mword>(INTCPS_SYSSTATUS))
147     ;
148
149   // auto-idle
150   Io::write<Mword>(1, INTCPS_SYSCONFIG);
151
152   // disable treshold
153   Io::write<Mword>(0xff, INTCPS_TRESHOLD);
154
155   // set priority for each interrupt line, lets take 0x20
156   // setting bit0 to 0 means IRQ (1 would mean FIQ)
157   for (int m = 0; m < Config::Max_num_dirqs; ++m)
158     Io::write<Mword>(0x20 << 2, INTCPS_ILRm_base + (4 * m));
159
160   // mask all interrupts
161   for (int n = 0; n < 3; ++n)
162     Io::write<Mword>(0xffffffff, INTCPS_MIR_SETn_base + 0x20 * n);
163 }
164
165 IMPLEMENT inline
166 Pic::Status Pic::disable_all_save()
167 { return 0; }
168
169 IMPLEMENT inline
170 void Pic::restore_all( Status /*s*/ )
171 {}
172
173 PUBLIC static inline NEEDS["io.h",<cstdio>]
174 Unsigned32 Pic::pending()
175 {
176   for (int n = 0; n < (Config::Max_num_dirqs >> 5); ++n)
177     {
178       unsigned long x = Io::read<Mword>(INTCPS_PENDING_IRQn_base + 0x20 * n);
179       for (int i = 0; i < 32; ++i)
180         if (x & (1 << i))
181         {
182           return i + n * 32;
183         }
184     }
185   return 0;
186 }
187
188 PUBLIC static inline
189 Mword Pic::is_pending(Mword &irqs, Mword irq)
190 { return irqs == irq; }
191
192 //---------------------------------------------------------------------------
193 IMPLEMENTATION [debug && omap3]:
194
195 PUBLIC
196 char const *
197 Omap3_pin::pin_type() const
198 { return "HW OMAP3 IRQ"; }