2 * Functions for saving/restoring console.
4 * Originally from swsusp.
7 #include <linux/console.h>
8 #include <linux/vt_kern.h>
9 #include <linux/kbd_kern.h>
11 #include <linux/module.h>
14 #define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1)
16 static int orig_fgconsole
, orig_kmsg
;
18 static DEFINE_MUTEX(vt_switch_mutex
);
21 struct list_head head
;
26 static LIST_HEAD(pm_vt_switch_list
);
30 * pm_vt_switch_required - indicate VT switch at suspend requirements
32 * @required: if true, caller needs VT switch at suspend/resume time
34 * The different console drivers may or may not require VT switches across
35 * suspend/resume, depending on how they handle restoring video state and
36 * what may be running.
38 * Drivers can indicate support for switchless suspend/resume, which can
39 * save time and flicker, by using this routine and passing 'false' as
40 * the argument. If any loaded driver needs VT switching, or the
41 * no_console_suspend argument has been passed on the command line, VT
42 * switches will occur.
44 void pm_vt_switch_required(struct device
*dev
, bool required
)
46 struct pm_vt_switch
*entry
, *tmp
;
48 mutex_lock(&vt_switch_mutex
);
49 list_for_each_entry(tmp
, &pm_vt_switch_list
, head
) {
50 if (tmp
->dev
== dev
) {
51 /* already registered, update requirement */
52 tmp
->required
= required
;
57 entry
= kmalloc(sizeof(*entry
), GFP_KERNEL
);
61 entry
->required
= required
;
64 list_add(&entry
->head
, &pm_vt_switch_list
);
66 mutex_unlock(&vt_switch_mutex
);
68 EXPORT_SYMBOL(pm_vt_switch_required
);
71 * pm_vt_switch_unregister - stop tracking a device's VT switching needs
74 * Remove @dev from the vt switch list.
76 void pm_vt_switch_unregister(struct device
*dev
)
78 struct pm_vt_switch
*tmp
;
80 mutex_lock(&vt_switch_mutex
);
81 list_for_each_entry(tmp
, &pm_vt_switch_list
, head
) {
82 if (tmp
->dev
== dev
) {
88 mutex_unlock(&vt_switch_mutex
);
90 EXPORT_SYMBOL(pm_vt_switch_unregister
);
93 * There are three cases when a VT switch on suspend/resume are required:
94 * 1) no driver has indicated a requirement one way or another, so preserve
96 * 2) console suspend is disabled, we want to see debug messages across
98 * 3) any registered driver indicates it needs a VT switch
100 * If none of these conditions is present, meaning we have at least one driver
101 * that doesn't need the switch, and none that do, we can avoid it to make
102 * resume look a little prettier (and suspend too, but that's usually hidden,
103 * e.g. when closing the lid on a laptop).
105 static bool pm_vt_switch(void)
107 struct pm_vt_switch
*entry
;
110 mutex_lock(&vt_switch_mutex
);
111 if (list_empty(&pm_vt_switch_list
))
114 if (!console_suspend_enabled
)
117 list_for_each_entry(entry
, &pm_vt_switch_list
, head
) {
124 mutex_unlock(&vt_switch_mutex
);
128 int pm_prepare_console(void)
133 orig_fgconsole
= vt_move_to_console(SUSPEND_CONSOLE
, 1);
134 if (orig_fgconsole
< 0)
137 orig_kmsg
= vt_kmsg_redirect(SUSPEND_CONSOLE
);
141 void pm_restore_console(void)
146 if (orig_fgconsole
>= 0) {
147 vt_move_to_console(orig_fgconsole
, 0);
148 vt_kmsg_redirect(orig_kmsg
);