memory.h 6.7 KB

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