├── EfiPkg ├── Bus │ └── Lpc │ │ └── AppleSmcDxe │ │ ├── AppleSmcDxe.inf │ │ ├── SmcIo.c │ │ ├── SmcIoInternal.h │ │ ├── SmcMmio.c │ │ ├── SmcPmio.c │ │ └── VirtualSmc.c ├── EfiPkg.dsc ├── Library │ ├── AcpiTscTimerLib │ │ ├── BaseTscTimerLib.c │ │ ├── BaseTscTimerLib.inf │ │ ├── DxeTscTimerLib.c │ │ ├── DxeTscTimerLib.inf │ │ ├── PeiTscTimerLib.c │ │ ├── PeiTscTimerLib.inf │ │ ├── TscTimerLibInternal.h │ │ └── TscTimerLibShare.c │ ├── AppleBaseDebugLibInterrupt │ │ ├── AppleBaseDebugLibInterrupt.inf │ │ └── DebugLib.c │ ├── AppleBaseStackCheckLib │ │ ├── AppleBaseStackCheckLib.inf │ │ ├── AppleBaseStackCheckLibGcc.c │ │ ├── AppleBaseStackCheckLibNull.c │ │ ├── Ia32 │ │ │ └── CheckStackCanary.S │ │ └── X64 │ │ │ └── CheckStackCanary.S │ ├── AppleCpuExtensionsLib │ │ ├── AppleCpuExtensionsLib.inf │ │ ├── EnableCpuExtensionsNull.c │ │ └── Ia32X64 │ │ │ ├── EnableCpuExtensions.c │ │ │ ├── EnableSseAvx.nasm │ │ │ └── EnableSseAvxGccInline.c │ ├── AppleDataHubLib │ │ ├── AppleDataHubLib.c │ │ └── AppleDataHubLib.inf │ ├── AppleDxeDebugPrintErrorLevelLib │ │ ├── AppleDxeDebugPrintErrorLevelLib.c │ │ └── AppleDxeDebugPrintErrorLevelLib.inf │ ├── AppleEventLib │ │ ├── AppleEventLib.c │ │ └── AppleEventLib.inf │ ├── AppleInterruptLib │ │ ├── AppleInterruptLib.inf │ │ ├── Ia32 │ │ │ ├── Interrupt.S │ │ │ └── Interrupt.nasm │ │ ├── InterruptNull.c │ │ └── X64 │ │ │ ├── Interrupt.S │ │ │ └── Interrupt.nasm │ ├── AppleSmbiosLib │ │ ├── AppleSmbiosLib.c │ │ └── AppleSmbiosLib.inf │ ├── BiosIdLib │ │ ├── BiosIdLib.c │ │ └── BiosIdLib.inf │ ├── UefiApplicationEntryPoint │ │ ├── ApplicationEntryPoint.c │ │ ├── Ia32 │ │ │ └── _ModuleEntryPoint.S │ │ ├── UefiApplicationEntryPoint.inf │ │ ├── X64 │ │ │ └── _ModuleEntryPoint.S │ │ └── _ModuleEntryPoint.c │ └── UefiDriverEntryPoint │ │ ├── DriverEntryPoint.c │ │ ├── Ia32 │ │ └── _ModuleEntryPoint.S │ │ ├── UefiDriverEntryPoint.inf │ │ ├── X64 │ │ └── _ModuleEntryPoint.S │ │ └── _ModuleEntryPoint.c ├── Platform │ ├── AppleBootPolicyDxe │ │ ├── AppleBootPolicy.c │ │ └── AppleBootPolicyDxe.inf │ ├── AppleEventDxe │ │ ├── AppleEvent.c │ │ ├── AppleEventDxe.inf │ │ ├── AppleEventInternal.h │ │ ├── AppleKeyMap.c │ │ ├── EventQueue.c │ │ ├── KeyHandler.c │ │ └── PointerHandler.c │ ├── AppleKeyMapAggregatorDxe │ │ ├── AppleKeyMapAggregator.c │ │ └── AppleKeyMapAggregatorDxe.inf │ ├── ApplePlatformInfoDatabase │ │ └── Dxe │ │ │ ├── ApplePlatformInfoDatabase.c │ │ │ └── ApplePlatformInfoDatabaseDxe.inf │ ├── ApplePlatformSecurityPolicyDxe │ │ └── ApplePlatformSecurityPolicy.c │ ├── EfiDevicePathPropertyDatabaseDxe │ │ ├── EfiDevicePathPropertyDatabase.c │ │ └── EfiDevicePathPropertyDatabaseDxe.inf │ ├── EfiOSInfoDxe │ │ ├── EfiOSInfo.c │ │ └── EfiOSInfoDxe.inf │ └── UserInterfaceThemeDriverDxe │ │ ├── UserInterfaceThemeDriver.c │ │ └── UserInterfaceThemeDriverDxe.inf └── Universal │ └── AppleSmbiosDxe │ ├── AppleSmbios.c │ ├── AppleSmbiosDxe.inf │ ├── AppleSmbiosInternal.h │ ├── Ia32X64 │ └── InternalGetProcessorClass.c │ └── InternalGetProcessorClass.c ├── StoragePkg └── PartitionDxe │ ├── Apm.c │ ├── Apm.h │ ├── ComponentName.c │ ├── ElTorito.c │ ├── ElTorito.h │ ├── Gpt.c │ ├── Gpt.h │ ├── Mbr.c │ ├── Mbr.h │ ├── Partition.c │ ├── Partition.h │ └── PartitionDxe.inf └── UsbPkg └── Bus └── Usb └── UsbKbDxe ├── AppleKeyMap.c ├── ComponentName.c ├── EfiKey.c ├── EfiKey.h ├── Keyboard.c ├── Keyboard.h └── UsbKbDxe.inf /EfiPkg/Bus/Lpc/AppleSmcDxe/AppleSmcDxe.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | BASE_NAME = AppleSmcDxe 3 | FILE_GUID = DB8AF09A-34E3-4A7B-8225-8C5B0C059EB8 4 | MODULE_TYPE = DXE_DRIVER 5 | ENTRY_POINT = AppleSmcMain 6 | INF_VERSION = 0x00010005 7 | 8 | [Packages] 9 | MdePkg/MdePkg.dec 10 | EfiPkg/EfiPkg.dec 11 | 12 | [Guids] 13 | gAppleSmcMmioAddressHobGuid ## SOMETIMES_CONSUMES 14 | 15 | [Protocols] 16 | gAppleSmcIoProtocolGuid ## PRODUCES 17 | 18 | [LibraryClasses] 19 | BaseMemoryLib 20 | DebugLib 21 | MemoryAllocationLib 22 | HobLib 23 | IoLib 24 | TimerLib 25 | UefiLib 26 | UefiBootServicesTableLib 27 | UefiDriverEntryPoint 28 | 29 | [Sources] 30 | SmcIo.c 31 | SmcPmio.c 32 | SmcMmio.c 33 | VirtualSmc.c 34 | 35 | [Depex] 36 | gEfiPcdProtocolGuid 37 | -------------------------------------------------------------------------------- /EfiPkg/Bus/Lpc/AppleSmcDxe/SmcIoInternal.h: -------------------------------------------------------------------------------- 1 | #ifndef SMC_IO_INTERNAL_H_ 2 | #define SMC_IO_INTERNAL_H_ 3 | 4 | #include 5 | 6 | // SMC_DEV_SIGNATURE 7 | #define SMC_DEV_SIGNATURE \ 8 | SIGNATURE_64 ('A', 'p', 'p', 'l', 'e', 'S', 'm', 'c') 9 | 10 | // SMC_DEV_FROM_THIS 11 | #define SMC_DEV_FROM_THIS(x) CR ((x), SMC_DEV, SmcIo, SMC_DEV_SIGNATURE) 12 | 13 | // SMC_KEY_PRESENCE_MAP 14 | typedef struct { 15 | SMC_KEY Key; 16 | BOOLEAN Present; 17 | } SMC_KEY_PRESENCE_MAP; 18 | 19 | // SMC_DEV 20 | typedef struct SMC_DEV { 21 | UINT64 Signature; ///< 22 | EFI_HANDLE Handle; ///< 23 | EFI_LOCK Lock; ///< 24 | APPLE_SMC_IO_PROTOCOL SmcIo; ///< 25 | UINT32 KeyPresenceMapLength; ///< 26 | UINT32 MaxKeyPresenceMapLength; ///< 27 | SMC_KEY_PRESENCE_MAP *KeyPresenceMap; ///< 28 | } SMC_DEV; 29 | 30 | // SmcIoSmcReadStatus 31 | SMC_STATUS 32 | SmcIoSmcReadStatus ( 33 | IN SMC_DEV *SmcDev 34 | ); 35 | 36 | // SmcIoSmcReadResult 37 | SMC_RESULT 38 | SmcIoSmcReadResult ( 39 | IN SMC_DEV *SmcDev 40 | ); 41 | 42 | // SmcIoSmcWriteCommand 43 | EFI_STATUS 44 | SmcIoSmcWriteCommand ( 45 | IN SMC_DEV *SmcDev, 46 | IN SMC_COMMAND Command 47 | ); 48 | 49 | // SmcIoSmcReadData8 50 | EFI_STATUS 51 | SmcIoSmcReadData8 ( 52 | IN SMC_DEV *SmcDev, 53 | OUT UINT8 *Data 54 | ); 55 | 56 | // SmcIoSmcReadData16 57 | EFI_STATUS 58 | SmcIoSmcReadData16 ( 59 | IN SMC_DEV *SmcDev, 60 | IN UINT16 *Data 61 | ); 62 | 63 | // SmcIoSmcReadData32 64 | EFI_STATUS 65 | SmcIoSmcReadData32 ( 66 | IN SMC_DEV *SmcDev, 67 | IN UINT32 *Data 68 | ); 69 | 70 | // SmcIoSmcWriteData8 71 | EFI_STATUS 72 | SmcIoSmcWriteData8 ( 73 | IN SMC_DEV *SmcDev, 74 | IN SMC_DATA Data 75 | ); 76 | 77 | // SmcIoSmcWriteData16 78 | EFI_STATUS 79 | SmcIoSmcWriteData16 ( 80 | IN SMC_DEV *SmcDev, 81 | IN UINT16 Data 82 | ); 83 | 84 | // SmcIoSmcWriteData32 85 | EFI_STATUS 86 | SmcIoSmcWriteData32 ( 87 | IN SMC_DEV *SmcDev, 88 | IN UINT32 Data 89 | ); 90 | 91 | // SmcIoSmcTimeoutWaitingForBusyClear 92 | EFI_STATUS 93 | SmcIoSmcTimeoutWaitingForBusyClear ( 94 | IN SMC_DEV *SmcDev 95 | ); 96 | 97 | // SmcIoSmcTimeoutWaitingLongForBusyClear 98 | EFI_STATUS 99 | SmcIoSmcTimeoutWaitingLongForBusyClear ( 100 | IN SMC_DEV *SmcDev 101 | ); 102 | 103 | // SmcIoSmcSmcInABadState 104 | EFI_STATUS 105 | SmcIoSmcSmcInABadState ( 106 | IN SMC_DEV *SmcDev 107 | ); 108 | 109 | // SMC MMIO 110 | 111 | // SmcReadValueMmio 112 | EFI_STATUS 113 | SmcReadValueMmio ( 114 | IN SMC_ADDRESS BaseAddress, 115 | IN SMC_KEY Key, 116 | IN OUT SMC_DATA_SIZE *Size, 117 | OUT SMC_DATA *Value 118 | ); 119 | 120 | // SmcWriteValueMmio 121 | EFI_STATUS 122 | SmcWriteValueMmio ( 123 | IN SMC_ADDRESS BaseAddress, 124 | IN SMC_KEY Key, 125 | IN UINT32 Size, 126 | IN SMC_DATA *Value 127 | ); 128 | 129 | // SmcGetKeyFromIndexMmio 130 | EFI_STATUS 131 | SmcGetKeyFromIndexMmio ( 132 | IN SMC_ADDRESS BaseAddress, 133 | IN SMC_KEY_INDEX Index, 134 | IN SMC_KEY *Key 135 | ); 136 | 137 | // SmcGetKeyInfoMmio 138 | EFI_STATUS 139 | SmcGetKeyInfoMmio ( 140 | IN SMC_ADDRESS BaseAddress, 141 | IN SMC_KEY Key, 142 | IN SMC_DATA_SIZE *Size, 143 | IN SMC_KEY_TYPE *Type, 144 | IN SMC_KEY_ATTRIBUTES *Attributes 145 | ); 146 | 147 | // SmcFlashTypeMmio 148 | EFI_STATUS 149 | SmcFlashTypeMmio ( 150 | IN SMC_ADDRESS BaseAddress, 151 | IN SMC_FLASH_TYPE Type 152 | ); 153 | 154 | // SmcFlashWriteMmio 155 | EFI_STATUS 156 | SmcFlashWriteMmio ( 157 | IN SMC_ADDRESS BaseAddress, 158 | IN UINT32 Unknown, 159 | IN UINT32 Size, 160 | IN SMC_DATA *Data 161 | ); 162 | 163 | // SmcFlashAuthMmio 164 | EFI_STATUS 165 | SmcFlashAuthMmio ( 166 | IN SMC_ADDRESS BaseAddress, 167 | IN UINT32 Size, 168 | IN SMC_DATA *Data 169 | ); 170 | 171 | // SmcMmioInterface 172 | BOOLEAN 173 | SmcMmioInterface ( 174 | IN SMC_ADDRESS BaseAddress 175 | ); 176 | 177 | // SmcResetMmio 178 | EFI_STATUS 179 | SmcResetMmio ( 180 | IN SMC_ADDRESS BaseAddress, 181 | IN UINT32 Mode 182 | ); 183 | 184 | // Virtual SMC 185 | 186 | // SmcIoVirtualSmcReadValue 187 | EFI_STATUS 188 | SmcIoVirtualSmcReadValue ( 189 | IN APPLE_SMC_IO_PROTOCOL *This, 190 | IN SMC_KEY Key, 191 | IN SMC_DATA_SIZE Size, 192 | OUT SMC_DATA *Value 193 | ); 194 | 195 | // SmcIoVirtualSmcWriteValue 196 | EFI_STATUS 197 | SmcIoVirtualSmcWriteValue ( 198 | IN APPLE_SMC_IO_PROTOCOL *This, 199 | IN SMC_KEY Key, 200 | IN SMC_DATA_SIZE Size, 201 | OUT SMC_DATA *Value 202 | ); 203 | 204 | // SmcIoVirtualSmcMakeKey 205 | EFI_STATUS 206 | SmcIoVirtualSmcMakeKey ( 207 | IN CHAR8 *Name, 208 | OUT SMC_KEY *Key 209 | ); 210 | 211 | // SmcGetyKeyCount 212 | EFI_STATUS 213 | SmcIoVirtualSmcGetKeyCount ( 214 | IN APPLE_SMC_IO_PROTOCOL *This, 215 | OUT UINT32 *Count 216 | ); 217 | 218 | // SmcIoVirtualSmcGetKeyFromIndex 219 | EFI_STATUS 220 | SmcIoVirtualSmcGetKeyFromIndex ( 221 | IN APPLE_SMC_IO_PROTOCOL *This, 222 | IN SMC_KEY_INDEX Index, 223 | OUT SMC_KEY *Key 224 | ); 225 | 226 | // SmcIoVirtualSmcGetKeyInfo 227 | EFI_STATUS 228 | SmcIoVirtualSmcGetKeyInfo ( 229 | IN APPLE_SMC_IO_PROTOCOL *This, 230 | IN SMC_KEY Key, 231 | OUT SMC_DATA_SIZE *Size, 232 | OUT SMC_KEY_TYPE *Type, 233 | OUT SMC_KEY_ATTRIBUTES *Attributes 234 | ); 235 | 236 | // SmcIoVirtualSmcReset 237 | EFI_STATUS 238 | SmcIoVirtualSmcReset ( 239 | IN APPLE_SMC_IO_PROTOCOL *This, 240 | IN UINT32 Mode 241 | ); 242 | 243 | // SmcIoVirtualSmcFlashType 244 | EFI_STATUS 245 | SmcIoVirtualSmcFlashType ( 246 | IN APPLE_SMC_IO_PROTOCOL *This, 247 | IN SMC_FLASH_TYPE Type 248 | ); 249 | 250 | // SmcIoVirtualSmcFlashWrite 251 | EFI_STATUS 252 | SmcIoVirtualSmcFlashWrite ( 253 | IN APPLE_SMC_IO_PROTOCOL *This, 254 | IN UINT32 Unknown, 255 | IN SMC_FLASH_SIZE Size, 256 | IN SMC_DATA *Data 257 | ); 258 | 259 | // SmcIoVirtualSmcFlashAuth 260 | EFI_STATUS 261 | SmcIoVirtualSmcFlashAuth ( 262 | IN APPLE_SMC_IO_PROTOCOL *This, 263 | IN SMC_FLASH_SIZE Size, 264 | IN SMC_DATA *Data 265 | ); 266 | 267 | #endif // SMC_IO_INTERNAL_H_ 268 | -------------------------------------------------------------------------------- /EfiPkg/Bus/Lpc/AppleSmcDxe/SmcPmio.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "SmcIoInternal.h" 11 | 12 | // ITERATION_STALL 13 | #define ITERATION_STALL 50 14 | 15 | // SmcIoSmcReadStatus 16 | SMC_STATUS 17 | SmcIoSmcReadStatus ( 18 | IN SMC_DEV *SmcDev 19 | ) 20 | { 21 | return IoRead8 (SmcDev->SmcIo.Address + SMC_PORT_OFFSET_STATUS); 22 | } 23 | 24 | // SmcIoSmcReadResult 25 | SMC_RESULT 26 | SmcIoSmcReadResult ( 27 | IN SMC_DEV *SmcDev 28 | ) 29 | { 30 | return IoRead8 (SmcDev->SmcIo.Address + SMC_PORT_OFFSET_RESULT); 31 | } 32 | 33 | // SmcIoSmcWriteCommand 34 | EFI_STATUS 35 | SmcIoSmcWriteCommand ( 36 | IN SMC_DEV *SmcDev, 37 | IN SMC_COMMAND Command 38 | ) 39 | { 40 | EFI_STATUS Status; 41 | 42 | UINTN Index; 43 | SMC_STATUS SmcStatus; 44 | 45 | Index = 60000; 46 | SmcStatus = SmcIoSmcReadStatus (SmcDev); 47 | 48 | while ((SmcStatus & SMC_STATUS_IB_CLOSED) != 0) { 49 | SmcStatus = SmcIoSmcReadStatus (SmcDev); 50 | 51 | if (Index == 0) { 52 | Status = EFI_TIMEOUT; 53 | goto Done; 54 | } 55 | 56 | --Index; 57 | 58 | gBS->Stall (ITERATION_STALL); 59 | } 60 | 61 | IoWrite8 ((SmcDev->SmcIo.Address + SMC_PORT_OFFSET_COMMAND), Command); 62 | 63 | Index = 20000; 64 | 65 | while ((SmcStatus & SMC_STATUS_BUSY) == 0) { 66 | SmcStatus = SmcIoSmcReadStatus (SmcDev); 67 | 68 | if (Index == 0) { 69 | Status = EFI_TIMEOUT; 70 | goto Done; 71 | } 72 | 73 | --Index; 74 | 75 | gBS->Stall (ITERATION_STALL); 76 | } 77 | 78 | Status = EFI_SUCCESS; 79 | 80 | Done: 81 | return Status; 82 | } 83 | 84 | // SmcIoSmcReadData8 85 | EFI_STATUS 86 | SmcIoSmcReadData8 ( 87 | IN SMC_DEV *SmcDev, 88 | OUT UINT8 *Data 89 | ) 90 | { 91 | EFI_STATUS Status; 92 | 93 | UINTN Index; 94 | SMC_STATUS SmcStatus; 95 | SMC_DATA Buffer; 96 | 97 | Index = 60000; 98 | SmcStatus = SmcIoSmcReadStatus (SmcDev); 99 | 100 | while ((SmcStatus & (SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY)) == SMC_STATUS_BUSY) { 101 | SmcStatus = SmcIoSmcReadStatus (SmcDev); 102 | 103 | if (Index == 0) { 104 | Status = EFI_TIMEOUT; 105 | goto Done; 106 | } 107 | 108 | --Index; 109 | 110 | gBS->Stall (ITERATION_STALL); 111 | } 112 | 113 | if ((SmcStatus & SMC_STATUS_BUSY) != 0) { 114 | Buffer = IoRead8 (SmcDev->SmcIo.Address + SMC_PORT_OFFSET_DATA); 115 | 116 | Status = EFI_SUCCESS; 117 | *Data = Buffer; 118 | } else { 119 | Status = EFI_NOT_READY; 120 | } 121 | 122 | Done: 123 | return Status; 124 | } 125 | 126 | // SmcIoSmcReadData16 127 | EFI_STATUS 128 | SmcIoSmcReadData16 ( 129 | IN SMC_DEV *SmcDev, 130 | IN UINT16 *Data 131 | ) 132 | { 133 | EFI_STATUS Status; 134 | 135 | UINT8 Value[2]; 136 | 137 | Status = SmcIoSmcReadData8 (SmcDev, &Value[1]); 138 | 139 | if (!EFI_ERROR (Status)) { 140 | Status = SmcIoSmcReadData8 (SmcDev, &Value[0]); 141 | 142 | if (!EFI_ERROR (Status)) { 143 | CopyMem ((VOID *)Data, (VOID *)&Value[0], sizeof (Value)); 144 | } 145 | } 146 | 147 | return Status; 148 | } 149 | 150 | // SmcIoSmcReadData32 151 | EFI_STATUS 152 | SmcIoSmcReadData32 ( 153 | IN SMC_DEV *SmcDev, 154 | IN UINT32 *Data 155 | ) 156 | { 157 | EFI_STATUS Status; 158 | 159 | UINT16 Value[2]; 160 | 161 | Status = SmcIoSmcReadData16 (SmcDev, &Value[1]); 162 | 163 | if (!EFI_ERROR (Status)) { 164 | Status = SmcIoSmcReadData16 (SmcDev, &Value[0]); 165 | 166 | if (!EFI_ERROR (Status)) { 167 | CopyMem ((VOID *)Data, (VOID *)&Value[0], sizeof (Value)); 168 | } 169 | } 170 | 171 | return Status; 172 | } 173 | 174 | // SmcIoSmcWriteData8 175 | EFI_STATUS 176 | SmcIoSmcWriteData8 ( 177 | IN SMC_DEV *SmcDev, 178 | IN SMC_DATA Data 179 | ) 180 | { 181 | EFI_STATUS Status; 182 | 183 | UINTN RemainingIterations; 184 | SMC_STATUS SmcStatus; 185 | 186 | RemainingIterations = 60000; 187 | SmcStatus = SmcIoSmcReadStatus (SmcDev); 188 | 189 | while ((SmcStatus & SMC_STATUS_IB_CLOSED) != 0) { 190 | SmcStatus = SmcIoSmcReadStatus (SmcDev); 191 | 192 | if (RemainingIterations == 0) { 193 | Status = EFI_TIMEOUT; 194 | goto Done; 195 | } 196 | 197 | --RemainingIterations; 198 | 199 | gBS->Stall (ITERATION_STALL); 200 | } 201 | 202 | if ((SmcStatus & SMC_STATUS_BUSY) != 0) { 203 | IoWrite8 ((SmcDev->SmcIo.Address + SMC_PORT_OFFSET_DATA), Data); 204 | 205 | Status = EFI_SUCCESS; 206 | } else { 207 | Status = EFI_NOT_READY; 208 | } 209 | 210 | Done: 211 | return Status; 212 | } 213 | 214 | // SmcIoSmcWriteData16 215 | EFI_STATUS 216 | SmcIoSmcWriteData16 ( 217 | IN SMC_DEV *SmcDev, 218 | IN UINT16 Data 219 | ) 220 | { 221 | EFI_STATUS Status; 222 | 223 | UINT8 *DataPtr; 224 | 225 | DataPtr = (UINT8 *)&Data; 226 | 227 | Status = SmcIoSmcWriteData8 (SmcDev, DataPtr[1]); 228 | 229 | if (!EFI_ERROR (Status)) { 230 | Status = SmcIoSmcWriteData8 (SmcDev, DataPtr[0]); 231 | } 232 | 233 | return Status; 234 | } 235 | 236 | // SmcIoSmcWriteData32 237 | EFI_STATUS 238 | SmcIoSmcWriteData32 ( 239 | IN SMC_DEV *SmcDev, 240 | IN UINT32 Data 241 | ) 242 | { 243 | EFI_STATUS Status; 244 | 245 | UINT8 *DataPtr; 246 | 247 | DataPtr = (UINT8 *)&Data; 248 | 249 | Status = SmcIoSmcWriteData8 (SmcDev, DataPtr[3]); 250 | 251 | if (!EFI_ERROR (Status)) { 252 | Status = SmcIoSmcWriteData8 (SmcDev, DataPtr[2]); 253 | 254 | if (!EFI_ERROR (Status)) { 255 | Status = SmcIoSmcWriteData8 (SmcDev, DataPtr[1]); 256 | 257 | if (!EFI_ERROR (Status)) { 258 | Status = SmcIoSmcWriteData8 (SmcDev, DataPtr[0]); 259 | } 260 | } 261 | } 262 | 263 | return Status; 264 | } 265 | 266 | // SmcIoSmcTimeoutWaitingForBusyClear 267 | EFI_STATUS 268 | SmcIoSmcTimeoutWaitingForBusyClear ( 269 | IN SMC_DEV *SmcDev 270 | ) 271 | { 272 | EFI_STATUS Status; 273 | 274 | SMC_STATUS SmcStatus; 275 | UINTN Index; 276 | 277 | Index = 20000; 278 | SmcStatus = SmcIoSmcReadStatus (SmcDev); 279 | 280 | while ((SmcStatus & SMC_STATUS_BUSY) != 0) { 281 | SmcStatus = SmcIoSmcReadStatus (SmcDev); 282 | 283 | if (Index == 0) { 284 | Status = EFI_TIMEOUT; 285 | goto Done; 286 | } 287 | 288 | --Index; 289 | 290 | gBS->Stall (ITERATION_STALL); 291 | } 292 | 293 | Status = EFI_SUCCESS; 294 | 295 | Done: 296 | return Status; 297 | } 298 | 299 | // SmcIoSmcTimeoutWaitingLongForBusyClear 300 | EFI_STATUS 301 | SmcIoSmcTimeoutWaitingLongForBusyClear ( 302 | IN SMC_DEV *SmcDev 303 | ) 304 | { 305 | EFI_STATUS Status; 306 | 307 | SMC_STATUS SmcStatus; 308 | UINTN Index; 309 | 310 | Index = 100000; 311 | SmcStatus = SmcIoSmcReadStatus (SmcDev); 312 | 313 | while ((SmcStatus & SMC_STATUS_BUSY) != 0) { 314 | SmcStatus = SmcIoSmcReadStatus (SmcDev); 315 | 316 | if (Index == 0) { 317 | Status = EFI_TIMEOUT; 318 | goto Done; 319 | } 320 | 321 | --Index; 322 | 323 | gBS->Stall (ITERATION_STALL); 324 | } 325 | 326 | Status = EFI_SUCCESS; 327 | 328 | Done: 329 | return Status; 330 | } 331 | 332 | // SmcIoSmcSmcInABadState 333 | EFI_STATUS 334 | SmcIoSmcSmcInABadState ( 335 | IN SMC_DEV *SmcDev 336 | ) 337 | { 338 | EFI_STATUS Status; 339 | 340 | Status = SmcIoSmcTimeoutWaitingForBusyClear (SmcDev); 341 | 342 | if (EFI_ERROR (Status)) { 343 | Status = SmcIoSmcWriteCommand (SmcDev, SmcCmdReadValue); 344 | 345 | if (!EFI_ERROR (Status)) { 346 | Status = SmcIoSmcTimeoutWaitingForBusyClear (SmcDev); 347 | } 348 | } 349 | 350 | return Status; 351 | } 352 | -------------------------------------------------------------------------------- /EfiPkg/Bus/Lpc/AppleSmcDxe/VirtualSmc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include "SmcIoInternal.h" 9 | 10 | #pragma pack (1) 11 | 12 | // SMC_KEY_VALUE 13 | typedef PACKED struct { 14 | SMC_KEY Key; 15 | UINT8 Size; 16 | UINT8 Data[23]; 17 | } SMC_KEY_VALUE; 18 | 19 | #pragma pack () 20 | 21 | // gSoftwareSmcKeyValueList 22 | STATIC SMC_KEY_VALUE gSoftwareSmcKeyValueList[] = { 23 | { 24 | SMC_MAKE_KEY ('B', 'N', 'u', 'm'), 25 | 1, 26 | { 27 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 28 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 29 | } 30 | }, 31 | { 32 | SMC_MAKE_KEY ('B', 'A', 'T', 'P'), 33 | 1, 34 | { 35 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 37 | } 38 | }, 39 | { 40 | SMC_MAKE_KEY ('B', 'R', 'S', 'C'), 41 | 2, 42 | { 43 | 0x64, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 45 | } 46 | }, 47 | { 48 | SMC_MAKE_KEY ('B', 'I', 'S', 'n'), 49 | 1, 50 | { 51 | 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 53 | } 54 | }, 55 | { 56 | SMC_MAKE_KEY ('M', 'S', 'L', 'D'), 57 | 1, 58 | { 59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 61 | } 62 | }, 63 | { 64 | SMC_MAKE_KEY ('R', 'P', 'l', 't'), 65 | 3, 66 | { 67 | 0x7A, 0x6F, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 69 | } 70 | }, 71 | { 72 | SMC_MAKE_KEY ('R', 'E', 'V', ' '), 73 | 6, 74 | { 75 | 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 76 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 77 | } 78 | }, 79 | { 80 | 0, 81 | 0, 82 | { 83 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 84 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 85 | } 86 | } 87 | }; 88 | 89 | // SmcIoVirtualSmcReadValue 90 | EFI_STATUS 91 | SmcIoVirtualSmcReadValue ( 92 | IN APPLE_SMC_IO_PROTOCOL *This, 93 | IN SMC_KEY Key, 94 | IN SMC_DATA_SIZE Size, 95 | OUT SMC_DATA *Value 96 | ) 97 | { 98 | EFI_STATUS Status; 99 | 100 | SMC_KEY_VALUE *Walker; 101 | UINTN Index; 102 | 103 | Status = EFI_INVALID_PARAMETER; 104 | 105 | if ((This != NULL) && (Value != NULL)) { 106 | Status = EFI_UNSUPPORTED; 107 | 108 | if (gSoftwareSmcKeyValueList != NULL) { 109 | Index = 1; 110 | 111 | Walker = &gSoftwareSmcKeyValueList[0]; 112 | 113 | while (Walker->Key != 0) { 114 | if (Walker->Key == Key) { 115 | // BUG: Size may be smaller - Buffer overflow. 116 | 117 | Size = Walker->Size; 118 | 119 | CopyMem ( 120 | (VOID *)Value, 121 | (VOID *)&Walker->Data[0], 122 | Walker->Size 123 | ); 124 | 125 | Status = EFI_SUCCESS; 126 | 127 | break; 128 | } 129 | 130 | Walker = &gSoftwareSmcKeyValueList[Index]; 131 | } 132 | } 133 | } 134 | 135 | return Status; 136 | } 137 | 138 | // SmcIoVirtualSmcWriteValue 139 | EFI_STATUS 140 | SmcIoVirtualSmcWriteValue ( 141 | IN APPLE_SMC_IO_PROTOCOL *This, 142 | IN SMC_KEY Key, 143 | IN SMC_DATA_SIZE Size, 144 | OUT SMC_DATA *Value 145 | ) 146 | { 147 | return EFI_SUCCESS; 148 | } 149 | 150 | // SmcIoVirtualSmcMakeKey 151 | EFI_STATUS 152 | SmcIoVirtualSmcMakeKey ( 153 | IN CHAR8 *Name, 154 | OUT SMC_KEY *Key 155 | ) 156 | { 157 | // TODO: Implement. 158 | 159 | return EFI_SUCCESS; 160 | } 161 | 162 | // SmcGetyKeyCount 163 | EFI_STATUS 164 | SmcIoVirtualSmcGetKeyCount ( 165 | IN APPLE_SMC_IO_PROTOCOL *This, 166 | OUT UINT32 *Count 167 | ) 168 | { 169 | // TODO: Implement. 170 | 171 | return EFI_SUCCESS; 172 | } 173 | 174 | // SmcIoVirtualSmcGetKeyFromIndex 175 | EFI_STATUS 176 | SmcIoVirtualSmcGetKeyFromIndex ( 177 | IN APPLE_SMC_IO_PROTOCOL *This, 178 | IN SMC_KEY_INDEX Index, 179 | OUT SMC_KEY *Key 180 | ) 181 | { 182 | // TODO: Implement. 183 | 184 | return EFI_SUCCESS; 185 | } 186 | 187 | // SmcIoVirtualSmcGetKeyInfo 188 | EFI_STATUS 189 | SmcIoVirtualSmcGetKeyInfo ( 190 | IN APPLE_SMC_IO_PROTOCOL *This, 191 | IN SMC_KEY Key, 192 | OUT SMC_DATA_SIZE *Size, 193 | OUT SMC_KEY_TYPE *Type, 194 | OUT SMC_KEY_ATTRIBUTES *Attributes 195 | ) 196 | { 197 | // TODO: Implement. 198 | 199 | return EFI_SUCCESS; 200 | } 201 | 202 | // SmcIoVirtualSmcReset 203 | EFI_STATUS 204 | SmcIoVirtualSmcReset ( 205 | IN APPLE_SMC_IO_PROTOCOL *This, 206 | IN UINT32 Mode 207 | ) 208 | { 209 | return EFI_SUCCESS; 210 | } 211 | 212 | // SmcIoVirtualSmcFlashType 213 | EFI_STATUS 214 | SmcIoVirtualSmcFlashType ( 215 | IN APPLE_SMC_IO_PROTOCOL *This, 216 | IN SMC_FLASH_TYPE Type 217 | ) 218 | { 219 | return EFI_SUCCESS; 220 | } 221 | 222 | // SmcIoVirtualSmcFlashWrite 223 | EFI_STATUS 224 | SmcIoVirtualSmcFlashWrite ( 225 | IN APPLE_SMC_IO_PROTOCOL *This, 226 | IN UINT32 Unknown, 227 | IN SMC_FLASH_SIZE Size, 228 | IN SMC_DATA *Data 229 | ) 230 | { 231 | return EFI_SUCCESS; 232 | } 233 | 234 | // SmcIoVirtualSmcFlashAuth 235 | EFI_STATUS 236 | SmcIoVirtualSmcFlashAuth ( 237 | IN APPLE_SMC_IO_PROTOCOL *This, 238 | IN SMC_FLASH_SIZE Size, 239 | IN SMC_DATA *Data 240 | ) 241 | { 242 | return EFI_SUCCESS; 243 | } 244 | -------------------------------------------------------------------------------- /EfiPkg/EfiPkg.dsc: -------------------------------------------------------------------------------- 1 | [Defines] 2 | PLATFORM_NAME = Efi 3 | PLATFORM_GUID = 0ADCC78E-2FDC-4491-998D-8684A7B602E9 4 | PLATFORM_VERSION = 2017.001 5 | DSC_SPECIFICATION = 0x00010006 6 | SUPPORTED_ARCHITECTURES = IA32|IPF|X64|EBC|ARM|AARCH64 7 | BUILD_TARGETS = DEBUG|NOOPT|RELEASE 8 | SKUID_IDENTIFIER = DEFAULT 9 | #OUTPUT_DIRECTORY = BuildResults/J137 10 | 11 | DEFINE STACK_PROTECTOR_ENABLE = TRUE 12 | 13 | DEFINE PEI_LTO_ENABLE = TRUE 14 | DEFINE DXE_LTO_ENABLE = TRUE 15 | 16 | [LibraryClasses] 17 | # 18 | # Entry point 19 | # 20 | PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf 21 | PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf 22 | DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf 23 | UefiDriverEntryPoint|EfiPkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf 24 | UefiApplicationEntryPoint|EfiPkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf 25 | # 26 | # Basic 27 | # 28 | BaseLib|MdePkg/Library/BaseLib/BaseLib.inf 29 | BaseMemoryLib|MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf 30 | PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf 31 | IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf 32 | # 33 | # UEFI & PI 34 | # 35 | UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf 36 | UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf 37 | UefiLib|MdePkg/Library/UefiLib/UefiLib.inf 38 | DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf 39 | # 40 | # Misc 41 | # 42 | DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf 43 | DebugLib|EfiPkg/Library/AppleBaseDebugLibInterrupt/AppleBaseDebugLibInterrupt.inf 44 | # 45 | # Generic Modules 46 | # 47 | UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf 48 | PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf 49 | # 50 | # Apple 51 | # 52 | AppleCpuExtensionsLib|EfiPkg/Library/AppleCpuExtensionsLib/AppleCpuExtensionsLib.inf 53 | AppleDataHubLib|EfiPkg/Library/AppleDataHubLib/AppleDataHubLib.inf 54 | AppleEventLib|EfiPkg/Library/AppleEventLib/AppleEventLib.inf 55 | AppleInterruptLib|EfiPkg/Library/AppleInterruptLib/AppleInterruptLib.inf 56 | AppleSmbiosLib|EfiPkg/Library/AppleSmbiosLib/AppleSmbiosLib.inf 57 | BiosIdLib|EfiPkg/Library/BiosIdLib/BiosIdLib.inf 58 | 59 | # 60 | # Since software stack checking may be heuristically enabled by the compiler 61 | # include BaseStackCheckLib unconditionally. 62 | # 63 | NULL|EfiPkg/Library/AppleBaseStackCheckLib/AppleBaseStackCheckLib.inf 64 | 65 | [LibraryClasses.common.PEI_CORE] 66 | HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf 67 | MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf 68 | ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf 69 | 70 | [LibraryClasses.common.PEIM] 71 | HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf 72 | MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf 73 | ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf 74 | 75 | [LibraryClasses.IA32.PEI_CORE, LibraryClasses.X64.PEI_CORE, LibraryClasses.IA32.PEIM, LibraryClasses.X64.PEIM] 76 | TimerLib|EfiPkg/Library/AcpiTscTimerLib/PeiTscTimerLib.inf 77 | 78 | [LibraryClasses.IPF] 79 | TimerLib|UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/SecPeiDxeTimerLibUefiCpu.inf 80 | 81 | [LibraryClasses.EBC] 82 | TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf 83 | 84 | [LibraryClasses.common.DXE_CORE] 85 | HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf 86 | MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf 87 | DebugPrintErrorLevelLib|EfiPkg/Library/AppleDxeDebugPrintErrorLevelLib/AppleDxeDebugPrintErrorLevelLib.inf 88 | ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf 89 | 90 | [LibraryClasses.IA32.DXE_CORE, LibraryClasses.X64.DXE_CORE, LibraryClasses.IA32.DXE_DRIVER, LibraryClasses.X64.DXE_DRIVER, LibraryClasses.IA32.DXE_RUNTIME_DRIVER, LibraryClasses.X64.DXE_RUNTIME_DRIVER, LibraryClasses.IA32.DXE_SMM_DRIVER, LibraryClasses.X64.DXE_SMM_DRIVER, LibraryClasses.IA32.UEFI_DRIVER, LibraryClasses.X64.UEFI_DRIVER, LibraryClasses.IA32.UEFI_APPLICATION, LibraryClasses.X64.UEFI_APPLICATION] 91 | TimerLib|EfiPkg/Library/AcpiTscTimerLib/DxeTscTimerLib.inf 92 | 93 | [LibraryClasses.common.DXE_DRIVER] 94 | HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf 95 | MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf 96 | DebugPrintErrorLevelLib|EfiPkg/Library/AppleDxeDebugPrintErrorLevelLib/AppleDxeDebugPrintErrorLevelLib.inf 97 | ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf 98 | 99 | [LibraryClasses.common.DXE_RUNTIME_DRIVER] 100 | HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf 101 | MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf 102 | DebugPrintErrorLevelLib|EfiPkg/Library/AppleDxeDebugPrintErrorLevelLib/AppleDxeDebugPrintErrorLevelLib.inf 103 | ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf 104 | 105 | [LibraryClasses.common.SMM_CORE] 106 | HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf 107 | MemoryAllocationLib|MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationLib.inf 108 | ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf 109 | 110 | [LibraryClasses.common.DXE_SMM_DRIVER] 111 | HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf 112 | MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf 113 | ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf 114 | 115 | [LibraryClasses.common.UEFI_DRIVER] 116 | HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf 117 | MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf 118 | DebugPrintErrorLevelLib|EfiPkg/Library/AppleDxeDebugPrintErrorLevelLib/AppleDxeDebugPrintErrorLevelLib.inf 119 | ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf 120 | 121 | [LibraryClasses.common.UEFI_APPLICATION] 122 | HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf 123 | MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf 124 | DebugPrintErrorLevelLib|EfiPkg/Library/AppleDxeDebugPrintErrorLevelLib/AppleDxeDebugPrintErrorLevelLib.inf 125 | ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf 126 | 127 | [LibraryClasses.ARM, LibraryClasses.AARCH64] 128 | # 129 | # It is not possible to prevent ARM compiler calls to generic intrinsic functions. 130 | # This library provides the instrinsic functions generated by a given compiler. 131 | # [LibraryClasses.ARM] and NULL mean link this library into all ARM images. 132 | # 133 | NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf 134 | 135 | ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf 136 | TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf 137 | ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf 138 | 139 | [PcdsFixedAtBuild] 140 | gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x11 141 | 142 | ## Indicates the maximum node number of linked list.

