linamh/sys-kernel/geos_one-sources/files/colored-printk-2.6.26.patch
2009-01-27 14:53:31 +00:00

356 lines
11 KiB
Diff

diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
index 643fd86..837f3c2 100644
--- a/arch/x86/kernel/early_printk.c
+++ b/arch/x86/kernel/early_printk.c
@@ -15,7 +15,8 @@
static int max_ypos = 25, max_xpos = 80;
static int current_ypos = 25, current_xpos;
-static void early_vga_write(struct console *con, const char *str, unsigned n)
+static void early_vga_write(struct console *con, const char *str, unsigned n,
+ unsigned int loglevel)
{
char c;
int i, k, j;
@@ -84,7 +85,8 @@ static int early_serial_putc(unsigned char ch)
return timeout ? 0 : -1;
}
-static void early_serial_write(struct console *con, const char *s, unsigned n)
+static void early_serial_write(struct console *con, const char *s, unsigned n,
+ unsigned int loglevel)
{
while (*s && n-- > 0) {
if (*s == '\n')
@@ -180,7 +182,8 @@ static void __init simnow_init(char *str)
simnow_fd = simnow(XOPEN, (unsigned long)fn, O_WRONLY|O_APPEND|O_CREAT, 0644);
}
-static void simnow_write(struct console *con, const char *s, unsigned n)
+static void simnow_write(struct console *con, const char *s, unsigned n,
+ unsigned int loglevel)
{
simnow(XWRITE, simnow_fd, (unsigned long)s, n);
}
@@ -204,7 +207,7 @@ void early_printk(const char *fmt, ...)
va_start(ap, fmt);
n = vscnprintf(buf, 512, fmt, ap);
- early_console->write(early_console, buf, n);
+ early_console->write(early_console, buf, n, 0);
va_end(ap);
}
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 57ba5c2..10556dd 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -71,6 +71,111 @@ config NR_TTY_DEVICES
If unsure, say 63.
+menuconfig VT_CKO
+ bool "Colored kernel message output"
+ depends on VT_CONSOLE
+ ---help---
+ This option enables kernel messages to be emitted in
+ colors other than the default.
+
+ The color value you need to enter is composed (OR-ed)
+ of a foreground and a background color.
+
+ Foreground:
+ 0x00 = black, 0x08 = dark gray,
+ 0x01 = red, 0x09 = light red,
+ 0x02 = green, 0x0A = light green,
+ 0x03 = brown, 0x0B = yellow,
+ 0x04 = blue, 0x0C = light blue,
+ 0x05 = magenta, 0x0D = light magenta,
+ 0x06 = cyan, 0x0E = light cyan,
+ 0x07 = gray, 0x0F = white,
+
+ (Foreground colors 0x08 to 0x0F do not work when a VGA
+ console font with 512 glyphs is used.)
+
+ Background:
+ 0x00 = black, 0x40 = blue,
+ 0x10 = red, 0x50 = magenta,
+ 0x20 = green, 0x60 = cyan,
+ 0x30 = brown, 0x70 = gray,
+
+ For example, 0x1F would yield white on red.
+
+ If unsure, say N.
+
+config VT_PRINTK_EMERG_COLOR
+ hex "Emergency messages color"
+ range 0x00 0xFF
+ depends on VT_CKO
+ default 0x07
+ ---help---
+ This option defines with which color kernel emergency messages will
+ be printed to the console.
+
+config VT_PRINTK_ALERT_COLOR
+ hex "Alert messages color"
+ range 0x00 0xFF
+ depends on VT_CKO
+ default 0x07
+ ---help---
+ This option defines with which color kernel alert messages will
+ be printed to the console.
+
+config VT_PRINTK_CRIT_COLOR
+ hex "Critical messages color"
+ range 0x00 0xFF
+ depends on VT_CKO
+ default 0x07
+ ---help---
+ This option defines with which color kernel critical messages will
+ be printed to the console.
+
+config VT_PRINTK_ERR_COLOR
+ hex "Error messages color"
+ range 0x00 0xFF
+ depends on VT_CKO
+ default 0x07
+ ---help---
+ This option defines with which color kernel error messages will
+ be printed to the console.
+
+config VT_PRINTK_WARNING_COLOR
+ hex "Warning messages color"
+ range 0x00 0xFF
+ depends on VT_CKO
+ default 0x07
+ ---help---
+ This option defines with which color kernel warning messages will
+ be printed to the console.
+
+config VT_PRINTK_NOTICE_COLOR
+ hex "Notice messages color"
+ range 0x00 0xFF
+ depends on VT_CKO
+ default 0x07
+ ---help---
+ This option defines with which color kernel notice messages will
+ be printed to the console.
+
+config VT_PRINTK_INFO_COLOR
+ hex "Information messages color"
+ range 0x00 0xFF
+ depends on VT_CKO
+ default 0x07
+ ---help---
+ This option defines with which color kernel information messages will
+ be printed to the console.
+
+config VT_PRINTK_DEBUG_COLOR
+ hex "Debug messages color"
+ range 0x00 0xFF
+ depends on VT_CKO
+ default 0x07
+ ---help---
+ This option defines with which color kernel debug messages will
+ be printed to the console.
+
config HW_CONSOLE
bool
depends on VT && !S390 && !UML
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 935f1c2..1fee2dc 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -73,6 +73,7 @@
*/
#include <linux/module.h>
+#include <linux/moduleparam.h>
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/tty.h>
@@ -2409,17 +2410,45 @@ struct tty_driver *console_driver;
#ifdef CONFIG_VT_CONSOLE
+#ifdef CONFIG_VT_CKO
+static unsigned int printk_color[8] __read_mostly = {
+ CONFIG_VT_PRINTK_EMERG_COLOR, /* KERN_EMERG */
+ CONFIG_VT_PRINTK_ALERT_COLOR, /* KERN_ALERT */
+ CONFIG_VT_PRINTK_CRIT_COLOR, /* KERN_CRIT */
+ CONFIG_VT_PRINTK_ERR_COLOR, /* KERN_ERR */
+ CONFIG_VT_PRINTK_WARNING_COLOR, /* KERN_WARNING */
+ CONFIG_VT_PRINTK_NOTICE_COLOR, /* KERN_NOTICE */
+ CONFIG_VT_PRINTK_INFO_COLOR, /* KERN_INFO */
+ CONFIG_VT_PRINTK_DEBUG_COLOR, /* KERN_DEBUG */
+};
+module_param_array(printk_color, uint, NULL, S_IRUGO | S_IWUSR);
+
+static inline void vc_set_color(struct vc_data *vc, unsigned char color)
+{
+ vc->vc_color = color_table[color & 0xF] |
+ (color_table[(color >> 4) & 0x7] << 4) |
+ (color & 0x80);
+ update_attr(vc);
+}
+#else
+static unsigned int printk_color[8];
+static inline void vc_set_color(const struct vc_data *vc, unsigned char c)
+{
+}
+#endif
+
/*
* Console on virtual terminal
*
* The console must be locked when we get here.
*/
-static void vt_console_print(struct console *co, const char *b, unsigned count)
+static void vt_console_print(struct console *co, const char *b, unsigned count,
+ unsigned int loglevel)
{
struct vc_data *vc = vc_cons[fg_console].d;
- unsigned char c;
static DEFINE_SPINLOCK(printing_lock);
+ unsigned char current_color, c;
const ushort *start;
ushort cnt = 0;
ushort myx;
@@ -2452,11 +2481,19 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
start = (ushort *)vc->vc_pos;
+ /*
+ * We always get a valid loglevel - <8> and "no level" is transformed
+ * to <4> in the typical kernel.
+ */
+ current_color = printk_color[loglevel];
+ vc_set_color(vc, current_color);
+
/* Contrived structure to try to emulate original need_wrap behaviour
* Problems caused when we have need_wrap set on '\n' character */
while (count--) {
c = *b++;
if (c == 10 || c == 13 || c == 8 || vc->vc_need_wrap) {
+ vc_set_color(vc, vc->vc_def_color);
if (cnt > 0) {
if (CON_IS_VISIBLE(vc))
vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, vc->vc_x);
@@ -2469,6 +2506,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
bs(vc);
start = (ushort *)vc->vc_pos;
myx = vc->vc_x;
+ vc_set_color(vc, current_color);
continue;
}
if (c != 13)
@@ -2476,6 +2514,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
cr(vc);
start = (ushort *)vc->vc_pos;
myx = vc->vc_x;
+ vc_set_color(vc, current_color);
if (c == 10 || c == 13)
continue;
}
@@ -2498,6 +2537,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
vc->vc_need_wrap = 1;
}
}
+ vc_set_color(vc, vc->vc_def_color);
set_cursor(vc);
notify_update(vc);
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 665341e..4c27de8 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -694,7 +694,8 @@ static struct notifier_block netconsole_netdev_notifier = {
.notifier_call = netconsole_netdev_event,
};
-static void write_msg(struct console *con, const char *msg, unsigned int len)
+static void write_msg(struct console *con, const char *msg, unsigned int len,
+ unsigned int loglevel)
{
int frag, left;
unsigned long flags;
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 1bc00b7..b4f1b6f 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -2527,7 +2527,8 @@ static void serial8250_console_putchar(struct uart_port *port, int ch)
* The console_lock must be held when we get here.
*/
static void
-serial8250_console_write(struct console *co, const char *s, unsigned int count)
+serial8250_console_write(struct console *co, const char *s, unsigned int count,
+ unsigned int loglevel)
{
struct uart_8250_port *up = &serial8250_ports[co->index];
unsigned long flags;
diff --git a/drivers/serial/8250_early.c b/drivers/serial/8250_early.c
index f279745..2a928bd 100644
--- a/drivers/serial/8250_early.c
+++ b/drivers/serial/8250_early.c
@@ -83,7 +83,7 @@ static void __init serial_putc(struct uart_port *port, int c)
}
static void __init early_serial8250_write(struct console *console,
- const char *s, unsigned int count)
+ const char *s, unsigned int count, unsigned int loglevel)
{
struct uart_port *port = &early_device.port;
unsigned int ier;
diff --git a/include/linux/console.h b/include/linux/console.h
index a4f27fb..46fcfd3 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -95,7 +95,7 @@ void give_up_console(const struct consw *sw);
struct console {
char name[16];
- void (*write)(struct console *, const char *, unsigned);
+ void (*write)(struct console *, const char *, unsigned, unsigned int);
int (*read)(struct console *, char *, unsigned);
struct tty_driver *(*device)(struct console *, int *);
void (*unblank)(void);
diff --git a/kernel/printk.c b/kernel/printk.c
index 6e920ce..a1aaa3f 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -444,7 +444,8 @@ asmlinkage long sys_syslog(int type, char __user *buf, int len)
/*
* Call the console drivers on a range of log_buf
*/
-static void __call_console_drivers(unsigned start, unsigned end)
+static void __call_console_drivers(unsigned start, unsigned end,
+ unsigned int loglevel)
{
struct console *con;
@@ -452,7 +453,7 @@ static void __call_console_drivers(unsigned start, unsigned end)
if ((con->flags & CON_ENABLED) && con->write &&
(cpu_online(smp_processor_id()) ||
(con->flags & CON_ANYTIME)))
- con->write(con, &LOG_BUF(start), end - start);
+ con->write(con, &LOG_BUF(start), end - start, loglevel);
}
}
@@ -479,10 +480,11 @@ static void _call_console_drivers(unsigned start,
if ((start & LOG_BUF_MASK) > (end & LOG_BUF_MASK)) {
/* wrapped write */
__call_console_drivers(start & LOG_BUF_MASK,
- log_buf_len);
- __call_console_drivers(0, end & LOG_BUF_MASK);
+ log_buf_len, msg_log_level);
+ __call_console_drivers(0, end & LOG_BUF_MASK,
+ msg_log_level);
} else {
- __call_console_drivers(start, end);
+ __call_console_drivers(start, end, msg_log_level);
}
}
}