18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * System Trace Module (STM) infrastructure apis
48c2ecf20Sopenharmony_ci * Copyright (C) 2014 Intel Corporation.
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef _STM_H_
88c2ecf20Sopenharmony_ci#define _STM_H_
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/device.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/**
138c2ecf20Sopenharmony_ci * enum stp_packet_type - STP packets that an STM driver sends
148c2ecf20Sopenharmony_ci */
158c2ecf20Sopenharmony_cienum stp_packet_type {
168c2ecf20Sopenharmony_ci	STP_PACKET_DATA = 0,
178c2ecf20Sopenharmony_ci	STP_PACKET_FLAG,
188c2ecf20Sopenharmony_ci	STP_PACKET_USER,
198c2ecf20Sopenharmony_ci	STP_PACKET_MERR,
208c2ecf20Sopenharmony_ci	STP_PACKET_GERR,
218c2ecf20Sopenharmony_ci	STP_PACKET_TRIG,
228c2ecf20Sopenharmony_ci	STP_PACKET_XSYNC,
238c2ecf20Sopenharmony_ci};
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/**
268c2ecf20Sopenharmony_ci * enum stp_packet_flags - STP packet modifiers
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_cienum stp_packet_flags {
298c2ecf20Sopenharmony_ci	STP_PACKET_MARKED	= 0x1,
308c2ecf20Sopenharmony_ci	STP_PACKET_TIMESTAMPED	= 0x2,
318c2ecf20Sopenharmony_ci};
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_cistruct stp_policy;
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistruct stm_device;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/**
388c2ecf20Sopenharmony_ci * struct stm_data - STM device description and callbacks
398c2ecf20Sopenharmony_ci * @name:		device name
408c2ecf20Sopenharmony_ci * @stm:		internal structure, only used by stm class code
418c2ecf20Sopenharmony_ci * @sw_start:		first STP master available to software
428c2ecf20Sopenharmony_ci * @sw_end:		last STP master available to software
438c2ecf20Sopenharmony_ci * @sw_nchannels:	number of STP channels per master
448c2ecf20Sopenharmony_ci * @sw_mmiosz:		size of one channel's IO space, for mmap, optional
458c2ecf20Sopenharmony_ci * @hw_override:	masters in the STP stream will not match the ones
468c2ecf20Sopenharmony_ci *			assigned by software, but are up to the STM hardware
478c2ecf20Sopenharmony_ci * @packet:		callback that sends an STP packet
488c2ecf20Sopenharmony_ci * @mmio_addr:		mmap callback, optional
498c2ecf20Sopenharmony_ci * @link:		called when a new stm_source gets linked to us, optional
508c2ecf20Sopenharmony_ci * @unlink:		likewise for unlinking, again optional
518c2ecf20Sopenharmony_ci * @set_options:	set device-specific options on a channel
528c2ecf20Sopenharmony_ci *
538c2ecf20Sopenharmony_ci * Fill out this structure before calling stm_register_device() to create
548c2ecf20Sopenharmony_ci * an STM device and stm_unregister_device() to destroy it. It will also be
558c2ecf20Sopenharmony_ci * passed back to @packet(), @mmio_addr(), @link(), @unlink() and @set_options()
568c2ecf20Sopenharmony_ci * callbacks.
578c2ecf20Sopenharmony_ci *
588c2ecf20Sopenharmony_ci * Normally, an STM device will have a range of masters available to software
598c2ecf20Sopenharmony_ci * and the rest being statically assigned to various hardware trace sources.
608c2ecf20Sopenharmony_ci * The former is defined by the the range [@sw_start..@sw_end] of the device
618c2ecf20Sopenharmony_ci * description. That is, the lowest master that can be allocated to software
628c2ecf20Sopenharmony_ci * writers is @sw_start and data from this writer will appear is @sw_start
638c2ecf20Sopenharmony_ci * master in the STP stream.
648c2ecf20Sopenharmony_ci *
658c2ecf20Sopenharmony_ci * The @packet callback should adhere to the following rules:
668c2ecf20Sopenharmony_ci *   1) it must return the number of bytes it consumed from the payload;
678c2ecf20Sopenharmony_ci *   2) therefore, if it sent a packet that does not have payload (like FLAG),
688c2ecf20Sopenharmony_ci *      it must return zero;
698c2ecf20Sopenharmony_ci *   3) if it does not support the requested packet type/flag combination,
708c2ecf20Sopenharmony_ci *      it must return -ENOTSUPP.
718c2ecf20Sopenharmony_ci *
728c2ecf20Sopenharmony_ci * The @unlink callback is called when there are no more active writers so
738c2ecf20Sopenharmony_ci * that the master/channel can be quiesced.
748c2ecf20Sopenharmony_ci */
758c2ecf20Sopenharmony_cistruct stm_data {
768c2ecf20Sopenharmony_ci	const char		*name;
778c2ecf20Sopenharmony_ci	struct stm_device	*stm;
788c2ecf20Sopenharmony_ci	unsigned int		sw_start;
798c2ecf20Sopenharmony_ci	unsigned int		sw_end;
808c2ecf20Sopenharmony_ci	unsigned int		sw_nchannels;
818c2ecf20Sopenharmony_ci	unsigned int		sw_mmiosz;
828c2ecf20Sopenharmony_ci	unsigned int		hw_override;
838c2ecf20Sopenharmony_ci	ssize_t			(*packet)(struct stm_data *, unsigned int,
848c2ecf20Sopenharmony_ci					  unsigned int, unsigned int,
858c2ecf20Sopenharmony_ci					  unsigned int, unsigned int,
868c2ecf20Sopenharmony_ci					  const unsigned char *);
878c2ecf20Sopenharmony_ci	phys_addr_t		(*mmio_addr)(struct stm_data *, unsigned int,
888c2ecf20Sopenharmony_ci					     unsigned int, unsigned int);
898c2ecf20Sopenharmony_ci	int			(*link)(struct stm_data *, unsigned int,
908c2ecf20Sopenharmony_ci					unsigned int);
918c2ecf20Sopenharmony_ci	void			(*unlink)(struct stm_data *, unsigned int,
928c2ecf20Sopenharmony_ci					  unsigned int);
938c2ecf20Sopenharmony_ci	long			(*set_options)(struct stm_data *, unsigned int,
948c2ecf20Sopenharmony_ci					       unsigned int, unsigned int,
958c2ecf20Sopenharmony_ci					       unsigned long);
968c2ecf20Sopenharmony_ci};
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ciint stm_register_device(struct device *parent, struct stm_data *stm_data,
998c2ecf20Sopenharmony_ci			struct module *owner);
1008c2ecf20Sopenharmony_civoid stm_unregister_device(struct stm_data *stm_data);
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistruct stm_source_device;
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/**
1058c2ecf20Sopenharmony_ci * struct stm_source_data - STM source device description and callbacks
1068c2ecf20Sopenharmony_ci * @name:	device name, will be used for policy lookup
1078c2ecf20Sopenharmony_ci * @src:	internal structure, only used by stm class code
1088c2ecf20Sopenharmony_ci * @nr_chans:	number of channels to allocate
1098c2ecf20Sopenharmony_ci * @link:	called when this source gets linked to an STM device
1108c2ecf20Sopenharmony_ci * @unlink:	called when this source is about to get unlinked from its STM
1118c2ecf20Sopenharmony_ci *
1128c2ecf20Sopenharmony_ci * Fill in this structure before calling stm_source_register_device() to
1138c2ecf20Sopenharmony_ci * register a source device. Also pass it to unregister and write calls.
1148c2ecf20Sopenharmony_ci */
1158c2ecf20Sopenharmony_cistruct stm_source_data {
1168c2ecf20Sopenharmony_ci	const char		*name;
1178c2ecf20Sopenharmony_ci	struct stm_source_device *src;
1188c2ecf20Sopenharmony_ci	unsigned int		percpu;
1198c2ecf20Sopenharmony_ci	unsigned int		nr_chans;
1208c2ecf20Sopenharmony_ci	int			(*link)(struct stm_source_data *data);
1218c2ecf20Sopenharmony_ci	void			(*unlink)(struct stm_source_data *data);
1228c2ecf20Sopenharmony_ci};
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ciint stm_source_register_device(struct device *parent,
1258c2ecf20Sopenharmony_ci			       struct stm_source_data *data);
1268c2ecf20Sopenharmony_civoid stm_source_unregister_device(struct stm_source_data *data);
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ciint notrace stm_source_write(struct stm_source_data *data, unsigned int chan,
1298c2ecf20Sopenharmony_ci			     const char *buf, size_t count);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci#endif /* _STM_H_ */
132