microsoft/mu_feature_ffa
Publicmirrored fromhttps://github.com/microsoft/mu_feature_ffaAvailable
FfaFeaturePkg/Applications/FfaPartitionTest/FfaPartitionTestApp.c
1662lines · modecode
| 1 | /** @file |
| 2 | FfaPartitionTestApp.c |
| 3 | |
| 4 | This is a Unit Test for the test FFA service library. |
| 5 | |
| 6 | Copyright (C) Microsoft Corporation. All rights reserved. |
| 7 | SPDX-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 | |
| 40 | typedef 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 | |
| 52 | UINT16 FfaPartId; |
| 53 | EFI_HARDWARE_INTERRUPT_PROTOCOL *gInterrupt; |
| 54 | |
| 55 | /// ================================================================================================ |
| 56 | /// ================================================================================================ |
| 57 | /// |
| 58 | /// HELPER FUNCTIONS |
| 59 | /// |
| 60 | /// ================================================================================================ |
| 61 | /// ================================================================================================ |
| 62 | |
| 63 | /** |
| 64 | EFI_CPU_INTERRUPT_HANDLER that is called when a processor interrupt occurs. |
| 65 | |
| 66 | @param InterruptType Defines the type of interrupt or exception that |
| 67 | occurred on the processor. This parameter is |
| 68 | processor architecture specific. |
| 69 | @param SystemContext A pointer to the processor context when |
| 70 | the interrupt occurred on the processor. |
| 71 | |
| 72 | @return None |
| 73 | |
| 74 | **/ |
| 75 | VOID |
| 76 | EFIAPI |
| 77 | ApIrqInterruptHandler ( |
| 78 | IN HARDWARE_INTERRUPT_SOURCE Source, |
| 79 | IN EFI_SYSTEM_CONTEXT SystemContext |
| 80 | ) |
| 81 | { |
| 82 | EFI_STATUS Status; |
| 83 | UINT64 Bitmap; |
| 84 | |
| 85 | DEBUG ((DEBUG_INFO, "Received IRQ interrupt %d!\n", Source)); |
| 86 | |
| 87 | // Then register this test app to receive notifications from the Ffa test SP |
| 88 | Status = FfaNotificationGet (0, ARM_FFA_NOTIFICATION_FLAG_BITMAP_SP, &Bitmap); |
| 89 | if (EFI_ERROR (Status)) { |
| 90 | DEBUG ((DEBUG_ERROR, "Unable to notification get with FF-A Ffa test SP (%r).\n", Status)); |
| 91 | } else { |
| 92 | DEBUG ((DEBUG_INFO, "Got notification from FF-A Ffa test SP with VM bitmap %x.\n", Bitmap)); |
| 93 | } |
| 94 | |
| 95 | gInterrupt->EndOfInterrupt (gInterrupt, Source); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | Helper prerequisite function to proceed with Inter-partition communication tests. |
| 100 | |
| 101 | @retval UNIT_TEST_PASSED Unit test case prerequisites |
| 102 | are met. |
| 103 | @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be skipped. |
| 104 | **/ |
| 105 | UNIT_TEST_STATUS |
| 106 | EFIAPI |
| 107 | CheckNotificationService ( |
| 108 | IN UNIT_TEST_CONTEXT Context |
| 109 | ) |
| 110 | { |
| 111 | UNIT_TEST_STATUS utStatus = UNIT_TEST_RUNNING; |
| 112 | FFA_TEST_CONTEXT *FfaTestContext; |
| 113 | |
| 114 | FfaTestContext = (FFA_TEST_CONTEXT *)Context; |
| 115 | if (FfaTestContext == NULL) { |
| 116 | DEBUG ((DEBUG_ERROR, "%a: FfaTestContext is NULL.\n", __func__)); |
| 117 | UT_ASSERT_NOT_NULL (FfaTestContext); |
| 118 | } |
| 119 | |
| 120 | if (!FfaTestContext->IsNotificationServiceAvailable) { |
| 121 | DEBUG ((DEBUG_INFO, "%a: Notification Service not available, skipping test.\n", __func__)); |
| 122 | utStatus = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET; |
| 123 | } else { |
| 124 | utStatus = UNIT_TEST_PASSED; |
| 125 | } |
| 126 | |
| 127 | return utStatus; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | Helper prerequisite function to proceed with Test service related cases. |
| 132 | |
| 133 | @retval UNIT_TEST_PASSED Unit test case prerequisites |
| 134 | are met. |
| 135 | @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be skipped. |
| 136 | **/ |
| 137 | UNIT_TEST_STATUS |
| 138 | EFIAPI |
| 139 | CheckTestService ( |
| 140 | IN UNIT_TEST_CONTEXT Context |
| 141 | ) |
| 142 | { |
| 143 | UNIT_TEST_STATUS utStatus = UNIT_TEST_RUNNING; |
| 144 | FFA_TEST_CONTEXT *FfaTestContext; |
| 145 | |
| 146 | FfaTestContext = (FFA_TEST_CONTEXT *)Context; |
| 147 | if (FfaTestContext == NULL) { |
| 148 | DEBUG ((DEBUG_ERROR, "%a: FfaTestContext is NULL.\n", __func__)); |
| 149 | UT_ASSERT_NOT_NULL (FfaTestContext); |
| 150 | } |
| 151 | |
| 152 | if (!FfaTestContext->IsTestServiceAvailable) { |
| 153 | DEBUG ((DEBUG_INFO, "%a: Test Service not available, skipping test.\n", __func__)); |
| 154 | utStatus = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET; |
| 155 | } else { |
| 156 | utStatus = UNIT_TEST_PASSED; |
| 157 | } |
| 158 | |
| 159 | return utStatus; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | Helper prerequisite function to proceed with TPM service related cases. |
| 164 | |
| 165 | @retval UNIT_TEST_PASSED Unit test case prerequisites |
| 166 | are met. |
| 167 | @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be skipped. |
| 168 | **/ |
| 169 | UNIT_TEST_STATUS |
| 170 | EFIAPI |
| 171 | CheckTPMService ( |
| 172 | IN UNIT_TEST_CONTEXT Context |
| 173 | ) |
| 174 | { |
| 175 | UNIT_TEST_STATUS utStatus = UNIT_TEST_RUNNING; |
| 176 | FFA_TEST_CONTEXT *FfaTestContext; |
| 177 | |
| 178 | FfaTestContext = (FFA_TEST_CONTEXT *)Context; |
| 179 | if (FfaTestContext == NULL) { |
| 180 | DEBUG ((DEBUG_ERROR, "%a: FfaTestContext is NULL.\n", __func__)); |
| 181 | UT_ASSERT_NOT_NULL (FfaTestContext); |
| 182 | } |
| 183 | |
| 184 | if (!FfaTestContext->IsTpm2ServiceAvailable) { |
| 185 | DEBUG ((DEBUG_INFO, "%a: TPM2 Service not available, skipping test.\n", __func__)); |
| 186 | utStatus = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET; |
| 187 | } else { |
| 188 | #ifdef TPM2_ENABLE |
| 189 | utStatus = UNIT_TEST_PASSED; |
| 190 | #else |
| 191 | DEBUG ((DEBUG_INFO, "%a: TPM2 Service is not enabled, skipping test.\n", __func__)); |
| 192 | utStatus = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET; |
| 193 | #endif // TPM2_ENABLE |
| 194 | } |
| 195 | |
| 196 | return utStatus; |
| 197 | } |
| 198 | |
| 199 | /// ================================================================================================ |
| 200 | /// ================================================================================================ |
| 201 | /// |
| 202 | /// TEST CASES |
| 203 | /// |
| 204 | /// ================================================================================================ |
| 205 | /// ================================================================================================ |
| 206 | |
| 207 | /** |
| 208 | This routine queries the version of FF-A framework, it must be at least the version |
| 209 | required by this UEFI codebase. |
| 210 | **/ |
| 211 | UNIT_TEST_STATUS |
| 212 | EFIAPI |
| 213 | FfaMiscVerifyVersion ( |
| 214 | IN UNIT_TEST_CONTEXT Context |
| 215 | ) |
| 216 | { |
| 217 | UNIT_TEST_STATUS utStatus = UNIT_TEST_RUNNING; |
| 218 | EFI_STATUS Status = EFI_SUCCESS; |
| 219 | UINT16 CurrentMajorVersion; |
| 220 | UINT16 CurrentMinorVersion; |
| 221 | |
| 222 | DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__)); |
| 223 | |
| 224 | // Query FF-A version to make sure FF-A is supported |
| 225 | Status = ArmFfaLibGetVersion ( |
| 226 | ARM_FFA_MAJOR_VERSION, |
| 227 | ARM_FFA_MINOR_VERSION, |
| 228 | &CurrentMajorVersion, |
| 229 | &CurrentMinorVersion |
| 230 | ); |
| 231 | if (EFI_ERROR (Status)) { |
| 232 | DEBUG ((DEBUG_ERROR, "Failed to get FF-A version. Status: %r\n", Status)); |
| 233 | UT_ASSERT_NOT_EFI_ERROR (Status); |
| 234 | } |
| 235 | |
| 236 | DEBUG ((DEBUG_INFO, "%a FF-A version: %d.%d\n", __func__, CurrentMajorVersion, CurrentMinorVersion)); |
| 237 | |
| 238 | UT_ASSERT_TRUE ( |
| 239 | (CurrentMajorVersion >= ARM_FFA_MAJOR_VERSION) && |
| 240 | (CurrentMinorVersion >= ARM_FFA_MINOR_VERSION) |
| 241 | ); |
| 242 | |
| 243 | utStatus = UNIT_TEST_PASSED; |
| 244 | UT_LOG_INFO ("FF-A version is supported: %d.%d", CurrentMajorVersion, CurrentMinorVersion); |
| 245 | return utStatus; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | This routine retrieves the partition information of the Ffa test SP and prints it. |
| 250 | **/ |
| 251 | UNIT_TEST_STATUS |
| 252 | EFIAPI |
| 253 | FfaMiscGetPartitionInfoRegs ( |
| 254 | IN UNIT_TEST_CONTEXT Context |
| 255 | ) |
| 256 | { |
| 257 | EFI_STATUS Status = EFI_SUCCESS; |
| 258 | EFI_FFA_PART_INFO_DESC FfaPartInfo; |
| 259 | ARM_SMC_ARGS SmcArgs; |
| 260 | UINT32 Count; |
| 261 | UINTN Index; |
| 262 | FFA_TEST_CONTEXT *FfaTestContext; |
| 263 | EFI_GUID *GuidsOfInterest[] = { |
| 264 | &gEfiMmCommunication2ProtocolGuid, |
| 265 | &gEfiTestServiceFfaGuid, |
| 266 | &gTpm2ServiceFfaGuid, |
| 267 | &gEfiNotificationServiceFfaGuid, |
| 268 | }; |
| 269 | |
| 270 | DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__)); |
| 271 | |
| 272 | FfaTestContext = (FFA_TEST_CONTEXT *)Context; |
| 273 | if (FfaTestContext == NULL) { |
| 274 | DEBUG ((DEBUG_ERROR, "%a: FfaTestContext is NULL.\n", __func__)); |
| 275 | UT_ASSERT_NOT_NULL (FfaTestContext); |
| 276 | } |
| 277 | |
| 278 | // |
| 279 | // Given the complexity of potentially having multiple partitions, we will |
| 280 | // just try to retrieve the partition information of the STMM SP, Test SP and TPM |
| 281 | // SP. The non-STMM SP availability will be checked in the next test case. |
| 282 | // |
| 283 | for (Index = 0; Index < ARRAY_SIZE (GuidsOfInterest); Index++) { |
| 284 | // Get the partition information of the STMM SP |
| 285 | ZeroMem (&SmcArgs, sizeof (SmcArgs)); |
| 286 | Count = 1; // We expect only one partition info |
| 287 | DEBUG ((DEBUG_INFO, "%a: Querying partition info for %g...\n", __func__, GuidsOfInterest[Index])); |
| 288 | Status = FfaPartitionInfoGetRegs (GuidsOfInterest[Index], 0, NULL, &Count, (EFI_FFA_PART_INFO_DESC *)&SmcArgs.Arg3); |
| 289 | if (EFI_ERROR (Status)) { |
| 290 | DEBUG ((DEBUG_ERROR, "Failed to get FF-A partition info. Status: %r\n", Status)); |
| 291 | } else { |
| 292 | CopyMem (&FfaPartInfo, &SmcArgs.Arg3, sizeof (EFI_FFA_PART_INFO_DESC)); |
| 293 | } |
| 294 | |
| 295 | if (CompareGuid (GuidsOfInterest[Index], &gEfiMmCommunication2ProtocolGuid)) { |
| 296 | if (EFI_ERROR (Status)) { |
| 297 | // If we are querying the MM Communication protocol, we need to bail. |
| 298 | DEBUG ((DEBUG_INFO, "%a MM Communication protocol not found, fatal error.\n", __func__)); |
| 299 | UT_ASSERT_NOT_EFI_ERROR (Status); |
| 300 | } else { |
| 301 | FfaTestContext->IsMmCommunicationServiceAvailable = TRUE; |
| 302 | FfaTestContext->FfaMmCommunicationPartId = FfaPartInfo.PartitionId; |
| 303 | } |
| 304 | } else if (CompareGuid (GuidsOfInterest[Index], &gEfiTestServiceFfaGuid)) { |
| 305 | if (EFI_ERROR (Status)) { |
| 306 | // If we are querying the Test Service, we can skip it. |
| 307 | DEBUG ((DEBUG_INFO, "%a Test Service not found, skipping.\n", __func__)); |
| 308 | UT_LOG_WARNING ("Test Service not found, skipping."); |
| 309 | continue; |
| 310 | } else { |
| 311 | FfaTestContext->IsTestServiceAvailable = TRUE; |
| 312 | FfaTestContext->FfaTestServicePartId = FfaPartInfo.PartitionId; |
| 313 | } |
| 314 | } else if (CompareGuid (GuidsOfInterest[Index], &gTpm2ServiceFfaGuid)) { |
| 315 | if (EFI_ERROR (Status)) { |
| 316 | // If we are querying the TPM Service, we can skip it. |
| 317 | DEBUG ((DEBUG_INFO, "%a TPM Service not found, skipping.\n", __func__)); |
| 318 | UT_LOG_WARNING ("TPM Service not found, skipping."); |
| 319 | continue; |
| 320 | } else { |
| 321 | FfaTestContext->IsTpm2ServiceAvailable = TRUE; |
| 322 | FfaTestContext->FfaTpm2ServicePartId = FfaPartInfo.PartitionId; |
| 323 | } |
| 324 | } else if (CompareGuid (GuidsOfInterest[Index], &gEfiNotificationServiceFfaGuid)) { |
| 325 | if (EFI_ERROR (Status)) { |
| 326 | // If we are querying the Notification Service, we can skip it. |
| 327 | DEBUG ((DEBUG_INFO, "%a Notification Service not found, skipping.\n", __func__)); |
| 328 | UT_LOG_WARNING ("Notification Service not found, skipping."); |
| 329 | continue; |
| 330 | } else { |
| 331 | FfaTestContext->IsNotificationServiceAvailable = TRUE; |
| 332 | FfaTestContext->FfaNotificationServicePartId = FfaPartInfo.PartitionId; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | DEBUG ((DEBUG_INFO, "FF-A Secure Partition Info:\n")); |
| 337 | DEBUG (( |
| 338 | DEBUG_INFO, |
| 339 | "\tID = 0x%lx, Execution contexts = %d, Properties = 0x%lx.\n", |
| 340 | FfaPartInfo.PartitionId, |
| 341 | FfaPartInfo.ExecContextCountOrProxyPartitionId, |
| 342 | FfaPartInfo.PartitionProps |
| 343 | )); |
| 344 | |
| 345 | DEBUG (( |
| 346 | DEBUG_INFO, |
| 347 | "\tSP Guid = %g.\n", |
| 348 | FfaPartInfo.PartitionUuid |
| 349 | )); |
| 350 | UT_ASSERT_MEM_EQUAL ( |
| 351 | &FfaPartInfo.PartitionUuid, |
| 352 | &gZeroGuid, |
| 353 | sizeof (EFI_GUID) |
| 354 | ); |
| 355 | } |
| 356 | |
| 357 | UT_ASSERT_TRUE (FfaTestContext->IsMmCommunicationServiceAvailable); |
| 358 | |
| 359 | return UNIT_TEST_PASSED; |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | This routine retrieves the partition information of Ffa SPs through Rx/Tx buffer |
| 364 | and prints them. |
| 365 | **/ |
| 366 | UNIT_TEST_STATUS |
| 367 | EFIAPI |
| 368 | FfaMiscGetPartitionInfo ( |
| 369 | IN UNIT_TEST_CONTEXT Context |
| 370 | ) |
| 371 | { |
| 372 | EFI_STATUS Status = EFI_SUCCESS; |
| 373 | EFI_FFA_PART_INFO_DESC FfaPartInfo; |
| 374 | UINT32 Count; |
| 375 | UINT32 Size; |
| 376 | |
| 377 | // Discover the Ffa test SP after converting the EFI_GUID to a format TF-A will |
| 378 | // understand. |
| 379 | Status = ArmFfaLibPartitionInfoGet (&gEfiMmCommunication2ProtocolGuid, 0, &Count, &Size); |
| 380 | if (EFI_ERROR (Status)) { |
| 381 | DEBUG ((DEBUG_ERROR, "Unable to discover FF-A test SP (%r).\n", Status)); |
| 382 | UT_ASSERT_NOT_EFI_ERROR (Status); |
| 383 | } |
| 384 | |
| 385 | // Retrieve the partition information from the returned registers |
| 386 | CopyMem (&FfaPartInfo, (VOID *)PcdGet64 (PcdFfaRxBuffer), sizeof (EFI_FFA_PART_INFO_DESC)); |
| 387 | |
| 388 | DEBUG ((DEBUG_INFO, "Discovered FF-A test SP.\n")); |
| 389 | DEBUG (( |
| 390 | DEBUG_INFO, |
| 391 | "\tID = 0x%lx, Execution contexts = %d, Properties = 0x%lx.\n", |
| 392 | FfaPartInfo.PartitionId, |
| 393 | FfaPartInfo.ExecContextCountOrProxyPartitionId, |
| 394 | FfaPartInfo.PartitionProps |
| 395 | )); |
| 396 | UT_ASSERT_MEM_EQUAL ( |
| 397 | &FfaPartInfo.PartitionUuid, |
| 398 | &gZeroGuid, |
| 399 | sizeof (EFI_GUID) |
| 400 | ); |
| 401 | DEBUG (( |
| 402 | DEBUG_INFO, |
| 403 | "\tSP Guid = %g.\n", |
| 404 | FfaPartInfo.PartitionUuid |
| 405 | )); |
| 406 | |
| 407 | return UNIT_TEST_PASSED; |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | This routine sets up the notifications for the Ffa test SP and verifies |
| 412 | that the notifications are working correctly. |
| 413 | **/ |
| 414 | UNIT_TEST_STATUS |
| 415 | EFIAPI |
| 416 | FfaMiscSetupNotifications ( |
| 417 | IN UNIT_TEST_CONTEXT Context |
| 418 | ) |
| 419 | { |
| 420 | EFI_STATUS Status = EFI_SUCCESS; |
| 421 | UINTN BindBitPos; |
| 422 | FFA_TEST_CONTEXT *FfaTestContext; |
| 423 | |
| 424 | DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__)); |
| 425 | |
| 426 | FfaTestContext = (FFA_TEST_CONTEXT *)Context; |
| 427 | UT_ASSERT_NOT_NULL (FfaTestContext); |
| 428 | |
| 429 | // |
| 430 | // Should be able to handle notification flow now. |
| 431 | // |
| 432 | // Now register UEFI to receive notifications by creating notification bitmaps |
| 433 | Status = FfaNotificationBitmapCreate (1); |
| 434 | if (EFI_ERROR (Status)) { |
| 435 | DEBUG ((DEBUG_ERROR, "Unable to create notification bitmap with FF-A Ffa test SP (%r).\n", Status)); |
| 436 | UT_ASSERT_NOT_EFI_ERROR (Status); |
| 437 | } |
| 438 | |
| 439 | // Then register this test app to receive notifications from the Ffa test SP |
| 440 | BindBitPos = 0x02; |
| 441 | FfaNotificationBind (FfaTestContext->FfaTestServicePartId, 0, (1 << BindBitPos)); |
| 442 | if (EFI_ERROR (Status)) { |
| 443 | DEBUG ((DEBUG_ERROR, "Unable to bind notification with FF-A Ffa test SP (%r).\n", Status)); |
| 444 | UT_ASSERT_NOT_EFI_ERROR (Status); |
| 445 | } |
| 446 | |
| 447 | DEBUG ((DEBUG_INFO, "Binding Bit%x - Value: %x Successful.\n", BindBitPos, (1 << BindBitPos))); |
| 448 | |
| 449 | return UNIT_TEST_PASSED; |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | This routine registers the notifications for the Ffa test SP and verifies |
| 454 | that the notifications are working correctly. |
| 455 | **/ |
| 456 | UNIT_TEST_STATUS |
| 457 | EFIAPI |
| 458 | FfaMiscRegisterNotifications ( |
| 459 | IN UNIT_TEST_CONTEXT Context |
| 460 | ) |
| 461 | { |
| 462 | EFI_STATUS Status = EFI_SUCCESS; |
| 463 | UINT64 Bitmap; |
| 464 | UINTN SriIndex; |
| 465 | UINTN Dummy; |
| 466 | |
| 467 | DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__)); |
| 468 | |
| 469 | // Followed by querying which notification ID is supported by the Ffa test SP |
| 470 | Status = ArmFfaLibGetFeatures (ARM_FFA_FEATURE_ID_SCHEDULE_RECEIVER_INTERRUPT, 0, &SriIndex, &Dummy); |
| 471 | if (EFI_ERROR (Status)) { |
| 472 | DEBUG ((DEBUG_ERROR, "Unable to query feature SRI number with FF-A Ffa test SP (%r).\n", Status)); |
| 473 | UT_ASSERT_NOT_EFI_ERROR (Status); |
| 474 | } |
| 475 | |
| 476 | DEBUG ((DEBUG_INFO, "Received feature SRI number with FF-A Ffa test SP (%d).\n", SriIndex)); |
| 477 | |
| 478 | // Register the IRQ handler for the FF-A Ffa test SP |
| 479 | Status = gBS->LocateProtocol (&gHardwareInterruptProtocolGuid, NULL, (VOID **)&gInterrupt); |
| 480 | if (!EFI_ERROR (Status)) { |
| 481 | Status = gInterrupt->RegisterInterruptSource (gInterrupt, SriIndex, ApIrqInterruptHandler); |
| 482 | if (EFI_ERROR (Status)) { |
| 483 | DEBUG ((DEBUG_ERROR, "Unable to register notification (%r).\n", Status)); |
| 484 | UT_ASSERT_NOT_EFI_ERROR (Status); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | DEBUG ((DEBUG_INFO, "Registered notification with FF-A Ffa test SP with VM bitmap %x.\n", Bitmap)); |
| 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 | **/ |
| 497 | UNIT_TEST_STATUS |
| 498 | EFIAPI |
| 499 | FfaMiscTestInterPartitionNormal ( |
| 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 | **/ |
| 576 | UNIT_TEST_STATUS |
| 577 | EFIAPI |
| 578 | FfaMiscTestInterPartitionSecondary ( |
| 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 | **/ |
| 645 | UNIT_TEST_STATUS |
| 646 | EFIAPI |
| 647 | FfaMiscTestInterPartitionDuplicateCookie ( |
| 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 | **/ |
| 704 | UNIT_TEST_STATUS |
| 705 | EFIAPI |
| 706 | FfaMiscTestInterPartitionInvalidDuplicateId ( |
| 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 | **/ |
| 763 | UNIT_TEST_STATUS |
| 764 | EFIAPI |
| 765 | FfaMiscTestInterPartitionInvalidMappingCountMin ( |
| 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 | **/ |
| 814 | UNIT_TEST_STATUS |
| 815 | EFIAPI |
| 816 | FfaMiscTestInterPartitionInvalidMappingCountMax ( |
| 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 | **/ |
| 865 | UNIT_TEST_STATUS |
| 866 | EFIAPI |
| 867 | FfaMiscTestInterPartitionUnregisterNormal ( |
| 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 | **/ |
| 924 | UNIT_TEST_STATUS |
| 925 | EFIAPI |
| 926 | FfaMiscTestInterPartitionUnregisterInvalidCookie ( |
| 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 | **/ |
| 983 | UNIT_TEST_STATUS |
| 984 | EFIAPI |
| 985 | FfaMiscTestInterPartitionUnregisterInvalidId ( |
| 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 | **/ |
| 1042 | UNIT_TEST_STATUS |
| 1043 | EFIAPI |
| 1044 | FfaMiscTestInterPartitionUnregisterInvalidUuid ( |
| 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 | **/ |
| 1088 | UNIT_TEST_STATUS |
| 1089 | EFIAPI |
| 1090 | FfaMiscTestNotificationEvent ( |
| 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 | // Test a Notification Event |
| 1104 | ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs)); |
| 1105 | DirectMsgArgs.Arg0 = TEST_OPCODE_TEST_NOTIFICATION; |
| 1106 | DirectMsgArgs.Arg1 = 0xba7aff2eb1eac765; |
| 1107 | DirectMsgArgs.Arg2 = 0xb710b3a359f64054; // Battery Service |
| 1108 | /* IMPORTANT NOTE: Only bit 2 has been bound, test needs to match binding call */ |
| 1109 | DirectMsgArgs.Arg3 = 0x02; // Cookie2 = ID2 = BitPos2 |
| 1110 | Status = ArmFfaLibMsgSendDirectReq2 ( |
| 1111 | FfaTestContext->FfaTestServicePartId, |
| 1112 | &gEfiTestServiceFfaGuid, |
| 1113 | &DirectMsgArgs |
| 1114 | ); |
| 1115 | if (EFI_ERROR (Status)) { |
| 1116 | DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status)); |
| 1117 | UT_ASSERT_NOT_EFI_ERROR (Status); |
| 1118 | } |
| 1119 | |
| 1120 | if (DirectMsgArgs.Arg0 != TEST_STATUS_SUCCESS) { |
| 1121 | DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0)); |
| 1122 | UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TEST_STATUS_SUCCESS); |
| 1123 | } else { |
| 1124 | DEBUG ((DEBUG_INFO, "Test Service Notification Event Success\n")); |
| 1125 | } |
| 1126 | |
| 1127 | return UNIT_TEST_PASSED; |
| 1128 | } |
| 1129 | |
| 1130 | /** |
| 1131 | This routine tests the TPM version retrieval with the Ffa test SP. |
| 1132 | **/ |
| 1133 | UNIT_TEST_STATUS |
| 1134 | EFIAPI |
| 1135 | FfaMiscTestTpmGetVersion ( |
| 1136 | IN UNIT_TEST_CONTEXT Context |
| 1137 | ) |
| 1138 | { |
| 1139 | DIRECT_MSG_ARGS DirectMsgArgs; |
| 1140 | EFI_STATUS Status; |
| 1141 | FFA_TEST_CONTEXT *FfaTestContext; |
| 1142 | |
| 1143 | DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__)); |
| 1144 | |
| 1145 | FfaTestContext = (FFA_TEST_CONTEXT *)Context; |
| 1146 | UT_ASSERT_NOT_NULL (FfaTestContext); |
| 1147 | |
| 1148 | // Call the TPM Service get_interface_version |
| 1149 | ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs)); |
| 1150 | DirectMsgArgs.Arg0 = TPM2_FFA_GET_INTERFACE_VERSION; |
| 1151 | Status = ArmFfaLibMsgSendDirectReq2 ( |
| 1152 | FfaTestContext->FfaTpm2ServicePartId, |
| 1153 | &gTpm2ServiceFfaGuid, |
| 1154 | &DirectMsgArgs |
| 1155 | ); |
| 1156 | if (EFI_ERROR (Status)) { |
| 1157 | DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status)); |
| 1158 | UT_ASSERT_NOT_EFI_ERROR (Status); |
| 1159 | } |
| 1160 | |
| 1161 | if (DirectMsgArgs.Arg0 != TPM2_FFA_SUCCESS_OK_RESULTS_RETURNED) { |
| 1162 | DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0)); |
| 1163 | UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TPM2_FFA_SUCCESS_OK_RESULTS_RETURNED); |
| 1164 | } else { |
| 1165 | DEBUG ((DEBUG_INFO, "TPM Service Interface Version: %d.%d\n", DirectMsgArgs.Arg1 >> 16, DirectMsgArgs.Arg1 & 0xFFFF)); |
| 1166 | } |
| 1167 | |
| 1168 | return UNIT_TEST_PASSED; |
| 1169 | } |
| 1170 | |
| 1171 | /** |
| 1172 | This routine tests the TPM Service to close locality with the Ffa test SP. |
| 1173 | **/ |
| 1174 | UNIT_TEST_STATUS |
| 1175 | EFIAPI |
| 1176 | FfaMiscTestTpmCloseLocality ( |
| 1177 | IN UNIT_TEST_CONTEXT Context |
| 1178 | ) |
| 1179 | { |
| 1180 | DIRECT_MSG_ARGS DirectMsgArgs; |
| 1181 | EFI_STATUS Status; |
| 1182 | FFA_TEST_CONTEXT *FfaTestContext; |
| 1183 | |
| 1184 | DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__)); |
| 1185 | |
| 1186 | FfaTestContext = (FFA_TEST_CONTEXT *)Context; |
| 1187 | UT_ASSERT_NOT_NULL (FfaTestContext); |
| 1188 | |
| 1189 | // Call the TPM Service to close locality0 |
| 1190 | ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs)); |
| 1191 | DirectMsgArgs.Arg0 = TPM2_FFA_START; |
| 1192 | DirectMsgArgs.Arg1 = 0x101; // Close Locality |
| 1193 | DirectMsgArgs.Arg2 = 0x00; // Locality Qualifier |
| 1194 | Status = ArmFfaLibMsgSendDirectReq2 ( |
| 1195 | FfaTestContext->FfaTpm2ServicePartId, |
| 1196 | &gTpm2ServiceFfaGuid, |
| 1197 | &DirectMsgArgs |
| 1198 | ); |
| 1199 | if (EFI_ERROR (Status)) { |
| 1200 | DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status)); |
| 1201 | UT_ASSERT_NOT_EFI_ERROR (Status); |
| 1202 | } |
| 1203 | |
| 1204 | if (DirectMsgArgs.Arg0 != TPM2_FFA_SUCCESS_OK) { |
| 1205 | DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0)); |
| 1206 | UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TPM2_FFA_SUCCESS_OK); |
| 1207 | } else { |
| 1208 | DEBUG ((DEBUG_INFO, "TPM Service Close Locality Success\n")); |
| 1209 | } |
| 1210 | |
| 1211 | return UNIT_TEST_PASSED; |
| 1212 | } |
| 1213 | |
| 1214 | /** |
| 1215 | This routine tests the TPM Service to request locality with the Ffa test SP. |
| 1216 | **/ |
| 1217 | UNIT_TEST_STATUS |
| 1218 | EFIAPI |
| 1219 | FfaMiscTestTpmRequestLocality ( |
| 1220 | IN UNIT_TEST_CONTEXT Context |
| 1221 | ) |
| 1222 | { |
| 1223 | DIRECT_MSG_ARGS DirectMsgArgs; |
| 1224 | EFI_STATUS Status; |
| 1225 | FFA_TEST_CONTEXT *FfaTestContext; |
| 1226 | |
| 1227 | DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__)); |
| 1228 | |
| 1229 | FfaTestContext = (FFA_TEST_CONTEXT *)Context; |
| 1230 | UT_ASSERT_NOT_NULL (FfaTestContext); |
| 1231 | |
| 1232 | // Call the TPM Service to request locality0 |
| 1233 | ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs)); |
| 1234 | DirectMsgArgs.Arg0 = TPM2_FFA_START; |
| 1235 | DirectMsgArgs.Arg1 = TPM2_FFA_START_FUNC_QUALIFIER_LOCALITY; |
| 1236 | DirectMsgArgs.Arg2 = 0x00; // Locality Qualifier |
| 1237 | Status = ArmFfaLibMsgSendDirectReq2 ( |
| 1238 | FfaTestContext->FfaTpm2ServicePartId, |
| 1239 | &gTpm2ServiceFfaGuid, |
| 1240 | &DirectMsgArgs |
| 1241 | ); |
| 1242 | if (EFI_ERROR (Status)) { |
| 1243 | DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status)); |
| 1244 | UT_ASSERT_NOT_EFI_ERROR (Status); |
| 1245 | } |
| 1246 | |
| 1247 | if (DirectMsgArgs.Arg0 != TPM2_FFA_ERROR_DENIED) { |
| 1248 | DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0)); |
| 1249 | UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TPM2_FFA_ERROR_DENIED); |
| 1250 | } else { |
| 1251 | DEBUG ((DEBUG_INFO, "TPM Service Rejected Request, Locality Closed\n")); |
| 1252 | } |
| 1253 | |
| 1254 | return UNIT_TEST_PASSED; |
| 1255 | } |
| 1256 | |
| 1257 | /** |
| 1258 | This routine tests the TPM Service to reopen locality with the Ffa test SP. |
| 1259 | **/ |
| 1260 | UNIT_TEST_STATUS |
| 1261 | EFIAPI |
| 1262 | FfaMiscTestTpmReopenLocality ( |
| 1263 | IN UNIT_TEST_CONTEXT Context |
| 1264 | ) |
| 1265 | { |
| 1266 | DIRECT_MSG_ARGS DirectMsgArgs; |
| 1267 | EFI_STATUS Status; |
| 1268 | FFA_TEST_CONTEXT *FfaTestContext; |
| 1269 | |
| 1270 | DEBUG ((DEBUG_INFO, "%a: enter...\n", __func__)); |
| 1271 | |
| 1272 | FfaTestContext = (FFA_TEST_CONTEXT *)Context; |
| 1273 | UT_ASSERT_NOT_NULL (FfaTestContext); |
| 1274 | |
| 1275 | // Call the TPM Service to reopen locality0 |
| 1276 | ZeroMem (&DirectMsgArgs, sizeof (DirectMsgArgs)); |
| 1277 | DirectMsgArgs.Arg0 = TPM2_FFA_START; |
| 1278 | DirectMsgArgs.Arg1 = 0x100; // Open Locality |
| 1279 | DirectMsgArgs.Arg2 = 0x00; // Locality Qualifier |
| 1280 | Status = ArmFfaLibMsgSendDirectReq2 ( |
| 1281 | FfaTestContext->FfaTpm2ServicePartId, |
| 1282 | &gTpm2ServiceFfaGuid, |
| 1283 | &DirectMsgArgs |
| 1284 | ); |
| 1285 | if (EFI_ERROR (Status)) { |
| 1286 | DEBUG ((DEBUG_ERROR, "Unable to communicate direct req 2 with FF-A Ffa test SP (%r).\n", Status)); |
| 1287 | UT_ASSERT_NOT_EFI_ERROR (Status); |
| 1288 | } |
| 1289 | |
| 1290 | if (DirectMsgArgs.Arg0 != TPM2_FFA_SUCCESS_OK) { |
| 1291 | DEBUG ((DEBUG_ERROR, "Command Failed: %x\n", DirectMsgArgs.Arg0)); |
| 1292 | UT_ASSERT_EQUAL (DirectMsgArgs.Arg0, TPM2_FFA_SUCCESS_OK); |
| 1293 | } else { |
| 1294 | DEBUG ((DEBUG_INFO, "TPM Service Open Locality Success\n")); |
| 1295 | } |
| 1296 | |
| 1297 | return UNIT_TEST_PASSED; |
| 1298 | } |
| 1299 | |
| 1300 | /** |
| 1301 | FfaPartitionTestAppEntry |
| 1302 | |
| 1303 | @param[in] ImageHandle The firmware allocated handle for the EFI image. |
| 1304 | @param[in] SystemTable A pointer to the EFI System Table. |
| 1305 | |
| 1306 | @retval EFI_SUCCESS The entry point executed successfully. |
| 1307 | @retval other Some error occurred when executing this entry point. |
| 1308 | |
| 1309 | **/ |
| 1310 | EFI_STATUS |
| 1311 | EFIAPI |
| 1312 | FfaPartitionTestAppEntry ( |
| 1313 | IN EFI_HANDLE ImageHandle, |
| 1314 | IN EFI_SYSTEM_TABLE *SystemTable |
| 1315 | ) |
| 1316 | { |
| 1317 | EFI_STATUS Status; |
| 1318 | UNIT_TEST_FRAMEWORK_HANDLE Fw = NULL; |
| 1319 | UNIT_TEST_SUITE_HANDLE Misc = NULL; |
| 1320 | FFA_TEST_CONTEXT FfaTestContext = { 0 }; |
| 1321 | |
| 1322 | DEBUG ((DEBUG_ERROR, "%a %a v%a\n", __FUNCTION__, UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION)); |
| 1323 | |
| 1324 | // Start setting up the test framework for running the tests. |
| 1325 | Status = InitUnitTestFramework (&Fw, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION); |
| 1326 | if (EFI_ERROR (Status)) { |
| 1327 | DEBUG ((DEBUG_ERROR, "%a Failed in InitUnitTestFramework. Status = %r\n", __FUNCTION__, Status)); |
| 1328 | goto Done; |
| 1329 | } |
| 1330 | |
| 1331 | // Misc test suite for all tests. |
| 1332 | Status = CreateUnitTestSuite (&Misc, Fw, "FF-A Miscellaneous Test cases", "Ffa.Miscellaneous", NULL, NULL); |
| 1333 | |
| 1334 | if (EFI_ERROR (Status)) { |
| 1335 | DEBUG ((DEBUG_ERROR, "%a Failed in CreateUnitTestSuite for TestSuite\n", __FUNCTION__)); |
| 1336 | Status = EFI_OUT_OF_RESOURCES; |
| 1337 | goto Done; |
| 1338 | } |
| 1339 | |
| 1340 | Status = AddTestCase ( |
| 1341 | Misc, |
| 1342 | "Verify FF-A framework version", |
| 1343 | "Ffa.Miscellaneous.VerifyVersion", |
| 1344 | FfaMiscVerifyVersion, |
| 1345 | NULL, |
| 1346 | NULL, |
| 1347 | &FfaTestContext |
| 1348 | ); |
| 1349 | if (EFI_ERROR (Status)) { |
| 1350 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for VerifyVersion\n", __FUNCTION__)); |
| 1351 | Status = EFI_OUT_OF_RESOURCES; |
| 1352 | goto Done; |
| 1353 | } |
| 1354 | |
| 1355 | Status = AddTestCase ( |
| 1356 | Misc, |
| 1357 | "Verify Partition Info via registers", |
| 1358 | "Ffa.Miscellaneous.VerifyPartitionInfoRegs", |
| 1359 | FfaMiscGetPartitionInfoRegs, |
| 1360 | NULL, |
| 1361 | NULL, |
| 1362 | &FfaTestContext |
| 1363 | ); |
| 1364 | if (EFI_ERROR (Status)) { |
| 1365 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for VerifyPartitionInfoRegs\n", __FUNCTION__)); |
| 1366 | Status = EFI_OUT_OF_RESOURCES; |
| 1367 | goto Done; |
| 1368 | } |
| 1369 | |
| 1370 | Status = AddTestCase ( |
| 1371 | Misc, |
| 1372 | "Verify Partition Info via Rx/Tx buffers", |
| 1373 | "Ffa.Miscellaneous.VerifyPartitionInfo", |
| 1374 | FfaMiscGetPartitionInfo, |
| 1375 | NULL, |
| 1376 | NULL, |
| 1377 | &FfaTestContext |
| 1378 | ); |
| 1379 | if (EFI_ERROR (Status)) { |
| 1380 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for VerifyPartitionInfo\n", __FUNCTION__)); |
| 1381 | Status = EFI_OUT_OF_RESOURCES; |
| 1382 | goto Done; |
| 1383 | } |
| 1384 | |
| 1385 | Status = AddTestCase ( |
| 1386 | Misc, |
| 1387 | "Verify FF-A Ffa test SP notifications", |
| 1388 | "Ffa.Miscellaneous.SetupNotifications", |
| 1389 | FfaMiscSetupNotifications, |
| 1390 | CheckTestService, |
| 1391 | NULL, |
| 1392 | &FfaTestContext |
| 1393 | ); |
| 1394 | if (EFI_ERROR (Status)) { |
| 1395 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for SetupNotifications\n", __FUNCTION__)); |
| 1396 | Status = EFI_OUT_OF_RESOURCES; |
| 1397 | goto Done; |
| 1398 | } |
| 1399 | |
| 1400 | Status = AddTestCase ( |
| 1401 | Misc, |
| 1402 | "Verify FF-A Ffa test SP notifications", |
| 1403 | "Ffa.Miscellaneous.RegisterNotifications", |
| 1404 | FfaMiscRegisterNotifications, |
| 1405 | NULL, |
| 1406 | NULL, |
| 1407 | &FfaTestContext |
| 1408 | ); |
| 1409 | if (EFI_ERROR (Status)) { |
| 1410 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for RegisterNotifications\n", __FUNCTION__)); |
| 1411 | Status = EFI_OUT_OF_RESOURCES; |
| 1412 | goto Done; |
| 1413 | } |
| 1414 | |
| 1415 | // |
| 1416 | // Test interpartition communication with the Ffa test SP. |
| 1417 | // These tests will only run if the Ffa test SP is available. |
| 1418 | // As a system level test, the order of the tests is important as the tests will |
| 1419 | // will corporate the states of inter-partition service to test the Ffa test SP. |
| 1420 | // |
| 1421 | Status = AddTestCase ( |
| 1422 | Misc, |
| 1423 | "Verify Ffa Inter Partition", |
| 1424 | "Ffa.Miscellaneous.FfaTestInterPartitionNormal", |
| 1425 | FfaMiscTestInterPartitionNormal, |
| 1426 | CheckNotificationService, |
| 1427 | NULL, |
| 1428 | &FfaTestContext |
| 1429 | ); |
| 1430 | if (EFI_ERROR (Status)) { |
| 1431 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionNormal\n", __FUNCTION__)); |
| 1432 | Status = EFI_OUT_OF_RESOURCES; |
| 1433 | goto Done; |
| 1434 | } |
| 1435 | |
| 1436 | Status = AddTestCase ( |
| 1437 | Misc, |
| 1438 | "Verify Ffa Inter Partition", |
| 1439 | "Ffa.Miscellaneous.FfaTestInterPartitionSecondary", |
| 1440 | FfaMiscTestInterPartitionSecondary, |
| 1441 | CheckNotificationService, |
| 1442 | NULL, |
| 1443 | &FfaTestContext |
| 1444 | ); |
| 1445 | if (EFI_ERROR (Status)) { |
| 1446 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionSecondary\n", __FUNCTION__)); |
| 1447 | Status = EFI_OUT_OF_RESOURCES; |
| 1448 | goto Done; |
| 1449 | } |
| 1450 | |
| 1451 | Status = AddTestCase ( |
| 1452 | Misc, |
| 1453 | "Verify Ffa Inter Partition", |
| 1454 | "Ffa.Miscellaneous.FfaTestInterPartitionDuplicateCookie", |
| 1455 | FfaMiscTestInterPartitionDuplicateCookie, |
| 1456 | CheckNotificationService, |
| 1457 | NULL, |
| 1458 | &FfaTestContext |
| 1459 | ); |
| 1460 | if (EFI_ERROR (Status)) { |
| 1461 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionDuplicateCookie\n", __FUNCTION__)); |
| 1462 | Status = EFI_OUT_OF_RESOURCES; |
| 1463 | goto Done; |
| 1464 | } |
| 1465 | |
| 1466 | Status = AddTestCase ( |
| 1467 | Misc, |
| 1468 | "Verify Ffa Inter Partition", |
| 1469 | "Ffa.Miscellaneous.FfaTestInterPartitionInvalidDuplicateId", |
| 1470 | FfaMiscTestInterPartitionInvalidDuplicateId, |
| 1471 | CheckNotificationService, |
| 1472 | NULL, |
| 1473 | &FfaTestContext |
| 1474 | ); |
| 1475 | if (EFI_ERROR (Status)) { |
| 1476 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionInvalidDuplicateId\n", __FUNCTION__)); |
| 1477 | Status = EFI_OUT_OF_RESOURCES; |
| 1478 | goto Done; |
| 1479 | } |
| 1480 | |
| 1481 | Status = AddTestCase ( |
| 1482 | Misc, |
| 1483 | "Verify Ffa Inter Partition", |
| 1484 | "Ffa.Miscellaneous.FfaTestInterPartitionInvalidMappingCountMin", |
| 1485 | FfaMiscTestInterPartitionInvalidMappingCountMin, |
| 1486 | CheckNotificationService, |
| 1487 | NULL, |
| 1488 | &FfaTestContext |
| 1489 | ); |
| 1490 | if (EFI_ERROR (Status)) { |
| 1491 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionInvalidMappingCountMin\n", __FUNCTION__)); |
| 1492 | Status = EFI_OUT_OF_RESOURCES; |
| 1493 | goto Done; |
| 1494 | } |
| 1495 | |
| 1496 | Status = AddTestCase ( |
| 1497 | Misc, |
| 1498 | "Verify Ffa Inter Partition", |
| 1499 | "Ffa.Miscellaneous.FfaTestInterPartitionInvalidMappingCountMax", |
| 1500 | FfaMiscTestInterPartitionInvalidMappingCountMax, |
| 1501 | CheckNotificationService, |
| 1502 | NULL, |
| 1503 | &FfaTestContext |
| 1504 | ); |
| 1505 | if (EFI_ERROR (Status)) { |
| 1506 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionInvalidMappingCountMax\n", __FUNCTION__)); |
| 1507 | Status = EFI_OUT_OF_RESOURCES; |
| 1508 | goto Done; |
| 1509 | } |
| 1510 | |
| 1511 | Status = AddTestCase ( |
| 1512 | Misc, |
| 1513 | "Verify Ffa Inter Partition", |
| 1514 | "Ffa.Miscellaneous.FfaTestInterPartitionUnregisterNormal", |
| 1515 | FfaMiscTestInterPartitionUnregisterNormal, |
| 1516 | CheckNotificationService, |
| 1517 | NULL, |
| 1518 | &FfaTestContext |
| 1519 | ); |
| 1520 | if (EFI_ERROR (Status)) { |
| 1521 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionUnregisterNormal\n", __FUNCTION__)); |
| 1522 | Status = EFI_OUT_OF_RESOURCES; |
| 1523 | goto Done; |
| 1524 | } |
| 1525 | |
| 1526 | Status = AddTestCase ( |
| 1527 | Misc, |
| 1528 | "Verify Ffa Inter Partition", |
| 1529 | "Ffa.Miscellaneous.FfaTestInterPartitionUnregisterInvalidCookie", |
| 1530 | FfaMiscTestInterPartitionUnregisterInvalidCookie, |
| 1531 | CheckNotificationService, |
| 1532 | NULL, |
| 1533 | &FfaTestContext |
| 1534 | ); |
| 1535 | if (EFI_ERROR (Status)) { |
| 1536 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionUnregisterInvalidCookie\n", __FUNCTION__)); |
| 1537 | Status = EFI_OUT_OF_RESOURCES; |
| 1538 | goto Done; |
| 1539 | } |
| 1540 | |
| 1541 | Status = AddTestCase ( |
| 1542 | Misc, |
| 1543 | "Verify Ffa Inter Partition", |
| 1544 | "Ffa.Miscellaneous.FfaTestInterPartitionUnregisterInvalidId", |
| 1545 | FfaMiscTestInterPartitionUnregisterInvalidId, |
| 1546 | CheckNotificationService, |
| 1547 | NULL, |
| 1548 | &FfaTestContext |
| 1549 | ); |
| 1550 | if (EFI_ERROR (Status)) { |
| 1551 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionUnregisterInvalidId\n", __FUNCTION__)); |
| 1552 | Status = EFI_OUT_OF_RESOURCES; |
| 1553 | goto Done; |
| 1554 | } |
| 1555 | |
| 1556 | Status = AddTestCase ( |
| 1557 | Misc, |
| 1558 | "Verify Ffa Inter Partition", |
| 1559 | "Ffa.Miscellaneous.FfaTestInterPartitionUnregisterInvalidUuid", |
| 1560 | FfaMiscTestInterPartitionUnregisterInvalidUuid, |
| 1561 | CheckNotificationService, |
| 1562 | NULL, |
| 1563 | &FfaTestContext |
| 1564 | ); |
| 1565 | if (EFI_ERROR (Status)) { |
| 1566 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestInterPartitionUnregisterInvalidUuid\n", __FUNCTION__)); |
| 1567 | Status = EFI_OUT_OF_RESOURCES; |
| 1568 | goto Done; |
| 1569 | } |
| 1570 | |
| 1571 | Status = AddTestCase ( |
| 1572 | Misc, |
| 1573 | "Verify Ffa Notification Event", |
| 1574 | "Ffa.Miscellaneous.FfaTestNotificationEvent", |
| 1575 | FfaMiscTestNotificationEvent, |
| 1576 | CheckTestService, |
| 1577 | NULL, |
| 1578 | &FfaTestContext |
| 1579 | ); |
| 1580 | if (EFI_ERROR (Status)) { |
| 1581 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestNotificationEvent\n", __FUNCTION__)); |
| 1582 | Status = EFI_OUT_OF_RESOURCES; |
| 1583 | goto Done; |
| 1584 | } |
| 1585 | |
| 1586 | // |
| 1587 | // As a system level test, the order of the tests is important as the tests will |
| 1588 | // will corporate the states of TPM service to test the Ffa test SP. |
| 1589 | // |
| 1590 | Status = AddTestCase ( |
| 1591 | Misc, |
| 1592 | "Verify Ffa TPM Service", |
| 1593 | "Ffa.Miscellaneous.FfaTestTpmGetVersion", |
| 1594 | FfaMiscTestTpmGetVersion, |
| 1595 | CheckTPMService, |
| 1596 | NULL, |
| 1597 | &FfaTestContext |
| 1598 | ); |
| 1599 | if (EFI_ERROR (Status)) { |
| 1600 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestTpmGetVersion\n", __FUNCTION__)); |
| 1601 | Status = EFI_OUT_OF_RESOURCES; |
| 1602 | goto Done; |
| 1603 | } |
| 1604 | |
| 1605 | Status = AddTestCase ( |
| 1606 | Misc, |
| 1607 | "Verify Ffa TPM Service", |
| 1608 | "Ffa.Miscellaneous.FfaTestTpmCloseLocality", |
| 1609 | FfaMiscTestTpmCloseLocality, |
| 1610 | CheckTPMService, |
| 1611 | NULL, |
| 1612 | &FfaTestContext |
| 1613 | ); |
| 1614 | if (EFI_ERROR (Status)) { |
| 1615 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestTpmCloseLocality\n", __FUNCTION__)); |
| 1616 | Status = EFI_OUT_OF_RESOURCES; |
| 1617 | goto Done; |
| 1618 | } |
| 1619 | |
| 1620 | Status = AddTestCase ( |
| 1621 | Misc, |
| 1622 | "Verify Ffa TPM Service", |
| 1623 | "Ffa.Miscellaneous.FfaTestTpmRequestLocality", |
| 1624 | FfaMiscTestTpmRequestLocality, |
| 1625 | CheckTPMService, |
| 1626 | NULL, |
| 1627 | &FfaTestContext |
| 1628 | ); |
| 1629 | if (EFI_ERROR (Status)) { |
| 1630 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestTpmRequestLocality\n", __FUNCTION__)); |
| 1631 | Status = EFI_OUT_OF_RESOURCES; |
| 1632 | goto Done; |
| 1633 | } |
| 1634 | |
| 1635 | Status = AddTestCase ( |
| 1636 | Misc, |
| 1637 | "Verify Ffa TPM Service", |
| 1638 | "Ffa.Miscellaneous.FfaTestTpmReopenLocality", |
| 1639 | FfaMiscTestTpmReopenLocality, |
| 1640 | CheckTPMService, |
| 1641 | NULL, |
| 1642 | &FfaTestContext |
| 1643 | ); |
| 1644 | if (EFI_ERROR (Status)) { |
| 1645 | DEBUG ((DEBUG_ERROR, "%a Failed in AddTestCase for FfaTestTpmReopenLocality\n", __FUNCTION__)); |
| 1646 | Status = EFI_OUT_OF_RESOURCES; |
| 1647 | goto Done; |
| 1648 | } |
| 1649 | |
| 1650 | // |
| 1651 | // Execute the tests. |
| 1652 | // |
| 1653 | Status = RunAllTestSuites (Fw); |
| 1654 | |
| 1655 | Done: |
| 1656 | if (Fw != NULL) { |
| 1657 | FreeUnitTestFramework (Fw); |
| 1658 | } |
| 1659 | |
| 1660 | DEBUG ((DEBUG_INFO, "%a exit - %r\n", __FUNCTION__, Status)); |
| 1661 | return Status; |
| 1662 | } |
| 1663 | |