ReactOS 0.4.17-dev-1190-g4c812f4
sleep.h File Reference
#include <uacpi/types.h>
#include <uacpi/status.h>
#include <uacpi/uacpi.h>
Include dependency graph for sleep.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE (uacpi_status uacpi_set_waking_vector(uacpi_phys_addr addr32, uacpi_phys_addr addr64)) typedef enum uacpi_sleep_state
 
uacpi_status uacpi_prepare_for_sleep_state (uacpi_sleep_state)
 
uacpi_status uacpi_enter_sleep_state (uacpi_sleep_state)
 
uacpi_status uacpi_enter_sleep_state_simple (uacpi_sleep_state)
 
uacpi_status uacpi_prepare_for_wake_from_sleep_state (uacpi_sleep_state)
 
uacpi_status uacpi_wake_from_sleep_state (uacpi_sleep_state)
 
uacpi_status uacpi_reboot (void)
 

Variables

 uacpi_sleep_state
 

Function Documentation

◆ UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE()

UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE ( uacpi_status   uacpi_set_waking_vector uacpi_phys_addr addr32, uacpi_phys_addr addr64)

Set the firmware waking vector in FACS.

'addr32' is the real mode entry-point address 'addr64' is the protected mode entry-point address

Definition at line 19 of file sleep.h.

24 {
25 UACPI_SLEEP_STATE_S0 = 0,
26 UACPI_SLEEP_STATE_S1,
27 UACPI_SLEEP_STATE_S2,
28 UACPI_SLEEP_STATE_S3,
29 UACPI_SLEEP_STATE_S4,
30 UACPI_SLEEP_STATE_S5,
31 UACPI_SLEEP_STATE_MAX = UACPI_SLEEP_STATE_S5,
uacpi_sleep_state
Definition: sleep.h:32

◆ uacpi_enter_sleep_state()

uacpi_status uacpi_enter_sleep_state ( uacpi_sleep_state  state_enum)

Enter the given sleep state after preparation.

Definition at line 499 of file sleep.c.

500{
501 uacpi_u8 state = state_enum;
502
504
505 if (uacpi_unlikely(state > UACPI_SLEEP_STATE_MAX))
507
508 if (uacpi_unlikely(g_uacpi_rt_ctx.last_sleep_typ_a > ACPI_SLP_TYP_MAX ||
509 g_uacpi_rt_ctx.last_sleep_typ_b > ACPI_SLP_TYP_MAX)) {
510 uacpi_error("invalid SLP_TYP values: 0x%02X:0x%02X",
511 g_uacpi_rt_ctx.last_sleep_typ_a,
512 g_uacpi_rt_ctx.last_sleep_typ_b);
514 }
515
516 return CALL_SLEEP_FN(enter_sleep_state, state);
517}
static int state
Definition: maze.c:121
#define ACPI_SLP_TYP_MAX
Definition: acpi.h:912
#define UACPI_ENSURE_INIT_LEVEL_AT_LEAST(lvl)
Definition: context.h:127
struct uacpi_runtime_context g_uacpi_rt_ctx
Definition: uacpi.c:18
#define uacpi_error(...)
Definition: log.h:36
#define uacpi_unlikely(expr)
Definition: compiler.h:88
uint8_t uacpi_u8
Definition: types.h:19
@ UACPI_STATUS_INVALID_ARGUMENT
Definition: status.h:18
@ UACPI_STATUS_AML_BAD_ENCODING
Definition: status.h:39
@ UACPI_INIT_LEVEL_NAMESPACE_INITIALIZED
Definition: types.h:84
#define CALL_SLEEP_FN(name, state)
Definition: sleep.c:12

Referenced by uacpi_enter_sleep_state_simple().

◆ uacpi_enter_sleep_state_simple()

uacpi_status uacpi_enter_sleep_state_simple ( uacpi_sleep_state  state)

Prepare & enter a given sleep state May be used as a shortcut if the kernel doesn't have any other work to do inbetween calling the two separate helpers

Definition at line 519 of file sleep.c.

520{
522
525 return ret;
526
528}
#define uacpi_unlikely_error(expr)
Definition: status.h:50
uacpi_status
Definition: status.h:10
return ret
Definition: mutex.c:147
uacpi_status uacpi_enter_sleep_state(enum uacpi_sleep_state state_enum)
Definition: sleep.c:499
uacpi_status uacpi_prepare_for_sleep_state(enum uacpi_sleep_state state_enum)
Definition: sleep.c:364

◆ uacpi_prepare_for_sleep_state()

uacpi_status uacpi_prepare_for_sleep_state ( uacpi_sleep_state  state_enum)

Prepare for a given sleep state.

Definition at line 364 of file sleep.c.

365{
366 uacpi_u8 state = state_enum;
368
370
371 if (uacpi_unlikely(state > UACPI_SLEEP_STATE_S5))
373
375 state,
376 &g_uacpi_rt_ctx.last_sleep_typ_a,
377 &g_uacpi_rt_ctx.last_sleep_typ_b
378 );
379 if (ret != UACPI_STATUS_OK)
380 return ret;
381
383 0,
384 &g_uacpi_rt_ctx.s0_sleep_typ_a,
385 &g_uacpi_rt_ctx.s0_sleep_typ_b
386 );
387
388 ret = eval_pts(state);
390 return ret;
391
393 return UACPI_STATUS_OK;
394}
@ UACPI_STATUS_OK
Definition: status.h:11
static uacpi_status get_slp_type_for_state(uacpi_u8 state, uacpi_u8 *a, uacpi_u8 *b)
Definition: sleep.c:200
static uacpi_status eval_pts(uacpi_u8 state)
Definition: sleep.c:309
static uacpi_status eval_sst_for_state(enum uacpi_sleep_state state)
Definition: sleep.c:327

