Skip to content

Commit 8d23355

Browse files
Alan CoxLive-CD User
authored andcommitted
vt: remove power stuff from kernel/power
In the past someone gratuitiously borrowed chunks of kernel internal vt code and dumped them in kernel/power. They have all sorts of deep relations with the vt code so put them in the vt tree instead Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 8b92e87 commit 8d23355

3 files changed

Lines changed: 62 additions & 58 deletions

File tree

‎drivers/char/vt_ioctl.c‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/tty.h>
1717
#include <linux/timer.h>
1818
#include <linux/kernel.h>
19+
#include <linux/module.h>
1920
#include <linux/kd.h>
2021
#include <linux/vt.h>
2122
#include <linux/string.h>
@@ -1483,3 +1484,58 @@ void change_console(struct vc_data *new_vc)
14831484

14841485
complete_change_console(new_vc);
14851486
}
1487+
1488+
/* Perform a kernel triggered VT switch for suspend/resume */
1489+
1490+
static int disable_vt_switch;
1491+
1492+
int vt_move_to_console(unsigned int vt, int alloc)
1493+
{
1494+
int prev;
1495+
1496+
acquire_console_sem();
1497+
/* Graphics mode - up to X */
1498+
if (disable_vt_switch) {
1499+
release_console_sem();
1500+
return 0;
1501+
}
1502+
prev = fg_console;
1503+
1504+
if (alloc && vc_allocate(vt)) {
1505+
/* we can't have a free VC for now. Too bad,
1506+
* we don't want to mess the screen for now. */
1507+
release_console_sem();
1508+
return -ENOSPC;
1509+
}
1510+
1511+
if (set_console(vt)) {
1512+
/*
1513+
* We're unable to switch to the SUSPEND_CONSOLE.
1514+
* Let the calling function know so it can decide
1515+
* what to do.
1516+
*/
1517+
release_console_sem();
1518+
return -EIO;
1519+
}
1520+
release_console_sem();
1521+
if (vt_waitactive(vt)) {
1522+
pr_debug("Suspend: Can't switch VCs.");
1523+
return -EINTR;
1524+
}
1525+
return prev;
1526+
}
1527+
1528+
/*
1529+
* Normally during a suspend, we allocate a new console and switch to it.
1530+
* When we resume, we switch back to the original console. This switch
1531+
* can be slow, so on systems where the framebuffer can handle restoration
1532+
* of video registers anyways, there's little point in doing the console
1533+
* switch. This function allows you to disable it by passing it '0'.
1534+
*/
1535+
void pm_set_vt_switch(int do_switch)
1536+
{
1537+
acquire_console_sem();
1538+
disable_vt_switch = !do_switch;
1539+
release_console_sem();
1540+
}
1541+
EXPORT_SYMBOL(pm_set_vt_switch);

‎include/linux/vt_kern.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,5 @@ struct vt_spawn_console {
117117
};
118118
extern struct vt_spawn_console vt_spawn_con;
119119

120+
extern int vt_move_to_console(unsigned int vt, int alloc);
120121
#endif /* _VT_KERN_H */

‎kernel/power/console.c‎

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,76 +14,23 @@
1414
#define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1)
1515

1616
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);
3317

3418
int pm_prepare_console(void)
3519
{
36-
acquire_console_sem();
37-
38-
if (disable_vt_switch) {
39-
release_console_sem();
40-
return 0;
41-
}
42-
43-
orig_fgconsole = fg_console;
44-
45-
if (vc_allocate(SUSPEND_CONSOLE)) {
46-
/* we can't have a free VC for now. Too bad,
47-
* we don't want to mess the screen for now. */
48-
release_console_sem();
20+
orig_fgconsole = vt_move_to_console(SUSPEND_CONSOLE, 1);
21+
if (orig_fgconsole < 0)
4922
return 1;
50-
}
5123

52-
if (set_console(SUSPEND_CONSOLE)) {
53-
/*
54-
* We're unable to switch to the SUSPEND_CONSOLE.
55-
* Let the calling function know so it can decide
56-
* what to do.
57-
*/
58-
release_console_sem();
59-
return 1;
60-
}
61-
release_console_sem();
62-
63-
if (vt_waitactive(SUSPEND_CONSOLE)) {
64-
pr_debug("Suspend: Can't switch VCs.");
65-
return 1;
66-
}
6724
orig_kmsg = kmsg_redirect;
6825
kmsg_redirect = SUSPEND_CONSOLE;
6926
return 0;
7027
}
7128

7229
void pm_restore_console(void)
7330
{
74-
acquire_console_sem();
75-
if (disable_vt_switch) {
76-
release_console_sem();
77-
return;
78-
}
79-
set_console(orig_fgconsole);
80-
release_console_sem();
81-
82-
if (vt_waitactive(orig_fgconsole)) {
83-
pr_debug("Resume: Can't switch VCs.");
84-
return;
31+
if (orig_fgconsole >= 0) {
32+
vt_move_to_console(orig_fgconsole, 0);
33+
kmsg_redirect = orig_kmsg;
8534
}
86-
87-
kmsg_redirect = orig_kmsg;
8835
}
8936
#endif

0 commit comments

Comments
 (0)