memory.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * linux/include/asm-arm/arch-s3c2400/memory.h by gj@denx.de
  3. * based on
  4. * linux/include/asm-arm/arch-sa1100/memory.h
  5. *
  6. * Copyright (c) 1999 Nicolas Pitre <nico@visuaide.com>
  7. */
  8. #ifndef __ASM_ARCH_MEMORY_H
  9. #define __ASM_ARCH_MEMORY_H
  10. /*
  11. * Task size: 3GB
  12. */
  13. #define TASK_SIZE (0xc0000000UL)
  14. #define TASK_SIZE_26 (0x04000000UL)
  15. /*
  16. * This decides where the kernel will search for a free chunk of vm
  17. * space during mmap's.
  18. */
  19. #define TASK_UNMAPPED_BASE (TASK_SIZE / 3)
  20. /*
  21. * Page offset: 3GB
  22. */
  23. #define PAGE_OFFSET (0xc0000000UL)
  24. /*
  25. * Physical DRAM offset is 0x0c000000 on the S3C2400
  26. */
  27. #define PHYS_OFFSET (0x0c000000UL)
  28. #include <linux/config.h>
  29. /* Modified for S3C2400, by chc, 20010509 */
  30. #define RAM_IN_BANK_0 32*1024*1024
  31. #define RAM_IN_BANK_1 0
  32. #define RAM_IN_BANK_2 0
  33. #define RAM_IN_BANK_3 0
  34. #define MEM_SIZE (RAM_IN_BANK_0+RAM_IN_BANK_1+RAM_IN_BANK_2+RAM_IN_BANK_3)
  35. /* translation macros */
  36. #define __virt_to_phys__is_a_macro
  37. #define __phys_to_virt__is_a_macro
  38. #if (RAM_IN_BANK_1 + RAM_IN_BANK_2 + RAM_IN_BANK_3 == 0)
  39. #define __virt_to_phys(x) ( (x) - PAGE_OFFSET + 0x0c000000 )
  40. #define __phys_to_virt(x) ( (x) - 0x0c000000 + PAGE_OFFSET )
  41. #elif (RAM_IN_BANK_0 == RAM_IN_BANK_1) && \
  42. (RAM_IN_BANK_2 + RAM_IN_BANK_3 == 0)
  43. /* Two identical banks */
  44. #define __virt_to_phys(x) \
  45. ( ((x) < PAGE_OFFSET+RAM_IN_BANK_0) ? \
  46. ((x) - PAGE_OFFSET + _DRAMBnk0) : \
  47. ((x) - PAGE_OFFSET - RAM_IN_BANK_0 + _DRAMBnk1) )
  48. #define __phys_to_virt(x) \
  49. ( ((x)&0x07ffffff) + \
  50. (((x)&0x08000000) ? PAGE_OFFSET+RAM_IN_BANK_0 : PAGE_OFFSET) )
  51. #else
  52. /* It's more efficient for all other cases to use the function call */
  53. #undef __virt_to_phys__is_a_macro
  54. #undef __phys_to_virt__is_a_macro
  55. extern unsigned long __virt_to_phys(unsigned long vpage);
  56. extern unsigned long __phys_to_virt(unsigned long ppage);
  57. #endif
  58. /*
  59. * Virtual view <-> DMA view memory address translations
  60. * virt_to_bus: Used to translate the virtual address to an
  61. * address suitable to be passed to set_dma_addr
  62. * bus_to_virt: Used to convert an address for DMA operations
  63. * to an address that the kernel can use.
  64. *
  65. * On the SA1100, bus addresses are equivalent to physical addresses.
  66. */
  67. #define __virt_to_bus__is_a_macro
  68. #define __virt_to_bus(x) __virt_to_phys(x)
  69. #define __bus_to_virt__is_a_macro
  70. #define __bus_to_virt(x) __phys_to_virt(x)
  71. #ifdef CONFIG_DISCONTIGMEM
  72. #error "CONFIG_DISCONTIGMEM will not work on S3C2400"
  73. /*
  74. * Because of the wide memory address space between physical RAM banks on the
  75. * SA1100, it's much more convenient to use Linux's NUMA support to implement
  76. * our memory map representation. Assuming all memory nodes have equal access
  77. * characteristics, we then have generic discontiguous memory support.
  78. *
  79. * Of course, all this isn't mandatory for SA1100 implementations with only
  80. * one used memory bank. For those, simply undefine CONFIG_DISCONTIGMEM.
  81. *
  82. * The nodes are matched with the physical memory bank addresses which are
  83. * incidentally the same as virtual addresses.
  84. *
  85. * node 0: 0xc0000000 - 0xc7ffffff
  86. * node 1: 0xc8000000 - 0xcfffffff
  87. * node 2: 0xd0000000 - 0xd7ffffff
  88. * node 3: 0xd8000000 - 0xdfffffff
  89. */
  90. #define NR_NODES 4
  91. /*
  92. * Given a kernel address, find the home node of the underlying memory.
  93. */
  94. #define KVADDR_TO_NID(addr) \
  95. (((unsigned long)(addr) - 0xc0000000) >> 27)
  96. /*
  97. * Given a physical address, convert it to a node id.
  98. */
  99. #define PHYS_TO_NID(addr) KVADDR_TO_NID(__phys_to_virt(addr))
  100. /*
  101. * Given a kaddr, ADDR_TO_MAPBASE finds the owning node of the memory
  102. * and returns the mem_map of that node.
  103. */
  104. #define ADDR_TO_MAPBASE(kaddr) \
  105. NODE_MEM_MAP(KVADDR_TO_NID((unsigned long)(kaddr)))
  106. /*
  107. * Given a kaddr, LOCAL_MEM_MAP finds the owning node of the memory
  108. * and returns the index corresponding to the appropriate page in the
  109. * node's mem_map.
  110. */
  111. #define LOCAL_MAP_NR(kvaddr) \
  112. (((unsigned long)(kvaddr) & 0x07ffffff) >> PAGE_SHIFT)
  113. /*
  114. * Given a kaddr, virt_to_page returns a pointer to the corresponding
  115. * mem_map entry.
  116. */
  117. #define virt_to_page(kaddr) \
  118. (ADDR_TO_MAPBASE(kaddr) + LOCAL_MAP_NR(kaddr))
  119. /*
  120. * VALID_PAGE returns a non-zero value if given page pointer is valid.
  121. * This assumes all node's mem_maps are stored within the node they refer to.
  122. */
  123. #define VALID_PAGE(page) \
  124. ({ unsigned int node = KVADDR_TO_NID(page); \
  125. ( (node < NR_NODES) && \
  126. ((unsigned)((page) - NODE_MEM_MAP(node)) < NODE_DATA(node)->node_size) ); \
  127. })
  128. #else
  129. #define PHYS_TO_NID(addr) (0)
  130. #endif
  131. #endif /* __ASM_ARCH_MEMORY_H */