coresight-priv.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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, offset) \
  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. u32 val; \
  43. pm_runtime_get_sync(_dev->parent); \
  44. if (fn) \
  45. val = fn(_dev->parent, offset); \
  46. else \
  47. val = readl_relaxed(drvdata->base + offset); \
  48. pm_runtime_put_sync(_dev->parent); \
  49. return scnprintf(buf, PAGE_SIZE, "0x%x\n", val); \
  50. } \
  51. static DEVICE_ATTR_RO(name)
  52. enum etm_addr_type {
  53. ETM_ADDR_TYPE_NONE,
  54. ETM_ADDR_TYPE_SINGLE,
  55. ETM_ADDR_TYPE_RANGE,
  56. ETM_ADDR_TYPE_START,
  57. ETM_ADDR_TYPE_STOP,
  58. };
  59. enum cs_mode {
  60. CS_MODE_DISABLED,
  61. CS_MODE_SYSFS,
  62. CS_MODE_PERF,
  63. };
  64. /**
  65. * struct cs_buffer - keep track of a recording session' specifics
  66. * @cur: index of the current buffer
  67. * @nr_pages: max number of pages granted to us
  68. * @offset: offset within the current buffer
  69. * @data_size: how much we collected in this run
  70. * @lost: other than zero if we had a HW buffer wrap around
  71. * @snapshot: is this run in snapshot mode
  72. * @data_pages: a handle the ring buffer
  73. */
  74. struct cs_buffers {
  75. unsigned int cur;
  76. unsigned int nr_pages;
  77. unsigned long offset;
  78. local_t data_size;
  79. local_t lost;
  80. bool snapshot;
  81. void **data_pages;
  82. };
  83. static inline void CS_LOCK(void __iomem *addr)
  84. {
  85. do {
  86. /* Wait for things to settle */
  87. mb();
  88. writel_relaxed(0x0, addr + CORESIGHT_LAR);
  89. } while (0);
  90. }
  91. static inline void CS_UNLOCK(void __iomem *addr)
  92. {
  93. do {
  94. writel_relaxed(CORESIGHT_UNLOCK, addr + CORESIGHT_LAR);
  95. /* Make sure everyone has seen this */
  96. mb();
  97. } while (0);
  98. }
  99. void coresight_disable_path(struct list_head *path);
  100. int coresight_enable_path(struct list_head *path, u32 mode);
  101. struct coresight_device *coresight_get_sink(struct list_head *path);
  102. struct coresight_device *coresight_get_enabled_sink(bool reset);
  103. struct list_head *coresight_build_path(struct coresight_device *csdev,
  104. struct coresight_device *sink);
  105. void coresight_release_path(struct list_head *path);
  106. #ifdef CONFIG_CORESIGHT_SOURCE_ETM3X
  107. extern int etm_readl_cp14(u32 off, unsigned int *val);
  108. extern int etm_writel_cp14(u32 off, u32 val);
  109. #else
  110. static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; }
  111. static inline int etm_writel_cp14(u32 off, u32 val) { return 0; }
  112. #endif
  113. #endif