]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/acpi.c
xnu-792.6.56.tar.gz
[apple/xnu.git] / osfmk / i386 / acpi.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #include <i386/misc_protos.h>
25 #include <i386/proc_reg.h>
26 #include <i386/pmap.h>
27 #include <i386/mtrr.h>
28 #include <i386/acpi.h>
29 #include <i386/mp.h>
30
31 #include <kern/cpu_data.h>
32
33 #include <IOKit/IOHibernatePrivate.h>
34 #include <IOKit/IOPlatformExpert.h>
35
36 extern void acpi_sleep_cpu(acpi_sleep_callback, void * refcon);
37 extern char acpi_wake_start[];
38 extern char acpi_wake_end[];
39
40 extern int serial_init(void);
41 extern unsigned int disableSerialOuput;
42
43 extern void set_kbd_leds(int leds);
44
45 vm_offset_t
46 acpi_install_wake_handler(void)
47 {
48 /* copy wake code to ACPI_WAKE_ADDR in low memory */
49 bcopy_phys((addr64_t) kvtophys((vm_offset_t)acpi_wake_start),
50 (addr64_t) ACPI_WAKE_ADDR,
51 acpi_wake_end - acpi_wake_start);
52
53 /* flush cache */
54 wbinvd();
55
56 /* return physical address of the wakeup code */
57 return ACPI_WAKE_ADDR;
58 }
59
60 typedef struct acpi_hibernate_callback_data {
61 acpi_sleep_callback func;
62 void *refcon;
63 } acpi_hibernate_callback_data;
64
65 static void
66 acpi_hibernate(void *refcon)
67 {
68 boolean_t hib;
69
70 acpi_hibernate_callback_data *data = (acpi_hibernate_callback_data *)refcon;
71
72 if (current_cpu_datap()->cpu_hibernate) {
73 hib = hibernate_write_image();
74 }
75
76 (data->func)(data->refcon);
77
78 /* should never get here! */
79 }
80
81 void
82 acpi_sleep_kernel(acpi_sleep_callback func, void *refcon)
83 {
84 acpi_hibernate_callback_data data;
85 boolean_t did_hibernate;
86
87 /* shutdown local APIC before passing control to BIOS */
88 lapic_shutdown();
89
90 data.func = func;
91 data.refcon = refcon;
92
93 /*
94 * Save master CPU state and sleep platform.
95 * Will not return until platform is woken up,
96 * or if sleep failed.
97 */
98 acpi_sleep_cpu(acpi_hibernate, &data);
99
100 /* reset UART if kprintf is enabled */
101 if (FALSE == disableSerialOuput)
102 serial_init();
103
104 if (current_cpu_datap()->cpu_hibernate) {
105 * (int *) CM1 = 0;
106 * (int *) CM2 = 0;
107 * (int *) CM3 = 0;
108
109 current_cpu_datap()->cpu_hibernate = 0;
110
111 did_hibernate = TRUE;
112 } else {
113 did_hibernate = FALSE;
114 }
115
116 /* restore MTRR settings */
117 mtrr_update_cpu();
118
119 /* set up PAT following boot processor power up */
120 pat_init();
121
122 if (did_hibernate) {
123 hibernate_machine_init();
124 }
125
126 /* re-enable and re-init local apic */
127 if (lapic_probe())
128 lapic_init();
129
130 /* let the realtime clock reset */
131 rtc_sleep_wakeup();
132
133 if (did_hibernate) {
134 enable_preemption();
135 }
136 }