18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * VM ops 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> 68c2ecf20Sopenharmony_ci * Copyright (C) 2008-2009 PetaLogix 78c2ecf20Sopenharmony_ci * Copyright (C) 2006 Atmark Techno, Inc. 88c2ecf20Sopenharmony_ci * Changes for MMU support: 98c2ecf20Sopenharmony_ci * Copyright (C) 2007 Xilinx, Inc. All rights reserved. 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifndef _ASM_MICROBLAZE_PAGE_H 138c2ecf20Sopenharmony_ci#define _ASM_MICROBLAZE_PAGE_H 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/pfn.h> 168c2ecf20Sopenharmony_ci#include <asm/setup.h> 178c2ecf20Sopenharmony_ci#include <asm/asm-compat.h> 188c2ecf20Sopenharmony_ci#include <linux/const.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#ifdef __KERNEL__ 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* PAGE_SHIFT determines the page size */ 238c2ecf20Sopenharmony_ci#if defined(CONFIG_MICROBLAZE_64K_PAGES) 248c2ecf20Sopenharmony_ci#define PAGE_SHIFT 16 258c2ecf20Sopenharmony_ci#elif defined(CONFIG_MICROBLAZE_16K_PAGES) 268c2ecf20Sopenharmony_ci#define PAGE_SHIFT 14 278c2ecf20Sopenharmony_ci#else 288c2ecf20Sopenharmony_ci#define PAGE_SHIFT 12 298c2ecf20Sopenharmony_ci#endif 308c2ecf20Sopenharmony_ci#define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT) 318c2ecf20Sopenharmony_ci#define PAGE_MASK (~(PAGE_SIZE-1)) 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define LOAD_OFFSET ASM_CONST((CONFIG_KERNEL_START-CONFIG_KERNEL_BASE_ADDR)) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define PTE_SHIFT (PAGE_SHIFT - 2) /* 1024 ptes per page */ 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* MS be sure that SLAB allocates aligned objects */ 408c2ecf20Sopenharmony_ci#define ARCH_DMA_MINALIGN L1_CACHE_BYTES 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define ARCH_SLAB_MINALIGN L1_CACHE_BYTES 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1))) 458c2ecf20Sopenharmony_ci#define PAGE_DOWN(addr) ((addr)&(~((PAGE_SIZE)-1))) 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#ifndef CONFIG_MMU 488c2ecf20Sopenharmony_ci/* 498c2ecf20Sopenharmony_ci * PAGE_OFFSET -- the first address of the first page of memory. When not 508c2ecf20Sopenharmony_ci * using MMU this corresponds to the first free page in physical memory (aligned 518c2ecf20Sopenharmony_ci * on a page boundary). 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_ciextern unsigned int __page_offset; 548c2ecf20Sopenharmony_ci#define PAGE_OFFSET __page_offset 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#else /* CONFIG_MMU */ 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* 598c2ecf20Sopenharmony_ci * PAGE_OFFSET -- the first address of the first page of memory. With MMU 608c2ecf20Sopenharmony_ci * it is set to the kernel start address (aligned on a page boundary). 618c2ecf20Sopenharmony_ci * 628c2ecf20Sopenharmony_ci * CONFIG_KERNEL_START is defined in arch/microblaze/config.in and used 638c2ecf20Sopenharmony_ci * in arch/microblaze/Makefile. 648c2ecf20Sopenharmony_ci */ 658c2ecf20Sopenharmony_ci#define PAGE_OFFSET CONFIG_KERNEL_START 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* 688c2ecf20Sopenharmony_ci * The basic type of a PTE - 32 bit physical addressing. 698c2ecf20Sopenharmony_ci */ 708c2ecf20Sopenharmony_citypedef unsigned long pte_basic_t; 718c2ecf20Sopenharmony_ci#define PTE_FMT "%.8lx" 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#endif /* CONFIG_MMU */ 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci# define copy_page(to, from) memcpy((to), (from), PAGE_SIZE) 768c2ecf20Sopenharmony_ci# define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE) 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci# define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE) 798c2ecf20Sopenharmony_ci# define copy_user_page(vto, vfrom, vaddr, topg) \ 808c2ecf20Sopenharmony_ci memcpy((vto), (vfrom), PAGE_SIZE) 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci/* 838c2ecf20Sopenharmony_ci * These are used to make use of C type-checking.. 848c2ecf20Sopenharmony_ci */ 858c2ecf20Sopenharmony_citypedef struct page *pgtable_t; 868c2ecf20Sopenharmony_citypedef struct { unsigned long pte; } pte_t; 878c2ecf20Sopenharmony_citypedef struct { unsigned long pgprot; } pgprot_t; 888c2ecf20Sopenharmony_ci/* FIXME this can depend on linux kernel version */ 898c2ecf20Sopenharmony_ci# ifdef CONFIG_MMU 908c2ecf20Sopenharmony_citypedef struct { unsigned long pgd; } pgd_t; 918c2ecf20Sopenharmony_ci# else /* CONFIG_MMU */ 928c2ecf20Sopenharmony_citypedef struct { unsigned long ste[64]; } pmd_t; 938c2ecf20Sopenharmony_citypedef struct { pmd_t pue[1]; } pud_t; 948c2ecf20Sopenharmony_citypedef struct { pud_t p4e[1]; } p4d_t; 958c2ecf20Sopenharmony_citypedef struct { p4d_t pge[1]; } pgd_t; 968c2ecf20Sopenharmony_ci# endif /* CONFIG_MMU */ 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci# define pte_val(x) ((x).pte) 998c2ecf20Sopenharmony_ci# define pgprot_val(x) ((x).pgprot) 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci# ifdef CONFIG_MMU 1028c2ecf20Sopenharmony_ci# define pgd_val(x) ((x).pgd) 1038c2ecf20Sopenharmony_ci# else /* CONFIG_MMU */ 1048c2ecf20Sopenharmony_ci# define pmd_val(x) ((x).ste[0]) 1058c2ecf20Sopenharmony_ci# define pud_val(x) ((x).pue[0]) 1068c2ecf20Sopenharmony_ci# define pgd_val(x) ((x).pge[0]) 1078c2ecf20Sopenharmony_ci# endif /* CONFIG_MMU */ 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci# define __pte(x) ((pte_t) { (x) }) 1108c2ecf20Sopenharmony_ci# define __pgd(x) ((pgd_t) { (x) }) 1118c2ecf20Sopenharmony_ci# define __pgprot(x) ((pgprot_t) { (x) }) 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/** 1148c2ecf20Sopenharmony_ci * Conversions for virtual address, physical address, pfn, and struct 1158c2ecf20Sopenharmony_ci * page are defined in the following files. 1168c2ecf20Sopenharmony_ci * 1178c2ecf20Sopenharmony_ci * virt -+ 1188c2ecf20Sopenharmony_ci * | asm-microblaze/page.h 1198c2ecf20Sopenharmony_ci * phys -+ 1208c2ecf20Sopenharmony_ci * | linux/pfn.h 1218c2ecf20Sopenharmony_ci * pfn -+ 1228c2ecf20Sopenharmony_ci * | asm-generic/memory_model.h 1238c2ecf20Sopenharmony_ci * page -+ 1248c2ecf20Sopenharmony_ci * 1258c2ecf20Sopenharmony_ci */ 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ciextern unsigned long max_low_pfn; 1288c2ecf20Sopenharmony_ciextern unsigned long min_low_pfn; 1298c2ecf20Sopenharmony_ciextern unsigned long max_pfn; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ciextern unsigned long memory_start; 1328c2ecf20Sopenharmony_ciextern unsigned long memory_size; 1338c2ecf20Sopenharmony_ciextern unsigned long lowmem_size; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ciextern unsigned long kernel_tlb; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ciextern int page_is_ram(unsigned long pfn); 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci# define phys_to_pfn(phys) (PFN_DOWN(phys)) 1408c2ecf20Sopenharmony_ci# define pfn_to_phys(pfn) (PFN_PHYS(pfn)) 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci# define virt_to_pfn(vaddr) (phys_to_pfn((__pa(vaddr)))) 1438c2ecf20Sopenharmony_ci# define pfn_to_virt(pfn) __va(pfn_to_phys((pfn))) 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci# ifdef CONFIG_MMU 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci# define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)) 1488c2ecf20Sopenharmony_ci# define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT) 1498c2ecf20Sopenharmony_ci# define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci# else /* CONFIG_MMU */ 1528c2ecf20Sopenharmony_ci# define virt_to_page(vaddr) (pfn_to_page(virt_to_pfn(vaddr))) 1538c2ecf20Sopenharmony_ci# define page_to_virt(page) (pfn_to_virt(page_to_pfn(page))) 1548c2ecf20Sopenharmony_ci# define page_to_phys(page) (pfn_to_phys(page_to_pfn(page))) 1558c2ecf20Sopenharmony_ci# define page_to_bus(page) (page_to_phys(page)) 1568c2ecf20Sopenharmony_ci# define phys_to_page(paddr) (pfn_to_page(phys_to_pfn(paddr))) 1578c2ecf20Sopenharmony_ci# endif /* CONFIG_MMU */ 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci# ifndef CONFIG_MMU 1608c2ecf20Sopenharmony_ci# define pfn_valid(pfn) (((pfn) >= min_low_pfn) && \ 1618c2ecf20Sopenharmony_ci ((pfn) <= (min_low_pfn + max_mapnr))) 1628c2ecf20Sopenharmony_ci# define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) 1638c2ecf20Sopenharmony_ci# else /* CONFIG_MMU */ 1648c2ecf20Sopenharmony_ci# define ARCH_PFN_OFFSET (memory_start >> PAGE_SHIFT) 1658c2ecf20Sopenharmony_ci# define pfn_valid(pfn) ((pfn) < (max_mapnr + ARCH_PFN_OFFSET)) 1668c2ecf20Sopenharmony_ci# endif /* CONFIG_MMU */ 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci# endif /* __ASSEMBLY__ */ 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci#define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr))) 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci# define __pa(x) __virt_to_phys((unsigned long)(x)) 1738c2ecf20Sopenharmony_ci# define __va(x) ((void *)__phys_to_virt((unsigned long)(x))) 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci/* Convert between virtual and physical address for MMU. */ 1768c2ecf20Sopenharmony_ci/* Handle MicroBlaze processor with virtual memory. */ 1778c2ecf20Sopenharmony_ci#ifndef CONFIG_MMU 1788c2ecf20Sopenharmony_ci#define __virt_to_phys(addr) addr 1798c2ecf20Sopenharmony_ci#define __phys_to_virt(addr) addr 1808c2ecf20Sopenharmony_ci#define tophys(rd, rs) addik rd, rs, 0 1818c2ecf20Sopenharmony_ci#define tovirt(rd, rs) addik rd, rs, 0 1828c2ecf20Sopenharmony_ci#else 1838c2ecf20Sopenharmony_ci#define __virt_to_phys(addr) \ 1848c2ecf20Sopenharmony_ci ((addr) + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START) 1858c2ecf20Sopenharmony_ci#define __phys_to_virt(addr) \ 1868c2ecf20Sopenharmony_ci ((addr) + CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR) 1878c2ecf20Sopenharmony_ci#define tophys(rd, rs) \ 1888c2ecf20Sopenharmony_ci addik rd, rs, (CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START) 1898c2ecf20Sopenharmony_ci#define tovirt(rd, rs) \ 1908c2ecf20Sopenharmony_ci addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR) 1918c2ecf20Sopenharmony_ci#endif /* CONFIG_MMU */ 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci#define TOPHYS(addr) __virt_to_phys(addr) 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci#ifdef CONFIG_MMU 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci#endif /* CONFIG_MMU */ 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */ 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci#include <asm-generic/memory_model.h> 2028c2ecf20Sopenharmony_ci#include <asm-generic/getorder.h> 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci#endif /* _ASM_MICROBLAZE_PAGE_H */ 205