1 /*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4 */
5
6 #include <arch.h>
7 #include <host_utils.h>
8 #include <spinlock.h>
9 #include <string.h>
10
host_memcpy_ns_read(void * dest,const void * ns_src,unsigned long size)11 bool host_memcpy_ns_read(void *dest, const void *ns_src, unsigned long size)
12 {
13 (void)memcpy(dest, ns_src, size);
14 return true;
15 }
16
host_memcpy_ns_write(void * ns_dest,const void * src,unsigned long size)17 bool host_memcpy_ns_write(void *ns_dest, const void *src, unsigned long size)
18 {
19 (void)memcpy(ns_dest, src, size);
20 return true;
21 }
22
host_monitor_call(unsigned long id,unsigned long arg0,unsigned long arg1,unsigned long arg2,unsigned long arg3,unsigned long arg4,unsigned long arg5)23 unsigned long host_monitor_call(unsigned long id,
24 unsigned long arg0,
25 unsigned long arg1,
26 unsigned long arg2,
27 unsigned long arg3,
28 unsigned long arg4,
29 unsigned long arg5)
30 {
31 /* Avoid MISRA C:2102-2.7 warnings */
32 (void)id;
33 (void)arg0;
34 (void)arg1;
35 (void)arg2;
36 (void)arg3;
37 (void)arg4;
38 (void)arg5;
39 return 0UL;
40 }
41
host_monitor_call_with_res(unsigned long id,unsigned long arg0,unsigned long arg1,unsigned long arg2,unsigned long arg3,unsigned long arg4,unsigned long arg5,struct smc_result * res)42 void host_monitor_call_with_res(unsigned long id,
43 unsigned long arg0,
44 unsigned long arg1,
45 unsigned long arg2,
46 unsigned long arg3,
47 unsigned long arg4,
48 unsigned long arg5,
49 struct smc_result *res)
50 {
51 /* Avoid MISRA C:2102-2.7 warnings */
52 (void)id;
53 (void)arg0;
54 (void)arg1;
55 (void)arg2;
56 (void)arg3;
57 (void)arg4;
58 (void)arg5;
59 (void)res;
60 }
61
host_run_realm(unsigned long * regs)62 int host_run_realm(unsigned long *regs)
63 {
64 /* Return an arbitrary exception */
65 return ARM_EXCEPTION_SYNC_LEL;
66 }
67
host_spinlock_acquire(spinlock_t * l)68 void host_spinlock_acquire(spinlock_t *l)
69 {
70 l->val = 1;
71 }
72
host_spinlock_release(spinlock_t * l)73 void host_spinlock_release(spinlock_t *l)
74 {
75 l->val = 0;
76 }
77
host_read_sysreg(char * reg_name)78 u_register_t host_read_sysreg(char *reg_name)
79 {
80 struct sysreg_cb *callbacks = host_util_get_sysreg_cb(reg_name);
81
82 /*
83 * Return 0UL as default value for registers which do not have
84 * a read callback installed.
85 */
86 if (callbacks == NULL) {
87 return 0UL;
88 }
89
90 if (callbacks->rd_cb == NULL) {
91 return 0UL;
92 }
93
94 return callbacks->rd_cb(&callbacks->value);
95 }
96
host_write_sysreg(char * reg_name,u_register_t v)97 void host_write_sysreg(char *reg_name, u_register_t v)
98 {
99 struct sysreg_cb *callbacks = host_util_get_sysreg_cb(reg_name);
100
101 /*
102 * Ignore the write if the register does not have a write
103 * callback installed.
104 */
105 if (callbacks != NULL) {
106 if (callbacks->wr_cb != NULL) {
107 callbacks->wr_cb(v, &callbacks->value);
108 }
109 }
110 }
111