1 /** @file 2 3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR> 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 Module Name: 24 25 PlatformInfoDxe.c 26 27 Abstract: 28 Platform Info driver to public platform related HOB data 29 30 --*/ 31 32 #include "PlatformInfoDxe.h" 33 34 /** 35 Entry point for the driver. 36 37 This routine get the platform HOB data from PEI and publish 38 as Platform Info variable that can be accessed during boot service and 39 runtime. PlatformInfoInit(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)40 41 @param ImageHandle Image Handle. 42 @param SystemTable EFI System Table. 43 44 @retval Status Function execution status. 45 46 **/ 47 EFI_STATUS 48 EFIAPI 49 PlatformInfoInit ( 50 IN EFI_HANDLE ImageHandle, 51 IN EFI_SYSTEM_TABLE *SystemTable 52 ) 53 { 54 EFI_STATUS Status; 55 EFI_PLATFORM_INFO_HOB *PlatformInfoHobPtr; 56 EFI_PEI_HOB_POINTERS GuidHob; 57 EFI_PLATFORM_INFO_HOB TmpHob; 58 UINTN VarSize; 59 EFI_OS_SELECTION_HOB *OsSlectionHobPtr; 60 UINT8 Selection; 61 SYSTEM_CONFIGURATION SystemConfiguration; 62 UINT8 *LpssDataHobPtr; 63 UINT8 *LpssDataVarPtr; 64 UINTN i; 65 66 VarSize = sizeof(SYSTEM_CONFIGURATION); 67 Status = gRT->GetVariable( 68 NORMAL_SETUP_NAME, 69 &gEfiNormalSetupGuid, 70 NULL, 71 &VarSize, 72 &SystemConfiguration 73 ); 74 75 if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) { 76 //The setup variable is corrupted 77 VarSize = sizeof(SYSTEM_CONFIGURATION); 78 Status = gRT->GetVariable( 79 L"SetupRecovery", 80 &gEfiNormalSetupGuid, 81 NULL, 82 &VarSize, 83 &SystemConfiguration 84 ); 85 ASSERT_EFI_ERROR (Status); 86 } 87 88 VarSize = sizeof(Selection); 89 Status = gRT->GetVariable( 90 L"OsSelection", 91 &gOsSelectionVariableGuid, 92 NULL, 93 &VarSize, 94 &Selection 95 ); 96 97 if (EFI_ERROR(Status)) { 98 Selection = SystemConfiguration.ReservedO; 99 Status = gRT->SetVariable ( 100 L"OsSelection", 101 &gOsSelectionVariableGuid, 102 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, 103 sizeof(Selection), 104 &Selection 105 ); 106 } 107 108 GuidHob.Raw = GetHobList (); 109 if (GuidHob.Raw != NULL) { 110 if ((GuidHob.Raw = GetNextGuidHob (&gOsSelectionVariableGuid, GuidHob.Raw)) != NULL) { 111 OsSlectionHobPtr = GET_GUID_HOB_DATA (GuidHob.Guid); 112 113 if (OsSlectionHobPtr->OsSelectionChanged) { 114 SystemConfiguration.ReservedO = OsSlectionHobPtr->OsSelection; 115 116 // 117 // Load Audio default configuration 118 // 119 SystemConfiguration.Lpe = OsSlectionHobPtr->Lpe; 120 SystemConfiguration.PchAzalia = OsSlectionHobPtr->PchAzalia; 121 122 // 123 // Load LPSS and SCC default configurations 124 // 125 LpssDataHobPtr = &OsSlectionHobPtr->LpssData.LpssPciModeEnabled; 126 LpssDataVarPtr = &SystemConfiguration.LpssPciModeEnabled; 127 for (i = 0; i < sizeof(EFI_PLATFORM_LPSS_DATA); i++) { 128 *LpssDataVarPtr = *LpssDataHobPtr; 129 LpssDataVarPtr++; 130 LpssDataHobPtr++; 131 } 132 133 SystemConfiguration.GOPEnable = TRUE; 134 135 Status = gRT->SetVariable ( 136 NORMAL_SETUP_NAME, 137 &gEfiNormalSetupGuid, 138 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, 139 sizeof(SYSTEM_CONFIGURATION), 140 &SystemConfiguration 141 ); 142 ASSERT_EFI_ERROR (Status); 143 } 144 } 145 } 146 147 GuidHob.Raw = GetHobList (); 148 if (GuidHob.Raw == NULL) { 149 return EFI_NOT_FOUND; 150 } 151 152 if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) { 153 PlatformInfoHobPtr = GET_GUID_HOB_DATA (GuidHob.Guid); 154 VarSize = sizeof(EFI_PLATFORM_INFO_HOB); 155 Status = gRT->GetVariable( 156 L"PlatformInfo", 157 &gEfiVlv2VariableGuid, 158 NULL, 159 &VarSize, 160 &TmpHob 161 ); 162 163 if (EFI_ERROR(Status) || CompareMem (&TmpHob, PlatformInfoHobPtr, VarSize)) { 164 165 // 166 // Write the Platform Info to volatile memory 167 // 168 Status = gRT->SetVariable( 169 L"PlatformInfo", 170 &gEfiVlv2VariableGuid, 171 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, 172 sizeof(EFI_PLATFORM_INFO_HOB), 173 PlatformInfoHobPtr 174 ); 175 if (EFI_ERROR(Status)) { 176 return Status; 177 } 178 } 179 } 180 181 return EFI_SUCCESS; 182 } 183 184