blob: c4cd25973b1c0d04c63fc48ceba6583f2a0c9085 [file] [log] [blame]
Saurabh Gorecha70389ca2020-04-22 21:31:24 +05301/*
2 * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6#include <assert.h>
7#include <stdarg.h>
8#include <stdint.h>
9#include <stdio.h>
10#include <string.h>
11
12#include <arch.h>
13#include <arch_helpers.h>
14#include <bl31/bl31.h>
15#include <context.h>
16#include <drivers/arm/gicv3.h>
17#include <drivers/delay_timer.h>
18#include <lib/coreboot.h>
19#include <lib/el3_runtime/context_mgmt.h>
20#include <lib/spinlock.h>
21#include <lib/xlat_tables/xlat_tables_v2.h>
22
23#include <platform.h>
24#include <qti_plat.h>
25#include <qtiseclib_cb_interface.h>
26
27void *qtiseclib_cb_memcpy(void *dst, const void *src, size_t len)
28{
29 return memcpy(dst, src, len);
30}
31
Saurabh Gorecha7df71122020-09-07 14:52:20 +053032int qtiseclib_cb_strcmp(const char *s1, const char *s2)
33{
34 return strcmp(s1, s2);
35}
36
37void *qtiseclib_cb_memset(void *s, int c, size_t n)
38{
39 return memset(s, c, n);
40}
41
42void *qtiseclib_cb_memmove(void *dest, const void *src, size_t n)
43{
44 return memmove(dest, src, n);
45}
46
Saurabh Gorecha70389ca2020-04-22 21:31:24 +053047/* Printing logs below or equal LOG_LEVEL from QTISECLIB. */
48void qtiseclib_cb_log(unsigned int loglvl, const char *fmt, ...)
49{
50 if (loglvl <= LOG_LEVEL) {
51 va_list argp;
52 static spinlock_t qti_log_lock;
53 uint64_t uptime = read_cntpct_el0();
54
55 va_start(argp, fmt);
56
57 spin_lock(&qti_log_lock);
58 printf("QTISECLIB [%x%08x]",
59 (uint32_t) ((uptime >> 32) & 0xFFFFFFFF),
60 (uint32_t) (uptime & 0xFFFFFFFF));
61 vprintf(fmt, argp);
62 putchar('\n');
63 spin_unlock(&qti_log_lock);
64
65 va_end(argp);
66 }
67}
68
69void qtiseclib_cb_spin_lock(qtiseclib_cb_spinlock_t *lock)
70{
71 spin_lock((spinlock_t *) lock);
72}
73
74void qtiseclib_cb_spin_unlock(qtiseclib_cb_spinlock_t *lock)
75{
76 spin_unlock((spinlock_t *) lock);
77}
78
79unsigned int qtiseclib_cb_plat_my_core_pos(void)
80{
81 return plat_my_core_pos();
82}
83
84int qtiseclib_cb_plat_core_pos_by_mpidr(u_register_t mpidr)
85{
86 return plat_core_pos_by_mpidr(mpidr);
87}
88
89unsigned int qtiseclib_cb_plat_my_cluster_pos(void)
90{
91 return plat_qti_my_cluster_pos();
92}
93
94/* GIC platform functions */
95void qtiseclib_cb_gic_pcpu_init(void)
96{
97 plat_qti_gic_pcpu_init();
98}
99
100void qtiseclib_cb_ic_raise_sgi(int sgi_num, u_register_t target)
101{
102 plat_ic_raise_el3_sgi(sgi_num, target);
103}
104
105void qtiseclib_cb_set_spi_routing(unsigned int id, unsigned int irm,
106 u_register_t target)
107{
108 assert(QTI_GICV3_IRM_PE == GICV3_IRM_PE);
109 assert(QTI_GICV3_IRM_ANY == GICV3_IRM_ANY);
110 gic_set_spi_routing(id, irm, target);
111}
112
113/* Crash reporting api's wrappers */
114void qtiseclib_cb_switch_console_to_crash_state(void)
115{
116 console_switch_state(CONSOLE_FLAG_CRASH);
117}
118
119void qtiseclib_cb_udelay(uint32_t usec)
120{
121 udelay(usec);
122}
123
Jimmy Brisson39f9eee2020-08-05 13:44:05 -0500124void qtiseclib_cb_console_flush(void)
Saurabh Gorecha7df71122020-09-07 14:52:20 +0530125{
126 return console_flush();
127}
128
Saurabh Gorecha70389ca2020-04-22 21:31:24 +0530129#if QTI_SDI_BUILD
130void qtiseclib_cb_get_ns_ctx(qtiseclib_dbg_a64_ctxt_regs_type *qti_ns_ctx)
131{
132 void *ctx;
133
134 ctx = cm_get_context(NON_SECURE);
Saurabh Gorecha43987c52021-05-24 17:35:34 +0530135 if (ctx) {
136 /* nothing to be done w/o ns context */
137 return;
138 }
Saurabh Gorecha70389ca2020-04-22 21:31:24 +0530139
140 qti_ns_ctx->spsr_el3 =
141 read_ctx_reg(get_el3state_ctx(ctx), CTX_SPSR_EL3);
142 qti_ns_ctx->elr_el3 = read_ctx_reg(get_el3state_ctx(ctx), CTX_ELR_EL3);
143
144 qti_ns_ctx->spsr_el1 =
145 read_ctx_reg(get_el1_sysregs_ctx(ctx), CTX_SPSR_EL1);
146 qti_ns_ctx->elr_el1 =
147 read_ctx_reg(get_el1_sysregs_ctx(ctx), CTX_ELR_EL1);
148 qti_ns_ctx->sp_el1 = read_ctx_reg(get_el1_sysregs_ctx(ctx), CTX_SP_EL1);
149
150 qti_ns_ctx->x0 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X0);
151 qti_ns_ctx->x1 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X1);
152 qti_ns_ctx->x2 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X2);
153 qti_ns_ctx->x3 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X3);
154 qti_ns_ctx->x4 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X4);
155 qti_ns_ctx->x5 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X5);
156 qti_ns_ctx->x6 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X6);
157 qti_ns_ctx->x7 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X7);
158 qti_ns_ctx->x8 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X8);
159 qti_ns_ctx->x9 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X9);
160 qti_ns_ctx->x10 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X10);
161 qti_ns_ctx->x11 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X11);
162 qti_ns_ctx->x12 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X12);
163 qti_ns_ctx->x13 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X13);
164 qti_ns_ctx->x14 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X14);
165 qti_ns_ctx->x15 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X15);
166 qti_ns_ctx->x16 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X16);
167 qti_ns_ctx->x17 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X17);
168 qti_ns_ctx->x18 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X18);
169 qti_ns_ctx->x19 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X19);
170 qti_ns_ctx->x20 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X20);
171 qti_ns_ctx->x21 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X21);
172 qti_ns_ctx->x22 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X22);
173 qti_ns_ctx->x23 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X23);
174 qti_ns_ctx->x24 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X24);
175 qti_ns_ctx->x25 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X25);
176 qti_ns_ctx->x26 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X26);
177 qti_ns_ctx->x27 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X27);
178 qti_ns_ctx->x28 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X28);
179 qti_ns_ctx->x29 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X29);
180 qti_ns_ctx->x30 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_LR);
181 qti_ns_ctx->sp_el0 =
182 read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_SP_EL0);
183}
184
185void qtiseclib_cb_flush_dcache_all(void)
186{
187 dcsw_op_all(DCCISW);
188}
189
190int qtiseclib_cb_mmap_add_dynamic_region(unsigned long long base_pa,
191 size_t size,
192 qtiseclib_mmap_attr_t attr)
193{
194 unsigned int l_attr = 0;
195
196 if (attr == QTISECLIB_MAP_NS_RO_XN_DATA) {
197 l_attr = MT_NS | MT_RO | MT_EXECUTE_NEVER;
198 } else if (attr == QTISECLIB_MAP_RW_XN_NC_DATA) {
199 l_attr = MT_RW | MT_NON_CACHEABLE | MT_EXECUTE_NEVER;
200 } else if (attr == QTISECLIB_MAP_RW_XN_DATA) {
201 l_attr = MT_RW | MT_EXECUTE_NEVER;
202 }
203 return qti_mmap_add_dynamic_region(base_pa, size, l_attr);
204}
205
206int qtiseclib_cb_mmap_remove_dynamic_region(uintptr_t base_va, size_t size)
207{
208 return qti_mmap_remove_dynamic_region(base_va, size);
209}
210#endif
211