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