"Initial check in for Widevine Third Party source"

git-svn-id: https://widevine-mirrored-source.googlecode.com/svn/trunk@8927 8780d7d1-120b-16fd-4e4d-63eabaf331ad
diff --git a/xnu-792.18.15/osfmk/device/Makefile b/xnu-792.18.15/osfmk/device/Makefile
new file mode 100644
index 0000000..f856dae
--- /dev/null
+++ b/xnu-792.18.15/osfmk/device/Makefile
@@ -0,0 +1,57 @@
+export MakeInc_cmd=${SRCROOT}/makedefs/MakeInc.cmd
+export MakeInc_def=${SRCROOT}/makedefs/MakeInc.def
+export MakeInc_rule=${SRCROOT}/makedefs/MakeInc.rule
+export MakeInc_dir=${SRCROOT}/makedefs/MakeInc.dir
+
+
+include $(MakeInc_cmd)
+include $(MakeInc_def)
+
+MIG_DEFS =	\
+	device.defs
+
+MIG_HDRS = \
+
+DATAFILES = \
+	device_types.h device_port.h device_types.defs \
+	${MIG_DEFS}
+
+MIGINCLUDES = \
+
+INSTALL_MI_LIST	= ${DATAFILES} ${_MIG_HDRS_} ${MIGINCLUDES}
+
+INSTALL_MI_DIR = device
+
+EXPORT_MI_LIST	= ${DATAFILES} ${_MIG_HDRS_} ${MIGINCLUDES}
+
+EXPORT_MI_DIR = device
+
+.ORDER: ${MIG_HDRS} ${MIGINCLUDES}
+
+#
+# Build path
+#       
+INCFLAGS_MAKEFILE= -I..
+
+MIGKSFLAGS	= -DMACH_KERNEL_PRIVATE -DKERNEL_SERVER=1
+MIGKUFLAGS	= -DMACH_KERNEL_PRIVATE -DKERNEL_USER=1
+
+DEVICE_FILES    = device_server.h device_server.c
+
+COMP_FILES	= ${DEVICE_FILES}
+
+.ORDER: ${DEVICE_FILES}
+
+${DEVICE_FILES}: device.defs
+	${MIG} ${MIGFLAGS} ${MIGKSFLAGS}	\
+	-header /dev/null			\
+	-user /dev/null				\
+	-sheader device_server.h		\
+	-server device_server.c			\
+	$<
+
+
+include $(MakeInc_rule)
+include $(MakeInc_dir)
+
+
diff --git a/xnu-792.18.15/osfmk/device/device.defs b/xnu-792.18.15/osfmk/device/device.defs
new file mode 100644
index 0000000..54067d2
--- /dev/null
+++ b/xnu-792.18.15/osfmk/device/device.defs
@@ -0,0 +1,513 @@
+/*
+ * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ * 
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ */
+/*
+ * @OSF_COPYRIGHT@
+ */
+/* 
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989 Carnegie Mellon University
+ * All Rights Reserved.
+ * 
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ * 
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ * 
+ * Carnegie Mellon requests users of this software to return to
+ * 
+ *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
+ *  School of Computer Science
+ *  Carnegie Mellon University
+ *  Pittsburgh PA 15213-3890
+ * 
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+/*
+ * File:	device/device.defs
+ * Author:	Douglas Orr
+ *		Feb 10, 1988
+ * Abstract:
+ *	Mach device support.  Mach devices are accessed through
+ *	block and character device interfaces to the kernel.
+ */
+
+subsystem
+#if	KERNEL_SERVER
+	  KernelServer
+#endif	/* KERNEL_SERVER */
+		       iokit 2800;
+
+#include <mach/std_types.defs>
+#include <mach/mach_types.defs>
+#include <mach/clock_types.defs>
+#include <mach/clock_types.defs>
+
+import <device/device_types.h>;
+
+serverprefix	is_;
+
+type reply_port_t = MACH_MSG_TYPE_MAKE_SEND_ONCE | polymorphic
+	ctype: mach_port_t;
+
+#if	IOKIT
+
+type io_name_t          = c_string[*:128];
+type io_string_t        = c_string[*:512];
+type io_struct_inband_t = array[*:4096] of char;
+type io_scalar_inband_t = array[*:16] of int;
+type io_async_ref_t 	= array[*:8] of natural_t;
+type io_buf_ptr_t	= ^array[] of MACH_MSG_TYPE_INTEGER_8;
+type NDR_record_t       = struct[8] of char;
+
+type io_object_t = mach_port_t
+		ctype: mach_port_t
+#if	KERNEL_SERVER
+		intran: io_object_t iokit_lookup_object_port(mach_port_t)
+		outtran: mach_port_t iokit_make_object_port(io_object_t)
+		destructor: iokit_remove_reference(io_object_t)
+#endif	/* KERNEL_SERVER */
+		;
+
+type io_connect_t = mach_port_t
+		ctype: mach_port_t
+#if	KERNEL_SERVER
+		intran: io_connect_t iokit_lookup_connect_port(mach_port_t)
+		outtran: mach_port_t iokit_make_connect_port(io_connect_t)
+		destructor: iokit_remove_reference(io_connect_t)
+#endif	/* KERNEL_SERVER */
+		;
+
+routine io_object_get_class(
+	    object		: io_object_t;
+	out className		: io_name_t
+	);
+
+routine io_object_conforms_to(
+	    object		: io_object_t;
+	in  className		: io_name_t;
+	out conforms		: boolean_t
+	);
+
+routine io_iterator_next(
+	    iterator		: io_object_t;
+	out object		: io_object_t
+	);
+
+routine io_iterator_reset(
+	    iterator		: io_object_t
+	);
+
+routine io_service_get_matching_services(
+	    master_port		: mach_port_t;
+	in  matching		: io_string_t;
+	out existing		: io_object_t
+	);
+
+routine io_registry_entry_get_property(
+	    registry_entry	: io_object_t;
+	in  property_name	: io_name_t;
+	out properties		: io_buf_ptr_t, physicalcopy
+	);
+
+routine io_registry_create_iterator(
+	    master_port		: mach_port_t;
+	in  plane		: io_name_t;
+	in  options		: int;
+	out iterator		: io_object_t
+	);
+
+routine io_registry_iterator_enter_entry(
+	    iterator		: io_object_t
+	);
+
+routine io_registry_iterator_exit_entry(
+	    iterator		: io_object_t
+	);
+
+routine io_registry_entry_from_path(
+	    master_port		: mach_port_t;
+	in  path		: io_string_t;
+	out registry_entry	: io_object_t
+	);
+
+routine io_registry_entry_get_name(
+	    registry_entry	: io_object_t;
+	out name		: io_name_t
+	);
+
+routine io_registry_entry_get_properties(
+	    registry_entry	: io_object_t;
+	out properties		: io_buf_ptr_t, physicalcopy
+	);
+
+routine io_registry_entry_get_property_bytes(
+	    registry_entry	: io_object_t;
+	in  property_name	: io_name_t;
+	out data		: io_struct_inband_t, CountInOut
+	);
+
+routine io_registry_entry_get_child_iterator(
+	    registry_entry	: io_object_t;
+	in  plane		: io_name_t;
+	out iterator		: io_object_t
+	);
+
+routine io_registry_entry_get_parent_iterator(
+	    registry_entry	: io_object_t;
+	in  plane		: io_name_t;
+	out iterator		: io_object_t
+	);
+
+routine io_service_open(
+	    service		: io_object_t;
+	in  owningTask		: task_t;
+	in  connect_type	: int;
+	out connection		: io_connect_t
+	);
+
+routine io_service_close(
+	    connection		: io_connect_t
+	);
+
+routine io_connect_get_service(
+	    connection		: io_connect_t;
+	out service		: io_object_t
+	);
+
+routine io_connect_set_notification_port(
+	    connection		: io_connect_t;
+	in  notification_type	: int;
+	in  port		: mach_port_make_send_t;
+	in  reference		: int
+	);
+
+routine io_connect_map_memory(
+	    connection		: io_connect_t;
+	in  memory_type		: int;
+	in  into_task		: task_t;
+	inout address		: vm_address_t;
+	inout size		: vm_size_t;
+	in  flags		: int
+	);
+
+routine io_connect_add_client(
+	    connection		: io_connect_t;
+	in  connect_to		: io_connect_t
+	);
+
+routine io_connect_set_properties(
+	    connection		: io_connect_t;
+	in  properties		: io_buf_ptr_t, physicalcopy;
+        out result		: natural_t
+	);
+
+
+routine io_connect_method_scalarI_scalarO(
+	    connection		: io_connect_t;
+	in  selector		: int;
+	in  input		: io_scalar_inband_t;
+	out output		: io_scalar_inband_t, CountInOut
+	);
+
+routine io_connect_method_scalarI_structureO(
+	    connection		: io_connect_t;
+	in  selector		: int;
+	in  input		: io_scalar_inband_t;
+	out output		: io_struct_inband_t, CountInOut
+	);
+
+routine io_connect_method_scalarI_structureI(
+	    connection		: io_connect_t;
+	in  selector		: int;
+	in  input		: io_scalar_inband_t;
+	in  inputStruct		: io_struct_inband_t
+	);
+
+routine io_connect_method_structureI_structureO(
+	    connection		: io_connect_t;
+	in  selector		: int;
+	in  input		: io_struct_inband_t;
+	out output		: io_struct_inband_t, CountInOut
+	);
+
+routine io_registry_entry_get_path(
+	    registry_entry	: io_object_t;
+	in  plane		: io_name_t;
+	out path		: io_string_t
+	);
+
+routine io_registry_get_root_entry(
+	    master_port		: mach_port_t;
+	out root		: io_object_t
+	);
+
+routine io_registry_entry_set_properties(
+	    registry_entry	: io_object_t;
+	in  properties		: io_buf_ptr_t, physicalcopy;
+        out result		: natural_t
+	);
+
+routine io_registry_entry_in_plane(
+	    registry_entry	: io_object_t;
+	in  plane		: io_name_t;
+	out inPlane		: boolean_t
+	);
+
+routine io_object_get_retain_count(
+	    object		: io_object_t;
+	out retainCount		: int
+	);
+
+routine io_service_get_busy_state(
+	    service		: io_object_t;
+	out busyState		: int
+	);
+
+routine io_service_wait_quiet(
+	    service		: io_object_t;
+	    wait_time		: mach_timespec_t
+	);
+
+routine io_registry_entry_create_iterator(
+	    registry_entry	: io_object_t;
+	in  plane		: io_name_t;
+	in  options		: int;
+	out iterator		: io_object_t
+	);
+
+routine io_iterator_is_valid(
+	    iterator		: io_object_t;
+	out is_valid		: boolean_t
+	);
+
+routine io_make_matching(
+	    master_port		: mach_port_t;
+	in  of_type		: int;
+	in  options		: int;
+	in  input		: io_struct_inband_t;
+	out matching		: io_string_t
+	);
+
+routine io_catalog_send_data(
+	    master_port		: mach_port_t;
+        in  flag                : int;
+	in  inData		: io_buf_ptr_t;
+        out result		: natural_t
+	);
+
+routine io_catalog_terminate(
+	    master_port		: mach_port_t;
+        in  flag                : int;
+	in  name		: io_name_t
+	);
+
+routine io_catalog_get_data(
+	    master_port		: mach_port_t;
+        in  flag                : int;
+	out outData		: io_buf_ptr_t
+	);
+
+routine io_catalog_get_gen_count(
+	    master_port		: mach_port_t;
+        out genCount            : int
+	);
+
+routine io_catalog_module_loaded(
+	    master_port		: mach_port_t;
+	in  name		: io_name_t
+	);
+
+routine io_catalog_reset(
+	    master_port		: mach_port_t;
+	in  flag		: int
+	);
+
+routine io_service_request_probe(
+	    service		: io_object_t;
+	in  options		: int
+	);
+
+routine io_registry_entry_get_name_in_plane(
+	    registry_entry	: io_object_t;
+	in  plane		: io_name_t;
+	out name		: io_name_t
+	);
+
+routine io_service_match_property_table(
+	    service		: io_object_t;
+	in  matching		: io_string_t;
+	out matches		: boolean_t
+	);
+
+routine io_async_method_scalarI_scalarO(
+	    connection		: io_connect_t;
+	in  wake_port		: mach_port_make_send_t;
+	in  reference		: io_async_ref_t;
+	in  selector		: int;
+	in  input		: io_scalar_inband_t;
+	out output		: io_scalar_inband_t, CountInOut
+	);
+
+routine io_async_method_scalarI_structureO(
+	    connection		: io_connect_t;
+	in  wake_port		: mach_port_make_send_t;
+	in  reference		: io_async_ref_t;
+	in  selector		: int;
+	in  input		: io_scalar_inband_t;
+	out output		: io_struct_inband_t, CountInOut
+	);
+
+routine io_async_method_scalarI_structureI(
+	    connection		: io_connect_t;
+	in  wake_port		: mach_port_make_send_t;
+	in  reference		: io_async_ref_t;
+	in  selector		: int;
+	in  input		: io_scalar_inband_t;
+	in  inputStruct		: io_struct_inband_t
+	);
+
+routine io_async_method_structureI_structureO(
+	    connection		: io_connect_t;
+	in  wake_port		: mach_port_make_send_t;
+	in  reference		: io_async_ref_t;
+	in  selector		: int;
+	in  input		: io_struct_inband_t;
+	out output		: io_struct_inband_t, CountInOut
+	);
+
+routine io_service_add_notification(
+	    master_port		: mach_port_t;
+	in  notification_type	: io_name_t;
+	in  matching		: io_string_t;
+	in  wake_port		: mach_port_make_send_t;
+	in  reference		: io_async_ref_t;
+	out notification	: io_object_t
+	);
+
+routine io_service_add_interest_notification(
+	    service		: io_object_t;
+	in  type_of_interest	: io_name_t;
+	in  wake_port		: mach_port_make_send_t;
+	in  reference		: io_async_ref_t;
+	out notification	: io_object_t
+	);
+
+routine io_service_acknowledge_notification(
+	    service		: io_object_t;
+	in  notify_ref		: natural_t;
+	in  response		: natural_t
+	);
+
+routine io_connect_get_notification_semaphore(
+	    connection		: io_connect_t;
+	in  notification_type	: natural_t;
+	out semaphore		: semaphore_t
+	);
+
+routine io_connect_unmap_memory(
+	    connection		: io_connect_t;
+	in  memory_type		: int;
+	in  into_task		: task_t;
+	in  address		: vm_address_t
+	);
+
+routine io_registry_entry_get_location_in_plane(
+	    registry_entry	: io_object_t;
+	in  plane		: io_name_t;
+	out location		: io_name_t
+	);
+
+routine io_registry_entry_get_property_recursively(
+	    registry_entry	: io_object_t;
+	in  plane		: io_name_t;
+	in  property_name	: io_name_t;
+	in  options		: int;
+	out properties		: io_buf_ptr_t, physicalcopy
+	);
+
+
+routine io_service_get_state(
+	    service		: io_object_t;
+	out state		: uint64_t
+	);
+
+routine io_service_get_matching_services_ool(
+	    master_port		: mach_port_t;
+	in  matching		: io_buf_ptr_t, physicalcopy;
+        out result		: natural_t;
+	out existing		: io_object_t
+	);
+
+routine io_service_match_property_table_ool(
+	    service		: io_object_t;
+	in  matching		: io_buf_ptr_t, physicalcopy;
+        out result		: natural_t;
+	out matches		: boolean_t
+	);
+
+routine io_service_add_notification_ool(
+	    master_port		: mach_port_t;
+	in  notification_type	: io_name_t;
+	in  matching		: io_buf_ptr_t, physicalcopy;
+	in  wake_port		: mach_port_make_send_t;
+	in  reference		: io_async_ref_t;
+        out result		: natural_t;
+	out notification	: io_object_t
+	);
+
+routine io_object_get_superclass(
+	    master_port		: mach_port_t;
+	in  obj_name			: io_name_t;
+	out class_name          : io_name_t   
+        );
+
+routine io_object_get_bundle_identifier(
+	    master_port		: mach_port_t;
+	in  obj_name			: io_name_t;
+	out class_name          : io_name_t   
+        );
+
+routine io_service_open_extended(
+	    service		: io_object_t;
+	in  owningTask		: task_t;
+	in  connect_type	: int;
+	in  ndr			: NDR_record_t;
+	in  properties		: io_buf_ptr_t, physicalcopy;
+        out result		: natural_t;
+	out connection		: io_connect_t
+	);
+
+#endif
+
+
diff --git a/xnu-792.18.15/osfmk/device/device_init.c b/xnu-792.18.15/osfmk/device/device_init.c
new file mode 100644
index 0000000..05e76bc
--- /dev/null
+++ b/xnu-792.18.15/osfmk/device/device_init.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ * 
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ */
+/*
+ * @OSF_COPYRIGHT@
+ */
+/* 
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989 Carnegie Mellon University
+ * All Rights Reserved.
+ * 
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ * 
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ * 
+ * Carnegie Mellon requests users of this software to return to
+ * 
+ *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
+ *  School of Computer Science
+ *  Carnegie Mellon University
+ *  Pittsburgh PA 15213-3890
+ * 
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+/*
+ */
+/*
+ *	Author: David B. Golub, Carnegie Mellon University
+ *	Date: 	8/89
+ *
+ * 	Initialize device service as part of kernel task.
+ */
+
+#include <mach/mach_types.h>
+#include <mach/port.h>
+
+#include <ipc/ipc_types.h>
+#include <ipc/ipc_port.h>
+#include <ipc/ipc_space.h>
+
+#include <kern/kern_types.h>
+#include <kern/host.h>
+#include <kern/ipc_kobject.h>
+#include <kern/startup.h>
+#include <kern/task.h>
+#include <kern/misc_protos.h>
+
+#include <device/device_types.h>
+#include <device/device_port.h>
+
+ipc_port_t	master_device_port;
+
+void
+device_service_create(void)
+{
+	master_device_port = ipc_port_alloc_kernel();
+	if (master_device_port == IP_NULL)
+	    panic("can't allocate master device port");
+
+	ipc_kobject_set(master_device_port, 1, IKOT_MASTER_DEVICE);
+	kernel_set_special_port(host_priv_self(), HOST_IO_MASTER_PORT,
+				ipc_port_make_send(master_device_port));
+
+#if 0
+	ds_init();
+	net_io_init();
+	device_pager_init();
+	datadev_init();
+
+	(void) kernel_thread(kernel_task, io_done_thread, (char *)0);
+	(void) kernel_thread(kernel_task, net_thread, (char *)0);
+#endif
+}
diff --git a/xnu-792.18.15/osfmk/device/device_port.h b/xnu-792.18.15/osfmk/device/device_port.h
new file mode 100644
index 0000000..8948ed5
--- /dev/null
+++ b/xnu-792.18.15/osfmk/device/device_port.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ * 
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ */
+/*
+ * @OSF_COPYRIGHT@
+ */
+/* 
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989 Carnegie Mellon University
+ * All Rights Reserved.
+ * 
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ * 
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ * 
+ * Carnegie Mellon requests users of this software to return to
+ * 
+ *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
+ *  School of Computer Science
+ *  Carnegie Mellon University
+ *  Pittsburgh PA 15213-3890
+ * 
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+/*
+ */
+/*
+ *	Author: David B. Golub, Carnegie Mellon University
+ *	Date: 	8/89
+ */
+
+#ifndef	_DEVICE_DEVICE_PORT_H_
+#define	_DEVICE_DEVICE_PORT_H_
+
+#include <device/device_types.h>
+
+/*
+ *	Master privileged I/O object for this host
+ */
+extern mach_port_t	master_device_port;
+
+#define DEVICE_PAGER_GUARDED		0x1
+#define DEVICE_PAGER_COHERENT		0x2
+#define DEVICE_PAGER_CACHE_INHIB	0x4
+#define DEVICE_PAGER_WRITE_THROUGH	0x8
+#define DEVICE_PAGER_CONTIGUOUS		0x100
+#define DEVICE_PAGER_NOPHYSCACHE	0x200
+
+#endif	/* _DEVICE_DEVICE_PORT_H_ */
diff --git a/xnu-792.18.15/osfmk/device/device_types.defs b/xnu-792.18.15/osfmk/device/device_types.defs
new file mode 100644
index 0000000..788ab01
--- /dev/null
+++ b/xnu-792.18.15/osfmk/device/device_types.defs
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2002,2000 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ * 
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ */
+/*
+ * @OSF_COPYRIGHT@
+ */
+/* 
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989 Carnegie Mellon University
+ * All Rights Reserved.
+ * 
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ * 
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ * 
+ * Carnegie Mellon requests users of this software to return to
+ * 
+ *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
+ *  School of Computer Science
+ *  Carnegie Mellon University
+ *  Pittsburgh PA 15213-3890
+ * 
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+/*
+ */
+/*
+ *	Author: David B. Golub, Carnegie Mellon University
+ *	Date: 	3/89
+ *	
+ *	Common definitions for device interface types.
+ */
+
+#ifndef	_DEVICE_DEVICE_TYPES_DEFS_
+#define	_DEVICE_DEVICE_TYPES_DEFS_
+
+/*
+ *	Basic types
+ */
+
+#include <mach/std_types.defs>
+#include <mach/mach_types.defs>
+
+type recnum_t		= uint32_t;
+type dev_mode_t		= uint32_t;
+type dev_flavor_t	= uint32_t;
+type dev_name_t         = c_string[*:128];
+type dev_status_t	= array[*:1024] of int;
+type io_buf_len_t	= integer_t;
+type io_buf_ptr_t	= ^array[] of MACH_MSG_TYPE_INTEGER_8;
+type io_buf_ptr_inband_t= array[*:128] of char;
+type filter_t		= short;
+type filter_array_t	= array[*:64] of filter_t;
+
+type device_t = mach_port_t
+		ctype: mach_port_t
+#if	KERNEL_SERVER
+		intran: device_t dev_port_lookup(mach_port_t)
+		outtran: mach_port_t convert_device_to_port(device_t)
+		destructor: device_deallocate(device_t)
+#endif	/* KERNEL_SERVER */
+		;
+
+type io_done_queue_t	= mach_port_t
+		ctype: mach_port_t
+#if	KERNEL_SERVER
+		intran: io_done_queue_t io_done_queue_port_lookup(mach_port_t)
+		outtran: mach_port_t convert_io_done_queue_to_port(io_done_queue_t)
+#endif	/* KERNEL_SERVER */
+		;
+
+import <device/device_types.h>;
+
+#endif	/* _DEVICE_DEVICE_TYPES_DEFS_ */
diff --git a/xnu-792.18.15/osfmk/device/device_types.h b/xnu-792.18.15/osfmk/device/device_types.h
new file mode 100644
index 0000000..0c0eb01
--- /dev/null
+++ b/xnu-792.18.15/osfmk/device/device_types.h
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ * 
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ */
+/*
+ * @OSF_COPYRIGHT@
+ */
+/* 
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989 Carnegie Mellon University
+ * All Rights Reserved.
+ * 
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ * 
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ * 
+ * Carnegie Mellon requests users of this software to return to
+ * 
+ *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
+ *  School of Computer Science
+ *  Carnegie Mellon University
+ *  Pittsburgh PA 15213-3890
+ * 
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+/*
+ */
+/*
+ *	Author: David B. Golub, Carnegie Mellon University
+ *	Date: 	3/89
+ */
+
+#ifndef	DEVICE_TYPES_H
+#define	DEVICE_TYPES_H
+
+/*
+ * Types for device interface.
+ */
+#include <mach/std_types.h>
+#include <mach/mach_types.h>
+#include <mach/message.h>
+#include <mach/port.h>
+
+/*
+ * IO buffer - out-of-line array of characters.
+ */
+typedef char *	io_buf_ptr_t;
+
+/*
+ * Some types for IOKit.
+ */
+
+#ifdef IOKIT
+
+/* must match device_types.defs */
+typedef	char		io_name_t[128];
+typedef	char		io_string_t[512];	
+typedef char 		io_struct_inband_t[4096];
+typedef int		io_scalar_inband_t[16];
+typedef natural_t	io_async_ref_t[8];
+
+#ifdef MACH_KERNEL
+
+typedef struct IOObject * io_object_t;
+typedef io_object_t io_connect_t;
+
+extern void iokit_remove_reference( io_object_t	obj );
+
+extern io_object_t iokit_lookup_object_port( ipc_port_t port );
+extern io_connect_t iokit_lookup_connect_port( ipc_port_t port );
+
+extern ipc_port_t iokit_make_object_port( io_object_t obj );
+extern ipc_port_t iokit_make_connect_port( io_connect_t obj );
+
+extern boolean_t iokit_notify( mach_msg_header_t *msg );
+
+#else
+
+#ifndef	__IOKIT_PORTS_DEFINED__
+#define __IOKIT_PORTS_DEFINED__
+typedef mach_port_t	io_object_t;
+#endif	/* __IOKIT_PORTS_DEFINED__ */
+
+#endif  /* MACH_KERNEL */
+
+#endif  /* IOKIT */
+
+#endif	/* DEVICE_TYPES_H */
+
diff --git a/xnu-792.18.15/osfmk/device/iokit_rpc.c b/xnu-792.18.15/osfmk/device/iokit_rpc.c
new file mode 100644
index 0000000..a04a511
--- /dev/null
+++ b/xnu-792.18.15/osfmk/device/iokit_rpc.c
@@ -0,0 +1,539 @@
+/*
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ * 
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ */
+#include <mach_kdb.h>
+#include <zone_debug.h>
+#include <mach_kdb.h>
+
+#include <mach/boolean.h>
+#include <mach/kern_return.h>
+#include <mach/mig_errors.h>
+#include <mach/port.h>
+#include <mach/vm_param.h>
+#include <mach/notify.h>
+#include <mach/mach_host_server.h>
+#include <mach/mach_types.h>
+
+#include <machine/machparam.h>		/* spl definitions */
+
+#include <ipc/ipc_port.h>
+#include <ipc/ipc_space.h>
+
+#include <kern/clock.h>
+#include <kern/spl.h>
+#include <kern/counters.h>
+#include <kern/queue.h>
+#include <kern/zalloc.h>
+#include <kern/thread.h>
+#include <kern/task.h>
+#include <kern/sched_prim.h>
+#include <kern/misc_protos.h>
+
+#include <vm/pmap.h>
+#include <vm/vm_map.h>
+#include <vm/vm_kern.h>
+
+#include <device/device_types.h>
+#include <device/device_port.h>
+#include <device/device_server.h>
+
+#include <machine/machparam.h>
+
+#ifdef __ppc__
+#include <ppc/mappings.h>
+#endif
+#ifdef __i386
+#include <i386/pmap.h>
+#endif
+#include <IOKit/IOTypes.h>
+
+#define EXTERN
+#define MIGEXTERN
+
+/*
+ * Functions in iokit:IOUserClient.cpp
+ */
+
+extern void iokit_add_reference( io_object_t obj );
+
+extern ipc_port_t iokit_port_for_object( io_object_t obj,
+			ipc_kobject_type_t type );
+
+extern kern_return_t iokit_client_died( io_object_t obj,
+                        ipc_port_t port, ipc_kobject_type_t type, mach_port_mscount_t * mscount );
+
+extern kern_return_t
+iokit_client_memory_for_type(
+	io_object_t	connect,
+	unsigned int	type,
+	unsigned int *	flags,
+	vm_address_t *	address,
+	vm_size_t    *	size );
+
+
+extern ppnum_t IOGetLastPageNumber(void);
+
+/*
+ * Lookup a device by its port.
+ * Doesn't consume the naked send right; produces a device reference.
+ */
+MIGEXTERN io_object_t
+iokit_lookup_object_port(
+	ipc_port_t	port)
+{
+	register io_object_t	obj;
+
+	if (!IP_VALID(port))
+	    return (NULL);
+
+	ip_lock(port);
+	if (ip_active(port) && (ip_kotype(port) == IKOT_IOKIT_OBJECT)) {
+	    obj = (io_object_t) port->ip_kobject;
+	    iokit_add_reference( obj );
+	}
+	else
+	    obj = NULL;
+
+	ip_unlock(port);
+
+	return( obj );
+}
+
+MIGEXTERN io_object_t
+iokit_lookup_connect_port(
+	ipc_port_t	port)
+{
+	register io_object_t	obj;
+
+	if (!IP_VALID(port))
+	    return (NULL);
+
+	ip_lock(port);
+	if (ip_active(port) && (ip_kotype(port) == IKOT_IOKIT_CONNECT)) {
+	    obj = (io_object_t) port->ip_kobject;
+	    iokit_add_reference( obj );
+	}
+	else
+	    obj = NULL;
+
+	ip_unlock(port);
+
+	return( obj );
+}
+
+EXTERN io_object_t
+iokit_lookup_connect_ref(io_object_t connectRef, ipc_space_t space)
+{
+	io_object_t obj = NULL;
+
+	if (connectRef && MACH_PORT_VALID((mach_port_name_t)connectRef)) {
+		ipc_port_t port;
+		kern_return_t kr;
+
+		kr = ipc_object_translate(space, (mach_port_name_t)connectRef, MACH_PORT_RIGHT_SEND, (ipc_object_t *)&port);
+
+		if (kr == KERN_SUCCESS) {
+            assert(IP_VALID(port));
+            
+            if (ip_active(port) && (ip_kotype(port) == IKOT_IOKIT_CONNECT)) {
+                obj = (io_object_t) port->ip_kobject;
+                iokit_add_reference(obj);
+            }
+            
+            ip_unlock(port);
+		}
+	}
+
+	return obj;
+}
+
+EXTERN io_object_t
+iokit_lookup_connect_ref_current_task(io_object_t connectRef)
+{
+	return iokit_lookup_connect_ref(connectRef, current_space());
+}
+
+EXTERN void
+iokit_retain_port( ipc_port_t port )
+{
+    ipc_port_reference( port );
+}
+
+EXTERN void
+iokit_release_port( ipc_port_t port )
+{
+    ipc_port_release( port );
+}
+
+/*
+ * Get the port for a device.
+ * Consumes a device reference; produces a naked send right.
+ */
+MIGEXTERN ipc_port_t
+iokit_make_object_port(
+	io_object_t	obj )
+{
+    register ipc_port_t	port;
+    register ipc_port_t	sendPort;
+
+    if( obj == NULL)
+        return IP_NULL;
+
+    port = iokit_port_for_object( obj, IKOT_IOKIT_OBJECT );
+    if( port) {
+	sendPort = ipc_port_make_send( port);
+	iokit_release_port( port );
+    } else
+	sendPort = IP_NULL;
+
+    iokit_remove_reference( obj );
+
+    return( sendPort);
+}
+
+MIGEXTERN ipc_port_t
+iokit_make_connect_port(
+	io_object_t	obj )
+{
+    register ipc_port_t	port;
+    register ipc_port_t	sendPort;
+
+    if( obj == NULL)
+        return IP_NULL;
+
+    port = iokit_port_for_object( obj, IKOT_IOKIT_CONNECT );
+    if( port) {
+	sendPort = ipc_port_make_send( port);
+	iokit_release_port( port );
+    } else
+	sendPort = IP_NULL;
+
+    iokit_remove_reference( obj );
+
+    return( sendPort);
+}
+
+
+EXTERN ipc_port_t
+iokit_alloc_object_port( io_object_t obj, ipc_kobject_type_t type );
+
+int gIOKitPortCount;
+
+EXTERN ipc_port_t
+iokit_alloc_object_port( io_object_t obj, ipc_kobject_type_t type )
+{
+    ipc_port_t		notify;
+    ipc_port_t		port;
+
+    do {
+
+	/* Allocate port, keeping a reference for it. */
+        port = ipc_port_alloc_kernel();
+        if( port == IP_NULL)
+            continue;
+
+        /* set kobject & type */
+//	iokit_add_reference( obj );
+	ipc_kobject_set( port, (ipc_kobject_t) obj, type);
+
+        /* Request no-senders notifications on the port. */
+        notify = ipc_port_make_sonce( port);
+        ip_lock( port);
+        ipc_port_nsrequest( port, 1, notify, &notify);
+        assert( notify == IP_NULL);
+	gIOKitPortCount++;
+
+    } while( FALSE);
+
+    return( port );
+}
+
+
+EXTERN kern_return_t
+iokit_destroy_object_port( ipc_port_t port )
+{
+    ipc_kobject_set( port, IKO_NULL, IKOT_NONE);
+
+//    iokit_remove_reference( obj );
+
+    ipc_port_dealloc_kernel( port);
+    gIOKitPortCount--;
+
+    return( KERN_SUCCESS);
+}
+
+EXTERN kern_return_t
+iokit_switch_object_port( ipc_port_t port, io_object_t obj, ipc_kobject_type_t type )
+{
+    ipc_kobject_set( port, (ipc_kobject_t) obj, type);
+
+    return( KERN_SUCCESS);
+}
+
+EXTERN mach_port_name_t
+iokit_make_send_right( task_t task, io_object_t obj, ipc_kobject_type_t type )
+{
+    ipc_port_t		port;
+    ipc_port_t		sendPort;
+    mach_port_name_t	name;
+
+    if( obj == NULL)
+        return MACH_PORT_NULL;
+
+    port = iokit_port_for_object( obj, type );
+    if( port) {
+	sendPort = ipc_port_make_send( port);
+	iokit_release_port( port );
+    } else
+	sendPort = IP_NULL;
+
+    if (IP_VALID( sendPort )) {
+    	kern_return_t	kr;
+    	kr = ipc_object_copyout( task->itk_space, (ipc_object_t) sendPort,
+				MACH_MSG_TYPE_PORT_SEND, TRUE, &name);
+	if ( kr != KERN_SUCCESS)
+		name = MACH_PORT_NULL;
+    } else if ( sendPort == IP_NULL)
+        name = MACH_PORT_NULL;
+    else if ( sendPort == IP_DEAD)
+    	name = MACH_PORT_DEAD;
+
+    iokit_remove_reference( obj );
+
+    return( name );
+}
+
+EXTERN kern_return_t
+iokit_mod_send_right( task_t task, mach_port_name_t name, mach_port_delta_t delta )
+{
+    return (mach_port_mod_refs( task->itk_space, name, MACH_PORT_RIGHT_SEND, delta ));
+}
+
+/*
+ * Handle the No-More_Senders notification generated from a device port destroy.
+ * Since there are no longer any tasks which hold a send right to this device
+ * port a NMS notification has been generated. 
+ */
+
+static void
+iokit_no_senders( mach_no_senders_notification_t * notification )
+{
+    ipc_port_t		port;
+    io_object_t		obj = NULL;
+    ipc_kobject_type_t	type;
+    ipc_port_t		notify;
+
+    port = (ipc_port_t) notification->not_header.msgh_remote_port;
+
+    // convert a port to io_object_t.
+    if( IP_VALID(port)) {
+        ip_lock(port);
+        if( ip_active(port)) {
+            obj = (io_object_t) port->ip_kobject;
+	    type = ip_kotype( port );
+            if( (IKOT_IOKIT_OBJECT  == type)
+	     || (IKOT_IOKIT_CONNECT == type))
+                iokit_add_reference( obj );
+            else
+                obj = NULL;
+	}
+        ip_unlock(port);
+
+        if( obj ) {
+
+	    mach_port_mscount_t mscount = notification->not_count;
+
+            if( KERN_SUCCESS != iokit_client_died( obj, port, type, &mscount ))
+	    {
+		/* Re-request no-senders notifications on the port. */
+		notify = ipc_port_make_sonce( port);
+		ip_lock( port);
+		ipc_port_nsrequest( port, mscount + 1, notify, &notify);
+		assert( notify == IP_NULL);
+	    }
+            iokit_remove_reference( obj );
+        }
+    }
+}
+
+
+EXTERN
+boolean_t
+iokit_notify( mach_msg_header_t * msg )
+{
+    switch (msg->msgh_id) {
+        case MACH_NOTIFY_NO_SENDERS:
+            iokit_no_senders((mach_no_senders_notification_t *) msg);
+            return TRUE;
+
+        case MACH_NOTIFY_PORT_DELETED:
+        case MACH_NOTIFY_PORT_DESTROYED:
+        case MACH_NOTIFY_SEND_ONCE:
+        case MACH_NOTIFY_DEAD_NAME:
+        default:
+            printf("iokit_notify: strange notification %ld\n", msg->msgh_id);
+            return FALSE;
+    }
+}
+
+/* need to create a pmap function to generalize */
+unsigned int IODefaultCacheBits(addr64_t pa)
+{
+
+      return(pmap_cache_attributes(pa >> PAGE_SHIFT));
+}
+
+kern_return_t IOMapPages(vm_map_t map, mach_vm_address_t va, mach_vm_address_t pa,
+			mach_vm_size_t length, unsigned int options)
+{
+    vm_prot_t	prot;
+    unsigned int flags;
+    pmap_t 	 pmap = map->pmap;
+
+    prot = (options & kIOMapReadOnly)
+		? VM_PROT_READ : (VM_PROT_READ|VM_PROT_WRITE);
+
+    switch(options & kIOMapCacheMask ) {			/* What cache mode do we need? */
+
+	case kIOMapDefaultCache:
+	default:
+	    flags = IODefaultCacheBits(pa);
+	    break;
+
+	case kIOMapInhibitCache:
+	    flags = VM_WIMG_IO;
+	    break;
+
+	case kIOMapWriteThruCache:
+	    flags = VM_WIMG_WTHRU;
+	    break;
+
+	case kIOMapWriteCombineCache:
+	    flags = VM_WIMG_WCOMB;
+	    break;
+
+	case kIOMapCopybackCache:
+	    flags = VM_WIMG_COPYBACK;
+	    break;
+    }
+
+    // Set up a block mapped area
+    pmap_map_block(pmap, va, (ppnum_t)atop_64(pa), (uint32_t) atop_64(round_page_64(length)), prot, flags, 0);
+
+    return( KERN_SUCCESS );
+}
+
+kern_return_t IOUnmapPages(vm_map_t map, mach_vm_address_t va, mach_vm_size_t length)
+{
+    pmap_t	pmap = map->pmap;
+
+    pmap_remove(pmap, trunc_page_64(va), round_page_64(va + length));
+
+    return( KERN_SUCCESS );
+}
+
+kern_return_t IOProtectCacheMode(vm_map_t map, mach_vm_address_t va,
+					mach_vm_size_t length, unsigned int options)
+{
+    mach_vm_size_t off;
+    vm_prot_t	   prot;
+    unsigned int   flags;
+    pmap_t 	   pmap = map->pmap;
+
+    prot = (options & kIOMapReadOnly)
+		? VM_PROT_READ : (VM_PROT_READ|VM_PROT_WRITE);
+
+    switch (options & kIOMapCacheMask)
+    {
+    /* What cache mode do we need? */
+	case kIOMapDefaultCache:
+	default:
+	    return (KERN_INVALID_ARGUMENT);
+
+	case kIOMapInhibitCache:
+	    flags = VM_WIMG_IO;
+	    break;
+
+	case kIOMapWriteThruCache:
+	    flags = VM_WIMG_WTHRU;
+	    break;
+
+	case kIOMapWriteCombineCache:
+	    flags = VM_WIMG_WCOMB;
+	    break;
+
+	case kIOMapCopybackCache:
+	    flags = VM_WIMG_COPYBACK;
+	    break;
+    }
+#if __ppc__
+    // can't remap block mappings, but ppc doesn't speculative read from WC
+#else
+
+    //  enter each page's physical address in the target map
+    for (off = 0; off < length; off += page_size)
+    {
+	ppnum_t ppnum = pmap_find_phys(pmap, va + off);
+	if (ppnum)
+	    pmap_enter(pmap, va + off, ppnum, prot, flags, TRUE);
+    }
+
+#endif
+
+    return (KERN_SUCCESS);
+}
+
+ppnum_t IOGetLastPageNumber(void)
+{
+    ppnum_t	 lastPage, highest = 0;
+
+#if __ppc__
+    int idx;
+    for (idx = 0; idx < pmap_mem_regions_count; idx++)
+    {
+	lastPage = pmap_mem_regions[idx].mrEnd;
+#elif __i386__
+    unsigned int idx;
+    for (idx = 0; idx < pmap_memory_region_count; idx++)
+    {
+	lastPage = pmap_memory_regions[idx].end - 1;
+#else
+#error arch
+#endif
+	if (lastPage > highest)
+	    highest = lastPage;
+    }
+    return (highest);
+}
+
+
+void IOGetTime( mach_timespec_t * clock_time);
+void IOGetTime( mach_timespec_t * clock_time)
+{
+	clock_get_system_nanotime(&clock_time->tv_sec, &clock_time->tv_nsec);
+}
+
diff --git a/xnu-792.18.15/osfmk/device/subrs.c b/xnu-792.18.15/osfmk/device/subrs.c
new file mode 100644
index 0000000..d71b43a
--- /dev/null
+++ b/xnu-792.18.15/osfmk/device/subrs.c
@@ -0,0 +1,381 @@
+/*
+ * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ * 
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ */
+/*
+ * @OSF_COPYRIGHT@
+ */
+/*
+ *(C)UNIX System Laboratories, Inc. all or some portions of this file are
+ *derived from material licensed to the University of California by
+ *American Telephone and Telegraph Co. or UNIX System Laboratories,
+ *Inc. and are reproduced herein with the permission of UNIX System
+ *Laboratories, Inc.
+ */
+
+/* 
+ * Mach Operating System
+ * Copyright (c) 1993,1991,1990,1989,1988 Carnegie Mellon University
+ * All Rights Reserved.
+ * 
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ * 
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ * 
+ * Carnegie Mellon requests users of this software to return to
+ * 
+ *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
+ *  School of Computer Science
+ *  Carnegie Mellon University
+ *  Pittsburgh PA 15213-3890
+ * 
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+/*
+ */
+/*
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*
+ * Random device subroutines and stubs.
+ */
+
+#include <vm/vm_kern.h>
+#include <kern/misc_protos.h>
+
+/* String routines, from CMU */
+#ifdef	strcpy
+#undef strcmp
+#undef strncmp
+#undef strcpy
+#undef strncpy
+#undef strlen
+#endif
+
+/*
+ * Abstract:
+ *      strcmp (s1, s2) compares the strings "s1" and "s2".
+ *      It returns 0 if the strings are identical. It returns
+ *      > 0 if the first character that differs in the two strings
+ *      is larger in s1 than in s2 or if s1 is longer than s2 and
+ *      the contents are identical up to the length of s2.
+ *      It returns < 0 if the first differing character is smaller
+ *      in s1 than in s2 or if s1 is shorter than s2 and the
+ *      contents are identical upto the length of s1.
+ */
+
+int
+strcmp(
+        register const char *s1,
+        register const char *s2)
+{
+        register unsigned int a, b;
+
+        do {
+                a = *s1++;
+                b = *s2++;
+                if (a != b)
+                        return a-b;     /* includes case when
+                                           'a' is zero and 'b' is not zero
+                                           or vice versa */
+	} while (a != '\0');
+
+        return 0;       /* both are zero */
+}
+
+/*
+ * Abstract:
+ *      strncmp (s1, s2, n) compares the strings "s1" and "s2"
+ *      in exactly the same way as strcmp does.  Except the
+ *      comparison runs for at most "n" characters.
+ */
+
+int
+strncmp(
+        register const char *s1,
+        register const char *s2,
+        size_t n)
+{
+        register unsigned int a, b;
+
+        while (n != 0) {
+                a = *s1++;
+                b = *s2++;
+                if (a != b)
+                        return a-b;     /* includes case when
+                                           'a' is zero and 'b' is not zero
+                                           or vice versa */
+                if (a == '\0')
+                        return 0;       /* both are zero */
+                n--;
+	}
+
+        return 0;
+}
+
+
+//
+// Lame implementation just for use by strcasecmp/strncasecmp
+//
+static int
+tolower(unsigned char ch)
+{
+    if (ch >= 'A' && ch <= 'Z')
+	ch = 'a' + (ch - 'A');
+
+    return ch;
+}
+
+int
+strcasecmp(const char *s1, const char *s2)
+{
+    const unsigned char *us1 = (const u_char *)s1,
+                 *us2 = (const u_char *)s2;
+
+    while (tolower(*us1) == tolower(*us2++))
+	if (*us1++ == '\0')
+	    return (0);
+    return (tolower(*us1) - tolower(*--us2));
+}
+
+int
+strncasecmp(const char *s1, const char *s2, size_t n)
+{
+    if (n != 0) {
+	const unsigned char *us1 = (const u_char *)s1,
+                     *us2 = (const u_char *)s2;
+
+	do {
+	    if (tolower(*us1) != tolower(*us2++))
+		return (tolower(*us1) - tolower(*--us2));
+	    if (*us1++ == '\0')
+		break;
+	} while (--n != 0);
+    }
+    return (0);
+}
+
+
+/*
+ * Abstract:
+ *      strcpy copies the contents of the string "from" including
+ *      the null terminator to the string "to". A pointer to "to"
+ *      is returned.
+ */
+
+char *
+strcpy(
+        register char *to,
+        register const char *from)
+{
+        register char *ret = to;
+
+        while ((*to++ = *from++) != '\0')
+                continue;
+
+        return ret;
+}
+
+
+/*
+ * Abstract:
+ *      strncpy copies "count" characters from the "from" string to
+ *      the "to" string. If "from" contains less than "count" characters
+ *      "to" will be padded with null characters until exactly "count"
+ *      characters have been written. The return value is a pointer
+ *      to the "to" string.
+ */
+
+char *
+strncpy(
+	char *s1, 
+	const char *s2,
+	size_t n)
+{
+        char *os1 = s1;
+        unsigned long i;
+
+        for (i = 0; i < n;)
+                if ((*s1++ = *s2++) == '\0')
+                        for (i++; i < n; i++)
+                                *s1++ = '\0';
+                else
+                        i++;
+        return (os1);
+}
+
+/*
+ * atoi:
+ *
+ *      This function converts an ascii string into an integer.
+ *
+ * input        : string
+ * output       : a number
+ */
+
+int
+atoi(
+	u_char  *cp)
+{
+        int     number;
+
+        for (number = 0; ('0' <= *cp) && (*cp <= '9'); cp++)
+                number = (number * 10) + (*cp - '0');
+
+        return( number );
+}
+
+/*
+ * convert an ASCII string (decimal radix) to an integer
+ * inputs:
+ *	p	string pointer.
+ *	t	char **, return a pointer to the cahr which terminates the
+ *		numeric string.
+ * returns:
+ *	integer value of the numeric string.
+ * side effect:
+ *	pointer to terminating char.
+ */
+
+int
+atoi_term(
+	char	*p,	/* IN */
+	char	**t)	/* OUT */
+{
+        register int n;
+        register int f;
+
+        n = 0;
+        f = 0;
+        for(;;p++) {
+                switch(*p) {
+                case ' ':
+                case '\t':
+                        continue;
+                case '-':
+                        f++;
+                case '+':
+                        p++;
+                }
+                break;
+        }
+        while(*p >= '0' && *p <= '9')
+                n = n*10 + *p++ - '0';
+
+        /* return pointer to terminating character */
+        if ( t )
+                *t = p;
+
+        return(f? -n: n);
+}
+
+/*
+ * convert an integer to an ASCII string.
+ * inputs:
+ *	num	integer to be converted
+ *	str	string pointer.
+ *
+ * outputs:
+ *	pointer to string start.
+ */
+
+char *
+itoa(
+	int	num,
+	char	*str)
+{
+        char    digits[11];
+        register char *dp;
+        register char *cp = str;
+
+        if (num == 0) {
+            *cp++ = '0';
+        }
+        else {
+            dp = digits;
+            while (num) {
+                *dp++ = '0' + num % 10;
+                num /= 10;
+            }
+            while (dp != digits) {
+                *cp++ = *--dp;
+            }
+        }
+        *cp++ = '\0';
+
+	return str;
+}
+
+char *
+strcat(
+	register char *dest,
+	register const char *src)
+{
+	char *old = dest;
+
+	while (*dest)
+		++dest;
+	while (*dest++ = *src++)
+		;
+	return (old);
+}
+