page.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
  3. * Copyright (C) 2004 Microtronix Datacom Ltd.
  4. *
  5. * MMU support based on asm/page.h from mips which is:
  6. *
  7. * Copyright (C) 1994 - 1999, 2000, 03 Ralf Baechle
  8. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file "COPYING" in the main directory of this archive
  12. * for more details.
  13. */
  14. #ifndef _ASM_NIOS2_PAGE_H
  15. #define _ASM_NIOS2_PAGE_H
  16. #include <linux/pfn.h>
  17. #include <linux/const.h>
  18. /*
  19. * PAGE_SHIFT determines the page size
  20. */
  21. #define PAGE_SHIFT 12
  22. #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
  23. #define PAGE_MASK (~(PAGE_SIZE - 1))
  24. /*
  25. * PAGE_OFFSET -- the first address of the first page of memory.
  26. */
  27. #define PAGE_OFFSET \
  28. (CONFIG_NIOS2_MEM_BASE + CONFIG_NIOS2_KERNEL_REGION_BASE)
  29. #ifndef __ASSEMBLY__
  30. /*
  31. * This gives the physical RAM offset.
  32. */
  33. #define PHYS_OFFSET CONFIG_NIOS2_MEM_BASE
  34. /*
  35. * It's normally defined only for FLATMEM config but it's
  36. * used in our early mem init code for all memory models.
  37. * So always define it.
  38. */
  39. #define ARCH_PFN_OFFSET PFN_UP(PHYS_OFFSET)
  40. #define clear_page(page) memset((page), 0, PAGE_SIZE)
  41. #define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)
  42. struct page;
  43. extern void clear_user_page(void *addr, unsigned long vaddr, struct page *page);
  44. extern void copy_user_page(void *vto, void *vfrom, unsigned long vaddr,
  45. struct page *to);
  46. /*
  47. * These are used to make use of C type-checking.
  48. */
  49. typedef struct page *pgtable_t;
  50. typedef struct { unsigned long pte; } pte_t;
  51. typedef struct { unsigned long pgd; } pgd_t;
  52. typedef struct { unsigned long pgprot; } pgprot_t;
  53. #define pte_val(x) ((x).pte)
  54. #define pgd_val(x) ((x).pgd)
  55. #define pgprot_val(x) ((x).pgprot)
  56. #define __pte(x) ((pte_t) { (x) })
  57. #define __pgd(x) ((pgd_t) { (x) })
  58. #define __pgprot(x) ((pgprot_t) { (x) })
  59. extern unsigned long memory_start;
  60. extern unsigned long memory_end;
  61. extern unsigned long memory_size;
  62. extern struct page *mem_map;
  63. #endif /* !__ASSEMBLY__ */
  64. # define __pa(x) \
  65. ((unsigned long)(x) - PAGE_OFFSET + PHYS_OFFSET)
  66. # define __va(x) \
  67. ((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET))
  68. #define page_to_virt(page) \
  69. ((void *)(((page) - mem_map) << PAGE_SHIFT) + PAGE_OFFSET)
  70. # define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
  71. # define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && \
  72. (pfn) < max_mapnr)
  73. # define virt_to_page(vaddr) pfn_to_page(PFN_DOWN(virt_to_phys(vaddr)))
  74. # define virt_addr_valid(vaddr) pfn_valid(PFN_DOWN(virt_to_phys(vaddr)))
  75. # define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
  76. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  77. # define UNCAC_ADDR(addr) \
  78. ((void *)((unsigned)(addr) | CONFIG_NIOS2_IO_REGION_BASE))
  79. # define CAC_ADDR(addr) \
  80. ((void *)(((unsigned)(addr) & ~CONFIG_NIOS2_IO_REGION_BASE) | \
  81. CONFIG_NIOS2_KERNEL_REGION_BASE))
  82. #include <asm-generic/memory_model.h>
  83. #include <asm-generic/getorder.h>
  84. #endif /* _ASM_NIOS2_PAGE_H */