MiscOnboardDeviceFunction.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /** @file
  2. Copyright (c) 1999 - 2020, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. MiscOnboardDeviceFunction.c
  6. Abstract:
  7. Create the device path for the Onboard device.
  8. The Onboard device information is Misc. subclass type 8 and SMBIOS type 10.
  9. **/
  10. #include "CommonHeader.h"
  11. #include "MiscSubclassDriver.h"
  12. /**
  13. This is a macro defined function, in fact, the function is
  14. MiscOnboardDeviceFunction (RecordType, RecordLen, RecordData, LogRecordData)
  15. This function makes boot time changes to the contents of the
  16. MiscOnboardDevice structure.
  17. @param MiscOnboardDevice The string which is used to create the function
  18. The Arguments in fact:
  19. @param RecordType Type of record to be processed from the Data
  20. Table. mMiscSubclassDataTable[].RecordType
  21. @param RecordLen Size of static RecordData from the Data Table.
  22. mMiscSubclassDataTable[].RecordLen
  23. @param RecordData Pointer to RecordData, which will be written to
  24. the Data Hub
  25. @param LogRecordData TRUE to log RecordData to Data Hub. FALSE when
  26. there is no more data to log.
  27. @retval EFI_SUCCESS *RecordData and *LogRecordData have been set.
  28. @retval EFI_UNSUPPORTED Unexpected RecordType value.
  29. @retval EFI_INVALID_PARAMETER One of the following parameter conditions was
  30. true: RecordLen was zero. RecordData was NULL.
  31. LogRecordData was NULL.
  32. **/
  33. MISC_SMBIOS_TABLE_FUNCTION (
  34. MiscOnboardDevice
  35. )
  36. {
  37. CHAR8 *OptionalStrStart;
  38. UINT8 StatusAndType;
  39. UINTN DescriptionStrLen;
  40. EFI_STRING DeviceDescription;
  41. STRING_REF TokenToGet;
  42. EFI_STATUS Status;
  43. EFI_SMBIOS_HANDLE SmbiosHandle;
  44. SMBIOS_TABLE_TYPE10 *SmbiosRecord;
  45. EFI_MISC_ONBOARD_DEVICE *ForType10InputData;
  46. ForType10InputData = (EFI_MISC_ONBOARD_DEVICE *)RecordData;
  47. //
  48. // First check for invalid parameters.
  49. //
  50. if (RecordData == NULL) {
  51. return EFI_INVALID_PARAMETER;
  52. }
  53. TokenToGet = 0;
  54. switch (ForType10InputData->OnBoardDeviceDescription) {
  55. case STR_MISC_ONBOARD_DEVICE_VIDEO:
  56. TokenToGet = STRING_TOKEN (STR_MISC_ONBOARD_DEVICE_VIDEO);
  57. break;
  58. case STR_MISC_ONBOARD_DEVICE_AUDIO:
  59. TokenToGet = STRING_TOKEN (STR_MISC_ONBOARD_DEVICE_AUDIO);
  60. break;
  61. default:
  62. break;
  63. }
  64. DeviceDescription = SmbiosMiscGetString (TokenToGet);
  65. DescriptionStrLen = StrLen(DeviceDescription);
  66. if (DescriptionStrLen > SMBIOS_STRING_MAX_LENGTH) {
  67. return EFI_UNSUPPORTED;
  68. }
  69. //
  70. // Two zeros following the last string.
  71. //
  72. SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE10) + DescriptionStrLen + 1 + 1);
  73. ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE10) + DescriptionStrLen + 1 + 1);
  74. SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_ONBOARD_DEVICE_INFORMATION;
  75. SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE10);
  76. //
  77. // Make handle chosen by smbios protocol.add automatically.
  78. //
  79. SmbiosRecord->Hdr.Handle = 0;
  80. //
  81. // Status & Type: Bit 7 Devicen Status, Bits 6:0 Type of Device
  82. //
  83. StatusAndType = (UINT8) ForType10InputData->OnBoardDeviceStatus.DeviceType;
  84. if (ForType10InputData->OnBoardDeviceStatus.DeviceEnabled != 0) {
  85. StatusAndType |= 0x80;
  86. } else {
  87. StatusAndType &= 0x7F;
  88. }
  89. SmbiosRecord->Device[0].DeviceType = StatusAndType;
  90. SmbiosRecord->Device[0].DescriptionString = 1;
  91. OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
  92. UnicodeStrToAsciiStrS (DeviceDescription, OptionalStrStart, DescriptionStrLen + 1 + 1);
  93. //
  94. // Now we have got the full smbios record, call smbios protocol to add this record.
  95. //
  96. SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  97. Status = Smbios-> Add(
  98. Smbios,
  99. NULL,
  100. &SmbiosHandle,
  101. (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
  102. );
  103. FreePool(SmbiosRecord);
  104. return Status;
  105. }