18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * System Trace Module (STM) infrastructure
48c2ecf20Sopenharmony_ci * Copyright (c) 2014, Intel Corporation.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * STM class implements generic infrastructure for  System Trace Module devices
78c2ecf20Sopenharmony_ci * as defined in MIPI STPv2 specification.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef _STM_STM_H_
118c2ecf20Sopenharmony_ci#define _STM_STM_H_
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/configfs.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistruct stp_policy;
168c2ecf20Sopenharmony_cistruct stp_policy_node;
178c2ecf20Sopenharmony_cistruct stm_protocol_driver;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ciint stp_configfs_init(void);
208c2ecf20Sopenharmony_civoid stp_configfs_exit(void);
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_civoid *stp_policy_node_priv(struct stp_policy_node *pn);
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistruct stp_master {
258c2ecf20Sopenharmony_ci	unsigned int	nr_free;
268c2ecf20Sopenharmony_ci	unsigned long	chan_map[];
278c2ecf20Sopenharmony_ci};
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistruct stm_device {
308c2ecf20Sopenharmony_ci	struct device		dev;
318c2ecf20Sopenharmony_ci	struct module		*owner;
328c2ecf20Sopenharmony_ci	struct stp_policy	*policy;
338c2ecf20Sopenharmony_ci	struct mutex		policy_mutex;
348c2ecf20Sopenharmony_ci	int			major;
358c2ecf20Sopenharmony_ci	unsigned int		sw_nmasters;
368c2ecf20Sopenharmony_ci	struct stm_data		*data;
378c2ecf20Sopenharmony_ci	struct mutex		link_mutex;
388c2ecf20Sopenharmony_ci	spinlock_t		link_lock;
398c2ecf20Sopenharmony_ci	struct list_head	link_list;
408c2ecf20Sopenharmony_ci	/* framing protocol in use */
418c2ecf20Sopenharmony_ci	const struct stm_protocol_driver	*pdrv;
428c2ecf20Sopenharmony_ci	const struct config_item_type		*pdrv_node_type;
438c2ecf20Sopenharmony_ci	/* master allocation */
448c2ecf20Sopenharmony_ci	spinlock_t		mc_lock;
458c2ecf20Sopenharmony_ci	struct stp_master	*masters[];
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define to_stm_device(_d)				\
498c2ecf20Sopenharmony_ci	container_of((_d), struct stm_device, dev)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistruct stp_policy_node *
528c2ecf20Sopenharmony_cistp_policy_node_lookup(struct stm_device *stm, char *s);
538c2ecf20Sopenharmony_civoid stp_policy_node_put(struct stp_policy_node *policy_node);
548c2ecf20Sopenharmony_civoid stp_policy_unbind(struct stp_policy *policy);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_civoid stp_policy_node_get_ranges(struct stp_policy_node *policy_node,
578c2ecf20Sopenharmony_ci				unsigned int *mstart, unsigned int *mend,
588c2ecf20Sopenharmony_ci				unsigned int *cstart, unsigned int *cend);
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ciconst struct config_item_type *
618c2ecf20Sopenharmony_ciget_policy_node_type(struct configfs_attribute **attrs);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistruct stm_output {
648c2ecf20Sopenharmony_ci	spinlock_t		lock;
658c2ecf20Sopenharmony_ci	unsigned int		master;
668c2ecf20Sopenharmony_ci	unsigned int		channel;
678c2ecf20Sopenharmony_ci	unsigned int		nr_chans;
688c2ecf20Sopenharmony_ci	void			*pdrv_private;
698c2ecf20Sopenharmony_ci};
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cistruct stm_file {
728c2ecf20Sopenharmony_ci	struct stm_device	*stm;
738c2ecf20Sopenharmony_ci	struct stm_output	output;
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistruct stm_device *stm_find_device(const char *name);
778c2ecf20Sopenharmony_civoid stm_put_device(struct stm_device *stm);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistruct stm_source_device {
808c2ecf20Sopenharmony_ci	struct device		dev;
818c2ecf20Sopenharmony_ci	struct stm_source_data	*data;
828c2ecf20Sopenharmony_ci	spinlock_t		link_lock;
838c2ecf20Sopenharmony_ci	struct stm_device __rcu	*link;
848c2ecf20Sopenharmony_ci	struct list_head	link_entry;
858c2ecf20Sopenharmony_ci	/* one output per stm_source device */
868c2ecf20Sopenharmony_ci	struct stm_output	output;
878c2ecf20Sopenharmony_ci};
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define to_stm_source_device(_d)				\
908c2ecf20Sopenharmony_ci	container_of((_d), struct stm_source_device, dev)
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_civoid *to_pdrv_policy_node(struct config_item *item);
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistruct stm_protocol_driver {
958c2ecf20Sopenharmony_ci	struct module	*owner;
968c2ecf20Sopenharmony_ci	const char	*name;
978c2ecf20Sopenharmony_ci	ssize_t		(*write)(struct stm_data *data,
988c2ecf20Sopenharmony_ci				 struct stm_output *output, unsigned int chan,
998c2ecf20Sopenharmony_ci				 const char *buf, size_t count);
1008c2ecf20Sopenharmony_ci	void		(*policy_node_init)(void *arg);
1018c2ecf20Sopenharmony_ci	int		(*output_open)(void *priv, struct stm_output *output);
1028c2ecf20Sopenharmony_ci	void		(*output_close)(struct stm_output *output);
1038c2ecf20Sopenharmony_ci	ssize_t		priv_sz;
1048c2ecf20Sopenharmony_ci	struct configfs_attribute	**policy_attr;
1058c2ecf20Sopenharmony_ci};
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ciint stm_register_protocol(const struct stm_protocol_driver *pdrv);
1088c2ecf20Sopenharmony_civoid stm_unregister_protocol(const struct stm_protocol_driver *pdrv);
1098c2ecf20Sopenharmony_ciint stm_lookup_protocol(const char *name,
1108c2ecf20Sopenharmony_ci			const struct stm_protocol_driver **pdrv,
1118c2ecf20Sopenharmony_ci			const struct config_item_type **type);
1128c2ecf20Sopenharmony_civoid stm_put_protocol(const struct stm_protocol_driver *pdrv);
1138c2ecf20Sopenharmony_cissize_t stm_data_write(struct stm_data *data, unsigned int m,
1148c2ecf20Sopenharmony_ci		       unsigned int c, bool ts_first, const void *buf,
1158c2ecf20Sopenharmony_ci		       size_t count);
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#endif /* _STM_STM_H_ */
118