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