blob: c52072ee0d368113ff6ba4342ecc871290ba5ff8 [file] [log] [blame]
nabkah01002e5692022-10-10 12:36:46 +01001/*
AlexeiFedorovf09c77a2024-09-10 15:50:44 +01002 * Copyright (c) 2022-2024, Arm Limited. All rights reserved.
nabkah01002e5692022-10-10 12:36:46 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <string.h>
Shruti Gupta550e3e82023-08-16 13:20:11 +01008#include <arch_helpers.h>
9#include <assert.h>
nabkah01002e5692022-10-10 12:36:46 +010010#include <host_shared_data.h>
AlexeiFedorovf09c77a2024-09-10 15:50:44 +010011#include <realm_def.h>
Shruti Gupta69cae792024-11-27 04:30:00 +000012#include <realm_helpers.h>
nabkah01002e5692022-10-10 12:36:46 +010013
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 Gupta69cae792024-11-27 04:30:00 +000020static host_shared_data_arr_t guest_shared_data;
nabkah01002e5692022-10-10 12:36:46 +010021
22/*
23 * Set guest mapped shared buffer pointer
24 */
Shruti Gupta69cae792024-11-27 04:30:00 +000025void realm_set_shared_structure(u_register_t ptr)
nabkah01002e5692022-10-10 12:36:46 +010026{
Shruti Gupta69cae792024-11-27 04:30:00 +000027 guest_shared_data = (host_shared_data_arr_t)ptr;
nabkah01002e5692022-10-10 12:36:46 +010028}
29
30/*
31 * Get guest mapped shared buffer pointer
32 */
Shruti Gupta550e3e82023-08-16 13:20:11 +010033host_shared_data_t *realm_get_my_shared_structure(void)
nabkah01002e5692022-10-10 12:36:46 +010034{
Shruti Gupta69cae792024-11-27 04:30:00 +000035 return &(*guest_shared_data)[realm_get_my_plane_num()][REC_IDX(read_mpidr_el1())];
nabkah01002e5692022-10-10 12:36:46 +010036}
37
38/*
39 * Return Host's data at index
40 */
Shruti Gupta550e3e82023-08-16 13:20:11 +010041u_register_t realm_shared_data_get_my_host_val(uint8_t index)
nabkah01002e5692022-10-10 12:36:46 +010042{
Shruti Gupta550e3e82023-08-16 13:20:11 +010043 assert(index < MAX_DATA_SIZE);
Shruti Gupta69cae792024-11-27 04:30:00 +000044 return (*guest_shared_data)[realm_get_my_plane_num()][REC_IDX(read_mpidr_el1())].host_param_val[index];
nabkah01002e5692022-10-10 12:36:46 +010045}
46
47/*
Shruti Gupta550e3e82023-08-16 13:20:11 +010048 * Get command sent from Host to this rec
nabkah01002e5692022-10-10 12:36:46 +010049 */
Shruti Gupta550e3e82023-08-16 13:20:11 +010050uint8_t realm_shared_data_get_my_realm_cmd(void)
nabkah01002e5692022-10-10 12:36:46 +010051{
Shruti Gupta69cae792024-11-27 04:30:00 +000052 return (*guest_shared_data)[realm_get_my_plane_num()][REC_IDX(read_mpidr_el1())].realm_cmd;
nabkah01002e5692022-10-10 12:36:46 +010053}
Shruti Gupta550e3e82023-08-16 13:20:11 +010054
55/*
56 * Set data to be shared from this rec to Host
57 */
58void realm_shared_data_set_my_realm_val(uint8_t index, u_register_t val)
59{
60 assert(index < MAX_DATA_SIZE);
Shruti Gupta69cae792024-11-27 04:30:00 +000061 (*guest_shared_data)[realm_get_my_plane_num()][REC_IDX(read_mpidr_el1())].realm_out_val[index] = val;
62}
63
64void 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
75u_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
85u_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
95void 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 Gupta550e3e82023-08-16 13:20:11 +0100102}