memory.h 4.5 KB

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