stm.h 3.1 KB

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