memory.h 5.9 KB

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