Antonio Nino Diaz | 7298c1f | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 11 | static DEFINE_BAKERY_LOCK(mhu_lock); |
| 12 | |
| 13 | void 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 | |
| 21 | void 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 | |
| 29 | uint32_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 | |
| 40 | void 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 | |
| 47 | void mhu_secure_init(void) |
| 48 | { |
| 49 | bakery_lock_init(&mhu_lock); |
| 50 | |
| 51 | mmio_write_32(GXBB_HIU_MAILBOX_CLR_3, 0xFFFFFFFF); |
| 52 | } |