page.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Page management definitions for the Hexagon architecture
  3. *
  4. * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #ifndef _ASM_PAGE_H
  21. #define _ASM_PAGE_H
  22. #include <linux/const.h>
  23. /* This is probably not the most graceful way to handle this. */
  24. #ifdef CONFIG_PAGE_SIZE_4KB
  25. #define PAGE_SHIFT 12
  26. #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_4KB
  27. #endif
  28. #ifdef CONFIG_PAGE_SIZE_16KB
  29. #define PAGE_SHIFT 14
  30. #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_16KB
  31. #endif
  32. #ifdef CONFIG_PAGE_SIZE_64KB
  33. #define PAGE_SHIFT 16
  34. #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_64KB
  35. #endif
  36. #ifdef CONFIG_PAGE_SIZE_256KB
  37. #define PAGE_SHIFT 18
  38. #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_256KB
  39. #endif
  40. #ifdef CONFIG_PAGE_SIZE_1MB
  41. #define PAGE_SHIFT 20
  42. #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_1MB
  43. #endif
  44. /*
  45. * These should be defined in hugetlb.h, but apparently not.
  46. * "Huge" for us should be 4MB or 16MB, which are both represented
  47. * in L1 PTE's. Right now, it's set up for 4MB.
  48. */
  49. #ifdef CONFIG_HUGETLB_PAGE
  50. #define HPAGE_SHIFT 22
  51. #define HPAGE_SIZE (1UL << HPAGE_SHIFT)
  52. #define HPAGE_MASK (~(HPAGE_SIZE-1))
  53. #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT-PAGE_SHIFT)
  54. #define HVM_HUGEPAGE_SIZE 0x5
  55. #endif
  56. #define PAGE_SIZE (1UL << PAGE_SHIFT)
  57. #define PAGE_MASK (~((1 << PAGE_SHIFT) - 1))
  58. #ifdef __KERNEL__
  59. #ifndef __ASSEMBLY__
  60. /*
  61. * This is for PFN_DOWN, which mm.h needs. Seems the right place to pull it in.
  62. */
  63. #include <linux/pfn.h>
  64. /*
  65. * We implement a two-level architecture-specific page table structure.
  66. * Null intermediate page table level (pmd, pud) definitions will come from
  67. * asm-generic/pagetable-nopmd.h and asm-generic/pagetable-nopud.h
  68. */
  69. typedef struct { unsigned long pte; } pte_t;
  70. typedef struct { unsigned long pgd; } pgd_t;
  71. typedef struct { unsigned long pgprot; } pgprot_t;
  72. typedef struct page *pgtable_t;
  73. #define pte_val(x) ((x).pte)
  74. #define pgd_val(x) ((x).pgd)
  75. #define pgprot_val(x) ((x).pgprot)
  76. #define __pte(x) ((pte_t) { (x) })
  77. #define __pgd(x) ((pgd_t) { (x) })
  78. #define __pgprot(x) ((pgprot_t) { (x) })
  79. /*
  80. * We need a __pa and a __va routine for kernel space.
  81. * MIPS says they're only used during mem_init.
  82. * also, check if we need a PHYS_OFFSET.
  83. */
  84. #define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + PHYS_OFFSET)
  85. #define __va(x) ((void *)((unsigned long)(x) - PHYS_OFFSET + PAGE_OFFSET))
  86. /* The "page frame" descriptor is defined in linux/mm.h */
  87. struct page;
  88. /* Returns page frame descriptor for virtual address. */
  89. #define virt_to_page(kaddr) pfn_to_page(PFN_DOWN(__pa(kaddr)))
  90. /* Default vm area behavior is non-executable. */
  91. #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
  92. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  93. #define pfn_valid(pfn) ((pfn) < max_mapnr)
  94. #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
  95. /* Need to not use a define for linesize; may move this to another file. */
  96. static inline void clear_page(void *page)
  97. {
  98. /* This can only be done on pages with L1 WB cache */
  99. asm volatile(
  100. " loop0(1f,%1);\n"
  101. "1: { dczeroa(%0);\n"
  102. " %0 = add(%0,#32); }:endloop0\n"
  103. : "+r" (page)
  104. : "r" (PAGE_SIZE/32)
  105. : "lc0", "sa0", "memory"
  106. );
  107. }
  108. #define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)
  109. /*
  110. * Under assumption that kernel always "sees" user map...
  111. */
  112. #define clear_user_page(page, vaddr, pg) clear_page(page)
  113. #define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
  114. /*
  115. * page_to_phys - convert page to physical address
  116. * @page - pointer to page entry in mem_map
  117. */
  118. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  119. #define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
  120. #define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)
  121. #define page_to_virt(page) __va(page_to_phys(page))
  122. /*
  123. * For port to Hexagon Virtual Machine, MAYBE we check for attempts
  124. * to reference reserved HVM space, but in any case, the VM will be
  125. * protected.
  126. */
  127. #define kern_addr_valid(addr) (1)
  128. #include <asm/mem-layout.h>
  129. #include <asm-generic/memory_model.h>
  130. /* XXX Todo: implement assembly-optimized version of getorder. */
  131. #include <asm-generic/getorder.h>
  132. #endif /* ifdef __ASSEMBLY__ */
  133. #endif /* ifdef __KERNEL__ */
  134. #endif