Add CONFIG_SYSTEM_SUSPEND and SCIF UART suspend/resume handlers
v2 cover Add CONFIG_SYSTEM_SUSPEND and SCIF UART suspend/resume handlers
From: Mykola Kvach <[email protected]>
Hi all,
This patch series introduces CONFIG_SYSTEM_SUSPEND to Xen and implements suspend/resume handlers for the SCIF UART driver. These changes address feedback and discussions on the Xen-devel mailing list:
https://lists.xenproject.org/archives/html/xen-devel/2025-03/msg00169.html https://lists.xenproject.org/archives/html/xen-devel/2025-03/msg02188.html
I am marking this series as v2, as it is a logical continuation of the discussion linked above regarding the SCIF driver changes.
Patch 1:
Introduces the CONFIG_SYSTEM_SUSPEND infrastructure, which enables Xen to
support suspend-to-RAM functionality. It adds three new Kconfig options:
- HAS_SYSTEM_SUSPEND: Indicates whether the architecture supports suspend.
- SYSTEM_SUSPEND_ALWAYS_ON: Forces suspend support on platforms that require it (e.g., x86).
- SYSTEM_SUSPEND: The user-facing option to enable suspend support, enabled by default when SYSTEM_SUSPEND_ALWAYS_ON is set.
This approach is intended to be easily extendable to other architectures in
the future.
Patch 2:
Implements suspend/resume callbacks for the SCIF UART driver. These functions
ensure proper shutdown and reinitialization of the UART hardware across suspend/resume cycles. Their inclusion is gated by the CONFIG_SYSTEM_SUSPEND option.
The SCIF suspend/resume functionality has been tested on the Renesas R-Car H3
Starter Kit board.
Compared to v1, the main change in this version is the addition of aCONFIG_SYSTEM_SUSPEND check around the SCIF driver's suspend/resume logic.
Best regards,
Mykola Kvach
Mykola Kvach (1):
xen: Introduce system suspend config option
Volodymyr Babchuk (1):
xen/char: implement suspend/resume calls for SCIF driver
xen/arch/x86/Kconfig | 2 ++ xen/common/Kconfig | 17 +++++++++++++++ xen/drivers/char/scif-uart.c | 40 ++++++++++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-)
Signature · 1 line
2.48.1
PATCH v2 1/2 xen: Introduce system suspend config option
From: Mykola Kvach <[email protected]>
This option enables the system suspend support. This is the mechanism that allows the system to be suspended to RAM and later resumed.
The patch introduces three options:
- HAS_SYSTEM_SUSPEND: indicates suspend support is available on the platform.
- SYSTEM_SUSPEND_ALWAYS_ON: used for architectures where suspend must always be enabled.
- SYSTEM_SUSPEND: user-facing option to enable/disable suspend if supported. Defaults to enabled if SYSTEM_SUSPEND_ALWAYS_ON is set and depends on HAS_SYSTEM_SUSPEND.
On x86, both HAS_SYSTEM_SUSPEND and SYSTEM_SUSPEND_ALWAYS_ON are selected by default, making suspend support always enabled. The options are designed to be easily extensible to other architectures (e.g., PPC, RISC-V) as future support is added.
---
Discussion on adding the SYSTEM_SUSPEND config can be found here:
https://lists.xenproject.org/archives/html/xen-devel/2025-03/msg00169.html
--- xen/arch/x86/Kconfig | 2 ++ xen/common/Kconfig | 17 +++++++++++++++++ 2 files changed, 19 insertions(+)
xen/arch/x86/Kconfig +2 -0
@@ -33,6 +33,8 @@ config X86 select HAS_VMAP select HAS_VPCI if HVM select NEEDS_LIBELF + select HAS_SYSTEM_SUSPEND + select SYSTEM_SUSPEND_ALWAYS_ON config ARCH_DEFCONFIG string
xen/common/Kconfig +17 -0
@@ -579,4 +579,21 @@ config BUDDY_ALLOCATOR_SIZE Amount of memory reserved for the buddy allocator to serve Xen heap, working alongside the colored one. +config HAS_SYSTEM_SUSPEND + bool + +config SYSTEM_SUSPEND_ALWAYS_ON + bool + +config SYSTEM_SUSPEND + bool "System suspend support" + depends on HAS_SYSTEM_SUSPEND + default y if SYSTEM_SUSPEND_ALWAYS_ON + help + This option enables the system suspend support. This is the + mechanism that allows the system to be suspended to RAM and + later resumed. + + If unsure, say N. + endmenu
Signature · 1 line
2.48.1
Re: [PATCH v2 1/2] xen: Introduce system suspend config option
xen/arch/x86/Kconfig config X86 · line 37
Quoted 8 lines · Mykola Kvach
xen/arch/x86/Kconfig +2
-0@@ -33,6 +33,8 @@ config X86 select HAS_VMAP select HAS_VPCI if HVM select NEEDS_LIBELF + select HAS_SYSTEM_SUSPEND + select SYSTEM_SUSPEND_ALWAYS_ON
To avoid other architectures potentially also needing to select both, how about moving the former one ...
xen/common/Kconfig config BUDDY_ALLOCATOR_SIZE · line 586
Quoted 11 lines
xen/common/Kconfig +5
-0@@ -579,4 +579,21 @@ config BUDDY_ALLOCATOR_SIZE Amount of memory reserved for the buddy allocator to serve Xen heap, working alongside the colored one. +config HAS_SYSTEM_SUSPEND + bool + +config SYSTEM_SUSPEND_ALWAYS_ON + bool
... here?
xen/common/Kconfig config BUDDY_ALLOCATOR_SIZE · line 591
Quoted 4 lines
xen/common/Kconfig +4
-0+config SYSTEM_SUSPEND + bool "System suspend support" + depends on HAS_SYSTEM_SUSPEND + default y if SYSTEM_SUSPEND_ALWAYS_ON
Hmm, this way "always on" isn't achieved. Someone can still turn it off, likely causing the build to fail (until it is properly made an optional feature). You also need to make the prompt invisible (by attaching "if SYSTEM_SUSPEND_ALWAYS_ON").
Also the default line could be shorter as "default SYSTEM_SUSPEND_ALWAYS_ON"; aiui with modern kconfig there's no difference anymore between the two.
Jan
PATCH v2 2/2 xen/char: implement suspend/resume calls for SCIF driver
In reply to Mykola KvachFrom: Volodymyr Babchuk <[email protected]>
The changes have been tested only on the Renesas R-Car H3 Starter Kit board.
---
In patch v2, I just added a CONFIG_SYSTEM_SUSPEND check around the suspend/resume functions in the SCIF driver.
--- xen/drivers/char/scif-uart.c | 40 ++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)
xen/drivers/char/scif-uart.c +38 -2
@@ -139,9 +139,8 @@ static void scif_uart_interrupt(int irq, void *data) } } -static void __init scif_uart_init_preirq (struct serial_port *port) +static void scif_uart_disable (struct scif_uart *uart) { -struct scif_uart *uart = port->uart;const struct port_params *params = uart->params;/*
@@ -155,6 +154,14 @@ static void __init scif_uart_init_preirq(struct serial_port *port)/* Reset TX/RX FIFOs */ scif_writew (uart,SCIF_SCFCR ,SCFCR_RFRST |SCFCR_TFRST ); +} + +static void scif_uart_init_preirq (struct serial_port *port) +{ +struct scif_uart *uart = port->uart; +const struct port_params *params = uart->params; + +scif_uart_disable (uart);/* Clear all errors and flags */ scif_readw (uart, params->status_reg);
@@ -271,6 +278,31 @@ static void scif_uart_stop_tx(struct serial_port *port)scif_writew (uart,SCIF_SCSCR ,scif_readw (uart,SCIF_SCSCR ) & ~SCSCR_TIE ); } +#ifdef CONFIG_SYSTEM_SUSPEND + +static void scif_uart_suspend (struct serial_port *port) +{ +struct scif_uart *uart = port->uart; + +scif_uart_stop_tx (port); +scif_uart_disable (uart); +} + +static void scif_uart_resume (struct serial_port *port) +{ +struct scif_uart *uart = port->uart; +const struct port_params *params = uart->params; +uint16_t ctrl; + +scif_uart_init_preirq (port); + +/* Enable TX/RX and Error Interrupts */ + ctrl =scif_readw (uart,SCIF_SCSCR ); +scif_writew (uart,SCIF_SCSCR , ctrl | params->irq_flags); +} + +#endif /* CONFIG_SYSTEM_SUSPEND */ +static struct uart_driver __read_mostly scif_uart_driver = { .init_preirq = scif_uart_init_preirq, .init_postirq = scif_uart_init_postirq,
@@ -281,6 +313,10 @@ static struct uart_driver __read_mostly scif_uart_driver = { .start_tx = scif_uart_start_tx, .stop_tx = scif_uart_stop_tx, .vuart_info = scif_vuart_info, +#ifdef CONFIG_SYSTEM_SUSPEND + .suspend = scif_uart_suspend, + .resume = scif_uart_resume, +#endif }; static const struct dt_device_match scif_uart_dt_match[] __initconst =
Signature · 1 line
2.48.1