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