2 Driver implementing the Tiano Legacy 8259 Protocol
4 Copyright (c) 2005 - 2009, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <FrameworkDxe.h>
14 #include <Protocol/Legacy8259.h>
15 #include <Protocol/PciIo.h>
17 #include <Library/UefiBootServicesTableLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/IoLib.h>
20 #include <Library/BaseLib.h>
21 #include <Library/PcdLib.h>
23 #include <IndustryStandard/Pci.h>
25 // 8259 Hardware definitions
27 #define LEGACY_MODE_BASE_VECTOR_MASTER 0x08
28 #define LEGACY_MODE_BASE_VECTOR_SLAVE 0x70
30 #define PROTECTED_MODE_BASE_VECTOR_MASTER 0x68
31 #define PROTECTED_MODE_BASE_VECTOR_SLAVE 0x70
33 #define LEGACY_8259_CONTROL_REGISTER_MASTER 0x20
34 #define LEGACY_8259_MASK_REGISTER_MASTER 0x21
35 #define LEGACY_8259_CONTROL_REGISTER_SLAVE 0xA0
36 #define LEGACY_8259_MASK_REGISTER_SLAVE 0xA1
37 #define LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_MASTER 0x4D0
38 #define LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_SLAVE 0x4D1
40 #define LEGACY_8259_EOI 0x20
42 // Protocol Function Prototypes
45 Sets the base address for the 8259 master and slave PICs.
47 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
48 @param[in] MasterBase Interrupt vectors for IRQ0-IRQ7.
49 @param[in] SlaveBase Interrupt vectors for IRQ8-IRQ15.
51 @retval EFI_SUCCESS The 8259 PIC was programmed successfully.
52 @retval EFI_DEVICE_ERROR There was an error while writing to the 8259 PIC.
57 Interrupt8259SetVectorBase (
58 IN EFI_LEGACY_8259_PROTOCOL
*This
,
64 Gets the current 16-bit real mode and 32-bit protected-mode IRQ masks.
66 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
67 @param[out] LegacyMask 16-bit mode interrupt mask for IRQ0-IRQ15.
68 @param[out] LegacyEdgeLevel 16-bit mode edge/level mask for IRQ-IRQ15.
69 @param[out] ProtectedMask 32-bit mode interrupt mask for IRQ0-IRQ15.
70 @param[out] ProtectedEdgeLevel 32-bit mode edge/level mask for IRQ0-IRQ15.
72 @retval EFI_SUCCESS The 8259 PIC was programmed successfully.
73 @retval EFI_DEVICE_ERROR There was an error while reading the 8259 PIC.
78 Interrupt8259GetMask (
79 IN EFI_LEGACY_8259_PROTOCOL
*This
,
80 OUT UINT16
*LegacyMask
, OPTIONAL
81 OUT UINT16
*LegacyEdgeLevel
, OPTIONAL
82 OUT UINT16
*ProtectedMask
, OPTIONAL
83 OUT UINT16
*ProtectedEdgeLevel OPTIONAL
87 Sets the current 16-bit real mode and 32-bit protected-mode IRQ masks.
89 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
90 @param[in] LegacyMask 16-bit mode interrupt mask for IRQ0-IRQ15.
91 @param[in] LegacyEdgeLevel 16-bit mode edge/level mask for IRQ-IRQ15.
92 @param[in] ProtectedMask 32-bit mode interrupt mask for IRQ0-IRQ15.
93 @param[in] ProtectedEdgeLevel 32-bit mode edge/level mask for IRQ0-IRQ15.
95 @retval EFI_SUCCESS The 8259 PIC was programmed successfully.
96 @retval EFI_DEVICE_ERROR There was an error while writing the 8259 PIC.
101 Interrupt8259SetMask (
102 IN EFI_LEGACY_8259_PROTOCOL
*This
,
103 IN UINT16
*LegacyMask
, OPTIONAL
104 IN UINT16
*LegacyEdgeLevel
, OPTIONAL
105 IN UINT16
*ProtectedMask
, OPTIONAL
106 IN UINT16
*ProtectedEdgeLevel OPTIONAL
110 Sets the mode of the PICs.
112 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
113 @param[in] Mode 16-bit real or 32-bit protected mode.
114 @param[in] Mask The value with which to set the interrupt mask.
115 @param[in] EdgeLevel The value with which to set the edge/level mask.
117 @retval EFI_SUCCESS The mode was set successfully.
118 @retval EFI_INVALID_PARAMETER The mode was not set.
123 Interrupt8259SetMode (
124 IN EFI_LEGACY_8259_PROTOCOL
*This
,
125 IN EFI_8259_MODE Mode
,
126 IN UINT16
*Mask
, OPTIONAL
127 IN UINT16
*EdgeLevel OPTIONAL
131 Translates the IRQ into a vector.
133 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
134 @param[in] Irq IRQ0-IRQ15.
135 @param[out] Vector The vector that is assigned to the IRQ.
137 @retval EFI_SUCCESS The Vector that matches Irq was returned.
138 @retval EFI_INVALID_PARAMETER Irq is not valid.
143 Interrupt8259GetVector (
144 IN EFI_LEGACY_8259_PROTOCOL
*This
,
150 Enables the specified IRQ.
152 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
153 @param[in] Irq IRQ0-IRQ15.
154 @param[in] LevelTriggered 0 = Edge triggered; 1 = Level triggered.
156 @retval EFI_SUCCESS The Irq was enabled on the 8259 PIC.
157 @retval EFI_INVALID_PARAMETER The Irq is not valid.
162 Interrupt8259EnableIrq (
163 IN EFI_LEGACY_8259_PROTOCOL
*This
,
165 IN BOOLEAN LevelTriggered
169 Disables the specified IRQ.
171 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
172 @param[in] Irq IRQ0-IRQ15.
174 @retval EFI_SUCCESS The Irq was disabled on the 8259 PIC.
175 @retval EFI_INVALID_PARAMETER The Irq is not valid.
180 Interrupt8259DisableIrq (
181 IN EFI_LEGACY_8259_PROTOCOL
*This
,
186 Reads the PCI configuration space to get the interrupt number that is assigned to the card.
188 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
189 @param[in] PciHandle PCI function for which to return the vector.
190 @param[out] Vector IRQ number that corresponds to the interrupt line.
192 @retval EFI_SUCCESS The interrupt line value was read successfully.
197 Interrupt8259GetInterruptLine (
198 IN EFI_LEGACY_8259_PROTOCOL
*This
,
199 IN EFI_HANDLE PciHandle
,
204 Issues the End of Interrupt (EOI) commands to PICs.
206 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
207 @param[in] Irq The interrupt for which to issue the EOI command.
209 @retval EFI_SUCCESS The EOI command was issued.
210 @retval EFI_INVALID_PARAMETER The Irq is not valid.
215 Interrupt8259EndOfInterrupt (
216 IN EFI_LEGACY_8259_PROTOCOL
*This
,