1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * System Trace Module (STM) infrastructure 4*4882a593Smuzhiyun * Copyright (c) 2014, Intel Corporation. 5*4882a593Smuzhiyun * 6*4882a593Smuzhiyun * STM class implements generic infrastructure for System Trace Module devices 7*4882a593Smuzhiyun * as defined in MIPI STPv2 specification. 8*4882a593Smuzhiyun */ 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun #ifndef _STM_STM_H_ 11*4882a593Smuzhiyun #define _STM_STM_H_ 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun #include <linux/configfs.h> 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun struct stp_policy; 16*4882a593Smuzhiyun struct stp_policy_node; 17*4882a593Smuzhiyun struct stm_protocol_driver; 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun int stp_configfs_init(void); 20*4882a593Smuzhiyun void stp_configfs_exit(void); 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun void *stp_policy_node_priv(struct stp_policy_node *pn); 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun struct stp_master { 25*4882a593Smuzhiyun unsigned int nr_free; 26*4882a593Smuzhiyun unsigned long chan_map[]; 27*4882a593Smuzhiyun }; 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun struct stm_device { 30*4882a593Smuzhiyun struct device dev; 31*4882a593Smuzhiyun struct module *owner; 32*4882a593Smuzhiyun struct stp_policy *policy; 33*4882a593Smuzhiyun struct mutex policy_mutex; 34*4882a593Smuzhiyun int major; 35*4882a593Smuzhiyun unsigned int sw_nmasters; 36*4882a593Smuzhiyun struct stm_data *data; 37*4882a593Smuzhiyun struct mutex link_mutex; 38*4882a593Smuzhiyun spinlock_t link_lock; 39*4882a593Smuzhiyun struct list_head link_list; 40*4882a593Smuzhiyun /* framing protocol in use */ 41*4882a593Smuzhiyun const struct stm_protocol_driver *pdrv; 42*4882a593Smuzhiyun const struct config_item_type *pdrv_node_type; 43*4882a593Smuzhiyun /* master allocation */ 44*4882a593Smuzhiyun spinlock_t mc_lock; 45*4882a593Smuzhiyun struct stp_master *masters[]; 46*4882a593Smuzhiyun }; 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun #define to_stm_device(_d) \ 49*4882a593Smuzhiyun container_of((_d), struct stm_device, dev) 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun struct stp_policy_node * 52*4882a593Smuzhiyun stp_policy_node_lookup(struct stm_device *stm, char *s); 53*4882a593Smuzhiyun void stp_policy_node_put(struct stp_policy_node *policy_node); 54*4882a593Smuzhiyun void stp_policy_unbind(struct stp_policy *policy); 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun void stp_policy_node_get_ranges(struct stp_policy_node *policy_node, 57*4882a593Smuzhiyun unsigned int *mstart, unsigned int *mend, 58*4882a593Smuzhiyun unsigned int *cstart, unsigned int *cend); 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun const struct config_item_type * 61*4882a593Smuzhiyun get_policy_node_type(struct configfs_attribute **attrs); 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun struct stm_output { 64*4882a593Smuzhiyun spinlock_t lock; 65*4882a593Smuzhiyun unsigned int master; 66*4882a593Smuzhiyun unsigned int channel; 67*4882a593Smuzhiyun unsigned int nr_chans; 68*4882a593Smuzhiyun void *pdrv_private; 69*4882a593Smuzhiyun }; 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun struct stm_file { 72*4882a593Smuzhiyun struct stm_device *stm; 73*4882a593Smuzhiyun struct stm_output output; 74*4882a593Smuzhiyun }; 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun struct stm_device *stm_find_device(const char *name); 77*4882a593Smuzhiyun void stm_put_device(struct stm_device *stm); 78*4882a593Smuzhiyun 79*4882a593Smuzhiyun struct stm_source_device { 80*4882a593Smuzhiyun struct device dev; 81*4882a593Smuzhiyun struct stm_source_data *data; 82*4882a593Smuzhiyun spinlock_t link_lock; 83*4882a593Smuzhiyun struct stm_device __rcu *link; 84*4882a593Smuzhiyun struct list_head link_entry; 85*4882a593Smuzhiyun /* one output per stm_source device */ 86*4882a593Smuzhiyun struct stm_output output; 87*4882a593Smuzhiyun }; 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun #define to_stm_source_device(_d) \ 90*4882a593Smuzhiyun container_of((_d), struct stm_source_device, dev) 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun void *to_pdrv_policy_node(struct config_item *item); 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun struct stm_protocol_driver { 95*4882a593Smuzhiyun struct module *owner; 96*4882a593Smuzhiyun const char *name; 97*4882a593Smuzhiyun ssize_t (*write)(struct stm_data *data, 98*4882a593Smuzhiyun struct stm_output *output, unsigned int chan, 99*4882a593Smuzhiyun const char *buf, size_t count); 100*4882a593Smuzhiyun void (*policy_node_init)(void *arg); 101*4882a593Smuzhiyun int (*output_open)(void *priv, struct stm_output *output); 102*4882a593Smuzhiyun void (*output_close)(struct stm_output *output); 103*4882a593Smuzhiyun ssize_t priv_sz; 104*4882a593Smuzhiyun struct configfs_attribute **policy_attr; 105*4882a593Smuzhiyun }; 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun int stm_register_protocol(const struct stm_protocol_driver *pdrv); 108*4882a593Smuzhiyun void stm_unregister_protocol(const struct stm_protocol_driver *pdrv); 109*4882a593Smuzhiyun int stm_lookup_protocol(const char *name, 110*4882a593Smuzhiyun const struct stm_protocol_driver **pdrv, 111*4882a593Smuzhiyun const struct config_item_type **type); 112*4882a593Smuzhiyun void stm_put_protocol(const struct stm_protocol_driver *pdrv); 113*4882a593Smuzhiyun ssize_t stm_data_write(struct stm_data *data, unsigned int m, 114*4882a593Smuzhiyun unsigned int c, bool ts_first, const void *buf, 115*4882a593Smuzhiyun size_t count); 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun #endif /* _STM_STM_H_ */ 118