blob: 9321b584ad54431b2db04689c7c32dcd9eef1734 [file] [log] [blame]
Jorge Ramirez-Ortizf1751c02018-09-23 09:41:00 +02001/*
2 * Copyright (c) 2015-2017, Renesas Electronics Corporation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <debug.h>
8#include <stdarg.h>
9#include <stdint.h>
10
11#include <arch_helpers.h>
12#include <platform_def.h>
13#include <bakery_lock.h>
14#include "rcar_def.h"
15#include "rcar_private.h"
16#include "rcar_printf.h"
17
18#define INDEX_TIMER_COUNT (4U)
19
20extern RCAR_INSTANTIATE_LOCK typedef struct log_head {
21 uint8_t head[4];
22 uint32_t index;
23 uint32_t size;
24 uint8_t res[4];
25} loghead_t;
26
27typedef struct log_map {
28 loghead_t header;
29 uint8_t log_data[RCAR_BL31_LOG_MAX];
30 uint8_t res_data[RCAR_LOG_RES_SIZE];
31} logmap_t;
32
33int32_t rcar_set_log_data(int32_t c)
34{
35 logmap_t *t_log;
36
37 t_log = (logmap_t *) RCAR_BL31_LOG_BASE;
38
39 rcar_lock_get();
40
41 /*
42 * If index is broken, then index and size initialize
43 */
44 if (t_log->header.index >= (uint32_t) RCAR_BL31_LOG_MAX) {
45 t_log->header.index = 0U;
46 t_log->header.size = 0U;
47 }
48 /*
49 * data store to log area then index and size renewal
50 */
51 t_log->log_data[t_log->header.index] = (uint8_t) c;
52 t_log->header.index++;
53 if (t_log->header.size < t_log->header.index) {
54 t_log->header.size = t_log->header.index;
55 }
56 if (t_log->header.index >= (uint32_t) RCAR_BL31_LOG_MAX) {
57 t_log->header.index = 0U;
58 }
59
60 rcar_lock_release();
61
62 return 1;
63}
64
65int32_t rcar_log_init(void)
66{
67
68 static const uint8_t const_header[] = "TLOG";
69 logmap_t *t_log;
70 int16_t init_flag = 0;
71
72 t_log = (logmap_t *) RCAR_BL31_LOG_BASE;
73 if (memcmp
74 ((const void *)t_log->header.head, (const void *)const_header,
75 sizeof(t_log->header.head)) != 0) {
76 /*
77 * Log header is not "TLOG", then log area initialize
78 */
79 init_flag = 1;
80 }
81 if (t_log->header.index >= (uint32_t) RCAR_BL31_LOG_MAX) {
82 /*
83 * index is broken, then log area initialize
84 */
85 init_flag = 1;
86 }
87 if (init_flag == 1) {
88 (void)memset((void *)t_log->log_data, 0,
89 (size_t) RCAR_BL31_LOG_MAX);
90 (void)memcpy((void *)t_log->header.head,
91 (const void *)const_header,
92 sizeof(t_log->header.head));
93 t_log->header.index = 0U;
94 t_log->header.size = 0U;
95#ifndef IMAGE_BL2
96 rcar_stack_generic_timer[INDEX_TIMER_COUNT] = 0U;
97#endif
98 }
99 rcar_lock_init();
100
101 return 1;
102}