rsi.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2024 ARM Ltd.
  4. */
  5. #ifndef __ASM_RSI_H_
  6. #define __ASM_RSI_H_
  7. #include <linux/errno.h>
  8. #include <linux/jump_label.h>
  9. #include <asm/rsi_cmds.h>
  10. #define RSI_PDEV_NAME "arm-cca-dev"
  11. DECLARE_STATIC_KEY_FALSE(rsi_present);
  12. void __init arm64_rsi_init(void);
  13. bool arm64_rsi_is_protected(phys_addr_t base, size_t size);
  14. static inline bool is_realm_world(void)
  15. {
  16. return static_branch_unlikely(&rsi_present);
  17. }
  18. static inline int rsi_set_memory_range(phys_addr_t start, phys_addr_t end,
  19. enum ripas state, unsigned long flags)
  20. {
  21. unsigned long ret;
  22. phys_addr_t top;
  23. while (start != end) {
  24. ret = rsi_set_addr_range_state(start, end, state, flags, &top);
  25. if (ret || top < start || top > end)
  26. return -EINVAL;
  27. start = top;
  28. }
  29. return 0;
  30. }
  31. /*
  32. * Convert the specified range to RAM. Do not use this if you rely on the
  33. * contents of a page that may already be in RAM state.
  34. */
  35. static inline int rsi_set_memory_range_protected(phys_addr_t start,
  36. phys_addr_t end)
  37. {
  38. return rsi_set_memory_range(start, end, RSI_RIPAS_RAM,
  39. RSI_CHANGE_DESTROYED);
  40. }
  41. /*
  42. * Convert the specified range to RAM. Do not convert any pages that may have
  43. * been DESTROYED, without our permission.
  44. */
  45. static inline int rsi_set_memory_range_protected_safe(phys_addr_t start,
  46. phys_addr_t end)
  47. {
  48. return rsi_set_memory_range(start, end, RSI_RIPAS_RAM,
  49. RSI_NO_CHANGE_DESTROYED);
  50. }
  51. static inline int rsi_set_memory_range_shared(phys_addr_t start,
  52. phys_addr_t end)
  53. {
  54. return rsi_set_memory_range(start, end, RSI_RIPAS_EMPTY,
  55. RSI_CHANGE_DESTROYED);
  56. }
  57. #endif /* __ASM_RSI_H_ */