|
|
/*
|
/*
|
* This file contains the implementation of the function described in irq.h
|
* This file contains the implementation of the function described in irq.h
|
* related to Intel 8259 Programmable Interrupt controller.
|
* related to Intel 8259 Programmable Interrupt controller.
|
*
|
*
|
* Copyright (C) 1998, 1999 valette@crf.canon.fr
|
* Copyright (C) 1998, 1999 valette@crf.canon.fr
|
*
|
*
|
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
* found in found in the file LICENSE in this distribution or at
|
* found in found in the file LICENSE in this distribution or at
|
* http://www.OARcorp.com/rtems/license.html.
|
* http://www.OARcorp.com/rtems/license.html.
|
*
|
*
|
* $Id: i8259.c,v 1.2 2001-09-27 12:01:06 chris Exp $
|
* $Id: i8259.c,v 1.2 2001-09-27 12:01:06 chris Exp $
|
*/
|
*/
|
|
|
#include <bsp.h>
|
#include <bsp.h>
|
#include <bsp/irq.h>
|
#include <bsp/irq.h>
|
|
|
/*-------------------------------------------------------------------------+
|
/*-------------------------------------------------------------------------+
|
| Cache for 1st and 2nd PIC IRQ line's status (enabled or disabled) register.
|
| Cache for 1st and 2nd PIC IRQ line's status (enabled or disabled) register.
|
+--------------------------------------------------------------------------*/
|
+--------------------------------------------------------------------------*/
|
/*
|
/*
|
* lower byte is interrupt mask on the master PIC.
|
* lower byte is interrupt mask on the master PIC.
|
* while upper bits are interrupt on the slave PIC.
|
* while upper bits are interrupt on the slave PIC.
|
*/
|
*/
|
volatile rtems_i8259_masks i8259s_cache = 0xfffb;
|
volatile rtems_i8259_masks i8259s_cache = 0xfffb;
|
|
|
/*-------------------------------------------------------------------------+
|
/*-------------------------------------------------------------------------+
|
| Function: BSP_irq_disable_at_i8259s
|
| Function: BSP_irq_disable_at_i8259s
|
| Description: Mask IRQ line in appropriate PIC chip.
|
| Description: Mask IRQ line in appropriate PIC chip.
|
| Global Variables: i8259s_cache
|
| Global Variables: i8259s_cache
|
| Arguments: vector_offset - number of IRQ line to mask.
|
| Arguments: vector_offset - number of IRQ line to mask.
|
| Returns: Nothing.
|
| Returns: Nothing.
|
+--------------------------------------------------------------------------*/
|
+--------------------------------------------------------------------------*/
|
int BSP_irq_disable_at_i8259s (const rtems_irq_symbolic_name irqLine)
|
int BSP_irq_disable_at_i8259s (const rtems_irq_symbolic_name irqLine)
|
{
|
{
|
unsigned short mask;
|
unsigned short mask;
|
unsigned int level;
|
unsigned int level;
|
|
|
if ( ((int)irqLine < BSP_ISA_IRQ_LOWEST_OFFSET) ||
|
if ( ((int)irqLine < BSP_ISA_IRQ_LOWEST_OFFSET) ||
|
((int)irqLine > BSP_ISA_IRQ_MAX_OFFSET)
|
((int)irqLine > BSP_ISA_IRQ_MAX_OFFSET)
|
)
|
)
|
return 1;
|
return 1;
|
|
|
_CPU_ISR_Disable(level);
|
_CPU_ISR_Disable(level);
|
|
|
mask = 1 << irqLine;
|
mask = 1 << irqLine;
|
i8259s_cache |= mask;
|
i8259s_cache |= mask;
|
|
|
if (irqLine < 8)
|
if (irqLine < 8)
|
{
|
{
|
outport_byte(PIC_MASTER_IMR_IO_PORT, i8259s_cache & 0xff);
|
outport_byte(PIC_MASTER_IMR_IO_PORT, i8259s_cache & 0xff);
|
}
|
}
|
else
|
else
|
{
|
{
|
outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8));
|
outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8));
|
}
|
}
|
_CPU_ISR_Enable (level);
|
_CPU_ISR_Enable (level);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*-------------------------------------------------------------------------+
|
/*-------------------------------------------------------------------------+
|
| Function: BSP_irq_enable_at_i8259s
|
| Function: BSP_irq_enable_at_i8259s
|
| Description: Unmask IRQ line in appropriate PIC chip.
|
| Description: Unmask IRQ line in appropriate PIC chip.
|
| Global Variables: i8259s_cache
|
| Global Variables: i8259s_cache
|
| Arguments: irqLine - number of IRQ line to mask.
|
| Arguments: irqLine - number of IRQ line to mask.
|
| Returns: Nothing.
|
| Returns: Nothing.
|
+--------------------------------------------------------------------------*/
|
+--------------------------------------------------------------------------*/
|
int BSP_irq_enable_at_i8259s (const rtems_irq_symbolic_name irqLine)
|
int BSP_irq_enable_at_i8259s (const rtems_irq_symbolic_name irqLine)
|
{
|
{
|
unsigned short mask;
|
unsigned short mask;
|
unsigned int level;
|
unsigned int level;
|
|
|
if ( ((int)irqLine < BSP_ISA_IRQ_LOWEST_OFFSET) ||
|
if ( ((int)irqLine < BSP_ISA_IRQ_LOWEST_OFFSET) ||
|
((int)irqLine > BSP_ISA_IRQ_MAX_OFFSET )
|
((int)irqLine > BSP_ISA_IRQ_MAX_OFFSET )
|
)
|
)
|
return 1;
|
return 1;
|
|
|
_CPU_ISR_Disable(level);
|
_CPU_ISR_Disable(level);
|
|
|
mask = ~(1 << irqLine);
|
mask = ~(1 << irqLine);
|
i8259s_cache &= mask;
|
i8259s_cache &= mask;
|
|
|
if (irqLine < 8)
|
if (irqLine < 8)
|
{
|
{
|
outport_byte(PIC_MASTER_IMR_IO_PORT, i8259s_cache & 0xff);
|
outport_byte(PIC_MASTER_IMR_IO_PORT, i8259s_cache & 0xff);
|
}
|
}
|
else
|
else
|
{
|
{
|
outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8));
|
outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8));
|
}
|
}
|
_CPU_ISR_Enable (level);
|
_CPU_ISR_Enable (level);
|
|
|
return 0;
|
return 0;
|
} /* mask_irq */
|
} /* mask_irq */
|
|
|
int BSP_irq_enabled_at_i8259s (const rtems_irq_symbolic_name irqLine)
|
int BSP_irq_enabled_at_i8259s (const rtems_irq_symbolic_name irqLine)
|
{
|
{
|
unsigned short mask;
|
unsigned short mask;
|
|
|
if ( ((int)irqLine < BSP_ISA_IRQ_LOWEST_OFFSET) ||
|
if ( ((int)irqLine < BSP_ISA_IRQ_LOWEST_OFFSET) ||
|
((int)irqLine > BSP_ISA_IRQ_MAX_OFFSET)
|
((int)irqLine > BSP_ISA_IRQ_MAX_OFFSET)
|
)
|
)
|
return 1;
|
return 1;
|
|
|
mask = (1 << irqLine);
|
mask = (1 << irqLine);
|
return (~(i8259s_cache & mask));
|
return (~(i8259s_cache & mask));
|
}
|
}
|
|
|
|
|
/*-------------------------------------------------------------------------+
|
/*-------------------------------------------------------------------------+
|
| Function: BSP_irq_ack_at_i8259s
|
| Function: BSP_irq_ack_at_i8259s
|
| Description: Signal generic End Of Interrupt (EOI) to appropriate PIC.
|
| Description: Signal generic End Of Interrupt (EOI) to appropriate PIC.
|
| Global Variables: None.
|
| Global Variables: None.
|
| Arguments: irqLine - number of IRQ line to acknowledge.
|
| Arguments: irqLine - number of IRQ line to acknowledge.
|
| Returns: Nothing.
|
| Returns: Nothing.
|
+--------------------------------------------------------------------------*/
|
+--------------------------------------------------------------------------*/
|
int BSP_irq_ack_at_i8259s (const rtems_irq_symbolic_name irqLine)
|
int BSP_irq_ack_at_i8259s (const rtems_irq_symbolic_name irqLine)
|
{
|
{
|
if (irqLine >= 8) {
|
if (irqLine >= 8) {
|
outport_byte(PIC_MASTER_COMMAND_IO_PORT, SLAVE_PIC_EOSI);
|
outport_byte(PIC_MASTER_COMMAND_IO_PORT, SLAVE_PIC_EOSI);
|
outport_byte(PIC_SLAVE_COMMAND_IO_PORT, (PIC_EOSI | (irqLine - 8)));
|
outport_byte(PIC_SLAVE_COMMAND_IO_PORT, (PIC_EOSI | (irqLine - 8)));
|
}
|
}
|
else {
|
else {
|
outport_byte(PIC_MASTER_COMMAND_IO_PORT, (PIC_EOSI | irqLine));
|
outport_byte(PIC_MASTER_COMMAND_IO_PORT, (PIC_EOSI | irqLine));
|
}
|
}
|
|
|
return 0;
|
return 0;
|
|
|
} /* ackIRQ */
|
} /* ackIRQ */
|
|
|
void BSP_i8259s_init(void)
|
void BSP_i8259s_init(void)
|
{
|
{
|
/*
|
/*
|
* init master 8259 interrupt controller
|
* init master 8259 interrupt controller
|
*/
|
*/
|
outport_byte(PIC_MASTER_COMMAND_IO_PORT, 0x11); /* Start init sequence */
|
outport_byte(PIC_MASTER_COMMAND_IO_PORT, 0x11); /* Start init sequence */
|
outport_byte(PIC_MASTER_IMR_IO_PORT, 0x00);/* Vector base = 0 */
|
outport_byte(PIC_MASTER_IMR_IO_PORT, 0x00);/* Vector base = 0 */
|
outport_byte(PIC_MASTER_IMR_IO_PORT, 0x04);/* edge tiggered, Cascade (slave) on IRQ2 */
|
outport_byte(PIC_MASTER_IMR_IO_PORT, 0x04);/* edge tiggered, Cascade (slave) on IRQ2 */
|
outport_byte(PIC_MASTER_IMR_IO_PORT, 0x01);/* Select 8086 mode */
|
outport_byte(PIC_MASTER_IMR_IO_PORT, 0x01);/* Select 8086 mode */
|
outport_byte(PIC_MASTER_IMR_IO_PORT, 0xFB); /* Mask all except cascade */
|
outport_byte(PIC_MASTER_IMR_IO_PORT, 0xFB); /* Mask all except cascade */
|
/*
|
/*
|
* init slave interrupt controller
|
* init slave interrupt controller
|
*/
|
*/
|
outport_byte(PIC_SLAVE_COMMAND_IO_PORT, 0x11); /* Start init sequence */
|
outport_byte(PIC_SLAVE_COMMAND_IO_PORT, 0x11); /* Start init sequence */
|
outport_byte(PIC_SLAVE_IMR_IO_PORT, 0x08);/* Vector base = 8 */
|
outport_byte(PIC_SLAVE_IMR_IO_PORT, 0x08);/* Vector base = 8 */
|
outport_byte(PIC_SLAVE_IMR_IO_PORT, 0x02);/* edge triggered, Cascade (slave) on IRQ2 */
|
outport_byte(PIC_SLAVE_IMR_IO_PORT, 0x02);/* edge triggered, Cascade (slave) on IRQ2 */
|
outport_byte(PIC_SLAVE_IMR_IO_PORT, 0x01); /* Select 8086 mode */
|
outport_byte(PIC_SLAVE_IMR_IO_PORT, 0x01); /* Select 8086 mode */
|
outport_byte(PIC_SLAVE_IMR_IO_PORT, 0xFF); /* Mask all */
|
outport_byte(PIC_SLAVE_IMR_IO_PORT, 0xFF); /* Mask all */
|
|
|
}
|
}
|
|
|
|
|