Skip to content

Commit

Permalink
drm/imagination: Add firmware trace to debugfs
Browse files Browse the repository at this point in the history
Firmware trace is exposed at /sys/debug/dri/<dev_nr>/pvr_fw/trace_0.
Trace is enabled via the group mask at
/sys/debug/dri/<dev_nr>/pvr_params/fw_trace_mask.

Changes since v8:
- Corrected license identifiers

Changes since v3:
- Use drm_dev_{enter,exit}

Co-developed-by: Matt Coster <matt.coster@imgtec.com>
Signed-off-by: Matt Coster <matt.coster@imgtec.com>
Signed-off-by: Sarah Walker <sarah.walker@imgtec.com>
Signed-off-by: Donald Robson <donald.robson@imgtec.com>
Link: https://lore.kernel.org/r/009cf9fee347fa96c8a665dc368fc54a5ffceff0.1700668843.git.donald.robson@imgtec.com
Signed-off-by: Maxime Ripard <mripard@kernel.org>
  • Loading branch information
Sarah Walker authored and Maxime Ripard committed Nov 23, 2023
1 parent 6b17baa commit cb56cd6
Show file tree
Hide file tree
Showing 9 changed files with 723 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/gpu/drm/imagination/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ powervr-y := \
pvr_hwrt.o \
pvr_job.o \
pvr_mmu.o \
pvr_params.o \
pvr_power.o \
pvr_queue.o \
pvr_stream.o \
Expand All @@ -28,4 +29,7 @@ powervr-y := \
pvr_vm.o \
pvr_vm_mips.o

powervr-$(CONFIG_DEBUG_FS) += \
pvr_debugfs.o

obj-$(CONFIG_DRM_POWERVR) += powervr.o
53 changes: 53 additions & 0 deletions drivers/gpu/drm/imagination/pvr_debugfs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT
/* Copyright (c) 2023 Imagination Technologies Ltd. */

#include "pvr_debugfs.h"

#include "pvr_device.h"
#include "pvr_fw_trace.h"
#include "pvr_params.h"

#include <linux/dcache.h>
#include <linux/debugfs.h>
#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/types.h>

#include <drm/drm_device.h>
#include <drm/drm_file.h>
#include <drm/drm_print.h>

static const struct pvr_debugfs_entry pvr_debugfs_entries[] = {
{"pvr_params", pvr_params_debugfs_init},
{"pvr_fw", pvr_fw_trace_debugfs_init},
};

void
pvr_debugfs_init(struct drm_minor *minor)
{
struct drm_device *drm_dev = minor->dev;
struct pvr_device *pvr_dev = to_pvr_device(drm_dev);
struct dentry *root = minor->debugfs_root;
size_t i;

for (i = 0; i < ARRAY_SIZE(pvr_debugfs_entries); ++i) {
const struct pvr_debugfs_entry *entry = &pvr_debugfs_entries[i];
struct dentry *dir;

dir = debugfs_create_dir(entry->name, root);
if (IS_ERR(dir)) {
drm_warn(drm_dev,
"failed to create debugfs dir '%s' (err=%d)",
entry->name, (int)PTR_ERR(dir));
continue;
}

entry->init(pvr_dev, dir);
}
}

/*
* Since all entries are created under &drm_minor->debugfs_root, there's no
* need for a pvr_debugfs_fini() as DRM will clean up everything under its root
* automatically.
*/
29 changes: 29 additions & 0 deletions drivers/gpu/drm/imagination/pvr_debugfs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
/* Copyright (c) 2023 Imagination Technologies Ltd. */

#ifndef PVR_DEBUGFS_H
#define PVR_DEBUGFS_H

/* Forward declaration from <drm/drm_drv.h>. */
struct drm_minor;

#if defined(CONFIG_DEBUG_FS)
/* Forward declaration from "pvr_device.h". */
struct pvr_device;

/* Forward declaration from <linux/dcache.h>. */
struct dentry;

struct pvr_debugfs_entry {
const char *name;
void (*init)(struct pvr_device *pvr_dev, struct dentry *dir);
};

void pvr_debugfs_init(struct drm_minor *minor);
#else /* defined(CONFIG_DEBUG_FS) */
#include <linux/compiler_attributes.h>

static __always_inline void pvr_debugfs_init(struct drm_minor *minor) {}
#endif /* defined(CONFIG_DEBUG_FS) */

#endif /* PVR_DEBUGFS_H */
9 changes: 9 additions & 0 deletions drivers/gpu/drm/imagination/pvr_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "pvr_device_info.h"

#include "pvr_fw.h"
#include "pvr_params.h"
#include "pvr_power.h"
#include "pvr_queue.h"
#include "pvr_rogue_cr_defs.h"
Expand Down Expand Up @@ -495,6 +496,14 @@ pvr_device_init(struct pvr_device *pvr_dev)
struct device *dev = drm_dev->dev;
int err;

/*
* Setup device parameters. We do this first in case other steps
* depend on them.
*/
err = pvr_device_params_init(&pvr_dev->params);
if (err)
return err;

/* Enable and initialize clocks required for the device to operate. */
err = pvr_device_clk_init(pvr_dev);
if (err)
Expand Down
10 changes: 10 additions & 0 deletions drivers/gpu/drm/imagination/pvr_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "pvr_ccb.h"
#include "pvr_device_info.h"
#include "pvr_fw.h"
#include "pvr_params.h"
#include "pvr_rogue_fwif_stream.h"
#include "pvr_stream.h"

Expand Down Expand Up @@ -148,6 +149,15 @@ struct pvr_device {
/** @fw_dev: Firmware related data. */
struct pvr_fw_device fw_dev;

/**
* @params: Device-specific parameters.
*
* The values of these parameters are initialized from the
* defaults specified as module parameters. They may be
* modified at runtime via debugfs (if enabled).
*/
struct pvr_device_params params;

/** @stream_musthave_quirks: Bit array of "must-have" quirks for stream commands. */
u32 stream_musthave_quirks[PVR_STREAM_TYPE_MAX][PVR_STREAM_EXTHDR_TYPE_MAX];

Expand Down
4 changes: 4 additions & 0 deletions drivers/gpu/drm/imagination/pvr_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Copyright (c) 2023 Imagination Technologies Ltd. */

#include "pvr_context.h"
#include "pvr_debugfs.h"
#include "pvr_device.h"
#include "pvr_drv.h"
#include "pvr_free_list.h"
Expand Down Expand Up @@ -1377,6 +1378,9 @@ static struct drm_driver pvr_drm_driver = {
.ioctls = pvr_drm_driver_ioctls,
.num_ioctls = ARRAY_SIZE(pvr_drm_driver_ioctls),
.fops = &pvr_drm_driver_fops,
#if defined(CONFIG_DEBUG_FS)
.debugfs_init = pvr_debugfs_init,
#endif

.name = PVR_DRIVER_NAME,
.desc = PVR_DRIVER_DESC,
Expand Down
Loading

0 comments on commit cb56cd6

Please sign in to comment.