tlkd_private.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef TLKD_PRIVATE_H
  7. #define TLKD_PRIVATE_H
  8. #include <platform_def.h>
  9. #include <arch.h>
  10. #include <bl31/interrupt_mgmt.h>
  11. #include <context.h>
  12. #include <lib/psci/psci.h>
  13. /*
  14. * This flag is used by the TLKD to determine if the SP is servicing a yielding
  15. * SMC request prior to programming the next entry into the SP e.g. if SP
  16. * execution is preempted by a non-secure interrupt and handed control to the
  17. * normal world. If another request which is distinct from what the SP was
  18. * previously doing arrives, then this flag will be help the TLKD to either
  19. * reject the new request or service it while ensuring that the previous context
  20. * is not corrupted.
  21. */
  22. #define YIELD_SMC_ACTIVE_FLAG_SHIFT 2
  23. #define YIELD_SMC_ACTIVE_FLAG_MASK 1
  24. #define get_yield_smc_active_flag(state) \
  25. (((state) >> YIELD_SMC_ACTIVE_FLAG_SHIFT) \
  26. & YIELD_SMC_ACTIVE_FLAG_MASK)
  27. #define set_yield_smc_active_flag(state) ((state) |= \
  28. (1 << YIELD_SMC_ACTIVE_FLAG_SHIFT))
  29. #define clr_yield_smc_active_flag(state) ((state) &= \
  30. ~(YIELD_SMC_ACTIVE_FLAG_MASK \
  31. << YIELD_SMC_ACTIVE_FLAG_SHIFT))
  32. /*******************************************************************************
  33. * Translate virtual address received from the NS world
  34. ******************************************************************************/
  35. #define TLK_TRANSLATE_NS_VADDR 4
  36. /*******************************************************************************
  37. * Secure Payload execution state information i.e. aarch32 or aarch64
  38. ******************************************************************************/
  39. #define SP_AARCH32 MODE_RW_32
  40. #define SP_AARCH64 MODE_RW_64
  41. /*******************************************************************************
  42. * Number of cpus that the present on this platform. TODO: Rely on a topology
  43. * tree to determine this in the future to avoid assumptions about mpidr
  44. * allocation
  45. ******************************************************************************/
  46. #define TLKD_CORE_COUNT PLATFORM_CORE_COUNT
  47. /*******************************************************************************
  48. * Constants that allow assembler code to preserve callee-saved registers of the
  49. * C runtime context while performing a security state switch.
  50. ******************************************************************************/
  51. #define TLKD_C_RT_CTX_X19 0x0
  52. #define TLKD_C_RT_CTX_X20 0x8
  53. #define TLKD_C_RT_CTX_X21 0x10
  54. #define TLKD_C_RT_CTX_X22 0x18
  55. #define TLKD_C_RT_CTX_X23 0x20
  56. #define TLKD_C_RT_CTX_X24 0x28
  57. #define TLKD_C_RT_CTX_X25 0x30
  58. #define TLKD_C_RT_CTX_X26 0x38
  59. #define TLKD_C_RT_CTX_X27 0x40
  60. #define TLKD_C_RT_CTX_X28 0x48
  61. #define TLKD_C_RT_CTX_X29 0x50
  62. #define TLKD_C_RT_CTX_X30 0x58
  63. #define TLKD_C_RT_CTX_SIZE 0x60
  64. #define TLKD_C_RT_CTX_ENTRIES (TLKD_C_RT_CTX_SIZE >> DWORD_SHIFT)
  65. #ifndef __ASSEMBLER__
  66. #include <stdint.h>
  67. #include <lib/cassert.h>
  68. /* AArch64 callee saved general purpose register context structure. */
  69. DEFINE_REG_STRUCT(c_rt_regs, TLKD_C_RT_CTX_ENTRIES);
  70. /*
  71. * Compile time assertion to ensure that both the compiler and linker
  72. * have the same double word aligned view of the size of the C runtime
  73. * register context.
  74. */
  75. CASSERT(TLKD_C_RT_CTX_SIZE == sizeof(c_rt_regs_t),
  76. assert_tlkd_c_rt_regs_size_mismatch);
  77. /*******************************************************************************
  78. * Structure which helps the SPD to maintain the per-cpu state of the SP.
  79. * 'state' - collection of flags to track SP state e.g. on/off
  80. * 'mpidr' - mpidr to associate a context with a cpu
  81. * 'c_rt_ctx' - stack address to restore C runtime context from after
  82. * returning from a synchronous entry into the SP.
  83. * 'cpu_ctx' - space to maintain SP architectural state
  84. * 'saved_tsp_args' - space to store arguments for TSP arithmetic operations
  85. * which will queried using the TSP_GET_ARGS SMC by TSP.
  86. ******************************************************************************/
  87. typedef struct tlk_context {
  88. uint32_t state;
  89. uint64_t mpidr;
  90. uint64_t c_rt_ctx;
  91. cpu_context_t cpu_ctx;
  92. } tlk_context_t;
  93. /*******************************************************************************
  94. * Function & Data prototypes
  95. ******************************************************************************/
  96. uint64_t tlkd_va_translate(uintptr_t va, int type);
  97. uint64_t tlkd_enter_sp(uint64_t *c_rt_ctx);
  98. void __dead2 tlkd_exit_sp(uint64_t c_rt_ctx, uint64_t ret);
  99. uint64_t tlkd_synchronous_sp_entry(tlk_context_t *tlk_ctx);
  100. void __dead2 tlkd_synchronous_sp_exit(tlk_context_t *tlk_ctx,
  101. uint64_t ret);
  102. void tlkd_init_tlk_ep_state(struct entry_point_info *tlk_entry_point,
  103. uint32_t rw,
  104. uint64_t pc,
  105. tlk_context_t *tlk_ctx);
  106. #endif /*__ASSEMBLER__*/
  107. #endif /* TLKD_PRIVATE_H */