^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * VM ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2008-2009 PetaLogix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2006 Atmark Techno, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Changes for MMU support:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 2007 Xilinx, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #ifndef _ASM_MICROBLAZE_PAGE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define _ASM_MICROBLAZE_PAGE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/pfn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/asm-compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/const.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #ifdef __KERNEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* PAGE_SHIFT determines the page size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #if defined(CONFIG_MICROBLAZE_64K_PAGES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define PAGE_SHIFT 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #elif defined(CONFIG_MICROBLAZE_16K_PAGES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define PAGE_SHIFT 14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define PAGE_SHIFT 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define PAGE_MASK (~(PAGE_SIZE-1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define LOAD_OFFSET ASM_CONST((CONFIG_KERNEL_START-CONFIG_KERNEL_BASE_ADDR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define PTE_SHIFT (PAGE_SHIFT - 2) /* 1024 ptes per page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #ifndef __ASSEMBLY__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* MS be sure that SLAB allocates aligned objects */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define ARCH_SLAB_MINALIGN L1_CACHE_BYTES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define PAGE_DOWN(addr) ((addr)&(~((PAGE_SIZE)-1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #ifndef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * PAGE_OFFSET -- the first address of the first page of memory. When not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * using MMU this corresponds to the first free page in physical memory (aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * on a page boundary).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) extern unsigned int __page_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define PAGE_OFFSET __page_offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #else /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * PAGE_OFFSET -- the first address of the first page of memory. With MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * it is set to the kernel start address (aligned on a page boundary).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * CONFIG_KERNEL_START is defined in arch/microblaze/config.in and used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * in arch/microblaze/Makefile.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define PAGE_OFFSET CONFIG_KERNEL_START
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * The basic type of a PTE - 32 bit physical addressing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) typedef unsigned long pte_basic_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define PTE_FMT "%.8lx"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #endif /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) # define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) # define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) # define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) # define copy_user_page(vto, vfrom, vaddr, topg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) memcpy((vto), (vfrom), PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * These are used to make use of C type-checking..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) typedef struct page *pgtable_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) typedef struct { unsigned long pte; } pte_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) typedef struct { unsigned long pgprot; } pgprot_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* FIXME this can depend on linux kernel version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) # ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) typedef struct { unsigned long pgd; } pgd_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) # else /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) typedef struct { unsigned long ste[64]; } pmd_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) typedef struct { pmd_t pue[1]; } pud_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) typedef struct { pud_t p4e[1]; } p4d_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) typedef struct { p4d_t pge[1]; } pgd_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) # endif /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) # define pte_val(x) ((x).pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) # define pgprot_val(x) ((x).pgprot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) # ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) # define pgd_val(x) ((x).pgd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) # else /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) # define pmd_val(x) ((x).ste[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) # define pud_val(x) ((x).pue[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) # define pgd_val(x) ((x).pge[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) # endif /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) # define __pte(x) ((pte_t) { (x) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) # define __pgd(x) ((pgd_t) { (x) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) # define __pgprot(x) ((pgprot_t) { (x) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * Conversions for virtual address, physical address, pfn, and struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * page are defined in the following files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * virt -+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * | asm-microblaze/page.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * phys -+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * | linux/pfn.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * pfn -+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * | asm-generic/memory_model.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * page -+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) extern unsigned long max_low_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) extern unsigned long min_low_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) extern unsigned long max_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) extern unsigned long memory_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) extern unsigned long memory_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) extern unsigned long lowmem_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) extern unsigned long kernel_tlb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) extern int page_is_ram(unsigned long pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) # define phys_to_pfn(phys) (PFN_DOWN(phys))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) # define pfn_to_phys(pfn) (PFN_PHYS(pfn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) # define virt_to_pfn(vaddr) (phys_to_pfn((__pa(vaddr))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) # define pfn_to_virt(pfn) __va(pfn_to_phys((pfn)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) # ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) # define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) # define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) # define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) # else /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) # define virt_to_page(vaddr) (pfn_to_page(virt_to_pfn(vaddr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) # define page_to_virt(page) (pfn_to_virt(page_to_pfn(page)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) # define page_to_phys(page) (pfn_to_phys(page_to_pfn(page)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) # define page_to_bus(page) (page_to_phys(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) # define phys_to_page(paddr) (pfn_to_page(phys_to_pfn(paddr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) # endif /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) # ifndef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) # define pfn_valid(pfn) (((pfn) >= min_low_pfn) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ((pfn) <= (min_low_pfn + max_mapnr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) # define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) # else /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) # define ARCH_PFN_OFFSET (memory_start >> PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) # define pfn_valid(pfn) ((pfn) < (max_mapnr + ARCH_PFN_OFFSET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) # endif /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) # endif /* __ASSEMBLY__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) # define __pa(x) __virt_to_phys((unsigned long)(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) # define __va(x) ((void *)__phys_to_virt((unsigned long)(x)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* Convert between virtual and physical address for MMU. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* Handle MicroBlaze processor with virtual memory. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #ifndef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #define __virt_to_phys(addr) addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #define __phys_to_virt(addr) addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #define tophys(rd, rs) addik rd, rs, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) #define tovirt(rd, rs) addik rd, rs, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #define __virt_to_phys(addr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ((addr) + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #define __phys_to_virt(addr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ((addr) + CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #define tophys(rd, rs) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) addik rd, rs, (CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) #define tovirt(rd, rs) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #endif /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #define TOPHYS(addr) __virt_to_phys(addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #endif /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #endif /* __KERNEL__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #include <asm-generic/memory_model.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #include <asm-generic/getorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #endif /* _ASM_MICROBLAZE_PAGE_H */