Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/accel/amdxdna/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ amdxdna-$(CONFIG_PCI_IOV) += \

amdxdna-$(CONFIG_DEBUG_FS) += \
amdxdna_debugfs.o \
aie4_debugfs.o \
124 changes: 124 additions & 0 deletions drivers/accel/amdxdna/aie4_debugfs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2026, Advanced Micro Devices, Inc.
*/

#include <drm/drm_file.h>
#include <linux/debugfs.h>
#include <linux/pm_runtime.h>
#include <linux/seq_file.h>
#include <linux/string.h>
#include <linux/uaccess.h>

#include "amdxdna_cbuf.h"
#include "amdxdna_debugfs.h"
#include "aie4_pci.h"
#include "aie4_msg_priv.h"
#include "amdxdna_mailbox.h"
#include "amdxdna_mailbox_helper.h"

#define _DBGFS_FOPS(_open, _release, _write) \
{ \
.owner = THIS_MODULE, \
.open = _open, \
.read = seq_read, \
.llseek = seq_lseek, \
.release = _release, \
.write = _write, \
}

#define AMDXDNA_DBGFS_FOPS(_name, _show, _write) \
static int amdxdna_dbgfs_##_name##_open(struct inode *inode, struct file *file) \
{ \
return single_open(file, _show, inode->i_private); \
} \
static int amdxdna_dbgfs_##_name##_release(struct inode *inode, struct file *file) \
{ \
return single_release(inode, file); \
} \
static const struct file_operations amdxdna_fops_##_name = \
_DBGFS_FOPS(amdxdna_dbgfs_##_name##_open, amdxdna_dbgfs_##_name##_release, _write)

#define AMDXDNA_DBGFS_FILE(_name, _mode) { #_name, &amdxdna_fops_##_name, _mode }

#define file_to_xdna(file) (((struct seq_file *)(file)->private_data)->private)

static int amdxdna_iommu_bypass_show(struct seq_file *m, void *unused)
{
return 0;
}

static ssize_t amdxdna_iommu_bypass_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
DECLARE_AIE_MSG(aie4_msg_echo, AIE4_MSG_OP_ECHO);
struct amdxdna_dev *xdna = file_to_xdna(file);
struct amdxdna_dev_hdl *ndev = xdna->dev_handle;
char kbuf[32];
u8 val;
int ret;

if (count == 0 || count >= sizeof(kbuf))
return -EINVAL;

if (copy_from_user(kbuf, buf, count))
return -EFAULT;
kbuf[count] = '\0';
strim(kbuf);

XDNA_DBG(xdna, "Trying to set iommu_bypass mode to %s", kbuf);

ret = kstrtou8(kbuf, 0, &val);
if (ret)
return ret;

if (!val)
return count;

XDNA_DBG(xdna, "Setting iommu_bypass mode to %d", val);

#define MAKE_MAGIC(a, b, c, d) ((u32)((a) << 24 | (b) << 16 | (c) << 8 | (d)))
req.val1 = MAKE_MAGIC('B', 'Y', 'P', 'A');
req.val2 = MAKE_MAGIC('M', 'A', 'G', 'C');

guard(mutex)(&xdna->dev_lock);
ret = aie_send_mgmt_msg_wait(&ndev->aie, &msg);
if (ret)
XDNA_ERR(xdna, "echo failed: %d", ret);
Comment on lines +86 to +87

if (req.val1 == resp.val1 &&
req.val2 == resp.val2)
XDNA_INFO(xdna, "echo finished, response correct value.");
else
XDNA_WARN(xdna, "echo finished, expect: 0x%x,0x%x, got: 0x%x,0x%x",
req.val1, req.val1, resp.val1, resp.val2);

return count;
}

/*
* Input/output format: <carveout_size>@<carveout_address>
*/
AMDXDNA_DBGFS_FOPS(iommu_bypass, amdxdna_iommu_bypass_show, amdxdna_iommu_bypass_write);

