From 66a2511a366113fa4d42dc500c9df9b348d9f208 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Tue, 23 May 2017 18:21:14 +0100 Subject: gpu: nvgpu: Begin removing variables in struct gk20a Begin removing all of the myriad flag variables in struct gk20a and replace that with one API that checks for flags being enabled or disabled. The API is as follows: bool nvgpu_is_enabled(struct gk20a *g, int flag); bool __nvgpu_set_enabled(struct gk20a *g, int flag, bool state); These APIs allow many of the gk20a flags to be replaced by defines. This makes flag usage consistent and saves a small amount of memory in struct gk20a. Also it makes struct gk20a easier to read since there's less clutter scattered through out. JIRA NVGPU-84 Change-Id: I6525cecbe97c4e8379e5f53e29ef0b4dbd1a7fc2 Signed-off-by: Alex Waterman Reviewed-on: http://git-master/r/1488049 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/enabled.c | 48 +++++++++++++++++++++++++++++++++ drivers/gpu/nvgpu/common/linux/module.c | 11 +++++--- drivers/gpu/nvgpu/common/linux/pci.c | 11 ++++++-- drivers/gpu/nvgpu/common/mm/gmmu.c | 3 ++- 4 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 drivers/gpu/nvgpu/common/enabled.c (limited to 'drivers/gpu/nvgpu/common') diff --git a/drivers/gpu/nvgpu/common/enabled.c b/drivers/gpu/nvgpu/common/enabled.c new file mode 100644 index 00000000..d56f0551 --- /dev/null +++ b/drivers/gpu/nvgpu/common/enabled.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "gk20a/gk20a.h" + +int nvgpu_init_enabled_flags(struct gk20a *g) +{ + /* + * Zero all flags initially. Flags that should be set to non-zero states + * can be done so during driver init. + */ + g->enabled_flags = nvgpu_kzalloc(g, + BITS_TO_LONGS(NVGPU_MAX_ENABLED_BITS) * + sizeof(unsigned long)); + if (!g->enabled_flags) + return -ENOMEM; + + return 0; +} + +bool nvgpu_is_enabled(struct gk20a *g, int flag) +{ + return test_bit(flag, g->enabled_flags); +} + +bool __nvgpu_set_enabled(struct gk20a *g, int flag, bool state) +{ + if (state) + return test_and_set_bit(flag, g->enabled_flags); + else + return test_and_clear_bit(flag, g->enabled_flags); +} diff --git a/drivers/gpu/nvgpu/common/linux/module.c b/drivers/gpu/nvgpu/common/linux/module.c index adf9ff37..d5fc40de 100644 --- a/drivers/gpu/nvgpu/common/linux/module.c +++ b/drivers/gpu/nvgpu/common/linux/module.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "gk20a/gk20a.h" #include "gk20a/platform_gk20a.h" @@ -873,11 +874,15 @@ static int gk20a_probe(struct platform_device *dev) set_gk20a(dev, gk20a); gk20a->dev = &dev->dev; - if (nvgpu_platform_is_simulation(gk20a)) - gk20a->is_fmodel = true; - nvgpu_kmem_init(gk20a); + err = nvgpu_init_enabled_flags(gk20a); + if (err) + return err; + + if (nvgpu_platform_is_simulation(gk20a)) + __nvgpu_set_enabled(gk20a, NVGPU_IS_FMODEL, true); + gk20a->irq_stall = platform_get_irq(dev, 0); gk20a->irq_nonstall = platform_get_irq(dev, 1); if (gk20a->irq_stall < 0 || gk20a->irq_nonstall < 0) diff --git a/drivers/gpu/nvgpu/common/linux/pci.c b/drivers/gpu/nvgpu/common/linux/pci.c index 767e9d47..0a5095fe 100644 --- a/drivers/gpu/nvgpu/common/linux/pci.c +++ b/drivers/gpu/nvgpu/common/linux/pci.c @@ -20,6 +20,7 @@ #include #include +#include #include "gk20a/gk20a.h" #include "gk20a/platform_gk20a.h" @@ -358,11 +359,17 @@ static int nvgpu_pci_probe(struct pci_dev *pdev, return -ENOMEM; } + nvgpu_kmem_init(g); + + err = nvgpu_init_enabled_flags(g); + if (err) { + kfree(g); + return err; + } + platform->g = g; g->dev = &pdev->dev; - nvgpu_kmem_init(g); - err = pci_enable_device(pdev); if (err) return err; diff --git a/drivers/gpu/nvgpu/common/mm/gmmu.c b/drivers/gpu/nvgpu/common/mm/gmmu.c index 695347bc..dc91cc2f 100644 --- a/drivers/gpu/nvgpu/common/mm/gmmu.c +++ b/drivers/gpu/nvgpu/common/mm/gmmu.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "gk20a/gk20a.h" #include "gk20a/mm_gk20a.h" @@ -74,7 +75,7 @@ static int nvgpu_alloc_gmmu_pages(struct vm_gk20a *vm, u32 order, u32 len = num_pages * PAGE_SIZE; int err; - if (g->is_fmodel) + if (nvgpu_is_enabled(g, NVGPU_IS_FMODEL)) return alloc_gmmu_phys_pages(vm, order, entry); /* -- cgit v1.2.2