summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gk20a/bus_gk20a.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/bus_gk20a.c')
-rw-r--r--drivers/gpu/nvgpu/gk20a/bus_gk20a.c173
1 files changed, 173 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/bus_gk20a.c b/drivers/gpu/nvgpu/gk20a/bus_gk20a.c
new file mode 100644
index 00000000..7f0cfe58
--- /dev/null
+++ b/drivers/gpu/nvgpu/gk20a/bus_gk20a.c
@@ -0,0 +1,173 @@
1/*
2 * Copyright (c) 2017, 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#include <nvgpu/page_allocator.h>
24#include <nvgpu/log.h>
25#include <nvgpu/soc.h>
26#include <nvgpu/bus.h>
27#include <nvgpu/mm.h>
28
29#include "gk20a.h"
30#include "bus_gk20a.h"
31
32#include <nvgpu/hw/gk20a/hw_bus_gk20a.h>
33#include <nvgpu/hw/gk20a/hw_mc_gk20a.h>
34#include <nvgpu/hw/gk20a/hw_gr_gk20a.h>
35#include <nvgpu/hw/gk20a/hw_timer_gk20a.h>
36
37void gk20a_bus_init_hw(struct gk20a *g)
38{
39 u32 timeout_period, intr_en_mask = 0;
40
41 if (nvgpu_platform_is_silicon(g))
42 timeout_period = g->default_pri_timeout ?
43 g->default_pri_timeout : 0x186A0;
44 else
45 timeout_period = 0x186A0;
46
47 if (nvgpu_platform_is_silicon(g) || nvgpu_platform_is_fpga(g)) {
48 intr_en_mask = bus_intr_en_0_pri_squash_m() |
49 bus_intr_en_0_pri_fecserr_m() |
50 bus_intr_en_0_pri_timeout_m();
51 gk20a_writel(g,
52 timer_pri_timeout_r(),
53 timer_pri_timeout_period_f(timeout_period) |
54 timer_pri_timeout_en_en_enabled_f());
55
56 } else {
57 gk20a_writel(g,
58 timer_pri_timeout_r(),
59 timer_pri_timeout_period_f(timeout_period) |
60 timer_pri_timeout_en_en_disabled_f());
61 }
62 gk20a_writel(g, bus_intr_en_0_r(), intr_en_mask);
63}
64
65void gk20a_bus_isr(struct gk20a *g)
66{
67 u32 val, save0, save1, err_code;
68
69 val = gk20a_readl(g, bus_intr_0_r());
70
71 if (val & (bus_intr_0_pri_squash_m() |
72 bus_intr_0_pri_fecserr_m() |
73 bus_intr_0_pri_timeout_m())) {
74
75 nvgpu_log(g, gpu_dbg_intr, "pmc_enable : 0x%x",
76 gk20a_readl(g, mc_enable_r()));
77
78 save0 = gk20a_readl(g, timer_pri_timeout_save_0_r());
79 if (timer_pri_timeout_save_0_fecs_tgt_v(save0)) {
80
81 err_code = gk20a_readl(g,
82 timer_pri_timeout_fecs_errcode_r());
83 /* write and addr fields are not reliable */
84 nvgpu_err(g, "NV_PBUS_INTR_0: 0x%08x "
85 "FECS_ERRCODE 0x%08x", val, err_code);
86
87 if ((err_code & 0xffffff00) == 0xbadf1300)
88 nvgpu_err(g, "NV_PGRAPH_PRI_GPC0_GPCCS_FS_GPC: "
89 "0x%08x",
90 gk20a_readl(g, gr_gpc0_fs_gpc_r()));
91 } else {
92 save1 = gk20a_readl(g, timer_pri_timeout_save_1_r());
93 nvgpu_err(g, "NV_PBUS_INTR_0: 0x%08x ADR 0x%08x "
94 "R/W %s DATA 0x%08x",
95 val,
96 timer_pri_timeout_save_0_addr_v(save0) << 2,
97 timer_pri_timeout_save_0_write_v(save0) ?
98 "WRITE" : "READ", save1);
99 }
100
101 gk20a_writel(g, timer_pri_timeout_save_0_r(), 0);
102 gk20a_writel(g, timer_pri_timeout_save_1_r(), 0);
103 } else {
104 nvgpu_err(g, "Unhandled NV_PBUS_INTR_0: 0x%08x", val);
105 }
106 gk20a_writel(g, bus_intr_0_r(), val);
107}
108
109int gk20a_read_ptimer(struct gk20a *g, u64 *value)
110{
111 const unsigned int max_iterations = 3;
112 unsigned int i = 0;
113 u32 gpu_timestamp_hi_prev = 0;
114
115 if (!value)
116 return -EINVAL;
117
118 /* Note. The GPU nanosecond timer consists of two 32-bit
119 * registers (high & low). To detect a possible low register
120 * wrap-around between the reads, we need to read the high
121 * register before and after low. The wraparound happens
122 * approximately once per 4 secs. */
123
124 /* get initial gpu_timestamp_hi value */
125 gpu_timestamp_hi_prev = gk20a_readl(g, timer_time_1_r());
126
127 for (i = 0; i < max_iterations; ++i) {
128 u32 gpu_timestamp_hi = 0;
129 u32 gpu_timestamp_lo = 0;
130
131 gpu_timestamp_lo = gk20a_readl(g, timer_time_0_r());
132 gpu_timestamp_hi = gk20a_readl(g, timer_time_1_r());
133
134 if (gpu_timestamp_hi == gpu_timestamp_hi_prev) {
135 *value = (((u64)gpu_timestamp_hi) << 32) |
136 gpu_timestamp_lo;
137 return 0;
138 }
139
140 /* wrap-around detected, retry */
141 gpu_timestamp_hi_prev = gpu_timestamp_hi;
142 }
143
144 /* too many iterations, bail out */
145 nvgpu_err(g, "failed to read ptimer");
146 return -EBUSY;
147}
148
149int gk20a_bus_bar1_bind(struct gk20a *g, struct nvgpu_mem *bar1_inst)
150{
151 u64 iova = nvgpu_inst_block_addr(g, bar1_inst);
152 u32 ptr_v = (u32)(iova >> bus_bar1_block_ptr_shift_v());
153
154 nvgpu_log(g, gpu_dbg_info, "bar1 inst block ptr: 0x%08x", ptr_v);
155
156 gk20a_writel(g, bus_bar1_block_r(),
157 nvgpu_aperture_mask(g, bar1_inst,
158 bus_bar1_block_target_sys_mem_ncoh_f(),
159 bus_bar1_block_target_vid_mem_f()) |
160 bus_bar1_block_mode_virtual_f() |
161 bus_bar1_block_ptr_f(ptr_v));
162
163 return 0;
164}
165
166void gk20a_init_bus(struct gpu_ops *gops)
167{
168 gops->bus.init_hw = gk20a_bus_init_hw;
169 gops->bus.isr = gk20a_bus_isr;
170 gops->bus.read_ptimer = gk20a_read_ptimer;
171 gops->bus.get_timestamps_zipper = nvgpu_get_timestamps_zipper;
172 gops->bus.bar1_bind = gk20a_bus_bar1_bind;
173}