mmzone.h 3.9 KB

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