gpu: pvr: move debugfs infrastructure to its own files
authorLuc Verhaegen <libv@codethink.co.uk>
Tue, 22 Mar 2011 11:38:33 +0000 (12:38 +0100)
committerGrazvydas Ignotas <notasas@gmail.com>
Sun, 20 May 2012 18:43:03 +0000 (21:43 +0300)
pvr_debug.* originally only provided some contrived code (which needs
sanitation) to do debug printing.

Future HW Recovery code will also be using debugfs and it makes sense
to lump all of them together in pvr_debugfs.*

Signed-off-by: Luc Verhaegen <libv@codethink.co.uk>
Signed-off-by: Imre Deak <imre.deak@nokia.com>
pvr/Makefile
pvr/module.c
pvr/pvr_debug.c
pvr/pvr_debug.h
pvr/pvr_debugfs.c [new file with mode: 0644]
pvr/pvr_debugfs.h [new file with mode: 0644]

index 4b20e00..2603208 100644 (file)
@@ -14,7 +14,7 @@ pvrsrvkm-objs         := osfunc.o mmap.o module.o pdump.o proc.o         \
                           pvr_events.o
 
 pvrsrvkm-objs-$(CONFIG_PVR_DEBUG) += pvr_debug.o
-pvrsrvkm-objs-$(CONFIG_DEBUG_FS) += pvr_debug.o
+pvrsrvkm-objs-$(CONFIG_DEBUG_FS) += pvr_debugfs.o
 pvrsrvkm-objs-$(CONFIG_PVR_TIMING) += pvr_debug.o
 
 pvrsrvkm-objs          += $(pvrsrvkm-objs-y) $(pvrsrvkm-objs-m)
index d94efe6..7543579 100644 (file)
 #include "private_data.h"
 #include "pvr_events.h"
 
+#ifdef CONFIG_DEBUG_FS
+#include "pvr_debugfs.h"
+#endif
+
 #define DRVNAME                "pvrsrvkm"
 
 #ifdef CONFIG_PVR_DEBUG_EXTRA
@@ -234,6 +238,10 @@ static int __init pvr_init(void)
        PVRDebugSetLevel(debug);
 #endif
 
+#ifdef CONFIG_DEBUG_FS
+       pvr_debugfs_init();
+#endif
+
        error = CreateProcEntries();
        if (error < 0)
                goto err1;
@@ -283,6 +291,9 @@ static void __exit pvr_cleanup(void)
 
        PVR_TRACE("pvr_cleanup: unloading");
 
+#ifdef CONFIG_DEBUG_FS
+       pvr_debugfs_cleanup();
+#endif
        pvr_dbg_cleanup();
 }
 
index 1c89499..116c6ea 100644 (file)
  *
  ******************************************************************************/
 
-#include <linux/io.h>
 #include <linux/uaccess.h>
 #include <linux/kernel.h>
 #include <linux/hardirq.h>
 #include <linux/module.h>
 #include <linux/spinlock.h>
-#include <linux/tty.h>
-#include <linux/debugfs.h>
-#include <linux/vmalloc.h>
 
-#include <stdarg.h>
 #include "img_types.h"
 #include "servicesext.h"
 #include "pvr_debug.h"
 #include "proc.h"
-#include "syscommon.h"
-#include "sgxinfokm.h"
-#include "sgxutils.h"
-#include "pvr_bridge_km.h"
 
 #ifdef CONFIG_PVR_DEBUG
 
