Pratik Patel | ef6da29 | 2012-09-17 17:37:19 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, The Linux Foundation. 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> |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 26 | #include <linux/sysfs.h> |
| 27 | #include <linux/stat.h> |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 28 | #include <linux/mutex.h> |
Pratik Patel | f17b147 | 2012-05-25 22:23:52 -0700 | [diff] [blame] | 29 | #include <linux/clk.h> |
Pratik Patel | 5f6d1af | 2012-06-13 15:48:13 -0700 | [diff] [blame] | 30 | #include <linux/of_coresight.h> |
Pratik Patel | 1746b8f | 2012-06-02 21:11:41 -0700 | [diff] [blame] | 31 | #include <linux/coresight.h> |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 32 | #include <asm/sections.h> |
Pratik Patel | 2d0c7b6 | 2012-02-24 19:04:37 -0800 | [diff] [blame] | 33 | #include <mach/socinfo.h> |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 34 | #include <mach/msm_memory_dump.h> |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 35 | |
Pratik Patel | 1746b8f | 2012-06-02 21:11:41 -0700 | [diff] [blame] | 36 | #include "coresight-priv.h" |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 37 | |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 38 | #define etm_writel_mm(drvdata, val, off) \ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 39 | __raw_writel((val), drvdata->base + off) |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 40 | #define etm_readl_mm(drvdata, off) \ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 41 | __raw_readl(drvdata->base + off) |
| 42 | |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 43 | #define etm_writel(drvdata, val, off) \ |
| 44 | ({ \ |
| 45 | if (cpu_is_krait_v3()) \ |
| 46 | etm_writel_cp14(val, off); \ |
| 47 | else \ |
| 48 | etm_writel_mm(drvdata, val, off); \ |
| 49 | }) |
| 50 | #define etm_readl(drvdata, off) \ |
| 51 | ({ \ |
| 52 | uint32_t val; \ |
| 53 | if (cpu_is_krait_v3()) \ |
| 54 | val = etm_readl_cp14(off); \ |
| 55 | else \ |
| 56 | val = etm_readl_mm(drvdata, off); \ |
| 57 | val; \ |
| 58 | }) |
| 59 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 60 | #define ETM_LOCK(drvdata) \ |
| 61 | do { \ |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 62 | /* recommended by spec to ensure ETM writes are committed prior |
| 63 | * to resuming execution |
| 64 | */ \ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 65 | mb(); \ |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 66 | isb(); \ |
| 67 | etm_writel_mm(drvdata, 0x0, CORESIGHT_LAR); \ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 68 | } while (0) |
| 69 | #define ETM_UNLOCK(drvdata) \ |
| 70 | do { \ |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 71 | etm_writel_mm(drvdata, CORESIGHT_UNLOCK, CORESIGHT_LAR); \ |
| 72 | /* ensure unlock and any pending writes are committed prior to |
| 73 | * programming ETM registers |
| 74 | */ \ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 75 | mb(); \ |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 76 | isb(); \ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 77 | } while (0) |
| 78 | |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 79 | /* |
| 80 | * Device registers: |
| 81 | * 0x000 - 0x2FC: Trace registers |
| 82 | * 0x300 - 0x314: Management registers |
| 83 | * 0x318 - 0xEFC: Trace registers |
| 84 | * |
| 85 | * Coresight registers |
| 86 | * 0xF00 - 0xF9C: Management registers |
| 87 | * 0xFA0 - 0xFA4: Management registers in PFTv1.0 |
| 88 | * Trace registers in PFTv1.1 |
| 89 | * 0xFA8 - 0xFFC: Management registers |
| 90 | */ |
| 91 | |
| 92 | /* Trace registers (0x000-0x2FC) */ |
| 93 | #define ETMCR (0x000) |
| 94 | #define ETMCCR (0x004) |
| 95 | #define ETMTRIGGER (0x008) |
| 96 | #define ETMSR (0x010) |
| 97 | #define ETMSCR (0x014) |
| 98 | #define ETMTSSCR (0x018) |
| 99 | #define ETMTEEVR (0x020) |
| 100 | #define ETMTECR1 (0x024) |
| 101 | #define ETMFFLR (0x02C) |
| 102 | #define ETMACVRn(n) (0x040 + (n * 4)) |
| 103 | #define ETMACTRn(n) (0x080 + (n * 4)) |
| 104 | #define ETMCNTRLDVRn(n) (0x140 + (n * 4)) |
| 105 | #define ETMCNTENRn(n) (0x150 + (n * 4)) |
| 106 | #define ETMCNTRLDEVRn(n) (0x160 + (n * 4)) |
| 107 | #define ETMCNTVRn(n) (0x170 + (n * 4)) |
| 108 | #define ETMSQ12EVR (0x180) |
| 109 | #define ETMSQ21EVR (0x184) |
| 110 | #define ETMSQ23EVR (0x188) |
Pratik Patel | d5bbc76 | 2012-01-29 14:13:21 -0800 | [diff] [blame] | 111 | #define ETMSQ31EVR (0x18C) |
| 112 | #define ETMSQ32EVR (0x190) |
| 113 | #define ETMSQ13EVR (0x194) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 114 | #define ETMSQR (0x19C) |
| 115 | #define ETMEXTOUTEVRn(n) (0x1A0 + (n * 4)) |
| 116 | #define ETMCIDCVRn(n) (0x1B0 + (n * 4)) |
| 117 | #define ETMCIDCMR (0x1BC) |
| 118 | #define ETMIMPSPEC0 (0x1C0) |
| 119 | #define ETMIMPSPEC1 (0x1C4) |
| 120 | #define ETMIMPSPEC2 (0x1C8) |
| 121 | #define ETMIMPSPEC3 (0x1CC) |
| 122 | #define ETMIMPSPEC4 (0x1D0) |
| 123 | #define ETMIMPSPEC5 (0x1D4) |
| 124 | #define ETMIMPSPEC6 (0x1D8) |
| 125 | #define ETMIMPSPEC7 (0x1DC) |
| 126 | #define ETMSYNCFR (0x1E0) |
| 127 | #define ETMIDR (0x1E4) |
| 128 | #define ETMCCER (0x1E8) |
| 129 | #define ETMEXTINSELR (0x1EC) |
| 130 | #define ETMTESSEICR (0x1F0) |
| 131 | #define ETMEIBCR (0x1F4) |
| 132 | #define ETMTSEVR (0x1F8) |
| 133 | #define ETMAUXCR (0x1FC) |
| 134 | #define ETMTRACEIDR (0x200) |
Pratik Patel | d5bbc76 | 2012-01-29 14:13:21 -0800 | [diff] [blame] | 135 | #define ETMVMIDCVR (0x240) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 136 | /* Management registers (0x300-0x314) */ |
| 137 | #define ETMOSLAR (0x300) |
| 138 | #define ETMOSLSR (0x304) |
| 139 | #define ETMOSSRR (0x308) |
| 140 | #define ETMPDCR (0x310) |
| 141 | #define ETMPDSR (0x314) |
| 142 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 143 | #define ETM_MAX_ADDR_CMP (16) |
| 144 | #define ETM_MAX_CNTR (4) |
| 145 | #define ETM_MAX_CTXID_CMP (3) |
| 146 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 147 | #define ETM_MODE_EXCLUDE BIT(0) |
| 148 | #define ETM_MODE_CYCACC BIT(1) |
| 149 | #define ETM_MODE_STALL BIT(2) |
| 150 | #define ETM_MODE_TIMESTAMP BIT(3) |
| 151 | #define ETM_MODE_CTXID BIT(4) |
| 152 | #define ETM_MODE_ALL (0x1F) |
| 153 | |
| 154 | #define ETM_EVENT_MASK (0x1FFFF) |
| 155 | #define ETM_SYNC_MASK (0xFFF) |
| 156 | #define ETM_ALL_MASK (0xFFFFFFFF) |
| 157 | |
| 158 | #define ETM_SEQ_STATE_MAX_VAL (0x2) |
| 159 | |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 160 | #define ETM_REG_DUMP_VER_OFF (4) |
| 161 | #define ETM_REG_DUMP_VER (1) |
| 162 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 163 | enum etm_addr_type { |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 164 | ETM_ADDR_TYPE_NONE, |
| 165 | ETM_ADDR_TYPE_SINGLE, |
| 166 | ETM_ADDR_TYPE_RANGE, |
| 167 | ETM_ADDR_TYPE_START, |
| 168 | ETM_ADDR_TYPE_STOP, |
| 169 | }; |
| 170 | |
Pratik Patel | 29cba15 | 2012-01-03 11:40:26 -0800 | [diff] [blame] | 171 | #ifdef CONFIG_MSM_QDSS_ETM_DEFAULT_ENABLE |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 172 | static int boot_enable = 1; |
Pratik Patel | 29cba15 | 2012-01-03 11:40:26 -0800 | [diff] [blame] | 173 | #else |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 174 | static int boot_enable; |
Pratik Patel | 29cba15 | 2012-01-03 11:40:26 -0800 | [diff] [blame] | 175 | #endif |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 176 | module_param_named( |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 177 | boot_enable, boot_enable, int, S_IRUGO |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 178 | ); |
| 179 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 180 | struct etm_drvdata { |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 181 | void __iomem *base; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 182 | struct device *dev; |
| 183 | struct coresight_device *csdev; |
| 184 | struct clk *clk; |
| 185 | struct mutex mutex; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 186 | struct wake_lock wake_lock; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 187 | int cpu; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 188 | uint8_t arch; |
| 189 | uint8_t nr_addr_cmp; |
| 190 | uint8_t nr_cntr; |
| 191 | uint8_t nr_ext_inp; |
| 192 | uint8_t nr_ext_out; |
| 193 | uint8_t nr_ctxid_cmp; |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 194 | uint8_t reset; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 195 | uint32_t mode; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 196 | uint32_t ctrl; |
| 197 | uint32_t trigger_event; |
| 198 | uint32_t startstop_ctrl; |
| 199 | uint32_t enable_event; |
| 200 | uint32_t enable_ctrl1; |
| 201 | uint32_t fifofull_level; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 202 | uint8_t addr_idx; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 203 | uint32_t addr_val[ETM_MAX_ADDR_CMP]; |
| 204 | uint32_t addr_acctype[ETM_MAX_ADDR_CMP]; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 205 | uint32_t addr_type[ETM_MAX_ADDR_CMP]; |
| 206 | uint8_t cntr_idx; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 207 | uint32_t cntr_rld_val[ETM_MAX_CNTR]; |
| 208 | uint32_t cntr_event[ETM_MAX_CNTR]; |
| 209 | uint32_t cntr_rld_event[ETM_MAX_CNTR]; |
| 210 | uint32_t cntr_val[ETM_MAX_CNTR]; |
| 211 | uint32_t seq_12_event; |
| 212 | uint32_t seq_21_event; |
| 213 | uint32_t seq_23_event; |
| 214 | uint32_t seq_31_event; |
| 215 | uint32_t seq_32_event; |
| 216 | uint32_t seq_13_event; |
| 217 | uint32_t seq_curr_state; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 218 | uint8_t ctxid_idx; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 219 | uint32_t ctxid_val[ETM_MAX_CTXID_CMP]; |
| 220 | uint32_t ctxid_mask; |
| 221 | uint32_t sync_freq; |
| 222 | uint32_t timestamp_event; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 223 | }; |
| 224 | |
Pratik Patel | c14b4df | 2012-09-05 18:07:59 -0700 | [diff] [blame] | 225 | static struct etm_drvdata *etm0drvdata; |
| 226 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 227 | /* ETM clock is derived from the processor clock and gets enabled on a |
| 228 | * logical OR of below items on Krait (pass2 onwards): |
| 229 | * 1.CPMR[ETMCLKEN] is 1 |
| 230 | * 2.ETMCR[PD] is 0 |
| 231 | * 3.ETMPDCR[PU] is 1 |
| 232 | * 4.Reset is asserted (core or debug) |
| 233 | * 5.APB memory mapped requests (eg. EDAP access) |
| 234 | * |
| 235 | * 1., 2. and 3. above are permanent enables whereas 4. and 5. are temporary |
| 236 | * enables |
| 237 | * |
| 238 | * We rely on 5. to be able to access ETMCR and then use 2. above for ETM |
| 239 | * clock vote in the driver and the save-restore code uses 1. above |
| 240 | * for its vote |
| 241 | */ |
Pratik Patel | ef6da29 | 2012-09-17 17:37:19 -0700 | [diff] [blame] | 242 | static void etm_set_pwrup(struct etm_drvdata *drvdata) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 243 | { |
Pratik Patel | ef6da29 | 2012-09-17 17:37:19 -0700 | [diff] [blame] | 244 | uint32_t etmpdcr; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 245 | |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 246 | etmpdcr = etm_readl_mm(drvdata, ETMPDCR); |
Pratik Patel | ef6da29 | 2012-09-17 17:37:19 -0700 | [diff] [blame] | 247 | etmpdcr |= BIT(3); |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 248 | etm_writel_mm(drvdata, etmpdcr, ETMPDCR); |
| 249 | /* ensure pwrup completes before subsequent cp14 accesses */ |
| 250 | mb(); |
| 251 | isb(); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Pratik Patel | ef6da29 | 2012-09-17 17:37:19 -0700 | [diff] [blame] | 254 | static void etm_clr_pwrup(struct etm_drvdata *drvdata) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 255 | { |
Pratik Patel | ef6da29 | 2012-09-17 17:37:19 -0700 | [diff] [blame] | 256 | uint32_t etmpdcr; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 257 | |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 258 | /* ensure pending cp14 accesses complete before clearing pwrup */ |
| 259 | mb(); |
| 260 | isb(); |
| 261 | etmpdcr = etm_readl_mm(drvdata, ETMPDCR); |
Pratik Patel | ef6da29 | 2012-09-17 17:37:19 -0700 | [diff] [blame] | 262 | etmpdcr &= ~BIT(3); |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 263 | etm_writel_mm(drvdata, etmpdcr, ETMPDCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 266 | static void etm_set_prog(struct etm_drvdata *drvdata) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 267 | { |
| 268 | uint32_t etmcr; |
| 269 | int count; |
| 270 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 271 | etmcr = etm_readl(drvdata, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 272 | etmcr |= BIT(10); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 273 | etm_writel(drvdata, etmcr, ETMCR); |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 274 | /* recommended by spec for cp14 accesses to ensure etmcr write is |
| 275 | * complete before polling etmsr |
| 276 | */ |
| 277 | isb(); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 278 | for (count = TIMEOUT_US; BVAL(etm_readl(drvdata, ETMSR), 1) != 1 |
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 setting prog bit, ETMSR: %#x\n", |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 282 | etm_readl(drvdata, ETMSR)); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 285 | static void etm_clr_prog(struct etm_drvdata *drvdata) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 286 | { |
| 287 | uint32_t etmcr; |
| 288 | int count; |
| 289 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 290 | etmcr = etm_readl(drvdata, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 291 | etmcr &= ~BIT(10); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 292 | etm_writel(drvdata, etmcr, ETMCR); |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 293 | /* recommended by spec for cp14 accesses to ensure etmcr write is |
| 294 | * complete before polling etmsr |
| 295 | */ |
| 296 | isb(); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 297 | for (count = TIMEOUT_US; BVAL(etm_readl(drvdata, ETMSR), 1) != 0 |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 298 | && count > 0; count--) |
| 299 | udelay(1); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 300 | WARN(count == 0, "timeout while clearing prog bit, ETMSR: %#x\n", |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 301 | etm_readl(drvdata, ETMSR)); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Pratik Patel | 66e1a41 | 2012-09-06 11:07:06 -0700 | [diff] [blame] | 304 | static void __etm_enable(void *info) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 305 | { |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 306 | int i; |
Pratik Patel | 66e1a41 | 2012-09-06 11:07:06 -0700 | [diff] [blame] | 307 | struct etm_drvdata *drvdata = info; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 308 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 309 | ETM_UNLOCK(drvdata); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 310 | /* Vote for ETM power/clock enable */ |
Pratik Patel | ef6da29 | 2012-09-17 17:37:19 -0700 | [diff] [blame] | 311 | etm_set_pwrup(drvdata); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 312 | etm_set_prog(drvdata); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 313 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 314 | etm_writel(drvdata, drvdata->ctrl | BIT(10), ETMCR); |
| 315 | etm_writel(drvdata, drvdata->trigger_event, ETMTRIGGER); |
| 316 | etm_writel(drvdata, drvdata->startstop_ctrl, ETMTSSCR); |
| 317 | etm_writel(drvdata, drvdata->enable_event, ETMTEEVR); |
| 318 | etm_writel(drvdata, drvdata->enable_ctrl1, ETMTECR1); |
| 319 | etm_writel(drvdata, drvdata->fifofull_level, ETMFFLR); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 320 | for (i = 0; i < drvdata->nr_addr_cmp; i++) { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 321 | etm_writel(drvdata, drvdata->addr_val[i], ETMACVRn(i)); |
| 322 | etm_writel(drvdata, drvdata->addr_acctype[i], ETMACTRn(i)); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 323 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 324 | for (i = 0; i < drvdata->nr_cntr; i++) { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 325 | etm_writel(drvdata, drvdata->cntr_rld_val[i], ETMCNTRLDVRn(i)); |
| 326 | etm_writel(drvdata, drvdata->cntr_event[i], ETMCNTENRn(i)); |
| 327 | etm_writel(drvdata, drvdata->cntr_rld_event[i], |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 328 | ETMCNTRLDEVRn(i)); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 329 | etm_writel(drvdata, drvdata->cntr_val[i], ETMCNTVRn(i)); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 330 | } |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 331 | etm_writel(drvdata, drvdata->seq_12_event, ETMSQ12EVR); |
| 332 | etm_writel(drvdata, drvdata->seq_21_event, ETMSQ21EVR); |
| 333 | etm_writel(drvdata, drvdata->seq_23_event, ETMSQ23EVR); |
| 334 | etm_writel(drvdata, drvdata->seq_31_event, ETMSQ31EVR); |
| 335 | etm_writel(drvdata, drvdata->seq_32_event, ETMSQ32EVR); |
| 336 | etm_writel(drvdata, drvdata->seq_13_event, ETMSQ13EVR); |
| 337 | etm_writel(drvdata, drvdata->seq_curr_state, ETMSQR); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 338 | for (i = 0; i < drvdata->nr_ext_out; i++) |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 339 | etm_writel(drvdata, 0x0000406F, ETMEXTOUTEVRn(i)); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 340 | for (i = 0; i < drvdata->nr_ctxid_cmp; i++) |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 341 | etm_writel(drvdata, drvdata->ctxid_val[i], ETMCIDCVRn(i)); |
| 342 | etm_writel(drvdata, drvdata->ctxid_mask, ETMCIDCMR); |
| 343 | etm_writel(drvdata, drvdata->sync_freq, ETMSYNCFR); |
| 344 | etm_writel(drvdata, 0x00000000, ETMEXTINSELR); |
| 345 | etm_writel(drvdata, drvdata->timestamp_event, ETMTSEVR); |
| 346 | etm_writel(drvdata, 0x00000000, ETMAUXCR); |
| 347 | etm_writel(drvdata, drvdata->cpu + 1, ETMTRACEIDR); |
| 348 | etm_writel(drvdata, 0x00000000, ETMVMIDCVR); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 349 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 350 | etm_clr_prog(drvdata); |
| 351 | ETM_LOCK(drvdata); |
Pratik Patel | 66e1a41 | 2012-09-06 11:07:06 -0700 | [diff] [blame] | 352 | |
| 353 | dev_dbg(drvdata->dev, "cpu: %d enable smp call done\n", drvdata->cpu); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 356 | static int etm_enable(struct coresight_device *csdev) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 357 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 358 | struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); |
| 359 | int ret; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 360 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 361 | wake_lock(&drvdata->wake_lock); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 362 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 363 | ret = clk_prepare_enable(drvdata->clk); |
Pratik Patel | f17b147 | 2012-05-25 22:23:52 -0700 | [diff] [blame] | 364 | if (ret) |
| 365 | goto err_clk; |
| 366 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 367 | mutex_lock(&drvdata->mutex); |
Pratik Patel | 66e1a41 | 2012-09-06 11:07:06 -0700 | [diff] [blame] | 368 | /* executing __etm_enable on the cpu whose ETM is being enabled |
| 369 | * ensures that register writes occur when cpu is powered. |
| 370 | */ |
| 371 | smp_call_function_single(drvdata->cpu, __etm_enable, drvdata, 1); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 372 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 373 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 374 | wake_unlock(&drvdata->wake_lock); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 375 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 376 | dev_info(drvdata->dev, "ETM tracing enabled\n"); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 377 | return 0; |
Pratik Patel | f17b147 | 2012-05-25 22:23:52 -0700 | [diff] [blame] | 378 | err_clk: |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 379 | wake_unlock(&drvdata->wake_lock); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 380 | return ret; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Pratik Patel | 66e1a41 | 2012-09-06 11:07:06 -0700 | [diff] [blame] | 383 | static void __etm_disable(void *info) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 384 | { |
Pratik Patel | 66e1a41 | 2012-09-06 11:07:06 -0700 | [diff] [blame] | 385 | struct etm_drvdata *drvdata = info; |
| 386 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 387 | ETM_UNLOCK(drvdata); |
| 388 | etm_set_prog(drvdata); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 389 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 390 | /* program trace enable to low by using always false event */ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 391 | etm_writel(drvdata, 0x6F | BIT(14), ETMTEEVR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 392 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 393 | /* Vote for ETM power/clock disable */ |
Pratik Patel | ef6da29 | 2012-09-17 17:37:19 -0700 | [diff] [blame] | 394 | etm_clr_pwrup(drvdata); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 395 | ETM_LOCK(drvdata); |
Pratik Patel | 66e1a41 | 2012-09-06 11:07:06 -0700 | [diff] [blame] | 396 | |
| 397 | dev_dbg(drvdata->dev, "cpu: %d disable smp call done\n", drvdata->cpu); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 400 | static void etm_disable(struct coresight_device *csdev) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 401 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 402 | struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 403 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 404 | wake_lock(&drvdata->wake_lock); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 405 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 406 | mutex_lock(&drvdata->mutex); |
Pratik Patel | 66e1a41 | 2012-09-06 11:07:06 -0700 | [diff] [blame] | 407 | /* executing __etm_disable on the cpu whose ETM is being disabled |
| 408 | * ensures that register writes occur when cpu is powered. |
| 409 | */ |
| 410 | smp_call_function_single(drvdata->cpu, __etm_disable, drvdata, 1); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 411 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 412 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 413 | clk_disable_unprepare(drvdata->clk); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 414 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 415 | wake_unlock(&drvdata->wake_lock); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 416 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 417 | dev_info(drvdata->dev, "ETM tracing disabled\n"); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 420 | static const struct coresight_ops_source etm_source_ops = { |
| 421 | .enable = etm_enable, |
| 422 | .disable = etm_disable, |
| 423 | }; |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 424 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 425 | static const struct coresight_ops etm_cs_ops = { |
| 426 | .source_ops = &etm_source_ops, |
| 427 | }; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 428 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 429 | static ssize_t etm_show_nr_addr_cmp(struct device *dev, |
| 430 | struct device_attribute *attr, char *buf) |
| 431 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 432 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 433 | unsigned long val = drvdata->nr_addr_cmp; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 434 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 435 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 436 | } |
| 437 | static DEVICE_ATTR(nr_addr_cmp, S_IRUGO, etm_show_nr_addr_cmp, NULL); |
| 438 | |
| 439 | static ssize_t etm_show_nr_cntr(struct device *dev, |
| 440 | struct device_attribute *attr, char *buf) |
| 441 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 442 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 443 | unsigned long val = drvdata->nr_cntr; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 444 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 445 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 446 | } |
| 447 | static DEVICE_ATTR(nr_cntr, S_IRUGO, etm_show_nr_cntr, NULL); |
| 448 | |
| 449 | static ssize_t etm_show_nr_ctxid_cmp(struct device *dev, |
| 450 | struct device_attribute *attr, char *buf) |
| 451 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 452 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 453 | unsigned long val = drvdata->nr_ctxid_cmp; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 454 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 455 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 456 | } |
| 457 | static DEVICE_ATTR(nr_ctxid_cmp, S_IRUGO, etm_show_nr_ctxid_cmp, NULL); |
| 458 | |
| 459 | static ssize_t etm_show_reset(struct device *dev, struct device_attribute *attr, |
| 460 | char *buf) |
| 461 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 462 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 463 | unsigned long val = drvdata->reset; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 464 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 465 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 466 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 467 | |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 468 | /* Reset to trace everything i.e. exclude nothing. */ |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 469 | static ssize_t etm_store_reset(struct device *dev, |
| 470 | struct device_attribute *attr, const char *buf, |
| 471 | size_t size) |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 472 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 473 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 474 | int i; |
| 475 | unsigned long val; |
| 476 | |
| 477 | if (sscanf(buf, "%lx", &val) != 1) |
| 478 | return -EINVAL; |
| 479 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 480 | mutex_lock(&drvdata->mutex); |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 481 | if (val) { |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 482 | drvdata->mode = ETM_MODE_EXCLUDE; |
| 483 | drvdata->ctrl = 0x0; |
Pratik Patel | 2d0c7b6 | 2012-02-24 19:04:37 -0800 | [diff] [blame] | 484 | if (cpu_is_krait_v1()) { |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 485 | drvdata->mode |= ETM_MODE_CYCACC; |
| 486 | drvdata->ctrl |= BIT(12); |
Pratik Patel | 2d0c7b6 | 2012-02-24 19:04:37 -0800 | [diff] [blame] | 487 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 488 | drvdata->trigger_event = 0x406F; |
| 489 | drvdata->startstop_ctrl = 0x0; |
| 490 | drvdata->enable_event = 0x6F; |
| 491 | drvdata->enable_ctrl1 = 0x1000000; |
| 492 | drvdata->fifofull_level = 0x28; |
| 493 | drvdata->addr_idx = 0x0; |
| 494 | for (i = 0; i < drvdata->nr_addr_cmp; i++) { |
| 495 | drvdata->addr_val[i] = 0x0; |
| 496 | drvdata->addr_acctype[i] = 0x0; |
| 497 | drvdata->addr_type[i] = ETM_ADDR_TYPE_NONE; |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 498 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 499 | drvdata->cntr_idx = 0x0; |
| 500 | for (i = 0; i < drvdata->nr_cntr; i++) { |
| 501 | drvdata->cntr_rld_val[i] = 0x0; |
| 502 | drvdata->cntr_event[i] = 0x406F; |
| 503 | drvdata->cntr_rld_event[i] = 0x406F; |
| 504 | drvdata->cntr_val[i] = 0x0; |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 505 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 506 | drvdata->seq_12_event = 0x406F; |
| 507 | drvdata->seq_21_event = 0x406F; |
| 508 | drvdata->seq_23_event = 0x406F; |
| 509 | drvdata->seq_31_event = 0x406F; |
| 510 | drvdata->seq_32_event = 0x406F; |
| 511 | drvdata->seq_13_event = 0x406F; |
| 512 | drvdata->seq_curr_state = 0x0; |
| 513 | drvdata->ctxid_idx = 0x0; |
| 514 | for (i = 0; i < drvdata->nr_ctxid_cmp; i++) |
| 515 | drvdata->ctxid_val[i] = 0x0; |
| 516 | drvdata->ctxid_mask = 0x0; |
Pratik Patel | 77b9063 | 2012-07-17 17:54:51 -0700 | [diff] [blame] | 517 | /* Bits[7:0] of ETMSYNCFR are reserved on Krait pass3 onwards */ |
| 518 | if (cpu_is_krait() && !cpu_is_krait_v1() && !cpu_is_krait_v2()) |
| 519 | drvdata->sync_freq = 0x100; |
| 520 | else |
| 521 | drvdata->sync_freq = 0x80; |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 522 | drvdata->timestamp_event = 0x406F; |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 523 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 524 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 525 | return size; |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 526 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 527 | static DEVICE_ATTR(reset, S_IRUGO | S_IWUSR, etm_show_reset, etm_store_reset); |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 528 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 529 | static ssize_t etm_show_mode(struct device *dev, struct device_attribute *attr, |
| 530 | char *buf) |
| 531 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 532 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 533 | unsigned long val = drvdata->mode; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 534 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 535 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 536 | } |
| 537 | |
| 538 | static ssize_t etm_store_mode(struct device *dev, struct device_attribute *attr, |
| 539 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 540 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 541 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 542 | unsigned long val; |
| 543 | |
| 544 | if (sscanf(buf, "%lx", &val) != 1) |
| 545 | return -EINVAL; |
| 546 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 547 | mutex_lock(&drvdata->mutex); |
| 548 | drvdata->mode = val & ETM_MODE_ALL; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 549 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 550 | if (drvdata->mode & ETM_MODE_EXCLUDE) |
| 551 | drvdata->enable_ctrl1 |= BIT(24); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 552 | else |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 553 | drvdata->enable_ctrl1 &= ~BIT(24); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 554 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 555 | if (drvdata->mode & ETM_MODE_CYCACC) |
| 556 | drvdata->ctrl |= BIT(12); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 557 | else |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 558 | drvdata->ctrl &= ~BIT(12); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 559 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 560 | if (drvdata->mode & ETM_MODE_STALL) |
| 561 | drvdata->ctrl |= BIT(7); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 562 | else |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 563 | drvdata->ctrl &= ~BIT(7); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 564 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 565 | if (drvdata->mode & ETM_MODE_TIMESTAMP) |
| 566 | drvdata->ctrl |= BIT(28); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 567 | else |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 568 | drvdata->ctrl &= ~BIT(28); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 569 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 570 | if (drvdata->mode & ETM_MODE_CTXID) |
| 571 | drvdata->ctrl |= (BIT(14) | BIT(15)); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 572 | else |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 573 | drvdata->ctrl &= ~(BIT(14) | BIT(15)); |
| 574 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 575 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 576 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 577 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 578 | static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, etm_show_mode, etm_store_mode); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 579 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 580 | static ssize_t etm_show_trigger_event(struct device *dev, |
| 581 | struct device_attribute *attr, char *buf) |
| 582 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 583 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 584 | unsigned long val = drvdata->trigger_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 585 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 586 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 587 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 588 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 589 | static ssize_t etm_store_trigger_event(struct device *dev, |
| 590 | struct device_attribute *attr, |
| 591 | const char *buf, size_t size) |
| 592 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 593 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 594 | unsigned long val; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 595 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 596 | if (sscanf(buf, "%lx", &val) != 1) |
| 597 | return -EINVAL; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 598 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 599 | drvdata->trigger_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 600 | return size; |
| 601 | } |
| 602 | static DEVICE_ATTR(trigger_event, S_IRUGO | S_IWUSR, etm_show_trigger_event, |
| 603 | etm_store_trigger_event); |
| 604 | |
| 605 | static ssize_t etm_show_enable_event(struct device *dev, |
| 606 | struct device_attribute *attr, char *buf) |
| 607 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 608 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 609 | unsigned long val = drvdata->enable_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 610 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 611 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 612 | } |
| 613 | |
| 614 | static ssize_t etm_store_enable_event(struct device *dev, |
| 615 | struct device_attribute *attr, |
| 616 | const char *buf, size_t size) |
| 617 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 618 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 619 | unsigned long val; |
| 620 | |
| 621 | if (sscanf(buf, "%lx", &val) != 1) |
| 622 | return -EINVAL; |
| 623 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 624 | drvdata->enable_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 625 | return size; |
| 626 | } |
| 627 | static DEVICE_ATTR(enable_event, S_IRUGO | S_IWUSR, etm_show_enable_event, |
| 628 | etm_store_enable_event); |
| 629 | |
| 630 | static ssize_t etm_show_fifofull_level(struct device *dev, |
| 631 | struct device_attribute *attr, char *buf) |
| 632 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 633 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 634 | unsigned long val = drvdata->fifofull_level; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 635 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 636 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 637 | } |
| 638 | |
| 639 | static ssize_t etm_store_fifofull_level(struct device *dev, |
| 640 | struct device_attribute *attr, |
| 641 | const char *buf, size_t size) |
| 642 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 643 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 644 | unsigned long val; |
| 645 | |
| 646 | if (sscanf(buf, "%lx", &val) != 1) |
| 647 | return -EINVAL; |
| 648 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 649 | drvdata->fifofull_level = val; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 650 | return size; |
| 651 | } |
| 652 | static DEVICE_ATTR(fifofull_level, S_IRUGO | S_IWUSR, etm_show_fifofull_level, |
| 653 | etm_store_fifofull_level); |
| 654 | |
| 655 | static ssize_t etm_show_addr_idx(struct device *dev, |
| 656 | struct device_attribute *attr, char *buf) |
| 657 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 658 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 659 | unsigned long val = drvdata->addr_idx; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 660 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 661 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 662 | } |
| 663 | |
| 664 | static ssize_t etm_store_addr_idx(struct device *dev, |
| 665 | struct device_attribute *attr, |
| 666 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 667 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 668 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 669 | unsigned long val; |
| 670 | |
| 671 | if (sscanf(buf, "%lx", &val) != 1) |
| 672 | return -EINVAL; |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 673 | if (val >= drvdata->nr_addr_cmp) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 674 | return -EINVAL; |
| 675 | |
| 676 | /* Use mutex to ensure index doesn't change while it gets dereferenced |
| 677 | * multiple times within a mutex block elsewhere. |
| 678 | */ |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 679 | mutex_lock(&drvdata->mutex); |
| 680 | drvdata->addr_idx = val; |
| 681 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 682 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 683 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 684 | static DEVICE_ATTR(addr_idx, S_IRUGO | S_IWUSR, etm_show_addr_idx, |
| 685 | etm_store_addr_idx); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 686 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 687 | static ssize_t etm_show_addr_single(struct device *dev, |
| 688 | struct device_attribute *attr, char *buf) |
| 689 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 690 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 691 | unsigned long val; |
| 692 | uint8_t idx; |
| 693 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 694 | mutex_lock(&drvdata->mutex); |
| 695 | idx = drvdata->addr_idx; |
| 696 | if (!(drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 697 | drvdata->addr_type[idx] == ETM_ADDR_TYPE_SINGLE)) { |
| 698 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 699 | return -EPERM; |
| 700 | } |
| 701 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 702 | val = drvdata->addr_val[idx]; |
| 703 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 704 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 705 | } |
| 706 | |
| 707 | static ssize_t etm_store_addr_single(struct device *dev, |
| 708 | struct device_attribute *attr, |
| 709 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 710 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 711 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 712 | unsigned long val; |
| 713 | uint8_t idx; |
| 714 | |
| 715 | if (sscanf(buf, "%lx", &val) != 1) |
| 716 | return -EINVAL; |
| 717 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 718 | mutex_lock(&drvdata->mutex); |
| 719 | idx = drvdata->addr_idx; |
| 720 | if (!(drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 721 | drvdata->addr_type[idx] == ETM_ADDR_TYPE_SINGLE)) { |
| 722 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 723 | return -EPERM; |
| 724 | } |
| 725 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 726 | drvdata->addr_val[idx] = val; |
| 727 | drvdata->addr_type[idx] = ETM_ADDR_TYPE_SINGLE; |
| 728 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 729 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 730 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 731 | static DEVICE_ATTR(addr_single, S_IRUGO | S_IWUSR, etm_show_addr_single, |
| 732 | etm_store_addr_single); |
| 733 | |
| 734 | static ssize_t etm_show_addr_range(struct device *dev, |
| 735 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 736 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 737 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 738 | unsigned long val1, val2; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 739 | uint8_t idx; |
| 740 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 741 | mutex_lock(&drvdata->mutex); |
| 742 | idx = drvdata->addr_idx; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 743 | if (idx % 2 != 0) { |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 744 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 745 | return -EPERM; |
| 746 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 747 | if (!((drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE && |
| 748 | drvdata->addr_type[idx + 1] == ETM_ADDR_TYPE_NONE) || |
| 749 | (drvdata->addr_type[idx] == ETM_ADDR_TYPE_RANGE && |
| 750 | drvdata->addr_type[idx + 1] == ETM_ADDR_TYPE_RANGE))) { |
| 751 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 752 | return -EPERM; |
| 753 | } |
| 754 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 755 | val1 = drvdata->addr_val[idx]; |
| 756 | val2 = drvdata->addr_val[idx + 1]; |
| 757 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 758 | return scnprintf(buf, PAGE_SIZE, "%#lx %#lx\n", val1, val2); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 759 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 760 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 761 | static ssize_t etm_store_addr_range(struct device *dev, |
| 762 | struct device_attribute *attr, |
| 763 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 764 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 765 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 766 | unsigned long val1, val2; |
| 767 | uint8_t idx; |
| 768 | |
| 769 | if (sscanf(buf, "%lx %lx", &val1, &val2) != 2) |
| 770 | return -EINVAL; |
| 771 | /* lower address comparator cannot have a higher address value */ |
| 772 | if (val1 > val2) |
| 773 | return -EINVAL; |
| 774 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 775 | mutex_lock(&drvdata->mutex); |
| 776 | idx = drvdata->addr_idx; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 777 | if (idx % 2 != 0) { |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 778 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 779 | return -EPERM; |
| 780 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 781 | if (!((drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE && |
| 782 | drvdata->addr_type[idx + 1] == ETM_ADDR_TYPE_NONE) || |
| 783 | (drvdata->addr_type[idx] == ETM_ADDR_TYPE_RANGE && |
| 784 | drvdata->addr_type[idx + 1] == ETM_ADDR_TYPE_RANGE))) { |
| 785 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 786 | return -EPERM; |
| 787 | } |
| 788 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 789 | drvdata->addr_val[idx] = val1; |
| 790 | drvdata->addr_type[idx] = ETM_ADDR_TYPE_RANGE; |
| 791 | drvdata->addr_val[idx + 1] = val2; |
| 792 | drvdata->addr_type[idx + 1] = ETM_ADDR_TYPE_RANGE; |
| 793 | drvdata->enable_ctrl1 |= (1 << (idx/2)); |
| 794 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 795 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 796 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 797 | static DEVICE_ATTR(addr_range, S_IRUGO | S_IWUSR, etm_show_addr_range, |
| 798 | etm_store_addr_range); |
| 799 | |
| 800 | static ssize_t etm_show_addr_start(struct device *dev, |
| 801 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 802 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 803 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 804 | unsigned long val; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 805 | uint8_t idx; |
| 806 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 807 | mutex_lock(&drvdata->mutex); |
| 808 | idx = drvdata->addr_idx; |
| 809 | if (!(drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 810 | drvdata->addr_type[idx] == ETM_ADDR_TYPE_START)) { |
| 811 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 812 | return -EPERM; |
| 813 | } |
| 814 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 815 | val = drvdata->addr_val[idx]; |
| 816 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 817 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 818 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 819 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 820 | static ssize_t etm_store_addr_start(struct device *dev, |
| 821 | struct device_attribute *attr, |
| 822 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 823 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 824 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 825 | unsigned long val; |
| 826 | uint8_t idx; |
| 827 | |
| 828 | if (sscanf(buf, "%lx", &val) != 1) |
| 829 | return -EINVAL; |
| 830 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 831 | mutex_lock(&drvdata->mutex); |
| 832 | idx = drvdata->addr_idx; |
| 833 | if (!(drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 834 | drvdata->addr_type[idx] == ETM_ADDR_TYPE_START)) { |
| 835 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 836 | return -EPERM; |
| 837 | } |
| 838 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 839 | drvdata->addr_val[idx] = val; |
| 840 | drvdata->addr_type[idx] = ETM_ADDR_TYPE_START; |
| 841 | drvdata->startstop_ctrl |= (1 << idx); |
| 842 | drvdata->enable_ctrl1 |= BIT(25); |
| 843 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 844 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 845 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 846 | static DEVICE_ATTR(addr_start, S_IRUGO | S_IWUSR, etm_show_addr_start, |
| 847 | etm_store_addr_start); |
| 848 | |
| 849 | static ssize_t etm_show_addr_stop(struct device *dev, |
| 850 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 851 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 852 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 853 | unsigned long val; |
| 854 | uint8_t idx; |
| 855 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 856 | mutex_lock(&drvdata->mutex); |
| 857 | idx = drvdata->addr_idx; |
| 858 | if (!(drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 859 | drvdata->addr_type[idx] == ETM_ADDR_TYPE_STOP)) { |
| 860 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 861 | return -EPERM; |
| 862 | } |
| 863 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 864 | val = drvdata->addr_val[idx]; |
| 865 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 866 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 867 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 868 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 869 | static ssize_t etm_store_addr_stop(struct device *dev, |
| 870 | struct device_attribute *attr, |
| 871 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 872 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 873 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 874 | unsigned long val; |
| 875 | uint8_t idx; |
| 876 | |
| 877 | if (sscanf(buf, "%lx", &val) != 1) |
| 878 | return -EINVAL; |
| 879 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 880 | mutex_lock(&drvdata->mutex); |
| 881 | idx = drvdata->addr_idx; |
| 882 | if (!(drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 883 | drvdata->addr_type[idx] == ETM_ADDR_TYPE_STOP)) { |
| 884 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 885 | return -EPERM; |
| 886 | } |
| 887 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 888 | drvdata->addr_val[idx] = val; |
| 889 | drvdata->addr_type[idx] = ETM_ADDR_TYPE_STOP; |
| 890 | drvdata->startstop_ctrl |= (1 << (idx + 16)); |
| 891 | drvdata->enable_ctrl1 |= BIT(25); |
| 892 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 893 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 894 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 895 | static DEVICE_ATTR(addr_stop, S_IRUGO | S_IWUSR, etm_show_addr_stop, |
| 896 | etm_store_addr_stop); |
| 897 | |
| 898 | static ssize_t etm_show_addr_acctype(struct device *dev, |
| 899 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 900 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 901 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 902 | unsigned long val; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 903 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 904 | mutex_lock(&drvdata->mutex); |
| 905 | val = drvdata->addr_acctype[drvdata->addr_idx]; |
| 906 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 907 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 908 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 909 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 910 | static ssize_t etm_store_addr_acctype(struct device *dev, |
| 911 | struct device_attribute *attr, |
| 912 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 913 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 914 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 915 | unsigned long val; |
| 916 | |
| 917 | if (sscanf(buf, "%lx", &val) != 1) |
| 918 | return -EINVAL; |
| 919 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 920 | mutex_lock(&drvdata->mutex); |
| 921 | drvdata->addr_acctype[drvdata->addr_idx] = val; |
| 922 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 923 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 924 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 925 | static DEVICE_ATTR(addr_acctype, S_IRUGO | S_IWUSR, etm_show_addr_acctype, |
| 926 | etm_store_addr_acctype); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 927 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 928 | static ssize_t etm_show_cntr_idx(struct device *dev, |
| 929 | struct device_attribute *attr, char *buf) |
| 930 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 931 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 932 | unsigned long val = drvdata->addr_idx; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 933 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 934 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 935 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 936 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 937 | static ssize_t etm_store_cntr_idx(struct device *dev, |
| 938 | struct device_attribute *attr, |
| 939 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 940 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 941 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 942 | unsigned long val; |
| 943 | |
| 944 | if (sscanf(buf, "%lx", &val) != 1) |
| 945 | return -EINVAL; |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 946 | if (val >= drvdata->nr_cntr) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 947 | return -EINVAL; |
| 948 | |
| 949 | /* Use mutex to ensure index doesn't change while it gets dereferenced |
| 950 | * multiple times within a mutex block elsewhere. |
| 951 | */ |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 952 | mutex_lock(&drvdata->mutex); |
| 953 | drvdata->cntr_idx = val; |
| 954 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 955 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 956 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 957 | static DEVICE_ATTR(cntr_idx, S_IRUGO | S_IWUSR, etm_show_cntr_idx, |
| 958 | etm_store_cntr_idx); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 959 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 960 | static ssize_t etm_show_cntr_rld_val(struct device *dev, |
| 961 | struct device_attribute *attr, char *buf) |
| 962 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 963 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 964 | unsigned long val; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 965 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 966 | mutex_lock(&drvdata->mutex); |
| 967 | val = drvdata->cntr_rld_val[drvdata->cntr_idx]; |
| 968 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 969 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 970 | } |
| 971 | |
| 972 | static ssize_t etm_store_cntr_rld_val(struct device *dev, |
| 973 | struct device_attribute *attr, |
| 974 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 975 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 976 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 977 | unsigned long val; |
| 978 | |
| 979 | if (sscanf(buf, "%lx", &val) != 1) |
| 980 | return -EINVAL; |
| 981 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 982 | mutex_lock(&drvdata->mutex); |
| 983 | drvdata->cntr_rld_val[drvdata->cntr_idx] = val; |
| 984 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 985 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 986 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 987 | static DEVICE_ATTR(cntr_rld_val, S_IRUGO | S_IWUSR, etm_show_cntr_rld_val, |
| 988 | etm_store_cntr_rld_val); |
| 989 | |
| 990 | static ssize_t etm_show_cntr_event(struct device *dev, |
| 991 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 992 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 993 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 994 | unsigned long val; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 995 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 996 | mutex_lock(&drvdata->mutex); |
| 997 | val = drvdata->cntr_event[drvdata->cntr_idx]; |
| 998 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 999 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1000 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1001 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1002 | static ssize_t etm_store_cntr_event(struct device *dev, |
| 1003 | struct device_attribute *attr, |
| 1004 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1005 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1006 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1007 | unsigned long val; |
| 1008 | |
| 1009 | if (sscanf(buf, "%lx", &val) != 1) |
| 1010 | return -EINVAL; |
| 1011 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1012 | mutex_lock(&drvdata->mutex); |
| 1013 | drvdata->cntr_event[drvdata->cntr_idx] = val & ETM_EVENT_MASK; |
| 1014 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1015 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1016 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1017 | static DEVICE_ATTR(cntr_event, S_IRUGO | S_IWUSR, etm_show_cntr_event, |
| 1018 | etm_store_cntr_event); |
| 1019 | |
| 1020 | static ssize_t etm_show_cntr_rld_event(struct device *dev, |
| 1021 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1022 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1023 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1024 | unsigned long val; |
| 1025 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1026 | mutex_lock(&drvdata->mutex); |
| 1027 | val = drvdata->cntr_rld_event[drvdata->cntr_idx]; |
| 1028 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1029 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1030 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1031 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1032 | static ssize_t etm_store_cntr_rld_event(struct device *dev, |
| 1033 | struct device_attribute *attr, |
| 1034 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1035 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1036 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1037 | unsigned long val; |
| 1038 | |
| 1039 | if (sscanf(buf, "%lx", &val) != 1) |
| 1040 | return -EINVAL; |
| 1041 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1042 | mutex_lock(&drvdata->mutex); |
| 1043 | drvdata->cntr_rld_event[drvdata->cntr_idx] = val & ETM_EVENT_MASK; |
| 1044 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1045 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1046 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1047 | static DEVICE_ATTR(cntr_rld_event, S_IRUGO | S_IWUSR, etm_show_cntr_rld_event, |
| 1048 | etm_store_cntr_rld_event); |
| 1049 | |
| 1050 | static ssize_t etm_show_cntr_val(struct device *dev, |
| 1051 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1052 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1053 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1054 | unsigned long val; |
| 1055 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1056 | mutex_lock(&drvdata->mutex); |
| 1057 | val = drvdata->cntr_val[drvdata->cntr_idx]; |
| 1058 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1059 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1060 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1061 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1062 | static ssize_t etm_store_cntr_val(struct device *dev, |
| 1063 | struct device_attribute *attr, |
| 1064 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1065 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1066 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1067 | unsigned long val; |
| 1068 | |
| 1069 | if (sscanf(buf, "%lx", &val) != 1) |
| 1070 | return -EINVAL; |
| 1071 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1072 | mutex_lock(&drvdata->mutex); |
| 1073 | drvdata->cntr_val[drvdata->cntr_idx] = val; |
| 1074 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1075 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1076 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1077 | static DEVICE_ATTR(cntr_val, S_IRUGO | S_IWUSR, etm_show_cntr_val, |
| 1078 | etm_store_cntr_val); |
| 1079 | |
| 1080 | static ssize_t etm_show_seq_12_event(struct device *dev, |
| 1081 | struct device_attribute *attr, char *buf) |
| 1082 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1083 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1084 | unsigned long val = drvdata->seq_12_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1085 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1086 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1087 | } |
| 1088 | |
| 1089 | static ssize_t etm_store_seq_12_event(struct device *dev, |
| 1090 | struct device_attribute *attr, |
| 1091 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1092 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1093 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1094 | unsigned long val; |
| 1095 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1096 | if (sscanf(buf, "%lx", &val) != 1) |
| 1097 | return -EINVAL; |
| 1098 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1099 | drvdata->seq_12_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1100 | return size; |
| 1101 | } |
| 1102 | static DEVICE_ATTR(seq_12_event, S_IRUGO | S_IWUSR, etm_show_seq_12_event, |
| 1103 | etm_store_seq_12_event); |
| 1104 | |
| 1105 | static ssize_t etm_show_seq_21_event(struct device *dev, |
| 1106 | struct device_attribute *attr, char *buf) |
| 1107 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1108 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1109 | unsigned long val = drvdata->seq_21_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1110 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1111 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1112 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1113 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1114 | static ssize_t etm_store_seq_21_event(struct device *dev, |
| 1115 | struct device_attribute *attr, |
| 1116 | const char *buf, size_t size) |
| 1117 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1118 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1119 | unsigned long val; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1120 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1121 | if (sscanf(buf, "%lx", &val) != 1) |
| 1122 | return -EINVAL; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1123 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1124 | drvdata->seq_21_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1125 | return size; |
| 1126 | } |
| 1127 | static DEVICE_ATTR(seq_21_event, S_IRUGO | S_IWUSR, etm_show_seq_21_event, |
| 1128 | etm_store_seq_21_event); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1129 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1130 | static ssize_t etm_show_seq_23_event(struct device *dev, |
| 1131 | struct device_attribute *attr, char *buf) |
| 1132 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1133 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1134 | unsigned long val = drvdata->seq_23_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1135 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1136 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1137 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1138 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1139 | static ssize_t etm_store_seq_23_event(struct device *dev, |
| 1140 | struct device_attribute *attr, |
| 1141 | const char *buf, size_t size) |
| 1142 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1143 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1144 | unsigned long val; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1145 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1146 | if (sscanf(buf, "%lx", &val) != 1) |
| 1147 | return -EINVAL; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1148 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1149 | drvdata->seq_23_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1150 | return size; |
| 1151 | } |
| 1152 | static DEVICE_ATTR(seq_23_event, S_IRUGO | S_IWUSR, etm_show_seq_23_event, |
| 1153 | etm_store_seq_23_event); |
| 1154 | |
| 1155 | static ssize_t etm_show_seq_31_event(struct device *dev, |
| 1156 | struct device_attribute *attr, char *buf) |
| 1157 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1158 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1159 | unsigned long val = drvdata->seq_31_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1160 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1161 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1162 | } |
| 1163 | |
| 1164 | static ssize_t etm_store_seq_31_event(struct device *dev, |
| 1165 | struct device_attribute *attr, |
| 1166 | const char *buf, size_t size) |
| 1167 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1168 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1169 | unsigned long val; |
| 1170 | |
| 1171 | if (sscanf(buf, "%lx", &val) != 1) |
| 1172 | return -EINVAL; |
| 1173 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1174 | drvdata->seq_31_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1175 | return size; |
| 1176 | } |
| 1177 | static DEVICE_ATTR(seq_31_event, S_IRUGO | S_IWUSR, etm_show_seq_31_event, |
| 1178 | etm_store_seq_31_event); |
| 1179 | |
| 1180 | static ssize_t etm_show_seq_32_event(struct device *dev, |
| 1181 | struct device_attribute *attr, char *buf) |
| 1182 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1183 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1184 | unsigned long val = drvdata->seq_32_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1185 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1186 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1187 | } |
| 1188 | |
| 1189 | static ssize_t etm_store_seq_32_event(struct device *dev, |
| 1190 | struct device_attribute *attr, |
| 1191 | const char *buf, size_t size) |
| 1192 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1193 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1194 | unsigned long val; |
| 1195 | |
| 1196 | if (sscanf(buf, "%lx", &val) != 1) |
| 1197 | return -EINVAL; |
| 1198 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1199 | drvdata->seq_32_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1200 | return size; |
| 1201 | } |
| 1202 | static DEVICE_ATTR(seq_32_event, S_IRUGO | S_IWUSR, etm_show_seq_32_event, |
| 1203 | etm_store_seq_32_event); |
| 1204 | |
| 1205 | static ssize_t etm_show_seq_13_event(struct device *dev, |
| 1206 | struct device_attribute *attr, char *buf) |
| 1207 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1208 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1209 | unsigned long val = drvdata->seq_13_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1210 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1211 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1212 | } |
| 1213 | |
| 1214 | static ssize_t etm_store_seq_13_event(struct device *dev, |
| 1215 | struct device_attribute *attr, |
| 1216 | const char *buf, size_t size) |
| 1217 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1218 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1219 | unsigned long val; |
| 1220 | |
| 1221 | if (sscanf(buf, "%lx", &val) != 1) |
| 1222 | return -EINVAL; |
| 1223 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1224 | drvdata->seq_13_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1225 | return size; |
| 1226 | } |
| 1227 | static DEVICE_ATTR(seq_13_event, S_IRUGO | S_IWUSR, etm_show_seq_13_event, |
| 1228 | etm_store_seq_13_event); |
| 1229 | |
| 1230 | static ssize_t etm_show_seq_curr_state(struct device *dev, |
| 1231 | struct device_attribute *attr, char *buf) |
| 1232 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1233 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1234 | unsigned long val = drvdata->seq_curr_state; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1235 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1236 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1237 | } |
| 1238 | |
| 1239 | static ssize_t etm_store_seq_curr_state(struct device *dev, |
| 1240 | struct device_attribute *attr, |
| 1241 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1242 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1243 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1244 | unsigned long val; |
| 1245 | |
| 1246 | if (sscanf(buf, "%lx", &val) != 1) |
| 1247 | return -EINVAL; |
| 1248 | if (val > ETM_SEQ_STATE_MAX_VAL) |
| 1249 | return -EINVAL; |
| 1250 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1251 | drvdata->seq_curr_state = val; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1252 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1253 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1254 | static DEVICE_ATTR(seq_curr_state, S_IRUGO | S_IWUSR, etm_show_seq_curr_state, |
| 1255 | etm_store_seq_curr_state); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1256 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1257 | static ssize_t etm_show_ctxid_idx(struct device *dev, |
| 1258 | struct device_attribute *attr, char *buf) |
| 1259 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1260 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1261 | unsigned long val = drvdata->ctxid_idx; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1262 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1263 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1264 | } |
| 1265 | |
| 1266 | static ssize_t etm_store_ctxid_idx(struct device *dev, |
| 1267 | struct device_attribute *attr, |
| 1268 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1269 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1270 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1271 | unsigned long val; |
| 1272 | |
| 1273 | if (sscanf(buf, "%lx", &val) != 1) |
| 1274 | return -EINVAL; |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1275 | if (val >= drvdata->nr_ctxid_cmp) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1276 | return -EINVAL; |
| 1277 | |
| 1278 | /* Use mutex to ensure index doesn't change while it gets dereferenced |
| 1279 | * multiple times within a mutex block elsewhere. |
| 1280 | */ |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1281 | mutex_lock(&drvdata->mutex); |
| 1282 | drvdata->ctxid_idx = val; |
| 1283 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1284 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1285 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1286 | static DEVICE_ATTR(ctxid_idx, S_IRUGO | S_IWUSR, etm_show_ctxid_idx, |
| 1287 | etm_store_ctxid_idx); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1288 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1289 | static ssize_t etm_show_ctxid_val(struct device *dev, |
| 1290 | struct device_attribute *attr, char *buf) |
| 1291 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1292 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1293 | unsigned long val; |
| 1294 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1295 | mutex_lock(&drvdata->mutex); |
| 1296 | val = drvdata->ctxid_val[drvdata->ctxid_idx]; |
| 1297 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1298 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1299 | } |
| 1300 | |
| 1301 | static ssize_t etm_store_ctxid_val(struct device *dev, |
| 1302 | struct device_attribute *attr, |
| 1303 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1304 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1305 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1306 | unsigned long val; |
| 1307 | |
| 1308 | if (sscanf(buf, "%lx", &val) != 1) |
| 1309 | return -EINVAL; |
| 1310 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1311 | mutex_lock(&drvdata->mutex); |
| 1312 | drvdata->ctxid_val[drvdata->ctxid_idx] = val; |
| 1313 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1314 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1315 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1316 | static DEVICE_ATTR(ctxid_val, S_IRUGO | S_IWUSR, etm_show_ctxid_val, |
| 1317 | etm_store_ctxid_val); |
| 1318 | |
| 1319 | static ssize_t etm_show_ctxid_mask(struct device *dev, |
| 1320 | struct device_attribute *attr, char *buf) |
| 1321 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1322 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1323 | unsigned long val = drvdata->ctxid_mask; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1324 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1325 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1326 | } |
| 1327 | |
| 1328 | static ssize_t etm_store_ctxid_mask(struct device *dev, |
| 1329 | struct device_attribute *attr, |
| 1330 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1331 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1332 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1333 | unsigned long val; |
| 1334 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1335 | if (sscanf(buf, "%lx", &val) != 1) |
| 1336 | return -EINVAL; |
| 1337 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1338 | drvdata->ctxid_mask = val; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1339 | return size; |
| 1340 | } |
| 1341 | static DEVICE_ATTR(ctxid_mask, S_IRUGO | S_IWUSR, etm_show_ctxid_mask, |
| 1342 | etm_store_ctxid_mask); |
| 1343 | |
| 1344 | static ssize_t etm_show_sync_freq(struct device *dev, |
| 1345 | struct device_attribute *attr, char *buf) |
| 1346 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1347 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1348 | unsigned long val = drvdata->sync_freq; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1349 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1350 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1351 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1352 | static ssize_t etm_store_sync_freq(struct device *dev, |
| 1353 | struct device_attribute *attr, |
| 1354 | const char *buf, size_t size) |
| 1355 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1356 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1357 | unsigned long val; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1358 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1359 | if (sscanf(buf, "%lx", &val) != 1) |
| 1360 | return -EINVAL; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1361 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1362 | drvdata->sync_freq = val & ETM_SYNC_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1363 | return size; |
| 1364 | } |
| 1365 | static DEVICE_ATTR(sync_freq, S_IRUGO | S_IWUSR, etm_show_sync_freq, |
| 1366 | etm_store_sync_freq); |
| 1367 | |
| 1368 | static ssize_t etm_show_timestamp_event(struct device *dev, |
| 1369 | struct device_attribute *attr, |
| 1370 | char *buf) |
| 1371 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1372 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1373 | unsigned long val = drvdata->timestamp_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1374 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1375 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1376 | } |
| 1377 | |
| 1378 | static ssize_t etm_store_timestamp_event(struct device *dev, |
| 1379 | struct device_attribute *attr, |
| 1380 | const char *buf, size_t size) |
| 1381 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1382 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1383 | unsigned long val; |
| 1384 | |
| 1385 | if (sscanf(buf, "%lx", &val) != 1) |
| 1386 | return -EINVAL; |
| 1387 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1388 | drvdata->timestamp_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1389 | return size; |
| 1390 | } |
| 1391 | static DEVICE_ATTR(timestamp_event, S_IRUGO | S_IWUSR, etm_show_timestamp_event, |
| 1392 | etm_store_timestamp_event); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1393 | |
| 1394 | static struct attribute *etm_attrs[] = { |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1395 | &dev_attr_nr_addr_cmp.attr, |
| 1396 | &dev_attr_nr_cntr.attr, |
| 1397 | &dev_attr_nr_ctxid_cmp.attr, |
| 1398 | &dev_attr_reset.attr, |
| 1399 | &dev_attr_mode.attr, |
| 1400 | &dev_attr_trigger_event.attr, |
| 1401 | &dev_attr_enable_event.attr, |
| 1402 | &dev_attr_fifofull_level.attr, |
| 1403 | &dev_attr_addr_idx.attr, |
| 1404 | &dev_attr_addr_single.attr, |
| 1405 | &dev_attr_addr_range.attr, |
| 1406 | &dev_attr_addr_start.attr, |
| 1407 | &dev_attr_addr_stop.attr, |
| 1408 | &dev_attr_addr_acctype.attr, |
| 1409 | &dev_attr_cntr_idx.attr, |
| 1410 | &dev_attr_cntr_rld_val.attr, |
| 1411 | &dev_attr_cntr_event.attr, |
| 1412 | &dev_attr_cntr_rld_event.attr, |
| 1413 | &dev_attr_cntr_val.attr, |
| 1414 | &dev_attr_seq_12_event.attr, |
| 1415 | &dev_attr_seq_21_event.attr, |
| 1416 | &dev_attr_seq_23_event.attr, |
| 1417 | &dev_attr_seq_31_event.attr, |
| 1418 | &dev_attr_seq_32_event.attr, |
| 1419 | &dev_attr_seq_13_event.attr, |
| 1420 | &dev_attr_seq_curr_state.attr, |
| 1421 | &dev_attr_ctxid_idx.attr, |
| 1422 | &dev_attr_ctxid_val.attr, |
| 1423 | &dev_attr_ctxid_mask.attr, |
| 1424 | &dev_attr_sync_freq.attr, |
| 1425 | &dev_attr_timestamp_event.attr, |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1426 | NULL, |
| 1427 | }; |
| 1428 | |
| 1429 | static struct attribute_group etm_attr_grp = { |
| 1430 | .attrs = etm_attrs, |
| 1431 | }; |
| 1432 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1433 | static const struct attribute_group *etm_attr_grps[] = { |
| 1434 | &etm_attr_grp, |
| 1435 | NULL, |
| 1436 | }; |
| 1437 | |
| 1438 | /* Memory mapped writes to clear os lock not supported */ |
| 1439 | static void etm_os_unlock(void *unused) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1440 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1441 | unsigned long value = 0x0; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1442 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1443 | asm("mcr p14, 1, %0, c1, c0, 4\n\t" : : "r" (value)); |
| 1444 | asm("isb\n\t"); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1445 | } |
| 1446 | |
Stephen Boyd | a951050 | 2012-04-24 16:23:34 -0700 | [diff] [blame] | 1447 | static bool __devinit etm_arch_supported(uint8_t arch) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1448 | { |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1449 | switch (arch) { |
| 1450 | case PFT_ARCH_V1_1: |
| 1451 | break; |
| 1452 | default: |
| 1453 | return false; |
| 1454 | } |
| 1455 | return true; |
| 1456 | } |
| 1457 | |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 1458 | static void __devinit etm_prepare_arch(struct etm_drvdata *drvdata) |
| 1459 | { |
| 1460 | /* Unlock OS lock first to allow memory mapped reads and writes. This |
| 1461 | * is required for Krait pass1 |
| 1462 | * */ |
| 1463 | etm_os_unlock(NULL); |
| 1464 | smp_call_function(etm_os_unlock, NULL, 1); |
| 1465 | } |
| 1466 | |
| 1467 | static void __devinit etm_init_arch_data(void *info) |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1468 | { |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1469 | uint32_t etmidr; |
| 1470 | uint32_t etmccr; |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 1471 | struct etm_drvdata *drvdata = info; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1472 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1473 | ETM_UNLOCK(drvdata); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 1474 | /* Vote for ETM power/clock enable */ |
Pratik Patel | ef6da29 | 2012-09-17 17:37:19 -0700 | [diff] [blame] | 1475 | etm_set_pwrup(drvdata); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1476 | /* Set prog bit. It will be set from reset but this is included to |
| 1477 | * ensure it is set |
| 1478 | */ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1479 | etm_set_prog(drvdata); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1480 | |
| 1481 | /* find all capabilities */ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1482 | etmidr = etm_readl(drvdata, ETMIDR); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1483 | drvdata->arch = BMVAL(etmidr, 4, 11); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1484 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1485 | etmccr = etm_readl(drvdata, ETMCCR); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1486 | drvdata->nr_addr_cmp = BMVAL(etmccr, 0, 3) * 2; |
| 1487 | drvdata->nr_cntr = BMVAL(etmccr, 13, 15); |
| 1488 | drvdata->nr_ext_inp = BMVAL(etmccr, 17, 19); |
| 1489 | drvdata->nr_ext_out = BMVAL(etmccr, 20, 22); |
| 1490 | drvdata->nr_ctxid_cmp = BMVAL(etmccr, 24, 25); |
Pratik Patel | 2d0c7b6 | 2012-02-24 19:04:37 -0800 | [diff] [blame] | 1491 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 1492 | /* Vote for ETM power/clock disable */ |
Pratik Patel | ef6da29 | 2012-09-17 17:37:19 -0700 | [diff] [blame] | 1493 | etm_clr_pwrup(drvdata); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1494 | ETM_LOCK(drvdata); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
Pratik Patel | c14b4df | 2012-09-05 18:07:59 -0700 | [diff] [blame] | 1497 | static void __devinit etm_copy_arch_data(struct etm_drvdata *drvdata) |
| 1498 | { |
| 1499 | drvdata->arch = etm0drvdata->arch; |
| 1500 | drvdata->nr_addr_cmp = etm0drvdata->nr_addr_cmp; |
| 1501 | drvdata->nr_cntr = etm0drvdata->nr_cntr; |
| 1502 | drvdata->nr_ext_inp = etm0drvdata->nr_ext_inp; |
| 1503 | drvdata->nr_ext_out = etm0drvdata->nr_ext_out; |
| 1504 | drvdata->nr_ctxid_cmp = etm0drvdata->nr_ctxid_cmp; |
| 1505 | } |
| 1506 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1507 | static void __devinit etm_init_default_data(struct etm_drvdata *drvdata) |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1508 | { |
| 1509 | int i; |
| 1510 | |
| 1511 | drvdata->trigger_event = 0x406F; |
| 1512 | drvdata->enable_event = 0x6F; |
| 1513 | drvdata->enable_ctrl1 = 0x1; |
| 1514 | drvdata->fifofull_level = 0x28; |
| 1515 | if (drvdata->nr_addr_cmp >= 2) { |
| 1516 | drvdata->addr_val[0] = (uint32_t) _stext; |
| 1517 | drvdata->addr_val[1] = (uint32_t) _etext; |
| 1518 | drvdata->addr_type[0] = ETM_ADDR_TYPE_RANGE; |
| 1519 | drvdata->addr_type[1] = ETM_ADDR_TYPE_RANGE; |
| 1520 | } |
| 1521 | for (i = 0; i < drvdata->nr_cntr; i++) { |
| 1522 | drvdata->cntr_event[i] = 0x406F; |
| 1523 | drvdata->cntr_rld_event[i] = 0x406F; |
| 1524 | } |
| 1525 | drvdata->seq_12_event = 0x406F; |
| 1526 | drvdata->seq_21_event = 0x406F; |
| 1527 | drvdata->seq_23_event = 0x406F; |
| 1528 | drvdata->seq_31_event = 0x406F; |
| 1529 | drvdata->seq_32_event = 0x406F; |
| 1530 | drvdata->seq_13_event = 0x406F; |
Pratik Patel | 77b9063 | 2012-07-17 17:54:51 -0700 | [diff] [blame] | 1531 | /* Bits[7:0] of ETMSYNCFR are reserved on Krait pass3 onwards */ |
| 1532 | if (cpu_is_krait() && !cpu_is_krait_v1() && !cpu_is_krait_v2()) |
| 1533 | drvdata->sync_freq = 0x100; |
| 1534 | else |
| 1535 | drvdata->sync_freq = 0x80; |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1536 | drvdata->timestamp_event = 0x406F; |
| 1537 | |
| 1538 | /* Overrides for Krait pass1 */ |
| 1539 | if (cpu_is_krait_v1()) { |
| 1540 | /* Krait pass1 doesn't support include filtering and non-cycle |
| 1541 | * accurate tracing |
| 1542 | */ |
| 1543 | drvdata->mode = (ETM_MODE_EXCLUDE | ETM_MODE_CYCACC); |
| 1544 | drvdata->ctrl = 0x1000; |
| 1545 | drvdata->enable_ctrl1 = 0x1000000; |
| 1546 | for (i = 0; i < drvdata->nr_addr_cmp; i++) { |
| 1547 | drvdata->addr_val[i] = 0x0; |
| 1548 | drvdata->addr_acctype[i] = 0x0; |
| 1549 | drvdata->addr_type[i] = ETM_ADDR_TYPE_NONE; |
| 1550 | } |
| 1551 | } |
| 1552 | } |
| 1553 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1554 | static int __devinit etm_probe(struct platform_device *pdev) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1555 | { |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 1556 | int ret; |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1557 | struct device *dev = &pdev->dev; |
Pratik Patel | 5f6d1af | 2012-06-13 15:48:13 -0700 | [diff] [blame] | 1558 | struct coresight_platform_data *pdata; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1559 | struct etm_drvdata *drvdata; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1560 | struct resource *res; |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1561 | uint32_t reg_size; |
| 1562 | static int count; |
| 1563 | void *baddr; |
| 1564 | struct msm_client_dump dump; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1565 | struct coresight_desc *desc; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1566 | |
Pratik Patel | 5f6d1af | 2012-06-13 15:48:13 -0700 | [diff] [blame] | 1567 | if (pdev->dev.of_node) { |
| 1568 | pdata = of_get_coresight_platform_data(dev, pdev->dev.of_node); |
| 1569 | if (IS_ERR(pdata)) |
| 1570 | return PTR_ERR(pdata); |
| 1571 | pdev->dev.platform_data = pdata; |
| 1572 | } |
| 1573 | |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1574 | drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); |
| 1575 | if (!drvdata) |
| 1576 | return -ENOMEM; |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1577 | drvdata->dev = &pdev->dev; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1578 | platform_set_drvdata(pdev, drvdata); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1579 | |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1580 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1581 | if (!res) |
| 1582 | return -ENODEV; |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1583 | reg_size = resource_size(res); |
Pratik Patel | 2c09b76 | 2012-07-21 15:54:54 -0700 | [diff] [blame] | 1584 | |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1585 | drvdata->base = devm_ioremap(dev, res->start, resource_size(res)); |
| 1586 | if (!drvdata->base) |
| 1587 | return -ENOMEM; |
| 1588 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1589 | mutex_init(&drvdata->mutex); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1590 | wake_lock_init(&drvdata->wake_lock, WAKE_LOCK_SUSPEND, "coresight-etm"); |
Pratik Patel | e10a77c | 2012-03-20 10:35:16 -0700 | [diff] [blame] | 1591 | |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1592 | drvdata->clk = devm_clk_get(dev, "core_clk"); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1593 | if (IS_ERR(drvdata->clk)) { |
| 1594 | ret = PTR_ERR(drvdata->clk); |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1595 | goto err0; |
Pratik Patel | f17b147 | 2012-05-25 22:23:52 -0700 | [diff] [blame] | 1596 | } |
Pratik Patel | 2c09b76 | 2012-07-21 15:54:54 -0700 | [diff] [blame] | 1597 | |
Pratik Patel | 6fb3834 | 2012-06-03 14:51:38 -0700 | [diff] [blame] | 1598 | ret = clk_set_rate(drvdata->clk, CORESIGHT_CLK_RATE_TRACE); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1599 | if (ret) |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1600 | goto err0; |
| 1601 | |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1602 | drvdata->cpu = count++; |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1603 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1604 | ret = clk_prepare_enable(drvdata->clk); |
Pratik Patel | f17b147 | 2012-05-25 22:23:52 -0700 | [diff] [blame] | 1605 | if (ret) |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1606 | goto err0; |
Pratik Patel | 2c09b76 | 2012-07-21 15:54:54 -0700 | [diff] [blame] | 1607 | |
Pratik Patel | c14b4df | 2012-09-05 18:07:59 -0700 | [diff] [blame] | 1608 | /* Use CPU0 to populate read-only configuration data for ETM0. For other |
| 1609 | * ETMs copy it over from ETM0. |
| 1610 | */ |
| 1611 | if (drvdata->cpu == 0) { |
Pratik Patel | e6e41da | 2012-09-12 12:50:29 -0700 | [diff] [blame] | 1612 | etm_prepare_arch(drvdata); |
| 1613 | smp_call_function_single(drvdata->cpu, etm_init_arch_data, |
| 1614 | drvdata, 1); |
Pratik Patel | c14b4df | 2012-09-05 18:07:59 -0700 | [diff] [blame] | 1615 | etm0drvdata = drvdata; |
| 1616 | } else { |
Pratik Patel | dc3a0a4 | 2012-09-11 17:48:23 -0700 | [diff] [blame] | 1617 | etm_copy_arch_data(drvdata); |
| 1618 | } |
| 1619 | if (etm_arch_supported(drvdata->arch) == false) { |
| 1620 | ret = -EINVAL; |
| 1621 | goto err1; |
Pratik Patel | c14b4df | 2012-09-05 18:07:59 -0700 | [diff] [blame] | 1622 | } |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1623 | etm_init_default_data(drvdata); |
Pratik Patel | 2c09b76 | 2012-07-21 15:54:54 -0700 | [diff] [blame] | 1624 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1625 | clk_disable_unprepare(drvdata->clk); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1626 | |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1627 | baddr = devm_kzalloc(dev, PAGE_SIZE + reg_size, GFP_KERNEL); |
| 1628 | if (baddr) { |
| 1629 | *(uint32_t *)(baddr + ETM_REG_DUMP_VER_OFF) = ETM_REG_DUMP_VER; |
| 1630 | dump.id = MSM_ETM0_REG + drvdata->cpu; |
| 1631 | dump.start_addr = virt_to_phys(baddr); |
| 1632 | dump.end_addr = dump.start_addr + PAGE_SIZE + reg_size; |
| 1633 | ret = msm_dump_table_register(&dump); |
| 1634 | if (ret) { |
| 1635 | devm_kfree(dev, baddr); |
| 1636 | dev_err(dev, "ETM REG dump setup failed\n"); |
| 1637 | } |
| 1638 | } else { |
| 1639 | dev_err(dev, "ETM REG dump space allocation failed\n"); |
| 1640 | } |
| 1641 | |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1642 | desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1643 | if (!desc) { |
| 1644 | ret = -ENOMEM; |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1645 | goto err0; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1646 | } |
| 1647 | desc->type = CORESIGHT_DEV_TYPE_SOURCE; |
| 1648 | desc->subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_PROC; |
| 1649 | desc->ops = &etm_cs_ops; |
| 1650 | desc->pdata = pdev->dev.platform_data; |
| 1651 | desc->dev = &pdev->dev; |
| 1652 | desc->groups = etm_attr_grps; |
| 1653 | desc->owner = THIS_MODULE; |
| 1654 | drvdata->csdev = coresight_register(desc); |
| 1655 | if (IS_ERR(drvdata->csdev)) { |
| 1656 | ret = PTR_ERR(drvdata->csdev); |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1657 | goto err0; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1658 | } |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1659 | |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1660 | dev_info(dev, "ETM initialized\n"); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1661 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1662 | if (boot_enable) |
| 1663 | coresight_enable(drvdata->csdev); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1664 | |
| 1665 | return 0; |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1666 | err1: |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1667 | clk_disable_unprepare(drvdata->clk); |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1668 | err0: |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1669 | wake_lock_destroy(&drvdata->wake_lock); |
| 1670 | mutex_destroy(&drvdata->mutex); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1671 | return ret; |
| 1672 | } |
| 1673 | |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1674 | static int __devexit etm_remove(struct platform_device *pdev) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1675 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1676 | struct etm_drvdata *drvdata = platform_get_drvdata(pdev); |
| 1677 | |
| 1678 | coresight_unregister(drvdata->csdev); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1679 | wake_lock_destroy(&drvdata->wake_lock); |
| 1680 | mutex_destroy(&drvdata->mutex); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1681 | return 0; |
| 1682 | } |
| 1683 | |
Pratik Patel | 9eae482 | 2012-05-14 17:34:53 -0700 | [diff] [blame] | 1684 | static struct of_device_id etm_match[] = { |
Pratik Patel | 5f6d1af | 2012-06-13 15:48:13 -0700 | [diff] [blame] | 1685 | {.compatible = "arm,coresight-etm"}, |
Pratik Patel | 9eae482 | 2012-05-14 17:34:53 -0700 | [diff] [blame] | 1686 | {} |
| 1687 | }; |
| 1688 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1689 | static struct platform_driver etm_driver = { |
| 1690 | .probe = etm_probe, |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1691 | .remove = __devexit_p(etm_remove), |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1692 | .driver = { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1693 | .name = "coresight-etm", |
Pratik Patel | 9eae482 | 2012-05-14 17:34:53 -0700 | [diff] [blame] | 1694 | .owner = THIS_MODULE, |
| 1695 | .of_match_table = etm_match, |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1696 | }, |
| 1697 | }; |
| 1698 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1699 | int __init etm_init(void) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1700 | { |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1701 | return platform_driver_register(&etm_driver); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1702 | } |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1703 | module_init(etm_init); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1704 | |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1705 | void __exit etm_exit(void) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1706 | { |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1707 | platform_driver_unregister(&etm_driver); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1708 | } |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1709 | module_exit(etm_exit); |
| 1710 | |
| 1711 | MODULE_LICENSE("GPL v2"); |
| 1712 | MODULE_DESCRIPTION("CoreSight Program Flow Trace driver"); |