From bd68f98ba76f43954e9858252a30e6c3b054c146 Mon Sep 17 00:00:00 2001 From: Terje Bergstrom Date: Mon, 1 May 2017 13:37:03 -0700 Subject: 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 --- drivers/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 ----------- drivers/gpu/nvgpu/platform_tegra.h | 29 ---------------------- .../gpu/nvgpu/tegra/linux/platform_gk20a_tegra.c | 25 ++++++++++++------- .../gpu/nvgpu/tegra/linux/platform_gk20a_tegra.h | 25 +++++++++++++++++++ .../gpu/nvgpu/tegra/linux/platform_gp10b_tegra.c | 9 ++++--- 8 files changed, 60 insertions(+), 85 deletions(-) delete mode 100644 drivers/gpu/nvgpu/platform_tegra.h create mode 100644 drivers/gpu/nvgpu/tegra/linux/platform_gk20a_tegra.h (limited to 'drivers') diff --git a/drivers/gpu/nvgpu/common/linux/driver_common.c b/drivers/gpu/nvgpu/common/linux/driver_common.c index 14d4dd40..7d6acf91 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 96ca69a3..03f61c33 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 2f52fdcf..2d87911d 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 8c93249a..44277abf 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/platform_tegra.h b/drivers/gpu/nvgpu/platform_tegra.h deleted file mode 100644 index 63aed5a7..00000000 --- a/drivers/gpu/nvgpu/platform_tegra.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * GK20A Platform (SoC) Interface - * - * Copyright (c) 2014-2016, 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, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - */ - -#ifndef _NVGPU_PLATFORM_TEGRA_H_ -#define _NVGPU_PLATFORM_TEGRA_H_ - -#include - -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); -int gk20a_tegra_secure_page_alloc(struct device *dev); - -#endif diff --git a/drivers/gpu/nvgpu/tegra/linux/platform_gk20a_tegra.c b/drivers/gpu/nvgpu/tegra/linux/platform_gk20a_tegra.c index 99c7e8b3..996fd251 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/tegra/linux/platform_gk20a_tegra.h b/drivers/gpu/nvgpu/tegra/linux/platform_gk20a_tegra.h new file mode 100644 index 00000000..1aa7c1e3 --- /dev/null +++ b/drivers/gpu/nvgpu/tegra/linux/platform_gk20a_tegra.h @@ -0,0 +1,25 @@ +/* + * GK20A Platform (SoC) Interface + * + * 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, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#ifndef _NVGPU_PLATFORM_GK20A_TEGRA_H_ +#define _NVGPU_PLATFORM_GK20A_TEGRA_H_ + +struct device; +struct gk20a; + +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 77b4b536..138b8fda 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, -- cgit v1.2.2