162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright (C) 2015 Red Hat, Inc. 362306a36Sopenharmony_ci * All Rights Reserved. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining 662306a36Sopenharmony_ci * a copy of this software and associated documentation files (the 762306a36Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 862306a36Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 962306a36Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to 1062306a36Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 1162306a36Sopenharmony_ci * the following conditions: 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the 1462306a36Sopenharmony_ci * next paragraph) shall be included in all copies or substantial 1562306a36Sopenharmony_ci * portions of the Software. 1662306a36Sopenharmony_ci * 1762306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 1862306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 1962306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 2062306a36Sopenharmony_ci * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 2162306a36Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 2262306a36Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 2362306a36Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2462306a36Sopenharmony_ci */ 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#include <linux/string_helpers.h> 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci#include <drm/drm_debugfs.h> 2962306a36Sopenharmony_ci#include <drm/drm_file.h> 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#include "virtgpu_drv.h" 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_cistatic void virtio_gpu_add_bool(struct seq_file *m, const char *name, 3462306a36Sopenharmony_ci bool value) 3562306a36Sopenharmony_ci{ 3662306a36Sopenharmony_ci seq_printf(m, "%-16s : %s\n", name, str_yes_no(value)); 3762306a36Sopenharmony_ci} 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_cistatic void virtio_gpu_add_int(struct seq_file *m, const char *name, int value) 4062306a36Sopenharmony_ci{ 4162306a36Sopenharmony_ci seq_printf(m, "%-16s : %d\n", name, value); 4262306a36Sopenharmony_ci} 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_cistatic int virtio_gpu_features(struct seq_file *m, void *data) 4562306a36Sopenharmony_ci{ 4662306a36Sopenharmony_ci struct drm_info_node *node = (struct drm_info_node *)m->private; 4762306a36Sopenharmony_ci struct virtio_gpu_device *vgdev = node->minor->dev->dev_private; 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci virtio_gpu_add_bool(m, "virgl", vgdev->has_virgl_3d); 5062306a36Sopenharmony_ci virtio_gpu_add_bool(m, "edid", vgdev->has_edid); 5162306a36Sopenharmony_ci virtio_gpu_add_bool(m, "indirect", vgdev->has_indirect); 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci virtio_gpu_add_bool(m, "resource uuid", 5462306a36Sopenharmony_ci vgdev->has_resource_assign_uuid); 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci virtio_gpu_add_bool(m, "blob resources", vgdev->has_resource_blob); 5762306a36Sopenharmony_ci virtio_gpu_add_bool(m, "context init", vgdev->has_context_init); 5862306a36Sopenharmony_ci virtio_gpu_add_int(m, "cap sets", vgdev->num_capsets); 5962306a36Sopenharmony_ci virtio_gpu_add_int(m, "scanouts", vgdev->num_scanouts); 6062306a36Sopenharmony_ci if (vgdev->host_visible_region.len) { 6162306a36Sopenharmony_ci seq_printf(m, "%-16s : 0x%lx +0x%lx\n", "host visible region", 6262306a36Sopenharmony_ci (unsigned long)vgdev->host_visible_region.addr, 6362306a36Sopenharmony_ci (unsigned long)vgdev->host_visible_region.len); 6462306a36Sopenharmony_ci } 6562306a36Sopenharmony_ci return 0; 6662306a36Sopenharmony_ci} 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_cistatic int 6962306a36Sopenharmony_civirtio_gpu_debugfs_irq_info(struct seq_file *m, void *data) 7062306a36Sopenharmony_ci{ 7162306a36Sopenharmony_ci struct drm_info_node *node = (struct drm_info_node *) m->private; 7262306a36Sopenharmony_ci struct virtio_gpu_device *vgdev = node->minor->dev->dev_private; 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci seq_printf(m, "fence %llu %lld\n", 7562306a36Sopenharmony_ci (u64)atomic64_read(&vgdev->fence_drv.last_fence_id), 7662306a36Sopenharmony_ci vgdev->fence_drv.current_fence_id); 7762306a36Sopenharmony_ci return 0; 7862306a36Sopenharmony_ci} 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_cistatic int 8162306a36Sopenharmony_civirtio_gpu_debugfs_host_visible_mm(struct seq_file *m, void *data) 8262306a36Sopenharmony_ci{ 8362306a36Sopenharmony_ci struct drm_info_node *node = (struct drm_info_node *)m->private; 8462306a36Sopenharmony_ci struct virtio_gpu_device *vgdev = node->minor->dev->dev_private; 8562306a36Sopenharmony_ci struct drm_printer p; 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci if (!vgdev->has_host_visible) { 8862306a36Sopenharmony_ci seq_puts(m, "Host allocations not visible to guest\n"); 8962306a36Sopenharmony_ci return 0; 9062306a36Sopenharmony_ci } 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci p = drm_seq_file_printer(m); 9362306a36Sopenharmony_ci drm_mm_print(&vgdev->host_visible_mm, &p); 9462306a36Sopenharmony_ci return 0; 9562306a36Sopenharmony_ci} 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_cistatic struct drm_info_list virtio_gpu_debugfs_list[] = { 9862306a36Sopenharmony_ci { "virtio-gpu-features", virtio_gpu_features }, 9962306a36Sopenharmony_ci { "virtio-gpu-irq-fence", virtio_gpu_debugfs_irq_info, 0, NULL }, 10062306a36Sopenharmony_ci { "virtio-gpu-host-visible-mm", virtio_gpu_debugfs_host_visible_mm }, 10162306a36Sopenharmony_ci}; 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci#define VIRTIO_GPU_DEBUGFS_ENTRIES ARRAY_SIZE(virtio_gpu_debugfs_list) 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_civoid 10662306a36Sopenharmony_civirtio_gpu_debugfs_init(struct drm_minor *minor) 10762306a36Sopenharmony_ci{ 10862306a36Sopenharmony_ci drm_debugfs_create_files(virtio_gpu_debugfs_list, 10962306a36Sopenharmony_ci VIRTIO_GPU_DEBUGFS_ENTRIES, 11062306a36Sopenharmony_ci minor->debugfs_root, minor); 11162306a36Sopenharmony_ci} 112