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

4.104.115
Last change on this file since ac7af4a was ac7af4a, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/30/09 at 04:37:44

Whitespace removal.

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