mmzone.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* K8 NUMA support */
  2. /* Copyright 2002,2003 by Andi Kleen, SuSE Labs */
  3. /* 2.5 Version loosely based on the NUMAQ Code by Pat Gaughen. */
  4. #ifndef _ASM_X86_64_MMZONE_H
  5. #define _ASM_X86_64_MMZONE_H 1
  6. #include <linux/config.h>
  7. #ifdef CONFIG_NUMA
  8. #define VIRTUAL_BUG_ON(x)
  9. #include <asm/smp.h>
  10. #define NODEMAPSIZE 0xff
  11. /* Simple perfect hash to map physical addresses to node numbers */
  12. extern int memnode_shift;
  13. extern u8 memnodemap[NODEMAPSIZE];
  14. extern int maxnode;
  15. extern struct pglist_data *node_data[];
  16. static inline __attribute__((pure)) int phys_to_nid(unsigned long addr)
  17. {
  18. int nid;
  19. VIRTUAL_BUG_ON((addr >> memnode_shift) >= NODEMAPSIZE);
  20. nid = memnodemap[addr >> memnode_shift];
  21. VIRTUAL_BUG_ON(nid > maxnode);
  22. return nid;
  23. }
  24. #define NODE_DATA(nid) (node_data[nid])
  25. #define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)
  26. #define node_end_pfn(nid) (NODE_DATA(nid)->node_start_pfn + \
  27. NODE_DATA(nid)->node_spanned_pages)
  28. #ifdef CONFIG_DISCONTIGMEM
  29. #define pfn_to_nid(pfn) phys_to_nid((unsigned long)(pfn) << PAGE_SHIFT)
  30. #define kvaddr_to_nid(kaddr) phys_to_nid(__pa(kaddr))
  31. /* AK: this currently doesn't deal with invalid addresses. We'll see
  32. if the 2.5 kernel doesn't pass them
  33. (2.4 used to). */
  34. #define pfn_to_page(pfn) ({ \
  35. int nid = phys_to_nid(((unsigned long)(pfn)) << PAGE_SHIFT); \
  36. ((pfn) - node_start_pfn(nid)) + NODE_DATA(nid)->node_mem_map; \
  37. })
  38. #define page_to_pfn(page) \
  39. (long)(((page) - page_zone(page)->zone_mem_map) + page_zone(page)->zone_start_pfn)
  40. #define pfn_valid(pfn) ((pfn) >= num_physpages ? 0 : \
  41. ({ u8 nid__ = pfn_to_nid(pfn); \
  42. nid__ != 0xff && (pfn) >= node_start_pfn(nid__) && (pfn) <= node_end_pfn(nid__); }))
  43. #endif
  44. #define local_mapnr(kvaddr) \
  45. ( (__pa(kvaddr) >> PAGE_SHIFT) - node_start_pfn(kvaddr_to_nid(kvaddr)) )
  46. #endif
  47. #endif