Referenced by uacpi_enter_sleep_state_simple().

◆ uacpi_prepare_for_wake_from_sleep_state()

uacpi_status uacpi_prepare_for_wake_from_sleep_state ( uacpi_sleep_state  state_enum)

Prepare to leave the given sleep state.

Definition at line 530 of file sleep.c.

533{
534 uacpi_u8 state = state_enum;
535
537
538 if (uacpi_unlikely(state > UACPI_SLEEP_STATE_MAX))
540
541 return CALL_SLEEP_FN(prepare_for_wake_from_sleep_state, state);
542}

◆ uacpi_reboot()

uacpi_status uacpi_reboot ( void  )

Attempt reset via the FADT reset register.

Definition at line 558 of file sleep.c.

559{
561 uacpi_handle pci_dev = UACPI_NULL, io_handle = UACPI_NULL;
562 struct acpi_fadt *fadt = &g_uacpi_rt_ctx.fadt;
563 struct acpi_gas *reset_reg = &fadt->reset_reg;
564
565 /*
566 * Allow restarting earlier than namespace load so that the kernel can
567 * use this in case of some initialization error.
568 */
570
571 if (!(fadt->flags & ACPI_RESET_REG_SUP) || !reset_reg->address)
573
574 switch (reset_reg->address_space_id) {
576 /*
577 * For SystemIO we don't do any checking, and we ignore bit width
578 * because that's what NT does.
579 */
580 ret = uacpi_kernel_io_map(reset_reg->address, 1, &io_handle);
582 return ret;
583
584 ret = uacpi_kernel_io_write8(io_handle, 0, fadt->reset_value);
585 break;
587 ret = uacpi_write_register(UACPI_REGISTER_RESET, fadt->reset_value);
588 break;
591
592 // Bus is assumed to be 0 here
593 address.segment = 0;
594 address.bus = 0;
595 address.device = (reset_reg->address >> 32) & 0xFF;
596 address.function = (reset_reg->address >> 16) & 0xFF;
597
600 break;
601
603 pci_dev, reset_reg->address & 0xFFFF, fadt->reset_value
604 );
605 break;
606 }
607 default:
609 "unable to perform a reset: unsupported address space '%s' (%d)",
610 uacpi_address_space_to_string(reset_reg->address_space_id),
611 reset_reg->address_space_id
612 );
614 }
615
616 if (ret == UACPI_STATUS_OK) {
617 /*
618 * This should've worked but we're still here.
619 * Spin for a bit then give up.
620 */
621 uacpi_u64 stalled_time = 0;
622
623 while (stalled_time < (1000 * 1000)) {
625 stalled_time += 100;
626 }
627
628 uacpi_error("reset timeout");
630 }
631
632 if (pci_dev != UACPI_NULL)
634 if (io_handle != UACPI_NULL)
635 uacpi_kernel_io_unmap(io_handle);
636
637 return ret;
638}
#define ACPI_RESET_REG_SUP
Definition: acpi.h:719
#define uacpi_warn(...)
Definition: log.h:35
uint64_t uacpi_u64
Definition: types.h:22
#define UACPI_NULL
Definition: types.h:33
uacpi_status uacpi_write_register(uacpi_register, uacpi_u64)
Definition: registers.c:286
@ UACPI_REGISTER_RESET
Definition: registers.h:24
@ UACPI_STATUS_NOT_FOUND
Definition: status.h:17
@ UACPI_STATUS_UNIMPLEMENTED
Definition: status.h:19
@ UACPI_STATUS_HARDWARE_TIMEOUT
Definition: status.h:28
const uacpi_char * uacpi_address_space_to_string(uacpi_address_space space)
Definition: types.c:12
@ UACPI_INIT_LEVEL_SUBSYSTEM_INITIALIZED
Definition: types.h:72
@ UACPI_ADDRESS_SPACE_SYSTEM_MEMORY
Definition: types.h:43
@ UACPI_ADDRESS_SPACE_PCI_CONFIG
Definition: types.h:45
@ UACPI_ADDRESS_SPACE_SYSTEM_IO
Definition: types.h:44
GLuint address
Definition: glext.h:9393
uacpi_status uacpi_kernel_io_map(uacpi_io_addr base, uacpi_size len, uacpi_handle *out_handle)
Definition: uacpiosl.c:165
void uacpi_kernel_pci_device_close(uacpi_handle)
Definition: uacpiosl.c:251
uacpi_status uacpi_kernel_io_write8(uacpi_handle, uacpi_size offset, uacpi_u8 in_value)
Definition: uacpiosl.c:320
void uacpi_kernel_stall(uacpi_u8 usec)
Definition: uacpiosl.c:42
uacpi_status uacpi_kernel_pci_device_open(uacpi_pci_address address, uacpi_handle *out_handle)
Definition: uacpiosl.c:242
uacpi_status uacpi_kernel_pci_write8(uacpi_handle device, uacpi_size offset, uacpi_u8 value)
Definition: uacpiosl.c:278
void uacpi_kernel_io_unmap(uacpi_handle handle)
Definition: uacpiosl.c:171
uacpi_u16 segment
Definition: types.h:88

◆ uacpi_wake_from_sleep_state()

uacpi_status uacpi_wake_from_sleep_state ( uacpi_sleep_state  state_enum)

Wake from the given sleep state.

Note that this discards a pending press of the power & sleep buttons, as that is most likely what has woken the system up, and enables the fixed event of either one if it has a handler installed. The latter is the case even if the event was disabled via uacpi_disable_fixed_event prior to going to sleep.

Definition at line 544 of file sleep.c.

547{
548 uacpi_u8 state = state_enum;
549
551
552 if (uacpi_unlikely(state > UACPI_SLEEP_STATE_MAX))
554
555 return CALL_SLEEP_FN(wake_from_sleep_state, state);
556}

Variable Documentation

◆ uacpi_sleep_state

uacpi_sleep_state

Definition at line 32 of file sleep.h.