microsoft/mu_feature_ffa
Publicmirrored from https://github.com/microsoft/mu_feature_ffaAvailable
FfaFeaturePkg/Library/TestServiceLib/TestServiceLib.c
117lines · modeblame
ac0f2cf1Raymond-MS1 years ago | 1 | /** @file |
| 2 | Implementation for the Test Service | |
| 3 | | |
| 4 | Copyright (c), Microsoft Corporation. | |
| 5 | SPDX-License-Identifier: BSD-2-Clause-Patent | |
| 6 | | |
| 7 | **/ | |
| 8 | | |
| 9 | #include <Uefi.h> | |
| 10 | #include <Library/DebugLib.h> | |
| 11 | #include <Library/BaseMemoryLib.h> | |
| 12 | #include <Library/TestServiceLib.h> | |
| 13 | #include <Library/NotificationServiceLib.h> | |
0585e78fRaymond-MS1 years ago | 14 | #include <Guid/TestServiceFfa.h> |
| 15 | #include <Guid/NotificationServiceFfa.h> | |
ac0f2cf1Raymond-MS1 years ago | 16 | |
| 17 | /* Test Service Defines */ | |
| 18 | #define DELAYED_SRI_BIT_POS (1) | |
| 19 | | |
| 20 | /** | |
| 21 | Handler for Test Notification command | |
| 22 | | |
| 23 | @param Request The incoming message | |
| 24 | @param Response The outgoing message | |
| 25 | | |
| 26 | @retval TEST_STATUS_SUCCESS Success | |
| 27 | @retval TEST_STATUS_INVALID_PARAMETER Invalid Parameter | |
| 28 | | |
| 29 | **/ | |
| 30 | STATIC | |
| 31 | TestStatus | |
| 32 | TestNotificationHandler ( | |
| 33 | DIRECT_MSG_ARGS_EX *Request, | |
| 34 | DIRECT_MSG_ARGS_EX *Response | |
| 35 | ) | |
| 36 | { | |
a56f62ecRaymond-MS1 years ago | 37 | UINT8 Uuid[16]; |
| 38 | TestStatus ReturnVal; | |
| 39 | UINT32 Flag; | |
1cf65721Raymond-MS1 years ago | 40 | UINT32 Cookie; |
a56f62ecRaymond-MS1 years ago | 41 | NotificationStatus Status; |
| 42 | | |
| 43 | ReturnVal = TEST_STATUS_INVALID_PARAMETER; | |
ac0f2cf1Raymond-MS1 years ago | 44 | |
1cf65721Raymond-MS1 years ago | 45 | /* Extract the UUID from the message x5-x6 (i.e. Arg1-Arg2) */ |
| 46 | NotificationServiceExtractUuid (Request->Arg1, Request->Arg2, Uuid); | |
ac0f2cf1Raymond-MS1 years ago | 47 | |
| 48 | /* Set the notification set flag to be a delayed SRI */ | |
1cf65721Raymond-MS1 years ago | 49 | Flag = (1 << DELAYED_SRI_BIT_POS); |
| 50 | Cookie = Request->Arg3; | |
| 51 | Status = NotificationServiceIdSet (Cookie, Uuid, Flag); | |
ac0f2cf1Raymond-MS1 years ago | 52 | |
| 53 | /* Check for a valid UUID and validate the input parameters */ | |
| 54 | if (Status == NOTIFICATION_STATUS_SUCCESS) { | |
| 55 | ReturnVal = TEST_STATUS_SUCCESS; | |
| 56 | } else { | |
| 57 | DEBUG ((DEBUG_ERROR, "Test Notification Handler Failed\n")); | |
| 58 | } | |
| 59 | | |
| 60 | Response->Arg0 = ReturnVal; | |
| 61 | return ReturnVal; | |
| 62 | } | |
| 63 | | |
| 64 | /** | |
| 65 | Initializes the Test service | |
| 66 | | |
| 67 | **/ | |
| 68 | VOID | |
| 69 | TestServiceInit ( | |
| 70 | VOID | |
| 71 | ) | |
| 72 | { | |
| 73 | /* Nothing to Init */ | |
| 74 | } | |
| 75 | | |
| 76 | /** | |
| 77 | Deinitializes the Test service | |
| 78 | | |
| 79 | **/ | |
| 80 | VOID | |
| 81 | TestServiceDeInit ( | |
| 82 | VOID | |
| 83 | ) | |
| 84 | { | |
| 85 | /* Nothing to Deinit */ | |
| 86 | } | |
| 87 | | |
| 88 | /** | |
| 89 | Handler for Test service commands | |
| 90 | | |
| 91 | @param Request The incoming message | |
| 92 | @param Response The outgoing message | |
| 93 | | |
| 94 | **/ | |
| 95 | VOID | |
| 96 | TestServiceHandle ( | |
| 97 | DIRECT_MSG_ARGS_EX *Request, | |
| 98 | DIRECT_MSG_ARGS_EX *Response | |
| 99 | ) | |
| 100 | { | |
| 101 | /* Validate the input parameters before attempting to dereference or pass them along */ | |
| 102 | if ((Request == NULL) || (Response == NULL)) { | |
| 103 | return; | |
| 104 | } | |
| 105 | | |
1cf65721Raymond-MS1 years ago | 106 | /* Command Opcode = x4 (i.e. Arg0)*/ |
| 107 | switch (Request->Arg0) { | |
ac0f2cf1Raymond-MS1 years ago | 108 | case TEST_OPCODE_TEST_NOTIFICATION: |
| 109 | TestNotificationHandler (Request, Response); | |
| 110 | break; | |
| 111 | | |
| 112 | default: | |
| 113 | Response->Arg0 = TEST_STATUS_INVALID_PARAMETER; | |
| 114 | DEBUG ((DEBUG_ERROR, "Invalid Test Service Opcode\n")); | |
| 115 | break; | |
| 116 | } | |
| 117 | } |