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