blob: 4c1d5b600d8c5ec81c4099d6cd428b0ac4cf22d0 [file] [log] [blame]
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +00001/*
2 * Copyright (c) 2018, 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
11static DEFINE_BAKERY_LOCK(mhu_lock);
12
13void mhu_secure_message_start(void)
14{
15 bakery_lock_get(&mhu_lock);
16
17 while (mmio_read_32(GXBB_HIU_MAILBOX_STAT_3) != 0)
18 ;
19}
20
21void mhu_secure_message_send(uint32_t msg)
22{
23 mmio_write_32(GXBB_HIU_MAILBOX_SET_3, msg);
24
25 while (mmio_read_32(GXBB_HIU_MAILBOX_STAT_3) != 0)
26 ;
27}
28
29uint32_t mhu_secure_message_wait(void)
30{
31 uint32_t val;
32
33 do {
34 val = mmio_read_32(GXBB_HIU_MAILBOX_STAT_0);
35 } while (val == 0);
36
37 return val;
38}
39
40void mhu_secure_message_end(void)
41{
42 mmio_write_32(GXBB_HIU_MAILBOX_CLR_0, 0xFFFFFFFF);
43
44 bakery_lock_release(&mhu_lock);
45}
46
47void mhu_secure_init(void)
48{
49 bakery_lock_init(&mhu_lock);
50
51 mmio_write_32(GXBB_HIU_MAILBOX_CLR_3, 0xFFFFFFFF);
52}