1 | /* |
---|
2 | * |
---|
3 | * This file contains the i8259/openpic-specific implementation of the function described in irq.h |
---|
4 | * |
---|
5 | * Copyright (C) 1998, 1999 valette@crf.canon.fr |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #include <stdlib.h> |
---|
15 | |
---|
16 | #include <bsp.h> |
---|
17 | #include <bsp/irq.h> |
---|
18 | #include <bsp/irq_supp.h> |
---|
19 | #include <bsp/VMEConfig.h> |
---|
20 | #include <bsp/openpic.h> |
---|
21 | #include <libcpu/raw_exception.h> |
---|
22 | #include <libcpu/io.h> |
---|
23 | #include <bsp/vectors.h> |
---|
24 | #include <stdlib.h> |
---|
25 | |
---|
26 | #include <rtems/bspIo.h> /* for printk */ |
---|
27 | #define RAVEN_INTR_ACK_REG 0xfeff0030 |
---|
28 | |
---|
29 | #ifdef BSP_PCI_ISA_BRIDGE_IRQ |
---|
30 | /* |
---|
31 | * pointer to the mask representing the additionnal irq vectors |
---|
32 | * that must be disabled when a particular entry is activated. |
---|
33 | * They will be dynamically computed from the priority table given |
---|
34 | * in BSP_rtems_irq_mngt_set(); |
---|
35 | * CAUTION : this table is accessed directly by interrupt routine |
---|
36 | * prologue. |
---|
37 | */ |
---|
38 | rtems_i8259_masks irq_mask_or_tbl[BSP_IRQ_NUMBER]; |
---|
39 | #endif |
---|
40 | |
---|
41 | /* |
---|
42 | * default handler connected on each irq after bsp initialization |
---|
43 | */ |
---|
44 | static rtems_irq_connect_data default_rtems_entry; |
---|
45 | |
---|
46 | static rtems_irq_connect_data* rtems_hdl_tbl; |
---|
47 | |
---|
48 | #ifdef BSP_PCI_ISA_BRIDGE_IRQ |
---|
49 | /* |
---|
50 | * Check if IRQ is an ISA IRQ |
---|
51 | */ |
---|
52 | static inline int is_isa_irq(const rtems_irq_number irqLine) |
---|
53 | { |
---|
54 | return (((int) irqLine <= BSP_ISA_IRQ_MAX_OFFSET) & |
---|
55 | ((int) irqLine >= BSP_ISA_IRQ_LOWEST_OFFSET) |
---|
56 | ); |
---|
57 | } |
---|
58 | #endif |
---|
59 | |
---|
60 | /* |
---|
61 | * Check if IRQ is an OPENPIC IRQ |
---|
62 | */ |
---|
63 | static inline int is_pci_irq(const rtems_irq_number irqLine) |
---|
64 | { |
---|
65 | return (((int) irqLine <= BSP_PCI_IRQ_MAX_OFFSET) & |
---|
66 | ((int) irqLine >= BSP_PCI_IRQ_LOWEST_OFFSET) |
---|
67 | ); |
---|
68 | } |
---|
69 | |
---|
70 | /* |
---|
71 | * ------------------------ RTEMS Irq helper functions ---------------- |
---|
72 | */ |
---|
73 | |
---|
74 | #ifdef BSP_PCI_ISA_BRIDGE_IRQ |
---|
75 | /* |
---|
76 | * Caution : this function assumes the variable "*config" |
---|
77 | * is already set and that the tables it contains are still valid |
---|
78 | * and accessible. |
---|
79 | */ |
---|
80 | static void compute_i8259_masks_from_prio (rtems_irq_global_settings* config) |
---|
81 | { |
---|
82 | int i; |
---|
83 | int j; |
---|
84 | /* |
---|
85 | * Always mask at least current interrupt to prevent re-entrance |
---|
86 | */ |
---|
87 | for (i=BSP_ISA_IRQ_LOWEST_OFFSET; i < BSP_ISA_IRQ_LOWEST_OFFSET + BSP_ISA_IRQ_NUMBER; i++) { |
---|
88 | * ((unsigned short*) &irq_mask_or_tbl[i]) = (1 << i); |
---|
89 | for (j = BSP_ISA_IRQ_LOWEST_OFFSET; j < BSP_ISA_IRQ_LOWEST_OFFSET + BSP_ISA_IRQ_NUMBER; j++) { |
---|
90 | /* |
---|
91 | * Mask interrupts at i8259 level that have a lower priority |
---|
92 | */ |
---|
93 | if (config->irqPrioTbl [i] > config->irqPrioTbl [j]) { |
---|
94 | * ((unsigned short*) &irq_mask_or_tbl[i]) |= (1 << j); |
---|
95 | } |
---|
96 | } |
---|
97 | } |
---|
98 | } |
---|
99 | #endif |
---|
100 | |
---|
101 | void |
---|
102 | BSP_enable_irq_at_pic(const rtems_irq_number name) |
---|
103 | { |
---|
104 | #ifdef BSP_PCI_ISA_BRIDGE_IRQ |
---|
105 | if (is_isa_irq(name)) { |
---|
106 | /* |
---|
107 | * Enable interrupt at PIC level |
---|
108 | */ |
---|
109 | BSP_irq_enable_at_i8259s ((int) name - BSP_ISA_IRQ_LOWEST_OFFSET); |
---|
110 | } |
---|
111 | #endif |
---|
112 | |
---|
113 | if (is_pci_irq(name)) { |
---|
114 | /* |
---|
115 | * Enable interrupt at OPENPIC level |
---|
116 | */ |
---|
117 | openpic_enable_irq ((int) name - BSP_PCI_IRQ_LOWEST_OFFSET); |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | int |
---|
122 | BSP_disable_irq_at_pic(const rtems_irq_number name) |
---|
123 | { |
---|
124 | #ifdef BSP_PCI_ISA_BRIDGE_IRQ |
---|
125 | if (is_isa_irq(name)) { |
---|
126 | /* |
---|
127 | * disable interrupt at PIC level |
---|
128 | */ |
---|
129 | return BSP_irq_disable_at_i8259s ((int) name - BSP_ISA_IRQ_LOWEST_OFFSET); |
---|
130 | } |
---|
131 | #endif |
---|
132 | if (is_pci_irq(name)) { |
---|
133 | /* |
---|
134 | * disable interrupt at OPENPIC level |
---|
135 | */ |
---|
136 | return openpic_disable_irq ((int) name - BSP_PCI_IRQ_LOWEST_OFFSET); |
---|
137 | } |
---|
138 | return -1; |
---|
139 | } |
---|
140 | |
---|
141 | /* |
---|
142 | * RTEMS Global Interrupt Handler Management Routines |
---|
143 | */ |
---|
144 | int BSP_setup_the_pic(rtems_irq_global_settings* config) |
---|
145 | { |
---|
146 | int i; |
---|
147 | /* |
---|
148 | * Store various code accelerators |
---|
149 | */ |
---|
150 | default_rtems_entry = config->defaultEntry; |
---|
151 | rtems_hdl_tbl = config->irqHdlTbl; |
---|
152 | |
---|
153 | /* |
---|
154 | * set up internal tables used by rtems interrupt prologue |
---|
155 | */ |
---|
156 | |
---|
157 | #ifdef BSP_PCI_ISA_BRIDGE_IRQ |
---|
158 | /* |
---|
159 | * start with ISA IRQ |
---|
160 | */ |
---|
161 | compute_i8259_masks_from_prio (config); |
---|
162 | |
---|
163 | for (i=BSP_ISA_IRQ_LOWEST_OFFSET; i < BSP_ISA_IRQ_LOWEST_OFFSET + BSP_ISA_IRQ_NUMBER; i++) { |
---|
164 | if (rtems_hdl_tbl[i].hdl != default_rtems_entry.hdl) { |
---|
165 | BSP_irq_enable_at_i8259s (i); |
---|
166 | } |
---|
167 | else { |
---|
168 | BSP_irq_disable_at_i8259s (i); |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | if ( BSP_ISA_IRQ_NUMBER > 0 ) { |
---|
173 | /* |
---|
174 | * must enable slave pic anyway |
---|
175 | */ |
---|
176 | BSP_irq_enable_at_i8259s (2); |
---|
177 | } |
---|
178 | #endif |
---|
179 | |
---|
180 | /* |
---|
181 | * continue with PCI IRQ |
---|
182 | */ |
---|
183 | for (i=BSP_PCI_IRQ_LOWEST_OFFSET; i < BSP_PCI_IRQ_LOWEST_OFFSET + BSP_PCI_IRQ_NUMBER ; i++) { |
---|
184 | /* |
---|
185 | * Note that openpic_set_priority() sets the TASK priority of the PIC |
---|
186 | */ |
---|
187 | openpic_set_source_priority(i - BSP_PCI_IRQ_LOWEST_OFFSET, |
---|
188 | config->irqPrioTbl[i]); |
---|
189 | if (rtems_hdl_tbl[i].hdl != default_rtems_entry.hdl) { |
---|
190 | openpic_enable_irq ((int) i - BSP_PCI_IRQ_LOWEST_OFFSET); |
---|
191 | } |
---|
192 | else { |
---|
193 | openpic_disable_irq ((int) i - BSP_PCI_IRQ_LOWEST_OFFSET); |
---|
194 | } |
---|
195 | } |
---|
196 | |
---|
197 | #ifdef BSP_PCI_ISA_BRIDGE_IRQ |
---|
198 | if ( BSP_ISA_IRQ_NUMBER > 0 ) { |
---|
199 | /* |
---|
200 | * Must enable PCI/ISA bridge IRQ |
---|
201 | */ |
---|
202 | openpic_enable_irq (0); |
---|
203 | } |
---|
204 | #endif |
---|
205 | |
---|
206 | return 1; |
---|
207 | } |
---|
208 | |
---|
209 | int _BSP_vme_bridge_irq = -1; |
---|
210 | |
---|
211 | unsigned BSP_spuriousIntr = 0; |
---|
212 | |
---|
213 | /* |
---|
214 | * High level IRQ handler called from shared_raw_irq_code_entry |
---|
215 | */ |
---|
216 | int C_dispatch_irq_handler (BSP_Exception_frame *frame, unsigned int excNum) |
---|
217 | { |
---|
218 | register unsigned int irq; |
---|
219 | #ifdef BSP_PCI_ISA_BRIDGE_IRQ |
---|
220 | register unsigned isaIntr; /* boolean */ |
---|
221 | register unsigned oldMask = 0; /* old isa pic masks */ |
---|
222 | register unsigned newMask; /* new isa pic masks */ |
---|
223 | #endif |
---|
224 | |
---|
225 | if (excNum == ASM_DEC_VECTOR) { |
---|
226 | |
---|
227 | bsp_irq_dispatch_list(rtems_hdl_tbl, BSP_DECREMENTER, default_rtems_entry.hdl); |
---|
228 | |
---|
229 | return 0; |
---|
230 | |
---|
231 | } |
---|
232 | irq = openpic_irq(0); |
---|
233 | if (irq == OPENPIC_VEC_SPURIOUS) { |
---|
234 | ++BSP_spuriousIntr; |
---|
235 | return 0; |
---|
236 | } |
---|
237 | |
---|
238 | /* some BSPs might want to use a different numbering... */ |
---|
239 | irq = irq - OPENPIC_VEC_SOURCE + BSP_PCI_IRQ_LOWEST_OFFSET; |
---|
240 | |
---|
241 | #ifdef BSP_PCI_ISA_BRIDGE_IRQ |
---|
242 | isaIntr = (irq == BSP_PCI_ISA_BRIDGE_IRQ); |
---|
243 | if (isaIntr) { |
---|
244 | /* |
---|
245 | * Acknowledge and read 8259 vector |
---|
246 | */ |
---|
247 | irq = (unsigned int) (*(unsigned char *) RAVEN_INTR_ACK_REG); |
---|
248 | /* |
---|
249 | * store current PIC mask |
---|
250 | */ |
---|
251 | oldMask = i8259s_cache; |
---|
252 | newMask = oldMask | irq_mask_or_tbl [irq]; |
---|
253 | i8259s_cache = newMask; |
---|
254 | outport_byte(PIC_MASTER_IMR_IO_PORT, i8259s_cache & 0xff); |
---|
255 | outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8)); |
---|
256 | BSP_irq_ack_at_i8259s (irq); |
---|
257 | openpic_eoi(0); |
---|
258 | } |
---|
259 | #endif |
---|
260 | |
---|
261 | /* dispatch handlers */ |
---|
262 | bsp_irq_dispatch_list(rtems_hdl_tbl, irq, default_rtems_entry.hdl); |
---|
263 | |
---|
264 | #ifdef BSP_PCI_ISA_BRIDGE_IRQ |
---|
265 | if (isaIntr) { |
---|
266 | i8259s_cache = oldMask; |
---|
267 | outport_byte(PIC_MASTER_IMR_IO_PORT, i8259s_cache & 0xff); |
---|
268 | outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8)); |
---|
269 | } |
---|
270 | else |
---|
271 | #endif |
---|
272 | { |
---|
273 | #ifdef BSP_PCI_VME_DRIVER_DOES_EOI |
---|
274 | /* leave it to the VME bridge driver to do EOI, so |
---|
275 | * it can re-enable the openpic while handling |
---|
276 | * VME interrupts (-> VME priorities in software) |
---|
277 | */ |
---|
278 | if (_BSP_vme_bridge_irq != irq) |
---|
279 | #endif |
---|
280 | openpic_eoi(0); |
---|
281 | } |
---|
282 | return 0; |
---|
283 | } |
---|