source: rtems/c/src/lib/libbsp/powerpc/qoriq/irq/irq.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 7.9 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup QorIQ
5 *
6 * @brief Interrupt implementation.
7 */
8
9/*
10 * Copyright (c) 2010, 2012 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#include <rtems.h>
24
25#include <libcpu/powerpc-utility.h>
26
27#include <bsp.h>
28#include <bsp/irq.h>
29#include <bsp/irq-generic.h>
30#include <bsp/vectors.h>
31#include <bsp/utility.h>
32#include <bsp/qoriq.h>
33
34#define VPR_MSK BSP_BBIT32(0)
35#define VPR_A BSP_BBIT32(1)
36#define VPR_P BSP_BBIT32(8)
37#define VPR_S BSP_BBIT32(9)
38#define VPR_PRIORITY(val) BSP_BFLD32(val, 12, 15)
39#define VPR_PRIORITY_GET(reg) BSP_BFLD32GET(reg, 12, 15)
40#define VPR_PRIORITY_SET(reg, val) BSP_BFLD32SET(reg, val, 12, 15)
41#define VPR_VECTOR(val) BSP_BFLD32(val, 16, 31)
42#define VPR_VECTOR_GET(reg) BSP_BFLD32GET(reg, 16, 31)
43#define VPR_VECTOR_SET(reg, val) BSP_BFLD32SET(reg, val, 16, 31)
44
45#define GCR_RST BSP_BBIT32(0)
46#define GCR_M BSP_BBIT32(2)
47
48#define SPURIOUS 0xffff
49
50static const uint16_t vpr_and_dr_offsets [] = {
51        [0] = 0x10200 >> 4,
52        [1] = 0x10220 >> 4,
53        [2] = 0x10240 >> 4,
54        [3] = 0x10260 >> 4,
55        [4] = 0x10280 >> 4,
56        [5] = 0x102a0 >> 4,
57        [6] = 0x102c0 >> 4,
58        [7] = 0x102e0 >> 4,
59        [8] = 0x10300 >> 4,
60        [9] = 0x10320 >> 4,
61        [10] = 0x10340 >> 4,
62        [11] = 0x10360 >> 4,
63        [12] = 0x10380 >> 4,
64        [13] = 0x103a0 >> 4,
65        [14] = 0x103c0 >> 4,
66        [15] = 0x103e0 >> 4,
67        [16] = 0x10400 >> 4,
68        [17] = 0x10420 >> 4,
69        [18] = 0x10440 >> 4,
70        [19] = 0x10460 >> 4,
71        [20] = 0x10480 >> 4,
72        [21] = 0x104a0 >> 4,
73        [22] = 0x104c0 >> 4,
74        [23] = 0x104e0 >> 4,
75        [24] = 0x10500 >> 4,
76        [25] = 0x10520 >> 4,
77        [26] = 0x10540 >> 4,
78        [27] = 0x10560 >> 4,
79        [28] = 0x10580 >> 4,
80        [29] = 0x105a0 >> 4,
81        [30] = 0x105c0 >> 4,
82        [31] = 0x105e0 >> 4,
83        [32] = 0x10600 >> 4,
84        [33] = 0x10620 >> 4,
85        [34] = 0x10640 >> 4,
86        [35] = 0x10660 >> 4,
87        [36] = 0x10680 >> 4,
88        [37] = 0x106a0 >> 4,
89        [38] = 0x106c0 >> 4,
90        [39] = 0x106e0 >> 4,
91        [40] = 0x10700 >> 4,
92        [41] = 0x10720 >> 4,
93        [42] = 0x10740 >> 4,
94        [43] = 0x10760 >> 4,
95        [44] = 0x10780 >> 4,
96        [45] = 0x107a0 >> 4,
97        [46] = 0x107c0 >> 4,
98        [47] = 0x107e0 >> 4,
99        [48] = 0x10800 >> 4,
100        [49] = 0x10820 >> 4,
101        [50] = 0x10840 >> 4,
102        [51] = 0x10860 >> 4,
103        [52] = 0x10880 >> 4,
104        [53] = 0x108a0 >> 4,
105        [54] = 0x108c0 >> 4,
106        [55] = 0x108e0 >> 4,
107        [56] = 0x10900 >> 4,
108        [57] = 0x10920 >> 4,
109        [58] = 0x10940 >> 4,
110        [59] = 0x10960 >> 4,
111        [60] = 0x10980 >> 4,
112        [61] = 0x109a0 >> 4,
113        [62] = 0x109c0 >> 4,
114        [63] = 0x109e0 >> 4,
115        [QORIQ_IRQ_EXT_0] = 0x10000 >> 4,
116        [QORIQ_IRQ_EXT_1] = 0x10020 >> 4,
117        [QORIQ_IRQ_EXT_2] = 0x10040 >> 4,
118        [QORIQ_IRQ_EXT_3] = 0x10060 >> 4,
119        [QORIQ_IRQ_EXT_4] = 0x10080 >> 4,
120        [QORIQ_IRQ_EXT_5] = 0x100a0 >> 4,
121        [QORIQ_IRQ_EXT_6] = 0x100c0 >> 4,
122        [QORIQ_IRQ_EXT_7] = 0x100e0 >> 4,
123        [QORIQ_IRQ_EXT_8] = 0x10100 >> 4,
124        [QORIQ_IRQ_EXT_9] = 0x10120 >> 4,
125        [QORIQ_IRQ_EXT_10] = 0x10140 >> 4,
126        [QORIQ_IRQ_EXT_11] = 0x10160 >> 4,
127        [QORIQ_IRQ_IPI_0] = 0x010a0 >> 4,
128        [QORIQ_IRQ_IPI_1] = 0x010b0 >> 4,
129        [QORIQ_IRQ_IPI_2] = 0x010c0 >> 4,
130        [QORIQ_IRQ_IPI_3] = 0x010d0 >> 4,
131        [QORIQ_IRQ_MI_0] = 0x11600 >> 4,
132        [QORIQ_IRQ_MI_1] = 0x11620 >> 4,
133        [QORIQ_IRQ_MI_2] = 0x11640 >> 4,
134        [QORIQ_IRQ_MI_3] = 0x11660 >> 4,
135        [QORIQ_IRQ_MI_4] = 0x11680 >> 4,
136        [QORIQ_IRQ_MI_5] = 0x116a0 >> 4,
137        [QORIQ_IRQ_MI_6] = 0x116c0 >> 4,
138        [QORIQ_IRQ_MI_7] = 0x116e0 >> 4,
139        [QORIQ_IRQ_MSI_0] = 0x11c00 >> 4,
140        [QORIQ_IRQ_MSI_1] = 0x11c20 >> 4,
141        [QORIQ_IRQ_MSI_2] = 0x11c40 >> 4,
142        [QORIQ_IRQ_MSI_3] = 0x11c60 >> 4,
143        [QORIQ_IRQ_MSI_4] = 0x11c80 >> 4,
144        [QORIQ_IRQ_MSI_5] = 0x11ca0 >> 4,
145        [QORIQ_IRQ_MSI_6] = 0x11cc0 >> 4,
146        [QORIQ_IRQ_MSI_7] = 0x11ce0 >> 4,
147        [QORIQ_IRQ_GT_A_0] = 0x01120 >> 4,
148        [QORIQ_IRQ_GT_A_1] = 0x01160 >> 4,
149        [QORIQ_IRQ_GT_A_2] = 0x011a0 >> 4,
150        [QORIQ_IRQ_GT_A_3] = 0x011e0 >> 4,
151        [QORIQ_IRQ_GT_B_0] = 0x02120 >> 4,
152        [QORIQ_IRQ_GT_B_1] = 0x02160 >> 4,
153        [QORIQ_IRQ_GT_B_2] = 0x021a0 >> 4,
154        [QORIQ_IRQ_GT_B_3] = 0x021e0 >> 4
155};
156
157rtems_status_code qoriq_pic_set_priority(
158        rtems_vector_number vector,
159        int new_priority,
160        int *old_priority
161)
162{
163        rtems_status_code sc = RTEMS_SUCCESSFUL;
164        uint32_t old_vpr = 0;
165
166        if (bsp_interrupt_is_valid_vector(vector)) {
167                int offs = vpr_and_dr_offsets [vector] << 2;
168                volatile uint32_t *vpr = (volatile uint32_t *) &qoriq.pic + offs;
169
170                if (QORIQ_PIC_PRIORITY_IS_VALID(new_priority)) {
171                        rtems_interrupt_level level;
172
173                        rtems_interrupt_disable(level);
174                        old_vpr = *vpr;
175                        *vpr = VPR_PRIORITY_SET(old_vpr, (uint32_t) new_priority);
176                        rtems_interrupt_enable(level);
177                } else if (new_priority < 0) {
178                        old_vpr = *vpr;
179                } else {
180                        sc = RTEMS_INVALID_PRIORITY;
181                }
182        } else {
183                sc = RTEMS_INVALID_ID;
184        }
185
186        if (old_priority != NULL) {
187                *old_priority = (int) VPR_PRIORITY_GET(old_vpr);
188        }
189
190        return sc;
191}
192
193rtems_status_code qoriq_pic_set_affinity(
194        rtems_vector_number vector,
195        uint32_t processor_index
196)
197{
198        rtems_status_code sc = RTEMS_SUCCESSFUL;
199
200        if (bsp_interrupt_is_valid_vector(vector)) {
201                if (processor_index <= 1) {
202                        int offs = (vpr_and_dr_offsets [vector] << 2) + 4;
203                        volatile uint32_t *dr = (volatile uint32_t *) &qoriq.pic + offs;
204
205                        *dr = BSP_BIT32(processor_index);
206                } else {
207                        sc = RTEMS_INVALID_NUMBER;
208                }
209        } else {
210                sc = RTEMS_INVALID_ID;
211        }
212
213        return sc;
214}
215
216static rtems_status_code pic_vector_enable(rtems_vector_number vector, uint32_t msk)
217{
218        rtems_status_code sc = RTEMS_SUCCESSFUL;
219
220        if (bsp_interrupt_is_valid_vector(vector)) {
221                int offs = vpr_and_dr_offsets [vector] << 2;
222                volatile uint32_t *vpr = (volatile uint32_t *) &qoriq.pic + offs;
223                rtems_interrupt_level level;
224
225                rtems_interrupt_disable(level);
226                *vpr = (*vpr & ~VPR_MSK) | msk;
227                rtems_interrupt_enable(level);
228        }
229
230        return sc;
231}
232
233rtems_status_code bsp_interrupt_vector_enable(rtems_vector_number vector)
234{
235        return pic_vector_enable(vector, 0);
236}
237
238rtems_status_code bsp_interrupt_vector_disable(rtems_vector_number vector)
239{
240        return pic_vector_enable(vector, VPR_MSK);
241}
242
243static void qoriq_interrupt_dispatch(void)
244{
245        rtems_vector_number vector = qoriq.pic.iack;
246
247        if (vector != SPURIOUS) {
248                uint32_t msr = ppc_external_exceptions_enable();
249
250                bsp_interrupt_handler_dispatch(vector);
251
252                ppc_external_exceptions_disable(msr);
253
254                qoriq.pic.eoi = 0;
255                qoriq.pic.whoami;
256        } else {
257                bsp_interrupt_handler_default(vector);
258        }
259}
260
261#ifndef PPC_EXC_CONFIG_USE_FIXED_HANDLER
262static int qoriq_external_exception_handler(BSP_Exception_frame *frame, unsigned exception_number)
263{
264        qoriq_interrupt_dispatch();
265
266        return 0;
267}
268#else
269void bsp_interrupt_dispatch(void)
270{
271        qoriq_interrupt_dispatch();
272}
273#endif
274
275static bool pic_is_ipi(rtems_vector_number vector)
276{
277        return QORIQ_IRQ_IPI_0 <= vector && vector <= QORIQ_IRQ_IPI_3;
278}
279
280static void pic_reset(void)
281{
282        qoriq.pic.gcr = GCR_RST;
283        while ((qoriq.pic.gcr & GCR_RST) != 0) {
284                /* Wait */
285        }
286}
287
288static void pic_global_timer_init(void)
289{
290        int i = 0;
291
292        qoriq.pic.tcra = 0;
293        qoriq.pic.tcrb = 0;
294
295        for (i = 0; i < 4; ++i) {
296                qoriq.pic.gta [0].bcr = GTBCR_CI;
297                qoriq.pic.gtb [0].bcr = GTBCR_CI;
298        }
299}
300
301rtems_status_code bsp_interrupt_facility_initialize(void)
302{
303        rtems_vector_number i = 0;
304        uint32_t processor_id = ppc_processor_id();
305
306#ifndef PPC_EXC_CONFIG_USE_FIXED_HANDLER
307        if (ppc_exc_set_handler(ASM_EXT_VECTOR, qoriq_external_exception_handler)) {
308                return RTEMS_IO_ERROR;
309        }
310#endif
311
312        if (processor_id == 0) {
313                /* Core 0 must do the basic initialization */
314
315                pic_reset();
316
317                for (i = BSP_INTERRUPT_VECTOR_MIN; i <= BSP_INTERRUPT_VECTOR_MAX; ++i) {
318                        volatile uint32_t *base = (volatile uint32_t *) &qoriq.pic;
319                        int offs = vpr_and_dr_offsets [i] << 2;
320                        volatile uint32_t *vpr = base + offs;
321
322                        *vpr = VPR_MSK | VPR_P | VPR_PRIORITY(1) | VPR_VECTOR(i);
323
324                        if (!pic_is_ipi(i)) {
325                                volatile uint32_t *dr = base + offs + 4;
326
327                                *dr = 0x1;
328                        }
329                }
330
331                qoriq.pic.mer03 = 0xf;
332                qoriq.pic.mer47 = 0xf;
333                qoriq.pic.svr = SPURIOUS;
334                qoriq.pic.gcr = GCR_M;
335
336                pic_global_timer_init();
337        }
338
339        qoriq.pic.ctpr = 0;
340
341        for (i = BSP_INTERRUPT_VECTOR_MIN; i <= BSP_INTERRUPT_VECTOR_MAX; ++i) {
342                qoriq.pic.iack;
343                qoriq.pic.eoi = 0;
344                qoriq.pic.whoami;
345        }
346
347        return RTEMS_SUCCESSFUL;
348}
Note: See TracBrowser for help on using the repository browser.