]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/acpi.c
xnu-1504.15.3.tar.gz
[apple/xnu.git] / osfmk / i386 / acpi.c
index b27d050b2b45f8a75e85188f18a0f887df004a7a..fb2cbe334839d430e0eb7c349d247dcc24f53e8c 100644 (file)
 #endif
 #include <i386/pmCPU.h>
 
+#include <i386/tsc.h>
+
 #include <kern/cpu_data.h>
 #include <console/serial_protos.h>
+#include <vm/vm_page.h>
 
 #if HIBERNATION
 #include <IOKit/IOHibernatePrivate.h>
 #endif
 #include <IOKit/IOPlatformExpert.h>
 
+#include <sys/kdebug.h>
+
 #if CONFIG_SLEEP
 extern void    acpi_sleep_cpu(acpi_sleep_callback, void * refcon);
 extern void acpi_wake_prot(void);
@@ -80,6 +85,10 @@ struct acpi_hibernate_callback_data {
 };
 typedef struct acpi_hibernate_callback_data acpi_hibernate_callback_data_t;
 
+unsigned int           save_kdebug_enable = 0;
+static uint64_t                acpi_sleep_abstime;
+
+
 #if CONFIG_SLEEP
 static void
 acpi_hibernate(void *refcon)
@@ -125,6 +134,9 @@ acpi_hibernate(void *refcon)
                cpu_IA32e_disable(current_cpu_datap());
 #endif
        }
+       kdebug_enable = 0;
+
+       acpi_sleep_abstime = mach_absolute_time();
 
        (data->func)(data->refcon);
 
@@ -133,8 +145,7 @@ acpi_hibernate(void *refcon)
 #endif /* CONFIG_SLEEP */
 #endif /* HIBERNATION */
 
-static uint64_t                acpi_sleep_abstime;
-extern void                    slave_pstart(void);
+extern void            slave_pstart(void);
 
 void
 acpi_sleep_kernel(acpi_sleep_callback func, void *refcon)
@@ -146,6 +157,9 @@ acpi_sleep_kernel(acpi_sleep_callback func, void *refcon)
        unsigned int    cpu;
        kern_return_t   rc;
        unsigned int    my_cpu;
+       uint64_t        now;
+       uint64_t        my_tsc;
+       uint64_t        my_abs;
 
        kprintf("acpi_sleep_kernel hib=%d\n",
                        current_cpu_datap()->cpu_hibernate);
@@ -185,6 +199,15 @@ acpi_sleep_kernel(acpi_sleep_callback func, void *refcon)
         */
        cpu_IA32e_disable(current_cpu_datap());
 #endif
+       /*
+        * Enable FPU/SIMD unit for potential hibernate acceleration
+        */
+       clear_ts(); 
+
+       KERNEL_DEBUG_CONSTANT(IOKDBG_CODE(DBG_HIBERNATE, 0) | DBG_FUNC_START, 0, 0, 0, 0, 0);
+
+       save_kdebug_enable = kdebug_enable;
+       kdebug_enable = 0;
 
        acpi_sleep_abstime = mach_absolute_time();
 
@@ -202,6 +225,7 @@ acpi_sleep_kernel(acpi_sleep_callback func, void *refcon)
 #else
        acpi_sleep_cpu(func, refcon);
 #endif
+
 #ifdef __x86_64__
        x86_64_post_sleep(old_cr3);
 #endif
@@ -258,16 +282,32 @@ acpi_sleep_kernel(acpi_sleep_callback func, void *refcon)
         */
        pmMarkAllCPUsOff();
 
+       ml_get_timebase(&now);
+
+       /* re-enable and re-init local apic (prior to starting timers) */
+       if (lapic_probe())
+               lapic_configure();
+
        /* let the realtime clock reset */
        rtc_sleep_wakeup(acpi_sleep_abstime);
 
-       if (did_hibernate){
+       kdebug_enable = save_kdebug_enable;
+
+       if (did_hibernate) {
+               
+               my_tsc = (now >> 32) | (now << 32);
+               my_abs = tmrCvt(my_tsc, tscFCvtt2n);
+
+               KERNEL_DEBUG_CONSTANT(IOKDBG_CODE(DBG_HIBERNATE, 2) | DBG_FUNC_START,
+                                     (uint32_t)(my_abs >> 32), (uint32_t)my_abs, 0, 0, 0);
                hibernate_machine_init();
+               KERNEL_DEBUG_CONSTANT(IOKDBG_CODE(DBG_HIBERNATE, 2) | DBG_FUNC_END, 0, 0, 0, 0, 0);
+
                current_cpu_datap()->cpu_hibernate = 0;
-       }
-       /* re-enable and re-init local apic */
-       if (lapic_probe())
-               lapic_configure();
+
+               KERNEL_DEBUG_CONSTANT(IOKDBG_CODE(DBG_HIBERNATE, 0) | DBG_FUNC_END, 0, 0, 0, 0, 0);
+       } else
+               KERNEL_DEBUG_CONSTANT(IOKDBG_CODE(DBG_HIBERNATE, 0) | DBG_FUNC_END, 0, 0, 0, 0, 0);
 
        /* Restore power management register state */
        pmCPUMarkRunning(current_cpu_datap());
@@ -275,11 +315,11 @@ acpi_sleep_kernel(acpi_sleep_callback func, void *refcon)
        /* Restore power management timer state */
        pmTimerRestore();
 
-       /* Restart tick interrupts from the LAPIC timer */
-       rtc_lapic_start_ticking();
+       /* Restart timer interrupts */
+       rtc_timer_start();
 
-       fpinit();
-       clear_fpu();
+       /* Reconfigure FP/SIMD unit */
+       init_fpu();
 
 #if HIBERNATION
 #ifdef __i386__