Gabor Toth | 3db0e25 | 2025-03-11 14:46:05 +0100 | [diff] [blame^] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
| 2 | /* |
| 3 | * Copyright (c) 2025, Arm Limited and Contributors. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | #include "sp_notification.h" |
| 7 | #include "sp_api.h" |
| 8 | #include <assert.h> |
| 9 | #include <string.h> |
| 10 | |
| 11 | static uint32_t build_notif_bind_flags(struct sp_notif_bind_flags *flags) |
| 12 | { |
| 13 | uint32_t res = 0; |
| 14 | |
| 15 | if (flags->per_cpu) |
| 16 | res |= FFA_NOTIF_BIND_FLAGS_PER_VCPU_NOTIFICATIONS; |
| 17 | |
| 18 | return res; |
| 19 | } |
| 20 | |
| 21 | static uint32_t build_notif_set_flags(struct sp_notif_set_flags *flags) |
| 22 | { |
| 23 | uint32_t res = 0; |
| 24 | |
| 25 | if (flags->per_cpu) { |
| 26 | res |= FFA_NOTIF_SET_FLAGS_PER_VCPU_NOTIFICATIONS; |
| 27 | res |= SHIFT_U32(flags->receiver_vcpu_id, FFA_NOTIF_SET_FLAGS_RECEIVER_VCPU_SHIFT); |
| 28 | } |
| 29 | |
| 30 | if (flags->delay_sched_rec_intr) |
| 31 | res |= FFA_NOTIF_SET_FLAGS_DELAY_SCHEDULE_RECEIVER; |
| 32 | |
| 33 | return res; |
| 34 | } |
| 35 | |
| 36 | sp_result sp_notification_bind(uint16_t sender, uint16_t receiver, |
| 37 | struct sp_notif_bind_flags *flags, uint64_t notification_bitmap) |
| 38 | { |
| 39 | return SP_RESULT_FFA(ffa_notification_bind(sender, receiver, build_notif_bind_flags(flags), |
| 40 | notification_bitmap)); |
| 41 | } |
| 42 | |
| 43 | sp_result sp_notification_unbind(uint16_t sender, uint16_t receiver, uint64_t notification_bitmap) |
| 44 | { |
| 45 | return SP_RESULT_FFA(ffa_notification_unbind(sender, receiver, notification_bitmap)); |
| 46 | } |
| 47 | |
| 48 | sp_result sp_notification_set(uint16_t sender, uint16_t receiver, struct sp_notif_set_flags *flags, |
| 49 | uint64_t notification_bitmap) |
| 50 | { |
| 51 | if (!flags->per_cpu && flags->receiver_vcpu_id) |
| 52 | return SP_RESULT_INVALID_PARAMETERS; |
| 53 | |
| 54 | return SP_RESULT_FFA(ffa_notification_set(sender, receiver, build_notif_set_flags(flags), |
| 55 | notification_bitmap)); |
| 56 | } |
| 57 | |
| 58 | sp_result sp_notification_get(uint16_t sender, uint16_t receiver, uint64_t *sp_notification_bitmap, |
| 59 | uint64_t *vm_notification_bitmap, uint32_t *spm_notification_bitmap, |
| 60 | uint32_t *hv_notification_bitmap) |
| 61 | { |
| 62 | uint32_t flags = 0; |
| 63 | uint64_t buff_framework_notification_bitmap = 0; |
| 64 | uint64_t buff_sp_notification_bitmap = 0; |
| 65 | uint64_t buff_vm_notification_bitmap = 0; |
| 66 | sp_result result = 0; |
| 67 | |
| 68 | if (sp_notification_bitmap) |
| 69 | flags |= FFA_NOTIF_GET_FLAGS_PENDING_SP_NOTIF; |
| 70 | if (vm_notification_bitmap) |
| 71 | flags |= FFA_NOTIF_GET_FLAGS_PENDING_VM_NOTIF; |
| 72 | if (spm_notification_bitmap) |
| 73 | flags |= FFA_NOTIF_GET_FLAGS_PENDING_SPM_NOTIF; |
| 74 | if (hv_notification_bitmap) |
| 75 | flags |= FFA_NOTIF_GET_FLAGS_PENDING_HV_NOTIF; |
| 76 | |
| 77 | result = SP_RESULT_FFA(ffa_notification_get(sender, receiver, flags, &buff_sp_notification_bitmap, |
| 78 | &buff_vm_notification_bitmap, |
| 79 | &buff_framework_notification_bitmap)); |
| 80 | if (sp_notification_bitmap) |
| 81 | *sp_notification_bitmap = buff_sp_notification_bitmap; |
| 82 | if (vm_notification_bitmap) |
| 83 | *vm_notification_bitmap = buff_vm_notification_bitmap; |
| 84 | if (spm_notification_bitmap) |
| 85 | *spm_notification_bitmap = buff_framework_notification_bitmap & 0xFFFFFFFF; |
| 86 | if (hv_notification_bitmap) |
| 87 | *hv_notification_bitmap = buff_framework_notification_bitmap >> 32 & 0xFFFFFFFF; |
| 88 | |
| 89 | return result; |
| 90 | } |