aboutsummaryrefslogtreecommitdiff
path: root/core/arch/arm/plat-bcm/bcm_elog.c
blob: 16b1382852cff0364cb7474e5e7b3250844c138d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: BSD-2-Clause
/*
 * Copyright 2019 Broadcom.
 */

#include <bcm_elog.h>
#include <io.h>

static struct bcm_elog global_elog;

void bcm_elog_putchar(char ch)
{
	struct bcm_elog *elog = &global_elog;
	uint32_t offset = 0, len = 0;
	vaddr_t base = 0;

	base = io_pa_or_va(&elog->base);

	offset = io_read32(base + BCM_ELOG_OFF_OFFSET);
	len = io_read32(base + BCM_ELOG_LEN_OFFSET);
	io_write8(base + offset, ch);
	offset++;

	/* Log buffer is now full and need to wrap around */
	if (offset >= elog->max_size)
		offset = BCM_ELOG_HEADER_LEN;

	/* Only increment length when log buffer is not full */
	if (len < elog->max_size - BCM_ELOG_HEADER_LEN)
		len++;

	io_write32(base + BCM_ELOG_OFF_OFFSET, offset);
	io_write32(base + BCM_ELOG_LEN_OFFSET, len);
}

void bcm_elog_init(uintptr_t pa_base, uint32_t size)
{
	struct bcm_elog *elog = &global_elog;
	uint32_t val = 0;
	vaddr_t base = 0;

	elog->base.pa = pa_base;
	elog->max_size = size;

	base = io_pa_or_va(&elog->base);

	/*
	 * If a valid signature is found, it means logging is already
	 * initialized. In this case, we should not re-initialize the entry
	 * header in the designated memory
	 */
	val = io_read32(base + BCM_ELOG_SIG_OFFSET);
	if (val != BCM_ELOG_SIG_VAL) {
		io_write32(base + BCM_ELOG_SIG_OFFSET, BCM_ELOG_SIG_VAL);
		io_write32(base + BCM_ELOG_OFF_OFFSET, BCM_ELOG_HEADER_LEN);
		io_write32(base + BCM_ELOG_LEN_OFFSET, 0);
	}
}