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]> Reviewed-by: Benjamin Welton <[email protected]> --- drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 35 +++++++++++++++++++- 1 file changed, 34 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..134660a4a4d3 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c @@ -23,9 +23,40 @@ */ #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; + struct amdgpu_device *adev; + + adev = drm_to_adev(dev); + if (!adev->pmc_profiler.supported) + return -EOPNOTSUPP; + + 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 +68,9 @@ 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; + if (args->perfcount_enable > 1) + return -EINVAL; + return amdgpu_profiler_pmc(dev, filp, args->perfcount_enable); default: return -EINVAL; } -- 2.53.0
