]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxeHstiLib/HstiAip.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / DxeHstiLib / HstiAip.c
1 /** @file
2
3 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
5
6 **/
7
8 #include "HstiDxe.h"
9
10 /**
11 Returns the current state information for the adapter.
12
13 This function returns information of type InformationType from the adapter.
14 If an adapter does not support the requested informational type, then
15 EFI_UNSUPPORTED is returned.
16
17 @param[in] This A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance.
18 @param[in] InformationType A pointer to an EFI_GUID that defines the contents of InformationBlock.
19 @param[out] InformationBlock The service returns a pointer to the buffer with the InformationBlock
20 structure which contains details about the data specific to InformationType.
21 @param[out] InformationBlockSize The driver returns the size of the InformationBlock in bytes.
22
23 @retval EFI_SUCCESS The InformationType information was retrieved.
24 @retval EFI_UNSUPPORTED The InformationType is not known.
25 @retval EFI_DEVICE_ERROR The device reported an error.
26 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
27 @retval EFI_INVALID_PARAMETER This is NULL.
28 @retval EFI_INVALID_PARAMETER InformationBlock is NULL.
29 @retval EFI_INVALID_PARAMETER InformationBlockSize is NULL.
30
31 **/
32 EFI_STATUS
33 EFIAPI
34 HstiAipGetInfo (
35 IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,
36 IN EFI_GUID *InformationType,
37 OUT VOID **InformationBlock,
38 OUT UINTN *InformationBlockSize
39 )
40 {
41 HSTI_AIP_PRIVATE_DATA *HstiAip;
42
43 if ((This == NULL) || (InformationBlock == NULL) || (InformationBlockSize == NULL)) {
44 return EFI_INVALID_PARAMETER;
45 }
46
47 if (!CompareGuid (InformationType, &gAdapterInfoPlatformSecurityGuid)) {
48 return EFI_UNSUPPORTED;
49 }
50
51 HstiAip = HSTI_AIP_PRIVATE_DATA_FROM_THIS (This);
52
53 *InformationBlock = AllocateCopyPool (HstiAip->HstiSize, HstiAip->Hsti);
54 if (*InformationBlock == NULL) {
55 return EFI_OUT_OF_RESOURCES;
56 }
57
58 *InformationBlockSize = HstiAip->HstiSize;
59 return EFI_SUCCESS;
60 }
61
62 /**
63 Sets state information for an adapter.
64
65 This function sends information of type InformationType for an adapter.
66 If an adapter does not support the requested information type, then EFI_UNSUPPORTED
67 is returned.
68
69 @param[in] This A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance.
70 @param[in] InformationType A pointer to an EFI_GUID that defines the contents of InformationBlock.
71 @param[in] InformationBlock A pointer to the InformationBlock structure which contains details
72 about the data specific to InformationType.
73 @param[in] InformationBlockSize The size of the InformationBlock in bytes.
74
75 @retval EFI_SUCCESS The information was received and interpreted successfully.
76 @retval EFI_UNSUPPORTED The InformationType is not known.
77 @retval EFI_DEVICE_ERROR The device reported an error.
78 @retval EFI_INVALID_PARAMETER This is NULL.
79 @retval EFI_INVALID_PARAMETER InformationBlock is NULL.
80 @retval EFI_WRITE_PROTECTED The InformationType cannot be modified using EFI_ADAPTER_INFO_SET_INFO().
81
82 **/
83 EFI_STATUS
84 EFIAPI
85 HstiAipSetInfo (
86 IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,
87 IN EFI_GUID *InformationType,
88 IN VOID *InformationBlock,
89 IN UINTN InformationBlockSize
90 )
91 {
92 HSTI_AIP_PRIVATE_DATA *HstiAip;
93 VOID *NewHsti;
94
95 if ((This == NULL) || (InformationBlock == NULL)) {
96 return EFI_INVALID_PARAMETER;
97 }
98
99 if (!CompareGuid (InformationType, &gAdapterInfoPlatformSecurityGuid)) {
100 return EFI_UNSUPPORTED;
101 }
102
103 if (!InternalHstiIsValidTable (InformationBlock, InformationBlockSize)) {
104 return EFI_VOLUME_CORRUPTED;
105 }
106
107 HstiAip = HSTI_AIP_PRIVATE_DATA_FROM_THIS (This);
108
109 if (InformationBlockSize > HstiAip->HstiMaxSize) {
110 NewHsti = AllocateZeroPool (InformationBlockSize);
111 if (NewHsti == NULL) {
112 return EFI_OUT_OF_RESOURCES;
113 }
114
115 FreePool (HstiAip->Hsti);
116 HstiAip->Hsti = NewHsti;
117 HstiAip->HstiSize = 0;
118 HstiAip->HstiMaxSize = InformationBlockSize;
119 }
120
121 CopyMem (HstiAip->Hsti, InformationBlock, InformationBlockSize);
122 HstiAip->HstiSize = InformationBlockSize;
123 return EFI_SUCCESS;
124 }
125
126 /**
127 Get a list of supported information types for this instance of the protocol.
128
129 This function returns a list of InformationType GUIDs that are supported on an
130 adapter with this instance of EFI_ADAPTER_INFORMATION_PROTOCOL. The list is returned
131 in InfoTypesBuffer, and the number of GUID pointers in InfoTypesBuffer is returned in
132 InfoTypesBufferCount.
133
134 @param[in] This A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance.
135 @param[out] InfoTypesBuffer A pointer to the array of InformationType GUIDs that are supported
136 by This.
137 @param[out] InfoTypesBufferCount A pointer to the number of GUIDs present in InfoTypesBuffer.
138
139 @retval EFI_SUCCESS The list of information type GUIDs that are supported on this adapter was
140 returned in InfoTypesBuffer. The number of information type GUIDs was
141 returned in InfoTypesBufferCount.
142 @retval EFI_INVALID_PARAMETER This is NULL.
143 @retval EFI_INVALID_PARAMETER InfoTypesBuffer is NULL.
144 @retval EFI_INVALID_PARAMETER InfoTypesBufferCount is NULL.
145 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the results.
146
147 **/
148 EFI_STATUS
149 EFIAPI
150 HstiAipGetSupportedTypes (
151 IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,
152 OUT EFI_GUID **InfoTypesBuffer,
153 OUT UINTN *InfoTypesBufferCount
154 )
155 {
156 if ((This == NULL) || (InfoTypesBuffer == NULL) || (InfoTypesBufferCount == NULL)) {
157 return EFI_INVALID_PARAMETER;
158 }
159
160 *InfoTypesBuffer = AllocateCopyPool (sizeof (gAdapterInfoPlatformSecurityGuid), &gAdapterInfoPlatformSecurityGuid);
161 if (*InfoTypesBuffer == NULL) {
162 return EFI_OUT_OF_RESOURCES;
163 }
164
165 *InfoTypesBufferCount = 1;
166
167 return EFI_SUCCESS;
168 }
169
170 EFI_ADAPTER_INFORMATION_PROTOCOL mAdapterInformationProtocol = {
171 HstiAipGetInfo,
172 HstiAipSetInfo,
173 HstiAipGetSupportedTypes,
174 };