From 71cd434f4f03f82f729ce39c7a429337607e6c10 Mon Sep 17 00:00:00 2001 From: Rajkumar Kasirajan Date: Sun, 14 Nov 2021 23:14:31 +0800 Subject: [PATCH] gpu: nvgpu: add thermal cooling support Add devfeq thermal cooling device for GPU software thermal throttling. Bug 3287074 Change-Id: Ib0b53a58177964dfda3c8993da9c4835e2cb8a6e Signed-off-by: Rajkumar Kasirajan Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2625659 Reviewed-by: svcacv Reviewed-by: Seshendra Gadagottu Reviewed-by: Srikar Srimath Tirumala Reviewed-by: Bibek Basu Reviewed-by: mobile promotions Tested-by: Seshendra Gadagottu Tested-by: mobile promotions GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/os/linux/os_linux.h | 3 +++ drivers/gpu/nvgpu/os/linux/scale.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/drivers/gpu/nvgpu/os/linux/os_linux.h b/drivers/gpu/nvgpu/os/linux/os_linux.h index 902db354d..a7ef5319b 100644 --- a/drivers/gpu/nvgpu/os/linux/os_linux.h +++ b/drivers/gpu/nvgpu/os/linux/os_linux.h @@ -74,6 +74,9 @@ struct nvgpu_os_linux { struct device *dev; struct dgpu_thermal_alert thermal_alert; struct nvgpu_interrupts interrupts; +#ifdef CONFIG_DEVFREQ_THERMAL + struct thermal_cooling_device *cooling; +#endif struct nvgpu_list_node class_list_head; struct nvgpu_list_node cdev_list_head; diff --git a/drivers/gpu/nvgpu/os/linux/scale.c b/drivers/gpu/nvgpu/os/linux/scale.c index bb812d2e4..b89928553 100644 --- a/drivers/gpu/nvgpu/os/linux/scale.c +++ b/drivers/gpu/nvgpu/os/linux/scale.c @@ -17,6 +17,9 @@ */ #include +#ifdef CONFIG_DEVFREQ_THERMAL +#include +#endif #include #include #include @@ -384,6 +387,9 @@ void gk20a_scale_init(struct device *dev) struct gk20a *g = platform->g; struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); struct gk20a_scale_profile *profile; +#ifdef CONFIG_DEVFREQ_THERMAL + struct thermal_cooling_device *cooling; +#endif int err; if (g->scale_profile) @@ -434,6 +440,14 @@ void gk20a_scale_init(struct device *dev) l->devfreq = devfreq; +#ifdef CONFIG_DEVFREQ_THERMAL + cooling = of_devfreq_cooling_register(dev->of_node, devfreq); + if (IS_ERR(cooling)) + dev_info(dev, "Failed to register cooling device\n"); + else + l->cooling = cooling; +#endif + /* create symlink /sys/devices/gpu.0/devfreq_dev */ if (devfreq != NULL) { error = sysfs_create_link(&dev->kobj, @@ -485,6 +499,13 @@ void gk20a_scale_exit(struct device *dev) } #endif +#ifdef CONFIG_DEVFREQ_THERMAL + if (l->cooling) { + devfreq_cooling_unregister(l->cooling); + l->cooling = NULL; + } +#endif + if (platform->devfreq_governor) { sysfs_remove_link(&dev->kobj, "devfreq_dev");