xref: /linux/arch/microblaze/include/asm/page.h (revision 762f99f4f3cb41a775b5157dd761217beba65873)
14726dd60SMichal Simek /* SPDX-License-Identifier: GPL-2.0 */
24b87d7a4SMichal Simek /*
31f84e1eaSMichal Simek  * VM ops
41f84e1eaSMichal Simek  *
51f84e1eaSMichal Simek  * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
61f84e1eaSMichal Simek  * Copyright (C) 2008-2009 PetaLogix
74b87d7a4SMichal Simek  * Copyright (C) 2006 Atmark Techno, Inc.
84b87d7a4SMichal Simek  * Changes for MMU support:
94b87d7a4SMichal Simek  *    Copyright (C) 2007 Xilinx, Inc.  All rights reserved.
104b87d7a4SMichal Simek  */
114b87d7a4SMichal Simek 
124b87d7a4SMichal Simek #ifndef _ASM_MICROBLAZE_PAGE_H
134b87d7a4SMichal Simek #define _ASM_MICROBLAZE_PAGE_H
144b87d7a4SMichal Simek 
154b87d7a4SMichal Simek #include <linux/pfn.h>
164b87d7a4SMichal Simek #include <asm/setup.h>
17a1253977SJohn Williams #include <asm/asm-compat.h>
181f84e1eaSMichal Simek #include <linux/const.h>
191f84e1eaSMichal Simek 
201f84e1eaSMichal Simek #ifdef __KERNEL__
214b87d7a4SMichal Simek 
224b87d7a4SMichal Simek /* PAGE_SHIFT determines the page size */
23ba9c4f88SSteven J. Magnani #define PAGE_SHIFT		12
24ba9c4f88SSteven J. Magnani #define PAGE_SIZE	(ASM_CONST(1) << PAGE_SHIFT)
254b87d7a4SMichal Simek #define PAGE_MASK	(~(PAGE_SIZE-1))
264b87d7a4SMichal Simek 
27a1253977SJohn Williams #define LOAD_OFFSET	ASM_CONST((CONFIG_KERNEL_START-CONFIG_KERNEL_BASE_ADDR))
28a1253977SJohn Williams 
299f78d3b5SMichal Simek #define PTE_SHIFT	(PAGE_SHIFT - 2)	/* 1024 ptes per page */
309f78d3b5SMichal Simek 
314b87d7a4SMichal Simek #ifndef __ASSEMBLY__
324b87d7a4SMichal Simek 
33de925d9dSMichal Simek /* MS be sure that SLAB allocates aligned objects */
34a6eb9fe1SFUJITA Tomonori #define ARCH_DMA_MINALIGN	L1_CACHE_BYTES
35de925d9dSMichal Simek 
36ffe57d02SMichal Simek #define ARCH_SLAB_MINALIGN	L1_CACHE_BYTES
37ffe57d02SMichal Simek 
381f84e1eaSMichal Simek /*
391f84e1eaSMichal Simek  * PAGE_OFFSET -- the first address of the first page of memory. With MMU
401f84e1eaSMichal Simek  * it is set to the kernel start address (aligned on a page boundary).
411f84e1eaSMichal Simek  *
421f84e1eaSMichal Simek  * CONFIG_KERNEL_START is defined in arch/microblaze/config.in and used
431f84e1eaSMichal Simek  * in arch/microblaze/Makefile.
441f84e1eaSMichal Simek  */
451f84e1eaSMichal Simek #define PAGE_OFFSET	CONFIG_KERNEL_START
461f84e1eaSMichal Simek 
471f84e1eaSMichal Simek /*
481f84e1eaSMichal Simek  * The basic type of a PTE - 32 bit physical addressing.
491f84e1eaSMichal Simek  */
501f84e1eaSMichal Simek typedef unsigned long pte_basic_t;
511f84e1eaSMichal Simek #define PTE_FMT		"%.8lx"
521f84e1eaSMichal Simek 
5343f2a6e8SMichal Simek # define copy_page(to, from)			memcpy((to), (from), PAGE_SIZE)
544b87d7a4SMichal Simek # define clear_page(pgaddr)			memset((pgaddr), 0, PAGE_SIZE)
554b87d7a4SMichal Simek 
564b87d7a4SMichal Simek # define clear_user_page(pgaddr, vaddr, page)	memset((pgaddr), 0, PAGE_SIZE)
574b87d7a4SMichal Simek # define copy_user_page(vto, vfrom, vaddr, topg) \
584b87d7a4SMichal Simek 			memcpy((vto), (vfrom), PAGE_SIZE)
594b87d7a4SMichal Simek 
604b87d7a4SMichal Simek /*
614b87d7a4SMichal Simek  * These are used to make use of C type-checking..
624b87d7a4SMichal Simek  */
634b87d7a4SMichal Simek typedef struct page *pgtable_t;
644b87d7a4SMichal Simek typedef struct { unsigned long	pte; }		pte_t;
654b87d7a4SMichal Simek typedef struct { unsigned long	pgprot; }	pgprot_t;
661f84e1eaSMichal Simek /* FIXME this can depend on linux kernel version */
671f84e1eaSMichal Simek typedef struct { unsigned long pgd; } pgd_t;
684b87d7a4SMichal Simek 
694b87d7a4SMichal Simek # define pte_val(x)	((x).pte)
704b87d7a4SMichal Simek # define pgprot_val(x)	((x).pgprot)
711f84e1eaSMichal Simek 
721f84e1eaSMichal Simek #   define pgd_val(x)      ((x).pgd)
734b87d7a4SMichal Simek 
744b87d7a4SMichal Simek # define __pte(x)	((pte_t) { (x) })
754b87d7a4SMichal Simek # define __pgd(x)	((pgd_t) { (x) })
764b87d7a4SMichal Simek # define __pgprot(x)	((pgprot_t) { (x) })
774b87d7a4SMichal Simek 
784b87d7a4SMichal Simek /**
794b87d7a4SMichal Simek  * Conversions for virtual address, physical address, pfn, and struct
804b87d7a4SMichal Simek  * page are defined in the following files.
814b87d7a4SMichal Simek  *
824b87d7a4SMichal Simek  * virt -+
834b87d7a4SMichal Simek  *	 | asm-microblaze/page.h
844b87d7a4SMichal Simek  * phys -+
854b87d7a4SMichal Simek  *	 | linux/pfn.h
864b87d7a4SMichal Simek  *  pfn -+
874b87d7a4SMichal Simek  *	 | asm-generic/memory_model.h
884b87d7a4SMichal Simek  * page -+
894b87d7a4SMichal Simek  *
904b87d7a4SMichal Simek  */
914b87d7a4SMichal Simek 
924b87d7a4SMichal Simek extern unsigned long max_low_pfn;
934b87d7a4SMichal Simek extern unsigned long min_low_pfn;
944b87d7a4SMichal Simek extern unsigned long max_pfn;
954b87d7a4SMichal Simek 
961f84e1eaSMichal Simek extern unsigned long memory_start;
971f84e1eaSMichal Simek extern unsigned long memory_size;
987c0d2615SMichal Simek extern unsigned long lowmem_size;
991f84e1eaSMichal Simek 
1000195c002SLinus Torvalds extern unsigned long kernel_tlb;
1011f84e1eaSMichal Simek 
1021f84e1eaSMichal Simek extern int page_is_ram(unsigned long pfn);
1034b87d7a4SMichal Simek 
1044b87d7a4SMichal Simek # define phys_to_pfn(phys)	(PFN_DOWN(phys))
1054b87d7a4SMichal Simek # define pfn_to_phys(pfn)	(PFN_PHYS(pfn))
1064b87d7a4SMichal Simek 
1074b87d7a4SMichal Simek # define virt_to_pfn(vaddr)	(phys_to_pfn((__pa(vaddr))))
1084b87d7a4SMichal Simek # define pfn_to_virt(pfn)	__va(pfn_to_phys((pfn)))
1094b87d7a4SMichal Simek 
110d79f3b06SMichal Simek #  define virt_to_page(kaddr)	(pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
111d79f3b06SMichal Simek #  define page_to_virt(page)   __va(page_to_pfn(page) << PAGE_SHIFT)
112d79f3b06SMichal Simek #  define page_to_phys(page)     (page_to_pfn(page) << PAGE_SHIFT)
113d79f3b06SMichal Simek 
1141f84e1eaSMichal Simek #  define ARCH_PFN_OFFSET	(memory_start >> PAGE_SHIFT)
115c3ab6bafSMike Rapoport #  define pfn_valid(pfn)	((pfn) >= ARCH_PFN_OFFSET && (pfn) < (max_mapnr + ARCH_PFN_OFFSET))
1164b87d7a4SMichal Simek # endif /* __ASSEMBLY__ */
1174b87d7a4SMichal Simek 
1184b87d7a4SMichal Simek #define	virt_addr_valid(vaddr)	(pfn_valid(virt_to_pfn(vaddr)))
1194b87d7a4SMichal Simek 
1201f84e1eaSMichal Simek # define __pa(x)	__virt_to_phys((unsigned long)(x))
1211f84e1eaSMichal Simek # define __va(x)	((void *)__phys_to_virt((unsigned long)(x)))
1221f84e1eaSMichal Simek 
1234b87d7a4SMichal Simek /* Convert between virtual and physical address for MMU. */
1244b87d7a4SMichal Simek /* Handle MicroBlaze processor with virtual memory. */
1251f84e1eaSMichal Simek #define __virt_to_phys(addr) \
1261f84e1eaSMichal Simek 	((addr) + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
1271f84e1eaSMichal Simek #define __phys_to_virt(addr) \
1281f84e1eaSMichal Simek 	((addr) + CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
1291f84e1eaSMichal Simek #define tophys(rd, rs) \
1301f84e1eaSMichal Simek 	addik rd, rs, (CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
1311f84e1eaSMichal Simek #define tovirt(rd, rs) \
1321f84e1eaSMichal Simek 	addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
1334b87d7a4SMichal Simek 
1344b87d7a4SMichal Simek #define TOPHYS(addr)  __virt_to_phys(addr)
1354b87d7a4SMichal Simek 
1364b87d7a4SMichal Simek #endif /* __KERNEL__ */
1374b87d7a4SMichal Simek 
1384b87d7a4SMichal Simek #include <asm-generic/memory_model.h>
1395b17e1cdSArnd Bergmann #include <asm-generic/getorder.h>
1404b87d7a4SMichal Simek 
1414b87d7a4SMichal Simek #endif /* _ASM_MICROBLAZE_PAGE_H */
142