Home | History | Annotate | Line # | Download | only in qxl
      1  1.2  riastrad /*	$NetBSD: qxl_debugfs.c,v 1.3 2021/12/18 23:45:42 riastradh Exp $	*/
      2  1.2  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright (C) 2009 Red Hat <bskeggs (at) redhat.com>
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining
      7  1.1  riastrad  * a copy of this software and associated documentation files (the
      8  1.1  riastrad  * "Software"), to deal in the Software without restriction, including
      9  1.1  riastrad  * without limitation the rights to use, copy, modify, merge, publish,
     10  1.1  riastrad  * distribute, sublicense, and/or sell copies of the Software, and to
     11  1.1  riastrad  * permit persons to whom the Software is furnished to do so, subject to
     12  1.1  riastrad  * the following conditions:
     13  1.1  riastrad  *
     14  1.1  riastrad  * The above copyright notice and this permission notice (including the
     15  1.1  riastrad  * next paragraph) shall be included in all copies or substantial
     16  1.1  riastrad  * portions of the Software.
     17  1.1  riastrad  *
     18  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     19  1.1  riastrad  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     20  1.1  riastrad  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     21  1.1  riastrad  * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
     22  1.1  riastrad  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     23  1.1  riastrad  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     24  1.1  riastrad  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     25  1.1  riastrad  *
     26  1.1  riastrad  */
     27  1.1  riastrad 
     28  1.1  riastrad /*
     29  1.1  riastrad  * Authors:
     30  1.1  riastrad  *  Alon Levy <alevy (at) redhat.com>
     31  1.1  riastrad  */
     32  1.1  riastrad 
     33  1.2  riastrad #include <sys/cdefs.h>
     34  1.2  riastrad __KERNEL_RCSID(0, "$NetBSD: qxl_debugfs.c,v 1.3 2021/12/18 23:45:42 riastradh Exp $");
     35  1.2  riastrad 
     36  1.3  riastrad #include <drm/drm_debugfs.h>
     37  1.3  riastrad #include <drm/drm_file.h>
     38  1.1  riastrad 
     39  1.1  riastrad #include "qxl_drv.h"
     40  1.1  riastrad #include "qxl_object.h"
     41  1.1  riastrad 
     42  1.1  riastrad #if defined(CONFIG_DEBUG_FS)
     43  1.1  riastrad static int
     44  1.1  riastrad qxl_debugfs_irq_received(struct seq_file *m, void *data)
     45  1.1  riastrad {
     46  1.1  riastrad 	struct drm_info_node *node = (struct drm_info_node *) m->private;
     47  1.1  riastrad 	struct qxl_device *qdev = node->minor->dev->dev_private;
     48  1.1  riastrad 
     49  1.1  riastrad 	seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
     50  1.1  riastrad 	seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
     51  1.1  riastrad 	seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
     52  1.1  riastrad 	seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
     53  1.1  riastrad 	seq_printf(m, "%d\n", qdev->irq_received_error);
     54  1.1  riastrad 	return 0;
     55  1.1  riastrad }
     56  1.1  riastrad 
     57  1.1  riastrad static int
     58  1.1  riastrad qxl_debugfs_buffers_info(struct seq_file *m, void *data)
     59  1.1  riastrad {
     60  1.1  riastrad 	struct drm_info_node *node = (struct drm_info_node *) m->private;
     61  1.1  riastrad 	struct qxl_device *qdev = node->minor->dev->dev_private;
     62  1.1  riastrad 	struct qxl_bo *bo;
     63  1.1  riastrad 
     64  1.1  riastrad 	list_for_each_entry(bo, &qdev->gem.objects, list) {
     65  1.3  riastrad 		struct dma_resv_list *fobj;
     66  1.2  riastrad 		int rel;
     67  1.2  riastrad 
     68  1.2  riastrad 		rcu_read_lock();
     69  1.3  riastrad 		fobj = rcu_dereference(bo->tbo.base.resv->fence);
     70  1.2  riastrad 		rel = fobj ? fobj->shared_count : 0;
     71  1.2  riastrad 		rcu_read_unlock();
     72  1.2  riastrad 
     73  1.2  riastrad 		seq_printf(m, "size %ld, pc %d, num releases %d\n",
     74  1.3  riastrad 			   (unsigned long)bo->tbo.base.size,
     75  1.2  riastrad 			   bo->pin_count, rel);
     76  1.1  riastrad 	}
     77  1.1  riastrad 	return 0;
     78  1.1  riastrad }
     79  1.1  riastrad 
     80  1.1  riastrad static struct drm_info_list qxl_debugfs_list[] = {
     81  1.1  riastrad 	{ "irq_received", qxl_debugfs_irq_received, 0, NULL },
     82  1.1  riastrad 	{ "qxl_buffers", qxl_debugfs_buffers_info, 0, NULL },
     83  1.1  riastrad };
     84  1.1  riastrad #define QXL_DEBUGFS_ENTRIES ARRAY_SIZE(qxl_debugfs_list)
     85  1.1  riastrad #endif
     86  1.1  riastrad 
     87  1.1  riastrad int
     88  1.1  riastrad qxl_debugfs_init(struct drm_minor *minor)
     89  1.1  riastrad {
     90  1.1  riastrad #if defined(CONFIG_DEBUG_FS)
     91  1.3  riastrad 	int r;
     92  1.3  riastrad 	struct qxl_device *dev =
     93  1.3  riastrad 		(struct qxl_device *) minor->dev->dev_private;
     94  1.3  riastrad 
     95  1.1  riastrad 	drm_debugfs_create_files(qxl_debugfs_list, QXL_DEBUGFS_ENTRIES,
     96  1.1  riastrad 				 minor->debugfs_root, minor);
     97  1.3  riastrad 
     98  1.3  riastrad 	r = qxl_ttm_debugfs_init(dev);
     99  1.3  riastrad 	if (r) {
    100  1.3  riastrad 		DRM_ERROR("Failed to init TTM debugfs\n");
    101  1.3  riastrad 		return r;
    102  1.3  riastrad 	}
    103  1.1  riastrad #endif
    104  1.1  riastrad 	return 0;
    105  1.1  riastrad }
    106  1.1  riastrad 
    107  1.1  riastrad int qxl_debugfs_add_files(struct qxl_device *qdev,
    108  1.1  riastrad 			  struct drm_info_list *files,
    109  1.3  riastrad 			  unsigned int nfiles)
    110  1.1  riastrad {
    111  1.3  riastrad 	unsigned int i;
    112  1.1  riastrad 
    113  1.1  riastrad 	for (i = 0; i < qdev->debugfs_count; i++) {
    114  1.1  riastrad 		if (qdev->debugfs[i].files == files) {
    115  1.1  riastrad 			/* Already registered */
    116  1.1  riastrad 			return 0;
    117  1.1  riastrad 		}
    118  1.1  riastrad 	}
    119  1.1  riastrad 
    120  1.1  riastrad 	i = qdev->debugfs_count + 1;
    121  1.1  riastrad 	if (i > QXL_DEBUGFS_MAX_COMPONENTS) {
    122  1.1  riastrad 		DRM_ERROR("Reached maximum number of debugfs components.\n");
    123  1.1  riastrad 		DRM_ERROR("Report so we increase QXL_DEBUGFS_MAX_COMPONENTS.\n");
    124  1.1  riastrad 		return -EINVAL;
    125  1.1  riastrad 	}
    126  1.1  riastrad 	qdev->debugfs[qdev->debugfs_count].files = files;
    127  1.1  riastrad 	qdev->debugfs[qdev->debugfs_count].num_files = nfiles;
    128  1.1  riastrad 	qdev->debugfs_count = i;
    129  1.1  riastrad #if defined(CONFIG_DEBUG_FS)
    130  1.1  riastrad 	drm_debugfs_create_files(files, nfiles,
    131  1.3  riastrad 				 qdev->ddev.primary->debugfs_root,
    132  1.3  riastrad 				 qdev->ddev.primary);
    133  1.1  riastrad #endif
    134  1.1  riastrad 	return 0;
    135  1.1  riastrad }
    136