mips_addrspace.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * File : mips_addrspace.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team
  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 as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2016Äê9ÔÂ12ÈÕ Urey the first version
  23. */
  24. #ifndef _MIPS_ADDRSPACE_H_
  25. #define _MIPS_ADDRSPACE_H_
  26. /*
  27. * Configure language
  28. */
  29. #ifdef __ASSEMBLY__
  30. #define _ATYPE_
  31. #define _ATYPE32_
  32. #define _ATYPE64_
  33. #define _CONST64_(x) x
  34. #else
  35. #define _ATYPE_ __PTRDIFF_TYPE__
  36. #define _ATYPE32_ int
  37. #define _ATYPE64_ __s64
  38. #ifdef CONFIG_64BIT
  39. #define _CONST64_(x) x ## L
  40. #else
  41. #define _CONST64_(x) x ## LL
  42. #endif
  43. #endif
  44. /*
  45. * 32-bit MIPS address spaces
  46. */
  47. #ifdef __ASSEMBLY__
  48. #define _ACAST32_
  49. #define _ACAST64_
  50. #else
  51. #define _ACAST32_ (_ATYPE_)(_ATYPE32_) /* widen if necessary */
  52. #define _ACAST64_ (_ATYPE64_) /* do _not_ narrow */
  53. #endif
  54. /*
  55. * Returns the kernel segment base of a given address
  56. */
  57. #define KSEGX(a) ((_ACAST32_ (a)) & 0xe0000000)
  58. /*
  59. * Returns the physical address of a CKSEGx / XKPHYS address
  60. */
  61. #define CPHYSADDR(a) ((_ACAST32_(a)) & 0x1fffffff)
  62. #define XPHYSADDR(a) ((_ACAST64_(a)) & \
  63. _CONST64_(0x000000ffffffffff))
  64. #ifdef CONFIG_64BIT
  65. /*
  66. * Memory segments (64bit kernel mode addresses)
  67. * The compatibility segments use the full 64-bit sign extended value. Note
  68. * the R8000 doesn't have them so don't reference these in generic MIPS code.
  69. */
  70. #define XKUSEG _CONST64_(0x0000000000000000)
  71. #define XKSSEG _CONST64_(0x4000000000000000)
  72. #define XKPHYS _CONST64_(0x8000000000000000)
  73. #define XKSEG _CONST64_(0xc000000000000000)
  74. #define CKSEG0 _CONST64_(0xffffffff80000000)
  75. #define CKSEG1 _CONST64_(0xffffffffa0000000)
  76. #define CKSSEG _CONST64_(0xffffffffc0000000)
  77. #define CKSEG3 _CONST64_(0xffffffffe0000000)
  78. #define CKSEG0ADDR(a) (CPHYSADDR(a) | CKSEG0)
  79. #define CKSEG1ADDR(a) (CPHYSADDR(a) | CKSEG1)
  80. #define CKSEG2ADDR(a) (CPHYSADDR(a) | CKSEG2)
  81. #define CKSEG3ADDR(a) (CPHYSADDR(a) | CKSEG3)
  82. #else
  83. #define CKSEG0ADDR(a) (CPHYSADDR(a) | KSEG0BASE)
  84. #define CKSEG1ADDR(a) (CPHYSADDR(a) | KSEG1BASE)
  85. #define CKSEG2ADDR(a) (CPHYSADDR(a) | KSEG2BASE)
  86. #define CKSEG3ADDR(a) (CPHYSADDR(a) | KSEG3BASE)
  87. /*
  88. * Map an address to a certain kernel segment
  89. */
  90. #define KSEG0ADDR(a) (CPHYSADDR(a) | KSEG0BASE)
  91. #define KSEG1ADDR(a) (CPHYSADDR(a) | KSEG1BASE)
  92. #define KSEG2ADDR(a) (CPHYSADDR(a) | KSEG2BASE)
  93. #define KSEG3ADDR(a) (CPHYSADDR(a) | KSEG3BASE)
  94. /*
  95. * Memory segments (32bit kernel mode addresses)
  96. * These are the traditional names used in the 32-bit universe.
  97. */
  98. //#define KUSEGBASE 0x00000000
  99. //#define KSEG0BASE 0x80000000
  100. //#define KSEG1BASE 0xa0000000
  101. //#define KSEG2BASE 0xc0000000
  102. //#define KSEG3BASE 0xe0000000
  103. #define CKUSEG 0x00000000
  104. #define CKSEG0 0x80000000
  105. #define CKSEG1 0xa0000000
  106. #define CKSEG2 0xc0000000
  107. #define CKSEG3 0xe0000000
  108. #endif
  109. /*
  110. * Cache modes for XKPHYS address conversion macros
  111. */
  112. #define K_CALG_COH_EXCL1_NOL2 0
  113. #define K_CALG_COH_SHRL1_NOL2 1
  114. #define K_CALG_UNCACHED 2
  115. #define K_CALG_NONCOHERENT 3
  116. #define K_CALG_COH_EXCL 4
  117. #define K_CALG_COH_SHAREABLE 5
  118. #define K_CALG_NOTUSED 6
  119. #define K_CALG_UNCACHED_ACCEL 7
  120. /*
  121. * 64-bit address conversions
  122. */
  123. #define PHYS_TO_XKSEG_UNCACHED(p) PHYS_TO_XKPHYS(K_CALG_UNCACHED, (p))
  124. #define PHYS_TO_XKSEG_CACHED(p) PHYS_TO_XKPHYS(K_CALG_COH_SHAREABLE, (p))
  125. #define XKPHYS_TO_PHYS(p) ((p) & TO_PHYS_MASK)
  126. #define PHYS_TO_XKPHYS(cm, a) (_CONST64_(0x8000000000000000) | \
  127. (_CONST64_(cm) << 59) | (a))
  128. /*
  129. * Returns the uncached address of a sdram address
  130. */
  131. #ifndef __ASSEMBLY__
  132. #if defined(CONFIG_SOC_AU1X00) || defined(CONFIG_TB0229)
  133. /* We use a 36 bit physical address map here and
  134. cannot access physical memory directly from core */
  135. #define UNCACHED_SDRAM(a) (((unsigned long)(a)) | 0x20000000)
  136. #else /* !CONFIG_SOC_AU1X00 */
  137. #define UNCACHED_SDRAM(a) CKSEG1ADDR(a)
  138. #endif /* CONFIG_SOC_AU1X00 */
  139. #endif /* __ASSEMBLY__ */
  140. /*
  141. * The ultimate limited of the 64-bit MIPS architecture: 2 bits for selecting
  142. * the region, 3 bits for the CCA mode. This leaves 59 bits of which the
  143. * R8000 implements most with its 48-bit physical address space.
  144. */
  145. #define TO_PHYS_MASK _CONST64_(0x07ffffffffffffff) /* 2^^59 - 1 */
  146. #ifndef CONFIG_CPU_R8000
  147. /*
  148. * The R8000 doesn't have the 32-bit compat spaces so we don't define them
  149. * in order to catch bugs in the source code.
  150. */
  151. #define COMPAT_K1BASE32 _CONST64_(0xffffffffa0000000)
  152. #define PHYS_TO_COMPATK1(x) ((x) | COMPAT_K1BASE32) /* 32-bit compat k1 */
  153. #endif
  154. #define KDM_TO_PHYS(x) (_ACAST64_ (x) & TO_PHYS_MASK)
  155. #define PHYS_TO_K0(x) (_ACAST64_ (x) | CAC_BASE)
  156. #ifndef __ASSEMBLY__
  157. /*
  158. * Change virtual addresses to physical addresses and vv.
  159. * These are trivial on the 1:1 Linux/MIPS mapping
  160. */
  161. static inline phys_addr_t virt_to_phys(volatile void * address)
  162. {
  163. #ifndef CONFIG_64BIT
  164. return CPHYSADDR(address);
  165. #else
  166. return XPHYSADDR(address);
  167. #endif
  168. }
  169. static inline void * phys_to_virt(unsigned long address)
  170. {
  171. #ifndef CONFIG_64BIT
  172. return (void *)KSEG0ADDR(address);
  173. #else
  174. return (void *)CKSEG0ADDR(address);
  175. #endif
  176. }
  177. #endif
  178. #endif /* _MIPS_ADDRSPACE_H_ */