Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010, 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 | /* |
| 14 | per-axi |
| 15 | DESCRIPTION |
| 16 | Functions related to AXI bus performance counter manipulations. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/io.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/proc_fs.h> |
| 24 | #include "asm/uaccess.h" |
| 25 | #include "per-axi.h" |
| 26 | #include "perf.h" |
| 27 | |
| 28 | /* |
| 29 | Definitions for AXI register addresses, macros to set and get register values |
| 30 | */ |
| 31 | #define AXI_BASE_SIZE 0x00004000 |
| 32 | #define AXI_REG_BASE (AXI_BASE + 0x00000000) |
| 33 | #define AXI_REG_BASE_PHYS 0xa8200000 |
| 34 | |
| 35 | #define __inpdw(port) ioread32(port) |
| 36 | #define in_dword_masked(addr, mask) (__inpdw(addr) & (mask)) |
| 37 | #define __outpdw(port, val) (iowrite32((uint32_t) (val), port)) |
| 38 | #define out_dword(addr, val) __outpdw(addr, val) |
| 39 | |
| 40 | #define HWIO_AXI_MONITOR_CYCLE_COUNT_UPPER_REG_ADDR \ |
| 41 | (AXI_REG_BASE + 0x00003434) |
| 42 | #define HWIO_AXI_MONITOR_CYCLE_COUNT_UPPER_REG_RMSK 0xffff |
| 43 | #define HWIO_AXI_MONITOR_CYCLE_COUNT_UPPER_REG_IN \ |
| 44 | in_dword_masked(HWIO_AXI_MONITOR_CYCLE_COUNT_UPPER_REG_ADDR, \ |
| 45 | HWIO_AXI_MONITOR_CYCLE_COUNT_UPPER_REG_RMSK) |
| 46 | |
| 47 | #define HWIO_AXI_MONITOR_CYCLE_COUNT_LOWER_REG_ADDR (AXI_REG_BASE + 0x00003438) |
| 48 | #define HWIO_AXI_MONITOR_CYCLE_COUNT_LOWER_REG_RMSK 0xffff |
| 49 | #define HWIO_AXI_MONITOR_CYCLE_COUNT_LOWER_REG_IN \ |
| 50 | in_dword_masked(HWIO_AXI_MONITOR_CYCLE_COUNT_LOWER_REG_ADDR, \ |
| 51 | HWIO_AXI_MONITOR_CYCLE_COUNT_LOWER_REG_RMSK) |
| 52 | |
| 53 | #define HWIO_AXI_MONITOR_SELECTION_REG0_ADDR (AXI_REG_BASE + 0x00003428) |
| 54 | #define HWIO_AXI_MONITOR_SELECTION_REG1_ADDR (AXI_REG_BASE + 0x0000342c) |
| 55 | #define HWIO_AXI_MONITOR_TENURE_SELECTION_REG_ADDR (AXI_REG_BASE + 0x00003430) |
| 56 | #define HWIO_AXI_MONITOR_SELECTION_REG0_ETC_BMSK 0x4000 |
| 57 | #define HWIO_AXI_MONITOR_SELECTION_REG0_ECC_BMSK 0x2000 |
| 58 | #define HWIO_AXI_MONITOR_SELECTION_REG0_EEC1_BMSK 0x800 |
| 59 | #define HWIO_AXI_MONITOR_SELECTION_REG0_EEC0_BMSK 0x200 |
| 60 | #define HWIO_AXI_MONITOR_CYCLE_COUNT_UPPER_REG_OUT(v) \ |
| 61 | out_dword(HWIO_AXI_MONITOR_CYCLE_COUNT_UPPER_REG_ADDR, v) |
| 62 | #define HWIO_AXI_MONITOR_CYCLE_COUNT_LOWER_REG_OUT(v) \ |
| 63 | out_dword(HWIO_AXI_MONITOR_CYCLE_COUNT_LOWER_REG_ADDR, v) |
| 64 | #define HWIO_AXI_MONITOR_SELECTION_REG0_OUT(v) \ |
| 65 | out_dword(HWIO_AXI_MONITOR_SELECTION_REG0_ADDR, v) |
| 66 | #define HWIO_AXI_MONITOR_SELECTION_REG1_OUT(v) \ |
| 67 | out_dword(HWIO_AXI_MONITOR_SELECTION_REG1_ADDR, v) |
| 68 | #define HWIO_AXI_MONITOR_TENURE_SELECTION_REG_OUT(v) \ |
| 69 | out_dword(HWIO_AXI_MONITOR_TENURE_SELECTION_REG_ADDR, v) |
| 70 | #define HWIO_AXI_MONITOR_SELECTION_REG0_RMSK 0xffff |
| 71 | #define HWIO_AXI_MONITOR_SELECTION_REG0_IN \ |
| 72 | in_dword_masked(HWIO_AXI_MONITOR_SELECTION_REG0_ADDR, \ |
| 73 | HWIO_AXI_MONITOR_SELECTION_REG0_RMSK) |
| 74 | |
| 75 | #define HWIO_AXI_CONFIGURATION_REG_ADDR (AXI_REG_BASE + 0x00000008) |
| 76 | #define HWIO_AXI_CONFIGURATION_REG_OUT(v) \ |
| 77 | out_dword(HWIO_AXI_CONFIGURATION_REG_ADDR, v) |
| 78 | #define HWIO_AXI_CONFIGURATION_REG_PPDM_BMSK 0x0 |
| 79 | #define HWIO_AXI_CONFIGURATION_REG_DISABLE 0x2 |
| 80 | #define AXI_EVTSEL_ENABLE_MASK 0x6a00 |
| 81 | #define AXI_EVTSEL_DISABLE_MASK 0x95ff |
| 82 | #define AXI_EVTSEL_RESET_MASK 0xfe40 |
| 83 | |
| 84 | #define HWIO_AXI_MONITOR_EVENT_LOWER_REG0_ADDR (AXI_REG_BASE + 0x00003450) |
| 85 | #define HWIO_AXI_MONITOR_EVENT_LOWER_REG0_RMSK 0xffff |
| 86 | #define HWIO_AXI_MONITOR_EVENT_LOWER_REG0_SHFT 0 |
| 87 | #define HWIO_AXI_MONITOR_EVENT_LOWER_REG0_IN \ |
| 88 | in_dword_masked(HWIO_AXI_MONITOR_EVENT_LOWER_REG0_ADDR, \ |
| 89 | HWIO_AXI_MONITOR_EVENT_LOWER_REG0_RMSK) |
| 90 | #define HWIO_AXI_MONITOR_EVENT_UPPER_REG0_ADDR (AXI_REG_BASE + 0x00003454) |
| 91 | #define HWIO_AXI_MONITOR_EVENT_UPPER_REG0_RMSK 0xffff |
| 92 | #define HWIO_AXI_MONITOR_EVENT_UPPER_REG0_SHFT 0 |
| 93 | #define HWIO_AXI_MONITOR_EVENT_UPPER_REG0_IN \ |
| 94 | in_dword_masked(HWIO_AXI_MONITOR_EVENT_UPPER_REG0_ADDR, \ |
| 95 | HWIO_AXI_MONITOR_EVENT_UPPER_REG0_RMSK) |
| 96 | |
| 97 | #define HWIO_AXI_MONITOR_EVENT_LOWER_REG1_ADDR (AXI_REG_BASE + 0x00003458) |
| 98 | #define HWIO_AXI_MONITOR_EVENT_LOWER_REG1_RMSK 0xffff |
| 99 | #define HWIO_AXI_MONITOR_EVENT_LOWER_REG1_SHFT 0 |
| 100 | #define HWIO_AXI_MONITOR_EVENT_LOWER_REG1_IN \ |
| 101 | in_dword_masked(HWIO_AXI_MONITOR_EVENT_LOWER_REG1_ADDR, \ |
| 102 | HWIO_AXI_MONITOR_EVENT_LOWER_REG1_RMSK) |
| 103 | #define HWIO_AXI_MONITOR_EVENT_UPPER_REG1_ADDR (AXI_REG_BASE + 0x0000345c) |
| 104 | #define HWIO_AXI_MONITOR_EVENT_UPPER_REG1_RMSK 0xffff |
| 105 | #define HWIO_AXI_MONITOR_EVENT_UPPER_REG1_SHFT 0 |
| 106 | #define HWIO_AXI_MONITOR_EVENT_UPPER_REG1_IN \ |
| 107 | in_dword_masked(HWIO_AXI_MONITOR_EVENT_UPPER_REG1_ADDR, \ |
| 108 | HWIO_AXI_MONITOR_EVENT_UPPER_REG1_RMSK) |
| 109 | |
| 110 | #define HWIO_AXI_MONITOR_TENURE_LOWER_REG_ADDR (AXI_REG_BASE + 0x00003448) |
| 111 | #define HWIO_AXI_MONITOR_TENURE_LOWER_REG_RMSK 0xffff |
| 112 | #define HWIO_AXI_MONITOR_TENURE_LOWER_REG_SHFT 0 |
| 113 | #define HWIO_AXI_MONITOR_TENURE_LOWER_REG_IN \ |
| 114 | in_dword_masked(HWIO_AXI_MONITOR_TENURE_LOWER_REG_ADDR, \ |
| 115 | HWIO_AXI_MONITOR_TENURE_LOWER_REG_RMSK) |
| 116 | #define HWIO_AXI_MONITOR_TENURE_UPPER_REG_ADDR (AXI_REG_BASE + 0x00003444) |
| 117 | #define HWIO_AXI_MONITOR_TENURE_UPPER_REG_RMSK 0xffff |
| 118 | #define HWIO_AXI_MONITOR_TENURE_UPPER_REG_SHFT 0 |
| 119 | #define HWIO_AXI_MONITOR_TENURE_UPPER_REG_IN \ |
| 120 | in_dword_masked(HWIO_AXI_MONITOR_TENURE_UPPER_REG_ADDR, \ |
| 121 | HWIO_AXI_MONITOR_TENURE_UPPER_REG_RMSK) |
| 122 | |
| 123 | #define HWIO_AXI_MONITOR_MIN_REG_ADDR (AXI_REG_BASE + 0x0000343c) |
| 124 | #define HWIO_AXI_MONITOR_MIN_REG_RMSK 0xffff |
| 125 | #define HWIO_AXI_MONITOR_MIN_REG_SHFT 0 |
| 126 | #define HWIO_AXI_MONITOR_MIN_REG_IN \ |
| 127 | in_dword_masked(HWIO_AXI_MONITOR_MIN_REG_ADDR, \ |
| 128 | HWIO_AXI_MONITOR_MIN_REG_RMSK) |
| 129 | #define HWIO_AXI_MONITOR_MAX_REG_ADDR (AXI_REG_BASE + 0x00003440) |
| 130 | #define HWIO_AXI_MONITOR_MAX_REG_RMSK 0xffff |
| 131 | #define HWIO_AXI_MONITOR_MAX_REG_SHFT 0 |
| 132 | #define HWIO_AXI_MONITOR_MAX_REG_IN \ |
| 133 | in_dword_masked(HWIO_AXI_MONITOR_MAX_REG_ADDR, \ |
| 134 | HWIO_AXI_MONITOR_MAX_REG_RMSK) |
| 135 | #define HWIO_AXI_MONITOR_LAST_TENURE_REG_ADDR (AXI_REG_BASE + 0x0000344c) |
| 136 | #define HWIO_AXI_MONITOR_LAST_TENURE_REG_RMSK 0xffff |
| 137 | #define HWIO_AXI_MONITOR_LAST_TENURE_REG_SHFT 0 |
| 138 | #define HWIO_AXI_MONITOR_LAST_TENURE_REG_IN \ |
| 139 | in_dword_masked(HWIO_AXI_MONITOR_LAST_TENURE_REG_ADDR, \ |
| 140 | HWIO_AXI_MONITOR_LAST_TENURE_REG_RMSK) |
| 141 | #define HWIO_AXI_MONITOR_TENURE_UPPER_REG_OUT(v) \ |
| 142 | out_dword(HWIO_AXI_MONITOR_TENURE_UPPER_REG_ADDR, v) |
| 143 | #define HWIO_AXI_MONITOR_TENURE_LOWER_REG_OUT(v) \ |
| 144 | out_dword(HWIO_AXI_MONITOR_TENURE_LOWER_REG_ADDR, v) |
| 145 | |
| 146 | #define HWIO_AXI_RESET_ALL 0x9400 |
| 147 | #define HWIO_AXI_ENABLE_ALL_NOCYCLES 0x4a00 |
| 148 | #define HWIO_AXI_DISABLE_ALL 0xb500 |
| 149 | uint32_t AXI_BASE; |
| 150 | |
| 151 | unsigned int is_first = 1; |
| 152 | struct perf_mon_axi_data pm_axi_info; |
| 153 | struct perf_mon_axi_cnts axi_cnts; |
| 154 | |
| 155 | /* |
| 156 | FUNCTION get_axi_sel_reg0 |
| 157 | |
| 158 | DESCRIPTION |
| 159 | Retrieve the value of AXI_SEL_REG0 |
| 160 | |
| 161 | DEPENDENCIES |
| 162 | |
| 163 | RETURN VALUE |
| 164 | AXI_SEL_REG0 |
| 165 | SIDE EFFECTS |
| 166 | */ |
| 167 | unsigned long get_axi_sel_reg0(void) |
| 168 | { |
| 169 | return pm_axi_info.sel_reg0; |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | FUNCTION get_axi_sel_reg1 |
| 174 | |
| 175 | DESCRIPTION |
| 176 | Retrieve the value of AXI_SEL_REG1 |
| 177 | |
| 178 | DEPENDENCIES |
| 179 | |
| 180 | RETURN VALUE |
| 181 | AXI_SEL_REG1 |
| 182 | SIDE EFFECTS |
| 183 | */ |
| 184 | unsigned long get_axi_sel_reg1(void) |
| 185 | { |
| 186 | return pm_axi_info.sel_reg1; |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | FUNCTION get_axi_ten_sel_reg |
| 191 | |
| 192 | DESCRIPTION |
| 193 | Retrieve the value of AXI_TEN_REG |
| 194 | |
| 195 | DEPENDENCIES |
| 196 | |
| 197 | RETURN VALUE |
| 198 | AXI_TEN_REG |
| 199 | SIDE EFFECTS |
| 200 | */ |
| 201 | unsigned long get_axi_ten_sel_reg(void) |
| 202 | { |
| 203 | return pm_axi_info.ten_sel_reg; |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | FUNCTION get_axi_valid |
| 208 | |
| 209 | DESCRIPTION |
| 210 | Retrieve the value of AXI valid bit |
| 211 | |
| 212 | DEPENDENCIES |
| 213 | |
| 214 | RETURN VALUE |
| 215 | AXI Valid bit |
| 216 | SIDE EFFECTS |
| 217 | */ |
| 218 | unsigned long get_axi_valid(void) |
| 219 | { |
| 220 | return pm_axi_info.valid; |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | FUNCTION get_axi_enable |
| 225 | |
| 226 | DESCRIPTION |
| 227 | Retrieve the value of AXI enable bit |
| 228 | |
| 229 | DEPENDENCIES |
| 230 | |
| 231 | RETURN VALUE |
| 232 | AXI enable bit |
| 233 | SIDE EFFECTS |
| 234 | */ |
| 235 | unsigned long get_axi_enable(void) |
| 236 | { |
| 237 | return pm_axi_info.enable; |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | FUNCTION get_axi_clear |
| 242 | |
| 243 | DESCRIPTION |
| 244 | Retrieve the value of AXI clear bit |
| 245 | |
| 246 | DEPENDENCIES |
| 247 | |
| 248 | RETURN VALUE |
| 249 | AXI clear bit |
| 250 | SIDE EFFECTS |
| 251 | */ |
| 252 | unsigned long get_axi_clear(void) |
| 253 | { |
| 254 | return pm_axi_info.clear; |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | FUNCTION pm_axi_cnts_write |
| 259 | |
| 260 | DESCRIPTION |
| 261 | Write handler for the /proc axi results directory. |
| 262 | |
| 263 | DEPENDENCIES |
| 264 | |
| 265 | RETURN VALUE |
| 266 | Number of characters to output. |
| 267 | |
| 268 | SIDE EFFECTS |
| 269 | */ |
| 270 | int pm_axi_cnts_write(struct file *file, const char *buff, |
| 271 | unsigned long cnt, void *data) |
| 272 | { |
| 273 | char *newbuf; |
| 274 | struct PerfMonAxiCnts *p = |
| 275 | (struct PerfMonAxiCnts *)data; |
| 276 | |
| 277 | if (p == 0) |
| 278 | return cnt; |
| 279 | /* |
| 280 | * Alloc the user data in kernel space. and then copy user to kernel |
| 281 | */ |
| 282 | newbuf = kmalloc(cnt + 1, GFP_KERNEL); |
| 283 | if (0 == newbuf) |
| 284 | return cnt; |
| 285 | if (copy_from_user(newbuf, buff, cnt) != 0) { |
| 286 | printk(KERN_INFO "%s copy_from_user failed\n", __func__); |
| 287 | return cnt; |
| 288 | } |
| 289 | return cnt; |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | FUNCTION pm_axi_update_cnts |
| 294 | |
| 295 | DESCRIPTION |
| 296 | Read the current AXI counter values. Check for overflows and |
| 297 | adjust the values stored accordingly. |
| 298 | |
| 299 | DEPENDENCIES |
| 300 | |
| 301 | RETURN VALUE |
| 302 | |
| 303 | SIDE EFFECTS |
| 304 | */ |
| 305 | void pm_axi_update_cnts(void) |
| 306 | { |
| 307 | if (is_first) { |
| 308 | pm_axi_start(); |
| 309 | } else { |
| 310 | if (pm_axi_info.valid == 1) { |
| 311 | pm_axi_info.valid = 0; |
| 312 | pm_axi_update(); |
| 313 | } else { |
| 314 | pm_axi_enable(); |
| 315 | } |
| 316 | } |
| 317 | is_first = 0; |
| 318 | axi_cnts.cycles += pm_get_axi_cycle_count(); |
| 319 | axi_cnts.cnt0 += pm_get_axi_evt0_count(); |
| 320 | axi_cnts.cnt1 += pm_get_axi_evt1_count(); |
| 321 | axi_cnts.tenure_total += pm_get_axi_ten_total_count(); |
| 322 | |
| 323 | axi_cnts.tenure_min = pm_get_axi_ten_min_count(); |
| 324 | axi_cnts.tenure_max = pm_get_axi_ten_max_count(); |
| 325 | axi_cnts.tenure_last = pm_get_axi_ten_last_count(); |
| 326 | |
| 327 | pm_axi_start(); |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | FUNCTION pm_axi_clear_cnts |
| 332 | |
| 333 | DESCRIPTION |
| 334 | Clear the locally stored AXI counter values. |
| 335 | Also clear the AXI counter registers. |
| 336 | |
| 337 | DEPENDENCIES |
| 338 | |
| 339 | RETURN VALUE |
| 340 | |
| 341 | SIDE EFFECTS |
| 342 | */ |
| 343 | void pm_axi_clear_cnts(void) |
| 344 | { |
| 345 | axi_cnts.cycles = 0; |
| 346 | axi_cnts.cnt0 = 0; |
| 347 | axi_cnts.cnt1 = 0; |
| 348 | axi_cnts.tenure_total = 0; |
| 349 | axi_cnts.tenure_min = 0; |
| 350 | axi_cnts.tenure_max = 0; |
| 351 | axi_cnts.tenure_last = 0; |
| 352 | pm_axi_start(); |
| 353 | } |
| 354 | |
| 355 | /* |
| 356 | FUNCTION pm_axi_read_decimal |
| 357 | |
| 358 | DESCRIPTION |
| 359 | Read handler for the /proc axi results directory in decimal format. |
| 360 | |
| 361 | DEPENDENCIES |
| 362 | |
| 363 | RETURN VALUE |
| 364 | Number of characters to output. |
| 365 | |
| 366 | SIDE EFFECTS |
| 367 | */ |
| 368 | int pm_axi_read_decimal(char *page, char **start, off_t off, int count, |
| 369 | int *eof, void *data) |
| 370 | { |
| 371 | struct perf_mon_axi_cnts *p = (struct perf_mon_axi_cnts *)data; |
| 372 | |
| 373 | return sprintf(page, "cnt0:%llu cnt1:%llu tenure:%llu ten_max:%llu \ |
| 374 | ten_min:%llu ten_last:%llu cycles:%llu\n", |
| 375 | p->cnt0, |
| 376 | p->cnt1, |
| 377 | p->tenure_total, |
| 378 | p->tenure_max, |
| 379 | p->tenure_min, |
| 380 | p->tenure_last, |
| 381 | p->cycles); |
| 382 | } |
| 383 | |
| 384 | /* |
| 385 | FUNCTION pm_axi_read_hex |
| 386 | |
| 387 | DESCRIPTION |
| 388 | Read handler for the /proc axi results directory in hex format. |
| 389 | |
| 390 | DEPENDENCIES |
| 391 | |
| 392 | RETURN VALUE |
| 393 | Number of characters to output. |
| 394 | |
| 395 | SIDE EFFECTS |
| 396 | */ |
| 397 | int pm_axi_read_hex(char *page, char **start, off_t off, int count, |
| 398 | int *eof, void *data) |
| 399 | { |
| 400 | struct perf_mon_axi_cnts *p = (struct perf_mon_axi_cnts *)data; |
| 401 | |
| 402 | return sprintf(page, "cnt0:%llx cnt1:%llx tenure:%llx ten_max:%llx \ |
| 403 | ten_min:%llx ten_last:%llx cycles:%llx\n", |
| 404 | p->cnt0, |
| 405 | p->cnt1, |
| 406 | p->tenure_total, |
| 407 | p->tenure_max, |
| 408 | p->tenure_min, |
| 409 | p->tenure_last, |
| 410 | p->cycles); |
| 411 | |
| 412 | } |
| 413 | |
| 414 | /* |
| 415 | FUNCTION pm_axi_set_proc_entry |
| 416 | |
| 417 | DESCRIPTION |
| 418 | Create a generic entry for the /proc axi settings directory. |
| 419 | |
| 420 | DEPENDENCIES |
| 421 | |
| 422 | RETURN VALUE |
| 423 | |
| 424 | SIDE EFFECTS |
| 425 | */ |
| 426 | void pm_axi_set_proc_entry(char *name, unsigned long *var, |
| 427 | struct proc_dir_entry *d, int hex) |
| 428 | { |
| 429 | struct proc_dir_entry *pe; |
| 430 | pe = create_proc_entry(name, 0777, d); |
| 431 | if (0 == pe) |
| 432 | return; |
| 433 | if (hex) { |
| 434 | pe->read_proc = per_process_read; |
| 435 | pe->write_proc = per_process_write_hex; |
| 436 | } else { |
| 437 | pe->read_proc = per_process_read_decimal; |
| 438 | pe->write_proc = per_process_write_dec; |
| 439 | } |
| 440 | pe->data = (void *)var; |
| 441 | } |
| 442 | |
| 443 | /* |
| 444 | FUNCTION pm_axi_get_cnt_proc_entry |
| 445 | |
| 446 | DESCRIPTION |
| 447 | Create a generic entry for the /proc axi results directory. |
| 448 | |
| 449 | DEPENDENCIES |
| 450 | |
| 451 | RETURN VALUE |
| 452 | |
| 453 | SIDE EFFECTS |
| 454 | */ |
| 455 | void pm_axi_get_cnt_proc_entry(char *name, struct perf_mon_axi_cnts *var, |
| 456 | struct proc_dir_entry *d, int hex) |
| 457 | { |
| 458 | struct proc_dir_entry *pe; |
| 459 | pe = create_proc_entry(name, 0777, d); |
| 460 | if (0 == pe) |
| 461 | return; |
| 462 | if (hex) { |
| 463 | pe->read_proc = pm_axi_read_hex; |
| 464 | pe->write_proc = pm_axi_cnts_write; |
| 465 | } else { |
| 466 | pe->read_proc = pm_axi_read_decimal; |
| 467 | pe->write_proc = pm_axi_cnts_write; |
| 468 | } |
| 469 | pe->data = (void *)var; |
| 470 | } |
| 471 | |
| 472 | /* |
| 473 | FUNCTION pm_axi_clear_tenure |
| 474 | |
| 475 | DESCRIPTION |
| 476 | Clear AXI tenure cntr manually. Temporary solution till hardware bug |
| 477 | is fixed |
| 478 | |
| 479 | DEPENDENCIES |
| 480 | |
| 481 | RETURN VALUE |
| 482 | |
| 483 | SIDE EFFECTS |
| 484 | */ |
| 485 | void pm_axi_clear_tenure(void) |
| 486 | { |
| 487 | HWIO_AXI_MONITOR_TENURE_UPPER_REG_OUT(0x0); |
| 488 | HWIO_AXI_MONITOR_TENURE_LOWER_REG_OUT(0x0); |
| 489 | } |
| 490 | |
| 491 | /* |
| 492 | FUNCTION pm_axi_init |
| 493 | |
| 494 | DESCRIPTION |
| 495 | Map AXI region to virtual memory. |
| 496 | |
| 497 | DEPENDENCIES |
| 498 | |
| 499 | RETURN VALUE |
| 500 | |
| 501 | SIDE EFFECTS |
| 502 | */ |
| 503 | void pm_axi_init() |
| 504 | { |
| 505 | /*Map the AXI regs*/ |
| 506 | #ifdef CONFIG_ARCH_QSD8X50 |
| 507 | { |
| 508 | /*Map the AXI regs*/ |
| 509 | AXI_BASE = (uint32_t)ioremap(AXI_REG_BASE_PHYS, AXI_BASE_SIZE); |
| 510 | if (!AXI_BASE) |
| 511 | printk(KERN_ERR "Mem map failed\n"); |
| 512 | } |
| 513 | #else |
| 514 | { |
| 515 | AXI_BASE = (uint32_t)kmalloc(AXI_BASE_SIZE, GFP_KERNEL); |
| 516 | } |
| 517 | #endif |
| 518 | |
| 519 | } |
| 520 | |
| 521 | /* |
| 522 | FUNCTION pm_axi_start |
| 523 | |
| 524 | DESCRIPTION |
| 525 | Set event0, event1 and tenure registers based on the /proc entries. |
| 526 | Set cycle cntr to fffffffe to start counters. |
| 527 | |
| 528 | DEPENDENCIES |
| 529 | |
| 530 | RETURN VALUE |
| 531 | |
| 532 | SIDE EFFECTS |
| 533 | */ |
| 534 | void |
| 535 | pm_axi_start() |
| 536 | { |
| 537 | unsigned long sel_reg0, sel_reg1, ten_sel_reg; |
| 538 | sel_reg0 = get_axi_sel_reg0(); |
| 539 | sel_reg1 = get_axi_sel_reg1(); |
| 540 | ten_sel_reg = get_axi_ten_sel_reg(); |
| 541 | HWIO_AXI_CONFIGURATION_REG_OUT(HWIO_AXI_CONFIGURATION_REG_PPDM_BMSK); |
| 542 | /*Set AXI Cycle Counter to enable AXI Monitors*/ |
| 543 | HWIO_AXI_MONITOR_CYCLE_COUNT_UPPER_REG_OUT(0xffff); |
| 544 | HWIO_AXI_MONITOR_CYCLE_COUNT_LOWER_REG_OUT(0xfffe); |
| 545 | /*Set master/slave*/ |
| 546 | HWIO_AXI_MONITOR_SELECTION_REG1_OUT(sel_reg1); |
| 547 | HWIO_AXI_MONITOR_SELECTION_REG0_OUT(HWIO_AXI_RESET_ALL); |
| 548 | HWIO_AXI_MONITOR_SELECTION_REG0_OUT(HWIO_AXI_ENABLE_ALL_NOCYCLES); |
| 549 | HWIO_AXI_MONITOR_SELECTION_REG0_OUT(HWIO_AXI_MONITOR_SELECTION_REG0_IN |
| 550 | | sel_reg0); |
| 551 | HWIO_AXI_MONITOR_SELECTION_REG0_OUT(HWIO_AXI_MONITOR_SELECTION_REG0_IN |
| 552 | | HWIO_AXI_MONITOR_SELECTION_REG0_ECC_BMSK); |
| 553 | HWIO_AXI_CONFIGURATION_REG_OUT(HWIO_AXI_CONFIGURATION_REG_PPDM_BMSK); |
| 554 | } |
| 555 | |
| 556 | /* |
| 557 | FUNCTION pm_axi_update |
| 558 | |
| 559 | DESCRIPTION |
| 560 | Set event0, event1 and tenure registers based on the /proc entries. |
| 561 | |
| 562 | DEPENDENCIES |
| 563 | |
| 564 | RETURN VALUE |
| 565 | |
| 566 | SIDE EFFECTS |
| 567 | */ |
| 568 | void |
| 569 | pm_axi_update() |
| 570 | { |
| 571 | HWIO_AXI_CONFIGURATION_REG_OUT(HWIO_AXI_CONFIGURATION_REG_PPDM_BMSK); |
| 572 | HWIO_AXI_MONITOR_SELECTION_REG0_OUT(HWIO_AXI_MONITOR_SELECTION_REG0_IN |
| 573 | | HWIO_AXI_RESET_ALL); |
| 574 | HWIO_AXI_MONITOR_SELECTION_REG0_OUT(HWIO_AXI_MONITOR_SELECTION_REG0_IN |
| 575 | & HWIO_AXI_DISABLE_ALL); |
| 576 | pm_axi_start(); |
| 577 | } |
| 578 | |
| 579 | /* |
| 580 | FUNCTION pm_axi_disable |
| 581 | |
| 582 | DESCRIPTION |
| 583 | Disable all cntrs. |
| 584 | |
| 585 | DEPENDENCIES |
| 586 | |
| 587 | RETURN VALUE |
| 588 | |
| 589 | SIDE EFFECTS |
| 590 | */ |
| 591 | void |
| 592 | pm_axi_disable(void) |
| 593 | { |
| 594 | unsigned long sel_reg0; |
| 595 | /*Disable cntrs*/ |
| 596 | sel_reg0 = get_axi_sel_reg0(); |
| 597 | HWIO_AXI_MONITOR_SELECTION_REG0_OUT(sel_reg0 & AXI_EVTSEL_DISABLE_MASK); |
| 598 | /*Disable clk*/ |
| 599 | HWIO_AXI_CONFIGURATION_REG_OUT(HWIO_AXI_CONFIGURATION_REG_DISABLE); |
| 600 | } |
| 601 | |
| 602 | /* |
| 603 | FUNCTION pm_axi_enable |
| 604 | |
| 605 | DESCRIPTION |
| 606 | Enable all cntrs. |
| 607 | |
| 608 | DEPENDENCIES |
| 609 | |
| 610 | RETURN VALUE |
| 611 | |
| 612 | SIDE EFFECTS |
| 613 | */ |
| 614 | void |
| 615 | pm_axi_enable(void) |
| 616 | { |
| 617 | unsigned long sel_reg0; |
| 618 | /*Enable cntrs*/ |
| 619 | sel_reg0 = get_axi_sel_reg0(); |
| 620 | HWIO_AXI_MONITOR_SELECTION_REG0_OUT(sel_reg0 | 0x6a00); |
| 621 | /*Enable clk*/ |
| 622 | HWIO_AXI_CONFIGURATION_REG_OUT(HWIO_AXI_CONFIGURATION_REG_PPDM_BMSK); |
| 623 | } |
| 624 | |
| 625 | /* |
| 626 | FUNCTION pm_axi_disable_cnts |
| 627 | |
| 628 | DESCRIPTION |
| 629 | Read cycle cntr value |
| 630 | |
| 631 | DEPENDENCIES |
| 632 | |
| 633 | RETURN VALUE |
| 634 | |
| 635 | SIDE EFFECTS |
| 636 | */ |
| 637 | unsigned long |
| 638 | pm_get_axi_cycle_count(void) |
| 639 | { |
| 640 | if (HWIO_AXI_MONITOR_CYCLE_COUNT_UPPER_REG_IN == 0x0 && |
| 641 | HWIO_AXI_MONITOR_CYCLE_COUNT_LOWER_REG_IN == 0x0) { |
| 642 | /*Set AXI Cycle Counter to enable AXI Monitors*/ |
| 643 | HWIO_AXI_MONITOR_CYCLE_COUNT_UPPER_REG_OUT(0xffff); |
| 644 | HWIO_AXI_MONITOR_CYCLE_COUNT_LOWER_REG_OUT(0xfffe); |
| 645 | } |
| 646 | return 0xfffffffe - ((HWIO_AXI_MONITOR_CYCLE_COUNT_UPPER_REG_IN << 16) |
| 647 | + HWIO_AXI_MONITOR_CYCLE_COUNT_LOWER_REG_IN); |
| 648 | } |
| 649 | |
| 650 | /* |
| 651 | FUNCTION pm_get_axi_evt0_count |
| 652 | |
| 653 | DESCRIPTION |
| 654 | Read Event0 cntr value |
| 655 | |
| 656 | DEPENDENCIES |
| 657 | |
| 658 | RETURN VALUE |
| 659 | |
| 660 | SIDE EFFECTS |
| 661 | */ |
| 662 | unsigned long |
| 663 | pm_get_axi_evt0_count(void) |
| 664 | { |
| 665 | return (HWIO_AXI_MONITOR_EVENT_UPPER_REG0_IN << 16) |
| 666 | + HWIO_AXI_MONITOR_EVENT_LOWER_REG0_IN; |
| 667 | } |
| 668 | |
| 669 | /* |
| 670 | FUNCTION pm_get_axi_evt1_count |
| 671 | |
| 672 | DESCRIPTION |
| 673 | Read Event1 cntr value |
| 674 | |
| 675 | DEPENDENCIES |
| 676 | |
| 677 | RETURN VALUE |
| 678 | |
| 679 | SIDE EFFECTS |
| 680 | */ |
| 681 | unsigned long |
| 682 | pm_get_axi_evt1_count(void) |
| 683 | { |
| 684 | return (HWIO_AXI_MONITOR_EVENT_UPPER_REG1_IN << 16) |
| 685 | + HWIO_AXI_MONITOR_EVENT_LOWER_REG1_IN; |
| 686 | } |
| 687 | |
| 688 | /* |
| 689 | FUNCTION pm_get_axi_ten_min_count |
| 690 | |
| 691 | DESCRIPTION |
| 692 | Read min tenure cntr value |
| 693 | |
| 694 | DEPENDENCIES |
| 695 | |
| 696 | RETURN VALUE |
| 697 | |
| 698 | SIDE EFFECTS |
| 699 | */ |
| 700 | unsigned long |
| 701 | pm_get_axi_ten_min_count(void) |
| 702 | { |
| 703 | return HWIO_AXI_MONITOR_MIN_REG_IN; |
| 704 | } |
| 705 | |
| 706 | /* |
| 707 | FUNCTION pm_get_axi_ten_max_count |
| 708 | |
| 709 | DESCRIPTION |
| 710 | Read max tenure cntr value |
| 711 | |
| 712 | DEPENDENCIES |
| 713 | |
| 714 | RETURN VALUE |
| 715 | |
| 716 | SIDE EFFECTS |
| 717 | */ |
| 718 | unsigned long |
| 719 | pm_get_axi_ten_max_count(void) |
| 720 | { |
| 721 | return HWIO_AXI_MONITOR_MAX_REG_IN; |
| 722 | } |
| 723 | |
| 724 | /* |
| 725 | FUNCTION pm_get_axi_ten_total_count |
| 726 | |
| 727 | DESCRIPTION |
| 728 | Read total tenure cntr value |
| 729 | |
| 730 | DEPENDENCIES |
| 731 | |
| 732 | RETURN VALUE |
| 733 | |
| 734 | SIDE EFFECTS |
| 735 | */ |
| 736 | unsigned long |
| 737 | pm_get_axi_ten_total_count(void) |
| 738 | { |
| 739 | return (HWIO_AXI_MONITOR_TENURE_UPPER_REG_IN << 16) |
| 740 | + HWIO_AXI_MONITOR_TENURE_LOWER_REG_IN; |
| 741 | } |
| 742 | |
| 743 | /* |
| 744 | FUNCTION pm_get_axi_ten_last_count |
| 745 | |
| 746 | DESCRIPTION |
| 747 | Read last tenure cntr value |
| 748 | |
| 749 | DEPENDENCIES |
| 750 | |
| 751 | RETURN VALUE |
| 752 | |
| 753 | SIDE EFFECTS |
| 754 | */ |
| 755 | unsigned long |
| 756 | pm_get_axi_ten_last_count(void) |
| 757 | { |
| 758 | return HWIO_AXI_MONITOR_LAST_TENURE_REG_IN; |
| 759 | } |