aml_mhu.c 925 Bytes
Newer Older
1
/*
2
 * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
8
9
10
11
12
 *
 * 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);

13
void aml_mhu_secure_message_start(void)
14
15
16
{
	bakery_lock_get(&mhu_lock);

17
	while (mmio_read_32(AML_HIU_MAILBOX_STAT_3) != 0)
18
19
20
		;
}

21
void aml_mhu_secure_message_send(uint32_t msg)
22
{
23
	mmio_write_32(AML_HIU_MAILBOX_SET_3, msg);
24

25
	while (mmio_read_32(AML_HIU_MAILBOX_STAT_3) != 0)
26
27
28
		;
}

29
uint32_t aml_mhu_secure_message_wait(void)
30
31
32
33
{
	uint32_t val;

	do {
34
		val = mmio_read_32(AML_HIU_MAILBOX_STAT_0);
35
36
37
38
39
	} while (val == 0);

	return val;
}

40
void aml_mhu_secure_message_end(void)
41
{
42
	mmio_write_32(AML_HIU_MAILBOX_CLR_0, 0xFFFFFFFF);
43
44
45
46

	bakery_lock_release(&mhu_lock);
}

47
void aml_mhu_secure_init(void)
48
49
50
{
	bakery_lock_init(&mhu_lock);

51
	mmio_write_32(AML_HIU_MAILBOX_CLR_3, 0xFFFFFFFF);
52
}