summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2017-05-23 13:21:14 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-05-30 16:24:35 -0400
commit66a2511a366113fa4d42dc500c9df9b348d9f208 (patch)
tree5d2367412887214d040d9ade1f1d48c93c434a46 /drivers/gpu/nvgpu/common
parentb817e9e207cca88698d28b6b4ab410f03d715171 (diff)
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 <alexw@nvidia.com> Reviewed-on: http://git-master/r/1488049 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common')
-rw-r--r--drivers/gpu/nvgpu/common/enabled.c48
-rw-r--r--drivers/gpu/nvgpu/common/linux/module.c11
-rw-r--r--drivers/gpu/nvgpu/common/linux/pci.c11
-rw-r--r--drivers/gpu/nvgpu/common/mm/gmmu.c3
4 files changed, 67 insertions, 6 deletions
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 @@
1/*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <nvgpu/enabled.h>
18#include <nvgpu/bitops.h>
19
20#include "gk20a/gk20a.h"
21
22int nvgpu_init_enabled_flags(struct gk20a *g)
23{
24 /*
25 * Zero all flags initially. Flags that should be set to non-zero states
26 * can be done so during driver init.
27 */
28 g->enabled_flags = nvgpu_kzalloc(g,
29 BITS_TO_LONGS(NVGPU_MAX_ENABLED_BITS) *
30 sizeof(unsigned long));
31 if (!g->enabled_flags)
32 return -ENOMEM;
33
34 return 0;
35}
36
37bool nvgpu_is_enabled(struct gk20a *g, int flag)
38{
39 return test_bit(flag, g->enabled_flags);
40}
41
42bool __nvgpu_set_enabled(struct gk20a *g, int flag, bool state)
43{
44 if (state)
45 return test_and_set_bit(flag, g->enabled_flags);
46 else
47 return test_and_clear_bit(flag, g->enabled_flags);
48}
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 @@
28#include <nvgpu/kmem.h> 28#include <nvgpu/kmem.h>
29#include <nvgpu/nvgpu_common.h> 29#include <nvgpu/nvgpu_common.h>
30#include <nvgpu/soc.h> 30#include <nvgpu/soc.h>
31#include <nvgpu/enabled.h>
31 32
32#include "gk20a/gk20a.h" 33#include "gk20a/gk20a.h"
33#include "gk20a/platform_gk20a.h" 34#include "gk20a/platform_gk20a.h"
@@ -873,11 +874,15 @@ static int gk20a_probe(struct platform_device *dev)
873 set_gk20a(dev, gk20a); 874 set_gk20a(dev, gk20a);
874 gk20a->dev = &dev->dev; 875 gk20a->dev = &dev->dev;
875 876
876 if (nvgpu_platform_is_simulation(gk20a))
877 gk20a->is_fmodel = true;
878
879 nvgpu_kmem_init(gk20a); 877 nvgpu_kmem_init(gk20a);
880 878
879 err = nvgpu_init_enabled_flags(gk20a);
880 if (err)
881 return err;
882
883 if (nvgpu_platform_is_simulation(gk20a))
884 __nvgpu_set_enabled(gk20a, NVGPU_IS_FMODEL, true);
885
881 gk20a->irq_stall = platform_get_irq(dev, 0); 886 gk20a->irq_stall = platform_get_irq(dev, 0);
882 gk20a->irq_nonstall = platform_get_irq(dev, 1); 887 gk20a->irq_nonstall = platform_get_irq(dev, 1);
883 if (gk20a->irq_stall < 0 || gk20a->irq_nonstall < 0) 888 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 @@
20 20
21#include <nvgpu/nvgpu_common.h> 21#include <nvgpu/nvgpu_common.h>
22#include <nvgpu/kmem.h> 22#include <nvgpu/kmem.h>
23#include <nvgpu/enabled.h>
23 24
24#include "gk20a/gk20a.h" 25#include "gk20a/gk20a.h"
25#include "gk20a/platform_gk20a.h" 26#include "gk20a/platform_gk20a.h"
@@ -358,11 +359,17 @@ static int nvgpu_pci_probe(struct pci_dev *pdev,
358 return -ENOMEM; 359 return -ENOMEM;
359 } 360 }
360 361
362 nvgpu_kmem_init(g);
363
364 err = nvgpu_init_enabled_flags(g);
365 if (err) {
366 kfree(g);
367 return err;
368 }
369
361 platform->g = g; 370 platform->g = g;
362 g->dev = &pdev->dev; 371 g->dev = &pdev->dev;
363 372
364 nvgpu_kmem_init(g);
365
366 err = pci_enable_device(pdev); 373 err = pci_enable_device(pdev);
367 if (err) 374 if (err)
368 return err; 375 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 @@
18#include <nvgpu/dma.h> 18#include <nvgpu/dma.h>
19#include <nvgpu/gmmu.h> 19#include <nvgpu/gmmu.h>
20#include <nvgpu/nvgpu_mem.h> 20#include <nvgpu/nvgpu_mem.h>
21#include <nvgpu/enabled.h>
21 22
22#include "gk20a/gk20a.h" 23#include "gk20a/gk20a.h"
23#include "gk20a/mm_gk20a.h" 24#include "gk20a/mm_gk20a.h"
@@ -74,7 +75,7 @@ static int nvgpu_alloc_gmmu_pages(struct vm_gk20a *vm, u32 order,
74 u32 len = num_pages * PAGE_SIZE; 75 u32 len = num_pages * PAGE_SIZE;
75 int err; 76 int err;
76 77
77 if (g->is_fmodel) 78 if (nvgpu_is_enabled(g, NVGPU_IS_FMODEL))
78 return alloc_gmmu_phys_pages(vm, order, entry); 79 return alloc_gmmu_phys_pages(vm, order, entry);
79 80
80 /* 81 /*