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