From 8cf5391330d5addeb269c056c9a9ec512cbbe7eb Mon Sep 17 00:00:00 2001 From: Sagar Kamble Date: Mon, 12 Oct 2020 11:28:37 +0530 Subject: [PATCH] gpu: nvgpu: create symbolic link gpu.0 under /sys/devices/ In linux kernel v4.14 and below gpu sysfs node is created under /sys/devices. In linux kernel v5.x it is created under /sys/devices/platform. Create symbolic link gpu.0 under /sys/devices/ as various tests and scripts expect it to be there. Bug 200665782 Change-Id: I807ce72fad94438f927df25e829082e771b72543 Signed-off-by: Sagar Kamble Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2426544 Tested-by: mobile promotions Reviewed-by: mobile promotions --- drivers/gpu/nvgpu/os/linux/sysfs.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/gpu/nvgpu/os/linux/sysfs.c b/drivers/gpu/nvgpu/os/linux/sysfs.c index 891468ce2..f49229229 100644 --- a/drivers/gpu/nvgpu/os/linux/sysfs.c +++ b/drivers/gpu/nvgpu/os/linux/sysfs.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -1109,6 +1110,13 @@ void nvgpu_remove_sysfs(struct device *dev) struct device *parent = container_of((kobj->parent), struct device, kobj); sysfs_remove_link(&parent->kobj, "gpu.0"); + +#if LINUX_VERSION_CODE > KERNEL_VERSION(4, 14, 0) + kobj = &parent->kobj; + parent = container_of((kobj->parent), + struct device, kobj); + sysfs_remove_link(&parent->kobj, "gpu.0"); +#endif } } @@ -1161,6 +1169,19 @@ int nvgpu_create_sysfs(struct device *dev) struct device, kobj); error |= sysfs_create_link(&parent->kobj, &dev->kobj, "gpu.0"); + +#if LINUX_VERSION_CODE > KERNEL_VERSION(4, 14, 0) + /* + * Create symbolic link under /sys/devices/ as various tests + * expect it to be there. Above sysfs_create_link creates + * it under /sys/devices/platform/ from kernels after v4.14. + */ + kobj = &parent->kobj; + parent = container_of((kobj->parent), + struct device, kobj); + error |= sysfs_create_link(&parent->kobj, + &dev->kobj, "gpu.0"); +#endif } if (error)