1 /*
2  * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <lib/bakery_lock.h>
8 #include <lib/mmio.h>
9 #include <platform_def.h>
10 
11 static DEFINE_BAKERY_LOCK(mhu_lock);
12 
aml_mhu_secure_message_start(void)13 void aml_mhu_secure_message_start(void)
14 {
15 	bakery_lock_get(&mhu_lock);
16 
17 	while (mmio_read_32(AML_HIU_MAILBOX_STAT_3) != 0)
18 		;
19 }
20 
aml_mhu_secure_message_send(uint32_t msg)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 
aml_mhu_secure_message_wait(void)29 uint32_t aml_mhu_secure_message_wait(void)
30 {
31 	uint32_t val;
32 
33 	do {
34 		val = mmio_read_32(AML_HIU_MAILBOX_STAT_0);
35 	} while (val == 0);
36 
37 	return val;
38 }
39 
aml_mhu_secure_message_end(void)40 void aml_mhu_secure_message_end(void)
41 {
42 	mmio_write_32(AML_HIU_MAILBOX_CLR_0, 0xFFFFFFFF);
43 
44 	bakery_lock_release(&mhu_lock);
45 }
46 
aml_mhu_secure_init(void)47 void aml_mhu_secure_init(void)
48 {
49 	bakery_lock_init(&mhu_lock);
50 
51 	mmio_write_32(AML_HIU_MAILBOX_CLR_3, 0xFFFFFFFF);
52 }
53