sys-kernel/e-sources: Bump to 3.14.3, BFS, Reiser4.
[gentoo-zh.git] / sys-kernel / e-sources / files / 3.14.3 / additional / colored-kernel-message-output.diff
blob024b2be5619203af1a2a6e0804eaed44878b9041
1 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
2 index 01d1c18..2a02d82 100644
3 --- a/arch/x86/kernel/early_printk.c
4 +++ b/arch/x86/kernel/early_printk.c
5 @@ -26,7 +26,8 @@
6 static int max_ypos = 25, max_xpos = 80;
7 static int current_ypos = 25, current_xpos;
9 -static void early_vga_write(struct console *con, const char *str, unsigned n)
10 +static void early_vga_write(struct console *con, const char *str, unsigned n,
11 + unsigned int loglevel)
13 char c;
14 int i, k, j;
15 @@ -104,7 +105,8 @@ static int early_serial_putc(unsigned char ch)
16 return timeout ? 0 : -1;
19 -static void early_serial_write(struct console *con, const char *s, unsigned n)
20 +static void early_serial_write(struct console *con, const char *s, unsigned n,
21 + unsigned int loglevel)
23 while (*s && n-- > 0) {
24 if (*s == '\n')
25 diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/accessibility/braille/braille_console.c
26 index dc34a5b..020118b 100644
27 --- a/drivers/accessibility/braille/braille_console.c
28 +++ b/drivers/accessibility/braille/braille_console.c
29 @@ -116,7 +116,7 @@ static void braille_write(u16 *buf)
30 *c++ = csum;
31 *c++ = ETX;
33 - braille_co->write(braille_co, data, c - data);
34 + braille_co->write(braille_co, data, c - data, 0);
37 /* Follow the VC cursor*/
38 diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
39 index ba2f5e7..b649820 100644
40 --- a/drivers/net/netconsole.c
41 +++ b/drivers/net/netconsole.c
42 @@ -728,7 +728,8 @@ static int netconsole_netdev_event(struct notifier_block *this,
43 .notifier_call = netconsole_netdev_event,
46 -static void write_msg(struct console *con, const char *msg, unsigned int len)
47 +static void write_msg(struct console *con, const char *msg, unsigned int len,
48 + unsigned int loglevel)
50 int frag, left;
51 unsigned long flags;
52 diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
53 index 978db34..63e7160 100644
54 --- a/drivers/tty/Kconfig
55 +++ b/drivers/tty/Kconfig
56 @@ -75,6 +75,111 @@ config VT_CONSOLE_SLEEP
57 def_bool y
58 depends on VT_CONSOLE && PM_SLEEP
60 +menuconfig VT_CKO
61 + bool "Colored kernel message output"
62 + depends on VT_CONSOLE
63 + ---help---
64 + This option enables kernel messages to be emitted in
65 + colors other than the default.
67 + The color value you need to enter is composed (OR-ed)
68 + of a foreground and a background color.
70 + Foreground:
71 + 0x00 = black, 0x08 = dark gray,
72 + 0x01 = red, 0x09 = light red,
73 + 0x02 = green, 0x0A = light green,
74 + 0x03 = brown, 0x0B = yellow,
75 + 0x04 = blue, 0x0C = light blue,
76 + 0x05 = magenta, 0x0D = light magenta,
77 + 0x06 = cyan, 0x0E = light cyan,
78 + 0x07 = gray, 0x0F = white,
80 + (Foreground colors 0x08 to 0x0F do not work when a VGA
81 + console font with 512 glyphs is used.)
83 + Background:
84 + 0x00 = black, 0x40 = blue,
85 + 0x10 = red, 0x50 = magenta,
86 + 0x20 = green, 0x60 = cyan,
87 + 0x30 = brown, 0x70 = gray,
89 + For example, 0x1F would yield white on red.
91 + If unsure, say N.
93 +config VT_PRINTK_EMERG_COLOR
94 + hex "Emergency messages color"
95 + range 0x00 0xFF
96 + depends on VT_CKO
97 + default 0x07
98 + ---help---
99 + This option defines with which color kernel emergency messages will
100 + be printed to the console.
102 +config VT_PRINTK_ALERT_COLOR
103 + hex "Alert messages color"
104 + range 0x00 0xFF
105 + depends on VT_CKO
106 + default 0x07
107 + ---help---
108 + This option defines with which color kernel alert messages will
109 + be printed to the console.
111 +config VT_PRINTK_CRIT_COLOR
112 + hex "Critical messages color"
113 + range 0x00 0xFF
114 + depends on VT_CKO
115 + default 0x07
116 + ---help---
117 + This option defines with which color kernel critical messages will
118 + be printed to the console.
120 +config VT_PRINTK_ERR_COLOR
121 + hex "Error messages color"
122 + range 0x00 0xFF
123 + depends on VT_CKO
124 + default 0x07
125 + ---help---
126 + This option defines with which color kernel error messages will
127 + be printed to the console.
129 +config VT_PRINTK_WARNING_COLOR
130 + hex "Warning messages color"
131 + range 0x00 0xFF
132 + depends on VT_CKO
133 + default 0x07
134 + ---help---
135 + This option defines with which color kernel warning messages will
136 + be printed to the console.
138 +config VT_PRINTK_NOTICE_COLOR
139 + hex "Notice messages color"
140 + range 0x00 0xFF
141 + depends on VT_CKO
142 + default 0x07
143 + ---help---
144 + This option defines with which color kernel notice messages will
145 + be printed to the console.
147 +config VT_PRINTK_INFO_COLOR
148 + hex "Information messages color"
149 + range 0x00 0xFF
150 + depends on VT_CKO
151 + default 0x07
152 + ---help---
153 + This option defines with which color kernel information messages will
154 + be printed to the console.
156 +config VT_PRINTK_DEBUG_COLOR
157 + hex "Debug messages color"
158 + range 0x00 0xFF
159 + depends on VT_CKO
160 + default 0x07
161 + ---help---
162 + This option defines with which color kernel debug messages will
163 + be printed to the console.
165 config HW_CONSOLE
166 bool
167 depends on VT && !UML
168 diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
169 index e33d38cb..d73fdfb 100644
170 --- a/drivers/tty/serial/8250/8250_core.c
171 +++ b/drivers/tty/serial/8250/8250_core.c
172 @@ -2850,7 +2850,8 @@ static void serial8250_console_putchar(struct uart_port *port, int ch)
173 * The console_lock must be held when we get here.
175 static void
176 -serial8250_console_write(struct console *co, const char *s, unsigned int count)
177 +serial8250_console_write(struct console *co, const char *s, unsigned int count,
178 + unsigned int loglevel)
180 struct uart_8250_port *up = &serial8250_ports[co->index];
181 struct uart_port *port = &up->port;
182 diff --git a/drivers/tty/serial/8250/8250_early.c b/drivers/tty/serial/8250/8250_early.c
183 index c100d63..bb28b49 100644
184 --- a/drivers/tty/serial/8250/8250_early.c
185 +++ b/drivers/tty/serial/8250/8250_early.c
186 @@ -98,7 +98,7 @@ static void __init serial_putc(struct uart_port *port, int c)
189 static void __init early_serial8250_write(struct console *console,
190 - const char *s, unsigned int count)
191 + const char *s, unsigned int count, unsigned int loglevel)
193 struct uart_port *port = &early_device.port;
194 unsigned int ier;
195 diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
196 index 61b1137..f1fa906 100644
197 --- a/drivers/tty/vt/vt.c
198 +++ b/drivers/tty/vt/vt.c
199 @@ -71,6 +71,7 @@
202 #include <linux/module.h>
203 +#include <linux/moduleparam.h>
204 #include <linux/types.h>
205 #include <linux/sched.h>
206 #include <linux/tty.h>
207 @@ -2430,16 +2431,44 @@ int vt_kmsg_redirect(int new)
208 return kmsg_con;
211 +#ifdef CONFIG_VT_CKO
212 +static unsigned int printk_color[8] __read_mostly = {
213 + CONFIG_VT_PRINTK_EMERG_COLOR, /* KERN_EMERG */
214 + CONFIG_VT_PRINTK_ALERT_COLOR, /* KERN_ALERT */
215 + CONFIG_VT_PRINTK_CRIT_COLOR, /* KERN_CRIT */
216 + CONFIG_VT_PRINTK_ERR_COLOR, /* KERN_ERR */
217 + CONFIG_VT_PRINTK_WARNING_COLOR, /* KERN_WARNING */
218 + CONFIG_VT_PRINTK_NOTICE_COLOR, /* KERN_NOTICE */
219 + CONFIG_VT_PRINTK_INFO_COLOR, /* KERN_INFO */
220 + CONFIG_VT_PRINTK_DEBUG_COLOR, /* KERN_DEBUG */
222 +module_param_array(printk_color, uint, NULL, S_IRUGO | S_IWUSR);
224 +static inline void vc_set_color(struct vc_data *vc, unsigned char color)
226 + vc->vc_color = color_table[color & 0xF] |
227 + (color_table[(color >> 4) & 0x7] << 4) |
228 + (color & 0x80);
229 + update_attr(vc);
231 +#else
232 +static unsigned int printk_color[8];
233 +static inline void vc_set_color(const struct vc_data *vc, unsigned char c)
236 +#endif
239 * Console on virtual terminal
241 * The console must be locked when we get here.
244 -static void vt_console_print(struct console *co, const char *b, unsigned count)
245 +static void vt_console_print(struct console *co, const char *b, unsigned count,
246 + unsigned int loglevel)
248 struct vc_data *vc = vc_cons[fg_console].d;
249 - unsigned char c;
250 + unsigned char current_color, c;
251 static DEFINE_SPINLOCK(printing_lock);
252 const ushort *start;
253 ushort cnt = 0;
254 @@ -2475,11 +2504,20 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
256 start = (ushort *)vc->vc_pos;
258 + /*
259 + * We always get a valid loglevel - <8> and "no level" is transformed
260 + * to <4> in the typical kernel.
261 + */
262 + current_color = printk_color[loglevel];
263 + vc_set_color(vc, current_color);
266 /* Contrived structure to try to emulate original need_wrap behaviour
267 * Problems caused when we have need_wrap set on '\n' character */
268 while (count--) {
269 c = *b++;
270 if (c == 10 || c == 13 || c == 8 || vc->vc_need_wrap) {
271 + vc_set_color(vc, vc->vc_def_color);
272 if (cnt > 0) {
273 if (CON_IS_VISIBLE(vc))
274 vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, vc->vc_x);
275 @@ -2492,6 +2530,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
276 bs(vc);
277 start = (ushort *)vc->vc_pos;
278 myx = vc->vc_x;
279 + vc_set_color(vc, current_color);
280 continue;
282 if (c != 13)
283 @@ -2499,6 +2538,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
284 cr(vc);
285 start = (ushort *)vc->vc_pos;
286 myx = vc->vc_x;
287 + vc_set_color(vc, current_color);
288 if (c == 10 || c == 13)
289 continue;
291 @@ -2521,6 +2561,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
292 vc->vc_need_wrap = 1;
295 + vc_set_color(vc, vc->vc_def_color);
296 set_cursor(vc);
297 notify_update(vc);
299 diff --git a/include/linux/console.h b/include/linux/console.h
300 index 7571a16..af01c35 100644
301 --- a/include/linux/console.h
302 +++ b/include/linux/console.h
303 @@ -118,7 +118,7 @@ static inline int con_debug_leave(void)
305 struct console {
306 char name[16];
307 - void (*write)(struct console *, const char *, unsigned);
308 + void (*write)(struct console *, const char *, unsigned, unsigned int);
309 int (*read)(struct console *, char *, unsigned);
310 struct tty_driver *(*device)(struct console *, int *);
311 void (*unblank)(void);
312 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
313 index be7c86b..8517cbe 100644
314 --- a/kernel/printk/printk.c
315 +++ b/kernel/printk/printk.c
316 @@ -1282,7 +1282,7 @@ static void call_console_drivers(int level, const char *text, size_t len)
317 if (!cpu_online(smp_processor_id()) &&
318 !(con->flags & CON_ANYTIME))
319 continue;
320 - con->write(con, text, len);
321 + con->write(con, text, len, level);
325 @@ -1732,7 +1732,7 @@ void early_vprintk(const char *fmt, va_list ap)
326 char buf[512];
327 int n = vscnprintf(buf, sizeof(buf), fmt, ap);
329 - early_console->write(early_console, buf, n);
330 + early_console->write(early_console, buf, n, 0);