1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (c) 2014, Linaro Limited 4 */ 5 #include <stdbool.h> 6 #include <trace.h> 7 #include <console.h> 8 #include <kernel/misc.h> 9 #include <kernel/spinlock.h> 10 #include <kernel/thread.h> 11 #include <mm/core_mmu.h> 12 13 const char trace_ext_prefix[] = "TC"; 14 int trace_level __nex_data = TRACE_LEVEL; 15 static unsigned int puts_lock __nex_bss = SPINLOCK_UNLOCK; 16 plat_trace_ext_puts(const char * str __unused)17void __weak plat_trace_ext_puts(const char *str __unused) 18 { 19 } 20 trace_ext_puts(const char * str)21void trace_ext_puts(const char *str) 22 { 23 uint32_t itr_status = thread_mask_exceptions(THREAD_EXCP_ALL); 24 bool mmu_enabled = cpu_mmu_enabled(); 25 bool was_contended = false; 26 const char *p; 27 28 if (mmu_enabled && !cpu_spin_trylock(&puts_lock)) { 29 was_contended = true; 30 cpu_spin_lock_no_dldetect(&puts_lock); 31 } 32 33 plat_trace_ext_puts(str); 34 35 console_flush(); 36 37 if (was_contended) 38 console_putc('*'); 39 40 for (p = str; *p; p++) 41 console_putc(*p); 42 43 console_flush(); 44 45 if (mmu_enabled) 46 cpu_spin_unlock(&puts_lock); 47 48 thread_unmask_exceptions(itr_status); 49 } 50 trace_ext_get_thread_id(void)51int trace_ext_get_thread_id(void) 52 { 53 return thread_get_id_may_fail(); 54 } 55 trace_ext_get_core_id(void)56int trace_ext_get_core_id(void) 57 { 58 /* If foreign interrupts aren't masked we report invalid core ID */ 59 if (thread_get_exceptions() & THREAD_EXCP_FOREIGN_INTR) 60 return get_core_pos(); 61 else 62 return -1; 63 } 64