summaryrefslogtreecommitdiff
path: root/include/runtime_services/host_realm_managment/host_shared_data.h
blob: 77203347d36fe5306a8ff6ff54dbdad227bfa451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright (c) 2022-2023, Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef HOST_SHARED_DATA_H
#define HOST_SHARED_DATA_H

#include <stdint.h>
#include <spinlock.h>

#define MAX_BUF_SIZE		10240U
#define MAX_DATA_SIZE		5U

/*
 * This structure maps the shared memory to be used between the Host and Realm
 * payload
 */
typedef struct host_shared_data {
	/* Buffer used from Realm for logging */
	uint8_t log_buffer[MAX_BUF_SIZE];

	/* Command set from Host and used by Realm */
	uint8_t realm_cmd;

	/* array of params passed from Host to Realm */
	u_register_t host_param_val[MAX_DATA_SIZE];

	/* array of output results passed from Realm to Host */
	u_register_t realm_out_val[MAX_DATA_SIZE];

	/* Lock to avoid concurrent accesses to log_buffer */
	spinlock_t printf_lock;
} host_shared_data_t;

/*
 * Different commands that the Host can requests the Realm to perform
 */
enum realm_cmd {
	REALM_SLEEP_CMD = 1U,
	REALM_GET_RSI_VERSION,
	REALM_PMU_CYCLE,
	REALM_PMU_EVENT,
	REALM_PMU_PRESERVE,
	REALM_PMU_INTERRUPT,
	REALM_REQ_FPU_FILL_CMD,
	REALM_REQ_FPU_CMP_CMD
};

/*
 * Index values for each parameter in the host_param_val array.
 */
enum host_param_index {
	HOST_CMD_INDEX = 0U,
	HOST_SLEEP_INDEX
};

enum host_call_cmd {
        HOST_CALL_GET_SHARED_BUFF_CMD = 1U,
        HOST_CALL_EXIT_SUCCESS_CMD,
        HOST_CALL_EXIT_FAILED_CMD
};

/*
 * Return shared buffer pointer mapped as host_shared_data_t structure
 */
host_shared_data_t *host_get_shared_structure(void);

/*
 * Set data to be shared from Host to realm
 */
void realm_shared_data_set_host_val(uint8_t index, u_register_t val);

/*
 * Set guest mapped shared buffer pointer
 */
void realm_set_shared_structure(host_shared_data_t *ptr);

/*
 * Get guest mapped shared buffer pointer
 */
host_shared_data_t *realm_get_shared_structure(void);

/*
 * Set data to be shared from Realm to Host
 */
void realm_shared_data_set_realm_val(uint8_t index, u_register_t val);

/*
 * Return Host's data at index
 */
u_register_t realm_shared_data_get_host_val(uint8_t index);

/*
 * Return Realm's data at index
 */
u_register_t realm_shared_data_get_realm_val(uint8_t index);

/*
 * Clear shared realm data
 */
void realm_shared_data_clear_realm_val(void);

/*
 * Clear shared Host data
 */
void realm_shared_data_clear_host_val(void);

/*
 * Get command sent from Host to realm
 */
uint8_t realm_shared_data_get_realm_cmd(void);

/*
 * Set command to be send from Host to realm
 */
void realm_shared_data_set_realm_cmd(uint8_t cmd);

#endif /* HOST_SHARED_DATA_H */