summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/i386/shared/irq/irq_init.c
blob: 73cdf2e8c16d9745e56be2334aa8b504fd2d6779 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* irq_init.c
 *
 *  This file contains the implementation of rtems initialization
 *  related to interrupt handling.
 *
 *  CopyRight (C) 1998 valette@crf.canon.fr
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id$
 */

#include <libcpu/cpu.h>
#include <irq.h>
#include <bsp.h>
#include <bspIo.h>

/*
 * rtems prologue generated in irq_asm.S
 */
extern void rtems_irq_prologue_0();
extern void rtems_irq_prologue_1();
extern void rtems_irq_prologue_2();
extern void rtems_irq_prologue_3();
extern void rtems_irq_prologue_4();
extern void rtems_irq_prologue_5();
extern void rtems_irq_prologue_6();
extern void rtems_irq_prologue_7();
extern void rtems_irq_prologue_8();
extern void rtems_irq_prologue_9();
extern void rtems_irq_prologue_10();
extern void rtems_irq_prologue_11();
extern void rtems_irq_prologue_12();
extern void rtems_irq_prologue_13();
extern void rtems_irq_prologue_14();
extern void rtems_irq_prologue_15();
/*
 * default idt vector
 */
extern void default_raw_idt_handler();
/*
 * default on/off function
 */
static void nop_func(){}
/*
 * default isOn function
 */
static int not_connected() {return 0;}


static rtems_raw_irq_connect_data 	idtHdl[IDT_SIZE];

/*
 * Table used to store rtems managed interrupt handlers.
 * Borrow the table to store raw handler entries at the beginning.
 * The table will be reinitialized before the call to BSP_rtems_irq_mngt_set().
 */
static rtems_irq_connect_data     	rtemsIrq[BSP_IRQ_LINES_NUMBER] = {
  {0,(rtems_irq_hdl)rtems_irq_prologue_0},
  {0,(rtems_irq_hdl)rtems_irq_prologue_1},
  {0,(rtems_irq_hdl)rtems_irq_prologue_2},
  {0,(rtems_irq_hdl)rtems_irq_prologue_3},
  {0,(rtems_irq_hdl)rtems_irq_prologue_4},
  {0,(rtems_irq_hdl)rtems_irq_prologue_5},
  {0,(rtems_irq_hdl)rtems_irq_prologue_6},
  {0,(rtems_irq_hdl)rtems_irq_prologue_7},
  {0,(rtems_irq_hdl)rtems_irq_prologue_8},
  {0,(rtems_irq_hdl)rtems_irq_prologue_9},
  {0,(rtems_irq_hdl)rtems_irq_prologue_10},
  {0,(rtems_irq_hdl)rtems_irq_prologue_11},
  {0,(rtems_irq_hdl)rtems_irq_prologue_12},
  {0,(rtems_irq_hdl)rtems_irq_prologue_13},
  {0,(rtems_irq_hdl)rtems_irq_prologue_14},
  {0,(rtems_irq_hdl)rtems_irq_prologue_15}
};

static rtems_raw_irq_connect_data 	defaultRawIrq = {
  /* vectorIdex,	 hdl			      , on	, off 		, isOn */
  0, 			default_raw_idt_handler ,nop_func	, nop_func,	not_connected
};

static rtems_irq_connect_data     	defaultIrq = {
  /* vectorIdex,	 hdl		, on		, off		, isOn */
  0, 			 nop_func	, nop_func	, nop_func	, not_connected
};

static rtems_irq_prio irqPrioTable[BSP_IRQ_LINES_NUMBER]={
  /*
   * actual rpiorities for interrupt :
   *	0   means that only current interrupt is masked
   *	255 means all other interrupts are masked
   * The second entry has a priority of 255 because
   * it is the slave pic entry and is should always remain
   * unamsked.
   */
  0,0,
  255,
  0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0
};
    

    
static interrupt_gate_descriptor	idtEntry;

static rtems_irq_global_settings     initial_config;
static rtems_raw_irq_global_settings raw_initial_config;

void raw_idt_notify()
{
  printk("raw_idt_notify has been called \n");
}

void  rtems_irq_mngt_init()
{
    int 			i;
    interrupt_gate_descriptor* 	idt_entry_tbl;
    unsigned int                limit;
    unsigned int 		level;

    i386_get_info_from_IDTR(&idt_entry_tbl, &limit);

    /* Convert into number of entries */
    limit = (limit + 1)/sizeof(interrupt_gate_descriptor);

    if(limit != IDT_SIZE) {
       printk("IDT table size mismatch !!! System locked\n");
       while(1);
    }
    

    _CPU_ISR_Disable(level);

    /*
     * Init the complete IDT vector table with defaultRawIrq value
     */
    for (i = 0; i < IDT_SIZE ; i++) {
      idtHdl[i] 	 = defaultRawIrq;
      idtHdl[i].idtIndex = i;
    }

    raw_initial_config.idtSize = IDT_SIZE;
    raw_initial_config.defaultRawEntry = defaultRawIrq;
    raw_initial_config.rawIrqHdlTbl = idtHdl;
    
    if (!i386_init_idt (&raw_initial_config)) {
      /*
       * put something here that will show the failure...
       */
      printk("Unable to initialize IDT!!! System locked\n");
      while (1);
    }
    /*
     * Patch the entry that will be used by RTEMS for interrupt management
     * with RTEMS prologue.
     */
    for (i = 0; i < BSP_IRQ_LINES_NUMBER; i++) {
      create_interrupt_gate_descriptor(&idtEntry,(rtems_raw_irq_hdl) rtemsIrq[i].hdl);
      idt_entry_tbl[i + BSP_ASM_IRQ_VECTOR_BASE] = idtEntry;
    }
    /*
     * At this point we have completed the initialization of IDT
     * with raw handlers.  We must now initialize the higher level
     * interrupt management.
     */
    /*
     * re-init the rtemsIrq table
     */
    for (i = 0; i < BSP_IRQ_LINES_NUMBER; i++) {
      rtemsIrq[i]      = defaultIrq;
      rtemsIrq[i].name = i;
    }
    /*
     * Init initial Interrupt management config
     */
    initial_config.irqNb 	= BSP_IRQ_LINES_NUMBER;
    initial_config.defaultEntry = defaultIrq;
    initial_config.irqHdlTbl	= rtemsIrq;
    initial_config.irqBase	= BSP_ASM_IRQ_VECTOR_BASE;
    initial_config.irqPrioTbl	= irqPrioTable;

    if (!BSP_rtems_irq_mngt_set(&initial_config)) {
      /*
       * put something here that will show the failure...
       */
      printk("Unable to initialize RTEMS interrupt Management!!! System locked\n");
      while (1);
    }

    /*
     * #define DEBUG    
     */
#ifdef DEBUG
    {
      /*
       * following adresses should be the same
       */
      unsigned tmp;

      printk("idt_entry_tbl =  %x Interrupt_descriptor_table addr = %x\n",
	     idt_entry_tbl, &Interrupt_descriptor_table);
      tmp = (unsigned) get_hdl_from_vector (BSP_ASM_IRQ_VECTOR_BASE + BSP_PERIODIC_TIMER);
      printk("clock isr address from idt = %x should be %x\n",
	     tmp, (unsigned) rtems_irq_prologue_0);
    }
    printk("i8259s_cache = %x\n", * (unsigned short*) &i8259s_cache);
    BSP_wait_polled_input();
#endif    
    asm volatile ("sti");
}