xref: /netbsd/sys/arch/ia64/include/pmap.h (revision 23d5800c)
1 /*-
2  * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to The NetBSD Foundation
6  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
7  * NASA Ames Research Center and by Chris G. Demetriou.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /*-
32  * Copyright (c) 1991 Regents of the University of California.
33  * All rights reserved.
34  *
35  * This code is derived from software contributed to Berkeley by
36  * the Systems Programming Group of the University of Utah Computer
37  * Science Department and William Jolitz of UUNET Technologies Inc.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  * 1. Redistributions of source code must retain the above copyright
43  *    notice, this list of conditions and the following disclaimer.
44  * 2. Redistributions in binary form must reproduce the above copyright
45  *    notice, this list of conditions and the following disclaimer in the
46  *    documentation and/or other materials provided with the distribution.
47  * 4. Neither the name of the University nor the names of its contributors
48  *    may be used to endorse or promote products derived from this software
49  *    without specific prior written permission.
50  *
51  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61  * SUCH DAMAGE.
62  *
63  * Derived from hp300 version by Mike Hibler, this version by William
64  * Jolitz uses a recursive map [a pde points to the page directory] to
65  * map the page tables using the pagetables themselves. This is done to
66  * reduce the impact on kernel virtual memory for lots of sparse address
67  * space, and to reduce the cost of memory to each process.
68  *
69  *	from: hp300: @(#)pmap.h	7.2 (Berkeley) 12/16/90
70  *	from: @(#)pmap.h	7.4 (Berkeley) 5/12/91
71  *	from: i386 pmap.h,v 1.54 1997/11/20 19:30:35 bde Exp
72  * $FreeBSD: releng/10.1/sys/ia64/include/pmap.h 268201 2014-07-02 23:57:55Z marcel $
73  */
74 
75 #ifndef _IA64_PMAP_H_
76 #define _IA64_PMAP_H_
77 
78 #include <sys/types.h>
79 #include <sys/queue.h>
80 #include <sys/lock.h>
81 #include <sys/mutex.h>
82 
83 #include <machine/pte.h>
84 #include <machine/vmparam.h>
85 
86 #include <machine/md_var.h>
87 
88 typedef char	vm_memattr_t;
89 
90 #define VM_MEMATTR_WRITE_BACK           ((vm_memattr_t)PTE_MA_WB)
91 #define VM_MEMATTR_UNCACHEABLE          ((vm_memattr_t)PTE_MA_UC)
92 #define VM_MEMATTR_UNCACHEABLE_EXPORTED ((vm_memattr_t)PTE_MA_UCE)
93 #define VM_MEMATTR_WRITE_COMBINING      ((vm_memattr_t)PTE_MA_WC)
94 #define VM_MEMATTR_NATPAGE              ((vm_memattr_t)PTE_MA_NATPAGE)
95 #define VM_MEMATTR_DEFAULT              VM_MEMATTR_WRITE_BACK
96 
97 #ifdef _KERNEL
98 
99 #define MAXKPT		(PAGE_SIZE/sizeof(vaddr_t))
100 
101 #define	vtophys(va)	pmap_kextract((vaddr_t)(va))
102 
103 #endif /* _KERNEL */
104 
105 /*
106  * Pmap stuff
107  */
108 struct	pv_entry;
109 struct	pv_chunk;
110 
111 struct pmap {
112 	kmutex_t		pm_mtx;
113 	TAILQ_HEAD(,pv_chunk)	pm_pvchunk;	/* list of mappings in pmap */
114 	uint32_t		pm_rid[IA64_VM_MINKERN_REGION];
115 	struct pmap_statistics	pm_stats;	/* pmap statistics */
116 	uint64_t		pm_refcount;	/* pmap reference count, atomic */
117 };
118 
119 typedef struct pmap *pmap_t;
120 
121 #ifdef _KERNEL
122 
123 #define	PMAP_LOCK(pmap)		mutex_enter(&(pmap)->pm_mtx)
124 #define	PMAP_LOCK_ASSERT(pmap)	KASSERT(mutex_owned(&(pmap)->pm_mtx))
125 #define	PMAP_LOCK_DESTROY(pmap)	mutex_destroy(&(pmap)->pm_mtx)
126 #define	PMAP_LOCK_INIT(pmap)	mutex_init(&(pmap)->pm_mtx, MUTEX_DEFAULT, IPL_NONE)
127 #define	PMAP_LOCKED(pmap)	mutex_owned(&(pmap)->pm_mtx)
128 #define	PMAP_MTX(pmap)		(&(pmap)->pm_mtx)
129 #define	PMAP_TRYLOCK(pmap)	mutex_tryenter(&(pmap)->pm_mtx)
130 #define	PMAP_UNLOCK(pmap)	mutex_exit(&(pmap)->pm_mtx)
131 
132 #endif
133 
134 /*
135  * For each vm_page_t, there is a list of all currently valid virtual
136  * mappings of that page.  An entry is a pv_entry_t, the list is pv_list.
137  */
138 typedef struct pv_entry {
139 	vaddr_t	pv_va;		/* virtual address for mapping */
140 	TAILQ_ENTRY(pv_entry)	pv_list;
141 } *pv_entry_t;
142 
143 void pmap_bootstrap(void);
144 
145 /* optional pmap API functions, according to pmap(9) */
146 #define PMAP_STEAL_MEMORY
147 #define PMAP_GROWKERNEL
148 
149 #define PMAP_NEED_PROCWR
150 void pmap_procwr(struct proc *, vaddr_t, vsize_t);
151 
152 /*
153  * Alternate mapping hooks for pool pages.  Avoids thrashing the TLB.
154  */
155 /* XXX
156 #define	PMAP_MAP_POOLPAGE(pa)		IA64_PHYS_TO_RR7((pa))
157 #define	PMAP_UNMAP_POOLPAGE(va)		IA64_RR_MASK((va))
158 */
159 
160 /*
161  * Macros for locking pmap structures.
162  *
163  * Note that we if we access the kernel pmap in interrupt context, it
164  * is only to update statistics.  Since stats are updated using atomic
165  * operations, locking the kernel pmap is not necessary.  Therefore,
166  * it is not necessary to block interrupts when locking pmap strucutres.
167  */
168 /* XXX
169 #define	PMAP_LOCK(pmap)		mutex_enter(&(pmap)->pm_slock)
170 #define	PMAP_UNLOCK(pmap)	mutex_exit(&(pmap)->pm_slock)
171 */
172 
173 /*
174  * pmap-specific data store in the vm_page structure.
175  */
176 #define	__HAVE_VM_PAGE_MD
177 
178 struct vm_page_md {
179 	TAILQ_HEAD(,pv_entry)	pv_list;
180 	vm_memattr_t		memattr;
181 #if 0 /* XXX freebsd */
182 	uint8_t		pv_flags;
183 	uint8_t		aflags;
184 #endif
185 };
186 
187 #define	VM_MDPAGE_INIT(pg)						\
188 do {									\
189 	TAILQ_INIT(&(pg)->mdpage.pv_list);				\
190 	(pg)->mdpage.memattr = VM_MEMATTR_DEFAULT;			\
191 } while (/*CONSTCOND*/0)
192 
193 #ifdef	_KERNEL
194 
195 extern uint64_t pmap_vhpt_base[];
196 extern uint64_t pmap_vhpt_log2size;
197 
198 vaddr_t pmap_page_to_va(struct vm_page*);
199 
200 /* Machine-architecture private */
201 vaddr_t pmap_alloc_vhpt(void);
202 void pmap_bootstrap(void);
203 void pmap_invalidate_all(void);
204 paddr_t pmap_kextract(vaddr_t va);
205 struct pmap *pmap_switch(struct pmap *pmap);
206 void pmap_remove_all_phys(struct vm_page*);  /* used in only pmap_page_protect */
207 
208 #endif /* _KERNEL */
209 
210 #endif /* _IA64_PMAP_H_ */
211