Saurabh Gorecha | 70389ca | 2020-04-22 21:31:24 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 27 | void *qtiseclib_cb_memcpy(void *dst, const void *src, size_t len) |
| 28 | { |
| 29 | return memcpy(dst, src, len); |
| 30 | } |
| 31 | |
Saurabh Gorecha | 7df7112 | 2020-09-07 14:52:20 +0530 | [diff] [blame] | 32 | int qtiseclib_cb_strcmp(const char *s1, const char *s2) |
| 33 | { |
| 34 | return strcmp(s1, s2); |
| 35 | } |
| 36 | |
| 37 | void *qtiseclib_cb_memset(void *s, int c, size_t n) |
| 38 | { |
| 39 | return memset(s, c, n); |
| 40 | } |
| 41 | |
| 42 | void *qtiseclib_cb_memmove(void *dest, const void *src, size_t n) |
| 43 | { |
| 44 | return memmove(dest, src, n); |
| 45 | } |
| 46 | |
Saurabh Gorecha | 70389ca | 2020-04-22 21:31:24 +0530 | [diff] [blame] | 47 | /* Printing logs below or equal LOG_LEVEL from QTISECLIB. */ |
| 48 | void 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 | |
| 69 | void qtiseclib_cb_spin_lock(qtiseclib_cb_spinlock_t *lock) |
| 70 | { |
| 71 | spin_lock((spinlock_t *) lock); |
| 72 | } |
| 73 | |
| 74 | void qtiseclib_cb_spin_unlock(qtiseclib_cb_spinlock_t *lock) |
| 75 | { |
| 76 | spin_unlock((spinlock_t *) lock); |
| 77 | } |
| 78 | |
| 79 | unsigned int qtiseclib_cb_plat_my_core_pos(void) |
| 80 | { |
| 81 | return plat_my_core_pos(); |
| 82 | } |
| 83 | |
| 84 | int qtiseclib_cb_plat_core_pos_by_mpidr(u_register_t mpidr) |
| 85 | { |
| 86 | return plat_core_pos_by_mpidr(mpidr); |
| 87 | } |
| 88 | |
| 89 | unsigned int qtiseclib_cb_plat_my_cluster_pos(void) |
| 90 | { |
| 91 | return plat_qti_my_cluster_pos(); |
| 92 | } |
| 93 | |
| 94 | /* GIC platform functions */ |
| 95 | void qtiseclib_cb_gic_pcpu_init(void) |
| 96 | { |
| 97 | plat_qti_gic_pcpu_init(); |
| 98 | } |
| 99 | |
| 100 | void qtiseclib_cb_ic_raise_sgi(int sgi_num, u_register_t target) |
| 101 | { |
| 102 | plat_ic_raise_el3_sgi(sgi_num, target); |
| 103 | } |
| 104 | |
| 105 | void 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 */ |
| 114 | void qtiseclib_cb_switch_console_to_crash_state(void) |
| 115 | { |
| 116 | console_switch_state(CONSOLE_FLAG_CRASH); |
| 117 | } |
| 118 | |
| 119 | void qtiseclib_cb_udelay(uint32_t usec) |
| 120 | { |
| 121 | udelay(usec); |
| 122 | } |
| 123 | |
Saurabh Gorecha | 7df7112 | 2020-09-07 14:52:20 +0530 | [diff] [blame] | 124 | int qtiseclib_cb_console_flush(void) |
| 125 | { |
| 126 | return console_flush(); |
| 127 | } |
| 128 | |
Saurabh Gorecha | 70389ca | 2020-04-22 21:31:24 +0530 | [diff] [blame] | 129 | #if QTI_SDI_BUILD |
| 130 | void 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); |
| 135 | |
| 136 | qti_ns_ctx->spsr_el3 = |
| 137 | read_ctx_reg(get_el3state_ctx(ctx), CTX_SPSR_EL3); |
| 138 | qti_ns_ctx->elr_el3 = read_ctx_reg(get_el3state_ctx(ctx), CTX_ELR_EL3); |
| 139 | |
| 140 | qti_ns_ctx->spsr_el1 = |
| 141 | read_ctx_reg(get_el1_sysregs_ctx(ctx), CTX_SPSR_EL1); |
| 142 | qti_ns_ctx->elr_el1 = |
| 143 | read_ctx_reg(get_el1_sysregs_ctx(ctx), CTX_ELR_EL1); |
| 144 | qti_ns_ctx->sp_el1 = read_ctx_reg(get_el1_sysregs_ctx(ctx), CTX_SP_EL1); |
| 145 | |
| 146 | qti_ns_ctx->x0 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X0); |
| 147 | qti_ns_ctx->x1 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X1); |
| 148 | qti_ns_ctx->x2 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X2); |
| 149 | qti_ns_ctx->x3 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X3); |
| 150 | qti_ns_ctx->x4 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X4); |
| 151 | qti_ns_ctx->x5 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X5); |
| 152 | qti_ns_ctx->x6 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X6); |
| 153 | qti_ns_ctx->x7 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X7); |
| 154 | qti_ns_ctx->x8 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X8); |
| 155 | qti_ns_ctx->x9 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X9); |
| 156 | qti_ns_ctx->x10 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X10); |
| 157 | qti_ns_ctx->x11 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X11); |
| 158 | qti_ns_ctx->x12 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X12); |
| 159 | qti_ns_ctx->x13 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X13); |
| 160 | qti_ns_ctx->x14 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X14); |
| 161 | qti_ns_ctx->x15 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X15); |
| 162 | qti_ns_ctx->x16 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X16); |
| 163 | qti_ns_ctx->x17 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X17); |
| 164 | qti_ns_ctx->x18 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X18); |
| 165 | qti_ns_ctx->x19 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X19); |
| 166 | qti_ns_ctx->x20 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X20); |
| 167 | qti_ns_ctx->x21 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X21); |
| 168 | qti_ns_ctx->x22 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X22); |
| 169 | qti_ns_ctx->x23 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X23); |
| 170 | qti_ns_ctx->x24 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X24); |
| 171 | qti_ns_ctx->x25 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X25); |
| 172 | qti_ns_ctx->x26 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X26); |
| 173 | qti_ns_ctx->x27 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X27); |
| 174 | qti_ns_ctx->x28 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X28); |
| 175 | qti_ns_ctx->x29 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X29); |
| 176 | qti_ns_ctx->x30 = read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_LR); |
| 177 | qti_ns_ctx->sp_el0 = |
| 178 | read_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_SP_EL0); |
| 179 | } |
| 180 | |
| 181 | void qtiseclib_cb_flush_dcache_all(void) |
| 182 | { |
| 183 | dcsw_op_all(DCCISW); |
| 184 | } |
| 185 | |
| 186 | int qtiseclib_cb_mmap_add_dynamic_region(unsigned long long base_pa, |
| 187 | size_t size, |
| 188 | qtiseclib_mmap_attr_t attr) |
| 189 | { |
| 190 | unsigned int l_attr = 0; |
| 191 | |
| 192 | if (attr == QTISECLIB_MAP_NS_RO_XN_DATA) { |
| 193 | l_attr = MT_NS | MT_RO | MT_EXECUTE_NEVER; |
| 194 | } else if (attr == QTISECLIB_MAP_RW_XN_NC_DATA) { |
| 195 | l_attr = MT_RW | MT_NON_CACHEABLE | MT_EXECUTE_NEVER; |
| 196 | } else if (attr == QTISECLIB_MAP_RW_XN_DATA) { |
| 197 | l_attr = MT_RW | MT_EXECUTE_NEVER; |
| 198 | } |
| 199 | return qti_mmap_add_dynamic_region(base_pa, size, l_attr); |
| 200 | } |
| 201 | |
| 202 | int qtiseclib_cb_mmap_remove_dynamic_region(uintptr_t base_va, size_t size) |
| 203 | { |
| 204 | return qti_mmap_remove_dynamic_region(base_va, size); |
| 205 | } |
| 206 | #endif |
| 207 | |