1 /** @file 2 Driver implementing the Tiano Legacy 8259 Protocol 3 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. 9 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. 12 13 **/ 14 15 #ifndef _8259_H__ 16 #define _8259_H__ 17 18 #include <FrameworkDxe.h> 19 20 #include <Protocol/Legacy8259.h> 21 #include <Protocol/PciIo.h> 22 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> 28 29 #include <IndustryStandard/Pci.h> 30 31 // 8259 Hardware definitions 32 33 #define LEGACY_MODE_BASE_VECTOR_MASTER 0x08 34 #define LEGACY_MODE_BASE_VECTOR_SLAVE 0x70 35 36 #define PROTECTED_MODE_BASE_VECTOR_MASTER 0x68 37 #define PROTECTED_MODE_BASE_VECTOR_SLAVE 0x70 38 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 45 46 #define LEGACY_8259_EOI 0x20 47 48 // Protocol Function Prototypes 49 50 /** 51 Sets the base address for the 8259 master and slave PICs. 52 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. 56 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. 59 60 **/ 61 EFI_STATUS 62 EFIAPI 63 Interrupt8259SetVectorBase ( 64 IN EFI_LEGACY_8259_PROTOCOL *This, 65 IN UINT8 MasterBase, 66 IN UINT8 SlaveBase 67 ); 68 69 /** 70 Gets the current 16-bit real mode and 32-bit protected-mode IRQ masks. 71 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. 77 78 @retval EFI_SUCCESS The 8259 PIC was programmed successfully. 79 @retval EFI_DEVICE_ERROR There was an error while reading the 8259 PIC. 80 81 **/ 82 EFI_STATUS 83 EFIAPI 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 90 ); 91 92 /** 93 Sets the current 16-bit real mode and 32-bit protected-mode IRQ masks. 94 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. 100 101 @retval EFI_SUCCESS The 8259 PIC was programmed successfully. 102 @retval EFI_DEVICE_ERROR There was an error while writing the 8259 PIC. 103 104 **/ 105 EFI_STATUS 106 EFIAPI 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 113 ); 114 115 /** 116 Sets the mode of the PICs. 117 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. 122 123 @retval EFI_SUCCESS The mode was set successfully. 124 @retval EFI_INVALID_PARAMETER The mode was not set. 125 126 **/ 127 EFI_STATUS 128 EFIAPI 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 134 ); 135 136 /** 137 Translates the IRQ into a vector. 138 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. 142 143 @retval EFI_SUCCESS The Vector that matches Irq was returned. 144 @retval EFI_INVALID_PARAMETER Irq is not valid. 145 146 **/ 147 EFI_STATUS 148 EFIAPI 149 Interrupt8259GetVector ( 150 IN EFI_LEGACY_8259_PROTOCOL *This, 151 IN EFI_8259_IRQ Irq, 152 OUT UINT8 *Vector 153 ); 154 155 /** 156 Enables the specified IRQ. 157 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. 161 162 @retval EFI_SUCCESS The Irq was enabled on the 8259 PIC. 163 @retval EFI_INVALID_PARAMETER The Irq is not valid. 164 165 **/ 166 EFI_STATUS 167 EFIAPI 168 Interrupt8259EnableIrq ( 169 IN EFI_LEGACY_8259_PROTOCOL *This, 170 IN EFI_8259_IRQ Irq, 171 IN BOOLEAN LevelTriggered 172 ); 173 174 /** 175 Disables the specified IRQ. 176 177 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance. 178 @param[in] Irq IRQ0-IRQ15. 179 180 @retval EFI_SUCCESS The Irq was disabled on the 8259 PIC. 181 @retval EFI_INVALID_PARAMETER The Irq is not valid. 182 183 **/ 184 EFI_STATUS 185 EFIAPI 186 Interrupt8259DisableIrq ( 187 IN EFI_LEGACY_8259_PROTOCOL *This, 188 IN EFI_8259_IRQ Irq 189 ); 190 191 /** 192 Reads the PCI configuration space to get the interrupt number that is assigned to the card. 193 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. 197 198 @retval EFI_SUCCESS The interrupt line value was read successfully. 199 200 **/ 201 EFI_STATUS 202 EFIAPI 203 Interrupt8259GetInterruptLine ( 204 IN EFI_LEGACY_8259_PROTOCOL *This, 205 IN EFI_HANDLE PciHandle, 206 OUT UINT8 *Vector 207 ); 208 209 /** 210 Issues the End of Interrupt (EOI) commands to PICs. 211 212 @param[in] This Indicates the EFI_LEGACY_8259_PROTOCOL instance. 213 @param[in] Irq The interrupt for which to issue the EOI command. 214 215 @retval EFI_SUCCESS The EOI command was issued. 216 @retval EFI_INVALID_PARAMETER The Irq is not valid. 217 218 **/ 219 EFI_STATUS 220 EFIAPI 221 Interrupt8259EndOfInterrupt ( 222 IN EFI_LEGACY_8259_PROTOCOL *This, 223 IN EFI_8259_IRQ Irq 224 ); 225 226 #endif 227