sdei.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (c) 2017-2022, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef SDEI_H
  7. #define SDEI_H
  8. #include <lib/spinlock.h>
  9. #include <lib/utils_def.h>
  10. #include <services/sdei_flags.h>
  11. /* Range 0xC4000020 - 0xC400003F reserved for SDE 64bit smc calls */
  12. #define SDEI_VERSION 0xC4000020U
  13. #define SDEI_EVENT_REGISTER 0xC4000021U
  14. #define SDEI_EVENT_ENABLE 0xC4000022U
  15. #define SDEI_EVENT_DISABLE 0xC4000023U
  16. #define SDEI_EVENT_CONTEXT 0xC4000024U
  17. #define SDEI_EVENT_COMPLETE 0xC4000025U
  18. #define SDEI_EVENT_COMPLETE_AND_RESUME 0xC4000026U
  19. #define SDEI_EVENT_UNREGISTER 0xC4000027U
  20. #define SDEI_EVENT_STATUS 0xC4000028U
  21. #define SDEI_EVENT_GET_INFO 0xC4000029U
  22. #define SDEI_EVENT_ROUTING_SET 0xC400002AU
  23. #define SDEI_PE_MASK 0xC400002BU
  24. #define SDEI_PE_UNMASK 0xC400002CU
  25. #define SDEI_INTERRUPT_BIND 0xC400002DU
  26. #define SDEI_INTERRUPT_RELEASE 0xC400002EU
  27. #define SDEI_EVENT_SIGNAL 0xC400002FU
  28. #define SDEI_FEATURES 0xC4000030U
  29. #define SDEI_PRIVATE_RESET 0xC4000031U
  30. #define SDEI_SHARED_RESET 0xC4000032U
  31. /* SDEI_EVENT_REGISTER flags */
  32. #define SDEI_REGF_RM_ANY 0ULL
  33. #define SDEI_REGF_RM_PE 1ULL
  34. /* SDEI_EVENT_COMPLETE status flags */
  35. #define SDEI_EV_HANDLED 0U
  36. #define SDEI_EV_FAILED 1U
  37. /* Indices of private and shared mappings */
  38. #define SDEI_MAP_IDX_PRIV_ 0U
  39. #define SDEI_MAP_IDX_SHRD_ 1U
  40. #define SDEI_MAP_IDX_MAX_ 2U
  41. /* The macros below are used to identify SDEI calls from the SMC function ID */
  42. #define SDEI_FID_MASK U(0xffe0)
  43. #define SDEI_FID_VALUE U(0x20)
  44. #define is_sdei_fid(_fid) \
  45. ((((_fid) & SDEI_FID_MASK) == SDEI_FID_VALUE) && \
  46. (((_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_64))
  47. #define SDEI_EVENT_MAP(_event, _intr, _flags) \
  48. { \
  49. .ev_num = (_event), \
  50. .intr = (_intr), \
  51. .map_flags = (_flags) \
  52. }
  53. #define SDEI_SHARED_EVENT(_event, _intr, _flags) \
  54. SDEI_EVENT_MAP(_event, _intr, _flags)
  55. #define SDEI_PRIVATE_EVENT(_event, _intr, _flags) \
  56. SDEI_EVENT_MAP(_event, _intr, (_flags) | SDEI_MAPF_PRIVATE)
  57. #define SDEI_DEFINE_EVENT_0(_intr) \
  58. SDEI_PRIVATE_EVENT(SDEI_EVENT_0, (_intr), SDEI_MAPF_SIGNALABLE)
  59. #define SDEI_EXPLICIT_EVENT(_event, _pri) \
  60. SDEI_EVENT_MAP((_event), 0, (_pri) | SDEI_MAPF_EXPLICIT | SDEI_MAPF_PRIVATE)
  61. /*
  62. * Declare shared and private entries for each core. Also declare a global
  63. * structure containing private and share entries.
  64. *
  65. * This macro must be used in the same file as the platform SDEI mappings are
  66. * declared. Only then would ARRAY_SIZE() yield a meaningful value.
  67. */
  68. #define REGISTER_SDEI_MAP(_private, _shared) \
  69. sdei_entry_t sdei_private_event_table \
  70. [PLATFORM_CORE_COUNT * ARRAY_SIZE(_private)]; \
  71. sdei_entry_t sdei_shared_event_table[ARRAY_SIZE(_shared)]; \
  72. const sdei_mapping_t sdei_global_mappings[] = { \
  73. [SDEI_MAP_IDX_PRIV_] = { \
  74. .map = (_private), \
  75. .num_maps = ARRAY_SIZE(_private) \
  76. }, \
  77. [SDEI_MAP_IDX_SHRD_] = { \
  78. .map = (_shared), \
  79. .num_maps = ARRAY_SIZE(_shared) \
  80. }, \
  81. }
  82. typedef uint8_t sdei_state_t;
  83. /* Runtime data of SDEI event */
  84. typedef struct sdei_entry {
  85. uint64_t ep; /* Entry point */
  86. uint64_t arg; /* Entry point argument */
  87. uint64_t affinity; /* Affinity of shared event */
  88. unsigned int reg_flags; /* Registration flags */
  89. /* Event handler states: registered, enabled, running */
  90. sdei_state_t state;
  91. } sdei_entry_t;
  92. /* Mapping of SDEI events to interrupts, and associated data */
  93. typedef struct sdei_ev_map {
  94. int32_t ev_num; /* Event number */
  95. unsigned int intr; /* Physical interrupt number for a bound map */
  96. unsigned int map_flags; /* Mapping flags, see SDEI_MAPF_* */
  97. int reg_count; /* Registration count */
  98. spinlock_t lock; /* Per-event lock */
  99. } sdei_ev_map_t;
  100. typedef struct sdei_mapping {
  101. sdei_ev_map_t *map;
  102. size_t num_maps;
  103. } sdei_mapping_t;
  104. /* Handler to be called to handle SDEI smc calls */
  105. uint64_t sdei_smc_handler(uint32_t smc_fid,
  106. uint64_t x1,
  107. uint64_t x2,
  108. uint64_t x3,
  109. uint64_t x4,
  110. void *cookie,
  111. void *handle,
  112. uint64_t flags);
  113. void sdei_init(void);
  114. /* Public API to dispatch an event to Normal world */
  115. int sdei_dispatch_event(int ev_num);
  116. /* Public API to check how many SDEI events are registered. */
  117. int sdei_get_registered_event_count(void);
  118. #endif /* SDEI_H */