| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: mem.c,v 1.26 2008/11/19 06:24:04 matt Exp $ */ | | 1 | /* $NetBSD: mem.c,v 1.27 2010/10/30 18:35:38 uebayasi Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1982, 1986, 1990, 1993 | | 4 | * Copyright (c) 1982, 1986, 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * the Systems Programming Group of the University of Utah Computer | | 8 | * the Systems Programming Group of the University of Utah Computer |
9 | * Science Department. | | 9 | * Science Department. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
| @@ -66,42 +66,44 @@ | | | @@ -66,42 +66,44 @@ |
66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
68 | * SUCH DAMAGE. | | 68 | * SUCH DAMAGE. |
69 | */ | | 69 | */ |
70 | | | 70 | |
71 | /* | | 71 | /* |
72 | * Memory special file | | 72 | * Memory special file |
73 | */ | | 73 | */ |
74 | | | 74 | |
75 | #include "opt_arm32_pmap.h" | | 75 | #include "opt_arm32_pmap.h" |
76 | #include "opt_compat_netbsd.h" | | 76 | #include "opt_compat_netbsd.h" |
77 | | | 77 | |
78 | #include <sys/cdefs.h> | | 78 | #include <sys/cdefs.h> |
79 | __KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.26 2008/11/19 06:24:04 matt Exp $"); | | 79 | __KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.27 2010/10/30 18:35:38 uebayasi Exp $"); |
80 | | | 80 | |
81 | #include <sys/param.h> | | 81 | #include <sys/param.h> |
82 | #include <sys/conf.h> | | 82 | #include <sys/conf.h> |
83 | #include <sys/buf.h> | | 83 | #include <sys/buf.h> |
84 | #include <sys/systm.h> | | 84 | #include <sys/systm.h> |
85 | #include <sys/uio.h> | | 85 | #include <sys/uio.h> |
86 | #include <sys/malloc.h> | | 86 | #include <sys/malloc.h> |
87 | #include <sys/proc.h> | | 87 | #include <sys/proc.h> |
88 | #include <sys/fcntl.h> | | 88 | #include <sys/fcntl.h> |
89 | #include <sys/kauth.h> | | 89 | #include <sys/kauth.h> |
90 | | | 90 | |
91 | #include <machine/cpu.h> | | 91 | #include <machine/cpu.h> |
92 | | | 92 | |
93 | #include <uvm/uvm_extern.h> | | 93 | #include <uvm/uvm_extern.h> |
94 | | | 94 | |
| | | 95 | #define VM_PAGE_TO_MD(pg) (&(pg)->mdpage) |
| | | 96 | |
95 | extern vaddr_t memhook; /* in pmap.c (poor name!) */ | | 97 | extern vaddr_t memhook; /* in pmap.c (poor name!) */ |
96 | extern kmutex_t memlock; /* in pmap.c */ | | 98 | extern kmutex_t memlock; /* in pmap.c */ |
97 | extern void *zeropage; /* in pmap.c */ | | 99 | extern void *zeropage; /* in pmap.c */ |
98 | | | 100 | |
99 | dev_type_read(mmrw); | | 101 | dev_type_read(mmrw); |
100 | dev_type_ioctl(mmioctl); | | 102 | dev_type_ioctl(mmioctl); |
101 | dev_type_mmap(mmmmap); | | 103 | dev_type_mmap(mmmmap); |
102 | | | 104 | |
103 | const struct cdevsw mem_cdevsw = { | | 105 | const struct cdevsw mem_cdevsw = { |
104 | .d_open = nullopen, | | 106 | .d_open = nullopen, |
105 | .d_close = nullclose, | | 107 | .d_close = nullclose, |
106 | .d_read = mmrw, | | 108 | .d_read = mmrw, |
107 | .d_write = mmrw, | | 109 | .d_write = mmrw, |
| @@ -135,27 +137,27 @@ mmrw(dev_t dev, struct uio *uio, int fla | | | @@ -135,27 +137,27 @@ mmrw(dev_t dev, struct uio *uio, int fla |
135 | } | | 137 | } |
136 | switch (minor(dev)) { | | 138 | switch (minor(dev)) { |
137 | | | 139 | |
138 | case DEV_MEM: | | 140 | case DEV_MEM: |
139 | v = uio->uio_offset; | | 141 | v = uio->uio_offset; |
140 | prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : | | 142 | prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : |
141 | VM_PROT_WRITE; | | 143 | VM_PROT_WRITE; |
142 | m = memhook; | | 144 | m = memhook; |
143 | #ifdef PMAP_CACHE_VIPT | | 145 | #ifdef PMAP_CACHE_VIPT |
144 | { | | 146 | { |
145 | struct vm_page *pg; | | 147 | struct vm_page *pg; |
146 | pg = PHYS_TO_VM_PAGE(trunc_page(v)); | | 148 | pg = PHYS_TO_VM_PAGE(trunc_page(v)); |
147 | if (pg != NULL && pmap_is_page_colored_p(pg)) | | 149 | if (pg != NULL && pmap_is_page_colored_p(pg)) |
148 | o = pg->mdpage.pvh_attrs; | | 150 | o = VM_PAGE_TO_MD(pg)->pvh_attrs; |
149 | else | | 151 | else |
150 | o = v; | | 152 | o = v; |
151 | m += o & arm_cache_prefer_mask; | | 153 | m += o & arm_cache_prefer_mask; |
152 | } | | 154 | } |
153 | #endif | | 155 | #endif |
154 | mutex_enter(&memlock); | | 156 | mutex_enter(&memlock); |
155 | pmap_enter(pmap_kernel(), m, | | 157 | pmap_enter(pmap_kernel(), m, |
156 | trunc_page(v), prot, prot|PMAP_WIRED); | | 158 | trunc_page(v), prot, prot|PMAP_WIRED); |
157 | pmap_update(pmap_kernel()); | | 159 | pmap_update(pmap_kernel()); |
158 | o = uio->uio_offset & PGOFSET; | | 160 | o = uio->uio_offset & PGOFSET; |
159 | c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); | | 161 | c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); |
160 | error = uiomove((char *)m + o, c, uio); | | 162 | error = uiomove((char *)m + o, c, uio); |
161 | pmap_remove(pmap_kernel(), m, m + PAGE_SIZE); | | 163 | pmap_remove(pmap_kernel(), m, m + PAGE_SIZE); |