From 9e4bbd2c9b4d5d9712921a7db058061e4f8cd389 Mon Sep 17 00:00:00 2001 From: Nicolin Chen Date: Thu, 30 Aug 2018 14:52:16 -0700 Subject: gpu: nvgpu: Add configurable comptag_mem_deduct sysfs node per device Adding a comptag_mem_deduct in the platform_gk20a has certain problems: 1) It's not really convenient for platform users to configure it. 2) All products using the same GPU have to share the same configuration. So this patch moves this comptag_mem_deduct from struct platform_gk20a to struct gr_gk20a (per device). And it adds an sysfs node for products or platform users to easily configure from user space. Note: The comptag memory will not be allocated until the GPU driver goes through the final poweron routine. So the user space has a small window to configure this sysfs node. Bug 2327574 Bug 2284925 Change-Id: Ie7d00b082704e422645c0ea254b59e22f9fc3b7f Signed-off-by: Nicolin Chen Reviewed-on: https://git-master.nvidia.com/r/1810334 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/os/linux/sysfs.c | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'drivers/gpu/nvgpu/os/linux/sysfs.c') diff --git a/drivers/gpu/nvgpu/os/linux/sysfs.c b/drivers/gpu/nvgpu/os/linux/sysfs.c index a42070d4..5eef8bfa 100644 --- a/drivers/gpu/nvgpu/os/linux/sysfs.c +++ b/drivers/gpu/nvgpu/os/linux/sysfs.c @@ -22,6 +22,7 @@ #include #include +#include "os_linux.h" #include "sysfs.h" #include "platform_gk20a.h" #include "gk20a/gr_gk20a.h" @@ -1159,6 +1160,40 @@ static DEVICE_ATTR(gfxp_wfi_timeout_count, (S_IRWXU|S_IRGRP|S_IROTH), static DEVICE_ATTR(gfxp_wfi_timeout_unit, (S_IRWXU|S_IRGRP|S_IROTH), gfxp_wfi_timeout_unit_read, gfxp_wfi_timeout_unit_store); +static ssize_t comptag_mem_deduct_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct gk20a *g = get_gk20a(dev); + unsigned long val; + + if (kstrtoul(buf, 10, &val) < 0) + return -EINVAL; + + if (val >= totalram_size_in_mb) { + dev_err(dev, "comptag_mem_deduct can not be set above %lu", + totalram_size_in_mb); + return -EINVAL; + } + + g->gr.comptag_mem_deduct = val; + /* Deduct the part taken by the running system */ + g->gr.max_comptag_mem -= val; + + return count; +} + +static ssize_t comptag_mem_deduct_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct gk20a *g = get_gk20a(dev); + + return sprintf(buf, "%d\n", g->gr.comptag_mem_deduct); +} + +static DEVICE_ATTR(comptag_mem_deduct, ROOTRW, + comptag_mem_deduct_show, comptag_mem_deduct_store); + void nvgpu_remove_sysfs(struct device *dev) { device_remove_file(dev, &dev_attr_elcg_enable); @@ -1200,6 +1235,8 @@ void nvgpu_remove_sysfs(struct device *dev) device_remove_file(dev, &dev_attr_gfxp_wfi_timeout_count); device_remove_file(dev, &dev_attr_gfxp_wfi_timeout_unit); + device_remove_file(dev, &dev_attr_comptag_mem_deduct); + if (strcmp(dev_name(dev), "gpu.0")) { struct kobject *kobj = &dev->kobj; struct device *parent = container_of((kobj->parent), @@ -1252,6 +1289,8 @@ int nvgpu_create_sysfs(struct device *dev) error |= device_create_file(dev, &dev_attr_gfxp_wfi_timeout_count); error |= device_create_file(dev, &dev_attr_gfxp_wfi_timeout_unit); + error |= device_create_file(dev, &dev_attr_comptag_mem_deduct); + if (strcmp(dev_name(dev), "gpu.0")) { struct kobject *kobj = &dev->kobj; struct device *parent = container_of((kobj->parent), -- cgit v1.2.2