summaryrefslogtreecommitdiff
path: root/Vlv2TbltDevicePkg/PlatformInfoDxe/PlatformInfoDxe.c
blob: 8bdcaee7c9730e71526881b9d11284b453b64923 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/** @file

  Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>
                                                                                   

  This program and the accompanying materials are licensed and made available under

  the terms and conditions of the BSD License that accompanies this distribution.  

  The full text of the license may be found at                                     

  http://opensource.org/licenses/bsd-license.php.                                  

                                                                                   

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,            

  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.    

                                                                                   


Module Name:

  PlatformInfoDxe.c

Abstract:
  Platform Info driver to public platform related HOB data

--*/

#include "PlatformInfoDxe.h"

/**
  Entry point for the driver.

  This routine get the platform HOB data from PEI and publish
  as Platform Info variable that can be accessed during boot service and
  runtime.

  @param ImageHandle    Image Handle.
  @param SystemTable    EFI System Table.

  @retval Status        Function execution status.

**/
EFI_STATUS
EFIAPI
PlatformInfoInit (
  IN EFI_HANDLE                         ImageHandle,
  IN EFI_SYSTEM_TABLE                   *SystemTable
  )
{
  EFI_STATUS                  Status;
  EFI_PLATFORM_INFO_HOB       *PlatformInfoHobPtr;
  EFI_PEI_HOB_POINTERS        GuidHob;
  EFI_PLATFORM_INFO_HOB       TmpHob;
  UINTN                       VarSize;
  EFI_OS_SELECTION_HOB        *OsSlectionHobPtr;
  UINT8                       Selection;
  SYSTEM_CONFIGURATION        SystemConfiguration;
  UINT8                       *LpssDataHobPtr;
  UINT8                       *LpssDataVarPtr;
  UINTN                       i;

  VarSize = sizeof(SYSTEM_CONFIGURATION);
  Status = gRT->GetVariable(
                  NORMAL_SETUP_NAME,
                  &gEfiNormalSetupGuid,
                  NULL,
                  &VarSize,
                  &SystemConfiguration
                  );
  
  if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {
    //The setup variable is corrupted
    VarSize = sizeof(SYSTEM_CONFIGURATION);
    Status = gRT->GetVariable(
              L"SetupRecovery",
              &gEfiNormalSetupGuid,
              NULL,
              &VarSize,
              &SystemConfiguration
              );
    ASSERT_EFI_ERROR (Status);
  }    

  VarSize = sizeof(Selection);
  Status = gRT->GetVariable(
                  L"OsSelection",
                  &gOsSelectionVariableGuid,
                  NULL,
                  &VarSize,
                  &Selection
                  );

  if (EFI_ERROR(Status)) {
    Selection = SystemConfiguration.ReservedO;
    Status = gRT->SetVariable (
                    L"OsSelection",
                    &gOsSelectionVariableGuid,
                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
                    sizeof(Selection),
                    &Selection
                    );
  }

  GuidHob.Raw = GetHobList ();
  if (GuidHob.Raw != NULL) {
    if ((GuidHob.Raw = GetNextGuidHob (&gOsSelectionVariableGuid, GuidHob.Raw)) != NULL) {
      OsSlectionHobPtr = GET_GUID_HOB_DATA (GuidHob.Guid);

      if (OsSlectionHobPtr->OsSelectionChanged) {
        SystemConfiguration.ReservedO = OsSlectionHobPtr->OsSelection;

        //
        // Load Audio default configuration
        //
        SystemConfiguration.Lpe         = OsSlectionHobPtr->Lpe;
        SystemConfiguration.PchAzalia   = OsSlectionHobPtr->PchAzalia;

        //
        // Load LPSS and SCC default configurations
        //
        LpssDataHobPtr = &OsSlectionHobPtr->LpssData.LpssPciModeEnabled;
        LpssDataVarPtr = &SystemConfiguration.LpssPciModeEnabled;
        for (i = 0; i < sizeof(EFI_PLATFORM_LPSS_DATA); i++) {
          *LpssDataVarPtr = *LpssDataHobPtr;
          LpssDataVarPtr++;
          LpssDataHobPtr++;
        }

        SystemConfiguration.GOPEnable = TRUE;

        Status = gRT->SetVariable (
                        NORMAL_SETUP_NAME,
                        &gEfiNormalSetupGuid,
                        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
                        sizeof(SYSTEM_CONFIGURATION),
                        &SystemConfiguration
                        );
        ASSERT_EFI_ERROR (Status);
      }
    }
  }

  GuidHob.Raw = GetHobList ();
  if (GuidHob.Raw == NULL) {
  	return EFI_NOT_FOUND;
  }

  if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) {
    PlatformInfoHobPtr = GET_GUID_HOB_DATA (GuidHob.Guid);
    VarSize = sizeof(EFI_PLATFORM_INFO_HOB);
    Status = gRT->GetVariable(
                    L"PlatformInfo",
                    &gEfiVlv2VariableGuid,
                    NULL,
                    &VarSize,
                    &TmpHob
                    );

    if (EFI_ERROR(Status) || CompareMem (&TmpHob, PlatformInfoHobPtr, VarSize)) {

      //
      // Write the Platform Info to volatile memory
      //
      Status = gRT->SetVariable(
                      L"PlatformInfo",
                      &gEfiVlv2VariableGuid,
                      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
                      sizeof(EFI_PLATFORM_INFO_HOB),
                      PlatformInfoHobPtr
                      );
      if (EFI_ERROR(Status)) {
        return Status;
      }
    }
  }

  return EFI_SUCCESS;
}