blob: ad074fe0597502eb623707cb0bb7d53a90bf3c80 [file] [log] [blame]
Jorge Ramirez-Ortizf1751c02018-09-23 09:41:00 +02001/*
Marek Vasut07370e52020-11-08 19:13:32 +01002 * Copyright (c) 2015-2020, Renesas Electronics Corporation. All rights reserved.
Jorge Ramirez-Ortizf1751c02018-09-23 09:41:00 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Jorge Ramirez-Ortizf1751c02018-09-23 09:41:00 +02007#include <stdarg.h>
8#include <stdint.h>
9
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#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-Ortizf1751c02018-09-23 09:41:00 +020019
20#define INDEX_TIMER_COUNT (4U)
21
Marek Vasut07370e52020-11-08 19:13:32 +010022#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 correclty aligned and accessed only with up-to 32bit, aligned,
28 * writes.
29 */
30CASSERT((RCAR_BL31_LOG_BASE & 0x7) == 0, assert_bl31_log_base_unaligned);
31CASSERT((RCAR_BL31_LOG_MAX & 0x7) == 0, assert_bl31_log_max_unaligned);
32
Jorge Ramirez-Ortizf1751c02018-09-23 09:41:00 +020033extern RCAR_INSTANTIATE_LOCK typedef struct log_head {
Marek Vasut07370e52020-11-08 19:13:32 +010034 uint32_t head;
Jorge Ramirez-Ortizf1751c02018-09-23 09:41:00 +020035 uint32_t index;
36 uint32_t size;
Marek Vasut07370e52020-11-08 19:13:32 +010037 uint32_t res;
Jorge Ramirez-Ortizf1751c02018-09-23 09:41:00 +020038} loghead_t;
39
40typedef 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
46int32_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
78int32_t rcar_log_init(void)
79{
Marek Vasut07370e52020-11-08 19:13:32 +010080 logmap_t *t_log = (logmap_t *)RCAR_BL31_LOG_BASE;
81 uint32_t *log_data = (uint32_t *)t_log->log_data;
Jorge Ramirez-Ortizf1751c02018-09-23 09:41:00 +020082 int16_t init_flag = 0;
Marek Vasut07370e52020-11-08 19:13:32 +010083 int i;
Jorge Ramirez-Ortizf1751c02018-09-23 09:41:00 +020084
Marek Vasut07370e52020-11-08 19:13:32 +010085 if (t_log->header.head != RCAR_LOG_HEAD) {
Jorge Ramirez-Ortizf1751c02018-09-23 09:41:00 +020086 /*
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 Vasut07370e52020-11-08 19:13:32 +010098 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-Ortizf1751c02018-09-23 09:41:00 +0200102 t_log->header.index = 0U;
103 t_log->header.size = 0U;
Jorge Ramirez-Ortizf1751c02018-09-23 09:41:00 +0200104 }
105 rcar_lock_init();
106
107 return 1;
108}