rcar_printf.c 2.39 KB
Newer Older
1
/*
2
 * Copyright (c) 2015-2020, Renesas Electronics Corporation. All rights reserved.
3
4
5
6
7
8
9
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <stdarg.h>
#include <stdint.h>

10
11
12
13
14
15
16
17
18
#include <platform_def.h>

#include <arch_helpers.h>
#include <common/debug.h>
#include <lib/bakery_lock.h>

#include "rcar_def.h"
#include "rcar_private.h"
#include "rcar_printf.h"
19
20
21

#define INDEX_TIMER_COUNT	(4U)

22
23
24
25
26
27
28
29
30
31
32
#define RCAR_LOG_HEAD	(('T' << 0) | ('L' << 8) | ('O' << 16) | ('G' << 24))

/*
 * The log is initialized and used before BL31 xlat tables are initialized,
 * therefore the log memory is a device memory at that point. Make sure the
 * memory is correclty aligned and accessed only with up-to 32bit, aligned,
 * writes.
 */
CASSERT((RCAR_BL31_LOG_BASE & 0x7) == 0, assert_bl31_log_base_unaligned);
CASSERT((RCAR_BL31_LOG_MAX & 0x7) == 0, assert_bl31_log_max_unaligned);

33
extern RCAR_INSTANTIATE_LOCK typedef struct log_head {
34
	uint32_t head;
35
36
	uint32_t index;
	uint32_t size;
37
	uint32_t res;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
} loghead_t;

typedef struct log_map {
	loghead_t header;
	uint8_t log_data[RCAR_BL31_LOG_MAX];
	uint8_t res_data[RCAR_LOG_RES_SIZE];
} logmap_t;

int32_t rcar_set_log_data(int32_t c)
{
	logmap_t *t_log;

	t_log = (logmap_t *) RCAR_BL31_LOG_BASE;

	rcar_lock_get();

	/*
	 * If index is broken, then index and size initialize
	 */
	if (t_log->header.index >= (uint32_t) RCAR_BL31_LOG_MAX) {
		t_log->header.index = 0U;
		t_log->header.size = 0U;
	}
	/*
	 * data store to log area then index and size renewal
	 */
	t_log->log_data[t_log->header.index] = (uint8_t) c;
	t_log->header.index++;
	if (t_log->header.size < t_log->header.index) {
		t_log->header.size = t_log->header.index;
	}
	if (t_log->header.index >= (uint32_t) RCAR_BL31_LOG_MAX) {
		t_log->header.index = 0U;
	}

	rcar_lock_release();

	return 1;
}

int32_t rcar_log_init(void)
{
80
81
	logmap_t *t_log = (logmap_t *)RCAR_BL31_LOG_BASE;
	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
88
89
90
91
92
93
94
95
96
97
		/*
		 * Log header is not "TLOG", then log area initialize
		 */
		init_flag = 1;
	}
	if (t_log->header.index >= (uint32_t) RCAR_BL31_LOG_MAX) {
		/*
		 * index is broken, then log area initialize
		 */
		init_flag = 1;
	}
	if (init_flag == 1) {
98
99
100
101
		for (i = 0; i < RCAR_BL31_LOG_MAX; i += 4)
			*log_data++ = 0;

		t_log->header.head = RCAR_LOG_HEAD;
102
103
104
105
106
107
108
		t_log->header.index = 0U;
		t_log->header.size = 0U;
	}
	rcar_lock_init();

	return 1;
}