diff options
Diffstat (limited to 'drivers/gpu/nvgpu/os/linux/io.c')
-rw-r--r-- | drivers/gpu/nvgpu/os/linux/io.c | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/os/linux/io.c b/drivers/gpu/nvgpu/os/linux/io.c new file mode 100644 index 00000000..c06512a5 --- /dev/null +++ b/drivers/gpu/nvgpu/os/linux/io.c | |||
@@ -0,0 +1,118 @@ | |||
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 <nvgpu/io.h> | ||
15 | #include <nvgpu/types.h> | ||
16 | |||
17 | #include "os_linux.h" | ||
18 | #include "gk20a/gk20a.h" | ||
19 | |||
20 | void nvgpu_writel(struct gk20a *g, u32 r, u32 v) | ||
21 | { | ||
22 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
23 | |||
24 | if (unlikely(!l->regs)) { | ||
25 | __gk20a_warn_on_no_regs(); | ||
26 | nvgpu_log(g, gpu_dbg_reg, "r=0x%x v=0x%x (failed)", r, v); | ||
27 | } else { | ||
28 | writel_relaxed(v, l->regs + r); | ||
29 | nvgpu_wmb(); | ||
30 | nvgpu_log(g, gpu_dbg_reg, "r=0x%x v=0x%x", r, v); | ||
31 | } | ||
32 | } | ||
33 | |||
34 | u32 nvgpu_readl(struct gk20a *g, u32 r) | ||
35 | { | ||
36 | u32 v = __nvgpu_readl(g, r); | ||
37 | |||
38 | if (v == 0xffffffff) | ||
39 | __nvgpu_check_gpu_state(g); | ||
40 | |||
41 | return v; | ||
42 | } | ||
43 | |||
44 | u32 __nvgpu_readl(struct gk20a *g, u32 r) | ||
45 | { | ||
46 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
47 | u32 v = 0xffffffff; | ||
48 | |||
49 | if (unlikely(!l->regs)) { | ||
50 | __gk20a_warn_on_no_regs(); | ||
51 | nvgpu_log(g, gpu_dbg_reg, "r=0x%x v=0x%x (failed)", r, v); | ||
52 | } else { | ||
53 | v = readl(l->regs + r); | ||
54 | nvgpu_log(g, gpu_dbg_reg, "r=0x%x v=0x%x", r, v); | ||
55 | } | ||
56 | |||
57 | return v; | ||
58 | } | ||
59 | |||
60 | void nvgpu_writel_check(struct gk20a *g, u32 r, u32 v) | ||
61 | { | ||
62 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
63 | |||
64 | if (unlikely(!l->regs)) { | ||
65 | __gk20a_warn_on_no_regs(); | ||
66 | nvgpu_log(g, gpu_dbg_reg, "r=0x%x v=0x%x (failed)", r, v); | ||
67 | } else { | ||
68 | nvgpu_wmb(); | ||
69 | do { | ||
70 | writel_relaxed(v, l->regs + r); | ||
71 | } while (readl(l->regs + r) != v); | ||
72 | nvgpu_log(g, gpu_dbg_reg, "r=0x%x v=0x%x", r, v); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | void nvgpu_bar1_writel(struct gk20a *g, u32 b, u32 v) | ||
77 | { | ||
78 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
79 | |||
80 | if (unlikely(!l->bar1)) { | ||
81 | __gk20a_warn_on_no_regs(); | ||
82 | nvgpu_log(g, gpu_dbg_reg, "b=0x%x v=0x%x (failed)", b, v); | ||
83 | } else { | ||
84 | nvgpu_wmb(); | ||
85 | writel_relaxed(v, l->bar1 + b); | ||
86 | nvgpu_log(g, gpu_dbg_reg, "b=0x%x v=0x%x", b, v); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | u32 nvgpu_bar1_readl(struct gk20a *g, u32 b) | ||
91 | { | ||
92 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
93 | u32 v = 0xffffffff; | ||
94 | |||
95 | if (unlikely(!l->bar1)) { | ||
96 | __gk20a_warn_on_no_regs(); | ||
97 | nvgpu_log(g, gpu_dbg_reg, "b=0x%x v=0x%x (failed)", b, v); | ||
98 | } else { | ||
99 | v = readl(l->bar1 + b); | ||
100 | nvgpu_log(g, gpu_dbg_reg, "b=0x%x v=0x%x", b, v); | ||
101 | } | ||
102 | |||
103 | return v; | ||
104 | } | ||
105 | |||
106 | bool nvgpu_io_exists(struct gk20a *g) | ||
107 | { | ||
108 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
109 | |||
110 | return l->regs != NULL; | ||
111 | } | ||
112 | |||
113 | bool nvgpu_io_valid_reg(struct gk20a *g, u32 r) | ||
114 | { | ||
115 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
116 | |||
117 | return r < resource_size(l->regs); | ||
118 | } | ||