162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright (C) 2009 Red Hat <bskeggs@redhat.com> 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining 562306a36Sopenharmony_ci * a copy of this software and associated documentation files (the 662306a36Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 762306a36Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 862306a36Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to 962306a36Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 1062306a36Sopenharmony_ci * the following conditions: 1162306a36Sopenharmony_ci * 1262306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the 1362306a36Sopenharmony_ci * next paragraph) shall be included in all copies or substantial 1462306a36Sopenharmony_ci * portions of the Software. 1562306a36Sopenharmony_ci * 1662306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 1762306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 1862306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 1962306a36Sopenharmony_ci * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 2062306a36Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 2162306a36Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 2262306a36Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci */ 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/* 2762306a36Sopenharmony_ci * Authors: 2862306a36Sopenharmony_ci * Alon Levy <alevy@redhat.com> 2962306a36Sopenharmony_ci */ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#include <drm/drm_debugfs.h> 3262306a36Sopenharmony_ci#include <drm/drm_file.h> 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#include "qxl_drv.h" 3562306a36Sopenharmony_ci#include "qxl_object.h" 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#if defined(CONFIG_DEBUG_FS) 3862306a36Sopenharmony_cistatic int 3962306a36Sopenharmony_ciqxl_debugfs_irq_received(struct seq_file *m, void *data) 4062306a36Sopenharmony_ci{ 4162306a36Sopenharmony_ci struct drm_info_node *node = (struct drm_info_node *) m->private; 4262306a36Sopenharmony_ci struct qxl_device *qdev = to_qxl(node->minor->dev); 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci seq_printf(m, "%d\n", atomic_read(&qdev->irq_received)); 4562306a36Sopenharmony_ci seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display)); 4662306a36Sopenharmony_ci seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor)); 4762306a36Sopenharmony_ci seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd)); 4862306a36Sopenharmony_ci seq_printf(m, "%d\n", qdev->irq_received_error); 4962306a36Sopenharmony_ci return 0; 5062306a36Sopenharmony_ci} 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_cistatic int 5362306a36Sopenharmony_ciqxl_debugfs_buffers_info(struct seq_file *m, void *data) 5462306a36Sopenharmony_ci{ 5562306a36Sopenharmony_ci struct drm_info_node *node = (struct drm_info_node *) m->private; 5662306a36Sopenharmony_ci struct qxl_device *qdev = to_qxl(node->minor->dev); 5762306a36Sopenharmony_ci struct qxl_bo *bo; 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci list_for_each_entry(bo, &qdev->gem.objects, list) { 6062306a36Sopenharmony_ci struct dma_resv_iter cursor; 6162306a36Sopenharmony_ci struct dma_fence *fence; 6262306a36Sopenharmony_ci int rel = 0; 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci dma_resv_iter_begin(&cursor, bo->tbo.base.resv, 6562306a36Sopenharmony_ci DMA_RESV_USAGE_BOOKKEEP); 6662306a36Sopenharmony_ci dma_resv_for_each_fence_unlocked(&cursor, fence) { 6762306a36Sopenharmony_ci if (dma_resv_iter_is_restarted(&cursor)) 6862306a36Sopenharmony_ci rel = 0; 6962306a36Sopenharmony_ci ++rel; 7062306a36Sopenharmony_ci } 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci seq_printf(m, "size %ld, pc %d, num releases %d\n", 7362306a36Sopenharmony_ci (unsigned long)bo->tbo.base.size, 7462306a36Sopenharmony_ci bo->tbo.pin_count, rel); 7562306a36Sopenharmony_ci } 7662306a36Sopenharmony_ci return 0; 7762306a36Sopenharmony_ci} 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_cistatic struct drm_info_list qxl_debugfs_list[] = { 8062306a36Sopenharmony_ci { "irq_received", qxl_debugfs_irq_received, 0, NULL }, 8162306a36Sopenharmony_ci { "qxl_buffers", qxl_debugfs_buffers_info, 0, NULL }, 8262306a36Sopenharmony_ci}; 8362306a36Sopenharmony_ci#define QXL_DEBUGFS_ENTRIES ARRAY_SIZE(qxl_debugfs_list) 8462306a36Sopenharmony_ci#endif 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_civoid 8762306a36Sopenharmony_ciqxl_debugfs_init(struct drm_minor *minor) 8862306a36Sopenharmony_ci{ 8962306a36Sopenharmony_ci#if defined(CONFIG_DEBUG_FS) 9062306a36Sopenharmony_ci struct qxl_device *dev = to_qxl(minor->dev); 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci drm_debugfs_create_files(qxl_debugfs_list, QXL_DEBUGFS_ENTRIES, 9362306a36Sopenharmony_ci minor->debugfs_root, minor); 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci qxl_ttm_debugfs_init(dev); 9662306a36Sopenharmony_ci#endif 9762306a36Sopenharmony_ci} 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_civoid qxl_debugfs_add_files(struct qxl_device *qdev, 10062306a36Sopenharmony_ci struct drm_info_list *files, 10162306a36Sopenharmony_ci unsigned int nfiles) 10262306a36Sopenharmony_ci{ 10362306a36Sopenharmony_ci unsigned int i; 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci for (i = 0; i < qdev->debugfs_count; i++) { 10662306a36Sopenharmony_ci if (qdev->debugfs[i].files == files) { 10762306a36Sopenharmony_ci /* Already registered */ 10862306a36Sopenharmony_ci return; 10962306a36Sopenharmony_ci } 11062306a36Sopenharmony_ci } 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci i = qdev->debugfs_count + 1; 11362306a36Sopenharmony_ci if (i > QXL_DEBUGFS_MAX_COMPONENTS) { 11462306a36Sopenharmony_ci DRM_ERROR("Reached maximum number of debugfs components.\n"); 11562306a36Sopenharmony_ci DRM_ERROR("Report so we increase QXL_DEBUGFS_MAX_COMPONENTS.\n"); 11662306a36Sopenharmony_ci return; 11762306a36Sopenharmony_ci } 11862306a36Sopenharmony_ci qdev->debugfs[qdev->debugfs_count].files = files; 11962306a36Sopenharmony_ci qdev->debugfs[qdev->debugfs_count].num_files = nfiles; 12062306a36Sopenharmony_ci qdev->debugfs_count = i; 12162306a36Sopenharmony_ci#if defined(CONFIG_DEBUG_FS) 12262306a36Sopenharmony_ci drm_debugfs_create_files(files, nfiles, 12362306a36Sopenharmony_ci qdev->ddev.primary->debugfs_root, 12462306a36Sopenharmony_ci qdev->ddev.primary); 12562306a36Sopenharmony_ci#endif 12662306a36Sopenharmony_ci} 127