Harsh Vardhan Dwivedi | 715fb83 | 2012-05-18 00:24:18 -0600 | [diff] [blame^] | 1 | /* Copyright (c) 2002,2008-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -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 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 15 | #include <linux/debugfs.h> |
| 16 | |
| 17 | #include "kgsl.h" |
| 18 | #include "kgsl_device.h" |
| 19 | |
| 20 | /*default log levels is error for everything*/ |
| 21 | #define KGSL_LOG_LEVEL_DEFAULT 3 |
| 22 | #define KGSL_LOG_LEVEL_MAX 7 |
| 23 | |
| 24 | struct dentry *kgsl_debugfs_dir; |
Harsh Vardhan Dwivedi | 715fb83 | 2012-05-18 00:24:18 -0600 | [diff] [blame^] | 25 | static struct dentry *pm_d_debugfs; |
| 26 | |
| 27 | static int pm_dump_set(void *data, u64 val) |
| 28 | { |
| 29 | struct kgsl_device *device = data; |
| 30 | |
| 31 | if (val) { |
| 32 | mutex_lock(&device->mutex); |
| 33 | kgsl_postmortem_dump(device, 1); |
| 34 | mutex_unlock(&device->mutex); |
| 35 | } |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | DEFINE_SIMPLE_ATTRIBUTE(pm_dump_fops, |
| 40 | NULL, |
| 41 | pm_dump_set, "%llu\n"); |
| 42 | |
| 43 | static int pm_regs_enabled_set(void *data, u64 val) |
| 44 | { |
| 45 | struct kgsl_device *device = data; |
| 46 | device->pm_regs_enabled = val ? 1 : 0; |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static int pm_regs_enabled_get(void *data, u64 *val) |
| 51 | { |
| 52 | struct kgsl_device *device = data; |
| 53 | *val = device->pm_regs_enabled; |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | static int pm_ib_enabled_set(void *data, u64 val) |
| 58 | { |
| 59 | struct kgsl_device *device = data; |
| 60 | device->pm_ib_enabled = val ? 1 : 0; |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int pm_ib_enabled_get(void *data, u64 *val) |
| 65 | { |
| 66 | struct kgsl_device *device = data; |
| 67 | *val = device->pm_ib_enabled; |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | |
| 72 | DEFINE_SIMPLE_ATTRIBUTE(pm_regs_enabled_fops, |
| 73 | pm_regs_enabled_get, |
| 74 | pm_regs_enabled_set, "%llu\n"); |
| 75 | |
| 76 | DEFINE_SIMPLE_ATTRIBUTE(pm_ib_enabled_fops, |
| 77 | pm_ib_enabled_get, |
| 78 | pm_ib_enabled_set, "%llu\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 79 | |
| 80 | static inline int kgsl_log_set(unsigned int *log_val, void *data, u64 val) |
| 81 | { |
| 82 | *log_val = min((unsigned int)val, (unsigned int)KGSL_LOG_LEVEL_MAX); |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | #define KGSL_DEBUGFS_LOG(__log) \ |
| 87 | static int __log ## _set(void *data, u64 val) \ |
| 88 | { \ |
| 89 | struct kgsl_device *device = data; \ |
| 90 | return kgsl_log_set(&device->__log, data, val); \ |
| 91 | } \ |
| 92 | static int __log ## _get(void *data, u64 *val) \ |
| 93 | { \ |
| 94 | struct kgsl_device *device = data; \ |
| 95 | *val = device->__log; \ |
| 96 | return 0; \ |
| 97 | } \ |
| 98 | DEFINE_SIMPLE_ATTRIBUTE(__log ## _fops, \ |
| 99 | __log ## _get, __log ## _set, "%llu\n"); \ |
| 100 | |
| 101 | KGSL_DEBUGFS_LOG(drv_log); |
| 102 | KGSL_DEBUGFS_LOG(cmd_log); |
| 103 | KGSL_DEBUGFS_LOG(ctxt_log); |
| 104 | KGSL_DEBUGFS_LOG(mem_log); |
| 105 | KGSL_DEBUGFS_LOG(pwr_log); |
| 106 | |
| 107 | void kgsl_device_debugfs_init(struct kgsl_device *device) |
| 108 | { |
| 109 | if (kgsl_debugfs_dir && !IS_ERR(kgsl_debugfs_dir)) |
| 110 | device->d_debugfs = debugfs_create_dir(device->name, |
| 111 | kgsl_debugfs_dir); |
| 112 | |
| 113 | if (!device->d_debugfs || IS_ERR(device->d_debugfs)) |
| 114 | return; |
| 115 | |
| 116 | device->cmd_log = KGSL_LOG_LEVEL_DEFAULT; |
| 117 | device->ctxt_log = KGSL_LOG_LEVEL_DEFAULT; |
| 118 | device->drv_log = KGSL_LOG_LEVEL_DEFAULT; |
| 119 | device->mem_log = KGSL_LOG_LEVEL_DEFAULT; |
| 120 | device->pwr_log = KGSL_LOG_LEVEL_DEFAULT; |
| 121 | |
| 122 | debugfs_create_file("log_level_cmd", 0644, device->d_debugfs, device, |
| 123 | &cmd_log_fops); |
| 124 | debugfs_create_file("log_level_ctxt", 0644, device->d_debugfs, device, |
| 125 | &ctxt_log_fops); |
| 126 | debugfs_create_file("log_level_drv", 0644, device->d_debugfs, device, |
| 127 | &drv_log_fops); |
| 128 | debugfs_create_file("log_level_mem", 0644, device->d_debugfs, device, |
| 129 | &mem_log_fops); |
| 130 | debugfs_create_file("log_level_pwr", 0644, device->d_debugfs, device, |
| 131 | &pwr_log_fops); |
Harsh Vardhan Dwivedi | 715fb83 | 2012-05-18 00:24:18 -0600 | [diff] [blame^] | 132 | |
| 133 | /* Create postmortem dump control files */ |
| 134 | |
| 135 | pm_d_debugfs = debugfs_create_dir("postmortem", device->d_debugfs); |
| 136 | |
| 137 | if (IS_ERR(pm_d_debugfs)) |
| 138 | return; |
| 139 | |
| 140 | debugfs_create_file("dump", 0600, pm_d_debugfs, device, |
| 141 | &pm_dump_fops); |
| 142 | debugfs_create_file("regs_enabled", 0644, pm_d_debugfs, device, |
| 143 | &pm_regs_enabled_fops); |
| 144 | debugfs_create_file("ib_enabled", 0644, pm_d_debugfs, device, |
| 145 | &pm_ib_enabled_fops); |
| 146 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void kgsl_core_debugfs_init(void) |
| 150 | { |
| 151 | kgsl_debugfs_dir = debugfs_create_dir("kgsl", 0); |
| 152 | } |
Jordan Crouse | d8f1c6b | 2011-10-04 09:31:29 -0600 | [diff] [blame] | 153 | |
| 154 | void kgsl_core_debugfs_close(void) |
| 155 | { |
| 156 | debugfs_remove_recursive(kgsl_debugfs_dir); |
| 157 | } |