Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 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/module.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/fs.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/miscdevice.h> |
| 18 | #include <linux/cpu.h> |
| 19 | #include <linux/smp.h> |
| 20 | #include <linux/percpu.h> |
| 21 | #include <linux/io.h> |
| 22 | #include <linux/uaccess.h> |
| 23 | #include <linux/wakelock.h> |
| 24 | #include <linux/pm_qos_params.h> |
| 25 | |
| 26 | #include <asm/atomic.h> |
| 27 | |
| 28 | #include "cp14.h" |
| 29 | |
| 30 | #define LOG_BUF_LEN 32768 |
| 31 | #define ETM_NUM_REGS 128 |
| 32 | #define ETB_NUM_REGS 9 |
| 33 | /* each slot is 4 bytes, 8kb total */ |
| 34 | #define ETB_RAM_SLOTS 2048 |
| 35 | |
| 36 | #define DATALOG_SYNC 0xB5C7 |
| 37 | #define ETM_DUMP_MSG_ID 0x000A6960 |
| 38 | #define ETB_DUMP_MSG_ID 0x000A6961 |
| 39 | |
| 40 | /* ETM Registers */ |
| 41 | #define ETM_REG_CONTROL 0x00 |
| 42 | #define ETM_REG_STATUS 0x04 |
| 43 | #define ETB_REG_CONTROL 0x71 |
| 44 | #define ETB_REG_STATUS 0x72 |
| 45 | #define ETB_REG_COUNT 0x73 |
| 46 | #define ETB_REG_ADDRESS 0x74 |
| 47 | #define ETB_REG_DATA 0x75 |
| 48 | |
| 49 | /* Bitmasks for the ETM control register */ |
| 50 | #define ETM_CONTROL_POWERDOWN 0x00000001 |
| 51 | #define ETM_CONTROL_PROGRAM 0x00000400 |
| 52 | |
| 53 | /* Bitmasks for the ETM status register */ |
| 54 | #define ETM_STATUS_PROGRAMMING 0x00000002 |
| 55 | |
| 56 | /* ETB Status Register bit definitions */ |
| 57 | #define OV 0x00200000 |
| 58 | |
| 59 | /* ETB Control Register bit definitions */ |
| 60 | #define AIR 0x00000008 |
| 61 | #define AIW 0x00000004 |
| 62 | #define CPTM 0x00000002 |
| 63 | #define CPTEN 0x00000001 |
| 64 | |
| 65 | /* Bitmasks for the swconfig field of ETM_CONFIG |
| 66 | * ETM trigger propagated to ETM instances on all cores |
| 67 | */ |
| 68 | #define TRIGGER_ALL 0x00000002 |
| 69 | |
| 70 | #define PROG_TIMEOUT_MS 500 |
| 71 | |
| 72 | static int trace_enabled; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 73 | static int cpu_to_dump; |
| 74 | static int next_cpu_to_dump; |
| 75 | static struct wake_lock etm_wake_lock; |
| 76 | static struct pm_qos_request_list etm_qos_req; |
| 77 | static int trace_on_boot; |
| 78 | module_param_named( |
| 79 | trace_on_boot, trace_on_boot, int, S_IRUGO |
| 80 | ); |
| 81 | |
| 82 | struct b { |
| 83 | uint8_t etm_log_buf[LOG_BUF_LEN]; |
| 84 | uint32_t log_end; |
| 85 | }; |
| 86 | |
| 87 | static struct b buf[NR_CPUS]; |
| 88 | static struct b __percpu * *alloc_b; |
| 89 | static atomic_t etm_dev_in_use; |
| 90 | |
| 91 | /* These default settings will be used to configure the ETM/ETB |
| 92 | * when the driver loads. */ |
| 93 | struct etm_config_struct { |
| 94 | uint32_t etm_00_control; |
| 95 | uint32_t etm_02_trigger_event; |
| 96 | uint32_t etm_06_te_start_stop; |
| 97 | uint32_t etm_07_te_single_addr_comp; |
| 98 | uint32_t etm_08_te_event; |
| 99 | uint32_t etm_09_te_control; |
| 100 | uint32_t etm_0a_fifofull_region; |
| 101 | uint32_t etm_0b_fifofull_level; |
| 102 | uint32_t etm_0c_vd_event; |
| 103 | uint32_t etm_0d_vd_single_addr_comp; |
| 104 | uint32_t etm_0e_vd_mmd; |
| 105 | uint32_t etm_0f_vd_control; |
| 106 | uint32_t etm_addr_comp_value[8]; /* 10 to 17 */ |
| 107 | uint32_t etm_addr_access_type[8]; /* 20 to 27 */ |
| 108 | uint32_t etm_data_comp_value[2]; /* 30 and 32 */ |
| 109 | uint32_t etm_data_comp_mask[2]; /* 40 and 42 */ |
| 110 | uint32_t etm_counter_reload_value[2]; /* 50 to 51 */ |
| 111 | uint32_t etm_counter_enable[2]; /* 54 to 55 */ |
| 112 | uint32_t etm_counter_reload_event[2]; /* 58 to 59 */ |
| 113 | uint32_t etm_60_seq_event_1_to_2; |
| 114 | uint32_t etm_61_seq_event_2_to_1; |
| 115 | uint32_t etm_62_seq_event_2_to_3; |
| 116 | uint32_t etm_63_seq_event_3_to_1; |
| 117 | uint32_t etm_64_seq_event_3_to_2; |
| 118 | uint32_t etm_65_seq_event_1_to_3; |
| 119 | uint32_t etm_6c_cid_comp_value_1; |
| 120 | uint32_t etm_6f_cid_comp_mask; |
| 121 | uint32_t etm_78_sync_freq; |
| 122 | uint32_t swconfig; |
| 123 | uint32_t etb_trig_cnt; |
| 124 | uint32_t etb_init_ptr; |
| 125 | }; |
| 126 | |
| 127 | static struct etm_config_struct etm_config = { |
| 128 | /* etm_00_control 0x0000D84E: 32-bit CID, cycle-accurate, |
| 129 | * monitorCPRT */ |
| 130 | .etm_00_control = 0x0000D84E, |
| 131 | /* etm_02_trigger_event 0x00000000: address comparator 0 matches */ |
| 132 | .etm_02_trigger_event = 0x00000000, |
| 133 | .etm_06_te_start_stop = 0x00000000, |
| 134 | .etm_07_te_single_addr_comp = 0x00000000, |
| 135 | /* etm_08_te_event 0x0000006F: always true */ |
| 136 | .etm_08_te_event = 0x0000006F, |
| 137 | /* etm_09_te_control 0x01000000: exclude none */ |
| 138 | .etm_09_te_control = 0x01000000, |
| 139 | .etm_0a_fifofull_region = 0x00000000, |
| 140 | .etm_0b_fifofull_level = 0x00000000, |
| 141 | /* etm_0c_vd_event 0x0000006F: always true */ |
| 142 | .etm_0c_vd_event = 0x0000006F, |
| 143 | .etm_0d_vd_single_addr_comp = 0x00000000, |
| 144 | .etm_0e_vd_mmd = 0x00000000, |
| 145 | /* etm_0f_vd_control 0x00010000: exclude none */ |
| 146 | .etm_0f_vd_control = 0x00010000, |
| 147 | .etm_addr_comp_value[0] = 0x00000000, |
| 148 | .etm_addr_comp_value[1] = 0x00000000, |
| 149 | .etm_addr_comp_value[2] = 0x00000000, |
| 150 | .etm_addr_comp_value[3] = 0x00000000, |
| 151 | .etm_addr_comp_value[4] = 0x00000000, |
| 152 | .etm_addr_comp_value[5] = 0x00000000, |
| 153 | .etm_addr_comp_value[6] = 0x00000000, |
| 154 | .etm_addr_comp_value[7] = 0x00000000, |
| 155 | .etm_addr_access_type[0] = 0x00000000, |
| 156 | .etm_addr_access_type[1] = 0x00000000, |
| 157 | .etm_addr_access_type[2] = 0x00000000, |
| 158 | .etm_addr_access_type[3] = 0x00000000, |
| 159 | .etm_addr_access_type[4] = 0x00000000, |
| 160 | .etm_addr_access_type[5] = 0x00000000, |
| 161 | .etm_addr_access_type[6] = 0x00000000, |
| 162 | .etm_addr_access_type[7] = 0x00000000, |
| 163 | .etm_data_comp_value[0] = 0x00000000, |
| 164 | .etm_data_comp_value[1] = 0x00000000, |
| 165 | .etm_data_comp_mask[0] = 0x00000000, |
| 166 | .etm_data_comp_mask[1] = 0x00000000, |
| 167 | .etm_counter_reload_value[0] = 0x00000000, |
| 168 | .etm_counter_reload_value[1] = 0x00000000, |
| 169 | .etm_counter_enable[0] = 0x0002406F, |
| 170 | .etm_counter_enable[1] = 0x0002406F, |
| 171 | .etm_counter_reload_event[0] = 0x0000406F, |
| 172 | .etm_counter_reload_event[1] = 0x0000406F, |
| 173 | .etm_60_seq_event_1_to_2 = 0x0000406F, |
| 174 | .etm_61_seq_event_2_to_1 = 0x0000406F, |
| 175 | .etm_62_seq_event_2_to_3 = 0x0000406F, |
| 176 | .etm_63_seq_event_3_to_1 = 0x0000406F, |
| 177 | .etm_64_seq_event_3_to_2 = 0x0000406F, |
| 178 | .etm_65_seq_event_1_to_3 = 0x0000406F, |
| 179 | .etm_6c_cid_comp_value_1 = 0x00000000, |
| 180 | .etm_6f_cid_comp_mask = 0x00000000, |
| 181 | .etm_78_sync_freq = 0x00000400, |
| 182 | .swconfig = 0x00000002, |
| 183 | /* etb_trig_cnt 0x00000000: ignore trigger */ |
| 184 | .etb_trig_cnt = 0x00000000, |
| 185 | /* etb_init_ptr 0x00000010: 16 marker bytes */ |
| 186 | .etb_init_ptr = 0x00000010, |
| 187 | }; |
| 188 | |
| 189 | static void emit_log_char(uint8_t c) |
| 190 | { |
| 191 | int this_cpu = get_cpu(); |
| 192 | struct b *mybuf = *per_cpu_ptr(alloc_b, this_cpu); |
| 193 | char *log_buf = mybuf->etm_log_buf; |
| 194 | int index = (mybuf->log_end)++ & (LOG_BUF_LEN - 1); |
| 195 | log_buf[index] = c; |
| 196 | put_cpu(); |
| 197 | } |
| 198 | |
| 199 | static void emit_log_word(uint32_t word) |
| 200 | { |
| 201 | emit_log_char(word >> 24); |
| 202 | emit_log_char(word >> 16); |
| 203 | emit_log_char(word >> 8); |
| 204 | emit_log_char(word >> 0); |
| 205 | } |
| 206 | |
| 207 | static void __cpu_enable_etb(void) |
| 208 | { |
| 209 | uint32_t etb_control; |
| 210 | uint32_t i; |
| 211 | |
| 212 | /* enable auto-increment on reads and writes */ |
| 213 | etb_control = AIR | AIW; |
| 214 | etm_write_reg(ETB_REG_CONTROL, etb_control); |
| 215 | |
| 216 | /* write tags to the slots before the write pointer so we can |
| 217 | * detect overflow */ |
| 218 | etm_write_reg(ETB_REG_ADDRESS, 0x00000000); |
| 219 | for (i = 0; i < (etm_config.etb_init_ptr >> 2); i++) |
| 220 | etm_write_reg(ETB_REG_DATA, 0xDEADBEEF); |
| 221 | |
| 222 | etm_write_reg(ETB_REG_STATUS, 0x00000000); |
| 223 | |
| 224 | /* initialize write pointer */ |
| 225 | etm_write_reg(ETB_REG_ADDRESS, etm_config.etb_init_ptr); |
| 226 | |
| 227 | /* multiple of 16 */ |
| 228 | etm_write_reg(ETB_REG_COUNT, etm_config.etb_trig_cnt & 0xFFFFFFF0); |
| 229 | |
| 230 | /* Enable ETB and enable the trigger counter as appropriate. A |
| 231 | * trigger count of 0 will be used to signify that the user wants to |
| 232 | * ignore the trigger (just keep writing to the ETB and overwriting |
| 233 | * the oldest data). For "trace before trigger" captures the user |
| 234 | * should set the trigger count to a small number. */ |
| 235 | |
| 236 | etb_control |= CPTEN; |
| 237 | if (etm_config.etb_trig_cnt) |
| 238 | etb_control |= CPTM; |
| 239 | etm_write_reg(ETB_REG_CONTROL, etb_control); |
| 240 | } |
| 241 | |
| 242 | static void __cpu_disable_etb(void) |
| 243 | { |
| 244 | uint32_t etb_control; |
| 245 | etb_control = etm_read_reg(ETB_REG_CONTROL); |
| 246 | etb_control &= ~CPTEN; |
| 247 | etm_write_reg(ETB_REG_CONTROL, etb_control); |
| 248 | } |
| 249 | |
| 250 | static void __cpu_enable_etm(void) |
| 251 | { |
| 252 | uint32_t etm_control; |
| 253 | unsigned long timeout = jiffies + msecs_to_jiffies(PROG_TIMEOUT_MS); |
| 254 | |
| 255 | etm_control = etm_read_reg(ETM_REG_CONTROL); |
| 256 | etm_control &= ~ETM_CONTROL_PROGRAM; |
| 257 | etm_write_reg(ETM_REG_CONTROL, etm_control); |
| 258 | |
| 259 | while ((etm_read_reg(ETM_REG_STATUS) & ETM_STATUS_PROGRAMMING) == 1) { |
| 260 | cpu_relax(); |
| 261 | if (time_after(jiffies, timeout)) { |
| 262 | pr_err("etm: timeout while clearing prog bit\n"); |
| 263 | break; |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | static void __cpu_disable_etm(void) |
| 269 | { |
| 270 | uint32_t etm_control; |
| 271 | unsigned long timeout = jiffies + msecs_to_jiffies(PROG_TIMEOUT_MS); |
| 272 | |
| 273 | etm_control = etm_read_reg(ETM_REG_CONTROL); |
| 274 | etm_control |= ETM_CONTROL_PROGRAM; |
| 275 | etm_write_reg(ETM_REG_CONTROL, etm_control); |
| 276 | |
| 277 | while ((etm_read_reg(ETM_REG_STATUS) & ETM_STATUS_PROGRAMMING) == 0) { |
| 278 | cpu_relax(); |
| 279 | if (time_after(jiffies, timeout)) { |
| 280 | pr_err("etm: timeout while setting prog bit\n"); |
| 281 | break; |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | static void __cpu_enable_trace(void *unused) |
| 287 | { |
| 288 | uint32_t etm_control; |
| 289 | uint32_t etm_trigger; |
| 290 | uint32_t etm_external_output; |
| 291 | |
| 292 | get_cpu(); |
| 293 | |
| 294 | etm_read_reg(0xC5); /* clear sticky bit in PDSR */ |
| 295 | |
| 296 | __cpu_disable_etb(); |
| 297 | __cpu_disable_etm(); |
| 298 | |
| 299 | etm_control = (etm_config.etm_00_control & ~ETM_CONTROL_POWERDOWN) |
| 300 | | ETM_CONTROL_PROGRAM; |
| 301 | etm_write_reg(0x00, etm_control); |
| 302 | |
| 303 | etm_trigger = etm_config.etm_02_trigger_event; |
| 304 | etm_external_output = 0x406F; /* always FALSE */ |
| 305 | |
| 306 | if (etm_config.swconfig & TRIGGER_ALL) { |
| 307 | uint32_t function = 0x5; /* A OR B */ |
| 308 | uint32_t resource_b = 0x60; /* external input 1 */ |
| 309 | |
| 310 | etm_trigger &= 0x7F; /* keep resource A, clear function and |
| 311 | * resource B */ |
| 312 | etm_trigger |= (function << 14); |
| 313 | etm_trigger |= (resource_b << 7); |
| 314 | etm_external_output = etm_trigger; |
| 315 | } |
| 316 | |
| 317 | etm_write_reg(0x02, etm_trigger); |
| 318 | etm_write_reg(0x06, etm_config.etm_06_te_start_stop); |
| 319 | etm_write_reg(0x07, etm_config.etm_07_te_single_addr_comp); |
| 320 | etm_write_reg(0x08, etm_config.etm_08_te_event); |
| 321 | etm_write_reg(0x09, etm_config.etm_09_te_control); |
| 322 | etm_write_reg(0x0a, etm_config.etm_0a_fifofull_region); |
| 323 | etm_write_reg(0x0b, etm_config.etm_0b_fifofull_level); |
| 324 | etm_write_reg(0x0c, etm_config.etm_0c_vd_event); |
| 325 | etm_write_reg(0x0d, etm_config.etm_0d_vd_single_addr_comp); |
| 326 | etm_write_reg(0x0e, etm_config.etm_0e_vd_mmd); |
| 327 | etm_write_reg(0x0f, etm_config.etm_0f_vd_control); |
| 328 | etm_write_reg(0x10, etm_config.etm_addr_comp_value[0]); |
| 329 | etm_write_reg(0x11, etm_config.etm_addr_comp_value[1]); |
| 330 | etm_write_reg(0x12, etm_config.etm_addr_comp_value[2]); |
| 331 | etm_write_reg(0x13, etm_config.etm_addr_comp_value[3]); |
| 332 | etm_write_reg(0x14, etm_config.etm_addr_comp_value[4]); |
| 333 | etm_write_reg(0x15, etm_config.etm_addr_comp_value[5]); |
| 334 | etm_write_reg(0x16, etm_config.etm_addr_comp_value[6]); |
| 335 | etm_write_reg(0x17, etm_config.etm_addr_comp_value[7]); |
| 336 | etm_write_reg(0x20, etm_config.etm_addr_access_type[0]); |
| 337 | etm_write_reg(0x21, etm_config.etm_addr_access_type[1]); |
| 338 | etm_write_reg(0x22, etm_config.etm_addr_access_type[2]); |
| 339 | etm_write_reg(0x23, etm_config.etm_addr_access_type[3]); |
| 340 | etm_write_reg(0x24, etm_config.etm_addr_access_type[4]); |
| 341 | etm_write_reg(0x25, etm_config.etm_addr_access_type[5]); |
| 342 | etm_write_reg(0x26, etm_config.etm_addr_access_type[6]); |
| 343 | etm_write_reg(0x27, etm_config.etm_addr_access_type[7]); |
| 344 | etm_write_reg(0x30, etm_config.etm_data_comp_value[0]); |
| 345 | etm_write_reg(0x32, etm_config.etm_data_comp_value[1]); |
| 346 | etm_write_reg(0x40, etm_config.etm_data_comp_mask[0]); |
| 347 | etm_write_reg(0x42, etm_config.etm_data_comp_mask[1]); |
| 348 | etm_write_reg(0x50, etm_config.etm_counter_reload_value[0]); |
| 349 | etm_write_reg(0x51, etm_config.etm_counter_reload_value[1]); |
| 350 | etm_write_reg(0x54, etm_config.etm_counter_enable[0]); |
| 351 | etm_write_reg(0x55, etm_config.etm_counter_enable[1]); |
| 352 | etm_write_reg(0x58, etm_config.etm_counter_reload_event[0]); |
| 353 | etm_write_reg(0x59, etm_config.etm_counter_reload_event[1]); |
| 354 | etm_write_reg(0x60, etm_config.etm_60_seq_event_1_to_2); |
| 355 | etm_write_reg(0x61, etm_config.etm_61_seq_event_2_to_1); |
| 356 | etm_write_reg(0x62, etm_config.etm_62_seq_event_2_to_3); |
| 357 | etm_write_reg(0x63, etm_config.etm_63_seq_event_3_to_1); |
| 358 | etm_write_reg(0x64, etm_config.etm_64_seq_event_3_to_2); |
| 359 | etm_write_reg(0x65, etm_config.etm_65_seq_event_1_to_3); |
| 360 | etm_write_reg(0x68, etm_external_output); |
| 361 | etm_write_reg(0x6c, etm_config.etm_6c_cid_comp_value_1); |
| 362 | etm_write_reg(0x6f, etm_config.etm_6f_cid_comp_mask); |
| 363 | etm_write_reg(0x78, etm_config.etm_78_sync_freq); |
| 364 | |
| 365 | /* Note that we must enable the ETB before we enable the ETM if we |
| 366 | * want to capture the "always true" trigger event. */ |
| 367 | |
| 368 | __cpu_enable_etb(); |
| 369 | __cpu_enable_etm(); |
| 370 | |
| 371 | put_cpu(); |
| 372 | } |
| 373 | |
| 374 | static void __cpu_disable_trace(void *unused) |
| 375 | { |
| 376 | uint32_t etm_control; |
| 377 | |
| 378 | get_cpu(); |
| 379 | etm_read_reg(0xC5); /* clear sticky bit in PDSR */ |
| 380 | |
| 381 | __cpu_disable_etm(); |
| 382 | |
| 383 | /* program trace enable to be low by using always false event */ |
| 384 | etm_write_reg(0x08, 0x6F | BIT(14)); |
| 385 | |
| 386 | /* set the powerdown bit */ |
| 387 | etm_control = etm_read_reg(ETM_REG_CONTROL); |
| 388 | etm_control |= ETM_CONTROL_POWERDOWN; |
| 389 | etm_write_reg(ETM_REG_CONTROL, etm_control); |
| 390 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 391 | __cpu_disable_etb(); |
| 392 | |
| 393 | put_cpu(); |
| 394 | } |
| 395 | |
| 396 | static void enable_trace(void) |
| 397 | { |
| 398 | wake_lock(&etm_wake_lock); |
| 399 | pm_qos_update_request(&etm_qos_req, 0); |
| 400 | |
| 401 | if (etm_config.swconfig & TRIGGER_ALL) { |
| 402 | /* This register is accessible from either core. |
| 403 | * CPU1_extout[0] -> CPU0_extin[0] |
| 404 | * CPU_extout[0] -> CPU1_extin[0] */ |
| 405 | l2tevselr0_write(0x00000001); |
| 406 | } |
| 407 | |
| 408 | get_cpu(); |
| 409 | __cpu_enable_trace(NULL); |
| 410 | smp_call_function(__cpu_enable_trace, NULL, 1); |
| 411 | put_cpu(); |
| 412 | |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 413 | /* 1. causes all online cpus to come out of idle PC |
| 414 | * 2. prevents idle PC until save restore flag is enabled atomically |
| 415 | * |
| 416 | * we rely on the user to prevent hotplug on/off racing with this |
| 417 | * operation and to ensure cores where trace is expected to be turned |
| 418 | * on are already hotplugged on |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 419 | */ |
| 420 | trace_enabled = 1; |
| 421 | |
| 422 | pm_qos_update_request(&etm_qos_req, PM_QOS_DEFAULT_VALUE); |
| 423 | wake_unlock(&etm_wake_lock); |
| 424 | } |
| 425 | |
| 426 | static void disable_trace(void) |
| 427 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 428 | wake_lock(&etm_wake_lock); |
| 429 | pm_qos_update_request(&etm_qos_req, 0); |
| 430 | |
| 431 | get_cpu(); |
| 432 | __cpu_disable_trace(NULL); |
| 433 | smp_call_function(__cpu_disable_trace, NULL, 1); |
| 434 | put_cpu(); |
| 435 | |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 436 | /* 1. causes all online cpus to come out of idle PC |
| 437 | * 2. prevents idle PC until save restore flag is disabled atomically |
| 438 | * |
| 439 | * we rely on the user to prevent hotplug on/off racing with this |
| 440 | * operation and to ensure cores where trace is expected to be turned |
| 441 | * off are already hotplugged on |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 442 | */ |
| 443 | trace_enabled = 0; |
| 444 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 445 | cpu_to_dump = next_cpu_to_dump = 0; |
| 446 | |
| 447 | pm_qos_update_request(&etm_qos_req, PM_QOS_DEFAULT_VALUE); |
| 448 | wake_unlock(&etm_wake_lock); |
| 449 | } |
| 450 | |
| 451 | static void generate_etb_dump(void) |
| 452 | { |
| 453 | uint32_t i; |
| 454 | uint32_t full_slots; |
| 455 | uint32_t etb_control; |
| 456 | uint32_t prim_len; |
| 457 | uint32_t uptime = 0; |
| 458 | |
| 459 | etb_control = etm_read_reg(ETB_REG_CONTROL); |
| 460 | etb_control |= AIR; |
| 461 | etm_write_reg(ETB_REG_CONTROL, etb_control); |
| 462 | |
| 463 | if (etm_read_reg(ETB_REG_STATUS) & OV) |
| 464 | full_slots = ETB_RAM_SLOTS; |
| 465 | else |
| 466 | full_slots = etm_read_reg(ETB_REG_ADDRESS) >> 2; |
| 467 | |
| 468 | prim_len = 28 + (full_slots * 4); |
| 469 | |
| 470 | emit_log_char((DATALOG_SYNC >> 8) & 0xFF); |
| 471 | emit_log_char((DATALOG_SYNC >> 0) & 0xFF); |
| 472 | emit_log_char((prim_len >> 8) & 0xFF); |
| 473 | emit_log_char((prim_len >> 0) & 0xFF); |
| 474 | emit_log_word(uptime); |
| 475 | emit_log_word(ETB_DUMP_MSG_ID); |
| 476 | emit_log_word(etm_read_reg(ETM_REG_CONTROL)); |
| 477 | emit_log_word(etm_config.etb_init_ptr >> 2); |
| 478 | emit_log_word(etm_read_reg(ETB_REG_ADDRESS) >> 2); |
| 479 | emit_log_word((etm_read_reg(ETB_REG_STATUS) & OV) >> 21); |
| 480 | |
| 481 | etm_write_reg(ETB_REG_ADDRESS, 0x00000000); |
| 482 | for (i = 0; i < full_slots; i++) |
| 483 | emit_log_word(etm_read_reg(ETB_REG_DATA)); |
| 484 | } |
| 485 | |
| 486 | static void generate_etm_dump(void) |
| 487 | { |
| 488 | uint32_t i; |
| 489 | uint32_t prim_len; |
| 490 | uint32_t uptime = 0; |
| 491 | |
| 492 | prim_len = 12 + (4 * ETM_NUM_REGS); |
| 493 | |
| 494 | emit_log_char((DATALOG_SYNC >> 8) & 0xFF); |
| 495 | emit_log_char((DATALOG_SYNC >> 0) & 0xFF); |
| 496 | emit_log_char((prim_len >> 8) & 0xFF); |
| 497 | emit_log_char((prim_len >> 0) & 0xFF); |
| 498 | emit_log_word(uptime); |
| 499 | emit_log_word(ETM_DUMP_MSG_ID); |
| 500 | |
| 501 | /* do not disturb ETB_REG_ADDRESS by reading ETB_REG_DATA */ |
| 502 | for (i = 0; i < ETM_NUM_REGS; i++) |
| 503 | if (i == ETB_REG_DATA) |
| 504 | emit_log_word(0); |
| 505 | else |
| 506 | emit_log_word(etm_read_reg(i)); |
| 507 | } |
| 508 | |
| 509 | static void dump_all(void *unused) |
| 510 | { |
| 511 | get_cpu(); |
| 512 | etm_read_reg(0xC5); /* clear sticky bit in PDSR in case |
| 513 | * trace hasn't been enabled yet. */ |
| 514 | __cpu_disable_etb(); |
| 515 | generate_etm_dump(); |
| 516 | generate_etb_dump(); |
| 517 | if (trace_enabled) |
| 518 | __cpu_enable_etb(); |
| 519 | put_cpu(); |
| 520 | } |
| 521 | |
| 522 | static void dump_trace(void) |
| 523 | { |
| 524 | get_cpu(); |
| 525 | dump_all(NULL); |
| 526 | smp_call_function(dump_all, NULL, 1); |
| 527 | put_cpu(); |
| 528 | } |
| 529 | |
| 530 | static int bytes_to_dump; |
| 531 | static uint8_t *etm_buf_ptr; |
| 532 | |
| 533 | static int etm_dev_open(struct inode *inode, struct file *file) |
| 534 | { |
| 535 | if (atomic_cmpxchg(&etm_dev_in_use, 0, 1)) |
| 536 | return -EBUSY; |
| 537 | |
| 538 | pr_debug("%s: successfully opened\n", __func__); |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | static ssize_t etm_dev_read(struct file *file, char __user *data, |
| 543 | size_t len, loff_t *ppos) |
| 544 | { |
| 545 | if (cpu_to_dump == next_cpu_to_dump) { |
| 546 | if (cpu_to_dump == 0) |
| 547 | dump_trace(); |
| 548 | bytes_to_dump = buf[cpu_to_dump].log_end; |
| 549 | buf[cpu_to_dump].log_end = 0; |
| 550 | etm_buf_ptr = buf[cpu_to_dump].etm_log_buf; |
| 551 | next_cpu_to_dump++; |
| 552 | if (next_cpu_to_dump >= num_possible_cpus()) |
| 553 | next_cpu_to_dump = 0; |
| 554 | } |
| 555 | |
| 556 | if (len > bytes_to_dump) |
| 557 | len = bytes_to_dump; |
| 558 | |
| 559 | if (copy_to_user(data, etm_buf_ptr, len)) { |
| 560 | pr_debug("%s: copy_to_user failed\n", __func__); |
| 561 | return -EFAULT; |
| 562 | } |
| 563 | |
| 564 | bytes_to_dump -= len; |
| 565 | etm_buf_ptr += len; |
| 566 | |
| 567 | pr_debug("%s: %d bytes copied, %d bytes left (cpu %d)\n", |
| 568 | __func__, len, bytes_to_dump, next_cpu_to_dump); |
| 569 | return len; |
| 570 | } |
| 571 | |
| 572 | static void setup_range_filter(char addr_type, char range, uint32_t reg1, |
| 573 | uint32_t addr1, uint32_t reg2, uint32_t addr2) |
| 574 | { |
| 575 | etm_config.etm_addr_comp_value[reg1] = addr1; |
| 576 | etm_config.etm_addr_comp_value[reg2] = addr2; |
| 577 | |
| 578 | etm_config.etm_07_te_single_addr_comp |= (1 << reg1); |
| 579 | etm_config.etm_07_te_single_addr_comp |= (1 << reg2); |
| 580 | |
| 581 | etm_config.etm_09_te_control |= (1 << (reg1/2)); |
| 582 | if (range == 'i') |
| 583 | etm_config.etm_09_te_control &= ~(1 << 24); |
| 584 | else if (range == 'e') |
| 585 | etm_config.etm_09_te_control |= (1 << 24); |
| 586 | |
| 587 | if (addr_type == 'i') { |
| 588 | etm_config.etm_addr_access_type[reg1] = 0x99; |
| 589 | etm_config.etm_addr_access_type[reg2] = 0x99; |
| 590 | } else if (addr_type == 'd') { |
| 591 | etm_config.etm_addr_access_type[reg1] = 0x9C; |
| 592 | etm_config.etm_addr_access_type[reg2] = 0x9C; |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | static void setup_start_stop_filter(char addr_type, char start_stop, |
| 597 | uint32_t reg, uint32_t addr) |
| 598 | { |
| 599 | etm_config.etm_addr_comp_value[reg] = addr; |
| 600 | |
| 601 | if (start_stop == 's') |
| 602 | etm_config.etm_06_te_start_stop |= (1 << reg); |
| 603 | else if (start_stop == 't') |
| 604 | etm_config.etm_06_te_start_stop |= (1 << (reg + 16)); |
| 605 | |
| 606 | etm_config.etm_09_te_control |= (1 << 25); |
| 607 | |
| 608 | if (addr_type == 'i') |
| 609 | etm_config.etm_addr_access_type[reg] = 0x99; |
| 610 | else if (addr_type == 'd') |
| 611 | etm_config.etm_addr_access_type[reg] = 0x9C; |
| 612 | } |
| 613 | |
| 614 | static void setup_viewdata_range_filter(char range, uint32_t reg1, |
| 615 | uint32_t addr1, uint32_t reg2, uint32_t addr2) |
| 616 | { |
| 617 | etm_config.etm_addr_comp_value[reg1] = addr1; |
| 618 | etm_config.etm_addr_comp_value[reg2] = addr2; |
| 619 | |
| 620 | if (range == 'i') { |
| 621 | etm_config.etm_0d_vd_single_addr_comp |= (1 << reg1); |
| 622 | etm_config.etm_0d_vd_single_addr_comp |= (1 << reg2); |
| 623 | etm_config.etm_0f_vd_control |= (1 << (reg1/2)); |
| 624 | } else if (range == 'e') { |
| 625 | etm_config.etm_0d_vd_single_addr_comp |= (1 << (reg1 + 16)); |
| 626 | etm_config.etm_0d_vd_single_addr_comp |= (1 << (reg2 + 16)); |
| 627 | etm_config.etm_0f_vd_control |= (1 << ((reg1/2) + 8)); |
| 628 | } |
| 629 | etm_config.etm_0f_vd_control &= ~(1 << 16); |
| 630 | |
| 631 | etm_config.etm_addr_access_type[reg1] = 0x9C; |
| 632 | etm_config.etm_addr_access_type[reg2] = 0x9C; |
| 633 | } |
| 634 | |
| 635 | static void setup_viewdata_start_stop_filter(char start_stop, uint32_t reg, |
| 636 | uint32_t addr) |
| 637 | { |
| 638 | etm_config.etm_addr_comp_value[reg] = addr; |
| 639 | |
| 640 | if (start_stop == 's') |
| 641 | etm_config.etm_06_te_start_stop |= (1 << reg); |
| 642 | else if (start_stop == 't') |
| 643 | etm_config.etm_06_te_start_stop |= (1 << (reg + 16)); |
| 644 | |
| 645 | etm_config.etm_addr_access_type[reg] = 0x9C; |
| 646 | } |
| 647 | |
| 648 | static void setup_access_type(uint32_t reg, uint32_t value) |
| 649 | { |
| 650 | etm_config.etm_addr_access_type[reg] &= 0xFFFFFFF8; |
| 651 | value &= 0x7; |
| 652 | etm_config.etm_addr_access_type[reg] |= value; |
| 653 | } |
| 654 | |
| 655 | static void reset_filter(void) |
| 656 | { |
| 657 | etm_config.etm_00_control = 0x0000D84E; |
| 658 | /* etm_02_trigger_event 0x00000000: address comparator 0 matches */ |
| 659 | etm_config.etm_02_trigger_event = 0x00000000; |
| 660 | etm_config.etm_06_te_start_stop = 0x00000000; |
| 661 | etm_config.etm_07_te_single_addr_comp = 0x00000000; |
| 662 | /* etm_08_te_event 0x0000006F: always true */ |
| 663 | etm_config.etm_08_te_event = 0x0000006F; |
| 664 | /* etm_09_te_control 0x01000000: exclude none */ |
| 665 | etm_config.etm_09_te_control = 0x01000000; |
| 666 | etm_config.etm_0a_fifofull_region = 0x00000000; |
| 667 | etm_config.etm_0b_fifofull_level = 0x00000000; |
| 668 | /* etm_0c_vd_event 0x0000006F: always true */ |
| 669 | etm_config.etm_0c_vd_event = 0x0000006F; |
| 670 | etm_config.etm_0d_vd_single_addr_comp = 0x00000000; |
| 671 | etm_config.etm_0e_vd_mmd = 0x00000000; |
| 672 | /* etm_0f_vd_control 0x00010000: exclude none */ |
| 673 | etm_config.etm_0f_vd_control = 0x00010000; |
| 674 | etm_config.etm_addr_comp_value[0] = 0x00000000; |
| 675 | etm_config.etm_addr_comp_value[1] = 0x00000000; |
| 676 | etm_config.etm_addr_comp_value[2] = 0x00000000; |
| 677 | etm_config.etm_addr_comp_value[3] = 0x00000000; |
| 678 | etm_config.etm_addr_comp_value[4] = 0x00000000; |
| 679 | etm_config.etm_addr_comp_value[5] = 0x00000000; |
| 680 | etm_config.etm_addr_comp_value[6] = 0x00000000; |
| 681 | etm_config.etm_addr_comp_value[7] = 0x00000000; |
| 682 | etm_config.etm_addr_access_type[0] = 0x00000000; |
| 683 | etm_config.etm_addr_access_type[1] = 0x00000000; |
| 684 | etm_config.etm_addr_access_type[2] = 0x00000000; |
| 685 | etm_config.etm_addr_access_type[3] = 0x00000000; |
| 686 | etm_config.etm_addr_access_type[4] = 0x00000000; |
| 687 | etm_config.etm_addr_access_type[5] = 0x00000000; |
| 688 | etm_config.etm_addr_access_type[6] = 0x00000000; |
| 689 | etm_config.etm_addr_access_type[7] = 0x00000000; |
| 690 | etm_config.etm_data_comp_value[0] = 0x00000000; |
| 691 | etm_config.etm_data_comp_value[1] = 0x00000000; |
| 692 | etm_config.etm_data_comp_mask[0] = 0x00000000; |
| 693 | etm_config.etm_data_comp_mask[1] = 0x00000000; |
| 694 | etm_config.etm_counter_reload_value[0] = 0x00000000; |
| 695 | etm_config.etm_counter_reload_value[1] = 0x00000000; |
| 696 | etm_config.etm_counter_enable[0] = 0x0002406F; |
| 697 | etm_config.etm_counter_enable[1] = 0x0002406F; |
| 698 | etm_config.etm_counter_reload_event[0] = 0x0000406F; |
| 699 | etm_config.etm_counter_reload_event[1] = 0x0000406F; |
| 700 | etm_config.etm_60_seq_event_1_to_2 = 0x0000406F; |
| 701 | etm_config.etm_61_seq_event_2_to_1 = 0x0000406F; |
| 702 | etm_config.etm_62_seq_event_2_to_3 = 0x0000406F; |
| 703 | etm_config.etm_63_seq_event_3_to_1 = 0x0000406F; |
| 704 | etm_config.etm_64_seq_event_3_to_2 = 0x0000406F; |
| 705 | etm_config.etm_65_seq_event_1_to_3 = 0x0000406F; |
| 706 | etm_config.etm_6c_cid_comp_value_1 = 0x00000000; |
| 707 | etm_config.etm_6f_cid_comp_mask = 0x00000000; |
| 708 | etm_config.etm_78_sync_freq = 0x00000400; |
| 709 | etm_config.swconfig = 0x00000002; |
| 710 | /* etb_trig_cnt 0x00000020: ignore trigger */ |
| 711 | etm_config.etb_trig_cnt = 0x00000000; |
| 712 | /* etb_init_ptr 0x00000010: 16 marker bytes */ |
| 713 | etm_config.etb_init_ptr = 0x00000010; |
| 714 | } |
| 715 | |
| 716 | #define MAX_COMMAND_STRLEN 40 |
| 717 | static ssize_t etm_dev_write(struct file *file, const char __user *data, |
| 718 | size_t len, loff_t *ppos) |
| 719 | { |
| 720 | char command[MAX_COMMAND_STRLEN]; |
| 721 | int strlen; |
| 722 | unsigned long value; |
| 723 | unsigned long reg1, reg2; |
| 724 | unsigned long addr1, addr2; |
| 725 | |
| 726 | strlen = strnlen_user(data, MAX_COMMAND_STRLEN); |
| 727 | pr_debug("etm: string length: %d", strlen); |
| 728 | if (strlen == 0 || strlen == (MAX_COMMAND_STRLEN+1)) { |
| 729 | pr_err("etm: error in strlen: %d", strlen); |
| 730 | return -EFAULT; |
| 731 | } |
| 732 | /* includes the null character */ |
| 733 | if (copy_from_user(command, data, strlen)) { |
| 734 | pr_err("etm: error in copy_from_user: %d", strlen); |
| 735 | return -EFAULT; |
| 736 | } |
| 737 | |
| 738 | pr_debug("etm: input = %s", command); |
| 739 | |
| 740 | switch (command[0]) { |
| 741 | case '0': |
| 742 | if (trace_enabled) { |
| 743 | disable_trace(); |
| 744 | pr_info("etm: tracing disabled\n"); |
| 745 | } |
| 746 | break; |
| 747 | case '1': |
| 748 | if (!trace_enabled) { |
| 749 | enable_trace(); |
| 750 | pr_info("etm: tracing enabled\n"); |
| 751 | } |
| 752 | break; |
| 753 | case 'f': |
| 754 | switch (command[2]) { |
| 755 | case 'i': |
| 756 | case 'd': |
| 757 | switch (command[4]) { |
| 758 | case 'i': |
| 759 | if (sscanf(&command[6], "%lx:%lx:%lx:%lx\\0", |
| 760 | ®1, &addr1, ®2, &addr2) != 4) |
| 761 | goto err_out; |
| 762 | if (reg1 > 7 || reg2 > 7 || (reg1 % 2)) |
| 763 | goto err_out; |
| 764 | setup_range_filter(command[2], 'i', |
| 765 | reg1, addr1, reg2, addr2); |
| 766 | break; |
| 767 | case 'e': |
| 768 | if (sscanf(&command[6], "%lx:%lx:%lx:%lx\\0", |
| 769 | ®1, &addr1, ®2, &addr2) != 4) |
| 770 | goto err_out; |
| 771 | if (reg1 > 7 || reg2 > 7 || (reg1 % 2) |
| 772 | || command[2] == 'd') |
| 773 | goto err_out; |
| 774 | setup_range_filter(command[2], 'e', |
| 775 | reg1, addr1, reg2, addr2); |
| 776 | break; |
| 777 | case 's': |
| 778 | if (sscanf(&command[6], "%lx:%lx\\0", |
| 779 | ®1, &addr1) != 2) |
| 780 | goto err_out; |
| 781 | if (reg1 > 7) |
| 782 | goto err_out; |
| 783 | setup_start_stop_filter(command[2], 's', |
| 784 | reg1, addr1); |
| 785 | break; |
| 786 | case 't': |
| 787 | if (sscanf(&command[6], "%lx:%lx\\0", |
| 788 | ®1, &addr1) != 2) |
| 789 | goto err_out; |
| 790 | if (reg1 > 7) |
| 791 | goto err_out; |
| 792 | setup_start_stop_filter(command[2], 't', |
| 793 | reg1, addr1); |
| 794 | break; |
| 795 | default: |
| 796 | goto err_out; |
| 797 | } |
| 798 | break; |
| 799 | case 'r': |
| 800 | reset_filter(); |
| 801 | break; |
| 802 | default: |
| 803 | goto err_out; |
| 804 | } |
| 805 | break; |
| 806 | case 'v': |
| 807 | switch (command[2]) { |
| 808 | case 'd': |
| 809 | switch (command[4]) { |
| 810 | case 'i': |
| 811 | if (sscanf(&command[6], "%lx:%lx:%lx:%lx\\0", |
| 812 | ®1, &addr1, ®2, &addr2) != 4) |
| 813 | goto err_out; |
| 814 | if (reg1 > 7 || reg2 > 7 || (reg1 % 2)) |
| 815 | goto err_out; |
| 816 | setup_viewdata_range_filter('i', |
| 817 | reg1, addr1, reg2, addr2); |
| 818 | break; |
| 819 | case 'e': |
| 820 | if (sscanf(&command[6], "%lx:%lx:%lx:%lx\\0", |
| 821 | ®1, &addr1, ®2, &addr2) != 4) |
| 822 | goto err_out; |
| 823 | if (reg1 > 7 || reg2 > 7 || (reg1 % 2)) |
| 824 | goto err_out; |
| 825 | setup_viewdata_range_filter('e', |
| 826 | reg1, addr1, reg2, addr2); |
| 827 | break; |
| 828 | case 's': |
| 829 | if (sscanf(&command[6], "%lx:%lx\\0", |
| 830 | ®1, &addr1) != 2) |
| 831 | goto err_out; |
| 832 | if (reg1 > 7) |
| 833 | goto err_out; |
| 834 | setup_viewdata_start_stop_filter('s', |
| 835 | reg1, addr1); |
| 836 | break; |
| 837 | case 't': |
| 838 | if (sscanf(&command[6], "%lx:%lx\\0", |
| 839 | ®1, &addr1) != 2) |
| 840 | goto err_out; |
| 841 | if (reg1 > 7) |
| 842 | goto err_out; |
| 843 | setup_viewdata_start_stop_filter('t', |
| 844 | reg1, addr1); |
| 845 | break; |
| 846 | default: |
| 847 | goto err_out; |
| 848 | } |
| 849 | break; |
| 850 | default: |
| 851 | goto err_out; |
| 852 | } |
| 853 | break; |
| 854 | case 'a': |
| 855 | switch (command[2]) { |
| 856 | case 't': |
| 857 | if (sscanf(&command[4], "%lx:%lx\\0", |
| 858 | ®1, &value) != 2) |
| 859 | goto err_out; |
| 860 | if (reg1 > 7 || value > 6) |
| 861 | goto err_out; |
| 862 | setup_access_type(reg1, value); |
| 863 | break; |
| 864 | default: |
| 865 | goto err_out; |
| 866 | } |
| 867 | break; |
| 868 | default: |
| 869 | goto err_out; |
| 870 | } |
| 871 | |
| 872 | return len; |
| 873 | |
| 874 | err_out: |
| 875 | return -EFAULT; |
| 876 | } |
| 877 | |
| 878 | static int etm_dev_release(struct inode *inode, struct file *file) |
| 879 | { |
| 880 | if (cpu_to_dump == next_cpu_to_dump) |
| 881 | next_cpu_to_dump = 0; |
| 882 | cpu_to_dump = next_cpu_to_dump; |
| 883 | |
| 884 | atomic_set(&etm_dev_in_use, 0); |
| 885 | pr_debug("%s: released\n", __func__); |
| 886 | return 0; |
| 887 | } |
| 888 | |
| 889 | static const struct file_operations etm_dev_fops = { |
| 890 | .owner = THIS_MODULE, |
| 891 | .open = etm_dev_open, |
| 892 | .read = etm_dev_read, |
| 893 | .write = etm_dev_write, |
| 894 | .release = etm_dev_release, |
| 895 | }; |
| 896 | |
| 897 | static struct miscdevice etm_dev = { |
| 898 | .name = "msm_etm", |
| 899 | .minor = MISC_DYNAMIC_MINOR, |
| 900 | .fops = &etm_dev_fops, |
| 901 | }; |
| 902 | |
| 903 | /* etm_save_reg_check and etm_restore_reg_check should be fast |
| 904 | * |
| 905 | * These functions will be called either from: |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 906 | * 1. per_cpu idle thread context for idle power collapses. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 907 | * 2. per_cpu idle thread context for hotplug/suspend power collapse for |
| 908 | * nonboot cpus. |
| 909 | * 3. suspend thread context for core0. |
| 910 | * |
| 911 | * In all cases we are guaranteed to be running on the same cpu for the |
| 912 | * entire duration. |
| 913 | * |
| 914 | * Another assumption is that etm registers won't change after trace_enabled |
| 915 | * is set. Current usage model guarantees this doesn't happen. |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 916 | * |
| 917 | * Also disabling all types of power_collapses when enabling and disabling |
| 918 | * trace provides mutual exclusion to be able to safely access |
| 919 | * ptm.trace_enabled here. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 920 | */ |
| 921 | void etm_save_reg_check(void) |
| 922 | { |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 923 | if (trace_enabled) |
| 924 | etm_save_reg(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | void etm_restore_reg_check(void) |
| 928 | { |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 929 | if (trace_enabled) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 930 | etm_restore_reg(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | static int __init etm_init(void) |
| 934 | { |
| 935 | int ret, cpu; |
| 936 | |
| 937 | ret = misc_register(&etm_dev); |
| 938 | if (ret) |
| 939 | return -ENODEV; |
| 940 | |
| 941 | alloc_b = alloc_percpu(typeof(*alloc_b)); |
| 942 | if (!alloc_b) |
| 943 | goto err1; |
| 944 | |
| 945 | for_each_possible_cpu(cpu) |
| 946 | *per_cpu_ptr(alloc_b, cpu) = &buf[cpu]; |
| 947 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 948 | wake_lock_init(&etm_wake_lock, WAKE_LOCK_SUSPEND, "msm_etm"); |
| 949 | pm_qos_add_request(&etm_qos_req, PM_QOS_CPU_DMA_LATENCY, |
| 950 | PM_QOS_DEFAULT_VALUE); |
| 951 | |
| 952 | cpu_to_dump = next_cpu_to_dump = 0; |
| 953 | |
| 954 | pr_info("ETM/ETB intialized.\n"); |
| 955 | |
| 956 | if (trace_on_boot) |
| 957 | enable_trace(); |
| 958 | |
| 959 | return 0; |
| 960 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 961 | err1: |
| 962 | misc_deregister(&etm_dev); |
| 963 | return -ENOMEM; |
| 964 | } |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 965 | module_init(etm_init); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 966 | |
| 967 | static void __exit etm_exit(void) |
| 968 | { |
| 969 | disable_trace(); |
| 970 | pm_qos_remove_request(&etm_qos_req); |
| 971 | wake_lock_destroy(&etm_wake_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 972 | free_percpu(alloc_b); |
| 973 | misc_deregister(&etm_dev); |
| 974 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 975 | module_exit(etm_exit); |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 976 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 977 | MODULE_LICENSE("GPL v2"); |
| 978 | MODULE_DESCRIPTION("embedded trace driver"); |