blob: db665203f39c911a89f18a754d7a8ac068ffb07c [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>
nabkah01002e5692022-10-10 12:36:46 +010012
13/**
14 * @brief - Returns the base address of the shared region
15 * @param - Void
16 * @return - Base address of the shared region
17 **/
18
19static host_shared_data_t *guest_shared_data;
20
21/*
22 * Set guest mapped shared buffer pointer
23 */
24void realm_set_shared_structure(host_shared_data_t *ptr)
25{
26 guest_shared_data = ptr;
27}
28
29/*
30 * Get guest mapped shared buffer pointer
31 */
Shruti Gupta550e3e82023-08-16 13:20:11 +010032host_shared_data_t *realm_get_my_shared_structure(void)
nabkah01002e5692022-10-10 12:36:46 +010033{
AlexeiFedorovf09c77a2024-09-10 15:50:44 +010034 return &guest_shared_data[REC_IDX(read_mpidr_el1())];
nabkah01002e5692022-10-10 12:36:46 +010035}
36
37/*
38 * Return Host's data at index
39 */
Shruti Gupta550e3e82023-08-16 13:20:11 +010040u_register_t realm_shared_data_get_my_host_val(uint8_t index)
nabkah01002e5692022-10-10 12:36:46 +010041{
Shruti Gupta550e3e82023-08-16 13:20:11 +010042 assert(index < MAX_DATA_SIZE);
AlexeiFedorovf09c77a2024-09-10 15:50:44 +010043 return guest_shared_data[REC_IDX(read_mpidr_el1())].host_param_val[index];
nabkah01002e5692022-10-10 12:36:46 +010044}
45
46/*
Shruti Gupta550e3e82023-08-16 13:20:11 +010047 * Get command sent from Host to this rec
nabkah01002e5692022-10-10 12:36:46 +010048 */
Shruti Gupta550e3e82023-08-16 13:20:11 +010049uint8_t realm_shared_data_get_my_realm_cmd(void)
nabkah01002e5692022-10-10 12:36:46 +010050{
AlexeiFedorovf09c77a2024-09-10 15:50:44 +010051 return guest_shared_data[REC_IDX(read_mpidr_el1())].realm_cmd;
nabkah01002e5692022-10-10 12:36:46 +010052}
Shruti Gupta550e3e82023-08-16 13:20:11 +010053
54/*
55 * Set data to be shared from this rec to Host
56 */
57void realm_shared_data_set_my_realm_val(uint8_t index, u_register_t val)
58{
59 assert(index < MAX_DATA_SIZE);
AlexeiFedorovf09c77a2024-09-10 15:50:44 +010060 guest_shared_data[REC_IDX(read_mpidr_el1())].realm_out_val[index] = val;
Shruti Gupta550e3e82023-08-16 13:20:11 +010061}