memory.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2005-2017 Andes Technology Corporation
  3. #ifndef __ASM_NDS32_MEMORY_H
  4. #define __ASM_NDS32_MEMORY_H
  5. #include <linux/compiler.h>
  6. #include <linux/sizes.h>
  7. #ifndef __ASSEMBLY__
  8. #include <asm/page.h>
  9. #endif
  10. #ifndef PHYS_OFFSET
  11. #define PHYS_OFFSET (0x0)
  12. #endif
  13. #ifndef __virt_to_bus
  14. #define __virt_to_bus __virt_to_phys
  15. #endif
  16. #ifndef __bus_to_virt
  17. #define __bus_to_virt __phys_to_virt
  18. #endif
  19. /*
  20. * TASK_SIZE - the maximum size of a user space task.
  21. * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area
  22. */
  23. #define TASK_SIZE ((CONFIG_PAGE_OFFSET) - (SZ_32M))
  24. #define TASK_UNMAPPED_BASE ALIGN(TASK_SIZE / 3, SZ_32M)
  25. #define PAGE_OFFSET (CONFIG_PAGE_OFFSET)
  26. /*
  27. * Physical vs virtual RAM address space conversion. These are
  28. * private definitions which should NOT be used outside memory.h
  29. * files. Use virt_to_phys/phys_to_virt/__pa/__va instead.
  30. */
  31. #ifndef __virt_to_phys
  32. #define __virt_to_phys(x) ((x) - PAGE_OFFSET + PHYS_OFFSET)
  33. #define __phys_to_virt(x) ((x) - PHYS_OFFSET + PAGE_OFFSET)
  34. #endif
  35. /*
  36. * The module space lives between the addresses given by TASK_SIZE
  37. * and PAGE_OFFSET - it must be within 32MB of the kernel text.
  38. */
  39. #define MODULES_END (PAGE_OFFSET)
  40. #define MODULES_VADDR (MODULES_END - SZ_32M)
  41. #if TASK_SIZE > MODULES_VADDR
  42. #error Top of user space clashes with start of module space
  43. #endif
  44. #ifndef __ASSEMBLY__
  45. /*
  46. * PFNs are used to describe any physical page; this means
  47. * PFN 0 == physical address 0.
  48. *
  49. * This is the PFN of the first RAM page in the kernel
  50. * direct-mapped view. We assume this is the first page
  51. * of RAM in the mem_map as well.
  52. */
  53. #define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT)
  54. /*
  55. * Drivers should NOT use these either.
  56. */
  57. #define __pa(x) __virt_to_phys((unsigned long)(x))
  58. #define __va(x) ((void *)__phys_to_virt((unsigned long)(x)))
  59. /*
  60. * Conversion between a struct page and a physical address.
  61. *
  62. * Note: when converting an unknown physical address to a
  63. * struct page, the resulting pointer must be validated
  64. * using VALID_PAGE(). It must return an invalid struct page
  65. * for any physical address not corresponding to a system
  66. * RAM address.
  67. *
  68. * pfn_valid(pfn) indicates whether a PFN number is valid
  69. *
  70. * virt_to_page(k) convert a _valid_ virtual address to struct page *
  71. * virt_addr_valid(k) indicates whether a virtual address is valid
  72. */
  73. #ifndef CONFIG_DISCONTIGMEM
  74. #define ARCH_PFN_OFFSET PHYS_PFN_OFFSET
  75. #define pfn_valid(pfn) ((pfn) >= PHYS_PFN_OFFSET && (pfn) < (PHYS_PFN_OFFSET + max_mapnr))
  76. #define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
  77. #define virt_addr_valid(kaddr) ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)
  78. #else /* CONFIG_DISCONTIGMEM */
  79. #error CONFIG_DISCONTIGMEM is not supported yet.
  80. #endif /* !CONFIG_DISCONTIGMEM */
  81. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  82. #endif
  83. #include <asm-generic/memory_model.h>
  84. #endif