From ce06f74d6ba9eb495661c29eabcd6da2f52c7c8b Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Thu, 23 Nov 2017 03:59:14 -0800 Subject: gpu: nvgpu: move cycle state buffer handler to linux We use dma_buf pointer cyclestate_buffer_handler in common code But since this is linux specific, we need to move this out of common code and into linux specific code Move dma_buf pointer cyclestate_buffer_handler from common channel code to struct nvgpu_channel_linux Fix all pointer accesses to this handle Move gk20a_channel_free_cycle_stats_buffer() to ioctl_channel.c since it is mostly linux specific And since gk20a_channel_free_cycle_stats_buffer() needs to be called while closing the channel, call it from nvgpu_channel_close_linux() Jira NVGPU-397 Jira NVGPU-415 Change-Id: Ifb429e49b8f7a1c9e2bc757f3efdd50b28ceca1f Signed-off-by: Deepak Nibade Reviewed-on: https://git-master.nvidia.com/r/1603909 GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/linux/ioctl_channel.c | 28 ++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'drivers/gpu/nvgpu/common/linux/ioctl_channel.c') diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_channel.c b/drivers/gpu/nvgpu/common/linux/ioctl_channel.c index 13355605..3a2f7b5e 100644 --- a/drivers/gpu/nvgpu/common/linux/ioctl_channel.c +++ b/drivers/gpu/nvgpu/common/linux/ioctl_channel.c @@ -102,17 +102,35 @@ struct channel_priv { #if defined(CONFIG_GK20A_CYCLE_STATS) +void gk20a_channel_free_cycle_stats_buffer(struct channel_gk20a *ch) +{ + struct nvgpu_channel_linux *priv = ch->os_priv; + + /* disable existing cyclestats buffer */ + nvgpu_mutex_acquire(&ch->cyclestate.cyclestate_buffer_mutex); + if (priv->cyclestate_buffer_handler) { + dma_buf_vunmap(priv->cyclestate_buffer_handler, + ch->cyclestate.cyclestate_buffer); + dma_buf_put(priv->cyclestate_buffer_handler); + priv->cyclestate_buffer_handler = NULL; + ch->cyclestate.cyclestate_buffer = NULL; + ch->cyclestate.cyclestate_buffer_size = 0; + } + nvgpu_mutex_release(&ch->cyclestate.cyclestate_buffer_mutex); +} + static int gk20a_channel_cycle_stats(struct channel_gk20a *ch, struct nvgpu_cycle_stats_args *args) { struct dma_buf *dmabuf; void *virtual_address; + struct nvgpu_channel_linux *priv = ch->os_priv; /* is it allowed to handle calls for current GPU? */ if (!nvgpu_is_enabled(ch->g, NVGPU_SUPPORT_CYCLE_STATS)) return -ENOSYS; - if (args->dmabuf_fd && !ch->cyclestate.cyclestate_buffer_handler) { + if (args->dmabuf_fd && !priv->cyclestate_buffer_handler) { /* set up new cyclestats buffer */ dmabuf = dma_buf_get(args->dmabuf_fd); @@ -122,18 +140,16 @@ static int gk20a_channel_cycle_stats(struct channel_gk20a *ch, if (!virtual_address) return -ENOMEM; - ch->cyclestate.cyclestate_buffer_handler = dmabuf; + priv->cyclestate_buffer_handler = dmabuf; ch->cyclestate.cyclestate_buffer = virtual_address; ch->cyclestate.cyclestate_buffer_size = dmabuf->size; return 0; - } else if (!args->dmabuf_fd && - ch->cyclestate.cyclestate_buffer_handler) { + } else if (!args->dmabuf_fd && priv->cyclestate_buffer_handler) { gk20a_channel_free_cycle_stats_buffer(ch); return 0; - } else if (!args->dmabuf_fd && - !ch->cyclestate.cyclestate_buffer_handler) { + } else if (!args->dmabuf_fd && !priv->cyclestate_buffer_handler) { /* no requst from GL */ return 0; -- cgit v1.2.2