1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/types.h>
#include <sys/smp_impldefs.h>
#include <sys/promif.h>
#include <sys/kmem.h>
#include <sys/archsystm.h>
#include <sys/cpuvar.h>
#include <sys/pte.h>
#include <vm/seg_kmem.h>
#include <sys/epm.h>
#include <sys/cpr.h>
#include <sys/machsystm.h>
#include <sys/clock.h>
#include <sys/cpr_wakecode.h>
#include <sys/acpi/acpi.h>
#ifdef OLDPMCODE
#include "acpi.h"
#endif
#include <sys/x86_archext.h>
#include <sys/reboot.h>
#include <sys/cpu_module.h>
#include <sys/kdi.h>
/*
* S3 stuff
*/
int acpi_rtc_wake = 0x0; /* wake in N seconds */
#if 0 /* debug */
static uint8_t branchbuf[64 * 1024]; /* for the HDT branch trace stuff */
#endif /* debug */
extern int boothowto;
#define BOOTCPU 0 /* cpu 0 is always the boot cpu */
extern void kernel_wc_code(void);
extern tod_ops_t *tod_ops;
extern int flushes_require_xcalls;
extern int tsc_gethrtime_enable;
extern cpuset_t cpu_ready_set;
extern void *(*cpu_pause_func)(void *);
/*
* This is what we've all been waiting for!
*/
int
acpi_enter_sleepstate(s3a_t *s3ap)
{
ACPI_PHYSICAL_ADDRESS wakephys = s3ap->s3a_wakephys;
caddr_t wakevirt = rm_platter_va;
/*LINTED*/
wakecode_t *wp = (wakecode_t *)wakevirt;
uint_t Sx = s3ap->s3a_state;
PT(PT_SWV);
/* Set waking vector */
if (AcpiSetFirmwareWakingVector(wakephys) != AE_OK) {
PT(PT_SWV_FAIL);
PMD(PMD_SX, ("Can't SetFirmwareWakingVector(%lx)\n",
(long)wakephys))
goto insomnia;
}
PT(PT_EWE);
/* Enable wake events */
if (AcpiEnableEvent(ACPI_EVENT_POWER_BUTTON, 0) != AE_OK) {
PT(PT_EWE_FAIL);
PMD(PMD_SX, ("Can't EnableEvent(POWER_BUTTON)\n"))
}
if (acpi_rtc_wake > 0) {
/* clear the RTC bit first */
(void) AcpiWriteBitRegister(ACPI_BITREG_RT_CLOCK_STATUS, 1);
PT(PT_RTCW);
if (AcpiEnableEvent(ACPI_EVENT_RTC, 0) != AE_OK) {
PT(PT_RTCW_FAIL);
PMD(PMD_SX, ("Can't EnableEvent(RTC)\n"))
}
/*
* Set RTC to wake us in a wee while.
*/
mutex_enter(&tod_lock);
PT(PT_TOD);
TODOP_SETWAKE(tod_ops, acpi_rtc_wake);
mutex_exit(&tod_lock);
}
/*
* Prepare for sleep ... could've done this earlier?
*/
PT(PT_SXP);
PMD(PMD_SX, ("Calling AcpiEnterSleepStatePrep(%d) ...\n", Sx))
if (AcpiEnterSleepStatePrep(Sx) != AE_OK) {
PMD(PMD_SX, ("... failed\n!"))
goto insomnia;
}
switch (s3ap->s3a_test_point) {
case DEVICE_SUSPEND_TO_RAM:
case FORCE_SUSPEND_TO_RAM:
case LOOP_BACK_PASS:
return (0);
case LOOP_BACK_FAIL:
return (1);
default:
ASSERT(s3ap->s3a_test_point == LOOP_BACK_NONE);
}
/*
* Tell the hardware to sleep.
*/
PT(PT_SXE);
PMD(PMD_SX, ("Calling AcpiEnterSleepState(%d) ...\n", Sx))
if (AcpiEnterSleepState(Sx) != AE_OK) {
PT(PT_SXE_FAIL);
PMD(PMD_SX, ("... failed!\n"))
}
insomnia:
PT(PT_INSOM);
/* cleanup is done in the caller */
return (1);
}
int
acpi_exit_sleepstate(s3a_t *s3ap)
{
int Sx = s3ap->s3a_state;
PT(PT_WOKE);
PMD(PMD_SX, ("!We woke up!\n"))
PT(PT_LSS);
if (AcpiLeaveSleepState(Sx) != AE_OK) {
PT(PT_LSS_FAIL);
PMD(PMD_SX, ("Problem with LeaveSleepState!\n"))
}
PT(PT_CPB);
if (AcpiClearEvent(ACPI_EVENT_POWER_BUTTON) != AE_OK) {
PT(PT_CPB_FAIL);
PMD(PMD_SX, ("Problem w/ ClearEvent(POWER_BUTTON)\n"))
}
if (acpi_rtc_wake > 0 &&
AcpiDisableEvent(ACPI_EVENT_RTC, 0) != AE_OK) {
PT(PT_DRTC_FAIL);
PMD(PMD_SX, ("Problem w/ DisableEvent(RTC)\n"))
}
PMD(PMD_SX, ("Exiting acpi_sleepstate() => 0\n"))
return (0);
}
|