diff --git a/drivers/accel/amdxdna/Kbuild b/drivers/accel/amdxdna/Kbuild index 96263db97..da8987556 100644 --- a/drivers/accel/amdxdna/Kbuild +++ b/drivers/accel/amdxdna/Kbuild @@ -60,3 +60,4 @@ amdxdna-$(CONFIG_PCI_IOV) += \ amdxdna-$(CONFIG_DEBUG_FS) += \ amdxdna_debugfs.o \ + aie4_debugfs.o \ diff --git a/drivers/accel/amdxdna/aie4_debugfs.c b/drivers/accel/amdxdna/aie4_debugfs.c new file mode 100644 index 000000000..9f330c73e --- /dev/null +++ b/drivers/accel/amdxdna/aie4_debugfs.c @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2026, Advanced Micro Devices, Inc. + */ + +#include +#include +#include +#include +#include +#include + +#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); + + 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: @ + */ +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); + } +} diff --git a/drivers/accel/amdxdna/aie4_msg_priv.h b/drivers/accel/amdxdna/aie4_msg_priv.h index bd48b3ef8..592232765 100644 --- a/drivers/accel/amdxdna/aie4_msg_priv.h +++ b/drivers/accel/amdxdna/aie4_msg_priv.h @@ -11,6 +11,7 @@ #include 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, @@ -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; diff --git a/drivers/accel/amdxdna/aie4_pci.c b/drivers/accel/amdxdna/aie4_pci.c index 2303317ec..ea6dd457b 100644 --- a/drivers/accel/amdxdna/aie4_pci.c +++ b/drivers/accel/amdxdna/aie4_pci.c @@ -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 = { @@ -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, }; diff --git a/drivers/accel/amdxdna/aie4_pci.h b/drivers/accel/amdxdna/aie4_pci.h index 33e7cde10..d95806ce6 100644 --- a/drivers/accel/amdxdna/aie4_pci.h +++ b/drivers/accel/amdxdna/aie4_pci.h @@ -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); + enum aie4_fw_feature { AIE4_GET_COREDUMP, AIE4_FEATURE_MAX diff --git a/drivers/accel/amdxdna/amdxdna_debugfs.c b/drivers/accel/amdxdna/amdxdna_debugfs.c index a6ec17c63..89ee60390 100644 --- a/drivers/accel/amdxdna/amdxdna_debugfs.c +++ b/drivers/accel/amdxdna/amdxdna_debugfs.c @@ -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); } diff --git a/drivers/accel/amdxdna/amdxdna_pci_drv.c b/drivers/accel/amdxdna/amdxdna_pci_drv.c index ac0d6e4bb..7da340d16 100644 --- a/drivers/accel/amdxdna/amdxdna_pci_drv.c +++ b/drivers/accel/amdxdna/amdxdna_pci_drv.c @@ -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: diff --git a/drivers/accel/amdxdna/amdxdna_pci_drv.h b/drivers/accel/amdxdna/amdxdna_pci_drv.h index 9d77aac7a..3d85c00e2 100644 --- a/drivers/accel/amdxdna/amdxdna_pci_drv.h +++ b/drivers/accel/amdxdna/amdxdna_pci_drv.h @@ -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 {