blob: 001686af056a7dae8ff48a152cf45522561b0e70 [file] [log] [blame]
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +00001/*
Carlo Caione9c85f252019-08-28 09:46:18 +01002 * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +00003 *
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
Carlo Caione9c85f252019-08-28 09:46:18 +010013void aml_mhu_secure_message_start(void)
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +000014{
15 bakery_lock_get(&mhu_lock);
16
Carlo Caione9c85f252019-08-28 09:46:18 +010017 while (mmio_read_32(AML_HIU_MAILBOX_STAT_3) != 0)
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +000018 ;
19}
20
Carlo Caione9c85f252019-08-28 09:46:18 +010021void aml_mhu_secure_message_send(uint32_t msg)
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +000022{
Carlo Caione9c85f252019-08-28 09:46:18 +010023 mmio_write_32(AML_HIU_MAILBOX_SET_3, msg);
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +000024
Carlo Caione9c85f252019-08-28 09:46:18 +010025 while (mmio_read_32(AML_HIU_MAILBOX_STAT_3) != 0)
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +000026 ;
27}
28
Carlo Caione9c85f252019-08-28 09:46:18 +010029uint32_t aml_mhu_secure_message_wait(void)
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +000030{
31 uint32_t val;
32
33 do {
Carlo Caione9c85f252019-08-28 09:46:18 +010034 val = mmio_read_32(AML_HIU_MAILBOX_STAT_0);
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +000035 } while (val == 0);
36
37 return val;
38}
39
Carlo Caione9c85f252019-08-28 09:46:18 +010040void aml_mhu_secure_message_end(void)
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +000041{
Carlo Caione9c85f252019-08-28 09:46:18 +010042 mmio_write_32(AML_HIU_MAILBOX_CLR_0, 0xFFFFFFFF);
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +000043
44 bakery_lock_release(&mhu_lock);
45}
46
Carlo Caione9c85f252019-08-28 09:46:18 +010047void aml_mhu_secure_init(void)
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +000048{
49 bakery_lock_init(&mhu_lock);
50
Carlo Caione9c85f252019-08-28 09:46:18 +010051 mmio_write_32(AML_HIU_MAILBOX_CLR_3, 0xFFFFFFFF);
Antonio Nino Diaz7298c1f2018-12-05 00:09:30 +000052}