]>
Commit | Line | Data |
---|---|---|
91447636 A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | ||
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> | |
28 | #include <i386/mp.h> | |
29 | ||
30 | #include <kern/cpu_data.h> | |
3a60a9f5 A |
31 | |
32 | #include <IOKit/IOHibernatePrivate.h> | |
91447636 A |
33 | #include <IOKit/IOPlatformExpert.h> |
34 | ||
35 | extern void acpi_sleep_cpu(acpi_sleep_callback, void * refcon); | |
36 | extern char acpi_wake_start[]; | |
37 | extern char acpi_wake_end[]; | |
38 | ||
39 | extern int serial_init(void); | |
40 | extern unsigned int disableSerialOuput; | |
41 | ||
42 | extern void set_kbd_leds(int leds); | |
43 | ||
44 | vm_offset_t | |
45 | acpi_install_wake_handler(void) | |
46 | { | |
47 | /* copy wake code to ACPI_WAKE_ADDR in low memory */ | |
48 | bcopy_phys((addr64_t) kvtophys((vm_offset_t)acpi_wake_start), | |
49 | (addr64_t) ACPI_WAKE_ADDR, | |
50 | acpi_wake_end - acpi_wake_start); | |
51 | ||
52 | /* flush cache */ | |
53 | wbinvd(); | |
54 | ||
55 | /* return physical address of the wakeup code */ | |
56 | return ACPI_WAKE_ADDR; | |
57 | } | |
58 | ||
3a60a9f5 | 59 | typedef struct acpi_hibernate_callback_data { |
91447636 A |
60 | acpi_sleep_callback func; |
61 | void *refcon; | |
3a60a9f5 | 62 | } acpi_hibernate_callback_data; |
91447636 A |
63 | |
64 | static void | |
3a60a9f5 | 65 | acpi_hibernate(void *refcon) |
91447636 | 66 | { |
3a60a9f5 A |
67 | boolean_t hib; |
68 | ||
69 | acpi_hibernate_callback_data *data = (acpi_hibernate_callback_data *)refcon; | |
91447636 | 70 | |
3a60a9f5 A |
71 | if (current_cpu_datap()->cpu_hibernate) { |
72 | hib = hibernate_write_image(); | |
73 | } | |
91447636 A |
74 | |
75 | (data->func)(data->refcon); | |
76 | ||
77 | /* should never get here! */ | |
78 | } | |
79 | ||
80 | void | |
81 | acpi_sleep_kernel(acpi_sleep_callback func, void *refcon) | |
82 | { | |
3a60a9f5 A |
83 | acpi_hibernate_callback_data data; |
84 | boolean_t did_hibernate; | |
91447636 A |
85 | |
86 | /* shutdown local APIC before passing control to BIOS */ | |
87 | lapic_shutdown(); | |
88 | ||
89 | data.func = func; | |
90 | data.refcon = refcon; | |
91 | ||
92 | /* | |
93 | * Save master CPU state and sleep platform. | |
94 | * Will not return until platform is woken up, | |
95 | * or if sleep failed. | |
96 | */ | |
3a60a9f5 | 97 | acpi_sleep_cpu(acpi_hibernate, &data); |
91447636 A |
98 | |
99 | /* reset UART if kprintf is enabled */ | |
100 | if (FALSE == disableSerialOuput) | |
101 | serial_init(); | |
102 | ||
3a60a9f5 A |
103 | if (current_cpu_datap()->cpu_hibernate) { |
104 | * (int *) CM1 = 0; | |
105 | * (int *) CM2 = 0; | |
106 | * (int *) CM3 = 0; | |
107 | ||
108 | current_cpu_datap()->cpu_hibernate = 0; | |
109 | ||
110 | did_hibernate = TRUE; | |
111 | } else { | |
112 | did_hibernate = FALSE; | |
113 | } | |
91447636 A |
114 | |
115 | /* restore MTRR settings */ | |
116 | mtrr_update_cpu(); | |
117 | ||
118 | /* set up PAT following boot processor power up */ | |
119 | pat_init(); | |
120 | ||
3a60a9f5 A |
121 | if (did_hibernate) { |
122 | hibernate_machine_init(); | |
123 | } | |
124 | ||
91447636 A |
125 | /* re-enable and re-init local apic */ |
126 | if (lapic_probe()) | |
127 | lapic_init(); | |
128 | ||
129 | /* let the realtime clock reset */ | |
130 | rtc_sleep_wakeup(); | |
131 | ||
3a60a9f5 A |
132 | if (did_hibernate) { |
133 | enable_preemption(); | |
134 | } | |
91447636 | 135 | } |