pmap.h revision 1.17 1 /* $NetBSD: pmap.h,v 1.17 1998/02/25 23:26:41 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1987 Carnegie-Mellon University
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Ralph Campbell.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)pmap.h 8.1 (Berkeley) 6/10/93
40 */
41
42 #ifndef _PMAP_MACHINE_
43 #define _PMAP_MACHINE_
44
45 /*
46 * The user address space is 2Gb (0x0 - 0x80000000).
47 * User programs are laid out in memory as follows:
48 * address
49 * USRTEXT 0x00001000
50 * USRDATA USRTEXT + text_size
51 * USRSTACK 0x7FFFFFFF
52 *
53 * The user address space is mapped using a two level structure where
54 * virtual address bits 30..22 are used to index into a segment table which
55 * points to a page worth of PTEs (4096 page can hold 1024 PTEs).
56 * Bits 21..12 are then used to index a PTE which describes a page within
57 * a segment.
58 *
59 * The wired entries in the TLB will contain the following:
60 * 0-1 (UPAGES) for curproc user struct and kernel stack.
61 *
62 * Note: The kernel doesn't use the same data structures as user programs.
63 * All the PTE entries are stored in a single array in Sysmap which is
64 * dynamically allocated at boot time.
65 */
66
67 #define mips_trunc_seg(x) ((vm_offset_t)(x) & ~SEGOFSET)
68 #define mips_round_seg(x) (((vm_offset_t)(x) + SEGOFSET) & ~SEGOFSET)
69 #define pmap_segmap(m, v) ((m)->pm_segtab->seg_tab[((v) >> SEGSHIFT)])
70
71 #define PMAP_SEGTABSIZE 512
72
73 union pt_entry;
74
75 struct segtab {
76 union pt_entry *seg_tab[PMAP_SEGTABSIZE];
77 };
78
79 /*
80 * Machine dependent pmap structure.
81 */
82 typedef struct pmap {
83 int pm_count; /* pmap reference count */
84 simple_lock_data_t pm_lock; /* lock on pmap */
85 struct pmap_statistics pm_stats; /* pmap statistics */
86 int pm_tlbpid; /* address space tag */
87 u_int pm_tlbgen; /* TLB PID generation number */
88 struct segtab *pm_segtab; /* pointers to pages of PTEs */
89 } *pmap_t;
90
91 /*
92 * For each vm_page_t, there is a list of all currently valid virtual
93 * mappings of that page. An entry is a pv_entry_t, the list is pv_table.
94 * XXX really should do this as a part of the higher level code.
95 */
96 typedef struct pv_entry {
97 struct pv_entry *pv_next; /* next pv_entry */
98 struct pmap *pv_pmap; /* pmap where mapping lies */
99 vm_offset_t pv_va; /* virtual address for mapping */
100 int pv_flags; /* some flags for the mapping */
101 } *pv_entry_t;
102
103 #define PV_UNCACHED 0x0001 /* page is mapped uncached */
104
105 /*
106 * Defines for pmap_attributes[phys_mach_page];
107 */
108 #define PMAP_ATTR_MOD 0x01 /* page has been modified */
109 #define PMAP_ATTR_REF 0x02 /* page has been referenced */
110
111
112 #ifdef _KERNEL
113
114 char *pmap_attributes; /* reference and modify bits */
115 struct pmap kernel_pmap_store;
116
117 #define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count)
118 #define pmap_kernel() (&kernel_pmap_store)
119 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
120
121 /*
122 * Bootstrap the system enough to run with virtual memory.
123 */
124 void pmap_bootstrap __P((void));
125
126 /*
127 * pmap_prefer() helps reduce virtual-coherency exceptions in
128 * the virtually-indexed cache on mips3 CPUs.
129 */
130 #ifdef MIPS3
131 #define PMAP_PREFER(pa, va) pmap_prefer((pa), (va))
132 void pmap_prefer __P((vm_offset_t, vm_offset_t *));
133 #endif /* MIPS3 */
134
135 #define PMAP_STEAL_MEMORY /* enable pmap_steal_memory() */
136
137 /*
138 * Kernel cache operations for the user-space API
139 */
140 int mips_user_cacheflush __P((struct proc *p, vm_offset_t va, int nbytes,
141 int whichcache));
142 int mips_user_cachectl __P((struct proc *p, vm_offset_t va, int nbytes,
143 int ctl));
144
145 #endif /* _KERNEL */
146 #endif /* _PMAP_MACHINE_ */
147