mmzone.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Written by Kanoj Sarcar (kanoj@sgi.com) Aug 99
  3. *
  4. * PowerPC64 port:
  5. * Copyright (C) 2002 Anton Blanchard, IBM Corp.
  6. */
  7. #ifndef _ASM_MMZONE_H_
  8. #define _ASM_MMZONE_H_
  9. #include <linux/config.h>
  10. #include <asm/smp.h>
  11. /* generic non-linear memory support:
  12. *
  13. * 1) we will not split memory into more chunks than will fit into the
  14. * flags field of the struct page
  15. */
  16. #ifdef CONFIG_NEED_MULTIPLE_NODES
  17. extern struct pglist_data *node_data[];
  18. /*
  19. * Return a pointer to the node data for node n.
  20. */
  21. #define NODE_DATA(nid) (node_data[nid])
  22. /*
  23. * Following are specific to this numa platform.
  24. */
  25. extern int numa_cpu_lookup_table[];
  26. extern char *numa_memory_lookup_table;
  27. extern cpumask_t numa_cpumask_lookup_table[];
  28. extern int nr_cpus_in_node[];
  29. #ifdef CONFIG_MEMORY_HOTPLUG
  30. extern unsigned long max_pfn;
  31. #endif
  32. /* 16MB regions */
  33. #define MEMORY_INCREMENT_SHIFT 24
  34. #define MEMORY_INCREMENT (1UL << MEMORY_INCREMENT_SHIFT)
  35. /* NUMA debugging, will not work on a DLPAR machine */
  36. #undef DEBUG_NUMA
  37. static inline int pa_to_nid(unsigned long pa)
  38. {
  39. int nid;
  40. #ifdef CONFIG_MEMORY_HOTPLUG
  41. /* kludge hot added sections default to node 0 */
  42. if (pa >= (max_pfn << PAGE_SHIFT))
  43. return 0;
  44. #endif
  45. nid = numa_memory_lookup_table[pa >> MEMORY_INCREMENT_SHIFT];
  46. #ifdef DEBUG_NUMA
  47. /* the physical address passed in is not in the map for the system */
  48. if (nid == -1) {
  49. printk("bad address: %lx\n", pa);
  50. BUG();
  51. }
  52. #endif
  53. return nid;
  54. }
  55. #define node_localnr(pfn, nid) ((pfn) - NODE_DATA(nid)->node_start_pfn)
  56. /*
  57. * Following are macros that each numa implmentation must define.
  58. */
  59. #define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)
  60. #define node_end_pfn(nid) (NODE_DATA(nid)->node_end_pfn)
  61. #ifdef CONFIG_DISCONTIGMEM
  62. /*
  63. * Given a kernel address, find the home node of the underlying memory.
  64. */
  65. #define kvaddr_to_nid(kaddr) pa_to_nid(__pa(kaddr))
  66. #define pfn_to_nid(pfn) pa_to_nid((unsigned long)(pfn) << PAGE_SHIFT)
  67. /* Written this way to avoid evaluating arguments twice */
  68. #define discontigmem_pfn_to_page(pfn) \
  69. ({ \
  70. unsigned long __tmp = pfn; \
  71. (NODE_DATA(pfn_to_nid(__tmp))->node_mem_map + \
  72. node_localnr(__tmp, pfn_to_nid(__tmp))); \
  73. })
  74. #define discontigmem_page_to_pfn(p) \
  75. ({ \
  76. struct page *__tmp = p; \
  77. (((__tmp) - page_zone(__tmp)->zone_mem_map) + \
  78. page_zone(__tmp)->zone_start_pfn); \
  79. })
  80. /* XXX fix for discontiguous physical memory */
  81. #define discontigmem_pfn_valid(pfn) ((pfn) < num_physpages)
  82. #endif /* CONFIG_DISCONTIGMEM */
  83. #endif /* CONFIG_NEED_MULTIPLE_NODES */
  84. #ifdef CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID
  85. #define early_pfn_to_nid(pfn) pa_to_nid(((unsigned long)pfn) << PAGE_SHIFT)
  86. #endif
  87. #endif /* _ASM_MMZONE_H_ */