aml_mhu.c 925 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <lib/bakery_lock.h>
  7. #include <lib/mmio.h>
  8. #include <platform_def.h>
  9. static DEFINE_BAKERY_LOCK(mhu_lock);
  10. void aml_mhu_secure_message_start(void)
  11. {
  12. bakery_lock_get(&mhu_lock);
  13. while (mmio_read_32(AML_HIU_MAILBOX_STAT_3) != 0)
  14. ;
  15. }
  16. void aml_mhu_secure_message_send(uint32_t msg)
  17. {
  18. mmio_write_32(AML_HIU_MAILBOX_SET_3, msg);
  19. while (mmio_read_32(AML_HIU_MAILBOX_STAT_3) != 0)
  20. ;
  21. }
  22. uint32_t aml_mhu_secure_message_wait(void)
  23. {
  24. uint32_t val;
  25. do {
  26. val = mmio_read_32(AML_HIU_MAILBOX_STAT_0);
  27. } while (val == 0);
  28. return val;
  29. }
  30. void aml_mhu_secure_message_end(void)
  31. {
  32. mmio_write_32(AML_HIU_MAILBOX_CLR_0, 0xFFFFFFFF);
  33. bakery_lock_release(&mhu_lock);
  34. }
  35. void aml_mhu_secure_init(void)
  36. {
  37. bakery_lock_init(&mhu_lock);
  38. mmio_write_32(AML_HIU_MAILBOX_CLR_3, 0xFFFFFFFF);
  39. }