mmzone.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 0xfff
  11. /* Simple perfect hash to map physical addresses to node numbers */
  12. extern int memnode_shift;
  13. extern u8 memnodemap[NODEMAPSIZE];
  14. extern struct pglist_data *node_data[];
  15. static inline __attribute__((pure)) int phys_to_nid(unsigned long addr)
  16. {
  17. unsigned nid;
  18. VIRTUAL_BUG_ON((addr >> memnode_shift) >= NODEMAPSIZE);
  19. nid = memnodemap[addr >> memnode_shift];
  20. VIRTUAL_BUG_ON(nid >= MAX_NUMNODES || !node_data[nid]);
  21. return nid;
  22. }
  23. #define NODE_DATA(nid) (node_data[nid])
  24. #define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)
  25. #define node_end_pfn(nid) (NODE_DATA(nid)->node_start_pfn + \
  26. NODE_DATA(nid)->node_spanned_pages)
  27. #ifdef CONFIG_DISCONTIGMEM
  28. #define pfn_to_nid(pfn) phys_to_nid((unsigned long)(pfn) << PAGE_SHIFT)
  29. #define kvaddr_to_nid(kaddr) phys_to_nid(__pa(kaddr))
  30. /* Requires pfn_valid(pfn) to be true */
  31. #define pfn_to_page(pfn) ({ \
  32. int nid = phys_to_nid(((unsigned long)(pfn)) << PAGE_SHIFT); \
  33. ((pfn) - node_start_pfn(nid)) + NODE_DATA(nid)->node_mem_map; \
  34. })
  35. #define page_to_pfn(page) \
  36. (long)(((page) - page_zone(page)->zone_mem_map) + page_zone(page)->zone_start_pfn)
  37. #define pfn_valid(pfn) ((pfn) >= num_physpages ? 0 : \
  38. ({ u8 nid__ = pfn_to_nid(pfn); \
  39. nid__ != 0xff && (pfn) >= node_start_pfn(nid__) && (pfn) < node_end_pfn(nid__); }))
  40. #endif
  41. #define local_mapnr(kvaddr) \
  42. ( (__pa(kvaddr) >> PAGE_SHIFT) - node_start_pfn(kvaddr_to_nid(kvaddr)) )
  43. #endif
  44. #endif