18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * page.h: Various defines and such for MMU operations on the Sparc for 48c2ecf20Sopenharmony_ci * the Linux kernel. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef _SPARC_PAGE_H 108c2ecf20Sopenharmony_ci#define _SPARC_PAGE_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/const.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define PAGE_SHIFT 12 158c2ecf20Sopenharmony_ci#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT) 168c2ecf20Sopenharmony_ci#define PAGE_MASK (~(PAGE_SIZE-1)) 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define clear_page(page) memset((void *)(page), 0, PAGE_SIZE) 218c2ecf20Sopenharmony_ci#define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE) 228c2ecf20Sopenharmony_ci#define clear_user_page(addr, vaddr, page) \ 238c2ecf20Sopenharmony_ci do { clear_page(addr); \ 248c2ecf20Sopenharmony_ci sparc_flush_page_to_ram(page); \ 258c2ecf20Sopenharmony_ci } while (0) 268c2ecf20Sopenharmony_ci#define copy_user_page(to, from, vaddr, page) \ 278c2ecf20Sopenharmony_ci do { copy_page(to, from); \ 288c2ecf20Sopenharmony_ci sparc_flush_page_to_ram(page); \ 298c2ecf20Sopenharmony_ci } while (0) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/* The following structure is used to hold the physical 328c2ecf20Sopenharmony_ci * memory configuration of the machine. This is filled in 338c2ecf20Sopenharmony_ci * prom_meminit() and is later used by mem_init() to set up 348c2ecf20Sopenharmony_ci * mem_map[]. We statically allocate SPARC_PHYS_BANKS+1 of 358c2ecf20Sopenharmony_ci * these structs, this is arbitrary. The entry after the 368c2ecf20Sopenharmony_ci * last valid one has num_bytes==0. 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_cistruct sparc_phys_banks { 398c2ecf20Sopenharmony_ci unsigned long base_addr; 408c2ecf20Sopenharmony_ci unsigned long num_bytes; 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define SPARC_PHYS_BANKS 32 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ciextern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS+1]; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* passing structs on the Sparc slow us down tremendously... */ 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/* #define STRICT_MM_TYPECHECKS */ 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#ifdef STRICT_MM_TYPECHECKS 528c2ecf20Sopenharmony_ci/* 538c2ecf20Sopenharmony_ci * These are used to make use of C type-checking.. 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_citypedef struct { unsigned long pte; } pte_t; 568c2ecf20Sopenharmony_citypedef struct { unsigned long iopte; } iopte_t; 578c2ecf20Sopenharmony_citypedef struct { unsigned long pmd; } pmd_t; 588c2ecf20Sopenharmony_citypedef struct { unsigned long pgd; } pgd_t; 598c2ecf20Sopenharmony_citypedef struct { unsigned long ctxd; } ctxd_t; 608c2ecf20Sopenharmony_citypedef struct { unsigned long pgprot; } pgprot_t; 618c2ecf20Sopenharmony_citypedef struct { unsigned long iopgprot; } iopgprot_t; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#define pte_val(x) ((x).pte) 648c2ecf20Sopenharmony_ci#define iopte_val(x) ((x).iopte) 658c2ecf20Sopenharmony_ci#define pmd_val(x) ((x).pmd) 668c2ecf20Sopenharmony_ci#define pgd_val(x) ((x).pgd) 678c2ecf20Sopenharmony_ci#define ctxd_val(x) ((x).ctxd) 688c2ecf20Sopenharmony_ci#define pgprot_val(x) ((x).pgprot) 698c2ecf20Sopenharmony_ci#define iopgprot_val(x) ((x).iopgprot) 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define __pte(x) ((pte_t) { (x) } ) 728c2ecf20Sopenharmony_ci#define __pmd(x) ((pmd_t) { { (x) }, }) 738c2ecf20Sopenharmony_ci#define __iopte(x) ((iopte_t) { (x) } ) 748c2ecf20Sopenharmony_ci#define __pgd(x) ((pgd_t) { (x) } ) 758c2ecf20Sopenharmony_ci#define __ctxd(x) ((ctxd_t) { (x) } ) 768c2ecf20Sopenharmony_ci#define __pgprot(x) ((pgprot_t) { (x) } ) 778c2ecf20Sopenharmony_ci#define __iopgprot(x) ((iopgprot_t) { (x) } ) 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci#else 808c2ecf20Sopenharmony_ci/* 818c2ecf20Sopenharmony_ci * .. while these make it easier on the compiler 828c2ecf20Sopenharmony_ci */ 838c2ecf20Sopenharmony_citypedef unsigned long pte_t; 848c2ecf20Sopenharmony_citypedef unsigned long iopte_t; 858c2ecf20Sopenharmony_citypedef unsigned long pmd_t; 868c2ecf20Sopenharmony_citypedef unsigned long pgd_t; 878c2ecf20Sopenharmony_citypedef unsigned long ctxd_t; 888c2ecf20Sopenharmony_citypedef unsigned long pgprot_t; 898c2ecf20Sopenharmony_citypedef unsigned long iopgprot_t; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci#define pte_val(x) (x) 928c2ecf20Sopenharmony_ci#define iopte_val(x) (x) 938c2ecf20Sopenharmony_ci#define pmd_val(x) (x) 948c2ecf20Sopenharmony_ci#define pgd_val(x) (x) 958c2ecf20Sopenharmony_ci#define ctxd_val(x) (x) 968c2ecf20Sopenharmony_ci#define pgprot_val(x) (x) 978c2ecf20Sopenharmony_ci#define iopgprot_val(x) (x) 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci#define __pte(x) (x) 1008c2ecf20Sopenharmony_ci#define __pmd(x) (x) 1018c2ecf20Sopenharmony_ci#define __iopte(x) (x) 1028c2ecf20Sopenharmony_ci#define __pgd(x) (x) 1038c2ecf20Sopenharmony_ci#define __ctxd(x) (x) 1048c2ecf20Sopenharmony_ci#define __pgprot(x) (x) 1058c2ecf20Sopenharmony_ci#define __iopgprot(x) (x) 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#endif 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_citypedef pte_t *pgtable_t; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#define TASK_UNMAPPED_BASE 0x50000000 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci#else /* !(__ASSEMBLY__) */ 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci#define __pgprot(x) (x) 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#endif /* !(__ASSEMBLY__) */ 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci#define PAGE_OFFSET 0xf0000000 1208c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 1218c2ecf20Sopenharmony_ciextern unsigned long phys_base; 1228c2ecf20Sopenharmony_ciextern unsigned long pfn_base; 1238c2ecf20Sopenharmony_ci#endif 1248c2ecf20Sopenharmony_ci#define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + phys_base) 1258c2ecf20Sopenharmony_ci#define __va(x) ((void *)((unsigned long) (x) - phys_base + PAGE_OFFSET)) 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci#define virt_to_phys __pa 1288c2ecf20Sopenharmony_ci#define phys_to_virt __va 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci#define ARCH_PFN_OFFSET (pfn_base) 1318c2ecf20Sopenharmony_ci#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#define pfn_valid(pfn) (((pfn) >= (pfn_base)) && (((pfn)-(pfn_base)) < max_mapnr)) 1348c2ecf20Sopenharmony_ci#define virt_addr_valid(kaddr) ((((unsigned long)(kaddr)-PAGE_OFFSET)>>PAGE_SHIFT) < max_mapnr) 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#include <asm-generic/memory_model.h> 1378c2ecf20Sopenharmony_ci#include <asm-generic/getorder.h> 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci#endif /* _SPARC_PAGE_H */ 140