2 Driver implementing the Tiano Legacy 8259 Protocol
4 Copyright (c) 2005 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Protocol/Legacy8259.h>
13 #include <Protocol/PciIo.h>
15 #include <Library/UefiBootServicesTableLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/IoLib.h>
18 #include <Library/BaseLib.h>
19 #include <Library/PcdLib.h>
21 #include <IndustryStandard/Pci.h>
23 // 8259 Hardware definitions
25 #define LEGACY_MODE_BASE_VECTOR_MASTER 0x08
26 #define LEGACY_MODE_BASE_VECTOR_SLAVE 0x70
28 #define PROTECTED_MODE_BASE_VECTOR_MASTER 0x68
29 #define PROTECTED_MODE_BASE_VECTOR_SLAVE 0x70
31 #define LEGACY_8259_CONTROL_REGISTER_MASTER 0x20
32 #define LEGACY_8259_MASK_REGISTER_MASTER 0x21
33 #define LEGACY_8259_CONTROL_REGISTER_SLAVE 0xA0
34 #define LEGACY_8259_MASK_REGISTER_SLAVE 0xA1
35 #define LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_MASTER 0x4D0
36 #define LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_SLAVE 0x4D1
38 #define LEGACY_8259_EOI 0x20
40 // Protocol Function Prototypes
43 Sets the base address for the 8259 master and slave PICs.
45 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
46 @param[in] MasterBase Interrupt vectors for IRQ0-IRQ7.
47 @param[in] SlaveBase Interrupt vectors for IRQ8-IRQ15.
49 @retval EFI_SUCCESS The 8259 PIC was programmed successfully.
50 @retval EFI_DEVICE_ERROR There was an error while writing to the 8259 PIC.
55 Interrupt8259SetVectorBase (
56 IN EFI_LEGACY_8259_PROTOCOL
*This
,
62 Gets the current 16-bit real mode and 32-bit protected-mode IRQ masks.
64 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
65 @param[out] LegacyMask 16-bit mode interrupt mask for IRQ0-IRQ15.
66 @param[out] LegacyEdgeLevel 16-bit mode edge/level mask for IRQ-IRQ15.
67 @param[out] ProtectedMask 32-bit mode interrupt mask for IRQ0-IRQ15.
68 @param[out] ProtectedEdgeLevel 32-bit mode edge/level mask for IRQ0-IRQ15.
70 @retval EFI_SUCCESS The 8259 PIC was programmed successfully.
71 @retval EFI_DEVICE_ERROR There was an error while reading the 8259 PIC.
76 Interrupt8259GetMask (
77 IN EFI_LEGACY_8259_PROTOCOL
*This
,
78 OUT UINT16
*LegacyMask
, OPTIONAL
79 OUT UINT16
*LegacyEdgeLevel
, OPTIONAL
80 OUT UINT16
*ProtectedMask
, OPTIONAL
81 OUT UINT16
*ProtectedEdgeLevel OPTIONAL
85 Sets the current 16-bit real mode and 32-bit protected-mode IRQ masks.
87 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
88 @param[in] LegacyMask 16-bit mode interrupt mask for IRQ0-IRQ15.
89 @param[in] LegacyEdgeLevel 16-bit mode edge/level mask for IRQ-IRQ15.
90 @param[in] ProtectedMask 32-bit mode interrupt mask for IRQ0-IRQ15.
91 @param[in] ProtectedEdgeLevel 32-bit mode edge/level mask for IRQ0-IRQ15.
93 @retval EFI_SUCCESS The 8259 PIC was programmed successfully.
94 @retval EFI_DEVICE_ERROR There was an error while writing the 8259 PIC.
99 Interrupt8259SetMask (
100 IN EFI_LEGACY_8259_PROTOCOL
*This
,
101 IN UINT16
*LegacyMask
, OPTIONAL
102 IN UINT16
*LegacyEdgeLevel
, OPTIONAL
103 IN UINT16
*ProtectedMask
, OPTIONAL
104 IN UINT16
*ProtectedEdgeLevel OPTIONAL
108 Sets the mode of the PICs.
110 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
111 @param[in] Mode 16-bit real or 32-bit protected mode.
112 @param[in] Mask The value with which to set the interrupt mask.
113 @param[in] EdgeLevel The value with which to set the edge/level mask.
115 @retval EFI_SUCCESS The mode was set successfully.
116 @retval EFI_INVALID_PARAMETER The mode was not set.
121 Interrupt8259SetMode (
122 IN EFI_LEGACY_8259_PROTOCOL
*This
,
123 IN EFI_8259_MODE Mode
,
124 IN UINT16
*Mask
, OPTIONAL
125 IN UINT16
*EdgeLevel OPTIONAL
129 Translates the IRQ into a vector.
131 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
132 @param[in] Irq IRQ0-IRQ15.
133 @param[out] Vector The vector that is assigned to the IRQ.
135 @retval EFI_SUCCESS The Vector that matches Irq was returned.
136 @retval EFI_INVALID_PARAMETER Irq is not valid.
141 Interrupt8259GetVector (
142 IN EFI_LEGACY_8259_PROTOCOL
*This
,
148 Enables the specified IRQ.
150 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
151 @param[in] Irq IRQ0-IRQ15.
152 @param[in] LevelTriggered 0 = Edge triggered; 1 = Level triggered.
154 @retval EFI_SUCCESS The Irq was enabled on the 8259 PIC.
155 @retval EFI_INVALID_PARAMETER The Irq is not valid.
160 Interrupt8259EnableIrq (
161 IN EFI_LEGACY_8259_PROTOCOL
*This
,
163 IN BOOLEAN LevelTriggered
167 Disables the specified IRQ.
169 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
170 @param[in] Irq IRQ0-IRQ15.
172 @retval EFI_SUCCESS The Irq was disabled on the 8259 PIC.
173 @retval EFI_INVALID_PARAMETER The Irq is not valid.
178 Interrupt8259DisableIrq (
179 IN EFI_LEGACY_8259_PROTOCOL
*This
,
184 Reads the PCI configuration space to get the interrupt number that is assigned to the card.
186 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
187 @param[in] PciHandle PCI function for which to return the vector.
188 @param[out] Vector IRQ number that corresponds to the interrupt line.
190 @retval EFI_SUCCESS The interrupt line value was read successfully.
195 Interrupt8259GetInterruptLine (
196 IN EFI_LEGACY_8259_PROTOCOL
*This
,
197 IN EFI_HANDLE PciHandle
,
202 Issues the End of Interrupt (EOI) commands to PICs.
204 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance.
205 @param[in] Irq The interrupt for which to issue the EOI command.
207 @retval EFI_SUCCESS The EOI command was issued.
208 @retval EFI_INVALID_PARAMETER The Irq is not valid.
213 Interrupt8259EndOfInterrupt (
214 IN EFI_LEGACY_8259_PROTOCOL
*This
,