source: rtems/c/src/lib/libbsp/powerpc/ep1a/irq/openpic_xxx_irq.c @ fb557a9

4.9
Last change on this file since fb557a9 was fb557a9, checked in by Joel Sherrill <joel.sherrill@…>, on 10/16/09 at 16:42:03

2009-10-16 Jennifer Averett <jennifer@…>

  • Makefile.am, configure.ac, preinstall.am, console/alloc360.c, console/config.c, console/console.c, console/m68360.h, console/mc68360_scc.c, console/rsPMCQ1.c, console/rsPMCQ1.h, include/bsp.h, irq/irq_init.c, irq/openpic_xxx_irq.c, start/start.S, startup/bspstart.c, startup/linkcmds, vme/VMEConfig.h: Updated and tested against RTEMS 4.9. Updated README file to latest source status. Modified to use the shared irq source code. Turned off debugging, cleaned up warnings, removed unused code. Tested with two PMCQ1 serial cards. Tested MC68360 serial ports and VME using external tests.
  • README, irq/irq.h, vme/vmeconfig.c: New files.
  • Property mode set to 100644
File size: 7.0 KB
Line 
1/*
2 *
3 *  This file contains the i8259/openpic-specific implementation of the function described in irq.h
4 *
5 *  Copyright (C) 1998, 1999 valette@crf.canon.fr
6 *
7 *  The license and distribution terms for this file may be
8 *  found in found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#include <stdlib.h>
15
16#include <bsp.h>
17#include <bsp/irq.h>
18#include <bsp/irq_supp.h>
19#include <bsp/VMEConfig.h>
20#include <bsp/openpic.h>
21#include <libcpu/raw_exception.h>
22#include <libcpu/io.h>
23#include <bsp/vectors.h>
24#include <stdlib.h>
25
26#include <rtems/bspIo.h>
27#define RAVEN_INTR_ACK_REG 0xfeff0030
28
29#ifdef BSP_PCI_ISA_BRIDGE_IRQ
30/*
31 * pointer to the mask representing the additionnal irq vectors
32 * that must be disabled when a particular entry is activated.
33 * They will be dynamically computed from the priority table given
34 * in BSP_rtems_irq_mngt_set();
35 * CAUTION : this table is accessed directly by interrupt routine
36 *           prologue.
37 */
38rtems_i8259_masks       irq_mask_or_tbl[BSP_IRQ_NUMBER];
39#endif
40
41/*
42 * default handler connected on each irq after bsp initialization
43 */
44static rtems_irq_connect_data      default_rtems_entry;
45static rtems_irq_connect_data*     rtems_hdl_tbl;
46
47/*
48 * Check if IRQ is an ISA IRQ
49 */
50static inline int is_isa_irq(const rtems_irq_number irqLine)
51{
52  if  ( BSP_ISA_IRQ_NUMBER == 0 )
53    return FALSE;
54
55  return (((int) irqLine <= BSP_ISA_IRQ_MAX_OFFSET) &&
56          ((int) irqLine >= BSP_ISA_IRQ_LOWEST_OFFSET)
57         );
58}
59
60/*
61 * Check if IRQ is an OPENPIC IRQ
62 */
63static inline int is_pci_irq(const rtems_irq_number irqLine)
64{
65  if ( BSP_PCI_IRQ_NUMBER == 0 )
66    return FALSE;
67
68  return (((int) irqLine <= BSP_PCI_IRQ_MAX_OFFSET) &&
69          ((int) irqLine >= BSP_PCI_IRQ_LOWEST_OFFSET)
70         );
71}
72
73/*
74 * ------------------------ RTEMS Irq helper functions ----------------
75 */
76
77#ifdef BSP_PCI_ISA_BRIDGE_IRQ
78/*
79 * Caution : this function assumes the variable "*config"
80 * is already set and that the tables it contains are still valid
81 * and accessible.
82 */
83static void compute_i8259_masks_from_prio (rtems_irq_global_settings* config)
84{
85  int i;
86  int j;
87  /*
88   * Always mask at least current interrupt to prevent re-entrance
89   */
90  for (i=BSP_ISA_IRQ_LOWEST_OFFSET; i < BSP_ISA_IRQ_LOWEST_OFFSET + BSP_ISA_IRQ_NUMBER; i++) {
91    * ((unsigned short*) &irq_mask_or_tbl[i]) = (1 << i);
92    for (j = BSP_ISA_IRQ_LOWEST_OFFSET; j < BSP_ISA_IRQ_LOWEST_OFFSET + BSP_ISA_IRQ_NUMBER; j++) {
93      /*
94       * Mask interrupts at i8259 level that have a lower priority
95       */
96      if (config->irqPrioTbl [i] > config->irqPrioTbl [j]) {
97        * ((unsigned short*) &irq_mask_or_tbl[i]) |= (1 << j);
98      }
99    }
100  }
101}
102#endif
103
104void BSP_enable_irq_at_pic(const rtems_irq_number name)
105{
106  if (is_isa_irq(name)) {
107    printk("BSP_enable_irq_at_pic: called with isa irq\n");
108  }
109  if (is_pci_irq(name)) {
110    /*
111     * enable interrupt at OPENPIC level.
112     */
113    openpic_enable_irq ( ((int)name - BSP_PCI_IRQ_LOWEST_OFFSET) + 16 ); 
114  }
115}
116
117int BSP_disable_irq_at_pic(const rtems_irq_number name)
118{
119    if (is_isa_irq(name)) {
120      /*
121       * disable interrupt at PIC level
122       */
123      printk("BSP_disable_irq_at_pic: called with isa irq\n");
124    }
125    if (is_pci_irq(name)) {
126      /*
127       * disable interrupt at OPENPIC level
128       */
129      return openpic_disable_irq (((int) name - BSP_PCI_IRQ_LOWEST_OFFSET) + 16  );
130    }
131    return -1;
132}
133
134/*
135 * RTEMS Global Interrupt Handler Management Routines
136 */
137int BSP_setup_the_pic(rtems_irq_global_settings* config)
138{
139    int i;
140
141   /*
142    * Store various code accelerators
143    */
144    default_rtems_entry = config->defaultEntry;
145    rtems_hdl_tbl       = config->irqHdlTbl;
146   
147    /*
148     * set up internal tables used by rtems interrupt prologue
149     */
150#ifdef BSP_PCI_ISA_BRIDGE_IRQ
151    /*
152     * start with ISA IRQ
153     */
154    compute_i8259_masks_from_prio (config);
155
156    for (i=BSP_ISA_IRQ_LOWEST_OFFSET; (i < (BSP_ISA_IRQ_LOWEST_OFFSET + BSP_ISA_IRQ_NUMBER)); i++) {
157      if (rtems_hdl_tbl[i].hdl != default_rtems_entry.hdl) {
158         BSP_irq_enable_at_i8259s (i);
159      }
160      else {
161         BSP_irq_disable_at_i8259s (i);
162      }
163    }
164
165        if ( BSP_ISA_IRQ_NUMBER > 0 ) {
166        /*
167                 * must enable slave pic anyway
168                 */
169                BSP_irq_enable_at_i8259s (2);
170        }
171#endif
172
173    /*
174     * continue with PCI IRQ
175     */
176    for (i=BSP_PCI_IRQ_LOWEST_OFFSET; i < BSP_PCI_IRQ_LOWEST_OFFSET + BSP_PCI_IRQ_NUMBER ; i++) {
177      /*
178       * Note that openpic_set_priority() sets the TASK priority of the PIC
179       */
180      openpic_set_source_priority(i - BSP_PCI_IRQ_LOWEST_OFFSET,
181                                  config->irqPrioTbl[i]);
182      if (rtems_hdl_tbl[i].hdl != default_rtems_entry.hdl) {
183         openpic_enable_irq ((int) i - BSP_PCI_IRQ_LOWEST_OFFSET);
184      }
185      else {
186         openpic_disable_irq ((int) i - BSP_PCI_IRQ_LOWEST_OFFSET);
187      }
188    }
189
190#ifdef BSP_PCI_ISA_BRIDGE_IRQ
191        if ( BSP_ISA_IRQ_NUMBER > 0 ) {
192          /*
193           * Must enable PCI/ISA bridge IRQ
194           */
195          openpic_enable_irq (0);
196        }
197#endif
198   
199    return 1;
200}
201
202int _BSP_vme_bridge_irq = -1;
203unsigned BSP_spuriousIntr = 0;
204
205/*
206 * High level IRQ handler called from shared_raw_irq_code_entry
207 */
208int C_dispatch_irq_handler (BSP_Exception_frame *frame, unsigned int excNum)
209{
210  register unsigned int irq;
211#ifdef BSP_PCI_ISA_BRIDGE_IRQ
212  register unsigned isaIntr;                  /* boolean */
213  register unsigned oldMask = 0;              /* old isa pic masks */
214  register unsigned newMask;                  /* new isa pic masks */
215#endif
216  if (excNum == ASM_DEC_VECTOR) {
217    bsp_irq_dispatch_list_base(rtems_hdl_tbl, BSP_DECREMENTER, default_rtems_entry.hdl);
218    return 0;
219
220  }
221  irq = openpic_irq(0);
222  if (irq == OPENPIC_VEC_SPURIOUS) {
223    printk("OPENPIC_VEC_SPURIOUS interrupt %d\n", OPENPIC_VEC_SPURIOUS );
224    ++BSP_spuriousIntr;
225    return 0;
226  }
227
228  /* some BSPs might want to use a different numbering... */
229  irq = irq - OPENPIC_VEC_SOURCE ;
230
231#ifdef BSP_PCI_ISA_BRIDGE_IRQ
232  isaIntr = (irq == BSP_PCI_ISA_BRIDGE_IRQ);
233  if (isaIntr)  {
234    /*
235     * Acknowledge and read 8259 vector
236     */
237    irq = (unsigned int) (*(unsigned char *) RAVEN_INTR_ACK_REG);
238    /*
239     * store current PIC mask
240     */
241    oldMask = i8259s_cache;
242    newMask = oldMask | irq_mask_or_tbl [irq];
243    i8259s_cache = newMask;
244    outport_byte(PIC_MASTER_IMR_IO_PORT, i8259s_cache & 0xff);
245    outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8));
246    BSP_irq_ack_at_i8259s (irq);
247    openpic_eoi(0);
248  }
249#endif
250
251  /* dispatch handlers */
252  bsp_irq_dispatch_list_base(rtems_hdl_tbl, irq, default_rtems_entry.hdl);
253
254#ifdef BSP_PCI_ISA_BRIDGE_IRQ
255  if (isaIntr)  {
256    i8259s_cache = oldMask;
257    outport_byte(PIC_MASTER_IMR_IO_PORT, i8259s_cache & 0xff);
258    outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8));
259  }
260  else
261#endif
262
263  {
264#ifdef BSP_PCI_VME_DRIVER_DOES_EOI
265    /* leave it to the VME bridge driver to do EOI, so
266     * it can re-enable the openpic while handling
267     * VME interrupts (-> VME priorities in software)
268     */
269    if (_BSP_vme_bridge_irq != irq)
270#endif
271      openpic_eoi(0);
272  }
273  return 0;
274
275}
Note: See TracBrowser for help on using the repository browser.