diff options
Diffstat (limited to 'arch/powerpc/include/asm/page.h')
| -rw-r--r-- | arch/powerpc/include/asm/page.h | 156 | 
1 files changed, 147 insertions, 9 deletions
diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h index 53b64be40eb..32e4e212b9c 100644 --- a/arch/powerpc/include/asm/page.h +++ b/arch/powerpc/include/asm/page.h @@ -36,6 +36,18 @@  #define PAGE_SIZE		(ASM_CONST(1) << PAGE_SHIFT) +#ifndef __ASSEMBLY__ +#ifdef CONFIG_HUGETLB_PAGE +extern unsigned int HPAGE_SHIFT; +#else +#define HPAGE_SHIFT PAGE_SHIFT +#endif +#define HPAGE_SIZE		((1UL) << HPAGE_SHIFT) +#define HPAGE_MASK		(~(HPAGE_SIZE - 1)) +#define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT - PAGE_SHIFT) +#define HUGE_MAX_HSTATE		(MMU_PAGE_COUNT-1) +#endif +  /* We do define AT_SYSINFO_EHDR but don't use the gate mechanism */  #define __HAVE_ARCH_GATE_AREA		1 @@ -66,7 +78,7 @@   *   * Also, KERNELBASE >= PAGE_OFFSET and PHYSICAL_START >= MEMORY_START   * - * There are two was to determine a physical address from a virtual one: + * There are two ways to determine a physical address from a virtual one:   * va = pa + PAGE_OFFSET - MEMORY_START   * va = pa + KERNELBASE - PHYSICAL_START   * @@ -80,28 +92,42 @@  #define PAGE_OFFSET	ASM_CONST(CONFIG_PAGE_OFFSET)  #define LOAD_OFFSET	ASM_CONST((CONFIG_KERNEL_START-CONFIG_PHYSICAL_START)) -#if defined(CONFIG_RELOCATABLE) +#if defined(CONFIG_NONSTATIC_KERNEL)  #ifndef __ASSEMBLY__  extern phys_addr_t memstart_addr;  extern phys_addr_t kernstart_addr; + +#ifdef CONFIG_RELOCATABLE_PPC32 +extern long long virt_phys_offset;  #endif + +#endif /* __ASSEMBLY__ */  #define PHYSICAL_START	kernstart_addr -#else + +#else	/* !CONFIG_NONSTATIC_KERNEL */  #define PHYSICAL_START	ASM_CONST(CONFIG_PHYSICAL_START)  #endif +/* See Description below for VIRT_PHYS_OFFSET */ +#ifdef CONFIG_RELOCATABLE_PPC32 +#define VIRT_PHYS_OFFSET virt_phys_offset +#else +#define VIRT_PHYS_OFFSET (KERNELBASE - PHYSICAL_START) +#endif + +  #ifdef CONFIG_PPC64  #define MEMORY_START	0UL -#elif defined(CONFIG_RELOCATABLE) +#elif defined(CONFIG_NONSTATIC_KERNEL)  #define MEMORY_START	memstart_addr  #else  #define MEMORY_START	(PHYSICAL_START + PAGE_OFFSET - KERNELBASE)  #endif  #ifdef CONFIG_FLATMEM -#define ARCH_PFN_OFFSET		(MEMORY_START >> PAGE_SHIFT) -#define pfn_valid(pfn)		((pfn) >= ARCH_PFN_OFFSET && (pfn) < (ARCH_PFN_OFFSET + max_mapnr)) +#define ARCH_PFN_OFFSET		((unsigned long)(MEMORY_START >> PAGE_SHIFT)) +#define pfn_valid(pfn)		((pfn) >= ARCH_PFN_OFFSET && (pfn) < max_mapnr)  #endif  #define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) @@ -113,16 +139,91 @@ extern phys_addr_t kernstart_addr;   * determine MEMORY_START until then.  However we can determine PHYSICAL_START   * from information at hand (program counter, TLB lookup).   * + * On BookE with RELOCATABLE (RELOCATABLE_PPC32) + * + *   With RELOCATABLE_PPC32,  we support loading the kernel at any physical  + *   address without any restriction on the page alignment. + * + *   We find the runtime address of _stext and relocate ourselves based on  + *   the following calculation: + * + *  	  virtual_base = ALIGN_DOWN(KERNELBASE,256M) + + *  				MODULO(_stext.run,256M) + *   and create the following mapping: + * + * 	  ALIGN_DOWN(_stext.run,256M) => ALIGN_DOWN(KERNELBASE,256M) + * + *   When we process relocations, we cannot depend on the + *   existing equation for the __va()/__pa() translations: + * + * 	   __va(x) = (x)  - PHYSICAL_START + KERNELBASE + * + *   Where: + *   	 PHYSICAL_START = kernstart_addr = Physical address of _stext + *  	 KERNELBASE = Compiled virtual address of _stext. + * + *   This formula holds true iff, kernel load address is TLB page aligned. + * + *   In our case, we need to also account for the shift in the kernel Virtual  + *   address. + * + *   E.g., + * + *   Let the kernel be loaded at 64MB and KERNELBASE be 0xc0000000 (same as PAGE_OFFSET). + *   In this case, we would be mapping 0 to 0xc0000000, and kernstart_addr = 64M + * + *   Now __va(1MB) = (0x100000) - (0x4000000) + 0xc0000000 + *                 = 0xbc100000 , which is wrong. + * + *   Rather, it should be : 0xc0000000 + 0x100000 = 0xc0100000 + *      	according to our mapping. + * + *   Hence we use the following formula to get the translations right: + * + * 	  __va(x) = (x) - [ PHYSICAL_START - Effective KERNELBASE ] + * + * 	  Where : + * 		PHYSICAL_START = dynamic load address.(kernstart_addr variable) + * 		Effective KERNELBASE = virtual_base = + * 				     = ALIGN_DOWN(KERNELBASE,256M) + + * 						MODULO(PHYSICAL_START,256M) + * + * 	To make the cost of __va() / __pa() more light weight, we introduce + * 	a new variable virt_phys_offset, which will hold : + * + * 	virt_phys_offset = Effective KERNELBASE - PHYSICAL_START + * 			 = ALIGN_DOWN(KERNELBASE,256M) -  + * 			 	ALIGN_DOWN(PHYSICALSTART,256M) + * + * 	Hence : + * + * 	__va(x) = x - PHYSICAL_START + Effective KERNELBASE + * 		= x + virt_phys_offset + * + * 		and + * 	__pa(x) = x + PHYSICAL_START - Effective KERNELBASE + * 		= x - virt_phys_offset + * 		   * On non-Book-E PPC64 PAGE_OFFSET and MEMORY_START are constants so use   * the other definitions for __va & __pa.   */  #ifdef CONFIG_BOOKE -#define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) - PHYSICAL_START + KERNELBASE)) -#define __pa(x) ((unsigned long)(x) + PHYSICAL_START - KERNELBASE) +#define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + VIRT_PHYS_OFFSET)) +#define __pa(x) ((unsigned long)(x) - VIRT_PHYS_OFFSET)  #else +#ifdef CONFIG_PPC64 +/* + * gcc miscompiles (unsigned long)(&static_var) - PAGE_OFFSET + * with -mcmodel=medium, so we use & and | instead of - and + on 64-bit. + */ +#define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) | PAGE_OFFSET)) +#define __pa(x) ((unsigned long)(x) & 0x0fffffffffffffffUL) + +#else /* 32-bit, non book E */  #define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + PAGE_OFFSET - MEMORY_START))  #define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + MEMORY_START)  #endif +#endif  /*   * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI, @@ -158,6 +259,26 @@ extern phys_addr_t kernstart_addr;  #define is_kernel_addr(x)	((x) >= PAGE_OFFSET)  #endif +#ifndef CONFIG_PPC_BOOK3S_64 +/* + * Use the top bit of the higher-level page table entries to indicate whether + * the entries we point to contain hugepages.  This works because we know that + * the page tables live in kernel space.  If we ever decide to support having + * page tables at arbitrary addresses, this breaks and will have to change. + */ +#ifdef CONFIG_PPC64 +#define PD_HUGE 0x8000000000000000 +#else +#define PD_HUGE 0x80000000 +#endif +#endif /* CONFIG_PPC_BOOK3S_64 */ + +/* + * Some number of bits at the level of the page table that points to + * a hugepte are used to encode the size.  This masks those bits. + */ +#define HUGEPD_SHIFT_MASK     0x3f +  #ifndef __ASSEMBLY__  #undef STRICT_MM_TYPECHECKS @@ -243,17 +364,29 @@ typedef unsigned long pgprot_t;  #endif  typedef struct { signed long pd; } hugepd_t; -#define HUGEPD_SHIFT_MASK     0x3f  #ifdef CONFIG_HUGETLB_PAGE +#ifdef CONFIG_PPC_BOOK3S_64 +static inline int hugepd_ok(hugepd_t hpd) +{ +	/* +	 * hugepd pointer, bottom two bits == 00 and next 4 bits +	 * indicate size of table +	 */ +	return (((hpd.pd & 0x3) == 0x0) && ((hpd.pd & HUGEPD_SHIFT_MASK) != 0)); +} +#else  static inline int hugepd_ok(hugepd_t hpd)  {  	return (hpd.pd > 0);  } +#endif  #define is_hugepd(pdep)               (hugepd_ok(*((hugepd_t *)(pdep)))) +int pgd_huge(pgd_t pgd);  #else /* CONFIG_HUGETLB_PAGE */  #define is_hugepd(pdep)			0 +#define pgd_huge(pgd)			0  #endif /* CONFIG_HUGETLB_PAGE */  struct page; @@ -261,6 +394,7 @@ extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg);  extern void copy_user_page(void *to, void *from, unsigned long vaddr,  		struct page *p);  extern int page_is_ram(unsigned long pfn); +extern int devmem_is_allowed(unsigned long pfn);  #ifdef CONFIG_PPC_SMLPAR  void arch_free_page(struct page *page, int order); @@ -269,7 +403,11 @@ void arch_free_page(struct page *page, int order);  struct vm_area_struct; +#if defined(CONFIG_PPC_64K_PAGES) && defined(CONFIG_PPC64) +typedef pte_t *pgtable_t; +#else  typedef struct page *pgtable_t; +#endif  #include <asm-generic/memory_model.h>  #endif /* __ASSEMBLY__ */  | 
