MiscPortInternalConnectorDesignatorFunction.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /** @file
  2. Copyright (c) 2004 - 2020, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. MiscPortInternalConnectorDesignatorFunction.c
  6. Abstract:
  7. Create the device path for the Port internal connector designator.
  8. Port internal connector designator information is Misc. subclass type 6
  9. and SMBIOS type 8.
  10. **/
  11. #include "CommonHeader.h"
  12. #include "MiscSubclassDriver.h"
  13. /**
  14. This is a macro defined function, in fact, the function is
  15. MiscPortInternalConnectorDesignatorFunction (RecordType, RecordLen, RecordData, LogRecordData)
  16. This function makes boot time changes to the contents of the
  17. MiscPortConnectorInformation.
  18. @param MiscPortInternalConnectorDesignator The string which is used to create
  19. the function
  20. The Arguments in fact:
  21. @param RecordType Type of record to be processed from
  22. the Data Table.
  23. mMiscSubclassDataTable[].RecordType
  24. @param RecordLen Size of static RecordData from the
  25. Data Table.
  26. mMiscSubclassDataTable[].RecordLen
  27. @param RecordData Pointer to RecordData, which will be
  28. written to the Data Hub
  29. @param LogRecordData TRUE to log RecordData to Data Hub.
  30. FALSE when there is no more data to
  31. log.
  32. @retval EFI_SUCCESS *RecordData and *LogRecordData have
  33. been set.
  34. @retval EFI_UNSUPPORTED Unexpected RecordType value.
  35. @retval EFI_INVALID_PARAMETER One of the following parameter
  36. conditions was true: RecordLen was
  37. zero. RecordData was NULL.
  38. LogRecordData was NULL.
  39. **/
  40. MISC_SMBIOS_TABLE_FUNCTION (
  41. MiscPortInternalConnectorDesignator
  42. )
  43. {
  44. CHAR8 *OptionalStrStart;
  45. UINTN InternalRefStrLen;
  46. UINTN ExternalRefStrLen;
  47. EFI_STRING InternalRef;
  48. EFI_STRING ExternalRef;
  49. STRING_REF TokenForInternal;
  50. STRING_REF TokenForExternal;
  51. EFI_STATUS Status;
  52. SMBIOS_TABLE_TYPE8 *SmbiosRecord;
  53. EFI_SMBIOS_HANDLE SmbiosHandle;
  54. EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR *ForType8InputData;
  55. ForType8InputData = (EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR *)RecordData;
  56. //
  57. // First check for invalid parameters.
  58. //
  59. if (RecordData == NULL) {
  60. return EFI_INVALID_PARAMETER;
  61. }
  62. TokenForInternal = 0;
  63. TokenForExternal = 0;
  64. switch (ForType8InputData->PortInternalConnectorDesignator) {
  65. case STR_MISC_PORT_INTERNAL_IDE1:
  66. TokenForInternal = STRING_TOKEN (STR_MISC_PORT_INTERNAL_IDE1);
  67. TokenForExternal = STRING_TOKEN(STR_MISC_PORT_EXTERNAL_IDE1);
  68. break;
  69. case STR_MISC_PORT_INTERNAL_IDE2:
  70. TokenForInternal = STRING_TOKEN (STR_MISC_PORT_INTERNAL_IDE2);
  71. TokenForExternal = STRING_TOKEN(STR_MISC_PORT_EXTERNAL_IDE2);
  72. break;
  73. case STR_MISC_PORT_INTERNAL_ATX_POWER:
  74. TokenForInternal = STRING_TOKEN (STR_MISC_PORT_INTERNAL_ATX_POWER);
  75. TokenForExternal = STRING_TOKEN(STR_MISC_PORT_EXTERNAL_ATX_POWER);
  76. break;
  77. default:
  78. break;
  79. }
  80. InternalRef = SmbiosMiscGetString (TokenForInternal);
  81. InternalRefStrLen = StrLen(InternalRef);
  82. if (InternalRefStrLen > SMBIOS_STRING_MAX_LENGTH) {
  83. return EFI_UNSUPPORTED;
  84. }
  85. ExternalRef = SmbiosMiscGetString (TokenForExternal);
  86. ExternalRefStrLen = StrLen(ExternalRef);
  87. if (ExternalRefStrLen > SMBIOS_STRING_MAX_LENGTH) {
  88. return EFI_UNSUPPORTED;
  89. }
  90. //
  91. // Two zeros following the last string.
  92. //
  93. SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE8) + InternalRefStrLen + 1 + ExternalRefStrLen + 1 + 1);
  94. ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE8) + InternalRefStrLen + 1 + ExternalRefStrLen + 1 + 1);
  95. SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PORT_CONNECTOR_INFORMATION;
  96. SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE8);
  97. //
  98. // Make handle chosen by smbios protocol.add automatically.
  99. //
  100. SmbiosRecord->Hdr.Handle = 0;
  101. SmbiosRecord->InternalReferenceDesignator = 1;
  102. SmbiosRecord->InternalConnectorType = (UINT8)ForType8InputData->PortInternalConnectorType;
  103. SmbiosRecord->ExternalReferenceDesignator = 2;
  104. SmbiosRecord->ExternalConnectorType = (UINT8)ForType8InputData->PortExternalConnectorType;
  105. SmbiosRecord->PortType = (UINT8)ForType8InputData->PortType;
  106. OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
  107. UnicodeStrToAsciiStrS (InternalRef, OptionalStrStart, InternalRefStrLen + 1 + ExternalRefStrLen + 1 + 1);
  108. UnicodeStrToAsciiStrS (ExternalRef, OptionalStrStart + InternalRefStrLen + 1, ExternalRefStrLen + 1 + 1);
  109. //
  110. // Now we have got the full smbios record, call smbios protocol to add this record.
  111. //
  112. SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  113. Status = Smbios-> Add(
  114. Smbios,
  115. NULL,
  116. &SmbiosHandle,
  117. (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
  118. );
  119. FreePool(SmbiosRecord);
  120. return Status;
  121. }