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