Skip to content

Commit e3e5a3d

Browse files
virtuosogregkh
authored andcommitted
stm class: stm_console: Add kernel-console-over-stm driver
This is a simple stm_source class device driver (kernelspace stm trace source) that registers a console and sends kernel messages over STM devices. Reviewed-by: Mathieu Poirier <[email protected]> Signed-off-by: Alexander Shishkin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2c41538 commit e3e5a3d

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

drivers/hwtracing/stm/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ config STM_DUMMY
1414
and discards your data. Use for stm class testing.
1515

1616
If you don't know what this is, say N.
17+
18+
config STM_SOURCE_CONSOLE
19+
tristate "Kernel console over STM devices"
20+
help
21+
This is a kernel space trace source that sends kernel log
22+
messages to trace hosts over STM devices.
23+
24+
If you want to send kernel console messages over STM devices,
25+
say Y.

drivers/hwtracing/stm/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ obj-$(CONFIG_STM) += stm_core.o
33
stm_core-y := core.o policy.o
44

55
obj-$(CONFIG_STM_DUMMY) += dummy_stm.o
6+
7+
obj-$(CONFIG_STM_SOURCE_CONSOLE) += stm_console.o
8+
9+
stm_console-y := console.o

drivers/hwtracing/stm/console.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Simple kernel console driver for STM devices
3+
* Copyright (c) 2014, Intel Corporation.
4+
*
5+
* This program is free software; you can redistribute it and/or modify it
6+
* under the terms and conditions of the GNU General Public License,
7+
* version 2, as published by the Free Software Foundation.
8+
*
9+
* This program is distributed in the hope it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12+
* more details.
13+
*
14+
* STM console will send kernel messages over STM devices to a trace host.
15+
*/
16+
17+
#include <linux/kernel.h>
18+
#include <linux/module.h>
19+
#include <linux/console.h>
20+
#include <linux/slab.h>
21+
#include <linux/stm.h>
22+
23+
static int stm_console_link(struct stm_source_data *data);
24+
static void stm_console_unlink(struct stm_source_data *data);
25+
26+
static struct stm_console {
27+
struct stm_source_data data;
28+
struct console console;
29+
} stm_console = {
30+
.data = {
31+
.name = "console",
32+
.nr_chans = 1,
33+
.link = stm_console_link,
34+
.unlink = stm_console_unlink,
35+
},
36+
};
37+
38+
static void
39+
stm_console_write(struct console *con, const char *buf, unsigned len)
40+
{
41+
struct stm_console *sc = container_of(con, struct stm_console, console);
42+
43+
stm_source_write(&sc->data, 0, buf, len);
44+
}
45+
46+
static int stm_console_link(struct stm_source_data *data)
47+
{
48+
struct stm_console *sc = container_of(data, struct stm_console, data);
49+
50+
strcpy(sc->console.name, "stm_console");
51+
sc->console.write = stm_console_write;
52+
sc->console.flags = CON_ENABLED | CON_PRINTBUFFER;
53+
register_console(&sc->console);
54+
55+
return 0;
56+
}
57+
58+
static void stm_console_unlink(struct stm_source_data *data)
59+
{
60+
struct stm_console *sc = container_of(data, struct stm_console, data);
61+
62+
unregister_console(&sc->console);
63+
}
64+
65+
static int stm_console_init(void)
66+
{
67+
return stm_source_register_device(NULL, &stm_console.data);
68+
}
69+
70+
static void stm_console_exit(void)
71+
{
72+
stm_source_unregister_device(&stm_console.data);
73+
}
74+
75+
module_init(stm_console_init);
76+
module_exit(stm_console_exit);
77+
78+
MODULE_LICENSE("GPL v2");
79+
MODULE_DESCRIPTION("stm_console driver");
80+
MODULE_AUTHOR("Alexander Shishkin <[email protected]>");

0 commit comments

Comments
 (0)