microsoft/mu_feature_ffa

Public

mirrored fromhttps://github.com/microsoft/mu_feature_ffaAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
test_delay

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

FfaFeaturePkg/Applications/FfaPartitionTest/FfaPartitionTestApp.c

1745lines · modecode

1/** @file
2FfaPartitionTestApp.c
3
4This is a Unit Test for the test FFA service library.
5
6Copyright (C) Microsoft Corporation. All rights reserved.
7SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#include <Uefi.h>
12#include <IndustryStandard/ArmFfaSvc.h>
13#include <IndustryStandard/ArmFfaBootInfo.h>
14#include <IndustryStandard/ArmFfaPartInfo.h>
15#include <Pi/PiMultiPhase.h>
16#include <Protocol/HardwareInterrupt.h>
17#include <Protocol/MmCommunication2.h>
18#include <Guid/NotificationServiceFfa.h>
19#include <Guid/TestServiceFfa.h>
20#include <Guid/Tpm2ServiceFfa.h>
21#include <Guid/ZeroGuid.h>
22
23#include <Library/ArmSmcLib.h>
24#include <Library/ArmSvcLib.h>
25#include <Library/ArmLib.h>
26#include <Library/ArmFfaLib.h>
27#include <Library/ArmFfaLibEx.h>
28#include <Library/BaseLib.h>
29#include <Library/BaseMemoryLib.h>
30#include <Library/DebugLib.h>
31#include <Library/MemoryAllocationLib.h>
32#include <Library/PrintLib.h>
33#include <Library/TimerLib.h>
34#include <Library/UefiLib.h>
35#include <Library/UefiBootServicesTableLib.h>
36#include <Library/UnitTestLib.h>
37
38#define UNIT_TEST_APP_NAME "FF-A Functional Test"
39#define UNIT_TEST_APP_VERSION "0.1"
40
41typedef struct {
42 BOOLEAN IsMmCommunicationServiceAvailable;
43 BOOLEAN IsTestServiceAvailable;
44 BOOLEAN IsTpm2ServiceAvailable;
45 BOOLEAN IsNotificationServiceAvailable;
46 UINT16 FfaMmCommunicationPartId;
47 UINT16 FfaTestServicePartId;
48 UINT16 FfaTpm2ServicePartId;
49 UINT16 FfaNotificationServicePartId;
50 UINTN SriIndex;
51} FFA_TEST_CONTEXT;
52
53UINT16 FfaPartId;
54EFI_HARDWARE_INTERRUPT_PROTOCOL *gInterrupt;
55BOOLEAN mIsInterruptFired;
56
57/// ================================================================================================
58/// ================================================================================================
59///
60/// HELPER FUNCTIONS
61///
62/// ================================================================================================
63/// ================================================================================================
64
65/**
66 EFI_CPU_INTERRUPT_HANDLER that is called when a processor interrupt occurs.
67
68 @param InterruptType Defines the type of interrupt or exception that
69 occurred on the processor. This parameter is
70 processor architecture specific.
71 @param SystemContext A pointer to the processor context when
72 the interrupt occurred on the processor.
73
74 @return None
75
76**/
77VOID
78EFIAPI
79ApIrqInterruptHandler (
80 IN HARDWARE_INTERRUPT_SOURCE Source,
81 IN EFI_SYSTEM_CONTEXT SystemContext
82 )
83{
84 EFI_STATUS Status;
85 UINT64 Bitmap;
86
87 DEBUG ((DEBUG_INFO, "Received IRQ interrupt %d!\n", Source));
88
89 // Then register this test app to receive notifications from the Ffa test SP
90 Status = FfaNotificationGet (0, ARM_FFA_NOTIFICATION_FLAG_BITMAP_SP, &Bitmap);
91 if (EFI_ERROR (Status)) {
92 DEBUG ((DEBUG_ERROR, "Unable to notification get with FF-A Ffa test SP (%r).\n", Status));
93 } else {
94 DEBUG ((DEBUG_INFO, "Got notification from FF-A Ffa test SP with VM bitmap %x.\n", Bitmap));
95 }
96
97 mIsInterruptFired = TRUE;
98
99 gInterrupt->EndOfInterrupt (gInterrupt, Source);
100}
101
102/**
103 Helper prerequisite function to proceed with Inter-partition communication tests.
104
105 @retval UNIT_TEST_PASSED Unit test case prerequisites
106 are met.
107 @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be skipped.
108**/
109UNIT_TEST_STATUS
110EFIAPI
111CheckNotificationService (
112 IN UNIT_TEST_CONTEXT Context
113 )
114{
115 UNIT_TEST_STATUS utStatus = UNIT_TEST_RUNNING;
116 FFA_TEST_CONTEXT *FfaTestContext;
117
118 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
119 if (FfaTestContext == NULL) {
120 DEBUG ((DEBUG_ERROR, "%a: FfaTestContext is NULL.\n", __func__));
121 UT_ASSERT_NOT_NULL (FfaTestContext);
122 }
123
124 if (!FfaTestContext->IsNotificationServiceAvailable) {
125 DEBUG ((DEBUG_INFO, "%a: Notification Service not available, skipping test.\n", __func__));
126 utStatus = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
127 } else {
128 utStatus = UNIT_TEST_PASSED;
129 }
130
131 return utStatus;
132}
133
134/**
135 Helper prerequisite function to proceed with Test service related cases.
136
137 @retval UNIT_TEST_PASSED Unit test case prerequisites
138 are met.
139 @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be skipped.
140**/
141UNIT_TEST_STATUS
142EFIAPI
143CheckTestService (
144 IN UNIT_TEST_CONTEXT Context
145 )
146{
147 UNIT_TEST_STATUS utStatus = UNIT_TEST_RUNNING;
148 FFA_TEST_CONTEXT *FfaTestContext;
149
150 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
151 if (FfaTestContext == NULL) {
152 DEBUG ((DEBUG_ERROR, "%a: FfaTestContext is NULL.\n", __func__));
153 UT_ASSERT_NOT_NULL (FfaTestContext);
154 }
155
156 if (!FfaTestContext->IsTestServiceAvailable) {
157 DEBUG ((DEBUG_INFO, "%a: Test Service not available, skipping test.\n", __func__));
158 utStatus = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
159 } else {
160 utStatus = UNIT_TEST_PASSED;
161 }
162
163 return utStatus;
164}
165
166/**
167 Helper prerequisite function to proceed with TPM service related cases.
168
169 @retval UNIT_TEST_PASSED Unit test case prerequisites
170 are met.
171 @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be skipped.
172**/
173UNIT_TEST_STATUS
174EFIAPI
175CheckTPMService (
176 IN UNIT_TEST_CONTEXT Context
177 )
178{
179 UNIT_TEST_STATUS utStatus = UNIT_TEST_RUNNING;
180 FFA_TEST_CONTEXT *FfaTestContext;
181
182 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
183 if (FfaTestContext == NULL) {
184 DEBUG ((DEBUG_ERROR, "%a: FfaTestContext is NULL.\n", __func__));
185 UT_ASSERT_NOT_NULL (FfaTestContext);
186 }
187
188 if (!FfaTestContext->IsTpm2ServiceAvailable) {
189 DEBUG ((DEBUG_INFO, "%a: TPM2 Service not available, skipping test.\n", __func__));
190 utStatus = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
191 } else {
192 #ifdef TPM2_ENABLE
193 utStatus = UNIT_TEST_PASSED;
194 #else
195 DEBUG ((DEBUG_INFO, "%a: TPM2 Service is not enabled, skipping test.\n", __func__));
196 utStatus = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
197 #endif // TPM2_ENABLE
198 }
199
200 return utStatus;
201}
202
203/// ================================================================================================
204/// ================================================================================================
205///
206/// TEST CASES
207///
208/// ================================================================================================
209/// ================================================================================================
210
211/**
212 This routine queries the version of FF-A framework, it must be at least the version
213 required by this UEFI codebase.
214**/
215UNIT_TEST_STATUS
216EFIAPI
217FfaMiscVerifyVersion (
218 IN UNIT_TEST_CONTEXT Context
219 )
220{
221 UNIT_TEST_STATUS utStatus = UNIT_TEST_RUNNING;
222 EFI_STATUS Status = EFI_SUCCESS;
223 UINT16 CurrentMajorVersion;
224 UINT16 CurrentMinorVersion;
225
226 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
227
228 // Query FF-A version to make sure FF-A is supported
229 Status = ArmFfaLibGetVersion (
230 ARM_FFA_MAJOR_VERSION,
231 ARM_FFA_MINOR_VERSION,
232 &CurrentMajorVersion,
233 &CurrentMinorVersion
234 );
235 if (EFI_ERROR (Status)) {
236 DEBUG ((DEBUG_ERROR, "Failed to get FF-A version. Status: %r\n", Status));
237 UT_ASSERT_NOT_EFI_ERROR (Status);
238 }
239
240 DEBUG ((DEBUG_INFO, "%a FF-A version: %d.%d\n", __func__, CurrentMajorVersion, CurrentMinorVersion));
241
242 UT_ASSERT_TRUE (
243 (CurrentMajorVersion >= ARM_FFA_MAJOR_VERSION) &&
244 (CurrentMinorVersion >= ARM_FFA_MINOR_VERSION)
245 );
246
247 utStatus = UNIT_TEST_PASSED;
248 UT_LOG_INFO ("FF-A version is supported: %d.%d", CurrentMajorVersion, CurrentMinorVersion);
249 return utStatus;
250}
251
252/**
253 This routine retrieves the partition information of the Ffa test SP and prints it.
254**/
255UNIT_TEST_STATUS
256EFIAPI
257FfaMiscGetPartitionInfoRegs (
258 IN UNIT_TEST_CONTEXT Context
259 )
260{
261 EFI_STATUS Status = EFI_SUCCESS;
262 EFI_FFA_PART_INFO_DESC FfaPartInfo;
263 ARM_SMC_ARGS SmcArgs;
264 UINT32 Count;
265 UINTN Index;
266 FFA_TEST_CONTEXT *FfaTestContext;
267 EFI_GUID *GuidsOfInterest[] = {
268 &gEfiMmCommunication2ProtocolGuid,
269 &gEfiTestServiceFfaGuid,
270 &gTpm2ServiceFfaGuid,
271 &gEfiNotificationServiceFfaGuid,
272 };
273
274 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
275
276 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
277 if (FfaTestContext == NULL) {
278 DEBUG ((DEBUG_ERROR, "%a: FfaTestContext is NULL.\n", __func__));
279 UT_ASSERT_NOT_NULL (FfaTestContext);
280 }
281
282 //
283 // Given the complexity of potentially having multiple partitions, we will
284 // just try to retrieve the partition information of the STMM SP, Test SP and TPM
285 // SP. The non-STMM SP availability will be checked in the next test case.
286 //
287 for (Index = 0; Index < ARRAY_SIZE (GuidsOfInterest); Index++) {
288 // Get the partition information of the STMM SP
289 ZeroMem (&SmcArgs, sizeof (SmcArgs));
290 Count = 1; // We expect only one partition info
291 DEBUG ((DEBUG_INFO, "%a: Querying partition info for %g...\n", __func__, GuidsOfInterest[Index]));
292 Status = FfaPartitionInfoGetRegs (GuidsOfInterest[Index], 0, NULL, &Count, (EFI_FFA_PART_INFO_DESC *)&SmcArgs.Arg3);
293 if (EFI_ERROR (Status)) {
294 DEBUG ((DEBUG_ERROR, "Failed to get FF-A partition info. Status: %r\n", Status));
295 } else {
296 CopyMem (&FfaPartInfo, &SmcArgs.Arg3, sizeof (EFI_FFA_PART_INFO_DESC));
297 }
298
299 if (CompareGuid (GuidsOfInterest[Index], &gEfiMmCommunication2ProtocolGuid)) {
300 if (EFI_ERROR (Status)) {
301 // If we are querying the MM Communication protocol, we need to bail.
302 DEBUG ((DEBUG_INFO, "%a MM Communication protocol not found, fatal error.\n", __func__));
303 UT_ASSERT_NOT_EFI_ERROR (Status);
304 } else {
305 FfaTestContext->IsMmCommunicationServiceAvailable = TRUE;
306 FfaTestContext->FfaMmCommunicationPartId = FfaPartInfo.PartitionId;
307 }
308 } else if (CompareGuid (GuidsOfInterest[Index], &gEfiTestServiceFfaGuid)) {
309 if (EFI_ERROR (Status)) {
310 // If we are querying the Test Service, we can skip it.
311 DEBUG ((DEBUG_INFO, "%a Test Service not found, skipping.\n", __func__));
312 UT_LOG_WARNING ("Test Service not found, skipping.");
313 continue;
314 } else {
315 FfaTestContext->IsTestServiceAvailable = TRUE;
316 FfaTestContext->FfaTestServicePartId = FfaPartInfo.PartitionId;
317 }
318 } else if (CompareGuid (GuidsOfInterest[Index], &gTpm2ServiceFfaGuid)) {
319 if (EFI_ERROR (Status)) {
320 // If we are querying the TPM Service, we can skip it.
321 DEBUG ((DEBUG_INFO, "%a TPM Service not found, skipping.\n", __func__));
322 UT_LOG_WARNING ("TPM Service not found, skipping.");
323 continue;
324 } else {
325 FfaTestContext->IsTpm2ServiceAvailable = TRUE;
326 FfaTestContext->FfaTpm2ServicePartId = FfaPartInfo.PartitionId;
327 }
328 } else if (CompareGuid (GuidsOfInterest[Index], &gEfiNotificationServiceFfaGuid)) {
329 if (EFI_ERROR (Status)) {
330 // If we are querying the Notification Service, we can skip it.
331 DEBUG ((DEBUG_INFO, "%a Notification Service not found, skipping.\n", __func__));
332 UT_LOG_WARNING ("Notification Service not found, skipping.");
333 continue;
334 } else {
335 FfaTestContext->IsNotificationServiceAvailable = TRUE;
336 FfaTestContext->FfaNotificationServicePartId = FfaPartInfo.PartitionId;
337 }
338 }
339
340 DEBUG ((DEBUG_INFO, "FF-A Secure Partition Info:\n"));
341 DEBUG ((
342 DEBUG_INFO,
343 "\tID = 0x%lx, Execution contexts = %d, Properties = 0x%lx.\n",
344 FfaPartInfo.PartitionId,
345 FfaPartInfo.ExecContextCountOrProxyPartitionId,
346 FfaPartInfo.PartitionProps
347 ));
348
349 DEBUG ((
350 DEBUG_INFO,
351 "\tSP Guid = %g.\n",
352 FfaPartInfo.PartitionUuid
353 ));
354 UT_ASSERT_MEM_EQUAL (
355 &FfaPartInfo.PartitionUuid,
356 &gZeroGuid,
357 sizeof (EFI_GUID)
358 );
359 }
360
361 UT_ASSERT_TRUE (FfaTestContext->IsMmCommunicationServiceAvailable);
362
363 return UNIT_TEST_PASSED;
364}
365
366/**
367 This routine retrieves the partition information of Ffa SPs through Rx/Tx buffer
368 and prints them.
369**/
370UNIT_TEST_STATUS
371EFIAPI
372FfaMiscGetPartitionInfo (
373 IN UNIT_TEST_CONTEXT Context
374 )
375{
376 EFI_STATUS Status = EFI_SUCCESS;
377 EFI_FFA_PART_INFO_DESC FfaPartInfo;
378 UINT32 Count;
379 UINT32 Size;
380
381 // Discover the Ffa test SP after converting the EFI_GUID to a format TF-A will
382 // understand.
383 Status = ArmFfaLibPartitionInfoGet (&gEfiMmCommunication2ProtocolGuid, 0, &Count, &Size);
384 if (EFI_ERROR (Status)) {
385 DEBUG ((DEBUG_ERROR, "Unable to discover FF-A test SP (%r).\n", Status));
386 UT_ASSERT_NOT_EFI_ERROR (Status);
387 }
388
389 // Retrieve the partition information from the returned registers
390 CopyMem (&FfaPartInfo, (VOID *)PcdGet64 (PcdFfaRxBuffer), sizeof (EFI_FFA_PART_INFO_DESC));
391
392 DEBUG ((DEBUG_INFO, "Discovered FF-A test SP.\n"));
393 DEBUG ((
394 DEBUG_INFO,
395 "\tID = 0x%lx, Execution contexts = %d, Properties = 0x%lx.\n",
396 FfaPartInfo.PartitionId,
397 FfaPartInfo.ExecContextCountOrProxyPartitionId,
398 FfaPartInfo.PartitionProps
399 ));
400 UT_ASSERT_MEM_EQUAL (
401 &FfaPartInfo.PartitionUuid,
402 &gZeroGuid,
403 sizeof (EFI_GUID)
404 );
405 DEBUG ((
406 DEBUG_INFO,
407 "\tSP Guid = %g.\n",
408 FfaPartInfo.PartitionUuid
409 ));
410
411 return UNIT_TEST_PASSED;
412}
413
414/**
415 This routine sets up the notifications for the Ffa test SP and verifies
416 that the notifications are working correctly.
417**/
418UNIT_TEST_STATUS
419EFIAPI
420FfaMiscSetupNotifications (
421 IN UNIT_TEST_CONTEXT Context
422 )
423{
424 EFI_STATUS Status = EFI_SUCCESS;
425 UINTN BindBitPos;
426 FFA_TEST_CONTEXT *FfaTestContext;
427
428 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
429
430 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
431 UT_ASSERT_NOT_NULL (FfaTestContext);
432
433 //
434 // Should be able to handle notification flow now.
435 //
436 // Now register UEFI to receive notifications by creating notification bitmaps
437 Status = FfaNotificationBitmapCreate (1);
438 if (EFI_ERROR (Status)) {
439 DEBUG ((DEBUG_ERROR, "Unable to create notification bitmap with FF-A Ffa test SP (%r).\n", Status));
440 UT_ASSERT_NOT_EFI_ERROR (Status);
441 }
442
443 // Then register this test app to receive notifications from the Ffa test SP
444 BindBitPos = 0x02;
445 FfaNotificationBind (FfaTestContext->FfaTestServicePartId, 0, (1 << BindBitPos));
446 if (EFI_ERROR (Status)) {
447 DEBUG ((DEBUG_ERROR, "Unable to bind notification with FF-A Ffa test SP (%r).\n", Status));
448 UT_ASSERT_NOT_EFI_ERROR (Status);
449 }
450
451 DEBUG ((DEBUG_INFO, "Binding Bit%x - Value: %x Successful %x.\n", BindBitPos, (1 << BindBitPos), FfaTestContext->FfaTestServicePartId));
452
453 return UNIT_TEST_PASSED;
454}
455
456/**
457 This routine registers the notifications for the Ffa test SP and verifies
458 that the notifications are working correctly.
459**/
460UNIT_TEST_STATUS
461EFIAPI
462FfaMiscRegisterNotifications (
463 IN UNIT_TEST_CONTEXT Context
464 )
465{
466 EFI_STATUS Status = EFI_SUCCESS;
467 UINTN SriIndex;
468 UINTN Dummy;
469
470 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
471
472 // Followed by querying which notification ID is supported by the Ffa test SP
473 Status = ArmFfaLibGetFeatures (ARM_FFA_FEATURE_ID_SCHEDULE_RECEIVER_INTERRUPT, 0, &SriIndex, &Dummy);
474 if (EFI_ERROR (Status)) {
475 DEBUG ((DEBUG_ERROR, "Unable to query feature SRI number with FF-A Ffa test SP (%r).\n", Status));
476 UT_ASSERT_NOT_EFI_ERROR (Status);
477 }
478
479 DEBUG ((DEBUG_INFO, "Received feature SRI number with FF-A Ffa test SP (%d).\n", SriIndex));
480
481 // Register the IRQ handler for the FF-A Ffa test SP
482 Status = gBS->LocateProtocol (&gHardwareInterruptProtocolGuid, NULL, (VOID **)&gInterrupt);
483 if (!EFI_ERROR (Status)) {
484 Status = gInterrupt->RegisterInterruptSource (gInterrupt, SriIndex, ApIrqInterruptHandler);
485 if (EFI_ERROR (Status)) {
486 DEBUG ((DEBUG_ERROR, "Unable to register notification (%r).\n", Status));
487 UT_ASSERT_NOT_EFI_ERROR (Status);
488 }
489 }
490
491 return UNIT_TEST_PASSED;
492}
493
494/**
495 This routine tests the inter-partition communication with the Ffa test SP.
496 It sends a message to the Ffa test SP and waits for a response.
497**/
498UNIT_TEST_STATUS
499EFIAPI
500FfaMiscTestInterPartitionNormal (
501 IN UNIT_TEST_CONTEXT Context
502 )
503{
504 EFI_STATUS Status = EFI_SUCCESS;
505 DIRECT_MSG_ARGS DirectMsgArgs;
506 NotificationMapping Mapping;
507 UINTN NumMappings;
508 INT8 ResponseVal;
509 FFA_TEST_CONTEXT *FfaTestContext;
510
511 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
512
513 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
514 UT_ASSERT_NOT_NULL (FfaTestContext);
515
516 // Register the Battery Service Notification Mappings
517 Mapping.Uint64 = 0;
518 NumMappings = 0x05;
519 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
520 /* Set the receiver service UUID */
521 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
522 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
523 DirectMsgArgs.Arg4 = 0xb710b3a359f64054;
524 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_REGISTER;
525 DirectMsgArgs.Arg6 = NumMappings;
526 DEBUG ((DEBUG_INFO, "Registering %x Mappings:\n", NumMappings));
527 Mapping.Bits.Cookie = 0;
528 Mapping.Bits.Id = 0;
529 DirectMsgArgs.Arg7 = Mapping.Uint64;
530 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
531 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
532 Mapping.Bits.Cookie = 1;
533 Mapping.Bits.Id = 1;
534 DirectMsgArgs.Arg8 = Mapping.Uint64;
535 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
536 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg8));
537 Mapping.Bits.Cookie = 2;
538 Mapping.Bits.Id = 2;
539 DirectMsgArgs.Arg9 = Mapping.Uint64;
540 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
541 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg9));
542 Mapping.Bits.Cookie = 3;
543 Mapping.Bits.Id = 3;
544 DirectMsgArgs.Arg10 = Mapping.Uint64;
545 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
546 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg10));
547 Mapping.Bits.Cookie = 4;
548 Mapping.Bits.Id = 4;
549 DirectMsgArgs.Arg11 = Mapping.Uint64;
550 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
551 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg11));
552 Status = ArmFfaLibMsgSendDirectReq2 (
553 FfaTestContext->FfaNotificationServicePartId,
554 &gEfiNotificationServiceFfaGuid,
555 &DirectMsgArgs
556 );
557 if (EFI_ERROR (Status)) {
558 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
559 UT_ASSERT_NOT_EFI_ERROR (Status);
560 }
561
562 ResponseVal = (INT8)DirectMsgArgs.Arg6;
563 if (ResponseVal != NOTIFICATION_STATUS_SUCCESS) {
564 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
565 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_SUCCESS);
566 } else {
567 DEBUG ((DEBUG_INFO, "Battery Service Register Success\n"));
568 }
569
570 return UNIT_TEST_PASSED;
571}
572
573/**
574 This routine tests the inter-partition communication with the Ffa test SP
575 in a secondary service.
576**/
577UNIT_TEST_STATUS
578EFIAPI
579FfaMiscTestInterPartitionSecondary (
580 IN UNIT_TEST_CONTEXT Context
581 )
582{
583 EFI_STATUS Status = EFI_SUCCESS;
584 DIRECT_MSG_ARGS DirectMsgArgs;
585 NotificationMapping Mapping;
586 UINTN NumMappings;
587 INT8 ResponseVal;
588 FFA_TEST_CONTEXT *FfaTestContext;
589
590 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
591
592 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
593 UT_ASSERT_NOT_NULL (FfaTestContext);
594
595 // Register the Thermal Service Notification Mappings
596 Mapping.Uint64 = 0;
597 NumMappings = 0x03;
598 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
599 /* Set the receiver service UUID */
600 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
601 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
602 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
603 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_REGISTER;
604 DirectMsgArgs.Arg6 = NumMappings;
605 DEBUG ((DEBUG_INFO, "Registering %x Mappings:\n", NumMappings));
606 Mapping.Bits.Cookie = 0;
607 Mapping.Bits.Id = 5;
608 DirectMsgArgs.Arg7 = Mapping.Uint64;
609 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
610 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
611 Mapping.Bits.Cookie = 1;
612 Mapping.Bits.Id = 6;
613 DirectMsgArgs.Arg8 = Mapping.Uint64;
614 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
615 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg8));
616 Mapping.Bits.Cookie = 2;
617 Mapping.Bits.Id = 7;
618 DirectMsgArgs.Arg9 = Mapping.Uint64;
619 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
620 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg9));
621 Status = ArmFfaLibMsgSendDirectReq2 (
622 FfaTestContext->FfaNotificationServicePartId,
623 &gEfiNotificationServiceFfaGuid,
624 &DirectMsgArgs
625 );
626 if (EFI_ERROR (Status)) {
627 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
628 UT_ASSERT_NOT_EFI_ERROR (Status);
629 }
630
631 ResponseVal = (INT8)DirectMsgArgs.Arg6;
632 if (ResponseVal != NOTIFICATION_STATUS_SUCCESS) {
633 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
634 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_SUCCESS);
635 } else {
636 DEBUG ((DEBUG_INFO, "Thermal Service Register Success\n"));
637 }
638
639 return UNIT_TEST_PASSED;
640}
641
642/**
643 This routine tests the inter-partition communication with the Ffa test SP
644 with a duplicate cookie.
645**/
646UNIT_TEST_STATUS
647EFIAPI
648FfaMiscTestInterPartitionDuplicateCookie (
649 IN UNIT_TEST_CONTEXT Context
650 )
651{
652 DIRECT_MSG_ARGS DirectMsgArgs;
653 NotificationMapping Mapping;
654 UINTN NumMappings;
655 INT8 ResponseVal;
656 EFI_STATUS Status;
657 FFA_TEST_CONTEXT *FfaTestContext;
658
659 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
660
661 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
662 UT_ASSERT_NOT_NULL (FfaTestContext);
663
664 // Register the Thermal Service Notification Mapping Duplicate Cookie - Invalid
665 Mapping.Uint64 = 0;
666 NumMappings = 0x01;
667 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
668 /* Set the receiver service UUID */
669 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
670 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
671 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
672 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_REGISTER;
673 DirectMsgArgs.Arg6 = NumMappings;
674 DEBUG ((DEBUG_INFO, "Registering %x Mappings:\n", NumMappings));
675 Mapping.Bits.Cookie = 2; // Duplicate Cookie
676 Mapping.Bits.Id = 8; // Different ID
677 DirectMsgArgs.Arg7 = Mapping.Uint64;
678 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
679 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
680 Status = ArmFfaLibMsgSendDirectReq2 (
681 FfaTestContext->FfaNotificationServicePartId,
682 &gEfiNotificationServiceFfaGuid,
683 &DirectMsgArgs
684 );
685 if (EFI_ERROR (Status)) {
686 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
687 UT_ASSERT_NOT_EFI_ERROR (Status);
688 }
689
690 ResponseVal = (INT8)DirectMsgArgs.Arg6;
691 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
692 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
693 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
694 } else {
695 DEBUG ((DEBUG_INFO, "Thermal Service Register Invalid Duplicate Cookie Success\n"));
696 }
697
698 return UNIT_TEST_PASSED;
699}
700
701/**
702 This routine tests the inter-partition communication with the Ffa test SP
703 with an invalid duplicate ID.
704**/
705UNIT_TEST_STATUS
706EFIAPI
707FfaMiscTestInterPartitionInvalidDuplicateId (
708 IN UNIT_TEST_CONTEXT Context
709 )
710{
711 DIRECT_MSG_ARGS DirectMsgArgs;
712 NotificationMapping Mapping;
713 UINTN NumMappings;
714 INT8 ResponseVal;
715 EFI_STATUS Status;
716 FFA_TEST_CONTEXT *FfaTestContext;
717
718 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
719
720 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
721 UT_ASSERT_NOT_NULL (FfaTestContext);
722
723 // Register the Thermal Service Notification Mapping Duplicate ID - Invalid
724 Mapping.Uint64 = 0;
725 NumMappings = 0x01;
726 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
727 /* Set the receiver service UUID */
728 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
729 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
730 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
731 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_REGISTER;
732 DirectMsgArgs.Arg6 = NumMappings;
733 DEBUG ((DEBUG_INFO, "Registering %x Mappings:\n", NumMappings));
734 Mapping.Bits.Cookie = 3; // Different Cookie
735 Mapping.Bits.Id = 7; // Duplicate ID
736 DirectMsgArgs.Arg7 = Mapping.Uint64;
737 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
738 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
739 Status = ArmFfaLibMsgSendDirectReq2 (
740 FfaTestContext->FfaNotificationServicePartId,
741 &gEfiNotificationServiceFfaGuid,
742 &DirectMsgArgs
743 );
744 if (EFI_ERROR (Status)) {
745 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
746 UT_ASSERT_NOT_EFI_ERROR (Status);
747 }
748
749 ResponseVal = (INT8)DirectMsgArgs.Arg6;
750 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
751 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
752 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
753 } else {
754 DEBUG ((DEBUG_INFO, "Thermal Service Register Invalid Duplicate ID Success\n"));
755 }
756
757 return UNIT_TEST_PASSED;
758}
759
760/**
761 This routine tests the inter-partition communication with the Ffa test SP
762 with an invalid mapping count minimum value.
763**/
764UNIT_TEST_STATUS
765EFIAPI
766FfaMiscTestInterPartitionInvalidMappingCountMin (
767 IN UNIT_TEST_CONTEXT Context
768 )
769{
770 DIRECT_MSG_ARGS DirectMsgArgs;
771 NotificationMapping Mapping;
772 INT8 ResponseVal;
773 EFI_STATUS Status;
774 FFA_TEST_CONTEXT *FfaTestContext;
775
776 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
777
778 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
779 UT_ASSERT_NOT_NULL (FfaTestContext);
780
781 // Register the Thermal Service Notification Invalid Mapping Count Min Value
782 Mapping.Uint64 = 0;
783 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
784 /* Set the receiver service UUID */
785 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
786 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
787 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
788 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_REGISTER;
789 DirectMsgArgs.Arg6 = 0x00; // Invalid
790 Status = ArmFfaLibMsgSendDirectReq2 (
791 FfaTestContext->FfaNotificationServicePartId,
792 &gEfiNotificationServiceFfaGuid,
793 &DirectMsgArgs
794 );
795 if (EFI_ERROR (Status)) {
796 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
797 UT_ASSERT_NOT_EFI_ERROR (Status);
798 }
799
800 ResponseVal = (INT8)DirectMsgArgs.Arg6;
801 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
802 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
803 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
804 } else {
805 DEBUG ((DEBUG_INFO, "Thermal Service Register Invalid Mapping Count MIN Success\n"));
806 }
807
808 return UNIT_TEST_PASSED;
809}
810
811/**
812 This routine tests the inter-partition communication with the Ffa test SP
813 with an invalid mapping count maximum value.
814**/
815UNIT_TEST_STATUS
816EFIAPI
817FfaMiscTestInterPartitionInvalidMappingCountMax (
818 IN UNIT_TEST_CONTEXT Context
819 )
820{
821 DIRECT_MSG_ARGS DirectMsgArgs;
822 NotificationMapping Mapping;
823 INT8 ResponseVal;
824 EFI_STATUS Status;
825 FFA_TEST_CONTEXT *FfaTestContext;
826
827 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
828
829 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
830 UT_ASSERT_NOT_NULL (FfaTestContext);
831
832 // Register the Thermal Service Notification Invalid Mapping Count Max Value
833 Mapping.Uint64 = 0;
834 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
835 /* Set the receiver service UUID */
836 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
837 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
838 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
839 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_REGISTER;
840 DirectMsgArgs.Arg6 = 0x8; // Invalid
841 Status = ArmFfaLibMsgSendDirectReq2 (
842 FfaTestContext->FfaNotificationServicePartId,
843 &gEfiNotificationServiceFfaGuid,
844 &DirectMsgArgs
845 );
846 if (EFI_ERROR (Status)) {
847 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
848 UT_ASSERT_NOT_EFI_ERROR (Status);
849 }
850
851 ResponseVal = (INT8)DirectMsgArgs.Arg6;
852 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
853 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
854 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
855 } else {
856 DEBUG ((DEBUG_INFO, "Thermal Service Register Invalid Mapping Count MAX Success\n"));
857 }
858
859 return UNIT_TEST_PASSED;
860}
861
862/**
863 This routine tests the inter-partition communication with the Ffa test SP
864 and unregisters the notifications.
865**/
866UNIT_TEST_STATUS
867EFIAPI
868FfaMiscTestInterPartitionUnregisterNormal (
869 IN UNIT_TEST_CONTEXT Context
870 )
871{
872 DIRECT_MSG_ARGS DirectMsgArgs;
873 NotificationMapping Mapping;
874 UINTN NumMappings;
875 INT8 ResponseVal;
876 EFI_STATUS Status;
877 FFA_TEST_CONTEXT *FfaTestContext;
878
879 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
880
881 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
882 UT_ASSERT_NOT_NULL (FfaTestContext);
883
884 // Unregister the Thermal Service Notification Mapping Cookie1
885 Mapping.Uint64 = 0;
886 NumMappings = 0x01;
887 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
888 /* Set the receiver service UUID */
889 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
890 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
891 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
892 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_UNREGISTER;
893 DirectMsgArgs.Arg6 = NumMappings;
894 DEBUG ((DEBUG_INFO, "Unregistering %x Mappings:\n", NumMappings));
895 Mapping.Bits.Cookie = 1;
896 Mapping.Bits.Id = 6;
897 DirectMsgArgs.Arg7 = Mapping.Uint64;
898 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
899 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
900 Status = ArmFfaLibMsgSendDirectReq2 (
901 FfaTestContext->FfaNotificationServicePartId,
902 &gEfiNotificationServiceFfaGuid,
903 &DirectMsgArgs
904 );
905 if (EFI_ERROR (Status)) {
906 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
907 UT_ASSERT_NOT_EFI_ERROR (Status);
908 }
909
910 ResponseVal = (INT8)DirectMsgArgs.Arg6;
911 if (ResponseVal != NOTIFICATION_STATUS_SUCCESS) {
912 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
913 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_SUCCESS);
914 } else {
915 DEBUG ((DEBUG_INFO, "Thermal Service Unregister Success\n"));
916 }
917
918 return UNIT_TEST_PASSED;
919}
920
921/**
922 This routine tests the inter-partition communication with the Ffa test SP
923 and unregisters the notifications with an invalid cookie.
924**/
925UNIT_TEST_STATUS
926EFIAPI
927FfaMiscTestInterPartitionUnregisterInvalidCookie (
928 IN UNIT_TEST_CONTEXT Context
929 )
930{
931 DIRECT_MSG_ARGS DirectMsgArgs;
932 NotificationMapping Mapping;
933 UINTN NumMappings;
934 INT8 ResponseVal;
935 EFI_STATUS Status;
936 FFA_TEST_CONTEXT *FfaTestContext;
937
938 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
939
940 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
941 UT_ASSERT_NOT_NULL (FfaTestContext);
942
943 // Unregister the Thermal Service Notification Mapping Cookie1 - Invalid
944 Mapping.Uint64 = 0;
945 NumMappings = 0x01;
946 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
947 /* Set the receiver service UUID */
948 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
949 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
950 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
951 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_UNREGISTER;
952 DirectMsgArgs.Arg6 = NumMappings;
953 DEBUG ((DEBUG_INFO, "Unregistering %x Mappings:\n", NumMappings));
954 Mapping.Bits.Cookie = 1;
955 Mapping.Bits.Id = 6;
956 DirectMsgArgs.Arg7 = Mapping.Uint64;
957 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
958 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
959 Status = ArmFfaLibMsgSendDirectReq2 (
960 FfaTestContext->FfaNotificationServicePartId,
961 &gEfiNotificationServiceFfaGuid,
962 &DirectMsgArgs
963 );
964 if (EFI_ERROR (Status)) {
965 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
966 UT_ASSERT_NOT_EFI_ERROR (Status);
967 }
968
969 ResponseVal = (INT8)DirectMsgArgs.Arg6;
970 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
971 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
972 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
973 } else {
974 DEBUG ((DEBUG_INFO, "Thermal Service Unregister Invalid Cookie Success\n"));
975 }
976
977 return UNIT_TEST_PASSED;
978}
979
980/**
981 This routine tests the inter-partition communication with the Ffa test SP
982 and unregisters the notifications with an invalid ID.
983**/
984UNIT_TEST_STATUS
985EFIAPI
986FfaMiscTestInterPartitionUnregisterInvalidId (
987 IN UNIT_TEST_CONTEXT Context
988 )
989{
990 DIRECT_MSG_ARGS DirectMsgArgs;
991 NotificationMapping Mapping;
992 UINTN NumMappings;
993 INT8 ResponseVal;
994 EFI_STATUS Status;
995 FFA_TEST_CONTEXT *FfaTestContext;
996
997 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
998
999 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1000 UT_ASSERT_NOT_NULL (FfaTestContext);
1001
1002 // Unregister the Thermal Service Notification Mapping Cookie/ID Mismatch - Invalid
1003 Mapping.Uint64 = 0;
1004 NumMappings = 0x01;
1005 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1006 /* Set the receiver service UUID */
1007 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
1008 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
1009 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
1010 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_UNREGISTER;
1011 DirectMsgArgs.Arg6 = NumMappings;
1012 DEBUG ((DEBUG_INFO, "Unregistering %x Mappings:\n", NumMappings));
1013 Mapping.Bits.Cookie = 0;
1014 Mapping.Bits.Id = 0;
1015 DirectMsgArgs.Arg7 = Mapping.Uint64;
1016 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
1017 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
1018 Status = ArmFfaLibMsgSendDirectReq2 (
1019 FfaTestContext->FfaNotificationServicePartId,
1020 &gEfiNotificationServiceFfaGuid,
1021 &DirectMsgArgs
1022 );
1023 if (EFI_ERROR (Status)) {
1024 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1025 UT_ASSERT_NOT_EFI_ERROR (Status);
1026 }
1027
1028 ResponseVal = (INT8)DirectMsgArgs.Arg6;
1029 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
1030 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
1031 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
1032 } else {
1033 DEBUG ((DEBUG_INFO, "Thermal Service Unregister Invalid Cookie/ID Mismatch Success\n"));
1034 }
1035
1036 return UNIT_TEST_PASSED;
1037}
1038
1039/**
1040 This routine tests the inter-partition communication with the Ffa test SP
1041 and unregisters the notifications with an invalid UUID.
1042**/
1043UNIT_TEST_STATUS
1044EFIAPI
1045FfaMiscTestInterPartitionUnregisterInvalidUuid (
1046 IN UNIT_TEST_CONTEXT Context
1047 )
1048{
1049 DIRECT_MSG_ARGS DirectMsgArgs;
1050 INT8 ResponseVal;
1051 EFI_STATUS Status;
1052 FFA_TEST_CONTEXT *FfaTestContext;
1053
1054 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
1055
1056 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1057 UT_ASSERT_NOT_NULL (FfaTestContext);
1058
1059 // Unregister Invalid Service UUID
1060 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1061 /* Set the receiver service UUID */
1062 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
1063 /* Do not set UUID in x7-x8 (i.e. Arg3-Arg4) - Invalid */
1064 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_UNREGISTER;
1065 Status = ArmFfaLibMsgSendDirectReq2 (
1066 FfaTestContext->FfaNotificationServicePartId,
1067 &gEfiNotificationServiceFfaGuid,
1068 &DirectMsgArgs
1069 );
1070 if (EFI_ERROR (Status)) {
1071 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1072 UT_ASSERT_NOT_EFI_ERROR (Status);
1073 }
1074
1075 ResponseVal = (INT8)DirectMsgArgs.Arg6;
1076 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
1077 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
1078 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
1079 } else {
1080 DEBUG ((DEBUG_INFO, "Unregister Invalid Service UUID Success\n"));
1081 }
1082
1083 return UNIT_TEST_PASSED;
1084}
1085
1086/**
1087 This routine tests the notification event with the Ffa test SP.
1088**/
1089UNIT_TEST_STATUS
1090EFIAPI
1091FfaMiscTestNotificationEvent (
1092 IN UNIT_TEST_CONTEXT Context
1093 )
1094{
1095 DIRECT_MSG_ARGS DirectMsgArgs;
1096 EFI_STATUS Status;
1097 FFA_TEST_CONTEXT *FfaTestContext;
1098
1099 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
1100
1101 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1102 UT_ASSERT_NOT_NULL (FfaTestContext);
1103
1104 mIsInterruptFired = FALSE; // Reset the interrupt fired flag
1105
1106 // Test a Notification Event
1107 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1108 DirectMsgArgs.Arg0 = TEST_OPCODE_TEST_NOTIFICATION;
1109 DirectMsgArgs.Arg1 = 0xba7aff2eb1eac765;
1110 DirectMsgArgs.Arg2 = 0xb710b3a359f64054; // Battery Service
1111 /* IMPORTANT NOTE: Only bit 2 has been bound, test needs to match binding call */
1112 DirectMsgArgs.Arg3 = 0x02; // Cookie2 = ID2 = BitPos2
1113 Status = ArmFfaLibMsgSendDirectReq2 (
1114 FfaTestContext->FfaTestServicePartId,
1115 &gEfiTestServiceFfaGuid,
1116 &DirectMsgArgs
1117 );
1118 if (EFI_ERROR (Status)) {
1119 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1120 UT_ASSERT_NOT_EFI_ERROR (Status);
1121 }
1122
1123 if (DirectMsgArgs.Arg0 != TEST_STATUS_SUCCESS) {
1124 DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0));
1125 UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TEST_STATUS_SUCCESS);
1126 } else {
1127 DEBUG ((DEBUG_INFO, "Test Service Notification Event Success\n"));
1128 }
1129
1130 // Delay for a bit and wait for the notification to be processed
1131 gBS->Stall (1000); // 1 millisecond
1132
1133 // Check if the notification was received
1134 UT_ASSERT_TRUE (mIsInterruptFired);
1135
1136 return UNIT_TEST_PASSED;
1137}
1138
1139/**
1140 This routine tests the notification event with the Ffa test SP.
1141**/
1142UNIT_TEST_STATUS
1143EFIAPI
1144FfaMiscTestDelayEvent (
1145 IN UNIT_TEST_CONTEXT Context
1146 )
1147{
1148 DIRECT_MSG_ARGS DirectMsgArgs;
1149 EFI_STATUS Status;
1150 FFA_TEST_CONTEXT *FfaTestContext;
1151 UINT64 StartTime;
1152 UINT64 EndTime;
1153 UINT64 ElapsedTime;
1154 UINT64 TimeToTest = 5000000; // 5 seconds in microseconds
1155
1156 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
1157
1158 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1159 UT_ASSERT_NOT_NULL (FfaTestContext);
1160
1161 mIsInterruptFired = FALSE; // Reset the interrupt fired flag
1162
1163 StartTime = GetPerformanceCounter ();
1164
1165 // Test a Notification Event
1166 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1167 DirectMsgArgs.Arg0 = TEST_OPCODE_TEST_DELAY;
1168 DirectMsgArgs.Arg1 = TimeToTest;
1169 Status = ArmFfaLibMsgSendDirectReq2 (
1170 FfaTestContext->FfaTestServicePartId,
1171 &gEfiTestServiceFfaGuid,
1172 &DirectMsgArgs
1173 );
1174 if (EFI_ERROR (Status)) {
1175 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1176 UT_ASSERT_NOT_EFI_ERROR (Status);
1177 }
1178
1179 if (DirectMsgArgs.Arg0 != TEST_STATUS_SUCCESS) {
1180 DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0));
1181 UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TEST_STATUS_SUCCESS);
1182 } else {
1183 DEBUG ((DEBUG_INFO, "Test Service Notification Event Success\n"));
1184 }
1185
1186 EndTime = GetPerformanceCounter ();
1187 ElapsedTime = GetTimeInNanoSecond (EndTime - StartTime);
1188 ElapsedTime = ElapsedTime / 1000; // Convert to microseconds
1189 DEBUG ((DEBUG_INFO, "Delay Event Elapsed Time: %lu us\n", ElapsedTime));
1190 if (ElapsedTime < TimeToTest) {
1191 DEBUG ((DEBUG_ERROR, "Delay Event Completed Too Quickly\n"));
1192 UT_ASSERT_TRUE (FALSE);
1193 }
1194
1195 return UNIT_TEST_PASSED;
1196}
1197
1198/**
1199 This routine tests the TPM version retrieval with the Ffa test SP.
1200**/
1201UNIT_TEST_STATUS
1202EFIAPI
1203FfaMiscTestTpmGetVersion (
1204 IN UNIT_TEST_CONTEXT Context
1205 )
1206{
1207 DIRECT_MSG_ARGS DirectMsgArgs;
1208 EFI_STATUS Status;
1209 FFA_TEST_CONTEXT *FfaTestContext;
1210
1211 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
1212
1213 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1214 UT_ASSERT_NOT_NULL (FfaTestContext);
1215
1216 // Call the TPM Service get_interface_version
1217 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1218 DirectMsgArgs.Arg0 = TPM2_FFA_GET_INTERFACE_VERSION;
1219 Status = ArmFfaLibMsgSendDirectReq2 (
1220 FfaTestContext->FfaTpm2ServicePartId,
1221 &gTpm2ServiceFfaGuid,
1222 &DirectMsgArgs
1223 );
1224 if (EFI_ERROR (Status)) {
1225 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1226 UT_ASSERT_NOT_EFI_ERROR (Status);
1227 }
1228
1229 if (DirectMsgArgs.Arg0 != TPM2_FFA_SUCCESS_OK_RESULTS_RETURNED) {
1230 DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0));
1231 UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TPM2_FFA_SUCCESS_OK_RESULTS_RETURNED);
1232 } else {
1233 DEBUG ((DEBUG_INFO, "TPM Service Interface Version: %d.%d\n", DirectMsgArgs.Arg1 >> 16, DirectMsgArgs.Arg1 & 0xFFFF));
1234 }
1235
1236 return UNIT_TEST_PASSED;
1237}
1238
1239/**
1240 This routine tests the TPM Service to close locality with the Ffa test SP.
1241**/
1242UNIT_TEST_STATUS
1243EFIAPI
1244FfaMiscTestTpmCloseLocality (
1245 IN UNIT_TEST_CONTEXT Context
1246 )
1247{
1248 DIRECT_MSG_ARGS DirectMsgArgs;
1249 EFI_STATUS Status;
1250 FFA_TEST_CONTEXT *FfaTestContext;
1251
1252 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
1253
1254 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1255 UT_ASSERT_NOT_NULL (FfaTestContext);
1256
1257 // Call the TPM Service to close locality0
1258 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1259 DirectMsgArgs.Arg0 = TPM2_FFA_START;
1260 DirectMsgArgs.Arg1 = 0x101; // Close Locality
1261 DirectMsgArgs.Arg2 = 0x00; // Locality Qualifier
1262 Status = ArmFfaLibMsgSendDirectReq2 (
1263 FfaTestContext->FfaTpm2ServicePartId,
1264 &gTpm2ServiceFfaGuid,
1265 &DirectMsgArgs
1266 );
1267 if (EFI_ERROR (Status)) {
1268 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1269 UT_ASSERT_NOT_EFI_ERROR (Status);
1270 }
1271
1272 if (DirectMsgArgs.Arg0 != TPM2_FFA_SUCCESS_OK) {
1273 DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0));
1274 UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TPM2_FFA_SUCCESS_OK);
1275 } else {
1276 DEBUG ((DEBUG_INFO, "TPM Service Close Locality Success\n"));
1277 }
1278
1279 return UNIT_TEST_PASSED;
1280}
1281
1282/**
1283 This routine tests the TPM Service to request locality with the Ffa test SP.
1284**/
1285UNIT_TEST_STATUS
1286EFIAPI
1287FfaMiscTestTpmRequestLocality (
1288 IN UNIT_TEST_CONTEXT Context
1289 )
1290{
1291 DIRECT_MSG_ARGS DirectMsgArgs;
1292 EFI_STATUS Status;
1293 FFA_TEST_CONTEXT *FfaTestContext;
1294
1295 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
1296
1297 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1298 UT_ASSERT_NOT_NULL (FfaTestContext);
1299
1300 // Call the TPM Service to request locality0
1301 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1302 DirectMsgArgs.Arg0 = TPM2_FFA_START;
1303 DirectMsgArgs.Arg1 = TPM2_FFA_START_FUNC_QUALIFIER_LOCALITY;
1304 DirectMsgArgs.Arg2 = 0x00; // Locality Qualifier
1305 Status = ArmFfaLibMsgSendDirectReq2 (
1306 FfaTestContext->FfaTpm2ServicePartId,
1307 &gTpm2ServiceFfaGuid,
1308 &DirectMsgArgs
1309 );
1310 if (EFI_ERROR (Status)) {
1311 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1312 UT_ASSERT_NOT_EFI_ERROR (Status);
1313 }
1314
1315 if (DirectMsgArgs.Arg0 != TPM2_FFA_ERROR_DENIED) {
1316 DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0));
1317 UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TPM2_FFA_ERROR_DENIED);
1318 } else {
1319 DEBUG ((DEBUG_INFO, "TPM Service Rejected Request, Locality Closed\n"));
1320 }
1321
1322 return UNIT_TEST_PASSED;
1323}
1324
1325/**
1326 This routine tests the TPM Service to reopen locality with the Ffa test SP.
1327**/
1328UNIT_TEST_STATUS
1329EFIAPI
1330FfaMiscTestTpmReopenLocality (
1331 IN UNIT_TEST_CONTEXT Context
1332 )
1333{
1334 DIRECT_MSG_ARGS DirectMsgArgs;
1335 EFI_STATUS Status;
1336 FFA_TEST_CONTEXT *FfaTestContext;
1337
1338 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
1339
1340 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1341 UT_ASSERT_NOT_NULL (FfaTestContext);
1342
1343 // Call the TPM Service to reopen locality0
1344 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1345 DirectMsgArgs.Arg0 = TPM2_FFA_START;
1346 DirectMsgArgs.Arg1 = 0x100; // Open Locality
1347 DirectMsgArgs.Arg2 = 0x00; // Locality Qualifier
1348 Status = ArmFfaLibMsgSendDirectReq2 (
1349 FfaTestContext->FfaTpm2ServicePartId,
1350 &gTpm2ServiceFfaGuid,
1351 &DirectMsgArgs
1352 );
1353 if (EFI_ERROR (Status)) {
1354 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1355 UT_ASSERT_NOT_EFI_ERROR (Status);
1356 }
1357
1358 if (DirectMsgArgs.Arg0 != TPM2_FFA_SUCCESS_OK) {
1359 DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0));
1360 UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TPM2_FFA_SUCCESS_OK);
1361 } else {
1362 DEBUG ((DEBUG_INFO, "TPM Service Open Locality Success\n"));
1363 }
1364
1365 return UNIT_TEST_PASSED;
1366}
1367
1368/**
1369 FfaPartitionTestAppEntry
1370
1371 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1372 @param[in] SystemTable A pointer to the EFI System Table.
1373
1374 @retval EFI_SUCCESS The entry point executed successfully.
1375 @retval other Some error occurred when executing this entry point.
1376
1377**/
1378EFI_STATUS
1379EFIAPI
1380FfaPartitionTestAppEntry (
1381 IN EFI_HANDLE ImageHandle,
1382 IN EFI_SYSTEM_TABLE *SystemTable
1383 )
1384{
1385 EFI_STATUS Status;
1386 UNIT_TEST_FRAMEWORK_HANDLE Fw = NULL;
1387 UNIT_TEST_SUITE_HANDLE Misc = NULL;
1388 FFA_TEST_CONTEXT FfaTestContext = { 0 };
1389
1390 DEBUG ((DEBUG_ERROR, "%a %a v%a\n", __FUNCTION__, UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));
1391
1392 // Start setting up the test framework for running the tests.
1393 Status = InitUnitTestFramework (&Fw, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION);
1394 if (EFI_ERROR (Status)) {
1395 DEBUG ((DEBUG_ERROR, "%a Failed in InitUnitTestFramework. Status = %r\n", __FUNCTION__, Status));
1396 goto Done;
1397 }
1398
1399 // Misc test suite for all tests.
1400 Status = CreateUnitTestSuite (&Misc, Fw, "FF-A Miscellaneous Test cases", "Ffa.Miscellaneous", NULL, NULL);
1401
1402 if (EFI_ERROR (Status)) {
1403 DEBUG ((DEBUG_ERROR, "%a Failed in CreateUnitTestSuite for TestSuite\n", __FUNCTION__));
1404 Status = EFI_OUT_OF_RESOURCES;
1405 goto Done;
1406 }
1407
1408 Status = AddTestCase (
1409 Misc,
1410 "Verify FF-A framework version",
1411 "Ffa.Miscellaneous.VerifyVersion",
1412 FfaMiscVerifyVersion,
1413 NULL,
1414 NULL,
1415 &FfaTestContext
1416 );
1417 if (EFI_ERROR (Status)) {
1418 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for VerifyVersion\n", __FUNCTION__));
1419 Status = EFI_OUT_OF_RESOURCES;
1420 goto Done;
1421 }
1422
1423 Status = AddTestCase (
1424 Misc,
1425 "Verify Partition Info via registers",
1426 "Ffa.Miscellaneous.VerifyPartitionInfoRegs",
1427 FfaMiscGetPartitionInfoRegs,
1428 NULL,
1429 NULL,
1430 &FfaTestContext
1431 );
1432 if (EFI_ERROR (Status)) {
1433 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for VerifyPartitionInfoRegs\n", __FUNCTION__));
1434 Status = EFI_OUT_OF_RESOURCES;
1435 goto Done;
1436 }
1437
1438 Status = AddTestCase (
1439 Misc,
1440 "Verify Partition Info via Rx/Tx buffers",
1441 "Ffa.Miscellaneous.VerifyPartitionInfo",
1442 FfaMiscGetPartitionInfo,
1443 NULL,
1444 NULL,
1445 &FfaTestContext
1446 );
1447 if (EFI_ERROR (Status)) {
1448 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for VerifyPartitionInfo\n", __FUNCTION__));
1449 Status = EFI_OUT_OF_RESOURCES;
1450 goto Done;
1451 }
1452
1453 Status = AddTestCase (
1454 Misc,
1455 "Verify FF-A Ffa test SP notifications",
1456 "Ffa.Miscellaneous.SetupNotifications",
1457 FfaMiscSetupNotifications,
1458 CheckTestService,
1459 NULL,
1460 &FfaTestContext
1461 );
1462 if (EFI_ERROR (Status)) {
1463 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for SetupNotifications\n", __FUNCTION__));
1464 Status = EFI_OUT_OF_RESOURCES;
1465 goto Done;
1466 }
1467
1468 Status = AddTestCase (
1469 Misc,
1470 "Verify FF-A Ffa test SP notifications",
1471 "Ffa.Miscellaneous.RegisterNotifications",
1472 FfaMiscRegisterNotifications,
1473 NULL,
1474 NULL,
1475 &FfaTestContext
1476 );
1477 if (EFI_ERROR (Status)) {
1478 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for RegisterNotifications\n", __FUNCTION__));
1479 Status = EFI_OUT_OF_RESOURCES;
1480 goto Done;
1481 }
1482
1483 //
1484 // Test interpartition communication with the Ffa test SP.
1485 // These tests will only run if the Ffa test SP is available.
1486 // As a system level test, the order of the tests is important as the tests will
1487 // will corporate the states of inter-partition service to test the Ffa test SP.
1488 //
1489 Status = AddTestCase (
1490 Misc,
1491 "Verify Ffa Inter Partition",
1492 "Ffa.Miscellaneous.FfaTestInterPartitionNormal",
1493 FfaMiscTestInterPartitionNormal,
1494 CheckNotificationService,
1495 NULL,
1496 &FfaTestContext
1497 );
1498 if (EFI_ERROR (Status)) {
1499 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionNormal\n", __FUNCTION__));
1500 Status = EFI_OUT_OF_RESOURCES;
1501 goto Done;
1502 }
1503
1504 Status = AddTestCase (
1505 Misc,
1506 "Verify Ffa Inter Partition",
1507 "Ffa.Miscellaneous.FfaTestInterPartitionSecondary",
1508 FfaMiscTestInterPartitionSecondary,
1509 CheckNotificationService,
1510 NULL,
1511 &FfaTestContext
1512 );
1513 if (EFI_ERROR (Status)) {
1514 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionSecondary\n", __FUNCTION__));
1515 Status = EFI_OUT_OF_RESOURCES;
1516 goto Done;
1517 }
1518
1519 Status = AddTestCase (
1520 Misc,
1521 "Verify Ffa Inter Partition",
1522 "Ffa.Miscellaneous.FfaTestInterPartitionDuplicateCookie",
1523 FfaMiscTestInterPartitionDuplicateCookie,
1524 CheckNotificationService,
1525 NULL,
1526 &FfaTestContext
1527 );
1528 if (EFI_ERROR (Status)) {
1529 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionDuplicateCookie\n", __FUNCTION__));
1530 Status = EFI_OUT_OF_RESOURCES;
1531 goto Done;
1532 }
1533
1534 Status = AddTestCase (
1535 Misc,
1536 "Verify Ffa Inter Partition",
1537 "Ffa.Miscellaneous.FfaTestInterPartitionInvalidDuplicateId",
1538 FfaMiscTestInterPartitionInvalidDuplicateId,
1539 CheckNotificationService,
1540 NULL,
1541 &FfaTestContext
1542 );
1543 if (EFI_ERROR (Status)) {
1544 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionInvalidDuplicateId\n", __FUNCTION__));
1545 Status = EFI_OUT_OF_RESOURCES;
1546 goto Done;
1547 }
1548
1549 Status = AddTestCase (
1550 Misc,
1551 "Verify Ffa Inter Partition",
1552 "Ffa.Miscellaneous.FfaTestInterPartitionInvalidMappingCountMin",
1553 FfaMiscTestInterPartitionInvalidMappingCountMin,
1554 CheckNotificationService,
1555 NULL,
1556 &FfaTestContext
1557 );
1558 if (EFI_ERROR (Status)) {
1559 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionInvalidMappingCountMin\n", __FUNCTION__));
1560 Status = EFI_OUT_OF_RESOURCES;
1561 goto Done;
1562 }
1563
1564 Status = AddTestCase (
1565 Misc,
1566 "Verify Ffa Inter Partition",
1567 "Ffa.Miscellaneous.FfaTestInterPartitionInvalidMappingCountMax",
1568 FfaMiscTestInterPartitionInvalidMappingCountMax,
1569 CheckNotificationService,
1570 NULL,
1571 &FfaTestContext
1572 );
1573 if (EFI_ERROR (Status)) {
1574 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionInvalidMappingCountMax\n", __FUNCTION__));
1575 Status = EFI_OUT_OF_RESOURCES;
1576 goto Done;
1577 }
1578
1579 Status = AddTestCase (
1580 Misc,
1581 "Verify Ffa Inter Partition",
1582 "Ffa.Miscellaneous.FfaTestInterPartitionUnregisterNormal",
1583 FfaMiscTestInterPartitionUnregisterNormal,
1584 CheckNotificationService,
1585 NULL,
1586 &FfaTestContext
1587 );
1588 if (EFI_ERROR (Status)) {
1589 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionUnregisterNormal\n", __FUNCTION__));
1590 Status = EFI_OUT_OF_RESOURCES;
1591 goto Done;
1592 }
1593
1594 Status = AddTestCase (
1595 Misc,
1596 "Verify Ffa Inter Partition",
1597 "Ffa.Miscellaneous.FfaTestInterPartitionUnregisterInvalidCookie",
1598 FfaMiscTestInterPartitionUnregisterInvalidCookie,
1599 CheckNotificationService,
1600 NULL,
1601 &FfaTestContext
1602 );
1603 if (EFI_ERROR (Status)) {
1604 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionUnregisterInvalidCookie\n", __FUNCTION__));
1605 Status = EFI_OUT_OF_RESOURCES;
1606 goto Done;
1607 }
1608
1609 Status = AddTestCase (
1610 Misc,
1611 "Verify Ffa Inter Partition",
1612 "Ffa.Miscellaneous.FfaTestInterPartitionUnregisterInvalidId",
1613 FfaMiscTestInterPartitionUnregisterInvalidId,
1614 CheckNotificationService,
1615 NULL,
1616 &FfaTestContext
1617 );
1618 if (EFI_ERROR (Status)) {
1619 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionUnregisterInvalidId\n", __FUNCTION__));
1620 Status = EFI_OUT_OF_RESOURCES;
1621 goto Done;
1622 }
1623
1624 Status = AddTestCase (
1625 Misc,
1626 "Verify Ffa Inter Partition",
1627 "Ffa.Miscellaneous.FfaTestInterPartitionUnregisterInvalidUuid",
1628 FfaMiscTestInterPartitionUnregisterInvalidUuid,
1629 CheckNotificationService,
1630 NULL,
1631 &FfaTestContext
1632 );
1633 if (EFI_ERROR (Status)) {
1634 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionUnregisterInvalidUuid\n", __FUNCTION__));
1635 Status = EFI_OUT_OF_RESOURCES;
1636 goto Done;
1637 }
1638
1639 Status = AddTestCase (
1640 Misc,
1641 "Verify Ffa Notification Event",
1642 "Ffa.Miscellaneous.FfaTestNotificationEvent",
1643 FfaMiscTestNotificationEvent,
1644 CheckTestService,
1645 NULL,
1646 &FfaTestContext
1647 );
1648 if (EFI_ERROR (Status)) {
1649 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestNotificationEvent\n", __FUNCTION__));
1650 Status = EFI_OUT_OF_RESOURCES;
1651 goto Done;
1652 }
1653
1654 Status = AddTestCase (
1655 Misc,
1656 "Verify Ffa Notification Event",
1657 "Ffa.Miscellaneous.FfaMiscTestDelayEvent",
1658 FfaMiscTestDelayEvent,
1659 CheckTestService,
1660 NULL,
1661 &FfaTestContext
1662 );
1663 if (EFI_ERROR (Status)) {
1664 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaMiscTestDelayEvent\n", __FUNCTION__));
1665 Status = EFI_OUT_OF_RESOURCES;
1666 goto Done;
1667 }
1668
1669 //
1670 // As a system level test, the order of the tests is important as the tests will
1671 // will corporate the states of TPM service to test the Ffa test SP.
1672 //
1673 Status = AddTestCase (
1674 Misc,
1675 "Verify Ffa TPM Service",
1676 "Ffa.Miscellaneous.FfaTestTpmGetVersion",
1677 FfaMiscTestTpmGetVersion,
1678 CheckTPMService,
1679 NULL,
1680 &FfaTestContext
1681 );
1682 if (EFI_ERROR (Status)) {
1683 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestTpmGetVersion\n", __FUNCTION__));
1684 Status = EFI_OUT_OF_RESOURCES;
1685 goto Done;
1686 }
1687
1688 Status = AddTestCase (
1689 Misc,
1690 "Verify Ffa TPM Service",
1691 "Ffa.Miscellaneous.FfaTestTpmCloseLocality",
1692 FfaMiscTestTpmCloseLocality,
1693 CheckTPMService,
1694 NULL,
1695 &FfaTestContext
1696 );
1697 if (EFI_ERROR (Status)) {
1698 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestTpmCloseLocality\n", __FUNCTION__));
1699 Status = EFI_OUT_OF_RESOURCES;
1700 goto Done;
1701 }
1702
1703 Status = AddTestCase (
1704 Misc,
1705 "Verify Ffa TPM Service",
1706 "Ffa.Miscellaneous.FfaTestTpmRequestLocality",
1707 FfaMiscTestTpmRequestLocality,
1708 CheckTPMService,
1709 NULL,
1710 &FfaTestContext
1711 );
1712 if (EFI_ERROR (Status)) {
1713 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestTpmRequestLocality\n", __FUNCTION__));
1714 Status = EFI_OUT_OF_RESOURCES;
1715 goto Done;
1716 }
1717
1718 Status = AddTestCase (
1719 Misc,
1720 "Verify Ffa TPM Service",
1721 "Ffa.Miscellaneous.FfaTestTpmReopenLocality",
1722 FfaMiscTestTpmReopenLocality,
1723 CheckTPMService,
1724 NULL,
1725 &FfaTestContext
1726 );
1727 if (EFI_ERROR (Status)) {
1728 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestTpmReopenLocality\n", __FUNCTION__));
1729 Status = EFI_OUT_OF_RESOURCES;
1730 goto Done;
1731 }
1732
1733 //
1734 // Execute the tests.
1735 //
1736 Status = RunAllTestSuites (Fw);
1737
1738Done:
1739 if (Fw != NULL) {
1740 FreeUnitTestFramework (Fw);
1741 }
1742
1743 DEBUG ((DEBUG_INFO, "%a exit - %r\n", __FUNCTION__, Status));
1744 return Status;
1745}
1746