]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/sun4v/sun4v/tte.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / sun4v / sun4v / tte.c
1 /*-
2  * Copyright (c) 2006 Kip Macy
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 #include "opt_ddb.h"
32 #include "opt_pmap.h"
33
34 #include <sys/param.h>
35 #include <sys/queue.h>
36 #include <sys/ktr.h>
37 #include <sys/lock.h>
38 #include <sys/mutex.h>
39 #include <sys/proc.h>
40 #include <sys/sched.h>
41 #include <sys/smp.h>
42 #include <sys/sysctl.h>
43 #include <sys/systm.h>
44
45 #include <vm/vm.h> 
46 #include <vm/vm_page.h>
47
48 #include <machine/cpufunc.h>
49 #include <machine/smp.h>
50 #include <machine/mmu.h>
51 #include <machine/tte.h>
52 #include <machine/cpu.h>
53 #include <machine/tte_hash.h>
54
55 void 
56 tte_clear_phys_bit(vm_page_t m, uint64_t flags)
57 {
58         pv_entry_t pv;
59         tte_t active_flags = (flags & ~VTD_SW_W);
60
61         if (m->flags & PG_FICTITIOUS) 
62                 return;
63
64         mtx_assert(&vm_page_queue_mtx, MA_OWNED);
65         /*
66          * Loop over all current mappings setting/clearing as appropos If
67          * setting RO do we need to clear the VAC?
68          */
69         TAILQ_FOREACH(pv, &m->md.pv_list, pv_list) {
70                 tte_t otte_data, matchbits;
71                 pmap_t pmap;
72
73                 pmap = pv->pv_pmap;
74                 PMAP_LOCK(pmap);
75                 otte_data = tte_hash_clear_bits(pmap->pm_hash, pv->pv_va, flags);
76                 if ((matchbits = (otte_data & active_flags)) != 0) {
77                         if ((otte_data & (VTD_SW_W|VTD_W)) == (VTD_SW_W|VTD_W)) 
78                                 vm_page_dirty(m);
79                         pmap_invalidate_page(pmap, pv->pv_va, TRUE);
80                 }
81                 PMAP_UNLOCK(pmap);
82         }
83 }
84
85 boolean_t 
86 tte_get_phys_bit(vm_page_t m, uint64_t flags)
87 {
88
89         pv_entry_t pv;
90         pmap_t pmap;
91         boolean_t rv;
92         
93         rv = FALSE;
94         if (m->flags & PG_FICTITIOUS)
95                 return (rv);
96
97         mtx_assert(&vm_page_queue_mtx, MA_OWNED);
98         TAILQ_FOREACH(pv, &m->md.pv_list, pv_list) {
99                 tte_t otte_data;
100
101                 pmap = pv->pv_pmap;
102                 otte_data = tte_hash_lookup(pmap->pm_hash, pv->pv_va);
103                 if ((rv = ((otte_data & flags) != 0)))
104                         break;
105         }
106
107         return (rv);
108 }
109
110 void 
111 tte_clear_virt_bit(struct pmap *pmap, vm_offset_t va, uint64_t flags)
112 {
113         (void)tte_hash_clear_bits(pmap->pm_hash, va, flags);
114 }
115
116 void 
117 tte_set_virt_bit(struct pmap *pmap, vm_offset_t va, uint64_t flags)
118 {
119         UNIMPLEMENTED;
120 }
121
122 boolean_t 
123 tte_get_virt_bit(struct pmap *pmap, vm_offset_t va, uint64_t flags)
124 {
125         tte_t tte_data;
126         
127         tte_data = tte_hash_lookup(pmap->pm_hash, va);
128         
129         return ((tte_data & flags) == flags);
130 }