intel_th.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Intel(R) Trace Hub data structures for implementing buffer sinks.
  4. *
  5. * Copyright (C) 2019 Intel Corporation.
  6. */
  7. #ifndef _INTEL_TH_H_
  8. #define _INTEL_TH_H_
  9. #include <linux/scatterlist.h>
  10. /* MSC operating modes (MSC_MODE) */
  11. enum {
  12. MSC_MODE_SINGLE = 0,
  13. MSC_MODE_MULTI,
  14. MSC_MODE_EXI,
  15. MSC_MODE_DEBUG,
  16. };
  17. struct msu_buffer {
  18. const char *name;
  19. /*
  20. * ->assign() called when buffer 'mode' is set to this driver
  21. * (aka mode_store())
  22. * @device: struct device * of the msc
  23. * @mode: allows the driver to set HW mode (see the enum above)
  24. * Returns: a pointer to a private structure associated with this
  25. * msc or NULL in case of error. This private structure
  26. * will then be passed into all other callbacks.
  27. */
  28. void *(*assign)(struct device *dev, int *mode);
  29. /* ->unassign(): some other mode is selected, clean up */
  30. void (*unassign)(void *priv);
  31. /*
  32. * ->alloc_window(): allocate memory for the window of a given
  33. * size
  34. * @sgt: pointer to sg_table, can be overridden by the buffer
  35. * driver, or kept intact
  36. * Returns: number of sg table entries <= number of pages;
  37. * 0 is treated as an allocation failure.
  38. */
  39. int (*alloc_window)(void *priv, struct sg_table **sgt,
  40. size_t size);
  41. void (*free_window)(void *priv, struct sg_table *sgt);
  42. /* ->activate(): trace has started */
  43. void (*activate)(void *priv);
  44. /* ->deactivate(): trace is about to stop */
  45. void (*deactivate)(void *priv);
  46. /*
  47. * ->ready(): window @sgt is filled up to the last block OR
  48. * tracing is stopped by the user; this window contains
  49. * @bytes data. The window in question transitions into
  50. * the "LOCKED" state, indicating that it can't be used
  51. * by hardware. To clear this state and make the window
  52. * available to the hardware again, call
  53. * intel_th_msc_window_unlock().
  54. */
  55. int (*ready)(void *priv, struct sg_table *sgt, size_t bytes);
  56. };
  57. int intel_th_msu_buffer_register(const struct msu_buffer *mbuf,
  58. struct module *owner);
  59. void intel_th_msu_buffer_unregister(const struct msu_buffer *mbuf);
  60. void intel_th_msc_window_unlock(struct device *dev, struct sg_table *sgt);
  61. #define module_intel_th_msu_buffer(__buffer) \
  62. static int __init __buffer##_init(void) \
  63. { \
  64. return intel_th_msu_buffer_register(&(__buffer), THIS_MODULE); \
  65. } \
  66. module_init(__buffer##_init); \
  67. static void __exit __buffer##_exit(void) \
  68. { \
  69. intel_th_msu_buffer_unregister(&(__buffer)); \
  70. } \
  71. module_exit(__buffer##_exit);
  72. #endif /* _INTEL_TH_H_ */