1 /* $NetBSD: pmap.h,v 1.56 2009/06/29 13:22:51 tsutsui Exp $ */
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
34 * @(#)pmap.h 8.1 (Berkeley) 6/10/93
38 * Copyright (c) 1987 Carnegie-Mellon University
40 * This code is derived from software contributed to Berkeley by
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
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.
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
71 * @(#)pmap.h 8.1 (Berkeley) 6/10/93
77 #include <mips/cpuregs.h> /* for KSEG0 below */
80 * The user address space is 2Gb (0x0 - 0x80000000).
81 * User programs are laid out in memory as follows:
84 * USRDATA USRTEXT + text_size
87 * The user address space is mapped using a two level structure where
88 * virtual address bits 30..22 are used to index into a segment table which
89 * points to a page worth of PTEs (4096 page can hold 1024 PTEs).
90 * Bits 21..12 are then used to index a PTE which describes a page within
93 * The wired entries in the TLB will contain the following:
94 * 0-1 (UPAGES) for curproc user struct and kernel stack.
96 * Note: The kernel doesn't use the same data structures as user programs.
97 * All the PTE entries are stored in a single array in Sysmap which is
98 * dynamically allocated at boot time.
101 #define mips_trunc_seg(x) ((vaddr_t)(x) & ~SEGOFSET)
102 #define mips_round_seg(x) (((vaddr_t)(x) + SEGOFSET) & ~SEGOFSET)
103 #define pmap_segmap(m, v) ((m)->pm_segtab->seg_tab[((v) >> SEGSHIFT)])
105 #define PMAP_SEGTABSIZE (1 << (31 - SEGSHIFT))
110 union pt_entry
*seg_tab
[PMAP_SEGTABSIZE
];
114 * Machine dependent pmap structure.
117 kmutex_t pm_lock
; /* lock on pmap */
118 struct segtab
*pm_segtab
; /* pointers to pages of PTEs */
119 int pm_count
; /* pmap reference count */
120 unsigned int pm_asid
; /* TLB address space tag */
121 unsigned int pm_asidgen
; /* its generation number */
122 struct pmap_statistics pm_stats
; /* pmap statistics */
126 * For each struct vm_page, there is a list of all currently valid virtual
127 * mappings of that page. An entry is a pv_entry_t, the list is pv_table.
128 * XXX really should do this as a part of the higher level code.
130 typedef struct pv_entry
{
131 struct pv_entry
*pv_next
; /* next pv_entry */
132 struct pmap
*pv_pmap
; /* pmap where mapping lies */
133 vaddr_t pv_va
; /* virtual address for mapping */
134 u_int pv_flags
; /* some flags for the mapping */
135 #define PV_UNCACHED 0x0001 /* page is mapped uncached */
138 /* pvh_attrs flags in struct vm_page_md */
139 #define PGA_MODIFIED 0x0001 /* page has been modified */
140 #define PGA_REFERENCED 0x0002 /* page has been recently referenced */
145 extern char *pmap_attributes
; /* reference and modify bits */
147 #define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count)
148 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
150 #define pmap_update(pmap) /* nothing (yet) */
151 #define pmap_phys_address(x) mips_ptob(x)
154 pmap_remove_all(struct pmap
*pmap
)
160 * Bootstrap the system enough to run with virtual memory.
162 void pmap_bootstrap(void);
164 void pmap_set_modified(paddr_t
);
166 void pmap_procwr(struct proc
*, vaddr_t
, size_t);
167 #define PMAP_NEED_PROCWR
170 * pmap_prefer() helps reduce virtual-coherency exceptions in
171 * the virtually-indexed cache on mips3 CPUs.
174 #define PMAP_PREFER(pa, va, sz, td) pmap_prefer((pa), (va), (td))
175 void pmap_prefer(vaddr_t
, vaddr_t
*, int);
176 #endif /* MIPS3_PLUS */
178 #define PMAP_STEAL_MEMORY /* enable pmap_steal_memory() */
181 * Alternate mapping hooks for pool pages. Avoids thrashing the TLB.
183 vaddr_t
mips_pmap_map_poolpage(paddr_t
);
184 paddr_t
mips_pmap_unmap_poolpage(vaddr_t
);
185 #define PMAP_MAP_POOLPAGE(pa) mips_pmap_map_poolpage(pa)
186 #define PMAP_UNMAP_POOLPAGE(va) mips_pmap_unmap_poolpage(va)
189 * Other hooks for the pool allocator.
192 #define POOL_VTOPHYS(va) (MIPS_KSEG0_P(va) \
193 ? MIPS_KSEG0_TO_PHYS(va) \
194 : MIPS_XKPHYS_TO_PHYS(va))
196 #define POOL_VTOPHYS(va) MIPS_KSEG0_TO_PHYS((vaddr_t)(va))
200 * Select CCA to use for unmanaged pages.
202 #define PMAP_CCA_FOR_PA(pa) CCA_UNCACHED /* uncached */
204 #if defined(_MIPS_PADDR_T_64BIT) || defined(_LP64)
205 #define PMAP_NOCACHE 0x4000000000000000ULL
209 #endif /* _MIPS_PMAP_H_ */