]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/device/iokit_rpc.c
xnu-344.49.tar.gz
[apple/xnu.git] / osfmk / device / iokit_rpc.c
index 637047f7ecc7ccdc7595bd444ea6db571c086ae1..008f828fd6a1e7af62905e4c56cb83d2a119fc7b 100644 (file)
@@ -3,19 +3,22 @@
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * 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. 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 OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * 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_LICENSE_HEADER_END@
  */
@@ -57,8 +60,6 @@
 #include <device/device_port.h>
 #include <device/device_server.h>
 
-#include <sys/ioctl.h>
-
 #include <machine/machparam.h>
 
 #ifdef __ppc__
@@ -82,7 +83,7 @@ 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 );
+                        ipc_port_t port, ipc_kobject_type_t type, mach_port_mscount_t mscount );
 
 extern kern_return_t
 iokit_client_memory_for_type(
@@ -172,6 +173,18 @@ 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.
@@ -181,17 +194,21 @@ 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)
-       port = ipc_port_make_send( port);
+    if( port) {
+       sendPort = ipc_port_make_send( port);
+       iokit_release_port( port );
+    } else
+       sendPort = IP_NULL;
 
     iokit_remove_reference( obj );
 
-    return( port);
+    return( sendPort);
 }
 
 MIGEXTERN ipc_port_t
@@ -199,17 +216,21 @@ 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)
-        port = ipc_port_make_send( port);
+    if( port) {
+       sendPort = ipc_port_make_send( port);
+       iokit_release_port( port );
+    } else
+       sendPort = IP_NULL;
 
     iokit_remove_reference( obj );
 
-    return( port);
+    return( sendPort);
 }
 
 
@@ -261,27 +282,41 @@ iokit_destroy_object_port( ipc_port_t port )
     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 )
 {
-    kern_return_t      kr;
     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)
-        port = ipc_port_make_send( port);
-    if( port == IP_NULL)
-        return MACH_PORT_NULL;
-
-    kr = ipc_object_copyout( task->itk_space, (ipc_object_t) port,
+    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;
+       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 );
 
@@ -300,6 +335,7 @@ 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;
 
@@ -312,13 +348,23 @@ iokit_no_senders( mach_no_senders_notification_t * notification )
             if( (IKOT_IOKIT_OBJECT  == type)
             || (IKOT_IOKIT_CONNECT == type))
                 iokit_add_reference( obj );
-           else
+            else
                 obj = NULL;
        }
         ip_unlock(port);
 
         if( obj ) {
-            (void) iokit_client_died( obj, port, type );
+
+           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 );
         }
     }
@@ -344,6 +390,21 @@ iokit_notify( mach_msg_header_t * msg )
     }
 }
 
+#ifndef i386
+unsigned int IOTranslateCacheBits(struct phys_entry *pp)
+{
+       unsigned int    flags;
+       unsigned int    memattr;
+
+       /* need to create a pmap function to generalize */
+       memattr = ((pp->pte1 & 0x00000078) >> 3);
+
+       /* NOTE: DEVICE_PAGER_FLAGS are made to line up */
+       flags = memattr & VM_WIMG_MASK;
+       return flags;
+}
+#endif
+
 kern_return_t IOMapPages(vm_map_t map, vm_offset_t va, vm_offset_t pa,
                        vm_size_t length, unsigned int options)
 {
@@ -388,15 +449,25 @@ kern_return_t IOMapPages(vm_map_t map, vm_offset_t va, vm_offset_t pa,
 #else
 //     enter each page's physical address in the target map
        for (off = 0; off < length; off += page_size) {         /* Loop for the whole length */
-               pmap_enter(pmap, va + off, pa + off, prot, TRUE);                       /* Map it in */
+               pmap_enter(pmap, va + off, pa + off, prot, VM_WIMG_USE_DEFAULT, TRUE);  /* Map it in */
        }
 #endif
 
     return( KERN_SUCCESS );
 }
 
+kern_return_t IOUnmapPages(vm_map_t map, vm_offset_t va, vm_size_t length)
+{
+    pmap_t     pmap = map->pmap;
+
+    pmap_remove(pmap, trunc_page(va), round_page(va + length));
+
+    return( KERN_SUCCESS );
+}
+
 void IOGetTime( mach_timespec_t * clock_time);
 void IOGetTime( mach_timespec_t * clock_time)
 {
        *clock_time = clock_get_system_value();
 }
+