]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/phys.c
xnu-517.9.5.tar.gz
[apple/xnu.git] / osfmk / i386 / phys.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 #include <string.h>
51
52 #include <mach/vm_param.h>
53 #include <mach/boolean.h>
54 #include <vm/pmap.h>
55 #include <vm/vm_page.h>
56 #include <kern/misc_protos.h>
57
58 /*
59 * pmap_zero_page zeros the specified (machine independent) page.
60 */
61 void
62 pmap_zero_page(
63 ppnum_t pn)
64 {
65 vm_offset_t p;
66 assert(pn != vm_page_fictitious_addr);
67 p = (vm_offset_t)i386_ptob(pn);
68 bzero((char *)phystokv(p), PAGE_SIZE);
69 }
70
71 /*
72 * pmap_zero_part_page
73 * zeros the specified (machine independent) part of a page.
74 */
75 void
76 pmap_zero_part_page(
77 ppnum_t pn,
78 vm_offset_t offset,
79 vm_size_t len)
80 {
81 assert(pn != vm_page_fictitious_addr);
82 assert(offset + len <= PAGE_SIZE);
83 bzero((char *)phystokv(i386_ptob(pn)) + offset, len);
84 }
85
86 /*
87 * pmap_copy_page copies the specified (machine independent) pages.
88 */
89 void
90 pmap_copy_page(
91 ppnum_t psrc,
92 ppnum_t pdst)
93
94 {
95 vm_offset_t src,dst;
96
97 assert(psrc != vm_page_fictitious_addr);
98 assert(pdst != vm_page_fictitious_addr);
99 src = (vm_offset_t)i386_ptob(psrc);
100 dst = (vm_offset_t)i386_ptob(pdst);
101
102 memcpy((void *)phystokv(dst), (void *)phystokv(src), PAGE_SIZE);
103 }
104
105 /*
106 * pmap_copy_page copies the specified (machine independent) pages.
107 */
108 void
109 pmap_copy_part_page(
110 ppnum_t psrc,
111 vm_offset_t src_offset,
112 ppnum_t pdst,
113 vm_offset_t dst_offset,
114 vm_size_t len)
115 {
116 vm_offset_t src, dst;
117
118 assert(psrc != vm_page_fictitious_addr);
119 assert(pdst != vm_page_fictitious_addr);
120 src = (vm_offset_t)i386_ptob(psrc);
121 dst = (vm_offset_t)i386_ptob(pdst);
122 assert(((dst & PAGE_MASK) + dst_offset + len) <= PAGE_SIZE);
123 assert(((src & PAGE_MASK) + src_offset + len) <= PAGE_SIZE);
124
125 memcpy((void *)(phystokv(dst) + dst_offset),
126 (void *)(phystokv(src) + src_offset), len);
127 }
128
129 /*
130 * pmap_copy_part_lpage copies part of a virtually addressed page
131 * to a physically addressed page.
132 */
133 void
134 pmap_copy_part_lpage(
135 vm_offset_t src,
136 ppnum_t pdst,
137 vm_offset_t dst_offset,
138 vm_size_t len)
139 {
140 vm_offset_t dst;
141
142 assert(src != vm_page_fictitious_addr);
143 assert(pdst != vm_page_fictitious_addr);
144 dst = (vm_offset_t)i386_ptob(pdst);
145 assert(((dst & PAGE_MASK) + dst_offset + len) <= PAGE_SIZE);
146
147 memcpy((void *)(phystokv(dst) + dst_offset), (void *)src, len);
148 }
149
150 /*
151 * pmap_copy_part_rpage copies part of a physically addressed page
152 * to a virtually addressed page.
153 */
154 void
155 pmap_copy_part_rpage(
156 ppnum_t psrc,
157 vm_offset_t src_offset,
158 vm_offset_t dst,
159 vm_size_t len)
160 {
161 vm_offset_t src;
162
163 assert(psrc != vm_page_fictitious_addr);
164 assert(dst != vm_page_fictitious_addr);
165 src = (vm_offset_t)i386_ptob(psrc);
166 assert(((src & PAGE_MASK) + src_offset + len) <= PAGE_SIZE);
167
168 memcpy((void *)dst, (void *)(phystokv(src) + src_offset), len);
169 }
170
171 /*
172 * kvtophys(addr)
173 *
174 * Convert a kernel virtual address to a physical address
175 */
176 vm_offset_t
177 kvtophys(
178 vm_offset_t addr)
179 {
180 pt_entry_t *pte;
181
182 if ((pte = pmap_pte(kernel_pmap, addr)) == PT_ENTRY_NULL)
183 return 0;
184 return i386_trunc_page(*pte) | (addr & INTEL_OFFMASK);
185 }