forked from lowRISC/opentitan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dif_pwrmgr.h
407 lines (374 loc) · 12.7 KB
/
dif_pwrmgr.h
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
#ifndef OPENTITAN_SW_DEVICE_LIB_DIF_DIF_PWRMGR_H_
#define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_PWRMGR_H_
/**
* @file
* @brief <a href="/book/hw/top_earlgrey/ip_autogen/pwrmgr/">Power Manager</a>
* Device Interface Functions
*/
#include <stdint.h>
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/dif/dif_base.h"
#include "sw/device/lib/dif/autogen/dif_pwrmgr_autogen.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/**
* A request type, i.e. wakeup or reset.
*/
typedef enum dif_pwrmgr_req_type {
/**
* A wakeup request.
*/
kDifPwrmgrReqTypeWakeup,
/**
* A reset request.
*/
kDifPwrmgrReqTypeReset,
} dif_pwrmgr_req_type_t;
/**
* Options for enabling/disabling various clock and power domains
* in low and active power states.
*
* Constants below are bitmasks that can be combined to define configurations.
*
* See also: `dif_pwrmgr_domain_config_t`.
*/
typedef enum dif_pwrmgr_domain_option {
/**
* Enable core clock in low power state.
*/
kDifPwrmgrDomainOptionCoreClockInLowPower = (1u << 0),
/**
* Enable input/output (IO) clock in low power state.
*/
kDifPwrmgrDomainOptionIoClockInLowPower = (1u << 1),
/**
* Enable USB clock in low power state.
*/
kDifPwrmgrDomainOptionUsbClockInLowPower = (1u << 2),
/**
* Enable USB clock in active power state.
*/
kDifPwrmgrDomainOptionUsbClockInActivePower = (1u << 3),
/**
* Enable main power domain in low power state.
*/
kDifPwrmgrDomainOptionMainPowerInLowPower = (1u << 4),
} dif_pwrmgr_domain_option_t;
/**
* A set of domain options.
*
* This type is used for specifying and querying which clock and power domains
* are enabled in low and active power states.
*
* See also: `dif_pwrmgr_domain_option_t`.
*/
typedef uint8_t dif_pwrmgr_domain_config_t;
/**
* A wakeup request source.
*
* Constants below are bitmasks that can be used to define sets of wakeup
* request sources.
*
* See also: `dif_pwrmgr_request_sources_t`.
*
* Note: This needs to be updated once the HW is finalized.
*/
typedef enum dif_pwrmgr_wakeup_request_source {
kDifPwrmgrWakeupRequestSourceOne = (1u << 0),
kDifPwrmgrWakeupRequestSourceTwo = (1u << 1),
kDifPwrmgrWakeupRequestSourceThree = (1u << 2),
kDifPwrmgrWakeupRequestSourceFour = (1u << 3),
kDifPwrmgrWakeupRequestSourceFive = (1u << 4),
kDifPwrmgrWakeupRequestSourceSix = (1u << 5),
} dif_pwrmgr_wakeup_request_source_t;
/**
* A reset request source.
*
* Constants below are bitmasks that can be used to define sets of reset
* request sources.
*
* See also: `dif_pwrmgr_request_sources_t`.
*
* Note: This needs to be updated once the HW is finalized.
*/
typedef enum dif_pwrmgr_reset_request_source {
kDifPwrmgrResetRequestSourceOne = (1u << 0),
kDifPwrmgrResetRequestSourceTwo = (1u << 1),
} dif_pwrmgr_reset_request_source_t;
/**
* A set of request sources.
*
* This type is used for specifying which request sources are enabled for a
* particular request type, i.e. wakeup or reset, as well querying wakeup
* reasons.
*
* See also: `dif_pwrmgr_wakeup_request_source_t`,
* `dif_pwrmgr_reset_request_source_t`.
*/
typedef uint32_t dif_pwrmgr_request_sources_t;
/**
* A wakeup type.
*
* Constants below are bitmasks that can be used to define sets of wakeup types.
*
* See also: `dif_pwrmgr_wakeup_types_t`.
*/
typedef enum dif_pwrmgr_wakeup_type {
/**
* Wakeup due to a peripheral request.
*/
kDifPwrmgrWakeupTypeRequest = (1u << 0),
/**
* Despite low power mode being enabled and executing a wait for interrupt
* (WFI) instruction, an interrupt arrived at just the right time to break the
* executing core out of WFI.
*/
kDifPwrmgrWakeupTypeFallThrough = (1u << 1),
/**
* Despite low power mode being enabled and executing a wait for interrupt
* (WFI) instruction, an active flash, life cycle, or OTP operation was
* in progress when the power controller attempted to initiate low power
* entry.
*/
kDifPwrmgrWakeupTypeAbort = (1u << 2),
} dif_pwrmgr_wakeup_type_t;
/**
* A set of wakeup types.
*
* See also: `dif_pwrmgr_wakeup_type_t`.
*/
typedef uint8_t dif_pwrmgr_wakeup_types_t;
typedef enum dif_pwrmgr_fatal_err_type {
/**
* A fatal error for regfile integrity.
*/
kDifPwrmgrFatalErrTypeRegfileIntegrity = 1u << 0,
/**
* A fatal error for escalation timeout.
*/
kDifPwrmgrFatalErrTypeEscalationTimeout = 1u << 1,
/**
* A fatal error for main power glitch.
*/
kDifPwrmgrFatalErrTypeMainPowerGlitch = 1u << 2,
} dif_pwrmgr_fatal_err_type_t;
/**
* A set of fatal errors.
*
* This type is used to read the fatal error codes.
*/
typedef uint32_t dif_pwrmgr_fatal_err_codes_t;
/**
* Wakeup types and requests from sources since the last time recording started.
*/
typedef struct dif_pwrmgr_wakeup_reason {
/**
* Wakeup types since the last time recording started.
*/
dif_pwrmgr_wakeup_types_t types;
/**
* Sources that requested wakeup since the last time recording started.
*/
dif_pwrmgr_request_sources_t request_sources;
} dif_pwrmgr_wakeup_reason_t;
/**
* Enables or disables low power state.
*
* When enabled, the power manager transitions to low power state on the next
* wait for interrupt (WFI) instruction. Since the hardware clears the
* corresponding bit automatically, this function must be called before each
* transition to low power state.
*
* This function can be configured to skip synchronization to the slow clock
* domain, under the assumption that timely synchronization will be performed
* by some of the other functions that can trigger it.
*
* @param pwrmgr A power manager handle.
* @param new_state Whether low power state is enabled.
* @param sync_state Whether to wait for state to transfer to slow domain
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_low_power_set_enabled(const dif_pwrmgr_t *pwrmgr,
dif_toggle_t new_state,
dif_toggle_t sync_state);
/**
* Checks whether low power state is enabled.
*
* @param pwrmgr A power manager handle.
* @param[out] cur_state Whether low power state is enabled.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_low_power_get_enabled(const dif_pwrmgr_t *pwrmgr,
dif_toggle_t *cur_state);
/**
* Configures power manager to enable/disable various clock and power domains in
* low and active power states.
*
* This function can be configured to skip synchronization to the slow clock
* domain, under the assumption that timely synchronization will be performed
* by some of the other functions that can trigger it.
*
* @param pwrmgr A power manager handle.
* @param config A domain configuration.
* @param sync_state Whether to wait for state to transfer to slow domain
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_set_domain_config(const dif_pwrmgr_t *pwrmgr,
dif_pwrmgr_domain_config_t config,
dif_toggle_t sync_state);
/**
* Gets current power manager configuration.
*
* @param pwrmgr A power manager handle.
* @param[out] config Current configuration.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_get_domain_config(const dif_pwrmgr_t *pwrmgr,
dif_pwrmgr_domain_config_t *config);
/**
* Sets sources enabled for a request type.
*
* A wakeup or reset request can be triggered by multiple sources, e.g. GPIO,
* watchdog timer, USB, etc. This function sets which sources are enabled for a
* particular request type.
*
* This function can be configured to skip synchronization to the slow clock
* domain, under the assumption that timely synchronization will be performed
* by some of the other functions that can trigger it.
*
* @param pwrmgr A power manager handle.
* @param req_type A request type.
* @param sources Sources enabled for the given request type.
* @param sync_state Whether to wait for state to transfer to slow domain
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_set_request_sources(
const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type,
dif_pwrmgr_request_sources_t sources, dif_toggle_t sync_state);
/**
* Gets sources enabled for a request type.
*
* A wakeup or reset request can be triggered by multiple sources, e.g. GPIO,
* watchdog timer, USB, etc. This function gets which sources are enabled for a
* particular request type.
*
* @param pwrmgr A power manager handle.
* @param req_type A request type.
* @param[out] sources Sources enabled for the given request type.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_get_request_sources(
const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type,
dif_pwrmgr_request_sources_t *sources);
/**
* Gets request sources that are currently active for a request type.
*
* @param pwrmgr A power manager handle.
* @param req_type A request type.
* @param[out] sources Request sources that are currently active for the given
* request type.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_get_current_request_sources(
const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type,
dif_pwrmgr_request_sources_t *sources);
/**
* Locks sources of a request type.
*
* Once the sources of a particular request type is locked, they cannot be
* changed until the hardware is reset.
*
* @param pwrmgr A power manager handle.
* @param req_type A request type.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_request_sources_lock(const dif_pwrmgr_t *pwrmgr,
dif_pwrmgr_req_type_t req_type);
/**
* Checks whether sources of a request type is locked.
*
* @param pwrmgr A power manager handle.
* @param req_type A request type.
* @param[out] is_locked Whether sources of the given request type is locked.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_request_sources_is_locked(
const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type,
bool *is_locked);
/**
* Enables or disables recording of wakeup requests.
*
* Power manager automatically starts recording wakeup requests when it
* begins a valid low power entry. Recording continues until it is explicitly
* disabled by calling this function.
*
* @param pwrmgr A power manager handle.
* @param new_state Whether wakeup requests should be recorded.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_wakeup_request_recording_set_enabled(
const dif_pwrmgr_t *pwrmgr, dif_toggle_t new_state);
/**
* Checks whether wakeup requests are being recorded.
*
* @param pwrmgr A power manager handle.
* @param[out] cur_state Whether wakeup requests are being recorded.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_wakeup_request_recording_get_enabled(
const dif_pwrmgr_t *pwrmgr, dif_toggle_t *cur_state);
/**
* Gets wakeup reason and source requests since the last time recording
* started.
*
* Power manager automatically starts recording wakeup requests when it
* begins a valid low power entry. Recording continues until it is explicitly
* disabled by calling `dif_pwrmgr_wakeup_request_recording_set_enabled`. Thus,
* it is possible to record wakeup requests from multiple sources as well as
* multiple wakeup types.
*
* @param pwrmgr A power manager handle.
* @param[out] reason Wakeup reasons.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_wakeup_reason_get(const dif_pwrmgr_t *pwrmgr,
dif_pwrmgr_wakeup_reason_t *reason);
/**
* Clears wakeup reason(s) recorded since the last time recording started.
*
* @param pwrmgr A power manager handle.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_wakeup_reason_clear(const dif_pwrmgr_t *pwrmgr);
/**
* Read the fatal error codes.
*
* @param pwrmgr Power Manager Handle.
* @param[out] codes The fatal error codes.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_pwrmgr_fatal_err_code_get_codes(
const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_fatal_err_codes_t *codes);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_PWRMGR_H_