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