]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/acpi.c
xnu-792.21.3.tar.gz
[apple/xnu.git] / osfmk / i386 / acpi.c
index 51623e41c7cf1627ed35c644dd6a73387662c3b5..006fe9d9b00f8ea4f018595d56dfdbe99694ea9c 100644 (file)
@@ -1,23 +1,29 @@
 /*
  * Copyright (c) 2000 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 <i386/misc_protos.h>
@@ -28,6 +34,8 @@
 #include <i386/mp.h>
 
 #include <kern/cpu_data.h>
+
+#include <IOKit/IOHibernatePrivate.h>
 #include <IOKit/IOPlatformExpert.h>
 
 extern void    acpi_sleep_cpu(acpi_sleep_callback, void * refcon);
@@ -54,16 +62,21 @@ acpi_install_wake_handler(void)
        return ACPI_WAKE_ADDR;
 }
 
-typedef struct acpi_sleep_callback_data {
+typedef struct acpi_hibernate_callback_data {
     acpi_sleep_callback func;
     void *refcon;
-} acpi_sleep_callback_data;
+} acpi_hibernate_callback_data;
 
 static void
-acpi_sleep_do_callback(void *refcon)
+acpi_hibernate(void *refcon)
 {
-    acpi_sleep_callback_data *data = (acpi_sleep_callback_data *)refcon;
+    boolean_t hib;
+
+    acpi_hibernate_callback_data *data = (acpi_hibernate_callback_data *)refcon;
 
+    if (current_cpu_datap()->cpu_hibernate) {
+        hib = hibernate_write_image();
+    }
 
     (data->func)(data->refcon);
 
@@ -73,7 +86,8 @@ acpi_sleep_do_callback(void *refcon)
 void
 acpi_sleep_kernel(acpi_sleep_callback func, void *refcon)
 {
-    acpi_sleep_callback_data data;
+    acpi_hibernate_callback_data data;
+    boolean_t did_hibernate;
 
        /* shutdown local APIC before passing control to BIOS */
        lapic_shutdown();
@@ -86,12 +100,23 @@ acpi_sleep_kernel(acpi_sleep_callback func, void *refcon)
         * Will not return until platform is woken up,
         * or if sleep failed.
         */
-    acpi_sleep_cpu(acpi_sleep_do_callback, &data);
+    acpi_sleep_cpu(acpi_hibernate, &data);
 
        /* reset UART if kprintf is enabled */
        if (FALSE == disableSerialOuput)
                serial_init();
 
+    if (current_cpu_datap()->cpu_hibernate) {
+        * (int *) CM1 = 0;
+        * (int *) CM2 = 0;
+        * (int *) CM3 = 0;
+
+        current_cpu_datap()->cpu_hibernate = 0;
+
+        did_hibernate = TRUE;
+    } else {
+        did_hibernate = FALSE;
+    }
 
        /* restore MTRR settings */
        mtrr_update_cpu();
@@ -99,6 +124,10 @@ acpi_sleep_kernel(acpi_sleep_callback func, void *refcon)
        /* set up PAT following boot processor power up */
        pat_init();
 
+    if (did_hibernate) {
+        hibernate_machine_init();
+    }
+        
        /* re-enable and re-init local apic */
        if (lapic_probe())
                lapic_init();
@@ -106,4 +135,7 @@ acpi_sleep_kernel(acpi_sleep_callback func, void *refcon)
        /* let the realtime clock reset */
        rtc_sleep_wakeup();
 
+    if (did_hibernate) {
+        enable_preemption();
+    }
 }