2 Based on files under Nt32Pkg/MiscSubClassPlatformDxe/
4 Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
5 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
6 Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
7 Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Library/BaseLib.h>
13 #include <Library/BaseMemoryLib.h>
14 #include <Library/DebugLib.h>
15 #include <Library/HiiLib.h>
16 #include <Library/MemoryAllocationLib.h>
17 #include <Library/OemMiscLib.h>
18 #include <Library/PrintLib.h>
19 #include <Library/UefiBootServicesTableLib.h>
21 #include "SmbiosMisc.h"
24 Get next language from language code list (with separator ';').
26 @param LangCode Input: point to first language in the list. On
27 Output: point to next language in the list, or
28 NULL if no more language in the list.
29 @param Lang The first language in the list.
35 IN OUT CHAR8
**LangCode
,
42 if (LangCode
== NULL
|| *LangCode
== NULL
|| Lang
== NULL
) {
47 StringPtr
= *LangCode
;
48 while (StringPtr
[Index
] != 0 && StringPtr
[Index
] != ';') {
52 (VOID
)CopyMem (Lang
, StringPtr
, Index
);
55 if (StringPtr
[Index
] == ';') {
58 *LangCode
= StringPtr
+ Index
;
62 This function returns the number of supported languages on HiiHandle.
64 @param HiiHandle The HII package list handle.
66 @retval The number of supported languages.
71 GetSupportedLanguageNumber (
72 IN EFI_HII_HANDLE HiiHandle
77 CHAR8
*LanguageString
;
80 Languages
= HiiGetSupportedLanguages (HiiHandle
);
81 if (Languages
== NULL
) {
86 Lang
= AllocatePool (AsciiStrSize (Languages
));
88 LanguageString
= Languages
;
89 while (*LanguageString
!= 0) {
90 GetNextLanguage (&LanguageString
, Lang
);
101 This function makes boot time changes to the contents of the
102 MiscNumberOfInstallableLanguages (Type 13) record.
104 @param RecordData Pointer to SMBIOS table with default values.
105 @param Smbios SMBIOS protocol.
107 @retval EFI_SUCCESS The SMBIOS table was successfully added.
108 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
109 @retval EFI_OUT_OF_RESOURCES Failed to allocate required memory.
112 SMBIOS_MISC_TABLE_FUNCTION(MiscNumberOfInstallableLanguages
)
115 CHAR8 CurrentLang
[SMBIOS_STRING_MAX_LENGTH
+ 1];
116 CHAR8
*OptionalStrStart
;
118 SMBIOS_TABLE_TYPE13
*SmbiosRecord
;
119 SMBIOS_TABLE_TYPE13
*InputData
;
124 // First check for invalid parameters.
126 if (RecordData
== NULL
) {
127 return EFI_INVALID_PARAMETER
;
130 InputData
= (SMBIOS_TABLE_TYPE13
*)RecordData
;
132 InputData
->InstallableLanguages
= GetSupportedLanguageNumber (mSmbiosMiscHiiHandle
);
135 // Try to check if current langcode matches with the langcodes in installed languages
137 ZeroMem (CurrentLang
, SMBIOS_STRING_MAX_LENGTH
- 1);
138 (VOID
)AsciiStrCpyS (CurrentLang
, SMBIOS_STRING_MAX_LENGTH
- 1, "en|US|iso8859-1");
139 LangStrLen
= AsciiStrLen (CurrentLang
);
142 // Two zeros following the last string.
144 SmbiosRecord
= AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE13
) + LangStrLen
+ 1 + 1);
145 if (SmbiosRecord
== NULL
) {
146 return EFI_OUT_OF_RESOURCES
;
149 (VOID
)CopyMem (SmbiosRecord
, InputData
, sizeof (SMBIOS_TABLE_TYPE13
));
151 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE13
);
153 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
154 (VOID
)AsciiStrCpyS (OptionalStrStart
, SMBIOS_STRING_MAX_LENGTH
- 1, CurrentLang
);
156 // Now we have got the full smbios record, call smbios protocol to add this record.
158 Status
= SmbiosMiscAddRecord ((UINT8
*)SmbiosRecord
, NULL
);
159 if (EFI_ERROR (Status
)) {
160 DEBUG ((DEBUG_ERROR
, "[%a]:[%dL] Smbios Type13 Table Log Failed! %r \n",
161 __FUNCTION__
, __LINE__
, Status
));
164 FreePool (SmbiosRecord
);