/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
#include <kern/clock.h>
#include <kern/spl.h>
-#include <kern/ast.h>
#include <kern/counters.h>
#include <kern/queue.h>
#include <kern/zalloc.h>
#include <kern/thread.h>
-#include <kern/thread_swap.h>
#include <kern/task.h>
#include <kern/sched_prim.h>
#include <kern/misc_protos.h>
#include <device/device_port.h>
#include <device/device_server.h>
-#include <sys/ioctl.h>
-
#include <machine/machparam.h>
#ifdef __ppc__
#include <ppc/mappings.h>
-#include <ppc/pmap_internals.h>
+#endif
+#ifdef __i386
+#include <i386/pmap.h>
#endif
#include <IOKit/IOTypes.h>
extern void iokit_add_reference( io_object_t obj );
-extern void iokit_remove_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 );
+ ipc_port_t port, ipc_kobject_type_t type, mach_port_mscount_t * mscount );
extern kern_return_t
iokit_client_memory_for_type(
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.
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
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);
}
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 );
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
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;
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, ¬ify);
+ assert( notify == IP_NULL);
+ }
iokit_remove_reference( obj );
}
}
}
}
+/* need to create a pmap function to generalize */
+unsigned int IODefaultCacheBits(addr64_t pa)
+{
+ unsigned int flags;
+#ifndef i386
+ struct phys_entry * pp;
+
+ // Find physical address
+ if ((pp = pmap_find_physentry(pa >> 12))) {
+ // Use physical attributes as default
+ // NOTE: DEVICE_PAGER_FLAGS are made to line up
+ flags = VM_MEM_COHERENT; /* We only support coherent memory */
+ if(pp->ppLink & ppG) flags |= VM_MEM_GUARDED; /* Add in guarded if it is */
+ if(pp->ppLink & ppI) flags |= VM_MEM_NOT_CACHEABLE; /* Add in cache inhibited if so */
+ } else
+ // If no physical, just hard code attributes
+ flags = VM_WIMG_IO;
+#else
+ extern pmap_paddr_t avail_end;
+
+ if (pa < avail_end)
+ flags = VM_WIMG_COPYBACK;
+ else
+ flags = VM_WIMG_IO;
+#endif
+
+ return flags;
+}
+
kern_return_t IOMapPages(vm_map_t map, vm_offset_t va, vm_offset_t pa,
vm_size_t length, unsigned int options)
{
vm_size_t off;
vm_prot_t prot;
- int memattr;
- struct phys_entry *pp;
- pmap_t pmap = map->pmap;
+ 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 kIOWriteCombineCache:
+ flags = VM_WIMG_WCOMB;
+ break;
+
+ case kIOMapCopybackCache:
+ flags = VM_WIMG_COPYBACK;
+ break;
+ }
#if __ppc__
- switch(options & kIOMapCacheMask ) { /* What cache mode do we need? */
-
- case kIOMapDefaultCache:
- default:
- if(pp = pmap_find_physentry(pa)) { /* Find physical address */
- memattr = ((pp->pte1 & 0x00000078) >> 3); /* Use physical attributes as default */
- }
- else { /* If no physical, just hard code attributes */
- memattr = PTE_WIMG_UNCACHED_COHERENT_GUARDED;
- }
- break;
-
- case kIOMapInhibitCache:
- memattr = PTE_WIMG_UNCACHED_COHERENT_GUARDED;
- break;
-
- case kIOMapWriteThruCache:
- memattr = PTE_WIMG_WT_CACHED_COHERENT_GUARDED;
- break;
-
- case kIOMapCopybackCache:
- memattr = PTE_WIMG_CB_CACHED_COHERENT;
- break;
- }
+ // Set up a block mapped area
+ pmap_map_block(pmap, (addr64_t)va, (ppnum_t)(pa >> 12), (uint32_t)(length >> 12), prot, flags, 0);
- pmap_map_block(pmap, va, pa, length, prot, memattr, 0); /* Set up a block mapped area */
-
#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 */
- }
+// enter each page's physical address in the target map
+
+ for (off = 0; off < length; off += page_size)
+ pmap_enter(pmap, va + off, (pa + off) >> 12, prot, flags, TRUE);
+
#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;
- vm_size_t off;
- boolean_t b;
-#if __ppc__
- b = mapping_remove(pmap, va);
-#else
- pmap_remove(pmap, va, va + length);
- b = TRUE;
-#endif
+ pmap_remove(pmap, trunc_page_64(va), round_page_64(va + length));
- return( b ? KERN_SUCCESS : KERN_INVALID_ADDRESS );
+ return( KERN_SUCCESS );
}
void IOGetTime( mach_timespec_t * clock_time);
void IOGetTime( mach_timespec_t * clock_time)
{
- *clock_time = clock_get_system_value();
+ clock_get_system_nanotime(&clock_time->tv_sec, &clock_time->tv_nsec);
}
-