MiscSubclassDriverEntryPoint.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. MiscSubclassDriverEntryPoint.c
  6. Abstract:
  7. This driver parses the mMiscSubclassDataTable structure to
  8. produce SMBIOS records.
  9. **/
  10. #include "CommonHeader.h"
  11. #include "MiscSubclassDriver.h"
  12. #include <Protocol/HiiString.h>
  13. #include <Guid/PlatformInfo.h>
  14. EFI_HII_HANDLE mHiiHandle;
  15. EFI_HII_STRING_PROTOCOL *mHiiString;
  16. EFI_PLATFORM_INFO_HOB *mPlatformInfo=NULL;
  17. EFI_STRING
  18. EFIAPI
  19. SmbiosMiscGetString (
  20. IN EFI_STRING_ID StringId
  21. ){
  22. EFI_STATUS Status;
  23. UINTN StringSize;
  24. CHAR16 TempString;
  25. EFI_STRING String;
  26. String = NULL;
  27. //
  28. // Retrieve the size of the string in the string package for the BestLanguage
  29. //
  30. StringSize = 0;
  31. Status = mHiiString->GetString (
  32. mHiiString,
  33. "en-US",
  34. mHiiHandle,
  35. StringId,
  36. &TempString,
  37. &StringSize,
  38. NULL
  39. );
  40. //
  41. // If GetString() returns EFI_SUCCESS for a zero size,
  42. // then there are no supported languages registered for HiiHandle. If GetString()
  43. // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
  44. // in the HII Database
  45. //
  46. if (Status != EFI_BUFFER_TOO_SMALL) {
  47. goto Error;
  48. }
  49. //
  50. // Allocate a buffer for the return string
  51. //
  52. String = AllocateZeroPool (StringSize);
  53. if (String == NULL) {
  54. goto Error;
  55. }
  56. //
  57. // Retrieve the string from the string package
  58. //
  59. Status = mHiiString->GetString (
  60. mHiiString,
  61. "en-US",
  62. mHiiHandle,
  63. StringId,
  64. String,
  65. &StringSize,
  66. NULL
  67. );
  68. if (EFI_ERROR (Status)) {
  69. //
  70. // Free the buffer and return NULL if the supported languages can not be retrieved.
  71. //
  72. FreePool (String);
  73. String = NULL;
  74. }
  75. Error:
  76. return String;
  77. }
  78. /**
  79. Standard EFI driver point. This driver parses the mMiscSubclassDataTable
  80. structure to produce SMBIOS records.
  81. @param ImageHandle - Handle for the image of this driver
  82. @param SystemTable - Pointer to the EFI System Table
  83. @retval EFI_SUCCESS - The data was successfully reported to the Data Hub.
  84. @retval EFI_DEVICE_ERROR - Can not locate any protocols
  85. **/
  86. EFI_STATUS
  87. EFIAPI
  88. MiscSubclassDriverEntryPoint (
  89. IN EFI_HANDLE ImageHandle,
  90. IN EFI_SYSTEM_TABLE *SystemTable
  91. )
  92. {
  93. UINTN Index;
  94. EFI_STATUS EfiStatus;
  95. EFI_SMBIOS_PROTOCOL *Smbios;
  96. EFI_PEI_HOB_POINTERS GuidHob;
  97. GuidHob.Raw = GetHobList ();
  98. if (GuidHob.Raw != NULL) {
  99. if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) {
  100. mPlatformInfo = GET_GUID_HOB_DATA (GuidHob.Guid);
  101. }
  102. }
  103. DEBUG ((EFI_D_ERROR, "PlatformInfoHob->BoardId [0x%x]\n", mPlatformInfo->BoardId));
  104. //
  105. // Retrieve the pointer to the UEFI HII String Protocol
  106. //
  107. EfiStatus = gBS->LocateProtocol (
  108. &gEfiHiiStringProtocolGuid,
  109. NULL,
  110. (VOID **) &mHiiString
  111. );
  112. ASSERT_EFI_ERROR (EfiStatus);
  113. EfiStatus = gBS->LocateProtocol(
  114. &gEfiSmbiosProtocolGuid,
  115. NULL,
  116. (VOID**)&Smbios
  117. );
  118. if (EFI_ERROR(EfiStatus)) {
  119. DEBUG((EFI_D_ERROR, "Could not locate SMBIOS protocol. %r\n", EfiStatus));
  120. return EfiStatus;
  121. }
  122. mHiiHandle = HiiAddPackages (
  123. &gEfiCallerIdGuid,
  124. NULL,
  125. MiscSubclassStrings,
  126. NULL
  127. );
  128. ASSERT (mHiiHandle != NULL);
  129. for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {
  130. //
  131. // If the entry have a function pointer, just log the data.
  132. //
  133. if (mMiscSubclassDataTable[Index].Function != NULL) {
  134. EfiStatus = (*mMiscSubclassDataTable[Index].Function)(
  135. mMiscSubclassDataTable[Index].RecordData,
  136. Smbios
  137. );
  138. if (EFI_ERROR(EfiStatus)) {
  139. DEBUG((EFI_D_ERROR, "Misc smbios store error. Index=%d, ReturnStatus=%r\n", Index, EfiStatus));
  140. return EfiStatus;
  141. }
  142. }
  143. }
  144. return EfiStatus;
  145. }