@@ -257,171 +248,15 @@ int PVRDebugProcGetLevel(char *page, char **start, off_t off, int count,
 
 #endif
 
-#ifdef CONFIG_DEBUG_FS
-
-static struct dentry *debugfs_dir;
-static u32 pvr_reset;
-
-static struct PVRSRV_DEVICE_NODE *get_sgx_node(void)
-{
-       struct SYS_DATA *sysdata;
-       struct PVRSRV_DEVICE_NODE *node;
-
-       if (SysAcquireData(&sysdata) != PVRSRV_OK)
-               return NULL;
-
-       for (node = sysdata->psDeviceNodeList; node; node = node->psNext)
-               if (node->sDevId.eDeviceType == PVRSRV_DEVICE_TYPE_SGX)
-                       break;
-
-       return node;
-}
-
-static int pvr_dbg_reset(void *data, u64 val)
-{
-       struct PVRSRV_DEVICE_NODE *node;
-       enum PVRSRV_ERROR err;
-       int r = 0;
-
-       if (val != 1)
-               return 0;
-
-       pvr_lock();
-
-       if (pvr_is_disabled()) {
-               r = -ENODEV;
-               goto exit;
-       }
-
-       node = get_sgx_node();
-       if (!node) {
-               r =  -ENODEV;
-               goto exit;
-       }
-
-       err = PVRSRVSetDevicePowerStateKM(node->sDevId.ui32DeviceIndex,
-                                            PVRSRV_POWER_STATE_D0);
-       if (err != PVRSRV_OK) {
-               r = -EIO;
-               goto exit;
-       }
-
-       HWRecoveryResetSGX(node);
-
-       SGXTestActivePowerEvent(node);
-exit:
-       pvr_unlock();
-
-       return r;
-}
-
-static int pvr_dbg_set(void *data, u64 val)
-{
-       u32 *var = data;
-
-       if (var == &pvr_reset)
-               return pvr_dbg_reset(data, val);
-
-       BUG();
-}
-
-DEFINE_SIMPLE_ATTRIBUTE(pvr_dbg_fops, NULL, pvr_dbg_set, "%llu\n");
-
-struct edm_buf_info {
-       size_t len;
-       char data[1];
-};
-
-static int pvr_dbg_edm_open(struct inode *inode, struct file *file)
-{
-       struct PVRSRV_DEVICE_NODE *node;
-       struct PVRSRV_SGXDEV_INFO *sgx_info;
-       struct edm_buf_info *bi;
-       size_t size;
-
-       /* Take a snapshot of the EDM trace buffer */
-       size = SGXMK_TRACE_BUFFER_SIZE * SGXMK_TRACE_BUF_STR_LEN;
-       bi = vmalloc(sizeof(*bi) + size);
-       if (!bi)
-               return -ENOMEM;
-
-       node = get_sgx_node();
-       sgx_info = node->pvDevice;
-       bi->len = snprint_edm_trace(sgx_info, bi->data, size);
-       file->private_data = bi;
-
-       return 0;
-}
-
-static int pvr_dbg_edm_release(struct inode *inode, struct file *file)
-{
-       vfree(file->private_data);
-
-       return 0;
-}
-
-static ssize_t pvr_dbg_edm_read(struct file *file, char __user *buffer,
-                               size_t count, loff_t *ppos)
-{
-       struct edm_buf_info *bi = file->private_data;
-
-       return simple_read_from_buffer(buffer, count, ppos, bi->data, bi->len);
-}
-
-static const struct file_operations pvr_dbg_edm_fops = {
-       .owner          = THIS_MODULE,
-       .open           = pvr_dbg_edm_open,
-       .read           = pvr_dbg_edm_read,
-       .release        = pvr_dbg_edm_release,
-};
-
-static int pvr_init_debugfs(void)
-{
-       debugfs_dir = debugfs_create_dir("pvr", NULL);
-       if (!debugfs_dir)
-               return -ENODEV;
-
-       if (!debugfs_create_file("reset_sgx", S_IWUGO, debugfs_dir, &pvr_reset,
-                                &pvr_dbg_fops)) {
-               debugfs_remove(debugfs_dir);
-               return -ENODEV;
-       }
-
-       if (!debugfs_create_file("edm_trace", S_IRUGO, debugfs_dir, NULL,
-                                &pvr_dbg_edm_fops)) {
-               debugfs_remove_recursive(debugfs_dir);
-               return -ENODEV;
-       }
-
-       return 0;
-}
-
-static void pvr_cleanup_debugfs(void)
-{
-       debugfs_remove_recursive(debugfs_dir);
-}
-
-#else          /* !CONFIG_DEBUG_FS */
-
-static int pvr_init_debugfs(void)
-{
-       return 0;
-}
-
-static void pvr_cleanup_debugfs(void) { }
-
-#endif
-
 void pvr_dbg_init(void)
 {
 #if defined(CONFIG_PVR_DEBUG) || defined(TIMING)
        mutex_init(&gsDebugMutexNonIRQ);
 #endif
-       pvr_init_debugfs();
 }
 
 void pvr_dbg_cleanup(void)
 {
-       pvr_cleanup_debugfs();
+
 }
 
index 4bad9c4..a886a8c 100644 (file)
@@ -102,7 +102,7 @@ void PVRSRVTrace(const char *pszFormat, ...);
 
 #endif         /* CONFIG_PVR_DEBUG */
 
-#if defined(CONFIG_PVR_DEBUG) || defined(TIMING) || defined(CONFIG_DEBUG_FS)
+#if defined(CONFIG_PVR_DEBUG) || defined(TIMING)
 
 void pvr_dbg_init(void);
 void pvr_dbg_cleanup(void);
diff --git a/pvr/pvr_debugfs.c b/pvr/pvr_debugfs.c
new file mode 100644 (file)
index 0000000..1dfebca
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 2010-2011 Imre Deak <imre.deak@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ *
+ * Debugfs interface living in pvr/ subdirectory.
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/debugfs.h>
+#include <linux/vmalloc.h>
+
+#include "img_types.h"
+#include "servicesext.h"
+#include "services.h"
+#include "sgxinfokm.h"
+#include "syscommon.h"
+#include "pvr_bridge_km.h"
+#include "sgxutils.h"
+#include "pvr_debugfs.h"
+
+static struct dentry *debugfs_dir;
+static u32 pvr_reset;
+
+/*
+ *
+ */
+static struct PVRSRV_DEVICE_NODE *get_sgx_node(void)
+{
+       struct SYS_DATA *sysdata;
+       struct PVRSRV_DEVICE_NODE *node;
+
+       if (SysAcquireData(&sysdata) != PVRSRV_OK)
+               return NULL;
+
+       for (node = sysdata->psDeviceNodeList; node; node = node->psNext)
+               if (node->sDevId.eDeviceType == PVRSRV_DEVICE_TYPE_SGX)
+                       break;
+
+       return node;
+}
+
+static int pvr_debugfs_reset(void *data, u64 val)
+{
+       struct PVRSRV_DEVICE_NODE *node;
+       enum PVRSRV_ERROR err;
+       int r = 0;
+
+       if (val != 1)
+               return 0;
+
+       pvr_lock();
+
+       if (pvr_is_disabled()) {
+               r = -ENODEV;
+               goto exit;
+       }
+
+       node = get_sgx_node();
+       if (!node) {
+               r =  -ENODEV;
+               goto exit;
+       }
+
+       err = PVRSRVSetDevicePowerStateKM(node->sDevId.ui32DeviceIndex,
+                                         PVRSRV_POWER_STATE_D0);
+       if (err != PVRSRV_OK) {
+               r = -EIO;
+               goto exit;
+       }
+
+       HWRecoveryResetSGX(node);
+
+       SGXTestActivePowerEvent(node);
+exit:
+       pvr_unlock();
+
+       return r;
+}
+
+static int pvr_debugfs_set(void *data, u64 val)
+{
+       u32 *var = data;
+
+       if (var == &pvr_reset)
+               return pvr_debugfs_reset(data, val);
+
+       BUG();
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(pvr_debugfs_fops, NULL, pvr_debugfs_set, "%llu\n");
+
+/*
+ *
+ */
+struct edm_buf_info {
+       size_t len;
+       char data[1];
+};
+
+static int pvr_debugfs_edm_open(struct inode *inode, struct file *file)
+{
+       struct PVRSRV_DEVICE_NODE *node;
+       struct PVRSRV_SGXDEV_INFO *sgx_info;
+       struct edm_buf_info *bi;
+       size_t size;
+
+       /* Take a snapshot of the EDM trace buffer */
+       size = SGXMK_TRACE_BUFFER_SIZE * SGXMK_TRACE_BUF_STR_LEN;
+       bi = vmalloc(sizeof(*bi) + size);
+       if (!bi)
+               return -ENOMEM;
+
+       node = get_sgx_node();
+       sgx_info = node->pvDevice;
+       bi->len = snprint_edm_trace(sgx_info, bi->data, size);
+       file->private_data = bi;
+
+       return 0;
+}
+
+static int pvr_debugfs_edm_release(struct inode *inode, struct file *file)
+{
+       vfree(file->private_data);
+
+       return 0;
+}
+
+static ssize_t pvr_debugfs_edm_read(struct file *file, char __user *buffer,
+                               size_t count, loff_t *ppos)
+{
+       struct edm_buf_info *bi = file->private_data;
+
+       return simple_read_from_buffer(buffer, count, ppos, bi->data, bi->len);
+}
+
+static const struct file_operations pvr_debugfs_edm_fops = {
+       .owner          = THIS_MODULE,
+       .open           = pvr_debugfs_edm_open,
+       .read           = pvr_debugfs_edm_read,
+       .release        = pvr_debugfs_edm_release,
+};
+
+
+/*
+ *
+ */
+int pvr_debugfs_init(void)
+{
+       debugfs_dir = debugfs_create_dir("pvr", NULL);
+       if (!debugfs_dir)
+               return -ENODEV;
+
+       if (!debugfs_create_file("reset_sgx", S_IWUSR, debugfs_dir, &pvr_reset,
+                                &pvr_debugfs_fops)) {
+               debugfs_remove(debugfs_dir);
+               return -ENODEV;
+       }
+
+       if (!debugfs_create_file("edm_trace", S_IRUGO, debugfs_dir, NULL,
+                                &pvr_debugfs_edm_fops)) {
+               debugfs_remove_recursive(debugfs_dir);
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+void pvr_debugfs_cleanup(void)
+{
+       debugfs_remove_recursive(debugfs_dir);
+}
diff --git a/pvr/pvr_debugfs.h b/pvr/pvr_debugfs.h
new file mode 100644 (file)
index 0000000..6adc51b
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2010-2011 Imre Deak <imre.deak@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _PVR_DEBUGFS_H_
+#define _PVR_DEBUGFS_H_ 1
+
+#ifndef CONFIG_DEBUG_FS
+#error Error: debugfs header included but CONFIG_DEBUG_FS is not defined!
+#endif
+
+int pvr_debugfs_init(void);
+void pvr_debugfs_cleanup(void);
+
+#endif /* _PVR_DEBUGFS_H_ */