memory_model.h 2.1 KB

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