ehf.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef EHF_H
  7. #define EHF_H
  8. #ifndef __ASSEMBLER__
  9. #include <cdefs.h>
  10. #include <stdint.h>
  11. #include <lib/utils_def.h>
  12. /* Valid priorities set bit 0 of the priority handler. */
  13. #define EHF_PRI_VALID_ BIT(0)
  14. /* Marker for no handler registered for a valid priority */
  15. #define EHF_NO_HANDLER_ (0U | EHF_PRI_VALID_)
  16. /* Extract the specified number of top bits from 7 lower bits of priority */
  17. #define EHF_PRI_TO_IDX(pri, plat_bits) \
  18. ((((unsigned) (pri)) & 0x7fu) >> (7u - (plat_bits)))
  19. /* Install exception priority descriptor at a suitable index */
  20. #define EHF_PRI_DESC(plat_bits, priority) \
  21. [EHF_PRI_TO_IDX(priority, plat_bits)] = { \
  22. .ehf_handler = EHF_NO_HANDLER_, \
  23. }
  24. /* Macro for platforms to register its exception priorities */
  25. #define EHF_REGISTER_PRIORITIES(priorities, num, bits) \
  26. const ehf_priorities_t exception_data = { \
  27. .num_priorities = (num), \
  28. .ehf_priorities = (priorities), \
  29. .pri_bits = (bits), \
  30. }
  31. /*
  32. * Priority stack, managed as a bitmap.
  33. *
  34. * Currently only supports 32 priority levels, allowing platforms to use up to 5
  35. * top bits of priority. But the type can be changed to uint64_t should need
  36. * arise to support 64 priority levels, allowing platforms to use up to 6 top
  37. * bits of priority.
  38. */
  39. typedef uint32_t ehf_pri_bits_t;
  40. /*
  41. * Per-PE exception data. The data for each PE is kept as a per-CPU data field.
  42. * See cpu_data.h.
  43. */
  44. typedef struct {
  45. ehf_pri_bits_t active_pri_bits;
  46. /* Priority mask value before any priority levels were active */
  47. uint8_t init_pri_mask;
  48. /* Non-secure priority mask value stashed during Secure execution */
  49. uint8_t ns_pri_mask;
  50. } __aligned(sizeof(uint64_t)) pe_exc_data_t;
  51. typedef int (*ehf_handler_t)(uint32_t intr_raw, uint32_t flags, void *handle,
  52. void *cookie);
  53. typedef struct ehf_pri_desc {
  54. /*
  55. * 4-byte-aligned exception handler. Bit 0 indicates the corresponding
  56. * priority level is valid. This is effectively of ehf_handler_t type,
  57. * but left as uintptr_t in order to make pointer arithmetic convenient.
  58. */
  59. uintptr_t ehf_handler;
  60. } ehf_pri_desc_t;
  61. typedef struct ehf_priority_type {
  62. ehf_pri_desc_t *ehf_priorities;
  63. unsigned int num_priorities;
  64. unsigned int pri_bits;
  65. } ehf_priorities_t;
  66. void ehf_init(void);
  67. void ehf_activate_priority(unsigned int priority);
  68. void ehf_deactivate_priority(unsigned int priority);
  69. void ehf_register_priority_handler(unsigned int pri, ehf_handler_t handler);
  70. void ehf_allow_ns_preemption(uint64_t preempt_ret_code);
  71. unsigned int ehf_is_ns_preemption_allowed(void);
  72. #endif /* __ASSEMBLER__ */
  73. #endif /* EHF_H */