Skip to content

Commit 2c41538

Browse files
virtuosogregkh
authored andcommitted
stm class: dummy_stm: Add dummy driver for testing stm class
This is a simple module that pretends to be an stm device and discards all the data that comes in. Useful for testing stm class and its users. Reviewed-by: Mathieu Poirier <[email protected]> Signed-off-by: Alexander Shishkin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a961e69 commit 2c41538

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

drivers/hwtracing/stm/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@ config STM
66
Examples of such devices are Intel(R) Trace Hub and Coresight STM.
77

88
Say Y here to enable System Trace Module device support.
9+
10+
config STM_DUMMY
11+
tristate "Dummy STM driver"
12+
help
13+
This is a simple dummy device that pretends to be an stm device
14+
and discards your data. Use for stm class testing.
15+
16+
If you don't know what this is, say N.

drivers/hwtracing/stm/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
obj-$(CONFIG_STM) += stm_core.o
22

33
stm_core-y := core.o policy.o
4+
5+
obj-$(CONFIG_STM_DUMMY) += dummy_stm.o

drivers/hwtracing/stm/dummy_stm.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* A dummy STM device for stm/stm_source class testing.
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 class implements generic infrastructure for System Trace Module devices
15+
* as defined in MIPI STPv2 specification.
16+
*/
17+
18+
#undef DEBUG
19+
#include <linux/kernel.h>
20+
#include <linux/module.h>
21+
#include <linux/slab.h>
22+
#include <linux/stm.h>
23+
24+
static ssize_t
25+
dummy_stm_packet(struct stm_data *stm_data, unsigned int master,
26+
unsigned int channel, unsigned int packet, unsigned int flags,
27+
unsigned int size, const unsigned char *payload)
28+
{
29+
#ifdef DEBUG
30+
u64 pl = 0;
31+
32+
if (payload)
33+
pl = *(u64 *)payload;
34+
35+
if (size < 8)
36+
pl &= (1ull << (size * 8)) - 1;
37+
trace_printk("[%u:%u] [pkt: %x/%x] (%llx)\n", master, channel,
38+
packet, size, pl);
39+
#endif
40+
return size;
41+
}
42+
43+
static struct stm_data dummy_stm = {
44+
.name = "dummy_stm",
45+
.sw_start = 0x0000,
46+
.sw_end = 0xffff,
47+
.sw_nchannels = 0xffff,
48+
.packet = dummy_stm_packet,
49+
};
50+
51+
static int dummy_stm_init(void)
52+
{
53+
return stm_register_device(NULL, &dummy_stm, THIS_MODULE);
54+
}
55+
56+
static void dummy_stm_exit(void)
57+
{
58+
stm_unregister_device(&dummy_stm);
59+
}
60+
61+
module_init(dummy_stm_init);
62+
module_exit(dummy_stm_exit);
63+
64+
MODULE_LICENSE("GPL v2");
65+
MODULE_DESCRIPTION("dummy_stm device");
66+
MODULE_AUTHOR("Alexander Shishkin <[email protected]>");

0 commit comments

Comments
 (0)