TianoCore EDK2 master
Loading...
Searching...
No Matches
TokenMapper.c
Go to the documentation of this file.
1
14#include <Library/DebugLib.h>
17
18#include "TokenMapper.h"
19
34EFIAPI
37 IN CM_OBJECT_TOKEN Token,
38 IN CM_OBJECT_ID ObjectId,
39 IN UINT32 Size,
40 IN VOID *Data
41 )
42{
43 TOKEN_MAP_DESCRIPTOR *TokenMapDesc;
44 CM_OBJ_DESCRIPTOR *CmObjDesc;
45
46 if ((TokenMapper == NULL) ||
48 (Size == 0) ||
49 (Data == NULL))
50 {
51 ASSERT (0);
52 return EFI_INVALID_PARAMETER;
53 }
54
56 ASSERT (0);
57 return EFI_BUFFER_TOO_SMALL;
58 }
59
61 TokenMapDesc->Token = Token;
62 CmObjDesc = &TokenMapDesc->CmObjDesc;
63 CmObjDesc->ObjectId = ObjectId;
64 CmObjDesc->Size = Size;
65
66 // Point inside the finalized array.
67 CmObjDesc->Data = Data;
68
69 // Only EArchCommonObjCmRef CmObj can be added as
70 // arrays (more than 1 elements).
71 if ((GET_CM_NAMESPACE_ID (ObjectId) == EObjNameSpaceArchCommon) &&
73 {
74 CmObjDesc->Count = Size / sizeof (CM_ARCH_COMMON_OBJ_REF);
75 } else {
76 CmObjDesc->Count = 1;
77 }
78
79 return EFI_SUCCESS;
80}
81
96EFIAPI
99 IN CM_OBJECT_TOKEN Token,
100 IN CM_OBJECT_ID ObjectId,
101 OUT CM_OBJ_DESCRIPTOR *CmObjDesc
102 )
103{
104 UINTN Index;
105 UINTN MaxCount;
106 TOKEN_MAP_DESCRIPTOR *TokenMapDesc;
107
108 // Nothing to do.
109 if ((TokenMapper != NULL) && (TokenMapper->MaxTokenDescCount == 0)) {
110 goto exit_handler;
111 }
112
113 if ((Token == CM_NULL_TOKEN) ||
114 (CmObjDesc == NULL) ||
115 (TokenMapper == NULL) ||
117 {
118 ASSERT (0);
119 return EFI_INVALID_PARAMETER;
120 }
121
122 TokenMapDesc = TokenMapper->TokenDescArray;
123 MaxCount = TokenMapper->MaxTokenDescCount;
124 for (Index = 0; Index < MaxCount; Index++) {
125 if ((TokenMapDesc->CmObjDesc.ObjectId == ObjectId) &&
126 (TokenMapDesc->Token == Token))
127 {
128 CopyMem (
129 CmObjDesc,
130 &TokenMapDesc->CmObjDesc,
131 sizeof (CM_OBJ_DESCRIPTOR)
132 );
133 return EFI_SUCCESS;
134 }
135
136 TokenMapDesc++;
137 } // for
138
139exit_handler:
140 DEBUG ((
141 DEBUG_INFO,
142 "INFO: Requested CmObj of type 0x%x with token 0x%x"
143 " not found in the dynamic repository\n.",
144 ObjectId,
145 Token
146 ));
147 return EFI_NOT_FOUND;
148}
149
160EFIAPI
163 IN UINTN DescriptorCount
164 )
165{
166 if (TokenMapper == NULL) {
167 ASSERT (0);
168 return EFI_INVALID_PARAMETER;
169 }
170
171 // Nothing to do.
172 if (DescriptorCount == 0) {
173 return EFI_SUCCESS;
174 }
175
177 DEBUG ((DEBUG_ERROR, "ERROR: Token mapper already initialised\n."));
178 ASSERT (0);
179 return EFI_ALREADY_STARTED;
180 }
181
183 AllocateZeroPool (sizeof (TOKEN_MAP_DESCRIPTOR) * DescriptorCount);
185 ASSERT (0);
186 return EFI_OUT_OF_RESOURCES;
187 }
188
189 TokenMapper->MaxTokenDescCount = DescriptorCount;
191
192 return EFI_SUCCESS;
193}
194
203EFIAPI
206 )
207{
208 // Nothing to do.
209 if ((TokenMapper != NULL) && (TokenMapper->MaxTokenDescCount == 0)) {
210 return EFI_SUCCESS;
211 }
212
213 if ((TokenMapper == NULL) ||
215 {
216 ASSERT (0);
217 return EFI_INVALID_PARAMETER;
218 }
219
223
224 return EFI_SUCCESS;
225}
UINT64 UINTN
struct CmArchCommonObjRef CM_ARCH_COMMON_OBJ_REF
@ EArchCommonObjCmRef
7 - CM Object Reference
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define GET_CM_NAMESPACE_ID(CmObjectId)
#define GET_CM_OBJECT_ID(CmObjectId)
@ EObjNameSpaceArchCommon
Arch Common Objects Namespace.
UINT32 CM_OBJECT_ID
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINTN CM_OBJECT_TOKEN
#define CM_NULL_TOKEN
EFI_STATUS EFIAPI TokenMapperInitialise(IN TOKEN_MAPPER *TokenMapper, IN UINTN DescriptorCount)
Definition: TokenMapper.c:161
EFI_STATUS EFIAPI TokenMapperGetObject(IN TOKEN_MAPPER *TokenMapper, IN CM_OBJECT_TOKEN Token, IN CM_OBJECT_ID ObjectId, OUT CM_OBJ_DESCRIPTOR *CmObjDesc)
Definition: TokenMapper.c:97
EFI_STATUS EFIAPI TokenMapperShutdown(IN TOKEN_MAPPER *TokenMapper)
Definition: TokenMapper.c:204
EFI_STATUS EFIAPI TokenMapperAddObject(IN TOKEN_MAPPER *TokenMapper, IN CM_OBJECT_TOKEN Token, IN CM_OBJECT_ID ObjectId, IN UINT32 Size, IN VOID *Data)
Definition: TokenMapper.c:35
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
VOID * Data
Pointer to the described Object or Object List.
UINT32 Size
Size of the described Object or Object List.
UINT32 Count
Count of objects in the list.
CM_OBJECT_ID ObjectId
Object Id.
CM_OBJECT_TOKEN Token
Object Token.
Definition: TokenMapper.h:24
CM_OBJ_DESCRIPTOR CmObjDesc
Definition: TokenMapper.h:29
UINTN MaxTokenDescCount
Maximum number of TOKEN_MAP_DESCRIPTOR entries in TokenDescArray.
Definition: TokenMapper.h:38
TOKEN_MAP_DESCRIPTOR * TokenDescArray
Array of TOKEN_MAP_DESCRIPTOR.
Definition: TokenMapper.h:44
UINTN ItemCount
Next TOKEN_MAP_DESCRIPTOR entry to use in TokenDescArray.
Definition: TokenMapper.h:41