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