143 | # 0 - No node number check for linked list.
144 | # >0 - Maximum node number of linked list.
145 | # @Prompt Maximum Length of Linked List. 146 | gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|0 147 | 148 | [Components] 149 | EfiPkg/Bus/Lpc/AppleSmcDxe/AppleSmcDxe.inf 150 | 151 | EfiPkg/Platform/AppleBootPolicyDxe/AppleBootPolicyDxe.inf 152 | EfiPkg/Platform/AppleEventDxe/AppleEventDxe.inf 153 | EfiPkg/Platform/AppleKeyMapAggregatorDxe/AppleKeyMapAggregatorDxe.inf 154 | EfiPkg/Platform/ApplePlatformInfoDatabase/Dxe/ApplePlatformInfoDatabaseDxe.inf 155 | EfiPkg/Platform/EfiDevicePathPropertyDatabaseDxe/EfiDevicePathPropertyDatabaseDxe.inf 156 | EfiPkg/Platform/EfiOSInfoDxe/EfiOSInfoDxe.inf 157 | EfiPkg/Platform/UserInterfaceThemeDriverDxe/UserInterfaceThemeDriverDxe.inf 158 | 159 | EfiPkg/Universal/AppleSmbiosDxe/AppleSmbiosDxe.inf 160 | 161 | EfiPkg/Library/AppleBaseDebugLibInterrupt/AppleBaseDebugLibInterrupt.inf 162 | EfiPkg/Library/AppleCpuExtensionsLib/AppleCpuExtensionsLib.inf 163 | EfiPkg/Library/AppleDataHubLib/AppleDataHubLib.inf 164 | EfiPkg/Library/AppleEventLib/AppleEventLib.inf 165 | EfiPkg/Library/AppleInterruptLib/AppleInterruptLib.inf 166 | EfiPkg/Library/AppleSmbiosLib/AppleSmbiosLib.inf 167 | EfiPkg/Library/BiosIdLib/BiosIdLib.inf 168 | EfiPkg/Library/AppleDxeDebugPrintErrorLevelLib/AppleDxeDebugPrintErrorLevelLib.inf 169 | EfiPkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf 170 | EfiPkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf 171 | 172 | StoragePkg/PartitionDxe/PartitionDxe.inf 173 | 174 | UsbPkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf 175 | 176 | [Components.IA32, Components.X64] 177 | EfiPkg/Library/AcpiTscTimerLib/BaseTscTimerLib.inf 178 | EfiPkg/Library/AcpiTscTimerLib/DxeTscTimerLib.inf 179 | EfiPkg/Library/AcpiTscTimerLib/PeiTscTimerLib.inf 180 | 181 | [BuildOptions] 182 | # FIXME: Requires implemented ___security_cookie, ___security_check_cookie 183 | # XCODE:*_*_*_PLATFORM_FLAGS = -fstack-protector 184 | 185 | !if $(PEI_LTO_ENABLE) 186 | XCODE:*_*_IA32_PLATFORM_FLAGS = -flto 187 | XCODE:*_*_*_DLINK_FLAGS = -object_path_lto $(DEST_DIR_DEBUG)/$(BASE_NAME).lto 188 | !endif 189 | 190 | !if $(DXE_LTO_ENABLE) 191 | XCODE:*_*_X64_PLATFORM_FLAGS = -flto 192 | XCODE:*_*_*_DLINK_FLAGS = -object_path_lto $(DEST_DIR_DEBUG)/$(BASE_NAME).lto 193 | !endif 194 | -------------------------------------------------------------------------------- /EfiPkg/Library/AcpiTscTimerLib/BaseTscTimerLib.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | A Base Timer Library implementation which uses the Time Stamp Counter in the processor. 3 | 4 | For Pentium 4 processors, Intel Xeon processors (family [0FH], models [03H and higher]); 5 | for Intel Core Solo and Intel Core Duo processors (family [06H], model [0EH]); 6 | for the Intel Xeon processor 5100 series and Intel Core 2 Duo processors (family [06H], model [0FH]); 7 | for Intel Core 2 and Intel Xeon processors (family [06H], display_model [17H]); 8 | for Intel Atom processors (family [06H], display_model [1CH]): 9 | the time-stamp counter increments at a constant rate. 10 | That rate may be set by the maximum core-clock to bus-clock ratio of the processor or may be set by 11 | the maximum resolved frequency at which the processor is booted. The maximum resolved frequency may 12 | differ from the maximum qualified frequency of the processor. 13 | 14 | The specific processor configuration determines the behavior. Constant TSC behavior ensures that the 15 | duration of each clock tick is uniform and supports the use of the TSC as a wall clock timer even if 16 | the processor core changes frequency. This is the architectural behavior moving forward. 17 | 18 | A Processor's support for invariant TSC is indicated by CPUID.0x80000007.EDX[8]. 19 | 20 | Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
21 | This program and the accompanying materials 22 | are licensed and made available under the terms and conditions of the BSD License 23 | which accompanies this distribution. The full text of the license may be found at 24 | http://opensource.org/licenses/bsd-license.php 25 | 26 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 27 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 28 | 29 | **/ 30 | 31 | #include 32 | 33 | #include "TscTimerLibInternal.h" 34 | 35 | /** Get TSC frequency. 36 | 37 | @return The number of TSC counts per second. 38 | 39 | **/ 40 | UINT64 41 | InternalGetTscFrequency ( 42 | VOID 43 | ) 44 | { 45 | return InternalCalculateTscFrequency (); 46 | } 47 | 48 | -------------------------------------------------------------------------------- /EfiPkg/Library/AcpiTscTimerLib/BaseTscTimerLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Base Timer Library which uses the Time Stamp Counter in the processor. 3 | # 4 | # Note: There will be 1ms penalty to get TSC frequency every time 5 | # by waiting for 3579 clocks of the ACPI timer, or 1ms. 6 | # 7 | # Note: This library is a sample implementation that depends on chipset ACPI timer. 8 | # It may not work on new generation chipset. PcAtChipsetPkg AcpiTimerLib is 9 | # the generic timer library that can replace this one. 10 | # 11 | # A version of the Timer Library using the processor's TSC. 12 | # The time stamp counter in newer processors may support an enhancement, referred to as invariant TSC. 13 | # The invariant TSC runs at a constant rate in all ACPI P-, C-. and T-states. 14 | # This is the architectural behavior moving forward. 15 | # TSC reads are much more efficient and do not incur the overhead associated with a ring transition or 16 | # access to a platform resource. 17 | # 18 | # Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
19 | # This program and the accompanying materials 20 | # are licensed and made available under the terms and conditions of the BSD License 21 | # which accompanies this distribution. The full text of the license may be found at 22 | # http://opensource.org/licenses/bsd-license.php 23 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 24 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 25 | # 26 | ## 27 | 28 | [Defines] 29 | INF_VERSION = 0x00010005 30 | BASE_NAME = BaseTscTimerLib 31 | FILE_GUID = D29338B9-50FE-4e4f-B7D4-A150A2C1F4FB 32 | MODULE_TYPE = BASE 33 | VERSION_STRING = 1.0 34 | LIBRARY_CLASS = TimerLib 35 | VALID_ARCHITECTURES = IA32 X64 36 | 37 | [Sources.common] 38 | TscTimerLibShare.c 39 | BaseTscTimerLib.c 40 | TscTimerLibInternal.h 41 | 42 | 43 | [Packages] 44 | MdePkg/MdePkg.dec 45 | EfiPkg/EfiPkg.dec 46 | 47 | 48 | [LibraryClasses] 49 | PcdLib 50 | BaseLib 51 | -------------------------------------------------------------------------------- /EfiPkg/Library/AcpiTscTimerLib/DxeTscTimerLib.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | A Dxe Timer Library implementation which uses the Time Stamp Counter in the processor. 3 | 4 | For Pentium 4 processors, Intel Xeon processors (family [0FH], models [03H and higher]); 5 | for Intel Core Solo and Intel Core Duo processors (family [06H], model [0EH]); 6 | for the Intel Xeon processor 5100 series and Intel Core 2 Duo processors (family [06H], model [0FH]); 7 | for Intel Core 2 and Intel Xeon processors (family [06H], display_model [17H]); 8 | for Intel Atom processors (family [06H], display_model [1CH]): 9 | the time-stamp counter increments at a constant rate. 10 | That rate may be set by the maximum core-clock to bus-clock ratio of the processor or may be set by 11 | the maximum resolved frequency at which the processor is booted. The maximum resolved frequency may 12 | differ from the maximum qualified frequency of the processor. 13 | 14 | The specific processor configuration determines the behavior. Constant TSC behavior ensures that the 15 | duration of each clock tick is uniform and supports the use of the TSC as a wall clock timer even if 16 | the processor core changes frequency. This is the architectural behavior moving forward. 17 | 18 | A Processor's support for invariant TSC is indicated by CPUID.0x80000007.EDX[8]. 19 | 20 | Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
21 | This program and the accompanying materials 22 | are licensed and made available under the terms and conditions of the BSD License 23 | which accompanies this distribution. The full text of the license may be found at 24 | http://opensource.org/licenses/bsd-license.php 25 | 26 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 27 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 28 | 29 | **/ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "TscTimerLibInternal.h" 39 | 40 | UINT64 mTscFrequency; 41 | 42 | /** The constructor function determines the actual TSC frequency. 43 | 44 | First, Get TSC frequency from system configuration table with TSC frequency GUID, 45 | if the table is not found, install it. 46 | This function will always return EFI_SUCCESS. 47 | 48 | @param ImageHandle The firmware allocated handle for the EFI image. 49 | @param SystemTable A pointer to the EFI System Table. 50 | 51 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. 52 | 53 | **/ 54 | EFI_STATUS 55 | EFIAPI 56 | DxeTscTimerLibConstructor ( 57 | IN EFI_HANDLE ImageHandle, 58 | IN EFI_SYSTEM_TABLE *SystemTable 59 | ) 60 | { 61 | EFI_STATUS Status; 62 | UINT64 *TscFrequency; 63 | EFI_HOB_GUID_TYPE *GuidHob; 64 | VOID *DataInHob; 65 | 66 | TscFrequency = NULL; 67 | // 68 | // Get TSC frequency from system configuration table with TSC frequency GUID. 69 | // 70 | Status = EfiGetSystemConfigurationTable (&gAppleTscFrequencyGuid, (VOID **) &TscFrequency); 71 | // BUG: Check with EFI_ERROR(). 72 | if (Status == EFI_SUCCESS) { 73 | mTscFrequency = *TscFrequency; 74 | return EFI_SUCCESS; 75 | } 76 | 77 | // 78 | // Get TSC frequency from TSC frequency GUID HOB. 79 | // 80 | GuidHob = GetFirstGuidHob (&gAppleTscFrequencyGuid); 81 | if (GuidHob != NULL) { 82 | DataInHob = GET_GUID_HOB_DATA (GuidHob); 83 | mTscFrequency = * (UINT64 *) DataInHob; 84 | } else { 85 | mTscFrequency = InternalCalculateTscFrequency (); 86 | } 87 | 88 | // 89 | // TSC frequency GUID system configuration table is not found, install it. 90 | // 91 | 92 | TscFrequency = AllocatePool (sizeof (UINT64)); 93 | 94 | if (TscFrequency != NULL) { 95 | return EFI_OUT_OF_RESOURCES; 96 | } 97 | 98 | *TscFrequency = mTscFrequency; 99 | // 100 | // TscFrequency now points to the number of TSC counts per second, install system configuration table for it. 101 | // 102 | gBS->InstallConfigurationTable (&gAppleTscFrequencyGuid, TscFrequency); 103 | 104 | return EFI_SUCCESS; 105 | } 106 | 107 | /** Get TSC frequency. 108 | 109 | @return The number of TSC counts per second. 110 | 111 | **/ 112 | UINT64 113 | InternalGetTscFrequency ( 114 | VOID 115 | ) 116 | { 117 | if (mTscFrequency == 0) { 118 | mTscFrequency = InternalGetTscFrequency (); 119 | } 120 | 121 | return mTscFrequency; 122 | } 123 | 124 | -------------------------------------------------------------------------------- /EfiPkg/Library/AcpiTscTimerLib/DxeTscTimerLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Dxe Timer Library which uses the Time Stamp Counter in the processor. 3 | # 4 | # Note: This library is a sample implementation that depends on chipset ACPI timer. 5 | # It may not work on new generation chipset. PcAtChipsetPkg AcpiTimerLib is 6 | # the generic timer library that can replace this one. 7 | # 8 | # A version of the Timer Library using the processor's TSC. 9 | # The time stamp counter in newer processors may support an enhancement, referred to as invariant TSC. 10 | # The invariant TSC runs at a constant rate in all ACPI P-, C-. and T-states. 11 | # This is the architectural behavior moving forward. 12 | # TSC reads are much more efficient and do not incur the overhead associated with a ring transition or 13 | # access to a platform resource. 14 | # 15 | # Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
16 | # This program and the accompanying materials 17 | # are licensed and made available under the terms and conditions of the BSD License 18 | # which accompanies this distribution. The full text of the license may be found at 19 | # http://opensource.org/licenses/bsd-license.php 20 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 21 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 22 | # 23 | ## 24 | 25 | [Defines] 26 | INF_VERSION = 0x00010005 27 | BASE_NAME = DxeTscTimerLib 28 | FILE_GUID = 95ab030f-b4fd-4ee4-92a5-9e04e87634d9 29 | MODULE_TYPE = DXE_DRIVER 30 | VERSION_STRING = 1.0 31 | LIBRARY_CLASS = TimerLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE 32 | 33 | CONSTRUCTOR = DxeTscTimerLibConstructor 34 | 35 | VALID_ARCHITECTURES = IA32 X64 36 | 37 | [Sources.common] 38 | TscTimerLibShare.c 39 | DxeTscTimerLib.c 40 | TscTimerLibInternal.h 41 | 42 | 43 | [Packages] 44 | MdePkg/MdePkg.dec 45 | EfiPkg/EfiPkg.dec 46 | 47 | 48 | [LibraryClasses] 49 | UefiBootServicesTableLib 50 | PcdLib 51 | BaseLib 52 | UefiLib 53 | DebugLib 54 | 55 | [Guids] 56 | gAppleTscFrequencyGuid ## SOMETIMES_PRODUCES ## CONSUMES ## SystemTable ## HOB 57 | -------------------------------------------------------------------------------- /EfiPkg/Library/AcpiTscTimerLib/PeiTscTimerLib.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | A Pei Timer Library implementation which uses the Time Stamp Counter in the processor. 3 | 4 | For Pentium 4 processors, Intel Xeon processors (family [0FH], models [03H and higher]); 5 | for Intel Core Solo and Intel Core Duo processors (family [06H], model [0EH]); 6 | for the Intel Xeon processor 5100 series and Intel Core 2 Duo processors (family [06H], model [0FH]); 7 | for Intel Core 2 and Intel Xeon processors (family [06H], display_model [17H]); 8 | for Intel Atom processors (family [06H], display_model [1CH]): 9 | the time-stamp counter increments at a constant rate. 10 | That rate may be set by the maximum core-clock to bus-clock ratio of the processor or may be set by 11 | the maximum resolved frequency at which the processor is booted. The maximum resolved frequency may 12 | differ from the maximum qualified frequency of the processor. 13 | 14 | The specific processor configuration determines the behavior. Constant TSC behavior ensures that the 15 | duration of each clock tick is uniform and supports the use of the TSC as a wall clock timer even if 16 | the processor core changes frequency. This is the architectural behavior moving forward. 17 | 18 | A Processor's support for invariant TSC is indicated by CPUID.0x80000007.EDX[8]. 19 | 20 | Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
21 | This program and the accompanying materials 22 | are licensed and made available under the terms and conditions of the BSD License 23 | which accompanies this distribution. The full text of the license may be found at 24 | http://opensource.org/licenses/bsd-license.php 25 | 26 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 27 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 28 | 29 | **/ 30 | 31 | #include 32 | #include 33 | #include 34 | #include "TscTimerLibInternal.h" 35 | 36 | /** Get TSC frequency from TSC frequency GUID HOB, if the HOB is not found, build it. 37 | 38 | @return The number of TSC counts per second. 39 | 40 | **/ 41 | UINT64 42 | InternalGetTscFrequency ( 43 | VOID 44 | ) 45 | { 46 | EFI_HOB_GUID_TYPE *GuidHob; 47 | VOID *DataInHob; 48 | UINT64 TscFrequency; 49 | 50 | // 51 | // Get TSC frequency from TSC frequency GUID HOB. 52 | // 53 | GuidHob = GetFirstGuidHob (&gAppleTscFrequencyGuid); 54 | if (GuidHob != NULL) { 55 | DataInHob = GET_GUID_HOB_DATA (GuidHob); 56 | TscFrequency = * (UINT64 *) DataInHob; 57 | return TscFrequency; 58 | } 59 | 60 | // 61 | // TSC frequency GUID HOB is not found, build it. 62 | // 63 | 64 | TscFrequency = InternalCalculateTscFrequency (); 65 | // 66 | // TscFrequency is now equal to the number of TSC counts per second, build GUID HOB for it. 67 | // 68 | BuildGuidDataHob ( 69 | &gAppleTscFrequencyGuid, 70 | &TscFrequency, 71 | sizeof (UINT64) 72 | ); 73 | 74 | return TscFrequency; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /EfiPkg/Library/AcpiTscTimerLib/PeiTscTimerLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Pei Timer Library which uses the Time Stamp Counter in the processor. 3 | # 4 | # Note: This library is a sample implementation that depends on chipset ACPI timer. 5 | # It may not work on new generation chipset. PcAtChipsetPkg AcpiTimerLib is 6 | # the generic timer library that can replace this one. 7 | # 8 | # A version of the Timer Library using the processor's TSC. 9 | # The time stamp counter in newer processors may support an enhancement, referred to as invariant TSC. 10 | # The invariant TSC runs at a constant rate in all ACPI P-, C-. and T-states. 11 | # This is the architectural behavior moving forward. 12 | # TSC reads are much more efficient and do not incur the overhead associated with a ring transition or 13 | # access to a platform resource. 14 | # 15 | # Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
16 | # This program and the accompanying materials 17 | # are licensed and made available under the terms and conditions of the BSD License 18 | # which accompanies this distribution. The full text of the license may be found at 19 | # http://opensource.org/licenses/bsd-license.php 20 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 21 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 22 | # 23 | ## 24 | 25 | [Defines] 26 | INF_VERSION = 0x00010005 27 | BASE_NAME = PeiTscTimerLib 28 | FILE_GUID = 342C36C0-15DF-43b4-9EC9-FBF748BFB3D1 29 | MODULE_TYPE = PEIM 30 | VERSION_STRING = 1.0 31 | LIBRARY_CLASS = TimerLib|PEIM PEI_CORE 32 | VALID_ARCHITECTURES = IA32 X64 33 | 34 | [Sources.common] 35 | TscTimerLibShare.c 36 | PeiTscTimerLib.c 37 | TscTimerLibInternal.h 38 | 39 | 40 | [Packages] 41 | MdePkg/MdePkg.dec 42 | EfiPkg/EfiPkg.dec 43 | 44 | 45 | [LibraryClasses] 46 | PcdLib 47 | BaseLib 48 | HobLib 49 | 50 | [Guids] 51 | gAppleTscFrequencyGuid ## PRODUCES ## HOB 52 | -------------------------------------------------------------------------------- /EfiPkg/Library/AcpiTscTimerLib/TscTimerLibInternal.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | Internal header file for TscTimerLib instances. 3 | 4 | Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
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 _TSC_TIMER_LIB_INTERNAL_H_ 16 | #define _TSC_TIMER_LIB_INTERNAL_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | /** Get TSC frequency. 25 | 26 | @return The number of TSC counts per second. 27 | 28 | **/ 29 | UINT64 30 | InternalGetTscFrequency ( 31 | VOID 32 | ); 33 | 34 | /** Calculate TSC frequency. 35 | 36 | The TSC counting frequency is determined by comparing how far it counts 37 | during a 1ms period as determined by the ACPI timer. The ACPI timer is 38 | used because it counts at a known frequency. 39 | If ACPI I/O space not enabled, this function will enable it. Then the 40 | TSC is sampled, followed by waiting for 3579 clocks of the ACPI timer, or 1ms. 41 | The TSC is then sampled again. The difference multiplied by 1000 is the TSC 42 | frequency. There will be a small error because of the overhead of reading 43 | the ACPI timer. An attempt is made to determine and compensate for this error. 44 | 45 | @return The number of TSC counts per second. 46 | 47 | **/ 48 | UINT64 49 | InternalCalculateTscFrequency ( 50 | VOID 51 | ); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /EfiPkg/Library/AcpiTscTimerLib/TscTimerLibShare.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | The Timer Library implementation which uses the Time Stamp Counter in the processor. 3 | 4 | For Pentium 4 processors, Intel Xeon processors (family [0FH], models [03H and higher]); 5 | for Intel Core Solo and Intel Core Duo processors (family [06H], model [0EH]); 6 | for the Intel Xeon processor 5100 series and Intel Core 2 Duo processors (family [06H], model [0FH]); 7 | for Intel Core 2 and Intel Xeon processors (family [06H], display_model [17H]); 8 | for Intel Atom processors (family [06H], display_model [1CH]): 9 | the time-stamp counter increments at a constant rate. 10 | That rate may be set by the maximum core-clock to bus-clock ratio of the processor or may be set by 11 | the maximum resolved frequency at which the processor is booted. The maximum resolved frequency may 12 | differ from the maximum qualified frequency of the processor. 13 | 14 | The specific processor configuration determines the behavior. Constant TSC behavior ensures that the 15 | duration of each clock tick is uniform and supports the use of the TSC as a wall clock timer even if 16 | the processor core changes frequency. This is the architectural behavior moving forward. 17 | 18 | A Processor's support for invariant TSC is indicated by CPUID.0x80000007.EDX[8]. 19 | 20 | Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
21 | This program and the accompanying materials 22 | are licensed and made available under the terms and conditions of the BSD License 23 | which accompanies this distribution. The full text of the license may be found at 24 | http://opensource.org/licenses/bsd-license.php 25 | 26 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 27 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 28 | 29 | **/ 30 | 31 | #include 32 | 33 | #include "TscTimerLibInternal.h" 34 | 35 | /** Calculate TSC frequency. 36 | 37 | The TSC counting frequency is determined by comparing how far it counts 38 | during a 1ms period as determined by the ACPI timer. The ACPI timer is 39 | used because it counts at a known frequency. 40 | If ACPI I/O space not enabled, this function will enable it. Then the 41 | TSC is sampled, followed by waiting for 3579 clocks of the ACPI timer, or 1ms. 42 | The TSC is then sampled again. The difference multiplied by 1000 is the TSC 43 | frequency. There will be a small error because of the overhead of reading 44 | the ACPI timer. An attempt is made to determine and compensate for this error. 45 | 46 | @return The number of TSC counts per second. 47 | 48 | **/ 49 | UINT64 50 | InternalCalculateTscFrequency ( 51 | VOID 52 | ) 53 | { 54 | UINT64 StartTSC; 55 | UINT64 EndTSC; 56 | UINT32 TimerAddr; 57 | UINT32 Ticks; 58 | UINT64 TscFrequency; 59 | 60 | TimerAddr = 0x1808; 61 | Ticks = IoRead32 (TimerAddr) + (3579); // Set Ticks to 1ms in the future 62 | StartTSC = AsmReadTsc(); // Get base value for the TSC 63 | 64 | // 65 | // Wait until the ACPI timer has counted 1ms. 66 | // Timer wrap-arounds are handled correctly by this function. 67 | // When the current ACPI timer value is greater than 'Ticks', the while loop will exit. 68 | // 69 | while (((Ticks - IoRead32 (TimerAddr)) & BIT23) == 0) { 70 | CpuPause(); 71 | } 72 | EndTSC = AsmReadTsc (); 73 | 74 | TscFrequency = MultU64x32 ( 75 | (EndTSC - StartTSC), // Number of TSC counts in 1ms 76 | 1000 // Number of ms in a second 77 | ); 78 | 79 | return TscFrequency; 80 | } 81 | 82 | /** Stalls the CPU for at least the given number of ticks. 83 | 84 | Stalls the CPU for at least the given number of ticks. It's invoked by 85 | MicroSecondDelay() and NanoSecondDelay(). 86 | 87 | @param[in] Delay A period of time to delay in ticks. 88 | 89 | **/ 90 | VOID 91 | InternalX86Delay ( 92 | IN UINT64 Delay 93 | ) 94 | { 95 | UINT64 Ticks; 96 | 97 | // 98 | // The target timer count is calculated here 99 | // 100 | Ticks = AsmReadTsc() + Delay; 101 | 102 | // 103 | // Wait until time out 104 | // Timer wrap-arounds are NOT handled correctly by this function. 105 | // Thus, this function must be called within 10 years of reset since 106 | // Intel guarantees a minimum of 10 years before the TSC wraps. 107 | // 108 | while (AsmReadTsc() <= Ticks) CpuPause(); 109 | } 110 | 111 | /** Stalls the CPU for at least the specified number of MicroSeconds. 112 | 113 | @param[in] MicroSeconds The minimum number of microseconds to delay. 114 | 115 | @return The value of MicroSeconds input. 116 | 117 | **/ 118 | UINTN 119 | EFIAPI 120 | MicroSecondDelay ( 121 | IN UINTN MicroSeconds 122 | ) 123 | { 124 | InternalX86Delay ( 125 | DivU64x32 ( 126 | MultU64x64 ( 127 | InternalGetTscFrequency (), 128 | MicroSeconds 129 | ), 130 | 1000000u 131 | ) 132 | ); 133 | return MicroSeconds; 134 | } 135 | 136 | /** Stalls the CPU for at least the specified number of NanoSeconds. 137 | 138 | @param[in] NanoSeconds The minimum number of nanoseconds to delay. 139 | 140 | @return The value of NanoSeconds input. 141 | 142 | **/ 143 | UINTN 144 | EFIAPI 145 | NanoSecondDelay ( 146 | IN UINTN NanoSeconds 147 | ) 148 | { 149 | InternalX86Delay ( 150 | DivU64x32 ( 151 | MultU64x32 ( 152 | InternalGetTscFrequency (), 153 | (UINT32)NanoSeconds 154 | ), 155 | 1000000000u 156 | ) 157 | ); 158 | return NanoSeconds; 159 | } 160 | 161 | /** Retrieves the current value of the 64-bit free running Time-Stamp counter. 162 | 163 | The time-stamp counter (as implemented in the P6 family, Pentium, Pentium M, 164 | Pentium 4, Intel Xeon, Intel Core Solo and Intel Core Duo processors and 165 | later processors) is a 64-bit counter that is set to 0 following a RESET of 166 | the processor. Following a RESET, the counter increments even when the 167 | processor is halted by the HLT instruction or the external STPCLK# pin. Note 168 | that the assertion of the external DPSLP# pin may cause the time-stamp 169 | counter to stop. 170 | 171 | The properties of the counter can be retrieved by the 172 | GetPerformanceCounterProperties() function. 173 | 174 | @return The current value of the free running performance counter. 175 | 176 | **/ 177 | UINT64 178 | EFIAPI 179 | GetPerformanceCounter ( 180 | VOID 181 | ) 182 | { 183 | return AsmReadTsc(); 184 | } 185 | 186 | /** Retrieves the 64-bit frequency in Hz and the range of performance counter 187 | values. 188 | 189 | If StartValue is not NULL, then the value that the performance counter starts 190 | with, 0x0, is returned in StartValue. If EndValue is not NULL, then the value 191 | that the performance counter end with, 0xFFFFFFFFFFFFFFFF, is returned in 192 | EndValue. 193 | 194 | The 64-bit frequency of the performance counter, in Hz, is always returned. 195 | To determine average processor clock frequency, Intel recommends the use of 196 | EMON logic to count processor core clocks over the period of time for which 197 | the average is required. 198 | 199 | 200 | @param[out] StartValue Pointer to where the performance counter's starting value is saved, or NULL. 201 | @param[out] EndValue Pointer to where the performance counter's ending value is saved, or NULL. 202 | 203 | @return The frequency in Hz. 204 | 205 | **/ 206 | UINT64 207 | EFIAPI 208 | GetPerformanceCounterProperties ( 209 | OUT UINT64 *StartValue, OPTIONAL 210 | OUT UINT64 *EndValue OPTIONAL 211 | ) 212 | { 213 | if (StartValue != NULL) { 214 | *StartValue = 0; 215 | } 216 | if (EndValue != NULL) { 217 | *EndValue = 0xFFFFFFFFFFFFFFFFull; 218 | } 219 | 220 | return InternalGetTscFrequency (); 221 | } 222 | 223 | /** 224 | Converts elapsed ticks of performance counter to time in nanoseconds. 225 | 226 | This function converts the elapsed ticks of running performance counter to 227 | time value in unit of nanoseconds. 228 | 229 | @param Ticks The number of elapsed ticks of running performance counter. 230 | 231 | @return The elapsed time in nanoseconds. 232 | 233 | **/ 234 | UINT64 235 | EFIAPI 236 | GetTimeInNanoSecond ( 237 | IN UINT64 Ticks 238 | ) 239 | { 240 | UINT64 Frequency; 241 | UINT64 NanoSeconds; 242 | UINT64 Remainder; 243 | INTN Shift; 244 | 245 | Frequency = GetPerformanceCounterProperties (NULL, NULL); 246 | 247 | // 248 | // Ticks 249 | // Time = --------- x 1,000,000,000 250 | // Frequency 251 | // 252 | NanoSeconds = MultU64x32 (DivU64x64Remainder (Ticks, Frequency, &Remainder), 1000000000u); 253 | 254 | // 255 | // Ensure (Remainder * 1,000,000,000) will not overflow 64-bit. 256 | // Since 2^29 < 1,000,000,000 = 0x3B9ACA00 < 2^30, Remainder should < 2^(64-30) = 2^34, 257 | // i.e. highest bit set in Remainder should <= 33. 258 | // 259 | Shift = MAX (0, HighBitSet64 (Remainder) - 33); 260 | Remainder = RShiftU64 (Remainder, (UINTN) Shift); 261 | Frequency = RShiftU64 (Frequency, (UINTN) Shift); 262 | NanoSeconds += DivU64x64Remainder (MultU64x32 (Remainder, 1000000000u), Frequency, NULL); 263 | 264 | return NanoSeconds; 265 | } 266 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleBaseDebugLibInterrupt/AppleBaseDebugLibInterrupt.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Instance of Debug Library based on Serial Port Library. 3 | # It uses Print Library to produce formatted output strings to seiral port device. 4 | # 5 | # Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
6 | # 7 | # This program and the accompanying materials 8 | # are licensed and made available under the terms and conditions of the BSD License 9 | # which accompanies this distribution. The full text of the license may be found at 10 | # http://opensource.org/licenses/bsd-license.php. 11 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 | # 14 | # 15 | ## 16 | 17 | [Defines] 18 | BASE_NAME = AppleBaseDebugLibInterrupt 19 | MODULE_TYPE = BASE 20 | VERSION_STRING = 1.0 21 | LIBRARY_CLASS = DebugLib 22 | INF_VERSION = 0x00010005 23 | 24 | [Sources] 25 | DebugLib.c 26 | 27 | [Packages] 28 | MdePkg/MdePkg.dec 29 | EfiPkg/EfiPkg.dec 30 | 31 | [LibraryClasses] 32 | AppleInterruptLib 33 | BaseMemoryLib 34 | PcdLib 35 | BaseLib 36 | DebugPrintErrorLevelLib 37 | 38 | [Pcd] 39 | gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue ## SOMETIMES_CONSUMES 40 | gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask ## CONSUMES 41 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleBaseDebugLibInterrupt/DebugLib.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Base Debug library instance base on Serial Port library. 3 | It uses PrintLib to send debug messages to serial port device. 4 | 5 | NOTE: If the Serial Port library enables hardware flow control, then a call 6 | to DebugPrint() or DebugAssert() may hang if writes to the serial port are 7 | being blocked. This may occur if a key(s) are pressed in a terminal emulator 8 | used to monitor the DEBUG() and ASSERT() messages. 9 | 10 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
11 | This program and the accompanying materials 12 | are licensed and made available under the terms and conditions of the BSD License 13 | which accompanies this distribution. The full text of the license may be found at 14 | http://opensource.org/licenses/bsd-license.php. 15 | 16 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 18 | 19 | **/ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | /** 32 | Prints a debug message to the debug output device if the specified error level is enabled. 33 | 34 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function 35 | GetDebugPrintErrorLevel (), then print the message specified by Format and the 36 | associated variable argument list to the debug output device. 37 | 38 | If Format is NULL, then ASSERT(). 39 | 40 | @param ErrorLevel The error level of the debug message. 41 | @param Format Format string for the debug message to print. 42 | @param ... Variable argument list whose contents are accessed 43 | based on the format string specified by Format. 44 | 45 | **/ 46 | VOID 47 | EFIAPI 48 | DebugPrint ( 49 | IN UINTN ErrorLevel, 50 | IN CONST CHAR8 *Format, 51 | ... 52 | ) 53 | { 54 | ASSERT (Format != NULL); 55 | 56 | return; 57 | } 58 | 59 | 60 | /** 61 | Prints an assert message containing a filename, line number, and description. 62 | This may be followed by a breakpoint or a dead loop. 63 | 64 | Print a message of the form "ASSERT (): \n" 65 | to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of 66 | PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if 67 | DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then 68 | CpuDeadLoop() is called. If neither of these bits are set, then this function 69 | returns immediately after the message is printed to the debug output device. 70 | DebugAssert() must actively prevent recursion. If DebugAssert() is called while 71 | processing another DebugAssert(), then DebugAssert() must return immediately. 72 | 73 | If FileName is NULL, then a string of "(NULL) Filename" is printed. 74 | If Description is NULL, then a string of "(NULL) Description" is printed. 75 | 76 | @param FileName The pointer to the name of the source file that generated the assert condition. 77 | @param LineNumber The line number in the source file that generated the assert condition 78 | @param Description The pointer to the description of the assert condition. 79 | 80 | **/ 81 | VOID 82 | EFIAPI 83 | DebugAssert ( 84 | IN CONST CHAR8 *FileName, 85 | IN UINTN LineNumber, 86 | IN CONST CHAR8 *Description 87 | ) 88 | { 89 | RETURN_STATUS Status; 90 | 91 | Status = AppleInterrupt (APPLE_INTERRUPT_ASSERT, FileName, LineNumber, Description, NULL, NULL); 92 | 93 | if (!RETURN_ERROR (Status)) { 94 | // 95 | // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings 96 | // 97 | if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) { 98 | CpuBreakpoint (); 99 | } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) { 100 | CpuDeadLoop (); 101 | } 102 | } 103 | } 104 | 105 | 106 | /** 107 | Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer. 108 | 109 | This function fills Length bytes of Buffer with the value specified by 110 | PcdDebugClearMemoryValue, and returns Buffer. 111 | 112 | If Buffer is NULL, then ASSERT(). 113 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). 114 | 115 | @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue. 116 | @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. 117 | 118 | @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue. 119 | 120 | **/ 121 | VOID * 122 | EFIAPI 123 | DebugClearMemory ( 124 | OUT VOID *Buffer, 125 | IN UINTN Length 126 | ) 127 | { 128 | // 129 | // If Buffer is NULL, then ASSERT(). 130 | // 131 | ASSERT (Buffer != NULL); 132 | 133 | // 134 | // SetMem() checks for the the ASSERT() condition on Length and returns Buffer 135 | // 136 | return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue)); 137 | } 138 | 139 | 140 | /** 141 | Returns TRUE if ASSERT() macros are enabled. 142 | 143 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of 144 | PcdDebugProperyMask is set. Otherwise FALSE is returned. 145 | 146 | @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set. 147 | @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear. 148 | 149 | **/ 150 | BOOLEAN 151 | EFIAPI 152 | DebugAssertEnabled ( 153 | VOID 154 | ) 155 | { 156 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0); 157 | } 158 | 159 | 160 | /** 161 | Returns TRUE if DEBUG() macros are enabled. 162 | 163 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of 164 | PcdDebugProperyMask is set. Otherwise FALSE is returned. 165 | 166 | @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set. 167 | @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear. 168 | 169 | **/ 170 | BOOLEAN 171 | EFIAPI 172 | DebugPrintEnabled ( 173 | VOID 174 | ) 175 | { 176 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0); 177 | } 178 | 179 | 180 | /** 181 | Returns TRUE if DEBUG_CODE() macros are enabled. 182 | 183 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of 184 | PcdDebugProperyMask is set. Otherwise FALSE is returned. 185 | 186 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set. 187 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear. 188 | 189 | **/ 190 | BOOLEAN 191 | EFIAPI 192 | DebugCodeEnabled ( 193 | VOID 194 | ) 195 | { 196 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0); 197 | } 198 | 199 | 200 | /** 201 | Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled. 202 | 203 | This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of 204 | PcdDebugProperyMask is set. Otherwise FALSE is returned. 205 | 206 | @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set. 207 | @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear. 208 | 209 | **/ 210 | BOOLEAN 211 | EFIAPI 212 | DebugClearMemoryEnabled ( 213 | VOID 214 | ) 215 | { 216 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0); 217 | } 218 | 219 | /** 220 | Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel. 221 | 222 | This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel. 223 | 224 | @retval TRUE Current ErrorLevel is supported. 225 | @retval FALSE Current ErrorLevel is not supported. 226 | 227 | **/ 228 | BOOLEAN 229 | EFIAPI 230 | DebugPrintLevelEnabled ( 231 | IN CONST UINTN ErrorLevel 232 | ) 233 | { 234 | return (BOOLEAN) ((ErrorLevel & GetDebugPrintErrorLevel ()) != 0); 235 | } 236 | 237 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleBaseStackCheckLib/AppleBaseStackCheckLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Stack Check Library 3 | # 4 | # Stack Check Library 5 | # 6 | # Copyright (c) 2014, ARM Ltd. All rights reserved.
7 | # 8 | # This program and the accompanying materials 9 | # are licensed and made available under the terms and conditions of the BSD License 10 | # which accompanies this distribution. The full text of the license may be found at 11 | # http://opensource.org/licenses/bsd-license.php. 12 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 14 | # 15 | # 16 | ## 17 | 18 | [Defines] 19 | INF_VERSION = 0x00010005 20 | BASE_NAME = AppleBaseStackCheckLib 21 | MODULE_TYPE = BASE 22 | VERSION_STRING = 1.0 23 | LIBRARY_CLASS = NULL 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | BaseLib 30 | DebugLib 31 | PcdLib 32 | 33 | [FixedPcd] 34 | gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask ## CONSUMES 35 | 36 | [Sources] 37 | AppleBaseStackCheckLibNull.c 38 | AppleBaseStackCheckLibGcc.c | GCC 39 | AppleBaseStackCheckLibGcc.c | XCODE 40 | AppleBaseStackCheckLibGcc.c | RVCT 41 | 42 | [Sources.IA32] 43 | Ia32/CheckStackCanary.S | GCC 44 | Ia32/CheckStackCanary.S | XCODE 45 | Ia32/CheckStackCanary.S | RVCT 46 | 47 | [Sources.X64] 48 | X64/CheckStackCanary.S | GCC 49 | X64/CheckStackCanary.S | XCODE 50 | X64/CheckStackCanary.S | RVCT 51 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleBaseStackCheckLib/AppleBaseStackCheckLibGcc.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Base Stack Check library for GCC/clang. 3 | 4 | Use -fstack-protector-all compiler flag to make the compiler insert the 5 | __stack_chk_guard "canary" value into the stack and check the value prior 6 | to exiting the function. If the "canary" is overwritten __stack_chk_fail() 7 | is called. This is GCC specific code. 8 | 9 | Copyright (c) 2012, Apple Inc. All rights reserved.
10 | This program and the accompanying materials 11 | are licensed and made available under the terms and conditions of the BSD License 12 | which accompanies this distribution. The full text of the license may be found at 13 | http://opensource.org/licenses/bsd-license.php. 14 | 15 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 16 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 17 | 18 | **/ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | // __stack_chk_guard 27 | /// "canary" value that is inserted by the compiler into the stack frame. 28 | VOID *__stack_chk_guard = (VOID *)0xD988199402CDD2D3; 29 | 30 | // __stack_chk_fail 31 | /** Error path for compiler generated stack "canary" value check code. If the 32 | stack canary has been overwritten this function gets called on exit of the 33 | function. 34 | **/ 35 | VOID 36 | __stack_chk_fail ( 37 | VOID 38 | ) 39 | { 40 | UINT8 DebugPropertyMask; 41 | 42 | DEBUG (( 43 | DEBUG_ERROR, 44 | "STACK FAULT: Buffer Overflow in function %a.\n", 45 | __builtin_return_address(0) 46 | )); 47 | 48 | // 49 | // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings even if 50 | // BaseDebugLibNull is in use. 51 | // 52 | DebugPropertyMask = PcdGet8 (PcdDebugPropertyMask); 53 | 54 | if ((DebugPropertyMask & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) { 55 | CpuBreakpoint (); 56 | } 57 | 58 | if ((DebugPropertyMask & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) { 59 | CpuDeadLoop (); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleBaseStackCheckLib/AppleBaseStackCheckLibNull.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acidanthera/mac-efi-firmware/759669b625c7d4b6d1d09afd06dd20a0bce8b353/EfiPkg/Library/AppleBaseStackCheckLib/AppleBaseStackCheckLibNull.c -------------------------------------------------------------------------------- /EfiPkg/Library/AppleBaseStackCheckLib/Ia32/CheckStackCanary.S: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # // CheckStackCanary 3 | # VOID 4 | # EFIAPI 5 | # CheckStackCanary ( 6 | # IN UINTN Value 7 | # ); 8 | #------------------------------------------------------------------------------ 9 | ASM_GLOBAL ASM_PFX(CheckStackCanary) 10 | ASM_PFX(CheckStackCanary): 11 | cmp ASM_PFX(__stack_chk_guard), %ecx 12 | jnz ASM_PFX(__stack_chk_fail) 13 | ret 14 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleBaseStackCheckLib/X64/CheckStackCanary.S: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # // CheckStackCanary 3 | # VOID 4 | # EFIAPI 5 | # CheckStackCanary ( 6 | # IN UINTN Value 7 | # ); 8 | #------------------------------------------------------------------------------ 9 | ASM_GLOBAL ASM_PFX(CheckStackCanary) 10 | ASM_PFX(CheckStackCanary): 11 | cmp ASM_PFX(__stack_chk_guard)(%rip), %rcx 12 | jnz ASM_PFX(__stack_chk_fail) 13 | ret 14 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleCpuExtensionsLib/AppleCpuExtensionsLib.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010005 3 | BASE_NAME = AppleCpuExtensionsLib 4 | MODULE_TYPE = BASE 5 | VERSION_STRING = 1.0 6 | LIBRARY_CLASS = AppleCpuExtensionsLib 7 | 8 | [Packages] 9 | MdePkg/MdePkg.dec 10 | EfiPkg/EfiPkg.dec 11 | 12 | [Sources.IA32, Sources.X64] 13 | Ia32X64/EnableCpuExtensions.c 14 | Ia32X64/EnableSseAvx.nasm | MSFT 15 | Ia32X64/EnableSseAvx.nasm | INTEL 16 | Ia32X64/EnableSseAvx.nasm | RVCT 17 | Ia32X64/EnableSseAvxGccInline.c | GCC 18 | Ia32X64/EnableSseAvxGccInline.c | XCODE 19 | 20 | [Sources.ARM, Sources.AARCH64, Sources.IPF, Sources.EBC] 21 | EnableCpuExtensionsNull.c 22 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleCpuExtensionsLib/EnableCpuExtensionsNull.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | // AppleEnableCpuExtensions 6 | VOID 7 | AppleEnableCpuExtensions ( 8 | VOID 9 | ) 10 | { 11 | return; 12 | } 13 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleCpuExtensionsLib/Ia32X64/EnableCpuExtensions.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | // InternalAsmEnableSseAvx 7 | VOID 8 | EFIAPI 9 | InternalAsmEnableSseAvx ( 10 | VOID 11 | ); 12 | 13 | // AppleEnableCpuExtensions 14 | VOID 15 | AppleEnableCpuExtensions ( 16 | VOID 17 | ) 18 | { 19 | UINTN Cr4; 20 | 21 | Cr4 = AsmReadCr4 (); 22 | 23 | // 24 | // check CR4.OSXSAVE[Bit 18] 25 | // 26 | if ((Cr4 & BIT18) != 0) { 27 | // 28 | // set CR4.OSXSAVE[Bit 18] 29 | // 30 | AsmWriteCr4 (Cr4 | BIT18); 31 | 32 | // 33 | // enable SSE and AVX 34 | // 35 | InternalAsmEnableSseAvx (); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleCpuExtensionsLib/Ia32X64/EnableSseAvx.nasm: -------------------------------------------------------------------------------- 1 | DEFAULT REL 2 | SECTION .text 3 | 4 | ;------------------------------------------------------------------------------ 5 | ; // InternalAsmEnableSseAvx 6 | ; VOID 7 | ; EFIAPI 8 | ; InternalAsmEnableSseAvx ( 9 | ; VOID 10 | ; ); 11 | ;------------------------------------------------------------------------------ 12 | global ASM_PFX(InternalAsmEnableSseAvx) 13 | ASM_PFX(InternalAsmEnableSseAvx): 14 | xor ecx, ecx 15 | xgetbv 16 | or eax, 6 17 | xor ecx, ecx 18 | xsetbv 19 | ret 20 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleCpuExtensionsLib/Ia32X64/EnableSseAvxGccInline.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // InternalAsmEnableSseAvx 4 | VOID 5 | InternalAsmEnableSseAvx ( 6 | VOID 7 | ) 8 | { 9 | __asm__ __volatile__ ( 10 | "xor %ecx, %ecx\n\t" 11 | // xgetbv 12 | ".byte 0x0F, 0x01, 0xD0\n\t" 13 | "orl $0x06, %eax\n\t" 14 | "xor %ecx, %ecx\n\t" 15 | // xsetbv 16 | ".byte 0x0F, 0x01, 0xD1" 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleDataHubLib/AppleDataHubLib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | // mDataHub 16 | STATIC EFI_DATA_HUB_PROTOCOL *mDataHub = NULL; 17 | 18 | // InternalGetDataHubProtocol 19 | STATIC 20 | EFI_STATUS 21 | InternalGetDataHubProtocol ( 22 | VOID 23 | ) 24 | { 25 | EFI_STATUS Status; 26 | 27 | Status = EFI_SUCCESS; 28 | 29 | if (mDataHub == NULL) { 30 | Status = gBS->LocateProtocol ( 31 | &gEfiDataHubProtocolGuid, 32 | NULL, 33 | (VOID **)&mDataHub 34 | ); 35 | } 36 | 37 | return Status; 38 | } 39 | 40 | // DataHubLogData 41 | VOID 42 | DataHubLogData ( 43 | IN EFI_GUID *DataRecordGuid, 44 | IN EFI_GUID *ProducerName, 45 | IN VOID *RawData, 46 | IN UINT32 RawDataSize 47 | ) 48 | { 49 | EFI_STATUS Status; 50 | 51 | Status = InternalGetDataHubProtocol (); 52 | 53 | if (!EFI_ERROR (Status)) { 54 | mDataHub->LogData ( 55 | mDataHub, 56 | DataRecordGuid, 57 | ProducerName, 58 | EFI_DATA_RECORD_CLASS_DATA, 59 | RawData, 60 | RawDataSize 61 | ); 62 | } 63 | } 64 | 65 | // DataHubLogApplePlatformData 66 | VOID 67 | DataHubLogApplePlatformData ( 68 | IN CHAR16 *Key, 69 | IN EFI_GUID *DataRecordGuid, 70 | IN VOID *Value, 71 | IN UINTN ValueSize 72 | ) 73 | { 74 | UINTN KeySize; 75 | APPLE_PLATFORM_DATA_RECORD *Record; 76 | 77 | KeySize = (StrLen (Key) * sizeof (*Key)); 78 | Record = AllocatePool (sizeof (*Record) + KeySize + ValueSize); 79 | 80 | if (Record != NULL) { 81 | Record->Header.Version = APPLE_SUBCLASS_VERSION; 82 | Record->Header.HeaderSize = sizeof (*Record); 83 | Record->Header.Instance = APPLE_SUBCLASS_INSTANCE; 84 | Record->Header.SubInstance = APPLE_SUBCLASS_INSTANCE; 85 | Record->Header.RecordType = APPLE_SUBCLASS_INSTANCE; 86 | Record->KeySize = (UINT32)KeySize; 87 | Record->ValueSize = (UINT32)ValueSize; 88 | 89 | CopyMem ((VOID *)&Record->Key[0], (VOID *)Key, KeySize); 90 | CopyMem ((VOID *)((UINTN)&Record->Key[0] + KeySize), Value, ValueSize); 91 | 92 | DataHubLogData ( 93 | DataRecordGuid, 94 | &gApplePlatformProducerNameGuid, 95 | (VOID *)Record, 96 | sizeof (*Record) 97 | ); 98 | 99 | FreePool ((VOID *)Record); 100 | } else { 101 | ASSERT (FALSE); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleDataHubLib/AppleDataHubLib.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | BASE_NAME = AppleDataHubLib 3 | MODULE_TYPE = UEFI_DRIVER 4 | INF_VERSION = 0x00010005 5 | LIBRARY_CLASS = AppleDataHubLib 6 | 7 | [Packages] 8 | MdePkg/MdePkg.dec 9 | EfiPkg/EfiPkg.dec 10 | IntelFrameworkPkg/IntelFrameworkPkg.dec 11 | 12 | [Protocols] 13 | gEfiDataHubProtocolGuid ## CONSUMES 14 | 15 | [LibraryClasses] 16 | BaseLib 17 | BaseMemoryLib 18 | DebugLib 19 | MemoryAllocationLib 20 | UefiBootServicesTableLib 21 | 22 | [Sources] 23 | AppleDataHubLib.c 24 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleDxeDebugPrintErrorLevelLib/AppleDxeDebugPrintErrorLevelLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Debug Print Error Level library instance that provide compatibility with the "err" shell command. 3 | # This includes support for the Debug Mask Protocol supports for global debug print error level mask 4 | # stored in an EFI Variable. This library instance only support DXE Phase modules. 5 | # 6 | # Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.
7 | # 8 | # This program and the accompanying materials 9 | # are licensed and made available under the terms and conditions of the BSD License 10 | # which accompanies this distribution. The full text of the license may be found at 11 | # http://opensource.org/licenses/bsd-license.php. 12 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 14 | # 15 | # 16 | ## 17 | 18 | [Defines] 19 | INF_VERSION = 0x00010005 20 | BASE_NAME = AppleDxeDebugPrintErrorLevelLib 21 | MODULE_TYPE = DXE_DRIVER 22 | VERSION_STRING = 1.0 23 | LIBRARY_CLASS = DebugPrintErrorLevelLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER UEFI_APPLICATION UEFI_DRIVER 24 | CONSTRUCTOR = DxeDebugPrintErrorLevelLibConstructor 25 | DESTRUCTOR = DxeDebugPrintErrorLevelLibDestructor 26 | 27 | [Packages] 28 | MdePkg/MdePkg.dec 29 | MdeModulePkg/MdeModulePkg.dec 30 | EfiPkg/EfiPkg.dec 31 | 32 | [Guids] 33 | gEfiHobListGuid ## CONSUMES 34 | gAppleDebugMaskHobGuid ## CONSUMES 35 | 36 | [Protocols] 37 | gEfiDebugMaskProtocolGuid ## PRODUCES 38 | 39 | [Pcd] 40 | gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel ## CONSUMES 41 | 42 | [LibraryClasses] 43 | PcdLib 44 | 45 | [Sources] 46 | AppleDxeDebugPrintErrorLevelLib.c 47 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleEventLib/AppleEventLib.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | // EventLibCreateTimerEvent 7 | EFI_EVENT 8 | EventLibCreateTimerEvent ( 9 | IN EFI_EVENT_NOTIFY NotifyFunction, 10 | IN VOID *NotifyContext, 11 | IN UINT64 TriggerTime, 12 | IN BOOLEAN SignalPeriodic, 13 | IN EFI_TPL NotifyTpl 14 | ) 15 | { 16 | EFI_EVENT Event; 17 | 18 | EFI_STATUS Status; 19 | 20 | Event = NULL; 21 | 22 | if (NotifyTpl >= TPL_CALLBACK) { 23 | Status = gBS->CreateEvent ( 24 | ((NotifyFunction != NULL) 25 | ? (EVT_TIMER | EVT_NOTIFY_SIGNAL) 26 | : EVT_TIMER), 27 | NotifyTpl, 28 | NotifyFunction, 29 | NotifyContext, 30 | &Event 31 | ); 32 | 33 | if (!EFI_ERROR (Status)) { 34 | Status = gBS->SetTimer ( 35 | Event, 36 | (SignalPeriodic ? TimerPeriodic : TimerRelative), 37 | TriggerTime 38 | ); 39 | 40 | if (EFI_ERROR (Status)) { 41 | gBS->CloseEvent (Event); 42 | 43 | Event = NULL; 44 | } 45 | } 46 | } 47 | 48 | return Event; 49 | } 50 | 51 | // EventLibCreateNotifyTimerEvent 52 | EFI_EVENT 53 | EventLibCreateNotifyTimerEvent ( 54 | IN EFI_EVENT_NOTIFY NotifyFunction, 55 | IN VOID *NotifyContext, 56 | IN UINT64 TriggerTime, 57 | IN BOOLEAN SignalPeriodic 58 | ) 59 | { 60 | return EventLibCreateTimerEvent ( 61 | NotifyFunction, 62 | NotifyContext, 63 | TriggerTime, 64 | SignalPeriodic, 65 | TPL_NOTIFY 66 | ); 67 | } 68 | 69 | // EventLibCancelEvent 70 | VOID 71 | EventLibCancelEvent ( 72 | IN EFI_EVENT Event 73 | ) 74 | { 75 | EFI_STATUS Status; 76 | 77 | Status = gBS->SetTimer (Event, TimerCancel, 0); 78 | 79 | if (!EFI_ERROR (Status)) { 80 | Status = gBS->CloseEvent (Event); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleEventLib/AppleEventLib.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | BASE_NAME = AppleEventLib 3 | MODULE_TYPE = BASE 4 | INF_VERSION = 0x00010005 5 | LIBRARY_CLASS = AppleEventLib 6 | 7 | [Packages] 8 | MdePkg/MdePkg.dec 9 | EfiPkg/EfiPkg.dec 10 | 11 | [Sources] 12 | AppleEventLib.c 13 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleInterruptLib/AppleInterruptLib.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | BASE_NAME = AppleInterruptLib 3 | MODULE_TYPE = UEFI_DRIVER 4 | INF_VERSION = 0x00010005 5 | LIBRARY_CLASS = AppleInterruptLib 6 | 7 | [Packages] 8 | MdePkg/MdePkg.dec 9 | EfiPkg/EfiPkg.dec 10 | 11 | [Sources.IA32] 12 | Ia32/Interrupt.nasm | MSFT 13 | Ia32/Interrupt.nasm | INTEL 14 | Ia32/Interrupt.nasm | RVCT 15 | Ia32/Interrupt.S | GCC 16 | Ia32/Interrupt.S | XCODE 17 | 18 | [Sources.X64] 19 | X64/Interrupt.nasm | MSFT 20 | X64/Interrupt.nasm | INTEL 21 | X64/Interrupt.nasm | RVCT 22 | X64/Interrupt.S | GCC 23 | X64/Interrupt.S | XCODE 24 | 25 | [Sources.ARM, Sources.AARCH64, Sources.IPF, Sources.EBC] 26 | InterruptNull.c 27 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleInterruptLib/Ia32/Interrupt.S: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # // AppleInterrupt 3 | # VOID 4 | # EFIAPI 5 | # AppleInterrupt ( 6 | # IN UINT32 FunctiondId, 7 | # ... 8 | # ); 9 | #------------------------------------------------------------------------------ 10 | ASM_GLOBAL ASM_PFX(AppleInterrupt) 11 | ASM_PFX(AppleInterrupt): 12 | push %ebp 13 | mov %ebp, %esp 14 | int $0x21 15 | pop %ebp 16 | ret 17 | 18 | ASM_FUNCTION_REMOVE_IF_UNREFERENCED 19 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleInterruptLib/Ia32/Interrupt.nasm: -------------------------------------------------------------------------------- 1 | DEFAULT REL 2 | SECTION .text 3 | 4 | ;------------------------------------------------------------------------------ 5 | ; // AppleInterrupt 6 | ; VOID 7 | ; EFIAPI 8 | ; AppleInterrupt ( 9 | ; IN UINT32 FunctiondId, 10 | ; ... 11 | ; ); 12 | ;------------------------------------------------------------------------------ 13 | global ASM_PFX(AppleInterrupt) 14 | ASM_PFX(AppleInterrupt): 15 | push ebp 16 | mov ebp, esp 17 | int 21h 18 | pop ebp 19 | retn 20 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleInterruptLib/InterruptNull.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // AppleInterrupt 4 | RETURN_STATUS 5 | EFIAPI 6 | AppleInterrupt ( 7 | IN UINT32 FunctiondId, 8 | ... 9 | ) 10 | { 11 | return RETURN_SUCCESS; 12 | } 13 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleInterruptLib/X64/Interrupt.S: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # // AppleInterrupt 3 | # VOID 4 | # EFIAPI 5 | # AppleInterrupt ( 6 | # IN UINT32 FunctiondId, 7 | # ... 8 | # ); 9 | #------------------------------------------------------------------------------ 10 | ASM_GLOBAL ASM_PFX(AppleInterrupt) 11 | ASM_PFX(AppleInterrupt): 12 | push %rbp 13 | mov %rbp, %rsp 14 | int $0x21 15 | pop %rbp 16 | ret 17 | 18 | ASM_FUNCTION_REMOVE_IF_UNREFERENCED 19 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleInterruptLib/X64/Interrupt.nasm: -------------------------------------------------------------------------------- 1 | DEFAULT REL 2 | SECTION .text 3 | 4 | ;------------------------------------------------------------------------------ 5 | ; // AppleInterrupt 6 | ; VOID 7 | ; EFIAPI 8 | ; AppleInterrupt ( 9 | ; IN UINT32 FunctiondId, 10 | ; ... 11 | ; ); 12 | ;------------------------------------------------------------------------------ 13 | global ASM_PFX(AppleInterrupt) 14 | ASM_PFX(AppleInterrupt): 15 | push rbp 16 | mov rbp, rsp 17 | int 21h 18 | pop rbp 19 | retn 20 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleSmbiosLib/AppleSmbiosLib.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | // mSmbios 15 | STATIC CONST EFI_SMBIOS_PROTOCOL *mSmbios = NULL; 16 | 17 | // InternalGetSmbiosProtocol 18 | STATIC 19 | EFI_STATUS 20 | InternalGetSmbiosProtocol ( 21 | VOID 22 | ) 23 | { 24 | EFI_STATUS Status; 25 | 26 | Status = EFI_SUCCESS; 27 | 28 | if (mSmbios == NULL) { 29 | Status = gBS->LocateProtocol ( 30 | &gEfiSmbiosProtocolGuid, 31 | NULL, 32 | (VOID **)&mSmbios 33 | ); 34 | } 35 | 36 | return Status; 37 | } 38 | 39 | // SmbiosGetRecord 40 | SMBIOS_STRUCTURE * 41 | SmbiosGetRecord ( 42 | IN EFI_SMBIOS_HANDLE Handle 43 | ) 44 | { 45 | SMBIOS_STRUCTURE *Record; 46 | 47 | EFI_STATUS Status; 48 | EFI_SMBIOS_HANDLE SmbiosHandle; 49 | EFI_SMBIOS_TABLE_HEADER *RecordWalker; 50 | EFI_HANDLE ProducerHandle; 51 | 52 | Record = NULL; 53 | 54 | Status = InternalGetSmbiosProtocol (); 55 | 56 | if (!EFI_ERROR (Status)) { 57 | SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED; 58 | RecordWalker = NULL; 59 | 60 | do { 61 | ProducerHandle = NULL; 62 | Status = mSmbios->GetNext ( 63 | mSmbios, 64 | &SmbiosHandle, 65 | NULL, 66 | &RecordWalker, 67 | &ProducerHandle 68 | ); 69 | 70 | if ((SmbiosHandle == Handle) && !EFI_ERROR (Status)) { 71 | Record = (SMBIOS_STRUCTURE *)RecordWalker; 72 | 73 | break; 74 | } 75 | } while (!EFI_ERROR (Status)); 76 | } 77 | 78 | return Record; 79 | } 80 | 81 | // SmbiosAdd 82 | VOID 83 | SmbiosAdd ( 84 | IN SMBIOS_STRUCTURE *Record 85 | ) 86 | { 87 | EFI_STATUS Status; 88 | 89 | EFI_SMBIOS_TABLE_HEADER *SmbiosRecord; 90 | EFI_SMBIOS_HANDLE SmbiosHandle; 91 | 92 | Status = InternalGetSmbiosProtocol (); 93 | 94 | if (!EFI_ERROR (Status)) { 95 | // BUG: Use AllocatePool () and manually set the two zeros. 96 | SmbiosRecord = AllocateZeroPool (Record->Length + 2); 97 | 98 | if (SmbiosRecord != NULL) { 99 | CopyMem ((VOID *)SmbiosRecord, (VOID *)Record, (UINTN)Record->Length); 100 | 101 | SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED; 102 | Status = mSmbios->Add ( 103 | mSmbios, 104 | gImageHandle, 105 | &SmbiosHandle, 106 | SmbiosRecord 107 | ); 108 | 109 | ASSERT_EFI_ERROR (Status); 110 | 111 | FreePool ((VOID *)SmbiosRecord); 112 | 113 | SmbiosGetRecord (SmbiosHandle); 114 | } 115 | } 116 | } 117 | 118 | // SmbiosUpdateString 119 | VOID 120 | SmbiosUpdateString ( 121 | IN EFI_SMBIOS_HANDLE *Handle, 122 | IN UINTN StringNumber, 123 | IN CHAR8 *String 124 | ) 125 | { 126 | EFI_STATUS Status; 127 | 128 | if (String != NULL && String[0] != L'\0') { 129 | Status = InternalGetSmbiosProtocol (); 130 | 131 | if (!EFI_ERROR (Status)) { 132 | mSmbios->UpdateString (mSmbios, Handle, &StringNumber, String); 133 | } 134 | } 135 | } 136 | 137 | // SmbiosGetFirstHandle 138 | SMBIOS_STRUCTURE * 139 | SmbiosGetFirstHandle ( 140 | IN EFI_SMBIOS_TYPE Type, 141 | IN OUT EFI_SMBIOS_HANDLE *Handle 142 | ) 143 | { 144 | SMBIOS_STRUCTURE *SmbiosRecord; 145 | 146 | EFI_STATUS Status; 147 | EFI_HANDLE ProducerHandle; 148 | EFI_SMBIOS_TABLE_HEADER *TempRecord; 149 | 150 | SmbiosRecord = NULL; 151 | 152 | Status = InternalGetSmbiosProtocol (); 153 | 154 | if (!EFI_ERROR (Status)) { 155 | ProducerHandle = NULL; 156 | 157 | Status = mSmbios->GetNext ( 158 | mSmbios, 159 | Handle, 160 | &Type, 161 | &TempRecord, 162 | &ProducerHandle 163 | ); 164 | 165 | if (!EFI_ERROR (Status)) { 166 | SmbiosRecord = (SMBIOS_STRUCTURE *)TempRecord; 167 | } 168 | } 169 | 170 | return SmbiosRecord; 171 | } 172 | 173 | // SmbiosInstallTables 174 | EFI_STATUS 175 | SmbiosInstallTables ( 176 | VOID 177 | ) 178 | { 179 | EFI_STATUS Status; 180 | 181 | APPLE_PLATFORM_INFO_DATABASE_PROTOCOL *PlatformInfoDb; 182 | UINT32 SmbiosTemplateSize; 183 | EFI_SMBIOS_TABLE_HEADER *SmbiosRecord; 184 | UINT32 DataSize; 185 | EFI_SMBIOS_HANDLE SmbiosHandle; 186 | UINT8 *Walker; 187 | 188 | Status = gBS->LocateProtocol ( 189 | &gApplePlatformInfoDatabaseProtocolGuid, 190 | NULL, 191 | (VOID **)&PlatformInfoDb 192 | ); 193 | 194 | if (!EFI_ERROR (Status)) { 195 | SmbiosTemplateSize = 0; 196 | Status = PlatformInfoDb->GetFirstDataSize ( 197 | PlatformInfoDb, 198 | &gEfiSmbiosProtocolGuid, 199 | &SmbiosTemplateSize 200 | ); 201 | 202 | if (!EFI_ERROR (Status) || (Status == EFI_BUFFER_TOO_SMALL)) { 203 | SmbiosRecord = AllocatePool (SmbiosTemplateSize); 204 | 205 | Status = EFI_OUT_OF_RESOURCES; 206 | 207 | if (SmbiosTemplateSize != 0) { 208 | Status = PlatformInfoDb->GetFirstData ( 209 | PlatformInfoDb, 210 | &gEfiSmbiosProtocolGuid, 211 | (VOID *)SmbiosRecord, 212 | &SmbiosTemplateSize 213 | ); 214 | 215 | if (!EFI_ERROR (Status)) { 216 | Status = InternalGetSmbiosProtocol (); 217 | 218 | if (EFI_ERROR (Status)) { 219 | Status = (EFI_INVALID_PARAMETER | (MAX_BIT - 2)); 220 | } else if (SmbiosTemplateSize != 0) { 221 | DataSize = 0; 222 | 223 | do { 224 | SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED; 225 | Status = mSmbios->Add ( 226 | mSmbios, 227 | gImageHandle, 228 | &SmbiosHandle, 229 | SmbiosRecord 230 | ); 231 | 232 | if (EFI_ERROR (Status)) { 233 | break; 234 | } 235 | 236 | SmbiosRecord = (EFI_SMBIOS_TABLE_HEADER *)( 237 | (UINTN)SmbiosRecord + SmbiosRecord->Length 238 | ); 239 | 240 | DataSize += (SmbiosRecord->Length + 2); 241 | 242 | Walker = (UINT8 *)SmbiosRecord; 243 | 244 | do { 245 | if ((Walker[0] == 0) && (Walker[1] == 0)) { 246 | break; 247 | } 248 | 249 | ++Walker; 250 | ++DataSize; 251 | } while ((DataSize - 2) < SmbiosTemplateSize); 252 | 253 | SmbiosRecord = (EFI_SMBIOS_TABLE_HEADER *)(Walker + 2); 254 | } while (ALIGN_VALUE (DataSize, 4) < SmbiosTemplateSize); 255 | 256 | if ((ALIGN_VALUE (DataSize, 4) >= SmbiosTemplateSize)) { 257 | ASSERT (DataSize <= SmbiosTemplateSize); 258 | } 259 | } 260 | } 261 | } 262 | } 263 | } 264 | 265 | return Status; 266 | } 267 | -------------------------------------------------------------------------------- /EfiPkg/Library/AppleSmbiosLib/AppleSmbiosLib.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | BASE_NAME = AppleSmbiosLib 3 | MODULE_TYPE = UEFI_DRIVER 4 | INF_VERSION = 0x00010005 5 | LIBRARY_CLASS = AppleSmbiosLib 6 | 7 | [Packages] 8 | MdePkg/MdePkg.dec 9 | EfiPkg/EfiPkg.dec 10 | 11 | [Protocols] 12 | gApplePlatformInfoDatabaseProtocolGuid ## CONSUMES 13 | gEfiSmbiosProtocolGuid ## CONSUMES 14 | 15 | [LibraryClasses] 16 | BaseMemoryLib 17 | DebugLib 18 | MemoryAllocationLib 19 | UefiBootServicesTableLib 20 | 21 | [Sources] 22 | AppleSmbiosLib.c 23 | -------------------------------------------------------------------------------- /EfiPkg/Library/BiosIdLib/BiosIdLib.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Boot service DXE BIOS ID library implementation. 3 | 4 | These functions in this file can be called during DXE and cannot be called during runtime 5 | or in SMM which should use a RT or SMM library. 6 | 7 | Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.
8 | This program and the accompanying materials 9 | are licensed and made available under the terms and conditions of the BSD License 10 | which accompanies this distribution. The full text of the license may be found at 11 | http://opensource.org/licenses/bsd-license.php 12 | 13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 15 | 16 | **/ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | STATIC 32 | VOID * 33 | InternalGetImage ( 34 | IN EFI_GUID *NameGuid, 35 | IN EFI_SECTION_TYPE SectionType, 36 | OUT UINTN *Size 37 | ) 38 | { 39 | VOID *Buffer; 40 | EFI_STATUS Status; 41 | EFI_HANDLE *HandleBuffer; 42 | UINTN NumberOfHandles; 43 | UINTN Index; 44 | EFI_FIRMWARE_VOLUME_PROTOCOL *Fv; 45 | UINT32 AuthenticationStatus; 46 | 47 | Buffer = NULL; 48 | 49 | HandleBuffer = NULL; 50 | 51 | Status = gBS->LocateHandleBuffer ( 52 | ByProtocol, 53 | &gEfiFirmwareVolumeProtocolGuid, 54 | NULL, 55 | &NumberOfHandles, 56 | &HandleBuffer 57 | ); 58 | if (!EFI_ERROR (Status)) { 59 | // 60 | // Find desired image in all Fvs 61 | // 62 | for (Index = 0; Index < NumberOfHandles; ++Index) { 63 | Status = gBS->HandleProtocol ( 64 | HandleBuffer[Index], 65 | &gEfiFirmwareVolumeProtocolGuid, 66 | (VOID**)&Fv 67 | ); 68 | 69 | if (EFI_ERROR (Status)) { 70 | break; 71 | } 72 | 73 | // 74 | // Read desired section content in NameGuid file 75 | // 76 | Buffer = NULL; 77 | *Size = 0; 78 | Status = Fv->ReadSection ( 79 | Fv, 80 | NameGuid, 81 | SectionType, 82 | 0, 83 | &Buffer, 84 | Size, 85 | &AuthenticationStatus 86 | ); 87 | 88 | if (!EFI_ERROR (Status)) { 89 | break; 90 | } 91 | } 92 | 93 | FreePool(HandleBuffer); 94 | } 95 | 96 | return Buffer; 97 | } 98 | 99 | // InternalGetBiosId 100 | /** This function returns BIOS ID by searching FV. 101 | 102 | @return BIOS ID 103 | **/ 104 | STATIC 105 | BIOS_ID_IMAGE * 106 | InternalGetBiosId ( 107 | VOID 108 | ) 109 | { 110 | BIOS_ID_IMAGE *BiosId; 111 | 112 | UINTN Size; 113 | 114 | DEBUG ((EFI_D_INFO, "Get BIOS ID from FV\n")); 115 | 116 | BiosId = InternalGetImage ( 117 | &gEfiBiosIdGuid, 118 | EFI_SECTION_RAW, 119 | &Size 120 | ); 121 | 122 | // 123 | // BiosId image is present in FV 124 | // 125 | if (BiosId != NULL) { 126 | DEBUG ((EFI_D_INFO, "Get BIOS ID from FV successfully\n")); 127 | DEBUG ((EFI_D_INFO, "BIOS ID: %s\n", (CHAR16 *)&BiosId->BiosIdString)); 128 | } 129 | 130 | return BiosId; 131 | } 132 | 133 | // GetRomInfo 134 | /** This function returns ROM Info by searching FV. 135 | 136 | @param[out] RomInfo ROM Info 137 | **/ 138 | VOID 139 | GetRomInfo ( 140 | OUT APPLE_ROM_INFO_STRING *RomInfo 141 | ) 142 | { 143 | APPLE_ROM_INFO_STRING RomInfoString; 144 | 145 | UINTN Size; 146 | 147 | RomInfoString = InternalGetImage ( 148 | &gAppleRomInfoGuid, 149 | EFI_SECTION_RAW, 150 | &Size 151 | ); 152 | 153 | // 154 | // RomInfo image is present in FV 155 | // 156 | if (RomInfoString != NULL) { 157 | DEBUG ((EFI_D_INFO, "Get ROM Info from FV successfully\n")); 158 | DEBUG ((EFI_D_INFO, "ROM Info: %s\n", RomInfoString)); 159 | } 160 | 161 | *RomInfo = RomInfoString; 162 | } 163 | 164 | // GetBiosVersionDateTime 165 | /** This function returns the Version & Release Date by getting and converting 166 | BIOS ID. 167 | 168 | @param[out] BiosVersion The Bios Version out of the conversion. 169 | @param[out] BiosReleaseDate The Bios Release Date out of the conversion. 170 | **/ 171 | VOID 172 | GetBiosVersionDateTime ( 173 | OUT CHAR8 **BiosVersion, 174 | OUT CHAR8 **BiosReleaseDate 175 | ) 176 | { 177 | BIOS_ID_IMAGE *BiosIdImage; 178 | UINTN Size; 179 | CHAR16 *BiosId; 180 | CHAR8 *Destination; 181 | 182 | *BiosVersion = NULL; 183 | *BiosReleaseDate = NULL; 184 | 185 | BiosIdImage = InternalGetBiosId (); 186 | 187 | if (BiosIdImage != NULL) { 188 | // 189 | // Fill the BiosVersion data from the BIOS ID. 190 | // 191 | BiosId = (CHAR16 *)&BiosIdImage->BiosIdString.BoardId[0]; 192 | 193 | while (*BiosId == L' ') { 194 | ++BiosId; 195 | } 196 | 197 | // BUG: Use ASCII size. 198 | Size = StrSize (BiosId); 199 | *BiosVersion = AllocateZeroPool (Size); 200 | 201 | if (*BiosVersion != NULL) { 202 | Destination = *BiosVersion; 203 | 204 | while (*BiosId != L'\0') { 205 | *Destination = (CHAR8)*BiosId; 206 | 207 | ++Destination; 208 | ++BiosId; 209 | } 210 | 211 | // BUG: Use ASCII size. 212 | Size = StrSize (L"MM/DD/20YY"); 213 | *BiosReleaseDate = AllocateZeroPool (Size); 214 | 215 | if (*BiosReleaseDate != NULL) { 216 | // 217 | // Fill the build timestamp date from the BIOS ID in the "MM/DD/YY" format. 218 | // 219 | (*BiosReleaseDate)[0] = (CHAR8)BiosIdImage->BiosIdString.TimeStamp[2]; 220 | (*BiosReleaseDate)[1] = (CHAR8)BiosIdImage->BiosIdString.TimeStamp[3]; 221 | (*BiosReleaseDate)[2] = '/'; 222 | 223 | (*BiosReleaseDate)[3] = (CHAR8)BiosIdImage->BiosIdString.TimeStamp[4]; 224 | (*BiosReleaseDate)[4] = (CHAR8)BiosIdImage->BiosIdString.TimeStamp[5]; 225 | (*BiosReleaseDate)[5] = '/'; 226 | 227 | // 228 | // Add 20 for SMBIOS table 229 | // Current Linux kernel will misjudge 09 as year 0, so using 2009 for SMBIOS table 230 | // 231 | (*BiosReleaseDate)[6] = '2'; 232 | (*BiosReleaseDate)[7] = '0'; 233 | (*BiosReleaseDate)[8] = (CHAR8)BiosIdImage->BiosIdString.TimeStamp[0]; 234 | (*BiosReleaseDate)[9] = (CHAR8)BiosIdImage->BiosIdString.TimeStamp[1]; 235 | } else { 236 | FreePool ((VOID *)*BiosVersion); 237 | 238 | *BiosVersion = NULL; 239 | } 240 | } 241 | 242 | if (BiosIdImage != NULL) { 243 | FreePool ((VOID *)BiosIdImage); 244 | } 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /EfiPkg/Library/BiosIdLib/BiosIdLib.inf: -------------------------------------------------------------------------------- 1 | #/*++ 2 | # 3 | # Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved 4 | # 5 | 6 | # This program and the accompanying materials are licensed and made available under 7 | 8 | # the terms and conditions of the BSD License that accompanies this distribution. 9 | 10 | # The full text of the license may be found at 11 | 12 | # http://opensource.org/licenses/bsd-license.php. 13 | 14 | # 15 | 16 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 17 | 18 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 19 | 20 | # 21 | 22 | 23 | # 24 | # Module Name: 25 | # 26 | # BiosIdLib.inf 27 | # 28 | # Abstract: 29 | # 30 | # Component description file for BIOS ID library 31 | # 32 | #--*/ 33 | [Defines] 34 | INF_VERSION = 0x00010005 35 | BASE_NAME = BiosIdLib 36 | FILE_GUID = 98546145-64F1-4d2e-814F-6BF963DB7930 37 | MODULE_TYPE = BASE 38 | VERSION_STRING = 1.0 39 | LIBRARY_CLASS = BiosIdLib 40 | PI_SPECIFICATION_VERSION = 0x0001000A 41 | 42 | [Sources] 43 | BiosIdLib.c 44 | 45 | [Packages] 46 | MdePkg/MdePkg.dec 47 | EfiPkg/EfiPkg.dec 48 | IntelFrameworkPkg/IntelFrameworkPkg.dec 49 | 50 | [LibraryClasses] 51 | HobLib 52 | MemoryAllocationLib 53 | 54 | [Guids] 55 | gEfiBiosIdGuid 56 | 57 | [Protocols] 58 | gEfiFirmwareVolumeProtocolGuid 59 | 60 | [Depex] 61 | gEfiFirmwareVolumeProtocolGuid 62 | -------------------------------------------------------------------------------- /EfiPkg/Library/UefiApplicationEntryPoint/ApplicationEntryPoint.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Entry point library instance to a UEFI application. 3 | 4 | Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.
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 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | /** 24 | Invokes the library destructors for all dependent libraries and terminates 25 | the UEFI Application. 26 | 27 | This function calls ProcessLibraryDestructorList() and the EFI Boot Service Exit() 28 | with a status specified by Status. 29 | 30 | @param Status Status returned by the application that is exiting. 31 | 32 | **/ 33 | VOID 34 | EFIAPI 35 | Exit ( 36 | IN EFI_STATUS Status 37 | ) 38 | 39 | { 40 | ProcessLibraryDestructorList (gImageHandle, gST); 41 | 42 | gBS->Exit (gImageHandle, Status, 0, NULL); 43 | } 44 | 45 | 46 | /** 47 | Naming required by the EBC compiler. 48 | 49 | Entry point to UEFI Application. 50 | 51 | This function is the entry point for a UEFI Application. This function must call 52 | ProcessLibraryConstructorList(), ProcessModuleEntryPointList(), and ProcessLibraryDestructorList(). 53 | The return value from ProcessModuleEntryPointList() is returned. 54 | If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than _gUefiDriverRevison, 55 | then return EFI_INCOMPATIBLE_VERSION. 56 | 57 | @param ImageHandle The image handle of the UEFI Application. 58 | @param SystemTable A pointer to the EFI System Table. 59 | 60 | @retval EFI_SUCCESS The UEFI Application exited normally. 61 | @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than SystemTable->Hdr.Revision. 62 | @retval Other Return value from ProcessModuleEntryPointList(). 63 | 64 | @param ImageHandle The image handle of the UEFI Application. 65 | @param SystemTable A pointer to the EFI System Table. 66 | 67 | @retval EFI_SUCCESS The UEFI Application exited normally. 68 | @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than SystemTable->Hdr.Revision. 69 | @retval Other Return value from ProcessModuleEntryPointList(). 70 | 71 | **/ 72 | EFI_STATUS 73 | EFIAPI 74 | EfiMain ( 75 | IN EFI_HANDLE ImageHandle, 76 | IN EFI_SYSTEM_TABLE *SystemTable 77 | ) 78 | { 79 | EFI_STATUS Status; 80 | 81 | if (_gUefiDriverRevision != 0) { 82 | // 83 | // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the application. 84 | // 85 | if (SystemTable->Hdr.Revision < _gUefiDriverRevision) { 86 | return EFI_INCOMPATIBLE_VERSION; 87 | } 88 | } 89 | 90 | // 91 | // Enable SSE and AVX 92 | // 93 | AppleEnableCpuExtensions (); 94 | 95 | // 96 | // Call constructor for all libraries. 97 | // 98 | ProcessLibraryConstructorList (ImageHandle, SystemTable); 99 | 100 | // 101 | // Call the module's entry point 102 | // 103 | Status = ProcessModuleEntryPointList (ImageHandle, SystemTable); 104 | 105 | // 106 | // Process destructor for all libraries. 107 | // 108 | ProcessLibraryDestructorList (ImageHandle, SystemTable); 109 | 110 | // 111 | // Return the return status code from the driver entry point 112 | // 113 | return Status; 114 | } 115 | -------------------------------------------------------------------------------- /EfiPkg/Library/UefiApplicationEntryPoint/Ia32/_ModuleEntryPoint.S: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # // _ModuleEntryPoint 3 | # <_ModuleEntryPointReturnType> 4 | # EFIAPI 5 | # _ModuleEntryPoint ( 6 | # <_ModuleEntryPointArguments> 7 | # ); 8 | #------------------------------------------------------------------------------ 9 | ASM_GLOBAL ASM_PFX(_ModuleEntryPoint) 10 | ASM_PFX(_ModuleEntryPoint): 11 | push %ebx 12 | lea ASM_PFX(__stack_chk_guard), %ebx 13 | # rdrand eax 14 | .byte 0x0F, 0xC7, 0xF0 15 | mov %eax, (%ebx) 16 | pop %ebx 17 | jmp ASM_PFX(EfiMain) 18 | 19 | ASM_FUNCTION_REMOVE_IF_UNREFERENCED 20 | -------------------------------------------------------------------------------- /EfiPkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Module entry point library for UEFI Application. 3 | # 4 | # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
5 | # 6 | # This program and the accompanying materials 7 | # are licensed and made available under the terms and conditions of the BSD License 8 | # which accompanies this distribution. The full text of the license may be found at 9 | # 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. 12 | # 13 | # 14 | ## 15 | 16 | [Defines] 17 | INF_VERSION = 0x00010005 18 | BASE_NAME = UefiApplicationEntryPoint 19 | FILE_GUID = DADE8301-CB29-4fd5-8148-56FD246C5B88 20 | MODULE_TYPE = UEFI_APPLICATION 21 | VERSION_STRING = 1.0 22 | LIBRARY_CLASS = UefiApplicationEntryPoint|UEFI_APPLICATION 23 | 24 | # 25 | # VALID_ARCHITECTURES = IA32 X64 IPF EBC 26 | # 27 | 28 | [Sources] 29 | ApplicationEntryPoint.c 30 | 31 | [Sources.IA32] 32 | Ia32/_ModuleEntryPoint.S | GCC 33 | Ia32/_ModuleEntryPoint.S | XCODE 34 | Ia32/_ModuleEntryPoint.S | RCVT 35 | 36 | [Sources.X64] 37 | X64/_ModuleEntryPoint.S | GCC 38 | X64/_ModuleEntryPoint.S | XCODE 39 | X64/_ModuleEntryPoint.S | RCVT 40 | 41 | [Sources.IA32, Sources.X64] 42 | _ModuleEntryPoint.c | MSFT 43 | _ModuleEntryPoint.c | INTEL 44 | 45 | 46 | [Packages] 47 | MdePkg/MdePkg.dec 48 | EfiPkg/EfiPkg.dec 49 | 50 | [LibraryClasses] 51 | AppleCpuExtensionsLib 52 | UefiBootServicesTableLib 53 | DebugLib 54 | BaseLib 55 | 56 | -------------------------------------------------------------------------------- /EfiPkg/Library/UefiApplicationEntryPoint/X64/_ModuleEntryPoint.S: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # // _ModuleEntryPoint 3 | # <_ModuleEntryPointReturnType> 4 | # EFIAPI 5 | # _ModuleEntryPoint ( 6 | # <_ModuleEntryPointArguments> 7 | # ); 8 | #------------------------------------------------------------------------------ 9 | ASM_GLOBAL ASM_PFX(_ModuleEntryPoint) 10 | ASM_PFX(_ModuleEntryPoint): 11 | push %rbx 12 | lea ASM_PFX(__stack_chk_guard)(%rip), %rbx 13 | # rdrand rax 14 | .byte 0x48, 0x0F, 0xC7, 0xF0 15 | mov %rax, (%rbx) 16 | pop %rbx 17 | jmp ASM_PFX(EfiMain) 18 | 19 | ASM_FUNCTION_REMOVE_IF_UNREFERENCED 20 | -------------------------------------------------------------------------------- /EfiPkg/Library/UefiApplicationEntryPoint/_ModuleEntryPoint.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | EFI_STATUS 4 | EFIAPI 5 | EfiMain ( 6 | IN EFI_HANDLE ImageHandle, 7 | IN EFI_SYSTEM_TABLE *SystemTable 8 | ); 9 | 10 | /** 11 | The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM 12 | Driver, or UEFI Driver. 13 | 14 | This function is the entry point for a DXE Driver, DXE Runtime Driver, DXE SMM Driver, 15 | or UEFI Driver. This function must call ProcessLibraryConstructorList() and 16 | ProcessModuleEntryPointList(). If the return status from ProcessModuleEntryPointList() 17 | is an error status, then ProcessLibraryDestructorList() must be called. The return 18 | value from ProcessModuleEntryPointList() is returned. If _gDriverUnloadImageCount 19 | is greater than zero, then an unload handler must be registered for this image 20 | and the unload handler must invoke ProcessModuleUnloadList(). 21 | If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than 22 | _gUefiDriverRevison, then return EFI_INCOMPATIBLE_VERSION. 23 | 24 | 25 | @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, 26 | DXE SMM Driver, or UEFI Driver. 27 | @param SystemTable A pointer to the EFI System Table. 28 | 29 | @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM 30 | Driver, or UEFI Driver exited normally. 31 | @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than 32 | SystemTable->Hdr.Revision. 33 | @retval Other Return value from ProcessModuleEntryPointList(). 34 | **/ 35 | EFI_STATUS 36 | EFIAPI 37 | _ModuleEntryPoint ( 38 | IN EFI_HANDLE ImageHandle, 39 | IN EFI_SYSTEM_TABLE *SystemTable 40 | ) 41 | { 42 | return EfiMain (ImageHandle, SystemTable); 43 | } 44 | -------------------------------------------------------------------------------- /EfiPkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Entry point to a EFI/DXE driver. 3 | 4 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
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 | 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | /** 29 | Unloads an image from memory. 30 | 31 | This function is a callback that a driver registers to do cleanup 32 | when the UnloadImage boot service function is called. 33 | 34 | @param ImageHandle The handle to the image to unload. 35 | 36 | @return Status returned by all unload(). 37 | 38 | **/ 39 | EFI_STATUS 40 | EFIAPI 41 | _DriverUnloadHandler ( 42 | EFI_HANDLE ImageHandle 43 | ) 44 | { 45 | EFI_STATUS Status; 46 | 47 | // 48 | // If an UnloadImage() handler is specified, then call it 49 | // 50 | Status = ProcessModuleUnloadList (ImageHandle); 51 | 52 | // 53 | // If the driver specific unload handler does not return an error, then call all of the 54 | // library destructors. If the unload handler returned an error, then the driver can not be 55 | // unloaded, and the library destructors should not be called 56 | // 57 | if (!EFI_ERROR (Status)) { 58 | ProcessLibraryDestructorList (ImageHandle, gST); 59 | } 60 | 61 | // 62 | // Return the status from the driver specific unload handler 63 | // 64 | return Status; 65 | } 66 | 67 | 68 | /** 69 | Naming required by the EBC compiler. 70 | 71 | The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM 72 | Driver, or UEFI Driver. 73 | 74 | This function is the entry point for a DXE Driver, DXE Runtime Driver, DXE SMM Driver, 75 | or UEFI Driver. This function must call ProcessLibraryConstructorList() and 76 | ProcessModuleEntryPointList(). If the return status from ProcessModuleEntryPointList() 77 | is an error status, then ProcessLibraryDestructorList() must be called. The return 78 | value from ProcessModuleEntryPointList() is returned. If _gDriverUnloadImageCount 79 | is greater than zero, then an unload handler must be registered for this image 80 | and the unload handler must invoke ProcessModuleUnloadList(). 81 | If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than 82 | _gUefiDriverRevison, then return EFI_INCOMPATIBLE_VERSION. 83 | 84 | 85 | @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, 86 | DXE SMM Driver, or UEFI Driver. 87 | @param SystemTable A pointer to the EFI System Table. 88 | 89 | @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM 90 | Driver, or UEFI Driver exited normally. 91 | @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than 92 | SystemTable->Hdr.Revision. 93 | @retval Other Return value from ProcessModuleEntryPointList(). 94 | **/ 95 | EFI_STATUS 96 | EFIAPI 97 | EfiMain ( 98 | IN EFI_HANDLE ImageHandle, 99 | IN EFI_SYSTEM_TABLE *SystemTable 100 | ) 101 | { 102 | EFI_STATUS Status; 103 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; 104 | 105 | if (_gUefiDriverRevision != 0) { 106 | // 107 | // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver 108 | // 109 | if (SystemTable->Hdr.Revision < _gUefiDriverRevision) { 110 | return EFI_INCOMPATIBLE_VERSION; 111 | } 112 | } 113 | 114 | // 115 | // Enable SSE and AVX 116 | // 117 | AppleEnableCpuExtensions (); 118 | 119 | // 120 | // Call constructor for all libraries 121 | // 122 | ProcessLibraryConstructorList (ImageHandle, SystemTable); 123 | 124 | // 125 | // Install unload handler... 126 | // 127 | if (_gDriverUnloadImageCount != 0) { 128 | Status = gBS->HandleProtocol ( 129 | ImageHandle, 130 | &gEfiLoadedImageProtocolGuid, 131 | (VOID **)&LoadedImage 132 | ); 133 | ASSERT_EFI_ERROR (Status); 134 | LoadedImage->Unload = _DriverUnloadHandler; 135 | } 136 | 137 | // 138 | // Call the driver entry point 139 | // 140 | Status = ProcessModuleEntryPointList (ImageHandle, SystemTable); 141 | 142 | // 143 | // If all of the drivers returned errors, then invoke all of the library destructors 144 | // 145 | if (EFI_ERROR (Status)) { 146 | ProcessLibraryDestructorList (ImageHandle, SystemTable); 147 | } 148 | 149 | // 150 | // Return the cummalative return status code from all of the driver entry points 151 | // 152 | return Status; 153 | } 154 | -------------------------------------------------------------------------------- /EfiPkg/Library/UefiDriverEntryPoint/Ia32/_ModuleEntryPoint.S: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # // _ModuleEntryPoint 3 | # <_ModuleEntryPointReturnType> 4 | # EFIAPI 5 | # _ModuleEntryPoint ( 6 | # <_ModuleEntryPointArguments> 7 | # ); 8 | #------------------------------------------------------------------------------ 9 | ASM_GLOBAL ASM_PFX(_ModuleEntryPoint) 10 | ASM_PFX(_ModuleEntryPoint): 11 | push %ebx 12 | lea ASM_PFX(__stack_chk_guard), %ebx 13 | # rdrand eax 14 | .byte 0x0F, 0xC7, 0xF0 15 | mov %eax, (%ebx) 16 | pop %ebx 17 | jmp ASM_PFX(EfiMain) 18 | 19 | ASM_FUNCTION_REMOVE_IF_UNREFERENCED 20 | -------------------------------------------------------------------------------- /EfiPkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Module entry point library for UEFI driver, DXE driver and SMM driver. 3 | # 4 | # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
5 | # 6 | # This program and the accompanying materials 7 | # are licensed and made available under the terms and conditions of the BSD License 8 | # which accompanies this distribution. The full text of the license may be found at 9 | # 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. 12 | # 13 | # 14 | ## 15 | 16 | [Defines] 17 | INF_VERSION = 0x00010005 18 | BASE_NAME = UefiDriverEntryPoint 19 | FILE_GUID = 331deb15-454b-48d8-9b74-70d01f3f3556 20 | MODULE_TYPE = UEFI_DRIVER 21 | VERSION_STRING = 1.0 22 | LIBRARY_CLASS = UefiDriverEntryPoint|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER UEFI_DRIVER SMM_CORE DXE_SMM_DRIVER 23 | 24 | # 25 | # The following information is for reference only and not required by the build tools. 26 | # 27 | # VALID_ARCHITECTURES = IA32 X64 IPF EBC 28 | # 29 | 30 | [Sources] 31 | DriverEntryPoint.c 32 | 33 | [Sources.IA32] 34 | Ia32/_ModuleEntryPoint.S | GCC 35 | Ia32/_ModuleEntryPoint.S | XCODE 36 | Ia32/_ModuleEntryPoint.S | RCVT 37 | 38 | [Sources.X64] 39 | X64/_ModuleEntryPoint.S | GCC 40 | X64/_ModuleEntryPoint.S | XCODE 41 | X64/_ModuleEntryPoint.S | RCVT 42 | 43 | [Sources.IA32, Sources.X64] 44 | _ModuleEntryPoint.c | MSFT 45 | _ModuleEntryPoint.c | INTEL 46 | 47 | [Sources.ARM, Sources.AARCH64, Sources.IPF, Sources.EBC] 48 | _ModuleEntryPoint.c 49 | 50 | 51 | 52 | [Packages] 53 | MdePkg/MdePkg.dec 54 | EfiPkg/EfiPkg.dec 55 | 56 | 57 | [LibraryClasses] 58 | AppleCpuExtensionsLib 59 | UefiBootServicesTableLib 60 | DebugLib 61 | BaseLib 62 | 63 | [Protocols] 64 | gEfiLoadedImageProtocolGuid ## SOMETIMES_CONSUMES 65 | 66 | 67 | # 68 | # For UEFI drivers, these architectural protocols defined in PI 1.0 spec need 69 | # to be appended and merged to the final dependency section. 70 | # 71 | [Depex.common.UEFI_DRIVER] 72 | gEfiBdsArchProtocolGuid AND 73 | gEfiCpuArchProtocolGuid AND 74 | gEfiMetronomeArchProtocolGuid AND 75 | gEfiMonotonicCounterArchProtocolGuid AND 76 | gEfiRealTimeClockArchProtocolGuid AND 77 | gEfiResetArchProtocolGuid AND 78 | gEfiRuntimeArchProtocolGuid AND 79 | gEfiSecurityArchProtocolGuid AND 80 | gEfiTimerArchProtocolGuid AND 81 | gEfiVariableWriteArchProtocolGuid AND 82 | gEfiVariableArchProtocolGuid AND 83 | gEfiWatchdogTimerArchProtocolGuid 84 | 85 | -------------------------------------------------------------------------------- /EfiPkg/Library/UefiDriverEntryPoint/X64/_ModuleEntryPoint.S: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # // _ModuleEntryPoint 3 | # <_ModuleEntryPointReturnType> 4 | # EFIAPI 5 | # _ModuleEntryPoint ( 6 | # <_ModuleEntryPointArguments> 7 | # ); 8 | #------------------------------------------------------------------------------ 9 | ASM_GLOBAL ASM_PFX(_ModuleEntryPoint) 10 | ASM_PFX(_ModuleEntryPoint): 11 | push %rbx 12 | lea ASM_PFX(__stack_chk_guard)(%rip), %rbx 13 | # rdrand rax 14 | .byte 0x48, 0x0F, 0xC7, 0xF0 15 | mov %rax, (%rbx) 16 | pop %rbx 17 | jmp ASM_PFX(EfiMain) 18 | 19 | ASM_FUNCTION_REMOVE_IF_UNREFERENCED 20 | -------------------------------------------------------------------------------- /EfiPkg/Library/UefiDriverEntryPoint/_ModuleEntryPoint.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | EFI_STATUS 4 | EFIAPI 5 | EfiMain ( 6 | IN EFI_HANDLE ImageHandle, 7 | IN EFI_SYSTEM_TABLE *SystemTable 8 | ); 9 | 10 | /** 11 | The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM 12 | Driver, or UEFI Driver. 13 | 14 | This function is the entry point for a DXE Driver, DXE Runtime Driver, DXE SMM Driver, 15 | or UEFI Driver. This function must call ProcessLibraryConstructorList() and 16 | ProcessModuleEntryPointList(). If the return status from ProcessModuleEntryPointList() 17 | is an error status, then ProcessLibraryDestructorList() must be called. The return 18 | value from ProcessModuleEntryPointList() is returned. If _gDriverUnloadImageCount 19 | is greater than zero, then an unload handler must be registered for this image 20 | and the unload handler must invoke ProcessModuleUnloadList(). 21 | If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than 22 | _gUefiDriverRevison, then return EFI_INCOMPATIBLE_VERSION. 23 | 24 | 25 | @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, 26 | DXE SMM Driver, or UEFI Driver. 27 | @param SystemTable A pointer to the EFI System Table. 28 | 29 | @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM 30 | Driver, or UEFI Driver exited normally. 31 | @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than 32 | SystemTable->Hdr.Revision. 33 | @retval Other Return value from ProcessModuleEntryPointList(). 34 | **/ 35 | EFI_STATUS 36 | EFIAPI 37 | _ModuleEntryPoint ( 38 | IN EFI_HANDLE ImageHandle, 39 | IN EFI_SYSTEM_TABLE *SystemTable 40 | ) 41 | { 42 | return EfiMain (ImageHandle, SystemTable); 43 | } 44 | -------------------------------------------------------------------------------- /EfiPkg/Platform/AppleBootPolicyDxe/AppleBootPolicyDxe.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | BASE_NAME = AppleBootPolicyDxe 3 | FILE_GUID = 4391AA92-6644-4D8A-9A84-DDD405C312F3 4 | MODULE_TYPE = UEFI_DRIVER 5 | ENTRY_POINT = AppleBootPolicyMain 6 | INF_VERSION = 0x00010005 7 | 8 | [Packages] 9 | MdePkg/MdePkg.dec 10 | EfiPkg/EfiPkg.dec 11 | 12 | [Guids] 13 | gAppleApfsContainerInfoGuid ## SOMETIMES_CONSUMES 14 | gAppleApfsVolumeInfoGuid ## SOMETIMES_CONSUMES 15 | gAppleBlessedSystemFileInfoGuid ## SOMETIMES_CONSUMES 16 | gAppleBlessedSystemFolderInfoGuid ## SOMETIMES_CONSUMES 17 | gEfiFileInfoGuid ## SOMETIMES_CONSUMES 18 | 19 | [Protocols] 20 | gAppleBootPolicyProtocolGuid ## PRODUCES 21 | gEfiSimpleFileSystemProtocolGuid ## SOMETIMES_CONSUMES 22 | 23 | [LibraryClasses] 24 | BaseLib 25 | BaseMemoryLib 26 | DebugLib 27 | DevicePathLib 28 | MemoryAllocationLib 29 | PrintLib 30 | UefiBootServicesTableLib 31 | UefiDriverEntryPoint 32 | 33 | [Sources] 34 | AppleBootPolicy.c 35 | -------------------------------------------------------------------------------- /EfiPkg/Platform/AppleEventDxe/AppleEventDxe.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | BASE_NAME = AppleEventDxe 3 | FILE_GUID = 0650F140-439A-2D4F-9807-C92669339399 4 | MODULE_TYPE = UEFI_DRIVER 5 | ENTRY_POINT = AppleEventMain 6 | INF_VERSION = 0x00010005 7 | 8 | [Packages] 9 | MdePkg/MdePkg.dec 10 | EfiPkg/EfiPkg.dec 11 | EfiMiscPkg/EfiMiscPkg.dec 12 | 13 | [Guids] 14 | gAppleVendorVariableGuid 15 | 16 | [Protocols] 17 | gAppleEventProtocolGuid ## PRODUCES 18 | gAppleKeyMapAggregatorProtocolGuid 19 | gEfiConsoleControlProtocolGuid 20 | gEfiSimplePointerProtocolGuid 21 | gEfiUgaDrawProtocolGuid 22 | gEfiGraphicsOutputProtocolGuid 23 | 24 | [LibraryClasses] 25 | AppleEventLib 26 | BaseLib 27 | BaseMemoryLib 28 | DebugLib 29 | UefiBootServicesTableLib 30 | UefiDriverEntryPoint 31 | UefiLib 32 | UefiRuntimeServicesTableLib 33 | 34 | [Sources] 35 | AppleEvent.c 36 | EventQueue.c 37 | KeyHandler.c 38 | PointerHandler.c 39 | AppleKeyMap.c 40 | -------------------------------------------------------------------------------- /EfiPkg/Platform/AppleEventDxe/AppleEventInternal.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLE_EVENT_INTERNAL_H_ 2 | #define APPLE_EVENT_INTERNAL_H_ 3 | 4 | #include 5 | 6 | #include 7 | 8 | // EventCreateKeyStrokePollEvent 9 | EFI_STATUS 10 | EventCreateKeyStrokePollEvent ( 11 | VOID 12 | ); 13 | 14 | // EventCancelKeyStrokePollEvent 15 | VOID 16 | EventCancelKeyStrokePollEvent ( 17 | VOID 18 | ); 19 | 20 | // EventIsCapsLockOnImpl 21 | /** Retrieves the state of the CapsLock key. 22 | 23 | @param[in, out] CLockOn This parameter indicates the state of the CapsLock 24 | key. 25 | 26 | @retval EFI_SUCCESS The CapsLock state was successfully returned 27 | in CLockOn. 28 | @retval EFI_INVALID_PARAMETER CLockOn is NULL. 29 | **/ 30 | EFI_STATUS 31 | EFIAPI 32 | EventIsCapsLockOnImpl ( 33 | IN OUT BOOLEAN *CLockOn 34 | ); 35 | 36 | // EventCreateSimplePointerInstallNotifyEvent 37 | EFI_STATUS 38 | EventCreateSimplePointerInstallNotifyEvent ( 39 | VOID 40 | ); 41 | 42 | // EventCreateSimplePointerInstallNotifyEvent 43 | VOID 44 | EventCloseSimplePointerInstallNotifyEvent ( 45 | VOID 46 | ); 47 | 48 | // EventCancelSimplePointerPollEvent 49 | VOID 50 | EventCancelSimplePointerPollEvent ( 51 | VOID 52 | ); 53 | 54 | // EventCreateSimplePointerPollEvent 55 | EFI_STATUS 56 | EventCreateSimplePointerPollEvent ( 57 | VOID 58 | ); 59 | 60 | // EventSimplePointerDesctructor 61 | VOID 62 | EventSimplePointerDesctructor ( 63 | VOID 64 | ); 65 | 66 | // EventCreateAppleEventQueueInfo 67 | APPLE_EVENT_INFORMATION * 68 | EventCreateAppleEventQueueInfo ( 69 | IN APPLE_EVENT_DATA EventData, 70 | IN APPLE_EVENT_TYPE EventType, 71 | IN DIMENSION *PointerPosition, 72 | IN APPLE_MODIFIER_MAP Modifiers 73 | ); 74 | 75 | // EventAddEventToQueue 76 | VOID 77 | EventAddEventToQueue ( 78 | IN APPLE_EVENT_INFORMATION *Information 79 | ); 80 | 81 | // EventCreateEventQueue 82 | EFI_STATUS 83 | EventCreateEventQueue ( 84 | IN APPLE_EVENT_DATA EventData, 85 | IN APPLE_EVENT_TYPE EventType, 86 | IN APPLE_MODIFIER_MAP Modifiers 87 | ); 88 | 89 | // InternalSignalAndCloseQueueEvent 90 | VOID 91 | InternalSignalAndCloseQueueEvent ( 92 | VOID 93 | ); 94 | 95 | // EventSetCursorPositionImpl 96 | EFI_STATUS 97 | EventSetCursorPositionImpl ( 98 | IN DIMENSION *Position 99 | ); 100 | 101 | // InternalCreateQueueEvent 102 | VOID 103 | InternalCreateQueueEvent ( 104 | VOID 105 | ); 106 | 107 | // InternalFlagAllEventsReady 108 | VOID 109 | InternalFlagAllEventsReady ( 110 | VOID 111 | ); 112 | 113 | // InternalSingalEvents 114 | VOID 115 | InternalSingalEvents ( 116 | IN APPLE_EVENT_INFORMATION *Information 117 | ); 118 | 119 | // InternalRemoveUnregisteredEvents 120 | VOID 121 | InternalRemoveUnregisteredEvents ( 122 | VOID 123 | ); 124 | 125 | // InternalGetModifierStrokes 126 | APPLE_MODIFIER_MAP 127 | InternalGetModifierStrokes ( 128 | VOID 129 | ); 130 | 131 | // EventInputKeyFromAppleKeyCode 132 | VOID 133 | EventInputKeyFromAppleKeyCode ( 134 | IN APPLE_KEY_CODE AppleKeyCode, 135 | OUT EFI_INPUT_KEY *InputKey, 136 | IN BOOLEAN Shifted 137 | ); 138 | 139 | #endif // APPLE_EVENT_INTERNAL_H_ 140 | -------------------------------------------------------------------------------- /EfiPkg/Platform/AppleEventDxe/EventQueue.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "AppleEventInternal.h" 12 | 13 | // APPLE_EVENT_QUEUE_SIGNATURE 14 | #define APPLE_EVENT_QUEUE_SIGNATURE SIGNATURE_32 ('A', 'E', 'v', 'Q') 15 | 16 | // APPLE_EVENT_QUEUE_FROM_LIST_ENTRY 17 | #define APPLE_EVENT_QUEUE_FROM_LIST_ENTRY(ListEntry) \ 18 | CR ((ListEntry), APPLE_EVENT_QUEUE, Link, APPLE_EVENT_QUEUE_SIGNATURE) 19 | 20 | // APPLE_EVENT_QUEUE 21 | typedef struct { 22 | UINT32 Signature; ///< 23 | LIST_ENTRY Link; ///< 24 | APPLE_EVENT_INFORMATION *Information; ///< 25 | } APPLE_EVENT_QUEUE; 26 | 27 | // mQueueEvent 28 | STATIC EFI_EVENT mQueueEvent = NULL; 29 | 30 | // mQueueEventCreated 31 | STATIC BOOLEAN mQueueEventCreated = FALSE; 32 | 33 | // mEventQueueList 34 | STATIC LIST_ENTRY mQueue = INITIALIZE_LIST_HEAD_VARIABLE (mQueue); 35 | 36 | // mQueueLock 37 | STATIC EFI_LOCK mQueueLock = { 38 | 0, 39 | 0, 40 | FALSE 41 | }; 42 | 43 | // InternalSignalAndCloseQueueEvent 44 | VOID 45 | InternalSignalAndCloseQueueEvent ( 46 | VOID 47 | ) 48 | { 49 | gBS->SignalEvent (mQueueEvent); 50 | 51 | if (mQueueEventCreated && (mQueueEvent != NULL)) { 52 | gBS->CloseEvent (mQueueEvent); 53 | } 54 | } 55 | 56 | // InternalQueueEventNotifyFunction 57 | STATIC 58 | VOID 59 | EFIAPI 60 | InternalQueueEventNotifyFunction ( 61 | IN EFI_EVENT Event, 62 | IN VOID *Context 63 | ) 64 | { 65 | EFI_STATUS Status; 66 | 67 | LIST_ENTRY *EventQueueEntry; 68 | APPLE_EVENT_QUEUE *EventQueue; 69 | 70 | if (mQueueEventCreated) { 71 | do { 72 | Status = EfiAcquireLockOrFail (&mQueueLock); 73 | 74 | // BUG: Should use EFI_ERROR(). 75 | } while (Status != EFI_SUCCESS); 76 | 77 | InternalFlagAllEventsReady (); 78 | 79 | EventQueueEntry = GetFirstNode (&mQueue); 80 | 81 | while (!IsNull (&mQueue, EventQueueEntry)) { 82 | EventQueue = APPLE_EVENT_QUEUE_FROM_LIST_ENTRY (EventQueueEntry); 83 | 84 | InternalSingalEvents (EventQueue->Information); 85 | 86 | if (((EventQueue->Information->EventType & APPLE_ALL_KEYBOARD_EVENTS) != 0) 87 | && (EventQueue->Information->EventData.KeyData != NULL)) { 88 | FreePool ( 89 | (VOID *)EventQueue->Information->EventData.KeyData 90 | ); 91 | } 92 | 93 | EventQueueEntry = RemoveEntryList (EventQueueEntry); 94 | FreePool ((VOID *)EventQueue->Information); 95 | FreePool ((VOID *)EventQueue); 96 | } 97 | 98 | InternalRemoveUnregisteredEvents (); 99 | EfiReleaseLock (&mQueueLock); 100 | } 101 | } 102 | 103 | // InternalCreateQueueEvent 104 | VOID 105 | InternalCreateQueueEvent ( 106 | VOID 107 | ) 108 | { 109 | EFI_STATUS Status; 110 | 111 | EfiInitializeLock (&mQueueLock, TPL_NOTIFY); 112 | 113 | Status = gBS->CreateEvent ( 114 | EVT_NOTIFY_SIGNAL, 115 | TPL_NOTIFY, 116 | InternalQueueEventNotifyFunction, 117 | NULL, 118 | &mQueueEvent 119 | ); 120 | 121 | if (!EFI_ERROR (Status)) { 122 | mQueueEventCreated = TRUE; 123 | } 124 | } 125 | 126 | 127 | // EventCreateAppleEventQueueInfo 128 | APPLE_EVENT_INFORMATION * 129 | EventCreateAppleEventQueueInfo ( 130 | IN APPLE_EVENT_DATA EventData, 131 | IN APPLE_EVENT_TYPE EventType, 132 | IN DIMENSION *PointerPosition, 133 | IN APPLE_MODIFIER_MAP Modifiers 134 | ) 135 | { 136 | APPLE_EVENT_INFORMATION *QueueInfo; 137 | 138 | EFI_TIME CreationTime; 139 | 140 | QueueInfo = AllocateZeroPool (sizeof (*QueueInfo)); 141 | 142 | if (QueueInfo != NULL) { 143 | gRT->GetTime (&CreationTime, NULL); 144 | 145 | QueueInfo->EventType = EventType; 146 | QueueInfo->EventData = EventData; 147 | QueueInfo->Modifiers = Modifiers; 148 | QueueInfo->CreationTime.Year = CreationTime.Year; 149 | QueueInfo->CreationTime.Month = CreationTime.Month; 150 | QueueInfo->CreationTime.Day = CreationTime.Day; 151 | QueueInfo->CreationTime.Hour = CreationTime.Hour; 152 | QueueInfo->CreationTime.Minute = CreationTime.Minute; 153 | QueueInfo->CreationTime.Second = CreationTime.Second; 154 | QueueInfo->CreationTime.Pad1 = CreationTime.Pad1; 155 | 156 | if (PointerPosition != NULL) { 157 | CopyMem ( 158 | (VOID *)&QueueInfo->PointerPosition, 159 | (VOID *)PointerPosition, 160 | sizeof (*PointerPosition) 161 | ); 162 | } 163 | } 164 | 165 | return QueueInfo; 166 | } 167 | 168 | // EventAddEventToQueue 169 | VOID 170 | EventAddEventToQueue ( 171 | IN APPLE_EVENT_INFORMATION *Information 172 | ) 173 | { 174 | EFI_STATUS Status; 175 | 176 | APPLE_EVENT_QUEUE *EventQueue; 177 | 178 | if (mQueueEventCreated) { 179 | do { 180 | Status = EfiAcquireLockOrFail (&mQueueLock); 181 | } while (Status != EFI_SUCCESS); 182 | 183 | EventQueue = AllocatePool (sizeof (*EventQueue)); 184 | 185 | if (EventQueue != NULL) { 186 | EventQueue->Signature = APPLE_EVENT_QUEUE_SIGNATURE; 187 | EventQueue->Information = Information; 188 | 189 | InsertTailList (&mQueue, &EventQueue->Link); 190 | } 191 | 192 | EfiReleaseLock (&mQueueLock); 193 | gBS->SignalEvent (mQueueEvent); 194 | } 195 | } 196 | 197 | // EventCreateEventQueue 198 | EFI_STATUS 199 | EventCreateEventQueue ( 200 | IN APPLE_EVENT_DATA EventData, 201 | IN APPLE_EVENT_TYPE EventType, 202 | IN APPLE_MODIFIER_MAP Modifiers 203 | ) 204 | { 205 | EFI_STATUS Status; 206 | 207 | APPLE_EVENT_INFORMATION *Information; 208 | 209 | Status = EFI_INVALID_PARAMETER; 210 | 211 | if (EventData.Raw != 0 || Modifiers != 0) { 212 | Information = EventCreateAppleEventQueueInfo ( 213 | EventData, 214 | EventType, 215 | NULL, 216 | Modifiers 217 | ); 218 | 219 | Status = EFI_OUT_OF_RESOURCES; 220 | 221 | if (Information != NULL) { 222 | EventAddEventToQueue (Information); 223 | 224 | Status = EFI_SUCCESS; 225 | } 226 | } 227 | 228 | return Status; 229 | } 230 | -------------------------------------------------------------------------------- /EfiPkg/Platform/AppleKeyMapAggregatorDxe/AppleKeyMapAggregatorDxe.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | BASE_NAME = AppleKeyMapAggregatorDxe 3 | FILE_GUID = 1612CCDF-2549-466A-BF6F-D06DAAE60958 4 | MODULE_TYPE = UEFI_DRIVER 5 | ENTRY_POINT = AppleKeyMapAggregatorMain 6 | INF_VERSION = 0x00010005 7 | 8 | [Packages] 9 | MdePkg/MdePkg.dec 10 | EfiPkg/EfiPkg.dec 11 | EfiMiscPkg/EfiMiscPkg.dec 12 | 13 | [Protocols] 14 | gAppleKeyMapDatabaseProtocolGuid ## PRODUCES 15 | gAppleKeyMapAggregatorProtocolGuid ## PRODUCES 16 | 17 | [LibraryClasses] 18 | BaseLib 19 | BaseMemoryLib 20 | DebugLib 21 | UefiBootServicesTableLib 22 | UefiDriverEntryPoint 23 | MemoryAllocationLib 24 | 25 | [Sources] 26 | AppleKeyMapAggregator.c 27 | -------------------------------------------------------------------------------- /EfiPkg/Platform/ApplePlatformInfoDatabase/Dxe/ApplePlatformInfoDatabaseDxe.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | BASE_NAME = ApplePlatformInfoDatabase 3 | FILE_GUID = 8B24E4D4-C84C-4FFC-81E5-D3EACC3F08D 4 | MODULE_TYPE = DXE_DRIVER 5 | ENTRY_POINT = ApplePlatformInfoDatabaseDxeMain 6 | INF_VERSION = 0x00010005 7 | 8 | [Packages] 9 | MdePkg/MdePkg.dec 10 | IntelFrameworkPkg/IntelFrameworkPkg.dec 11 | EfiPkg/EfiPkg.dec 12 | 13 | [Guids] 14 | gAppleHob1Guid ## SOMETIMES_CONSUMES 15 | gAppleFile1Guid ## SOMETIMES_CONSUMES 16 | 17 | [Protocols] 18 | gApplePlatformInfoDatabaseProtocolGuid ## PRODUCES 19 | gEfiFirmwareVolumeProtocolGuid 20 | 21 | [LibraryClasses] 22 | BaseMemoryLib 23 | DebugLib 24 | DevicePathLib 25 | HobLib 26 | MemoryAllocationLib 27 | UefiBootServicesTableLib 28 | UefiDriverEntryPoint 29 | UefiLib 30 | 31 | [Sources] 32 | ApplePlatformInfoDatabase.c 33 | 34 | [Depex] 35 | gEfiPcdProtocolGuid 36 | -------------------------------------------------------------------------------- /EfiPkg/Platform/ApplePlatformSecurityPolicyDxe/ApplePlatformSecurityPolicy.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acidanthera/mac-efi-firmware/759669b625c7d4b6d1d09afd06dd20a0bce8b353/EfiPkg/Platform/ApplePlatformSecurityPolicyDxe/ApplePlatformSecurityPolicy.c -------------------------------------------------------------------------------- /EfiPkg/Platform/EfiDevicePathPropertyDatabaseDxe/EfiDevicePathPropertyDatabaseDxe.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | BASE_NAME = EfiDevicePathPropertyDatabaseDxe 3 | FILE_GUID = 35628CFC-3CFF-444F-99C1-D5F06A069914 4 | INF_VERSION = 0x00010005 5 | MODULE_TYPE = UEFI_DRIVER 6 | ENTRY_POINT = EfiDevicePathPropertyDatabaseMain 7 | 8 | [Packages] 9 | MdePkg/MdePkg.dec 10 | EfiPkg/EfiPkg.dec 11 | 12 | [Guids] 13 | gAppleBootVariableGuid ## CONSUMES ## PRODUCES 14 | gAppleVendorVariableGuid ## CONSUMES ## PRODUCES 15 | 16 | [Protocols] 17 | gEfiDevicePathPropertyDatabaseProtocolGuid ## PRODUCES 18 | 19 | [LibraryClasses] 20 | BaseLib 21 | BaseMemoryLib 22 | DebugLib 23 | DevicePathLib 24 | MemoryAllocationLib 25 | PrintLib 26 | UefiBootServicesTableLib 27 | UefiDriverEntryPoint 28 | UefiRuntimeServicesTableLib 29 | 30 | [Sources] 31 | EfiDevicePathPropertyDatabase.c 32 | -------------------------------------------------------------------------------- /EfiPkg/Platform/EfiOSInfoDxe/EfiOSInfo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | // OS_INFO_VENDOR_NAME 15 | #define OS_INFO_VENDOR_NAME "Apple Inc." 16 | 17 | // mOSName 18 | STATIC CHAR8 *mOSName = NULL; 19 | 20 | // mOSVendor 21 | STATIC CHAR8 *mOSVendor = NULL; 22 | 23 | // mBootVTdEnabled 24 | STATIC UINTN mBootVTdEnabled = 0; 25 | 26 | // mAppleOSLoadedSignaled 27 | STATIC BOOLEAN mAppleOSLoadedSignaled = FALSE; 28 | 29 | // InternalOSInfoSet 30 | STATIC 31 | VOID 32 | InternalOSInfoSet ( 33 | VOID 34 | ) 35 | { 36 | INTN Result; 37 | 38 | if (mOSVendor != NULL) { 39 | Result = AsciiStrCmp (mOSVendor, OS_INFO_VENDOR_NAME); 40 | 41 | if (Result == 0) { 42 | if (!mAppleOSLoadedSignaled) { 43 | EfiNamedEventSignal (&gAppleOSLoadedNamedEventGuid); 44 | 45 | mAppleOSLoadedSignaled = TRUE; 46 | } 47 | 48 | // TODO: OSName logic. 49 | } 50 | } 51 | } 52 | 53 | // OSInfoOSName 54 | VOID 55 | EFIAPI 56 | OSInfoOSName ( 57 | IN CHAR8 *OSName 58 | ) 59 | { 60 | UINTN Size; 61 | 62 | CHAR8 *Buffer; 63 | 64 | Size = AsciiStrSize (OSName); 65 | Buffer = AllocateCopyPool (Size, (CONST VOID *)OSName); 66 | 67 | mOSName = Buffer; 68 | 69 | InternalOSInfoSet (); 70 | } 71 | 72 | // OSInfoOSVendor 73 | VOID 74 | EFIAPI 75 | OSInfoOSVendor ( 76 | IN CHAR8 *OSVendor 77 | ) 78 | { 79 | UINTN Size; 80 | 81 | CHAR8 *Buffer; 82 | 83 | Size = AsciiStrSize (OSVendor); 84 | Buffer = AllocateCopyPool (Size, (CONST VOID *)OSVendor); 85 | 86 | mOSVendor = Buffer; 87 | 88 | InternalOSInfoSet (); 89 | } 90 | 91 | // OSInfoSetBootVTdEnabled 92 | VOID 93 | EFIAPI 94 | OSInfoSetBootVTdEnabled ( 95 | IN UINTN *BootVTdEnabled 96 | ) 97 | { 98 | // BUG: Check BootVTdEnabled for NULL. 99 | 100 | mBootVTdEnabled = *BootVTdEnabled; 101 | } 102 | 103 | // OSInfoGetBootVTdEnabled 104 | VOID 105 | EFIAPI 106 | OSInfoGetBootVTdEnabled ( 107 | OUT UINTN *BootVTdEnabled 108 | ) 109 | { 110 | // BUG: Check BootVTdEnabled for NULL. 111 | 112 | *BootVTdEnabled = mBootVTdEnabled; 113 | } 114 | 115 | // EfiOSInfoMain 116 | /** 117 | 118 | @param[in] ImageHandle The firmware allocated handle for the EFI image. 119 | @param[in] SystemTable A pointer to the EFI System Table. 120 | 121 | @retval EFI_SUCCESS The entry point is executed successfully. 122 | @retval EFI_ALREADY_STARTED The protocol has already been installed. 123 | **/ 124 | EFI_STATUS 125 | EFIAPI 126 | EfiOSInfoMain ( 127 | IN EFI_HANDLE ImageHandle, 128 | IN EFI_SYSTEM_TABLE *SystemTable 129 | ) 130 | { 131 | STATIC EFI_OS_INFO_PROTOCOL OSInfoProtocol = { 132 | EFI_OS_INFO_PROTOCOL_REVISION, 133 | OSInfoOSName, 134 | OSInfoOSVendor, 135 | OSInfoSetBootVTdEnabled, 136 | OSInfoGetBootVTdEnabled 137 | }; 138 | 139 | return gBS->InstallProtocolInterface ( 140 | ImageHandle, 141 | &gEfiOSInfoProtocolGuid, 142 | EFI_NATIVE_INTERFACE, 143 | (VOID *)&OSInfoProtocol 144 | ); 145 | } 146 | -------------------------------------------------------------------------------- /EfiPkg/Platform/EfiOSInfoDxe/EfiOSInfoDxe.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | BASE_NAME = EfiOSInfoDxe 3 | FILE_GUID = 2ECED69B-2793-4388-BA3C-823040EBCCD2 4 | MODULE_TYPE = UEFI_DRIVER 5 | ENTRY_POINT = EfiOSInfoMain 6 | INF_VERSION = 0x00010005 7 | 8 | [Packages] 9 | MdePkg/MdePkg.dec 10 | EfiPkg/EfiPkg.dec 11 | 12 | [Guids] 13 | gAppleOSLoadedNamedEventGuid 14 | 15 | [Protocols] 16 | gEfiOSInfoProtocolGuid ## PRODUCES 17 | 18 | [LibraryClasses] 19 | BaseLib 20 | DebugLib 21 | MemoryAllocationLib 22 | UefiBootServicesTableLib 23 | UefiLib 24 | UefiDriverEntryPoint 25 | UefiRuntimeServicesTableLib 26 | 27 | [Sources] 28 | EfiOSInfo.c 29 | -------------------------------------------------------------------------------- /EfiPkg/Platform/UserInterfaceThemeDriverDxe/UserInterfaceThemeDriver.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | // DEFAULT_BACKGROUND_COLOR 15 | #define DEFAULT_BACKGROUND_COLOR 0 16 | 17 | // InternalGetBackgroundColor 18 | STATIC 19 | EFI_STATUS 20 | EFIAPI 21 | InternalGetBackgroundColor ( 22 | IN OUT UINT32 *BackgroundColor 23 | ); 24 | 25 | // mUserInterfaceThemeProtocol 26 | STATIC EFI_USER_INTERFACE_THEME_PROTOCOL mUserInterfaceThemeProtocol = { 27 | USER_THEME_INTERFACE_PROTOCOL_REVISION, 28 | InternalGetBackgroundColor 29 | }; 30 | 31 | // mDefaultBackgroundColorPresent 32 | STATIC BOOLEAN mDefaultBackgroundColorPresent = FALSE; 33 | 34 | // mLowBatteryUiBackgroundColor 35 | STATIC UINT32 mLowBatteryUiBackgroundColor = DEFAULT_BACKGROUND_COLOR; 36 | 37 | // mCriticalBatteryUi 38 | STATIC BOOLEAN mCriticalBatteryUi = FALSE; 39 | 40 | // mBackgroundColor 41 | STATIC UINT32 mBackgroundColor = DEFAULT_BACKGROUND_COLOR; 42 | 43 | // IsCriticalBatteryUi 44 | STATIC 45 | BOOLEAN 46 | IsCriticalBatteryUi ( 47 | VOID 48 | ) 49 | { 50 | BOOLEAN Result; 51 | 52 | EFI_STATUS Status; 53 | APPLE_SMC_IO_PROTOCOL *SmcIo; 54 | SMC_DATA Value; 55 | UINTN DataSize; 56 | UINT8 CriticalBatteryUi; 57 | 58 | Result = FALSE; 59 | 60 | Status = gBS->LocateProtocol ( 61 | &gAppleSmcIoProtocolGuid, 62 | NULL, 63 | (VOID **)&SmcIo 64 | ); 65 | 66 | if (!EFI_ERROR (Status)) { 67 | Status = SmcIo->SmcReadValue ( 68 | SmcIo, 69 | SMC_MAKE_IDENTIFIER ('B', 'B', 'I', 'F'), 70 | sizeof (Value), 71 | &Value 72 | ); 73 | 74 | Result = TRUE; 75 | 76 | if (EFI_ERROR (Status) || ((Value & BIT0) == 0)) { 77 | DataSize = 0; 78 | 79 | Result = FALSE; 80 | 81 | Status = gRT->GetVariable ( 82 | L"critical-battery-ui", 83 | &gAppleVendorVariableGuid, 84 | 0, 85 | &DataSize, 86 | &CriticalBatteryUi 87 | ); 88 | 89 | if (!EFI_ERROR (Status)) { 90 | Result = ((CriticalBatteryUi & 0x0F) != 0); 91 | } 92 | } 93 | } 94 | 95 | return Result; 96 | } 97 | 98 | // InternalGetBackgroundColor 99 | STATIC 100 | EFI_STATUS 101 | EFIAPI 102 | InternalGetBackgroundColor ( 103 | IN OUT UINT32 *BackgroundColor 104 | ) 105 | { 106 | EFI_STATUS Status; 107 | 108 | UINTN DataSize; 109 | 110 | Status = EFI_INVALID_PARAMETER; 111 | 112 | if (BackgroundColor != NULL) { 113 | if (mCriticalBatteryUi && IsCriticalBatteryUi ()) { 114 | CopyMem ( 115 | (VOID *)BackgroundColor, 116 | (VOID *)&mLowBatteryUiBackgroundColor, 117 | sizeof (*BackgroundColor) 118 | ); 119 | 120 | Status = EFI_SUCCESS; 121 | } else { 122 | CopyMem ( 123 | (VOID *)BackgroundColor, 124 | (VOID *)&mBackgroundColor, 125 | sizeof (*BackgroundColor) 126 | ); 127 | 128 | if (!mDefaultBackgroundColorPresent) { 129 | DataSize = 0; 130 | Status = gRT->GetVariable ( 131 | L"BootUIPrefix", 132 | &gAppleVendorVariableGuid, 133 | 0, 134 | &DataSize, 135 | NULL 136 | ); 137 | 138 | if (Status == EFI_BUFFER_TOO_SMALL) { 139 | ZeroMem (BackgroundColor, sizeof (*BackgroundColor)); 140 | 141 | Status = EFI_SUCCESS; 142 | } 143 | } 144 | } 145 | } 146 | 147 | return Status; 148 | } 149 | 150 | // UserInterfaceThemeDriverMain 151 | EFI_STATUS 152 | EFIAPI 153 | UserInterfaceThemeDriverMain ( 154 | IN EFI_HANDLE ImageHandle, 155 | IN EFI_SYSTEM_TABLE *SystemTable 156 | ) 157 | { 158 | EFI_BOOT_MODE BootMode; 159 | UINTN DataSize; 160 | EFI_STATUS Status; 161 | UINT32 BackgroundColor; 162 | EFI_HANDLE Handle; 163 | 164 | mDefaultBackgroundColorPresent = FALSE; 165 | 166 | mLowBatteryUiBackgroundColor = DEFAULT_BACKGROUND_COLOR; 167 | mCriticalBatteryUi = IsCriticalBatteryUi (); 168 | 169 | BootMode = GetBootModeHob (); 170 | 171 | if (BootMode == 0x81) { 172 | BackgroundColor = DEFAULT_BACKGROUND_COLOR; 173 | } else { 174 | DataSize = sizeof (BackgroundColor); 175 | Status = gRT->GetVariable ( 176 | L"DefaultBackgroundColor", 177 | &gAppleVendorVariableGuid, 178 | 0, 179 | &DataSize, 180 | &BackgroundColor 181 | ); 182 | 183 | if (!EFI_ERROR (Status)) { 184 | mDefaultBackgroundColorPresent = TRUE; 185 | } else { 186 | BackgroundColor = DEFAULT_BACKGROUND_COLOR; 187 | } 188 | } 189 | 190 | CopyMem ( 191 | (VOID *)&mBackgroundColor, 192 | (VOID *)&BackgroundColor, 193 | sizeof (BackgroundColor) 194 | ); 195 | 196 | Handle = NULL; 197 | 198 | return gBS->InstallProtocolInterface ( 199 | &Handle, 200 | &gEfiUserInterfaceThemeProtocolGuid, 201 | EFI_NATIVE_INTERFACE, 202 | &mUserInterfaceThemeProtocol 203 | ); 204 | } 205 | -------------------------------------------------------------------------------- /EfiPkg/Platform/UserInterfaceThemeDriverDxe/UserInterfaceThemeDriverDxe.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | BASE_NAME = UserInterfaceThemeDriverDxe 3 | FILE_GUID = BC468182-0C0B-D645-A8AC-FB5D81076AE8 4 | MODULE_TYPE = UEFI_DRIVER 5 | ENTRY_POINT = UserInterfaceThemeDriverMain 6 | INF_VERSION = 0x00010005 7 | 8 | [Packages] 9 | MdePkg/MdePkg.dec 10 | EfiPkg/EfiPkg.dec 11 | 12 | [Guids] 13 | gAppleVendorVariableGuid 14 | 15 | [Protocols] 16 | gAppleSmcIoProtocolGuid 17 | gEfiUserInterfaceThemeProtocolGuid 18 | 19 | [LibraryClasses] 20 | BaseMemoryLib 21 | HobLib 22 | UefiBootServicesTableLib 23 | UefiDriverEntryPoint 24 | UefiRuntimeServicesTableLib 25 | 26 | [Sources] 27 | UserInterfaceThemeDriver.c 28 | -------------------------------------------------------------------------------- /EfiPkg/Universal/AppleSmbiosDxe/AppleSmbiosDxe.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | BASE_NAME = AppleSmbios 3 | FILE_GUID = 92C6033D-A685-BB41-AA2F-6F6E2CD374A2 4 | MODULE_TYPE = DXE_DRIVER 5 | ENTRY_POINT = AppleSmbiosMain 6 | INF_VERSION = 0x00010005 7 | 8 | [Packages] 9 | MdePkg/MdePkg.dec 10 | EfiPkg/EfiPkg.dec 11 | IntelFrameworkPkg/IntelFrameworkPkg.dec 12 | 13 | [Guids] 14 | gApplePlatformProducerNameGuid ## SOMETIMES_CONSUMES 15 | gAppleFsbFrequencyPlatformInfoGuid ## SOMETIMES_CONSUMES 16 | gAppleRomDataRecordGuid ## SOMETIMES_PRODUCES 17 | gAppleRomProducerNameGuid ## SOMETIMES_PRODUCES 18 | gAppleSystemSerialNumbrDataRecordGuid ## SOMETIMES_PRODUCES 19 | gAppleSystemIdDataRecordGuid ## SOMETIMES_PRODUCES 20 | gAppleMachinePersonalityDataRecordGuid ## SOMETIMES_PRODUCES 21 | gAppleFsbFrequencyDataRecordGuid ## SOMETIMES_PRODUCES 22 | gAppleModelDataRecordGuid ## SOMETIMES_PRODUCES 23 | gAppleDevicePathsSupportedDataRecordGuid ## SOMETIMES_PRODUCES 24 | gAppleBoardIdDataRecordGuid ## SOMETIMES_PRODUCES 25 | gAppleBoardRevisionDataRecordGuid ## SOMETIMES_PRODUCES 26 | gAppleStartupPowerEventsDataRecordGuid ## SOMETIMES_PRODUCES 27 | gAppleInitialTscDataRecordGuid ## SOMETIMES_PRODUCES 28 | gAppleCoprocessorVersionDataRecordGuid ## SOMETIMES_PRODUCES 29 | gAppleRomInfoGuid ## SOMETIMES_CONSUMES 30 | gAppleVendorVariableGuid ## SOMETIMES_CONSUMES 31 | gAppleFsbFrequencyPlatformInfoIndexHobGuid ## SOMETIMES_CONSUMES 32 | gAppleProductInfoPlatformInfoGuid ## SOMETIMES_CONSUMES 33 | 34 | [Protocols] 35 | gAppleDiagAccessProtocolGuid ## SOMETIMES_CONSUMES 36 | gApplePlatformInfoDatabaseProtocolGuid ## SOMETIMES_CONSUMES 37 | gAppleSmcIoProtocolGuid ## SOMETIMES_CONSUMES 38 | 39 | [LibraryClasses] 40 | AppleDataHubLib 41 | AppleSmbiosLib 42 | BaseLib 43 | BaseMemoryLib 44 | BiosIdLib 45 | HobLib 46 | MemoryAllocationLib 47 | PrintLib 48 | UefiBootServicesTableLib 49 | UefiDriverEntryPoint 50 | UefiRuntimeServicesTableLib 51 | 52 | [Sources] 53 | AppleSmbios.c 54 | AppleSmbiosInternal.h 55 | 56 | [Sources.IA32, Sources.X64] 57 | Ia32X64/InternalGetProcessorClass.c 58 | 59 | [Sources.ARM, Sources.AARCH64, Sources.IPF, Sources.EBC] 60 | InternalGetProcessorClass.c 61 | 62 | [Depex] 63 | gEfiDataHubProtocolGuid AND 64 | gApplePlatformInfoDatabaseProtocolGuid AND 65 | gEfiFirmwareVolumeProtocolGuid AND 66 | gEfiVariableArchProtocolGuid AND 67 | gAppleDiagAccessProtocolGuid AND 68 | gAppleSmcIoProtocolGuid AND 69 | # TODO: 10562B2B-B6E0-43EC-95DE-EB411EDB64B0 AND 70 | gEfiPcdProtocolGuid 71 | -------------------------------------------------------------------------------- /EfiPkg/Universal/AppleSmbiosDxe/AppleSmbiosInternal.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLE_SMBIOS_INTERNAL_H_ 2 | #define APPLE_SMBIOS_INTERNAL_H_ 3 | 4 | // InternalGetProcessorClass 5 | VOID 6 | InternalGetProcessorClass ( 7 | OUT UINT8 *ProcessorClass 8 | ); 9 | 10 | #endif // APPLE_SMBIOS_INTERNAL_H_ 11 | -------------------------------------------------------------------------------- /EfiPkg/Universal/AppleSmbiosDxe/Ia32X64/InternalGetProcessorClass.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | CPUID Processor Brand String 10 | 11 | @param EAX CPUID_BRAND_STRING1 (0x80000002) 12 | 13 | @retval EAX Processor Brand String in type CPUID_BRAND_STRING_DATA. 14 | @retval EBX Processor Brand String Continued in type CPUID_BRAND_STRING_DATA. 15 | @retval ECX Processor Brand String Continued in type CPUID_BRAND_STRING_DATA. 16 | @retval EDX Processor Brand String Continued in type CPUID_BRAND_STRING_DATA. 17 | 18 | Example usage 19 | @code 20 | CPUID_BRAND_STRING_DATA Eax; 21 | CPUID_BRAND_STRING_DATA Ebx; 22 | CPUID_BRAND_STRING_DATA Ecx; 23 | CPUID_BRAND_STRING_DATA Edx; 24 | 25 | AsmCpuid (CPUID_BRAND_STRING1, &Eax.Uint32, &Ebx.Uint32, &Ecx.Uint32, &Edx.Uint32); 26 | @endcode 27 | **/ 28 | #define CPUID_BRAND_STRING1 0x80000002 29 | 30 | /** 31 | CPUID Processor Brand String 32 | 33 | @param EAX CPUID_BRAND_STRING2 (0x80000003) 34 | 35 | @retval EAX Processor Brand String Continued in type CPUID_BRAND_STRING_DATA. 36 | @retval EBX Processor Brand String Continued in type CPUID_BRAND_STRING_DATA. 37 | @retval ECX Processor Brand String Continued in type CPUID_BRAND_STRING_DATA. 38 | @retval EDX Processor Brand String Continued in type CPUID_BRAND_STRING_DATA. 39 | 40 | Example usage 41 | @code 42 | CPUID_BRAND_STRING_DATA Eax; 43 | CPUID_BRAND_STRING_DATA Ebx; 44 | CPUID_BRAND_STRING_DATA Ecx; 45 | CPUID_BRAND_STRING_DATA Edx; 46 | 47 | AsmCpuid (CPUID_BRAND_STRING2, &Eax.Uint32, &Ebx.Uint32, &Ecx.Uint32, &Edx.Uint32); 48 | @endcode 49 | **/ 50 | #define CPUID_BRAND_STRING2 0x80000003 51 | 52 | /** 53 | CPUID Processor Brand String 54 | 55 | @param EAX CPUID_BRAND_STRING3 (0x80000004) 56 | 57 | @retval EAX Processor Brand String Continued in type CPUID_BRAND_STRING_DATA. 58 | @retval EBX Processor Brand String Continued in type CPUID_BRAND_STRING_DATA. 59 | @retval ECX Processor Brand String Continued in type CPUID_BRAND_STRING_DATA. 60 | @retval EDX Processor Brand String Continued in type CPUID_BRAND_STRING_DATA. 61 | 62 | Example usage 63 | @code 64 | CPUID_BRAND_STRING_DATA Eax; 65 | CPUID_BRAND_STRING_DATA Ebx; 66 | CPUID_BRAND_STRING_DATA Ecx; 67 | CPUID_BRAND_STRING_DATA Edx; 68 | 69 | AsmCpuid (CPUID_BRAND_STRING3, &Eax.Uint32, &Ebx.Uint32, &Ecx.Uint32, &Edx.Uint32); 70 | @endcode 71 | **/ 72 | #define CPUID_BRAND_STRING3 0x80000004 73 | 74 | // CPUID_BRAND_STRING 75 | typedef struct { 76 | UINT32 Eax; 77 | UINT32 Ebx; 78 | UINT32 Ecx; 79 | UINT32 Edx; 80 | } CPUID_BRAND_STRING; 81 | 82 | // InternalGetProcessorClass 83 | VOID 84 | InternalGetProcessorClass ( 85 | OUT UINT8 *ProcessorClass 86 | ) 87 | { 88 | CHAR8 BrandString[3 * sizeof (CPUID_BRAND_STRING) + 1]; 89 | UINT32 Index; 90 | CPUID_BRAND_STRING BrandStringBuffer; 91 | CHAR8 *BrandStringWalker; 92 | 93 | BrandString[ARRAY_SIZE (BrandString) - 1] = '\0'; 94 | 95 | BrandStringWalker = &BrandString[0]; 96 | 97 | for (Index = CPUID_BRAND_STRING1; Index != CPUID_BRAND_STRING3; ++Index) { 98 | AsmCpuid ( 99 | Index, 100 | &BrandStringBuffer.Eax, 101 | &BrandStringBuffer.Ebx, 102 | &BrandStringBuffer.Ecx, 103 | &BrandStringBuffer.Edx 104 | ); 105 | 106 | CopyMem ( 107 | (VOID *)&BrandStringBuffer, 108 | (VOID *)BrandStringWalker, 109 | sizeof (BrandStringBuffer) 110 | ); 111 | 112 | ++BrandStringWalker; 113 | } 114 | 115 | BrandStringWalker = AsciiStrStr (&BrandString[0], "Core"); 116 | 117 | while ((*BrandStringWalker != ' ') && (*BrandStringWalker != '\0')) { 118 | ++BrandStringWalker; 119 | } 120 | 121 | while (*BrandStringWalker == ' ') { 122 | ++BrandStringWalker; 123 | } 124 | 125 | if (AsciiStrCmp (BrandStringWalker, "i7") == 0) { 126 | *ProcessorClass = AppleProcessorMajorI7; 127 | } else if (AsciiStrCmp (BrandStringWalker, "i5") == 0) { 128 | *ProcessorClass = AppleProcessorMajorI5; 129 | } else if (AsciiStrCmp (BrandStringWalker, "i3") == 0) { 130 | *ProcessorClass = AppleProcessorMajorI3; 131 | } else if (AsciiStrCmp (BrandStringWalker, "m3") == 0) { 132 | *ProcessorClass = AppleProcessorMajorM3; 133 | } else if (AsciiStrCmp (BrandStringWalker, "m5") == 0) { 134 | *ProcessorClass = AppleProcessorMajorM5; 135 | } else if (AsciiStrCmp (BrandStringWalker, "m7") == 0) { 136 | *ProcessorClass = AppleProcessorMajorM7; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /EfiPkg/Universal/AppleSmbiosDxe/InternalGetProcessorClass.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // InternalGetProcessorClass 4 | VOID 5 | InternalGetProcessorClass ( 6 | OUT UINT8 *ProcessorClass 7 | ) 8 | { 9 | *ProcessorClass = 0; 10 | } 11 | -------------------------------------------------------------------------------- /StoragePkg/PartitionDxe/Apm.c: -------------------------------------------------------------------------------- 1 | #include "Partition.h" 2 | #include "Apm.h" 3 | 4 | BOOLEAN 5 | PartitionInstallAppleChildHandles ( 6 | IN EFI_DRIVER_BINDING_PROTOCOL *This, 7 | IN EFI_HANDLE Handle, 8 | IN EFI_DISK_IO_PROTOCOL *DiskIo, 9 | IN EFI_BLOCK_IO_PROTOCOL *BlockIo, 10 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath 11 | ) 12 | /*++ 13 | 14 | Routine Description: 15 | Install child handles if the Handle supports APM format. 16 | 17 | Arguments: 18 | This - Calling context. 19 | Handle - Parent Handle 20 | DiskIo - Parent DiskIo interface 21 | BlockIo - Parent BlockIo interface 22 | DevicePath - Parent Device Path 23 | 24 | Returns: 25 | TRUE - If a child handle was added 26 | FALSE - Not found APM partition. 27 | 28 | --*/ 29 | { 30 | EFI_STATUS Status; 31 | UINT32 BlockSize; 32 | APM_DRIVER_DESCRIPTOR_MAP *Apm; 33 | APM_ENTRY *ApmEntry; 34 | UINTN NumberOfPartitionEntries; 35 | UINT64 Offset; 36 | UINT64 PartitionSize; 37 | UINT64 PartitionStart; 38 | EFI_LBA StartingLBA; 39 | EFI_LBA EndingLBA; 40 | UINT64 LBASize; 41 | UINT32 Remainder; 42 | UINTN Index; 43 | BOOLEAN ApmValid; 44 | HARDDRIVE_DEVICE_PATH HdDev; 45 | APPLE_PARTITION_INFO_PROTOCOL PartitionInfo; 46 | 47 | // 48 | // Check whether a medium is present 49 | // 50 | if (BlockIo->Media == NULL) { 51 | return FALSE; 52 | } 53 | 54 | // 55 | // Cerify the partition is physical 56 | // 57 | if (BlockIo->Media->LogicalPartition) { 58 | return FALSE; 59 | } 60 | 61 | // 62 | // Allocate a buffer for the APM Driver Descriptor Map 63 | // 64 | Apm = AllocatePool (BlockIo->Media->BlockSize); 65 | if (Apm == NULL) { 66 | return FALSE; 67 | } 68 | 69 | ApmValid = FALSE; 70 | 71 | // 72 | // Read the APM Driver Descriptor Map from LBA #0 73 | // 74 | Status = BlockIo->ReadBlocks ( 75 | BlockIo, 76 | BlockIo->Media->MediaId, 77 | 0, 78 | BlockIo->Media->BlockSize, 79 | Apm 80 | ); 81 | if (EFI_ERROR (Status)) { 82 | gBS->FreePool (Apm); 83 | return ApmValid; 84 | } 85 | // 86 | // Verify that the APM Driver Descriptor Map is valid 87 | // 88 | if (Apm->Signature != APM_DRIVER_DESCRIPTOR_MAP_SIGNATURE) { 89 | gBS->FreePool (Apm); 90 | return ApmValid; 91 | } 92 | 93 | BlockSize = SwapBytes16 (Apm->BlockSize); 94 | 95 | // 96 | // Allocate a buffer for an APM Entry 97 | // 98 | ApmEntry = AllocatePool (BlockSize); 99 | 100 | if (ApmEntry == NULL) { 101 | gBS->FreePool (Apm); 102 | return ApmValid; 103 | } 104 | 105 | // 106 | // Read the APM from LBA #1 107 | // 108 | Status = DiskIo->ReadDisk ( 109 | DiskIo, 110 | BlockIo->Media->MediaId, 111 | BlockSize, 112 | BlockSize, 113 | ApmEntry 114 | ); 115 | if (EFI_ERROR (Status)) { 116 | goto Done; 117 | } 118 | // 119 | // Verify that the APM is valid 120 | // 121 | if (ApmEntry->Signature != APM_ENTRY_SIGNATURE || 122 | CompareMem (ApmEntry->PartitionType, APM_ENTRY_TYPE_APM, sizeof (APM_ENTRY_TYPE_APM)) != 0 123 | ) { 124 | goto Done; 125 | } 126 | 127 | NumberOfPartitionEntries = SwapBytes32 (ApmEntry->NumberOfPartitionEntries); 128 | 129 | // 130 | // Check if there are Apple Partition Entries 131 | // 132 | if (NumberOfPartitionEntries < 2) { 133 | goto Done; 134 | } 135 | 136 | Offset = 2 * BlockSize; 137 | 138 | // 139 | // Read the Apple Partition Entries 140 | // 141 | for (Index = 1; Index < NumberOfPartitionEntries; ++Index, Offset += BlockSize) { 142 | Status = DiskIo->ReadDisk ( 143 | DiskIo, 144 | BlockIo->Media->MediaId, 145 | Offset, 146 | BlockSize, 147 | ApmEntry 148 | ); 149 | 150 | if (EFI_ERROR (Status) || 151 | ApmEntry->Signature != APM_ENTRY_SIGNATURE 152 | ) { 153 | goto Done; 154 | } 155 | 156 | // 157 | // Verify that the Apple Partition Entry is valid 158 | // 159 | if (CompareMem (ApmEntry->PartitionType, APM_ENTRY_TYPE_FREE, sizeof (APM_ENTRY_TYPE_FREE)) == 0 || 160 | SwapBytes32 (ApmEntry->PartitionSize) == 0 161 | ) { 162 | continue; 163 | } 164 | 165 | PartitionStart = SwapBytes32 (ApmEntry->PartitionStart); 166 | 167 | StartingLBA = DivU64x32Remainder ( 168 | MultU64x32 (PartitionStart, BlockSize), 169 | BlockIo->Media->BlockSize, 170 | &Remainder 171 | ); 172 | 173 | if (Remainder != 0) { 174 | continue; 175 | } 176 | 177 | // BUG: Already calculated above -> cache! 178 | PartitionSize = SwapBytes32 (ApmEntry->PartitionSize); 179 | 180 | LBASize = DivU64x32Remainder ( 181 | MultU64x32 (PartitionSize, BlockSize), 182 | BlockIo->Media->BlockSize, 183 | &Remainder 184 | ); 185 | 186 | if (Remainder != 0) { 187 | continue; 188 | } 189 | 190 | EndingLBA = StartingLBA + LBASize - 1; 191 | 192 | if (EndingLBA > BlockIo->Media->LastBlock) { 193 | continue; 194 | } 195 | 196 | ZeroMem (&HdDev, sizeof (HdDev)); 197 | HdDev.Header.Type = MEDIA_DEVICE_PATH; 198 | HdDev.Header.SubType = MEDIA_HARDDRIVE_DP; 199 | SetDevicePathNodeLength (&HdDev.Header, sizeof (HdDev)); 200 | 201 | HdDev.PartitionNumber = (UINT32) Index + 1; 202 | HdDev.MBRType = MBR_TYPE_APPLE_PARTITION_TABLE_HEADER; 203 | HdDev.PartitionStart = StartingLBA; 204 | HdDev.PartitionSize = LBASize; 205 | 206 | DEBUG ((EFI_D_INFO, " Index : %d\n", Index)); 207 | DEBUG ((EFI_D_INFO, " Start LBA : %x\n", HdDev.PartitionStart)); 208 | DEBUG ((EFI_D_INFO, " End LBA: %x\n", EndingLBA)); 209 | DEBUG ((EFI_D_INFO, " Partition size: %x\n", HdDev.PartitionSize)); 210 | DEBUG ((EFI_D_INFO, " Start : %x", MultU64x32 (PartitionStart, BlockSize))); 211 | DEBUG ((EFI_D_INFO, " End : %x", MultU64x32 ((PartitionStart + PartitionSize - 1), BlockSize))); 212 | 213 | ZeroMem (&PartitionInfo, sizeof (APPLE_PARTITION_INFO_PROTOCOL)); 214 | 215 | PartitionInfo.Revision = 0x010000; 216 | PartitionInfo.PartitionNumber = HdDev.PartitionNumber; 217 | PartitionInfo.MBRType = HdDev.MBRType; 218 | PartitionInfo.PartitionStart = HdDev.PartitionStart; 219 | PartitionInfo.PartitionSize = HdDev.PartitionSize; 220 | 221 | CopyMem (&PartitionInfo.PartitionType, ApmEntry->PartitionType, sizeof(EFI_GUID)); 222 | 223 | Status = PartitionInstallChildHandle ( 224 | This, 225 | Handle, 226 | DiskIo, 227 | BlockIo, 228 | DevicePath, 229 | (EFI_DEVICE_PATH_PROTOCOL *) &HdDev, 230 | StartingLBA, 231 | EndingLBA, 232 | BlockIo->Media->BlockSize, 233 | FALSE, 234 | &PartitionInfo 235 | ); 236 | 237 | if (!EFI_ERROR (Status)) { 238 | ApmValid = TRUE; 239 | } 240 | } 241 | 242 | Done: 243 | gBS->FreePool (ApmEntry); 244 | gBS->FreePool (Apm); 245 | 246 | return ApmValid; 247 | } 248 | -------------------------------------------------------------------------------- /StoragePkg/PartitionDxe/Apm.h: -------------------------------------------------------------------------------- 1 | #ifndef _APM_H_ 2 | #define _APM_H_ 3 | 4 | #pragma pack(1) 5 | 6 | #define MBR_TYPE_APPLE_PARTITION_TABLE_HEADER 0x20 7 | 8 | #define APM_ENTRY_TYPE_APM "Apple_partition_map" 9 | #define APM_ENTRY_TYPE_FREE "Apple_Free" 10 | 11 | typedef PACKED struct { 12 | UINT32 BlockStart; 13 | UINT16 NumberOfBlocks; 14 | UINT16 SystemType; 15 | } APM_DRIVER_DESCRIPTOR_MAP_ENTRY; 16 | 17 | #define APM_DRIVER_DESCRIPTOR_MAP_SIGNATURE SIGNATURE_16 ('E', 'R') 18 | 19 | // 20 | // APM Driver Descriptor Map Header 21 | // 22 | typedef PACKED struct { 23 | UINT16 Signature; 24 | UINT16 BlockSize; 25 | UINT32 BlockCount; 26 | UINT16 DeviceType; 27 | UINT16 DeviceId; 28 | UINT32 DriverData; 29 | UINT16 DriverDescriptorCount; 30 | APM_DRIVER_DESCRIPTOR_MAP_ENTRY DriverDescriptors[8]; 31 | UINT8 Reserved[430]; 32 | } APM_DRIVER_DESCRIPTOR_MAP; 33 | 34 | #define APM_ENTRY_SIGNATURE SIGNATURE_16 ('P', 'M') 35 | 36 | // 37 | // APM Entry Flags 38 | // 39 | #define APM_ENTRY_FLAGS_VALID BIT0 40 | #define APM_ENTRY_FLAGS_ALLOCATED BIT1 41 | #define APM_ENTRY_FLAGS_IN_USE BIT2 42 | #define APM_ENTRY_FLAGS_BOOTABLE BIT3 43 | #define APM_ENTRY_FLAGS_READABLE BIT4 44 | #define APM_ENTRY_FLAGS_WRITABLE BIT5 45 | #define APM_ENTRY_FLAGS_OS_PIC_CODE BIT6 46 | #define APM_ENTRY_FLAGS_OS_SPECIFIC_2 BIT7 47 | #define APM_ENTRY_FLAGS_OS_SPECIFIC_1 BIT8 48 | #define APM_ENTRY_FLAGS_RESERVED 0xFFFFFE00 49 | 50 | // 51 | // APM Entry Header 52 | // 53 | typedef PACKED struct { 54 | UINT16 Signature; 55 | UINT16 Reserved1; 56 | UINT32 NumberOfPartitionEntries; 57 | UINT32 PartitionStart; 58 | UINT32 PartitionSize; 59 | CHAR8 PartitionName[32]; 60 | CHAR8 PartitionType[32]; 61 | UINT32 LBAStart; 62 | UINT32 LBASize; 63 | UINT32 PartitionFlags; 64 | UINT32 BootStrapCodeLBA; 65 | UINT32 BootStrapCodeSize; 66 | UINT32 BootStrapCodeLoadAddress; 67 | UINT32 BootStrapCodeLoadAddress2; 68 | UINT32 BootStrapCodeEntry; 69 | UINT32 BootStrapCodeEntry2; 70 | UINT32 BootStrapCodeChecksum; 71 | UINT8 ProcessorType[16]; 72 | UINT32 Reserved2[32]; 73 | UINT32 Reserved3[62]; 74 | } APM_ENTRY; 75 | 76 | #pragma pack() 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /StoragePkg/PartitionDxe/ComponentName.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2004 - 2007, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | Module Name: 13 | 14 | ComponentName.c 15 | 16 | Abstract: 17 | 18 | --*/ 19 | 20 | #include "Partition.h" 21 | 22 | // 23 | // EFI Component Name Functions 24 | // 25 | EFI_STATUS 26 | EFIAPI 27 | PartitionComponentNameGetDriverName ( 28 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 29 | IN CHAR8 *Language, 30 | OUT CHAR16 **DriverName 31 | ); 32 | 33 | EFI_STATUS 34 | EFIAPI 35 | PartitionComponentNameGetControllerName ( 36 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 37 | IN EFI_HANDLE ControllerHandle, 38 | IN EFI_HANDLE ChildHandle OPTIONAL, 39 | IN CHAR8 *Language, 40 | OUT CHAR16 **ControllerName 41 | ); 42 | 43 | // 44 | // EFI Component Name Protocol 45 | // 46 | EFI_COMPONENT_NAME_PROTOCOL gPartitionComponentName = { 47 | PartitionComponentNameGetDriverName, 48 | PartitionComponentNameGetControllerName, 49 | "eng" 50 | }; 51 | 52 | static EFI_UNICODE_STRING_TABLE mPartitionDriverNameTable[] = { 53 | { 54 | "eng", 55 | L"Partition Driver" 56 | }, 57 | { 58 | NULL, 59 | NULL 60 | } 61 | }; 62 | 63 | EFI_STATUS 64 | EFIAPI 65 | PartitionComponentNameGetDriverName ( 66 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 67 | IN CHAR8 *Language, 68 | OUT CHAR16 **DriverName 69 | ) 70 | /*++ 71 | 72 | Routine Description: 73 | Retrieves a Unicode string that is the user readable name of the EFI Driver. 74 | 75 | Arguments: 76 | This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance. 77 | Language - A pointer to a three character ISO 639-2 language identifier. 78 | This is the language of the driver name that that the caller 79 | is requesting, and it must match one of the languages specified 80 | in SupportedLanguages. The number of languages supported by a 81 | driver is up to the driver writer. 82 | DriverName - A pointer to the Unicode string to return. This Unicode string 83 | is the name of the driver specified by This in the language 84 | specified by Language. 85 | 86 | Returns: 87 | EFI_SUCCESS - The Unicode string for the Driver specified by This 88 | and the language specified by Language was returned 89 | in DriverName. 90 | EFI_INVALID_PARAMETER - Language is NULL. 91 | EFI_INVALID_PARAMETER - DriverName is NULL. 92 | EFI_UNSUPPORTED - The driver specified by This does not support the 93 | language specified by Language. 94 | 95 | --*/ 96 | { 97 | return LookupUnicodeString ( 98 | Language, 99 | gPartitionComponentName.SupportedLanguages, 100 | mPartitionDriverNameTable, 101 | DriverName 102 | ); 103 | } 104 | 105 | EFI_STATUS 106 | EFIAPI 107 | PartitionComponentNameGetControllerName ( 108 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 109 | IN EFI_HANDLE ControllerHandle, 110 | IN EFI_HANDLE ChildHandle OPTIONAL, 111 | IN CHAR8 *Language, 112 | OUT CHAR16 **ControllerName 113 | ) 114 | /*++ 115 | 116 | Routine Description: 117 | Retrieves a Unicode string that is the user readable name of the controller 118 | that is being managed by an EFI Driver. 119 | 120 | Arguments: 121 | This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance. 122 | ControllerHandle - The handle of a controller that the driver specified by 123 | This is managing. This handle specifies the controller 124 | whose name is to be returned. 125 | ChildHandle - The handle of the child controller to retrieve the name 126 | of. This is an optional parameter that may be NULL. It 127 | will be NULL for device drivers. It will also be NULL 128 | for a bus drivers that wish to retrieve the name of the 129 | bus controller. It will not be NULL for a bus driver 130 | that wishes to retrieve the name of a child controller. 131 | Language - A pointer to a three character ISO 639-2 language 132 | identifier. This is the language of the controller name 133 | that that the caller is requesting, and it must match one 134 | of the languages specified in SupportedLanguages. The 135 | number of languages supported by a driver is up to the 136 | driver writer. 137 | ControllerName - A pointer to the Unicode string to return. This Unicode 138 | string is the name of the controller specified by 139 | ControllerHandle and ChildHandle in the language specified 140 | by Language from the point of view of the driver specified 141 | by This. 142 | 143 | Returns: 144 | EFI_SUCCESS - The Unicode string for the user readable name in the 145 | language specified by Language for the driver 146 | specified by This was returned in DriverName. 147 | EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE. 148 | EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE. 149 | EFI_INVALID_PARAMETER - Language is NULL. 150 | EFI_INVALID_PARAMETER - ControllerName is NULL. 151 | EFI_UNSUPPORTED - The driver specified by This is not currently managing 152 | the controller specified by ControllerHandle and 153 | ChildHandle. 154 | EFI_UNSUPPORTED - The driver specified by This does not support the 155 | language specified by Language. 156 | 157 | --*/ 158 | { 159 | return EFI_UNSUPPORTED; 160 | } 161 | -------------------------------------------------------------------------------- /StoragePkg/PartitionDxe/ElTorito.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2004 - 2009, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | Module Name: 13 | 14 | ElTorito.c 15 | 16 | Abstract: 17 | 18 | Decode an El Torito formatted CD-ROM 19 | 20 | Revision History 21 | 22 | --*/ 23 | 24 | #include "Partition.h" 25 | #include "ElTorito.h" 26 | 27 | BOOLEAN 28 | PartitionInstallElToritoChildHandles ( 29 | IN EFI_DRIVER_BINDING_PROTOCOL *This, 30 | IN EFI_HANDLE Handle, 31 | IN EFI_DISK_IO_PROTOCOL *DiskIo, 32 | IN EFI_BLOCK_IO_PROTOCOL *BlockIo, 33 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath 34 | ) 35 | /*++ 36 | 37 | Routine Description: 38 | Install child handles if the Handle supports El Torito format. 39 | 40 | Arguments: 41 | This - Calling context. 42 | Handle - Parent Handle 43 | DiskIo - Parent DiskIo interface 44 | BlockIo - Parent BlockIo interface 45 | DevicePath - Parent Device Path 46 | 47 | Returns: 48 | TRUE - some child handle(s) was added 49 | FALSE - no child handle was added 50 | 51 | --*/ 52 | { 53 | EFI_STATUS Status; 54 | UINT32 VolDescriptorLba; 55 | UINT32 Lba; 56 | EFI_BLOCK_IO_MEDIA *Media; 57 | CDROM_VOLUME_DESCRIPTOR *VolDescriptor; 58 | ELTORITO_CATALOG *Catalog; 59 | UINTN Check; 60 | UINTN Index; 61 | UINTN BootEntry; 62 | UINTN MaxIndex; 63 | UINT16 *CheckBuffer; 64 | CDROM_DEVICE_PATH CdDev; 65 | UINT32 SubBlockSize; 66 | UINT32 SectorCount; 67 | BOOLEAN Found; 68 | UINT32 Dummy; 69 | UINT32 VolSpaceSize; 70 | APPLE_PARTITION_INFO_PROTOCOL PartitionInfo; 71 | 72 | Found = FALSE; 73 | Media = BlockIo->Media; 74 | VolSpaceSize = 0; 75 | 76 | // 77 | // Check whether a medium is present 78 | // 79 | if (BlockIo->Media == NULL) { 80 | return Found; 81 | } 82 | 83 | // 84 | // CD_ROM has the fixed block size as 2048 bytes 85 | // 86 | if (Media->BlockSize != 2048) { 87 | return Found; 88 | } 89 | 90 | VolDescriptor = AllocatePool ((UINTN) Media->BlockSize); 91 | 92 | if (VolDescriptor == NULL) { 93 | return Found; 94 | } 95 | 96 | Catalog = (ELTORITO_CATALOG *) VolDescriptor; 97 | 98 | // 99 | // the ISO-9660 volume descriptor starts at 32k on the media 100 | // and CD_ROM has the fixed block size as 2048 bytes, so... 101 | // 102 | // 103 | // ((16*2048) / Media->BlockSize) - 1; 104 | // 105 | VolDescriptorLba = 15; 106 | // 107 | // Loop: handle one volume descriptor per time 108 | // 109 | while (TRUE) { 110 | 111 | VolDescriptorLba += 1; 112 | if (VolDescriptorLba > Media->LastBlock) { 113 | // 114 | // We are pointing past the end of the device so exit 115 | // 116 | break; 117 | } 118 | 119 | Status = BlockIo->ReadBlocks ( 120 | BlockIo, 121 | Media->MediaId, 122 | VolDescriptorLba, 123 | Media->BlockSize, 124 | VolDescriptor 125 | ); 126 | if (EFI_ERROR (Status)) { 127 | break; 128 | } 129 | // 130 | // Check for valid volume descriptor signature 131 | // 132 | if (VolDescriptor->Type == CDVOL_TYPE_END || 133 | CompareMem (VolDescriptor->Id, CDVOL_ID, sizeof (VolDescriptor->Id)) != 0 134 | ) { 135 | // 136 | // end of Volume descriptor list 137 | // 138 | break; 139 | } 140 | // 141 | // Read the Volume Space Size from Primary Volume Descriptor 81-88 byte, 142 | // the 32-bit numerical values is stored in Both-byte orders 143 | // 144 | if (VolDescriptor->Type == CDVOL_TYPE_CODED) { 145 | VolSpaceSize = VolDescriptor->VolSpaceSize[0]; 146 | } 147 | // 148 | // Is it an El Torito volume descriptor? 149 | // 150 | if (CompareMem (VolDescriptor->SystemId, CDVOL_ELTORITO_ID, sizeof (CDVOL_ELTORITO_ID) - 1) != 0) { 151 | continue; 152 | } 153 | // 154 | // Read in the boot El Torito boot catalog 155 | // 156 | Lba = UNPACK_INT32 (VolDescriptor->EltCatalog); 157 | if (Lba > Media->LastBlock) { 158 | continue; 159 | } 160 | 161 | Status = BlockIo->ReadBlocks ( 162 | BlockIo, 163 | Media->MediaId, 164 | Lba, 165 | Media->BlockSize, 166 | Catalog 167 | ); 168 | if (EFI_ERROR (Status)) { 169 | DEBUG ((EFI_D_ERROR, "EltCheckDevice: error reading catalog %r\n", Status)); 170 | continue; 171 | } 172 | // 173 | // We don't care too much about the Catalog header's contents, but we do want 174 | // to make sure it looks like a Catalog header 175 | // 176 | if (Catalog->Catalog.Indicator != ELTORITO_ID_CATALOG || Catalog->Catalog.Id55AA != 0xAA55) { 177 | DEBUG ((EFI_D_ERROR, "EltCheckBootCatalog: El Torito boot catalog header IDs not correct\n")); 178 | continue; 179 | } 180 | 181 | Check = 0; 182 | CheckBuffer = (UINT16 *) Catalog; 183 | for (Index = 0; Index < sizeof (ELTORITO_CATALOG) / sizeof (UINT16); Index += 1) { 184 | Check += CheckBuffer[Index]; 185 | } 186 | 187 | if (Check & 0xFFFF) { 188 | DEBUG ((EFI_D_ERROR, "EltCheckBootCatalog: El Torito boot catalog header checksum failed\n")); 189 | continue; 190 | } 191 | 192 | MaxIndex = Media->BlockSize / sizeof (ELTORITO_CATALOG); 193 | for (Index = 1, BootEntry = 1; Index < MaxIndex; Index += 1) { 194 | // 195 | // Next entry 196 | // 197 | Catalog += 1; 198 | 199 | // 200 | // Check this entry 201 | // 202 | if (Catalog->Boot.Indicator != ELTORITO_ID_SECTION_BOOTABLE || Catalog->Boot.Lba == 0) { 203 | continue; 204 | } 205 | 206 | SubBlockSize = 512; 207 | SectorCount = Catalog->Boot.SectorCount; 208 | 209 | switch (Catalog->Boot.MediaType) { 210 | 211 | case ELTORITO_NO_EMULATION: 212 | SubBlockSize = Media->BlockSize; 213 | break; 214 | 215 | case ELTORITO_HARD_DISK: 216 | break; 217 | 218 | case ELTORITO_12_DISKETTE: 219 | SectorCount = 0x50 * 0x02 * 0x0F; 220 | break; 221 | 222 | case ELTORITO_14_DISKETTE: 223 | SectorCount = 0x50 * 0x02 * 0x12; 224 | break; 225 | 226 | case ELTORITO_28_DISKETTE: 227 | SectorCount = 0x50 * 0x02 * 0x24; 228 | break; 229 | 230 | default: 231 | DEBUG ((EFI_D_INIT, "EltCheckDevice: unsupported El Torito boot media type %x\n", Catalog->Boot.MediaType)); 232 | SectorCount = 0; 233 | SubBlockSize = Media->BlockSize; 234 | break; 235 | } 236 | // 237 | // Create child device handle 238 | // 239 | CdDev.Header.Type = MEDIA_DEVICE_PATH; 240 | CdDev.Header.SubType = MEDIA_CDROM_DP; 241 | SetDevicePathNodeLength (&CdDev.Header, sizeof (CdDev)); 242 | 243 | if (Index == 1) { 244 | // 245 | // This is the initial/default entry 246 | // 247 | BootEntry = 0; 248 | } 249 | 250 | CdDev.BootEntry = (UINT32) BootEntry; 251 | BootEntry++; 252 | CdDev.PartitionStart = Catalog->Boot.Lba; 253 | if (SectorCount < 2) { 254 | // 255 | //When the SectorCount < 2, set the Partition as the whole CD. 256 | // 257 | CdDev.PartitionSize = (VolSpaceSize > Media->LastBlock + 1) ? 258 | (UINT32)(Media->LastBlock - Catalog->Boot.Lba + 1) : (UINT32)(VolSpaceSize - Catalog->Boot.Lba); 259 | } else { 260 | CdDev.PartitionSize = DivU64x32Remainder ( 261 | MultU64x32 (SectorCount, 262 | SubBlockSize) + Media->BlockSize - 1, 263 | Media->BlockSize, 264 | &Dummy 265 | ); 266 | } 267 | 268 | ZeroMem (&PartitionInfo, sizeof (APPLE_PARTITION_INFO_PROTOCOL)); 269 | 270 | PartitionInfo.Revision = 0x010000; 271 | PartitionInfo.PartitionNumber = CdDev.BootEntry; 272 | PartitionInfo.PartitionStart = CdDev.PartitionStart; 273 | PartitionInfo.PartitionSize = CdDev.PartitionSize; 274 | 275 | Status = PartitionInstallChildHandle ( 276 | This, 277 | Handle, 278 | DiskIo, 279 | BlockIo, 280 | DevicePath, 281 | (EFI_DEVICE_PATH_PROTOCOL *) &CdDev, 282 | Catalog->Boot.Lba, 283 | Catalog->Boot.Lba + CdDev.PartitionSize - 1, 284 | SubBlockSize, 285 | FALSE, 286 | &PartitionInfo 287 | ); 288 | if (!EFI_ERROR (Status)) { 289 | Found = TRUE; 290 | } 291 | } 292 | } 293 | 294 | gBS->FreePool (VolDescriptor); 295 | 296 | return Found; 297 | } 298 | -------------------------------------------------------------------------------- /StoragePkg/PartitionDxe/ElTorito.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2004, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | Module Name: 13 | 14 | ElTorito.h 15 | 16 | Abstract: 17 | 18 | Data Structures required for detecting ElTorito Partitions 19 | 20 | Revision History 21 | 22 | --*/ 23 | 24 | #ifndef _ELTORITO_H_ 25 | #define _ELTORITO_H_ 26 | 27 | #pragma pack(1) 28 | // 29 | // CDROM_VOLUME_DESCRIPTOR.Types 30 | // 31 | #define CDVOL_TYPE_STANDARD 0x0 32 | #define CDVOL_TYPE_CODED 0x1 33 | #define CDVOL_TYPE_END 0xFF 34 | 35 | // 36 | // CDROM_VOLUME_DESCRIPTOR.Id 37 | // 38 | #define CDVOL_ID "CD001" 39 | 40 | // 41 | // CDROM_VOLUME_DESCRIPTOR.SystemId 42 | // 43 | #define CDVOL_ELTORITO_ID "EL TORITO SPECIFICATION" 44 | 45 | // 46 | // Indicator types 47 | // 48 | #define ELTORITO_ID_CATALOG 0x01 49 | #define ELTORITO_ID_SECTION_BOOTABLE 0x88 50 | #define ELTORITO_ID_SECTION_NOT_BOOTABLE 0x00 51 | #define ELTORITO_ID_SECTION_HEADER 0x90 52 | #define ELTORITO_ID_SECTION_HEADER_FINAL 0x91 53 | 54 | // 55 | // ELTORITO_CATALOG.Boot.MediaTypes 56 | // 57 | #define ELTORITO_NO_EMULATION 0x00 58 | #define ELTORITO_12_DISKETTE 0x01 59 | #define ELTORITO_14_DISKETTE 0x02 60 | #define ELTORITO_28_DISKETTE 0x03 61 | #define ELTORITO_HARD_DISK 0x04 62 | 63 | // 64 | // El Torito Volume Descriptor 65 | // Note that the CDROM_VOLUME_DESCRIPTOR does not match the ISO-9660 66 | // descriptor. For some reason descriptor used by El Torito is 67 | // different, but they start the same. The El Torito descriptor 68 | // is left shifted 1 byte starting with the SystemId. (Note this 69 | // causes the field to get unaligned) 70 | // 71 | typedef PACKED struct { 72 | UINT8 Type; 73 | CHAR8 Id[5]; // CD001 74 | UINT8 Version; 75 | CHAR8 SystemId[26]; 76 | CHAR8 Unused[38]; 77 | UINT8 EltCatalog[4]; 78 | CHAR8 Unused2[5]; 79 | UINT32 VolSpaceSize[2]; 80 | } CDROM_VOLUME_DESCRIPTOR; 81 | 82 | // 83 | // Catalog Entry 84 | // 85 | typedef union { 86 | PACKED struct { 87 | CHAR8 Reserved[0x20]; 88 | } Unknown; 89 | 90 | // 91 | // Catalog validation entry (Catalog header) 92 | // 93 | PACKED struct { 94 | UINT8 Indicator; 95 | UINT8 PlatformId; 96 | UINT16 Reserved; 97 | CHAR8 ManufacId[24]; 98 | UINT16 Checksum; 99 | UINT16 Id55AA; 100 | } Catalog; 101 | 102 | // 103 | // Initial/Default Entry or Section Entry 104 | // 105 | PACKED struct { 106 | UINT8 Indicator; 107 | UINT8 MediaType : 4; 108 | UINT8 Reserved1 : 4; 109 | UINT16 LoadSegment; 110 | UINT8 SystemType; 111 | UINT8 Reserved2; 112 | UINT16 SectorCount; 113 | UINT32 Lba; 114 | } Boot; 115 | 116 | // 117 | // Section Header Entry 118 | // 119 | PACKED struct { 120 | UINT8 Indicator; 121 | UINT8 PlatformId; 122 | UINT16 SectionEntries; 123 | CHAR8 Id[28]; 124 | } Section; 125 | 126 | } ELTORITO_CATALOG; 127 | 128 | #pragma pack() 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /StoragePkg/PartitionDxe/Gpt.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2004, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | Module Name: 13 | 14 | Gpt.h 15 | 16 | Abstract: 17 | 18 | Data Structures required for detecting GPT Partitions 19 | 20 | Revision History 21 | 22 | --*/ 23 | 24 | #ifndef _GPT_H_ 25 | #define _GPT_H_ 26 | 27 | #pragma pack(1) 28 | 29 | #define EFI_PTAB_HEADER_SIGNATURE "EFI PART" 30 | 31 | // 32 | // EFI Partition Attributes 33 | // 34 | #define EFI_PART_REQUIRED_TO_FUNCTION 0x0000000000000001 35 | 36 | // 37 | // GPT Partition Entry Status 38 | // 39 | typedef PACKED struct { 40 | BOOLEAN OutOfRange; 41 | BOOLEAN Overlap; 42 | } EFI_PARTITION_ENTRY_STATUS; 43 | 44 | #pragma pack() 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /StoragePkg/PartitionDxe/Mbr.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2004 - 2006, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | Module Name: 13 | 14 | Mbr.h 15 | 16 | Abstract: 17 | 18 | Data Structures required for detecting MBR Partitions 19 | 20 | Revision History 21 | 22 | --*/ 23 | 24 | #ifndef _MBR_H_ 25 | #define _MBR_H_ 26 | 27 | #pragma pack(1) 28 | 29 | #define MBR_SIGNATURE 0xaa55 30 | #define MIN_MBR_DEVICE_SIZE 0x80000 31 | #define MBR_ERRATA_PAD 0x40000 // 128 MB 32 | #define EXTENDED_DOS_PARTITION 0x05 33 | #define EXTENDED_WINDOWS_PARTITION 0x0F 34 | #define MAX_MBR_PARTITIONS 4 35 | 36 | #define PMBR_GPT_PARTITION 0xEE 37 | #define EFI_PARTITION 0xEF 38 | #define MBR_SIZE 512 39 | 40 | // 41 | // MBR Partition Entry 42 | // 43 | typedef PACKED struct { 44 | UINT8 BootIndicator; 45 | UINT8 StartHead; 46 | UINT8 StartSector; 47 | UINT8 StartTrack; 48 | UINT8 OSIndicator; 49 | UINT8 EndHead; 50 | UINT8 EndSector; 51 | UINT8 EndTrack; 52 | UINT8 StartingLBA[4]; 53 | UINT8 SizeInLBA[4]; 54 | } MBR_PARTITION_RECORD; 55 | 56 | // 57 | // MBR Partition table 58 | // 59 | typedef PACKED struct { 60 | UINT8 BootStrapCode[440]; 61 | UINT8 UniqueMbrSignature[4]; 62 | UINT8 Unknown[2]; 63 | MBR_PARTITION_RECORD Partition[MAX_MBR_PARTITIONS]; 64 | UINT16 Signature; 65 | } MASTER_BOOT_RECORD; 66 | 67 | #pragma pack() 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /StoragePkg/PartitionDxe/Partition.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2004 - 2007, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | Module Name: 13 | 14 | Partition.h 15 | 16 | Abstract: 17 | 18 | Partition driver that produces logical BlockIo devices from a physical 19 | BlockIo device. The logical BlockIo devices are based on the format 20 | of the raw block devices media. Currently "El Torito CD-ROM", Legacy 21 | MBR, and GPT partition schemes are supported. 22 | 23 | Revision History 24 | 25 | --*/ 26 | 27 | #ifndef _PARTITION_H_ 28 | #define _PARTITION_H_ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | // 40 | // Driver Consumed Protocol Prototypes 41 | // 42 | #include 43 | #include 44 | #include 45 | 46 | // 47 | // Driver Consumed Guids 48 | // 49 | #include 50 | 51 | // 52 | // Driver Produced Protocol Prototypes 53 | // 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | // 60 | // Partition private data 61 | // 62 | #define PARTITION_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'a', 'r', 't') 63 | typedef struct { 64 | UINT64 Signature; 65 | 66 | EFI_HANDLE Handle; 67 | EFI_DEVICE_PATH_PROTOCOL *DevicePath; 68 | EFI_BLOCK_IO_PROTOCOL BlockIo; 69 | EFI_BLOCK_IO_MEDIA Media; 70 | 71 | EFI_DISK_IO_PROTOCOL *DiskIo; 72 | EFI_BLOCK_IO_PROTOCOL *ParentBlockIo; 73 | UINT64 Start; 74 | UINT64 End; 75 | UINT32 BlockSize; 76 | 77 | EFI_GUID *EspGuid; 78 | 79 | APPLE_PARTITION_INFO_PROTOCOL PartitionInfo; 80 | } PARTITION_PRIVATE_DATA; 81 | 82 | #define PARTITION_DEVICE_FROM_BLOCK_IO_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo, PARTITION_PRIVATE_DATA_SIGNATURE) 83 | 84 | // 85 | // Global Variables 86 | // 87 | extern EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding; 88 | extern EFI_COMPONENT_NAME_PROTOCOL gPartitionComponentName; 89 | 90 | // 91 | // Extract INT32 from char array 92 | // 93 | #define UNPACK_INT32(a) (INT32)( (((UINT8 *) a)[0] << 0) | \ 94 | (((UINT8 *) a)[1] << 8) | \ 95 | (((UINT8 *) a)[2] << 16) | \ 96 | (((UINT8 *) a)[3] << 24) ) 97 | 98 | // 99 | // Extract UINT32 from char array 100 | // 101 | #define UNPACK_UINT32(a) (UINT32)( (((UINT8 *) a)[0] << 0) | \ 102 | (((UINT8 *) a)[1] << 8) | \ 103 | (((UINT8 *) a)[2] << 16) | \ 104 | (((UINT8 *) a)[3] << 24) ) 105 | 106 | EFI_STATUS 107 | PartitionInstallChildHandle ( 108 | IN EFI_DRIVER_BINDING_PROTOCOL *This, 109 | IN EFI_HANDLE ParentHandle, 110 | IN EFI_DISK_IO_PROTOCOL *ParentDiskIo, 111 | IN EFI_BLOCK_IO_PROTOCOL *ParentBlockIo, 112 | IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath, 113 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, 114 | IN EFI_LBA Start, 115 | IN EFI_LBA End, 116 | IN UINT32 BlockSize, 117 | IN BOOLEAN InstallEspGuid, 118 | IN APPLE_PARTITION_INFO_PROTOCOL *PartitionInfo 119 | ) 120 | ; 121 | 122 | BOOLEAN 123 | PartitionInstallGptChildHandles ( 124 | IN EFI_DRIVER_BINDING_PROTOCOL *This, 125 | IN EFI_HANDLE Handle, 126 | IN EFI_DISK_IO_PROTOCOL *DiskIo, 127 | IN EFI_BLOCK_IO_PROTOCOL *BlockIo, 128 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath 129 | ) 130 | ; 131 | 132 | BOOLEAN 133 | PartitionInstallAppleChildHandles ( 134 | IN EFI_DRIVER_BINDING_PROTOCOL *This, 135 | IN EFI_HANDLE Handle, 136 | IN EFI_DISK_IO_PROTOCOL *DiskIo, 137 | IN EFI_BLOCK_IO_PROTOCOL *BlockIo, 138 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath 139 | ) 140 | ; 141 | 142 | BOOLEAN 143 | PartitionInstallElToritoChildHandles ( 144 | IN EFI_DRIVER_BINDING_PROTOCOL *This, 145 | IN EFI_HANDLE Handle, 146 | IN EFI_DISK_IO_PROTOCOL *DiskIo, 147 | IN EFI_BLOCK_IO_PROTOCOL *BlockIo, 148 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath 149 | ) 150 | ; 151 | 152 | BOOLEAN 153 | PartitionInstallMbrChildHandles ( 154 | IN EFI_DRIVER_BINDING_PROTOCOL *This, 155 | IN EFI_HANDLE Handle, 156 | IN EFI_DISK_IO_PROTOCOL *DiskIo, 157 | IN EFI_BLOCK_IO_PROTOCOL *BlockIo, 158 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath 159 | ) 160 | ; 161 | 162 | typedef 163 | BOOLEAN 164 | (*PARTITION_DETECT_ROUTINE) ( 165 | IN EFI_DRIVER_BINDING_PROTOCOL *This, 166 | IN EFI_HANDLE Handle, 167 | IN EFI_DISK_IO_PROTOCOL *DiskIo, 168 | IN EFI_BLOCK_IO_PROTOCOL *BlockIo, 169 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath 170 | ); 171 | 172 | #endif 173 | -------------------------------------------------------------------------------- /StoragePkg/PartitionDxe/PartitionDxe.inf: -------------------------------------------------------------------------------- 1 | #/*++ 2 | # 3 | # Copyright (c) 2004, Intel Corporation 4 | # All rights reserved. This program and the accompanying materials 5 | # are licensed and made available under the terms and conditions of the BSD License 6 | # which accompanies this distribution. The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | # Module Name: 13 | # 14 | # PartitionDxe.inf 15 | # 16 | # Abstract: 17 | # 18 | # Component description file for Partition module. 19 | # 20 | #--*/ 21 | 22 | [Defines] 23 | INF_VERSION = 0x00010005 24 | BASE_NAME = PartitionDxe 25 | FILE_GUID = 43B93232-AFBE-11D4-BD0F-0080C73C8881 26 | MODULE_TYPE = UEFI_DRIVER 27 | VERSION_STRING = 1.0 28 | ENTRY_POINT = PartitionEntryPoint 29 | 30 | [Sources] 31 | ComponentName.c 32 | Mbr.c 33 | Mbr.h 34 | Gpt.c 35 | Apm.c 36 | Apm.h 37 | ElTorito.c 38 | ElTorito.h 39 | Partition.c 40 | Partition.h 41 | 42 | 43 | [Packages] 44 | MdePkg/MdePkg.dec 45 | EfiPkg/EfiPkg.dec 46 | 47 | 48 | [LibraryClasses] 49 | DevicePathLib 50 | UefiBootServicesTableLib 51 | MemoryAllocationLib 52 | BaseMemoryLib 53 | UefiLib 54 | BaseLib 55 | UefiDriverEntryPoint 56 | DebugLib 57 | 58 | 59 | [Guids] 60 | gEfiPartTypeUnusedGuid ## SOMETIMES_CONSUMES ## GUID 61 | ## SOMETIMES_CONSUMES ## GUID 62 | ## SOMETIMES_CONSUMES ## GUID # Install protocol 63 | gEfiPartTypeSystemPartGuid 64 | 65 | 66 | [Protocols] 67 | ## BY_START 68 | ## TO_START 69 | gEfiBlockIoProtocolGuid 70 | ## BY_START 71 | ## TO_START 72 | gEfiBlockIo2ProtocolGuid 73 | ## BY_START 74 | ## TO_START 75 | gEfiDevicePathProtocolGuid 76 | gEfiDiskIoProtocolGuid ## TO_START 77 | gApplePartitionInfoProtocolGuid ## SOMETIMES_PRODUCES 78 | -------------------------------------------------------------------------------- /UsbPkg/Bus/Usb/UsbKbDxe/ComponentName.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2004 - 2007, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | Module Name: 13 | 14 | ComponentName.c 15 | 16 | Abstract: 17 | 18 | --*/ 19 | 20 | #include 21 | #include "Keyboard.h" 22 | 23 | // 24 | // EFI Component Name Functions 25 | // 26 | EFI_STATUS 27 | EFIAPI 28 | UsbKeyboardComponentNameGetDriverName ( 29 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 30 | IN CHAR8 *Language, 31 | OUT CHAR16 **DriverName 32 | ); 33 | 34 | EFI_STATUS 35 | EFIAPI 36 | UsbKeyboardComponentNameGetControllerName ( 37 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 38 | IN EFI_HANDLE ControllerHandle, 39 | IN EFI_HANDLE ChildHandle OPTIONAL, 40 | IN CHAR8 *Language, 41 | OUT CHAR16 **ControllerName 42 | ); 43 | 44 | // 45 | // EFI Component Name Protocol 46 | // 47 | EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName = { 48 | UsbKeyboardComponentNameGetDriverName, 49 | UsbKeyboardComponentNameGetControllerName, 50 | "eng" 51 | }; 52 | 53 | STATIC EFI_UNICODE_STRING_TABLE mUsbKeyboardDriverNameTable[] = { 54 | { "eng", L"Usb Keyboard Driver" }, 55 | { NULL , NULL } 56 | }; 57 | 58 | 59 | EFI_STATUS 60 | EFIAPI 61 | UsbKeyboardComponentNameGetDriverName ( 62 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 63 | IN CHAR8 *Language, 64 | OUT CHAR16 **DriverName 65 | ) 66 | /*++ 67 | 68 | Routine Description: 69 | Retrieves a Unicode string that is the user readable name of the EFI Driver. 70 | 71 | Arguments: 72 | This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance. 73 | Language - A pointer to a three character ISO 639-2 language identifier. 74 | This is the language of the driver name that that the caller 75 | is requesting, and it must match one of the languages specified 76 | in SupportedLanguages. The number of languages supported by a 77 | driver is up to the driver writer. 78 | DriverName - A pointer to the Unicode string to return. This Unicode string 79 | is the name of the driver specified by This in the language 80 | specified by Language. 81 | 82 | Returns: 83 | EFI_SUCCESS - The Unicode string for the Driver specified by This 84 | and the language specified by Language was returned 85 | in DriverName. 86 | EFI_INVALID_PARAMETER - Language is NULL. 87 | EFI_INVALID_PARAMETER - DriverName is NULL. 88 | EFI_UNSUPPORTED - The driver specified by This does not support the 89 | language specified by Language. 90 | 91 | --*/ 92 | { 93 | return LookupUnicodeString ( 94 | Language, 95 | gUsbKeyboardComponentName.SupportedLanguages, 96 | mUsbKeyboardDriverNameTable, 97 | DriverName 98 | ); 99 | } 100 | 101 | EFI_STATUS 102 | EFIAPI 103 | UsbKeyboardComponentNameGetControllerName ( 104 | IN EFI_COMPONENT_NAME_PROTOCOL *This, 105 | IN EFI_HANDLE ControllerHandle, 106 | IN EFI_HANDLE ChildHandle OPTIONAL, 107 | IN CHAR8 *Language, 108 | OUT CHAR16 **ControllerName 109 | ) 110 | /*++ 111 | 112 | Routine Description: 113 | Retrieves a Unicode string that is the user readable name of the controller 114 | that is being managed by an EFI Driver. 115 | 116 | Arguments: 117 | This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance. 118 | ControllerHandle - The handle of a controller that the driver specified by 119 | This is managing. This handle specifies the controller 120 | whose name is to be returned. 121 | ChildHandle - The handle of the child controller to retrieve the name 122 | of. This is an optional parameter that may be NULL. It 123 | will be NULL for device drivers. It will also be NULL 124 | for a bus drivers that wish to retrieve the name of the 125 | bus controller. It will not be NULL for a bus driver 126 | that wishes to retrieve the name of a child controller. 127 | Language - A pointer to a three character ISO 639-2 language 128 | identifier. This is the language of the controller name 129 | that that the caller is requesting, and it must match one 130 | of the languages specified in SupportedLanguages. The 131 | number of languages supported by a driver is up to the 132 | driver writer. 133 | ControllerName - A pointer to the Unicode string to return. This Unicode 134 | string is the name of the controller specified by 135 | ControllerHandle and ChildHandle in the language specified 136 | by Language from the point of view of the driver specified 137 | by This. 138 | 139 | Returns: 140 | EFI_SUCCESS - The Unicode string for the user readable name in the 141 | language specified by Language for the driver 142 | specified by This was returned in DriverName. 143 | EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE. 144 | EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE. 145 | EFI_INVALID_PARAMETER - Language is NULL. 146 | EFI_INVALID_PARAMETER - ControllerName is NULL. 147 | EFI_UNSUPPORTED - The driver specified by This is not currently managing 148 | the controller specified by ControllerHandle and 149 | ChildHandle. 150 | EFI_UNSUPPORTED - The driver specified by This does not support the 151 | language specified by Language. 152 | 153 | --*/ 154 | { 155 | EFI_STATUS Status; 156 | USB_KB_DEV *UsbKbDev; 157 | EFI_SIMPLE_TEXT_INPUT_PROTOCOL *SimpleTxtIn; 158 | EFI_USB_IO_PROTOCOL *UsbIoProtocol; 159 | // 160 | // This is a device driver, so ChildHandle must be NULL. 161 | // 162 | if (ChildHandle != NULL) { 163 | return EFI_UNSUPPORTED; 164 | } 165 | 166 | // 167 | // Check Controller's handle 168 | // 169 | Status = gBS->OpenProtocol ( 170 | ControllerHandle, 171 | &gEfiUsbIoProtocolGuid, 172 | (VOID **) &UsbIoProtocol, 173 | gUsbKeyboardDriverBinding.DriverBindingHandle, 174 | ControllerHandle, 175 | EFI_OPEN_PROTOCOL_BY_DRIVER 176 | ); 177 | if (!EFI_ERROR (Status)) { 178 | gBS->CloseProtocol ( 179 | ControllerHandle, 180 | &gEfiUsbIoProtocolGuid, 181 | gUsbKeyboardDriverBinding.DriverBindingHandle, 182 | ControllerHandle 183 | ); 184 | 185 | return EFI_UNSUPPORTED; 186 | } 187 | 188 | if (Status != EFI_ALREADY_STARTED) { 189 | return EFI_UNSUPPORTED; 190 | } 191 | // 192 | // Get the device context 193 | // 194 | Status = gBS->OpenProtocol ( 195 | ControllerHandle, 196 | &gEfiSimpleTextInProtocolGuid, 197 | (VOID **) &SimpleTxtIn, 198 | gUsbKeyboardDriverBinding.DriverBindingHandle, 199 | ControllerHandle, 200 | EFI_OPEN_PROTOCOL_GET_PROTOCOL 201 | ); 202 | 203 | if (EFI_ERROR (Status)) { 204 | return Status; 205 | } 206 | 207 | UsbKbDev = USB_KB_DEV_FROM_THIS (SimpleTxtIn); 208 | 209 | return LookupUnicodeString ( 210 | Language, 211 | gUsbKeyboardComponentName.SupportedLanguages, 212 | UsbKbDev->ControllerNameTable, 213 | ControllerName 214 | ); 215 | 216 | } 217 | -------------------------------------------------------------------------------- /UsbPkg/Bus/Usb/UsbKbDxe/EfiKey.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | Copyright (c) 2004 - 2008, Intel Corporation 3 | All rights reserved. This program and the accompanying materials 4 | are licensed and made available under the terms and conditions of the BSD License 5 | which accompanies this distribution. The full text of the license may be found at 6 | http://opensource.org/licenses/bsd-license.php 7 | 8 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | 11 | Module Name: 12 | 13 | EfiKey.h 14 | 15 | Abstract: 16 | 17 | Header file for USB Keyboard Driver's Data Structures 18 | 19 | Revision History 20 | --*/ 21 | #ifndef _USB_KB_H 22 | #define _USB_KB_H 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | // 42 | // Driver Consumed Protocol Prototypes 43 | // 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | // 53 | // Driver Produced Protocol Prototypes 54 | // 55 | #include 56 | #include 57 | #include 58 | 59 | #include 60 | 61 | #define MAX_KEY_ALLOWED 32 62 | 63 | #define HZ 1000 * 1000 * 10 64 | #define USBKBD_REPEAT_DELAY ((HZ) / 2) 65 | #define USBKBD_REPEAT_RATE ((HZ) / 50) 66 | 67 | #define CLASS_HID 3 68 | #define SUBCLASS_BOOT 1 69 | #define PROTOCOL_KEYBOARD 1 70 | 71 | #define BOOT_PROTOCOL 0 72 | #define REPORT_PROTOCOL 1 73 | 74 | typedef struct { 75 | UINT8 Down; 76 | UINT8 KeyCode; 77 | } USB_KEY; 78 | 79 | typedef struct { 80 | USB_KEY buffer[MAX_KEY_ALLOWED + 1]; 81 | UINT8 bHead; 82 | UINT8 bTail; 83 | } USB_KB_BUFFER; 84 | 85 | #define USB_KB_DEV_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'd') 86 | 87 | typedef struct { 88 | UINTN Signature; 89 | EFI_DEVICE_PATH_PROTOCOL *DevicePath; 90 | EFI_EVENT DelayedRecoveryEvent; 91 | EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput; 92 | APPLE_KEY_MAP_DATABASE_PROTOCOL *KeyMapDb; 93 | UINTN KeyMapDbIndex; 94 | EFI_USB_IO_PROTOCOL *UsbIo; 95 | 96 | EFI_USB_DEVICE_DESCRIPTOR DeviceDescriptor; 97 | EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor; 98 | EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor; 99 | 100 | USB_KB_BUFFER KeyboardBuffer; 101 | UINT8 CtrlOn; 102 | UINT8 AltOn; 103 | UINT8 ShiftOn; 104 | UINT8 NumLockOn; 105 | UINT8 CapsOn; 106 | UINT8 ScrollOn; 107 | UINT8 LastKeyCodeArray[8]; 108 | UINT8 CurKeyChar; 109 | 110 | UINT8 RepeatKey; 111 | EFI_EVENT RepeatTimer; 112 | 113 | EFI_UNICODE_STRING_TABLE *ControllerNameTable; 114 | 115 | UINT8 Unknown; 116 | } USB_KB_DEV; 117 | 118 | // 119 | // Global Variables 120 | // 121 | extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding; 122 | extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName; 123 | extern EFI_GUID gEfiUsbKeyboardDriverGuid; 124 | 125 | #define USB_KB_DEV_FROM_THIS(a) \ 126 | CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE) 127 | 128 | #define MOD_CONTROL_L 0x01 129 | #define MOD_CONTROL_R 0x10 130 | #define MOD_SHIFT_L 0x02 131 | #define MOD_SHIFT_R 0x20 132 | #define MOD_ALT_L 0x04 133 | #define MOD_ALT_R 0x40 134 | #define MOD_WIN_L 0x08 135 | #define MOD_WIN_R 0x80 136 | 137 | typedef struct { 138 | UINT8 Mask; 139 | UINT8 Key; 140 | } KB_MODIFIER; 141 | 142 | #define USB_KEYCODE_MAX_MAKE 0x64 143 | 144 | #define USBKBD_VALID_KEYCODE(key) ((UINT8) (key) > 3) 145 | 146 | typedef struct { 147 | UINT8 NumLock : 1; 148 | UINT8 CapsLock : 1; 149 | UINT8 ScrollLock : 1; 150 | UINT8 Resrvd : 5; 151 | } LED_MAP; 152 | 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /UsbPkg/Bus/Usb/UsbKbDxe/Keyboard.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | Copyright (c) 2004 - 2008, Intel Corporation 3 | All rights reserved. This program and the accompanying materials 4 | are licensed and made available under the terms and conditions of the BSD License 5 | which accompanies this distribution. The full text of the license may be found at 6 | http://opensource.org/licenses/bsd-license.php 7 | 8 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | 11 | Module Name: 12 | 13 | Keyboard.h 14 | 15 | Abstract: 16 | 17 | Function prototype for USB Keyboard Driver 18 | 19 | Revision History 20 | --*/ 21 | 22 | #ifndef _KEYBOARD_H 23 | #define _KEYBOARD_H 24 | 25 | #include "EfiKey.h" 26 | #include 27 | 28 | BOOLEAN 29 | IsUSBKeyboard ( 30 | IN EFI_USB_IO_PROTOCOL *UsbIo 31 | ); 32 | 33 | EFI_STATUS 34 | InitUSBKeyboard ( 35 | IN USB_KB_DEV *UsbKeyboardDevice 36 | ); 37 | 38 | EFI_STATUS 39 | EFIAPI 40 | KeyboardHandler ( 41 | IN VOID *Data, 42 | IN UINTN DataLength, 43 | IN VOID *Context, 44 | IN UINT32 Result 45 | ); 46 | 47 | VOID 48 | EFIAPI 49 | USBKeyboardRecoveryHandler ( 50 | IN EFI_EVENT Event, 51 | IN VOID *Context 52 | ); 53 | 54 | EFI_STATUS 55 | USBParseKey ( 56 | IN OUT USB_KB_DEV *UsbKeyboardDevice, 57 | OUT UINT8 *KeyChar 58 | ); 59 | 60 | EFI_STATUS 61 | USBKeyCodeToEFIScanCode ( 62 | IN USB_KB_DEV *UsbKeyboardDevice, 63 | IN UINT8 KeyChar, 64 | OUT EFI_INPUT_KEY *Key 65 | ); 66 | 67 | EFI_STATUS 68 | InitUSBKeyBuffer ( 69 | IN OUT USB_KB_BUFFER *KeyboardBuffer 70 | ); 71 | 72 | BOOLEAN 73 | IsUSBKeyboardBufferEmpty ( 74 | IN USB_KB_BUFFER *KeyboardBuffer 75 | ); 76 | 77 | BOOLEAN 78 | IsUSBKeyboardBufferFull ( 79 | IN USB_KB_BUFFER *KeyboardBuffer 80 | ); 81 | 82 | EFI_STATUS 83 | InsertKeyCode ( 84 | IN OUT USB_KB_BUFFER *KeyboardBuffer, 85 | IN UINT8 Key, 86 | IN UINT8 Down 87 | ); 88 | 89 | EFI_STATUS 90 | RemoveKeyCode ( 91 | IN OUT USB_KB_BUFFER *KeyboardBuffer, 92 | OUT USB_KEY *UsbKey 93 | ); 94 | 95 | VOID 96 | EFIAPI 97 | USBKeyboardRepeatHandler ( 98 | IN EFI_EVENT Event, 99 | IN VOID *Context 100 | ); 101 | 102 | EFI_STATUS 103 | SetKeyLED ( 104 | IN USB_KB_DEV *UsbKeyboardDevice 105 | ); 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /UsbPkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Component description file for UsbKb module 3 | # 4 | # Copyright (C) 2004, Intel Corporation
5 | # All rights reserved. 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 | 16 | [Defines] 17 | BASE_NAME = UsbKb 18 | FILE_GUID = 2D2E62CF-9ECF-43B7-8219-94E7FC713DFE 19 | MODULE_TYPE = UEFI_DRIVER 20 | ENTRY_POINT = USBKeyboardDriverBindingEntryPoint 21 | INF_VERSION = 0x00010005 22 | 23 | [Packages] 24 | MdePkg/MdePkg.dec 25 | EfiPkg/EfiPkg.dec 26 | EfiMiscPkg/EfiMiscPkg.dec 27 | 28 | [Guids] 29 | gAppleKeyboardPlatformInfoGuid ## CONSUMES 30 | 31 | [Protocols] 32 | gAppleKeyMapDatabaseProtocolGuid ## CONSUMES 33 | gApplePlatformInfoDatabaseProtocolGuid ## SOMETIMES_CONSUMES 34 | gEfiKeyboardInfoProtocolGuid ## SOMETIMES_PRODUCES 35 | gEfiUsbIoProtocolGuid 36 | gEfiSimpleTextInProtocolGuid 37 | gEfiHotPlugDeviceGuid 38 | 39 | [Pcd] 40 | gEfiMdePkgTokenSpaceGuid.PcdUsbTransferTimeoutValue ## CONSUMES 41 | 42 | [LibraryClasses] 43 | BaseMemoryLib 44 | DebugLib 45 | MemoryAllocationLib 46 | ReportStatusCodeLib 47 | UefiBootServicesTableLib 48 | UefiDriverEntryPoint 49 | UefiLib 50 | UefiRuntimeServicesTableLib ##Remove 51 | UefiUsbLib 52 | 53 | [Sources] 54 | EfiKey.c 55 | Keyboard.c 56 | AppleKeyMap.c 57 | ComponentName.c 58 | --------------------------------------------------------------------------------