Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 1 | /* |
Carlo Caione | 9c85f25 | 2019-08-28 09:46:18 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved. |
Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 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 | |
Carlo Caione | 9c85f25 | 2019-08-28 09:46:18 +0100 | [diff] [blame] | 13 | void aml_mhu_secure_message_start(void) |
Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 14 | { |
| 15 | bakery_lock_get(&mhu_lock); |
| 16 | |
Carlo Caione | 9c85f25 | 2019-08-28 09:46:18 +0100 | [diff] [blame] | 17 | while (mmio_read_32(AML_HIU_MAILBOX_STAT_3) != 0) |
Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 18 | ; |
| 19 | } |
| 20 | |
Carlo Caione | 9c85f25 | 2019-08-28 09:46:18 +0100 | [diff] [blame] | 21 | void aml_mhu_secure_message_send(uint32_t msg) |
Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 22 | { |
Carlo Caione | 9c85f25 | 2019-08-28 09:46:18 +0100 | [diff] [blame] | 23 | mmio_write_32(AML_HIU_MAILBOX_SET_3, msg); |
Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 24 | |
Carlo Caione | 9c85f25 | 2019-08-28 09:46:18 +0100 | [diff] [blame] | 25 | while (mmio_read_32(AML_HIU_MAILBOX_STAT_3) != 0) |
Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 26 | ; |
| 27 | } |
| 28 | |
Carlo Caione | 9c85f25 | 2019-08-28 09:46:18 +0100 | [diff] [blame] | 29 | uint32_t aml_mhu_secure_message_wait(void) |
Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 30 | { |
| 31 | uint32_t val; |
| 32 | |
| 33 | do { |
Carlo Caione | 9c85f25 | 2019-08-28 09:46:18 +0100 | [diff] [blame] | 34 | val = mmio_read_32(AML_HIU_MAILBOX_STAT_0); |
Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 35 | } while (val == 0); |
| 36 | |
| 37 | return val; |
| 38 | } |
| 39 | |
Carlo Caione | 9c85f25 | 2019-08-28 09:46:18 +0100 | [diff] [blame] | 40 | void aml_mhu_secure_message_end(void) |
Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 41 | { |
Carlo Caione | 9c85f25 | 2019-08-28 09:46:18 +0100 | [diff] [blame] | 42 | mmio_write_32(AML_HIU_MAILBOX_CLR_0, 0xFFFFFFFF); |
Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 43 | |
| 44 | bakery_lock_release(&mhu_lock); |
| 45 | } |
| 46 | |
Carlo Caione | 9c85f25 | 2019-08-28 09:46:18 +0100 | [diff] [blame] | 47 | void aml_mhu_secure_init(void) |
Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 48 | { |
| 49 | bakery_lock_init(&mhu_lock); |
| 50 | |
Carlo Caione | 9c85f25 | 2019-08-28 09:46:18 +0100 | [diff] [blame] | 51 | mmio_write_32(AML_HIU_MAILBOX_CLR_3, 0xFFFFFFFF); |
Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 52 | } |