mmzone.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * Written by Kanoj Sarcar (kanoj@sgi.com) Aug 99
  3.  * Adapted for K8/x86-64 Jul 2002 by Andi Kleen.
  4.  */
  5. #ifndef _ASM_MMZONE_H_
  6. #define _ASM_MMZONE_H_
  7. #include <linux/config.h>
  8. typedef struct plat_pglist_data {
  9. pg_data_t gendata;
  10. unsigned long   start_pfn, end_pfn;
  11. } plat_pg_data_t;
  12. struct bootmem_data_t;
  13. /*
  14.  * Following are macros that are specific to this numa platform.
  15.  * 
  16.  * XXX check what the compiler generates for all this
  17.  */
  18. extern plat_pg_data_t *plat_node_data[];
  19. #define MAXNODE 8 
  20. #define MAX_NUMNODES MAXNODE
  21. #define NODEMAPSIZE 0xff
  22. /* Simple perfect hash to map physical addresses to node numbers */
  23. extern int memnode_shift; 
  24. extern u8  memnodemap[NODEMAPSIZE]; 
  25. extern int maxnode;
  26. #if 0
  27. #define VIRTUAL_BUG_ON(x) do { if (x) out_of_line_bug(); } while(0)
  28. #else
  29. #define VIRTUAL_BUG_ON(x) do {} while (0) 
  30. #endif
  31. /* VALID_PAGE below hardcodes the same algorithm*/
  32. static inline int phys_to_nid(unsigned long addr) 
  33. int nid; 
  34. VIRTUAL_BUG_ON((addr >> memnode_shift) >= NODEMAPSIZE);
  35. nid = memnodemap[addr >> memnode_shift]; 
  36. VIRTUAL_BUG_ON(nid > maxnode); 
  37. return nid; 
  38. #define PLAT_NODE_DATA(n) (plat_node_data[(n)])
  39. #define PLAT_NODE_DATA_STARTNR(n)
  40. (PLAT_NODE_DATA(n)->gendata.node_start_mapnr)
  41. #define PLAT_NODE_DATA_SIZE(n) (PLAT_NODE_DATA(n)->gendata.node_size)
  42. #define PLAT_NODE_DATA_LOCALNR(p, n)
  43. (((p) - PLAT_NODE_DATA(n)->gendata.node_start_paddr) >> PAGE_SHIFT)
  44. #ifdef CONFIG_DISCONTIGMEM
  45. /*
  46.  * Following are macros that each numa implmentation must define.
  47.  */
  48. /*
  49.  * Given a kernel address, find the home node of the underlying memory.
  50.  */
  51. #define KVADDR_TO_NID(kaddr) phys_to_nid(__pa(kaddr))
  52. /*
  53.  * Return a pointer to the node data for node n.
  54.  */
  55. #define NODE_DATA(n) (&((PLAT_NODE_DATA(n))->gendata))
  56. /*
  57.  * NODE_MEM_MAP gives the kaddr for the mem_map of the node.
  58.  */
  59. #define NODE_MEM_MAP(nid) (NODE_DATA(nid)->node_mem_map)
  60. /*
  61.  * Given a kaddr, ADDR_TO_MAPBASE finds the owning node of the memory
  62.  * and returns the the mem_map of that node.
  63.  */
  64. #define ADDR_TO_MAPBASE(kaddr) 
  65. NODE_MEM_MAP(KVADDR_TO_NID((unsigned long)(kaddr)))
  66. /*
  67.  * Given a kaddr, LOCAL_BASE_ADDR finds the owning node of the memory
  68.  * and returns the kaddr corresponding to first physical page in the
  69.  * node's mem_map.
  70.  */
  71. #define LOCAL_BASE_ADDR(kaddr) ((unsigned long)__va(NODE_DATA(KVADDR_TO_NID(kaddr))->node_start_paddr))
  72. #define LOCAL_MAP_NR(kvaddr) 
  73. (((unsigned long)(kvaddr)-LOCAL_BASE_ADDR(kvaddr)) >> PAGE_SHIFT)
  74. #define BAD_PAGE 0xffffffffffff
  75. /* this really should be optimized a bit */
  76. static inline unsigned long 
  77. paddr_to_local_pfn(unsigned long phys_addr, struct page **mem_map, int check) 
  78. unsigned long nid;
  79. if (check) { /* we rely on gcc optimizing this way for most cases */ 
  80. unsigned long index = phys_addr >> memnode_shift; 
  81. if (index >= NODEMAPSIZE || memnodemap[index] == 0xff) { 
  82. *mem_map = NULL;
  83. return BAD_PAGE;
  84. nid = memnodemap[index];
  85. } else { 
  86. nid = phys_to_nid(phys_addr); 
  87. }     
  88. plat_pg_data_t *plat_pgdat = plat_node_data[nid]; 
  89. unsigned long pfn = phys_addr >> PAGE_SHIFT; 
  90. VIRTUAL_BUG_ON(pfn >= plat_pgdat->end_pfn);
  91. VIRTUAL_BUG_ON(pfn < plat_pgdat->start_pfn);
  92. *mem_map = plat_pgdat->gendata.node_mem_map; 
  93. return pfn - plat_pgdat->start_pfn;
  94. #define virt_to_page(kaddr) 
  95. ({ struct page *lmemmap; 
  96.    unsigned long lpfn = paddr_to_local_pfn(__pa(kaddr),&lmemmap,0); 
  97.    lmemmap + lpfn;  })
  98. /* needs to handle bad addresses too */
  99. #define pte_page(pte) 
  100. ({ struct page *lmemmap; 
  101.    unsigned long addr = pte_val(pte) & PHYSICAL_PAGE_MASK; 
  102.    unsigned long lpfn = paddr_to_local_pfn(addr,&lmemmap,1); 
  103.    lmemmap + lpfn;  })
  104. #define pfn_to_page(pfn) virt_to_page(__va((unsigned long)(pfn) << PAGE_SHIFT))
  105. #define page_to_pfn(page) ({ 
  106. int nodeid = phys_to_nid(__pa(page));  
  107. plat_pg_data_t *nd = PLAT_NODE_DATA(nodeid); 
  108. (page - nd->gendata.node_mem_map) + nd->start_pfn; 
  109. })
  110. #define VALID_PAGE(page_ptr) ({ 
  111. int ok = 0; 
  112. unsigned long phys = __pa(page_ptr); 
  113.         unsigned long index = phys >> memnode_shift; 
  114. if (index <= NODEMAPSIZE) {    
  115. unsigned nodeid = memnodemap[index];    
  116. pg_data_t *nd = NODE_DATA(nodeid);    
  117. struct page *lmemmap = nd->node_mem_map;   
  118. ok = (nodeid != 0xff) && 
  119.      (page_ptr >= lmemmap && page_ptr < lmemmap + nd->node_size); 
  120. ok; 
  121. })
  122. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  123. extern void setup_node_bootmem(int nodeid, unsigned long start_, unsigned long end_);
  124. #ifdef CONFIG_NUMA
  125. extern int fake_node;
  126. #define cputonode(cpu) (fake_node ? 0 : (cpu))
  127. #define numa_node_id() cputonode(smp_processor_id())
  128. #endif /* CONFIG_NUMA */
  129. #define MAX_NR_NODES 8
  130. #endif /* CONFIG_DISCONTIGMEM */
  131. #endif /* _ASM_MMZONE_H_ */