1 /* SPDX-License-Identifier: GPL-2.0 */
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.
12 #ifndef _ASM_MICROBLAZE_PAGE_H
13 #define _ASM_MICROBLAZE_PAGE_H
15 #include <linux/pfn.h>
16 #include <asm/setup.h>
17 #include <asm/asm-compat.h>
18 #include <linux/const.h>
22 /* PAGE_SHIFT determines the page size */
24 #define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT)
25 #define PAGE_MASK (~(PAGE_SIZE-1))
27 #define LOAD_OFFSET ASM_CONST((CONFIG_KERNEL_START-CONFIG_KERNEL_BASE_ADDR))
29 #define PTE_SHIFT (PAGE_SHIFT - 2) /* 1024 ptes per page */
33 /* MS be sure that SLAB allocates aligned objects */
34 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
36 #define ARCH_SLAB_MINALIGN L1_CACHE_BYTES
38 #define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1)))
39 #define PAGE_DOWN(addr) ((addr)&(~((PAGE_SIZE)-1)))
42 * PAGE_OFFSET -- the first address of the first page of memory. With MMU
43 * it is set to the kernel start address (aligned on a page boundary).
45 * CONFIG_KERNEL_START is defined in arch/microblaze/config.in and used
46 * in arch/microblaze/Makefile.
48 #define PAGE_OFFSET CONFIG_KERNEL_START
51 * The basic type of a PTE - 32 bit physical addressing.
53 typedef unsigned long pte_basic_t;
54 #define PTE_FMT "%.8lx"
56 # define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)
57 # define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE)
59 # define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE)
60 # define copy_user_page(vto, vfrom, vaddr, topg) \
61 memcpy((vto), (vfrom), PAGE_SIZE)
64 * These are used to make use of C type-checking..
66 typedef struct page *pgtable_t;
67 typedef struct { unsigned long pte; } pte_t;
68 typedef struct { unsigned long pgprot; } pgprot_t;
69 /* FIXME this can depend on linux kernel version */
70 typedef struct { unsigned long pgd; } pgd_t;
72 # define pte_val(x) ((x).pte)
73 # define pgprot_val(x) ((x).pgprot)
75 # define pgd_val(x) ((x).pgd)
77 # define __pte(x) ((pte_t) { (x) })
78 # define __pgd(x) ((pgd_t) { (x) })
79 # define __pgprot(x) ((pgprot_t) { (x) })
82 * Conversions for virtual address, physical address, pfn, and struct
83 * page are defined in the following files.
86 * | asm-microblaze/page.h
90 * | asm-generic/memory_model.h
95 extern unsigned long max_low_pfn;
96 extern unsigned long min_low_pfn;
97 extern unsigned long max_pfn;
99 extern unsigned long memory_start;
100 extern unsigned long memory_size;
101 extern unsigned long lowmem_size;
103 extern unsigned long kernel_tlb;
105 extern int page_is_ram(unsigned long pfn);
107 # define phys_to_pfn(phys) (PFN_DOWN(phys))
108 # define pfn_to_phys(pfn) (PFN_PHYS(pfn))
110 # define virt_to_pfn(vaddr) (phys_to_pfn((__pa(vaddr))))
111 # define pfn_to_virt(pfn) __va(pfn_to_phys((pfn)))
113 # define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
114 # define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT)
115 # define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
117 # define ARCH_PFN_OFFSET (memory_start >> PAGE_SHIFT)
118 # define pfn_valid(pfn) ((pfn) < (max_mapnr + ARCH_PFN_OFFSET))
120 # endif /* __ASSEMBLY__ */
122 #define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr)))
124 # define __pa(x) __virt_to_phys((unsigned long)(x))
125 # define __va(x) ((void *)__phys_to_virt((unsigned long)(x)))
127 /* Convert between virtual and physical address for MMU. */
128 /* Handle MicroBlaze processor with virtual memory. */
129 #define __virt_to_phys(addr) \
130 ((addr) + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
131 #define __phys_to_virt(addr) \
132 ((addr) + CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
133 #define tophys(rd, rs) \
134 addik rd, rs, (CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
135 #define tovirt(rd, rs) \
136 addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
138 #define TOPHYS(addr) __virt_to_phys(addr)
140 #endif /* __KERNEL__ */
142 #include <asm-generic/memory_model.h>
143 #include <asm-generic/getorder.h>
145 #endif /* _ASM_MICROBLAZE_PAGE_H */