microsoft/mu_feature_ffa

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.1.7

Branches

Tags

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

Clone

HTTPS

Download ZIP

FfaFeaturePkg/Applications/FfaPartitionTest/FfaPartitionTestApp.c

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