xref: /openbmc/linux/drivers/hwtracing/stm/console.c (revision 3cf3cdea)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Simple kernel console driver for STM devices
4  * Copyright (c) 2014, Intel Corporation.
5  *
6  * STM console will send kernel messages over STM devices to a trace host.
7  */
8 
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/console.h>
12 #include <linux/slab.h>
13 #include <linux/stm.h>
14 
15 static int stm_console_link(struct stm_source_data *data);
16 static void stm_console_unlink(struct stm_source_data *data);
17 
18 static struct stm_console {
19 	struct stm_source_data	data;
20 	struct console		console;
21 } stm_console = {
22 	.data	= {
23 		.name		= "console",
24 		.nr_chans	= 1,
25 		.link		= stm_console_link,
26 		.unlink		= stm_console_unlink,
27 	},
28 };
29 
30 static void
31 stm_console_write(struct console *con, const char *buf, unsigned len)
32 {
33 	struct stm_console *sc = container_of(con, struct stm_console, console);
34 
35 	stm_source_write(&sc->data, 0, buf, len);
36 }
37 
38 static int stm_console_link(struct stm_source_data *data)
39 {
40 	struct stm_console *sc = container_of(data, struct stm_console, data);
41 
42 	strcpy(sc->console.name, "stm_console");
43 	sc->console.write = stm_console_write;
44 	sc->console.flags = CON_ENABLED | CON_PRINTBUFFER;
45 	register_console(&sc->console);
46 
47 	return 0;
48 }
49 
50 static void stm_console_unlink(struct stm_source_data *data)
51 {
52 	struct stm_console *sc = container_of(data, struct stm_console, data);
53 
54 	unregister_console(&sc->console);
55 }
56 
57 static int stm_console_init(void)
58 {
59 	return stm_source_register_device(NULL, &stm_console.data);
60 }
61 
62 static void stm_console_exit(void)
63 {
64 	stm_source_unregister_device(&stm_console.data);
65 }
66 
67 module_init(stm_console_init);
68 module_exit(stm_console_exit);
69 
70 MODULE_LICENSE("GPL v2");
71 MODULE_DESCRIPTION("stm_console driver");
72 MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@linux.intel.com>");
73