Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
| 8 | #include <platform.h> |
| 9 | #include <spinlock.h> |
| 10 | #include <stdarg.h> |
| 11 | #include <stdio.h> |
| 12 | |
| 13 | /* Lock to avoid concurrent accesses to the serial console */ |
| 14 | static spinlock_t printf_lock; |
| 15 | |
| 16 | /* |
| 17 | * Print the MPID header, e.g.: [cpu 0x0100] |
| 18 | * |
| 19 | * If SHELL_COLOR == 1, this also prints shell's color escape sequences to ease |
| 20 | * identifying which CPU displays the message. There are 8 standard colors so |
| 21 | * if the platform has more than 8 CPUs, some colors will be reused. |
| 22 | */ |
| 23 | #if SHELL_COLOR |
| 24 | #define PRINT_MPID_HDR(_mpid) \ |
| 25 | do { \ |
| 26 | unsigned int linear_id = platform_get_core_pos(_mpid); \ |
| 27 | printf("\033[1;%u;40m", 30 + (linear_id & 0x7)); \ |
| 28 | printf("[cpu 0x%.4x] ", _mpid); \ |
| 29 | printf("\033[0m"); \ |
| 30 | } while (0) |
| 31 | #else |
| 32 | #define PRINT_MPID_HDR(_mpid) \ |
| 33 | printf("[cpu 0x%.4x] ", _mpid) |
| 34 | #endif /* SHELL_COLOR */ |
| 35 | |
| 36 | void mp_printf(const char *fmt, ...) |
| 37 | { |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 38 | /* |
| 39 | * As part of testing Firmware Update feature on Cortex-A57 CPU, an |
| 40 | * issue was discovered while printing in NS_BL1U stage. The issue |
| 41 | * appears when the second call to `NOTICE()` is made in the |
| 42 | * `ns_bl1u_main()`. As a result of this issue the CPU hangs and the |
| 43 | * debugger is also not able to connect anymore. |
| 44 | * |
| 45 | * After further debugging and experiments it was found that if |
| 46 | * `read_mpidr_el1()` is avoided or volatile qualifier is used for |
| 47 | * reading the mpidr, this issue gets resolved. |
| 48 | * |
| 49 | * NOTE: The actual/real reason why this happens is still not known. |
| 50 | * Moreover this problem is not encountered on Cortex-A53 CPU. |
| 51 | */ |
| 52 | volatile unsigned int mpid = read_mpidr_el1() & 0xFFFF; |
| 53 | |
Sandrine Bailleux | 411a6b2 | 2018-11-08 14:08:09 +0100 | [diff] [blame^] | 54 | va_list ap; |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 55 | va_start(ap, fmt); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 56 | |
| 57 | spin_lock(&printf_lock); |
| 58 | PRINT_MPID_HDR(mpid); |
Sandrine Bailleux | 411a6b2 | 2018-11-08 14:08:09 +0100 | [diff] [blame^] | 59 | vprintf(fmt, ap); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 60 | spin_unlock(&printf_lock); |
Sandrine Bailleux | 411a6b2 | 2018-11-08 14:08:09 +0100 | [diff] [blame^] | 61 | |
| 62 | va_end(ap); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 63 | } |