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 <kernel/virtualization.h> 12 #include <mm/core_mmu.h> 13 14 const char trace_ext_prefix[] = "TC"; 15 int trace_level __nex_data = TRACE_LEVEL; 16 static unsigned int puts_lock __nex_bss = SPINLOCK_UNLOCK; 17 18 void __weak plat_trace_ext_puts(const char *str __unused) 19 { 20 } 21 22 void trace_ext_puts(const char *str) 23 { 24 uint32_t itr_status = thread_mask_exceptions(THREAD_EXCP_ALL); 25 bool mmu_enabled = cpu_mmu_enabled(); 26 bool was_contended = false; 27 const char *p; 28 29 if (mmu_enabled && !cpu_spin_trylock(&puts_lock)) { 30 was_contended = true; 31 cpu_spin_lock_no_dldetect(&puts_lock); 32 } 33 34 plat_trace_ext_puts(str); 35 36 console_flush(); 37 38 if (was_contended) 39 console_putc('*'); 40 41 for (p = str; *p; p++) 42 console_putc(*p); 43 44 console_flush(); 45 46 if (mmu_enabled) 47 cpu_spin_unlock(&puts_lock); 48 49 thread_unmask_exceptions(itr_status); 50 } 51 52 int trace_ext_get_thread_id(void) 53 { 54 return thread_get_id_may_fail(); 55 } 56 57 int trace_ext_get_core_id(void) 58 { 59 /* If foreign interrupts aren't masked we report invalid core ID */ 60 if (thread_get_exceptions() & THREAD_EXCP_FOREIGN_INTR) 61 return get_core_pos(); 62 else 63 return -1; 64 } 65 66 int trace_ext_get_guest_id(void) 67 { 68 return virt_get_current_guest_id(); 69 } 70