#include <linux/module.h>
#include <linux/types.h>
#include <linux/sched/signal.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/kd.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/major.h>
#include <linux/mm.h>
#include <linux/console.h>
#include <linux/init.h>
#include <linux/mutex.h>
#include <linux/vt_kern.h>
#include <linux/selection.h>
#include <linux/tiocl.h>
#include <linux/kbd_kern.h>
#include <linux/consolemap.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/workqueue.h>
#include <linux/pm.h>
#include <linux/font.h>
#include <linux/bitops.h>
#include <linux/notifier.h>
#include <linux/device.h>
#include <linux/io.h>
#include <linux/uaccess.h>
#include <linux/kdb.h>
#include <linux/ctype.h>
#include <linux/bsearch.h>
#include <linux/gcd.h>
#define MAX_NR_CON_DRIVER …
#define CON_DRIVER_FLAG_MODULE …
#define CON_DRIVER_FLAG_INIT …
#define CON_DRIVER_FLAG_ATTR …
#define CON_DRIVER_FLAG_ZOMBIE …
struct con_driver { … };
static struct con_driver registered_con_driver[MAX_NR_CON_DRIVER];
const struct consw *conswitchp;
#define DEFAULT_BELL_PITCH …
#define DEFAULT_BELL_DURATION …
#define DEFAULT_CURSOR_BLINK_MS …
struct vc vc_cons [MAX_NR_CONSOLES];
EXPORT_SYMBOL(…);
static const struct consw *con_driver_map[MAX_NR_CONSOLES];
static int con_open(struct tty_struct *, struct file *);
static void vc_init(struct vc_data *vc, int do_clear);
static void gotoxy(struct vc_data *vc, int new_x, int new_y);
static void save_cur(struct vc_data *vc);
static void reset_terminal(struct vc_data *vc, int do_clear);
static void con_flush_chars(struct tty_struct *tty);
static int set_vesa_blanking(u8 __user *mode);
static void set_cursor(struct vc_data *vc);
static void hide_cursor(struct vc_data *vc);
static void console_callback(struct work_struct *ignored);
static void con_driver_unregister_callback(struct work_struct *ignored);
static void blank_screen_t(struct timer_list *unused);
static void set_palette(struct vc_data *vc);
static void unblank_screen(void);
#define vt_get_kmsg_redirect() …
int default_utf8 = …;
module_param(default_utf8, int, S_IRUGO | S_IWUSR);
int global_cursor_default = …;
module_param(global_cursor_default, int, S_IRUGO | S_IWUSR);
EXPORT_SYMBOL(…);
static int cur_default = …;
module_param(cur_default, int, S_IRUGO | S_IWUSR);
static int ignore_poke;
int do_poke_blanked_console;
int console_blanked;
EXPORT_SYMBOL(…);
static enum vesa_blank_mode vesa_blank_mode;
static int vesa_off_interval;
static int blankinterval;
core_param(…);
static DECLARE_WORK(console_work, console_callback);
static DECLARE_WORK(con_driver_unregister_work, con_driver_unregister_callback);
int fg_console;
EXPORT_SYMBOL(…);
int last_console;
int want_console = …;
static int saved_fg_console;
static int saved_last_console;
static int saved_want_console;
static int saved_vc_mode;
static int saved_console_blanked;
static struct vc_data *master_display_fg;
static int scrollback_delta;
int (*console_blank_hook)(int);
EXPORT_SYMBOL(…);
static DEFINE_TIMER(console_timer, blank_screen_t);
static int blank_state;
static int blank_timer_expired;
enum { … };
static struct device *tty0dev;
static ATOMIC_NOTIFIER_HEAD(vt_notifier_list);
int register_vt_notifier(struct notifier_block *nb)
{ … }
EXPORT_SYMBOL_GPL(…);
int unregister_vt_notifier(struct notifier_block *nb)
{ … }
EXPORT_SYMBOL_GPL(…);
static void notify_write(struct vc_data *vc, unsigned int unicode)
{ … }
static void notify_update(struct vc_data *vc)
{ … }
static inline bool con_is_fg(const struct vc_data *vc)
{ … }
static inline bool con_should_update(const struct vc_data *vc)
{ … }
static inline u16 *screenpos(const struct vc_data *vc, unsigned int offset,
bool viewed)
{ … }
static void con_putc(struct vc_data *vc, u16 ca, unsigned int y, unsigned int x)
{ … }
static inline void scrolldelta(int lines)
{ … }
void schedule_console_callback(void)
{ … }
static u32 **vc_uniscr_alloc(unsigned int cols, unsigned int rows)
{ … }
static void vc_uniscr_free(u32 **uni_lines)
{ … }
static void vc_uniscr_set(struct vc_data *vc, u32 **new_uni_lines)
{ … }
static void vc_uniscr_putc(struct vc_data *vc, u32 uc)
{ … }
static void vc_uniscr_insert(struct vc_data *vc, unsigned int nr)
{ … }
static void vc_uniscr_delete(struct vc_data *vc, unsigned int nr)
{ … }
static void vc_uniscr_clear_line(struct vc_data *vc, unsigned int x,
unsigned int nr)
{ … }
static void vc_uniscr_clear_lines(struct vc_data *vc, unsigned int y,
unsigned int nr)
{ … }
static void juggle_array(u32 **array, unsigned int size, unsigned int nr)
{ … }
static void vc_uniscr_scroll(struct vc_data *vc, unsigned int top,
unsigned int bottom, enum con_scroll dir,
unsigned int nr)
{ … }
static void vc_uniscr_copy_area(u32 **dst_lines,
unsigned int dst_cols,
unsigned int dst_rows,
u32 **src_lines,
unsigned int src_cols,
unsigned int src_top_row,
unsigned int src_bot_row)
{ … }
int vc_uniscr_check(struct vc_data *vc)
{ … }
void vc_uniscr_copy_line(const struct vc_data *vc, void *dest, bool viewed,
unsigned int row, unsigned int col, unsigned int nr)
{ … }
static void con_scroll(struct vc_data *vc, unsigned int top,
unsigned int bottom, enum con_scroll dir,
unsigned int nr)
{ … }
static void do_update_region(struct vc_data *vc, unsigned long start, int count)
{ … }
void update_region(struct vc_data *vc, unsigned long start, int count)
{ … }
EXPORT_SYMBOL(…);
static u8 build_attr(struct vc_data *vc, u8 _color,
enum vc_intensity _intensity, bool _blink, bool _underline,
bool _reverse, bool _italic)
{ … }
static void update_attr(struct vc_data *vc)
{ … }
void invert_screen(struct vc_data *vc, int offset, int count, bool viewed)
{ … }
void complement_pos(struct vc_data *vc, int offset)
{ … }
static void insert_char(struct vc_data *vc, unsigned int nr)
{ … }
static void delete_char(struct vc_data *vc, unsigned int nr)
{ … }
static int softcursor_original = …;
static void add_softcursor(struct vc_data *vc)
{ … }
static void hide_softcursor(struct vc_data *vc)
{ … }
static void hide_cursor(struct vc_data *vc)
{ … }
static void set_cursor(struct vc_data *vc)
{ … }
static void set_origin(struct vc_data *vc)
{ … }
static void save_screen(struct vc_data *vc)
{ … }
static void flush_scrollback(struct vc_data *vc)
{ … }
void clear_buffer_attributes(struct vc_data *vc)
{ … }
void redraw_screen(struct vc_data *vc, int is_switch)
{ … }
EXPORT_SYMBOL(…);
int vc_cons_allocated(unsigned int i)
{ … }
static void visual_init(struct vc_data *vc, int num, bool init)
{ … }
static void visual_deinit(struct vc_data *vc)
{ … }
static void vc_port_destruct(struct tty_port *port)
{ … }
static const struct tty_port_operations vc_port_ops = …;
#define VC_MAXCOL …
#define VC_MAXROW …
int vc_allocate(unsigned int currcons)
{ … }
static inline int resize_screen(struct vc_data *vc, int width, int height,
bool from_user)
{ … }
static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
unsigned int cols, unsigned int lines, bool from_user)
{ … }
int __vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows,
bool from_user)
{ … }
EXPORT_SYMBOL(…);
static int vt_resize(struct tty_struct *tty, struct winsize *ws)
{ … }
struct vc_data *vc_deallocate(unsigned int currcons)
{ … }
enum { … };
#define set_kbd(vc, x) …
#define clr_kbd(vc, x) …
#define is_kbd(vc, x) …
#define decarm …
#define decckm …
#define kbdapplic …
#define lnm …
const unsigned char color_table[] = …;
EXPORT_SYMBOL(…);
unsigned char default_red[] = …;
module_param_array(…);
EXPORT_SYMBOL(…);
unsigned char default_grn[] = …;
module_param_array(…);
EXPORT_SYMBOL(…);
unsigned char default_blu[] = …;
module_param_array(…);
EXPORT_SYMBOL(…);
static void gotoxy(struct vc_data *vc, int new_x, int new_y)
{ … }
static void gotoxay(struct vc_data *vc, int new_x, int new_y)
{ … }
void scrollback(struct vc_data *vc)
{ … }
void scrollfront(struct vc_data *vc, int lines)
{ … }
static void lf(struct vc_data *vc)
{ … }
static void ri(struct vc_data *vc)
{ … }
static inline void cr(struct vc_data *vc)
{ … }
static inline void bs(struct vc_data *vc)
{ … }
static inline void del(struct vc_data *vc)
{ … }
enum CSI_J { … };
static void csi_J(struct vc_data *vc, enum CSI_J vpar)
{ … }
enum { … };
static void csi_K(struct vc_data *vc)
{ … }
static void csi_X(struct vc_data *vc)
{ … }
static void default_attr(struct vc_data *vc)
{ … }
struct rgb { … };
static void rgb_from_256(unsigned int i, struct rgb *c)
{ … }
static void rgb_foreground(struct vc_data *vc, const struct rgb *c)
{ … }
static void rgb_background(struct vc_data *vc, const struct rgb *c)
{ … }
static int vc_t416_color(struct vc_data *vc, int i,
void(*set_color)(struct vc_data *vc, const struct rgb *c))
{ … }
enum { … };
static void csi_m(struct vc_data *vc)
{ … }
static void respond_string(const char *p, size_t len, struct tty_port *port)
{ … }
static void cursor_report(struct vc_data *vc, struct tty_struct *tty)
{ … }
static inline void status_report(struct tty_struct *tty)
{ … }
static inline void respond_ID(struct tty_struct *tty)
{ … }
void mouse_report(struct tty_struct *tty, int butt, int mrx, int mry)
{ … }
int mouse_reporting(void)
{ … }
enum { … };
static void csi_DEC_hl(struct vc_data *vc, bool on_off)
{ … }
enum { … };
static void csi_hl(struct vc_data *vc, bool on_off)
{ … }
enum CSI_right_square_bracket { … };
static void csi_RSB(struct vc_data *vc)
{ … }
static void csi_at(struct vc_data *vc, unsigned int nr)
{ … }
static void csi_L(struct vc_data *vc)
{ … }
static void csi_P(struct vc_data *vc)
{ … }
static void csi_M(struct vc_data *vc)
{ … }
static void save_cur(struct vc_data *vc)
{ … }
static void restore_cur(struct vc_data *vc)
{ … }
enum vc_ctl_state { … };
static void reset_terminal(struct vc_data *vc, int do_clear)
{ … }
static void vc_setGx(struct vc_data *vc, unsigned int which, u8 c)
{ … }
static bool ansi_control_string(enum vc_ctl_state state)
{ … }
enum { … };
static bool handle_ascii(struct tty_struct *tty, struct vc_data *vc, u8 c)
{ … }
static void handle_esc(struct tty_struct *tty, struct vc_data *vc, u8 c)
{ … }
static void csi_DEC(struct tty_struct *tty, struct vc_data *vc, u8 c)
{ … }
static void csi_ECMA(struct tty_struct *tty, struct vc_data *vc, u8 c)
{ … }
static void vc_reset_params(struct vc_data *vc)
{ … }
static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
{ … }
struct interval { … };
static int ucs_cmp(const void *key, const void *elt)
{ … }
static int is_double_width(uint32_t ucs)
{ … }
struct vc_draw_region { … };
static void con_flush(struct vc_data *vc, struct vc_draw_region *draw)
{ … }
static inline int vc_translate_ascii(const struct vc_data *vc, int c)
{ … }
static inline int vc_sanitize_unicode(const int c)
{ … }
static int vc_translate_unicode(struct vc_data *vc, int c, bool *rescan)
{ … }
static int vc_translate(struct vc_data *vc, int *c, bool *rescan)
{ … }
static inline unsigned char vc_invert_attr(const struct vc_data *vc)
{ … }
static bool vc_is_control(struct vc_data *vc, int tc, int c)
{ … }
static int vc_con_write_normal(struct vc_data *vc, int tc, int c,
struct vc_draw_region *draw)
{ … }
static int do_con_write(struct tty_struct *tty, const u8 *buf, int count)
{ … }
static void console_callback(struct work_struct *ignored)
{ … }
int set_console(int nr)
{ … }
struct tty_driver *console_driver;
#ifdef CONFIG_VT_CONSOLE
int vt_kmsg_redirect(int new)
{ … }
static void vt_console_print(struct console *co, const char *b, unsigned count)
{ … }
static struct tty_driver *vt_console_device(struct console *c, int *index)
{ … }
static int vt_console_setup(struct console *co, char *options)
{ … }
static struct console vt_console_driver = …;
#endif
int tioclinux(struct tty_struct *tty, unsigned long arg)
{ … }
static ssize_t con_write(struct tty_struct *tty, const u8 *buf, size_t count)
{ … }
static int con_put_char(struct tty_struct *tty, u8 ch)
{ … }
static unsigned int con_write_room(struct tty_struct *tty)
{ … }
static void con_throttle(struct tty_struct *tty)
{ … }
static void con_unthrottle(struct tty_struct *tty)
{ … }
static void con_stop(struct tty_struct *tty)
{ … }
static void con_start(struct tty_struct *tty)
{ … }
static void con_flush_chars(struct tty_struct *tty)
{ … }
static int con_install(struct tty_driver *driver, struct tty_struct *tty)
{ … }
static int con_open(struct tty_struct *tty, struct file *filp)
{ … }
static void con_close(struct tty_struct *tty, struct file *filp)
{ … }
static void con_shutdown(struct tty_struct *tty)
{ … }
static void con_cleanup(struct tty_struct *tty)
{ … }
static int con_ldisc_ok(struct tty_struct *tty, int ldisc)
{ … }
static int default_color = …;
static int default_italic_color = …;
static int default_underline_color = …;
module_param_named(color, default_color, int, S_IRUGO | S_IWUSR);
module_param_named(italic, default_italic_color, int, S_IRUGO | S_IWUSR);
module_param_named(underline, default_underline_color, int, S_IRUGO | S_IWUSR);
static void vc_init(struct vc_data *vc, int do_clear)
{ … }
static int __init con_init(void)
{ … }
console_initcall(con_init);
static const struct tty_operations con_ops = …;
static struct cdev vc0_cdev;
static ssize_t show_tty_active(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static DEVICE_ATTR(active, S_IRUGO, show_tty_active, NULL);
static struct attribute *vt_dev_attrs[] = …;
ATTRIBUTE_GROUPS(…);
int __init vty_init(const struct file_operations *console_fops)
{ … }
static const struct class vtconsole_class = …;
static int do_bind_con_driver(const struct consw *csw, int first, int last,
int deflt)
{
struct module *owner = csw->owner;
const char *desc = NULL;
struct con_driver *con_driver;
int i, j = -1, k = -1, retval = -ENODEV;
if (!try_module_get(owner))
return -ENODEV;
WARN_CONSOLE_UNLOCKED();
for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
con_driver = ®istered_con_driver[i];
if (con_driver->con == csw) {
desc = con_driver->desc;
retval = 0;
break;
}
}
if (retval)
goto err;
if (!(con_driver->flag & CON_DRIVER_FLAG_INIT)) {
csw->con_startup();
con_driver->flag |= CON_DRIVER_FLAG_INIT;
}
if (deflt) {
if (conswitchp)
module_put(conswitchp->owner);
__module_get(owner);
conswitchp = csw;
}
first = max(first, con_driver->first);
last = min(last, con_driver->last);
for (i = first; i <= last; i++) {
int old_was_color;
struct vc_data *vc = vc_cons[i].d;
if (con_driver_map[i])
module_put(con_driver_map[i]->owner);
__module_get(owner);
con_driver_map[i] = csw;
if (!vc || !vc->vc_sw)
continue;
j = i;
if (con_is_visible(vc)) {
k = i;
save_screen(vc);
}
old_was_color = vc->vc_can_do_color;
vc->vc_sw->con_deinit(vc);
vc->vc_origin = (unsigned long)vc->vc_screenbuf;
visual_init(vc, i, false);
set_origin(vc);
update_attr(vc);
if (old_was_color != vc->vc_can_do_color)
clear_buffer_attributes(vc);
}
pr_info("Console: switching ");
if (!deflt)
pr_cont("consoles %d-%d ", first + 1, last + 1);
if (j >= 0) {
struct vc_data *vc = vc_cons[j].d;
pr_cont("to %s %s %dx%d\n",
vc->vc_can_do_color ? "colour" : "mono",
desc, vc->vc_cols, vc->vc_rows);
if (k >= 0) {
vc = vc_cons[k].d;
update_screen(vc);
}
} else {
pr_cont("to %s\n", desc);
}
retval = 0;
err:
module_put(owner);
return retval;
};
#ifdef CONFIG_VT_HW_CONSOLE_BINDING
int do_unbind_con_driver(const struct consw *csw, int first, int last, int deflt)
{ … }
EXPORT_SYMBOL_GPL(…);
static int vt_bind(struct con_driver *con)
{ … }
static int vt_unbind(struct con_driver *con)
{ … }
#else
static inline int vt_bind(struct con_driver *con)
{
return 0;
}
static inline int vt_unbind(struct con_driver *con)
{
return 0;
}
#endif
static ssize_t store_bind(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static ssize_t show_bind(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static ssize_t show_name(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static DEVICE_ATTR(bind, S_IRUGO|S_IWUSR, show_bind, store_bind);
static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
static struct attribute *con_dev_attrs[] = …;
ATTRIBUTE_GROUPS(…);
static int vtconsole_init_device(struct con_driver *con)
{ … }
static void vtconsole_deinit_device(struct con_driver *con)
{ … }
int con_is_bound(const struct consw *csw)
{ … }
EXPORT_SYMBOL(…);
bool con_is_visible(const struct vc_data *vc)
{ … }
EXPORT_SYMBOL(…);
void con_debug_enter(struct vc_data *vc)
{ … }
EXPORT_SYMBOL_GPL(…);
void con_debug_leave(void)
{ … }
EXPORT_SYMBOL_GPL(…);
static int do_register_con_driver(const struct consw *csw, int first, int last)
{ … }
int do_unregister_con_driver(const struct consw *csw)
{ … }
EXPORT_SYMBOL_GPL(…);
static void con_driver_unregister_callback(struct work_struct *ignored)
{ … }
int do_take_over_console(const struct consw *csw, int first, int last, int deflt)
{ … }
EXPORT_SYMBOL_GPL(…);
void give_up_console(const struct consw *csw)
{ … }
EXPORT_SYMBOL(…);
static int __init vtconsole_class_init(void)
{ … }
postcore_initcall(vtconsole_class_init);
static int set_vesa_blanking(u8 __user *mode_user)
{ … }
void do_blank_screen(int entering_gfx)
{ … }
EXPORT_SYMBOL(…);
void do_unblank_screen(int leaving_gfx)
{ … }
EXPORT_SYMBOL(…);
static void unblank_screen(void)
{ … }
static void blank_screen_t(struct timer_list *unused)
{ … }
void poke_blanked_console(void)
{ … }
static void set_palette(struct vc_data *vc)
{ … }
int con_set_cmap(unsigned char __user *arg)
{ … }
int con_get_cmap(unsigned char __user *arg)
{ … }
void reset_palette(struct vc_data *vc)
{ … }
#define max_font_width …
#define max_font_height …
#define max_font_glyphs …
#define max_font_size …
static int con_font_get(struct vc_data *vc, struct console_font_op *op)
{ … }
static int con_font_set(struct vc_data *vc, const struct console_font_op *op)
{ … }
static int con_font_default(struct vc_data *vc, struct console_font_op *op)
{ … }
int con_font_op(struct vc_data *vc, struct console_font_op *op)
{ … }
u16 screen_glyph(const struct vc_data *vc, int offset)
{ … }
EXPORT_SYMBOL_GPL(…);
u32 screen_glyph_unicode(const struct vc_data *vc, int n)
{ … }
EXPORT_SYMBOL_GPL(…);
unsigned short *screen_pos(const struct vc_data *vc, int w_offset, bool viewed)
{ … }
EXPORT_SYMBOL_GPL(…);
void getconsxy(const struct vc_data *vc, unsigned char xy[static 2])
{ … }
void putconsxy(struct vc_data *vc, unsigned char xy[static const 2])
{ … }
u16 vcs_scr_readw(const struct vc_data *vc, const u16 *org)
{ … }
void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org)
{ … }
void vcs_scr_updated(struct vc_data *vc)
{ … }