xref: /netbsd-src/sys/arch/powerpc/include/booke/pmap.h (revision fdd524d4ccd2bb0c6f67401e938dabf773eb0372)
1 /*	$NetBSD: pmap.h,v 1.16 2016/07/11 16:06:52 matt Exp $	*/
2 /*-
3  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to The NetBSD Foundation
7  * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
8  * Agency and which was developed by Matt Thomas of 3am Software Foundry.
9  *
10  * This material is based upon work supported by the Defense Advanced Research
11  * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
12  * Contract No. N66001-09-C-2073.
13  * Approved for Public Release, Distribution Unlimited
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  * 1. Redistributions of source code must retain the above copyright
19  *    notice, this list of conditions and the following disclaimer.
20  * 2. Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in the
22  *    documentation and/or other materials provided with the distribution.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 #ifndef _POWERPC_BOOKE_PMAP_H_
37 #define _POWERPC_BOOKE_PMAP_H_
38 
39 #ifdef _LOCORE
40 #error use assym.h instead
41 #endif
42 
43 #if defined(_MODULE)
44 #error this file should not be included by loadable kernel modules
45 #endif
46 
47 #ifdef _KERNEL_OPT
48 #include "opt_pmap.h"
49 #endif
50 
51 #include <sys/cpu.h>
52 #include <sys/kcore.h>
53 #include <uvm/uvm_page.h>
54 #ifdef __PMAP_PRIVATE
55 #include <powerpc/booke/cpuvar.h>
56 #endif
57 
58 #define	PMAP_NEED_PROCWR
59 
60 #include <uvm/pmap/vmpagemd.h>
61 
62 #include <powerpc/booke/pte.h>
63 
64 #define	NBSEG		(NBPG*NPTEPG)
65 #define	SEGSHIFT	(PGSHIFT + PGSHIFT - 2)
66 #define SEGOFSET	((1 << SEGSHIFT) - 1)
67 #define PMAP_SEGTABSIZE	(1 << (32 - SEGSHIFT))
68 #define	NPTEPG		(NBPG >> 2)
69 
70 #define	KERNEL_PID	0
71 
72 #define	PMAP_TLB_NUM_PIDS		256
73 #define	PMAP_TLB_MAX			1
74 #define	PMAP_INVALID_SEGTAB_ADDRESS	((pmap_segtab_t *)0xfeeddead)
75 #define	PMAP_TLB_FLUSH_ASID_ON_RESET	false
76 
77 #define	pmap_phys_address(x)		(x)
78 
79 void	pmap_procwr(struct proc *, vaddr_t, size_t);
80 #define	PMAP_NEED_PROCWR
81 
82 #ifdef __PMAP_PRIVATE
83 struct vm_page *
84 	pmap_md_alloc_poolpage(int flags);
85 vaddr_t	pmap_md_map_poolpage(paddr_t, vsize_t);
86 void	pmap_md_unmap_poolpage(vaddr_t, vsize_t);
87 bool	pmap_md_direct_mapped_vaddr_p(vaddr_t);
88 bool	pmap_md_io_vaddr_p(vaddr_t);
89 paddr_t	pmap_md_direct_mapped_vaddr_to_paddr(vaddr_t);
90 vaddr_t	pmap_md_direct_map_paddr(paddr_t);
91 void	pmap_md_init(void);
92 
93 bool	pmap_md_tlb_check_entry(void *, vaddr_t, tlb_asid_t, pt_entry_t);
94 
95 #ifdef MULTIPROCESSOR
96 #define	PMAP_MD_NEED_TLB_MISS_LOCK
97 void	pmap_md_tlb_miss_lock_enter(void);
98 void	pmap_md_tlb_miss_lock_exit(void);
99 #endif	/* MULTIPROCESSOR */
100 
101 #ifdef PMAP_MINIMALTLB
102 vaddr_t	pmap_kvptefill(vaddr_t, vaddr_t, pt_entry_t);
103 #endif
104 #endif
105 
106 void	pmap_md_page_syncicache(struct vm_page *, const kcpuset_t *);
107 vaddr_t	pmap_bootstrap(vaddr_t, vaddr_t, phys_ram_seg_t *, size_t);
108 bool	pmap_extract(struct pmap *, vaddr_t, paddr_t *);
109 
110 static inline paddr_t vtophys(vaddr_t);
111 
112 static inline paddr_t
113 vtophys(vaddr_t va)
114 {
115 	paddr_t pa;
116 
117 	if (pmap_extract(pmap_kernel(), va, &pa))
118 		return pa;
119 	KASSERT(0);
120 	return (paddr_t) -1;
121 }
122 
123 #ifdef __PMAP_PRIVATE
124 /*
125  * Virtual Cache Alias helper routines.  Not a problem for Booke CPUs.
126  */
127 static inline bool
128 pmap_md_vca_add(struct vm_page *pg, vaddr_t va, pt_entry_t *nptep)
129 {
130 	return false;
131 }
132 
133 static inline void
134 pmap_md_vca_remove(struct vm_page *pg, vaddr_t va, bool dirty)
135 {
136 
137 }
138 
139 static inline void
140 pmap_md_vca_clean(struct vm_page *pg, vaddr_t va, int op)
141 {
142 }
143 #endif
144 
145 #ifdef __PMAP_PRIVATE
146 static inline size_t
147 pmap_md_tlb_asid_max(void)
148 {
149 	return PMAP_TLB_NUM_PIDS - 1;
150 }
151 
152 struct vm_physseg;
153 static inline bool
154 pmap_md_ok_to_steal_p(const struct vm_physseg *seg, size_t npgs)
155 {
156 	return true;
157 }
158 #endif
159 
160 #define	POOL_VTOPHYS(va)	((paddr_t)(vaddr_t)(va))
161 #define	POOL_PHYSTOV(pa)	((vaddr_t)(paddr_t)(pa))
162 
163 #include <uvm/pmap/pmap.h>
164 
165 #endif /* !_POWERPC_BOOKE_PMAP_H_ */
166