MiscSystemSlotDesignationFunction.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*++
  2. Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. MiscSystemSlotDesignatorFunction.c
  6. Abstract:
  7. BIOS system slot designator information boot time changes.
  8. SMBIOS type 9.
  9. --*/
  10. #include "MiscSubclassDriver.h"
  11. /**
  12. This function makes boot time changes to the contents of the
  13. MiscSystemSlotDesignator structure (Type 9).
  14. @param RecordData Pointer to copy of RecordData from the Data Table.
  15. @retval EFI_SUCCESS All parameters were valid.
  16. @retval EFI_UNSUPPORTED Unexpected RecordType value.
  17. @retval EFI_INVALID_PARAMETER Invalid parameter was found.
  18. **/
  19. MISC_SMBIOS_TABLE_FUNCTION(MiscSystemSlotDesignation)
  20. {
  21. CHAR8 *OptionalStrStart;
  22. UINTN SlotDesignationStrLen;
  23. EFI_STATUS Status;
  24. EFI_STRING SlotDesignation;
  25. STRING_REF TokenToGet;
  26. SMBIOS_TABLE_TYPE9 *SmbiosRecord;
  27. EFI_SMBIOS_HANDLE SmbiosHandle;
  28. EFI_MISC_SYSTEM_SLOT_DESIGNATION* ForType9InputData;
  29. ForType9InputData = (EFI_MISC_SYSTEM_SLOT_DESIGNATION *)RecordData;
  30. //
  31. // First check for invalid parameters.
  32. //
  33. if (RecordData == NULL) {
  34. return EFI_INVALID_PARAMETER;
  35. }
  36. TokenToGet = 0;
  37. switch (ForType9InputData->SlotDesignation) {
  38. case STR_MISC_SYSTEM_SLOT_PCIEX16_1:
  39. TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCIEX16_1);
  40. break;
  41. case STR_MISC_SYSTEM_SLOT_PCIEX16_2:
  42. TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCIEX16_2);
  43. break;
  44. case STR_MISC_SYSTEM_SLOT_PCIEX4:
  45. TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCIEX4);
  46. break;
  47. case STR_MISC_SYSTEM_SLOT_PCIEX1_1:
  48. TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCIEX1_1);
  49. break;
  50. case STR_MISC_SYSTEM_SLOT_PCIEX1_2:
  51. TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCIEX1_2);
  52. break;
  53. case STR_MISC_SYSTEM_SLOT_PCIEX1_3:
  54. TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCIEX1_3);
  55. break;
  56. case STR_MISC_SYSTEM_SLOT_PCI1:
  57. TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCI1);
  58. break;
  59. case STR_MISC_SYSTEM_SLOT_PCI2:
  60. TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCI2);
  61. break;
  62. case STR_MISC_SYSTEM_SLOT_PCI3:
  63. TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCI3);
  64. break;
  65. default:
  66. break;
  67. }
  68. SlotDesignation = SmbiosMiscGetString (TokenToGet);
  69. SlotDesignationStrLen = StrLen(SlotDesignation);
  70. if (SlotDesignationStrLen > SMBIOS_STRING_MAX_LENGTH) {
  71. return EFI_UNSUPPORTED;
  72. }
  73. //
  74. // Two zeros following the last string.
  75. //
  76. SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE9) + SlotDesignationStrLen + 1 + 1);
  77. ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE9) +SlotDesignationStrLen + 1 + 1);
  78. SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_SLOTS;
  79. SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE9);
  80. SmbiosRecord->Hdr.Handle = 0;
  81. SmbiosRecord->SlotDesignation = 1;
  82. SmbiosRecord->SlotType = (UINT8)ForType9InputData->SlotType;
  83. SmbiosRecord->SlotDataBusWidth = (UINT8)ForType9InputData->SlotDataBusWidth;
  84. SmbiosRecord->CurrentUsage = (UINT8)ForType9InputData->SlotUsage;
  85. SmbiosRecord->SlotLength = (UINT8)ForType9InputData->SlotLength;
  86. SmbiosRecord->SlotID = ForType9InputData->SlotId;
  87. //
  88. // Slot Characteristics
  89. //
  90. CopyMem ((UINT8 *) &SmbiosRecord->SlotCharacteristics1,(UINT8 *) &ForType9InputData->SlotCharacteristics,2);
  91. OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
  92. UnicodeStrToAsciiStrS (SlotDesignation, OptionalStrStart, SlotDesignationStrLen + 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. }