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