]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxeHstiLib/HstiAip.c
MdePkg: Replace BSD License with BSD+Patent License
[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 if (!CompareGuid (InformationType, &gAdapterInfoPlatformSecurityGuid)) {
47 return EFI_UNSUPPORTED;
48 }
49
50 HstiAip = HSTI_AIP_PRIVATE_DATA_FROM_THIS(This);
51
52 *InformationBlock = AllocateCopyPool (HstiAip->HstiSize, HstiAip->Hsti);
53 if (*InformationBlock == NULL) {
54 return EFI_OUT_OF_RESOURCES;
55 }
56 *InformationBlockSize = HstiAip->HstiSize;
57 return EFI_SUCCESS;
58 }
59
60 /**
61 Sets state information for an adapter.
62
63 This function sends information of type InformationType for an adapter.
64 If an adapter does not support the requested information type, then EFI_UNSUPPORTED
65 is returned.
66
67 @param[in] This A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance.
68 @param[in] InformationType A pointer to an EFI_GUID that defines the contents of InformationBlock.
69 @param[in] InformationBlock A pointer to the InformationBlock structure which contains details
70 about the data specific to InformationType.
71 @param[in] InformationBlockSize The size of the InformationBlock in bytes.
72
73 @retval EFI_SUCCESS The information was received and interpreted successfully.
74 @retval EFI_UNSUPPORTED The InformationType is not known.
75 @retval EFI_DEVICE_ERROR The device reported an error.
76 @retval EFI_INVALID_PARAMETER This is NULL.
77 @retval EFI_INVALID_PARAMETER InformationBlock is NULL.
78 @retval EFI_WRITE_PROTECTED The InformationType cannot be modified using EFI_ADAPTER_INFO_SET_INFO().
79
80 **/
81 EFI_STATUS
82 EFIAPI
83 HstiAipSetInfo (
84 IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,
85 IN EFI_GUID *InformationType,
86 IN VOID *InformationBlock,
87 IN UINTN InformationBlockSize
88 )
89 {
90 HSTI_AIP_PRIVATE_DATA *HstiAip;
91 VOID *NewHsti;
92
93 if ((This == NULL) || (InformationBlock == NULL)) {
94 return EFI_INVALID_PARAMETER;
95 }
96 if (!CompareGuid (InformationType, &gAdapterInfoPlatformSecurityGuid)) {
97 return EFI_UNSUPPORTED;
98 }
99
100 if (!InternalHstiIsValidTable (InformationBlock, InformationBlockSize)) {
101 return EFI_VOLUME_CORRUPTED;
102 }
103
104 HstiAip = HSTI_AIP_PRIVATE_DATA_FROM_THIS(This);
105
106 if (InformationBlockSize > HstiAip->HstiMaxSize) {
107 NewHsti = AllocateZeroPool (InformationBlockSize);
108 if (NewHsti == NULL) {
109 return EFI_OUT_OF_RESOURCES;
110 }
111 FreePool (HstiAip->Hsti);
112 HstiAip->Hsti = NewHsti;
113 HstiAip->HstiSize = 0;
114 HstiAip->HstiMaxSize = InformationBlockSize;
115 }
116
117 CopyMem (HstiAip->Hsti, InformationBlock, InformationBlockSize);
118 HstiAip->HstiSize = InformationBlockSize;
119 return EFI_SUCCESS;
120 }
121
122 /**
123 Get a list of supported information types for this instance of the protocol.
124
125 This function returns a list of InformationType GUIDs that are supported on an
126 adapter with this instance of EFI_ADAPTER_INFORMATION_PROTOCOL. The list is returned
127 in InfoTypesBuffer, and the number of GUID pointers in InfoTypesBuffer is returned in
128 InfoTypesBufferCount.
129
130 @param[in] This A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance.
131 @param[out] InfoTypesBuffer A pointer to the array of InformationType GUIDs that are supported
132 by This.
133 @param[out] InfoTypesBufferCount A pointer to the number of GUIDs present in InfoTypesBuffer.
134
135 @retval EFI_SUCCESS The list of information type GUIDs that are supported on this adapter was
136 returned in InfoTypesBuffer. The number of information type GUIDs was
137 returned in InfoTypesBufferCount.
138 @retval EFI_INVALID_PARAMETER This is NULL.
139 @retval EFI_INVALID_PARAMETER InfoTypesBuffer is NULL.
140 @retval EFI_INVALID_PARAMETER InfoTypesBufferCount is NULL.
141 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the results.
142
143 **/
144 EFI_STATUS
145 EFIAPI
146 HstiAipGetSupportedTypes (
147 IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,
148 OUT EFI_GUID **InfoTypesBuffer,
149 OUT UINTN *InfoTypesBufferCount
150 )
151 {
152 if ((This == NULL) || (InfoTypesBuffer == NULL) || (InfoTypesBufferCount == NULL)) {
153 return EFI_INVALID_PARAMETER;
154 }
155
156 *InfoTypesBuffer = AllocateCopyPool (sizeof(gAdapterInfoPlatformSecurityGuid), &gAdapterInfoPlatformSecurityGuid);
157 if (*InfoTypesBuffer == NULL) {
158 return EFI_OUT_OF_RESOURCES;
159 }
160 *InfoTypesBufferCount = 1;
161
162 return EFI_SUCCESS;
163 }
164
165 EFI_ADAPTER_INFORMATION_PROTOCOL mAdapterInformationProtocol = {
166 HstiAipGetInfo,
167 HstiAipSetInfo,
168 HstiAipGetSupportedTypes,
169 };