coresight-priv.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CORESIGHT_PRIV_H
  6. #define _CORESIGHT_PRIV_H
  7. #include <linux/bitops.h>
  8. #include <linux/io.h>
  9. #include <linux/coresight.h>
  10. #include <linux/pm_runtime.h>
  11. /*
  12. * Coresight management registers (0xf00-0xfcc)
  13. * 0xfa0 - 0xfa4: Management registers in PFTv1.0
  14. * Trace registers in PFTv1.1
  15. */
  16. #define CORESIGHT_ITCTRL 0xf00
  17. #define CORESIGHT_CLAIMSET 0xfa0
  18. #define CORESIGHT_CLAIMCLR 0xfa4
  19. #define CORESIGHT_LAR 0xfb0
  20. #define CORESIGHT_LSR 0xfb4
  21. #define CORESIGHT_AUTHSTATUS 0xfb8
  22. #define CORESIGHT_DEVID 0xfc8
  23. #define CORESIGHT_DEVTYPE 0xfcc
  24. #define TIMEOUT_US 100
  25. #define BMVAL(val, lsb, msb) ((val & GENMASK(msb, lsb)) >> lsb)
  26. #define ETM_MODE_EXCL_KERN BIT(30)
  27. #define ETM_MODE_EXCL_USER BIT(31)
  28. typedef u32 (*coresight_read_fn)(const struct device *, u32 offset);
  29. #define __coresight_simple_func(type, func, name, lo_off, hi_off) \
  30. static ssize_t name##_show(struct device *_dev, \
  31. struct device_attribute *attr, char *buf) \
  32. { \
  33. type *drvdata = dev_get_drvdata(_dev->parent); \
  34. coresight_read_fn fn = func; \
  35. u64 val; \
  36. pm_runtime_get_sync(_dev->parent); \
  37. if (fn) \
  38. val = (u64)fn(_dev->parent, lo_off); \
  39. else \
  40. val = coresight_read_reg_pair(drvdata->base, \
  41. lo_off, hi_off); \
  42. pm_runtime_put_sync(_dev->parent); \
  43. return scnprintf(buf, PAGE_SIZE, "0x%llx\n", val); \
  44. } \
  45. static DEVICE_ATTR_RO(name)
  46. #define coresight_simple_func(type, func, name, offset) \
  47. __coresight_simple_func(type, func, name, offset, -1)
  48. #define coresight_simple_reg32(type, name, offset) \
  49. __coresight_simple_func(type, NULL, name, offset, -1)
  50. #define coresight_simple_reg64(type, name, lo_off, hi_off) \
  51. __coresight_simple_func(type, NULL, name, lo_off, hi_off)
  52. extern const u32 barrier_pkt[4];
  53. #define CORESIGHT_BARRIER_PKT_SIZE (sizeof(barrier_pkt))
  54. enum etm_addr_type {
  55. ETM_ADDR_TYPE_NONE,
  56. ETM_ADDR_TYPE_SINGLE,
  57. ETM_ADDR_TYPE_RANGE,
  58. ETM_ADDR_TYPE_START,
  59. ETM_ADDR_TYPE_STOP,
  60. };
  61. enum cs_mode {
  62. CS_MODE_DISABLED,
  63. CS_MODE_SYSFS,
  64. CS_MODE_PERF,
  65. };
  66. /**
  67. * struct cs_buffer - keep track of a recording session' specifics
  68. * @cur: index of the current buffer
  69. * @nr_pages: max number of pages granted to us
  70. * @offset: offset within the current buffer
  71. * @data_size: how much we collected in this run
  72. * @snapshot: is this run in snapshot mode
  73. * @data_pages: a handle the ring buffer
  74. */
  75. struct cs_buffers {
  76. unsigned int cur;
  77. unsigned int nr_pages;
  78. unsigned long offset;
  79. local_t data_size;
  80. bool snapshot;
  81. void **data_pages;
  82. };
  83. static inline void coresight_insert_barrier_packet(void *buf)
  84. {
  85. if (buf)
  86. memcpy(buf, barrier_pkt, CORESIGHT_BARRIER_PKT_SIZE);
  87. }
  88. static inline void CS_LOCK(void __iomem *addr)
  89. {
  90. do {
  91. /* Wait for things to settle */
  92. mb();
  93. writel_relaxed(0x0, addr + CORESIGHT_LAR);
  94. } while (0);
  95. }
  96. static inline void CS_UNLOCK(void __iomem *addr)
  97. {
  98. do {
  99. writel_relaxed(CORESIGHT_UNLOCK, addr + CORESIGHT_LAR);
  100. /* Make sure everyone has seen this */
  101. mb();
  102. } while (0);
  103. }
  104. static inline u64
  105. coresight_read_reg_pair(void __iomem *addr, s32 lo_offset, s32 hi_offset)
  106. {
  107. u64 val;
  108. val = readl_relaxed(addr + lo_offset);
  109. val |= (hi_offset < 0) ? 0 :
  110. (u64)readl_relaxed(addr + hi_offset) << 32;
  111. return val;
  112. }
  113. static inline void coresight_write_reg_pair(void __iomem *addr, u64 val,
  114. s32 lo_offset, s32 hi_offset)
  115. {
  116. writel_relaxed((u32)val, addr + lo_offset);
  117. if (hi_offset >= 0)
  118. writel_relaxed((u32)(val >> 32), addr + hi_offset);
  119. }
  120. void coresight_disable_path(struct list_head *path);
  121. int coresight_enable_path(struct list_head *path, u32 mode);
  122. struct coresight_device *coresight_get_sink(struct list_head *path);
  123. struct coresight_device *coresight_get_enabled_sink(bool reset);
  124. struct list_head *coresight_build_path(struct coresight_device *csdev,
  125. struct coresight_device *sink);
  126. void coresight_release_path(struct list_head *path);
  127. #ifdef CONFIG_CORESIGHT_SOURCE_ETM3X
  128. extern int etm_readl_cp14(u32 off, unsigned int *val);
  129. extern int etm_writel_cp14(u32 off, u32 val);
  130. #else
  131. static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; }
  132. static inline int etm_writel_cp14(u32 off, u32 val) { return 0; }
  133. #endif
  134. #endif