nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 1 | /* |
AlexeiFedorov | f09c77a | 2024-09-10 15:50:44 +0100 | [diff] [blame] | 2 | * Copyright (c) 2022-2024, Arm Limited. All rights reserved. |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <string.h> |
Shruti Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 8 | #include <arch_helpers.h> |
| 9 | #include <assert.h> |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 10 | #include <host_shared_data.h> |
AlexeiFedorov | f09c77a | 2024-09-10 15:50:44 +0100 | [diff] [blame] | 11 | #include <realm_def.h> |
Shruti Gupta | 69cae79 | 2024-11-27 04:30:00 +0000 | [diff] [blame] | 12 | #include <realm_helpers.h> |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 13 | |
| 14 | /** |
| 15 | * @brief - Returns the base address of the shared region |
| 16 | * @param - Void |
| 17 | * @return - Base address of the shared region |
| 18 | **/ |
| 19 | |
Shruti Gupta | 69cae79 | 2024-11-27 04:30:00 +0000 | [diff] [blame] | 20 | static host_shared_data_arr_t guest_shared_data; |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * Set guest mapped shared buffer pointer |
| 24 | */ |
Shruti Gupta | 69cae79 | 2024-11-27 04:30:00 +0000 | [diff] [blame] | 25 | void realm_set_shared_structure(u_register_t ptr) |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 26 | { |
Shruti Gupta | 69cae79 | 2024-11-27 04:30:00 +0000 | [diff] [blame] | 27 | guest_shared_data = (host_shared_data_arr_t)ptr; |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | /* |
| 31 | * Get guest mapped shared buffer pointer |
| 32 | */ |
Shruti Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 33 | host_shared_data_t *realm_get_my_shared_structure(void) |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 34 | { |
Shruti Gupta | 69cae79 | 2024-11-27 04:30:00 +0000 | [diff] [blame] | 35 | return &(*guest_shared_data)[realm_get_my_plane_num()][REC_IDX(read_mpidr_el1())]; |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | /* |
| 39 | * Return Host's data at index |
| 40 | */ |
Shruti Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 41 | u_register_t realm_shared_data_get_my_host_val(uint8_t index) |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 42 | { |
Shruti Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 43 | assert(index < MAX_DATA_SIZE); |
Shruti Gupta | 69cae79 | 2024-11-27 04:30:00 +0000 | [diff] [blame] | 44 | return (*guest_shared_data)[realm_get_my_plane_num()][REC_IDX(read_mpidr_el1())].host_param_val[index]; |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /* |
Shruti Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 48 | * Get command sent from Host to this rec |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 49 | */ |
Shruti Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 50 | uint8_t realm_shared_data_get_my_realm_cmd(void) |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 51 | { |
Shruti Gupta | 69cae79 | 2024-11-27 04:30:00 +0000 | [diff] [blame] | 52 | return (*guest_shared_data)[realm_get_my_plane_num()][REC_IDX(read_mpidr_el1())].realm_cmd; |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 53 | } |
Shruti Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * Set data to be shared from this rec to Host |
| 57 | */ |
| 58 | void realm_shared_data_set_my_realm_val(uint8_t index, u_register_t val) |
| 59 | { |
| 60 | assert(index < MAX_DATA_SIZE); |
Shruti Gupta | 69cae79 | 2024-11-27 04:30:00 +0000 | [diff] [blame] | 61 | (*guest_shared_data)[realm_get_my_plane_num()][REC_IDX(read_mpidr_el1())].realm_out_val[index] = val; |
| 62 | } |
| 63 | |
| 64 | void realm_shared_data_set_plane_n_val(unsigned int plane_num, unsigned int rec_num, |
| 65 | uint8_t index, u_register_t val) |
| 66 | { |
| 67 | assert(index < MAX_DATA_SIZE); |
| 68 | assert(plane_num < MAX_PLANE_COUNT); |
| 69 | assert(rec_num < MAX_REC_COUNT); |
| 70 | assert(is_plane0); |
| 71 | |
| 72 | (*guest_shared_data)[plane_num][rec_num].realm_out_val[index] = val; |
| 73 | } |
| 74 | |
| 75 | u_register_t realm_shared_data_get_plane_n_val(unsigned int plane_num, |
| 76 | unsigned int rec_num, uint8_t index) |
| 77 | { |
| 78 | assert(plane_num < MAX_PLANE_COUNT); |
| 79 | assert(rec_num < MAX_REC_COUNT); |
| 80 | assert(is_plane0); |
| 81 | |
| 82 | return (*guest_shared_data)[plane_num][rec_num].realm_out_val[index]; |
| 83 | } |
| 84 | |
| 85 | u_register_t realm_shared_data_get_plane_n_cmd(unsigned int plane_num, |
| 86 | unsigned int rec_num, uint8_t index) |
| 87 | { |
| 88 | assert(plane_num < MAX_PLANE_COUNT); |
| 89 | assert(rec_num < MAX_REC_COUNT); |
| 90 | assert(is_plane0); |
| 91 | |
| 92 | return (*guest_shared_data)[plane_num][rec_num].realm_cmd; |
| 93 | } |
| 94 | |
| 95 | void realm_shared_data_set_plane_n_cmd(uint8_t cmd, unsigned int plane_num, unsigned int rec_num) |
| 96 | { |
| 97 | assert(plane_num < MAX_PLANE_COUNT); |
| 98 | assert(rec_num < MAX_REC_COUNT); |
| 99 | assert(is_plane0); |
| 100 | |
| 101 | (*guest_shared_data)[plane_num][rec_num].realm_cmd = cmd; |
Shruti Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 102 | } |