summaryrefslogtreecommitdiffstats
path: root/plat/amlogic/common/aml_mhu.c
blob: 001686af056a7dae8ff48a152cf45522561b0e70 (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
/*
 * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <lib/bakery_lock.h>
#include <lib/mmio.h>
#include <platform_def.h>

static DEFINE_BAKERY_LOCK(mhu_lock);

void aml_mhu_secure_message_start(void)
{
	bakery_lock_get(&mhu_lock);

	while (mmio_read_32(AML_HIU_MAILBOX_STAT_3) != 0)
		;
}

void aml_mhu_secure_message_send(uint32_t msg)
{
	mmio_write_32(AML_HIU_MAILBOX_SET_3, msg);

	while (mmio_read_32(AML_HIU_MAILBOX_STAT_3) != 0)
		;
}

uint32_t aml_mhu_secure_message_wait(void)
{
	uint32_t val;

	do {
		val = mmio_read_32(AML_HIU_MAILBOX_STAT_0);
	} while (val == 0);

	return val;
}

void aml_mhu_secure_message_end(void)
{
	mmio_write_32(AML_HIU_MAILBOX_CLR_0, 0xFFFFFFFF);

	bakery_lock_release(&mhu_lock);
}

void aml_mhu_secure_init(void)
{
	bakery_lock_init(&mhu_lock);

	mmio_write_32(AML_HIU_MAILBOX_CLR_3, 0xFFFFFFFF);
}