Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 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 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
Pratik Patel | cf41862 | 2011-09-22 11:15:11 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/device.h> |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/io.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <linux/fs.h> |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 22 | #include <linux/slab.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/smp.h> |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 25 | #include <linux/wakelock.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame^] | 26 | #include <linux/pm_qos.h> |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 27 | #include <linux/sysfs.h> |
| 28 | #include <linux/stat.h> |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 29 | #include <asm/sections.h> |
Pratik Patel | 2d0c7b6 | 2012-02-24 19:04:37 -0800 | [diff] [blame] | 30 | #include <mach/socinfo.h> |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 31 | |
Pratik Patel | b27a935 | 2012-03-17 22:37:21 -0700 | [diff] [blame] | 32 | #include "qdss-priv.h" |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 33 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 34 | #define etm_writel(etm, cpu, val, off) \ |
| 35 | __raw_writel((val), etm.base + (SZ_4K * cpu) + off) |
| 36 | #define etm_readl(etm, cpu, off) \ |
| 37 | __raw_readl(etm.base + (SZ_4K * cpu) + off) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 38 | |
| 39 | /* |
| 40 | * Device registers: |
| 41 | * 0x000 - 0x2FC: Trace registers |
| 42 | * 0x300 - 0x314: Management registers |
| 43 | * 0x318 - 0xEFC: Trace registers |
| 44 | * |
| 45 | * Coresight registers |
| 46 | * 0xF00 - 0xF9C: Management registers |
| 47 | * 0xFA0 - 0xFA4: Management registers in PFTv1.0 |
| 48 | * Trace registers in PFTv1.1 |
| 49 | * 0xFA8 - 0xFFC: Management registers |
| 50 | */ |
| 51 | |
| 52 | /* Trace registers (0x000-0x2FC) */ |
| 53 | #define ETMCR (0x000) |
| 54 | #define ETMCCR (0x004) |
| 55 | #define ETMTRIGGER (0x008) |
| 56 | #define ETMSR (0x010) |
| 57 | #define ETMSCR (0x014) |
| 58 | #define ETMTSSCR (0x018) |
| 59 | #define ETMTEEVR (0x020) |
| 60 | #define ETMTECR1 (0x024) |
| 61 | #define ETMFFLR (0x02C) |
| 62 | #define ETMACVRn(n) (0x040 + (n * 4)) |
| 63 | #define ETMACTRn(n) (0x080 + (n * 4)) |
| 64 | #define ETMCNTRLDVRn(n) (0x140 + (n * 4)) |
| 65 | #define ETMCNTENRn(n) (0x150 + (n * 4)) |
| 66 | #define ETMCNTRLDEVRn(n) (0x160 + (n * 4)) |
| 67 | #define ETMCNTVRn(n) (0x170 + (n * 4)) |
| 68 | #define ETMSQ12EVR (0x180) |
| 69 | #define ETMSQ21EVR (0x184) |
| 70 | #define ETMSQ23EVR (0x188) |
Pratik Patel | d5bbc76 | 2012-01-29 14:13:21 -0800 | [diff] [blame] | 71 | #define ETMSQ31EVR (0x18C) |
| 72 | #define ETMSQ32EVR (0x190) |
| 73 | #define ETMSQ13EVR (0x194) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 74 | #define ETMSQR (0x19C) |
| 75 | #define ETMEXTOUTEVRn(n) (0x1A0 + (n * 4)) |
| 76 | #define ETMCIDCVRn(n) (0x1B0 + (n * 4)) |
| 77 | #define ETMCIDCMR (0x1BC) |
| 78 | #define ETMIMPSPEC0 (0x1C0) |
| 79 | #define ETMIMPSPEC1 (0x1C4) |
| 80 | #define ETMIMPSPEC2 (0x1C8) |
| 81 | #define ETMIMPSPEC3 (0x1CC) |
| 82 | #define ETMIMPSPEC4 (0x1D0) |
| 83 | #define ETMIMPSPEC5 (0x1D4) |
| 84 | #define ETMIMPSPEC6 (0x1D8) |
| 85 | #define ETMIMPSPEC7 (0x1DC) |
| 86 | #define ETMSYNCFR (0x1E0) |
| 87 | #define ETMIDR (0x1E4) |
| 88 | #define ETMCCER (0x1E8) |
| 89 | #define ETMEXTINSELR (0x1EC) |
| 90 | #define ETMTESSEICR (0x1F0) |
| 91 | #define ETMEIBCR (0x1F4) |
| 92 | #define ETMTSEVR (0x1F8) |
| 93 | #define ETMAUXCR (0x1FC) |
| 94 | #define ETMTRACEIDR (0x200) |
Pratik Patel | d5bbc76 | 2012-01-29 14:13:21 -0800 | [diff] [blame] | 95 | #define ETMVMIDCVR (0x240) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 96 | /* Management registers (0x300-0x314) */ |
| 97 | #define ETMOSLAR (0x300) |
| 98 | #define ETMOSLSR (0x304) |
| 99 | #define ETMOSSRR (0x308) |
| 100 | #define ETMPDCR (0x310) |
| 101 | #define ETMPDSR (0x314) |
| 102 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 103 | #define ETM_MAX_ADDR_CMP (16) |
| 104 | #define ETM_MAX_CNTR (4) |
| 105 | #define ETM_MAX_CTXID_CMP (3) |
| 106 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 107 | #define ETM_MODE_EXCLUDE BIT(0) |
| 108 | #define ETM_MODE_CYCACC BIT(1) |
| 109 | #define ETM_MODE_STALL BIT(2) |
| 110 | #define ETM_MODE_TIMESTAMP BIT(3) |
| 111 | #define ETM_MODE_CTXID BIT(4) |
| 112 | #define ETM_MODE_ALL (0x1F) |
| 113 | |
| 114 | #define ETM_EVENT_MASK (0x1FFFF) |
| 115 | #define ETM_SYNC_MASK (0xFFF) |
| 116 | #define ETM_ALL_MASK (0xFFFFFFFF) |
| 117 | |
| 118 | #define ETM_SEQ_STATE_MAX_VAL (0x2) |
| 119 | |
| 120 | enum { |
| 121 | ETM_ADDR_TYPE_NONE, |
| 122 | ETM_ADDR_TYPE_SINGLE, |
| 123 | ETM_ADDR_TYPE_RANGE, |
| 124 | ETM_ADDR_TYPE_START, |
| 125 | ETM_ADDR_TYPE_STOP, |
| 126 | }; |
| 127 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 128 | #define ETM_LOCK(cpu) \ |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 129 | do { \ |
| 130 | mb(); \ |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 131 | etm_writel(etm, cpu, 0x0, CS_LAR); \ |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 132 | } while (0) |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 133 | #define ETM_UNLOCK(cpu) \ |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 134 | do { \ |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 135 | etm_writel(etm, cpu, CS_UNLOCK_MAGIC, CS_LAR); \ |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 136 | mb(); \ |
| 137 | } while (0) |
| 138 | |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 139 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 140 | #ifdef MODULE_PARAM_PREFIX |
| 141 | #undef MODULE_PARAM_PREFIX |
| 142 | #endif |
| 143 | #define MODULE_PARAM_PREFIX "qdss." |
| 144 | |
Pratik Patel | 29cba15 | 2012-01-03 11:40:26 -0800 | [diff] [blame] | 145 | #ifdef CONFIG_MSM_QDSS_ETM_DEFAULT_ENABLE |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 146 | static int etm_boot_enable = 1; |
Pratik Patel | 29cba15 | 2012-01-03 11:40:26 -0800 | [diff] [blame] | 147 | #else |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 148 | static int etm_boot_enable; |
Pratik Patel | 29cba15 | 2012-01-03 11:40:26 -0800 | [diff] [blame] | 149 | #endif |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 150 | module_param_named( |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 151 | etm_boot_enable, etm_boot_enable, int, S_IRUGO |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 152 | ); |
| 153 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 154 | struct etm_ctx { |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 155 | void __iomem *base; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 156 | bool enabled; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 157 | struct wake_lock wake_lock; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame^] | 158 | struct pm_qos_request qos_req; |
Pratik Patel | e10a77c | 2012-03-20 10:35:16 -0700 | [diff] [blame] | 159 | struct qdss_source *src; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 160 | struct mutex mutex; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 161 | struct device *dev; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 162 | struct kobject *kobj; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 163 | uint8_t arch; |
| 164 | uint8_t nr_addr_cmp; |
| 165 | uint8_t nr_cntr; |
| 166 | uint8_t nr_ext_inp; |
| 167 | uint8_t nr_ext_out; |
| 168 | uint8_t nr_ctxid_cmp; |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 169 | uint8_t reset; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 170 | uint32_t mode; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 171 | uint32_t ctrl; |
| 172 | uint32_t trigger_event; |
| 173 | uint32_t startstop_ctrl; |
| 174 | uint32_t enable_event; |
| 175 | uint32_t enable_ctrl1; |
| 176 | uint32_t fifofull_level; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 177 | uint8_t addr_idx; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 178 | uint32_t addr_val[ETM_MAX_ADDR_CMP]; |
| 179 | uint32_t addr_acctype[ETM_MAX_ADDR_CMP]; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 180 | uint32_t addr_type[ETM_MAX_ADDR_CMP]; |
| 181 | uint8_t cntr_idx; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 182 | uint32_t cntr_rld_val[ETM_MAX_CNTR]; |
| 183 | uint32_t cntr_event[ETM_MAX_CNTR]; |
| 184 | uint32_t cntr_rld_event[ETM_MAX_CNTR]; |
| 185 | uint32_t cntr_val[ETM_MAX_CNTR]; |
| 186 | uint32_t seq_12_event; |
| 187 | uint32_t seq_21_event; |
| 188 | uint32_t seq_23_event; |
| 189 | uint32_t seq_31_event; |
| 190 | uint32_t seq_32_event; |
| 191 | uint32_t seq_13_event; |
| 192 | uint32_t seq_curr_state; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 193 | uint8_t ctxid_idx; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 194 | uint32_t ctxid_val[ETM_MAX_CTXID_CMP]; |
| 195 | uint32_t ctxid_mask; |
| 196 | uint32_t sync_freq; |
| 197 | uint32_t timestamp_event; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 198 | }; |
| 199 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 200 | static struct etm_ctx etm = { |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 201 | .trigger_event = 0x406F, |
| 202 | .enable_event = 0x6F, |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 203 | .enable_ctrl1 = 0x1, |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 204 | .fifofull_level = 0x28, |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 205 | .addr_val = {(uint32_t) _stext, (uint32_t) _etext}, |
| 206 | .addr_type = {ETM_ADDR_TYPE_RANGE, ETM_ADDR_TYPE_RANGE}, |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 207 | .cntr_event = {[0 ... (ETM_MAX_CNTR - 1)] = 0x406F}, |
| 208 | .cntr_rld_event = {[0 ... (ETM_MAX_CNTR - 1)] = 0x406F}, |
| 209 | .seq_12_event = 0x406F, |
| 210 | .seq_21_event = 0x406F, |
| 211 | .seq_23_event = 0x406F, |
| 212 | .seq_31_event = 0x406F, |
| 213 | .seq_32_event = 0x406F, |
| 214 | .seq_13_event = 0x406F, |
| 215 | .sync_freq = 0x80, |
| 216 | .timestamp_event = 0x406F, |
| 217 | }; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 218 | |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 219 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 220 | /* ETM clock is derived from the processor clock and gets enabled on a |
| 221 | * logical OR of below items on Krait (pass2 onwards): |
| 222 | * 1.CPMR[ETMCLKEN] is 1 |
| 223 | * 2.ETMCR[PD] is 0 |
| 224 | * 3.ETMPDCR[PU] is 1 |
| 225 | * 4.Reset is asserted (core or debug) |
| 226 | * 5.APB memory mapped requests (eg. EDAP access) |
| 227 | * |
| 228 | * 1., 2. and 3. above are permanent enables whereas 4. and 5. are temporary |
| 229 | * enables |
| 230 | * |
| 231 | * We rely on 5. to be able to access ETMCR and then use 2. above for ETM |
| 232 | * clock vote in the driver and the save-restore code uses 1. above |
| 233 | * for its vote |
| 234 | */ |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 235 | static void etm_set_pwrdwn(int cpu) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 236 | { |
| 237 | uint32_t etmcr; |
| 238 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 239 | etmcr = etm_readl(etm, cpu, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 240 | etmcr |= BIT(0); |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 241 | etm_writel(etm, cpu, etmcr, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 244 | static void etm_clr_pwrdwn(int cpu) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 245 | { |
| 246 | uint32_t etmcr; |
| 247 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 248 | etmcr = etm_readl(etm, cpu, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 249 | etmcr &= ~BIT(0); |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 250 | etm_writel(etm, cpu, etmcr, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 253 | static void etm_set_prog(int cpu) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 254 | { |
| 255 | uint32_t etmcr; |
| 256 | int count; |
| 257 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 258 | etmcr = etm_readl(etm, cpu, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 259 | etmcr |= BIT(10); |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 260 | etm_writel(etm, cpu, etmcr, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 261 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 262 | for (count = TIMEOUT_US; BVAL(etm_readl(etm, cpu, ETMSR), 1) != 1 |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 263 | && count > 0; count--) |
| 264 | udelay(1); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 265 | WARN(count == 0, "timeout while setting prog bit, ETMSR: %#x\n", |
| 266 | etm_readl(etm, cpu, ETMSR)); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 269 | static void etm_clr_prog(int cpu) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 270 | { |
| 271 | uint32_t etmcr; |
| 272 | int count; |
| 273 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 274 | etmcr = etm_readl(etm, cpu, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 275 | etmcr &= ~BIT(10); |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 276 | etm_writel(etm, cpu, etmcr, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 277 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 278 | for (count = TIMEOUT_US; BVAL(etm_readl(etm, cpu, ETMSR), 1) != 0 |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 279 | && count > 0; count--) |
| 280 | udelay(1); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 281 | WARN(count == 0, "timeout while clearing prog bit, ETMSR: %#x\n", |
| 282 | etm_readl(etm, cpu, ETMSR)); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 285 | static void __etm_enable(int cpu) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 286 | { |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 287 | int i; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 288 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 289 | ETM_UNLOCK(cpu); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 290 | /* Vote for ETM power/clock enable */ |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 291 | etm_clr_pwrdwn(cpu); |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 292 | etm_set_prog(cpu); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 293 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 294 | etm_writel(etm, cpu, etm.ctrl | BIT(10), ETMCR); |
| 295 | etm_writel(etm, cpu, etm.trigger_event, ETMTRIGGER); |
| 296 | etm_writel(etm, cpu, etm.startstop_ctrl, ETMTSSCR); |
| 297 | etm_writel(etm, cpu, etm.enable_event, ETMTEEVR); |
| 298 | etm_writel(etm, cpu, etm.enable_ctrl1, ETMTECR1); |
| 299 | etm_writel(etm, cpu, etm.fifofull_level, ETMFFLR); |
| 300 | for (i = 0; i < etm.nr_addr_cmp; i++) { |
| 301 | etm_writel(etm, cpu, etm.addr_val[i], ETMACVRn(i)); |
| 302 | etm_writel(etm, cpu, etm.addr_acctype[i], ETMACTRn(i)); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 303 | } |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 304 | for (i = 0; i < etm.nr_cntr; i++) { |
| 305 | etm_writel(etm, cpu, etm.cntr_rld_val[i], ETMCNTRLDVRn(i)); |
| 306 | etm_writel(etm, cpu, etm.cntr_event[i], ETMCNTENRn(i)); |
| 307 | etm_writel(etm, cpu, etm.cntr_rld_event[i], ETMCNTRLDEVRn(i)); |
| 308 | etm_writel(etm, cpu, etm.cntr_val[i], ETMCNTVRn(i)); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 309 | } |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 310 | etm_writel(etm, cpu, etm.seq_12_event, ETMSQ12EVR); |
| 311 | etm_writel(etm, cpu, etm.seq_21_event, ETMSQ21EVR); |
| 312 | etm_writel(etm, cpu, etm.seq_23_event, ETMSQ23EVR); |
| 313 | etm_writel(etm, cpu, etm.seq_31_event, ETMSQ31EVR); |
| 314 | etm_writel(etm, cpu, etm.seq_32_event, ETMSQ32EVR); |
| 315 | etm_writel(etm, cpu, etm.seq_13_event, ETMSQ13EVR); |
| 316 | etm_writel(etm, cpu, etm.seq_curr_state, ETMSQR); |
| 317 | for (i = 0; i < etm.nr_ext_out; i++) |
| 318 | etm_writel(etm, cpu, 0x0000406F, ETMEXTOUTEVRn(i)); |
| 319 | for (i = 0; i < etm.nr_ctxid_cmp; i++) |
| 320 | etm_writel(etm, cpu, etm.ctxid_val[i], ETMCIDCVRn(i)); |
| 321 | etm_writel(etm, cpu, etm.ctxid_mask, ETMCIDCMR); |
| 322 | etm_writel(etm, cpu, etm.sync_freq, ETMSYNCFR); |
| 323 | etm_writel(etm, cpu, 0x00000000, ETMEXTINSELR); |
| 324 | etm_writel(etm, cpu, etm.timestamp_event, ETMTSEVR); |
| 325 | etm_writel(etm, cpu, 0x00000000, ETMAUXCR); |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 326 | etm_writel(etm, cpu, cpu+1, ETMTRACEIDR); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 327 | etm_writel(etm, cpu, 0x00000000, ETMVMIDCVR); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 328 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 329 | etm_clr_prog(cpu); |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 330 | ETM_LOCK(cpu); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 333 | static int etm_enable(void) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 334 | { |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 335 | int ret, cpu; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 336 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 337 | if (etm.enabled) { |
| 338 | dev_err(etm.dev, "ETM tracing already enabled\n"); |
| 339 | ret = -EPERM; |
| 340 | goto err; |
| 341 | } |
| 342 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 343 | wake_lock(&etm.wake_lock); |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 344 | /* 1. causes all online cpus to come out of idle PC |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 345 | * 2. prevents idle PC until save restore flag is enabled atomically |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 346 | * |
| 347 | * we rely on the user to prevent hotplug on/off racing with this |
| 348 | * operation and to ensure cores where trace is expected to be turned |
| 349 | * on are already hotplugged on |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 350 | */ |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 351 | pm_qos_update_request(&etm.qos_req, 0); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 352 | |
Pratik Patel | e10a77c | 2012-03-20 10:35:16 -0700 | [diff] [blame] | 353 | ret = qdss_enable(etm.src); |
| 354 | if (ret) |
| 355 | goto err_qdss; |
| 356 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 357 | for_each_online_cpu(cpu) |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 358 | __etm_enable(cpu); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 359 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 360 | etm.enabled = true; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 361 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 362 | pm_qos_update_request(&etm.qos_req, PM_QOS_DEFAULT_VALUE); |
| 363 | wake_unlock(&etm.wake_lock); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 364 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 365 | dev_info(etm.dev, "ETM tracing enabled\n"); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 366 | return 0; |
Pratik Patel | e10a77c | 2012-03-20 10:35:16 -0700 | [diff] [blame] | 367 | |
| 368 | err_qdss: |
| 369 | pm_qos_update_request(&etm.qos_req, PM_QOS_DEFAULT_VALUE); |
| 370 | wake_unlock(&etm.wake_lock); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 371 | err: |
| 372 | return ret; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 375 | static void __etm_disable(int cpu) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 376 | { |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 377 | ETM_UNLOCK(cpu); |
| 378 | etm_set_prog(cpu); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 379 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 380 | /* program trace enable to low by using always false event */ |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 381 | etm_writel(etm, cpu, 0x6F | BIT(14), ETMTEEVR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 382 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 383 | /* Vote for ETM power/clock disable */ |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 384 | etm_set_pwrdwn(cpu); |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 385 | ETM_LOCK(cpu); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 388 | static int etm_disable(void) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 389 | { |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 390 | int ret, cpu; |
| 391 | |
| 392 | if (!etm.enabled) { |
| 393 | dev_err(etm.dev, "ETM tracing already disabled\n"); |
| 394 | ret = -EPERM; |
| 395 | goto err; |
| 396 | } |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 397 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 398 | wake_lock(&etm.wake_lock); |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 399 | /* 1. causes all online cpus to come out of idle PC |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 400 | * 2. prevents idle PC until save restore flag is disabled atomically |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 401 | * |
| 402 | * we rely on the user to prevent hotplug on/off racing with this |
| 403 | * operation and to ensure cores where trace is expected to be turned |
| 404 | * off are already hotplugged on |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 405 | */ |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 406 | pm_qos_update_request(&etm.qos_req, 0); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 407 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 408 | for_each_online_cpu(cpu) |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 409 | __etm_disable(cpu); |
Pratik Patel | e10a77c | 2012-03-20 10:35:16 -0700 | [diff] [blame] | 410 | |
| 411 | qdss_disable(etm.src); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 412 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 413 | etm.enabled = false; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 414 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 415 | pm_qos_update_request(&etm.qos_req, PM_QOS_DEFAULT_VALUE); |
| 416 | wake_unlock(&etm.wake_lock); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 417 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 418 | dev_info(etm.dev, "ETM tracing disabled\n"); |
| 419 | return 0; |
| 420 | err: |
| 421 | return ret; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 424 | /* Memory mapped writes to clear os lock not supported */ |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 425 | static void etm_os_unlock(void *unused) |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 426 | { |
| 427 | unsigned long value = 0x0; |
| 428 | |
| 429 | asm("mcr p14, 1, %0, c1, c0, 4\n\t" : : "r" (value)); |
| 430 | asm("isb\n\t"); |
| 431 | } |
| 432 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 433 | #define ETM_STORE(__name, mask) \ |
| 434 | static ssize_t __name##_store(struct kobject *kobj, \ |
| 435 | struct kobj_attribute *attr, \ |
| 436 | const char *buf, size_t n) \ |
| 437 | { \ |
| 438 | unsigned long val; \ |
| 439 | \ |
| 440 | if (sscanf(buf, "%lx", &val) != 1) \ |
| 441 | return -EINVAL; \ |
| 442 | \ |
| 443 | etm.__name = val & mask; \ |
| 444 | return n; \ |
| 445 | } |
| 446 | |
| 447 | #define ETM_SHOW(__name) \ |
| 448 | static ssize_t __name##_show(struct kobject *kobj, \ |
| 449 | struct kobj_attribute *attr, \ |
| 450 | char *buf) \ |
| 451 | { \ |
| 452 | unsigned long val = etm.__name; \ |
| 453 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); \ |
| 454 | } |
| 455 | |
| 456 | #define ETM_ATTR(__name) \ |
| 457 | static struct kobj_attribute __name##_attr = \ |
| 458 | __ATTR(__name, S_IRUGO | S_IWUSR, __name##_show, __name##_store) |
| 459 | #define ETM_ATTR_RO(__name) \ |
| 460 | static struct kobj_attribute __name##_attr = \ |
| 461 | __ATTR(__name, S_IRUGO, __name##_show, NULL) |
| 462 | |
| 463 | static ssize_t enabled_store(struct kobject *kobj, |
| 464 | struct kobj_attribute *attr, |
| 465 | const char *buf, size_t n) |
| 466 | { |
| 467 | int ret = 0; |
| 468 | unsigned long val; |
| 469 | |
| 470 | if (sscanf(buf, "%lx", &val) != 1) |
| 471 | return -EINVAL; |
| 472 | |
| 473 | mutex_lock(&etm.mutex); |
| 474 | if (val) |
| 475 | ret = etm_enable(); |
| 476 | else |
| 477 | ret = etm_disable(); |
| 478 | mutex_unlock(&etm.mutex); |
| 479 | |
| 480 | if (ret) |
| 481 | return ret; |
| 482 | return n; |
| 483 | } |
| 484 | ETM_SHOW(enabled); |
| 485 | ETM_ATTR(enabled); |
| 486 | |
| 487 | ETM_SHOW(nr_addr_cmp); |
| 488 | ETM_ATTR_RO(nr_addr_cmp); |
| 489 | ETM_SHOW(nr_cntr); |
| 490 | ETM_ATTR_RO(nr_cntr); |
| 491 | ETM_SHOW(nr_ctxid_cmp); |
| 492 | ETM_ATTR_RO(nr_ctxid_cmp); |
| 493 | |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 494 | /* Reset to trace everything i.e. exclude nothing. */ |
| 495 | static ssize_t reset_store(struct kobject *kobj, |
| 496 | struct kobj_attribute *attr, |
| 497 | const char *buf, size_t n) |
| 498 | { |
| 499 | int i; |
| 500 | unsigned long val; |
| 501 | |
| 502 | if (sscanf(buf, "%lx", &val) != 1) |
| 503 | return -EINVAL; |
| 504 | |
| 505 | mutex_lock(&etm.mutex); |
| 506 | if (val) { |
Pratik Patel | 2d0c7b6 | 2012-02-24 19:04:37 -0800 | [diff] [blame] | 507 | etm.mode = ETM_MODE_EXCLUDE; |
| 508 | etm.ctrl = 0x0; |
| 509 | if (cpu_is_krait_v1()) { |
| 510 | etm.mode |= ETM_MODE_CYCACC; |
| 511 | etm.ctrl |= BIT(12); |
| 512 | } |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 513 | etm.trigger_event = 0x406F; |
| 514 | etm.startstop_ctrl = 0x0; |
| 515 | etm.enable_event = 0x6F; |
| 516 | etm.enable_ctrl1 = 0x1000000; |
| 517 | etm.fifofull_level = 0x28; |
| 518 | etm.addr_idx = 0x0; |
| 519 | for (i = 0; i < etm.nr_addr_cmp; i++) { |
| 520 | etm.addr_val[i] = 0x0; |
| 521 | etm.addr_acctype[i] = 0x0; |
| 522 | etm.addr_type[i] = ETM_ADDR_TYPE_NONE; |
| 523 | } |
| 524 | etm.cntr_idx = 0x0; |
| 525 | for (i = 0; i < etm.nr_cntr; i++) { |
| 526 | etm.cntr_rld_val[i] = 0x0; |
| 527 | etm.cntr_event[i] = 0x406F; |
| 528 | etm.cntr_rld_event[i] = 0x406F; |
| 529 | etm.cntr_val[i] = 0x0; |
| 530 | } |
| 531 | etm.seq_12_event = 0x406F; |
| 532 | etm.seq_21_event = 0x406F; |
| 533 | etm.seq_23_event = 0x406F; |
| 534 | etm.seq_31_event = 0x406F; |
| 535 | etm.seq_32_event = 0x406F; |
| 536 | etm.seq_13_event = 0x406F; |
| 537 | etm.seq_curr_state = 0x0; |
| 538 | etm.ctxid_idx = 0x0; |
| 539 | for (i = 0; i < etm.nr_ctxid_cmp; i++) |
| 540 | etm.ctxid_val[i] = 0x0; |
| 541 | etm.ctxid_mask = 0x0; |
| 542 | etm.sync_freq = 0x80; |
| 543 | etm.timestamp_event = 0x406F; |
| 544 | } |
| 545 | mutex_unlock(&etm.mutex); |
| 546 | return n; |
| 547 | } |
| 548 | ETM_SHOW(reset); |
| 549 | ETM_ATTR(reset); |
| 550 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 551 | static ssize_t mode_store(struct kobject *kobj, |
| 552 | struct kobj_attribute *attr, |
| 553 | const char *buf, size_t n) |
| 554 | { |
| 555 | unsigned long val; |
| 556 | |
| 557 | if (sscanf(buf, "%lx", &val) != 1) |
| 558 | return -EINVAL; |
| 559 | |
| 560 | mutex_lock(&etm.mutex); |
| 561 | etm.mode = val & ETM_MODE_ALL; |
| 562 | |
| 563 | if (etm.mode & ETM_MODE_EXCLUDE) |
| 564 | etm.enable_ctrl1 |= BIT(24); |
| 565 | else |
| 566 | etm.enable_ctrl1 &= ~BIT(24); |
| 567 | |
| 568 | if (etm.mode & ETM_MODE_CYCACC) |
| 569 | etm.ctrl |= BIT(12); |
| 570 | else |
| 571 | etm.ctrl &= ~BIT(12); |
| 572 | |
| 573 | if (etm.mode & ETM_MODE_STALL) |
| 574 | etm.ctrl |= BIT(7); |
| 575 | else |
| 576 | etm.ctrl &= ~BIT(7); |
| 577 | |
| 578 | if (etm.mode & ETM_MODE_TIMESTAMP) |
| 579 | etm.ctrl |= BIT(28); |
| 580 | else |
| 581 | etm.ctrl &= ~BIT(28); |
| 582 | if (etm.mode & ETM_MODE_CTXID) |
| 583 | etm.ctrl |= (BIT(14) | BIT(15)); |
| 584 | else |
| 585 | etm.ctrl &= ~(BIT(14) | BIT(15)); |
| 586 | mutex_unlock(&etm.mutex); |
| 587 | |
| 588 | return n; |
| 589 | } |
| 590 | ETM_SHOW(mode); |
| 591 | ETM_ATTR(mode); |
| 592 | |
| 593 | ETM_STORE(trigger_event, ETM_EVENT_MASK); |
| 594 | ETM_SHOW(trigger_event); |
| 595 | ETM_ATTR(trigger_event); |
| 596 | |
| 597 | ETM_STORE(enable_event, ETM_EVENT_MASK); |
| 598 | ETM_SHOW(enable_event); |
| 599 | ETM_ATTR(enable_event); |
| 600 | |
| 601 | ETM_STORE(fifofull_level, ETM_ALL_MASK); |
| 602 | ETM_SHOW(fifofull_level); |
| 603 | ETM_ATTR(fifofull_level); |
| 604 | |
| 605 | static ssize_t addr_idx_store(struct kobject *kobj, |
| 606 | struct kobj_attribute *attr, |
| 607 | const char *buf, size_t n) |
| 608 | { |
| 609 | unsigned long val; |
| 610 | |
| 611 | if (sscanf(buf, "%lx", &val) != 1) |
| 612 | return -EINVAL; |
| 613 | if (val >= etm.nr_addr_cmp) |
| 614 | return -EINVAL; |
| 615 | |
| 616 | /* Use mutex to ensure index doesn't change while it gets dereferenced |
| 617 | * multiple times within a mutex block elsewhere. |
| 618 | */ |
| 619 | mutex_lock(&etm.mutex); |
| 620 | etm.addr_idx = val; |
| 621 | mutex_unlock(&etm.mutex); |
| 622 | return n; |
| 623 | } |
| 624 | ETM_SHOW(addr_idx); |
| 625 | ETM_ATTR(addr_idx); |
| 626 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 627 | static ssize_t addr_single_store(struct kobject *kobj, |
| 628 | struct kobj_attribute *attr, |
| 629 | const char *buf, size_t n) |
| 630 | { |
| 631 | unsigned long val; |
| 632 | uint8_t idx; |
| 633 | |
| 634 | if (sscanf(buf, "%lx", &val) != 1) |
| 635 | return -EINVAL; |
| 636 | |
| 637 | mutex_lock(&etm.mutex); |
| 638 | idx = etm.addr_idx; |
| 639 | if (!(etm.addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 640 | etm.addr_type[idx] == ETM_ADDR_TYPE_SINGLE)) { |
| 641 | mutex_unlock(&etm.mutex); |
| 642 | return -EPERM; |
| 643 | } |
| 644 | |
| 645 | etm.addr_val[idx] = val; |
| 646 | etm.addr_type[idx] = ETM_ADDR_TYPE_SINGLE; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 647 | mutex_unlock(&etm.mutex); |
| 648 | return n; |
| 649 | } |
| 650 | static ssize_t addr_single_show(struct kobject *kobj, |
| 651 | struct kobj_attribute *attr, |
| 652 | char *buf) |
| 653 | { |
| 654 | unsigned long val; |
| 655 | uint8_t idx; |
| 656 | |
| 657 | mutex_lock(&etm.mutex); |
| 658 | idx = etm.addr_idx; |
| 659 | if (!(etm.addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 660 | etm.addr_type[idx] == ETM_ADDR_TYPE_SINGLE)) { |
| 661 | mutex_unlock(&etm.mutex); |
| 662 | return -EPERM; |
| 663 | } |
| 664 | |
| 665 | val = etm.addr_val[idx]; |
| 666 | mutex_unlock(&etm.mutex); |
| 667 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 668 | } |
| 669 | ETM_ATTR(addr_single); |
| 670 | |
| 671 | static ssize_t addr_range_store(struct kobject *kobj, |
| 672 | struct kobj_attribute *attr, |
| 673 | const char *buf, size_t n) |
| 674 | { |
| 675 | unsigned long val1, val2; |
| 676 | uint8_t idx; |
| 677 | |
| 678 | if (sscanf(buf, "%lx %lx", &val1, &val2) != 2) |
| 679 | return -EINVAL; |
| 680 | /* lower address comparator cannot have a higher address value */ |
| 681 | if (val1 > val2) |
| 682 | return -EINVAL; |
| 683 | |
| 684 | mutex_lock(&etm.mutex); |
| 685 | idx = etm.addr_idx; |
| 686 | if (idx % 2 != 0) { |
| 687 | mutex_unlock(&etm.mutex); |
| 688 | return -EPERM; |
| 689 | } |
| 690 | if (!((etm.addr_type[idx] == ETM_ADDR_TYPE_NONE && |
| 691 | etm.addr_type[idx + 1] == ETM_ADDR_TYPE_NONE) || |
| 692 | (etm.addr_type[idx] == ETM_ADDR_TYPE_RANGE && |
| 693 | etm.addr_type[idx + 1] == ETM_ADDR_TYPE_RANGE))) { |
| 694 | mutex_unlock(&etm.mutex); |
| 695 | return -EPERM; |
| 696 | } |
| 697 | |
| 698 | etm.addr_val[idx] = val1; |
| 699 | etm.addr_type[idx] = ETM_ADDR_TYPE_RANGE; |
| 700 | etm.addr_val[idx + 1] = val2; |
| 701 | etm.addr_type[idx + 1] = ETM_ADDR_TYPE_RANGE; |
| 702 | etm.enable_ctrl1 |= (1 << (idx/2)); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 703 | mutex_unlock(&etm.mutex); |
| 704 | return n; |
| 705 | } |
| 706 | static ssize_t addr_range_show(struct kobject *kobj, |
| 707 | struct kobj_attribute *attr, |
| 708 | char *buf) |
| 709 | { |
| 710 | unsigned long val1, val2; |
| 711 | uint8_t idx; |
| 712 | |
| 713 | mutex_lock(&etm.mutex); |
| 714 | idx = etm.addr_idx; |
| 715 | if (idx % 2 != 0) { |
| 716 | mutex_unlock(&etm.mutex); |
| 717 | return -EPERM; |
| 718 | } |
| 719 | if (!((etm.addr_type[idx] == ETM_ADDR_TYPE_NONE && |
| 720 | etm.addr_type[idx + 1] == ETM_ADDR_TYPE_NONE) || |
| 721 | (etm.addr_type[idx] == ETM_ADDR_TYPE_RANGE && |
| 722 | etm.addr_type[idx + 1] == ETM_ADDR_TYPE_RANGE))) { |
| 723 | mutex_unlock(&etm.mutex); |
| 724 | return -EPERM; |
| 725 | } |
| 726 | |
| 727 | val1 = etm.addr_val[idx]; |
| 728 | val2 = etm.addr_val[idx + 1]; |
| 729 | mutex_unlock(&etm.mutex); |
| 730 | return scnprintf(buf, PAGE_SIZE, "%#lx %#lx\n", val1, val2); |
| 731 | } |
| 732 | ETM_ATTR(addr_range); |
| 733 | |
| 734 | static ssize_t addr_start_store(struct kobject *kobj, |
| 735 | struct kobj_attribute *attr, |
| 736 | const char *buf, size_t n) |
| 737 | { |
| 738 | unsigned long val; |
| 739 | uint8_t idx; |
| 740 | |
| 741 | if (sscanf(buf, "%lx", &val) != 1) |
| 742 | return -EINVAL; |
| 743 | |
| 744 | mutex_lock(&etm.mutex); |
| 745 | idx = etm.addr_idx; |
| 746 | if (!(etm.addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 747 | etm.addr_type[idx] == ETM_ADDR_TYPE_START)) { |
| 748 | mutex_unlock(&etm.mutex); |
| 749 | return -EPERM; |
| 750 | } |
| 751 | |
| 752 | etm.addr_val[idx] = val; |
| 753 | etm.addr_type[idx] = ETM_ADDR_TYPE_START; |
| 754 | etm.startstop_ctrl |= (1 << idx); |
| 755 | etm.enable_ctrl1 |= BIT(25); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 756 | mutex_unlock(&etm.mutex); |
| 757 | return n; |
| 758 | } |
| 759 | static ssize_t addr_start_show(struct kobject *kobj, |
| 760 | struct kobj_attribute *attr, |
| 761 | char *buf) |
| 762 | { |
| 763 | unsigned long val; |
| 764 | uint8_t idx; |
| 765 | |
| 766 | mutex_lock(&etm.mutex); |
| 767 | idx = etm.addr_idx; |
| 768 | if (!(etm.addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 769 | etm.addr_type[idx] == ETM_ADDR_TYPE_START)) { |
| 770 | mutex_unlock(&etm.mutex); |
| 771 | return -EPERM; |
| 772 | } |
| 773 | |
| 774 | val = etm.addr_val[idx]; |
| 775 | mutex_unlock(&etm.mutex); |
| 776 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 777 | } |
| 778 | ETM_ATTR(addr_start); |
| 779 | |
| 780 | static ssize_t addr_stop_store(struct kobject *kobj, |
| 781 | struct kobj_attribute *attr, |
| 782 | const char *buf, size_t n) |
| 783 | { |
| 784 | unsigned long val; |
| 785 | uint8_t idx; |
| 786 | |
| 787 | if (sscanf(buf, "%lx", &val) != 1) |
| 788 | return -EINVAL; |
| 789 | |
| 790 | mutex_lock(&etm.mutex); |
| 791 | idx = etm.addr_idx; |
| 792 | if (!(etm.addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 793 | etm.addr_type[idx] == ETM_ADDR_TYPE_STOP)) { |
| 794 | mutex_unlock(&etm.mutex); |
| 795 | return -EPERM; |
| 796 | } |
| 797 | |
| 798 | etm.addr_val[idx] = val; |
| 799 | etm.addr_type[idx] = ETM_ADDR_TYPE_STOP; |
| 800 | etm.startstop_ctrl |= (1 << (idx + 16)); |
| 801 | etm.enable_ctrl1 |= BIT(25); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 802 | mutex_unlock(&etm.mutex); |
| 803 | return n; |
| 804 | } |
| 805 | static ssize_t addr_stop_show(struct kobject *kobj, |
| 806 | struct kobj_attribute *attr, |
| 807 | char *buf) |
| 808 | { |
| 809 | unsigned long val; |
| 810 | uint8_t idx; |
| 811 | |
| 812 | mutex_lock(&etm.mutex); |
| 813 | idx = etm.addr_idx; |
| 814 | if (!(etm.addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 815 | etm.addr_type[idx] == ETM_ADDR_TYPE_STOP)) { |
| 816 | mutex_unlock(&etm.mutex); |
| 817 | return -EPERM; |
| 818 | } |
| 819 | |
| 820 | val = etm.addr_val[idx]; |
| 821 | mutex_unlock(&etm.mutex); |
| 822 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 823 | } |
| 824 | ETM_ATTR(addr_stop); |
| 825 | |
| 826 | static ssize_t addr_acctype_store(struct kobject *kobj, |
| 827 | struct kobj_attribute *attr, |
| 828 | const char *buf, size_t n) |
| 829 | { |
| 830 | unsigned long val; |
| 831 | |
| 832 | if (sscanf(buf, "%lx", &val) != 1) |
| 833 | return -EINVAL; |
| 834 | |
| 835 | mutex_lock(&etm.mutex); |
| 836 | etm.addr_acctype[etm.addr_idx] = val; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 837 | mutex_unlock(&etm.mutex); |
| 838 | return n; |
| 839 | } |
| 840 | static ssize_t addr_acctype_show(struct kobject *kobj, |
| 841 | struct kobj_attribute *attr, |
| 842 | char *buf) |
| 843 | { |
| 844 | unsigned long val; |
| 845 | |
| 846 | mutex_lock(&etm.mutex); |
| 847 | val = etm.addr_acctype[etm.addr_idx]; |
| 848 | mutex_unlock(&etm.mutex); |
| 849 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 850 | } |
| 851 | ETM_ATTR(addr_acctype); |
| 852 | |
| 853 | static ssize_t cntr_idx_store(struct kobject *kobj, |
| 854 | struct kobj_attribute *attr, |
| 855 | const char *buf, size_t n) |
| 856 | { |
| 857 | unsigned long val; |
| 858 | |
| 859 | if (sscanf(buf, "%lx", &val) != 1) |
| 860 | return -EINVAL; |
| 861 | if (val >= etm.nr_cntr) |
| 862 | return -EINVAL; |
| 863 | |
| 864 | /* Use mutex to ensure index doesn't change while it gets dereferenced |
| 865 | * multiple times within a mutex block elsewhere. |
| 866 | */ |
| 867 | mutex_lock(&etm.mutex); |
| 868 | etm.cntr_idx = val; |
| 869 | mutex_unlock(&etm.mutex); |
| 870 | return n; |
| 871 | } |
| 872 | ETM_SHOW(cntr_idx); |
| 873 | ETM_ATTR(cntr_idx); |
| 874 | |
| 875 | static ssize_t cntr_rld_val_store(struct kobject *kobj, |
| 876 | struct kobj_attribute *attr, |
| 877 | const char *buf, size_t n) |
| 878 | { |
| 879 | unsigned long val; |
| 880 | |
| 881 | if (sscanf(buf, "%lx", &val) != 1) |
| 882 | return -EINVAL; |
| 883 | |
| 884 | mutex_lock(&etm.mutex); |
| 885 | etm.cntr_rld_val[etm.cntr_idx] = val; |
| 886 | mutex_unlock(&etm.mutex); |
| 887 | return n; |
| 888 | } |
| 889 | static ssize_t cntr_rld_val_show(struct kobject *kobj, |
| 890 | struct kobj_attribute *attr, |
| 891 | char *buf) |
| 892 | { |
| 893 | unsigned long val; |
| 894 | mutex_lock(&etm.mutex); |
| 895 | val = etm.cntr_rld_val[etm.cntr_idx]; |
| 896 | mutex_unlock(&etm.mutex); |
| 897 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 898 | } |
| 899 | ETM_ATTR(cntr_rld_val); |
| 900 | |
| 901 | static ssize_t cntr_event_store(struct kobject *kobj, |
| 902 | struct kobj_attribute *attr, |
| 903 | const char *buf, size_t n) |
| 904 | { |
| 905 | unsigned long val; |
| 906 | |
| 907 | if (sscanf(buf, "%lx", &val) != 1) |
| 908 | return -EINVAL; |
| 909 | |
| 910 | mutex_lock(&etm.mutex); |
| 911 | etm.cntr_event[etm.cntr_idx] = val & ETM_EVENT_MASK; |
| 912 | mutex_unlock(&etm.mutex); |
| 913 | return n; |
| 914 | } |
| 915 | static ssize_t cntr_event_show(struct kobject *kobj, |
| 916 | struct kobj_attribute *attr, |
| 917 | char *buf) |
| 918 | { |
| 919 | unsigned long val; |
| 920 | |
| 921 | mutex_lock(&etm.mutex); |
| 922 | val = etm.cntr_event[etm.cntr_idx]; |
| 923 | mutex_unlock(&etm.mutex); |
| 924 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 925 | } |
| 926 | ETM_ATTR(cntr_event); |
| 927 | |
| 928 | static ssize_t cntr_rld_event_store(struct kobject *kobj, |
| 929 | struct kobj_attribute *attr, |
| 930 | const char *buf, size_t n) |
| 931 | { |
| 932 | unsigned long val; |
| 933 | |
| 934 | if (sscanf(buf, "%lx", &val) != 1) |
| 935 | return -EINVAL; |
| 936 | |
| 937 | mutex_lock(&etm.mutex); |
| 938 | etm.cntr_rld_event[etm.cntr_idx] = val & ETM_EVENT_MASK; |
| 939 | mutex_unlock(&etm.mutex); |
| 940 | return n; |
| 941 | } |
| 942 | static ssize_t cntr_rld_event_show(struct kobject *kobj, |
| 943 | struct kobj_attribute *attr, |
| 944 | char *buf) |
| 945 | { |
| 946 | unsigned long val; |
| 947 | |
| 948 | mutex_lock(&etm.mutex); |
| 949 | val = etm.cntr_rld_event[etm.cntr_idx]; |
| 950 | mutex_unlock(&etm.mutex); |
| 951 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 952 | } |
| 953 | ETM_ATTR(cntr_rld_event); |
| 954 | |
| 955 | static ssize_t cntr_val_store(struct kobject *kobj, |
| 956 | struct kobj_attribute *attr, |
| 957 | const char *buf, size_t n) |
| 958 | { |
| 959 | unsigned long val; |
| 960 | |
| 961 | if (sscanf(buf, "%lx", &val) != 1) |
| 962 | return -EINVAL; |
| 963 | |
| 964 | mutex_lock(&etm.mutex); |
| 965 | etm.cntr_val[etm.cntr_idx] = val; |
| 966 | mutex_unlock(&etm.mutex); |
| 967 | return n; |
| 968 | } |
| 969 | static ssize_t cntr_val_show(struct kobject *kobj, |
| 970 | struct kobj_attribute *attr, |
| 971 | char *buf) |
| 972 | { |
| 973 | unsigned long val; |
| 974 | |
| 975 | mutex_lock(&etm.mutex); |
| 976 | val = etm.cntr_val[etm.cntr_idx]; |
| 977 | mutex_unlock(&etm.mutex); |
| 978 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 979 | } |
| 980 | ETM_ATTR(cntr_val); |
| 981 | |
| 982 | ETM_STORE(seq_12_event, ETM_EVENT_MASK); |
| 983 | ETM_SHOW(seq_12_event); |
| 984 | ETM_ATTR(seq_12_event); |
| 985 | |
| 986 | ETM_STORE(seq_21_event, ETM_EVENT_MASK); |
| 987 | ETM_SHOW(seq_21_event); |
| 988 | ETM_ATTR(seq_21_event); |
| 989 | |
| 990 | ETM_STORE(seq_23_event, ETM_EVENT_MASK); |
| 991 | ETM_SHOW(seq_23_event); |
| 992 | ETM_ATTR(seq_23_event); |
| 993 | |
| 994 | ETM_STORE(seq_31_event, ETM_EVENT_MASK); |
| 995 | ETM_SHOW(seq_31_event); |
| 996 | ETM_ATTR(seq_31_event); |
| 997 | |
| 998 | ETM_STORE(seq_32_event, ETM_EVENT_MASK); |
| 999 | ETM_SHOW(seq_32_event); |
| 1000 | ETM_ATTR(seq_32_event); |
| 1001 | |
| 1002 | ETM_STORE(seq_13_event, ETM_EVENT_MASK); |
| 1003 | ETM_SHOW(seq_13_event); |
| 1004 | ETM_ATTR(seq_13_event); |
| 1005 | |
| 1006 | static ssize_t seq_curr_state_store(struct kobject *kobj, |
| 1007 | struct kobj_attribute *attr, |
| 1008 | const char *buf, size_t n) |
| 1009 | { |
| 1010 | unsigned long val; |
| 1011 | |
| 1012 | if (sscanf(buf, "%lx", &val) != 1) |
| 1013 | return -EINVAL; |
| 1014 | if (val > ETM_SEQ_STATE_MAX_VAL) |
| 1015 | return -EINVAL; |
| 1016 | |
| 1017 | etm.seq_curr_state = val; |
| 1018 | return n; |
| 1019 | } |
| 1020 | ETM_SHOW(seq_curr_state); |
| 1021 | ETM_ATTR(seq_curr_state); |
| 1022 | |
| 1023 | static ssize_t ctxid_idx_store(struct kobject *kobj, |
| 1024 | struct kobj_attribute *attr, |
| 1025 | const char *buf, size_t n) |
| 1026 | { |
| 1027 | unsigned long val; |
| 1028 | |
| 1029 | if (sscanf(buf, "%lx", &val) != 1) |
| 1030 | return -EINVAL; |
| 1031 | if (val >= etm.nr_ctxid_cmp) |
| 1032 | return -EINVAL; |
| 1033 | |
| 1034 | /* Use mutex to ensure index doesn't change while it gets dereferenced |
| 1035 | * multiple times within a mutex block elsewhere. |
| 1036 | */ |
| 1037 | mutex_lock(&etm.mutex); |
| 1038 | etm.ctxid_idx = val; |
| 1039 | mutex_unlock(&etm.mutex); |
| 1040 | return n; |
| 1041 | } |
| 1042 | ETM_SHOW(ctxid_idx); |
| 1043 | ETM_ATTR(ctxid_idx); |
| 1044 | |
| 1045 | static ssize_t ctxid_val_store(struct kobject *kobj, |
| 1046 | struct kobj_attribute *attr, |
| 1047 | const char *buf, size_t n) |
| 1048 | { |
| 1049 | unsigned long val; |
| 1050 | |
| 1051 | if (sscanf(buf, "%lx", &val) != 1) |
| 1052 | return -EINVAL; |
| 1053 | |
| 1054 | mutex_lock(&etm.mutex); |
| 1055 | etm.ctxid_val[etm.ctxid_idx] = val; |
| 1056 | mutex_unlock(&etm.mutex); |
| 1057 | return n; |
| 1058 | } |
| 1059 | static ssize_t ctxid_val_show(struct kobject *kobj, |
| 1060 | struct kobj_attribute *attr, |
| 1061 | char *buf) |
| 1062 | { |
| 1063 | unsigned long val; |
| 1064 | |
| 1065 | mutex_lock(&etm.mutex); |
| 1066 | val = etm.ctxid_val[etm.ctxid_idx]; |
| 1067 | mutex_unlock(&etm.mutex); |
| 1068 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1069 | } |
| 1070 | ETM_ATTR(ctxid_val); |
| 1071 | |
| 1072 | ETM_STORE(ctxid_mask, ETM_ALL_MASK); |
| 1073 | ETM_SHOW(ctxid_mask); |
| 1074 | ETM_ATTR(ctxid_mask); |
| 1075 | |
| 1076 | ETM_STORE(sync_freq, ETM_SYNC_MASK); |
| 1077 | ETM_SHOW(sync_freq); |
| 1078 | ETM_ATTR(sync_freq); |
| 1079 | |
| 1080 | ETM_STORE(timestamp_event, ETM_EVENT_MASK); |
| 1081 | ETM_SHOW(timestamp_event); |
| 1082 | ETM_ATTR(timestamp_event); |
| 1083 | |
| 1084 | static struct attribute *etm_attrs[] = { |
| 1085 | &nr_addr_cmp_attr.attr, |
| 1086 | &nr_cntr_attr.attr, |
| 1087 | &nr_ctxid_cmp_attr.attr, |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 1088 | &reset_attr.attr, |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1089 | &mode_attr.attr, |
| 1090 | &trigger_event_attr.attr, |
| 1091 | &enable_event_attr.attr, |
| 1092 | &fifofull_level_attr.attr, |
| 1093 | &addr_idx_attr.attr, |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1094 | &addr_single_attr.attr, |
| 1095 | &addr_range_attr.attr, |
| 1096 | &addr_start_attr.attr, |
| 1097 | &addr_stop_attr.attr, |
| 1098 | &addr_acctype_attr.attr, |
| 1099 | &cntr_idx_attr.attr, |
| 1100 | &cntr_rld_val_attr.attr, |
| 1101 | &cntr_event_attr.attr, |
| 1102 | &cntr_rld_event_attr.attr, |
| 1103 | &cntr_val_attr.attr, |
| 1104 | &seq_12_event_attr.attr, |
| 1105 | &seq_21_event_attr.attr, |
| 1106 | &seq_23_event_attr.attr, |
| 1107 | &seq_31_event_attr.attr, |
| 1108 | &seq_32_event_attr.attr, |
| 1109 | &seq_13_event_attr.attr, |
| 1110 | &seq_curr_state_attr.attr, |
| 1111 | &ctxid_idx_attr.attr, |
| 1112 | &ctxid_val_attr.attr, |
| 1113 | &ctxid_mask_attr.attr, |
| 1114 | &sync_freq_attr.attr, |
| 1115 | ×tamp_event_attr.attr, |
| 1116 | NULL, |
| 1117 | }; |
| 1118 | |
| 1119 | static struct attribute_group etm_attr_grp = { |
| 1120 | .attrs = etm_attrs, |
| 1121 | }; |
| 1122 | |
Stephen Boyd | a951050 | 2012-04-24 16:23:34 -0700 | [diff] [blame] | 1123 | static int __devinit etm_sysfs_init(void) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1124 | { |
| 1125 | int ret; |
| 1126 | |
| 1127 | etm.kobj = kobject_create_and_add("etm", qdss_get_modulekobj()); |
| 1128 | if (!etm.kobj) { |
| 1129 | dev_err(etm.dev, "failed to create ETM sysfs kobject\n"); |
| 1130 | ret = -ENOMEM; |
| 1131 | goto err_create; |
| 1132 | } |
| 1133 | |
| 1134 | ret = sysfs_create_file(etm.kobj, &enabled_attr.attr); |
| 1135 | if (ret) { |
| 1136 | dev_err(etm.dev, "failed to create ETM sysfs enabled" |
| 1137 | " attribute\n"); |
| 1138 | goto err_file; |
| 1139 | } |
| 1140 | |
| 1141 | if (sysfs_create_group(etm.kobj, &etm_attr_grp)) |
| 1142 | dev_err(etm.dev, "failed to create ETM sysfs group\n"); |
| 1143 | |
| 1144 | return 0; |
| 1145 | err_file: |
| 1146 | kobject_put(etm.kobj); |
| 1147 | err_create: |
| 1148 | return ret; |
| 1149 | } |
| 1150 | |
Stephen Boyd | a951050 | 2012-04-24 16:23:34 -0700 | [diff] [blame] | 1151 | static void __devexit etm_sysfs_exit(void) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1152 | { |
| 1153 | sysfs_remove_group(etm.kobj, &etm_attr_grp); |
| 1154 | sysfs_remove_file(etm.kobj, &enabled_attr.attr); |
| 1155 | kobject_put(etm.kobj); |
| 1156 | } |
| 1157 | |
Stephen Boyd | a951050 | 2012-04-24 16:23:34 -0700 | [diff] [blame] | 1158 | static bool __devinit etm_arch_supported(uint8_t arch) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1159 | { |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1160 | switch (arch) { |
| 1161 | case PFT_ARCH_V1_1: |
| 1162 | break; |
| 1163 | default: |
| 1164 | return false; |
| 1165 | } |
| 1166 | return true; |
| 1167 | } |
| 1168 | |
Stephen Boyd | a951050 | 2012-04-24 16:23:34 -0700 | [diff] [blame] | 1169 | static int __devinit etm_arch_init(void) |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1170 | { |
Pratik Patel | 2d0c7b6 | 2012-02-24 19:04:37 -0800 | [diff] [blame] | 1171 | int ret, i; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1172 | /* use cpu 0 for setup */ |
| 1173 | int cpu = 0; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1174 | uint32_t etmidr; |
| 1175 | uint32_t etmccr; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1176 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 1177 | /* Unlock OS lock first to allow memory mapped reads and writes */ |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1178 | etm_os_unlock(NULL); |
| 1179 | smp_call_function(etm_os_unlock, NULL, 1); |
| 1180 | ETM_UNLOCK(cpu); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 1181 | /* Vote for ETM power/clock enable */ |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1182 | etm_clr_pwrdwn(cpu); |
| 1183 | /* Set prog bit. It will be set from reset but this is included to |
| 1184 | * ensure it is set |
| 1185 | */ |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1186 | etm_set_prog(cpu); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1187 | |
| 1188 | /* find all capabilities */ |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1189 | etmidr = etm_readl(etm, cpu, ETMIDR); |
| 1190 | etm.arch = BMVAL(etmidr, 4, 11); |
| 1191 | if (etm_arch_supported(etm.arch) == false) { |
| 1192 | ret = -EINVAL; |
| 1193 | goto err; |
| 1194 | } |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1195 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1196 | etmccr = etm_readl(etm, cpu, ETMCCR); |
| 1197 | etm.nr_addr_cmp = BMVAL(etmccr, 0, 3) * 2; |
| 1198 | etm.nr_cntr = BMVAL(etmccr, 13, 15); |
| 1199 | etm.nr_ext_inp = BMVAL(etmccr, 17, 19); |
| 1200 | etm.nr_ext_out = BMVAL(etmccr, 20, 22); |
| 1201 | etm.nr_ctxid_cmp = BMVAL(etmccr, 24, 25); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1202 | |
Pratik Patel | 2d0c7b6 | 2012-02-24 19:04:37 -0800 | [diff] [blame] | 1203 | if (cpu_is_krait_v1()) { |
| 1204 | /* Krait pass1 doesn't support include filtering and non-cycle |
| 1205 | * accurate tracing |
| 1206 | */ |
| 1207 | etm.mode = (ETM_MODE_EXCLUDE | ETM_MODE_CYCACC); |
| 1208 | etm.ctrl = 0x1000; |
| 1209 | etm.enable_ctrl1 = 0x1000000; |
| 1210 | for (i = 0; i < etm.nr_addr_cmp; i++) { |
| 1211 | etm.addr_val[i] = 0x0; |
| 1212 | etm.addr_acctype[i] = 0x0; |
| 1213 | etm.addr_type[i] = ETM_ADDR_TYPE_NONE; |
| 1214 | } |
| 1215 | } |
| 1216 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 1217 | /* Vote for ETM power/clock disable */ |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1218 | etm_set_pwrdwn(cpu); |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1219 | ETM_LOCK(cpu); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1220 | |
| 1221 | return 0; |
| 1222 | err: |
| 1223 | return ret; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1226 | static int __devinit etm_probe(struct platform_device *pdev) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1227 | { |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 1228 | int ret; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1229 | struct resource *res; |
| 1230 | |
| 1231 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1232 | if (!res) { |
| 1233 | ret = -EINVAL; |
| 1234 | goto err_res; |
| 1235 | } |
| 1236 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1237 | etm.base = ioremap_nocache(res->start, resource_size(res)); |
| 1238 | if (!etm.base) { |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1239 | ret = -EINVAL; |
| 1240 | goto err_ioremap; |
| 1241 | } |
| 1242 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1243 | etm.dev = &pdev->dev; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1244 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1245 | mutex_init(&etm.mutex); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1246 | wake_lock_init(&etm.wake_lock, WAKE_LOCK_SUSPEND, "msm_etm"); |
| 1247 | pm_qos_add_request(&etm.qos_req, PM_QOS_CPU_DMA_LATENCY, |
| 1248 | PM_QOS_DEFAULT_VALUE); |
Pratik Patel | e10a77c | 2012-03-20 10:35:16 -0700 | [diff] [blame] | 1249 | etm.src = qdss_get("msm_etm"); |
| 1250 | if (IS_ERR(etm.src)) { |
| 1251 | ret = PTR_ERR(etm.src); |
| 1252 | goto err_qdssget; |
| 1253 | } |
| 1254 | |
Pratik Patel | cc320a4 | 2011-12-22 10:48:14 -0800 | [diff] [blame] | 1255 | ret = qdss_clk_enable(); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1256 | if (ret) |
Pratik Patel | cc320a4 | 2011-12-22 10:48:14 -0800 | [diff] [blame] | 1257 | goto err_clk; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1258 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1259 | ret = etm_arch_init(); |
| 1260 | if (ret) |
| 1261 | goto err_arch; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1262 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1263 | ret = etm_sysfs_init(); |
| 1264 | if (ret) |
| 1265 | goto err_sysfs; |
| 1266 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1267 | etm.enabled = false; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1268 | |
Pratik Patel | cc320a4 | 2011-12-22 10:48:14 -0800 | [diff] [blame] | 1269 | qdss_clk_disable(); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1270 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1271 | dev_info(etm.dev, "ETM initialized\n"); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1272 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1273 | if (etm_boot_enable) |
| 1274 | etm_enable(); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1275 | |
| 1276 | return 0; |
| 1277 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1278 | err_sysfs: |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1279 | err_arch: |
| 1280 | qdss_clk_disable(); |
Pratik Patel | cc320a4 | 2011-12-22 10:48:14 -0800 | [diff] [blame] | 1281 | err_clk: |
Pratik Patel | e10a77c | 2012-03-20 10:35:16 -0700 | [diff] [blame] | 1282 | qdss_put(etm.src); |
| 1283 | err_qdssget: |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1284 | pm_qos_remove_request(&etm.qos_req); |
| 1285 | wake_lock_destroy(&etm.wake_lock); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1286 | mutex_destroy(&etm.mutex); |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1287 | iounmap(etm.base); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1288 | err_ioremap: |
| 1289 | err_res: |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1290 | dev_err(etm.dev, "ETM init failed\n"); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1291 | return ret; |
| 1292 | } |
| 1293 | |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1294 | static int __devexit etm_remove(struct platform_device *pdev) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1295 | { |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1296 | if (etm.enabled) |
| 1297 | etm_disable(); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1298 | etm_sysfs_exit(); |
Pratik Patel | e10a77c | 2012-03-20 10:35:16 -0700 | [diff] [blame] | 1299 | qdss_put(etm.src); |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1300 | pm_qos_remove_request(&etm.qos_req); |
| 1301 | wake_lock_destroy(&etm.wake_lock); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1302 | mutex_destroy(&etm.mutex); |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1303 | iounmap(etm.base); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1304 | |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1308 | static struct platform_driver etm_driver = { |
| 1309 | .probe = etm_probe, |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1310 | .remove = __devexit_p(etm_remove), |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1311 | .driver = { |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1312 | .name = "msm_etm", |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1313 | }, |
| 1314 | }; |
| 1315 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1316 | int __init etm_init(void) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1317 | { |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1318 | return platform_driver_register(&etm_driver); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1319 | } |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1320 | module_init(etm_init); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1321 | |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1322 | void __exit etm_exit(void) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1323 | { |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1324 | platform_driver_unregister(&etm_driver); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1325 | } |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1326 | module_exit(etm_exit); |
| 1327 | |
| 1328 | MODULE_LICENSE("GPL v2"); |
| 1329 | MODULE_DESCRIPTION("CoreSight Program Flow Trace driver"); |