source: rtems/c/src/lib/libbsp/powerpc/shared/irq/openpic_i8259_irq.c @ a9e62c2

4.104.114.95
Last change on this file since a9e62c2 was a9e62c2, checked in by Till Straumann <strauman@…>, on 12/08/07 at 17:26:19

2007-12-08 Till Straumann <strauman@…>

  • ep1a/irq/irq.c, gen5200/irq/irq.c, gen83xx/irq/irq_init.c, mbx8xx/irq/irq.c, mpc8260ads/irq/irq.c, mvme5500/irq/irq.c, psim/irq/no_pic.c, score603e/irq/irq.c, shared/irq/irq_supp.h, shared/irq/openpic_i8259_irq.c, virtex/irq/irq_init.c: let C_dispatch_irq_handler() return zero to indicate to low-level exception handling code that the exception was handled (not used yet).
  • 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> /* for printk */
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;
45
46static rtems_irq_connect_data*          rtems_hdl_tbl;
47
48#ifdef BSP_PCI_ISA_BRIDGE_IRQ
49/*
50 * Check if IRQ is an ISA IRQ
51 */
52static inline int is_isa_irq(const rtems_irq_number irqLine)
53{
54  return (((int) irqLine <= BSP_ISA_IRQ_MAX_OFFSET) &
55          ((int) irqLine >= BSP_ISA_IRQ_LOWEST_OFFSET)
56         );
57}
58#endif
59
60/*
61 * Check if IRQ is an OPENPIC IRQ
62 */
63static inline int is_pci_irq(const rtems_irq_number irqLine)
64{
65  return (((int) irqLine <= BSP_PCI_IRQ_MAX_OFFSET) &
66          ((int) irqLine >= BSP_PCI_IRQ_LOWEST_OFFSET)
67         );
68}
69
70/*
71 * ------------------------ RTEMS Irq helper functions ----------------
72 */
73
74#ifdef BSP_PCI_ISA_BRIDGE_IRQ
75/*
76 * Caution : this function assumes the variable "*config"
77 * is already set and that the tables it contains are still valid
78 * and accessible.
79 */
80static void compute_i8259_masks_from_prio (rtems_irq_global_settings* config)
81{
82  int i;
83  int j;
84  /*
85   * Always mask at least current interrupt to prevent re-entrance
86   */
87  for (i=BSP_ISA_IRQ_LOWEST_OFFSET; i < BSP_ISA_IRQ_LOWEST_OFFSET + BSP_ISA_IRQ_NUMBER; i++) {
88    * ((unsigned short*) &irq_mask_or_tbl[i]) = (1 << i);
89    for (j = BSP_ISA_IRQ_LOWEST_OFFSET; j < BSP_ISA_IRQ_LOWEST_OFFSET + BSP_ISA_IRQ_NUMBER; j++) {
90      /*
91       * Mask interrupts at i8259 level that have a lower priority
92       */
93      if (config->irqPrioTbl [i] > config->irqPrioTbl [j]) {
94        * ((unsigned short*) &irq_mask_or_tbl[i]) |= (1 << j);
95      }
96    }
97  }
98}
99#endif
100
101void
102BSP_enable_irq_at_pic(const rtems_irq_number name)
103{
104#ifdef BSP_PCI_ISA_BRIDGE_IRQ
105    if (is_isa_irq(name)) {
106      /*
107       * Enable interrupt at PIC level
108       */
109      BSP_irq_enable_at_i8259s ((int) name - BSP_ISA_IRQ_LOWEST_OFFSET);
110    }
111#endif
112   
113    if (is_pci_irq(name)) {
114      /*
115       * Enable interrupt at OPENPIC level
116       */
117      openpic_enable_irq ((int) name - BSP_PCI_IRQ_LOWEST_OFFSET);
118    }
119}
120
121int
122BSP_disable_irq_at_pic(const rtems_irq_number name)
123{
124#ifdef BSP_PCI_ISA_BRIDGE_IRQ
125    if (is_isa_irq(name)) {
126      /*
127       * disable interrupt at PIC level
128       */
129      return BSP_irq_disable_at_i8259s ((int) name - BSP_ISA_IRQ_LOWEST_OFFSET);
130    }
131#endif
132    if (is_pci_irq(name)) {
133      /*
134       * disable interrupt at OPENPIC level
135       */
136      return openpic_disable_irq ((int) name - BSP_PCI_IRQ_LOWEST_OFFSET);
137    }
138        return -1;
139}
140
141/*
142 * RTEMS Global Interrupt Handler Management Routines
143 */
144int BSP_setup_the_pic(rtems_irq_global_settings* config)
145{
146    int i;
147   /*
148    * Store various code accelerators
149    */
150    default_rtems_entry = config->defaultEntry;
151    rtems_hdl_tbl               = config->irqHdlTbl;
152
153    /*
154     * set up internal tables used by rtems interrupt prologue
155     */
156
157#ifdef BSP_PCI_ISA_BRIDGE_IRQ
158    /*
159     * start with ISA IRQ
160     */
161    compute_i8259_masks_from_prio (config);
162
163    for (i=BSP_ISA_IRQ_LOWEST_OFFSET; i < BSP_ISA_IRQ_LOWEST_OFFSET + BSP_ISA_IRQ_NUMBER; i++) {
164      if (rtems_hdl_tbl[i].hdl != default_rtems_entry.hdl) {
165         BSP_irq_enable_at_i8259s (i);
166      }
167      else {
168         BSP_irq_disable_at_i8259s (i);
169      }
170    }
171
172        if ( BSP_ISA_IRQ_NUMBER > 0 ) {
173        /*
174                 * must enable slave pic anyway
175                 */
176                BSP_irq_enable_at_i8259s (2);
177        }
178#endif
179
180    /*
181     * continue with PCI IRQ
182     */
183    for (i=BSP_PCI_IRQ_LOWEST_OFFSET; i < BSP_PCI_IRQ_LOWEST_OFFSET + BSP_PCI_IRQ_NUMBER ; i++) {
184      /*
185       * Note that openpic_set_priority() sets the TASK priority of the PIC
186       */
187      openpic_set_source_priority(i - BSP_PCI_IRQ_LOWEST_OFFSET,
188                                  config->irqPrioTbl[i]);
189      if (rtems_hdl_tbl[i].hdl != default_rtems_entry.hdl) {
190         openpic_enable_irq ((int) i - BSP_PCI_IRQ_LOWEST_OFFSET);
191      }
192      else {
193         openpic_disable_irq ((int) i - BSP_PCI_IRQ_LOWEST_OFFSET);
194      }
195    }
196
197#ifdef BSP_PCI_ISA_BRIDGE_IRQ
198        if ( BSP_ISA_IRQ_NUMBER > 0 ) {
199        /*
200             * Must enable PCI/ISA bridge IRQ
201             */
202        openpic_enable_irq (0);
203        }
204#endif
205
206    return 1;
207}
208
209int _BSP_vme_bridge_irq = -1;
210
211unsigned BSP_spuriousIntr = 0;
212
213/*
214 * High level IRQ handler called from shared_raw_irq_code_entry
215 */
216int C_dispatch_irq_handler (BSP_Exception_frame *frame, unsigned int excNum)
217{
218  register unsigned int irq;
219#ifdef BSP_PCI_ISA_BRIDGE_IRQ
220  register unsigned isaIntr;                  /* boolean */
221  register unsigned oldMask = 0;              /* old isa pic masks */
222  register unsigned newMask;                  /* new isa pic masks */
223#endif
224
225  if (excNum == ASM_DEC_VECTOR) {
226
227        bsp_irq_dispatch_list(rtems_hdl_tbl, BSP_DECREMENTER, default_rtems_entry.hdl);
228
229    return 0;
230
231  }
232  irq = openpic_irq(0);
233  if (irq == OPENPIC_VEC_SPURIOUS) {
234    ++BSP_spuriousIntr;
235    return 0;
236  }
237
238  /* some BSPs might want to use a different numbering... */
239  irq = irq - OPENPIC_VEC_SOURCE + BSP_PCI_IRQ_LOWEST_OFFSET;
240
241#ifdef BSP_PCI_ISA_BRIDGE_IRQ
242  isaIntr = (irq == BSP_PCI_ISA_BRIDGE_IRQ);
243  if (isaIntr)  {
244    /*
245     * Acknowledge and read 8259 vector
246     */
247    irq = (unsigned int) (*(unsigned char *) RAVEN_INTR_ACK_REG);
248    /*
249     * store current PIC mask
250     */
251    oldMask = i8259s_cache;
252    newMask = oldMask | irq_mask_or_tbl [irq];
253    i8259s_cache = newMask;
254    outport_byte(PIC_MASTER_IMR_IO_PORT, i8259s_cache & 0xff);
255    outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8));
256    BSP_irq_ack_at_i8259s (irq);
257    openpic_eoi(0);
258  }
259#endif
260
261  /* dispatch handlers */
262  bsp_irq_dispatch_list(rtems_hdl_tbl, irq, default_rtems_entry.hdl);
263
264#ifdef BSP_PCI_ISA_BRIDGE_IRQ
265  if (isaIntr)  {
266    i8259s_cache = oldMask;
267    outport_byte(PIC_MASTER_IMR_IO_PORT, i8259s_cache & 0xff);
268    outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8));
269  }
270  else
271#endif
272  {
273#ifdef BSP_PCI_VME_DRIVER_DOES_EOI
274        /* leave it to the VME bridge driver to do EOI, so
275     * it can re-enable the openpic while handling
276     * VME interrupts (-> VME priorities in software)
277         */
278        if (_BSP_vme_bridge_irq != irq)
279#endif
280                openpic_eoi(0);
281  }
282  return 0;
283}
Note: See TracBrowser for help on using the repository browser.