linux/drivers/gpu/drm/i915/gvt/debugfs.c
<<
>>
Prefs
   1/*
   2 * Copyright(c) 2011-2017 Intel Corporation. All rights reserved.
   3 *
   4 * Permission is hereby granted, free of charge, to any person obtaining a
   5 * copy of this software and associated documentation files (the "Software"),
   6 * to deal in the Software without restriction, including without limitation
   7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   8 * and/or sell copies of the Software, and to permit persons to whom the
   9 * Software is furnished to do so, subject to the following conditions:
  10 *
  11 * The above copyright notice and this permission notice (including the next
  12 * paragraph) shall be included in all copies or substantial portions of the
  13 * Software.
  14 *
  15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21 * SOFTWARE.
  22 */
  23#include <linux/debugfs.h>
  24#include <linux/list_sort.h>
  25#include "i915_drv.h"
  26#include "gvt.h"
  27
  28struct mmio_diff_param {
  29        struct intel_vgpu *vgpu;
  30        int total;
  31        int diff;
  32        struct list_head diff_mmio_list;
  33};
  34
  35struct diff_mmio {
  36        struct list_head node;
  37        u32 offset;
  38        u32 preg;
  39        u32 vreg;
  40};
  41
  42/* Compare two diff_mmio items. */
  43static int mmio_offset_compare(void *priv,
  44        struct list_head *a, struct list_head *b)
  45{
  46        struct diff_mmio *ma;
  47        struct diff_mmio *mb;
  48
  49        ma = container_of(a, struct diff_mmio, node);
  50        mb = container_of(b, struct diff_mmio, node);
  51        if (ma->offset < mb->offset)
  52                return -1;
  53        else if (ma->offset > mb->offset)
  54                return 1;
  55        return 0;
  56}
  57
  58static inline int mmio_diff_handler(struct intel_gvt *gvt,
  59                                    u32 offset, void *data)
  60{
  61        struct drm_i915_private *dev_priv = gvt->dev_priv;
  62        struct mmio_diff_param *param = data;
  63        struct diff_mmio *node;
  64        u32 preg, vreg;
  65
  66        preg = I915_READ_NOTRACE(_MMIO(offset));
  67        vreg = vgpu_vreg(param->vgpu, offset);
  68
  69        if (preg != vreg) {
  70                node = kmalloc(sizeof(*node), GFP_KERNEL);
  71                if (!node)
  72                        return -ENOMEM;
  73
  74                node->offset = offset;
  75                node->preg = preg;
  76                node->vreg = vreg;
  77                list_add(&node->node, &param->diff_mmio_list);
  78                param->diff++;
  79        }
  80        param->total++;
  81        return 0;
  82}
  83
  84/* Show the all the different values of tracked mmio. */
  85static int vgpu_mmio_diff_show(struct seq_file *s, void *unused)
  86{
  87        struct intel_vgpu *vgpu = s->private;
  88        struct intel_gvt *gvt = vgpu->gvt;
  89        struct mmio_diff_param param = {
  90                .vgpu = vgpu,
  91                .total = 0,
  92                .diff = 0,
  93        };
  94        struct diff_mmio *node, *next;
  95
  96        INIT_LIST_HEAD(&param.diff_mmio_list);
  97
  98        mutex_lock(&gvt->lock);
  99        spin_lock_bh(&gvt->scheduler.mmio_context_lock);
 100
 101        mmio_hw_access_pre(gvt->dev_priv);
 102        /* Recognize all the diff mmios to list. */
 103        intel_gvt_for_each_tracked_mmio(gvt, mmio_diff_handler, &param);
 104        mmio_hw_access_post(gvt->dev_priv);
 105
 106        spin_unlock_bh(&gvt->scheduler.mmio_context_lock);
 107        mutex_unlock(&gvt->lock);
 108
 109        /* In an ascending order by mmio offset. */
 110        list_sort(NULL, &param.diff_mmio_list, mmio_offset_compare);
 111
 112        seq_printf(s, "%-8s %-8s %-8s %-8s\n", "Offset", "HW", "vGPU", "Diff");
 113        list_for_each_entry_safe(node, next, &param.diff_mmio_list, node) {
 114                u32 diff = node->preg ^ node->vreg;
 115
 116                seq_printf(s, "%08x %08x %08x %*pbl\n",
 117                           node->offset, node->preg, node->vreg,
 118                           32, &diff);
 119                list_del(&node->node);
 120                kfree(node);
 121        }
 122        seq_printf(s, "Total: %d, Diff: %d\n", param.total, param.diff);
 123        return 0;
 124}
 125
 126static int vgpu_mmio_diff_open(struct inode *inode, struct file *file)
 127{
 128        return single_open(file, vgpu_mmio_diff_show, inode->i_private);
 129}
 130
 131static const struct file_operations vgpu_mmio_diff_fops = {
 132        .open           = vgpu_mmio_diff_open,
 133        .read           = seq_read,
 134        .llseek         = seq_lseek,
 135        .release        = single_release,
 136};
 137
 138/**
 139 * intel_gvt_debugfs_add_vgpu - register debugfs entries for a vGPU
 140 * @vgpu: a vGPU
 141 *
 142 * Returns:
 143 * Zero on success, negative error code if failed.
 144 */
 145int intel_gvt_debugfs_add_vgpu(struct intel_vgpu *vgpu)
 146{
 147        struct dentry *ent;
 148        char name[10] = "";
 149
 150        sprintf(name, "vgpu%d", vgpu->id);
 151        vgpu->debugfs = debugfs_create_dir(name, vgpu->gvt->debugfs_root);
 152        if (!vgpu->debugfs)
 153                return -ENOMEM;
 154
 155        ent = debugfs_create_bool("active", 0444, vgpu->debugfs,
 156                                  &vgpu->active);
 157        if (!ent)
 158                return -ENOMEM;
 159
 160        ent = debugfs_create_file("mmio_diff", 0444, vgpu->debugfs,
 161                                  vgpu, &vgpu_mmio_diff_fops);
 162        if (!ent)
 163                return -ENOMEM;
 164
 165        return 0;
 166}
 167
 168/**
 169 * intel_gvt_debugfs_remove_vgpu - remove debugfs entries of a vGPU
 170 * @vgpu: a vGPU
 171 */
 172void intel_gvt_debugfs_remove_vgpu(struct intel_vgpu *vgpu)
 173{
 174        debugfs_remove_recursive(vgpu->debugfs);
 175        vgpu->debugfs = NULL;
 176}
 177
 178/**
 179 * intel_gvt_debugfs_init - register gvt debugfs root entry
 180 * @gvt: GVT device
 181 *
 182 * Returns:
 183 * zero on success, negative if failed.
 184 */
 185int intel_gvt_debugfs_init(struct intel_gvt *gvt)
 186{
 187        struct drm_minor *minor = gvt->dev_priv->drm.primary;
 188        struct dentry *ent;
 189
 190        gvt->debugfs_root = debugfs_create_dir("gvt", minor->debugfs_root);
 191        if (!gvt->debugfs_root) {
 192                gvt_err("Cannot create debugfs dir\n");
 193                return -ENOMEM;
 194        }
 195
 196        ent = debugfs_create_ulong("num_tracked_mmio", 0444, gvt->debugfs_root,
 197                                   &gvt->mmio.num_tracked_mmio);
 198        if (!ent)
 199                return -ENOMEM;
 200
 201        return 0;
 202}
 203
 204/**
 205 * intel_gvt_debugfs_clean - remove debugfs entries
 206 * @gvt: GVT device
 207 */
 208void intel_gvt_debugfs_clean(struct intel_gvt *gvt)
 209{
 210        debugfs_remove_recursive(gvt->debugfs_root);
 211        gvt->debugfs_root = NULL;
 212}
 213