summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/os/linux/soc.c
diff options
context:
space:
mode:
authorTerje Bergstrom <tbergstrom@nvidia.com>2018-04-18 15:59:00 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2018-06-15 20:47:31 -0400
commit2a2c16af5f9f1ccfc93a13e820d5381e5c881e92 (patch)
tree2e5d7b042270a649978e5bb540857012c85fb5b5 /drivers/gpu/nvgpu/os/linux/soc.c
parent98d996f4ffb0137d119b5849cae46d7b7e5693e1 (diff)
gpu: nvgpu: Move Linux files away from common
Move all Linux source code files to drivers/gpu/nvgpu/os/linux from drivers/gpu/nvgpu/common/linux. This changes the meaning of common to be OS independent. JIRA NVGPU-598 JIRA NVGPU-601 Change-Id: Ib7f2a43d3688bb0d0b7dcc48469a6783fd988ce9 Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1747714 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/os/linux/soc.c')
-rw-r--r--drivers/gpu/nvgpu/os/linux/soc.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/os/linux/soc.c b/drivers/gpu/nvgpu/os/linux/soc.c
new file mode 100644
index 00000000..1b27d6f1
--- /dev/null
+++ b/drivers/gpu/nvgpu/os/linux/soc.c
@@ -0,0 +1,122 @@
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
14#include <soc/tegra/chip-id.h>
15#include <soc/tegra/fuse.h>
16#include <soc/tegra/tegra_bpmp.h>
17#ifdef CONFIG_TEGRA_HV_MANAGER
18#include <soc/tegra/virt/syscalls.h>
19#endif
20
21#include <nvgpu/soc.h>
22#include "os_linux.h"
23#include "platform_gk20a.h"
24
25bool nvgpu_platform_is_silicon(struct gk20a *g)
26{
27 return tegra_platform_is_silicon();
28}
29
30bool nvgpu_platform_is_simulation(struct gk20a *g)
31{
32 return tegra_platform_is_vdk();
33}
34
35bool nvgpu_platform_is_fpga(struct gk20a *g)
36{
37 return tegra_platform_is_fpga();
38}
39
40bool nvgpu_is_hypervisor_mode(struct gk20a *g)
41{
42 return is_tegra_hypervisor_mode();
43}
44
45bool nvgpu_is_bpmp_running(struct gk20a *g)
46{
47 return tegra_bpmp_running();
48}
49
50bool nvgpu_is_soc_t194_a01(struct gk20a *g)
51{
52 return ((tegra_get_chip_id() == TEGRA194 &&
53 tegra_chip_get_revision() == TEGRA194_REVISION_A01) ?
54 true : false);
55}
56
57#ifdef CONFIG_TEGRA_HV_MANAGER
58/* When nvlink is enabled on dGPU, we need to use physical memory addresses.
59 * There is no SMMU translation. However, the device initially enumerates as a
60 * PCIe device. As such, when allocation memory for this PCIe device, the DMA
61 * framework ends up allocating memory using SMMU (if enabled in device tree).
62 * As a result, when we switch to nvlink, we need to use underlying physical
63 * addresses, even if memory mappings exist in SMMU.
64 * In addition, when stage-2 SMMU translation is enabled (for instance when HV
65 * is enabled), the addresses we get from dma_alloc are IPAs. We need to
66 * convert them to PA.
67 */
68static u64 nvgpu_tegra_hv_ipa_pa(struct gk20a *g, u64 ipa)
69{
70 struct device *dev = dev_from_gk20a(g);
71 struct gk20a_platform *platform = gk20a_get_platform(dev);
72 struct hyp_ipa_pa_info info;
73 int err;
74 u64 pa = 0ULL;
75
76 err = hyp_read_ipa_pa_info(&info, platform->vmid, ipa);
77 if (err < 0) {
78 /* WAR for bug 2096877
79 * hyp_read_ipa_pa_info only looks up RAM mappings.
80 * assume one to one IPA:PA mapping for syncpt aperture
81 */
82 u64 start = g->syncpt_unit_base;
83 u64 end = g->syncpt_unit_base + g->syncpt_unit_size;
84 if ((ipa >= start) && (ipa < end)) {
85 pa = ipa;
86 nvgpu_log(g, gpu_dbg_map_v,
87 "ipa=%llx vmid=%d -> pa=%llx (SYNCPT)\n",
88 ipa, platform->vmid, pa);
89 } else {
90 nvgpu_err(g, "ipa=%llx translation failed vmid=%u err=%d",
91 ipa, platform->vmid, err);
92 }
93 } else {
94 pa = info.base + info.offset;
95 nvgpu_log(g, gpu_dbg_map_v,
96 "ipa=%llx vmid=%d -> pa=%llx "
97 "base=%llx offset=%llx size=%llx\n",
98 ipa, platform->vmid, pa, info.base,
99 info.offset, info.size);
100 }
101 return pa;
102}
103#endif
104
105int nvgpu_init_soc_vars(struct gk20a *g)
106{
107#ifdef CONFIG_TEGRA_HV_MANAGER
108 struct device *dev = dev_from_gk20a(g);
109 struct gk20a_platform *platform = gk20a_get_platform(dev);
110 int err;
111
112 if (nvgpu_is_hypervisor_mode(g)) {
113 err = hyp_read_gid(&platform->vmid);
114 if (err) {
115 nvgpu_err(g, "failed to read vmid");
116 return err;
117 }
118 platform->phys_addr = nvgpu_tegra_hv_ipa_pa;
119 }
120#endif
121 return 0;
122}