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 | |
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; |
| 25 | |
| 26 | static inline int kgsl_log_set(unsigned int *log_val, void *data, u64 val) |
| 27 | { |
| 28 | *log_val = min((unsigned int)val, (unsigned int)KGSL_LOG_LEVEL_MAX); |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | #define KGSL_DEBUGFS_LOG(__log) \ |
| 33 | static int __log ## _set(void *data, u64 val) \ |
| 34 | { \ |
| 35 | struct kgsl_device *device = data; \ |
| 36 | return kgsl_log_set(&device->__log, data, val); \ |
| 37 | } \ |
| 38 | static int __log ## _get(void *data, u64 *val) \ |
| 39 | { \ |
| 40 | struct kgsl_device *device = data; \ |
| 41 | *val = device->__log; \ |
| 42 | return 0; \ |
| 43 | } \ |
| 44 | DEFINE_SIMPLE_ATTRIBUTE(__log ## _fops, \ |
| 45 | __log ## _get, __log ## _set, "%llu\n"); \ |
| 46 | |
| 47 | KGSL_DEBUGFS_LOG(drv_log); |
| 48 | KGSL_DEBUGFS_LOG(cmd_log); |
| 49 | KGSL_DEBUGFS_LOG(ctxt_log); |
| 50 | KGSL_DEBUGFS_LOG(mem_log); |
| 51 | KGSL_DEBUGFS_LOG(pwr_log); |
| 52 | |
| 53 | void kgsl_device_debugfs_init(struct kgsl_device *device) |
| 54 | { |
| 55 | if (kgsl_debugfs_dir && !IS_ERR(kgsl_debugfs_dir)) |
| 56 | device->d_debugfs = debugfs_create_dir(device->name, |
| 57 | kgsl_debugfs_dir); |
| 58 | |
| 59 | if (!device->d_debugfs || IS_ERR(device->d_debugfs)) |
| 60 | return; |
| 61 | |
| 62 | device->cmd_log = KGSL_LOG_LEVEL_DEFAULT; |
| 63 | device->ctxt_log = KGSL_LOG_LEVEL_DEFAULT; |
| 64 | device->drv_log = KGSL_LOG_LEVEL_DEFAULT; |
| 65 | device->mem_log = KGSL_LOG_LEVEL_DEFAULT; |
| 66 | device->pwr_log = KGSL_LOG_LEVEL_DEFAULT; |
| 67 | |
| 68 | debugfs_create_file("log_level_cmd", 0644, device->d_debugfs, device, |
| 69 | &cmd_log_fops); |
| 70 | debugfs_create_file("log_level_ctxt", 0644, device->d_debugfs, device, |
| 71 | &ctxt_log_fops); |
| 72 | debugfs_create_file("log_level_drv", 0644, device->d_debugfs, device, |
| 73 | &drv_log_fops); |
| 74 | debugfs_create_file("log_level_mem", 0644, device->d_debugfs, device, |
| 75 | &mem_log_fops); |
| 76 | debugfs_create_file("log_level_pwr", 0644, device->d_debugfs, device, |
| 77 | &pwr_log_fops); |
| 78 | } |
| 79 | |
| 80 | void kgsl_core_debugfs_init(void) |
| 81 | { |
| 82 | kgsl_debugfs_dir = debugfs_create_dir("kgsl", 0); |
| 83 | } |
Jordan Crouse | d8f1c6b | 2011-10-04 09:31:29 -0600 | [diff] [blame] | 84 | |
| 85 | void kgsl_core_debugfs_close(void) |
| 86 | { |
| 87 | debugfs_remove_recursive(kgsl_debugfs_dir); |
| 88 | } |