stm.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * System Trace Module (STM) infrastructure apis
  3. * Copyright (C) 2014 Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _STM_H_
  15. #define _STM_H_
  16. #include <linux/device.h>
  17. /**
  18. * enum stp_packet_type - STP packets that an STM driver sends
  19. */
  20. enum stp_packet_type {
  21. STP_PACKET_DATA = 0,
  22. STP_PACKET_FLAG,
  23. STP_PACKET_USER,
  24. STP_PACKET_MERR,
  25. STP_PACKET_GERR,
  26. STP_PACKET_TRIG,
  27. STP_PACKET_XSYNC,
  28. };
  29. /**
  30. * enum stp_packet_flags - STP packet modifiers
  31. */
  32. enum stp_packet_flags {
  33. STP_PACKET_MARKED = 0x1,
  34. STP_PACKET_TIMESTAMPED = 0x2,
  35. };
  36. struct stp_policy;
  37. struct stm_device;
  38. /**
  39. * struct stm_data - STM device description and callbacks
  40. * @name: device name
  41. * @stm: internal structure, only used by stm class code
  42. * @sw_start: first STP master available to software
  43. * @sw_end: last STP master available to software
  44. * @sw_nchannels: number of STP channels per master
  45. * @sw_mmiosz: size of one channel's IO space, for mmap, optional
  46. * @packet: callback that sends an STP packet
  47. * @mmio_addr: mmap callback, optional
  48. * @link: called when a new stm_source gets linked to us, optional
  49. * @unlink: likewise for unlinking, again optional
  50. * @set_options: set device-specific options on a channel
  51. *
  52. * Fill out this structure before calling stm_register_device() to create
  53. * an STM device and stm_unregister_device() to destroy it. It will also be
  54. * passed back to @packet(), @mmio_addr(), @link(), @unlink() and @set_options()
  55. * callbacks.
  56. *
  57. * Normally, an STM device will have a range of masters available to software
  58. * and the rest being statically assigned to various hardware trace sources.
  59. * The former is defined by the the range [@sw_start..@sw_end] of the device
  60. * description. That is, the lowest master that can be allocated to software
  61. * writers is @sw_start and data from this writer will appear is @sw_start
  62. * master in the STP stream.
  63. */
  64. struct stm_data {
  65. const char *name;
  66. struct stm_device *stm;
  67. unsigned int sw_start;
  68. unsigned int sw_end;
  69. unsigned int sw_nchannels;
  70. unsigned int sw_mmiosz;
  71. ssize_t (*packet)(struct stm_data *, unsigned int,
  72. unsigned int, unsigned int,
  73. unsigned int, unsigned int,
  74. const unsigned char *);
  75. phys_addr_t (*mmio_addr)(struct stm_data *, unsigned int,
  76. unsigned int, unsigned int);
  77. int (*link)(struct stm_data *, unsigned int,
  78. unsigned int);
  79. void (*unlink)(struct stm_data *, unsigned int,
  80. unsigned int);
  81. long (*set_options)(struct stm_data *, unsigned int,
  82. unsigned int, unsigned int,
  83. unsigned long);
  84. };
  85. int stm_register_device(struct device *parent, struct stm_data *stm_data,
  86. struct module *owner);
  87. void stm_unregister_device(struct stm_data *stm_data);
  88. struct stm_source_device;
  89. /**
  90. * struct stm_source_data - STM source device description and callbacks
  91. * @name: device name, will be used for policy lookup
  92. * @src: internal structure, only used by stm class code
  93. * @nr_chans: number of channels to allocate
  94. * @link: called when this source gets linked to an STM device
  95. * @unlink: called when this source is about to get unlinked from its STM
  96. *
  97. * Fill in this structure before calling stm_source_register_device() to
  98. * register a source device. Also pass it to unregister and write calls.
  99. */
  100. struct stm_source_data {
  101. const char *name;
  102. struct stm_source_device *src;
  103. unsigned int percpu;
  104. unsigned int nr_chans;
  105. int (*link)(struct stm_source_data *data);
  106. void (*unlink)(struct stm_source_data *data);
  107. };
  108. int stm_source_register_device(struct device *parent,
  109. struct stm_source_data *data);
  110. void stm_source_unregister_device(struct stm_source_data *data);
  111. int stm_source_write(struct stm_source_data *data, unsigned int chan,
  112. const char *buf, size_t count);
  113. #endif /* _STM_H_ */