1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4  */
5 #ifndef HOST_HARNESS_H
6 #define HOST_HARNESS_H
7 
8 #include <stdbool.h>
9 #include <stddef.h>
10 #include <stdint.h>
11 #include <types.h>
12 
13 /* Fake host wrapper to read and write sysregs */
14 u_register_t host_read_sysreg(char *reg_name);
15 void host_write_sysreg(char *reg_name, u_register_t v);
16 
17 struct spinlock_s;
18 struct byte_spinlock_s;
19 
20 /* Fake host harness to lock and release spin lock */
21 void host_spinlock_acquire(struct spinlock_s *l);
22 void host_spinlock_release(struct spinlock_s *l);
23 void host_byte_spinlock_acquire(struct byte_spinlock_s *l);
24 void host_byte_spinlock_release(struct byte_spinlock_s *l);
25 
26 /*
27  * Fake host Wrapper to copy data from NS into Realm memory. The function
28  * returns true if the copy succeeds. If the access to the NS memory generates
29  * a fault, false is returned to the caller. In case of failure
30  * (when false is returned), partial data may have been written to the
31  * destination buffer.
32  *
33  * Args:
34  *    dest - The address of buffer in Realm memory to write into.
35  *    ns_src - The address of buffer in NS memory to read from.
36  *    size - The number of bytes to copy.
37  *    All arguments must be aligned to 8 bytes.
38  */
39 
40 bool host_memcpy_ns_read(void *dest, const void *ns_src, unsigned long size);
41 
42 /*
43  * Fake host wrapper to copy data from Realm into NS memory.The function
44  * returns true if the copy succeeds. If the access to the NS memory generates
45  * a fault, false is returned to the caller. In case of failure (when false is
46  * returned), partial data may have been written to the destination buffer.
47  *
48  * Args:
49  *    ns_dest - The address of buffer in NS memory to write into.
50  *    src - The address of buffer in Realm memory to read from.
51  *    size - The number of bytes to copy.
52  *    All arguments must be aligned to 8 bytes.
53  */
54 bool host_memcpy_ns_write(void *ns_dest, const void *src, unsigned long size);
55 
56 /*
57  * Fake host wrapper to run a realm.
58  * Args:
59  *     regs - pointer to GP regs to be restored/save when entering/exiting
60  *            Realm
61  * Return: Realm exception syndrome return.
62  */
63 int host_run_realm(unsigned long *regs);
64 
65 /*
66  * Fake Host wrapper for monitor_call.
67  */
68 unsigned long host_monitor_call(unsigned long id, unsigned long arg0,
69 		unsigned long arg1, unsigned long arg2, unsigned long arg3,
70 		unsigned long arg4, unsigned long arg5);
71 
72 struct smc_result;
73 /*
74  * Fake Host wrapper for monitor_call_with_res.
75  */
76 void host_monitor_call_with_res(unsigned long id, unsigned long arg0,
77 		unsigned long arg1, unsigned long arg2, unsigned long arg3,
78 		unsigned long arg4, unsigned long arg5,
79 		struct smc_result *res);
80 
81 /*
82  * Fake host wrapper to map a given PA.
83  *
84  * It returns the VA to which the buffer is mapped.
85  */
86 void *host_buffer_arch_map(unsigned int slot, unsigned long addr);
87 
88 /*
89  * Fake host wrapper to unmap a buffer slot correspondig to the VA passed
90  * in `buf`.
91  */
92 void host_buffer_arch_unmap(void *buf);
93 
94 /*
95  * Fake host wrapper to delegate a granule using the Granule Transition Service
96  */
97 unsigned long host_gtsi_delegate(unsigned long addr);
98 
99 /*
100  * Fake host wrapper to undelegate a granule using the Granule Transition Service
101  */
102 unsigned long host_gtsi_undelegate(unsigned long addr);
103 
104 #endif /* HOST_HARNESS_H */
105