This commit introduces ioctl handler for PMC. In this commit, the handler only performs basic checkings, including permission and whether user queues are enabled.
Signed-off-by: Zhu Lingshan <[email protected]> --- drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 28 +++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c index 04902696adab..feff37279575 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c @@ -23,9 +23,35 @@ */ #include <linux/errno.h> +#include <linux/capability.h> #include <drm/amdgpu_drm.h> +#include "amdgpu.h" +#include "amdgpu_userq.h" #include "amdgpu_profiler.h" +static int amdgpu_profiler_check_access(struct drm_device *dev) +{ + if (!perfmon_capable()) + return -EPERM; + + if (!amdgpu_userq_enabled(dev)) + return -EOPNOTSUPP; + + return 0; +} + +static int amdgpu_profiler_pmc(struct drm_device *dev, struct drm_file *filp, + bool enable) +{ + int ret; + + ret = amdgpu_profiler_check_access(dev); + if (ret) + return ret; + + return -EOPNOTSUPP; +} + int amdgpu_profiler_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) { struct drm_amdgpu_profiler_args *args = data; @@ -37,7 +63,7 @@ int amdgpu_profiler_ioctl(struct drm_device *dev, void *data, struct drm_file *f case AMDGPU_PROFILER_OP_RESERVE: return -EOPNOTSUPP; case AMDGPU_PROFILER_OP_PMC: - return -EOPNOTSUPP; + return amdgpu_profiler_pmc(dev, filp, args->perfcount_enable); default: return -EINVAL; } -- 2.55.0
