Jorge Ramirez-Ortiz | f1751c0 | 2018-09-23 09:41:00 +0200 | [diff] [blame] | 1 | /* |
Marek Vasut | 07370e5 | 2020-11-08 19:13:32 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2020, Renesas Electronics Corporation. All rights reserved. |
Jorge Ramirez-Ortiz | f1751c0 | 2018-09-23 09:41:00 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Jorge Ramirez-Ortiz | f1751c0 | 2018-09-23 09:41:00 +0200 | [diff] [blame] | 7 | #include <stdarg.h> |
| 8 | #include <stdint.h> |
| 9 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <platform_def.h> |
| 11 | |
| 12 | #include <arch_helpers.h> |
| 13 | #include <common/debug.h> |
| 14 | #include <lib/bakery_lock.h> |
| 15 | |
| 16 | #include "rcar_def.h" |
| 17 | #include "rcar_private.h" |
| 18 | #include "rcar_printf.h" |
Jorge Ramirez-Ortiz | f1751c0 | 2018-09-23 09:41:00 +0200 | [diff] [blame] | 19 | |
| 20 | #define INDEX_TIMER_COUNT (4U) |
| 21 | |
Marek Vasut | 07370e5 | 2020-11-08 19:13:32 +0100 | [diff] [blame] | 22 | #define RCAR_LOG_HEAD (('T' << 0) | ('L' << 8) | ('O' << 16) | ('G' << 24)) |
| 23 | |
| 24 | /* |
| 25 | * The log is initialized and used before BL31 xlat tables are initialized, |
| 26 | * therefore the log memory is a device memory at that point. Make sure the |
Elyes Haouas | 2be03c0 | 2023-02-13 09:14:48 +0100 | [diff] [blame] | 27 | * memory is correctly aligned and accessed only with up-to 32bit, aligned, |
Marek Vasut | 07370e5 | 2020-11-08 19:13:32 +0100 | [diff] [blame] | 28 | * writes. |
| 29 | */ |
| 30 | CASSERT((RCAR_BL31_LOG_BASE & 0x7) == 0, assert_bl31_log_base_unaligned); |
| 31 | CASSERT((RCAR_BL31_LOG_MAX & 0x7) == 0, assert_bl31_log_max_unaligned); |
| 32 | |
Jorge Ramirez-Ortiz | f1751c0 | 2018-09-23 09:41:00 +0200 | [diff] [blame] | 33 | extern RCAR_INSTANTIATE_LOCK typedef struct log_head { |
Marek Vasut | 07370e5 | 2020-11-08 19:13:32 +0100 | [diff] [blame] | 34 | uint32_t head; |
Jorge Ramirez-Ortiz | f1751c0 | 2018-09-23 09:41:00 +0200 | [diff] [blame] | 35 | uint32_t index; |
| 36 | uint32_t size; |
Marek Vasut | 07370e5 | 2020-11-08 19:13:32 +0100 | [diff] [blame] | 37 | uint32_t res; |
Jorge Ramirez-Ortiz | f1751c0 | 2018-09-23 09:41:00 +0200 | [diff] [blame] | 38 | } loghead_t; |
| 39 | |
| 40 | typedef struct log_map { |
| 41 | loghead_t header; |
| 42 | uint8_t log_data[RCAR_BL31_LOG_MAX]; |
| 43 | uint8_t res_data[RCAR_LOG_RES_SIZE]; |
| 44 | } logmap_t; |
| 45 | |
| 46 | int32_t rcar_set_log_data(int32_t c) |
| 47 | { |
| 48 | logmap_t *t_log; |
| 49 | |
| 50 | t_log = (logmap_t *) RCAR_BL31_LOG_BASE; |
| 51 | |
| 52 | rcar_lock_get(); |
| 53 | |
| 54 | /* |
| 55 | * If index is broken, then index and size initialize |
| 56 | */ |
| 57 | if (t_log->header.index >= (uint32_t) RCAR_BL31_LOG_MAX) { |
| 58 | t_log->header.index = 0U; |
| 59 | t_log->header.size = 0U; |
| 60 | } |
| 61 | /* |
| 62 | * data store to log area then index and size renewal |
| 63 | */ |
| 64 | t_log->log_data[t_log->header.index] = (uint8_t) c; |
| 65 | t_log->header.index++; |
| 66 | if (t_log->header.size < t_log->header.index) { |
| 67 | t_log->header.size = t_log->header.index; |
| 68 | } |
| 69 | if (t_log->header.index >= (uint32_t) RCAR_BL31_LOG_MAX) { |
| 70 | t_log->header.index = 0U; |
| 71 | } |
| 72 | |
| 73 | rcar_lock_release(); |
| 74 | |
| 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | int32_t rcar_log_init(void) |
| 79 | { |
Marek Vasut | 07370e5 | 2020-11-08 19:13:32 +0100 | [diff] [blame] | 80 | logmap_t *t_log = (logmap_t *)RCAR_BL31_LOG_BASE; |
| 81 | uint32_t *log_data = (uint32_t *)t_log->log_data; |
Jorge Ramirez-Ortiz | f1751c0 | 2018-09-23 09:41:00 +0200 | [diff] [blame] | 82 | int16_t init_flag = 0; |
Marek Vasut | 07370e5 | 2020-11-08 19:13:32 +0100 | [diff] [blame] | 83 | int i; |
Jorge Ramirez-Ortiz | f1751c0 | 2018-09-23 09:41:00 +0200 | [diff] [blame] | 84 | |
Marek Vasut | 07370e5 | 2020-11-08 19:13:32 +0100 | [diff] [blame] | 85 | if (t_log->header.head != RCAR_LOG_HEAD) { |
Jorge Ramirez-Ortiz | f1751c0 | 2018-09-23 09:41:00 +0200 | [diff] [blame] | 86 | /* |
| 87 | * Log header is not "TLOG", then log area initialize |
| 88 | */ |
| 89 | init_flag = 1; |
| 90 | } |
| 91 | if (t_log->header.index >= (uint32_t) RCAR_BL31_LOG_MAX) { |
| 92 | /* |
| 93 | * index is broken, then log area initialize |
| 94 | */ |
| 95 | init_flag = 1; |
| 96 | } |
| 97 | if (init_flag == 1) { |
Marek Vasut | 07370e5 | 2020-11-08 19:13:32 +0100 | [diff] [blame] | 98 | for (i = 0; i < RCAR_BL31_LOG_MAX; i += 4) |
| 99 | *log_data++ = 0; |
| 100 | |
| 101 | t_log->header.head = RCAR_LOG_HEAD; |
Jorge Ramirez-Ortiz | f1751c0 | 2018-09-23 09:41:00 +0200 | [diff] [blame] | 102 | t_log->header.index = 0U; |
| 103 | t_log->header.size = 0U; |
Jorge Ramirez-Ortiz | f1751c0 | 2018-09-23 09:41:00 +0200 | [diff] [blame] | 104 | } |
| 105 | rcar_lock_init(); |
| 106 | |
| 107 | return 1; |
| 108 | } |