46 case TRNG_STATUS_NOT_SUPPORTED:
49 case TRNG_STATUS_INVALID_PARAMETER:
52 case TRNG_STATUS_NO_ENTROPY:
55 case TRNG_STATUS_SUCCESS:
83 OUT UINT16 *MajorRevision,
84 OUT UINT16 *MinorRevision
91 if ((MajorRevision ==
NULL) || (MinorRevision ==
NULL)) {
95 ZeroMem (&Parameters,
sizeof (Parameters));
97 Parameters.Arg0 = ARM_SMC_ID_TRNG_VERSION;
100 Revision = (INT32)Parameters.Arg0;
106 *MinorRevision = (Revision & TRNG_REV_MINOR_MASK);
107 *MajorRevision = ((Revision >> TRNG_REV_MAJOR_SHIFT) & TRNG_REV_MAJOR_MASK);
128 OUT UINT32 *Capability OPTIONAL
132 RETURN_STATUS Status;
134 ZeroMem (&Parameters,
sizeof (Parameters));
136 Parameters.Arg0 = ARM_SMC_ID_TRNG_FEATURES;
137 Parameters.Arg1 = FunctionId;
145 if (Capability !=
NULL) {
146 *Capability = (UINT32)Parameters.Arg0;
180 ZeroMem (&Parameters,
sizeof (Parameters));
182 Parameters.Arg0 = ARM_SMC_ID_TRNG_GET_UUID;
186 if ((INT32)Parameters.Arg0 == TRNG_STATUS_NOT_SUPPORTED) {
190 Guid->Data1 = (Parameters.Arg0 & MAX_UINT32);
191 Guid->Data2 = (Parameters.Arg1 & MAX_UINT16);
192 Guid->Data3 = ((Parameters.Arg1 >> 16) & MAX_UINT16);
194 Guid->Data4[0] = (Parameters.Arg2 & MAX_UINT8);
195 Guid->Data4[1] = ((Parameters.Arg2 >> 8) & MAX_UINT8);
196 Guid->Data4[2] = ((Parameters.Arg2 >> 16) & MAX_UINT8);
197 Guid->Data4[3] = ((Parameters.Arg2 >> 24) & MAX_UINT8);
199 Guid->Data4[4] = (Parameters.Arg3 & MAX_UINT8);
200 Guid->Data4[5] = ((Parameters.Arg3 >> 8) & MAX_UINT8);
201 Guid->Data4[6] = ((Parameters.Arg3 >> 16) & MAX_UINT8);
202 Guid->Data4[7] = ((Parameters.Arg3 >> 24) & MAX_UINT8);
204 DEBUG ((DEBUG_INFO,
"FW-TRNG: UUID %g\n", Guid));
221 return MAX_ENTROPY_BITS;
253 RETURN_STATUS Status;
258 UINTN EntropyData[3];
260 if ((EntropyBits == 0) ||
261 (EntropyBits > MAX_ENTROPY_BITS) ||
267 EntropyBytes = (EntropyBits + 7) >> 3;
268 if (EntropyBytes > BufferSize) {
273 ZeroMem (&Parameters,
sizeof (Parameters));
275 Parameters.Arg0 = ARM_SMC_ID_TRNG_RND;
276 Parameters.Arg1 = EntropyBits;
287 EntropyData[0] = Parameters.Arg3;
288 EntropyData[1] = Parameters.Arg2;
289 EntropyData[2] = Parameters.Arg1;
291 CopyMem (Buffer, EntropyData, EntropyBytes);
294 BytesToClear = BufferSize - EntropyBytes;
295 if (BytesToClear != 0) {
296 ZeroMem (&Buffer[EntropyBytes], BytesToClear);
300 LastValidBits = EntropyBits & 0x7;
301 if (LastValidBits != 0) {
302 Buffer[EntropyBytes - 1] &= (0xFF >> (8 - LastValidBits));
323 RETURN_STATUS Status;
328 ZeroMem (&Parameters,
sizeof (Parameters));
330 Parameters.Arg0 = SMCCC_VERSION;
339 if ((INT32)Parameters.Arg0 < 0x10001) {
369 "FW-TRNG: Version %d.%d, GUID {%g}\n",
380 DEBUG ((DEBUG_ERROR,
"ArmTrngLib could not be correctly initialized.\n"));
VOID EFIAPI ArmMonitorCall(IN OUT ARM_MONITOR_ARGS *Args)
STATIC RETURN_STATUS TrngStatusToReturnStatus(IN INT32 TrngStatus)
RETURN_STATUS EFIAPI GetArmTrngVersion(OUT UINT16 *MajorRevision, OUT UINT16 *MinorRevision)
RETURN_STATUS EFIAPI GetArmTrngUuid(OUT GUID *Guid)
RETURN_STATUS EFIAPI ArmTrngLibConstructor(VOID)
RETURN_STATUS EFIAPI GetArmTrngEntropy(IN UINTN EntropyBits, IN UINTN BufferSize, OUT UINT8 *Buffer)
STATIC RETURN_STATUS EFIAPI GetArmTrngFeatures(IN CONST UINT32 FunctionId, OUT UINT32 *Capability OPTIONAL)
UINTN EFIAPI GetArmTrngMaxSupportedEntropyBits(VOID)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define RETURN_ERROR(StatusCode)
#define RETURN_UNSUPPORTED
#define RETURN_INVALID_PARAMETER
#define RETURN_BAD_BUFFER_SIZE
#define DEBUG_CODE_BEGIN()
#define DEBUG(Expression)