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