xref: /openbmc/linux/arch/microblaze/include/asm/page.h (revision d79f3b06)
14b87d7a4SMichal Simek /*
21f84e1eaSMichal Simek  * VM ops
31f84e1eaSMichal Simek  *
41f84e1eaSMichal Simek  * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
51f84e1eaSMichal Simek  * Copyright (C) 2008-2009 PetaLogix
64b87d7a4SMichal Simek  * Copyright (C) 2006 Atmark Techno, Inc.
74b87d7a4SMichal Simek  * Changes for MMU support:
84b87d7a4SMichal Simek  *    Copyright (C) 2007 Xilinx, Inc.  All rights reserved.
94b87d7a4SMichal Simek  *
104b87d7a4SMichal Simek  * This file is subject to the terms and conditions of the GNU General Public
114b87d7a4SMichal Simek  * License. See the file "COPYING" in the main directory of this archive
124b87d7a4SMichal Simek  * for more details.
134b87d7a4SMichal Simek  */
144b87d7a4SMichal Simek 
154b87d7a4SMichal Simek #ifndef _ASM_MICROBLAZE_PAGE_H
164b87d7a4SMichal Simek #define _ASM_MICROBLAZE_PAGE_H
174b87d7a4SMichal Simek 
184b87d7a4SMichal Simek #include <linux/pfn.h>
194b87d7a4SMichal Simek #include <asm/setup.h>
20a1253977SJohn Williams #include <asm/asm-compat.h>
211f84e1eaSMichal Simek #include <linux/const.h>
221f84e1eaSMichal Simek 
231f84e1eaSMichal Simek #ifdef __KERNEL__
244b87d7a4SMichal Simek 
254b87d7a4SMichal Simek /* PAGE_SHIFT determines the page size */
264b87d7a4SMichal Simek #define PAGE_SHIFT	(12)
271f84e1eaSMichal Simek #define PAGE_SIZE	(_AC(1, UL) << PAGE_SHIFT)
284b87d7a4SMichal Simek #define PAGE_MASK	(~(PAGE_SIZE-1))
294b87d7a4SMichal Simek 
30a1253977SJohn Williams #define LOAD_OFFSET	ASM_CONST((CONFIG_KERNEL_START-CONFIG_KERNEL_BASE_ADDR))
31a1253977SJohn Williams 
324b87d7a4SMichal Simek #ifndef __ASSEMBLY__
334b87d7a4SMichal Simek 
344b87d7a4SMichal Simek #define PAGE_UP(addr)	(((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1)))
354b87d7a4SMichal Simek #define PAGE_DOWN(addr)	((addr)&(~((PAGE_SIZE)-1)))
364b87d7a4SMichal Simek 
374b87d7a4SMichal Simek /* align addr on a size boundary - adjust address up/down if needed */
384b87d7a4SMichal Simek #define _ALIGN_UP(addr, size)	(((addr)+((size)-1))&(~((size)-1)))
394b87d7a4SMichal Simek #define _ALIGN_DOWN(addr, size)	((addr)&(~((size)-1)))
404b87d7a4SMichal Simek 
414b87d7a4SMichal Simek /* align addr on a size boundary - adjust address up if needed */
424b87d7a4SMichal Simek #define _ALIGN(addr, size)	_ALIGN_UP(addr, size)
434b87d7a4SMichal Simek 
441f84e1eaSMichal Simek #ifndef CONFIG_MMU
454b87d7a4SMichal Simek /*
464b87d7a4SMichal Simek  * PAGE_OFFSET -- the first address of the first page of memory. When not
474b87d7a4SMichal Simek  * using MMU this corresponds to the first free page in physical memory (aligned
484b87d7a4SMichal Simek  * on a page boundary).
494b87d7a4SMichal Simek  */
504b87d7a4SMichal Simek extern unsigned int __page_offset;
514b87d7a4SMichal Simek #define PAGE_OFFSET __page_offset
524b87d7a4SMichal Simek 
531f84e1eaSMichal Simek #else /* CONFIG_MMU */
541f84e1eaSMichal Simek 
551f84e1eaSMichal Simek /*
561f84e1eaSMichal Simek  * PAGE_OFFSET -- the first address of the first page of memory. With MMU
571f84e1eaSMichal Simek  * it is set to the kernel start address (aligned on a page boundary).
581f84e1eaSMichal Simek  *
591f84e1eaSMichal Simek  * CONFIG_KERNEL_START is defined in arch/microblaze/config.in and used
601f84e1eaSMichal Simek  * in arch/microblaze/Makefile.
611f84e1eaSMichal Simek  */
621f84e1eaSMichal Simek #define PAGE_OFFSET	CONFIG_KERNEL_START
631f84e1eaSMichal Simek 
641f84e1eaSMichal Simek /*
651f84e1eaSMichal Simek  * The basic type of a PTE - 32 bit physical addressing.
661f84e1eaSMichal Simek  */
671f84e1eaSMichal Simek typedef unsigned long pte_basic_t;
681f84e1eaSMichal Simek #define PTE_SHIFT	(PAGE_SHIFT - 2)	/* 1024 ptes per page */
691f84e1eaSMichal Simek #define PTE_FMT		"%.8lx"
701f84e1eaSMichal Simek 
711f84e1eaSMichal Simek #endif /* CONFIG_MMU */
721f84e1eaSMichal Simek 
731f84e1eaSMichal Simek #  ifndef CONFIG_MMU
744b87d7a4SMichal Simek #  define copy_page(to, from)			memcpy((to), (from), PAGE_SIZE)
754b87d7a4SMichal Simek #  define get_user_page(vaddr)			__get_free_page(GFP_KERNEL)
764b87d7a4SMichal Simek #  define free_user_page(page, addr)		free_page(addr)
771f84e1eaSMichal Simek #  else /* CONFIG_MMU */
781f84e1eaSMichal Simek extern void copy_page(void *to, void *from);
791f84e1eaSMichal Simek #  endif /* CONFIG_MMU */
804b87d7a4SMichal Simek 
814b87d7a4SMichal Simek # define clear_page(pgaddr)			memset((pgaddr), 0, PAGE_SIZE)
824b87d7a4SMichal Simek 
834b87d7a4SMichal Simek # define clear_user_page(pgaddr, vaddr, page)	memset((pgaddr), 0, PAGE_SIZE)
844b87d7a4SMichal Simek # define copy_user_page(vto, vfrom, vaddr, topg) \
854b87d7a4SMichal Simek 			memcpy((vto), (vfrom), PAGE_SIZE)
864b87d7a4SMichal Simek 
874b87d7a4SMichal Simek /*
884b87d7a4SMichal Simek  * These are used to make use of C type-checking..
894b87d7a4SMichal Simek  */
904b87d7a4SMichal Simek typedef struct page *pgtable_t;
914b87d7a4SMichal Simek typedef struct { unsigned long	pte; }		pte_t;
924b87d7a4SMichal Simek typedef struct { unsigned long	pgprot; }	pgprot_t;
931f84e1eaSMichal Simek /* FIXME this can depend on linux kernel version */
941f84e1eaSMichal Simek #   ifdef CONFIG_MMU
951f84e1eaSMichal Simek typedef struct { unsigned long pmd; } pmd_t;
961f84e1eaSMichal Simek typedef struct { unsigned long pgd; } pgd_t;
971f84e1eaSMichal Simek #   else /* CONFIG_MMU */
984b87d7a4SMichal Simek typedef struct { unsigned long	ste[64]; }	pmd_t;
994b87d7a4SMichal Simek typedef struct { pmd_t		pue[1]; }	pud_t;
1004b87d7a4SMichal Simek typedef struct { pud_t		pge[1]; }	pgd_t;
1011f84e1eaSMichal Simek #   endif /* CONFIG_MMU */
1024b87d7a4SMichal Simek 
1034b87d7a4SMichal Simek # define pte_val(x)	((x).pte)
1044b87d7a4SMichal Simek # define pgprot_val(x)	((x).pgprot)
1051f84e1eaSMichal Simek 
1061f84e1eaSMichal Simek #   ifdef CONFIG_MMU
1071f84e1eaSMichal Simek #   define pmd_val(x)      ((x).pmd)
1081f84e1eaSMichal Simek #   define pgd_val(x)      ((x).pgd)
1091f84e1eaSMichal Simek #   else  /* CONFIG_MMU */
1104b87d7a4SMichal Simek #   define pmd_val(x)	((x).ste[0])
1114b87d7a4SMichal Simek #   define pud_val(x)	((x).pue[0])
1124b87d7a4SMichal Simek #   define pgd_val(x)	((x).pge[0])
1131f84e1eaSMichal Simek #   endif  /* CONFIG_MMU */
1144b87d7a4SMichal Simek 
1154b87d7a4SMichal Simek # define __pte(x)	((pte_t) { (x) })
1164b87d7a4SMichal Simek # define __pmd(x)	((pmd_t) { (x) })
1174b87d7a4SMichal Simek # define __pgd(x)	((pgd_t) { (x) })
1184b87d7a4SMichal Simek # define __pgprot(x)	((pgprot_t) { (x) })
1194b87d7a4SMichal Simek 
1204b87d7a4SMichal Simek /**
1214b87d7a4SMichal Simek  * Conversions for virtual address, physical address, pfn, and struct
1224b87d7a4SMichal Simek  * page are defined in the following files.
1234b87d7a4SMichal Simek  *
1244b87d7a4SMichal Simek  * virt -+
1254b87d7a4SMichal Simek  *	 | asm-microblaze/page.h
1264b87d7a4SMichal Simek  * phys -+
1274b87d7a4SMichal Simek  *	 | linux/pfn.h
1284b87d7a4SMichal Simek  *  pfn -+
1294b87d7a4SMichal Simek  *	 | asm-generic/memory_model.h
1304b87d7a4SMichal Simek  * page -+
1314b87d7a4SMichal Simek  *
1324b87d7a4SMichal Simek  */
1334b87d7a4SMichal Simek 
1344b87d7a4SMichal Simek extern unsigned long max_low_pfn;
1354b87d7a4SMichal Simek extern unsigned long min_low_pfn;
1364b87d7a4SMichal Simek extern unsigned long max_pfn;
1374b87d7a4SMichal Simek 
1381f84e1eaSMichal Simek extern unsigned long memory_start;
1391f84e1eaSMichal Simek extern unsigned long memory_end;
1401f84e1eaSMichal Simek extern unsigned long memory_size;
1411f84e1eaSMichal Simek 
1421f84e1eaSMichal Simek extern int page_is_ram(unsigned long pfn);
1434b87d7a4SMichal Simek 
1444b87d7a4SMichal Simek # define phys_to_pfn(phys)	(PFN_DOWN(phys))
1454b87d7a4SMichal Simek # define pfn_to_phys(pfn)	(PFN_PHYS(pfn))
1464b87d7a4SMichal Simek 
1474b87d7a4SMichal Simek # define virt_to_pfn(vaddr)	(phys_to_pfn((__pa(vaddr))))
1484b87d7a4SMichal Simek # define pfn_to_virt(pfn)	__va(pfn_to_phys((pfn)))
1494b87d7a4SMichal Simek 
1501f84e1eaSMichal Simek #  ifdef CONFIG_MMU
151d79f3b06SMichal Simek 
152d79f3b06SMichal Simek #  define virt_to_page(kaddr)	(pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
153d79f3b06SMichal Simek #  define page_to_virt(page)   __va(page_to_pfn(page) << PAGE_SHIFT)
154d79f3b06SMichal Simek #  define page_to_phys(page)     (page_to_pfn(page) << PAGE_SHIFT)
155d79f3b06SMichal Simek 
1561f84e1eaSMichal Simek #  else /* CONFIG_MMU */
1574b87d7a4SMichal Simek #  define virt_to_page(vaddr)	(pfn_to_page(virt_to_pfn(vaddr)))
1584b87d7a4SMichal Simek #  define page_to_virt(page)	(pfn_to_virt(page_to_pfn(page)))
1594b87d7a4SMichal Simek #  define page_to_phys(page)	(pfn_to_phys(page_to_pfn(page)))
1604b87d7a4SMichal Simek #  define page_to_bus(page)	(page_to_phys(page))
1614b87d7a4SMichal Simek #  define phys_to_page(paddr)	(pfn_to_page(phys_to_pfn(paddr)))
1621f84e1eaSMichal Simek #  endif /* CONFIG_MMU */
1634b87d7a4SMichal Simek 
1641f84e1eaSMichal Simek #  ifndef CONFIG_MMU
1655dd48a23Ssteve@digidescorp.com #  define pfn_valid(pfn)	(((pfn) >= min_low_pfn) && \
1665dd48a23Ssteve@digidescorp.com 				((pfn) <= (min_low_pfn + max_mapnr)))
1674b87d7a4SMichal Simek #  define ARCH_PFN_OFFSET	(PAGE_OFFSET >> PAGE_SHIFT)
1681f84e1eaSMichal Simek #  else /* CONFIG_MMU */
1691f84e1eaSMichal Simek #  define ARCH_PFN_OFFSET	(memory_start >> PAGE_SHIFT)
1701f84e1eaSMichal Simek #  define pfn_valid(pfn)	((pfn) < (max_mapnr + ARCH_PFN_OFFSET))
1711f84e1eaSMichal Simek #  define VALID_PAGE(page) 	((page - mem_map) < max_mapnr)
1721f84e1eaSMichal Simek #  endif /* CONFIG_MMU */
1734b87d7a4SMichal Simek 
1744b87d7a4SMichal Simek # endif /* __ASSEMBLY__ */
1754b87d7a4SMichal Simek 
1764b87d7a4SMichal Simek #define	virt_addr_valid(vaddr)	(pfn_valid(virt_to_pfn(vaddr)))
1774b87d7a4SMichal Simek 
1781f84e1eaSMichal Simek 
1791f84e1eaSMichal Simek #  ifndef CONFIG_MMU
1801f84e1eaSMichal Simek #  define __pa(vaddr)	((unsigned long) (vaddr))
1811f84e1eaSMichal Simek #  define __va(paddr)	((void *) (paddr))
1821f84e1eaSMichal Simek #  else /* CONFIG_MMU */
1831f84e1eaSMichal Simek #  define __pa(x)	__virt_to_phys((unsigned long)(x))
1841f84e1eaSMichal Simek #  define __va(x)	((void *)__phys_to_virt((unsigned long)(x)))
1851f84e1eaSMichal Simek #  endif /* CONFIG_MMU */
1861f84e1eaSMichal Simek 
1871f84e1eaSMichal Simek 
1884b87d7a4SMichal Simek /* Convert between virtual and physical address for MMU. */
1894b87d7a4SMichal Simek /* Handle MicroBlaze processor with virtual memory. */
1901f84e1eaSMichal Simek #ifndef CONFIG_MMU
1914b87d7a4SMichal Simek #define __virt_to_phys(addr)	addr
1924b87d7a4SMichal Simek #define __phys_to_virt(addr)	addr
1931f84e1eaSMichal Simek #define tophys(rd, rs)	addik rd, rs, 0
1941f84e1eaSMichal Simek #define tovirt(rd, rs)	addik rd, rs, 0
1951f84e1eaSMichal Simek #else
1961f84e1eaSMichal Simek #define __virt_to_phys(addr) \
1971f84e1eaSMichal Simek 	((addr) + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
1981f84e1eaSMichal Simek #define __phys_to_virt(addr) \
1991f84e1eaSMichal Simek 	((addr) + CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
2001f84e1eaSMichal Simek #define tophys(rd, rs) \
2011f84e1eaSMichal Simek 	addik rd, rs, (CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
2021f84e1eaSMichal Simek #define tovirt(rd, rs) \
2031f84e1eaSMichal Simek 	addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
2041f84e1eaSMichal Simek #endif /* CONFIG_MMU */
2054b87d7a4SMichal Simek 
2064b87d7a4SMichal Simek #define TOPHYS(addr)  __virt_to_phys(addr)
2074b87d7a4SMichal Simek 
2081f84e1eaSMichal Simek #ifdef CONFIG_MMU
2091f84e1eaSMichal Simek #ifdef CONFIG_CONTIGUOUS_PAGE_ALLOC
2101f84e1eaSMichal Simek #define WANT_PAGE_VIRTUAL 1 /* page alloc 2 relies on this */
2111f84e1eaSMichal Simek #endif
2121f84e1eaSMichal Simek 
2131f84e1eaSMichal Simek #define VM_DATA_DEFAULT_FLAGS	(VM_READ | VM_WRITE | VM_EXEC | \
2141f84e1eaSMichal Simek 				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2151f84e1eaSMichal Simek #endif /* CONFIG_MMU */
2161f84e1eaSMichal Simek 
2174b87d7a4SMichal Simek #endif /* __KERNEL__ */
2184b87d7a4SMichal Simek 
2194b87d7a4SMichal Simek #include <asm-generic/memory_model.h>
2205b17e1cdSArnd Bergmann #include <asm-generic/getorder.h>
2214b87d7a4SMichal Simek 
2224b87d7a4SMichal Simek #endif /* _ASM_MICROBLAZE_PAGE_H */
223