summaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/nvgpu/Makefile3
-rw-r--r--drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c32
-rw-r--r--drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c17
-rw-r--r--drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c38
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/vgpu/vgpu_ivm.h35
5 files changed, 101 insertions, 24 deletions
diff --git a/drivers/gpu/nvgpu/Makefile b/drivers/gpu/nvgpu/Makefile
index d9d1da95..4def6ee4 100644
--- a/drivers/gpu/nvgpu/Makefile
+++ b/drivers/gpu/nvgpu/Makefile
@@ -177,7 +177,8 @@ nvgpu-$(CONFIG_TEGRA_GR_VIRTUALIZATION) += \
177 common/linux/vgpu/css_vgpu.o \ 177 common/linux/vgpu/css_vgpu.o \
178 common/linux/vgpu/gm20b/vgpu_gr_gm20b.o \ 178 common/linux/vgpu/gm20b/vgpu_gr_gm20b.o \
179 common/linux/vgpu/sysfs_vgpu.o \ 179 common/linux/vgpu/sysfs_vgpu.o \
180 common/linux/vgpu/vgpu_ivc.o 180 common/linux/vgpu/vgpu_ivc.o \
181 common/linux/vgpu/vgpu_ivm.o
181 182
182nvgpu-$(CONFIG_COMMON_CLK) += \ 183nvgpu-$(CONFIG_COMMON_CLK) += \
183 common/linux/clk.o 184 common/linux/clk.o
diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c b/drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c
index ba13c54e..e0798475 100644
--- a/drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c
+++ b/drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c
@@ -15,7 +15,7 @@
15 */ 15 */
16#if defined(CONFIG_GK20A_CYCLE_STATS) 16#if defined(CONFIG_GK20A_CYCLE_STATS)
17 17
18#include <linux/tegra-ivc.h> 18#include <nvgpu/vgpu/vgpu_ivm.h>
19#include <linux/tegra_vgpu.h> 19#include <linux/tegra_vgpu.h>
20#include <uapi/linux/nvgpu.h> 20#include <uapi/linux/nvgpu.h>
21 21
@@ -45,7 +45,7 @@ static struct tegra_hv_ivm_cookie *vgpu_css_reserve_mempool(struct gk20a *g)
45 } 45 }
46 46
47 mempool = args.args[0]; 47 mempool = args.args[0];
48 cookie = tegra_hv_mempool_reserve(mempool); 48 cookie = vgpu_ivm_mempool_reserve(mempool);
49 if (IS_ERR_OR_NULL(cookie)) { 49 if (IS_ERR_OR_NULL(cookie)) {
50 nvgpu_err(g, "mempool %u reserve failed", mempool); 50 nvgpu_err(g, "mempool %u reserve failed", mempool);
51 return ERR_PTR(-EINVAL); 51 return ERR_PTR(-EINVAL);
@@ -61,18 +61,19 @@ u32 vgpu_css_get_buffer_size(struct gk20a *g)
61 nvgpu_log_fn(g, " "); 61 nvgpu_log_fn(g, " ");
62 62
63 if (css_cookie) { 63 if (css_cookie) {
64 nvgpu_log_info(g, "buffer size = %llu", css_cookie->size); 64 size = (u32)vgpu_ivm_get_size(css_cookie);
65 return (u32)css_cookie->size; 65 nvgpu_log_info(g, "buffer size = 0x%08x", size);
66 return size;
66 } 67 }
67 68
68 cookie = vgpu_css_reserve_mempool(g); 69 cookie = vgpu_css_reserve_mempool(g);
69 if (IS_ERR(cookie)) 70 if (IS_ERR(cookie))
70 return 0; 71 return 0;
71 72
72 size = cookie->size; 73 size = vgpu_ivm_get_size(cookie);
73 74
74 tegra_hv_mempool_unreserve(cookie); 75 vgpu_ivm_mempool_unreserve(cookie);
75 nvgpu_log_info(g, "buffer size = %u", size); 76 nvgpu_log_info(g, "buffer size = 0x%08x", size);
76 return size; 77 return size;
77} 78}
78 79
@@ -82,6 +83,7 @@ static int vgpu_css_init_snapshot_buffer(struct gr_gk20a *gr)
82 struct gk20a_cs_snapshot *data = gr->cs_data; 83 struct gk20a_cs_snapshot *data = gr->cs_data;
83 void *buf = NULL; 84 void *buf = NULL;
84 int err; 85 int err;
86 u64 size;
85 87
86 gk20a_dbg_fn(""); 88 gk20a_dbg_fn("");
87 89
@@ -92,15 +94,15 @@ static int vgpu_css_init_snapshot_buffer(struct gr_gk20a *gr)
92 if (IS_ERR(css_cookie)) 94 if (IS_ERR(css_cookie))
93 return PTR_ERR(css_cookie); 95 return PTR_ERR(css_cookie);
94 96
97 size = vgpu_ivm_get_size(css_cookie);
95 /* Make sure buffer size is large enough */ 98 /* Make sure buffer size is large enough */
96 if (css_cookie->size < CSS_MIN_HW_SNAPSHOT_SIZE) { 99 if (size < CSS_MIN_HW_SNAPSHOT_SIZE) {
97 nvgpu_info(g, "mempool size %lld too small", 100 nvgpu_info(g, "mempool size 0x%llx too small", size);
98 css_cookie->size);
99 err = -ENOMEM; 101 err = -ENOMEM;
100 goto fail; 102 goto fail;
101 } 103 }
102 104
103 buf = ioremap_cache(css_cookie->ipa, css_cookie->size); 105 buf = ioremap_cache(vgpu_ivm_get_ipa(css_cookie), size);
104 if (!buf) { 106 if (!buf) {
105 nvgpu_info(g, "ioremap_cache failed"); 107 nvgpu_info(g, "ioremap_cache failed");
106 err = -EINVAL; 108 err = -EINVAL;
@@ -109,12 +111,12 @@ static int vgpu_css_init_snapshot_buffer(struct gr_gk20a *gr)
109 111
110 data->hw_snapshot = buf; 112 data->hw_snapshot = buf;
111 data->hw_end = data->hw_snapshot + 113 data->hw_end = data->hw_snapshot +
112 css_cookie->size / sizeof(struct gk20a_cs_snapshot_fifo_entry); 114 size / sizeof(struct gk20a_cs_snapshot_fifo_entry);
113 data->hw_get = data->hw_snapshot; 115 data->hw_get = data->hw_snapshot;
114 memset(data->hw_snapshot, 0xff, css_cookie->size); 116 memset(data->hw_snapshot, 0xff, size);
115 return 0; 117 return 0;
116fail: 118fail:
117 tegra_hv_mempool_unreserve(css_cookie); 119 vgpu_ivm_mempool_unreserve(css_cookie);
118 css_cookie = NULL; 120 css_cookie = NULL;
119 return err; 121 return err;
120} 122}
@@ -129,7 +131,7 @@ void vgpu_css_release_snapshot_buffer(struct gr_gk20a *gr)
129 iounmap(data->hw_snapshot); 131 iounmap(data->hw_snapshot);
130 data->hw_snapshot = NULL; 132 data->hw_snapshot = NULL;
131 133
132 tegra_hv_mempool_unreserve(css_cookie); 134 vgpu_ivm_mempool_unreserve(css_cookie);
133 css_cookie = NULL; 135 css_cookie = NULL;
134 136
135 gk20a_dbg_info("cyclestats(vgpu): buffer for snapshots released\n"); 137 gk20a_dbg_info("cyclestats(vgpu): buffer for snapshots released\n");
diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c b/drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c
index bf692c4d..67a00c36 100644
--- a/drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c
+++ b/drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c
@@ -15,7 +15,6 @@
15 */ 15 */
16 16
17#include <linux/string.h> 17#include <linux/string.h>
18#include <linux/tegra-ivc.h>
19#include <linux/tegra_vgpu.h> 18#include <linux/tegra_vgpu.h>
20 19
21#include <uapi/linux/nvgpu.h> 20#include <uapi/linux/nvgpu.h>
@@ -24,6 +23,7 @@
24#include <nvgpu/bug.h> 23#include <nvgpu/bug.h>
25#include <nvgpu/enabled.h> 24#include <nvgpu/enabled.h>
26#include <nvgpu/ctxsw_trace.h> 25#include <nvgpu/ctxsw_trace.h>
26#include <nvgpu/vgpu/vgpu_ivm.h>
27 27
28#include "gk20a/gk20a.h" 28#include "gk20a/gk20a.h"
29#include "vgpu.h" 29#include "vgpu.h"
@@ -62,7 +62,7 @@ int vgpu_fecs_trace_init(struct gk20a *g)
62 __nvgpu_set_enabled(g, NVGPU_SUPPORT_FECS_CTXSW_TRACE, true); 62 __nvgpu_set_enabled(g, NVGPU_SUPPORT_FECS_CTXSW_TRACE, true);
63 63
64 mempool = args.args[0]; 64 mempool = args.args[0];
65 vcst->cookie = tegra_hv_mempool_reserve(mempool); 65 vcst->cookie = vgpu_ivm_mempool_reserve(mempool);
66 if (IS_ERR(vcst->cookie)) { 66 if (IS_ERR(vcst->cookie)) {
67 dev_info(dev_from_gk20a(g), 67 dev_info(dev_from_gk20a(g),
68 "mempool %u reserve failed\n", mempool); 68 "mempool %u reserve failed\n", mempool);
@@ -71,7 +71,8 @@ int vgpu_fecs_trace_init(struct gk20a *g)
71 goto fail; 71 goto fail;
72 } 72 }
73 73
74 vcst->buf = ioremap_cache(vcst->cookie->ipa, vcst->cookie->size); 74 vcst->buf = ioremap_cache(vgpu_ivm_get_ipa(vcst->cookie),
75 vgpu_ivm_get_size(vcst->cookie));
75 if (!vcst->buf) { 76 if (!vcst->buf) {
76 dev_info(dev_from_gk20a(g), "ioremap_cache failed\n"); 77 dev_info(dev_from_gk20a(g), "ioremap_cache failed\n");
77 err = -EINVAL; 78 err = -EINVAL;
@@ -91,7 +92,7 @@ int vgpu_fecs_trace_init(struct gk20a *g)
91fail: 92fail:
92 iounmap(vcst->buf); 93 iounmap(vcst->buf);
93 if (vcst->cookie) 94 if (vcst->cookie)
94 tegra_hv_mempool_unreserve(vcst->cookie); 95 vgpu_ivm_mempool_unreserve(vcst->cookie);
95 nvgpu_kfree(g, vcst); 96 nvgpu_kfree(g, vcst);
96 return err; 97 return err;
97} 98}
@@ -101,7 +102,7 @@ int vgpu_fecs_trace_deinit(struct gk20a *g)
101 struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace; 102 struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
102 103
103 iounmap(vcst->buf); 104 iounmap(vcst->buf);
104 tegra_hv_mempool_unreserve(vcst->cookie); 105 vgpu_ivm_mempool_unreserve(vcst->cookie);
105 nvgpu_kfree(g, vcst); 106 nvgpu_kfree(g, vcst);
106 return 0; 107 return 0;
107} 108}
@@ -164,7 +165,7 @@ int vgpu_alloc_user_buffer(struct gk20a *g, void **buf, size_t *size)
164 struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace; 165 struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
165 166
166 *buf = vcst->buf; 167 *buf = vcst->buf;
167 *size = vcst->cookie->size; 168 *size = vgpu_ivm_get_size(vcst->cookie);
168 return 0; 169 return 0;
169} 170}
170 171
@@ -176,14 +177,14 @@ int vgpu_free_user_buffer(struct gk20a *g)
176int vgpu_mmap_user_buffer(struct gk20a *g, struct vm_area_struct *vma) 177int vgpu_mmap_user_buffer(struct gk20a *g, struct vm_area_struct *vma)
177{ 178{
178 struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace; 179 struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
179 unsigned long size = vcst->cookie->size; 180 unsigned long size = vgpu_ivm_get_size(vcst->cookie);
180 unsigned long vsize = vma->vm_end - vma->vm_start; 181 unsigned long vsize = vma->vm_end - vma->vm_start;
181 182
182 size = min(size, vsize); 183 size = min(size, vsize);
183 size = round_up(size, PAGE_SIZE); 184 size = round_up(size, PAGE_SIZE);
184 185
185 return remap_pfn_range(vma, vma->vm_start, 186 return remap_pfn_range(vma, vma->vm_start,
186 vcst->cookie->ipa >> PAGE_SHIFT, 187 vgpu_ivm_get_ipa(vcst->cookie) >> PAGE_SHIFT,
187 size, 188 size,
188 vma->vm_page_prot); 189 vma->vm_page_prot);
189} 190}
diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c b/drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c
new file mode 100644
index 00000000..82475cac
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c
@@ -0,0 +1,38 @@
1/*
2 * Copyright (c) 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 <nvgpu/vgpu/vgpu_ivm.h>
18#include <linux/tegra-ivc.h>
19
20struct tegra_hv_ivm_cookie *vgpu_ivm_mempool_reserve(unsigned int id)
21{
22 return tegra_hv_mempool_reserve(id);
23}
24
25int vgpu_ivm_mempool_unreserve(struct tegra_hv_ivm_cookie *cookie)
26{
27 return tegra_hv_mempool_unreserve(cookie);
28}
29
30u64 vgpu_ivm_get_ipa(struct tegra_hv_ivm_cookie *cookie)
31{
32 return cookie->ipa;
33}
34
35u64 vgpu_ivm_get_size(struct tegra_hv_ivm_cookie *cookie)
36{
37 return cookie->size;
38}
diff --git a/drivers/gpu/nvgpu/include/nvgpu/vgpu/vgpu_ivm.h b/drivers/gpu/nvgpu/include/nvgpu/vgpu/vgpu_ivm.h
new file mode 100644
index 00000000..ba2cfc56
--- /dev/null
+++ b/drivers/gpu/nvgpu/include/nvgpu/vgpu/vgpu_ivm.h
@@ -0,0 +1,35 @@
1/*
2 * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23#ifndef __VGPU_IVM_H__
24#define __VGPU_IVM_H__
25
26#include <nvgpu/types.h>
27
28struct tegra_hv_ivm_cookie;
29
30struct tegra_hv_ivm_cookie *vgpu_ivm_mempool_reserve(unsigned int id);
31int vgpu_ivm_mempool_unreserve(struct tegra_hv_ivm_cookie *cookie);
32u64 vgpu_ivm_get_ipa(struct tegra_hv_ivm_cookie *cookie);
33u64 vgpu_ivm_get_size(struct tegra_hv_ivm_cookie *cookie);
34
35#endif