4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include <sys/types.h>
28 #include <sys/smp_impldefs.h>
29 #include <sys/promif.h>
32 #include <sys/archsystm.h>
33 #include <sys/cpuvar.h>
35 #include <vm/seg_kmem.h>
38 #include <sys/machsystm.h>
39 #include <sys/clock.h>
41 #include <sys/cpr_wakecode.h>
42 #include <sys/acpi/acpi.h>
48 #include <sys/x86_archext.h>
49 #include <sys/reboot.h>
50 #include <sys/cpu_module.h>
57 int acpi_rtc_wake
= 0x0; /* wake in N seconds */
60 static uint8_t branchbuf
[64 * 1024]; /* for the HDT branch trace stuff */
65 #define BOOTCPU 0 /* cpu 0 is always the boot cpu */
67 extern void kernel_wc_code(void);
68 extern tod_ops_t
*tod_ops
;
69 extern int flushes_require_xcalls
;
70 extern int tsc_gethrtime_enable
;
72 extern cpuset_t cpu_ready_set
;
76 * This is what we've all been waiting for!
79 acpi_enter_sleepstate(s3a_t
*s3ap
)
81 ACPI_PHYSICAL_ADDRESS wakephys
= s3ap
->s3a_wakephys
;
82 caddr_t wakevirt
= rm_platter_va
;
84 wakecode_t
*wp
= (wakecode_t
*)wakevirt
;
85 uint_t Sx
= s3ap
->s3a_state
;
88 /* Set waking vector */
89 if (AcpiSetFirmwareWakingVector(wakephys
) != AE_OK
) {
91 PMD(PMD_SX
, ("Can't SetFirmwareWakingVector(%lx)\n",
97 /* Enable wake events */
98 if (AcpiEnableEvent(ACPI_EVENT_POWER_BUTTON
, 0) != AE_OK
) {
100 PMD(PMD_SX
, ("Can't EnableEvent(POWER_BUTTON)\n"))
102 if (acpi_rtc_wake
> 0) {
103 /* clear the RTC bit first */
104 (void) AcpiWriteBitRegister(ACPI_BITREG_RT_CLOCK_STATUS
, 1);
106 if (AcpiEnableEvent(ACPI_EVENT_RTC
, 0) != AE_OK
) {
108 PMD(PMD_SX
, ("Can't EnableEvent(RTC)\n"))
112 * Set RTC to wake us in a wee while.
114 mutex_enter(&tod_lock
);
116 TODOP_SETWAKE(tod_ops
, acpi_rtc_wake
);
117 mutex_exit(&tod_lock
);
121 * Prepare for sleep ... could've done this earlier?
124 PMD(PMD_SX
, ("Calling AcpiEnterSleepStatePrep(%d) ...\n", Sx
))
125 if (AcpiEnterSleepStatePrep(Sx
) != AE_OK
) {
126 PMD(PMD_SX
, ("... failed\n!"))
130 switch (s3ap
->s3a_test_point
) {
131 case DEVICE_SUSPEND_TO_RAM
:
132 case FORCE_SUSPEND_TO_RAM
:
138 ASSERT(s3ap
->s3a_test_point
== LOOP_BACK_NONE
);
142 * Tell the hardware to sleep.
145 PMD(PMD_SX
, ("Calling AcpiEnterSleepState(%d) ...\n", Sx
))
146 if (AcpiEnterSleepState(Sx
) != AE_OK
) {
148 PMD(PMD_SX
, ("... failed!\n"))
153 /* cleanup is done in the caller */
158 acpi_exit_sleepstate(s3a_t
*s3ap
)
160 int Sx
= s3ap
->s3a_state
;
163 PMD(PMD_SX
, ("!We woke up!\n"))
166 if (AcpiLeaveSleepState(Sx
) != AE_OK
) {
168 PMD(PMD_SX
, ("Problem with LeaveSleepState!\n"))
172 if (AcpiClearEvent(ACPI_EVENT_POWER_BUTTON
) != AE_OK
) {
174 PMD(PMD_SX
, ("Problem w/ ClearEvent(POWER_BUTTON)\n"))
176 if (acpi_rtc_wake
> 0 &&
177 AcpiDisableEvent(ACPI_EVENT_RTC
, 0) != AE_OK
) {
179 PMD(PMD_SX
, ("Problem w/ DisableEvent(RTC)\n"))
182 PMD(PMD_SX
, ("Exiting acpi_sleepstate() => 0\n"))