mmzone.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Written by Pat Gaughen (gone@us.ibm.com) Mar 2002
  3. *
  4. */
  5. #ifndef _ASM_MMZONE_H_
  6. #define _ASM_MMZONE_H_
  7. #include <asm/smp.h>
  8. #ifdef CONFIG_DISCONTIGMEM
  9. #ifdef CONFIG_NUMA
  10. #ifdef CONFIG_X86_NUMAQ
  11. #include <asm/numaq.h>
  12. #else /* summit or generic arch */
  13. #include <asm/srat.h>
  14. #endif
  15. #else /* !CONFIG_NUMA */
  16. #define get_memcfg_numa get_memcfg_numa_flat
  17. #define get_zholes_size(n) (0)
  18. #endif /* CONFIG_NUMA */
  19. extern struct pglist_data *node_data[];
  20. #define NODE_DATA(nid) (node_data[nid])
  21. /*
  22. * generic node memory support, the following assumptions apply:
  23. *
  24. * 1) memory comes in 256Mb contigious chunks which are either present or not
  25. * 2) we will not have more than 64Gb in total
  26. *
  27. * for now assume that 64Gb is max amount of RAM for whole system
  28. * 64Gb / 4096bytes/page = 16777216 pages
  29. */
  30. #define MAX_NR_PAGES 16777216
  31. #define MAX_ELEMENTS 256
  32. #define PAGES_PER_ELEMENT (MAX_NR_PAGES/MAX_ELEMENTS)
  33. extern s8 physnode_map[];
  34. static inline int pfn_to_nid(unsigned long pfn)
  35. {
  36. #ifdef CONFIG_NUMA
  37. return((int) physnode_map[(pfn) / PAGES_PER_ELEMENT]);
  38. #else
  39. return 0;
  40. #endif
  41. }
  42. /*
  43. * Following are macros that are specific to this numa platform.
  44. */
  45. #define reserve_bootmem(addr, size) \
  46. reserve_bootmem_node(NODE_DATA(0), (addr), (size))
  47. #define alloc_bootmem(x) \
  48. __alloc_bootmem_node(NODE_DATA(0), (x), SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
  49. #define alloc_bootmem_low(x) \
  50. __alloc_bootmem_node(NODE_DATA(0), (x), SMP_CACHE_BYTES, 0)
  51. #define alloc_bootmem_pages(x) \
  52. __alloc_bootmem_node(NODE_DATA(0), (x), PAGE_SIZE, __pa(MAX_DMA_ADDRESS))
  53. #define alloc_bootmem_low_pages(x) \
  54. __alloc_bootmem_node(NODE_DATA(0), (x), PAGE_SIZE, 0)
  55. #define alloc_bootmem_node(ignore, x) \
  56. __alloc_bootmem_node(NODE_DATA(0), (x), SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
  57. #define alloc_bootmem_pages_node(ignore, x) \
  58. __alloc_bootmem_node(NODE_DATA(0), (x), PAGE_SIZE, __pa(MAX_DMA_ADDRESS))
  59. #define alloc_bootmem_low_pages_node(ignore, x) \
  60. __alloc_bootmem_node(NODE_DATA(0), (x), PAGE_SIZE, 0)
  61. #define node_localnr(pfn, nid) ((pfn) - node_data[nid]->node_start_pfn)
  62. /*
  63. * Following are macros that each numa implmentation must define.
  64. */
  65. /*
  66. * Given a kernel address, find the home node of the underlying memory.
  67. */
  68. #define kvaddr_to_nid(kaddr) pfn_to_nid(__pa(kaddr) >> PAGE_SHIFT)
  69. #define node_mem_map(nid) (NODE_DATA(nid)->node_mem_map)
  70. #define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)
  71. #define node_end_pfn(nid) \
  72. ({ \
  73. pg_data_t *__pgdat = NODE_DATA(nid); \
  74. __pgdat->node_start_pfn + __pgdat->node_spanned_pages; \
  75. })
  76. #define local_mapnr(kvaddr) \
  77. ({ \
  78. unsigned long __pfn = __pa(kvaddr) >> PAGE_SHIFT; \
  79. (__pfn - node_start_pfn(pfn_to_nid(__pfn))); \
  80. })
  81. /* XXX: FIXME -- wli */
  82. #define kern_addr_valid(kaddr) (0)
  83. #define pfn_to_page(pfn) \
  84. ({ \
  85. unsigned long __pfn = pfn; \
  86. int __node = pfn_to_nid(__pfn); \
  87. &node_mem_map(__node)[node_localnr(__pfn,__node)]; \
  88. })
  89. #define page_to_pfn(pg) \
  90. ({ \
  91. struct page *__page = pg; \
  92. struct zone *__zone = page_zone(__page); \
  93. (unsigned long)(__page - __zone->zone_mem_map) \
  94. + __zone->zone_start_pfn; \
  95. })
  96. #ifdef CONFIG_X86_NUMAQ /* we have contiguous memory on NUMA-Q */
  97. #define pfn_valid(pfn) ((pfn) < num_physpages)
  98. #else
  99. static inline int pfn_valid(int pfn)
  100. {
  101. int nid = pfn_to_nid(pfn);
  102. if (nid >= 0)
  103. return (pfn < node_end_pfn(nid));
  104. return 0;
  105. }
  106. #endif
  107. extern int get_memcfg_numa_flat(void );
  108. /*
  109. * This allows any one NUMA architecture to be compiled
  110. * for, and still fall back to the flat function if it
  111. * fails.
  112. */
  113. static inline void get_memcfg_numa(void)
  114. {
  115. #ifdef CONFIG_X86_NUMAQ
  116. if (get_memcfg_numaq())
  117. return;
  118. #elif CONFIG_ACPI_SRAT
  119. if (get_memcfg_from_srat())
  120. return;
  121. #endif
  122. get_memcfg_numa_flat();
  123. }
  124. #endif /* CONFIG_DISCONTIGMEM */
  125. #endif /* _ASM_MMZONE_H_ */