2 Driver implementing the Tiano Legacy 8259 Protocol
4 Copyright (c) 2005 - 2009, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <FrameworkDxe.h>
20 #include <Protocol/Legacy8259.h>
21 #include <Protocol/PciIo.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/IoLib.h>
26 #include <Library/BaseLib.h>
27 #include <Library/PcdLib.h>
29 #include <IndustryStandard/Pci.h>
31 // 8259 Hardware definitions
33 #define LEGACY_MODE_BASE_VECTOR_MASTER 0x08
34 #define LEGACY_MODE_BASE_VECTOR_SLAVE 0x70
36 #define PROTECTED_MODE_BASE_VECTOR_MASTER 0x68
37 #define PROTECTED_MODE_BASE_VECTOR_SLAVE 0x70
39 #define LEGACY_8259_CONTROL_REGISTER_MASTER 0x20
40 #define LEGACY_8259_MASK_REGISTER_MASTER 0x21
41 #define LEGACY_8259_CONTROL_REGISTER_SLAVE 0xA0
42 #define LEGACY_8259_MASK_REGISTER_SLAVE 0xA1
43 #define LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_MASTER 0x4D0
44 #define LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_SLAVE 0x4D1
46 #define LEGACY_8259_EOI 0x20
48 // Protocol Function Prototypes
51 Sets the base address for the 8259 master and slave PICs.
53 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
54 @param[in] MasterBase Interrupt vectors for IRQ0-IRQ7.
55 @param[in] SlaveBase Interrupt vectors for IRQ8-IRQ15.
57 @retval EFI_SUCCESS The 8259 PIC was programmed successfully.
58 @retval EFI_DEVICE_ERROR There was an error while writing to the 8259 PIC.
63 Interrupt8259SetVectorBase (
64 IN EFI_LEGACY_8259_PROTOCOL
*This
,
70 Gets the current 16-bit real mode and 32-bit protected-mode IRQ masks.
72 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
73 @param[out] LegacyMask 16-bit mode interrupt mask for IRQ0-IRQ15.
74 @param[out] LegacyEdgeLevel 16-bit mode edge/level mask for IRQ-IRQ15.
75 @param[out] ProtectedMask 32-bit mode interrupt mask for IRQ0-IRQ15.
76 @param[out] ProtectedEdgeLevel 32-bit mode edge/level mask for IRQ0-IRQ15.
78 @retval EFI_SUCCESS The 8259 PIC was programmed successfully.
79 @retval EFI_DEVICE_ERROR There was an error while reading the 8259 PIC.
84 Interrupt8259GetMask (
85 IN EFI_LEGACY_8259_PROTOCOL
*This
,
86 OUT UINT16
*LegacyMask
, OPTIONAL
87 OUT UINT16
*LegacyEdgeLevel
, OPTIONAL
88 OUT UINT16
*ProtectedMask
, OPTIONAL
89 OUT UINT16
*ProtectedEdgeLevel OPTIONAL
93 Sets the current 16-bit real mode and 32-bit protected-mode IRQ masks.
95 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
96 @param[in] LegacyMask 16-bit mode interrupt mask for IRQ0-IRQ15.
97 @param[in] LegacyEdgeLevel 16-bit mode edge/level mask for IRQ-IRQ15.
98 @param[in] ProtectedMask 32-bit mode interrupt mask for IRQ0-IRQ15.
99 @param[in] ProtectedEdgeLevel 32-bit mode edge/level mask for IRQ0-IRQ15.
101 @retval EFI_SUCCESS The 8259 PIC was programmed successfully.
102 @retval EFI_DEVICE_ERROR There was an error while writing the 8259 PIC.
107 Interrupt8259SetMask (
108 IN EFI_LEGACY_8259_PROTOCOL
*This
,
109 IN UINT16
*LegacyMask
, OPTIONAL
110 IN UINT16
*LegacyEdgeLevel
, OPTIONAL
111 IN UINT16
*ProtectedMask
, OPTIONAL
112 IN UINT16
*ProtectedEdgeLevel OPTIONAL
116 Sets the mode of the PICs.
118 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
119 @param[in] Mode 16-bit real or 32-bit protected mode.
120 @param[in] Mask The value with which to set the interrupt mask.
121 @param[in] EdgeLevel The value with which to set the edge/level mask.
123 @retval EFI_SUCCESS The mode was set successfully.
124 @retval EFI_INVALID_PARAMETER The mode was not set.
129 Interrupt8259SetMode (
130 IN EFI_LEGACY_8259_PROTOCOL
*This
,
131 IN EFI_8259_MODE Mode
,
132 IN UINT16
*Mask
, OPTIONAL
133 IN UINT16
*EdgeLevel OPTIONAL
137 Translates the IRQ into a vector.
139 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
140 @param[in] Irq IRQ0-IRQ15.
141 @param[out] Vector The vector that is assigned to the IRQ.
143 @retval EFI_SUCCESS The Vector that matches Irq was returned.
144 @retval EFI_INVALID_PARAMETER Irq is not valid.
149 Interrupt8259GetVector (
150 IN EFI_LEGACY_8259_PROTOCOL
*This
,
156 Enables the specified IRQ.
158 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
159 @param[in] Irq IRQ0-IRQ15.
160 @param[in] LevelTriggered 0 = Edge triggered; 1 = Level triggered.
162 @retval EFI_SUCCESS The Irq was enabled on the 8259 PIC.
163 @retval EFI_INVALID_PARAMETER The Irq is not valid.
168 Interrupt8259EnableIrq (
169 IN EFI_LEGACY_8259_PROTOCOL
*This
,
171 IN BOOLEAN LevelTriggered
175 Disables the specified IRQ.
177 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
178 @param[in] Irq IRQ0-IRQ15.
180 @retval EFI_SUCCESS The Irq was disabled on the 8259 PIC.
181 @retval EFI_INVALID_PARAMETER The Irq is not valid.
186 Interrupt8259DisableIrq (
187 IN EFI_LEGACY_8259_PROTOCOL
*This
,
192 Reads the PCI configuration space to get the interrupt number that is assigned to the card.
194 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
195 @param[in] PciHandle PCI function for which to return the vector.
196 @param[out] Vector IRQ number that corresponds to the interrupt line.
198 @retval EFI_SUCCESS The interrupt line value was read successfully.
203 Interrupt8259GetInterruptLine (
204 IN EFI_LEGACY_8259_PROTOCOL
*This
,
205 IN EFI_HANDLE PciHandle
,
210 Issues the End of Interrupt (EOI) commands to PICs.
212 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
213 @param[in] Irq The interrupt for which to issue the EOI command.
215 @retval EFI_SUCCESS The EOI command was issued.
216 @retval EFI_INVALID_PARAMETER The Irq is not valid.
221 Interrupt8259EndOfInterrupt (
222 IN EFI_LEGACY_8259_PROTOCOL
*This
,