]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/powerpc/include/pmap.h
Import libxo-0.7.2; add xo_options.7.
[FreeBSD/FreeBSD.git] / sys / powerpc / include / pmap.h
1 /*-
2  * Copyright (C) 2006 Semihalf, Marian Balakowicz <m8@semihalf.com>
3  * All rights reserved.
4  *
5  * Adapted for Freescale's e500 core CPUs.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
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.  IN
21  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31 /*-
32  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
33  * Copyright (C) 1995, 1996 TooLs GmbH.
34  * All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  * 2. Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in the
43  *    documentation and/or other materials provided with the distribution.
44  * 3. All advertising materials mentioning features or use of this software
45  *    must display the following acknowledgement:
46  *      This product includes software developed by TooLs GmbH.
47  * 4. The name of TooLs GmbH may not be used to endorse or promote products
48  *    derived from this software without specific prior written permission.
49  *
50  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
51  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
55  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
56  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
57  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
58  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
59  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60  *
61  *      from: $NetBSD: pmap.h,v 1.17 2000/03/30 16:18:24 jdolecek Exp $
62  */
63
64 #ifndef _MACHINE_PMAP_H_
65 #define _MACHINE_PMAP_H_
66
67 #include <sys/queue.h>
68 #include <sys/tree.h>
69 #include <sys/_cpuset.h>
70 #include <sys/_lock.h>
71 #include <sys/_mutex.h>
72 #include <machine/sr.h>
73 #include <machine/pte.h>
74 #include <machine/slb.h>
75 #include <machine/tlb.h>
76
77 struct pmap;
78 typedef struct pmap *pmap_t;
79
80 #if defined(AIM)
81
82 #if !defined(NPMAPS)
83 #define NPMAPS          32768
84 #endif /* !defined(NPMAPS) */
85
86 struct  slbtnode;
87
88 struct pvo_entry {
89         LIST_ENTRY(pvo_entry) pvo_vlink;        /* Link to common virt page */
90 #ifndef __powerpc64__
91         LIST_ENTRY(pvo_entry) pvo_olink;        /* Link to overflow entry */
92 #endif
93         RB_ENTRY(pvo_entry) pvo_plink;  /* Link to pmap entries */
94         struct {
95 #ifndef __powerpc64__
96                 /* 32-bit fields */
97                 struct  pte pte;
98 #endif
99                 /* 64-bit fields */
100                 uintptr_t   slot;
101                 vm_paddr_t  pa;
102                 vm_prot_t   prot;
103         } pvo_pte;
104         pmap_t          pvo_pmap;               /* Owning pmap */
105         vm_offset_t     pvo_vaddr;              /* VA of entry */
106         uint64_t        pvo_vpn;                /* Virtual page number */
107 };
108 LIST_HEAD(pvo_head, pvo_entry);
109 RB_HEAD(pvo_tree, pvo_entry);
110 int pvo_vaddr_compare(struct pvo_entry *, struct pvo_entry *);
111 RB_PROTOTYPE(pvo_tree, pvo_entry, pvo_plink, pvo_vaddr_compare);
112
113 /* Used by 32-bit PMAP */
114 #define PVO_PTEGIDX_MASK        0x007UL         /* which PTEG slot */
115 #define PVO_PTEGIDX_VALID       0x008UL         /* slot is valid */
116 /* Used by 64-bit PMAP */
117 #define PVO_HID                 0x008UL         /* PVO entry in alternate hash*/
118 /* Used by both */
119 #define PVO_WIRED               0x010UL         /* PVO entry is wired */
120 #define PVO_MANAGED             0x020UL         /* PVO entry is managed */
121 #define PVO_BOOTSTRAP           0x080UL         /* PVO entry allocated during
122                                                    bootstrap */
123 #define PVO_DEAD                0x100UL         /* waiting to be deleted */
124 #define PVO_LARGE               0x200UL         /* large page */
125 #define PVO_VADDR(pvo)          ((pvo)->pvo_vaddr & ~ADDR_POFF)
126 #define PVO_PTEGIDX_GET(pvo)    ((pvo)->pvo_vaddr & PVO_PTEGIDX_MASK)
127 #define PVO_PTEGIDX_ISSET(pvo)  ((pvo)->pvo_vaddr & PVO_PTEGIDX_VALID)
128 #define PVO_PTEGIDX_CLR(pvo)    \
129         ((void)((pvo)->pvo_vaddr &= ~(PVO_PTEGIDX_VALID|PVO_PTEGIDX_MASK)))
130 #define PVO_PTEGIDX_SET(pvo, i) \
131         ((void)((pvo)->pvo_vaddr |= (i)|PVO_PTEGIDX_VALID))
132 #define PVO_VSID(pvo)           ((pvo)->pvo_vpn >> 16)
133
134 struct  pmap {
135         struct          pmap_statistics pm_stats;
136         struct  mtx     pm_mtx;
137         
138     #ifdef __powerpc64__
139         struct slbtnode *pm_slb_tree_root;
140         struct slb      **pm_slb;
141         int             pm_slb_len;
142     #else
143         register_t      pm_sr[16];
144     #endif
145         cpuset_t        pm_active;
146
147         struct pmap     *pmap_phys;
148         struct pvo_tree pmap_pvo;
149 };
150
151 struct  md_page {
152         volatile int32_t mdpg_attrs;
153         vm_memattr_t     mdpg_cache_attrs;
154         struct  pvo_head mdpg_pvoh;
155 };
156
157 #define pmap_page_get_memattr(m)        ((m)->md.mdpg_cache_attrs)
158 #define pmap_page_is_mapped(m)  (!LIST_EMPTY(&(m)->md.mdpg_pvoh))
159
160 /*
161  * Return the VSID corresponding to a given virtual address.
162  * If no VSID is currently defined, it will allocate one, and add
163  * it to a free slot if available.
164  *
165  * NB: The PMAP MUST be locked already.
166  */
167 uint64_t va_to_vsid(pmap_t pm, vm_offset_t va);
168
169 /* Lock-free, non-allocating lookup routines */
170 uint64_t kernel_va_to_slbv(vm_offset_t va);
171 struct slb *user_va_to_slb_entry(pmap_t pm, vm_offset_t va);
172
173 uint64_t allocate_user_vsid(pmap_t pm, uint64_t esid, int large);
174 void    free_vsid(pmap_t pm, uint64_t esid, int large);
175 void    slb_insert_user(pmap_t pm, struct slb *slb);
176 void    slb_insert_kernel(uint64_t slbe, uint64_t slbv);
177
178 struct slbtnode *slb_alloc_tree(void);
179 void     slb_free_tree(pmap_t pm);
180 struct slb **slb_alloc_user_cache(void);
181 void    slb_free_user_cache(struct slb **);
182
183 #elif defined(BOOKE)
184
185 struct pmap {
186         struct pmap_statistics  pm_stats;       /* pmap statistics */
187         struct mtx              pm_mtx;         /* pmap mutex */
188         tlbtid_t                pm_tid[MAXCPU]; /* TID to identify this pmap entries in TLB */
189         cpuset_t                pm_active;      /* active on cpus */
190
191 #ifdef __powerpc64__
192         /* Page table directory, array of pointers to page directories. */
193         pte_t **pm_pp2d[PP2D_NENTRIES];
194
195         /* List of allocated pdir bufs (pdir kva regions). */
196         TAILQ_HEAD(, ptbl_buf)  pm_pdir_list;
197 #else
198         /* Page table directory, array of pointers to page tables. */
199         pte_t                   *pm_pdir[PDIR_NENTRIES];
200 #endif
201
202         /* List of allocated ptbl bufs (ptbl kva regions). */
203         TAILQ_HEAD(, ptbl_buf)  pm_ptbl_list;
204 };
205
206 struct pv_entry {
207         pmap_t pv_pmap;
208         vm_offset_t pv_va;
209         TAILQ_ENTRY(pv_entry) pv_link;
210 };
211 typedef struct pv_entry *pv_entry_t;
212
213 struct md_page {
214         TAILQ_HEAD(, pv_entry) pv_list;
215         int     pv_tracked;
216 };
217
218 #define pmap_page_get_memattr(m)        VM_MEMATTR_DEFAULT
219 #define pmap_page_is_mapped(m)  (!TAILQ_EMPTY(&(m)->md.pv_list))
220
221 #else
222 /*
223  * Common pmap members between AIM and BOOKE.
224  * libkvm needs pm_stats at the same location between both, as it doesn't define
225  * AIM nor BOOKE, and is expected to work across all.
226  */
227 struct pmap {
228         struct pmap_statistics  pm_stats;       /* pmap statistics */
229         struct mtx              pm_mtx;         /* pmap mutex */
230 };
231 #endif /* AIM */
232
233 extern  struct pmap kernel_pmap_store;
234 #define kernel_pmap     (&kernel_pmap_store)
235
236 #ifdef _KERNEL
237
238 #define PMAP_LOCK(pmap)         mtx_lock(&(pmap)->pm_mtx)
239 #define PMAP_LOCK_ASSERT(pmap, type) \
240                                 mtx_assert(&(pmap)->pm_mtx, (type))
241 #define PMAP_LOCK_DESTROY(pmap) mtx_destroy(&(pmap)->pm_mtx)
242 #define PMAP_LOCK_INIT(pmap)    mtx_init(&(pmap)->pm_mtx, \
243                                     (pmap == kernel_pmap) ? "kernelpmap" : \
244                                     "pmap", NULL, MTX_DEF)
245 #define PMAP_LOCKED(pmap)       mtx_owned(&(pmap)->pm_mtx)
246 #define PMAP_MTX(pmap)          (&(pmap)->pm_mtx)
247 #define PMAP_TRYLOCK(pmap)      mtx_trylock(&(pmap)->pm_mtx)
248 #define PMAP_UNLOCK(pmap)       mtx_unlock(&(pmap)->pm_mtx)
249
250 #define pmap_page_is_write_mapped(m)    (((m)->aflags & PGA_WRITEABLE) != 0)
251
252 void            pmap_bootstrap(vm_offset_t, vm_offset_t);
253 void            pmap_kenter(vm_offset_t va, vm_paddr_t pa);
254 void            pmap_kenter_attr(vm_offset_t va, vm_paddr_t pa, vm_memattr_t);
255 void            pmap_kremove(vm_offset_t);
256 void            *pmap_mapdev(vm_paddr_t, vm_size_t);
257 void            *pmap_mapdev_attr(vm_paddr_t, vm_size_t, vm_memattr_t);
258 void            pmap_unmapdev(vm_offset_t, vm_size_t);
259 void            pmap_page_set_memattr(vm_page_t, vm_memattr_t);
260 int             pmap_change_attr(vm_offset_t, vm_size_t, vm_memattr_t);
261 void            pmap_deactivate(struct thread *);
262 vm_paddr_t      pmap_kextract(vm_offset_t);
263 int             pmap_dev_direct_mapped(vm_paddr_t, vm_size_t);
264 boolean_t       pmap_mmu_install(char *name, int prio);
265
266 #define vtophys(va)     pmap_kextract((vm_offset_t)(va))
267
268 #define PHYS_AVAIL_SZ   256     /* Allows up to 16GB Ram on pSeries with
269                                  * logical memory block size of 64MB.
270                                  * For more Ram increase the lmb or this value.
271                                  */
272
273 extern  vm_paddr_t phys_avail[PHYS_AVAIL_SZ];
274 extern  vm_offset_t virtual_avail;
275 extern  vm_offset_t virtual_end;
276
277 extern  vm_offset_t msgbuf_phys;
278
279 extern  int pmap_bootstrapped;
280
281 vm_offset_t pmap_early_io_map(vm_paddr_t pa, vm_size_t size);
282 void pmap_early_io_unmap(vm_offset_t va, vm_size_t size);
283 void pmap_track_page(pmap_t pmap, vm_offset_t va);
284
285 #endif
286
287 #endif /* !_MACHINE_PMAP_H_ */