1 | /* genpvec.c |
---|
2 | * |
---|
3 | * These routines handle the external exception. Multiple ISRs occur off |
---|
4 | * of this one interrupt. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-1997. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may in |
---|
10 | * the file LICENSE in this distribution or at |
---|
11 | * http://www.rtems.com/license/LICENSE. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <bsp.h> |
---|
17 | #include <rtems/chain.h> |
---|
18 | #include <rtems/bspIo.h> |
---|
19 | #include <assert.h> |
---|
20 | |
---|
21 | #include <stdio.h> /* for sprintf */ |
---|
22 | |
---|
23 | /* |
---|
24 | * Proto types for this file |
---|
25 | */ |
---|
26 | |
---|
27 | rtems_isr external_exception_ISR ( |
---|
28 | rtems_vector_number vector /* IN */ |
---|
29 | ); |
---|
30 | |
---|
31 | #define NUM_LIRQ_HANDLERS 20 |
---|
32 | #define NUM_LIRQ ( MAX_BOARD_IRQS - PPC_IRQ_LAST ) |
---|
33 | |
---|
34 | /* |
---|
35 | * Structure to for one of possible multiple interrupt handlers for |
---|
36 | * a given interrupt. |
---|
37 | */ |
---|
38 | typedef struct |
---|
39 | { |
---|
40 | rtems_chain_node Node; |
---|
41 | rtems_isr_entry handler; /* isr routine */ |
---|
42 | rtems_vector_number vector; /* vector number */ |
---|
43 | } EE_ISR_Type; |
---|
44 | |
---|
45 | /* Note: The following will not work if we add a method to remove |
---|
46 | * handlers at a later time. |
---|
47 | */ |
---|
48 | EE_ISR_Type ISR_Nodes [NUM_LIRQ_HANDLERS]; |
---|
49 | uint16_t Nodes_Used; |
---|
50 | rtems_chain_control ISR_Array [NUM_LIRQ]; |
---|
51 | |
---|
52 | /* XXX */ |
---|
53 | void init_irq_data_register(void); |
---|
54 | |
---|
55 | void initialize_external_exception_vector (void) |
---|
56 | { |
---|
57 | int i; |
---|
58 | rtems_isr_entry previous_isr; |
---|
59 | rtems_status_code status; |
---|
60 | |
---|
61 | Nodes_Used = 0; |
---|
62 | |
---|
63 | /* |
---|
64 | * Mask out all interupts until they have a handler installed. |
---|
65 | */ |
---|
66 | |
---|
67 | for (i=0; i <NUM_LIRQ; i++) |
---|
68 | rtems_chain_initialize_empty( &ISR_Array[i] ); |
---|
69 | |
---|
70 | init_irq_data_register(); |
---|
71 | |
---|
72 | /* |
---|
73 | * Install external_exception_ISR () as the handler for |
---|
74 | * the General Purpose Interrupt. |
---|
75 | */ |
---|
76 | status = rtems_interrupt_catch( external_exception_ISR, |
---|
77 | PPC_IRQ_EXTERNAL, (rtems_isr_entry *) &previous_isr ); |
---|
78 | } |
---|
79 | |
---|
80 | void Init_EE_mask_init() { |
---|
81 | ; |
---|
82 | } |
---|
83 | |
---|
84 | /* |
---|
85 | * This routine installs one of multiple ISRs for the general purpose |
---|
86 | * inerrupt. |
---|
87 | */ |
---|
88 | rtems_isr_entry set_EE_vector( |
---|
89 | rtems_isr_entry handler, /* isr routine */ |
---|
90 | rtems_vector_number vector /* vector number */ |
---|
91 | ) |
---|
92 | { |
---|
93 | uint16_t vec_idx = vector - Score_IRQ_First; |
---|
94 | uint32_t index; |
---|
95 | |
---|
96 | assert (Nodes_Used < NUM_LIRQ_HANDLERS); |
---|
97 | |
---|
98 | /* |
---|
99 | * If we have already installed this handler for this vector, then |
---|
100 | * just reset it. |
---|
101 | */ |
---|
102 | |
---|
103 | for ( index=0 ; index <= Nodes_Used ; index++ ) { |
---|
104 | if ( ISR_Nodes[index].vector == vector && |
---|
105 | ISR_Nodes[index].handler == handler ) |
---|
106 | return NULL; |
---|
107 | } |
---|
108 | |
---|
109 | /* |
---|
110 | * Doing things in this order makes them more atomic |
---|
111 | */ |
---|
112 | |
---|
113 | Nodes_Used++; |
---|
114 | |
---|
115 | index = Nodes_Used - 1; |
---|
116 | |
---|
117 | ISR_Nodes[index].handler = handler; |
---|
118 | ISR_Nodes[index].vector = vector; |
---|
119 | |
---|
120 | /* printf( "Vector Index: %04x, Vector: %d (%x)\n", |
---|
121 | vec_idx, vector, vector); */ |
---|
122 | |
---|
123 | rtems_chain_append( &ISR_Array[vec_idx], &ISR_Nodes[index].Node ); |
---|
124 | |
---|
125 | /* |
---|
126 | * Unmask the interrupt. |
---|
127 | */ |
---|
128 | unmask_irq( vec_idx ); |
---|
129 | |
---|
130 | return NULL; |
---|
131 | } |
---|
132 | |
---|
133 | /* |
---|
134 | * This interrupt service routine is called for an External Exception. |
---|
135 | */ |
---|
136 | rtems_isr external_exception_ISR ( |
---|
137 | rtems_vector_number vector /* IN */ |
---|
138 | ) |
---|
139 | { |
---|
140 | uint16_t index; |
---|
141 | EE_ISR_Type *node; |
---|
142 | uint16_t value; |
---|
143 | #if (HAS_PMC_PSC8) |
---|
144 | uint16_t PMC_irq; |
---|
145 | uint16_t check_irq; |
---|
146 | uint16_t status_word; |
---|
147 | #endif |
---|
148 | |
---|
149 | index = read_and_clear_irq(); |
---|
150 | if ( index >= NUM_LIRQ ) { |
---|
151 | printk( "ERROR:: Invalid interrupt number (%02x)\n", index ); |
---|
152 | return; |
---|
153 | } |
---|
154 | |
---|
155 | #if (HAS_PMC_PSC8) |
---|
156 | PMC_irq = SCORE603E_PCI_IRQ_0 - SCORE603E_IRQ00; |
---|
157 | |
---|
158 | if (index == PMC_irq) { |
---|
159 | status_word = read_and_clear_PMC_irq( index ); |
---|
160 | |
---|
161 | for (check_irq=SCORE603E_IRQ16; check_irq<=SCORE603E_IRQ19; check_irq++) { |
---|
162 | if ( Is_PMC_IRQ( check_irq, status_word )) { |
---|
163 | index = check_irq - SCORE603E_IRQ00; |
---|
164 | node = (EE_ISR_Type *)(ISR_Array[ index ].first); |
---|
165 | |
---|
166 | if ( rtems_chain_is_tail( &ISR_Array[ index ], (void *)node ) ) { |
---|
167 | printk"ERROR:: check %d interrupt %02d has no isr\n", check_irq, index); |
---|
168 | value = get_irq_mask(); |
---|
169 | printk(" Mask = %02x\n", value); |
---|
170 | } |
---|
171 | while ( !rtems_chain_is_tail( &ISR_Array[ index ], (void *)node ) ) { |
---|
172 | (*node->handler)( node->vector ); |
---|
173 | node = (EE_ISR_Type *) node->Node.next; |
---|
174 | } |
---|
175 | } |
---|
176 | } |
---|
177 | } |
---|
178 | else |
---|
179 | #endif |
---|
180 | { |
---|
181 | node = (EE_ISR_Type *)(ISR_Array[ index ].first); |
---|
182 | if ( rtems_chain_is_tail( &ISR_Array[ index ], (void *)node ) ) { |
---|
183 | printk( "ERROR:: interrupt %02x has no isr\n", index); |
---|
184 | value = get_irq_mask(); |
---|
185 | printk(" Mask = %02x\n", value); |
---|
186 | return; |
---|
187 | } |
---|
188 | while ( !rtems_chain_is_tail( &ISR_Array[ index ], (void *)node ) ) { |
---|
189 | (*node->handler)( node->vector ); |
---|
190 | node = (EE_ISR_Type *) node->Node.next; |
---|
191 | } |
---|
192 | } |
---|
193 | |
---|
194 | } |
---|