mmzone.h 3.9 KB

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