| 1 |
/* |
| 2 |
* Copyright (c) 2015-2020, Renesas Electronics Corporation. All rights reserved. |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: BSD-3-Clause |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <stdarg.h> |
| 8 |
#include <stdint.h> |
| 9 |
|
| 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" |
| 19 |
|
| 20 |
#define INDEX_TIMER_COUNT (4U) |
| 21 |
|
| 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 |
| 27 |
* memory is correctly aligned and accessed only with up-to 32bit, aligned, |
| 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 |
|
| 33 |
extern RCAR_INSTANTIATE_LOCK typedef struct log_head { |
| 34 |
uint32_t head; |
| 35 |
uint32_t index; |
| 36 |
uint32_t size; |
| 37 |
uint32_t res; |
| 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 |
{ |
| 80 |
logmap_t *t_log = (logmap_t *)RCAR_BL31_LOG_BASE; |
| 81 |
uint32_t *log_data = (uint32_t *)t_log->log_data; |
| 82 |
int16_t init_flag = 0; |
| 83 |
int i; |
| 84 |
|
| 85 |
if (t_log->header.head != RCAR_LOG_HEAD) { |
| 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) { |
| 98 |
for (i = 0; i < RCAR_BL31_LOG_MAX; i += 4) |
| 99 |
*log_data++ = 0; |
| 100 |
|
| 101 |
t_log->header.head = RCAR_LOG_HEAD; |
| 102 |
t_log->header.index = 0U; |
| 103 |
t_log->header.size = 0U; |
| 104 |
} |
| 105 |
rcar_lock_init(); |
| 106 |
|
| 107 |
return 1; |
| 108 |
} |