xref: /openbmc/linux/arch/microblaze/include/asm/page.h (revision 927a8e38)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * VM ops
4  *
5  * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
6  * Copyright (C) 2008-2009 PetaLogix
7  * Copyright (C) 2006 Atmark Techno, Inc.
8  * Changes for MMU support:
9  *    Copyright (C) 2007 Xilinx, Inc.  All rights reserved.
10  */
11 
12 #ifndef _ASM_MICROBLAZE_PAGE_H
13 #define _ASM_MICROBLAZE_PAGE_H
14 
15 #include <linux/pfn.h>
16 #include <asm/setup.h>
17 #include <asm/asm-compat.h>
18 #include <linux/const.h>
19 
20 #ifdef __KERNEL__
21 
22 /* PAGE_SHIFT determines the page size */
23 #define PAGE_SHIFT		12
24 #define PAGE_SIZE	(ASM_CONST(1) << PAGE_SHIFT)
25 #define PAGE_MASK	(~(PAGE_SIZE-1))
26 
27 #define LOAD_OFFSET	ASM_CONST((CONFIG_KERNEL_START-CONFIG_KERNEL_BASE_ADDR))
28 
29 #define PTE_SHIFT	(PAGE_SHIFT - 2)	/* 1024 ptes per page */
30 
31 #ifndef __ASSEMBLY__
32 
33 /*
34  * PAGE_OFFSET -- the first address of the first page of memory. With MMU
35  * it is set to the kernel start address (aligned on a page boundary).
36  *
37  * CONFIG_KERNEL_START is defined in arch/microblaze/config.in and used
38  * in arch/microblaze/Makefile.
39  */
40 #define PAGE_OFFSET	CONFIG_KERNEL_START
41 
42 /*
43  * The basic type of a PTE - 32 bit physical addressing.
44  */
45 typedef unsigned long pte_basic_t;
46 #define PTE_FMT		"%.8lx"
47 
48 # define copy_page(to, from)			memcpy((to), (from), PAGE_SIZE)
49 # define clear_page(pgaddr)			memset((pgaddr), 0, PAGE_SIZE)
50 
51 # define clear_user_page(pgaddr, vaddr, page)	memset((pgaddr), 0, PAGE_SIZE)
52 # define copy_user_page(vto, vfrom, vaddr, topg) \
53 			memcpy((vto), (vfrom), PAGE_SIZE)
54 
55 /*
56  * These are used to make use of C type-checking..
57  */
58 typedef struct page *pgtable_t;
59 typedef struct { unsigned long	pte; }		pte_t;
60 typedef struct { unsigned long	pgprot; }	pgprot_t;
61 /* FIXME this can depend on linux kernel version */
62 typedef struct { unsigned long pgd; } pgd_t;
63 
64 # define pte_val(x)	((x).pte)
65 # define pgprot_val(x)	((x).pgprot)
66 
67 #   define pgd_val(x)      ((x).pgd)
68 
69 # define __pte(x)	((pte_t) { (x) })
70 # define __pgd(x)	((pgd_t) { (x) })
71 # define __pgprot(x)	((pgprot_t) { (x) })
72 
73 /**
74  * Conversions for virtual address, physical address, pfn, and struct
75  * page are defined in the following files.
76  *
77  * virt -+
78  *	 | asm-microblaze/page.h
79  * phys -+
80  *	 | linux/pfn.h
81  *  pfn -+
82  *	 | asm-generic/memory_model.h
83  * page -+
84  *
85  */
86 
87 extern unsigned long max_low_pfn;
88 extern unsigned long min_low_pfn;
89 extern unsigned long max_pfn;
90 
91 extern unsigned long memory_start;
92 extern unsigned long memory_size;
93 extern unsigned long lowmem_size;
94 
95 extern unsigned long kernel_tlb;
96 
97 extern int page_is_ram(unsigned long pfn);
98 
99 # define phys_to_pfn(phys)	(PFN_DOWN(phys))
100 # define pfn_to_phys(pfn)	(PFN_PHYS(pfn))
101 
102 # define virt_to_pfn(vaddr)	(phys_to_pfn((__pa(vaddr))))
103 # define pfn_to_virt(pfn)	__va(pfn_to_phys((pfn)))
104 
105 #  define virt_to_page(kaddr)	(pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
106 #  define page_to_virt(page)   __va(page_to_pfn(page) << PAGE_SHIFT)
107 #  define page_to_phys(page)     (page_to_pfn(page) << PAGE_SHIFT)
108 
109 #  define ARCH_PFN_OFFSET	(memory_start >> PAGE_SHIFT)
110 # endif /* __ASSEMBLY__ */
111 
112 #define	virt_addr_valid(vaddr)	(pfn_valid(virt_to_pfn(vaddr)))
113 
114 # define __pa(x)	__virt_to_phys((unsigned long)(x))
115 # define __va(x)	((void *)__phys_to_virt((unsigned long)(x)))
116 
117 /* Convert between virtual and physical address for MMU. */
118 /* Handle MicroBlaze processor with virtual memory. */
119 #define __virt_to_phys(addr) \
120 	((addr) + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
121 #define __phys_to_virt(addr) \
122 	((addr) + CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
123 #define tophys(rd, rs) \
124 	addik rd, rs, (CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
125 #define tovirt(rd, rs) \
126 	addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
127 
128 #define TOPHYS(addr)  __virt_to_phys(addr)
129 
130 #endif /* __KERNEL__ */
131 
132 #include <asm-generic/memory_model.h>
133 #include <asm-generic/getorder.h>
134 
135 #endif /* _ASM_MICROBLAZE_PAGE_H */
136