SmbiosMiscEntryPoint.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /**@file
  2. Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
  3. Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
  4. Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
  5. This program and the accompanying materials
  6. are licensed and made available under the terms and conditions of the BSD License
  7. which accompanies this distribution. The full text of the license may be found at
  8. http://opensource.org/licenses/bsd-license.php
  9. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  11. Module Name:
  12. SmbiosMiscEntryPoint.c
  13. Abstract:
  14. This driver parses the mSmbiosMiscDataTable structure and reports
  15. any generated data using SMBIOS protocol.
  16. Based on files under Nt32Pkg/MiscSubClassPlatformDxe/
  17. **/
  18. #include "SmbiosMisc.h"
  19. #define MAX_HANDLE_COUNT 0x10
  20. EFI_HANDLE mImageHandle;
  21. EFI_HII_HANDLE mHiiHandle;
  22. EFI_SMBIOS_PROTOCOL *mSmbios = NULL;
  23. //
  24. // Data Table Array
  25. //
  26. extern EFI_MISC_SMBIOS_DATA_TABLE mSmbiosMiscDataTable[];
  27. //
  28. // Data Table Array Entries
  29. //
  30. extern UINTN mSmbiosMiscDataTableEntries;
  31. extern UINT8 SmbiosMiscDxeStrings[];
  32. /**
  33. Standard EFI driver point. This driver parses the mSmbiosMiscDataTable
  34. structure and reports any generated data using SMBIOS protocol.
  35. @param ImageHandle Handle for the image of this driver
  36. @param SystemTable Pointer to the EFI System Table
  37. @retval EFI_SUCCESS The data was successfully stored.
  38. **/
  39. EFI_STATUS
  40. EFIAPI
  41. SmbiosMiscEntryPoint(
  42. IN EFI_HANDLE ImageHandle,
  43. IN EFI_SYSTEM_TABLE *SystemTable
  44. )
  45. {
  46. UINTN Index;
  47. EFI_STATUS EfiStatus;
  48. EFI_SMBIOS_PROTOCOL *Smbios;
  49. mImageHandle = ImageHandle;
  50. EfiStatus = gBS->LocateProtocol(&gEfiSmbiosProtocolGuid, NULL, (VOID**)&Smbios);
  51. if (EFI_ERROR(EfiStatus))
  52. {
  53. DEBUG((EFI_D_ERROR, "Could not locate SMBIOS protocol. %r\n", EfiStatus));
  54. return EfiStatus;
  55. }
  56. mSmbios = Smbios;
  57. mHiiHandle = HiiAddPackages (
  58. &gEfiCallerIdGuid,
  59. mImageHandle,
  60. SmbiosMiscDxeStrings,
  61. NULL
  62. );
  63. if(mHiiHandle == NULL)
  64. {
  65. return EFI_OUT_OF_RESOURCES;
  66. }
  67. for (Index = 0; Index < mSmbiosMiscDataTableEntries; ++Index)
  68. {
  69. //
  70. // If the entry have a function pointer, just log the data.
  71. //
  72. if (mSmbiosMiscDataTable[Index].Function != NULL)
  73. {
  74. EfiStatus = (*mSmbiosMiscDataTable[Index].Function)(
  75. mSmbiosMiscDataTable[Index].RecordData,
  76. Smbios
  77. );
  78. if (EFI_ERROR(EfiStatus))
  79. {
  80. DEBUG((EFI_D_ERROR, "Misc smbios store error. Index=%d, ReturnStatus=%r\n", Index, EfiStatus));
  81. return EfiStatus;
  82. }
  83. }
  84. }
  85. return EfiStatus;
  86. }
  87. /**
  88. Logs SMBIOS record.
  89. @param Buffer The data for the fixed portion of the SMBIOS record. The format of the record is
  90. determined by EFI_SMBIOS_TABLE_HEADER.Type. The size of the formatted area is defined
  91. by EFI_SMBIOS_TABLE_HEADER.Length and either followed by a double-null (0x0000) or
  92. a set of null terminated strings and a null.
  93. @param SmbiosHandle A unique handle will be assigned to the SMBIOS record.
  94. @retval EFI_SUCCESS Record was added.
  95. @retval EFI_OUT_OF_RESOURCES Record was not added due to lack of system resources.
  96. **/
  97. EFI_STATUS
  98. LogSmbiosData (
  99. IN UINT8 *Buffer,
  100. IN OUT EFI_SMBIOS_HANDLE *SmbiosHandle
  101. )
  102. {
  103. EFI_STATUS Status;
  104. *SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  105. Status = mSmbios->Add (
  106. mSmbios,
  107. NULL,
  108. SmbiosHandle,
  109. (EFI_SMBIOS_TABLE_HEADER *)Buffer
  110. );
  111. return Status;
  112. }
  113. VOID
  114. GetLinkTypeHandle(
  115. IN UINT8 SmbiosType,
  116. OUT UINT16 **HandleArray,
  117. OUT UINTN *HandleCount
  118. )
  119. {
  120. EFI_STATUS Status;
  121. EFI_SMBIOS_HANDLE SmbiosHandle;
  122. EFI_SMBIOS_TABLE_HEADER *LinkTypeData = NULL;
  123. if(mSmbios == NULL)
  124. return ;
  125. SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  126. *HandleArray = AllocateZeroPool(sizeof(UINT16) * MAX_HANDLE_COUNT);
  127. if (*HandleArray == NULL)
  128. {
  129. DEBUG ((EFI_D_INFO, "HandleArray allocate memory resource failed.\n"));
  130. return;
  131. }
  132. *HandleCount = 0;
  133. while(1)
  134. {
  135. Status = mSmbios->GetNext(
  136. mSmbios,
  137. &SmbiosHandle,
  138. &SmbiosType,
  139. &LinkTypeData,
  140. NULL
  141. );
  142. if(!EFI_ERROR(Status))
  143. {
  144. (*HandleArray)[*HandleCount] = LinkTypeData->Handle;
  145. (*HandleCount)++;
  146. }
  147. else
  148. {
  149. break;
  150. }
  151. }
  152. }