memory.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * linux/include/asm-arm/memory.h
  3. *
  4. * Copyright (C) 2000-2002 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. * Note: this file should not be included by non-asm/.h files
  11. */
  12. #ifndef __ASM_ARM_MEMORY_H
  13. #define __ASM_ARM_MEMORY_H
  14. /*
  15. * Allow for constants defined here to be used from assembly code
  16. * by prepending the UL suffix only with actual C code compilation.
  17. */
  18. #ifndef __ASSEMBLY__
  19. #define UL(x) (x##UL)
  20. #else
  21. #define UL(x) (x)
  22. #endif
  23. #include <linux/config.h>
  24. #include <linux/compiler.h>
  25. #include <asm/arch/memory.h>
  26. #include <asm/sizes.h>
  27. #ifndef TASK_SIZE
  28. /*
  29. * TASK_SIZE - the maximum size of a user space task.
  30. * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area
  31. */
  32. #define TASK_SIZE UL(0xbf000000)
  33. #define TASK_UNMAPPED_BASE UL(0x40000000)
  34. #endif
  35. /*
  36. * The maximum size of a 26-bit user space task.
  37. */
  38. #define TASK_SIZE_26 UL(0x04000000)
  39. /*
  40. * Page offset: 3GB
  41. */
  42. #ifndef PAGE_OFFSET
  43. #define PAGE_OFFSET UL(0xc0000000)
  44. #endif
  45. /*
  46. * Size of DMA-consistent memory region. Must be multiple of 2M,
  47. * between 2MB and 14MB inclusive.
  48. */
  49. #ifndef CONSISTENT_DMA_SIZE
  50. #define CONSISTENT_DMA_SIZE SZ_2M
  51. #endif
  52. /*
  53. * Physical vs virtual RAM address space conversion. These are
  54. * private definitions which should NOT be used outside memory.h
  55. * files. Use virt_to_phys/phys_to_virt/__pa/__va instead.
  56. */
  57. #ifndef __virt_to_phys
  58. #define __virt_to_phys(x) ((x) - PAGE_OFFSET + PHYS_OFFSET)
  59. #define __phys_to_virt(x) ((x) - PHYS_OFFSET + PAGE_OFFSET)
  60. #endif
  61. /*
  62. * Convert a physical address to a Page Frame Number and back
  63. */
  64. #define __phys_to_pfn(paddr) ((paddr) >> PAGE_SHIFT)
  65. #define __pfn_to_phys(pfn) ((pfn) << PAGE_SHIFT)
  66. /*
  67. * The module space lives between the addresses given by TASK_SIZE
  68. * and PAGE_OFFSET - it must be within 32MB of the kernel text.
  69. */
  70. #define MODULE_END (PAGE_OFFSET)
  71. #define MODULE_START (MODULE_END - 16*1048576)
  72. #if TASK_SIZE > MODULE_START
  73. #error Top of user space clashes with start of module space
  74. #endif
  75. /*
  76. * The XIP kernel gets mapped at the bottom of the module vm area.
  77. * Since we use sections to map it, this macro replaces the physical address
  78. * with its virtual address while keeping offset from the base section.
  79. */
  80. #define XIP_VIRT_ADDR(physaddr) (MODULE_START + ((physaddr) & 0x000fffff))
  81. #ifndef __ASSEMBLY__
  82. /*
  83. * The DMA mask corresponding to the maximum bus address allocatable
  84. * using GFP_DMA. The default here places no restriction on DMA
  85. * allocations. This must be the smallest DMA mask in the system,
  86. * so a successful GFP_DMA allocation will always satisfy this.
  87. */
  88. #ifndef ISA_DMA_THRESHOLD
  89. #define ISA_DMA_THRESHOLD (0xffffffffULL)
  90. #endif
  91. #ifndef arch_adjust_zones
  92. #define arch_adjust_zones(node,size,holes) do { } while (0)
  93. #endif
  94. /*
  95. * PFNs are used to describe any physical page; this means
  96. * PFN 0 == physical address 0.
  97. *
  98. * This is the PFN of the first RAM page in the kernel
  99. * direct-mapped view. We assume this is the first page
  100. * of RAM in the mem_map as well.
  101. */
  102. #define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT)
  103. /*
  104. * These are *only* valid on the kernel direct mapped RAM memory.
  105. * Note: Drivers should NOT use these. They are the wrong
  106. * translation for translating DMA addresses. Use the driver
  107. * DMA support - see dma-mapping.h.
  108. */
  109. static inline unsigned long virt_to_phys(void *x)
  110. {
  111. return __virt_to_phys((unsigned long)(x));
  112. }
  113. static inline void *phys_to_virt(unsigned long x)
  114. {
  115. return (void *)(__phys_to_virt((unsigned long)(x)));
  116. }
  117. /*
  118. * Drivers should NOT use these either.
  119. */
  120. #define __pa(x) __virt_to_phys((unsigned long)(x))
  121. #define __va(x) ((void *)__phys_to_virt((unsigned long)(x)))
  122. #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
  123. /*
  124. * Virtual <-> DMA view memory address translations
  125. * Again, these are *only* valid on the kernel direct mapped RAM
  126. * memory. Use of these is *deprecated* (and that doesn't mean
  127. * use the __ prefixed forms instead.) See dma-mapping.h.
  128. */
  129. static inline __deprecated unsigned long virt_to_bus(void *x)
  130. {
  131. return __virt_to_bus((unsigned long)x);
  132. }
  133. static inline __deprecated void *bus_to_virt(unsigned long x)
  134. {
  135. return (void *)__bus_to_virt(x);
  136. }
  137. /*
  138. * Conversion between a struct page and a physical address.
  139. *
  140. * Note: when converting an unknown physical address to a
  141. * struct page, the resulting pointer must be validated
  142. * using VALID_PAGE(). It must return an invalid struct page
  143. * for any physical address not corresponding to a system
  144. * RAM address.
  145. *
  146. * page_to_pfn(page) convert a struct page * to a PFN number
  147. * pfn_to_page(pfn) convert a _valid_ PFN number to struct page *
  148. * pfn_valid(pfn) indicates whether a PFN number is valid
  149. *
  150. * virt_to_page(k) convert a _valid_ virtual address to struct page *
  151. * virt_addr_valid(k) indicates whether a virtual address is valid
  152. */
  153. #ifndef CONFIG_DISCONTIGMEM
  154. #define page_to_pfn(page) (((page) - mem_map) + PHYS_PFN_OFFSET)
  155. #define pfn_to_page(pfn) ((mem_map + (pfn)) - PHYS_PFN_OFFSET)
  156. #define pfn_valid(pfn) ((pfn) >= PHYS_PFN_OFFSET && (pfn) < (PHYS_PFN_OFFSET + max_mapnr))
  157. #define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
  158. #define virt_addr_valid(kaddr) ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)
  159. #define PHYS_TO_NID(addr) (0)
  160. #else /* CONFIG_DISCONTIGMEM */
  161. /*
  162. * This is more complex. We have a set of mem_map arrays spread
  163. * around in memory.
  164. */
  165. #include <linux/numa.h>
  166. #define page_to_pfn(page) \
  167. (( (page) - page_zone(page)->zone_mem_map) \
  168. + page_zone(page)->zone_start_pfn)
  169. #define pfn_to_page(pfn) \
  170. (PFN_TO_MAPBASE(pfn) + LOCAL_MAP_NR((pfn) << PAGE_SHIFT))
  171. #define pfn_valid(pfn) \
  172. ({ \
  173. unsigned int nid = PFN_TO_NID(pfn); \
  174. int valid = nid < MAX_NUMNODES; \
  175. if (valid) { \
  176. pg_data_t *node = NODE_DATA(nid); \
  177. valid = (pfn - node->node_start_pfn) < \
  178. node->node_spanned_pages; \
  179. } \
  180. valid; \
  181. })
  182. #define virt_to_page(kaddr) \
  183. (ADDR_TO_MAPBASE(kaddr) + LOCAL_MAP_NR(kaddr))
  184. #define virt_addr_valid(kaddr) (KVADDR_TO_NID(kaddr) < MAX_NUMNODES)
  185. /*
  186. * Common discontigmem stuff.
  187. * PHYS_TO_NID is used by the ARM kernel/setup.c
  188. */
  189. #define PHYS_TO_NID(addr) PFN_TO_NID((addr) >> PAGE_SHIFT)
  190. #endif /* !CONFIG_DISCONTIGMEM */
  191. /*
  192. * For BIO. "will die". Kill me when bio_to_phys() and bvec_to_phys() die.
  193. */
  194. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  195. /*
  196. * Optional device DMA address remapping. Do _not_ use directly!
  197. * We should really eliminate virt_to_bus() here - it's deprecated.
  198. */
  199. #ifndef __arch_page_to_dma
  200. #define page_to_dma(dev, page) ((dma_addr_t)__virt_to_bus((unsigned long)page_address(page)))
  201. #define dma_to_virt(dev, addr) ((void *)__bus_to_virt(addr))
  202. #define virt_to_dma(dev, addr) ((dma_addr_t)__virt_to_bus((unsigned long)(addr)))
  203. #else
  204. #define page_to_dma(dev, page) (__arch_page_to_dma(dev, page))
  205. #define dma_to_virt(dev, addr) (__arch_dma_to_virt(dev, addr))
  206. #define virt_to_dma(dev, addr) (__arch_virt_to_dma(dev, addr))
  207. #endif
  208. #endif
  209. #endif