BoardId.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /** @file
  2. Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. BoardId.c
  6. Abstract:
  7. Initialization for the board ID.
  8. This code should be common across a chipset family of products.
  9. --*/
  10. #include "PchRegs.h"
  11. #include "PlatformDxe.h"
  12. #include <Guid/EfiVpdData.h>
  13. //
  14. // Global module data
  15. //
  16. UINT32 mBoardId;
  17. UINT8 mBoardIdIndex;
  18. EFI_BOARD_FEATURES mBoardFeatures;
  19. UINT16 mSubsystemDeviceId;
  20. UINT16 mSubsystemAudioDeviceId;
  21. CHAR8 BoardAaNumber[7];
  22. BOOLEAN mFoundAANum;
  23. /**
  24. Write the boardid variable if it does not already exist.
  25. **/
  26. VOID
  27. InitializeBoardId (
  28. )
  29. {
  30. UINT32 BoardIdBufferSize;
  31. EFI_STATUS Status;
  32. DMI_DATA DmiDataVariable;
  33. UINTN Size;
  34. #if defined(DUPLICATE_AA_NO_BASE_ADDR)
  35. CHAR8 DuplicateAaNoAscii[sizeof(DmiDataVariable.BaseBoardVersion)];
  36. UINTN iter;
  37. #endif
  38. #if defined(GPIO_BOARD_ID_SUPPORT) && GPIO_BOARD_ID_SUPPORT != 0
  39. UINT8 Data8;
  40. #endif
  41. //
  42. // Update data from the updatable DMI data area
  43. //
  44. Size = sizeof (DMI_DATA);
  45. SetMem(&DmiDataVariable, Size, 0xFF);
  46. Status = gRT->GetVariable (
  47. DMI_DATA_NAME,
  48. &gDmiDataGuid,
  49. NULL,
  50. &Size,
  51. &DmiDataVariable
  52. );
  53. #if defined(DUPLICATE_AA_NO_BASE_ADDR)
  54. //
  55. // Get AA# from flash descriptor region
  56. //
  57. EfiSetMem(DuplicateAaNoAscii, sizeof(DuplicateAaNoAscii), 0xFF);
  58. FlashRead((UINT8 *)(UINTN)DUPLICATE_AA_NO_BASE_ADDR,
  59. (UINT8 *)DuplicateAaNoAscii,
  60. sizeof(DuplicateAaNoAscii));
  61. //
  62. // Validate AA# read from VPD
  63. //
  64. for (iter = 0; iter < sizeof(DuplicateAaNoAscii); iter++) {
  65. if ((DuplicateAaNoAscii[iter] != 0xFF) &&
  66. (DuplicateAaNoAscii[iter] != DmiDataVariable.BaseBoardVersion[iter])) {
  67. DmiDataVariable.BaseBoardVersion[iter] = DuplicateAaNoAscii[iter];
  68. }
  69. }
  70. Status = EFI_SUCCESS;
  71. #endif
  72. mFoundAANum = FALSE;
  73. //
  74. // No variable...no copy
  75. //
  76. if (EFI_ERROR (Status)) {
  77. mBoardIdIndex = 0; // If we can't find the BoardId in the table, use the first entry
  78. } else {
  79. //
  80. // This is the correct method of checking for AA#.
  81. //
  82. CopyMem(&BoardAaNumber, ((((UINT8*)&DmiDataVariable.BaseBoardVersion)+2)), 6);
  83. BoardAaNumber[6] = 0;
  84. for (mBoardIdIndex = 0; mBoardIdIndex < mBoardIdDecodeTableSize; mBoardIdIndex++) {
  85. if (AsciiStrnCmp(mBoardIdDecodeTable[mBoardIdIndex].AaNumber, BoardAaNumber, 6) == 0) {
  86. mFoundAANum = TRUE;
  87. break;
  88. }
  89. }
  90. if(!mFoundAANum) {
  91. //
  92. // Add check for AA#'s that is programmed without the AA as leading chars.
  93. //
  94. CopyMem(&BoardAaNumber, (((UINT8*)&DmiDataVariable.BaseBoardVersion)), 6);
  95. BoardAaNumber[6] = 0;
  96. for (mBoardIdIndex = 0; mBoardIdIndex < mBoardIdDecodeTableSize; mBoardIdIndex++) {
  97. if (AsciiStrnCmp(mBoardIdDecodeTable[mBoardIdIndex].AaNumber, BoardAaNumber, 6) == 0) {
  98. mFoundAANum = TRUE;
  99. break;
  100. }
  101. }
  102. }
  103. }
  104. #if defined(GPIO_BOARD_ID_SUPPORT) && GPIO_BOARD_ID_SUPPORT != 0
  105. //
  106. // If we can't find the BoardAA# in the table, find BoardId
  107. //
  108. if (mFoundAANum != TRUE) {
  109. //
  110. // BoardID BIT Location
  111. // 0 GPIO33 (ICH)
  112. // 1 GPIO34 (ICH)
  113. //
  114. Data8 = IoRead8(GPIO_BASE_ADDRESS + R_PCH_GPIO_SC_LVL2);
  115. //
  116. // BoardId[0]
  117. //
  118. mBoardId = (UINT32)((Data8 >> 1) & BIT0);
  119. //
  120. // BoardId[1]
  121. //
  122. mBoardId |= (UINT32)((Data8 >> 1) & BIT1);
  123. for (mBoardIdIndex = 0; mBoardIdIndex < mBoardIdDecodeTableSize; mBoardIdIndex++) {
  124. if (mBoardIdDecodeTable[mBoardIdIndex].BoardId == mBoardId) {
  125. break;
  126. }
  127. }
  128. #endif
  129. if (mBoardIdIndex == mBoardIdDecodeTableSize) {
  130. mBoardIdIndex = 0; // If we can't find the BoardId in the table, use the first entry
  131. }
  132. #if defined(GPIO_BOARD_ID_SUPPORT) && GPIO_BOARD_ID_SUPPORT != 0
  133. }
  134. #endif
  135. mBoardFeatures = mBoardIdDecodeTable[mBoardIdIndex].Features;
  136. mSubsystemDeviceId = mBoardIdDecodeTable[mBoardIdIndex].SubsystemDeviceId;
  137. mSubsystemAudioDeviceId = mBoardIdDecodeTable[mBoardIdIndex].AudioSubsystemDeviceId;
  138. //
  139. // Set the BoardFeatures variable
  140. //
  141. BoardIdBufferSize = sizeof (mBoardFeatures);
  142. gRT->SetVariable (
  143. BOARD_FEATURES_NAME,
  144. &gEfiBoardFeaturesGuid,
  145. EFI_VARIABLE_NON_VOLATILE |
  146. EFI_VARIABLE_BOOTSERVICE_ACCESS |
  147. EFI_VARIABLE_RUNTIME_ACCESS,
  148. BoardIdBufferSize,
  149. &mBoardFeatures
  150. );
  151. }