]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/vm/device_vm.c
xnu-2422.90.20.tar.gz
[apple/xnu.git] / osfmk / vm / device_vm.c
index 46422003418c55d898720d8dcb5cad8461dc19ab..f3df12b70644fdf8122dbc8515d4ac96019ff780 100644 (file)
@@ -1,23 +1,29 @@
 /*
- * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_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.
+ * 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.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * 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@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 
 #include <sys/errno.h>
 
 
 /* until component support available */
-int    device_pager_workaround;
-
-typedef int device_port_t;
+const struct memory_object_pager_ops device_pager_ops = {
+       device_pager_reference,
+       device_pager_deallocate,
+       device_pager_init,
+       device_pager_terminate,
+       device_pager_data_request,
+       device_pager_data_return,
+       device_pager_data_initialize,
+       device_pager_data_unlock,
+       device_pager_synchronize,
+       device_pager_map,
+       device_pager_last_unmap,
+       NULL, /* data_reclaim */
+       "device pager"
+};
+
+typedef uintptr_t device_port_t;
 
+/*
+ * The start of "struct device_pager" MUST match a "struct memory_object".
+ */
 typedef struct device_pager {
-       int             *pager;         /* pager workaround pointer     */
-       unsigned int    pager_ikot;     /* fake ip_kotype()             */
+       struct ipc_object_header        pager_header;   /* fake ip_kotype()     */
+       memory_object_pager_ops_t pager_ops; /* == &device_pager_ops    */
        unsigned int    ref_count;      /* reference count              */
        memory_object_control_t control_handle; /* mem object's cntrl handle */
        device_port_t   device_handle;  /* device_handle */
@@ -71,7 +94,7 @@ typedef struct device_pager {
        int             flags;
 } *device_pager_t;
 
-
+#define pager_ikot pager_header.io_bits
 
 
 device_pager_t
@@ -104,7 +127,7 @@ device_pager_bootstrap(void)
        size = (vm_size_t) sizeof(struct device_pager);
        device_pager_zone = zinit(size, (vm_size_t) MAX_DNODE*size,
                                PAGE_SIZE, "device node pager structures");
-
+       zone_change(device_pager_zone, Z_CALLERACCT, FALSE);
        return;
 }
 
@@ -114,7 +137,7 @@ device_pager_bootstrap(void)
 memory_object_t
 device_pager_setup(
        __unused memory_object_t device,
-       int             device_handle,
+       uintptr_t               device_handle,
        vm_size_t       size,
        int             flags)
 {
@@ -161,11 +184,13 @@ device_pager_populate_object(
                return kr;
 
        if(!vm_object->phys_contiguous) {
-               int null_size = 0;
+               unsigned int null_size = 0;
+               assert((upl_size_t) size == size);
                kr = vm_object_upl_request(vm_object,
-                       (vm_object_offset_t)offset, size, &upl,  NULL,
-                       &null_size, (UPL_NO_SYNC | UPL_CLEAN_IN_PLACE)); 
-
+                                          (vm_object_offset_t)offset,
+                                          (upl_size_t) size, &upl,  NULL,
+                                          &null_size,
+                                          (UPL_NO_SYNC | UPL_CLEAN_IN_PLACE));
                if(kr != KERN_SUCCESS)
                        panic("device_pager_populate_object: list_req failed");
 
@@ -187,7 +212,7 @@ device_pager_lookup(
        device_pager_t  device_object;
 
        device_object = (device_pager_t)name;
-       assert(device_object->pager == &device_pager_workaround);
+       assert(device_object->pager_ops == &device_pager_ops);
        return (device_object);
 }
 
@@ -198,7 +223,7 @@ kern_return_t
 device_pager_init(
        memory_object_t mem_obj, 
        memory_object_control_t control, 
-       __unused vm_size_t pg_size)
+       __unused memory_object_cluster_size_t pg_size)
 {
        device_pager_t   device_object;
        kern_return_t   kr;
@@ -254,9 +279,11 @@ device_pager_init(
 /*ARGSUSED6*/
 kern_return_t
 device_pager_data_return(
-       memory_object_t         mem_obj,
-       memory_object_offset_t  offset,
-       vm_size_t               data_cnt,
+       memory_object_t                 mem_obj,
+       memory_object_offset_t          offset,
+       memory_object_cluster_size_t                    data_cnt,
+       __unused memory_object_offset_t *resid_offset,
+       __unused int                    *io_error,
        __unused boolean_t              dirty,
        __unused boolean_t              kernel_copy,
        __unused int                    upl_flags)  
@@ -280,8 +307,9 @@ kern_return_t
 device_pager_data_request(
        memory_object_t         mem_obj,
        memory_object_offset_t  offset,
-       vm_size_t               length,
-       __unused vm_prot_t              protection_required)
+       memory_object_cluster_size_t            length,
+       __unused vm_prot_t      protection_required,
+        __unused memory_object_fault_info_t    fault_info)
 {
        device_pager_t  device_object;
 
@@ -336,7 +364,7 @@ device_pager_deallocate(
                         * We still have to release the "memory object control"
                         * handle.
                         */
-                       assert(device_control->object == VM_OBJECT_NULL);
+                       assert(device_control->moc_object == VM_OBJECT_NULL);
                        memory_object_control_deallocate(device_control);
                        device_object->control_handle =
                                MEMORY_OBJECT_CONTROL_NULL;
@@ -351,7 +379,7 @@ kern_return_t
 device_pager_data_initialize(
         __unused memory_object_t               mem_obj,
         __unused memory_object_offset_t        offset,
-        __unused vm_size_t             data_cnt)
+        __unused memory_object_cluster_size_t          data_cnt)
 {
        panic("device_pager_data_initialize");
        return KERN_FAILURE;
@@ -361,7 +389,7 @@ kern_return_t
 device_pager_data_unlock(
        __unused memory_object_t                mem_obj,
        __unused memory_object_offset_t offset,
-       __unused vm_size_t              size,
+       __unused memory_object_size_t           size,
        __unused vm_prot_t              desired_access)
 {
        return KERN_FAILURE;
@@ -383,7 +411,7 @@ kern_return_t
 device_pager_synchronize(
        memory_object_t         mem_obj,
        memory_object_offset_t  offset,
-       vm_offset_t             length,
+       memory_object_size_t            length,
        __unused vm_sync_t              sync_flags)
 {
        device_pager_t  device_object;
@@ -400,7 +428,15 @@ device_pager_synchronize(
  *
  */
 kern_return_t
-device_pager_unmap(
+device_pager_map(
+       __unused memory_object_t        mem_obj,
+       __unused vm_prot_t              prot)
+{
+       return KERN_SUCCESS;
+}
+
+kern_return_t
+device_pager_last_unmap(
        __unused memory_object_t        mem_obj)
 {
        return KERN_SUCCESS;
@@ -412,14 +448,14 @@ device_pager_unmap(
  *
  */
 device_pager_t
-device_object_create()
+device_object_create(void)
 {
        register device_pager_t  device_object;
 
        device_object = (struct device_pager *) zalloc(device_pager_zone);
        if (device_object == DEVICE_PAGER_NULL)
                return(DEVICE_PAGER_NULL);
-       device_object->pager = &device_pager_workaround;
+       device_object->pager_ops = &device_pager_ops;
        device_object->pager_ikot = IKOT_MEMORY_OBJECT;
        device_object->ref_count = 1;
        device_object->control_handle = MEMORY_OBJECT_CONTROL_NULL;