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