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