source: rtems/c/src/lib/libcpu/powerpc/ppc403/ictrl/ictrl.c @ 458bd34

4.104.114.84.95
Last change on this file since 458bd34 was 458bd34, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 5, 1999 at 4:44:02 PM

This is another pass at making sure that nothing outside the BSP
unnecessarily uses any variables defined by the BSP. On this
sweep, use of BSP_Configuration and Cpu_table was eliminated.

A significant part of this modification was the addition of
macros to access fields in the RTEMS configuration structures.

This is necessary to strengthen the division between the BSP independent
parts of RTEMS and the BSPs themselves. This started after
comments and analysis by Ralf Corsepius <corsepiu@…>.

  • Property mode set to 100644
File size: 5.6 KB
Line 
1/*  ictrl.c
2 *
3 *  This routine installs and handles external interrupt vectors for
4 *  PowerPC 403 CPU built-in external interrupt controller
5 *
6 *  Author: Thomas Doerfler <td@imd.m.isar.de>
7 *
8 *  COPYRIGHT (c) 1998 by IMD, Puchheim, Germany
9 *
10 *  To anyone who acknowledges that this file is provided "AS IS"
11 *  without any express or implied warranty:
12 *      permission to use, copy, modify, and distribute this file
13 *      for any purpose is hereby granted without fee, provided that
14 *      the above copyright notice and this notice appears in all
15 *      copies, and that the name of IMD not be used in
16 *      advertising or publicity pertaining to distribution of the
17 *      software without specific, written prior permission.
18 *      IMD makes no representations about the suitability
19 *      of this software for any purpose.
20 *
21 */
22
23#include "ictrl.h"
24#include <rtems.h>
25#include <rtems/libio.h>
26
27#include <stdlib.h>                     /* for atexit() */
28
29/*
30 *  ISR vector table to dispatch external interrupts
31 */
32 
33rtems_isr_entry ictrl_vector_table[PPC_IRQ_EXT_MAX];
34
35/*
36 *
37 *  some utilities to access the EXI* registers
38 *
39 */
40
41/*
42 *  clear bits in EXISR that have a bit set in mask
43 */
44RTEMS_INLINE_ROUTINE void 
45clr_exisr(unsigned32 mask) 
46{
47    asm volatile ("mtdcr 0x40,%0"::"r" (mask));/*EXISR*/
48} 
49
50/*
51 *  get value of EXISR
52 */
53RTEMS_INLINE_ROUTINE unsigned32
54get_exisr(void) 
55{
56    unsigned32 val;
57
58    asm volatile ("mfdcr %0,0x40":"=r" (val));/*EXISR*/
59    return val; 
60} 
61
62/*
63 *  get value of EXIER
64 */
65RTEMS_INLINE_ROUTINE unsigned32
66get_exier(void) 
67{
68    unsigned32 val;
69    asm volatile ("mfdcr %0,0x42":"=r" (val));/*EXIER*/
70    return val; 
71} 
72
73/*
74 *  set value of EXIER
75 */
76RTEMS_INLINE_ROUTINE void 
77set_exier(unsigned32 val) 
78{
79    asm volatile ("mtdcr 0x42,%0"::"r" (val));/*EXIER*/
80} 
81
82/*
83 *  enable an external interrupt, make this interrupt consistent
84 */
85RTEMS_INLINE_ROUTINE void 
86enable_ext_irq( unsigned32 mask)
87{
88    unsigned32 isrlvl;
89    _CPU_ISR_Disable(isrlvl);
90    set_exier(get_exier() | ((mask)&PPC_EXI_MASK));
91    _CPU_ISR_Enable(isrlvl);
92}
93
94/*
95 *  disable an external interrupt, make this interrupt consistent
96 */
97RTEMS_INLINE_ROUTINE void 
98disable_ext_irq( unsigned32 mask)
99{
100    unsigned32 isrlvl;
101    _CPU_ISR_Disable(isrlvl);
102    set_exier(get_exier() & ~(mask) & PPC_EXI_MASK);
103    _CPU_ISR_Enable(isrlvl);
104}
105
106/*
107 *
108 *  this function is called, when a external interrupt is present and
109 *  enabled but there is no handler installed. It will clear
110 *  the corresponding enable bits and call the spurious handler
111 *  present in the CPU Configuration Table, if any.
112 *
113 */
114void 
115ictrl_spurious_handler(unsigned32 spurious_mask, 
116                       CPU_Interrupt_frame *cpu_frame)
117{
118  int v;
119 
120  for (v=0; v < PPC_IRQ_EXT_MAX; v++) {
121    if (VEC_TO_EXMSK(v) & spurious_mask) {
122      clr_exisr(VEC_TO_EXMSK(v));
123      disable_ext_irq(VEC_TO_EXMSK(v));
124#if 0
125      printf("spurious external interrupt: %d at pc 0x%x; disabling\n",
126             vector, cpu_frame->Interrupt.pcoqfront);
127#endif
128      if (rtems_cpu_configuration_get_spurious_handler()) {
129        rtems_cpu_configuration_get_spurious_handler()(v + PPC_IRQ_EXT_BASE,cpu_frame);
130      }
131    }
132  }
133}
134
135
136/*
137 *  ISR Handler: this is called from the primary exception dispatcher
138 */
139 
140void
141ictrl_isr(rtems_vector_number vector,CPU_Interrupt_frame *cpu_frame)
142{
143  unsigned32        istat,
144                    mask,
145                    global_vec;
146  int               exvec;
147  rtems_isr_entry handler;
148
149  istat = get_exisr() & get_exier() & PPC_EXI_MASK;
150
151  /* FIXME: this may be speeded up using cntlzw instruction */
152  for (exvec = 0;exvec < PPC_IRQ_EXT_MAX;exvec++) {
153    mask = VEC_TO_EXMSK(exvec);
154    if (0 != (istat & mask)) {
155      clr_exisr(mask);
156      handler = ictrl_vector_table[exvec];
157      if (handler) {
158        istat &= ~mask;
159        global_vec = exvec + PPC_IRQ_EXT_BASE;
160        (handler)(global_vec);
161      }
162    }
163  }
164  if (istat != 0) { /* anything left? then we have a spurious interrupt */
165    ictrl_spurious_handler(istat,cpu_frame);
166  }
167}
168
169/*
170 *
171 * the following functions form the user interface
172 *
173 */
174
175/*
176 *
177 * install a user vector for one of the external interrupt sources
178 *
179 */ 
180rtems_status_code
181ictrl_set_vector(rtems_isr_entry   new_handler,
182                 unsigned32        vector,
183                 rtems_isr_entry   *old_handler
184)
185{
186  /*
187   *  We put the actual user ISR address in 'ictrl_vector_table'.  This will
188   *  be used by the _ictrl_isr so the user gets control.
189   */
190
191  /* check for valid vector range */
192  if ((vector >= PPC_IRQ_EXT_BASE) &&
193      (vector <  PPC_IRQ_EXT_BASE + PPC_IRQ_EXT_MAX)) {
194
195    /* return old handler entry */
196    *old_handler = ictrl_vector_table[vector - PPC_IRQ_EXT_BASE];
197
198    if (new_handler != NULL) {
199      /* store handler function... */
200      ictrl_vector_table[vector - PPC_IRQ_EXT_BASE] = new_handler;
201      /* then enable it in EXIER register */
202      enable_ext_irq(VEC_TO_EXMSK(vector - PPC_IRQ_EXT_BASE));
203    }
204    else { /* new_handler == NULL */
205      /* then disable it in EXIER register */
206      disable_ext_irq(VEC_TO_EXMSK(vector - PPC_IRQ_EXT_BASE));
207      ictrl_vector_table[vector - PPC_IRQ_EXT_BASE] = NULL;
208    }
209    return RTEMS_SUCCESSFUL;
210  }
211  else {
212    return RTEMS_INVALID_NUMBER;
213  }
214}
215
216/*
217 * Called via atexit()
218 * deactivate the interrupt controller
219 */
220
221void
222ictrl_exit(void)
223{
224  /* mark them all unused */
225  disable_ext_irq(~0);
226  clr_exisr(~0);
227 
228}
229
230/*
231 * activate the interrupt controller
232 */
233
234rtems_status_code
235ictrl_init(void)
236{
237  proc_ptr dummy;
238
239  /* mark them all unused */
240  disable_ext_irq(~0);
241  clr_exisr(~0);
242 
243  /* install the external interrupt handler */
244  _CPU_ISR_install_vector(PPC_IRQ_EXTERNAL,
245                          ictrl_isr,
246                          &dummy);
247  atexit(ictrl_exit);
248  return RTEMS_SUCCESSFUL;
249}
250
Note: See TracBrowser for help on using the repository browser.