Skip to content

Commit b6f448e

Browse files
dilingertorvalds
authored andcommitted
PM/gxfb: add hook to PM console layer that allows disabling of suspend VT switch
Prior to suspend, we allocate and switch to a new VT; after suspend, we switch back to the original VT. This can be slow, and is completely unnecessary if the framebuffer we're using can restore video properly. This adds a hook that allows drivers to select whether or not to do this vt switch, and changes the gxfb driver to call this hook. It also adds a module param to gxfb to allow controlling of the vt switch (defaulting to no switch). (Note: I'm not convinced that console_sem is the best way to protect this, but we should probably have some form of locking..) [akpm@linux-foundation.org: build fix] Signed-off-by: Andres Salomon <dilinger@debian.org> Cc: Jordan Crouse <jordan.crouse@amd.com> Cc: "Antonino A. Daplas" <adaplas@pol.net> Cc: Pavel Machek <pavel@ucw.cz> Cc: "Rafael J. Wysocki" <rjw@sisk.pl> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 46fb6f1 commit b6f448e

4 files changed

Lines changed: 48 additions & 4 deletions

File tree

‎Documentation/fb/gxfb.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ Accepted options:
4545
mode_option - specify the video mode. Of the form
4646
<x>x<y>[-<bpp>][@<refresh>]
4747
vram - size of video ram (normally auto-detected)
48-
48+
vt_switch - enable vt switching during suspend/resume. The vt
49+
switch is slow, but harmless.
4950

5051
--
5152
Andres Salomon <dilinger@debian.org>

‎drivers/video/geode/gxfb_core.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/delay.h>
3030
#include <linux/fb.h>
3131
#include <linux/console.h>
32+
#include <linux/suspend.h>
3233
#include <linux/init.h>
3334
#include <linux/pci.h>
3435
#include <asm/geode.h>
@@ -37,6 +38,7 @@
3738

3839
static char *mode_option;
3940
static int vram;
41+
static int vt_switch;
4042

4143
/* Modes relevant to the GX (taken from modedb.c) */
4244
static const struct fb_videomode gx_modedb[] __initdata = {
@@ -382,6 +384,8 @@ static int __init gxfb_probe(struct pci_dev *pdev, const struct pci_device_id *i
382384
gxfb_check_var(&info->var, info);
383385
gxfb_set_par(info);
384386

387+
pm_set_vt_switch(vt_switch);
388+
385389
if (register_framebuffer(info) < 0) {
386390
ret = -EINVAL;
387391
goto err;
@@ -502,5 +506,8 @@ MODULE_PARM_DESC(mode_option, "video mode (<x>x<y>[-<bpp>][@<refr>])");
502506
module_param(vram, int, 0);
503507
MODULE_PARM_DESC(vram, "video memory size");
504508

509+
module_param(vt_switch, int, 0);
510+
MODULE_PARM_DESC(vt_switch, "enable VT switch during suspend/resume");
511+
505512
MODULE_DESCRIPTION("Framebuffer driver for the AMD Geode GX");
506513
MODULE_LICENSE("GPL");

‎include/linux/suspend.h‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@
1212
#include <asm/errno.h>
1313

1414
#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
15+
extern void pm_set_vt_switch(int);
1516
extern int pm_prepare_console(void);
1617
extern void pm_restore_console(void);
1718
#else
18-
static inline int pm_prepare_console(void) { return 0; }
19-
static inline void pm_restore_console(void) {}
19+
static inline void pm_set_vt_switch(int do_switch)
20+
{
21+
}
22+
23+
static inline int pm_prepare_console(void)
24+
{
25+
return 0;
26+
}
27+
28+
static inline void pm_restore_console(void)
29+
{
30+
}
2031
#endif
2132

2233
typedef int __bitwise suspend_state_t;

‎kernel/power/console.c‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,39 @@
77
#include <linux/vt_kern.h>
88
#include <linux/kbd_kern.h>
99
#include <linux/console.h>
10+
#include <linux/module.h>
1011
#include "power.h"
1112

1213
#if defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
1314
#define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1)
1415

1516
static int orig_fgconsole, orig_kmsg;
17+
static int disable_vt_switch;
18+
19+
/*
20+
* Normally during a suspend, we allocate a new console and switch to it.
21+
* When we resume, we switch back to the original console. This switch
22+
* can be slow, so on systems where the framebuffer can handle restoration
23+
* of video registers anyways, there's little point in doing the console
24+
* switch. This function allows you to disable it by passing it '0'.
25+
*/
26+
void pm_set_vt_switch(int do_switch)
27+
{
28+
acquire_console_sem();
29+
disable_vt_switch = !do_switch;
30+
release_console_sem();
31+
}
32+
EXPORT_SYMBOL(pm_set_vt_switch);
1633

1734
int pm_prepare_console(void)
1835
{
1936
acquire_console_sem();
2037

38+
if (disable_vt_switch) {
39+
release_console_sem();
40+
return 0;
41+
}
42+
2143
orig_fgconsole = fg_console;
2244

2345
if (vc_allocate(SUSPEND_CONSOLE)) {
@@ -50,9 +72,12 @@ int pm_prepare_console(void)
5072
void pm_restore_console(void)
5173
{
5274
acquire_console_sem();
75+
if (disable_vt_switch) {
76+
release_console_sem();
77+
return;
78+
}
5379
set_console(orig_fgconsole);
5480
release_console_sem();
5581
kmsg_redirect = orig_kmsg;
56-
return;
5782
}
5883
#endif

0 commit comments

Comments
 (0)