A system has one accel node per DSP domain, and which node is which is not something user space can tell from the node name: /dev/accel/accel0 may be the CDSP on one platform and the ADSP on another. An application that wants a particular DSP has to open the nodes and ask.
Add DRM_IOCTL_QDA_QUERY, which returns the name of the DSP behind a given node, taken from the "label" property of its device tree node. The ioctl takes a query_type selector so that later additions (DSP capabilities, attributes) do not each need an ioctl of their own, and is DRM_IOWR rather than DRM_IOR so that the selector reaches the kernel. Unknown query types are rejected with -EINVAL rather than returning zeroes, so that user space can tell an unsupported query on an old kernel apart from a query that legitimately returned nothing. Signed-off-by: Ekansh Gupta <[email protected]> --- MAINTAINERS | 1 + drivers/accel/qda/Makefile | 1 + drivers/accel/qda/qda_drv.c | 8 ++++++++ drivers/accel/qda/qda_ioctl.c | 30 ++++++++++++++++++++++++++++++ drivers/accel/qda/qda_ioctl.h | 13 +++++++++++++ include/uapi/drm/qda_accel.h | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 94 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 77687a35ac13..1316e63c1151 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22982,6 +22982,7 @@ S: Supported T: git https://gitlab.freedesktop.org/drm/misc/kernel.git F: Documentation/accel/qda/ F: drivers/accel/qda/ +F: include/uapi/drm/qda_accel.h QUALCOMM EMAC GIGABIT ETHERNET DRIVER M: Timur Tabi <[email protected]> diff --git a/drivers/accel/qda/Makefile b/drivers/accel/qda/Makefile index 1ca991e198ed..402e7dbebbf0 100644 --- a/drivers/accel/qda/Makefile +++ b/drivers/accel/qda/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_DRM_ACCEL_QDA) := qda.o qda-y := \ qda_cb.o \ qda_drv.o \ + qda_ioctl.o \ qda_memory_manager.o \ qda_rpmsg.o \ qda_soc.o diff --git a/drivers/accel/qda/qda_drv.c b/drivers/accel/qda/qda_drv.c index a99e23933f6b..e722135238f3 100644 --- a/drivers/accel/qda/qda_drv.c +++ b/drivers/accel/qda/qda_drv.c @@ -8,8 +8,10 @@ #include <drm/drm_gem.h> #include <drm/drm_ioctl.h> #include <drm/drm_print.h> +#include <drm/qda_accel.h> #include "qda_drv.h" +#include "qda_ioctl.h" static struct qda_session *qda_session_alloc(struct qda_dev *qdev) { @@ -54,11 +56,17 @@ static void qda_postclose(struct drm_device *dev, struct drm_file *file) DEFINE_DRM_ACCEL_FOPS(qda_accel_fops); +static const struct drm_ioctl_desc qda_ioctls[] = { + DRM_IOCTL_DEF_DRV(QDA_QUERY, qda_ioctl_query, 0), +}; + static const struct drm_driver qda_drm_driver = { .driver_features = DRIVER_COMPUTE_ACCEL, .fops = &qda_accel_fops, .open = qda_open, .postclose = qda_postclose, + .ioctls = qda_ioctls, + .num_ioctls = ARRAY_SIZE(qda_ioctls), .name = QDA_DRIVER_NAME, .desc = "Qualcomm DSP Accelerator Driver", }; diff --git a/drivers/accel/qda/qda_ioctl.c b/drivers/accel/qda/qda_ioctl.c new file mode 100644 index 000000000000..380c2526d9d2 --- /dev/null +++ b/drivers/accel/qda/qda_ioctl.c @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +#include <linux/string.h> +#include <drm/drm_device.h> +#include <drm/drm_file.h> +#include <drm/qda_accel.h> +#include "qda_drv.h" +#include "qda_ioctl.h" + +/** + * qda_ioctl_query() - Query a property of the DSP + * @dev: DRM device structure + * @data: User-space data (struct drm_qda_query) + * @file_priv: DRM file private data + * + * Return: 0 on success, negative error code on failure + */ +int qda_ioctl_query(struct drm_device *dev, void *data, struct drm_file *file_priv) +{ + struct qda_dev *qdev = qda_dev_from_drm(dev); + struct drm_qda_query *args = data; + + switch (args->query_type) { + case QDA_QUERY_DSP_NAME: + strscpy(args->dsp_name, qdev->dsp_name, sizeof(args->dsp_name)); + return 0; + default: + return -EINVAL; + } +} diff --git a/drivers/accel/qda/qda_ioctl.h b/drivers/accel/qda/qda_ioctl.h new file mode 100644 index 000000000000..b8fd536a111f --- /dev/null +++ b/drivers/accel/qda/qda_ioctl.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + */ + +#ifndef __QDA_IOCTL_H__ +#define __QDA_IOCTL_H__ + +#include "qda_drv.h" + +int qda_ioctl_query(struct drm_device *dev, void *data, struct drm_file *file_priv); + +#endif /* __QDA_IOCTL_H__ */ diff --git a/include/uapi/drm/qda_accel.h b/include/uapi/drm/qda_accel.h new file mode 100644 index 000000000000..b9dc4787bd42 --- /dev/null +++ b/include/uapi/drm/qda_accel.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ +/* + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + */ + +#ifndef __QDA_ACCEL_H__ +#define __QDA_ACCEL_H__ + +#include "drm.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +#define DRM_QDA_QUERY 0x00 + +#define DRM_IOCTL_QDA_QUERY DRM_IOWR(DRM_COMMAND_BASE + DRM_QDA_QUERY, \ + struct drm_qda_query) + +/* Query type definitions for drm_qda_query */ +#define QDA_QUERY_DSP_NAME 1 + +/** + * struct drm_qda_query - Device information query structure + * @query_type: Type of query (input) + * @dsp_name: Null-terminated name of the DSP (returned when query_type is + * QDA_QUERY_DSP_NAME) + * + * This structure is used with DRM_IOCTL_QDA_QUERY to query device attributes + * based on @query_type. + */ +struct drm_qda_query { + __u32 query_type; + __u8 dsp_name[16]; +}; + +#if defined(__cplusplus) +} +#endif + +#endif /* __QDA_ACCEL_H__ */ -- 2.34.1
