Intel® Quark™ Microcontroller Software Interface  1.4.0
Intel® Quark™ Microcontroller BSP
power_states.h
1 /*
2  * {% copyright %}
3  */
4 
5 #ifndef __POWER_STATES_H__
6 #define __POWER_STATES_H__
7 
8 #include "qm_common.h"
9 #include "qm_soc_regs.h"
10 
11 /**
12  * SoC Power mode control for Quark SE Microcontrollers.
13  *
14  * Available SoC states are:
15  * - Low Power Sensing Standby (LPSS)
16  * - Sleep
17  *
18  * LPSS can only be enabled from the Sensor core,
19  * refer to @ref qm_ss_power_soc_lpss_enable for further details.
20  *
21  * @defgroup groupSoCPower Quark SE SoC Power states
22  * @{
23  */
24 
25 /**
26  * Enter SoC sleep state.
27  *
28  * Put the SoC into sleep state until next SoC wake event.
29  *
30  * - Core well is turned off
31  * - Always on well is on
32  * - Hybrid Clock is off
33  * - RTC Clock is on
34  *
35  * Possible SoC wake events are:
36  * - Low Power Comparator Interrupt
37  * - AON GPIO Interrupt
38  * - AON Timer Interrupt
39  * - RTC Interrupt
40  */
41 void qm_power_soc_sleep(void);
42 
43 /**
44  * Enter SoC deep sleep state.
45  *
46  * Put the SoC into deep sleep state until next SoC wake event.
47  *
48  * - Core well is turned off
49  * - Always on well is on
50  * - Hybrid Clock is off
51  * - RTC Clock is on
52  *
53  * Possible SoC wake events are:
54  * - Low Power Comparator Interrupt
55  * - AON GPIO Interrupt
56  * - AON Timer Interrupt
57  * - RTC Interrupt
58  *
59  * This function puts 1P8V regulators and 3P3V into Linear Mode.
60  */
61 void qm_power_soc_deep_sleep(void);
62 
63 #if (ENABLE_RESTORE_CONTEXT) && (!QM_SENSOR)
64 /**
65  * Enter SoC sleep state and restore after wake up.
66  *
67  * Put the SoC into sleep state until next SoC wake event
68  * and continue execution after wake up where the application stopped.
69  *
70  * If the library is built with ENABLE_RESTORE_CONTEXT=1, then this function
71  * will use the common RAM __x86_restore_info[0] to save the necessary context
72  * to bring back the CPU to the point where this function was called.
73  * This means that applications should refrain from using them.
74  *
75  * This function calls qm_x86_save_context and qm_x86_restore_context
76  * in order to restore execution where it stopped.
77  * All power management transitions are done by qm_power_soc_sleep().
78  */
80 
81 /**
82  * Enter SoC deep sleep state and restore after wake up.
83  *
84  * Put the SoC into deep sleep state until next SoC wake event
85  * and continue execution after wake up where the application stopped.
86  *
87  * If the library is built with ENABLE_RESTORE_CONTEXT=1, then this function
88  * will use the common RAM __x86_restore_info[0] to save the necessary context
89  * to bring back the CPU to the point where this function was called.
90  * This means that applications should refrain from using them.
91  *
92  * This function calls qm_x86_save_context and qm_x86_restore_context
93  * in order to restore execution where it stopped.
94  * All power management transitions are done by qm_power_soc_deep_sleep().
95  */
97 
98 /**
99  * Save context, enter x86 C2 power save state and restore after wake up.
100  *
101  * This routine is same as qm_power_soc_sleep_restore(), just instead of
102  * going to sleep it will go to C2 power save state.
103  * Note: this function has a while(1) which will spin until we enter
104  * (and exit) sleep while the power state change will be managed by
105  * the other core.
106  */
107 void qm_power_sleep_wait(void);
108 
109 /**
110  * Enable the x86 startup restore flag, see GPS0 #define in qm_soc_regs.h
111  */
113 
114 #endif /* ENABLE_RESTORE_CONTEXT */
115 
116 /**
117  * @}
118  */
119 
120 #if (!QM_SENSOR)
121 /**
122  * Host Power mode control for Quark SE Microcontrollers.<BR>
123  * These functions cannot be called from the Sensor Subsystem.
124  *
125  * @defgroup groupSEPower Quark SE Host Power states
126  * @{
127  */
128 
129 /**
130  * Enter Host C1 state.
131  *
132  * Put the Host into C1.<BR>
133  * Processor Clock is gated in this state.<BR>
134  * Nothing is turned off in this state.
135  *
136  * This function can be called with interrupts disabled.
137  * Interrupts will be enabled before triggering the transition.
138  *
139  * A wake event causes the Host to transition to C0.<BR>
140  * A wake event is a host interrupt.
141  */
142 void qm_power_cpu_c1(void);
143 
144 /**
145  * Enter Host C2 state or SoC LPSS state.
146  *
147  * Put the Host into C2.
148  * Processor Clock is gated in this state.
149  * All rails are supplied.
150  *
151  * This enables entry in LPSS if:
152  * - Sensor Subsystem is in SS2.
153  * - LPSS entry is enabled.
154  *
155  * If C2 is entered:
156  * - A wake event causes the Host to transition to C0.
157  * - A wake event is a host interrupt.
158  *
159  * If LPSS is entered:
160  * - LPSS wake events applies.
161  * - If the Sensor Subsystem wakes the SoC from LPSS, Host is back in C2.
162  */
163 void qm_power_cpu_c2(void);
164 
165 /**
166  * Enter Host C2LP state or SoC LPSS state.
167  *
168  * Put the Host into C2LP.
169  * Processor Complex Clock is gated in this state.
170  * All rails are supplied.
171  *
172  * This enables entry in LPSS if:
173  * - Sensor Subsystem is in SS2.
174  * - LPSS is allowed.
175  *
176  * If C2LP is entered:
177  * - A wake event causes the Host to transition to C0.
178  * - A wake event is a Host interrupt.
179  *
180  * If LPSS is entered:
181  * - LPSS wake events apply if LPSS is entered.
182  * - If the Sensor Subsystem wakes the SoC from LPSS,
183  * Host transitions back to C2LP.
184  */
185 void qm_power_cpu_c2lp(void);
186 #endif
187 
188 #if (ENABLE_RESTORE_CONTEXT) && (!QM_SENSOR) && (!UNIT_TEST)
189 /**
190  * Save resume vector.
191  *
192  * Saves the resume vector in the common RAM __x86_restore_info[0] location.
193  * The bootloader will jump to the resume vector once a wake up event
194  * is triggered.
195  */
196 #define qm_x86_set_resume_vector(_restore_label, shared_mem) \
197  __asm__ __volatile__("movl $" #_restore_label ", %[trap]\n\t" \
198  : /* Output operands. */ \
199  : /* Input operands. */ \
200  [trap] "m"(shared_mem) \
201  : /* Clobbered registers list. */ \
202  )
203 
204 /* Save execution context.
205  *
206  * This routine saves 'idtr', EFLAGS and general purpose registers onto the
207  * stack.
208  *
209  * The bootloader will set the 'gdt' before calling into the 'restore_trap'
210  * function, so we don't need to save it here.
211  */
212 #define qm_x86_save_context(stack_pointer) \
213  __asm__ __volatile__("sub $8, %%esp\n\t" \
214  "sidt (%%esp)\n\t" \
215  "lea %[stackpointer], %%eax\n\t" \
216  "pushfl\n\t" \
217  "pushal\n\t" \
218  "movl %%dr0, %%edx\n\t" \
219  "pushl %%edx\n\t" \
220  "movl %%dr1, %%edx\n\t" \
221  "pushl %%edx\n\t" \
222  "movl %%dr2, %%edx\n\t" \
223  "pushl %%edx\n\t" \
224  "movl %%dr3, %%edx\n\t" \
225  "pushl %%edx\n\t" \
226  "movl %%dr6, %%edx\n\t" \
227  "pushl %%edx\n\t" \
228  "movl %%dr7, %%edx\n\t" \
229  "pushl %%edx\n\t" \
230  "movl %%esp, (%%eax)\n\t" \
231  : /* Output operands. */ \
232  : /* Input operands. */ \
233  [stackpointer] "m"(stack_pointer) \
234  : /* Clobbered registers list. */ \
235  "eax", "edx")
236 
237 /* Restore trap. This routine recovers the stack pointer into esp and retrieves
238  * 'idtr', EFLAGS and general purpose registers from stack.
239  *
240  * This routine is called from the bootloader to restore the execution context
241  * from before entering in sleep mode.
242  */
243 #define qm_x86_restore_context(_restore_label, stack_pointer) \
244  __asm__ __volatile__(#_restore_label ":\n\t" \
245  "lea %[stackpointer], %%eax\n\t" \
246  "movl (%%eax), %%esp\n\t" \
247  "popl %%edx\n\t" \
248  "movl %%edx, %%dr7\n\t" \
249  "popl %%edx\n\t" \
250  "movl %%edx, %%dr6\n\t" \
251  "popl %%edx\n\t" \
252  "movl %%edx, %%dr3\n\t" \
253  "popl %%edx\n\t" \
254  "movl %%edx, %%dr2\n\t" \
255  "popl %%edx\n\t" \
256  "movl %%edx, %%dr1\n\t" \
257  "popl %%edx\n\t" \
258  "movl %%edx, %%dr0\n\t" \
259  "popal\n\t" \
260  "popfl\n\t" \
261  "lidt (%%esp)\n\t" \
262  "add $8, %%esp\n\t" \
263  : /* Output operands. */ \
264  : /* Input operands. */ \
265  [stackpointer] "m"(stack_pointer) \
266  : /* Clobbered registers list. */ \
267  "eax", "edx")
268 
269 #else
270 #define qm_x86_set_resume_vector(_restore_label, shared_mem)
271 #define qm_x86_save_context(stack_pointer)
272 #define qm_x86_restore_context(_restore_label, stack_pointer)
273 #endif
274 
275 /**
276  * @}
277  */
278 
279 #endif /* __POWER_STATES_H__ */
void qm_power_cpu_c1(void)
Enter Host C1 state.
Definition: power_states.c:145
void qm_power_soc_deep_sleep(const qm_power_wake_event_t wake_event)
Put SoC to deep sleep.
Definition: power_states.c:180
void qm_power_cpu_c2lp(void)
Enter Host C2LP state or SoC LPSS state.
Definition: power_states.c:170
void qm_power_soc_deep_sleep_restore(void)
Enter SoC deep sleep state and restore after wake up.
Definition: power_states.c:304
void qm_power_soc_sleep()
Put SoC to sleep.
Definition: power_states.c:59
void qm_power_soc_sleep_restore(void)
Enter SoC sleep state and restore after wake up.
Definition: power_states.c:135
void qm_power_soc_set_x86_restore_flag(void)
Enable the x86 startup restore flag, see GPS0 #define in qm_soc_regs.h.
Definition: power_states.c:138
void qm_power_sleep_wait(void)
Save context, enter x86 C2 power save state and restore after wake up.
Definition: power_states.c:108
void qm_power_cpu_c2(void)
Enter Host C2 state or SoC LPSS state.
Definition: power_states.c:160