mhu.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice, this
  8. * list of conditions and the following disclaimer.
  9. *
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * Neither the name of ARM nor the names of its contributors may be used
  15. * to endorse or promote products derived from this software without specific
  16. * prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include <arch_helpers.h>
  31. #include <bakery_lock.h>
  32. #include <mmio.h>
  33. #include "juno_def.h"
  34. #include "juno_private.h"
  35. #include "mhu.h"
  36. /* SCP MHU secure channel registers */
  37. #define SCP_INTR_S_STAT 0x200
  38. #define SCP_INTR_S_SET 0x208
  39. #define SCP_INTR_S_CLEAR 0x210
  40. /* CPU MHU secure channel registers */
  41. #define CPU_INTR_S_STAT 0x300
  42. #define CPU_INTR_S_SET 0x308
  43. #define CPU_INTR_S_CLEAR 0x310
  44. #if IMAGE_BL31
  45. #if USE_COHERENT_MEM
  46. static bakery_lock_t mhu_secure_lock __attribute__ ((section("tzfw_coherent_mem")));
  47. #define LOCK_ARG &mhu_secure_lock
  48. #else
  49. #define LOCK_ARG JUNO_MHU_BAKERY_ID
  50. #endif /*__USE_COHERENT_MEM__ */
  51. #else
  52. #define LOCK_ARG /* Locks required only for BL3-1 images */
  53. #endif /* __IMAGE_BL31__ */
  54. void mhu_secure_message_start(void)
  55. {
  56. juno_lock_get(LOCK_ARG);
  57. /* Make sure any previous command has finished */
  58. while (mmio_read_32(MHU_BASE + CPU_INTR_S_STAT) != 0)
  59. ;
  60. }
  61. void mhu_secure_message_send(uint32_t command)
  62. {
  63. /* Send command to SCP and wait for it to pick it up */
  64. mmio_write_32(MHU_BASE + CPU_INTR_S_SET, command);
  65. while (mmio_read_32(MHU_BASE + CPU_INTR_S_STAT) != 0)
  66. ;
  67. }
  68. uint32_t mhu_secure_message_wait(void)
  69. {
  70. /* Wait for response from SCP */
  71. uint32_t response;
  72. while (!(response = mmio_read_32(MHU_BASE + SCP_INTR_S_STAT)))
  73. ;
  74. return response;
  75. }
  76. void mhu_secure_message_end(void)
  77. {
  78. /* Clear any response we got by writing all ones to the CLEAR register */
  79. mmio_write_32(MHU_BASE + SCP_INTR_S_CLEAR, 0xffffffffu);
  80. juno_lock_release(LOCK_ARG);
  81. }
  82. void mhu_secure_init(void)
  83. {
  84. juno_lock_init(LOCK_ARG);
  85. /*
  86. * Clear the CPU's INTR register to make sure we don't see a stale
  87. * or garbage value and think it's a message we've already sent.
  88. */
  89. mmio_write_32(MHU_BASE + CPU_INTR_S_CLEAR, 0xffffffffu);
  90. }