2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 #include <i386/misc_protos.h>
24 #include <i386/proc_reg.h>
25 #include <i386/pmap.h>
26 #include <i386/mtrr.h>
27 #include <i386/acpi.h>
30 #include <i386/mp_desc.h>
32 #include <kern/cpu_data.h>
34 #include <IOKit/IOHibernatePrivate.h>
35 #include <IOKit/IOPlatformExpert.h>
37 extern void acpi_sleep_cpu(acpi_sleep_callback
, void * refcon
);
38 extern char acpi_wake_start
[];
39 extern char acpi_wake_end
[];
41 extern int serial_init(void);
42 extern unsigned int disableSerialOuput
;
44 extern void set_kbd_leds(int leds
);
46 extern void fpinit(void);
49 acpi_install_wake_handler(void)
51 /* copy wake code to ACPI_WAKE_ADDR in low memory */
52 bcopy_phys(kvtophys((vm_offset_t
)acpi_wake_start
),
53 (addr64_t
) ACPI_WAKE_ADDR
,
54 acpi_wake_end
- acpi_wake_start
);
59 /* return physical address of the wakeup code */
60 return ACPI_WAKE_ADDR
;
63 typedef struct acpi_hibernate_callback_data
{
64 acpi_sleep_callback func
;
66 } acpi_hibernate_callback_data
;
69 acpi_hibernate(void *refcon
)
73 acpi_hibernate_callback_data
*data
= (acpi_hibernate_callback_data
*)refcon
;
75 if (current_cpu_datap()->cpu_hibernate
) {
77 dohalt
= hibernate_write_image();
81 HIBLOG("power off\n");
83 (*PE_halt_restart
)(kPEHaltCPU
);
90 // should we come back via regular wake, set the state in memory.
91 cpu_datap(0)->cpu_hibernate
= 0;
95 (data
->func
)(data
->refcon
);
97 /* should never get here! */
101 acpi_sleep_kernel(acpi_sleep_callback func
, void *refcon
)
103 acpi_hibernate_callback_data data
;
104 boolean_t did_hibernate
;
106 kprintf("acpi_sleep_kernel hib=%d\n", current_cpu_datap()->cpu_hibernate
);
108 /* shutdown local APIC before passing control to BIOS */
112 data
.refcon
= refcon
;
114 /* Save HPET state */
118 * If we're in 64-bit mode, drop back into legacy mode during sleep.
120 if (cpu_mode_is64bit()) {
121 cpu_IA32e_disable(current_cpu_datap());
122 kprintf("acpi_sleep_kernel legacy mode re-entered\n");
126 * Save master CPU state and sleep platform.
127 * Will not return until platform is woken up,
128 * or if sleep failed.
130 acpi_sleep_cpu(acpi_hibernate
, &data
);
132 /* reset UART if kprintf is enabled */
133 if (FALSE
== disableSerialOuput
)
136 kprintf("ret from acpi_sleep_cpu hib=%d\n", current_cpu_datap()->cpu_hibernate
);
138 if (current_cpu_datap()->cpu_hibernate
) {
140 for (i
=0; i
<PMAP_NWINDOWS
; i
++) {
141 *current_cpu_datap()->cpu_pmap
->mapwindow
[i
].prv_CMAP
= 0;
143 current_cpu_datap()->cpu_hibernate
= 0;
144 did_hibernate
= TRUE
;
147 did_hibernate
= FALSE
;
150 /* Re-enable 64-bit mode if necessary. */
151 if (cpu_mode_is64bit()) {
152 cpu_IA32e_enable(current_cpu_datap());
153 cpu_desc_load64(current_cpu_datap());
154 kprintf("acpi_sleep_kernel 64-bit mode re-enabled\n");
155 fast_syscall_init64();
160 /* restore MTRR settings */
163 /* set up PAT following boot processor power up */
167 hibernate_machine_init();
170 /* re-enable and re-init local apic */
174 /* Restore HPET state */
177 /* let the realtime clock reset */