]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b | 27 | */ |
1c79356b | 28 | #include <zone_debug.h> |
1c79356b A |
29 | #include <mach/boolean.h> |
30 | #include <mach/kern_return.h> | |
31 | #include <mach/mig_errors.h> | |
32 | #include <mach/port.h> | |
33 | #include <mach/vm_param.h> | |
34 | #include <mach/notify.h> | |
2d21ac55 | 35 | //#include <mach/mach_host_server.h> |
1c79356b A |
36 | #include <mach/mach_types.h> |
37 | ||
0a7de745 | 38 | #include <machine/machparam.h> /* spl definitions */ |
1c79356b A |
39 | |
40 | #include <ipc/ipc_port.h> | |
41 | #include <ipc/ipc_space.h> | |
42 | ||
43 | #include <kern/clock.h> | |
44 | #include <kern/spl.h> | |
1c79356b A |
45 | #include <kern/counters.h> |
46 | #include <kern/queue.h> | |
47 | #include <kern/zalloc.h> | |
48 | #include <kern/thread.h> | |
1c79356b A |
49 | #include <kern/task.h> |
50 | #include <kern/sched_prim.h> | |
51 | #include <kern/misc_protos.h> | |
52 | ||
53 | #include <vm/pmap.h> | |
54 | #include <vm/vm_map.h> | |
55 | #include <vm/vm_kern.h> | |
56 | ||
57 | #include <device/device_types.h> | |
58 | #include <device/device_port.h> | |
59 | #include <device/device_server.h> | |
60 | ||
1c79356b A |
61 | #include <machine/machparam.h> |
62 | ||
b0d623f7 | 63 | #if defined(__i386__) || defined(__x86_64__) |
91447636 A |
64 | #include <i386/pmap.h> |
65 | #endif | |
5ba3f43e A |
66 | #if defined(__arm__) || defined(__arm64__) |
67 | #include <arm/pmap.h> | |
68 | #endif | |
a39ff7e2 | 69 | #include <IOKit/IOKitServer.h> |
1c79356b A |
70 | |
71 | #define EXTERN | |
72 | #define MIGEXTERN | |
73 | ||
1c79356b A |
74 | /* |
75 | * Lookup a device by its port. | |
76 | * Doesn't consume the naked send right; produces a device reference. | |
77 | */ | |
cb323159 | 78 | io_object_t |
a39ff7e2 | 79 | iokit_lookup_io_object(ipc_port_t port, ipc_kobject_type_t type) |
1c79356b | 80 | { |
0a7de745 | 81 | io_object_t obj; |
1c79356b | 82 | |
0a7de745 A |
83 | if (!IP_VALID(port)) { |
84 | return NULL; | |
85 | } | |
1c79356b | 86 | |
316670eb | 87 | iokit_lock_port(port); |
a39ff7e2 | 88 | if (ip_active(port) && (ip_kotype(port) == type)) { |
0a7de745 A |
89 | obj = (io_object_t) port->ip_kobject; |
90 | iokit_add_reference( obj, type ); | |
91 | } else { | |
92 | obj = NULL; | |
1c79356b | 93 | } |
1c79356b | 94 | |
316670eb | 95 | iokit_unlock_port(port); |
1c79356b | 96 | |
0a7de745 | 97 | return obj; |
1c79356b A |
98 | } |
99 | ||
100 | MIGEXTERN io_object_t | |
a39ff7e2 | 101 | iokit_lookup_object_port( |
0a7de745 | 102 | ipc_port_t port) |
1c79356b | 103 | { |
0a7de745 | 104 | return iokit_lookup_io_object(port, IKOT_IOKIT_OBJECT); |
a39ff7e2 | 105 | } |
1c79356b | 106 | |
a39ff7e2 A |
107 | MIGEXTERN io_object_t |
108 | iokit_lookup_connect_port( | |
0a7de745 | 109 | ipc_port_t port) |
a39ff7e2 | 110 | { |
0a7de745 | 111 | return iokit_lookup_io_object(port, IKOT_IOKIT_CONNECT); |
1c79356b A |
112 | } |
113 | ||
cb323159 A |
114 | MIGEXTERN io_object_t |
115 | iokit_lookup_uext_object_port( | |
116 | ipc_port_t port) | |
117 | { | |
118 | return iokit_lookup_io_object(port, IKOT_UEXT_OBJECT); | |
119 | } | |
120 | ||
a39ff7e2 A |
121 | static io_object_t |
122 | iokit_lookup_object_in_space_with_port_name(mach_port_name_t name, ipc_kobject_type_t type, ipc_space_t space) | |
1c79356b A |
123 | { |
124 | io_object_t obj = NULL; | |
125 | ||
a39ff7e2 | 126 | if (name && MACH_PORT_VALID(name)) { |
1c79356b A |
127 | ipc_port_t port; |
128 | kern_return_t kr; | |
129 | ||
cb323159 | 130 | kr = ipc_port_translate_send(space, name, &port); |
1c79356b A |
131 | |
132 | if (kr == KERN_SUCCESS) { | |
316670eb | 133 | assert(IP_VALID(port)); |
cb323159 | 134 | require_ip_active(port); |
316670eb A |
135 | ip_reference(port); |
136 | ip_unlock(port); | |
137 | ||
138 | iokit_lock_port(port); | |
cb323159 | 139 | if (ip_kotype(port) == type) { |
316670eb | 140 | obj = (io_object_t) port->ip_kobject; |
a39ff7e2 | 141 | iokit_add_reference(obj, type); |
316670eb A |
142 | } |
143 | iokit_unlock_port(port); | |
144 | ||
145 | ip_release(port); | |
1c79356b A |
146 | } |
147 | } | |
148 | ||
149 | return obj; | |
150 | } | |
151 | ||
152 | EXTERN io_object_t | |
a39ff7e2 | 153 | iokit_lookup_object_with_port_name(mach_port_name_t name, ipc_kobject_type_t type, task_t task) |
1c79356b | 154 | { |
0a7de745 | 155 | return iokit_lookup_object_in_space_with_port_name(name, type, task->itk_space); |
a39ff7e2 A |
156 | } |
157 | ||
158 | EXTERN io_object_t | |
159 | iokit_lookup_connect_ref_current_task(mach_port_name_t name) | |
160 | { | |
0a7de745 | 161 | return iokit_lookup_object_in_space_with_port_name(name, IKOT_IOKIT_CONNECT, current_space()); |
1c79356b A |
162 | } |
163 | ||
cb323159 A |
164 | EXTERN io_object_t |
165 | iokit_lookup_uext_ref_current_task(mach_port_name_t name) | |
166 | { | |
167 | return iokit_lookup_object_in_space_with_port_name(name, IKOT_UEXT_OBJECT, current_space()); | |
168 | } | |
169 | ||
9bccf70c A |
170 | EXTERN void |
171 | iokit_retain_port( ipc_port_t port ) | |
172 | { | |
0a7de745 | 173 | ipc_port_reference( port ); |
9bccf70c A |
174 | } |
175 | ||
176 | EXTERN void | |
177 | iokit_release_port( ipc_port_t port ) | |
178 | { | |
0a7de745 | 179 | ipc_port_release( port ); |
9bccf70c A |
180 | } |
181 | ||
b0d623f7 A |
182 | EXTERN void |
183 | iokit_release_port_send( ipc_port_t port ) | |
184 | { | |
0a7de745 | 185 | ipc_port_release_send( port ); |
b0d623f7 A |
186 | } |
187 | ||
316670eb A |
188 | extern lck_mtx_t iokit_obj_to_port_binding_lock; |
189 | ||
190 | EXTERN void | |
191 | iokit_lock_port( __unused ipc_port_t port ) | |
192 | { | |
0a7de745 | 193 | lck_mtx_lock(&iokit_obj_to_port_binding_lock); |
316670eb A |
194 | } |
195 | ||
196 | EXTERN void | |
197 | iokit_unlock_port( __unused ipc_port_t port ) | |
198 | { | |
0a7de745 | 199 | lck_mtx_unlock(&iokit_obj_to_port_binding_lock); |
316670eb A |
200 | } |
201 | ||
1c79356b A |
202 | /* |
203 | * Get the port for a device. | |
204 | * Consumes a device reference; produces a naked send right. | |
205 | */ | |
a39ff7e2 A |
206 | |
207 | static ipc_port_t | |
208 | iokit_make_port_of_type(io_object_t obj, ipc_kobject_type_t type) | |
1c79356b | 209 | { |
0a7de745 A |
210 | ipc_port_t port; |
211 | ipc_port_t sendPort; | |
1c79356b | 212 | |
0a7de745 A |
213 | if (obj == NULL) { |
214 | return IP_NULL; | |
215 | } | |
1c79356b | 216 | |
0a7de745 A |
217 | port = iokit_port_for_object( obj, type ); |
218 | if (port) { | |
219 | sendPort = ipc_port_make_send( port); | |
220 | iokit_release_port( port ); | |
221 | } else { | |
222 | sendPort = IP_NULL; | |
223 | } | |
1c79356b | 224 | |
0a7de745 | 225 | iokit_remove_reference( obj ); |
1c79356b | 226 | |
0a7de745 | 227 | return sendPort; |
1c79356b A |
228 | } |
229 | ||
230 | MIGEXTERN ipc_port_t | |
a39ff7e2 | 231 | iokit_make_object_port( |
0a7de745 | 232 | io_object_t obj ) |
1c79356b | 233 | { |
0a7de745 | 234 | return iokit_make_port_of_type(obj, IKOT_IOKIT_OBJECT); |
a39ff7e2 | 235 | } |
1c79356b | 236 | |
a39ff7e2 A |
237 | MIGEXTERN ipc_port_t |
238 | iokit_make_connect_port( | |
0a7de745 | 239 | io_object_t obj ) |
a39ff7e2 | 240 | { |
0a7de745 | 241 | return iokit_make_port_of_type(obj, IKOT_IOKIT_CONNECT); |
1c79356b A |
242 | } |
243 | ||
1c79356b A |
244 | int gIOKitPortCount; |
245 | ||
246 | EXTERN ipc_port_t | |
247 | iokit_alloc_object_port( io_object_t obj, ipc_kobject_type_t type ) | |
248 | { | |
cb323159 A |
249 | /* Allocate port, keeping a reference for it. */ |
250 | gIOKitPortCount++; | |
251 | ipc_kobject_alloc_options_t options = IPC_KOBJECT_ALLOC_NSREQUEST; | |
252 | if (type == IKOT_IOKIT_CONNECT) { | |
253 | options |= IPC_KOBJECT_ALLOC_IMMOVABLE_SEND; | |
254 | } | |
255 | return ipc_kobject_alloc_port((ipc_kobject_t) obj, type, options); | |
1c79356b A |
256 | } |
257 | ||
1c79356b A |
258 | EXTERN kern_return_t |
259 | iokit_destroy_object_port( ipc_port_t port ) | |
260 | { | |
0a7de745 A |
261 | iokit_lock_port(port); |
262 | ipc_kobject_set( port, IKO_NULL, IKOT_NONE); | |
1c79356b A |
263 | |
264 | // iokit_remove_reference( obj ); | |
0a7de745 A |
265 | iokit_unlock_port(port); |
266 | ipc_port_dealloc_kernel( port); | |
267 | gIOKitPortCount--; | |
1c79356b | 268 | |
0a7de745 | 269 | return KERN_SUCCESS; |
1c79356b A |
270 | } |
271 | ||
43866e37 A |
272 | EXTERN kern_return_t |
273 | iokit_switch_object_port( ipc_port_t port, io_object_t obj, ipc_kobject_type_t type ) | |
274 | { | |
0a7de745 A |
275 | iokit_lock_port(port); |
276 | ipc_kobject_set( port, (ipc_kobject_t) obj, type); | |
277 | iokit_unlock_port(port); | |
43866e37 | 278 | |
0a7de745 | 279 | return KERN_SUCCESS; |
43866e37 A |
280 | } |
281 | ||
1c79356b A |
282 | EXTERN mach_port_name_t |
283 | iokit_make_send_right( task_t task, io_object_t obj, ipc_kobject_type_t type ) | |
284 | { | |
0a7de745 A |
285 | ipc_port_t port; |
286 | ipc_port_t sendPort; | |
287 | mach_port_name_t name = 0; | |
288 | ||
289 | if (obj == NULL) { | |
290 | return MACH_PORT_NULL; | |
39236c6e | 291 | } |
1c79356b | 292 | |
0a7de745 A |
293 | port = iokit_port_for_object( obj, type ); |
294 | if (port) { | |
295 | sendPort = ipc_port_make_send( port); | |
296 | iokit_release_port( port ); | |
297 | } else { | |
298 | sendPort = IP_NULL; | |
299 | } | |
300 | ||
301 | if (IP_VALID( sendPort )) { | |
302 | kern_return_t kr; | |
cb323159 A |
303 | // Remove once <rdar://problem/45522961> is fixed. |
304 | // We need to make ith_knote NULL as ipc_object_copyout() uses | |
305 | // thread-argument-passing and its value should not be garbage | |
306 | current_thread()->ith_knote = ITH_KNOTE_NULL; | |
307 | kr = ipc_object_copyout( task->itk_space, ip_to_object(sendPort), | |
308 | MACH_MSG_TYPE_PORT_SEND, NULL, NULL, &name); | |
0a7de745 A |
309 | if (kr != KERN_SUCCESS) { |
310 | ipc_port_release_send( sendPort ); | |
311 | name = MACH_PORT_NULL; | |
312 | } | |
313 | } else if (sendPort == IP_NULL) { | |
314 | name = MACH_PORT_NULL; | |
315 | } else if (sendPort == IP_DEAD) { | |
316 | name = MACH_PORT_DEAD; | |
317 | } | |
318 | ||
319 | return name; | |
1c79356b A |
320 | } |
321 | ||
91447636 A |
322 | EXTERN kern_return_t |
323 | iokit_mod_send_right( task_t task, mach_port_name_t name, mach_port_delta_t delta ) | |
324 | { | |
0a7de745 | 325 | return mach_port_mod_refs( task->itk_space, name, MACH_PORT_RIGHT_SEND, delta ); |
91447636 A |
326 | } |
327 | ||
1c79356b A |
328 | /* |
329 | * Handle the No-More_Senders notification generated from a device port destroy. | |
330 | * Since there are no longer any tasks which hold a send right to this device | |
0a7de745 | 331 | * port a NMS notification has been generated. |
1c79356b A |
332 | */ |
333 | ||
334 | static void | |
335 | iokit_no_senders( mach_no_senders_notification_t * notification ) | |
336 | { | |
0a7de745 A |
337 | ipc_port_t port; |
338 | io_object_t obj = NULL; | |
339 | ipc_kobject_type_t type = IKOT_NONE; | |
340 | ipc_port_t notify; | |
1c79356b | 341 | |
cb323159 | 342 | port = notification->not_header.msgh_remote_port; |
9bccf70c | 343 | |
0a7de745 A |
344 | // convert a port to io_object_t. |
345 | if (IP_VALID(port)) { | |
346 | iokit_lock_port(port); | |
316670eb | 347 | if (ip_active(port)) { |
0a7de745 A |
348 | obj = (io_object_t) port->ip_kobject; |
349 | type = ip_kotype( port ); | |
350 | if ((IKOT_IOKIT_OBJECT == type) | |
351 | || (IKOT_IOKIT_CONNECT == type) | |
cb323159 A |
352 | || (IKOT_IOKIT_IDENT == type) |
353 | || (IKOT_UEXT_OBJECT == type)) { | |
0a7de745 A |
354 | iokit_add_reference( obj, IKOT_IOKIT_OBJECT ); |
355 | } else { | |
356 | obj = NULL; | |
357 | } | |
316670eb | 358 | } |
0a7de745 A |
359 | iokit_unlock_port(port); |
360 | ||
361 | if (obj) { | |
362 | mach_port_mscount_t mscount = notification->not_count; | |
363 | ||
364 | if (KERN_SUCCESS != iokit_client_died( obj, port, type, &mscount )) { | |
365 | /* Re-request no-senders notifications on the port (if still active) */ | |
366 | ip_lock(port); | |
367 | if (ip_active(port)) { | |
368 | notify = ipc_port_make_sonce_locked(port); | |
369 | ipc_port_nsrequest( port, mscount + 1, notify, ¬ify); | |
370 | /* port unlocked */ | |
371 | if (notify != IP_NULL) { | |
372 | ipc_port_release_sonce(notify); | |
373 | } | |
374 | } else { | |
375 | ip_unlock(port); | |
376 | } | |
377 | } | |
378 | iokit_remove_reference( obj ); | |
379 | } | |
380 | } | |
1c79356b A |
381 | } |
382 | ||
383 | ||
384 | EXTERN | |
385 | boolean_t | |
386 | iokit_notify( mach_msg_header_t * msg ) | |
387 | { | |
0a7de745 A |
388 | switch (msg->msgh_id) { |
389 | case MACH_NOTIFY_NO_SENDERS: | |
390 | iokit_no_senders((mach_no_senders_notification_t *) msg); | |
391 | return TRUE; | |
392 | ||
393 | case MACH_NOTIFY_PORT_DELETED: | |
394 | case MACH_NOTIFY_PORT_DESTROYED: | |
395 | case MACH_NOTIFY_SEND_ONCE: | |
396 | case MACH_NOTIFY_DEAD_NAME: | |
397 | default: | |
398 | printf("iokit_notify: strange notification %d\n", msg->msgh_id); | |
399 | return FALSE; | |
400 | } | |
1c79356b A |
401 | } |
402 | ||
55e303ae | 403 | /* need to create a pmap function to generalize */ |
0a7de745 A |
404 | unsigned int |
405 | IODefaultCacheBits(addr64_t pa) | |
de355530 | 406 | { |
0a7de745 | 407 | return pmap_cache_attributes((ppnum_t)(pa >> PAGE_SHIFT)); |
9bccf70c | 408 | } |
9bccf70c | 409 | |
0a7de745 A |
410 | kern_return_t |
411 | IOMapPages(vm_map_t map, mach_vm_address_t va, mach_vm_address_t pa, | |
412 | mach_vm_size_t length, unsigned int options) | |
1c79356b | 413 | { |
0a7de745 A |
414 | vm_prot_t prot; |
415 | unsigned int flags; | |
416 | ppnum_t pagenum; | |
417 | pmap_t pmap = map->pmap; | |
1c79356b | 418 | |
0a7de745 A |
419 | prot = (options & kIOMapReadOnly) |
420 | ? VM_PROT_READ : (VM_PROT_READ | VM_PROT_WRITE); | |
1c79356b | 421 | |
0a7de745 | 422 | pagenum = (ppnum_t)atop_64(pa); |
55e303ae | 423 | |
0a7de745 | 424 | switch (options & kIOMapCacheMask) { /* What cache mode do we need? */ |
55e303ae A |
425 | case kIOMapDefaultCache: |
426 | default: | |
0a7de745 A |
427 | flags = IODefaultCacheBits(pa); |
428 | break; | |
55e303ae A |
429 | |
430 | case kIOMapInhibitCache: | |
0a7de745 A |
431 | flags = VM_WIMG_IO; |
432 | break; | |
55e303ae A |
433 | |
434 | case kIOMapWriteThruCache: | |
0a7de745 A |
435 | flags = VM_WIMG_WTHRU; |
436 | break; | |
55e303ae | 437 | |
0c530ab8 | 438 | case kIOMapWriteCombineCache: |
0a7de745 A |
439 | flags = VM_WIMG_WCOMB; |
440 | break; | |
55e303ae A |
441 | |
442 | case kIOMapCopybackCache: | |
0a7de745 A |
443 | flags = VM_WIMG_COPYBACK; |
444 | break; | |
5ba3f43e | 445 | |
316670eb | 446 | case kIOMapCopybackInnerCache: |
0a7de745 A |
447 | flags = VM_WIMG_INNERWBACK; |
448 | break; | |
5ba3f43e A |
449 | |
450 | case kIOMapPostedWrite: | |
0a7de745 A |
451 | flags = VM_WIMG_POSTED; |
452 | break; | |
cb323159 A |
453 | |
454 | case kIOMapRealTimeCache: | |
455 | flags = VM_WIMG_RT; | |
456 | break; | |
0a7de745 | 457 | } |
1c79356b | 458 | |
0a7de745 | 459 | pmap_set_cache_attributes(pagenum, flags); |
6d2010ae | 460 | |
0a7de745 | 461 | vm_map_set_cache_attr(map, (vm_map_offset_t)va); |
6d2010ae A |
462 | |
463 | ||
0a7de745 A |
464 | // Set up a block mapped area |
465 | return pmap_map_block(pmap, va, pagenum, (uint32_t) atop_64(round_page_64(length)), prot, 0, 0); | |
0c530ab8 A |
466 | } |
467 | ||
0a7de745 A |
468 | kern_return_t |
469 | IOUnmapPages(vm_map_t map, mach_vm_address_t va, mach_vm_size_t length) | |
0c530ab8 | 470 | { |
0a7de745 | 471 | pmap_t pmap = map->pmap; |
0c530ab8 | 472 | |
0a7de745 | 473 | pmap_remove(pmap, trunc_page_64(va), round_page_64(va + length)); |
0c530ab8 | 474 | |
0a7de745 | 475 | return KERN_SUCCESS; |
0c530ab8 A |
476 | } |
477 | ||
0a7de745 A |
478 | kern_return_t |
479 | IOProtectCacheMode(vm_map_t __unused map, mach_vm_address_t __unused va, | |
480 | mach_vm_size_t __unused length, unsigned int __unused options) | |
0c530ab8 | 481 | { |
0a7de745 A |
482 | mach_vm_size_t off; |
483 | vm_prot_t prot; | |
484 | unsigned int flags; | |
485 | pmap_t pmap = map->pmap; | |
486 | pmap_flush_context pmap_flush_context_storage; | |
487 | boolean_t delayed_pmap_flush = FALSE; | |
488 | ||
489 | prot = (options & kIOMapReadOnly) | |
490 | ? VM_PROT_READ : (VM_PROT_READ | VM_PROT_WRITE); | |
491 | ||
492 | switch (options & kIOMapCacheMask) { | |
2d21ac55 | 493 | // what cache mode do we need? |
0c530ab8 A |
494 | case kIOMapDefaultCache: |
495 | default: | |
0a7de745 | 496 | return KERN_INVALID_ARGUMENT; |
0c530ab8 A |
497 | |
498 | case kIOMapInhibitCache: | |
0a7de745 A |
499 | flags = VM_WIMG_IO; |
500 | break; | |
0c530ab8 A |
501 | |
502 | case kIOMapWriteThruCache: | |
0a7de745 A |
503 | flags = VM_WIMG_WTHRU; |
504 | break; | |
4452a7af | 505 | |
0c530ab8 | 506 | case kIOMapWriteCombineCache: |
0a7de745 A |
507 | flags = VM_WIMG_WCOMB; |
508 | break; | |
0c530ab8 A |
509 | |
510 | case kIOMapCopybackCache: | |
0a7de745 A |
511 | flags = VM_WIMG_COPYBACK; |
512 | break; | |
5ba3f43e A |
513 | |
514 | case kIOMapCopybackInnerCache: | |
0a7de745 A |
515 | flags = VM_WIMG_INNERWBACK; |
516 | break; | |
5ba3f43e A |
517 | |
518 | case kIOMapPostedWrite: | |
0a7de745 A |
519 | flags = VM_WIMG_POSTED; |
520 | break; | |
cb323159 A |
521 | |
522 | case kIOMapRealTimeCache: | |
523 | flags = VM_WIMG_RT; | |
524 | break; | |
39236c6e | 525 | } |
55e303ae | 526 | |
0a7de745 A |
527 | pmap_flush_context_init(&pmap_flush_context_storage); |
528 | delayed_pmap_flush = FALSE; | |
529 | ||
530 | // enter each page's physical address in the target map | |
531 | for (off = 0; off < length; off += page_size) { | |
532 | ppnum_t ppnum = pmap_find_phys(pmap, va + off); | |
533 | if (ppnum) { | |
534 | pmap_enter_options(pmap, va + off, ppnum, prot, VM_PROT_NONE, flags, TRUE, | |
535 | PMAP_OPTIONS_NOFLUSH, (void *)&pmap_flush_context_storage); | |
536 | delayed_pmap_flush = TRUE; | |
537 | } | |
538 | } | |
539 | if (delayed_pmap_flush == TRUE) { | |
540 | pmap_flush(&pmap_flush_context_storage); | |
541 | } | |
542 | ||
543 | return KERN_SUCCESS; | |
1c79356b A |
544 | } |
545 | ||
0a7de745 A |
546 | ppnum_t |
547 | IOGetLastPageNumber(void) | |
e3027f41 | 548 | { |
6d2010ae | 549 | #if __i386__ || __x86_64__ |
0a7de745 | 550 | ppnum_t lastPage, highest = 0; |
6d2010ae A |
551 | unsigned int idx; |
552 | ||
0a7de745 | 553 | for (idx = 0; idx < pmap_memory_region_count; idx++) { |
6d2010ae | 554 | lastPage = pmap_memory_regions[idx].end - 1; |
0a7de745 | 555 | if (lastPage > highest) { |
6d2010ae | 556 | highest = lastPage; |
0a7de745 | 557 | } |
6d2010ae | 558 | } |
0a7de745 | 559 | return highest; |
5ba3f43e A |
560 | #elif __arm__ || __arm64__ |
561 | return 0; | |
0c530ab8 | 562 | #else |
6d2010ae | 563 | #error unknown arch |
0c530ab8 | 564 | #endif |
6601e61a | 565 | } |
4452a7af | 566 | |
0c530ab8 | 567 | |
1c79356b | 568 | void IOGetTime( mach_timespec_t * clock_time); |
0a7de745 A |
569 | void |
570 | IOGetTime( mach_timespec_t * clock_time) | |
1c79356b | 571 | { |
b0d623f7 A |
572 | clock_sec_t sec; |
573 | clock_nsec_t nsec; | |
574 | clock_get_system_nanotime(&sec, &nsec); | |
575 | clock_time->tv_sec = (typeof(clock_time->tv_sec))sec; | |
576 | clock_time->tv_nsec = nsec; | |
1c79356b | 577 | } |