static const struct {
const char *name;
const struct file_operations *fops;
umode_t mode;
} aie4_dbgfs_files[] = {
AMDXDNA_DBGFS_FILE(iommu_bypass, 0200),
};

void aie4_debugfs_init(struct amdxdna_dev *xdna)
{
struct drm_minor *minor = xdna->ddev.accel;
int i;

for (i = 0; i < ARRAY_SIZE(aie4_dbgfs_files); i++) {
debugfs_create_file(aie4_dbgfs_files[i].name,
aie4_dbgfs_files[i].mode,
minor->debugfs_root,
xdna,
aie4_dbgfs_files[i].fops);
}
}
12 changes: 12 additions & 0 deletions drivers/accel/amdxdna/aie4_msg_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <linux/types.h>

enum aie4_msg_opcode {
AIE4_MSG_OP_ECHO = 0x10001,
AIE4_MSG_OP_SUSPEND = 0x10003,
AIE4_MSG_OP_ATTACH_WORK_BUFFER = 0x1000D,
AIE4_MSG_OP_AIE_COREDUMP = 0x30010,
Expand All @@ -32,6 +33,17 @@ enum aie4_msg_status {
MAX_AIE4_MSG_STATUS_CODE = 0x4,
};

struct aie4_msg_echo_req {
__u32 val1;
__u32 val2;
} __packed;

struct aie4_msg_echo_resp {
enum aie4_msg_status status;
__u32 val1;
__u32 val2;
} __packed;

struct aie4_msg_suspend_req {
__u32 rsvd;
} __packed;
Expand Down
2 changes: 2 additions & 0 deletions drivers/accel/amdxdna/aie4_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ const struct amdxdna_dev_ops aie4_pf_ops = {
.init = aie4_pf_init,
.fini = aie4_pf_fini,
.sriov_configure = aie4_sriov_configure,
.debugfs = aie4_debugfs_init,
};

const struct amdxdna_dev_ops aie4_vf_ops = {
Expand All @@ -797,4 +798,5 @@ const struct amdxdna_dev_ops aie4_classic_ops = {
.get_aie_info = aie4_get_info,
.get_array = aie4_get_array,
.get_coredump = aie4_get_aie_coredump,
.debugfs = aie4_debugfs_init,
};
3 changes: 3 additions & 0 deletions drivers/accel/amdxdna/aie4_pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ static inline int aie4_sriov_stop(struct amdxdna_dev_hdl *ndev)
}
#endif

/* aie4_debugfs.c */
void aie4_debugfs_init(struct amdxdna_dev *xdna);
Comment on lines +83 to +84

enum aie4_fw_feature {
AIE4_GET_COREDUMP,
AIE4_FEATURE_MAX
Expand Down
3 changes: 3 additions & 0 deletions drivers/accel/amdxdna/amdxdna_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,7 @@ void amdxdna_debugfs_init(struct amdxdna_dev *xdna)
xdna,
amdxdna_dbgfs_files[i].fops);
}

if (xdna->dev_info->ops->debugfs)
xdna->dev_info->ops->debugfs(xdna);
}
1 change: 1 addition & 0 deletions drivers/accel/amdxdna/amdxdna_pci_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ static int amdxdna_probe(struct pci_dev *pdev, const struct pci_device_id *id)
}

amdxdna_debugfs_init(xdna);

return 0;

failed_sysfs_fini:
Expand Down
1 change: 1 addition & 0 deletions drivers/accel/amdxdna/amdxdna_pci_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct amdxdna_dev_ops {
struct amdxdna_hwctx *hwctx, u32 num_bufs);
int (*get_dev_revision)(struct amdxdna_dev *xdna, u32 *rev);
int (*hwctx_heap_expand)(struct amdxdna_hwctx *hwctx);
void (*debugfs)(struct amdxdna_dev *xdna);
};

struct amdxdna_fw_feature_tbl {
Expand Down