Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.54.26.7
      1 /*	$NetBSD: pmap.h,v 1.54.26.7 2010/01/22 07:41:10 matt Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1992, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Ralph Campbell.
      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  * 3. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  *	@(#)pmap.h	8.1 (Berkeley) 6/10/93
     35  */
     36 
     37 /*
     38  * Copyright (c) 1987 Carnegie-Mellon University
     39  *
     40  * This code is derived from software contributed to Berkeley by
     41  * Ralph Campbell.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. All advertising materials mentioning features or use of this software
     52  *    must display the following acknowledgement:
     53  *	This product includes software developed by the University of
     54  *	California, Berkeley and its contributors.
     55  * 4. Neither the name of the University nor the names of its contributors
     56  *    may be used to endorse or promote products derived from this software
     57  *    without specific prior written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  * SUCH DAMAGE.
     70  *
     71  *	@(#)pmap.h	8.1 (Berkeley) 6/10/93
     72  */
     73 
     74 #ifndef	_MIPS_PMAP_H_
     75 #define	_MIPS_PMAP_H_
     76 
     77 #include <mips/cpuregs.h>	/* for KSEG0 below */
     78 //#include <mips/pte.h>
     79 
     80 /*
     81  * The user address space is 2Gb (0x0 - 0x80000000).
     82  * User programs are laid out in memory as follows:
     83  *			address
     84  *	USRTEXT		0x00001000
     85  *	USRDATA		USRTEXT + text_size
     86  *	USRSTACK	0x7FFFFFFF
     87  *
     88  * The user address space is mapped using a two level structure where
     89  * virtual address bits 30..22 are used to index into a segment table which
     90  * points to a page worth of PTEs (4096 page can hold 1024 PTEs).
     91  * Bits 21..12 are then used to index a PTE which describes a page within
     92  * a segment.
     93  *
     94  * The wired entries in the TLB will contain the following:
     95  *	0-1	(UPAGES)	for curproc user struct and kernel stack.
     96  *
     97  * Note: The kernel doesn't use the same data structures as user programs.
     98  * All the PTE entries are stored in a single array in Sysmap which is
     99  * dynamically allocated at boot time.
    100  */
    101 
    102 #define mips_trunc_seg(x)	((vaddr_t)(x) & ~SEGOFSET)
    103 #define mips_round_seg(x)	(((vaddr_t)(x) + SEGOFSET) & ~SEGOFSET)
    104 
    105 #define PMAP_SEGTABSIZE		(1 << (31 - SEGSHIFT))
    106 
    107 union pt_entry;
    108 
    109 struct segtab {
    110 	union pt_entry	*seg_tab[PMAP_SEGTABSIZE];
    111 };
    112 
    113 /*
    114  * Structure defining an tlb entry data set.
    115  */
    116 struct tlb {
    117 	vaddr_t	tlb_hi;		/* should be 64 bits */
    118 	uint32_t tlb_lo0;	/* XXX maybe 64 bits (only 32 really used) */
    119 	uint32_t tlb_lo1;	/* XXX maybe 64 bits (only 32 really used) */
    120 };
    121 
    122 struct tlbmask {
    123 	vaddr_t	tlb_hi;		/* should be 64 bits */
    124 	uint32_t tlb_lo0;	/* XXX maybe 64 bits (only 32 really used) */
    125 	uint32_t tlb_lo1;	/* XXX maybe 64 bits (only 32 really used) */
    126 	uint32_t tlb_mask;
    127 };
    128 
    129 struct pmap;
    130 typedef bool (*pte_callback_t)(struct pmap *, vaddr_t, vaddr_t,
    131 	union pt_entry *, uintptr_t);
    132 union pt_entry *pmap_pte_lookup(struct pmap *, vaddr_t);
    133 union pt_entry *pmap_pte_reserve(struct pmap *, vaddr_t, int);
    134 void pmap_pte_process(struct pmap *, vaddr_t, vaddr_t, pte_callback_t,
    135 	uintptr_t);
    136 void pmap_segtab_activate(struct lwp *);
    137 void pmap_segtab_alloc(struct pmap *);
    138 void pmap_segtab_free(struct pmap *);
    139 
    140 /*
    141  * Per cpu asid info
    142  */
    143 struct pmap_asid_info {
    144 	uint32_t	pai_asid;	/* TLB address space tag */
    145 	uint32_t	pai_asid_generation; /* its generation number */
    146 	struct tlb	*pai_tlb;
    147 };
    148 
    149 #ifdef MULTIPROCESSOR
    150 #define	PMAP_PAI(pmap, ci)	(&(pmap)->pm_pai[(ci)->ci_cpuid])
    151 #else
    152 #define	PMAP_PAI(pmap, ci)	(&(pmap)->pm_pai[0])
    153 #endif
    154 #define	PMAP_PAI_ASIDVALID_P(pai, ci)	\
    155 		((pai)->pai_asid != (ci)->ci_pmap_asid_reserved \
    156 		 && (pai)->pai_asid_generation == (ci)->ci_pmap_asid_generation)
    157 
    158 /*
    159  * Machine dependent pmap structure.
    160  */
    161 typedef struct pmap {
    162 	kmutex_t		pm_lock;	/* lock on pmap */
    163 	struct segtab		*pm_segtab;	/* pointers to pages of PTEs */
    164 #ifdef MULTIPROCESSOR
    165 	uint32_t		pm_cpus;	/* pmap was active on ... */
    166 #endif
    167 	int			pm_count;	/* pmap reference count */
    168 	struct pmap_statistics	pm_stats;	/* pmap statistics */
    169 	struct pmap_asid_info	pm_pai[1];
    170 } *pmap_t;
    171 
    172 /*
    173  * For each struct vm_page, there is a list of all currently valid virtual
    174  * mappings of that page.  An entry is a pv_entry_t, the list is pv_table.
    175  * XXX really should do this as a part of the higher level code.
    176  */
    177 typedef struct pv_entry {
    178 	struct pv_entry	*pv_next;	/* next pv_entry */
    179 	struct pmap	*pv_pmap;	/* pmap where mapping lies */
    180 	vaddr_t		pv_va;		/* virtual address for mapping */
    181 	int		pv_flags;	/* some flags for the mapping */
    182 } *pv_entry_t;
    183 
    184 #define	PV_UNCACHED	0x0001		/* page is mapped uncached */
    185 #define	PV_MODIFIED	0x0002		/* page has been modified */
    186 #define	PV_REFERENCED	0x0004		/* page has been recently referenced */
    187 
    188 
    189 #ifdef	_KERNEL
    190 
    191 struct pmap_kernel {
    192 	struct pmap kernel_pmap;
    193 #ifdef MULTIPROCESSOR
    194 	struct pmap_asid_info kernel_pai[MAXCPUS-1];
    195 #endif
    196 };
    197 
    198 extern struct pmap_kernel kernel_pmap_store;
    199 extern paddr_t mips_avail_start;
    200 extern paddr_t mips_avail_end;
    201 extern vaddr_t mips_virtual_end;
    202 
    203 #define pmap_kernel()		(&kernel_pmap_store.kernel_pmap)
    204 #define	pmap_wired_count(pmap) 	((pmap)->pm_stats.wired_count)
    205 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
    206 
    207 #define pmap_phys_address(x)	mips_ptob(x)
    208 
    209 static __inline void
    210 pmap_remove_all(struct pmap *pmap)
    211 {
    212 	/* Nothing. */
    213 }
    214 
    215 /*
    216  *	Bootstrap the system enough to run with virtual memory.
    217  */
    218 void	pmap_bootstrap(void);
    219 
    220 void	pmap_set_modified(paddr_t);
    221 void	pmap_procwr(struct proc *, vaddr_t, size_t);
    222 #define	PMAP_NEED_PROCWR
    223 
    224 uint32_t pmap_tlb_asid_alloc(pmap_t pmap, struct cpu_info *ci);
    225 void	pmap_tlb_invalidate_asid(pmap_t pmap);
    226 int	pmap_tlb_update(pmap_t pmap, vaddr_t, uint32_t);
    227 void	pmap_tlb_invalidate_addr(pmap_t pmap, vaddr_t);
    228 
    229 /*
    230  * pmap_prefer() helps reduce virtual-coherency exceptions in
    231  * the virtually-indexed cache on mips3 CPUs.
    232  */
    233 #ifdef MIPS3_PLUS
    234 #define PMAP_PREFER(pa, va, sz, td)	pmap_prefer((pa), (va), (td))
    235 void	pmap_prefer(vaddr_t, vaddr_t *, int);
    236 #endif /* MIPS3_PLUS */
    237 
    238 #define	PMAP_STEAL_MEMORY	/* enable pmap_steal_memory() */
    239 
    240 /*
    241  * Alternate mapping hooks for pool pages.  Avoids thrashing the TLB.
    242  */
    243 vaddr_t mips_pmap_map_poolpage(paddr_t);
    244 paddr_t mips_pmap_unmap_poolpage(vaddr_t);
    245 struct vm_page *mips_pmap_alloc_poolpage(int);
    246 #define	PMAP_ALLOC_POOLPAGE(flags)	mips_pmap_alloc_poolpage(flags)
    247 #define	PMAP_MAP_POOLPAGE(pa)		mips_pmap_map_poolpage(pa)
    248 #define	PMAP_UNMAP_POOLPAGE(va)		mips_pmap_unmap_poolpage(va)
    249 
    250 /*
    251  * Other hooks for the pool allocator.
    252  */
    253 #ifdef _LP64
    254 #define	POOL_VTOPHYS(va)	(MIPS_KSEG0_P(va) \
    255 				    ? MIPS_KSEG0_TO_PHYS(va) \
    256 				    : MIPS_XKPHYS_TO_PHYS(va))
    257 #else
    258 #define	POOL_VTOPHYS(va)	MIPS_KSEG0_TO_PHYS((vaddr_t)(va))
    259 #endif
    260 
    261 /*
    262  * Select CCA to use for unmanaged pages.
    263  */
    264 #define	PMAP_CCA_FOR_PA(pa)	CCA_UNCACHED		/* uncached */
    265 
    266 #if defined(_MIPS_PADDR_T_64BIT) || defined(_LP64)
    267 #define PMAP_NOCACHE	0x4000000000000000ULL
    268 #endif
    269 
    270 #endif	/* _KERNEL */
    271 #endif	/* _MIPS_PMAP_H_ */
    272