memory.h 6.8 KB

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