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