microsoft/mu_feature_ffa

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
fix_upload

Branches

Tags

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

Clone

HTTPS

Download ZIP

FfaFeaturePkg/Applications/FfaPartitionTest/FfaPartitionTestApp.c

1670lines · 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 return UNIT_TEST_PASSED;
411}
412
413/**
414 This routine sets up the notifications for the Ffa test SP and verifies
415 that the notifications are working correctly.
416**/
417UNIT_TEST_STATUS
418EFIAPI
419FfaMiscSetupNotifications (
420 IN UNIT_TEST_CONTEXT Context
421 )
422{
423 EFI_STATUS Status = EFI_SUCCESS;
424 UINTN BindBitPos;
425 FFA_TEST_CONTEXT *FfaTestContext;
426
427 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
428
429 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
430 UT_ASSERT_NOT_NULL (FfaTestContext);
431
432 //
433 // Should be able to handle notification flow now.
434 //
435 // Now register UEFI to receive notifications by creating notification bitmaps
436 Status = FfaNotificationBitmapCreate (1);
437 if (EFI_ERROR (Status)) {
438 DEBUG ((DEBUG_ERROR, "Unable to create notification bitmap with FF-A Ffa test SP (%r).\n", Status));
439 UT_ASSERT_NOT_EFI_ERROR (Status);
440 }
441
442 // Then register this test app to receive notifications from the Ffa test SP
443 BindBitPos = 0x02;
444 FfaNotificationBind (FfaTestContext->FfaTestServicePartId, 0, (1 << BindBitPos));
445 if (EFI_ERROR (Status)) {
446 DEBUG ((DEBUG_ERROR, "Unable to bind notification with FF-A Ffa test SP (%r).\n", Status));
447 UT_ASSERT_NOT_EFI_ERROR (Status);
448 }
449
450 DEBUG ((DEBUG_INFO, "Binding Bit%x - Value: %x Successful %x.\n", BindBitPos, (1 << BindBitPos), FfaTestContext->FfaTestServicePartId));
451
452 return UNIT_TEST_PASSED;
453}
454
455/**
456 This routine registers the notifications for the Ffa test SP and verifies
457 that the notifications are working correctly.
458**/
459UNIT_TEST_STATUS
460EFIAPI
461FfaMiscRegisterNotifications (
462 IN UNIT_TEST_CONTEXT Context
463 )
464{
465 EFI_STATUS Status = EFI_SUCCESS;
466 UINTN SriIndex;
467 UINTN Dummy;
468
469 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
470
471 // Followed by querying which notification ID is supported by the Ffa test SP
472 Status = ArmFfaLibGetFeatures (ARM_FFA_FEATURE_ID_SCHEDULE_RECEIVER_INTERRUPT, 0, &SriIndex, &Dummy);
473 if (EFI_ERROR (Status)) {
474 DEBUG ((DEBUG_ERROR, "Unable to query feature SRI number with FF-A Ffa test SP (%r).\n", Status));
475 UT_ASSERT_NOT_EFI_ERROR (Status);
476 }
477
478 DEBUG ((DEBUG_INFO, "Received feature SRI number with FF-A Ffa test SP (%d).\n", SriIndex));
479
480 // Register the IRQ handler for the FF-A Ffa test SP
481 Status = gBS->LocateProtocol (&gHardwareInterruptProtocolGuid, NULL, (VOID **)&gInterrupt);
482 if (!EFI_ERROR (Status)) {
483 Status = gInterrupt->RegisterInterruptSource (gInterrupt, SriIndex, ApIrqInterruptHandler);
484 if (EFI_ERROR (Status)) {
485 DEBUG ((DEBUG_ERROR, "Unable to register notification (%r).\n", Status));
486 UT_ASSERT_NOT_EFI_ERROR (Status);
487 }
488 }
489
490 return UNIT_TEST_PASSED;
491}
492
493/**
494 This routine tests the inter-partition communication with the Ffa test SP.
495 It sends a message to the Ffa test SP and waits for a response.
496**/
497UNIT_TEST_STATUS
498EFIAPI
499FfaMiscTestInterPartitionNormal (
500 IN UNIT_TEST_CONTEXT Context
501 )
502{
503 EFI_STATUS Status = EFI_SUCCESS;
504 DIRECT_MSG_ARGS DirectMsgArgs;
505 NotificationMapping Mapping;
506 UINTN NumMappings;
507 INT8 ResponseVal;
508 FFA_TEST_CONTEXT *FfaTestContext;
509
510 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
511
512 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
513 UT_ASSERT_NOT_NULL (FfaTestContext);
514
515 // Register the Battery Service Notification Mappings
516 Mapping.Uint64 = 0;
517 NumMappings = 0x05;
518 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
519 /* Set the receiver service UUID */
520 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
521 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
522 DirectMsgArgs.Arg4 = 0xb710b3a359f64054;
523 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_REGISTER;
524 DirectMsgArgs.Arg6 = NumMappings;
525 DEBUG ((DEBUG_INFO, "Registering %x Mappings:\n", NumMappings));
526 Mapping.Bits.Cookie = 0;
527 Mapping.Bits.Id = 0;
528 DirectMsgArgs.Arg7 = Mapping.Uint64;
529 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
530 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
531 Mapping.Bits.Cookie = 1;
532 Mapping.Bits.Id = 1;
533 DirectMsgArgs.Arg8 = Mapping.Uint64;
534 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
535 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg8));
536 Mapping.Bits.Cookie = 2;
537 Mapping.Bits.Id = 2;
538 DirectMsgArgs.Arg9 = Mapping.Uint64;
539 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
540 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg9));
541 Mapping.Bits.Cookie = 3;
542 Mapping.Bits.Id = 3;
543 DirectMsgArgs.Arg10 = Mapping.Uint64;
544 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
545 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg10));
546 Mapping.Bits.Cookie = 4;
547 Mapping.Bits.Id = 4;
548 DirectMsgArgs.Arg11 = Mapping.Uint64;
549 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
550 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg11));
551 Status = ArmFfaLibMsgSendDirectReq2 (
552 FfaTestContext->FfaNotificationServicePartId,
553 &gEfiNotificationServiceFfaGuid,
554 &DirectMsgArgs
555 );
556 if (EFI_ERROR (Status)) {
557 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
558 UT_ASSERT_NOT_EFI_ERROR (Status);
559 }
560
561 ResponseVal = (INT8)DirectMsgArgs.Arg6;
562 if (ResponseVal != NOTIFICATION_STATUS_SUCCESS) {
563 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
564 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_SUCCESS);
565 } else {
566 DEBUG ((DEBUG_INFO, "Battery Service Register Success\n"));
567 }
568
569 return UNIT_TEST_PASSED;
570}
571
572/**
573 This routine tests the inter-partition communication with the Ffa test SP
574 in a secondary service.
575**/
576UNIT_TEST_STATUS
577EFIAPI
578FfaMiscTestInterPartitionSecondary (
579 IN UNIT_TEST_CONTEXT Context
580 )
581{
582 EFI_STATUS Status = EFI_SUCCESS;
583 DIRECT_MSG_ARGS DirectMsgArgs;
584 NotificationMapping Mapping;
585 UINTN NumMappings;
586 INT8 ResponseVal;
587 FFA_TEST_CONTEXT *FfaTestContext;
588
589 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
590
591 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
592 UT_ASSERT_NOT_NULL (FfaTestContext);
593
594 // Register the Thermal Service Notification Mappings
595 Mapping.Uint64 = 0;
596 NumMappings = 0x03;
597 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
598 /* Set the receiver service UUID */
599 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
600 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
601 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
602 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_REGISTER;
603 DirectMsgArgs.Arg6 = NumMappings;
604 DEBUG ((DEBUG_INFO, "Registering %x Mappings:\n", NumMappings));
605 Mapping.Bits.Cookie = 0;
606 Mapping.Bits.Id = 5;
607 DirectMsgArgs.Arg7 = Mapping.Uint64;
608 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
609 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
610 Mapping.Bits.Cookie = 1;
611 Mapping.Bits.Id = 6;
612 DirectMsgArgs.Arg8 = Mapping.Uint64;
613 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
614 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg8));
615 Mapping.Bits.Cookie = 2;
616 Mapping.Bits.Id = 7;
617 DirectMsgArgs.Arg9 = Mapping.Uint64;
618 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
619 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg9));
620 Status = ArmFfaLibMsgSendDirectReq2 (
621 FfaTestContext->FfaNotificationServicePartId,
622 &gEfiNotificationServiceFfaGuid,
623 &DirectMsgArgs
624 );
625 if (EFI_ERROR (Status)) {
626 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
627 UT_ASSERT_NOT_EFI_ERROR (Status);
628 }
629
630 ResponseVal = (INT8)DirectMsgArgs.Arg6;
631 if (ResponseVal != NOTIFICATION_STATUS_SUCCESS) {
632 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
633 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_SUCCESS);
634 } else {
635 DEBUG ((DEBUG_INFO, "Thermal Service Register Success\n"));
636 }
637
638 return UNIT_TEST_PASSED;
639}
640
641/**
642 This routine tests the inter-partition communication with the Ffa test SP
643 with a duplicate cookie.
644**/
645UNIT_TEST_STATUS
646EFIAPI
647FfaMiscTestInterPartitionDuplicateCookie (
648 IN UNIT_TEST_CONTEXT Context
649 )
650{
651 DIRECT_MSG_ARGS DirectMsgArgs;
652 NotificationMapping Mapping;
653 UINTN NumMappings;
654 INT8 ResponseVal;
655 EFI_STATUS Status;
656 FFA_TEST_CONTEXT *FfaTestContext;
657
658 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
659
660 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
661 UT_ASSERT_NOT_NULL (FfaTestContext);
662
663 // Register the Thermal Service Notification Mapping Duplicate Cookie - Invalid
664 Mapping.Uint64 = 0;
665 NumMappings = 0x01;
666 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
667 /* Set the receiver service UUID */
668 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
669 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
670 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
671 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_REGISTER;
672 DirectMsgArgs.Arg6 = NumMappings;
673 DEBUG ((DEBUG_INFO, "Registering %x Mappings:\n", NumMappings));
674 Mapping.Bits.Cookie = 2; // Duplicate Cookie
675 Mapping.Bits.Id = 8; // Different ID
676 DirectMsgArgs.Arg7 = Mapping.Uint64;
677 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
678 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
679 Status = ArmFfaLibMsgSendDirectReq2 (
680 FfaTestContext->FfaNotificationServicePartId,
681 &gEfiNotificationServiceFfaGuid,
682 &DirectMsgArgs
683 );
684 if (EFI_ERROR (Status)) {
685 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
686 UT_ASSERT_NOT_EFI_ERROR (Status);
687 }
688
689 ResponseVal = (INT8)DirectMsgArgs.Arg6;
690 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
691 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
692 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
693 } else {
694 DEBUG ((DEBUG_INFO, "Thermal Service Register Invalid Duplicate Cookie Success\n"));
695 }
696
697 return UNIT_TEST_PASSED;
698}
699
700/**
701 This routine tests the inter-partition communication with the Ffa test SP
702 with an invalid duplicate ID.
703**/
704UNIT_TEST_STATUS
705EFIAPI
706FfaMiscTestInterPartitionInvalidDuplicateId (
707 IN UNIT_TEST_CONTEXT Context
708 )
709{
710 DIRECT_MSG_ARGS DirectMsgArgs;
711 NotificationMapping Mapping;
712 UINTN NumMappings;
713 INT8 ResponseVal;
714 EFI_STATUS Status;
715 FFA_TEST_CONTEXT *FfaTestContext;
716
717 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
718
719 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
720 UT_ASSERT_NOT_NULL (FfaTestContext);
721
722 // Register the Thermal Service Notification Mapping Duplicate ID - Invalid
723 Mapping.Uint64 = 0;
724 NumMappings = 0x01;
725 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
726 /* Set the receiver service UUID */
727 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
728 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
729 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
730 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_REGISTER;
731 DirectMsgArgs.Arg6 = NumMappings;
732 DEBUG ((DEBUG_INFO, "Registering %x Mappings:\n", NumMappings));
733 Mapping.Bits.Cookie = 3; // Different Cookie
734 Mapping.Bits.Id = 7; // Duplicate ID
735 DirectMsgArgs.Arg7 = Mapping.Uint64;
736 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
737 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
738 Status = ArmFfaLibMsgSendDirectReq2 (
739 FfaTestContext->FfaNotificationServicePartId,
740 &gEfiNotificationServiceFfaGuid,
741 &DirectMsgArgs
742 );
743 if (EFI_ERROR (Status)) {
744 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
745 UT_ASSERT_NOT_EFI_ERROR (Status);
746 }
747
748 ResponseVal = (INT8)DirectMsgArgs.Arg6;
749 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
750 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
751 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
752 } else {
753 DEBUG ((DEBUG_INFO, "Thermal Service Register Invalid Duplicate ID Success\n"));
754 }
755
756 return UNIT_TEST_PASSED;
757}
758
759/**
760 This routine tests the inter-partition communication with the Ffa test SP
761 with an invalid mapping count minimum value.
762**/
763UNIT_TEST_STATUS
764EFIAPI
765FfaMiscTestInterPartitionInvalidMappingCountMin (
766 IN UNIT_TEST_CONTEXT Context
767 )
768{
769 DIRECT_MSG_ARGS DirectMsgArgs;
770 NotificationMapping Mapping;
771 INT8 ResponseVal;
772 EFI_STATUS Status;
773 FFA_TEST_CONTEXT *FfaTestContext;
774
775 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
776
777 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
778 UT_ASSERT_NOT_NULL (FfaTestContext);
779
780 // Register the Thermal Service Notification Invalid Mapping Count Min Value
781 Mapping.Uint64 = 0;
782 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
783 /* Set the receiver service UUID */
784 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
785 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
786 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
787 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_REGISTER;
788 DirectMsgArgs.Arg6 = 0x00; // Invalid
789 Status = ArmFfaLibMsgSendDirectReq2 (
790 FfaTestContext->FfaNotificationServicePartId,
791 &gEfiNotificationServiceFfaGuid,
792 &DirectMsgArgs
793 );
794 if (EFI_ERROR (Status)) {
795 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
796 UT_ASSERT_NOT_EFI_ERROR (Status);
797 }
798
799 ResponseVal = (INT8)DirectMsgArgs.Arg6;
800 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
801 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
802 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
803 } else {
804 DEBUG ((DEBUG_INFO, "Thermal Service Register Invalid Mapping Count MIN Success\n"));
805 }
806
807 return UNIT_TEST_PASSED;
808}
809
810/**
811 This routine tests the inter-partition communication with the Ffa test SP
812 with an invalid mapping count maximum value.
813**/
814UNIT_TEST_STATUS
815EFIAPI
816FfaMiscTestInterPartitionInvalidMappingCountMax (
817 IN UNIT_TEST_CONTEXT Context
818 )
819{
820 DIRECT_MSG_ARGS DirectMsgArgs;
821 NotificationMapping Mapping;
822 INT8 ResponseVal;
823 EFI_STATUS Status;
824 FFA_TEST_CONTEXT *FfaTestContext;
825
826 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
827
828 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
829 UT_ASSERT_NOT_NULL (FfaTestContext);
830
831 // Register the Thermal Service Notification Invalid Mapping Count Max Value
832 Mapping.Uint64 = 0;
833 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
834 /* Set the receiver service UUID */
835 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
836 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
837 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
838 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_REGISTER;
839 DirectMsgArgs.Arg6 = 0x8; // Invalid
840 Status = ArmFfaLibMsgSendDirectReq2 (
841 FfaTestContext->FfaNotificationServicePartId,
842 &gEfiNotificationServiceFfaGuid,
843 &DirectMsgArgs
844 );
845 if (EFI_ERROR (Status)) {
846 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
847 UT_ASSERT_NOT_EFI_ERROR (Status);
848 }
849
850 ResponseVal = (INT8)DirectMsgArgs.Arg6;
851 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
852 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
853 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
854 } else {
855 DEBUG ((DEBUG_INFO, "Thermal Service Register Invalid Mapping Count MAX Success\n"));
856 }
857
858 return UNIT_TEST_PASSED;
859}
860
861/**
862 This routine tests the inter-partition communication with the Ffa test SP
863 and unregisters the notifications.
864**/
865UNIT_TEST_STATUS
866EFIAPI
867FfaMiscTestInterPartitionUnregisterNormal (
868 IN UNIT_TEST_CONTEXT Context
869 )
870{
871 DIRECT_MSG_ARGS DirectMsgArgs;
872 NotificationMapping Mapping;
873 UINTN NumMappings;
874 INT8 ResponseVal;
875 EFI_STATUS Status;
876 FFA_TEST_CONTEXT *FfaTestContext;
877
878 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
879
880 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
881 UT_ASSERT_NOT_NULL (FfaTestContext);
882
883 // Unregister the Thermal Service Notification Mapping Cookie1
884 Mapping.Uint64 = 0;
885 NumMappings = 0x01;
886 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
887 /* Set the receiver service UUID */
888 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
889 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
890 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
891 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_UNREGISTER;
892 DirectMsgArgs.Arg6 = NumMappings;
893 DEBUG ((DEBUG_INFO, "Unregistering %x Mappings:\n", NumMappings));
894 Mapping.Bits.Cookie = 1;
895 Mapping.Bits.Id = 6;
896 DirectMsgArgs.Arg7 = Mapping.Uint64;
897 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
898 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
899 Status = ArmFfaLibMsgSendDirectReq2 (
900 FfaTestContext->FfaNotificationServicePartId,
901 &gEfiNotificationServiceFfaGuid,
902 &DirectMsgArgs
903 );
904 if (EFI_ERROR (Status)) {
905 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
906 UT_ASSERT_NOT_EFI_ERROR (Status);
907 }
908
909 ResponseVal = (INT8)DirectMsgArgs.Arg6;
910 if (ResponseVal != NOTIFICATION_STATUS_SUCCESS) {
911 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
912 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_SUCCESS);
913 } else {
914 DEBUG ((DEBUG_INFO, "Thermal Service Unregister Success\n"));
915 }
916
917 return UNIT_TEST_PASSED;
918}
919
920/**
921 This routine tests the inter-partition communication with the Ffa test SP
922 and unregisters the notifications with an invalid cookie.
923**/
924UNIT_TEST_STATUS
925EFIAPI
926FfaMiscTestInterPartitionUnregisterInvalidCookie (
927 IN UNIT_TEST_CONTEXT Context
928 )
929{
930 DIRECT_MSG_ARGS DirectMsgArgs;
931 NotificationMapping Mapping;
932 UINTN NumMappings;
933 INT8 ResponseVal;
934 EFI_STATUS Status;
935 FFA_TEST_CONTEXT *FfaTestContext;
936
937 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
938
939 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
940 UT_ASSERT_NOT_NULL (FfaTestContext);
941
942 // Unregister the Thermal Service Notification Mapping Cookie1 - Invalid
943 Mapping.Uint64 = 0;
944 NumMappings = 0x01;
945 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
946 /* Set the receiver service UUID */
947 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
948 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
949 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
950 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_UNREGISTER;
951 DirectMsgArgs.Arg6 = NumMappings;
952 DEBUG ((DEBUG_INFO, "Unregistering %x Mappings:\n", NumMappings));
953 Mapping.Bits.Cookie = 1;
954 Mapping.Bits.Id = 6;
955 DirectMsgArgs.Arg7 = Mapping.Uint64;
956 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
957 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
958 Status = ArmFfaLibMsgSendDirectReq2 (
959 FfaTestContext->FfaNotificationServicePartId,
960 &gEfiNotificationServiceFfaGuid,
961 &DirectMsgArgs
962 );
963 if (EFI_ERROR (Status)) {
964 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
965 UT_ASSERT_NOT_EFI_ERROR (Status);
966 }
967
968 ResponseVal = (INT8)DirectMsgArgs.Arg6;
969 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
970 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
971 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
972 } else {
973 DEBUG ((DEBUG_INFO, "Thermal Service Unregister Invalid Cookie Success\n"));
974 }
975
976 return UNIT_TEST_PASSED;
977}
978
979/**
980 This routine tests the inter-partition communication with the Ffa test SP
981 and unregisters the notifications with an invalid ID.
982**/
983UNIT_TEST_STATUS
984EFIAPI
985FfaMiscTestInterPartitionUnregisterInvalidId (
986 IN UNIT_TEST_CONTEXT Context
987 )
988{
989 DIRECT_MSG_ARGS DirectMsgArgs;
990 NotificationMapping Mapping;
991 UINTN NumMappings;
992 INT8 ResponseVal;
993 EFI_STATUS Status;
994 FFA_TEST_CONTEXT *FfaTestContext;
995
996 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
997
998 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
999 UT_ASSERT_NOT_NULL (FfaTestContext);
1000
1001 // Unregister the Thermal Service Notification Mapping Cookie/ID Mismatch - Invalid
1002 Mapping.Uint64 = 0;
1003 NumMappings = 0x01;
1004 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1005 /* Set the receiver service UUID */
1006 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
1007 DirectMsgArgs.Arg3 = 0xba7aff2eb1eac765;
1008 DirectMsgArgs.Arg4 = 0xb610b3a359f64054;
1009 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_UNREGISTER;
1010 DirectMsgArgs.Arg6 = NumMappings;
1011 DEBUG ((DEBUG_INFO, "Unregistering %x Mappings:\n", NumMappings));
1012 Mapping.Bits.Cookie = 0;
1013 Mapping.Bits.Id = 0;
1014 DirectMsgArgs.Arg7 = Mapping.Uint64;
1015 DEBUG ((DEBUG_INFO, "Cookie: %x, Id: %x\n", Mapping.Bits.Cookie, Mapping.Bits.Id));
1016 DEBUG ((DEBUG_INFO, "Register Value: %lx\n", DirectMsgArgs.Arg7));
1017 Status = ArmFfaLibMsgSendDirectReq2 (
1018 FfaTestContext->FfaNotificationServicePartId,
1019 &gEfiNotificationServiceFfaGuid,
1020 &DirectMsgArgs
1021 );
1022 if (EFI_ERROR (Status)) {
1023 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1024 UT_ASSERT_NOT_EFI_ERROR (Status);
1025 }
1026
1027 ResponseVal = (INT8)DirectMsgArgs.Arg6;
1028 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
1029 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
1030 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
1031 } else {
1032 DEBUG ((DEBUG_INFO, "Thermal Service Unregister Invalid Cookie/ID Mismatch Success\n"));
1033 }
1034
1035 return UNIT_TEST_PASSED;
1036}
1037
1038/**
1039 This routine tests the inter-partition communication with the Ffa test SP
1040 and unregisters the notifications with an invalid UUID.
1041**/
1042UNIT_TEST_STATUS
1043EFIAPI
1044FfaMiscTestInterPartitionUnregisterInvalidUuid (
1045 IN UNIT_TEST_CONTEXT Context
1046 )
1047{
1048 DIRECT_MSG_ARGS DirectMsgArgs;
1049 INT8 ResponseVal;
1050 EFI_STATUS Status;
1051 FFA_TEST_CONTEXT *FfaTestContext;
1052
1053 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
1054
1055 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1056 UT_ASSERT_NOT_NULL (FfaTestContext);
1057
1058 // Unregister Invalid Service UUID
1059 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1060 /* Set the receiver service UUID */
1061 /* x4-x6 (i.e. Arg0-Arg2) should be 0 */
1062 /* Do not set UUID in x7-x8 (i.e. Arg3-Arg4) - Invalid */
1063 DirectMsgArgs.Arg5 = NOTIFICATION_OPCODE_UNREGISTER;
1064 Status = ArmFfaLibMsgSendDirectReq2 (
1065 FfaTestContext->FfaNotificationServicePartId,
1066 &gEfiNotificationServiceFfaGuid,
1067 &DirectMsgArgs
1068 );
1069 if (EFI_ERROR (Status)) {
1070 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1071 UT_ASSERT_NOT_EFI_ERROR (Status);
1072 }
1073
1074 ResponseVal = (INT8)DirectMsgArgs.Arg6;
1075 if (ResponseVal != NOTIFICATION_STATUS_INVALID_PARAMETER) {
1076 DEBUG ((DEBUG_ERROR, "Command Failed: %d\n", DirectMsgArgs.Arg6));
1077 UT_ASSERT_EQUAL (ResponseVal, NOTIFICATION_STATUS_INVALID_PARAMETER);
1078 } else {
1079 DEBUG ((DEBUG_INFO, "Unregister Invalid Service UUID Success\n"));
1080 }
1081
1082 return UNIT_TEST_PASSED;
1083}
1084
1085/**
1086 This routine tests the notification event with the Ffa test SP.
1087**/
1088UNIT_TEST_STATUS
1089EFIAPI
1090FfaMiscTestNotificationEvent (
1091 IN UNIT_TEST_CONTEXT Context
1092 )
1093{
1094 DIRECT_MSG_ARGS DirectMsgArgs;
1095 EFI_STATUS Status;
1096 FFA_TEST_CONTEXT *FfaTestContext;
1097
1098 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
1099
1100 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1101 UT_ASSERT_NOT_NULL (FfaTestContext);
1102
1103 mIsInterruptFired = FALSE; // Reset the interrupt fired flag
1104
1105 // Test a Notification Event
1106 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1107 DirectMsgArgs.Arg0 = TEST_OPCODE_TEST_NOTIFICATION;
1108 DirectMsgArgs.Arg1 = 0xba7aff2eb1eac765;
1109 DirectMsgArgs.Arg2 = 0xb710b3a359f64054; // Battery Service
1110 /* IMPORTANT NOTE: Only bit 2 has been bound, test needs to match binding call */
1111 DirectMsgArgs.Arg3 = 0x02; // Cookie2 = ID2 = BitPos2
1112 Status = ArmFfaLibMsgSendDirectReq2 (
1113 FfaTestContext->FfaTestServicePartId,
1114 &gEfiTestServiceFfaGuid,
1115 &DirectMsgArgs
1116 );
1117 if (EFI_ERROR (Status)) {
1118 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1119 UT_ASSERT_NOT_EFI_ERROR (Status);
1120 }
1121
1122 if (DirectMsgArgs.Arg0 != TEST_STATUS_SUCCESS) {
1123 DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0));
1124 UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TEST_STATUS_SUCCESS);
1125 } else {
1126 DEBUG ((DEBUG_INFO, "Test Service Notification Event Success\n"));
1127 }
1128
1129 // Delay for a bit and wait for the notification to be processed
1130 gBS->Stall (1000); // 1 millisecond
1131
1132 // Check if the notification was received
1133 UT_ASSERT_TRUE (mIsInterruptFired);
1134
1135 return UNIT_TEST_PASSED;
1136}
1137
1138/**
1139 This routine tests the TPM version retrieval with the Ffa test SP.
1140**/
1141UNIT_TEST_STATUS
1142EFIAPI
1143FfaMiscTestTpmGetVersion (
1144 IN UNIT_TEST_CONTEXT Context
1145 )
1146{
1147 DIRECT_MSG_ARGS DirectMsgArgs;
1148 EFI_STATUS Status;
1149 FFA_TEST_CONTEXT *FfaTestContext;
1150
1151 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
1152
1153 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1154 UT_ASSERT_NOT_NULL (FfaTestContext);
1155
1156 // Call the TPM Service get_interface_version
1157 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1158 DirectMsgArgs.Arg0 = TPM2_FFA_GET_INTERFACE_VERSION;
1159 Status = ArmFfaLibMsgSendDirectReq2 (
1160 FfaTestContext->FfaTpm2ServicePartId,
1161 &gTpm2ServiceFfaGuid,
1162 &DirectMsgArgs
1163 );
1164 if (EFI_ERROR (Status)) {
1165 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1166 UT_ASSERT_NOT_EFI_ERROR (Status);
1167 }
1168
1169 if (DirectMsgArgs.Arg0 != TPM2_FFA_SUCCESS_OK_RESULTS_RETURNED) {
1170 DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0));
1171 UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TPM2_FFA_SUCCESS_OK_RESULTS_RETURNED);
1172 } else {
1173 DEBUG ((DEBUG_INFO, "TPM Service Interface Version: %d.%d\n", DirectMsgArgs.Arg1 >> 16, DirectMsgArgs.Arg1 & 0xFFFF));
1174 }
1175
1176 return UNIT_TEST_PASSED;
1177}
1178
1179/**
1180 This routine tests the TPM Service to close locality with the Ffa test SP.
1181**/
1182UNIT_TEST_STATUS
1183EFIAPI
1184FfaMiscTestTpmCloseLocality (
1185 IN UNIT_TEST_CONTEXT Context
1186 )
1187{
1188 DIRECT_MSG_ARGS DirectMsgArgs;
1189 EFI_STATUS Status;
1190 FFA_TEST_CONTEXT *FfaTestContext;
1191
1192 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
1193
1194 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1195 UT_ASSERT_NOT_NULL (FfaTestContext);
1196
1197 // Call the TPM Service to close locality0
1198 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1199 DirectMsgArgs.Arg0 = TPM2_FFA_START;
1200 DirectMsgArgs.Arg1 = 0x101; // Close Locality
1201 DirectMsgArgs.Arg2 = 0x00; // Locality Qualifier
1202 Status = ArmFfaLibMsgSendDirectReq2 (
1203 FfaTestContext->FfaTpm2ServicePartId,
1204 &gTpm2ServiceFfaGuid,
1205 &DirectMsgArgs
1206 );
1207 if (EFI_ERROR (Status)) {
1208 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1209 UT_ASSERT_NOT_EFI_ERROR (Status);
1210 }
1211
1212 if (DirectMsgArgs.Arg0 != TPM2_FFA_SUCCESS_OK) {
1213 DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0));
1214 UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TPM2_FFA_SUCCESS_OK);
1215 } else {
1216 DEBUG ((DEBUG_INFO, "TPM Service Close Locality Success\n"));
1217 }
1218
1219 return UNIT_TEST_PASSED;
1220}
1221
1222/**
1223 This routine tests the TPM Service to request locality with the Ffa test SP.
1224**/
1225UNIT_TEST_STATUS
1226EFIAPI
1227FfaMiscTestTpmRequestLocality (
1228 IN UNIT_TEST_CONTEXT Context
1229 )
1230{
1231 DIRECT_MSG_ARGS DirectMsgArgs;
1232 EFI_STATUS Status;
1233 FFA_TEST_CONTEXT *FfaTestContext;
1234
1235 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
1236
1237 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1238 UT_ASSERT_NOT_NULL (FfaTestContext);
1239
1240 // Call the TPM Service to request locality0
1241 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1242 DirectMsgArgs.Arg0 = TPM2_FFA_START;
1243 DirectMsgArgs.Arg1 = TPM2_FFA_START_FUNC_QUALIFIER_LOCALITY;
1244 DirectMsgArgs.Arg2 = 0x00; // Locality Qualifier
1245 Status = ArmFfaLibMsgSendDirectReq2 (
1246 FfaTestContext->FfaTpm2ServicePartId,
1247 &gTpm2ServiceFfaGuid,
1248 &DirectMsgArgs
1249 );
1250 if (EFI_ERROR (Status)) {
1251 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1252 UT_ASSERT_NOT_EFI_ERROR (Status);
1253 }
1254
1255 if (DirectMsgArgs.Arg0 != TPM2_FFA_ERROR_DENIED) {
1256 DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0));
1257 UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TPM2_FFA_ERROR_DENIED);
1258 } else {
1259 DEBUG ((DEBUG_INFO, "TPM Service Rejected Request, Locality Closed\n"));
1260 }
1261
1262 return UNIT_TEST_PASSED;
1263}
1264
1265/**
1266 This routine tests the TPM Service to reopen locality with the Ffa test SP.
1267**/
1268UNIT_TEST_STATUS
1269EFIAPI
1270FfaMiscTestTpmReopenLocality (
1271 IN UNIT_TEST_CONTEXT Context
1272 )
1273{
1274 DIRECT_MSG_ARGS DirectMsgArgs;
1275 EFI_STATUS Status;
1276 FFA_TEST_CONTEXT *FfaTestContext;
1277
1278 DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__));
1279
1280 FfaTestContext = (FFA_TEST_CONTEXT *)Context;
1281 UT_ASSERT_NOT_NULL (FfaTestContext);
1282
1283 // Call the TPM Service to reopen locality0
1284 ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs));
1285 DirectMsgArgs.Arg0 = TPM2_FFA_START;
1286 DirectMsgArgs.Arg1 = 0x100; // Open Locality
1287 DirectMsgArgs.Arg2 = 0x00; // Locality Qualifier
1288 Status = ArmFfaLibMsgSendDirectReq2 (
1289 FfaTestContext->FfaTpm2ServicePartId,
1290 &gTpm2ServiceFfaGuid,
1291 &DirectMsgArgs
1292 );
1293 if (EFI_ERROR (Status)) {
1294 DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status));
1295 UT_ASSERT_NOT_EFI_ERROR (Status);
1296 }
1297
1298 if (DirectMsgArgs.Arg0 != TPM2_FFA_SUCCESS_OK) {
1299 DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0));
1300 UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TPM2_FFA_SUCCESS_OK);
1301 } else {
1302 DEBUG ((DEBUG_INFO, "TPM Service Open Locality Success\n"));
1303 }
1304
1305 return UNIT_TEST_PASSED;
1306}
1307
1308/**
1309 FfaPartitionTestAppEntry
1310
1311 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1312 @param[in] SystemTable A pointer to the EFI System Table.
1313
1314 @retval EFI_SUCCESS The entry point executed successfully.
1315 @retval other Some error occurred when executing this entry point.
1316
1317**/
1318EFI_STATUS
1319EFIAPI
1320FfaPartitionTestAppEntry (
1321 IN EFI_HANDLE ImageHandle,
1322 IN EFI_SYSTEM_TABLE *SystemTable
1323 )
1324{
1325 EFI_STATUS Status;
1326 UNIT_TEST_FRAMEWORK_HANDLE Fw = NULL;
1327 UNIT_TEST_SUITE_HANDLE Misc = NULL;
1328 FFA_TEST_CONTEXT FfaTestContext = { 0 };
1329
1330 DEBUG ((DEBUG_ERROR, "%a %a v%a\n", __FUNCTION__, UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));
1331
1332 // Start setting up the test framework for running the tests.
1333 Status = InitUnitTestFramework (&Fw, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION);
1334 if (EFI_ERROR (Status)) {
1335 DEBUG ((DEBUG_ERROR, "%a Failed in InitUnitTestFramework. Status = %r\n", __FUNCTION__, Status));
1336 goto Done;
1337 }
1338
1339 // Misc test suite for all tests.
1340 Status = CreateUnitTestSuite (&Misc, Fw, "FF-A Miscellaneous Test cases", "Ffa.Miscellaneous", NULL, NULL);
1341
1342 if (EFI_ERROR (Status)) {
1343 DEBUG ((DEBUG_ERROR, "%a Failed in CreateUnitTestSuite for TestSuite\n", __FUNCTION__));
1344 Status = EFI_OUT_OF_RESOURCES;
1345 goto Done;
1346 }
1347
1348 Status = AddTestCase (
1349 Misc,
1350 "Verify FF-A framework version",
1351 "Ffa.Miscellaneous.VerifyVersion",
1352 FfaMiscVerifyVersion,
1353 NULL,
1354 NULL,
1355 &FfaTestContext
1356 );
1357 if (EFI_ERROR (Status)) {
1358 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for VerifyVersion\n", __FUNCTION__));
1359 Status = EFI_OUT_OF_RESOURCES;
1360 goto Done;
1361 }
1362
1363 Status = AddTestCase (
1364 Misc,
1365 "Verify Partition Info via registers",
1366 "Ffa.Miscellaneous.VerifyPartitionInfoRegs",
1367 FfaMiscGetPartitionInfoRegs,
1368 NULL,
1369 NULL,
1370 &FfaTestContext
1371 );
1372 if (EFI_ERROR (Status)) {
1373 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for VerifyPartitionInfoRegs\n", __FUNCTION__));
1374 Status = EFI_OUT_OF_RESOURCES;
1375 goto Done;
1376 }
1377
1378 Status = AddTestCase (
1379 Misc,
1380 "Verify Partition Info via Rx/Tx buffers",
1381 "Ffa.Miscellaneous.VerifyPartitionInfo",
1382 FfaMiscGetPartitionInfo,
1383 NULL,
1384 NULL,
1385 &FfaTestContext
1386 );
1387 if (EFI_ERROR (Status)) {
1388 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for VerifyPartitionInfo\n", __FUNCTION__));
1389 Status = EFI_OUT_OF_RESOURCES;
1390 goto Done;
1391 }
1392
1393 Status = AddTestCase (
1394 Misc,
1395 "Verify FF-A Ffa test SP notifications",
1396 "Ffa.Miscellaneous.SetupNotifications",
1397 FfaMiscSetupNotifications,
1398 CheckTestService,
1399 NULL,
1400 &FfaTestContext
1401 );
1402 if (EFI_ERROR (Status)) {
1403 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for SetupNotifications\n", __FUNCTION__));
1404 Status = EFI_OUT_OF_RESOURCES;
1405 goto Done;
1406 }
1407
1408 Status = AddTestCase (
1409 Misc,
1410 "Verify FF-A Ffa test SP notifications",
1411 "Ffa.Miscellaneous.RegisterNotifications",
1412 FfaMiscRegisterNotifications,
1413 NULL,
1414 NULL,
1415 &FfaTestContext
1416 );
1417 if (EFI_ERROR (Status)) {
1418 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for RegisterNotifications\n", __FUNCTION__));
1419 Status = EFI_OUT_OF_RESOURCES;
1420 goto Done;
1421 }
1422
1423 //
1424 // Test interpartition communication with the Ffa test SP.
1425 // These tests will only run if the Ffa test SP is available.
1426 // As a system level test, the order of the tests is important as the tests will
1427 // will corporate the states of inter-partition service to test the Ffa test SP.
1428 //
1429 Status = AddTestCase (
1430 Misc,
1431 "Verify Ffa Inter Partition",
1432 "Ffa.Miscellaneous.FfaTestInterPartitionNormal",
1433 FfaMiscTestInterPartitionNormal,
1434 CheckNotificationService,
1435 NULL,
1436 &FfaTestContext
1437 );
1438 if (EFI_ERROR (Status)) {
1439 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionNormal\n", __FUNCTION__));
1440 Status = EFI_OUT_OF_RESOURCES;
1441 goto Done;
1442 }
1443
1444 Status = AddTestCase (
1445 Misc,
1446 "Verify Ffa Inter Partition",
1447 "Ffa.Miscellaneous.FfaTestInterPartitionSecondary",
1448 FfaMiscTestInterPartitionSecondary,
1449 CheckNotificationService,
1450 NULL,
1451 &FfaTestContext
1452 );
1453 if (EFI_ERROR (Status)) {
1454 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionSecondary\n", __FUNCTION__));
1455 Status = EFI_OUT_OF_RESOURCES;
1456 goto Done;
1457 }
1458
1459 Status = AddTestCase (
1460 Misc,
1461 "Verify Ffa Inter Partition",
1462 "Ffa.Miscellaneous.FfaTestInterPartitionDuplicateCookie",
1463 FfaMiscTestInterPartitionDuplicateCookie,
1464 CheckNotificationService,
1465 NULL,
1466 &FfaTestContext
1467 );
1468 if (EFI_ERROR (Status)) {
1469 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionDuplicateCookie\n", __FUNCTION__));
1470 Status = EFI_OUT_OF_RESOURCES;
1471 goto Done;
1472 }
1473
1474 Status = AddTestCase (
1475 Misc,
1476 "Verify Ffa Inter Partition",
1477 "Ffa.Miscellaneous.FfaTestInterPartitionInvalidDuplicateId",
1478 FfaMiscTestInterPartitionInvalidDuplicateId,
1479 CheckNotificationService,
1480 NULL,
1481 &FfaTestContext
1482 );
1483 if (EFI_ERROR (Status)) {
1484 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionInvalidDuplicateId\n", __FUNCTION__));
1485 Status = EFI_OUT_OF_RESOURCES;
1486 goto Done;
1487 }
1488
1489 Status = AddTestCase (
1490 Misc,
1491 "Verify Ffa Inter Partition",
1492 "Ffa.Miscellaneous.FfaTestInterPartitionInvalidMappingCountMin",
1493 FfaMiscTestInterPartitionInvalidMappingCountMin,
1494 CheckNotificationService,
1495 NULL,
1496 &FfaTestContext
1497 );
1498 if (EFI_ERROR (Status)) {
1499 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionInvalidMappingCountMin\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.FfaTestInterPartitionInvalidMappingCountMax",
1508 FfaMiscTestInterPartitionInvalidMappingCountMax,
1509 CheckNotificationService,
1510 NULL,
1511 &FfaTestContext
1512 );
1513 if (EFI_ERROR (Status)) {
1514 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionInvalidMappingCountMax\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.FfaTestInterPartitionUnregisterNormal",
1523 FfaMiscTestInterPartitionUnregisterNormal,
1524 CheckNotificationService,
1525 NULL,
1526 &FfaTestContext
1527 );
1528 if (EFI_ERROR (Status)) {
1529 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionUnregisterNormal\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.FfaTestInterPartitionUnregisterInvalidCookie",
1538 FfaMiscTestInterPartitionUnregisterInvalidCookie,
1539 CheckNotificationService,
1540 NULL,
1541 &FfaTestContext
1542 );
1543 if (EFI_ERROR (Status)) {
1544 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionUnregisterInvalidCookie\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.FfaTestInterPartitionUnregisterInvalidId",
1553 FfaMiscTestInterPartitionUnregisterInvalidId,
1554 CheckNotificationService,
1555 NULL,
1556 &FfaTestContext
1557 );
1558 if (EFI_ERROR (Status)) {
1559 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionUnregisterInvalidId\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.FfaTestInterPartitionUnregisterInvalidUuid",
1568 FfaMiscTestInterPartitionUnregisterInvalidUuid,
1569 CheckNotificationService,
1570 NULL,
1571 &FfaTestContext
1572 );
1573 if (EFI_ERROR (Status)) {
1574 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionUnregisterInvalidUuid\n", __FUNCTION__));
1575 Status = EFI_OUT_OF_RESOURCES;
1576 goto Done;
1577 }
1578
1579 Status = AddTestCase (
1580 Misc,
1581 "Verify Ffa Notification Event",
1582 "Ffa.Miscellaneous.FfaTestNotificationEvent",
1583 FfaMiscTestNotificationEvent,
1584 CheckTestService,
1585 NULL,
1586 &FfaTestContext
1587 );
1588 if (EFI_ERROR (Status)) {
1589 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestNotificationEvent\n", __FUNCTION__));
1590 Status = EFI_OUT_OF_RESOURCES;
1591 goto Done;
1592 }
1593
1594 //
1595 // As a system level test, the order of the tests is important as the tests will
1596 // will corporate the states of TPM service to test the Ffa test SP.
1597 //
1598 Status = AddTestCase (
1599 Misc,
1600 "Verify Ffa TPM Service",
1601 "Ffa.Miscellaneous.FfaTestTpmGetVersion",
1602 FfaMiscTestTpmGetVersion,
1603 CheckTPMService,
1604 NULL,
1605 &FfaTestContext
1606 );
1607 if (EFI_ERROR (Status)) {
1608 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestTpmGetVersion\n", __FUNCTION__));
1609 Status = EFI_OUT_OF_RESOURCES;
1610 goto Done;
1611 }
1612
1613 Status = AddTestCase (
1614 Misc,
1615 "Verify Ffa TPM Service",
1616 "Ffa.Miscellaneous.FfaTestTpmCloseLocality",
1617 FfaMiscTestTpmCloseLocality,
1618 CheckTPMService,
1619 NULL,
1620 &FfaTestContext
1621 );
1622 if (EFI_ERROR (Status)) {
1623 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestTpmCloseLocality\n", __FUNCTION__));
1624 Status = EFI_OUT_OF_RESOURCES;
1625 goto Done;
1626 }
1627
1628 Status = AddTestCase (
1629 Misc,
1630 "Verify Ffa TPM Service",
1631 "Ffa.Miscellaneous.FfaTestTpmRequestLocality",
1632 FfaMiscTestTpmRequestLocality,
1633 CheckTPMService,
1634 NULL,
1635 &FfaTestContext
1636 );
1637 if (EFI_ERROR (Status)) {
1638 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestTpmRequestLocality\n", __FUNCTION__));
1639 Status = EFI_OUT_OF_RESOURCES;
1640 goto Done;
1641 }
1642
1643 Status = AddTestCase (
1644 Misc,
1645 "Verify Ffa TPM Service",
1646 "Ffa.Miscellaneous.FfaTestTpmReopenLocality",
1647 FfaMiscTestTpmReopenLocality,
1648 CheckTPMService,
1649 NULL,
1650 &FfaTestContext
1651 );
1652 if (EFI_ERROR (Status)) {
1653 DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestTpmReopenLocality\n", __FUNCTION__));
1654 Status = EFI_OUT_OF_RESOURCES;
1655 goto Done;
1656 }
1657
1658 //
1659 // Execute the tests.
1660 //
1661 Status = RunAllTestSuites (Fw);
1662
1663Done:
1664 if (Fw != NULL) {
1665 FreeUnitTestFramework (Fw);
1666 }
1667
1668 DEBUG ((DEBUG_INFO, "%a exit - %r\n", __FUNCTION__, Status));
1669 return Status;
1670}
1671