blob: 210ff2292361a9daecdf0ac027dc3f28a9d1fbff [file] [log] [blame]
Alexander Shishkin7bd1d402015-09-22 15:47:10 +03001/*
2 * System Trace Module (STM) infrastructure apis
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
15#ifndef _STM_H_
16#define _STM_H_
17
18#include <linux/device.h>
19
20/**
21 * enum stp_packet_type - STP packets that an STM driver sends
22 */
23enum stp_packet_type {
24 STP_PACKET_DATA = 0,
25 STP_PACKET_FLAG,
26 STP_PACKET_USER,
27 STP_PACKET_MERR,
28 STP_PACKET_GERR,
29 STP_PACKET_TRIG,
30 STP_PACKET_XSYNC,
31};
32
33/**
34 * enum stp_packet_flags - STP packet modifiers
35 */
36enum stp_packet_flags {
37 STP_PACKET_MARKED = 0x1,
38 STP_PACKET_TIMESTAMPED = 0x2,
39};
40
41struct stp_policy;
42
43struct stm_device;
44
45/**
46 * struct stm_data - STM device description and callbacks
47 * @name: device name
48 * @stm: internal structure, only used by stm class code
49 * @sw_start: first STP master available to software
50 * @sw_end: last STP master available to software
51 * @sw_nchannels: number of STP channels per master
52 * @sw_mmiosz: size of one channel's IO space, for mmap, optional
Alexander Shishkin8e996a22016-05-03 11:33:37 -060053 * @hw_override: masters in the STP stream will not match the ones
54 * assigned by software, but are up to the STM hardware
Alexander Shishkin7bd1d402015-09-22 15:47:10 +030055 * @packet: callback that sends an STP packet
56 * @mmio_addr: mmap callback, optional
57 * @link: called when a new stm_source gets linked to us, optional
58 * @unlink: likewise for unlinking, again optional
59 * @set_options: set device-specific options on a channel
60 *
61 * Fill out this structure before calling stm_register_device() to create
62 * an STM device and stm_unregister_device() to destroy it. It will also be
63 * passed back to @packet(), @mmio_addr(), @link(), @unlink() and @set_options()
64 * callbacks.
65 *
66 * Normally, an STM device will have a range of masters available to software
67 * and the rest being statically assigned to various hardware trace sources.
68 * The former is defined by the the range [@sw_start..@sw_end] of the device
69 * description. That is, the lowest master that can be allocated to software
70 * writers is @sw_start and data from this writer will appear is @sw_start
71 * master in the STP stream.
Alexander Shishkinf8560a92016-02-15 19:12:01 +020072 *
73 * The @packet callback should adhere to the following rules:
74 * 1) it must return the number of bytes it consumed from the payload;
75 * 2) therefore, if it sent a packet that does not have payload (like FLAG),
76 * it must return zero;
77 * 3) if it does not support the requested packet type/flag combination,
78 * it must return -ENOTSUPP.
Alexander Shishkincc842402016-02-15 19:12:09 +020079 *
80 * The @unlink callback is called when there are no more active writers so
81 * that the master/channel can be quiesced.
Alexander Shishkin7bd1d402015-09-22 15:47:10 +030082 */
83struct stm_data {
84 const char *name;
85 struct stm_device *stm;
86 unsigned int sw_start;
87 unsigned int sw_end;
88 unsigned int sw_nchannels;
89 unsigned int sw_mmiosz;
Alexander Shishkin8e996a22016-05-03 11:33:37 -060090 unsigned int hw_override;
Alexander Shishkin7bd1d402015-09-22 15:47:10 +030091 ssize_t (*packet)(struct stm_data *, unsigned int,
92 unsigned int, unsigned int,
93 unsigned int, unsigned int,
94 const unsigned char *);
95 phys_addr_t (*mmio_addr)(struct stm_data *, unsigned int,
96 unsigned int, unsigned int);
97 int (*link)(struct stm_data *, unsigned int,
98 unsigned int);
99 void (*unlink)(struct stm_data *, unsigned int,
100 unsigned int);
101 long (*set_options)(struct stm_data *, unsigned int,
102 unsigned int, unsigned int,
103 unsigned long);
104};
105
106int stm_register_device(struct device *parent, struct stm_data *stm_data,
107 struct module *owner);
108void stm_unregister_device(struct stm_data *stm_data);
109
110struct stm_source_device;
111
112/**
113 * struct stm_source_data - STM source device description and callbacks
114 * @name: device name, will be used for policy lookup
115 * @src: internal structure, only used by stm class code
116 * @nr_chans: number of channels to allocate
117 * @link: called when this source gets linked to an STM device
118 * @unlink: called when this source is about to get unlinked from its STM
119 *
120 * Fill in this structure before calling stm_source_register_device() to
121 * register a source device. Also pass it to unregister and write calls.
122 */
123struct stm_source_data {
124 const char *name;
125 struct stm_source_device *src;
126 unsigned int percpu;
127 unsigned int nr_chans;
128 int (*link)(struct stm_source_data *data);
129 void (*unlink)(struct stm_source_data *data);
130};
131
132int stm_source_register_device(struct device *parent,
133 struct stm_source_data *data);
134void stm_source_unregister_device(struct stm_source_data *data);
135
Chunyan Zhang9dfed802016-11-21 15:57:23 +0800136int notrace stm_source_write(struct stm_source_data *data, unsigned int chan,
137 const char *buf, size_t count);
Alexander Shishkin7bd1d402015-09-22 15:47:10 +0300138
139#endif /* _STM_H_ */