]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/ppc/machine_routines.c
xnu-1456.1.26.tar.gz
[apple/xnu.git] / osfmk / ppc / machine_routines.c
index b6a6ce457a6c7bf7e034a6496c4861fc045170c7..7edacae01318a0e841cb00b1f1b44990d396642e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
 #include <ppc/mem.h>
 #include <ppc/new_screen.h>
 #include <ppc/proc_reg.h>
+#include <ppc/machine_cpu.h> /* for cpu_signal_handler() */
+#include <ppc/fpu_protos.h>
 #include <kern/kern_types.h>
 #include <kern/processor.h>
 #include <kern/machine.h>
 
 #include <vm/vm_page.h>
 
-unsigned int           LockTimeOut = 12500000;
+unsigned int           LockTimeOut = 1250000000;
 unsigned int           MutexSpin = 0;
 
-decl_mutex_data(static,mcpus_lock);
-unsigned int           mcpus_lock_initialized = 0;
-unsigned int           mcpus_state = 0;
+static int max_cpus_initialized = 0;
 
 uint32_t warFlags = 0;
 #define warDisMBpoff   0x80000000
@@ -88,11 +88,6 @@ extern unsigned int mulckePatch_eieio;
 extern unsigned int sulckPatch_eieio;
 extern unsigned int rwlesPatch_eieio;
 extern unsigned int rwldPatch_eieio;
-#if     !MACH_LDEBUG
-extern unsigned int entfsectPatch_isync;
-extern unsigned int retfsectPatch_isync;
-extern unsigned int retfsectPatch_eieio;
-#endif
 
 struct patch_up {
         unsigned int    *addr;
@@ -131,11 +126,6 @@ patch_up_t patch_up_table[] = {
        {&sulckPatch_eieio,             0x60000000},
        {&rwlesPatch_eieio,             0x60000000},
        {&rwldPatch_eieio,              0x60000000},
-#if     !MACH_LDEBUG
-       {&entfsectPatch_isync,          0x60000000},
-       {&retfsectPatch_isync,          0x60000000},
-       {&retfsectPatch_eieio,          0x60000000},
-#endif
        {NULL,                          0x00000000}
 };
 
@@ -148,9 +138,17 @@ ml_io_map(
        vm_offset_t phys_addr, 
        vm_size_t size)
 {
-       return(io_map(phys_addr,size));
+       return(io_map(phys_addr,size,VM_WIMG_IO));
 }
 
+
+void ml_get_bouncepool_info(vm_offset_t *phys_addr, vm_size_t *size)
+{
+        *phys_addr = 0;
+       *size      = 0;
+}
+
+
 /*
  *     Routine:        ml_static_malloc
  *     Function:       static memory allocation
@@ -247,7 +245,48 @@ void ml_install_interrupt_handler(
        proc_info->interrupts_enabled = TRUE;  
        (void) ml_set_interrupts_enabled(current_state);
 
-       initialize_screen(0, kPEAcquireScreen);
+       initialize_screen(NULL, kPEAcquireScreen);
+}
+
+/*
+ *     Routine:        ml_nofault_copy
+ *     Function:       Perform a physical mode copy if the source and
+ *                     destination have valid translations in the kernel pmap.
+ *                     If translations are present, they are assumed to
+ *                     be wired; i.e. no attempt is made to guarantee that the
+ *                     translations obtained remained valid for
+ *                     the duration of their use.
+ */
+
+vm_size_t ml_nofault_copy(
+       vm_offset_t virtsrc, vm_offset_t virtdst, vm_size_t size)
+{
+       addr64_t cur_phys_dst, cur_phys_src;
+       uint32_t count, pindex, nbytes = 0;
+
+       while (size > 0) {
+               if (!(cur_phys_src = kvtophys(virtsrc)))
+                       break;
+               if (!(cur_phys_dst = kvtophys(virtdst)))
+                       break;
+               if (!mapping_phys_lookup((cur_phys_src>>12), &pindex) ||
+                   !mapping_phys_lookup((cur_phys_dst>>12), &pindex))
+                       break;
+               count = PAGE_SIZE - (cur_phys_src & PAGE_MASK);
+               if (count > (PAGE_SIZE - (cur_phys_dst & PAGE_MASK)))
+                       count = PAGE_SIZE - (cur_phys_dst & PAGE_MASK);
+               if (count > size)
+                       count = size;
+
+               bcopy_phys(cur_phys_src, cur_phys_dst, count);
+
+               nbytes += count;
+               virtsrc += count;
+               virtdst += count;
+               size -= count;
+       }
+
+       return nbytes;
 }
 
 /*
@@ -303,14 +342,9 @@ void ml_cause_interrupt(void)
  */
 void ml_thread_policy(
        thread_t thread,
-       unsigned policy_id,
+__unused       unsigned policy_id,
        unsigned policy_info)
 {
-
-       if ((policy_id == MACHINE_GROUP) &&
-               ((PerProcTable[master_cpu].ppe_vaddr->pf.Available) & pfSMPcap))
-                       thread_bind(thread, master_processor);
-
        if (policy_info & MACHINE_NETWORK_WORKLOOP) {
                spl_t           s = splsched();
 
@@ -404,8 +438,9 @@ ml_processor_register(
        }
 
        if (!boot_processor) {
-               (void)hw_atomic_add((uint32_t *)&saveanchor.savetarget, FreeListMin);   /* saveareas for this processor */
-               processor_init((struct processor *)proc_info->processor, proc_info->cpu_number);
+               (void)hw_atomic_add(&saveanchor.savetarget, FreeListMin);   /* saveareas for this processor */
+               processor_init((struct processor *)proc_info->processor,
+                                                               proc_info->cpu_number, processor_pset(master_processor));
        }
 
        *processor_out = (struct processor *)proc_info->processor;
@@ -458,35 +493,30 @@ ml_enable_nap(int target_cpu, boolean_t nap_enabled)
  *     Function:
  */
 void
-ml_init_max_cpus(unsigned int mcpus)
+ml_init_max_cpus(unsigned int max_cpus)
 {
+       boolean_t current_state;
 
-       if (hw_compare_and_store(0,1,&mcpus_lock_initialized))
-               mutex_init(&mcpus_lock,0);
-       mutex_lock(&mcpus_lock);
-       if ((mcpus_state & MAX_CPUS_SET)
-           || (mcpus == 0)
-           || (mcpus > MAX_CPUS))
-               panic("ml_init_max_cpus(): Invalid call, max_cpus: %d\n", mcpus);
-
-       machine_info.max_cpus = mcpus;
-       machine_info.physical_cpu_max = mcpus;
-       machine_info.logical_cpu_max = mcpus;
-       mcpus_state |= MAX_CPUS_SET;
-
-       if (mcpus_state & MAX_CPUS_WAIT) {
-               mcpus_state |= ~MAX_CPUS_WAIT;
-               thread_wakeup((event_t)&mcpus_state);
+       current_state = ml_set_interrupts_enabled(FALSE);
+       if (max_cpus_initialized != MAX_CPUS_SET) {
+                       if (max_cpus > 0 && max_cpus <= MAX_CPUS) {
+                       /*
+                        * Note: max_ncpus is the maximum number
+                        * that the kernel supports or that the "cpus="
+                        * boot-arg has set. Here we take int minimum.
+                        */
+                       machine_info.max_cpus = MIN(max_cpus, max_ncpus);
+                       machine_info.physical_cpu_max = max_cpus;
+                       machine_info.logical_cpu_max = max_cpus;
+               }
+               if (max_cpus_initialized == MAX_CPUS_WAIT)
+                       wakeup((event_t)&max_cpus_initialized);
+               max_cpus_initialized = MAX_CPUS_SET;
        }
-       mutex_unlock(&mcpus_lock);
-
+       
        if (machine_info.logical_cpu_max == 1) {
-               struct patch_up *patch_up_ptr;
-               boolean_t current_state;
-
-               patch_up_ptr = &patch_up_table[0];
+               struct patch_up *patch_up_ptr = &patch_up_table[0];
 
-               current_state = ml_set_interrupts_enabled(FALSE);
                while (patch_up_ptr->addr != NULL) {
                        /*
                         * Patch for V=R kernel text section
@@ -496,8 +526,9 @@ ml_init_max_cpus(unsigned int mcpus)
                        sync_cache64((addr64_t)((unsigned int)(patch_up_ptr->addr)),4);
                        patch_up_ptr++;
                }
-               (void) ml_set_interrupts_enabled(current_state);
        }
+       
+       (void) ml_set_interrupts_enabled(current_state);        
 }
 
 /*
@@ -507,15 +538,15 @@ ml_init_max_cpus(unsigned int mcpus)
 unsigned int
 ml_get_max_cpus(void)
 {
-       if (hw_compare_and_store(0,1,&mcpus_lock_initialized))
-               mutex_init(&mcpus_lock,0);
-       mutex_lock(&mcpus_lock);
-       if (!(mcpus_state & MAX_CPUS_SET)) {
-               mcpus_state |= MAX_CPUS_WAIT;
-               thread_sleep_mutex((event_t)&mcpus_state,
-                                        &mcpus_lock, THREAD_UNINT);
-       } else
-               mutex_unlock(&mcpus_lock);
+       boolean_t current_state;
+
+       current_state = ml_set_interrupts_enabled(FALSE);
+       if (max_cpus_initialized != MAX_CPUS_SET) {
+                       max_cpus_initialized = MAX_CPUS_WAIT;
+                       assert_wait((event_t)&max_cpus_initialized, THREAD_UNINT);
+                       (void)thread_block(THREAD_CONTINUE_NULL);
+       }
+       (void) ml_set_interrupts_enabled(current_state);
        return(machine_info.max_cpus);
 }
 
@@ -526,8 +557,8 @@ ml_get_max_cpus(void)
 void
 ml_cpu_up(void)
 {
-       hw_atomic_add(&machine_info.physical_cpu, 1);
-       hw_atomic_add(&machine_info.logical_cpu, 1);
+       (void)hw_atomic_add(&machine_info.physical_cpu, 1);
+       (void)hw_atomic_add(&machine_info.logical_cpu, 1);
 }
 
 /*
@@ -537,8 +568,8 @@ ml_cpu_up(void)
 void
 ml_cpu_down(void)
 {
-       hw_atomic_sub(&machine_info.physical_cpu, 1);
-       hw_atomic_sub(&machine_info.logical_cpu, 1);
+       (void)hw_atomic_sub(&machine_info.physical_cpu, 1);
+       (void)hw_atomic_sub(&machine_info.logical_cpu, 1);
 }
 
 /*
@@ -622,8 +653,6 @@ ml_enable_cache_level(int cache_level, int enable)
 }
 
 
-decl_simple_lock_data(, spsLock);
-
 /*
  *      Routine:        ml_set_processor_speed
  *      Function:
@@ -654,7 +683,7 @@ ml_set_processor_speed(unsigned long speed)
                                 */
                                for (i=200; i>0; i--) {
                                        current_state = ml_set_interrupts_enabled(FALSE);
-                                       if (cpu != cpu_number()) {
+                                       if (cpu != (unsigned)cpu_number()) {
                                                        if (PerProcTable[cpu].ppe_vaddr->cpu_flags & SignalReady)
                                                        /*
                                                         * Target cpu is off-line, skip
@@ -719,7 +748,7 @@ ml_init_lock_timeout(void)
        nanoseconds_to_absolutetime(NSEC_PER_SEC>>2, &abstime);
        LockTimeOut = (unsigned int)abstime;
 
-       if (PE_parse_boot_arg("mtxspin", &mtxspin)) {
+       if (PE_parse_boot_argn("mtxspin", &mtxspin, sizeof (mtxspin))) {
                if (mtxspin > USEC_PER_SEC>>4)
                        mtxspin =  USEC_PER_SEC>>4;
                nanoseconds_to_absolutetime(mtxspin*NSEC_PER_USEC, &abstime);
@@ -769,57 +798,40 @@ machine_processor_shutdown(
        return((thread_t)(getPerProc()->old_thread));
 }
 
-/*
- *     Routine:        set_be_bit
- *     Function:
- */
-int
-set_be_bit(
-       void)
-{
-       boolean_t current_state;
 
-       current_state = ml_set_interrupts_enabled(FALSE);
-       getPerProc()->cpu_flags |= traceBE;
-       (void) ml_set_interrupts_enabled(current_state);
-       return(1);
-}
+void ml_mem_backoff(void) {
 
-/*
- *     Routine:        clr_be_bit
- *     Function:
- */
-int
-clr_be_bit(
-       void)
-{
-       boolean_t current_state;
+       if(warFlags & warDisMBpoff) return;                                     /* If backoff disabled, exit */
 
-       current_state = ml_set_interrupts_enabled(FALSE);
-       getPerProc()->cpu_flags &= ~traceBE;
-       (void) ml_set_interrupts_enabled(current_state);
-       return(1);
+       __asm__ volatile("sync");
+       __asm__ volatile("isync");
+       
+       return;
 }
 
+
+
 /*
- *     Routine:        be_tracing
- *     Function:
+ * Stubs for CPU Stepper
  */
-int
-be_tracing(
-       void)
+void
+machine_run_count(__unused uint32_t count)
 {
-  return(getPerProc()->cpu_flags & traceBE);
 }
 
+boolean_t
+machine_cpu_is_inactive(__unused int num)
+{
+    return(FALSE);
+}
 
-void ml_mem_backoff(void) {
-
-       if(warFlags & warDisMBpoff) return;                                     /* If backoff disabled, exit */
+vm_offset_t ml_stack_remaining(void)
+{
+       uintptr_t local = (uintptr_t) &local;
 
-       __asm__ volatile("sync");
-       __asm__ volatile("isync");
-       
-       return;
+       if (ml_at_interrupt_context()) {
+           return (local - (getPerProc()->intstack_top_ss - INTSTACK_SIZE));
+       } else {
+           return (local - current_thread()->kernel_stack);
+       }
 }
-