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