• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015-2019, 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 extern RCAR_INSTANTIATE_LOCK typedef struct log_head {
23 	uint8_t head[4];
24 	uint32_t index;
25 	uint32_t size;
26 	uint8_t res[4];
27 } loghead_t;
28 
29 typedef struct log_map {
30 	loghead_t header;
31 	uint8_t log_data[RCAR_BL31_LOG_MAX];
32 	uint8_t res_data[RCAR_LOG_RES_SIZE];
33 } logmap_t;
34 
rcar_set_log_data(int32_t c)35 int32_t rcar_set_log_data(int32_t c)
36 {
37 	logmap_t *t_log;
38 
39 	t_log = (logmap_t *) RCAR_BL31_LOG_BASE;
40 
41 	rcar_lock_get();
42 
43 	/*
44 	 * If index is broken, then index and size initialize
45 	 */
46 	if (t_log->header.index >= (uint32_t) RCAR_BL31_LOG_MAX) {
47 		t_log->header.index = 0U;
48 		t_log->header.size = 0U;
49 	}
50 	/*
51 	 * data store to log area then index and size renewal
52 	 */
53 	t_log->log_data[t_log->header.index] = (uint8_t) c;
54 	t_log->header.index++;
55 	if (t_log->header.size < t_log->header.index) {
56 		t_log->header.size = t_log->header.index;
57 	}
58 	if (t_log->header.index >= (uint32_t) RCAR_BL31_LOG_MAX) {
59 		t_log->header.index = 0U;
60 	}
61 
62 	rcar_lock_release();
63 
64 	return 1;
65 }
66 
rcar_log_init(void)67 int32_t rcar_log_init(void)
68 {
69 
70 	static const uint8_t const_header[] = "TLOG";
71 	logmap_t *t_log;
72 	int16_t init_flag = 0;
73 
74 	t_log = (logmap_t *) RCAR_BL31_LOG_BASE;
75 	if (memcmp
76 	    ((const void *)t_log->header.head, (const void *)const_header,
77 	     sizeof(t_log->header.head)) != 0) {
78 		/*
79 		 * Log header is not "TLOG", then log area initialize
80 		 */
81 		init_flag = 1;
82 	}
83 	if (t_log->header.index >= (uint32_t) RCAR_BL31_LOG_MAX) {
84 		/*
85 		 * index is broken, then log area initialize
86 		 */
87 		init_flag = 1;
88 	}
89 	if (init_flag == 1) {
90 		(void)memset((void *)t_log->log_data, 0,
91 			     (size_t) RCAR_BL31_LOG_MAX);
92 		(void)memcpy((void *)t_log->header.head,
93 			     (const void *)const_header,
94 			     sizeof(t_log->header.head));
95 		t_log->header.index = 0U;
96 		t_log->header.size = 0U;
97 	}
98 	rcar_lock_init();
99 
100 	return 1;
101 }
102