coresight-priv.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. /*
  25. * Coresight device CLAIM protocol.
  26. * See PSCI - ARM DEN 0022D, Section: 6.8.1 Debug and Trace save and restore.
  27. */
  28. #define CORESIGHT_CLAIM_SELF_HOSTED BIT(1)
  29. #define TIMEOUT_US 100
  30. #define BMVAL(val, lsb, msb) ((val & GENMASK(msb, lsb)) >> lsb)
  31. #define ETM_MODE_EXCL_KERN BIT(30)
  32. #define ETM_MODE_EXCL_USER BIT(31)
  33. typedef u32 (*coresight_read_fn)(const struct device *, u32 offset);
  34. #define __coresight_simple_func(type, func, name, lo_off, hi_off) \
  35. static ssize_t name##_show(struct device *_dev, \
  36. struct device_attribute *attr, char *buf) \
  37. { \
  38. type *drvdata = dev_get_drvdata(_dev->parent); \
  39. coresight_read_fn fn = func; \
  40. u64 val; \
  41. pm_runtime_get_sync(_dev->parent); \
  42. if (fn) \
  43. val = (u64)fn(_dev->parent, lo_off); \
  44. else \
  45. val = coresight_read_reg_pair(drvdata->base, \
  46. lo_off, hi_off); \
  47. pm_runtime_put_sync(_dev->parent); \
  48. return scnprintf(buf, PAGE_SIZE, "0x%llx\n", val); \
  49. } \
  50. static DEVICE_ATTR_RO(name)
  51. #define coresight_simple_func(type, func, name, offset) \
  52. __coresight_simple_func(type, func, name, offset, -1)
  53. #define coresight_simple_reg32(type, name, offset) \
  54. __coresight_simple_func(type, NULL, name, offset, -1)
  55. #define coresight_simple_reg64(type, name, lo_off, hi_off) \
  56. __coresight_simple_func(type, NULL, name, lo_off, hi_off)
  57. extern const u32 barrier_pkt[4];
  58. #define CORESIGHT_BARRIER_PKT_SIZE (sizeof(barrier_pkt))
  59. enum etm_addr_type {
  60. ETM_ADDR_TYPE_NONE,
  61. ETM_ADDR_TYPE_SINGLE,
  62. ETM_ADDR_TYPE_RANGE,
  63. ETM_ADDR_TYPE_START,
  64. ETM_ADDR_TYPE_STOP,
  65. };
  66. enum cs_mode {
  67. CS_MODE_DISABLED,
  68. CS_MODE_SYSFS,
  69. CS_MODE_PERF,
  70. };
  71. /**
  72. * struct cs_buffer - keep track of a recording session' specifics
  73. * @cur: index of the current buffer
  74. * @nr_pages: max number of pages granted to us
  75. * @offset: offset within the current buffer
  76. * @data_size: how much we collected in this run
  77. * @snapshot: is this run in snapshot mode
  78. * @data_pages: a handle the ring buffer
  79. */
  80. struct cs_buffers {
  81. unsigned int cur;
  82. unsigned int nr_pages;
  83. unsigned long offset;
  84. local_t data_size;
  85. bool snapshot;
  86. void **data_pages;
  87. };
  88. static inline void coresight_insert_barrier_packet(void *buf)
  89. {
  90. if (buf)
  91. memcpy(buf, barrier_pkt, CORESIGHT_BARRIER_PKT_SIZE);
  92. }
  93. static inline void CS_LOCK(void __iomem *addr)
  94. {
  95. do {
  96. /* Wait for things to settle */
  97. mb();
  98. writel_relaxed(0x0, addr + CORESIGHT_LAR);
  99. } while (0);
  100. }
  101. static inline void CS_UNLOCK(void __iomem *addr)
  102. {
  103. do {
  104. writel_relaxed(CORESIGHT_UNLOCK, addr + CORESIGHT_LAR);
  105. /* Make sure everyone has seen this */
  106. mb();
  107. } while (0);
  108. }
  109. static inline u64
  110. coresight_read_reg_pair(void __iomem *addr, s32 lo_offset, s32 hi_offset)
  111. {
  112. u64 val;
  113. val = readl_relaxed(addr + lo_offset);
  114. val |= (hi_offset < 0) ? 0 :
  115. (u64)readl_relaxed(addr + hi_offset) << 32;
  116. return val;
  117. }
  118. static inline void coresight_write_reg_pair(void __iomem *addr, u64 val,
  119. s32 lo_offset, s32 hi_offset)
  120. {
  121. writel_relaxed((u32)val, addr + lo_offset);
  122. if (hi_offset >= 0)
  123. writel_relaxed((u32)(val >> 32), addr + hi_offset);
  124. }
  125. void coresight_disable_path(struct list_head *path);
  126. int coresight_enable_path(struct list_head *path, u32 mode, void *sink_data);
  127. struct coresight_device *coresight_get_sink(struct list_head *path);
  128. struct coresight_device *coresight_get_enabled_sink(bool reset);
  129. struct list_head *coresight_build_path(struct coresight_device *csdev,
  130. struct coresight_device *sink);
  131. void coresight_release_path(struct list_head *path);
  132. #ifdef CONFIG_CORESIGHT_SOURCE_ETM3X
  133. extern int etm_readl_cp14(u32 off, unsigned int *val);
  134. extern int etm_writel_cp14(u32 off, u32 val);
  135. #else
  136. static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; }
  137. static inline int etm_writel_cp14(u32 off, u32 val) { return 0; }
  138. #endif
  139. #endif