]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/PlatformDxe/BoardId.c
Vlv2TbltDevicePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / Vlv2TbltDevicePkg / PlatformDxe / BoardId.c
1 /** @file
2
3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
4
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7
8
9 Module Name:
10
11
12 BoardId.c
13
14 Abstract:
15
16 Initialization for the board ID.
17
18 This code should be common across a chipset family of products.
19
20
21
22 --*/
23
24 #include "PchRegs.h"
25 #include "PlatformDxe.h"
26 #include <Guid/IdccData.h>
27 #include <Guid/EfiVpdData.h>
28 #include <Protocol/DataHub.h>
29
30
31 extern EFI_GUID mPlatformDriverGuid;
32
33 //
34 // Global module data
35 //
36 UINT32 mBoardId;
37 UINT8 mBoardIdIndex;
38 EFI_BOARD_FEATURES mBoardFeatures;
39 UINT16 mSubsystemDeviceId;
40 UINT16 mSubsystemAudioDeviceId;
41 CHAR8 BoardAaNumber[7];
42 BOOLEAN mFoundAANum;
43
44 /**
45
46 Write the boardid variable if it does not already exist.
47
48 **/
49 VOID
50 InitializeBoardId (
51 )
52 {
53
54 UINT32 BoardIdBufferSize;
55 EFI_IDCC_BOARD_FORM_FACTOR IdccBoardFormFactor;
56 EFI_DATA_HUB_PROTOCOL *DataHub;
57 EFI_STATUS Status;
58 DMI_DATA DmiDataVariable;
59 UINTN Size;
60 #if defined(DUPLICATE_AA_NO_BASE_ADDR)
61 CHAR8 DuplicateAaNoAscii[sizeof(DmiDataVariable.BaseBoardVersion)];
62 UINTN iter;
63 #endif
64 #if defined(GPIO_BOARD_ID_SUPPORT) && GPIO_BOARD_ID_SUPPORT != 0
65 UINT8 Data8;
66 #endif
67
68 //
69 // Update data from the updatable DMI data area
70 //
71 Size = sizeof (DMI_DATA);
72 SetMem(&DmiDataVariable, Size, 0xFF);
73 Status = gRT->GetVariable (
74 DMI_DATA_NAME,
75 &gDmiDataGuid,
76 NULL,
77 &Size,
78 &DmiDataVariable
79 );
80
81 #if defined(DUPLICATE_AA_NO_BASE_ADDR)
82 //
83 // Get AA# from flash descriptor region
84 //
85 EfiSetMem(DuplicateAaNoAscii, sizeof(DuplicateAaNoAscii), 0xFF);
86 FlashRead((UINT8 *)(UINTN)DUPLICATE_AA_NO_BASE_ADDR,
87 (UINT8 *)DuplicateAaNoAscii,
88 sizeof(DuplicateAaNoAscii));
89
90 //
91 // Validate AA# read from VPD
92 //
93 for (iter = 0; iter < sizeof(DuplicateAaNoAscii); iter++) {
94 if ((DuplicateAaNoAscii[iter] != 0xFF) &&
95 (DuplicateAaNoAscii[iter] != DmiDataVariable.BaseBoardVersion[iter])) {
96 DmiDataVariable.BaseBoardVersion[iter] = DuplicateAaNoAscii[iter];
97 }
98 }
99
100 Status = EFI_SUCCESS;
101 #endif
102
103 mFoundAANum = FALSE;
104
105 //
106 // No variable...no copy
107 //
108 if (EFI_ERROR (Status)) {
109 mBoardIdIndex = 0; // If we can't find the BoardId in the table, use the first entry
110 } else {
111 //
112 // This is the correct method of checking for AA#.
113 //
114 CopyMem(&BoardAaNumber, ((((UINT8*)&DmiDataVariable.BaseBoardVersion)+2)), 6);
115 BoardAaNumber[6] = 0;
116 for (mBoardIdIndex = 0; mBoardIdIndex < mBoardIdDecodeTableSize; mBoardIdIndex++) {
117 if (AsciiStrnCmp(mBoardIdDecodeTable[mBoardIdIndex].AaNumber, BoardAaNumber, 6) == 0) {
118 mFoundAANum = TRUE;
119 break;
120 }
121 }
122
123 if(!mFoundAANum) {
124 //
125 // Add check for AA#'s that is programmed without the AA as leading chars.
126 //
127 CopyMem(&BoardAaNumber, (((UINT8*)&DmiDataVariable.BaseBoardVersion)), 6);
128 BoardAaNumber[6] = 0;
129 for (mBoardIdIndex = 0; mBoardIdIndex < mBoardIdDecodeTableSize; mBoardIdIndex++) {
130 if (AsciiStrnCmp(mBoardIdDecodeTable[mBoardIdIndex].AaNumber, BoardAaNumber, 6) == 0) {
131 mFoundAANum = TRUE;
132 break;
133 }
134 }
135 }
136 }
137
138 #if defined(GPIO_BOARD_ID_SUPPORT) && GPIO_BOARD_ID_SUPPORT != 0
139 //
140 // If we can't find the BoardAA# in the table, find BoardId
141 //
142 if (mFoundAANum != TRUE) {
143 //
144 // BoardID BIT Location
145 // 0 GPIO33 (ICH)
146 // 1 GPIO34 (ICH)
147 //
148 Data8 = IoRead8(GPIO_BASE_ADDRESS + R_PCH_GPIO_SC_LVL2);
149
150 //
151 // BoardId[0]
152 //
153 mBoardId = (UINT32)((Data8 >> 1) & BIT0);
154 //
155 // BoardId[1]
156 //
157 mBoardId |= (UINT32)((Data8 >> 1) & BIT1);
158
159 for (mBoardIdIndex = 0; mBoardIdIndex < mBoardIdDecodeTableSize; mBoardIdIndex++) {
160 if (mBoardIdDecodeTable[mBoardIdIndex].BoardId == mBoardId) {
161 break;
162 }
163 }
164 #endif
165 if (mBoardIdIndex == mBoardIdDecodeTableSize) {
166 mBoardIdIndex = 0; // If we can't find the BoardId in the table, use the first entry
167 }
168 #if defined(GPIO_BOARD_ID_SUPPORT) && GPIO_BOARD_ID_SUPPORT != 0
169 }
170 #endif
171
172 mBoardFeatures = mBoardIdDecodeTable[mBoardIdIndex].Features;
173 mSubsystemDeviceId = mBoardIdDecodeTable[mBoardIdIndex].SubsystemDeviceId;
174 mSubsystemAudioDeviceId = mBoardIdDecodeTable[mBoardIdIndex].AudioSubsystemDeviceId;
175
176 //
177 // Set the BoardFeatures variable
178 //
179 BoardIdBufferSize = sizeof (mBoardFeatures);
180 gRT->SetVariable (
181 BOARD_FEATURES_NAME,
182 &gEfiBoardFeaturesGuid,
183 EFI_VARIABLE_NON_VOLATILE |
184 EFI_VARIABLE_BOOTSERVICE_ACCESS |
185 EFI_VARIABLE_RUNTIME_ACCESS,
186 BoardIdBufferSize,
187 &mBoardFeatures
188 );
189
190 //
191 // Get the Data Hub protocol
192 //
193 Status = gBS->LocateProtocol (
194 &gEfiDataHubProtocolGuid,
195 NULL,
196 (VOID **) &DataHub
197 );
198 if (!(EFI_ERROR(Status))) {
199 //
200 // Fill out data
201 //
202 IdccBoardFormFactor.IdccHeader.Type = EFI_IDCC_BOARD_FORM_FACTOR_TYPE;
203 IdccBoardFormFactor.IdccHeader.RecordLength = sizeof(EFI_IDCC_BOARD_FORM_FACTOR);
204 if ((mBoardFeatures & B_BOARD_FEATURES_FORM_FACTOR_ATX) || (mBoardFeatures & B_BOARD_FEATURES_FORM_FACTOR_MICRO_ATX)) {
205 IdccBoardFormFactor.BoardFormFactor = ATX_FORM_FACTOR; // ATX
206 } else {
207 IdccBoardFormFactor.BoardFormFactor = BTX_FORM_FACTOR; // BTX
208 }
209
210 //
211 // Publish the Board Form Factor value for IDCC
212 //
213 Status = DataHub->LogData (
214 DataHub,
215 &gIdccDataHubGuid,
216 &mPlatformDriverGuid,
217 EFI_DATA_RECORD_CLASS_DATA,
218 &IdccBoardFormFactor,
219 sizeof(EFI_IDCC_BOARD_FORM_FACTOR)
220 );
221 }
222 }
223