Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2002,2008-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 | |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/debugfs.h> |
| 16 | #include <linux/uaccess.h> |
| 17 | #include <linux/io.h> |
| 18 | |
| 19 | #include "kgsl.h" |
| 20 | #include "adreno_postmortem.h" |
| 21 | #include "adreno.h" |
| 22 | |
Jeremy Gebben | eebc461 | 2011-08-31 10:15:21 -0700 | [diff] [blame] | 23 | #include "a2xx_reg.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 24 | |
| 25 | unsigned int kgsl_cff_dump_enable; |
| 26 | int kgsl_pm_regs_enabled; |
| 27 | |
| 28 | static uint32_t kgsl_ib_base; |
| 29 | static uint32_t kgsl_ib_size; |
| 30 | |
| 31 | static struct dentry *pm_d_debugfs; |
| 32 | |
| 33 | static int pm_dump_set(void *data, u64 val) |
| 34 | { |
| 35 | struct kgsl_device *device = data; |
| 36 | |
| 37 | if (val) { |
| 38 | mutex_lock(&device->mutex); |
| 39 | adreno_postmortem_dump(device, 1); |
| 40 | mutex_unlock(&device->mutex); |
| 41 | } |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | DEFINE_SIMPLE_ATTRIBUTE(pm_dump_fops, |
| 47 | NULL, |
| 48 | pm_dump_set, "%llu\n"); |
| 49 | |
| 50 | static int pm_regs_enabled_set(void *data, u64 val) |
| 51 | { |
| 52 | kgsl_pm_regs_enabled = val ? 1 : 0; |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static int pm_regs_enabled_get(void *data, u64 *val) |
| 57 | { |
| 58 | *val = kgsl_pm_regs_enabled; |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | DEFINE_SIMPLE_ATTRIBUTE(pm_regs_enabled_fops, |
| 63 | pm_regs_enabled_get, |
| 64 | pm_regs_enabled_set, "%llu\n"); |
| 65 | |
| 66 | |
| 67 | static int kgsl_cff_dump_enable_set(void *data, u64 val) |
| 68 | { |
| 69 | #ifdef CONFIG_MSM_KGSL_CFF_DUMP |
| 70 | kgsl_cff_dump_enable = (val != 0); |
| 71 | return 0; |
| 72 | #else |
| 73 | return -EINVAL; |
| 74 | #endif |
| 75 | } |
| 76 | |
| 77 | static int kgsl_cff_dump_enable_get(void *data, u64 *val) |
| 78 | { |
| 79 | *val = kgsl_cff_dump_enable; |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | DEFINE_SIMPLE_ATTRIBUTE(kgsl_cff_dump_enable_fops, kgsl_cff_dump_enable_get, |
| 84 | kgsl_cff_dump_enable_set, "%llu\n"); |
| 85 | |
| 86 | static int kgsl_dbgfs_open(struct inode *inode, struct file *file) |
| 87 | { |
| 88 | file->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE); |
| 89 | file->private_data = inode->i_private; |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | static int kgsl_dbgfs_release(struct inode *inode, struct file *file) |
| 94 | { |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static int kgsl_hex_dump(const char *prefix, int c, uint8_t *data, |
| 99 | int rowc, int linec, char __user *buff) |
| 100 | { |
| 101 | int ss; |
| 102 | /* Prefix of 20 chars max, 32 bytes per row, in groups of four - that's |
| 103 | * 8 groups at 8 chars per group plus a space, plus new-line, plus |
| 104 | * ending character */ |
| 105 | char linebuf[20 + 64 + 1 + 1]; |
| 106 | |
| 107 | ss = snprintf(linebuf, sizeof(linebuf), prefix, c); |
| 108 | hex_dump_to_buffer(data, linec, rowc, 4, linebuf+ss, |
| 109 | sizeof(linebuf)-ss, 0); |
Tarun Karra | 44cbeb7 | 2011-08-18 13:30:24 -0700 | [diff] [blame] | 110 | strlcat(linebuf, "\n", sizeof(linebuf)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 111 | linebuf[sizeof(linebuf)-1] = 0; |
| 112 | ss = strlen(linebuf); |
| 113 | if (copy_to_user(buff, linebuf, ss+1)) |
| 114 | return -EFAULT; |
| 115 | return ss; |
| 116 | } |
| 117 | |
| 118 | static ssize_t kgsl_ib_dump_read( |
| 119 | struct file *file, |
| 120 | char __user *buff, |
| 121 | size_t buff_count, |
| 122 | loff_t *ppos) |
| 123 | { |
| 124 | int i, count = kgsl_ib_size, remaining, pos = 0, tot = 0, ss; |
| 125 | struct kgsl_device *device = file->private_data; |
| 126 | const int rowc = 32; |
| 127 | unsigned int pt_base, ib_memsize; |
| 128 | uint8_t *base_addr; |
| 129 | char linebuf[80]; |
| 130 | |
| 131 | if (!ppos || !device || !kgsl_ib_base) |
| 132 | return 0; |
| 133 | |
| 134 | kgsl_regread(device, MH_MMU_PT_BASE, &pt_base); |
| 135 | base_addr = kgsl_sharedmem_convertaddr(device, pt_base, kgsl_ib_base, |
| 136 | &ib_memsize); |
| 137 | |
| 138 | if (!base_addr) |
| 139 | return 0; |
| 140 | |
| 141 | pr_info("%s ppos=%ld, buff_count=%d, count=%d\n", __func__, (long)*ppos, |
| 142 | buff_count, count); |
| 143 | ss = snprintf(linebuf, sizeof(linebuf), "IB: base=%08x(%08x" |
| 144 | "), size=%d, memsize=%d\n", kgsl_ib_base, |
| 145 | (uint32_t)base_addr, kgsl_ib_size, ib_memsize); |
| 146 | if (*ppos == 0) { |
| 147 | if (copy_to_user(buff, linebuf, ss+1)) |
| 148 | return -EFAULT; |
| 149 | tot += ss; |
| 150 | buff += ss; |
| 151 | *ppos += ss; |
| 152 | } |
| 153 | pos += ss; |
| 154 | remaining = count; |
| 155 | for (i = 0; i < count; i += rowc) { |
| 156 | int linec = min(remaining, rowc); |
| 157 | |
| 158 | remaining -= rowc; |
| 159 | ss = kgsl_hex_dump("IB: %05x: ", i, base_addr, rowc, linec, |
| 160 | buff); |
| 161 | if (ss < 0) |
| 162 | return ss; |
| 163 | |
| 164 | if (pos >= *ppos) { |
| 165 | if (tot+ss >= buff_count) { |
| 166 | ss = copy_to_user(buff, "", 1); |
| 167 | return tot; |
| 168 | } |
| 169 | tot += ss; |
| 170 | buff += ss; |
| 171 | *ppos += ss; |
| 172 | } |
| 173 | pos += ss; |
| 174 | base_addr += linec; |
| 175 | } |
| 176 | |
| 177 | return tot; |
| 178 | } |
| 179 | |
| 180 | static ssize_t kgsl_ib_dump_write( |
| 181 | struct file *file, |
| 182 | const char __user *buff, |
| 183 | size_t count, |
| 184 | loff_t *ppos) |
| 185 | { |
| 186 | char local_buff[64]; |
| 187 | |
| 188 | if (count >= sizeof(local_buff)) |
| 189 | return -EFAULT; |
| 190 | |
| 191 | if (copy_from_user(local_buff, buff, count)) |
| 192 | return -EFAULT; |
| 193 | |
| 194 | local_buff[count] = 0; /* end of string */ |
| 195 | sscanf(local_buff, "%x %d", &kgsl_ib_base, &kgsl_ib_size); |
| 196 | |
| 197 | pr_info("%s: base=%08X size=%d\n", __func__, kgsl_ib_base, |
| 198 | kgsl_ib_size); |
| 199 | |
| 200 | return count; |
| 201 | } |
| 202 | |
| 203 | static const struct file_operations kgsl_ib_dump_fops = { |
| 204 | .open = kgsl_dbgfs_open, |
| 205 | .release = kgsl_dbgfs_release, |
| 206 | .read = kgsl_ib_dump_read, |
| 207 | .write = kgsl_ib_dump_write, |
| 208 | }; |
| 209 | |
| 210 | static int kgsl_regread_nolock(struct kgsl_device *device, |
| 211 | unsigned int offsetwords, unsigned int *value) |
| 212 | { |
| 213 | unsigned int *reg; |
| 214 | |
| 215 | if (offsetwords*sizeof(uint32_t) >= device->regspace.sizebytes) { |
| 216 | KGSL_DRV_ERR(device, "invalid offset %d\n", offsetwords); |
| 217 | return -ERANGE; |
| 218 | } |
| 219 | |
| 220 | reg = (unsigned int *)(device->regspace.mmio_virt_base |
| 221 | + (offsetwords << 2)); |
| 222 | *value = __raw_readl(reg); |
| 223 | return 0; |
| 224 | } |
| 225 | |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame^] | 226 | #define ADRENO_ISTORE_START 0x5000 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 227 | static ssize_t kgsl_istore_read( |
| 228 | struct file *file, |
| 229 | char __user *buff, |
| 230 | size_t buff_count, |
| 231 | loff_t *ppos) |
| 232 | { |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame^] | 233 | int i, count, remaining, pos = 0, tot = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 234 | struct kgsl_device *device = file->private_data; |
| 235 | const int rowc = 8; |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame^] | 236 | struct adreno_device *adreno_dev; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 237 | |
| 238 | if (!ppos || !device) |
| 239 | return 0; |
| 240 | |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame^] | 241 | adreno_dev = ADRENO_DEVICE(device); |
| 242 | count = adreno_dev->istore_size * ADRENO_ISTORE_WORDS; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 243 | remaining = count; |
| 244 | for (i = 0; i < count; i += rowc) { |
| 245 | unsigned int vals[rowc]; |
| 246 | int j, ss; |
| 247 | int linec = min(remaining, rowc); |
| 248 | remaining -= rowc; |
| 249 | |
| 250 | if (pos >= *ppos) { |
| 251 | for (j = 0; j < linec; ++j) |
| 252 | kgsl_regread_nolock(device, |
Jeremy Gebben | ddf6b57 | 2011-09-09 13:39:49 -0700 | [diff] [blame^] | 253 | ADRENO_ISTORE_START + i + j, |
| 254 | vals + j); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 255 | } else |
| 256 | memset(vals, 0, sizeof(vals)); |
| 257 | |
| 258 | ss = kgsl_hex_dump("IS: %04x: ", i, (uint8_t *)vals, rowc*4, |
| 259 | linec*4, buff); |
| 260 | if (ss < 0) |
| 261 | return ss; |
| 262 | |
| 263 | if (pos >= *ppos) { |
| 264 | if (tot+ss >= buff_count) |
| 265 | return tot; |
| 266 | tot += ss; |
| 267 | buff += ss; |
| 268 | *ppos += ss; |
| 269 | } |
| 270 | pos += ss; |
| 271 | } |
| 272 | |
| 273 | return tot; |
| 274 | } |
| 275 | |
| 276 | static const struct file_operations kgsl_istore_fops = { |
| 277 | .open = kgsl_dbgfs_open, |
| 278 | .release = kgsl_dbgfs_release, |
| 279 | .read = kgsl_istore_read, |
| 280 | .llseek = default_llseek, |
| 281 | }; |
| 282 | |
| 283 | typedef void (*reg_read_init_t)(struct kgsl_device *device); |
| 284 | typedef void (*reg_read_fill_t)(struct kgsl_device *device, int i, |
| 285 | unsigned int *vals, int linec); |
| 286 | static ssize_t kgsl_reg_read(struct kgsl_device *device, int count, |
| 287 | reg_read_init_t reg_read_init, |
| 288 | reg_read_fill_t reg_read_fill, const char *prefix, char __user *buff, |
| 289 | loff_t *ppos) |
| 290 | { |
| 291 | int i, remaining; |
| 292 | const int rowc = 8; |
| 293 | |
| 294 | if (!ppos || *ppos || !device) |
| 295 | return 0; |
| 296 | |
| 297 | mutex_lock(&device->mutex); |
| 298 | reg_read_init(device); |
| 299 | remaining = count; |
| 300 | for (i = 0; i < count; i += rowc) { |
| 301 | unsigned int vals[rowc]; |
| 302 | int ss; |
| 303 | int linec = min(remaining, rowc); |
| 304 | remaining -= rowc; |
| 305 | |
| 306 | reg_read_fill(device, i, vals, linec); |
| 307 | ss = kgsl_hex_dump(prefix, i, (uint8_t *)vals, rowc*4, linec*4, |
| 308 | buff); |
| 309 | if (ss < 0) { |
| 310 | mutex_unlock(&device->mutex); |
| 311 | return ss; |
| 312 | } |
| 313 | buff += ss; |
| 314 | *ppos += ss; |
| 315 | } |
| 316 | mutex_unlock(&device->mutex); |
| 317 | |
| 318 | return *ppos; |
| 319 | } |
| 320 | |
| 321 | |
| 322 | static void kgsl_sx_reg_read_init(struct kgsl_device *device) |
| 323 | { |
| 324 | kgsl_regwrite(device, REG_RBBM_PM_OVERRIDE2, 0xFF); |
| 325 | kgsl_regwrite(device, REG_RBBM_DEBUG_CNTL, 0); |
| 326 | } |
| 327 | |
| 328 | static void kgsl_sx_reg_read_fill(struct kgsl_device *device, int i, |
| 329 | unsigned int *vals, int linec) |
| 330 | { |
| 331 | int j; |
| 332 | |
| 333 | for (j = 0; j < linec; ++j) { |
| 334 | kgsl_regwrite(device, REG_RBBM_DEBUG_CNTL, 0x1B00 | i); |
| 335 | kgsl_regread(device, REG_RBBM_DEBUG_OUT, vals+j); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | static ssize_t kgsl_sx_debug_read( |
| 340 | struct file *file, |
| 341 | char __user *buff, |
| 342 | size_t buff_count, |
| 343 | loff_t *ppos) |
| 344 | { |
| 345 | struct kgsl_device *device = file->private_data; |
| 346 | return kgsl_reg_read(device, 0x1B, kgsl_sx_reg_read_init, |
| 347 | kgsl_sx_reg_read_fill, "SX: %02x: ", buff, ppos); |
| 348 | } |
| 349 | |
| 350 | static const struct file_operations kgsl_sx_debug_fops = { |
| 351 | .open = kgsl_dbgfs_open, |
| 352 | .release = kgsl_dbgfs_release, |
| 353 | .read = kgsl_sx_debug_read, |
| 354 | }; |
| 355 | |
| 356 | static void kgsl_cp_reg_read_init(struct kgsl_device *device) |
| 357 | { |
| 358 | kgsl_regwrite(device, REG_RBBM_DEBUG_CNTL, 0); |
| 359 | } |
| 360 | |
| 361 | static void kgsl_cp_reg_read_fill(struct kgsl_device *device, int i, |
| 362 | unsigned int *vals, int linec) |
| 363 | { |
| 364 | int j; |
| 365 | |
| 366 | for (j = 0; j < linec; ++j) { |
| 367 | kgsl_regwrite(device, REG_RBBM_DEBUG_CNTL, 0x1628); |
| 368 | kgsl_regread(device, REG_RBBM_DEBUG_OUT, vals+j); |
| 369 | msleep(100); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | static ssize_t kgsl_cp_debug_read( |
| 374 | struct file *file, |
| 375 | char __user *buff, |
| 376 | size_t buff_count, |
| 377 | loff_t *ppos) |
| 378 | { |
| 379 | struct kgsl_device *device = file->private_data; |
| 380 | return kgsl_reg_read(device, 20, kgsl_cp_reg_read_init, |
| 381 | kgsl_cp_reg_read_fill, |
| 382 | "CP: %02x: ", buff, ppos); |
| 383 | } |
| 384 | |
| 385 | static const struct file_operations kgsl_cp_debug_fops = { |
| 386 | .open = kgsl_dbgfs_open, |
| 387 | .release = kgsl_dbgfs_release, |
| 388 | .read = kgsl_cp_debug_read, |
| 389 | }; |
| 390 | |
| 391 | static void kgsl_mh_reg_read_init(struct kgsl_device *device) |
| 392 | { |
| 393 | kgsl_regwrite(device, REG_RBBM_DEBUG_CNTL, 0); |
| 394 | } |
| 395 | |
| 396 | static void kgsl_mh_reg_read_fill(struct kgsl_device *device, int i, |
| 397 | unsigned int *vals, int linec) |
| 398 | { |
| 399 | int j; |
| 400 | |
| 401 | for (j = 0; j < linec; ++j) { |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 402 | kgsl_regwrite(device, MH_DEBUG_CTRL, i+j); |
| 403 | kgsl_regread(device, MH_DEBUG_DATA, vals+j); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
| 407 | static ssize_t kgsl_mh_debug_read( |
| 408 | struct file *file, |
| 409 | char __user *buff, |
| 410 | size_t buff_count, |
| 411 | loff_t *ppos) |
| 412 | { |
| 413 | struct kgsl_device *device = file->private_data; |
| 414 | return kgsl_reg_read(device, 0x40, kgsl_mh_reg_read_init, |
| 415 | kgsl_mh_reg_read_fill, |
| 416 | "MH: %02x: ", buff, ppos); |
| 417 | } |
| 418 | |
| 419 | static const struct file_operations kgsl_mh_debug_fops = { |
| 420 | .open = kgsl_dbgfs_open, |
| 421 | .release = kgsl_dbgfs_release, |
| 422 | .read = kgsl_mh_debug_read, |
| 423 | }; |
| 424 | |
| 425 | void adreno_debugfs_init(struct kgsl_device *device) |
| 426 | { |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 427 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 428 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 429 | if (!device->d_debugfs || IS_ERR(device->d_debugfs)) |
| 430 | return; |
| 431 | |
| 432 | debugfs_create_file("ib_dump", 0600, device->d_debugfs, device, |
| 433 | &kgsl_ib_dump_fops); |
| 434 | debugfs_create_file("istore", 0400, device->d_debugfs, device, |
| 435 | &kgsl_istore_fops); |
| 436 | debugfs_create_file("sx_debug", 0400, device->d_debugfs, device, |
| 437 | &kgsl_sx_debug_fops); |
| 438 | debugfs_create_file("cp_debug", 0400, device->d_debugfs, device, |
| 439 | &kgsl_cp_debug_fops); |
| 440 | debugfs_create_file("mh_debug", 0400, device->d_debugfs, device, |
| 441 | &kgsl_mh_debug_fops); |
| 442 | debugfs_create_file("cff_dump", 0644, device->d_debugfs, device, |
| 443 | &kgsl_cff_dump_enable_fops); |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 444 | debugfs_create_u32("wait_timeout", 0644, device->d_debugfs, |
| 445 | &adreno_dev->wait_timeout); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 446 | |
| 447 | /* Create post mortem control files */ |
| 448 | |
| 449 | pm_d_debugfs = debugfs_create_dir("postmortem", device->d_debugfs); |
| 450 | |
| 451 | if (IS_ERR(pm_d_debugfs)) |
| 452 | return; |
| 453 | |
| 454 | debugfs_create_file("dump", 0600, pm_d_debugfs, device, |
| 455 | &pm_dump_fops); |
| 456 | debugfs_create_file("regs_enabled", 0644, pm_d_debugfs, device, |
| 457 | &pm_regs_enabled_fops); |
| 458 | } |