Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Simple kernel console driver for STM devices
0004  * Copyright (c) 2014, Intel Corporation.
0005  *
0006  * STM console will send kernel messages over STM devices to a trace host.
0007  */
0008 
0009 #include <linux/kernel.h>
0010 #include <linux/module.h>
0011 #include <linux/console.h>
0012 #include <linux/slab.h>
0013 #include <linux/stm.h>
0014 
0015 static int stm_console_link(struct stm_source_data *data);
0016 static void stm_console_unlink(struct stm_source_data *data);
0017 
0018 static struct stm_console {
0019     struct stm_source_data  data;
0020     struct console      console;
0021 } stm_console = {
0022     .data   = {
0023         .name       = "console",
0024         .nr_chans   = 1,
0025         .link       = stm_console_link,
0026         .unlink     = stm_console_unlink,
0027     },
0028 };
0029 
0030 static void
0031 stm_console_write(struct console *con, const char *buf, unsigned len)
0032 {
0033     struct stm_console *sc = container_of(con, struct stm_console, console);
0034 
0035     stm_source_write(&sc->data, 0, buf, len);
0036 }
0037 
0038 static int stm_console_link(struct stm_source_data *data)
0039 {
0040     struct stm_console *sc = container_of(data, struct stm_console, data);
0041 
0042     strcpy(sc->console.name, "stm_console");
0043     sc->console.write = stm_console_write;
0044     sc->console.flags = CON_ENABLED | CON_PRINTBUFFER;
0045     register_console(&sc->console);
0046 
0047     return 0;
0048 }
0049 
0050 static void stm_console_unlink(struct stm_source_data *data)
0051 {
0052     struct stm_console *sc = container_of(data, struct stm_console, data);
0053 
0054     unregister_console(&sc->console);
0055 }
0056 
0057 static int stm_console_init(void)
0058 {
0059     return stm_source_register_device(NULL, &stm_console.data);
0060 }
0061 
0062 static void stm_console_exit(void)
0063 {
0064     stm_source_unregister_device(&stm_console.data);
0065 }
0066 
0067 module_init(stm_console_init);
0068 module_exit(stm_console_exit);
0069 
0070 MODULE_LICENSE("GPL v2");
0071 MODULE_DESCRIPTION("stm_console driver");
0072 MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@linux.intel.com>");