aboutsummaryrefslogtreecommitdiffstats
path: root/include/os/linux/sim_pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'include/os/linux/sim_pci.c')
-rw-r--r--include/os/linux/sim_pci.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/include/os/linux/sim_pci.c b/include/os/linux/sim_pci.c
new file mode 100644
index 0000000..340f1fa
--- /dev/null
+++ b/include/os/linux/sim_pci.c
@@ -0,0 +1,93 @@
1/*
2 * Copyright (c) 2017-2018, 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 <linux/io.h>
18#include <linux/highmem.h>
19#include <linux/platform_device.h>
20
21#include <nvgpu/log.h>
22#include <nvgpu/linux/vm.h>
23#include <nvgpu/bitops.h>
24#include <nvgpu/nvgpu_mem.h>
25#include <nvgpu/dma.h>
26#include <nvgpu/hw_sim_pci.h>
27#include <nvgpu/sim.h>
28#include <nvgpu/io.h>
29#include <nvgpu/gk20a.h>
30
31#include "os_linux.h"
32#include "module.h"
33
34static bool _nvgpu_pci_is_simulation(struct gk20a *g, u32 sim_base)
35{
36 u32 cfg;
37 bool is_simulation = false;
38
39 cfg = nvgpu_readl(g, sim_base + sim_config_r());
40 if (sim_config_mode_v(cfg) == sim_config_mode_enabled_v())
41 is_simulation = true;
42
43 return is_simulation;
44}
45
46void nvgpu_remove_sim_support_linux_pci(struct gk20a *g)
47{
48 struct sim_nvgpu_linux *sim_linux;
49 bool is_simulation;
50
51 is_simulation = _nvgpu_pci_is_simulation(g, sim_r());
52
53 if (!is_simulation) {
54 return;
55 }
56
57 if (!g->sim) {
58 nvgpu_warn(g, "sim_gk20a not allocated");
59 return;
60 }
61 sim_linux = container_of(g->sim, struct sim_nvgpu_linux, sim);
62
63 if (sim_linux->regs) {
64 sim_writel(g->sim, sim_config_r(), sim_config_mode_disabled_v());
65 sim_linux->regs = NULL;
66 }
67 nvgpu_kfree(g, sim_linux);
68 g->sim = NULL;
69}
70
71int nvgpu_init_sim_support_linux_pci(struct gk20a *g)
72{
73 struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g);
74 struct sim_nvgpu_linux *sim_linux;
75 int err = -ENOMEM;
76 bool is_simulation;
77
78 is_simulation = _nvgpu_pci_is_simulation(g, sim_r());
79 __nvgpu_set_enabled(g, NVGPU_IS_FMODEL, is_simulation);
80
81 if (!is_simulation)
82 return 0;
83
84 sim_linux = nvgpu_kzalloc(g, sizeof(*sim_linux));
85 if (!sim_linux)
86 return err;
87 g->sim = &sim_linux->sim;
88 g->sim->g = g;
89 sim_linux->regs = l->regs + sim_r();
90 sim_linux->remove_support_linux = nvgpu_remove_sim_support_linux_pci;
91
92 return 0;
93}