microsoft/mu_feature_ffa
Publicmirrored from https://github.com/microsoft/mu_feature_ffaAvailable
FfaFeaturePkg/Library/NotificationServiceLib/NotificationServiceLib.c
536lines · modeblame
97eb3c34Raymond-MS1 years ago | 1 | /** @file |
| 2 | Implementation for the Notification 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/NotificationServiceLib.h> | |
0585e78fRaymond-MS1 years ago | 13 | #include <Guid/NotificationServiceFfa.h> |
97eb3c34Raymond-MS1 years ago | 14 | |
| 15 | /* Notification Service Defines */ | |
| 16 | #define NOTIFICATION_MAX_SERVICES (16) | |
1cf65721Raymond-MS1 years ago | 17 | #define NOTIFICATION_MAX_MAPPINGS (64) |
| 18 | #define NOTIFICATION_NOT_FOUND (-1) | |
| 19 | | |
| 20 | #define MESSAGE_INFO_DIR_RESP (0x100) | |
| 21 | #define MESSAGE_INFO_ID_MASK (0x03) | |
| 22 | | |
| 23 | #define RETURN_STATUS_MASK (0xFF) | |
| 24 | | |
| 25 | #define MAPPING_MIN (0x01) | |
| 26 | #define MAPPING_MAX (0x07) | |
| 27 | | |
| 28 | #define PER_VCPU_BIT_POS (0) | |
97eb3c34Raymond-MS1 years ago | 29 | |
| 30 | /* Notification Service Structures */ | |
| 31 | typedef struct { | |
1cf65721Raymond-MS1 years ago | 32 | UINT32 Cookie; // SW defined value |
| 33 | UINT16 Id; // Global bitmask value | |
| 34 | BOOLEAN PerVcpu; // Notification flag | |
| 35 | UINT16 SourceId; | |
97eb3c34Raymond-MS1 years ago | 36 | BOOLEAN InUse; |
1cf65721Raymond-MS1 years ago | 37 | } NotifInfo; |
97eb3c34Raymond-MS1 years ago | 38 | |
1cf65721Raymond-MS1 years ago | 39 | typedef struct { |
97eb3c34Raymond-MS1 years ago | 40 | UINT8 ServiceUuid[16]; |
1cf65721Raymond-MS1 years ago | 41 | NotifInfo ServiceInfo[NOTIFICATION_MAX_MAPPINGS]; |
97eb3c34Raymond-MS1 years ago | 42 | BOOLEAN InUse; |
| 43 | } NotifService; | |
| 44 | | |
| 45 | /* Notification Service Variables */ | |
1cf65721Raymond-MS1 years ago | 46 | STATIC UINT64 GlobalBitmask; |
| 47 | STATIC NotifService NotificationServices[NOTIFICATION_MAX_SERVICES]; | |
97eb3c34Raymond-MS1 years ago | 48 | |
| 49 | /** | |
1cf65721Raymond-MS1 years ago | 50 | Checks if the cookie passed in matches one stored within the service structure |
97eb3c34Raymond-MS1 years ago | 51 | |
1cf65721Raymond-MS1 years ago | 52 | @param Cookie The cookie value to search for |
| 53 | @param Service The service to search for the given ID | |
97eb3c34Raymond-MS1 years ago | 54 | |
1cf65721Raymond-MS1 years ago | 55 | @return The index of the cookie if found, otherwise -1 (NOTIFICATION_NOT_FOUND) |
97eb3c34Raymond-MS1 years ago | 56 | |
| 57 | **/ | |
| 58 | STATIC | |
| 59 | INT8 | |
1cf65721Raymond-MS1 years ago | 60 | IsMatchingCookie ( |
| 61 | UINT32 Cookie, | |
97eb3c34Raymond-MS1 years ago | 62 | NotifService *Service |
| 63 | ) | |
| 64 | { | |
03d3c59akuqin121 years ago | 65 | UINT8 Index; |
a56f62ecRaymond-MS1 years ago | 66 | |
97eb3c34Raymond-MS1 years ago | 67 | /* Validate the incoming function parameters */ |
| 68 | if (Service == NULL) { | |
1cf65721Raymond-MS1 years ago | 69 | return NOTIFICATION_NOT_FOUND; |
97eb3c34Raymond-MS1 years ago | 70 | } |
| 71 | | |
1cf65721Raymond-MS1 years ago | 72 | for (Index = 0; Index < NOTIFICATION_MAX_MAPPINGS; Index++) { |
| 73 | if (Service->ServiceInfo[Index].InUse && (Service->ServiceInfo[Index].Cookie == Cookie)) { | |
a56f62ecRaymond-MS1 years ago | 74 | return Index; |
97eb3c34Raymond-MS1 years ago | 75 | } |
| 76 | } | |
| 77 | | |
1cf65721Raymond-MS1 years ago | 78 | return NOTIFICATION_NOT_FOUND; |
97eb3c34Raymond-MS1 years ago | 79 | } |
| 80 | | |
| 81 | /** | |
| 82 | Adds or removes service bit information to the local notification services struct array | |
| 83 | | |
1cf65721Raymond-MS1 years ago | 84 | @param Unregister Whether or not we are adding or removing bit information |
| 85 | @param Request The incoming message containing the bit information | |
| 86 | @param Service The service we are updating bit information for | |
97eb3c34Raymond-MS1 years ago | 87 | |
| 88 | @retval NOTIFICATION_STATUS_SUCCESS Success | |
| 89 | @retval NOTIFICATION_STATUS_INVALID_PARAMETER Invalid parameter | |
| 90 | | |
| 91 | **/ | |
| 92 | STATIC | |
| 93 | NotificationStatus | |
1cf65721Raymond-MS1 years ago | 94 | UpdateServiceInfo ( |
| 95 | BOOLEAN Unregister, | |
97eb3c34Raymond-MS1 years ago | 96 | DIRECT_MSG_ARGS_EX *Request, |
| 97 | NotifService *Service | |
| 98 | ) | |
| 99 | { | |
1cf65721Raymond-MS1 years ago | 100 | NotificationStatus ReturnVal; |
| 101 | INT8 FoundIndex; | |
| 102 | UINT8 ReqNumMappings; | |
| 103 | NotificationMapping *ReqMappings; | |
| 104 | UINT8 ReqMappingIndex; | |
| 105 | UINT16 MappingId; | |
| 106 | UINT32 Cookie; | |
| 107 | UINT8 PerVcpu; | |
| 108 | UINT8 EmptyIndex; | |
| 109 | BOOLEAN EmptyFound; | |
| 110 | NotifService TempService; | |
| 111 | UINT64 TempBitmask; | |
a56f62ecRaymond-MS1 years ago | 112 | |
97eb3c34Raymond-MS1 years ago | 113 | /* Validate the incoming function parameters */ |
| 114 | if ((Request == NULL) || (Service == NULL)) { | |
| 115 | return NOTIFICATION_STATUS_INVALID_PARAMETER; | |
| 116 | } | |
| 117 | | |
1cf65721Raymond-MS1 years ago | 118 | /* Number of cookie/ID pairs = x10. Cookie/ID pairs = x11 (i.e. Arg6/Arg7) */ |
| 119 | ReqNumMappings = Request->Arg6; | |
| 120 | ReqMappings = (NotificationMapping *)&Request->Arg7; | |
97eb3c34Raymond-MS1 years ago | 121 | |
1cf65721Raymond-MS1 years ago | 122 | /* You must be adding/removing at least one bit and no more than a transaction supports */ |
| 123 | if ((ReqNumMappings < MAPPING_MIN) || (ReqNumMappings > MAPPING_MAX)) { | |
| 124 | DEBUG ((DEBUG_ERROR, "Invalid Number of Mappings: %x\n", ReqNumMappings)); | |
a56f62ecRaymond-MS1 years ago | 125 | return NOTIFICATION_STATUS_INVALID_PARAMETER; |
| 126 | } | |
97eb3c34Raymond-MS1 years ago | 127 | |
a56f62ecRaymond-MS1 years ago | 128 | /* Copy the current service structure and global bitmask to the temporaries */ |
03d3c59akuqin121 years ago | 129 | CopyMem (&TempService, Service, sizeof (NotifService)); |
a56f62ecRaymond-MS1 years ago | 130 | TempBitmask = GlobalBitmask; |
| 131 | | |
| 132 | /* Need to go through all of the setup bits and update the structure */ | |
1cf65721Raymond-MS1 years ago | 133 | ReturnVal = NOTIFICATION_STATUS_SUCCESS; |
| 134 | for (ReqMappingIndex = 0; ReqMappingIndex < ReqNumMappings; ReqMappingIndex++) { | |
| 135 | MappingId = ReqMappings[ReqMappingIndex].Bits.Id; | |
| 136 | Cookie = ReqMappings[ReqMappingIndex].Bits.Cookie; | |
| 137 | PerVcpu = ReqMappings[ReqMappingIndex].Bits.PerVcpu; | |
| 138 | FoundIndex = IsMatchingCookie (Cookie, &TempService); | |
| 139 | | |
| 140 | /* Check if we are doing an unregister */ | |
| 141 | if (Unregister) { | |
| 142 | /* If we can not find the cookie to unregister, it is an error */ | |
| 143 | if (FoundIndex == NOTIFICATION_NOT_FOUND) { | |
| 144 | DEBUG ((DEBUG_ERROR, "Invalid Unregister - Cookie: %x Not Registered\n", Cookie)); | |
| 145 | ReturnVal = NOTIFICATION_STATUS_INVALID_PARAMETER; | |
| 146 | break; | |
| 147 | /* If the IDs do not match, it is an error */ | |
| 148 | } else if (TempService.ServiceInfo[FoundIndex].Id != MappingId) { | |
| 149 | DEBUG (( | |
| 150 | DEBUG_ERROR, | |
| 151 | "Invalid Unregister - ID Registered: %x Mismatch\n", | |
| 152 | TempService.ServiceInfo[FoundIndex].Id | |
| 153 | )); | |
a56f62ecRaymond-MS1 years ago | 154 | ReturnVal = NOTIFICATION_STATUS_INVALID_PARAMETER; |
| 155 | break; | |
1cf65721Raymond-MS1 years ago | 156 | /* If the Source IDs do not match, it is an error */ |
| 157 | } else if (TempService.ServiceInfo[FoundIndex].SourceId != Request->SourceId) { | |
| 158 | DEBUG (( | |
| 159 | DEBUG_ERROR, | |
| 160 | "Invalid Unregister - Source ID: %x Mismatch\n", | |
| 161 | TempService.ServiceInfo[FoundIndex].SourceId | |
| 162 | )); | |
a56f62ecRaymond-MS1 years ago | 163 | ReturnVal = NOTIFICATION_STATUS_INVALID_PARAMETER; |
| 164 | break; | |
1cf65721Raymond-MS1 years ago | 165 | /* Otherwise, clear the data */ |
a56f62ecRaymond-MS1 years ago | 166 | } else { |
1cf65721Raymond-MS1 years ago | 167 | TempService.ServiceInfo[FoundIndex].Cookie = 0; |
| 168 | TempService.ServiceInfo[FoundIndex].Id = 0; | |
| 169 | TempService.ServiceInfo[FoundIndex].InUse = FALSE; | |
| 170 | TempService.ServiceInfo[FoundIndex].PerVcpu = FALSE; | |
| 171 | TempService.ServiceInfo[FoundIndex].SourceId = 0; | |
| 172 | TempBitmask &= ~(1 << MappingId); | |
97eb3c34Raymond-MS1 years ago | 173 | } |
1cf65721Raymond-MS1 years ago | 174 | |
| 175 | /* Otherwise, we are doing a register */ | |
97eb3c34Raymond-MS1 years ago | 176 | } else { |
1cf65721Raymond-MS1 years ago | 177 | /* If we can find the cookie to register, it is an error */ |
| 178 | if (FoundIndex != NOTIFICATION_NOT_FOUND) { | |
| 179 | DEBUG ((DEBUG_ERROR, "Invalid Register - Cookie: %x Already Registered\n", Cookie)); | |
a56f62ecRaymond-MS1 years ago | 180 | ReturnVal = NOTIFICATION_STATUS_INVALID_PARAMETER; |
| 181 | break; | |
1cf65721Raymond-MS1 years ago | 182 | /* If the Bitmask bit is set, it is an error */ |
| 183 | } else if (TempBitmask & (1 << MappingId)) { | |
| 184 | DEBUG ((DEBUG_ERROR, "Invalid Register - ID: %x Already Registered\n", MappingId)); | |
a56f62ecRaymond-MS1 years ago | 185 | ReturnVal = NOTIFICATION_STATUS_INVALID_PARAMETER; |
| 186 | break; | |
1cf65721Raymond-MS1 years ago | 187 | /* Otherwise, set the data */ |
a56f62ecRaymond-MS1 years ago | 188 | } else { |
| 189 | /* Need to loop through the bits within the structure and find an empty location */ | |
| 190 | EmptyFound = FALSE; | |
1cf65721Raymond-MS1 years ago | 191 | for (EmptyIndex = 0; EmptyIndex < NOTIFICATION_MAX_MAPPINGS; EmptyIndex++) { |
| 192 | if (!TempService.ServiceInfo[EmptyIndex].InUse) { | |
a56f62ecRaymond-MS1 years ago | 193 | EmptyFound = TRUE; |
| 194 | break; | |
| 195 | } | |
97eb3c34Raymond-MS1 years ago | 196 | } |
| 197 | | |
a56f62ecRaymond-MS1 years ago | 198 | /* If we can not find an empty space, it is an error */ |
| 199 | if (!EmptyFound) { | |
1cf65721Raymond-MS1 years ago | 200 | DEBUG ((DEBUG_ERROR, "Register Failed - No Memory Available\n")); |
a56f62ecRaymond-MS1 years ago | 201 | ReturnVal = NOTIFICATION_STATUS_NO_MEM; |
| 202 | break; | |
1cf65721Raymond-MS1 years ago | 203 | /* Otherwise, update the data */ |
a56f62ecRaymond-MS1 years ago | 204 | } else { |
1cf65721Raymond-MS1 years ago | 205 | TempService.ServiceInfo[EmptyIndex].Cookie = Cookie; |
| 206 | TempService.ServiceInfo[EmptyIndex].Id = MappingId; | |
| 207 | TempService.ServiceInfo[EmptyIndex].InUse = TRUE; | |
| 208 | TempService.ServiceInfo[EmptyIndex].PerVcpu = (PerVcpu) ? TRUE : FALSE; | |
| 209 | TempService.ServiceInfo[EmptyIndex].SourceId = Request->SourceId; | |
| 210 | TempBitmask |= (1 << MappingId); | |
a56f62ecRaymond-MS1 years ago | 211 | } |
97eb3c34Raymond-MS1 years ago | 212 | } |
| 213 | } | |
| 214 | | |
1cf65721Raymond-MS1 years ago | 215 | /* Copy the temporaries back if everything was successful */ |
| 216 | if (ReturnVal == NOTIFICATION_STATUS_SUCCESS) { | |
| 217 | CopyMem (Service, &TempService, sizeof (NotifService)); | |
| 218 | GlobalBitmask = TempBitmask; | |
| 219 | } | |
a56f62ecRaymond-MS1 years ago | 220 | } |
| 221 | | |
97eb3c34Raymond-MS1 years ago | 222 | return ReturnVal; |
| 223 | } | |
| 224 | | |
| 225 | /** | |
1cf65721Raymond-MS1 years ago | 226 | Searches the NotificationServices structure for the provided UUID or an |
| 227 | empty location to place a new service. | |
97eb3c34Raymond-MS1 years ago | 228 | |
1cf65721Raymond-MS1 years ago | 229 | @param Uuid The UUID to search for |
| 230 | @param LocateEmpty Whether or not to search for an empty location | |
97eb3c34Raymond-MS1 years ago | 231 | |
1cf65721Raymond-MS1 years ago | 232 | @retval A pointer to the service that matches the UUID, an empty location |
| 233 | or NULL if no match could be found. | |
97eb3c34Raymond-MS1 years ago | 234 | |
| 235 | **/ | |
| 236 | STATIC | |
1cf65721Raymond-MS1 years ago | 237 | NotifService * |
| 238 | LocateService ( | |
| 239 | UINT8 *Uuid, | |
| 240 | BOOLEAN LocateEmpty | |
97eb3c34Raymond-MS1 years ago | 241 | ) |
| 242 | { | |
1cf65721Raymond-MS1 years ago | 243 | UINT8 Index; |
| 244 | NotifService *Service; | |
a56f62ecRaymond-MS1 years ago | 245 | |
1cf65721Raymond-MS1 years ago | 246 | Service = NULL; |
97eb3c34Raymond-MS1 years ago | 247 | |
1cf65721Raymond-MS1 years ago | 248 | /* Traverse the NotificationServices structure */ |
a56f62ecRaymond-MS1 years ago | 249 | for (Index = 0; Index < NOTIFICATION_MAX_SERVICES; Index++) { |
1cf65721Raymond-MS1 years ago | 250 | /* If looking for a UUID, check if the service is marked as InUse */ |
| 251 | if (!LocateEmpty && NotificationServices[Index].InUse) { | |
| 252 | /* Check if the UUID matches */ | |
| 253 | if (!CompareMem (Uuid, NotificationServices[Index].ServiceUuid, sizeof (Uuid))) { | |
| 254 | Service = &NotificationServices[Index]; | |
| 255 | break; | |
| 256 | } | |
| 257 | | |
| 258 | /* If looking for an empty location, check if the service is not marked as InUse */ | |
| 259 | } else if (LocateEmpty && !NotificationServices[Index].InUse) { | |
a56f62ecRaymond-MS1 years ago | 260 | Service = &NotificationServices[Index]; |
97eb3c34Raymond-MS1 years ago | 261 | break; |
| 262 | } | |
| 263 | } | |
| 264 | | |
1cf65721Raymond-MS1 years ago | 265 | return Service; |
97eb3c34Raymond-MS1 years ago | 266 | } |
| 267 | | |
| 268 | /** | |
1cf65721Raymond-MS1 years ago | 269 | Handler for Notification Register command |
97eb3c34Raymond-MS1 years ago | 270 | |
| 271 | @param Request The incoming message | |
| 272 | @param Response The outgoing message | |
| 273 | | |
| 274 | @retval NOTIFICATION_STATUS_SUCCESS Success | |
| 275 | @retval NOTIFICATION_STATUS_INVALID_PARAMETER Invalid parameter | |
1cf65721Raymond-MS1 years ago | 276 | @retval NOTIFICATION_STATUS_NO_MEM Out of resources |
97eb3c34Raymond-MS1 years ago | 277 | |
| 278 | **/ | |
| 279 | STATIC | |
| 280 | NotificationStatus | |
1cf65721Raymond-MS1 years ago | 281 | RegisterHandler ( |
| 282 | DIRECT_MSG_ARGS_EX *Request | |
97eb3c34Raymond-MS1 years ago | 283 | ) |
| 284 | { | |
a56f62ecRaymond-MS1 years ago | 285 | NotifService *Service; |
| 286 | UINT8 Uuid[16]; | |
| 287 | NotificationStatus ReturnVal; | |
| 288 | | |
| 289 | ReturnVal = NOTIFICATION_STATUS_NO_MEM; | |
97eb3c34Raymond-MS1 years ago | 290 | |
1cf65721Raymond-MS1 years ago | 291 | /* Extract the UUID from the message x7-x8 (i.e. Arg3-Arg4) */ |
| 292 | NotificationServiceExtractUuid (Request->Arg3, Request->Arg4, Uuid); | |
97eb3c34Raymond-MS1 years ago | 293 | |
1cf65721Raymond-MS1 years ago | 294 | /* Attempt to locate the service via the UUID provided */ |
| 295 | Service = LocateService (Uuid, FALSE); | |
97eb3c34Raymond-MS1 years ago | 296 | |
| 297 | /* The UUID was not found in the list, attempt to find an empty location to add it */ | |
| 298 | if (Service == NULL) { | |
1cf65721Raymond-MS1 years ago | 299 | Service = LocateService (Uuid, TRUE); |
97eb3c34Raymond-MS1 years ago | 300 | } |
| 301 | | |
1cf65721Raymond-MS1 years ago | 302 | /* Check for a valid UUID */ |
a56f62ecRaymond-MS1 years ago | 303 | if (Service != NULL) { |
1cf65721Raymond-MS1 years ago | 304 | ReturnVal = UpdateServiceInfo (FALSE, Request, Service); |
| 305 | /* Check if the update was successful and this was a new addition */ | |
| 306 | if ((ReturnVal == NOTIFICATION_STATUS_SUCCESS) && (!Service->InUse)) { | |
| 307 | /* Update the UUID and set the location to InUse */ | |
| 308 | CopyMem (Service->ServiceUuid, Uuid, sizeof (Uuid)); | |
| 309 | Service->InUse = TRUE; | |
| 310 | } | |
97eb3c34Raymond-MS1 years ago | 311 | } else { |
1cf65721Raymond-MS1 years ago | 312 | DEBUG ((DEBUG_ERROR, "Service Register Failed - Error Code: %d\n", ReturnVal)); |
97eb3c34Raymond-MS1 years ago | 313 | } |
| 314 | | |
| 315 | return ReturnVal; | |
| 316 | } | |
| 317 | | |
| 318 | /** | |
1cf65721Raymond-MS1 years ago | 319 | Handler for Notification Unregister command |
97eb3c34Raymond-MS1 years ago | 320 | |
| 321 | @param Request The incoming message | |
| 322 | @param Response The outgoing message | |
| 323 | | |
| 324 | @retval NOTIFICATION_STATUS_SUCCESS Success | |
| 325 | @retval NOTIFICATION_STATUS_INVALID_PARAMETER Invalid parameter | |
| 326 | | |
| 327 | **/ | |
| 328 | STATIC | |
| 329 | NotificationStatus | |
1cf65721Raymond-MS1 years ago | 330 | UnregisterHandler ( |
| 331 | DIRECT_MSG_ARGS_EX *Request | |
97eb3c34Raymond-MS1 years ago | 332 | ) |
| 333 | { | |
a56f62ecRaymond-MS1 years ago | 334 | NotifService *Service; |
| 335 | UINT8 Uuid[16]; | |
| 336 | NotificationStatus ReturnVal; | |
| 337 | | |
| 338 | ReturnVal = NOTIFICATION_STATUS_INVALID_PARAMETER; | |
97eb3c34Raymond-MS1 years ago | 339 | |
1cf65721Raymond-MS1 years ago | 340 | /* Extract the UUID from the message x7-x8 (i.e. Arg3-Arg4) */ |
| 341 | NotificationServiceExtractUuid (Request->Arg3, Request->Arg4, Uuid); | |
97eb3c34Raymond-MS1 years ago | 342 | |
1cf65721Raymond-MS1 years ago | 343 | /* Attempt to locate the service via the UUID provided */ |
| 344 | Service = LocateService (Uuid, FALSE); | |
97eb3c34Raymond-MS1 years ago | 345 | |
1cf65721Raymond-MS1 years ago | 346 | /* Check for a valid UUID */ |
a56f62ecRaymond-MS1 years ago | 347 | if (Service != NULL) { |
1cf65721Raymond-MS1 years ago | 348 | ReturnVal = UpdateServiceInfo (TRUE, Request, Service); |
97eb3c34Raymond-MS1 years ago | 349 | } else { |
1cf65721Raymond-MS1 years ago | 350 | DEBUG ((DEBUG_ERROR, "Service Unregister Failed - Error Code: %d\n", ReturnVal)); |
97eb3c34Raymond-MS1 years ago | 351 | } |
| 352 | | |
| 353 | return ReturnVal; | |
| 354 | } | |
| 355 | | |
| 356 | /** | |
| 357 | Initializes the Notification service | |
| 358 | | |
| 359 | **/ | |
| 360 | VOID | |
| 361 | NotificationServiceInit ( | |
| 362 | VOID | |
| 363 | ) | |
| 364 | { | |
1cf65721Raymond-MS1 years ago | 365 | /* Initialize Global Bitmask */ |
a56f62ecRaymond-MS1 years ago | 366 | GlobalBitmask = 0; |
| 367 | | |
1cf65721Raymond-MS1 years ago | 368 | /* Initialize the Notification Service structure */ |
| 369 | ZeroMem (&NotificationServices[0], sizeof (NotificationServices)); | |
97eb3c34Raymond-MS1 years ago | 370 | } |
| 371 | | |
| 372 | /** | |
| 373 | Deinitializes the Notification service | |
| 374 | | |
| 375 | **/ | |
| 376 | VOID | |
| 377 | NotificationServiceDeInit ( | |
| 378 | VOID | |
| 379 | ) | |
| 380 | { | |
| 381 | /* Nothing to DeInit */ | |
| 382 | } | |
| 383 | | |
| 384 | /** | |
| 385 | Handler for Notification service commands | |
| 386 | | |
| 387 | @param Request The incoming message | |
| 388 | @param Response The outgoing message | |
| 389 | | |
| 390 | **/ | |
| 391 | VOID | |
| 392 | NotificationServiceHandle ( | |
| 393 | DIRECT_MSG_ARGS_EX *Request, | |
| 394 | DIRECT_MSG_ARGS_EX *Response | |
| 395 | ) | |
| 396 | { | |
1cf65721Raymond-MS1 years ago | 397 | NotificationStatus ReturnVal; |
a56f62ecRaymond-MS1 years ago | 398 | |
97eb3c34Raymond-MS1 years ago | 399 | /* Validate the input parameters before attempting to dereference or pass them along */ |
| 400 | if ((Request == NULL) || (Response == NULL)) { | |
| 401 | return; | |
| 402 | } | |
| 403 | | |
1cf65721Raymond-MS1 years ago | 404 | /* TODO: Figure out how to set x5-x8 */ |
| 405 | /* Set common response register values */ | |
| 406 | Response->Arg1 = Request->Arg1; | |
| 407 | Response->Arg2 = Request->Arg2; | |
| 408 | Response->Arg3 = Request->Arg3; | |
| 409 | Response->Arg4 = Request->Arg4; | |
| 410 | Response->Arg5 = Request->Arg5 | MESSAGE_INFO_DIR_RESP; | |
| 411 | | |
| 412 | /* Message ID = Bits[0:1] of x9 (i.e. Arg5)*/ | |
| 413 | switch (Request->Arg5 & MESSAGE_INFO_ID_MASK) { | |
| 414 | case NOTIFICATION_OPCODE_ADD: | |
| 415 | case NOTIFICATION_OPCODE_REMOVE: | |
| 416 | ReturnVal = NOTIFICATION_STATUS_NOT_SUPPORTED; | |
| 417 | DEBUG ((DEBUG_ERROR, "Add/Remove Unsupported\n")); | |
| 418 | break; | |
97eb3c34Raymond-MS1 years ago | 419 | |
1cf65721Raymond-MS1 years ago | 420 | case NOTIFICATION_OPCODE_MEM_ASSIGN: |
| 421 | case NOTIFICATION_OPCODE_MEM_UNASSIGN: | |
| 422 | ReturnVal = NOTIFICATION_STATUS_NOT_SUPPORTED; | |
| 423 | DEBUG ((DEBUG_ERROR, "Memory Assign/Unassign Unsupported\n")); | |
97eb3c34Raymond-MS1 years ago | 424 | break; |
| 425 | | |
1cf65721Raymond-MS1 years ago | 426 | case NOTIFICATION_OPCODE_REGISTER: |
| 427 | ReturnVal = RegisterHandler (Request); | |
97eb3c34Raymond-MS1 years ago | 428 | break; |
| 429 | | |
1cf65721Raymond-MS1 years ago | 430 | case NOTIFICATION_OPCODE_UNREGISTER: |
| 431 | ReturnVal = UnregisterHandler (Request); | |
97eb3c34Raymond-MS1 years ago | 432 | break; |
| 433 | | |
| 434 | default: | |
1cf65721Raymond-MS1 years ago | 435 | ReturnVal = NOTIFICATION_STATUS_INVALID_PARAMETER; |
97eb3c34Raymond-MS1 years ago | 436 | DEBUG ((DEBUG_ERROR, "Invalid Notification Service Opcode\n")); |
| 437 | break; | |
| 438 | } | |
1cf65721Raymond-MS1 years ago | 439 | |
| 440 | /* Update the return status - Bits[0:7] of x10 (i.e. Arg6) */ | |
| 441 | Response->Arg6 = (((UINTN)(UINT8)ReturnVal) & RETURN_STATUS_MASK); | |
97eb3c34Raymond-MS1 years ago | 442 | } |
| 443 | | |
| 444 | /** | |
| 445 | Calls NotificationSet on the given ID with the given flag | |
| 446 | | |
| 447 | @param Id The ID to trigger the event on | |
| 448 | @param ServiceUuid The service containing the ID to trigger | |
| 449 | @param Flag The NotificationSet flag to use | |
| 450 | | |
| 451 | @retval NOTIFICATION_STATUS_SUCCESS Success | |
| 452 | @retval NOTIFICATION_STATUS_INVALID_PARAMETER Invalid parameter | |
| 453 | | |
| 454 | **/ | |
| 455 | NotificationStatus | |
| 456 | NotificationServiceIdSet ( | |
1cf65721Raymond-MS1 years ago | 457 | UINT32 Cookie, |
97eb3c34Raymond-MS1 years ago | 458 | UINT8 *ServiceUuid, |
| 459 | UINT32 Flag | |
| 460 | ) | |
| 461 | { | |
a56f62ecRaymond-MS1 years ago | 462 | NotifService *Service; |
| 463 | NotificationStatus ReturnVal; | |
| 464 | UINT8 Index; | |
| 465 | UINT64 Bitmask; | |
| 466 | EFI_STATUS Status; | |
| 467 | | |
97eb3c34Raymond-MS1 years ago | 468 | /* Validate the incoming function parameters */ |
| 469 | if (ServiceUuid == NULL) { | |
| 470 | return NOTIFICATION_STATUS_INVALID_PARAMETER; | |
| 471 | } | |
| 472 | | |
a56f62ecRaymond-MS1 years ago | 473 | ReturnVal = NOTIFICATION_STATUS_INVALID_PARAMETER; |
97eb3c34Raymond-MS1 years ago | 474 | |
1cf65721Raymond-MS1 years ago | 475 | /* Attempt to locate the service via the UUID provided */ |
| 476 | Service = LocateService (ServiceUuid, FALSE); | |
97eb3c34Raymond-MS1 years ago | 477 | |
1cf65721Raymond-MS1 years ago | 478 | /* Check for a valid UUID */ |
97eb3c34Raymond-MS1 years ago | 479 | if (Service != NULL) { |
1cf65721Raymond-MS1 years ago | 480 | /* Attempt to find the cookie within the mapped list */ |
| 481 | for (Index = 0; Index < NOTIFICATION_MAX_MAPPINGS; Index++) { | |
| 482 | if (Service->ServiceInfo[Index].Cookie == Cookie) { | |
| 483 | Bitmask = (1 << Service->ServiceInfo[Index].Id); | |
| 484 | if (Service->ServiceInfo[Index].PerVcpu) { | |
| 485 | Flag |= (1 << PER_VCPU_BIT_POS); | |
| 486 | } | |
| 487 | | |
| 488 | Status = FfaNotificationSet (Service->ServiceInfo[Index].SourceId, Flag, Bitmask); | |
| 489 | if (!EFI_ERROR (Status)) { | |
97eb3c34Raymond-MS1 years ago | 490 | ReturnVal = NOTIFICATION_STATUS_SUCCESS; |
| 491 | } | |
| 492 | | |
| 493 | break; | |
| 494 | } | |
| 495 | } | |
| 496 | } | |
| 497 | | |
| 498 | return ReturnVal; | |
| 499 | } | |
| 500 | | |
| 501 | /** | |
| 502 | Extracts the UUID from the message arguments | |
| 503 | | |
1cf65721Raymond-MS1 years ago | 504 | @param UuidLo The lower bytes of the UUID |
| 505 | @param UuidHi The higher bytes of the UUID | |
| 506 | @param Uuid The UUID to populate | |
97eb3c34Raymond-MS1 years ago | 507 | |
| 508 | **/ | |
| 509 | VOID | |
| 510 | NotificationServiceExtractUuid ( | |
1cf65721Raymond-MS1 years ago | 511 | UINT64 UuidLo, |
| 512 | UINT64 UuidHi, | |
| 513 | UINT8 *Uuid | |
97eb3c34Raymond-MS1 years ago | 514 | ) |
| 515 | { | |
1cf65721Raymond-MS1 years ago | 516 | UINT8 Index; |
| 517 | UINT8 UuidHiByte; | |
| 518 | UINT8 UuidLoByte; | |
a56f62ecRaymond-MS1 years ago | 519 | |
97eb3c34Raymond-MS1 years ago | 520 | /* Validate the incoming function parameters */ |
1cf65721Raymond-MS1 years ago | 521 | if (Uuid == NULL) { |
97eb3c34Raymond-MS1 years ago | 522 | return; |
| 523 | } | |
| 524 | | |
| 525 | /* Copy the upper 8 bytes */ | |
a56f62ecRaymond-MS1 years ago | 526 | for (Index = 0; Index < 8; Index++) { |
03d3c59akuqin121 years ago | 527 | UuidHiByte = (UINT8)(UuidHi >> ((7 - Index) * 8)); |
a56f62ecRaymond-MS1 years ago | 528 | Uuid[Index] = UuidHiByte; |
97eb3c34Raymond-MS1 years ago | 529 | } |
| 530 | | |
| 531 | /* Copy the lower 8 bytes */ | |
a56f62ecRaymond-MS1 years ago | 532 | for (Index = 8; Index < 16; Index++) { |
03d3c59akuqin121 years ago | 533 | UuidLoByte = (UINT8)(UuidLo >> ((15 - Index) * 8)); |
a56f62ecRaymond-MS1 years ago | 534 | Uuid[Index] = UuidLoByte; |
97eb3c34Raymond-MS1 years ago | 535 | } |
| 536 | } |