source: rtems/c/src/lib/libbsp/powerpc/shared/irq/i8259.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 *  This file contains the implementation of the function described in irq.h
3 *  related to Intel 8259 Programmable Interrupt controller.
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 the file LICENSE in this distribution or at
9 *  http://www.rtems.org/license/LICENSE.
10 */
11
12#include <bsp.h>
13#include <bsp/irq.h>
14
15/*-------------------------------------------------------------------------+
16| Cache for 1st and 2nd PIC IRQ line's status (enabled or disabled) register.
17+--------------------------------------------------------------------------*/
18/*
19 * lower byte is interrupt mask on the master PIC.
20 * while upper bits are interrupt on the slave PIC.
21 */
22volatile rtems_i8259_masks i8259s_cache = 0xfffb;
23
24/*-------------------------------------------------------------------------+
25|         Function:  BSP_irq_disable_at_i8259s
26|      Description: Mask IRQ line in appropriate PIC chip.
27| Global Variables: i8259s_cache
28|        Arguments: vector_offset - number of IRQ line to mask.
29|          Returns: original state or -1 on error.
30+--------------------------------------------------------------------------*/
31int BSP_irq_disable_at_i8259s    (const rtems_irq_number irqLine)
32{
33  unsigned short        mask;
34  rtems_interrupt_level level;
35  int                   rval;
36
37  if ( ((int)irqLine < BSP_ISA_IRQ_LOWEST_OFFSET) ||
38       ((int)irqLine > BSP_ISA_IRQ_MAX_OFFSET)
39       )
40    return -1;
41
42  rtems_interrupt_disable(level);
43
44  mask = 1 << irqLine;
45  rval = i8259s_cache & mask ? 0 : 1;
46  i8259s_cache |= mask;
47
48  if (irqLine < 8)
49  {
50    outport_byte(PIC_MASTER_IMR_IO_PORT, i8259s_cache & 0xff);
51  }
52  else
53  {
54    outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8));
55  }
56  rtems_interrupt_enable(level);
57
58  return rval;
59}
60
61/*-------------------------------------------------------------------------+
62|         Function:  BSP_irq_enable_at_i8259s
63|      Description: Unmask IRQ line in appropriate PIC chip.
64| Global Variables: i8259s_cache
65|        Arguments: irqLine - number of IRQ line to mask.
66|          Returns: Nothing.
67+--------------------------------------------------------------------------*/
68int BSP_irq_enable_at_i8259s    (const rtems_irq_number irqLine)
69{
70  unsigned short        mask;
71  rtems_interrupt_level level;
72
73  if ( ((int)irqLine < BSP_ISA_IRQ_LOWEST_OFFSET) ||
74       ((int)irqLine > BSP_ISA_IRQ_MAX_OFFSET )
75       )
76    return 1;
77
78  rtems_interrupt_disable(level);
79
80  mask = ~(1 << irqLine);
81  i8259s_cache &= mask;
82
83  if (irqLine < 8)
84  {
85    outport_byte(PIC_MASTER_IMR_IO_PORT, i8259s_cache & 0xff);
86  }
87  else
88  {
89    outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8));
90  }
91  rtems_interrupt_enable(level);
92
93  return 0;
94} /* mask_irq */
95
96int BSP_irq_enabled_at_i8259s           (const rtems_irq_number irqLine)
97{
98  unsigned short mask;
99
100  if ( ((int)irqLine < BSP_ISA_IRQ_LOWEST_OFFSET) ||
101       ((int)irqLine > BSP_ISA_IRQ_MAX_OFFSET)
102     )
103    return 1;
104
105  mask = (1 << irqLine);
106  return  (~(i8259s_cache & mask));
107}
108
109/*-------------------------------------------------------------------------+
110|         Function: BSP_irq_ack_at_i8259s
111|      Description: Signal generic End Of Interrupt (EOI) to appropriate PIC.
112| Global Variables: None.
113|        Arguments: irqLine - number of IRQ line to acknowledge.
114|          Returns: Nothing.
115+--------------------------------------------------------------------------*/
116int BSP_irq_ack_at_i8259s       (const rtems_irq_number irqLine)
117{
118  if (irqLine >= 8) {
119    outport_byte(PIC_MASTER_COMMAND_IO_PORT, SLAVE_PIC_EOSI);
120    outport_byte(PIC_SLAVE_COMMAND_IO_PORT, (PIC_EOSI | (irqLine - 8)));
121  }
122  else {
123    outport_byte(PIC_MASTER_COMMAND_IO_PORT, (PIC_EOSI | irqLine));
124  }
125
126  return 0;
127
128} /* ackIRQ */
129
130void BSP_i8259s_init(void)
131{
132  /*
133   * init master 8259 interrupt controller
134   */
135  outport_byte(PIC_MASTER_COMMAND_IO_PORT, 0x11); /* Start init sequence */
136  outport_byte(PIC_MASTER_IMR_IO_PORT, 0x00);/* Vector base  = 0 */
137  outport_byte(PIC_MASTER_IMR_IO_PORT, 0x04);/* edge tiggered, Cascade (slave) on IRQ2 */
138  outport_byte(PIC_MASTER_IMR_IO_PORT, 0x01);/* Select 8086 mode */
139  outport_byte(PIC_MASTER_IMR_IO_PORT, 0xFB); /* Mask all except cascade */
140  /*
141   * init slave  interrupt controller
142   */
143  outport_byte(PIC_SLAVE_COMMAND_IO_PORT, 0x11); /* Start init sequence */
144  outport_byte(PIC_SLAVE_IMR_IO_PORT, 0x08);/* Vector base  = 8 */
145  outport_byte(PIC_SLAVE_IMR_IO_PORT, 0x02);/* edge triggered, Cascade (slave) on IRQ2 */
146  outport_byte(PIC_SLAVE_IMR_IO_PORT, 0x01); /* Select 8086 mode */
147  outport_byte(PIC_SLAVE_IMR_IO_PORT, 0xFF); /* Mask all */
148
149}
Note: See TracBrowser for help on using the repository browser.