Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.2
      1 /* $NetBSD: pmap.h,v 1.2 2019/06/01 12:42:28 maxv Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Matt Thomas of 3am Software Foundry.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _RISCV_PMAP_H_
     33 #define _RISCV_PMAP_H_
     34 
     35 #ifdef _KERNEL_OPT
     36 #include "opt_modular.h"
     37 #endif
     38 
     39 #if !defined(_MODULE)
     40 
     41 #include <sys/types.h>
     42 #include <sys/pool.h>
     43 #include <sys/evcnt.h>
     44 
     45 #include <uvm/uvm_physseg.h>
     46 #include <uvm/pmap/vmpagemd.h>
     47 
     48 #include <riscv/pte.h>
     49 
     50 #define	PMAP_SEGTABSIZE		NPTEPG
     51 
     52 #define NBSEG		(NBPG*NPTEPG)
     53 #ifdef _LP64
     54 #define NBXSEG		(NBSEG*NSEGPG)
     55 #define XSEGSHIFT	(SEGSHIFT + PGSHIFT - 3)
     56 #define XSEGOFSET	(PTE_PPN1|SEGOFSET)
     57 #define SEGSHIFT	(PGSHIFT + PGSHIFT - 3)
     58 #else
     59 #define SEGSHIFT	(PGSHIFT + PGSHIFT - 2)
     60 #endif
     61 #define SEGOFSET	(PTE_PPN0|PAGE_MASK)
     62 
     63 #define KERNEL_PID	0
     64 
     65 #define PMAP_HWPAGEWALKER		1
     66 #define PMAP_TLB_NUM_PIDS		256
     67 #define PMAP_TLB_MAX			1
     68 #ifdef _LP64
     69 #define PMAP_INVALID_PDETAB_ADDRESS	((pmap_pdetab_t *)(VM_MIN_KERNEL_ADDRESS - PAGE_SIZE))
     70 #define PMAP_INVALID_SEGTAB_ADDRESS	((pmap_segtab_t *)(VM_MIN_KERNEL_ADDRESS - PAGE_SIZE))
     71 #else
     72 #define PMAP_INVALID_PDETAB_ADDRESS	((pmap_pdetab_t *)0xdeadbeef)
     73 #define PMAP_INVALID_SEGTAB_ADDRESS	((pmap_segtab_t *)0xdeadbeef)
     74 #endif
     75 #define PMAP_TLB_FLUSH_ASID_ON_RESET	false
     76 
     77 #define pmap_phys_address(x)		(x)
     78 
     79 #ifndef __BSD_PTENTRY_T__
     80 #define __BSD_PTENTRY_T__
     81 #ifdef _LP64
     82 #define PRIxPTE         PRIx64
     83 #else
     84 #define PRIxPTE         PRIx32
     85 #endif
     86 #endif /* __BSD_PTENTRY_T__ */
     87 
     88 #define PMAP_NEED_PROCWR
     89 static inline void
     90 pmap_procwr(struct proc *p, vaddr_t va, vsize_t len)
     91 {
     92 	__asm __volatile("fence\trw,rw; fence.i");
     93 }
     94 
     95 
     96 #include <uvm/pmap/tlb.h>
     97 
     98 #include <uvm/pmap/pmap_tlb.h>
     99 
    100 #define PMAP_GROWKERNEL
    101 #define PMAP_STEAL_MEMORY
    102 
    103 #ifdef _KERNEL
    104 
    105 #define __HAVE_PMAP_MD
    106 struct pmap_md {
    107 	paddr_t md_ptbr;
    108 	pd_entry_t *md_pdetab;
    109 };
    110 
    111 struct vm_page *
    112         pmap_md_alloc_poolpage(int flags);
    113 vaddr_t pmap_md_map_poolpage(paddr_t, vsize_t);
    114 void    pmap_md_unmap_poolpage(vaddr_t, vsize_t);
    115 bool    pmap_md_direct_mapped_vaddr_p(vaddr_t);
    116 bool    pmap_md_io_vaddr_p(vaddr_t);
    117 paddr_t pmap_md_direct_mapped_vaddr_to_paddr(vaddr_t);
    118 vaddr_t pmap_md_direct_map_paddr(paddr_t);
    119 void    pmap_md_init(void);
    120 bool    pmap_md_tlb_check_entry(void *, vaddr_t, tlb_asid_t, pt_entry_t);
    121 //void    pmap_md_page_syncicache(struct vm_page *, const kcpuset_t *);
    122 
    123 void	pmap_md_pdetab_activate(struct pmap *);
    124 void	pmap_md_pdetab_init(struct pmap *);
    125 bool	pmap_md_ok_to_steal_p(const uvm_physseg_t, size_t);
    126 
    127 #ifdef __PMAP_PRIVATE
    128 static inline void
    129 pmap_md_page_syncicache(struct vm_page *pg, const kcpuset_t *kc)
    130 {
    131 	__asm __volatile("fence\trw,rw; fence.i");
    132 }
    133 
    134 /*
    135  * Virtual Cache Alias helper routines.  Not a problem for RISCV CPUs.
    136  */
    137 static inline bool
    138 pmap_md_vca_add(struct vm_page *pg, vaddr_t va, pt_entry_t *nptep)
    139 {
    140 	return false;
    141 }
    142 
    143 static inline void
    144 pmap_md_vca_remove(struct vm_page *pg, vaddr_t va)
    145 {
    146 
    147 }
    148 
    149 static inline void
    150 pmap_md_vca_clean(struct vm_page *pg, vaddr_t va, int op)
    151 {
    152 }
    153 
    154 static inline size_t
    155 pmap_md_tlb_asid_max(void)
    156 {
    157 	return PMAP_TLB_NUM_PIDS - 1;
    158 }
    159 #endif /* __PMAP_PRIVATE */
    160 #endif /* _KERNEL */
    161 
    162 #define POOL_VTOPHYS(va)	((paddr_t)((vaddr_t)(va)-VM_MAX_KERNEL_ADDRESS))
    163 #define POOL_PHYSTOV(pa)	((vaddr_t)(paddr_t)(pa)+VM_MAX_KERNEL_ADDRESS)
    164 
    165 #include <uvm/pmap/pmap.h>
    166 
    167 #endif /* !_MODULE */
    168 
    169 #if defined(MODULAR) || defined(_MODULE)
    170 /*
    171  * Define a compatible vm_page_md so that struct vm_page is the same size
    172  * whether we are using modules or not.
    173  */
    174 #ifndef __HAVE_VM_PAGE_MD
    175 #define __HAVE_VM_PAGE_MD
    176 
    177 struct vm_page_md {
    178 	uintptr_t mdpg_dummy[3];
    179 };
    180 __CTASSERT(sizeof(struct vm_page_md) == sizeof(uintptr_t)*3);
    181 
    182 #endif /* !__HAVE_VM_PAGE_MD */
    183 
    184 #endif /* MODULAR || _MODULE */
    185 
    186 #endif /* !_RISCV_PMAP_H_ */
    187