domain.h 3.7 KB

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