diff --git a/drivers/gpu/msm/adreno.c b/drivers/gpu/msm/adreno.c index 08a54d3d0478..8ab1514ebe6a 100644 --- a/drivers/gpu/msm/adreno.c +++ b/drivers/gpu/msm/adreno.c @@ -1552,6 +1552,8 @@ int adreno_device_probe(struct platform_device *pdev, adreno_debugfs_init(adreno_dev); adreno_profile_init(adreno_dev); + adreno_dev->perfcounter = false; + adreno_sysfs_init(adreno_dev); kgsl_pwrscale_init(device, pdev, CONFIG_QCOM_ADRENO_DEFAULT_GOVERNOR); diff --git a/drivers/gpu/msm/adreno.h b/drivers/gpu/msm/adreno.h index 833ff5211925..e7dd6c18a6ad 100644 --- a/drivers/gpu/msm/adreno.h +++ b/drivers/gpu/msm/adreno.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* * Copyright (c) 2008-2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. */ #ifndef __ADRENO_H #define __ADRENO_H @@ -576,6 +577,11 @@ struct adreno_device { const void *cp_init_cmds; /** @irq_mask: The current interrupt mask for the GPU device */ u32 irq_mask; + /* + * @perfcounter: Flag to clear perfcounters across contexts and + * controls perfcounter ioctl read + */ + bool perfcounter; }; /** diff --git a/drivers/gpu/msm/adreno_compat.c b/drivers/gpu/msm/adreno_compat.c index 2c568e979fa1..e00dc4897a93 100644 --- a/drivers/gpu/msm/adreno_compat.c +++ b/drivers/gpu/msm/adreno_compat.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2013-2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. */ #include "adreno.h" @@ -158,6 +159,14 @@ static long adreno_ioctl_perfcounter_read_compat( struct kgsl_perfcounter_read_compat *read32 = data; struct kgsl_perfcounter_read read; + /* + * When performance counter zapping is enabled, the counters are cleared + * across context switches. Reading the counters when they are zapped is + * not permitted. + */ + if (!adreno_dev->perfcounter) + return -EPERM; + read.reads = (struct kgsl_perfcounter_read_group __user *) (uintptr_t)read32->reads; read.count = read32->count; diff --git a/drivers/gpu/msm/adreno_ioctl.c b/drivers/gpu/msm/adreno_ioctl.c index 2b69d7934d78..5d77bd8ad9e3 100644 --- a/drivers/gpu/msm/adreno_ioctl.c +++ b/drivers/gpu/msm/adreno_ioctl.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2002,2007-2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -133,6 +134,14 @@ static long adreno_ioctl_perfcounter_read(struct kgsl_device_private *dev_priv, struct adreno_device *adreno_dev = ADRENO_DEVICE(dev_priv->device); struct kgsl_perfcounter_read *read = data; + /* + * When performance counter zapping is enabled, the counters are cleared + * across context switches. Reading the counters when they are zapped is + * not permitted. + */ + if (!adreno_dev->perfcounter) + return -EPERM; + return (long) adreno_perfcounter_read_group(adreno_dev, read->reads, read->count); } diff --git a/drivers/gpu/msm/adreno_sysfs.c b/drivers/gpu/msm/adreno_sysfs.c index 4152bb63fdaa..310fb4ecf5a1 100644 --- a/drivers/gpu/msm/adreno_sysfs.c +++ b/drivers/gpu/msm/adreno_sysfs.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2014-2020, The Linux Foundation. All rights reserved. + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -188,6 +189,19 @@ static int _bcl_store(struct adreno_device *adreno_dev, bool val) val); } +static bool _perfcounter_show(struct adreno_device *adreno_dev) +{ + return adreno_dev->perfcounter; +} + +static int _perfcounter_store(struct adreno_device *adreno_dev, bool val) +{ + if (adreno_dev->perfcounter == val) + return 0; + + return adreno_power_cycle_bool(adreno_dev, &adreno_dev->perfcounter, val); +} + ssize_t adreno_sysfs_store_u32(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -266,6 +280,7 @@ static ADRENO_SYSFS_BOOL(ifpc); static ADRENO_SYSFS_RO_U32(ifpc_count); static ADRENO_SYSFS_BOOL(acd); static ADRENO_SYSFS_BOOL(bcl); +static ADRENO_SYSFS_BOOL(perfcounter); static const struct attribute *_attr_list[] = { @@ -285,6 +300,7 @@ static const struct attribute *_attr_list[] = { &adreno_attr_ifpc_count.attr.attr, &adreno_attr_acd.attr.attr, &adreno_attr_bcl.attr.attr, + &adreno_attr_perfcounter.attr.attr, NULL, }; @@ -311,7 +327,14 @@ void adreno_sysfs_close(struct adreno_device *adreno_dev) int adreno_sysfs_init(struct adreno_device *adreno_dev) { struct kgsl_device *device = KGSL_DEVICE(adreno_dev); + int ret; - return sysfs_create_files(&device->dev->kobj, _attr_list); + ret = sysfs_create_files(&device->dev->kobj, _attr_list); + + /* Notify userspace */ + if (!ret) + kobject_uevent(&device->dev->kobj, KOBJ_ADD); + + return ret; }