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