domain.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * arch/arm/include/asm/domain.h
  4. *
  5. * Copyright (C) 1999 Russell King.
  6. */
  7. #ifndef __ASM_PROC_DOMAIN_H
  8. #define __ASM_PROC_DOMAIN_H
  9. #ifndef __ASSEMBLY__
  10. #include <asm/barrier.h>
  11. #include <asm/thread_info.h>
  12. #endif
  13. /*
  14. * Domain numbers
  15. *
  16. * DOMAIN_IO - domain 2 includes all IO only
  17. * DOMAIN_USER - domain 1 includes all user memory only
  18. * DOMAIN_KERNEL - domain 0 includes all kernel memory only
  19. *
  20. * The domain numbering depends on whether we support 36 physical
  21. * address for I/O or not. Addresses above the 32 bit boundary can
  22. * only be mapped using supersections and supersections can only
  23. * be set for domain 0. We could just default to DOMAIN_IO as zero,
  24. * but there may be systems with supersection support and no 36-bit
  25. * addressing. In such cases, we want to map system memory with
  26. * supersections to reduce TLB misses and footprint.
  27. *
  28. * 36-bit addressing and supersections are only available on
  29. * CPUs based on ARMv6+ or the Intel XSC3 core.
  30. */
  31. #ifndef CONFIG_IO_36
  32. #define DOMAIN_KERNEL 0
  33. #define DOMAIN_USER 1
  34. #define DOMAIN_IO 2
  35. #else
  36. #define DOMAIN_KERNEL 2
  37. #define DOMAIN_USER 1
  38. #define DOMAIN_IO 0
  39. #endif
  40. #define DOMAIN_VECTORS 3
  41. /*
  42. * Domain types
  43. */
  44. #define DOMAIN_NOACCESS 0
  45. #define DOMAIN_CLIENT 1
  46. #ifdef CONFIG_CPU_USE_DOMAINS
  47. #define DOMAIN_MANAGER 3
  48. #else
  49. #define DOMAIN_MANAGER 1
  50. #endif
  51. #define domain_mask(dom) ((3) << (2 * (dom)))
  52. #define domain_val(dom,type) ((type) << (2 * (dom)))
  53. #ifdef CONFIG_CPU_SW_DOMAIN_PAN
  54. #define DACR_INIT \
  55. (domain_val(DOMAIN_USER, DOMAIN_NOACCESS) | \
  56. domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
  57. domain_val(DOMAIN_IO, DOMAIN_CLIENT) | \
  58. domain_val(DOMAIN_VECTORS, DOMAIN_CLIENT))
  59. #else
  60. #define DACR_INIT \
  61. (domain_val(DOMAIN_USER, DOMAIN_CLIENT) | \
  62. domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
  63. domain_val(DOMAIN_IO, DOMAIN_CLIENT) | \
  64. domain_val(DOMAIN_VECTORS, DOMAIN_CLIENT))
  65. #endif
  66. #define __DACR_DEFAULT \
  67. domain_val(DOMAIN_KERNEL, DOMAIN_CLIENT) | \
  68. domain_val(DOMAIN_IO, DOMAIN_CLIENT) | \
  69. domain_val(DOMAIN_VECTORS, DOMAIN_CLIENT)
  70. #define DACR_UACCESS_DISABLE \
  71. (__DACR_DEFAULT | domain_val(DOMAIN_USER, DOMAIN_NOACCESS))
  72. #define DACR_UACCESS_ENABLE \
  73. (__DACR_DEFAULT | domain_val(DOMAIN_USER, DOMAIN_CLIENT))
  74. #ifndef __ASSEMBLY__
  75. #ifdef CONFIG_CPU_CP15_MMU
  76. static __always_inline unsigned int get_domain(void)
  77. {
  78. unsigned int domain;
  79. asm(
  80. "mrc p15, 0, %0, c3, c0 @ get domain"
  81. : "=r" (domain)
  82. : "m" (current_thread_info()->cpu_domain));
  83. return domain;
  84. }
  85. static __always_inline void set_domain(unsigned int val)
  86. {
  87. asm volatile(
  88. "mcr p15, 0, %0, c3, c0 @ set domain"
  89. : : "r" (val) : "memory");
  90. isb();
  91. }
  92. #else
  93. static __always_inline unsigned int get_domain(void)
  94. {
  95. return 0;
  96. }
  97. static __always_inline void set_domain(unsigned int val)
  98. {
  99. }
  100. #endif
  101. /*
  102. * Generate the T (user) versions of the LDR/STR and related
  103. * instructions (inline assembly)
  104. */
  105. #ifdef CONFIG_CPU_USE_DOMAINS
  106. #define TUSER(instr) TUSERCOND(instr, )
  107. #define TUSERCOND(instr, cond) #instr "t" #cond
  108. #else
  109. #define TUSER(instr) TUSERCOND(instr, )
  110. #define TUSERCOND(instr, cond) #instr #cond
  111. #endif
  112. #else /* __ASSEMBLY__ */
  113. /*
  114. * Generate the T (user) versions of the LDR/STR and related
  115. * instructions
  116. */
  117. #ifdef CONFIG_CPU_USE_DOMAINS
  118. #define TUSER(instr) instr ## t
  119. #else
  120. #define TUSER(instr) instr
  121. #endif
  122. #endif /* __ASSEMBLY__ */
  123. #endif /* !__ASM_PROC_DOMAIN_H */