From bd68f98ba76f43954e9858252a30e6c3b054c146 Mon Sep 17 00:00:00 2001 From: Terje Bergstrom Date: Mon, 1 May 2017 13:37:03 -0700 Subject: [PATCH] gpu: nvgpu: Move secure_alloc to struct gk20a Move the function pointer for VPR page allocation to struct gk20a and use it from there. At the same time remove secure_page_alloc pointer and add a direct call to it in probe. Move platform_tegra.h as tegra/linux/platform_gk20a_tegra.h, as it's only declaring functions defined in platform_gk20a_tegra.c to other files in the same directory. JIRA NVGPU-16 Change-Id: I19ac9ee0b2f6734203ae32a1f51d67fd51aced9f Signed-off-by: Terje Bergstrom Reviewed-on: http://git-master/r/1473706 Reviewed-by: mobile promotions Tested-by: mobile promotions --- .../gpu/nvgpu/common/linux/driver_common.c | 19 -------------- drivers/gpu/nvgpu/gk20a/gk20a.h | 8 ++++++ drivers/gpu/nvgpu/gk20a/gr_gk20a.c | 16 +++++------- drivers/gpu/nvgpu/gk20a/platform_gk20a.h | 14 ----------- .../nvgpu/tegra/linux/platform_gk20a_tegra.c | 25 ++++++++++++------- .../linux/platform_gk20a_tegra.h} | 16 +++++------- .../nvgpu/tegra/linux/platform_gp10b_tegra.c | 9 ++++--- 7 files changed, 41 insertions(+), 66 deletions(-) rename drivers/gpu/nvgpu/{platform_tegra.h => tegra/linux/platform_gk20a_tegra.h} (63%) diff --git a/drivers/gpu/nvgpu/common/linux/driver_common.c b/drivers/gpu/nvgpu/common/linux/driver_common.c index 14d4dd400..7d6acf919 100644 --- a/drivers/gpu/nvgpu/common/linux/driver_common.c +++ b/drivers/gpu/nvgpu/common/linux/driver_common.c @@ -134,20 +134,6 @@ static void nvgpu_init_mm_vars(struct gk20a *g) nvgpu_mutex_init(&g->mm.priv_lock); } -static int gk20a_secure_page_alloc(struct device *dev) -{ - struct gk20a_platform *platform = dev_get_drvdata(dev); - int err = 0; - - if (platform->secure_page_alloc) { - err = platform->secure_page_alloc(dev); - if (!err) - platform->secure_alloc_ready = true; - } - - return err; -} - int nvgpu_probe(struct gk20a *g, const char *debugfs_symlink, const char *interface_name, @@ -178,11 +164,6 @@ int nvgpu_probe(struct gk20a *g, if (IS_ENABLED(CONFIG_GK20A_DEVFREQ)) gk20a_scale_init(g->dev); - err = gk20a_secure_page_alloc(g->dev); - if (err) - dev_err(g->dev, - "failed to allocate secure buffer %d\n", err); - if (platform->late_probe) { err = platform->late_probe(g->dev); if (err) { diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.h b/drivers/gpu/nvgpu/gk20a/gk20a.h index 96ca69a3a..03f61c33c 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/gk20a.h @@ -669,6 +669,14 @@ struct gpu_ops { void (*init_inst_block)(struct nvgpu_mem *inst_block, struct vm_gk20a *vm, u32 big_page_size); bool (*mmu_fault_pending)(struct gk20a *g); + /* This function is called to allocate secure memory (memory + * that the CPU cannot see). The function should fill the + * context buffer descriptor (especially fields destroy, sgt, + * size). + */ + int (*secure_alloc)(struct device *dev, + struct gr_ctx_buffer_desc *desc, + size_t size); } mm; struct { u32 (*enter)(struct gk20a *g, struct nvgpu_mem *mem, diff --git a/drivers/gpu/nvgpu/gk20a/gr_gk20a.c b/drivers/gpu/nvgpu/gk20a/gr_gk20a.c index 2f52fdcf0..2d87911d4 100644 --- a/drivers/gpu/nvgpu/gk20a/gr_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/gr_gk20a.c @@ -2722,7 +2722,6 @@ static void gr_gk20a_free_global_ctx_buffers(struct gk20a *g) static int gr_gk20a_alloc_global_ctx_buffers(struct gk20a *g) { - struct gk20a_platform *platform = dev_get_drvdata(g->dev); struct gr_gk20a *gr = &g->gr; int attr_buffer_size, err; struct device *dev = g->dev; @@ -2744,8 +2743,8 @@ static int gr_gk20a_alloc_global_ctx_buffers(struct gk20a *g) if (err) goto clean_up; - if (platform->secure_alloc) - platform->secure_alloc(dev, + if (g->ops.mm.secure_alloc) + g->ops.mm.secure_alloc(dev, &gr->global_ctx_buffer[CIRCULAR_VPR], cb_buffer_size); @@ -2756,8 +2755,8 @@ static int gr_gk20a_alloc_global_ctx_buffers(struct gk20a *g) if (err) goto clean_up; - if (platform->secure_alloc) - platform->secure_alloc(dev, + if (g->ops.mm.secure_alloc) + g->ops.mm.secure_alloc(dev, &gr->global_ctx_buffer[PAGEPOOL_VPR], pagepool_buffer_size); @@ -2768,14 +2767,11 @@ static int gr_gk20a_alloc_global_ctx_buffers(struct gk20a *g) if (err) goto clean_up; - if (platform->secure_alloc) - platform->secure_alloc(dev, + if (g->ops.mm.secure_alloc) + g->ops.mm.secure_alloc(dev, &gr->global_ctx_buffer[ATTRIBUTE_VPR], attr_buffer_size); - if (platform->secure_buffer.destroy) - platform->secure_buffer.destroy(dev, &platform->secure_buffer); - gk20a_dbg_info("golden_image_size : %d", gr->ctx_vars.golden_image_size); diff --git a/drivers/gpu/nvgpu/gk20a/platform_gk20a.h b/drivers/gpu/nvgpu/gk20a/platform_gk20a.h index 8c93249a5..44277abf6 100644 --- a/drivers/gpu/nvgpu/gk20a/platform_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/platform_gk20a.h @@ -148,21 +148,7 @@ struct gk20a_platform { /* Powerdown platform dependencies */ void (*idle)(struct device *dev); - /* This function is called to allocate secure memory (memory that the - * CPU cannot see). The function should fill the context buffer - * descriptor (especially fields destroy, sgt, size). - */ - int (*secure_alloc)(struct device *dev, - struct gr_ctx_buffer_desc *desc, - size_t size); - - /* Function to allocate a secure buffer of PAGE_SIZE at probe time. - * This is also helpful to trigger secure memory resizing - * while GPU is off - */ - int (*secure_page_alloc)(struct device *dev); struct secure_page_buffer secure_buffer; - bool secure_alloc_ready; /* Device is going to be suspended */ int (*suspend)(struct device *); diff --git a/drivers/gpu/nvgpu/tegra/linux/platform_gk20a_tegra.c b/drivers/gpu/nvgpu/tegra/linux/platform_gk20a_tegra.c index 99c7e8b32..996fd251d 100644 --- a/drivers/gpu/nvgpu/tegra/linux/platform_gk20a_tegra.c +++ b/drivers/gpu/nvgpu/tegra/linux/platform_gk20a_tegra.c @@ -110,6 +110,8 @@ static void gk20a_tegra_secure_page_destroy(struct device *dev, dma_free_attrs(&tegra_vpr_dev, secure_buffer->size, (void *)(uintptr_t)secure_buffer->iova, secure_buffer->iova, __DMA_ATTR(attrs)); + + secure_buffer->destroy = NULL; } int gk20a_tegra_secure_page_alloc(struct device *dev) @@ -153,7 +155,7 @@ static void gk20a_tegra_secure_destroy(struct gk20a *g, } } -int gk20a_tegra_secure_alloc(struct device *dev, +static int gk20a_tegra_secure_alloc(struct device *dev, struct gr_ctx_buffer_desc *desc, size_t size) { @@ -164,9 +166,6 @@ int gk20a_tegra_secure_alloc(struct device *dev, struct page *page; int err = 0; - if (!platform->secure_alloc_ready) - return -EINVAL; - dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, __DMA_ATTR(attrs)); (void)dma_alloc_attrs(&tegra_vpr_dev, size, &iova, GFP_KERNEL, __DMA_ATTR(attrs)); @@ -194,6 +193,9 @@ int gk20a_tegra_secure_alloc(struct device *dev, desc->mem.size = size; desc->mem.aperture = APERTURE_SYSMEM; + if (platform->secure_buffer.destroy) + platform->secure_buffer.destroy(dev, &platform->secure_buffer); + return err; fail_sgt: @@ -896,6 +898,11 @@ void gk20a_tegra_idle(struct device *dev) #endif } +void gk20a_tegra_init_secure_alloc(struct gk20a *g) +{ + g->ops.mm.secure_alloc = gk20a_tegra_secure_alloc; +} + static int gk20a_tegra_probe(struct device *dev) { struct gk20a_platform *platform = dev_get_drvdata(dev); @@ -974,6 +981,7 @@ static int gk20a_tegra_probe(struct device *dev) gk20a_tegra_get_clocks(dev); nvgpu_linux_init_clk_support(platform->g); + gk20a_tegra_init_secure_alloc(platform->g); if (platform->clk_register) { ret = platform->clk_register(platform->g); @@ -988,8 +996,11 @@ static int gk20a_tegra_probe(struct device *dev) return 0; } -static int gk20a_tegra_late_probe(struct device *dev) +int gk20a_tegra_late_probe(struct device *dev) { + /* Cause early VPR resize */ + gk20a_tegra_secure_page_alloc(dev); + /* Initialise tegra specific scaling quirks */ gk20a_tegra_scale_init(dev); @@ -1085,8 +1096,6 @@ struct gk20a_platform gk20a_tegra_platform = { .devfreq_governor = "nvhost_podgov", .qos_notify = gk20a_scale_qos_notify, - .secure_alloc = gk20a_tegra_secure_alloc, - .secure_page_alloc = gk20a_tegra_secure_page_alloc, .dump_platform_dependencies = gk20a_tegra_debug_dump, .soc_name = "tegra12x", @@ -1157,8 +1166,6 @@ struct gk20a_platform gm20b_tegra_platform = { .devfreq_governor = "nvhost_podgov", .qos_notify = gk20a_scale_qos_notify, - .secure_alloc = gk20a_tegra_secure_alloc, - .secure_page_alloc = gk20a_tegra_secure_page_alloc, .dump_platform_dependencies = gk20a_tegra_debug_dump, .has_cde = true, diff --git a/drivers/gpu/nvgpu/platform_tegra.h b/drivers/gpu/nvgpu/tegra/linux/platform_gk20a_tegra.h similarity index 63% rename from drivers/gpu/nvgpu/platform_tegra.h rename to drivers/gpu/nvgpu/tegra/linux/platform_gk20a_tegra.h index 63aed5a70..1aa7c1e3f 100644 --- a/drivers/gpu/nvgpu/platform_tegra.h +++ b/drivers/gpu/nvgpu/tegra/linux/platform_gk20a_tegra.h @@ -1,7 +1,7 @@ /* * GK20A Platform (SoC) Interface * - * Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2014-2017, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -13,17 +13,13 @@ * more details. */ -#ifndef _NVGPU_PLATFORM_TEGRA_H_ -#define _NVGPU_PLATFORM_TEGRA_H_ +#ifndef _NVGPU_PLATFORM_GK20A_TEGRA_H_ +#define _NVGPU_PLATFORM_GK20A_TEGRA_H_ -#include +struct device; +struct gk20a; -struct platform_device; -struct gr_ctx_buffer_desc; - -int gk20a_tegra_secure_alloc(struct device *dev, - struct gr_ctx_buffer_desc *desc, - size_t size); +void gk20a_tegra_init_secure_alloc(struct gk20a *g); int gk20a_tegra_secure_page_alloc(struct device *dev); #endif diff --git a/drivers/gpu/nvgpu/tegra/linux/platform_gp10b_tegra.c b/drivers/gpu/nvgpu/tegra/linux/platform_gp10b_tegra.c index 77b4b5365..138b8fda0 100644 --- a/drivers/gpu/nvgpu/tegra/linux/platform_gp10b_tegra.c +++ b/drivers/gpu/nvgpu/tegra/linux/platform_gp10b_tegra.c @@ -36,7 +36,7 @@ #include "gk20a/gk20a.h" #include "gk20a/gk20a_scale.h" -#include "platform_tegra.h" +#include "platform_gk20a_tegra.h" #include "gp10b/gp10b_sysfs.h" #include "gp10b/platform_gp10b.h" @@ -163,12 +163,16 @@ static int gp10b_tegra_probe(struct device *dev) gp10b_tegra_get_clocks(dev); nvgpu_linux_init_clk_support(platform->g); + gk20a_tegra_init_secure_alloc(platform->g); return 0; } static int gp10b_tegra_late_probe(struct device *dev) { + /* Cause early VPR resize */ + gk20a_tegra_secure_page_alloc(dev); + /*Create GP10B specific sysfs*/ gp10b_create_sysfs(dev); @@ -423,9 +427,6 @@ struct gk20a_platform gp10b_tegra_platform = { .qos_notify = gk20a_scale_qos_notify, - .secure_alloc = gk20a_tegra_secure_alloc, - .secure_page_alloc = gk20a_tegra_secure_page_alloc, - .reset_assert = gp10b_tegra_reset_assert, .reset_deassert = gp10b_tegra_reset_deassert,