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