From a870ff1d294126a3b46db4e0fdc14276035a2840 Mon Sep 17 00:00:00 2001 From: Konsta Holtta Date: Thu, 2 Oct 2014 15:25:53 +0300 Subject: gpu: nvgpu: Remove get and put client routines gk20a_get_client() and gk20a_put_client() routines are effectively dead code. The GPU has been using pm_runtime for reference counting whether the device should be turned on or off, and gk20a_get_client() and gk20a_put_client() have had no positive effect on the behaviour. In worst case these functions trigger some issues as they may trigger code paths that should not be run. There is also a race between get/put and busy/idle. This patch removes the functions and reworks as_gk20a.c to correctly use gk20a_busy()/gk20a_idle() where put/get was required. Additionally, finalize_poweron() is moved to gk20a_busy(), similarly as it was with gk20a_get_client(). If pm_runtime is not in use, the device is only powered on and never off. Currently this affects vgpu power management since it does not use pm_runtime yet. Bug 1562096 Change-Id: I3162655f83457e9caccd9264eed36b5d51e60c52 Signed-off-by: Arto Merilainen Signed-off-by: Konsta Holtta Reviewed-on: http://git-master/r/414998 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Seshendra Gadagottu Tested-by: Seshendra Gadagottu GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/gk20a/as_gk20a.c | 22 ++++------ drivers/gpu/nvgpu/gk20a/channel_gk20a.c | 10 ----- drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c | 18 +------- drivers/gpu/nvgpu/gk20a/gk20a.c | 74 ++++----------------------------- drivers/gpu/nvgpu/gk20a/gk20a.h | 2 - 5 files changed, 16 insertions(+), 110 deletions(-) (limited to 'drivers/gpu/nvgpu') diff --git a/drivers/gpu/nvgpu/gk20a/as_gk20a.c b/drivers/gpu/nvgpu/gk20a/as_gk20a.c index 74d83a7d..27608cec 100644 --- a/drivers/gpu/nvgpu/gk20a/as_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/as_gk20a.c @@ -56,14 +56,19 @@ int gk20a_as_alloc_share(struct gk20a_as *as, as_share->ref_cnt.counter = 1; /* this will set as_share->vm. */ + err = gk20a_busy(g->dev); + if (err) + goto failed; err = g->ops.mm.vm_alloc_share(as_share, flags); + gk20a_idle(g->dev); + if (err) goto failed; *out = as_share; return 0; - failed: +failed: kfree(as_share); return err; } @@ -180,16 +185,9 @@ int gk20a_as_dev_open(struct inode *inode, struct file *filp) g = container_of(inode->i_cdev, struct gk20a, as.cdev); - err = gk20a_get_client(g); - if (err) { - gk20a_dbg_fn("fail to get channel!"); - return err; - } - err = gk20a_as_alloc_share(&g->as, 0, &as_share); if (err) { gk20a_dbg_fn("failed to alloc share"); - gk20a_put_client(g); return err; } @@ -200,16 +198,10 @@ int gk20a_as_dev_open(struct inode *inode, struct file *filp) int gk20a_as_dev_release(struct inode *inode, struct file *filp) { struct gk20a_as_share *as_share = filp->private_data; - int ret; - struct gk20a *g = gk20a_from_as(as_share->as); gk20a_dbg_fn(""); - ret = gk20a_as_release_share(as_share); - - gk20a_put_client(g); - - return ret; + return gk20a_as_release_share(as_share); } long gk20a_as_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) diff --git a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c index bcc05079..eaea5a77 100644 --- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c @@ -726,7 +726,6 @@ int gk20a_channel_release(struct inode *inode, struct file *filp) gk20a_free_channel(ch, true); gk20a_idle(ch->g->dev); - gk20a_put_client(g); filp->private_data = NULL; return 0; } @@ -788,23 +787,14 @@ static int __gk20a_channel_open(struct gk20a *g, struct file *filp) trace_gk20a_channel_open(dev_name(&g->dev->dev)); - err = gk20a_get_client(g); - if (err) { - gk20a_err(dev_from_gk20a(g), - "failed to get client ref"); - return err; - } - err = gk20a_busy(g->dev); if (err) { - gk20a_put_client(g); gk20a_err(dev_from_gk20a(g), "failed to power on, %d", err); return err; } ch = gk20a_open_new_channel(g); gk20a_idle(g->dev); if (!ch) { - gk20a_put_client(g); gk20a_err(dev_from_gk20a(g), "failed to get f"); return -ENOMEM; diff --git a/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c b/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c index 6969a3a7..fbc93fc3 100644 --- a/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c @@ -25,7 +25,6 @@ int gk20a_ctrl_dev_open(struct inode *inode, struct file *filp) { - int err; struct gk20a *g; gk20a_dbg_fn(""); @@ -35,22 +34,13 @@ int gk20a_ctrl_dev_open(struct inode *inode, struct file *filp) filp->private_data = g->dev; - err = gk20a_get_client(g); - if (err) { - gk20a_dbg_fn("fail to get channel!"); - return err; - } - return 0; } int gk20a_ctrl_dev_release(struct inode *inode, struct file *filp) { - struct platform_device *dev = filp->private_data; - gk20a_dbg_fn(""); - gk20a_put_client(get_gk20a(dev)); return 0; } @@ -177,21 +167,15 @@ static int gk20a_ctrl_alloc_as( } fd_install(fd, file); - err = gk20a_get_client(g); - if (err) - goto clean_up; - err = gk20a_as_alloc_share(&g->as, args->big_page_size, &as_share); if (err) - goto clean_up_client; + goto clean_up; file->private_data = as_share; args->as_fd = fd; return 0; -clean_up_client: - gk20a_put_client(g); clean_up: put_unused_fd(fd); return err; diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.c b/drivers/gpu/nvgpu/gk20a/gk20a.c index a09a0631..98dce955 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/gk20a.c @@ -734,72 +734,6 @@ static int gk20a_init_support(struct platform_device *dev) return err; } -static int gk20a_init_client(struct platform_device *dev) -{ - struct gk20a *g = get_gk20a(dev); - struct gk20a_platform *platform = gk20a_get_platform(dev); - int err; - - gk20a_dbg_fn(""); - - if (platform->virtual_dev) { - err = vgpu_pm_finalize_poweron(&dev->dev); - if (err) - return err; - } - -#ifndef CONFIG_PM_RUNTIME - gk20a_pm_finalize_poweron(&dev->dev); -#endif - - err = gk20a_init_mm_setup_sw(g); - if (err) - return err; - - if (IS_ENABLED(CONFIG_GK20A_DEVFREQ)) - gk20a_scale_hw_init(dev); - return 0; -} - -static void gk20a_deinit_client(struct platform_device *dev) -{ - struct gk20a_platform *platform = gk20a_get_platform(dev); - - gk20a_dbg_fn(""); - - if (platform->virtual_dev) { - vgpu_pm_prepare_poweroff(&dev->dev); - return; - } - -#ifndef CONFIG_PM_RUNTIME - gk20a_pm_prepare_poweroff(&dev->dev); -#endif -} - -int gk20a_get_client(struct gk20a *g) -{ - int err = 0; - - mutex_lock(&g->client_lock); - if (g->client_refcount == 0) - err = gk20a_init_client(g->dev); - if (!err) - g->client_refcount++; - mutex_unlock(&g->client_lock); - return err; -} - -void gk20a_put_client(struct gk20a *g) -{ - mutex_lock(&g->client_lock); - if (g->client_refcount == 1) - gk20a_deinit_client(g->dev); - g->client_refcount--; - mutex_unlock(&g->client_lock); - WARN_ON(g->client_refcount < 0); -} - static int gk20a_pm_prepare_poweroff(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); @@ -1662,6 +1596,14 @@ int gk20a_busy(struct platform_device *pdev) if (platform->idle) platform->idle(pdev); } +#else + if (!g->power_on) { + ret = platform->virtual_dev ? + vgpu_pm_finalize_poweron(&dev->dev) + : gk20a_pm_finalize_poweron(&dev->dev); + if (ret) + goto fail; + } #endif gk20a_scale_notify_busy(pdev); diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.h b/drivers/gpu/nvgpu/gk20a/gk20a.h index 04a4cf66..20afd2bd 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/gk20a.h @@ -710,8 +710,6 @@ void gk20a_idle(struct platform_device *pdev); void gk20a_disable(struct gk20a *g, u32 units); void gk20a_enable(struct gk20a *g, u32 units); void gk20a_reset(struct gk20a *g, u32 units); -int gk20a_get_client(struct gk20a *g); -void gk20a_put_client(struct gk20a *g); int __gk20a_do_idle(struct platform_device *pdev); int __gk20a_do_unidle(struct platform_device *pdev); -- cgit v1.2.2