memory_model.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef __ASM_MEMORY_MODEL_H
  2. #define __ASM_MEMORY_MODEL_H
  3. #ifndef __ASSEMBLY__
  4. #if defined(CONFIG_FLATMEM)
  5. #ifndef ARCH_PFN_OFFSET
  6. #define ARCH_PFN_OFFSET (0UL)
  7. #endif
  8. #elif defined(CONFIG_DISCONTIGMEM)
  9. #ifndef arch_pfn_to_nid
  10. #define arch_pfn_to_nid(pfn) pfn_to_nid(pfn)
  11. #endif
  12. #ifndef arch_local_page_offset
  13. #define arch_local_page_offset(pfn, nid) \
  14. ((pfn) - NODE_DATA(nid)->node_start_pfn)
  15. #endif
  16. #endif /* CONFIG_DISCONTIGMEM */
  17. /*
  18. * supports 3 memory models.
  19. */
  20. #if defined(CONFIG_FLATMEM)
  21. #define __pfn_to_page(pfn) (mem_map + ((pfn) - ARCH_PFN_OFFSET))
  22. #define __page_to_pfn(page) ((unsigned long)((page) - mem_map) + \
  23. ARCH_PFN_OFFSET)
  24. #elif defined(CONFIG_DISCONTIGMEM)
  25. #define __pfn_to_page(pfn) \
  26. ({ unsigned long __pfn = (pfn); \
  27. unsigned long __nid = arch_pfn_to_nid(__pfn); \
  28. NODE_DATA(__nid)->node_mem_map + arch_local_page_offset(__pfn, __nid);\
  29. })
  30. #define __page_to_pfn(pg) \
  31. ({ struct page *__pg = (pg); \
  32. struct pglist_data *__pgdat = NODE_DATA(page_to_nid(__pg)); \
  33. (unsigned long)(__pg - __pgdat->node_mem_map) + \
  34. __pgdat->node_start_pfn; \
  35. })
  36. #elif defined(CONFIG_SPARSEMEM_VMEMMAP)
  37. /* memmap is virtually contiguous. */
  38. #define __pfn_to_page(pfn) (vmemmap + (pfn))
  39. #define __page_to_pfn(page) (unsigned long)((page) - vmemmap)
  40. #elif defined(CONFIG_SPARSEMEM)
  41. /*
  42. * Note: section's mem_map is encorded to reflect its start_pfn.
  43. * section[i].section_mem_map == mem_map's address - start_pfn;
  44. */
  45. #define __page_to_pfn(pg) \
  46. ({ struct page *__pg = (pg); \
  47. int __sec = page_to_section(__pg); \
  48. (unsigned long)(__pg - __section_mem_map_addr(__nr_to_section(__sec))); \
  49. })
  50. #define __pfn_to_page(pfn) \
  51. ({ unsigned long __pfn = (pfn); \
  52. struct mem_section *__sec = __pfn_to_section(__pfn); \
  53. __section_mem_map_addr(__sec) + __pfn; \
  54. })
  55. #endif /* CONFIG_FLATMEM/DISCONTIGMEM/SPARSEMEM */
  56. #define page_to_pfn __page_to_pfn
  57. #define pfn_to_page __pfn_to_page
  58. #endif /* __ASSEMBLY__ */
  59. #endif