| 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 |
.type = STM_USER, |
| 26 |
.link = stm_console_link, |
| 27 |
.unlink = stm_console_unlink, |
| 28 |
}, |
| 29 |
}; |
| 30 |
|
| 31 |
static void |
| 32 |
stm_console_write(struct console *con, const char *buf, unsigned len) |
| 33 |
{ |
| 34 |
struct stm_console *sc = container_of(con, struct stm_console, console); |
| 35 |
|
| 36 |
stm_source_write(&sc->data, 0, buf, len); |
| 37 |
} |
| 38 |
|
| 39 |
static int stm_console_link(struct stm_source_data *data) |
| 40 |
{ |
| 41 |
struct stm_console *sc = container_of(data, struct stm_console, data); |
| 42 |
|
| 43 |
strcpy(sc->console.name, "stm_console"); |
| 44 |
sc->console.write = stm_console_write; |
| 45 |
sc->console.flags = CON_ENABLED | CON_PRINTBUFFER; |
| 46 |
register_console(&sc->console); |
| 47 |
|
| 48 |
return 0; |
| 49 |
} |
| 50 |
|
| 51 |
static void stm_console_unlink(struct stm_source_data *data) |
| 52 |
{ |
| 53 |
struct stm_console *sc = container_of(data, struct stm_console, data); |
| 54 |
|
| 55 |
unregister_console(&sc->console); |
| 56 |
} |
| 57 |
|
| 58 |
static int stm_console_init(void) |
| 59 |
{ |
| 60 |
return stm_source_register_device(NULL, &stm_console.data); |
| 61 |
} |
| 62 |
|
| 63 |
static void stm_console_exit(void) |
| 64 |
{ |
| 65 |
stm_source_unregister_device(&stm_console.data); |
| 66 |
} |
| 67 |
|
| 68 |
module_init(stm_console_init); |
| 69 |
module_exit(stm_console_exit); |
| 70 |
|
| 71 |
MODULE_LICENSE("GPL v2"); |
| 72 |
MODULE_DESCRIPTION("stm_console driver"); |
| 73 |
MODULE_AUTHOR("Alexander Shishkin <[email protected]>"); |