]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/powerpc/include/pmap.h
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.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/_lock.h>
69 #include <sys/_mutex.h>
70 #include <machine/sr.h>
71 #include <machine/pte.h>
72 #include <machine/tlb.h>
73
74 struct pmap_md {
75         u_int           md_index;
76         vm_paddr_t      md_paddr;
77         vm_offset_t     md_vaddr;
78         vm_size_t       md_size;
79 };
80
81 #if defined(AIM)
82
83 #if !defined(NPMAPS)
84 #define NPMAPS          32768
85 #endif /* !defined(NPMAPS) */
86
87 struct  pmap {
88         struct  mtx     pm_mtx;
89         u_int           pm_sr[16];
90         u_int           pm_active;
91         u_int           pm_context;
92
93         struct pmap     *pmap_phys;
94         struct          pmap_statistics pm_stats;
95 };
96
97 typedef struct pmap *pmap_t;
98
99 struct pvo_entry {
100         LIST_ENTRY(pvo_entry) pvo_vlink;        /* Link to common virt page */
101         LIST_ENTRY(pvo_entry) pvo_olink;        /* Link to overflow entry */
102         union {
103                 struct  pte pte;                /* 32 bit PTE */
104                 struct  lpte lpte;              /* 64 bit PTE */
105         } pvo_pte;
106         pmap_t          pvo_pmap;               /* Owning pmap */
107         vm_offset_t     pvo_vaddr;              /* VA of entry */
108 };
109 LIST_HEAD(pvo_head, pvo_entry);
110
111 struct  md_page {
112         u_int64_t mdpg_attrs;
113         struct  pvo_head mdpg_pvoh;
114 };
115
116 #define pmap_page_get_memattr(m)        VM_MEMATTR_DEFAULT
117 #define pmap_page_is_mapped(m)  (!LIST_EMPTY(&(m)->md.mdpg_pvoh))
118 #define pmap_page_set_memattr(m, ma)    (void)0
119
120 #else
121
122 struct pmap {
123         struct mtx              pm_mtx;         /* pmap mutex */
124         tlbtid_t                pm_tid[MAXCPU]; /* TID to identify this pmap entries in TLB */
125         u_int                   pm_active;      /* active on cpus */
126         int                     pm_refs;        /* ref count */
127         struct pmap_statistics  pm_stats;       /* pmap statistics */
128
129         /* Page table directory, array of pointers to page tables. */
130         pte_t                   *pm_pdir[PDIR_NENTRIES];
131
132         /* List of allocated ptbl bufs (ptbl kva regions). */
133         TAILQ_HEAD(, ptbl_buf)  pm_ptbl_list;
134 };
135 typedef struct pmap *pmap_t;
136
137 struct pv_entry {
138         pmap_t pv_pmap;
139         vm_offset_t pv_va;
140         TAILQ_ENTRY(pv_entry) pv_link;
141 };
142 typedef struct pv_entry *pv_entry_t;
143
144 struct md_page {
145         TAILQ_HEAD(, pv_entry) pv_list;
146 };
147
148 #define pmap_page_get_memattr(m)        VM_MEMATTR_DEFAULT
149 #define pmap_page_is_mapped(m)  (!TAILQ_EMPTY(&(m)->md.pv_list))
150 #define pmap_page_set_memattr(m, ma)    (void)0
151
152 #endif /* AIM */
153
154 extern  struct pmap kernel_pmap_store;
155 #define kernel_pmap     (&kernel_pmap_store)
156
157 #ifdef _KERNEL
158
159 #define PMAP_LOCK(pmap)         mtx_lock(&(pmap)->pm_mtx)
160 #define PMAP_LOCK_ASSERT(pmap, type) \
161                                 mtx_assert(&(pmap)->pm_mtx, (type))
162 #define PMAP_LOCK_DESTROY(pmap) mtx_destroy(&(pmap)->pm_mtx)
163 #define PMAP_LOCK_INIT(pmap)    mtx_init(&(pmap)->pm_mtx, "pmap", \
164                                     NULL, MTX_DEF)
165 #define PMAP_LOCKED(pmap)       mtx_owned(&(pmap)->pm_mtx)
166 #define PMAP_MTX(pmap)          (&(pmap)->pm_mtx)
167 #define PMAP_TRYLOCK(pmap)      mtx_trylock(&(pmap)->pm_mtx)
168 #define PMAP_UNLOCK(pmap)       mtx_unlock(&(pmap)->pm_mtx)
169
170 void            pmap_bootstrap(vm_offset_t, vm_offset_t);
171 void            pmap_kenter(vm_offset_t va, vm_offset_t pa);
172 void            pmap_kremove(vm_offset_t);
173 void            *pmap_mapdev(vm_offset_t, vm_size_t);
174 void            pmap_unmapdev(vm_offset_t, vm_size_t);
175 void            pmap_deactivate(struct thread *);
176 vm_offset_t     pmap_kextract(vm_offset_t);
177 int             pmap_dev_direct_mapped(vm_offset_t, vm_size_t);
178 boolean_t       pmap_mmu_install(char *name, int prio);
179
180 #define vtophys(va)     pmap_kextract((vm_offset_t)(va))
181
182 #define PHYS_AVAIL_SZ   128
183 extern  vm_offset_t phys_avail[PHYS_AVAIL_SZ];
184 extern  vm_offset_t virtual_avail;
185 extern  vm_offset_t virtual_end;
186
187 extern  vm_offset_t msgbuf_phys;
188
189 extern  int pmap_bootstrapped;
190
191 extern vm_offset_t pmap_dumpsys_map(struct pmap_md *, vm_size_t, vm_size_t *);
192 extern void pmap_dumpsys_unmap(struct pmap_md *, vm_size_t, vm_offset_t);
193
194 extern struct pmap_md *pmap_scan_md(struct pmap_md *);
195
196 #endif
197
198 #endif /* !_MACHINE_PMAP_H_ */