VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibStandaloneMm.c

Last change on this file was 108794, checked in by vboxsync, 4 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

  • Property svn:eol-style set to native
File size: 5.4 KB
Line 
1/** @file
2
3 Implementation functions and structures for var check services.
4 This file provides functions and structures to register and handle variable checks
5 in the Standalone MM environment, specifically for HII variables.
6
7Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
8SPDX-License-Identifier: BSD-2-Clause-Patent
9
10**/
11
12#include <Uefi.h>
13#include <Library/DebugLib.h>
14#include <Library/MemoryAllocationLib.h>
15#include <Library/MmServicesTableLib.h>
16#include <Protocol/MmCommunication.h>
17#include <Library/VarCheckLib.h>
18
19#include "VarCheckHii.h"
20#include "VarCheckHiiLibCommon.h"
21
22//
23// In the standalone setup, mVarCheckHiiBin is used for sending, while mVarCheckHiiBinMmReceived is used for receiving,
24// while in the traditional setup, mVarCheckHiiBin is used for both sending and receiving.
25//
26VAR_CHECK_HII_VARIABLE_HEADER *mMmReceivedVarCheckHiiBin = NULL;
27UINTN mMmReceivedVarCheckHiiBinSize = 0;
28EFI_GUID gVarCheckReceivedHiiBinHandlerGuid = VAR_CHECK_RECEIVED_HII_BIN_HANDLER_GUID;
29
30/**
31 Registers a handler for HII variable checks in MM environment.
32 This function is intended to be called to register a handler for checking variables
33 in the Standalone MM environment. It allocates memory for the variable
34 check data and copies the data from the communication buffer.
35
36 @param[in] DispatchHandle The handle of the dispatch function.
37 @param[in] Context Optional context for the handler, not used in this implementation.
38 @param CommBuffer The buffer of data being passed in.
39 @param CommBufferSize The size of the data being passed in.
40 @retval EFI_SUCCESS Registration and memory allocation were successful.
41 @retval EFI_INVALID_PARAMETER The CommBuffer or CommBufferSize is NULL.
42 @retval EFI_ACCESS_DENIED The buffer size is invalid or the buffer is in an invalid location.
43 @retval EFI_OUT_OF_RESOURCES Memory allocation for the variable check data failed.
44
45**/
46EFI_STATUS
47EFIAPI
48VarCheckHiiLibReceiveHiiBinHandler (
49 IN EFI_HANDLE DispatchHandle,
50 IN CONST VOID *Context OPTIONAL,
51 IN OUT VOID *CommBuffer OPTIONAL,
52 IN OUT UINTN *CommBufferSize OPTIONAL
53 )
54{
55 EFI_STATUS Status;
56
57 //
58 // If input is invalid, stop processing this SMI
59 //
60 if ((CommBuffer == NULL) || (CommBufferSize == NULL)) {
61 return EFI_SUCCESS;
62 }
63
64 mMmReceivedVarCheckHiiBinSize = *CommBufferSize;
65
66 if (mMmReceivedVarCheckHiiBinSize < sizeof (VAR_CHECK_HII_VARIABLE_HEADER)) {
67 DEBUG ((DEBUG_ERROR, "%a: MM Communication buffer size is invalid for this handler!\n", __func__));
68 return EFI_ACCESS_DENIED;
69 }
70
71 mMmReceivedVarCheckHiiBin = AllocateZeroPool (mMmReceivedVarCheckHiiBinSize);
72 if (mMmReceivedVarCheckHiiBin == NULL) {
73 DEBUG ((DEBUG_ERROR, "%a: Failed to allocate memory for mVarCheckHiiBinMm\n", __func__));
74 return EFI_OUT_OF_RESOURCES;
75 }
76
77 CopyMem (mMmReceivedVarCheckHiiBin, CommBuffer, mMmReceivedVarCheckHiiBinSize);
78 if (DispatchHandle != NULL) {
79 Status = gMmst->MmiHandlerUnRegister (DispatchHandle);
80 }
81
82 if (EFI_ERROR (Status)) {
83 DEBUG ((DEBUG_ERROR, "%a: Failed to unregister handler - %r!\n", __func__, Status));
84 } else {
85 DEBUG ((DEBUG_INFO, "%a: Handler unregistered successfully.\n", __func__));
86 }
87
88 return EFI_SUCCESS;
89}
90
91/**
92
93 Sets the variable check handler for HII.
94 This function registers a handler that will be invoked for variable checks
95 in the HII environment. It allows for custom validation logic to be implemented
96 for setting HII variables.
97 @param[in] VariableName Name of Variable to set.
98 @param[in] VendorGuid Variable vendor GUID.
99 @param[in] Attributes Attribute value of the variable.
100 @param[in] DataSize Size of Data to set.
101 @param[in] Data Data pointer.
102
103**/
104EFI_STATUS
105EFIAPI
106SetVariableCheckHandlerHii (
107 IN CHAR16 *VariableName,
108 IN EFI_GUID *VendorGuid,
109 IN UINT32 Attributes,
110 IN UINTN DataSize,
111 IN VOID *Data
112 )
113{
114 return CheckHiiVariableCommon (mMmReceivedVarCheckHiiBin, mMmReceivedVarCheckHiiBinSize, VariableName, VendorGuid, Attributes, DataSize, Data);
115}
116
117/**
118 Constructor function for variable check library in Standalone MM.
119 This function registers a handler for variable checks and sets up the environment
120 for variable checking in the Standalone MM environment.
121 @param[in] ImageHandle The firmware allocated handle for the EFI image.
122 @param[in] SystemTable A pointer to the EFI system table.
123 @retval EFI_SUCCESS The constructor executed successfully.
124 @retval Others An error occurred during execution.
125
126**/
127EFI_STATUS
128EFIAPI
129VarCheckHiiLibConstructorStandaloneMm (
130 IN EFI_HANDLE ImageHandle,
131 IN EFI_MM_SYSTEM_TABLE *SystemTable
132 )
133{
134 EFI_STATUS Status;
135 EFI_HANDLE DispatchHandle;
136
137 DEBUG ((DEBUG_INFO, "%a: starts.\n", __func__));
138 //
139 // Register a handler to recieve the HII variable checking data.
140 //
141 Status = gMmst->MmiHandlerRegister (VarCheckHiiLibReceiveHiiBinHandler, &gVarCheckReceivedHiiBinHandlerGuid, &DispatchHandle);
142 if (EFI_ERROR (Status)) {
143 DEBUG ((DEBUG_ERROR, "%a: Failed to register handler - %r!\n", __func__, Status));
144
145 return Status;
146 }
147
148 VarCheckLibRegisterAddressPointer ((VOID **)&mMmReceivedVarCheckHiiBin);
149 VarCheckLibRegisterSetVariableCheckHandler (SetVariableCheckHandlerHii);
150 DEBUG ((DEBUG_INFO, "%a: ends.\n", __func__));
151 return EFI_SUCCESS;
152}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette