3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
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.
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.
21 Initialization for the board ID.
23 This code should be common across a chipset family of products.
30 #include "PlatformDxe.h"
31 #include <Guid/IdccData.h>
32 #include <Guid/EfiVpdData.h>
33 #include <Protocol/DataHub.h>
36 extern EFI_GUID mPlatformDriverGuid
;
43 EFI_BOARD_FEATURES mBoardFeatures
;
44 UINT16 mSubsystemDeviceId
;
45 UINT16 mSubsystemAudioDeviceId
;
46 CHAR8 BoardAaNumber
[7];
51 Write the boardid variable if it does not already exist.
59 UINT32 BoardIdBufferSize
;
60 EFI_IDCC_BOARD_FORM_FACTOR IdccBoardFormFactor
;
61 EFI_DATA_HUB_PROTOCOL
*DataHub
;
63 DMI_DATA DmiDataVariable
;
65 #if defined(DUPLICATE_AA_NO_BASE_ADDR)
66 CHAR8 DuplicateAaNoAscii
[sizeof(DmiDataVariable
.BaseBoardVersion
)];
69 #if defined(GPIO_BOARD_ID_SUPPORT) && GPIO_BOARD_ID_SUPPORT != 0
74 // Update data from the updatable DMI data area
76 Size
= sizeof (DMI_DATA
);
77 SetMem(&DmiDataVariable
, Size
, 0xFF);
78 Status
= gRT
->GetVariable (
86 #if defined(DUPLICATE_AA_NO_BASE_ADDR)
88 // Get AA# from flash descriptor region
90 EfiSetMem(DuplicateAaNoAscii
, sizeof(DuplicateAaNoAscii
), 0xFF);
91 FlashRead((UINT8
*)(UINTN
)DUPLICATE_AA_NO_BASE_ADDR
,
92 (UINT8
*)DuplicateAaNoAscii
,
93 sizeof(DuplicateAaNoAscii
));
96 // Validate AA# read from VPD
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
];
105 Status
= EFI_SUCCESS
;
111 // No variable...no copy
113 if (EFI_ERROR (Status
)) {
114 mBoardIdIndex
= 0; // If we can't find the BoardId in the table, use the first entry
117 // This is the correct method of checking for AA#.
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) {
130 // Add check for AA#'s that is programmed without the AA as leading chars.
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) {
143 #if defined(GPIO_BOARD_ID_SUPPORT) && GPIO_BOARD_ID_SUPPORT != 0
145 // If we can't find the BoardAA# in the table, find BoardId
147 if (mFoundAANum
!= TRUE
) {
149 // BoardID BIT Location
153 Data8
= IoRead8(GPIO_BASE_ADDRESS
+ R_PCH_GPIO_SC_LVL2
);
158 mBoardId
= (UINT32
)((Data8
>> 1) & BIT0
);
162 mBoardId
|= (UINT32
)((Data8
>> 1) & BIT1
);
164 for (mBoardIdIndex
= 0; mBoardIdIndex
< mBoardIdDecodeTableSize
; mBoardIdIndex
++) {
165 if (mBoardIdDecodeTable
[mBoardIdIndex
].BoardId
== mBoardId
) {
170 if (mBoardIdIndex
== mBoardIdDecodeTableSize
) {
171 mBoardIdIndex
= 0; // If we can't find the BoardId in the table, use the first entry
173 #if defined(GPIO_BOARD_ID_SUPPORT) && GPIO_BOARD_ID_SUPPORT != 0
177 mBoardFeatures
= mBoardIdDecodeTable
[mBoardIdIndex
].Features
;
178 mSubsystemDeviceId
= mBoardIdDecodeTable
[mBoardIdIndex
].SubsystemDeviceId
;
179 mSubsystemAudioDeviceId
= mBoardIdDecodeTable
[mBoardIdIndex
].AudioSubsystemDeviceId
;
182 // Set the BoardFeatures variable
184 BoardIdBufferSize
= sizeof (mBoardFeatures
);
187 &gEfiBoardFeaturesGuid
,
188 EFI_VARIABLE_NON_VOLATILE
|
189 EFI_VARIABLE_BOOTSERVICE_ACCESS
|
190 EFI_VARIABLE_RUNTIME_ACCESS
,
196 // Get the Data Hub protocol
198 Status
= gBS
->LocateProtocol (
199 &gEfiDataHubProtocolGuid
,
203 if (!(EFI_ERROR(Status
))) {
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
212 IdccBoardFormFactor
.BoardFormFactor
= BTX_FORM_FACTOR
; // BTX
216 // Publish the Board Form Factor value for IDCC
218 Status
= DataHub
->LogData (
221 &mPlatformDriverGuid
,
222 EFI_DATA_RECORD_CLASS_DATA
,
223 &IdccBoardFormFactor
,
224 sizeof(EFI_IDCC_BOARD_FORM_FACTOR
)