Home | History | Annotate | Line # | Download | only in include
      1  1.77     skrll /*	$NetBSD: pmap.h,v 1.77 2022/10/26 07:35:19 skrll Exp $	*/
      2   1.5       cgd 
      3  1.26    simonb /*
      4   1.3     glass  * Copyright (c) 1992, 1993
      5   1.3     glass  *	The Regents of the University of California.  All rights reserved.
      6  1.44       agc  *
      7  1.44       agc  * This code is derived from software contributed to Berkeley by
      8  1.44       agc  * Ralph Campbell.
      9  1.44       agc  *
     10  1.44       agc  * Redistribution and use in source and binary forms, with or without
     11  1.44       agc  * modification, are permitted provided that the following conditions
     12  1.44       agc  * are met:
     13  1.44       agc  * 1. Redistributions of source code must retain the above copyright
     14  1.44       agc  *    notice, this list of conditions and the following disclaimer.
     15  1.44       agc  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.44       agc  *    notice, this list of conditions and the following disclaimer in the
     17  1.44       agc  *    documentation and/or other materials provided with the distribution.
     18  1.44       agc  * 3. Neither the name of the University nor the names of its contributors
     19  1.44       agc  *    may be used to endorse or promote products derived from this software
     20  1.44       agc  *    without specific prior written permission.
     21  1.44       agc  *
     22  1.44       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.44       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.44       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.44       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.44       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.44       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.44       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.44       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.44       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.44       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.44       agc  * SUCH DAMAGE.
     33  1.44       agc  *
     34  1.44       agc  *	@(#)pmap.h	8.1 (Berkeley) 6/10/93
     35  1.44       agc  */
     36  1.44       agc 
     37  1.44       agc /*
     38  1.44       agc  * Copyright (c) 1987 Carnegie-Mellon University
     39   1.1   deraadt  *
     40   1.1   deraadt  * This code is derived from software contributed to Berkeley by
     41   1.1   deraadt  * Ralph Campbell.
     42   1.1   deraadt  *
     43   1.1   deraadt  * Redistribution and use in source and binary forms, with or without
     44   1.1   deraadt  * modification, are permitted provided that the following conditions
     45   1.1   deraadt  * are met:
     46   1.1   deraadt  * 1. Redistributions of source code must retain the above copyright
     47   1.1   deraadt  *    notice, this list of conditions and the following disclaimer.
     48   1.1   deraadt  * 2. Redistributions in binary form must reproduce the above copyright
     49   1.1   deraadt  *    notice, this list of conditions and the following disclaimer in the
     50   1.1   deraadt  *    documentation and/or other materials provided with the distribution.
     51   1.1   deraadt  * 3. All advertising materials mentioning features or use of this software
     52   1.1   deraadt  *    must display the following acknowledgement:
     53   1.1   deraadt  *	This product includes software developed by the University of
     54   1.1   deraadt  *	California, Berkeley and its contributors.
     55   1.1   deraadt  * 4. Neither the name of the University nor the names of its contributors
     56   1.1   deraadt  *    may be used to endorse or promote products derived from this software
     57   1.1   deraadt  *    without specific prior written permission.
     58   1.1   deraadt  *
     59   1.1   deraadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60   1.1   deraadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61   1.1   deraadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62   1.1   deraadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63   1.1   deraadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64   1.1   deraadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65   1.1   deraadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66   1.1   deraadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67   1.1   deraadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68   1.1   deraadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69   1.1   deraadt  * SUCH DAMAGE.
     70   1.1   deraadt  *
     71   1.5       cgd  *	@(#)pmap.h	8.1 (Berkeley) 6/10/93
     72   1.1   deraadt  */
     73   1.1   deraadt 
     74  1.41    simonb #ifndef	_MIPS_PMAP_H_
     75  1.41    simonb #define	_MIPS_PMAP_H_
     76   1.1   deraadt 
     77  1.60      matt #ifdef _KERNEL_OPT
     78  1.60      matt #include "opt_multiprocessor.h"
     79  1.68      matt #include "opt_uvmhist.h"
     80  1.70       mrg #include "opt_cputype.h"
     81  1.60      matt #endif
     82  1.60      matt 
     83  1.64      matt #include <sys/evcnt.h>
     84  1.65      matt #include <sys/kcpuset.h>
     85  1.68      matt #include <sys/kernhist.h>
     86  1.64      matt 
     87  1.68      matt #ifndef __BSD_PTENTRY_T__
     88  1.72    simonb #define	__BSD_PTENTRY_T__
     89  1.68      matt typedef uint32_t pt_entry_t;
     90  1.72    simonb #define	PRIxPTE		PRIx32
     91  1.68      matt #endif /* __BSD_PTENTRY_T__ */
     92  1.68      matt 
     93  1.72    simonb #define	KERNEL_PID			0
     94  1.68      matt 
     95  1.68      matt #if defined(__PMAP_PRIVATE)
     96  1.75     skrll struct vm_page_md;
     97  1.68      matt 
     98  1.68      matt #include <mips/locore.h>
     99  1.68      matt #include <mips/cache.h>
    100  1.68      matt 
    101  1.72    simonb #define	PMAP_VIRTUAL_CACHE_ALIASES
    102  1.72    simonb #define	PMAP_INVALID_SEGTAB_ADDRESS	((pmap_segtab_t *)NULL)
    103  1.76     skrll #define	PMAP_TLB_NEED_SHOOTDOWN		1
    104  1.72    simonb #define	PMAP_TLB_FLUSH_ASID_ON_RESET	false
    105  1.68      matt #if UPAGES > 1
    106  1.72    simonb #define	PMAP_TLB_WIRED_UPAGES		MIPS3_TLB_WIRED_UPAGES
    107  1.68      matt #endif
    108  1.72    simonb #define	pmap_md_tlb_asid_max()		(MIPS_TLB_NUM_PIDS - 1)
    109  1.68      matt #ifdef MULTIPROCESSOR
    110  1.72    simonb #define	PMAP_NO_PV_UNCACHED
    111  1.68      matt #endif
    112  1.68      matt 
    113  1.68      matt /*
    114  1.68      matt  * We need the pmap_segtab's to be aligned on MIPS*R2 so we can use the
    115  1.68      matt  * EXT/INS instructions on their addresses.
    116  1.72    simonb  */
    117  1.68      matt #if (MIPS32R2 + MIPS64R2 + MIPS64R2_RMIXL) > 0
    118  1.72    simonb #define	PMAP_SEGTAB_ALIGN __aligned(sizeof(void *)*NSEGPG) __section(".data1")
    119  1.72    simonb #endif
    120  1.68      matt 
    121  1.69    cherry #include <uvm/uvm_physseg.h>
    122  1.68      matt 
    123  1.68      matt void	pmap_md_init(void);
    124  1.68      matt void	pmap_md_icache_sync_all(void);
    125  1.68      matt void	pmap_md_icache_sync_range_index(vaddr_t, vsize_t);
    126  1.75     skrll void	pmap_md_page_syncicache(struct vm_page_md *, const kcpuset_t *);
    127  1.75     skrll bool	pmap_md_vca_add(struct vm_page_md *, vaddr_t, pt_entry_t *);
    128  1.75     skrll void	pmap_md_vca_clean(struct vm_page_md *, int);
    129  1.68      matt void	pmap_md_vca_remove(struct vm_page *, vaddr_t, bool, bool);
    130  1.69    cherry bool	pmap_md_ok_to_steal_p(const uvm_physseg_t, size_t);
    131  1.68      matt bool	pmap_md_tlb_check_entry(void *, vaddr_t, tlb_asid_t, pt_entry_t);
    132  1.68      matt 
    133  1.68      matt static inline bool
    134  1.68      matt pmap_md_virtual_cache_aliasing_p(void)
    135  1.68      matt {
    136  1.68      matt 	return MIPS_CACHE_VIRTUAL_ALIAS;
    137  1.68      matt }
    138  1.68      matt 
    139  1.68      matt static inline vsize_t
    140  1.68      matt pmap_md_cache_prefer_mask(void)
    141  1.68      matt {
    142  1.68      matt 	return MIPS_HAS_R4K_MMU ? mips_cache_info.mci_cache_prefer_mask : 0;
    143  1.68      matt }
    144  1.73     skrll 
    145  1.73     skrll static inline void
    146  1.73     skrll pmap_md_xtab_activate(struct pmap *pm, struct lwp *l)
    147  1.73     skrll {
    148  1.73     skrll 
    149  1.73     skrll 	/* nothing */
    150  1.73     skrll }
    151  1.73     skrll 
    152  1.73     skrll static inline void
    153  1.73     skrll pmap_md_xtab_deactivate(struct pmap *pm)
    154  1.73     skrll {
    155  1.73     skrll 
    156  1.73     skrll 	/* nothing */
    157  1.73     skrll }
    158  1.73     skrll 
    159  1.68      matt #endif /* __PMAP_PRIVATE */
    160  1.68      matt 
    161  1.77     skrll // these use register_t so we can pass XKPHYS addresses to them on N32
    162  1.77     skrll bool	pmap_md_direct_mapped_vaddr_p(register_t);
    163  1.77     skrll paddr_t	pmap_md_direct_mapped_vaddr_to_paddr(register_t);
    164  1.77     skrll bool	pmap_md_io_vaddr_p(vaddr_t);
    165  1.77     skrll 
    166  1.77     skrll /*
    167  1.77     skrll  * Alternate mapping hooks for pool pages.  Avoids thrashing the TLB.
    168  1.77     skrll  */
    169  1.77     skrll vaddr_t pmap_md_map_poolpage(paddr_t, size_t);
    170  1.77     skrll paddr_t pmap_md_unmap_poolpage(vaddr_t, size_t);
    171  1.77     skrll struct vm_page *pmap_md_alloc_poolpage(int);
    172  1.77     skrll 
    173  1.77     skrll /*
    174  1.77     skrll  * Other hooks for the pool allocator.
    175  1.77     skrll  */
    176  1.77     skrll paddr_t	pmap_md_pool_vtophys(vaddr_t);
    177  1.77     skrll vaddr_t	pmap_md_pool_phystov(paddr_t);
    178  1.77     skrll #define	POOL_VTOPHYS(va)	pmap_md_pool_vtophys((vaddr_t)va)
    179  1.77     skrll #define	POOL_PHYSTOV(pa)	pmap_md_pool_phystov((paddr_t)pa)
    180  1.77     skrll 
    181  1.77     skrll #define pmap_md_direct_map_paddr(pa)	pmap_md_pool_phystov((paddr_t)pa)
    182  1.77     skrll 
    183  1.68      matt struct tlbmask {
    184  1.68      matt 	vaddr_t	tlb_hi;
    185  1.68      matt #ifdef __mips_o32
    186  1.68      matt 	uint32_t tlb_lo0;
    187  1.68      matt 	uint32_t tlb_lo1;
    188  1.68      matt #else
    189  1.68      matt 	uint64_t tlb_lo0;
    190  1.68      matt 	uint64_t tlb_lo1;
    191  1.68      matt #endif
    192  1.68      matt 	uint32_t tlb_mask;
    193  1.68      matt };
    194  1.68      matt 
    195  1.68      matt #ifdef _LP64
    196  1.72    simonb #define	PMAP_SEGTABSIZE		NSEGPG
    197  1.68      matt #else
    198  1.72    simonb #define	PMAP_SEGTABSIZE		(1 << (31 - SEGSHIFT))
    199  1.68      matt #endif
    200  1.68      matt 
    201  1.74       mrg #include <uvm/uvm_pmap.h>
    202  1.68      matt #include <uvm/pmap/vmpagemd.h>
    203  1.68      matt #include <uvm/pmap/pmap.h>
    204  1.75     skrll #include <uvm/pmap/pmap_pvt.h>
    205  1.68      matt #include <uvm/pmap/pmap_tlb.h>
    206  1.68      matt #include <uvm/pmap/pmap_synci.h>
    207  1.68      matt 
    208  1.68      matt #ifdef _KERNEL
    209  1.68      matt /*
    210  1.68      matt  * Select CCA to use for unmanaged pages.
    211  1.68      matt  */
    212  1.68      matt #define	PMAP_CCA_FOR_PA(pa)	CCA_UNCACHED		/* uncached */
    213  1.68      matt 
    214  1.68      matt #if defined(_MIPS_PADDR_T_64BIT) || defined(_LP64)
    215  1.72    simonb #define	PGC_NOCACHE	0x4000000000000000ULL
    216  1.72    simonb #define	PGC_PREFETCH	0x2000000000000000ULL
    217  1.68      matt #endif
    218  1.68      matt 
    219  1.68      matt #if defined(__PMAP_PRIVATE)
    220  1.68      matt #include <mips/pte.h>
    221  1.68      matt #endif
    222  1.18   thorpej 
    223   1.1   deraadt /*
    224   1.3     glass  * The user address space is 2Gb (0x0 - 0x80000000).
    225   1.3     glass  * User programs are laid out in memory as follows:
    226   1.3     glass  *			address
    227   1.3     glass  *	USRTEXT		0x00001000
    228   1.3     glass  *	USRDATA		USRTEXT + text_size
    229   1.3     glass  *	USRSTACK	0x7FFFFFFF
    230   1.3     glass  *
    231   1.3     glass  * The user address space is mapped using a two level structure where
    232   1.3     glass  * virtual address bits 30..22 are used to index into a segment table which
    233   1.3     glass  * points to a page worth of PTEs (4096 page can hold 1024 PTEs).
    234  1.26    simonb  * Bits 21..12 are then used to index a PTE which describes a page within
    235   1.3     glass  * a segment.
    236   1.3     glass  *
    237   1.1   deraadt  * The wired entries in the TLB will contain the following:
    238   1.3     glass  *	0-1	(UPAGES)	for curproc user struct and kernel stack.
    239   1.3     glass  *
    240   1.3     glass  * Note: The kernel doesn't use the same data structures as user programs.
    241   1.3     glass  * All the PTE entries are stored in a single array in Sysmap which is
    242   1.3     glass  * dynamically allocated at boot time.
    243   1.1   deraadt  */
    244   1.1   deraadt 
    245  1.72    simonb #define	pmap_phys_address(x)	mips_ptob(x)
    246  1.39       chs 
    247  1.12  jonathan /*
    248  1.13  jonathan  *	Bootstrap the system enough to run with virtual memory.
    249  1.13  jonathan  */
    250  1.38    simonb void	pmap_bootstrap(void);
    251  1.68      matt void	pmap_md_alloc_ephemeral_address_space(struct cpu_info *);
    252  1.38    simonb void	pmap_procwr(struct proc *, vaddr_t, size_t);
    253  1.25        is #define	PMAP_NEED_PROCWR
    254  1.13  jonathan 
    255  1.13  jonathan /*
    256  1.28     soren  * pmap_prefer() helps reduce virtual-coherency exceptions in
    257  1.13  jonathan  * the virtually-indexed cache on mips3 CPUs.
    258  1.13  jonathan  */
    259  1.38    simonb #ifdef MIPS3_PLUS
    260  1.72    simonb #define	PMAP_PREFER(pa, va, sz, td)	pmap_prefer((pa), (va), (sz), (td))
    261  1.60      matt void	pmap_prefer(vaddr_t, vaddr_t *, vsize_t, int);
    262  1.38    simonb #endif /* MIPS3_PLUS */
    263  1.13  jonathan 
    264  1.63     skrll #define	PMAP_ENABLE_PMAP_KMPAGE	/* enable the PMAP_KMPAGE flag */
    265  1.18   thorpej 
    266  1.70       mrg #ifdef MIPS64_SB1
    267  1.70       mrg /* uncached accesses are bad; all accesses should be cached (and coherent) */
    268  1.70       mrg #undef PMAP_PAGEIDLEZERO
    269  1.70       mrg #define	PMAP_PAGEIDLEZERO(pa)   (pmap_zero_page(pa), true)
    270  1.70       mrg 
    271  1.70       mrg int sbmips_cca_for_pa(paddr_t);
    272  1.70       mrg 
    273  1.70       mrg #undef PMAP_CCA_FOR_PA
    274  1.70       mrg #define	PMAP_CCA_FOR_PA(pa)	sbmips_cca_for_pa(pa)
    275  1.70       mrg #endif
    276  1.70       mrg 
    277  1.75     skrll #ifdef __HAVE_PMAP_PV_TRACK
    278  1.75     skrll struct pmap_page {
    279  1.75     skrll         struct vm_page_md       pp_md;
    280  1.75     skrll };
    281  1.75     skrll 
    282  1.75     skrll #define PMAP_PAGE_TO_MD(ppage)  (&((ppage)->pp_md))
    283  1.75     skrll #endif
    284  1.75     skrll 
    285   1.6       jtc #endif	/* _KERNEL */
    286  1.41    simonb #endif	/* _MIPS_PMAP_H_ */
    287