Antonio Nino Diaz | 272e871 | 2018-09-18 01:36:00 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | 272e871 | 2018-09-18 01:36:00 +0100 | [diff] [blame] | 7 | #include <platform_def.h> |
| 8 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | #include <lib/bakery_lock.h> |
| 10 | #include <lib/mmio.h> |
| 11 | |
Antonio Nino Diaz | 272e871 | 2018-09-18 01:36:00 +0100 | [diff] [blame] | 12 | static DEFINE_BAKERY_LOCK(mhu_lock); |
| 13 | |
| 14 | void 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 | |
| 22 | void 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 | |
| 30 | uint32_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 | |
| 41 | void 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 | |
| 48 | void mhu_secure_init(void) |
| 49 | { |
| 50 | bakery_lock_init(&mhu_lock); |
| 51 | |
| 52 | mmio_write_32(GXBB_HIU_MAILBOX_CLR_3, 0xFFFFFFFF); |
| 53 | } |