coresight-priv.h 4.4 KB

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