]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/acpi.c
xnu-792.2.4.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 * 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>
31 #include <IOKit/IOPlatformExpert.h>
32
33 extern void acpi_sleep_cpu(acpi_sleep_callback, void * refcon);
34 extern char acpi_wake_start[];
35 extern char acpi_wake_end[];
36
37 extern int serial_init(void);
38 extern unsigned int disableSerialOuput;
39
40 extern void set_kbd_leds(int leds);
41
42 vm_offset_t
43 acpi_install_wake_handler(void)
44 {
45 /* copy wake code to ACPI_WAKE_ADDR in low memory */
46 bcopy_phys((addr64_t) kvtophys((vm_offset_t)acpi_wake_start),
47 (addr64_t) ACPI_WAKE_ADDR,
48 acpi_wake_end - acpi_wake_start);
49
50 /* flush cache */
51 wbinvd();
52
53 /* return physical address of the wakeup code */
54 return ACPI_WAKE_ADDR;
55 }
56
57 typedef struct acpi_sleep_callback_data {
58 acpi_sleep_callback func;
59 void *refcon;
60 } acpi_sleep_callback_data;
61
62 static void
63 acpi_sleep_do_callback(void *refcon)
64 {
65 acpi_sleep_callback_data *data = (acpi_sleep_callback_data *)refcon;
66
67
68 (data->func)(data->refcon);
69
70 /* should never get here! */
71 }
72
73 void
74 acpi_sleep_kernel(acpi_sleep_callback func, void *refcon)
75 {
76 acpi_sleep_callback_data data;
77
78 /* shutdown local APIC before passing control to BIOS */
79 lapic_shutdown();
80
81 data.func = func;
82 data.refcon = refcon;
83
84 /*
85 * Save master CPU state and sleep platform.
86 * Will not return until platform is woken up,
87 * or if sleep failed.
88 */
89 acpi_sleep_cpu(acpi_sleep_do_callback, &data);
90
91 /* reset UART if kprintf is enabled */
92 if (FALSE == disableSerialOuput)
93 serial_init();
94
95
96 /* restore MTRR settings */
97 mtrr_update_cpu();
98
99 /* set up PAT following boot processor power up */
100 pat_init();
101
102 /* re-enable and re-init local apic */
103 if (lapic_probe())
104 lapic_init();
105
106 /* let the realtime clock reset */
107 rtc_sleep_wakeup();
108
109 }