blob: c852d89df5620fbe1f0bc76bfca46cb8c5315e29 [file] [log] [blame]
nabkah01002e5692022-10-10 12:36:46 +01001/*
AlexeiFedorov2f30f102023-03-13 19:37:46 +00002 * Copyright (c) 2022-2023, Arm Limited. All rights reserved.
nabkah01002e5692022-10-10 12:36:46 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef HOST_SHARED_DATA_H
8#define HOST_SHARED_DATA_H
9
10#include <stdint.h>
11#include <spinlock.h>
12
13#define MAX_BUF_SIZE 10240U
14#define MAX_DATA_SIZE 5U
15
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010016#define REALM_CMD_BUFFER_SIZE 1024U
17
nabkah01002e5692022-10-10 12:36:46 +010018/*
19 * This structure maps the shared memory to be used between the Host and Realm
20 * payload
21 */
22typedef struct host_shared_data {
AlexeiFedorov2f30f102023-03-13 19:37:46 +000023 /* Buffer used from Realm for logging */
nabkah01002e5692022-10-10 12:36:46 +010024 uint8_t log_buffer[MAX_BUF_SIZE];
25
AlexeiFedorov2f30f102023-03-13 19:37:46 +000026 /* Command set from Host and used by Realm */
nabkah01002e5692022-10-10 12:36:46 +010027 uint8_t realm_cmd;
28
AlexeiFedorov2f30f102023-03-13 19:37:46 +000029 /* array of params passed from Host to Realm */
nabkah01002e5692022-10-10 12:36:46 +010030 u_register_t host_param_val[MAX_DATA_SIZE];
31
AlexeiFedorov2f30f102023-03-13 19:37:46 +000032 /* array of output results passed from Realm to Host */
nabkah01002e5692022-10-10 12:36:46 +010033 u_register_t realm_out_val[MAX_DATA_SIZE];
34
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010035 /* Buffer to save Realm command results */
36 uint8_t realm_cmd_output_buffer[REALM_CMD_BUFFER_SIZE];
37
nabkah01002e5692022-10-10 12:36:46 +010038 /* Lock to avoid concurrent accesses to log_buffer */
39 spinlock_t printf_lock;
40} host_shared_data_t;
41
42/*
43 * Different commands that the Host can requests the Realm to perform
44 */
45enum realm_cmd {
46 REALM_SLEEP_CMD = 1U,
AlexeiFedorov2f30f102023-03-13 19:37:46 +000047 REALM_GET_RSI_VERSION,
48 REALM_PMU_CYCLE,
49 REALM_PMU_EVENT,
50 REALM_PMU_PRESERVE,
Shruti Gupta369955a2023-04-19 18:05:56 +010051 REALM_PMU_INTERRUPT,
52 REALM_REQ_FPU_FILL_CMD,
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010053 REALM_REQ_FPU_CMP_CMD,
54 REALM_SVE_RDVL,
55 REALM_SVE_ID_REGISTERS,
Arunachalam Ganapathyc1136a82023-04-12 15:24:44 +010056 REALM_SVE_PROBE_VL,
57 REALM_SVE_OPS
nabkah01002e5692022-10-10 12:36:46 +010058};
59
60/*
61 * Index values for each parameter in the host_param_val array.
62 */
63enum host_param_index {
64 HOST_CMD_INDEX = 0U,
65 HOST_SLEEP_INDEX
66};
AlexeiFedorov2f30f102023-03-13 19:37:46 +000067
68enum host_call_cmd {
69 HOST_CALL_GET_SHARED_BUFF_CMD = 1U,
70 HOST_CALL_EXIT_SUCCESS_CMD,
71 HOST_CALL_EXIT_FAILED_CMD
72};
73
nabkah01002e5692022-10-10 12:36:46 +010074/*
75 * Return shared buffer pointer mapped as host_shared_data_t structure
76 */
77host_shared_data_t *host_get_shared_structure(void);
AlexeiFedorov2f30f102023-03-13 19:37:46 +000078
nabkah01002e5692022-10-10 12:36:46 +010079/*
80 * Set data to be shared from Host to realm
81 */
82void realm_shared_data_set_host_val(uint8_t index, u_register_t val);
83
84/*
85 * Set guest mapped shared buffer pointer
86 */
87void realm_set_shared_structure(host_shared_data_t *ptr);
88
89/*
90 * Get guest mapped shared buffer pointer
91 */
92host_shared_data_t *realm_get_shared_structure(void);
93
94/*
95 * Set data to be shared from Realm to Host
96 */
97void realm_shared_data_set_realm_val(uint8_t index, u_register_t val);
98
99/*
100 * Return Host's data at index
101 */
102u_register_t realm_shared_data_get_host_val(uint8_t index);
103
104/*
105 * Return Realm's data at index
106 */
107u_register_t realm_shared_data_get_realm_val(uint8_t index);
108
109/*
110 * Clear shared realm data
111 */
112void realm_shared_data_clear_realm_val(void);
113
114/*
115 * Clear shared Host data
116 */
117void realm_shared_data_clear_host_val(void);
118
119/*
120 * Get command sent from Host to realm
121 */
122uint8_t realm_shared_data_get_realm_cmd(void);
123
124/*
125 * Set command to be send from Host to realm
126 */
127void realm_shared_data_set_realm_cmd(uint8_t cmd);
128
129#endif /* HOST_SHARED_DATA_H */