source: rtems/c/src/lib/libbsp/i386/shared/irq/irq_init.c @ 6b54dcb

Last change on this file since 6b54dcb was 6b54dcb, checked in by Pavel Pisa <pisa@…>, on Oct 12, 2016 at 7:40:41 AM

bsps/i386: replace global interrupt disable by SMP build supporting locking.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/* irq_init.c
2 *
3 *  This file contains the implementation of rtems initialization
4 *  related to interrupt handling.
5 *
6 *  Copyright (c) 2009 embedded brains GmbH
7 *  CopyRight (C) 1998 valette@crf.canon.fr
8 *
9 *  COPYRIGHT (c) 2011.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#include <rtems/bspIo.h>
18
19#include <rtems/score/cpu.h>
20
21#include <bsp.h>
22#include <bsp/irq.h>
23#include <bsp/irq-generic.h>
24
25/*
26 * rtems prologue generated in irq_asm.S
27 */
28extern void rtems_irq_prologue_0(void);
29extern void rtems_irq_prologue_1(void);
30extern void rtems_irq_prologue_2(void);
31extern void rtems_irq_prologue_3(void);
32extern void rtems_irq_prologue_4(void);
33extern void rtems_irq_prologue_5(void);
34extern void rtems_irq_prologue_6(void);
35extern void rtems_irq_prologue_7(void);
36extern void rtems_irq_prologue_8(void);
37extern void rtems_irq_prologue_9(void);
38extern void rtems_irq_prologue_10(void);
39extern void rtems_irq_prologue_11(void);
40extern void rtems_irq_prologue_12(void);
41extern void rtems_irq_prologue_13(void);
42extern void rtems_irq_prologue_14(void);
43extern void rtems_irq_prologue_15(void);
44extern void rtems_irq_prologue_16(void);
45/*
46 * default vectors
47 */
48extern void default_raw_idt_handler(void);
49
50/*
51 * default raw on/off function
52 */
53static void raw_nop_func(const struct __rtems_raw_irq_connect_data__ *unused)
54{
55}
56
57/*
58 * default raw isOn function
59 */
60static int raw_not_connected(
61  const struct __rtems_raw_irq_connect_data__ *unused
62)
63{
64  return 0;
65}
66
67static rtems_raw_irq_connect_data       idtHdl[IDT_SIZE];
68
69static rtems_raw_irq_hdl rtemsIrq[BSP_IRQ_VECTOR_NUMBER] = {
70  rtems_irq_prologue_0,
71  rtems_irq_prologue_1,
72  rtems_irq_prologue_2,
73  rtems_irq_prologue_3,
74  rtems_irq_prologue_4,
75  rtems_irq_prologue_5,
76  rtems_irq_prologue_6,
77  rtems_irq_prologue_7,
78  rtems_irq_prologue_8,
79  rtems_irq_prologue_9,
80  rtems_irq_prologue_10,
81  rtems_irq_prologue_11,
82  rtems_irq_prologue_12,
83  rtems_irq_prologue_13,
84  rtems_irq_prologue_14,
85  rtems_irq_prologue_15,
86  rtems_irq_prologue_16,
87};
88
89static rtems_raw_irq_connect_data       defaultRawIrq = {
90  0,                       /* vectorIdex */
91  default_raw_idt_handler, /* hdl */
92  raw_nop_func,            /* on */
93  raw_nop_func,            /* off */
94  raw_not_connected        /* isOn */
95};
96
97static interrupt_gate_descriptor        idtEntry;
98
99static rtems_raw_irq_global_settings raw_initial_config;
100
101
102/*
103 *  This method is called from irq_asm.S and cannot be static.
104 */
105void raw_idt_notify(void)
106{
107  printk("raw_idt_notify has been called \n");
108}
109
110void  rtems_irq_mngt_init(void)
111{
112    int                         i;
113    interrupt_gate_descriptor*  idt_entry_tbl;
114    unsigned int                limit;
115    rtems_interrupt_level       level;
116
117    i386_get_info_from_IDTR(&idt_entry_tbl, &limit);
118
119    /* Convert into number of entries */
120    limit = (limit + 1)/sizeof(interrupt_gate_descriptor);
121
122    if(limit != IDT_SIZE) {
123       printk("IDT table size mismatch !!! System locked\n");
124       while(1);
125    }
126
127    /*
128     * The interrupt management can be initialized only once
129     * during system bootup and that should happen on boot
130     * CPU so there is no need to synchronize with others CPUs.
131     */
132    rtems_interrupt_local_disable(level);
133
134    /*
135     * Init the complete IDT vector table with defaultRawIrq value
136     */
137    for (i = 0; i < IDT_SIZE ; i++) {
138      idtHdl[i]          = defaultRawIrq;
139      idtHdl[i].idtIndex = i;
140    }
141
142    raw_initial_config.idtSize = IDT_SIZE;
143    raw_initial_config.defaultRawEntry = defaultRawIrq;
144    raw_initial_config.rawIrqHdlTbl = idtHdl;
145
146    if (!i386_init_idt (&raw_initial_config)) {
147      /*
148       * put something here that will show the failure...
149       */
150      printk("Unable to initialize IDT!!! System locked\n");
151      while (1);
152    }
153    /*
154     * Patch the entry that will be used by RTEMS for interrupt management
155     * with RTEMS prologue.
156     */
157    for (i = 0; i < BSP_IRQ_VECTOR_NUMBER; i++) {
158      create_interrupt_gate_descriptor(&idtEntry, rtemsIrq[i]);
159      idt_entry_tbl[i + BSP_ASM_IRQ_VECTOR_BASE] = idtEntry;
160    }
161    /*
162     * At this point we have completed the initialization of IDT
163     * with raw handlers.  We must now initialize the higher level
164     * interrupt management.
165     */
166
167    /*
168     * Init initial Interrupt management config
169     */
170    bsp_interrupt_initialize();
171
172    /*
173     * #define DEBUG
174     */
175#ifdef DEBUG
176    {
177      /*
178       * following adresses should be the same
179       */
180      unsigned tmp;
181
182      printk("idt_entry_tbl =  %x Interrupt_descriptor_table addr = %x\n",
183             idt_entry_tbl, &Interrupt_descriptor_table);
184      tmp = (unsigned) get_hdl_from_vector (BSP_ASM_IRQ_VECTOR_BASE + BSP_PERIODIC_TIMER);
185      printk("clock isr address from idt = %x should be %x\n",
186             tmp, (unsigned) rtems_irq_prologue_0);
187    }
188    printk("i8259s_cache = %x\n", * (unsigned short*) &i8259s_cache);
189    BSP_wait_polled_input();
190#endif
191}
Note: See TracBrowser for help on using the repository browser.