MiscSystemOptionStringFunction.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*++
  2. Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. MiscSystemOptionStringFunction.c
  6. Abstract:
  7. BIOS system option string boot time changes.
  8. SMBIOS type 12.
  9. --*/
  10. #include "CommonHeader.h"
  11. #include "MiscSubclassDriver.h"
  12. /**
  13. This function makes boot time changes to the contents of the
  14. MiscSystemOptionString (Type 12).
  15. @param RecordData Pointer to copy of RecordData from the Data Table.
  16. @retval EFI_SUCCESS All parameters were valid.
  17. @retval EFI_UNSUPPORTED Unexpected RecordType value.
  18. @retval EFI_INVALID_PARAMETER Invalid parameter was found.
  19. **/
  20. MISC_SMBIOS_TABLE_FUNCTION(SystemOptionString)
  21. {
  22. CHAR8 *OptionalStrStart;
  23. UINTN OptStrLen;
  24. EFI_STRING OptionString;
  25. EFI_STATUS Status;
  26. STRING_REF TokenToGet;
  27. EFI_SMBIOS_HANDLE SmbiosHandle;
  28. SMBIOS_TABLE_TYPE12 *SmbiosRecord;
  29. //
  30. // First check for invalid parameters.
  31. //
  32. if (RecordData == NULL) {
  33. return EFI_INVALID_PARAMETER;
  34. }
  35. TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_OPTION_EN_US);
  36. OptionString = SmbiosMiscGetString (TokenToGet);
  37. OptStrLen = StrLen(OptionString);
  38. if (OptStrLen > SMBIOS_STRING_MAX_LENGTH) {
  39. return EFI_UNSUPPORTED;
  40. }
  41. //
  42. // Two zeros following the last string.
  43. //
  44. SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE12) + OptStrLen + 1 + 1);
  45. ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE12) + OptStrLen + 1 + 1);
  46. SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_CONFIGURATION_OPTIONS;
  47. SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE12);
  48. //
  49. // Make handle chosen by smbios protocol.add automatically.
  50. //
  51. SmbiosRecord->Hdr.Handle = 0;
  52. SmbiosRecord->StringCount = 1;
  53. OptionalStrStart = (CHAR8*) (SmbiosRecord + 1);
  54. UnicodeStrToAsciiStrS (OptionString, OptionalStrStart, OptStrLen + 1 + 1);
  55. //
  56. // Now we have got the full smbios record, call smbios protocol to add this record.
  57. //
  58. SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  59. Status = Smbios-> Add(
  60. Smbios,
  61. NULL,
  62. &SmbiosHandle,
  63. (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
  64. );
  65. FreePool(SmbiosRecord);
  66. return Status;
  67. }