Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.63.4.4
      1  1.63.4.4     skrll /*	$NetBSD: pmap.h,v 1.63.4.4 2017/08/28 17:51:45 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.63.4.2     skrll #include "opt_uvmhist.h"
     80  1.63.4.4     skrll #include "opt_cputype.h"
     81      1.60      matt #endif
     82      1.60      matt 
     83  1.63.4.1     skrll #include <sys/evcnt.h>
     84  1.63.4.1     skrll #include <sys/kcpuset.h>
     85  1.63.4.2     skrll #include <sys/kernhist.h>
     86  1.63.4.1     skrll 
     87  1.63.4.2     skrll #ifndef __BSD_PTENTRY_T__
     88  1.63.4.2     skrll #define __BSD_PTENTRY_T__
     89  1.63.4.2     skrll typedef uint32_t pt_entry_t;
     90  1.63.4.2     skrll #define PRIxPTE		PRIx32
     91  1.63.4.2     skrll #endif /* __BSD_PTENTRY_T__ */
     92      1.18   thorpej 
     93  1.63.4.2     skrll #define KERNEL_PID			0
     94       1.1   deraadt 
     95  1.63.4.2     skrll #if defined(__PMAP_PRIVATE)
     96       1.3     glass 
     97  1.63.4.2     skrll #include <mips/locore.h>
     98  1.63.4.2     skrll #include <mips/cache.h>
     99       1.3     glass 
    100  1.63.4.2     skrll #define PMAP_VIRTUAL_CACHE_ALIASES
    101  1.63.4.2     skrll #define PMAP_INVALID_SEGTAB_ADDRESS	((pmap_segtab_t *)NULL)
    102  1.63.4.2     skrll #define	PMAP_TLB_NEED_SHOOTDOWN
    103  1.63.4.2     skrll #define PMAP_TLB_FLUSH_ASID_ON_RESET	false
    104  1.63.4.2     skrll #if UPAGES > 1
    105  1.63.4.2     skrll #define PMAP_TLB_WIRED_UPAGES		MIPS3_TLB_WIRED_UPAGES
    106  1.63.4.2     skrll #endif
    107  1.63.4.2     skrll #define pmap_md_tlb_asid_max()		(MIPS_TLB_NUM_PIDS - 1)
    108  1.63.4.2     skrll #ifdef MULTIPROCESSOR
    109  1.63.4.2     skrll #define PMAP_NO_PV_UNCACHED
    110      1.60      matt #endif
    111  1.63.4.1     skrll 
    112       1.1   deraadt /*
    113  1.63.4.2     skrll  * We need the pmap_segtab's to be aligned on MIPS*R2 so we can use the
    114  1.63.4.2     skrll  * EXT/INS instructions on their addresses.
    115      1.60      matt  */
    116  1.63.4.2     skrll #if (MIPS32R2 + MIPS64R2 + MIPS64R2_RMIXL) > 0
    117  1.63.4.2     skrll #define PMAP_SEGTAB_ALIGN __aligned(sizeof(void *)*NSEGPG) __section(".data1")
    118  1.63.4.2     skrll #endif
    119      1.60      matt 
    120  1.63.4.3     skrll #include <uvm/uvm_physseg.h>
    121      1.60      matt 
    122  1.63.4.2     skrll void	pmap_md_init(void);
    123  1.63.4.2     skrll void	pmap_md_icache_sync_all(void);
    124  1.63.4.2     skrll void	pmap_md_icache_sync_range_index(vaddr_t, vsize_t);
    125  1.63.4.2     skrll void	pmap_md_page_syncicache(struct vm_page *, const kcpuset_t *);
    126  1.63.4.2     skrll bool	pmap_md_vca_add(struct vm_page *, vaddr_t, pt_entry_t *);
    127  1.63.4.2     skrll void	pmap_md_vca_clean(struct vm_page *, int);
    128  1.63.4.2     skrll void	pmap_md_vca_remove(struct vm_page *, vaddr_t, bool, bool);
    129  1.63.4.3     skrll bool	pmap_md_ok_to_steal_p(const uvm_physseg_t, size_t);
    130  1.63.4.2     skrll bool	pmap_md_tlb_check_entry(void *, vaddr_t, tlb_asid_t, pt_entry_t);
    131      1.60      matt 
    132  1.63.4.2     skrll static inline bool
    133  1.63.4.2     skrll pmap_md_virtual_cache_aliasing_p(void)
    134  1.63.4.2     skrll {
    135  1.63.4.2     skrll 	return MIPS_CACHE_VIRTUAL_ALIAS;
    136  1.63.4.2     skrll }
    137      1.60      matt 
    138  1.63.4.2     skrll static inline vsize_t
    139  1.63.4.2     skrll pmap_md_cache_prefer_mask(void)
    140  1.63.4.2     skrll {
    141  1.63.4.2     skrll 	return MIPS_HAS_R4K_MMU ? mips_cache_info.mci_cache_prefer_mask : 0;
    142  1.63.4.2     skrll }
    143  1.63.4.2     skrll #endif /* __PMAP_PRIVATE */
    144      1.60      matt 
    145  1.63.4.2     skrll struct tlbmask {
    146  1.63.4.2     skrll 	vaddr_t	tlb_hi;
    147  1.63.4.2     skrll #ifdef __mips_o32
    148  1.63.4.2     skrll 	uint32_t tlb_lo0;
    149  1.63.4.2     skrll 	uint32_t tlb_lo1;
    150  1.63.4.2     skrll #else
    151  1.63.4.2     skrll 	uint64_t tlb_lo0;
    152  1.63.4.2     skrll 	uint64_t tlb_lo1;
    153      1.60      matt #endif
    154  1.63.4.2     skrll 	uint32_t tlb_mask;
    155      1.60      matt };
    156      1.17   thorpej 
    157  1.63.4.2     skrll #ifdef _LP64
    158  1.63.4.2     skrll #define PMAP_SEGTABSIZE		NSEGPG
    159      1.60      matt #else
    160  1.63.4.2     skrll #define PMAP_SEGTABSIZE		(1 << (31 - SEGSHIFT))
    161      1.60      matt #endif
    162       1.1   deraadt 
    163  1.63.4.2     skrll #include <uvm/pmap/vmpagemd.h>
    164  1.63.4.2     skrll #include <uvm/pmap/pmap.h>
    165  1.63.4.2     skrll #include <uvm/pmap/pmap_tlb.h>
    166  1.63.4.2     skrll #include <uvm/pmap/pmap_synci.h>
    167      1.13  jonathan 
    168  1.63.4.2     skrll #ifdef _KERNEL
    169  1.63.4.2     skrll /*
    170  1.63.4.2     skrll  * Select CCA to use for unmanaged pages.
    171  1.63.4.2     skrll  */
    172  1.63.4.2     skrll #define	PMAP_CCA_FOR_PA(pa)	CCA_UNCACHED		/* uncached */
    173      1.13  jonathan 
    174  1.63.4.2     skrll #if defined(_MIPS_PADDR_T_64BIT) || defined(_LP64)
    175  1.63.4.2     skrll #define PGC_NOCACHE	0x4000000000000000ULL
    176  1.63.4.2     skrll #define PGC_PREFETCH	0x2000000000000000ULL
    177  1.63.4.2     skrll #endif
    178  1.63.4.1     skrll 
    179  1.63.4.2     skrll #if defined(__PMAP_PRIVATE)
    180  1.63.4.2     skrll #include <mips/pte.h>
    181      1.60      matt #endif
    182       1.7   mycroft 
    183  1.63.4.2     skrll /*
    184  1.63.4.2     skrll  * The user address space is 2Gb (0x0 - 0x80000000).
    185  1.63.4.2     skrll  * User programs are laid out in memory as follows:
    186  1.63.4.2     skrll  *			address
    187  1.63.4.2     skrll  *	USRTEXT		0x00001000
    188  1.63.4.2     skrll  *	USRDATA		USRTEXT + text_size
    189  1.63.4.2     skrll  *	USRSTACK	0x7FFFFFFF
    190  1.63.4.2     skrll  *
    191  1.63.4.2     skrll  * The user address space is mapped using a two level structure where
    192  1.63.4.2     skrll  * virtual address bits 30..22 are used to index into a segment table which
    193  1.63.4.2     skrll  * points to a page worth of PTEs (4096 page can hold 1024 PTEs).
    194  1.63.4.2     skrll  * Bits 21..12 are then used to index a PTE which describes a page within
    195  1.63.4.2     skrll  * a segment.
    196  1.63.4.2     skrll  *
    197  1.63.4.2     skrll  * The wired entries in the TLB will contain the following:
    198  1.63.4.2     skrll  *	0-1	(UPAGES)	for curproc user struct and kernel stack.
    199  1.63.4.2     skrll  *
    200  1.63.4.2     skrll  * Note: The kernel doesn't use the same data structures as user programs.
    201  1.63.4.2     skrll  * All the PTE entries are stored in a single array in Sysmap which is
    202  1.63.4.2     skrll  * dynamically allocated at boot time.
    203  1.63.4.2     skrll  */
    204      1.31   thorpej 
    205      1.51  macallan #define pmap_phys_address(x)	mips_ptob(x)
    206      1.39       chs 
    207      1.12  jonathan /*
    208      1.13  jonathan  *	Bootstrap the system enough to run with virtual memory.
    209      1.13  jonathan  */
    210      1.38    simonb void	pmap_bootstrap(void);
    211  1.63.4.2     skrll void	pmap_md_alloc_ephemeral_address_space(struct cpu_info *);
    212      1.38    simonb void	pmap_procwr(struct proc *, vaddr_t, size_t);
    213      1.25        is #define	PMAP_NEED_PROCWR
    214      1.13  jonathan 
    215      1.13  jonathan /*
    216      1.28     soren  * pmap_prefer() helps reduce virtual-coherency exceptions in
    217      1.13  jonathan  * the virtually-indexed cache on mips3 CPUs.
    218      1.13  jonathan  */
    219      1.38    simonb #ifdef MIPS3_PLUS
    220      1.60      matt #define PMAP_PREFER(pa, va, sz, td)	pmap_prefer((pa), (va), (sz), (td))
    221      1.60      matt void	pmap_prefer(vaddr_t, vaddr_t *, vsize_t, int);
    222      1.38    simonb #endif /* MIPS3_PLUS */
    223      1.13  jonathan 
    224      1.63     skrll #define	PMAP_ENABLE_PMAP_KMPAGE	/* enable the PMAP_KMPAGE flag */
    225      1.18   thorpej 
    226  1.63.4.2     skrll // these use register_t so we can pass XKPHYS adddresses to them on N32
    227  1.63.4.2     skrll bool	pmap_md_direct_mapped_vaddr_p(register_t);
    228  1.63.4.2     skrll paddr_t	pmap_md_direct_mapped_vaddr_to_paddr(register_t);
    229  1.63.4.2     skrll bool	pmap_md_io_vaddr_p(vaddr_t);
    230  1.63.4.1     skrll 
    231      1.18   thorpej /*
    232      1.18   thorpej  * Alternate mapping hooks for pool pages.  Avoids thrashing the TLB.
    233      1.18   thorpej  */
    234  1.63.4.2     skrll vaddr_t pmap_md_map_poolpage(paddr_t, size_t);
    235  1.63.4.2     skrll paddr_t pmap_md_unmap_poolpage(vaddr_t, size_t);
    236  1.63.4.2     skrll struct vm_page *pmap_md_alloc_poolpage(int);
    237      1.42   thorpej 
    238      1.42   thorpej /*
    239      1.42   thorpej  * Other hooks for the pool allocator.
    240      1.42   thorpej  */
    241  1.63.4.2     skrll paddr_t	pmap_md_pool_vtophys(vaddr_t);
    242  1.63.4.2     skrll vaddr_t	pmap_md_pool_phystov(paddr_t);
    243  1.63.4.2     skrll #define	POOL_VTOPHYS(va)	pmap_md_pool_vtophys((vaddr_t)va)
    244  1.63.4.2     skrll #define	POOL_PHYSTOV(pa)	pmap_md_pool_phystov((paddr_t)pa)
    245      1.60      matt 
    246  1.63.4.4     skrll #ifdef MIPS64_SB1
    247  1.63.4.4     skrll /* uncached accesses are bad; all accesses should be cached (and coherent) */
    248  1.63.4.4     skrll #undef PMAP_PAGEIDLEZERO
    249  1.63.4.4     skrll #define	PMAP_PAGEIDLEZERO(pa)   (pmap_zero_page(pa), true)
    250  1.63.4.4     skrll 
    251  1.63.4.4     skrll int sbmips_cca_for_pa(paddr_t);
    252  1.63.4.4     skrll 
    253  1.63.4.4     skrll #undef PMAP_CCA_FOR_PA
    254  1.63.4.4     skrll #define	PMAP_CCA_FOR_PA(pa)	sbmips_cca_for_pa(pa)
    255  1.63.4.4     skrll #endif
    256  1.63.4.4     skrll 
    257       1.6       jtc #endif	/* _KERNEL */
    258      1.41    simonb #endif	/* _MIPS_PMAP_H_ */
    259