blob: 903ef411c057b8af6a5a384ea01bfd8f076ec942 [file] [log] [blame]
Antonio Nino Diaz272e8712018-09-18 01:36:00 +01001/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaz272e8712018-09-18 01:36:00 +01007#include <platform_def.h>
8
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <lib/bakery_lock.h>
10#include <lib/mmio.h>
11
Antonio Nino Diaz272e8712018-09-18 01:36:00 +010012static DEFINE_BAKERY_LOCK(mhu_lock);
13
14void mhu_secure_message_start(void)
15{
16 bakery_lock_get(&mhu_lock);
17
18 while (mmio_read_32(GXBB_HIU_MAILBOX_STAT_3) != 0)
19 ;
20}
21
22void mhu_secure_message_send(uint32_t msg)
23{
24 mmio_write_32(GXBB_HIU_MAILBOX_SET_3, msg);
25
26 while (mmio_read_32(GXBB_HIU_MAILBOX_STAT_3) != 0)
27 ;
28}
29
30uint32_t mhu_secure_message_wait(void)
31{
32 uint32_t val;
33
34 do {
35 val = mmio_read_32(GXBB_HIU_MAILBOX_STAT_0);
36 } while (val == 0);
37
38 return val;
39}
40
41void mhu_secure_message_end(void)
42{
43 mmio_write_32(GXBB_HIU_MAILBOX_CLR_0, 0xFFFFFFFF);
44
45 bakery_lock_release(&mhu_lock);
46}
47
48void mhu_secure_init(void)
49{
50 bakery_lock_init(&mhu_lock);
51
52 mmio_write_32(GXBB_HIU_MAILBOX_CLR_3, 0xFFFFFFFF);
53}