8259.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 663 行 · 第 1/2 页
C
663 行
/*++
Copyright (c) 2005 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
8259.c
Abstract:
This contains the installation function for the driver.
--*/
#include "8259.h"
//
// Global for the CPU I/O Protocol that is consumed by this driver
//
EFI_CPU_IO_PROTOCOL *mCpuIo;
//
// Global for the Legacy 8259 Protocol that is prodiced by this driver
//
EFI_LEGACY_8259_PROTOCOL m8259 = {
Interrupt8259SetVectorBase,
Interrupt8259GetMask,
Interrupt8259SetMask,
Interrupt8259SetMode,
Interrupt8259GetVector,
Interrupt8259EnableIrq,
Interrupt8259DisableIrq,
Interrupt8259GetInterruptLine,
Interrupt8259EndOfInterrupt
};
//
// Global for the handle that the Legacy 8259 Protocol is installed
//
EFI_HANDLE m8259Handle = NULL;
UINT8 mMasterBase = 0xff;
UINT8 mSlaveBase = 0xff;
EFI_8259_MODE mMode = Efi8259ProtectedMode;
UINT16 mProtectedModeMask = 0xffff;
UINT16 mLegacyModeMask = 0x06b8;
UINT16 mProtectedModeEdgeLevel = 0x0000;
UINT16 mLegacyModeEdgeLevel = 0x0000;
//
// Worker Functions
//
VOID
IoWrite8 (
IN UINT16 Port,
IN UINT8 Value
)
/*++
Routine Description:
Writes an I/O port using the CPU I/O Protocol
Arguments:
Register - I/O Port to write
Value - The 8 bit value to write to Port
Returns:
None
--*/
{
mCpuIo->Io.Write (mCpuIo, EfiCpuIoWidthUint8, Port, 1, &Value);
}
UINT8
IoRead8 (
IN UINT16 Port
)
/*++
Routine Description:
Writes an I/O port using the CPU I/O Protocol
Arguments:
Register - I/O Port to write
Value - The 8 bit value to write to Port
Returns:
None
--*/
{
UINT8 Value;
mCpuIo->Io.Read (mCpuIo, EfiCpuIoWidthUint8, Port, 1, &Value);
return Value;
}
VOID
Interrupt8259WriteMask (
IN UINT16 Mask,
IN UINT16 EdgeLevel
)
/*++
Routine Description:
Sets the 8250 mask to the valud specified by Mask
Arguments:
Mask - A 16 bit valute that represents the master and slave mask values
Returns:
None
--*/
// TODO: EdgeLevel - add argument and description to function comment
{
IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, (UINT8) Mask);
IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, (UINT8) (Mask >> 8));
IoWrite8 (LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_MASTER, (UINT8) EdgeLevel);
IoWrite8 (LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_SLAVE, (UINT8) (EdgeLevel >> 8));
}
VOID
Interrupt8259ReadMask (
IN UINT16 *Mask,
IN UINT16 *EdgeLevel
)
/*++
Routine Description:
Sets the 8250 mask to the valud specified by Mask
Arguments:
Mask - A 16 bit valute that represents the master and slave mask values
Returns:
None
--*/
// TODO: EdgeLevel - add argument and description to function comment
{
if (Mask != NULL) {
*Mask = (UINT16) (IoRead8 (LEGACY_8259_MASK_REGISTER_MASTER) | (IoRead8 (LEGACY_8259_MASK_REGISTER_SLAVE) << 8));
}
if (EdgeLevel != NULL) {
*EdgeLevel = (UINT16)
(
IoRead8 (LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_MASTER) |
(IoRead8 (LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_SLAVE) << 8)
);
}
}
//
// Legacy 8259 Protocol Interface Function
//
EFI_STATUS
EFIAPI
Interrupt8259SetVectorBase (
IN EFI_LEGACY_8259_PROTOCOL *This,
IN UINT8 MasterBase,
IN UINT8 SlaveBase
)
/*++
Routine Description:
Sets the base vector for the 8250 Master and Slave interrupt controllers
Arguments:
This - Protocol instance pointer.
MasterBase - Base vector of the 8259 Master
SlaveBase - Base vector of the 8259 Slave
Returns:
EFI_SUCCESS - 8259 programmed
--*/
{
UINT8 Mask;
if (SlaveBase != mSlaveBase) {
mSlaveBase = SlaveBase;
//
// Initialize Slave interrupt controller.
//
Mask = IoRead8 (LEGACY_8259_MASK_REGISTER_SLAVE);
IoWrite8 (LEGACY_8259_CONTROL_REGISTER_SLAVE, 0x11);
IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, mSlaveBase);
IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, 0x02);
IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, 0x01);
IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, Mask);
}
if (MasterBase != mMasterBase) {
mMasterBase = MasterBase;
//
// Initialize Master interrupt controller.
//
Mask = IoRead8 (LEGACY_8259_MASK_REGISTER_MASTER);
IoWrite8 (LEGACY_8259_CONTROL_REGISTER_MASTER, 0x11);
IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, mMasterBase);
IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, 0x04);
IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, 0x01);
IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, Mask);
}
IoWrite8 (LEGACY_8259_CONTROL_REGISTER_SLAVE, 0x20);
IoWrite8 (LEGACY_8259_CONTROL_REGISTER_MASTER, 0x20);
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
Interrupt8259GetMask (
IN EFI_LEGACY_8259_PROTOCOL * This,
OUT UINT16 *LegacyMask, OPTIONAL
OUT UINT16 *LegacyEdgeLevel, OPTIONAL
OUT UINT16 *ProtectedMask, OPTIONAL
OUT UINT16 *ProtectedEdgeLevel OPTIONAL
)
/*++
Routine Description:
Get the 8259 master and slave address that maps IRQ to processor interrupt
vector number. Get the Context of the device including the state of the
interrupt mask.
Arguments:
This - Protocol instance pointer.
Returns:
EFI_SUCCESS - 8259 programmed
EFI_DEVICE_ERROR - Error writting to 8259
--*/
// TODO: LegacyMask - add argument and description to function comment
// TODO: LegacyEdgeLevel - add argument and description to function comment
// TODO: ProtectedMask - add argument and description to function comment
// TODO: ProtectedEdgeLevel - add argument and description to function comment
{
if (LegacyMask != NULL) {
*LegacyMask = mLegacyModeMask;
}
if (LegacyEdgeLevel != NULL) {
*LegacyEdgeLevel = mLegacyModeEdgeLevel;
}
if (ProtectedMask != NULL) {
*ProtectedMask = mProtectedModeMask;
}
if (ProtectedEdgeLevel != NULL) {
*ProtectedEdgeLevel = mProtectedModeEdgeLevel;
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
Interrupt8259SetMask (
IN EFI_LEGACY_8259_PROTOCOL * This,
IN UINT16 *LegacyMask, OPTIONAL
IN UINT16 *LegacyEdgeLevel, OPTIONAL
IN UINT16 *ProtectedMask, OPTIONAL
IN UINT16 *ProtectedEdgeLevel OPTIONAL
)
/*++
Routine Description:
Set the 8259 interrupt and edge/level masks for legacy and/or protected
mode operation. This routine does not touch the hardware but only the
RAM copies of the masks.
Arguments:
This - Protocol instance pointer.
Returns:
EFI_SUCCESS - 8259 masks updated
--*/
// TODO: LegacyMask - add argument and description to function comment
// TODO: LegacyEdgeLevel - add argument and description to function comment
// TODO: ProtectedMask - add argument and description to function comment
// TODO: ProtectedEdgeLevel - add argument and description to function comment
{
if (LegacyMask != NULL) {
mLegacyModeMask = *LegacyMask;
}
if (LegacyEdgeLevel != NULL) {
mLegacyModeEdgeLevel = *LegacyEdgeLevel;
}
if (ProtectedMask != NULL) {
mProtectedModeMask = *ProtectedMask;
}
if (ProtectedEdgeLevel != NULL) {
mProtectedModeEdgeLevel = *ProtectedEdgeLevel;
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
Interrupt8259SetMode (
IN EFI_LEGACY_8259_PROTOCOL * This,
IN EFI_8259_MODE Mode,
IN UINT16 *Mask, OPTIONAL
IN UINT16 *EdgeLevel OPTIONAL
)
/*++
Routine Description:
Set the 8259 master and slave address that maps IRQ to processor interrupt
vector number. Restore the Context of the device, so that the interrupt
mask is put back in it's previous mode.
Arguments:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?