1b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_PAGE_64_H 2b8b572e1SStephen Rothwell #define _ASM_POWERPC_PAGE_64_H 3b8b572e1SStephen Rothwell 4b8b572e1SStephen Rothwell /* 5b8b572e1SStephen Rothwell * Copyright (C) 2001 PPC64 Team, IBM Corp 6b8b572e1SStephen Rothwell * 7b8b572e1SStephen Rothwell * This program is free software; you can redistribute it and/or 8b8b572e1SStephen Rothwell * modify it under the terms of the GNU General Public License 9b8b572e1SStephen Rothwell * as published by the Free Software Foundation; either version 10b8b572e1SStephen Rothwell * 2 of the License, or (at your option) any later version. 11b8b572e1SStephen Rothwell */ 12b8b572e1SStephen Rothwell 13b8b572e1SStephen Rothwell /* 14b8b572e1SStephen Rothwell * We always define HW_PAGE_SHIFT to 12 as use of 64K pages remains Linux 15b8b572e1SStephen Rothwell * specific, every notion of page number shared with the firmware, TCEs, 16b8b572e1SStephen Rothwell * iommu, etc... still uses a page size of 4K. 17b8b572e1SStephen Rothwell */ 18b8b572e1SStephen Rothwell #define HW_PAGE_SHIFT 12 19b8b572e1SStephen Rothwell #define HW_PAGE_SIZE (ASM_CONST(1) << HW_PAGE_SHIFT) 20b8b572e1SStephen Rothwell #define HW_PAGE_MASK (~(HW_PAGE_SIZE-1)) 21b8b572e1SStephen Rothwell 22b8b572e1SStephen Rothwell /* 23b8b572e1SStephen Rothwell * PAGE_FACTOR is the number of bits factor between PAGE_SHIFT and 24b8b572e1SStephen Rothwell * HW_PAGE_SHIFT, that is 4K pages. 25b8b572e1SStephen Rothwell */ 26b8b572e1SStephen Rothwell #define PAGE_FACTOR (PAGE_SHIFT - HW_PAGE_SHIFT) 27b8b572e1SStephen Rothwell 28b8b572e1SStephen Rothwell /* Segment size; normal 256M segments */ 29b8b572e1SStephen Rothwell #define SID_SHIFT 28 30b8b572e1SStephen Rothwell #define SID_MASK ASM_CONST(0xfffffffff) 31b8b572e1SStephen Rothwell #define ESID_MASK 0xfffffffff0000000UL 32b8b572e1SStephen Rothwell #define GET_ESID(x) (((x) >> SID_SHIFT) & SID_MASK) 33b8b572e1SStephen Rothwell 34b8b572e1SStephen Rothwell /* 1T segments */ 35b8b572e1SStephen Rothwell #define SID_SHIFT_1T 40 36b8b572e1SStephen Rothwell #define SID_MASK_1T 0xffffffUL 37b8b572e1SStephen Rothwell #define ESID_MASK_1T 0xffffff0000000000UL 38b8b572e1SStephen Rothwell #define GET_ESID_1T(x) (((x) >> SID_SHIFT_1T) & SID_MASK_1T) 39b8b572e1SStephen Rothwell 40b8b572e1SStephen Rothwell #ifndef __ASSEMBLY__ 41b8b572e1SStephen Rothwell #include <asm/cache.h> 42b8b572e1SStephen Rothwell 43b8b572e1SStephen Rothwell typedef unsigned long pte_basic_t; 44b8b572e1SStephen Rothwell 45b8b572e1SStephen Rothwell static __inline__ void clear_page(void *addr) 46b8b572e1SStephen Rothwell { 47b8b572e1SStephen Rothwell unsigned long lines, line_size; 48b8b572e1SStephen Rothwell 49b8b572e1SStephen Rothwell line_size = ppc64_caches.dline_size; 50b8b572e1SStephen Rothwell lines = ppc64_caches.dlines_per_page; 51b8b572e1SStephen Rothwell 52b8b572e1SStephen Rothwell __asm__ __volatile__( 53b8b572e1SStephen Rothwell "mtctr %1 # clear_page\n\ 54b8b572e1SStephen Rothwell 1: dcbz 0,%0\n\ 55b8b572e1SStephen Rothwell add %0,%0,%3\n\ 56b8b572e1SStephen Rothwell bdnz+ 1b" 57b8b572e1SStephen Rothwell : "=r" (addr) 58b8b572e1SStephen Rothwell : "r" (lines), "0" (addr), "r" (line_size) 59b8b572e1SStephen Rothwell : "ctr", "memory"); 60b8b572e1SStephen Rothwell } 61b8b572e1SStephen Rothwell 62b8b572e1SStephen Rothwell extern void copy_4K_page(void *to, void *from); 63b8b572e1SStephen Rothwell 64b8b572e1SStephen Rothwell #ifdef CONFIG_PPC_64K_PAGES 65b8b572e1SStephen Rothwell static inline void copy_page(void *to, void *from) 66b8b572e1SStephen Rothwell { 67b8b572e1SStephen Rothwell unsigned int i; 68b8b572e1SStephen Rothwell for (i=0; i < (1 << (PAGE_SHIFT - 12)); i++) { 69b8b572e1SStephen Rothwell copy_4K_page(to, from); 70b8b572e1SStephen Rothwell to += 4096; 71b8b572e1SStephen Rothwell from += 4096; 72b8b572e1SStephen Rothwell } 73b8b572e1SStephen Rothwell } 74b8b572e1SStephen Rothwell #else /* CONFIG_PPC_64K_PAGES */ 75b8b572e1SStephen Rothwell static inline void copy_page(void *to, void *from) 76b8b572e1SStephen Rothwell { 77b8b572e1SStephen Rothwell copy_4K_page(to, from); 78b8b572e1SStephen Rothwell } 79b8b572e1SStephen Rothwell #endif /* CONFIG_PPC_64K_PAGES */ 80b8b572e1SStephen Rothwell 81b8b572e1SStephen Rothwell /* Log 2 of page table size */ 82b8b572e1SStephen Rothwell extern u64 ppc64_pft_size; 83b8b572e1SStephen Rothwell 84b8b572e1SStephen Rothwell /* Large pages size */ 85b8b572e1SStephen Rothwell #ifdef CONFIG_HUGETLB_PAGE 86b8b572e1SStephen Rothwell extern unsigned int HPAGE_SHIFT; 87b8b572e1SStephen Rothwell #else 88b8b572e1SStephen Rothwell #define HPAGE_SHIFT PAGE_SHIFT 89b8b572e1SStephen Rothwell #endif 90b8b572e1SStephen Rothwell #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT) 91b8b572e1SStephen Rothwell #define HPAGE_MASK (~(HPAGE_SIZE - 1)) 92b8b572e1SStephen Rothwell #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) 93d1837cbaSDavid Gibson #define HUGE_MAX_HSTATE (MMU_PAGE_COUNT-1) 94b8b572e1SStephen Rothwell 95b8b572e1SStephen Rothwell #endif /* __ASSEMBLY__ */ 96b8b572e1SStephen Rothwell 97b8b572e1SStephen Rothwell #ifdef CONFIG_PPC_MM_SLICES 98b8b572e1SStephen Rothwell 99b8b572e1SStephen Rothwell #define SLICE_LOW_SHIFT 28 100b8b572e1SStephen Rothwell #define SLICE_HIGH_SHIFT 40 101b8b572e1SStephen Rothwell 102b8b572e1SStephen Rothwell #define SLICE_LOW_TOP (0x100000000ul) 103b8b572e1SStephen Rothwell #define SLICE_NUM_LOW (SLICE_LOW_TOP >> SLICE_LOW_SHIFT) 104b8b572e1SStephen Rothwell #define SLICE_NUM_HIGH (PGTABLE_RANGE >> SLICE_HIGH_SHIFT) 105b8b572e1SStephen Rothwell 106b8b572e1SStephen Rothwell #define GET_LOW_SLICE_INDEX(addr) ((addr) >> SLICE_LOW_SHIFT) 107b8b572e1SStephen Rothwell #define GET_HIGH_SLICE_INDEX(addr) ((addr) >> SLICE_HIGH_SHIFT) 108b8b572e1SStephen Rothwell 109b8b572e1SStephen Rothwell #ifndef __ASSEMBLY__ 110b8b572e1SStephen Rothwell 111b8b572e1SStephen Rothwell struct slice_mask { 112b8b572e1SStephen Rothwell u16 low_slices; 113b8b572e1SStephen Rothwell u16 high_slices; 114b8b572e1SStephen Rothwell }; 115b8b572e1SStephen Rothwell 116b8b572e1SStephen Rothwell struct mm_struct; 117b8b572e1SStephen Rothwell 118b8b572e1SStephen Rothwell extern unsigned long slice_get_unmapped_area(unsigned long addr, 119b8b572e1SStephen Rothwell unsigned long len, 120b8b572e1SStephen Rothwell unsigned long flags, 121b8b572e1SStephen Rothwell unsigned int psize, 122b8b572e1SStephen Rothwell int topdown, 123b8b572e1SStephen Rothwell int use_cache); 124b8b572e1SStephen Rothwell 125b8b572e1SStephen Rothwell extern unsigned int get_slice_psize(struct mm_struct *mm, 126b8b572e1SStephen Rothwell unsigned long addr); 127b8b572e1SStephen Rothwell 128b8b572e1SStephen Rothwell extern void slice_init_context(struct mm_struct *mm, unsigned int psize); 129b8b572e1SStephen Rothwell extern void slice_set_user_psize(struct mm_struct *mm, unsigned int psize); 130b8b572e1SStephen Rothwell extern void slice_set_range_psize(struct mm_struct *mm, unsigned long start, 131b8b572e1SStephen Rothwell unsigned long len, unsigned int psize); 132b8b572e1SStephen Rothwell 133b8b572e1SStephen Rothwell #define slice_mm_new_context(mm) ((mm)->context.id == 0) 134b8b572e1SStephen Rothwell 135b8b572e1SStephen Rothwell #endif /* __ASSEMBLY__ */ 136b8b572e1SStephen Rothwell #else 137b8b572e1SStephen Rothwell #define slice_init() 13857e2a99fSBenjamin Herrenschmidt #ifdef CONFIG_PPC_STD_MMU_64 139b8b572e1SStephen Rothwell #define get_slice_psize(mm, addr) ((mm)->context.user_psize) 140b8b572e1SStephen Rothwell #define slice_set_user_psize(mm, psize) \ 141b8b572e1SStephen Rothwell do { \ 142b8b572e1SStephen Rothwell (mm)->context.user_psize = (psize); \ 143b8b572e1SStephen Rothwell (mm)->context.sllp = SLB_VSID_USER | mmu_psize_defs[(psize)].sllp; \ 144b8b572e1SStephen Rothwell } while (0) 14557e2a99fSBenjamin Herrenschmidt #else /* CONFIG_PPC_STD_MMU_64 */ 14657e2a99fSBenjamin Herrenschmidt #ifdef CONFIG_PPC_64K_PAGES 14757e2a99fSBenjamin Herrenschmidt #define get_slice_psize(mm, addr) MMU_PAGE_64K 14857e2a99fSBenjamin Herrenschmidt #else /* CONFIG_PPC_64K_PAGES */ 14957e2a99fSBenjamin Herrenschmidt #define get_slice_psize(mm, addr) MMU_PAGE_4K 15057e2a99fSBenjamin Herrenschmidt #endif /* !CONFIG_PPC_64K_PAGES */ 15157e2a99fSBenjamin Herrenschmidt #define slice_set_user_psize(mm, psize) do { BUG(); } while(0) 15257e2a99fSBenjamin Herrenschmidt #endif /* !CONFIG_PPC_STD_MMU_64 */ 15357e2a99fSBenjamin Herrenschmidt 154b8b572e1SStephen Rothwell #define slice_set_range_psize(mm, start, len, psize) \ 155b8b572e1SStephen Rothwell slice_set_user_psize((mm), (psize)) 156b8b572e1SStephen Rothwell #define slice_mm_new_context(mm) 1 157b8b572e1SStephen Rothwell #endif /* CONFIG_PPC_MM_SLICES */ 158b8b572e1SStephen Rothwell 159b8b572e1SStephen Rothwell #ifdef CONFIG_HUGETLB_PAGE 160b8b572e1SStephen Rothwell 161b8b572e1SStephen Rothwell #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA 162b8b572e1SStephen Rothwell 163b8b572e1SStephen Rothwell #endif /* !CONFIG_HUGETLB_PAGE */ 164b8b572e1SStephen Rothwell 165b8b572e1SStephen Rothwell #define VM_DATA_DEFAULT_FLAGS \ 166cab175f9SDenis Kirjanov (is_32bit_task() ? \ 167b8b572e1SStephen Rothwell VM_DATA_DEFAULT_FLAGS32 : VM_DATA_DEFAULT_FLAGS64) 168b8b572e1SStephen Rothwell 169b8b572e1SStephen Rothwell /* 170b8b572e1SStephen Rothwell * This is the default if a program doesn't have a PT_GNU_STACK 171b8b572e1SStephen Rothwell * program header entry. The PPC64 ELF ABI has a non executable stack 172*25985edcSLucas De Marchi * stack by default, so in the absence of a PT_GNU_STACK program header 173b8b572e1SStephen Rothwell * we turn execute permission off. 174b8b572e1SStephen Rothwell */ 175b8b572e1SStephen Rothwell #define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \ 176b8b572e1SStephen Rothwell VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) 177b8b572e1SStephen Rothwell 178b8b572e1SStephen Rothwell #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \ 179b8b572e1SStephen Rothwell VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) 180b8b572e1SStephen Rothwell 181b8b572e1SStephen Rothwell #define VM_STACK_DEFAULT_FLAGS \ 182cab175f9SDenis Kirjanov (is_32bit_task() ? \ 183b8b572e1SStephen Rothwell VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64) 184b8b572e1SStephen Rothwell 1855b17e1cdSArnd Bergmann #include <asm-generic/getorder.h> 186b8b572e1SStephen Rothwell 187b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PAGE_64_H */ 188