Commit 7bd1d409 authored by Alexander Shishkin's avatar Alexander Shishkin Committed by Greg Kroah-Hartman

stm class: Introduce an abstraction for System Trace Module devices

A System Trace Module (STM) is a device exporting data in System Trace
Protocol (STP) format as defined by MIPI STP standards. Examples of such
devices are Intel(R) Trace Hub and Coresight STM.

This abstraction provides a unified interface for software trace sources
to send their data over an STM device to a debug host. In order to do
that, such a trace source needs to be assigned a pair of master/channel
identifiers that all the data from this source will be tagged with. The
STP decoder on the debug host side will use these master/channel tags to
distinguish different trace streams from one another inside one STP
stream.

This abstraction provides a configfs-based policy management mechanism
for dynamic allocation of these master/channel pairs based on trace
source-supplied string identifier. It has the flexibility of being
defined at runtime and at the same time (provided that the policy
definition is aligned with the decoding end) consistency.

For userspace trace sources, this abstraction provides write()-based and
mmap()-based (if the underlying stm device allows this) output mechanism.

For kernel-side trace sources, we provide "stm_source" device class that
can be connected to an stm device at run time.

Cc: linux-api@vger.kernel.org
Reviewed-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: default avatarAlexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9b76968d
What: /config/stp-policy
Date: June 2015
KernelVersion: 4.3
Description:
This group contains policies mandating Master/Channel allocation
for software sources wishing to send trace data over an STM
device.
What: /config/stp-policy/<device>.<policy>
Date: June 2015
KernelVersion: 4.3
Description:
This group is the root of a policy; its name is a concatenation
of an stm device name to which this policy applies and an
arbitrary string. If <device> part doesn't match an existing
stm device, mkdir will fail with ENODEV; if that device already
has a policy assigned to it, mkdir will fail with EBUSY.
What: /config/stp-policy/<device>.<policy>/device
Date: June 2015
KernelVersion: 4.3
Description:
STM device to which this policy applies, read only. Same as the
<device> component of its parent directory.
What: /config/stp-policy/<device>.<policy>/<node>
Date: June 2015
KernelVersion: 4.3
Description:
Policy node is a string identifier that software clients will
use to request a master/channel to be allocated and assigned to
them.
What: /config/stp-policy/<device>.<policy>/<node>/masters
Date: June 2015
KernelVersion: 4.3
Description:
Range of masters from which to allocate for users of this node.
Write two numbers: the first master and the last master number.
What: /config/stp-policy/<device>.<policy>/<node>/channels
Date: June 2015
KernelVersion: 4.3
Description:
Range of channels from which to allocate for users of this node.
Write two numbers: the first channel and the last channel
number.
What: /sys/class/stm/<stm>/masters
Date: June 2015
KernelVersion: 4.3
Contact: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Description:
Shows first and last available to software master numbers on
this STM device.
What: /sys/class/stm/<stm>/channels
Date: June 2015
KernelVersion: 4.3
Contact: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Description:
Shows the number of channels per master on this STM device.
What: /sys/class/stm_source/<stm_source>/stm_source_link
Date: June 2015
KernelVersion: 4.3
Contact: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Description:
stm_source device linkage to stm device, where its tracing data
is directed. Reads return an existing connection or "<none>" if
this stm_source is not connected to any stm device yet.
Write an existing (registered) stm device's name here to
connect that device. If a device is already connected to this
stm_source, it will first be disconnected.
...@@ -81,6 +81,9 @@ Code Seq#(hex) Include File Comments ...@@ -81,6 +81,9 @@ Code Seq#(hex) Include File Comments
0x22 all scsi/sg.h 0x22 all scsi/sg.h
'#' 00-3F IEEE 1394 Subsystem Block for the entire subsystem '#' 00-3F IEEE 1394 Subsystem Block for the entire subsystem
'$' 00-0F linux/perf_counter.h, linux/perf_event.h '$' 00-0F linux/perf_counter.h, linux/perf_event.h
'%' 00-0F include/uapi/linux/stm.h
System Trace Module subsystem
<mailto:alexander.shishkin@linux.intel.com>
'&' 00-07 drivers/firewire/nosy-user.h '&' 00-07 drivers/firewire/nosy-user.h
'1' 00-1F <linux/timepps.h> PPS kit from Ulrich Windl '1' 00-1F <linux/timepps.h> PPS kit from Ulrich Windl
<ftp://ftp.de.kernel.org/pub/linux/daemons/ntp/PPS/> <ftp://ftp.de.kernel.org/pub/linux/daemons/ntp/PPS/>
......
System Trace Module
===================
System Trace Module (STM) is a device described in MIPI STP specs as
STP trace stream generator. STP (System Trace Protocol) is a trace
protocol multiplexing data from multiple trace sources, each one of
which is assigned a unique pair of master and channel. While some of
these masters and channels are statically allocated to certain
hardware trace sources, others are available to software. Software
trace sources are usually free to pick for themselves any
master/channel combination from this pool.
On the receiving end of this STP stream (the decoder side), trace
sources can only be identified by master/channel combination, so in
order for the decoder to be able to make sense of the trace that
involves multiple trace sources, it needs to be able to map those
master/channel pairs to the trace sources that it understands.
For instance, it is helpful to know that syslog messages come on
master 7 channel 15, while arbitrary user applications can use masters
48 to 63 and channels 0 to 127.
To solve this mapping problem, stm class provides a policy management
mechanism via configfs, that allows defining rules that map string
identifiers to ranges of masters and channels. If these rules (policy)
are consistent with what decoder expects, it will be able to properly
process the trace data.
This policy is a tree structure containing rules (policy_node) that
have a name (string identifier) and a range of masters and channels
associated with it, located in "stp-policy" subsystem directory in
configfs. The topmost directory's name (the policy) is formatted as
the STM device name to which this policy applies and and arbitrary
string identifier separated by a stop. From the examle above, a rule
may look like this:
$ ls /config/stp-policy/dummy_stm.my-policy/user
channels masters
$ cat /config/stp-policy/dummy_stm.my-policy/user/masters
48 63
$ cat /config/stp-policy/dummy_stm.my-policy/user/channels
0 127
which means that the master allocation pool for this rule consists of
masters 48 through 63 and channel allocation pool has channels 0
through 127 in it. Now, any producer (trace source) identifying itself
with "user" identification string will be allocated a master and
channel from within these ranges.
These rules can be nested, for example, one can define a rule "dummy"
under "user" directory from the example above and this new rule will
be used for trace sources with the id string of "user/dummy".
Trace sources have to open the stm class device's node and write their
trace data into its file descriptor. In order to identify themselves
to the policy, they need to do a STP_POLICY_ID_SET ioctl on this file
descriptor providing their id string. Otherwise, they will be
automatically allocated a master/channel pair upon first write to this
file descriptor according to the "default" rule of the policy, if such
exists.
Some STM devices may allow direct mapping of the channel mmio regions
to userspace for zero-copy writing. One mappable page (in terms of
mmu) will usually contain multiple channels' mmios, so the user will
need to allocate that many channels to themselves (via the
aforementioned ioctl() call) to be able to do this. That is, if your
stm device's channel mmio region is 64 bytes and hardware page size is
4096 bytes, after a successful STP_POLICY_ID_SET ioctl() call with
width==64, you should be able to mmap() one page on this file
descriptor and obtain direct access to an mmio region for 64 channels.
For kernel-based trace sources, there is "stm_source" device
class. Devices of this class can be connected and disconnected to/from
stm devices at runtime via a sysfs attribute.
Examples of STM devices are Intel(R) Trace Hub [1] and Coresight STM
[2].
[1] https://software.intel.com/sites/default/files/managed/d3/3c/intel-th-developer-manual.pdf
[2] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0444b/index.html
...@@ -188,4 +188,6 @@ source "drivers/nvdimm/Kconfig" ...@@ -188,4 +188,6 @@ source "drivers/nvdimm/Kconfig"
source "drivers/nvmem/Kconfig" source "drivers/nvmem/Kconfig"
source "drivers/hwtracing/stm/Kconfig"
endmenu endmenu
...@@ -165,5 +165,6 @@ obj-$(CONFIG_PERF_EVENTS) += perf/ ...@@ -165,5 +165,6 @@ obj-$(CONFIG_PERF_EVENTS) += perf/
obj-$(CONFIG_RAS) += ras/ obj-$(CONFIG_RAS) += ras/
obj-$(CONFIG_THUNDERBOLT) += thunderbolt/ obj-$(CONFIG_THUNDERBOLT) += thunderbolt/
obj-$(CONFIG_CORESIGHT) += hwtracing/coresight/ obj-$(CONFIG_CORESIGHT) += hwtracing/coresight/
obj-$(CONFIG_STM) += hwtracing/stm/
obj-$(CONFIG_ANDROID) += android/ obj-$(CONFIG_ANDROID) += android/
obj-$(CONFIG_NVMEM) += nvmem/ obj-$(CONFIG_NVMEM) += nvmem/
config STM
tristate "System Trace Module devices"
help
A System Trace Module (STM) is a device exporting data in System
Trace Protocol (STP) format as defined by MIPI STP standards.
Examples of such devices are Intel(R) Trace Hub and Coresight STM.
Say Y here to enable System Trace Module device support.
obj-$(CONFIG_STM) += stm_core.o
stm_core-y := core.o policy.o
This diff is collapsed.
This diff is collapsed.
/*
* System Trace Module (STM) infrastructure
* Copyright (c) 2014, Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* STM class implements generic infrastructure for System Trace Module devices
* as defined in MIPI STPv2 specification.
*/
#ifndef _STM_STM_H_
#define _STM_STM_H_
struct stp_policy;
struct stp_policy_node;
struct stp_policy_node *
stp_policy_node_lookup(struct stm_device *stm, char *s);
void stp_policy_node_put(struct stp_policy_node *policy_node);
void stp_policy_unbind(struct stp_policy *policy);
void stp_policy_node_get_ranges(struct stp_policy_node *policy_node,
unsigned int *mstart, unsigned int *mend,
unsigned int *cstart, unsigned int *cend);
int stp_configfs_init(void);
void stp_configfs_exit(void);
struct stp_master {
unsigned int nr_free;
unsigned long chan_map[0];
};
struct stm_device {
struct device dev;
struct module *owner;
struct stp_policy *policy;
struct mutex policy_mutex;
int major;
unsigned int sw_nmasters;
struct stm_data *data;
spinlock_t link_lock;
struct list_head link_list;
/* master allocation */
spinlock_t mc_lock;
struct stp_master *masters[0];
};
#define to_stm_device(_d) \
container_of((_d), struct stm_device, dev)
struct stm_output {
unsigned int master;
unsigned int channel;
unsigned int nr_chans;
};
struct stm_file {
struct stm_device *stm;
struct stp_policy_node *policy_node;
struct stm_output output;
};
struct stm_device *stm_find_device(const char *name);
void stm_put_device(struct stm_device *stm);
struct stm_source_device {
struct device dev;
struct stm_source_data *data;
spinlock_t link_lock;
struct stm_device *link;
struct list_head link_entry;
/* one output per stm_source device */
struct stp_policy_node *policy_node;
struct stm_output output;
};
#define to_stm_source_device(_d) \
container_of((_d), struct stm_source_device, dev)
#endif /* _STM_STM_H_ */
/*
* System Trace Module (STM) infrastructure apis
* Copyright (C) 2014 Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/
#ifndef _STM_H_
#define _STM_H_
#include <linux/device.h>
/**
* enum stp_packet_type - STP packets that an STM driver sends
*/
enum stp_packet_type {
STP_PACKET_DATA = 0,
STP_PACKET_FLAG,
STP_PACKET_USER,
STP_PACKET_MERR,
STP_PACKET_GERR,
STP_PACKET_TRIG,
STP_PACKET_XSYNC,
};
/**
* enum stp_packet_flags - STP packet modifiers
*/
enum stp_packet_flags {
STP_PACKET_MARKED = 0x1,
STP_PACKET_TIMESTAMPED = 0x2,
};
struct stp_policy;
struct stm_device;
/**
* struct stm_data - STM device description and callbacks
* @name: device name
* @stm: internal structure, only used by stm class code
* @sw_start: first STP master available to software
* @sw_end: last STP master available to software
* @sw_nchannels: number of STP channels per master
* @sw_mmiosz: size of one channel's IO space, for mmap, optional
* @packet: callback that sends an STP packet
* @mmio_addr: mmap callback, optional
* @link: called when a new stm_source gets linked to us, optional
* @unlink: likewise for unlinking, again optional
* @set_options: set device-specific options on a channel
*
* Fill out this structure before calling stm_register_device() to create
* an STM device and stm_unregister_device() to destroy it. It will also be
* passed back to @packet(), @mmio_addr(), @link(), @unlink() and @set_options()
* callbacks.
*
* Normally, an STM device will have a range of masters available to software
* and the rest being statically assigned to various hardware trace sources.
* The former is defined by the the range [@sw_start..@sw_end] of the device
* description. That is, the lowest master that can be allocated to software
* writers is @sw_start and data from this writer will appear is @sw_start
* master in the STP stream.
*/
struct stm_data {
const char *name;
struct stm_device *stm;
unsigned int sw_start;
unsigned int sw_end;
unsigned int sw_nchannels;
unsigned int sw_mmiosz;
ssize_t (*packet)(struct stm_data *, unsigned int,
unsigned int, unsigned int,
unsigned int, unsigned int,
const unsigned char *);
phys_addr_t (*mmio_addr)(struct stm_data *, unsigned int,
unsigned int, unsigned int);
int (*link)(struct stm_data *, unsigned int,
unsigned int);
void (*unlink)(struct stm_data *, unsigned int,
unsigned int);
long (*set_options)(struct stm_data *, unsigned int,
unsigned int, unsigned int,
unsigned long);
};
int stm_register_device(struct device *parent, struct stm_data *stm_data,
struct module *owner);
void stm_unregister_device(struct stm_data *stm_data);
struct stm_source_device;
/**
* struct stm_source_data - STM source device description and callbacks
* @name: device name, will be used for policy lookup
* @src: internal structure, only used by stm class code
* @nr_chans: number of channels to allocate
* @link: called when this source gets linked to an STM device
* @unlink: called when this source is about to get unlinked from its STM
*
* Fill in this structure before calling stm_source_register_device() to
* register a source device. Also pass it to unregister and write calls.
*/
struct stm_source_data {
const char *name;
struct stm_source_device *src;
unsigned int percpu;
unsigned int nr_chans;
int (*link)(struct stm_source_data *data);
void (*unlink)(struct stm_source_data *data);
};
int stm_source_register_device(struct device *parent,
struct stm_source_data *data);
void stm_source_unregister_device(struct stm_source_data *data);
int stm_source_write(struct stm_source_data *data, unsigned int chan,
const char *buf, size_t count);
#endif /* _STM_H_ */
/*
* System Trace Module (STM) userspace interfaces
* Copyright (c) 2014, Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* STM class implements generic infrastructure for System Trace Module devices
* as defined in MIPI STPv2 specification.
*/
#ifndef _UAPI_LINUX_STM_H
#define _UAPI_LINUX_STM_H
#include <linux/types.h>
/**
* struct stp_policy_id - identification for the STP policy
* @size: size of the structure including real id[] length
* @master: assigned master
* @channel: first assigned channel
* @width: number of requested channels
* @id: identification string
*
* User must calculate the total size of the structure and put it into
* @size field, fill out the @id and desired @width. In return, kernel
* fills out @master, @channel and @width.
*/
struct stp_policy_id {
__u32 size;
__u16 master;
__u16 channel;
__u16 width;
/* padding */
__u16 __reserved_0;
__u32 __reserved_1;
char id[0];
};
#define STP_POLICY_ID_SET _IOWR('%', 0, struct stp_policy_id)
#define STP_POLICY_ID_GET _IOR('%', 1, struct stp_policy_id)
#define STP_SET_OPTIONS _IOW('%', 2, __u64)
#endif /* _UAPI_LINUX_STM_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment