xref: /netbsd/sys/arch/hppa/include/pmap.h (revision 6550d01e)
1 /*	$NetBSD: pmap.h,v 1.29 2010/11/14 13:33:21 uebayasi Exp $	*/
2 
3 /*	$OpenBSD: pmap.h,v 1.35 2007/12/14 18:32:23 deraadt Exp $	*/
4 
5 /*
6  * Copyright (c) 2002-2004 Michael Shalayeff
7  * All rights reserved.
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 AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /*
32  *	Pmap header for hppa.
33  */
34 
35 #ifndef	_HPPA_PMAP_H_
36 #define	_HPPA_PMAP_H_
37 
38 #ifdef _KERNEL_OPT
39 #include "opt_cputype.h"
40 #endif
41 
42 #include <sys/mutex.h>
43 #include <machine/pte.h>
44 #include <machine/cpufunc.h>
45 
46 #include <uvm/uvm_pglist.h>
47 #include <uvm/uvm_object.h>
48 
49 #ifdef	_KERNEL
50 
51 struct pmap {
52 	struct uvm_object pm_obj;	/* object (lck by object lock) */
53 #define	pm_lock	pm_obj.vmobjlock
54 	struct vm_page	*pm_ptphint;
55 	struct vm_page	*pm_pdir_pg;	/* vm_page for pdir */
56 	volatile uint32_t *pm_pdir;	/* page dir (read-only after create) */
57 	pa_space_t	pm_space;	/* space id (read-only after create) */
58 	u_int		pm_pid;		/* prot id (read-only after create) */
59 
60 	struct pmap_statistics	pm_stats;
61 };
62 
63 #define	PVF_MOD		PTE_PROT(TLB_DIRTY)	/* pg/mp is modified */
64 #define	PVF_REF		PTE_PROT(TLB_REFTRAP)	/* pg/mp (inv) is referenced */
65 #define	PVF_WRITE	PTE_PROT(TLB_WRITE)	/* pg/mp is writable */
66 #define	PVF_UNCACHEABLE	PTE_PROT(TLB_UNCACHEABLE)	/* pg/mp is uncacheable */
67 
68 #define	HPPA_MAX_PID	0xfffa
69 #define	HPPA_SID_MAX	0x7ffd
70 
71 /*
72  * DON'T CHANGE THIS - this is assumed in lots of places.
73  */
74 #define	HPPA_SID_KERNEL	0
75 #define	HPPA_PID_KERNEL	2
76 
77 struct pv_entry {			/* locked by its list's pvh_lock */
78 	struct pv_entry	*pv_next;
79 	struct pmap	*pv_pmap;	/* the pmap */
80 	vaddr_t		pv_va;		/* the virtual address + flags */
81 #define	PV_VAMASK	(~(PAGE_SIZE - 1))
82 #define	PV_KENTER	0x001
83 
84 	struct vm_page	*pv_ptp;	/* the vm_page of the PTP */
85 };
86 
87 extern int pmap_hptsize;
88 extern struct pdc_hwtlb pdc_hwtlb;
89 
90 /*
91  * pool quickmaps
92  */
93 static inline vaddr_t hppa_map_poolpage(paddr_t pa)
94 {
95 	return (vaddr_t)pa;
96 }
97 
98 static inline paddr_t hppa_unmap_poolpage(vaddr_t va)
99 {
100 	pdcache(HPPA_SID_KERNEL, va, PAGE_SIZE);
101 
102 #if defined(HP8000_CPU) || defined(HP8200_CPU) || \
103     defined(HP8500_CPU) || defined(HP8600_CPU)
104 	ficache(HPPA_SID_KERNEL, va, PAGE_SIZE);
105 	pdtlb(HPPA_SID_KERNEL, va);
106 	pitlb(HPPA_SID_KERNEL, va);
107 #endif
108 
109 	return (paddr_t)va;
110 }
111 
112 #define	PMAP_MAP_POOLPAGE(pa)	hppa_map_poolpage(pa)
113 #define	PMAP_UNMAP_POOLPAGE(va)	hppa_unmap_poolpage(va)
114 
115 /*
116  * according to the parisc manual aliased va's should be
117  * different by high 12 bits only.
118  */
119 #define	PMAP_PREFER(o,h,s,td)	do {					\
120 	vaddr_t pmap_prefer_hint;					\
121 	pmap_prefer_hint = (*(h) & HPPA_PGAMASK) | ((o) & HPPA_PGAOFF);	\
122 	if (pmap_prefer_hint < *(h))					\
123 		pmap_prefer_hint += HPPA_PGALIAS;			\
124 	*(h) = pmap_prefer_hint;					\
125 } while(0)
126 
127 #define	pmap_sid2pid(s)			(((s) + 1) << 1)
128 #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
129 #define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
130 #define	pmap_update(p)
131 
132 #define	pmap_copy(dpmap,spmap,da,len,sa)
133 
134 #define	pmap_clear_modify(pg)	pmap_changebit(pg, 0, PTE_PROT(TLB_DIRTY))
135 #define	pmap_clear_reference(pg) \
136 				pmap_changebit(pg, PTE_PROT(TLB_REFTRAP), 0)
137 #define	pmap_is_modified(pg)	pmap_testbit(pg, PTE_PROT(TLB_DIRTY))
138 #define	pmap_is_referenced(pg)	pmap_testbit(pg, PTE_PROT(TLB_REFTRAP))
139 #define	pmap_phys_address(ppn)	((ppn) << PAGE_SHIFT)
140 
141 void	pmap_activate(struct lwp *);
142 
143 void pmap_bootstrap(vaddr_t);
144 bool pmap_changebit(struct vm_page *, u_int, u_int);
145 bool pmap_testbit(struct vm_page *, u_int);
146 void pmap_write_protect(struct pmap *, vaddr_t, vaddr_t, vm_prot_t);
147 void pmap_remove(struct pmap *pmap, vaddr_t sva, vaddr_t eva);
148 void pmap_page_remove(struct vm_page *pg);
149 
150 static inline void
151 pmap_deactivate(struct lwp *l)
152 {
153 	/* Nothing. */
154 }
155 
156 static inline void
157 pmap_remove_all(struct pmap *pmap)
158 {
159 	/* Nothing. */
160 }
161 
162 static inline int
163 pmap_prot(struct pmap *pmap, int prot)
164 {
165 	extern u_int hppa_prot[];
166 	return (hppa_prot[prot] | (pmap == pmap_kernel()? 0 : TLB_USER));
167 }
168 
169 static inline void
170 pmap_page_protect(struct vm_page *pg, vm_prot_t prot)
171 {
172 	if ((prot & UVM_PROT_WRITE) == 0) {
173 		if (prot & (UVM_PROT_RX))
174 			pmap_changebit(pg, 0, PTE_PROT(TLB_WRITE));
175 		else
176 			pmap_page_remove(pg);
177 	}
178 }
179 
180 static inline void
181 pmap_protect(struct pmap *pmap, vaddr_t sva, vaddr_t eva, vm_prot_t prot)
182 {
183 	if ((prot & UVM_PROT_WRITE) == 0) {
184 		if (prot & (UVM_PROT_RX))
185 			pmap_write_protect(pmap, sva, eva, prot);
186 		else
187 			pmap_remove(pmap, sva, eva);
188 	}
189 }
190 
191 #define	pmap_sid(pmap, va) \
192 	((((va) & 0xc0000000) != 0xc0000000) ? \
193 	 (pmap)->pm_space : HPPA_SID_KERNEL)
194 
195 #define __HAVE_VM_PAGE_MD
196 
197 struct pv_entry;
198 
199 struct vm_page_md {
200 	struct kmutex	pvh_lock;	/* locks every pv on this list */
201 	struct pv_entry	*pvh_list;	/* head of list (locked by pvh_lock) */
202 	u_int		pvh_attrs;	/* to preserve ref/mod */
203 	int		pvh_aliases;	/* alias counting */
204 };
205 
206 #define	VM_MDPAGE_INIT(pg) \
207 do {									\
208 	mutex_init(&(pg)->mdpage.pvh_lock, MUTEX_NODEBUG, IPL_VM);	\
209 	(pg)->mdpage.pvh_list = NULL;					\
210 	(pg)->mdpage.pvh_attrs = 0;					\
211 	(pg)->mdpage.pvh_aliases = 0;					\
212 } while (0)
213 
214 #endif /* _KERNEL */
215 
216 #endif /* _HPPA_PMAP_H_ */
217