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