diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/nvhost.c')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/nvhost.c | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/nvhost.c b/drivers/gpu/nvgpu/common/linux/nvhost.c new file mode 100644 index 00000000..611351ae --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/nvhost.c | |||
@@ -0,0 +1,212 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017, 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/nvhost.h> | ||
18 | #include <linux/nvhost_ioctl.h> | ||
19 | #include <linux/of_platform.h> | ||
20 | |||
21 | #include <nvgpu/nvhost.h> | ||
22 | |||
23 | #include "nvhost_priv.h" | ||
24 | |||
25 | #include "gk20a/gk20a.h" | ||
26 | #include "os_linux.h" | ||
27 | |||
28 | int nvgpu_get_nvhost_dev(struct gk20a *g) | ||
29 | { | ||
30 | struct device_node *np = dev_from_gk20a(g)->of_node; | ||
31 | struct platform_device *host1x_pdev = NULL; | ||
32 | const __be32 *host1x_ptr; | ||
33 | |||
34 | host1x_ptr = of_get_property(np, "nvidia,host1x", NULL); | ||
35 | if (host1x_ptr) { | ||
36 | struct device_node *host1x_node = | ||
37 | of_find_node_by_phandle(be32_to_cpup(host1x_ptr)); | ||
38 | |||
39 | host1x_pdev = of_find_device_by_node(host1x_node); | ||
40 | if (!host1x_pdev) { | ||
41 | nvgpu_warn(g, "host1x device not available"); | ||
42 | return -EPROBE_DEFER; | ||
43 | } | ||
44 | |||
45 | } else { | ||
46 | if (g->has_syncpoints) { | ||
47 | nvgpu_warn(g, "host1x reference not found. assuming no syncpoints support"); | ||
48 | g->has_syncpoints = false; | ||
49 | } | ||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | g->nvhost_dev = nvgpu_kzalloc(g, sizeof(struct nvgpu_nvhost_dev)); | ||
54 | if (!g->nvhost_dev) | ||
55 | return -ENOMEM; | ||
56 | |||
57 | g->nvhost_dev->host1x_pdev = host1x_pdev; | ||
58 | |||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | void nvgpu_free_nvhost_dev(struct gk20a *g) | ||
63 | { | ||
64 | nvgpu_kfree(g, g->nvhost_dev); | ||
65 | } | ||
66 | |||
67 | int nvgpu_nvhost_module_busy_ext( | ||
68 | struct nvgpu_nvhost_dev *nvhost_dev) | ||
69 | { | ||
70 | return nvhost_module_busy_ext(nvhost_dev->host1x_pdev); | ||
71 | } | ||
72 | |||
73 | void nvgpu_nvhost_module_idle_ext( | ||
74 | struct nvgpu_nvhost_dev *nvhost_dev) | ||
75 | { | ||
76 | nvhost_module_idle_ext(nvhost_dev->host1x_pdev); | ||
77 | } | ||
78 | |||
79 | void nvgpu_nvhost_debug_dump_device( | ||
80 | struct nvgpu_nvhost_dev *nvhost_dev) | ||
81 | { | ||
82 | nvhost_debug_dump_device(nvhost_dev->host1x_pdev); | ||
83 | } | ||
84 | |||
85 | const char *nvgpu_nvhost_syncpt_get_name( | ||
86 | struct nvgpu_nvhost_dev *nvhost_dev, int id) | ||
87 | { | ||
88 | return nvhost_syncpt_get_name(nvhost_dev->host1x_pdev, id); | ||
89 | } | ||
90 | |||
91 | bool nvgpu_nvhost_syncpt_is_valid_pt_ext( | ||
92 | struct nvgpu_nvhost_dev *nvhost_dev, u32 id) | ||
93 | { | ||
94 | return nvhost_syncpt_is_valid_pt_ext(nvhost_dev->host1x_pdev, id); | ||
95 | } | ||
96 | |||
97 | int nvgpu_nvhost_syncpt_is_expired_ext( | ||
98 | struct nvgpu_nvhost_dev *nvhost_dev, u32 id, u32 thresh) | ||
99 | { | ||
100 | return nvhost_syncpt_is_expired_ext(nvhost_dev->host1x_pdev, | ||
101 | id, thresh); | ||
102 | } | ||
103 | |||
104 | u32 nvgpu_nvhost_syncpt_incr_max_ext( | ||
105 | struct nvgpu_nvhost_dev *nvhost_dev, u32 id, u32 incrs) | ||
106 | { | ||
107 | return nvhost_syncpt_incr_max_ext(nvhost_dev->host1x_pdev, id, incrs); | ||
108 | } | ||
109 | |||
110 | int nvgpu_nvhost_intr_register_notifier( | ||
111 | struct nvgpu_nvhost_dev *nvhost_dev, u32 id, u32 thresh, | ||
112 | void (*callback)(void *, int), void *private_data) | ||
113 | { | ||
114 | return nvhost_intr_register_notifier(nvhost_dev->host1x_pdev, | ||
115 | id, thresh, | ||
116 | callback, private_data); | ||
117 | } | ||
118 | |||
119 | void nvgpu_nvhost_syncpt_set_min_eq_max_ext( | ||
120 | struct nvgpu_nvhost_dev *nvhost_dev, u32 id) | ||
121 | { | ||
122 | nvhost_syncpt_set_min_eq_max_ext(nvhost_dev->host1x_pdev, id); | ||
123 | } | ||
124 | |||
125 | void nvgpu_nvhost_syncpt_put_ref_ext( | ||
126 | struct nvgpu_nvhost_dev *nvhost_dev, u32 id) | ||
127 | { | ||
128 | nvhost_syncpt_put_ref_ext(nvhost_dev->host1x_pdev, id); | ||
129 | } | ||
130 | |||
131 | u32 nvgpu_nvhost_get_syncpt_host_managed( | ||
132 | struct nvgpu_nvhost_dev *nvhost_dev, | ||
133 | u32 param, const char *syncpt_name) | ||
134 | { | ||
135 | return nvhost_get_syncpt_host_managed(nvhost_dev->host1x_pdev, | ||
136 | param, syncpt_name); | ||
137 | } | ||
138 | |||
139 | int nvgpu_nvhost_syncpt_wait_timeout_ext( | ||
140 | struct nvgpu_nvhost_dev *nvhost_dev, u32 id, | ||
141 | u32 thresh, u32 timeout, u32 *value, struct timespec *ts) | ||
142 | { | ||
143 | return nvhost_syncpt_wait_timeout_ext(nvhost_dev->host1x_pdev, | ||
144 | id, thresh, timeout, value, ts); | ||
145 | } | ||
146 | |||
147 | int nvgpu_nvhost_syncpt_read_ext_check( | ||
148 | struct nvgpu_nvhost_dev *nvhost_dev, u32 id, u32 *val) | ||
149 | { | ||
150 | return nvhost_syncpt_read_ext_check(nvhost_dev->host1x_pdev, id, val); | ||
151 | } | ||
152 | |||
153 | int nvgpu_nvhost_create_symlink(struct gk20a *g) | ||
154 | { | ||
155 | struct device *dev = dev_from_gk20a(g); | ||
156 | int err = 0; | ||
157 | |||
158 | if (g->nvhost_dev && | ||
159 | (dev->parent != &g->nvhost_dev->host1x_pdev->dev)) { | ||
160 | err = sysfs_create_link(&g->nvhost_dev->host1x_pdev->dev.kobj, | ||
161 | &dev->kobj, | ||
162 | dev_name(dev)); | ||
163 | } | ||
164 | |||
165 | return err; | ||
166 | } | ||
167 | |||
168 | void nvgpu_nvhost_remove_symlink(struct gk20a *g) | ||
169 | { | ||
170 | struct device *dev = dev_from_gk20a(g); | ||
171 | |||
172 | if (g->nvhost_dev && | ||
173 | (dev->parent != &g->nvhost_dev->host1x_pdev->dev)) { | ||
174 | sysfs_remove_link(&g->nvhost_dev->host1x_pdev->dev.kobj, | ||
175 | dev_name(dev)); | ||
176 | } | ||
177 | } | ||
178 | |||
179 | #ifdef CONFIG_SYNC | ||
180 | u32 nvgpu_nvhost_sync_pt_id(struct sync_pt *pt) | ||
181 | { | ||
182 | return nvhost_sync_pt_id(pt); | ||
183 | } | ||
184 | |||
185 | u32 nvgpu_nvhost_sync_pt_thresh(struct sync_pt *pt) | ||
186 | { | ||
187 | return nvhost_sync_pt_thresh(pt); | ||
188 | } | ||
189 | |||
190 | struct sync_fence *nvgpu_nvhost_sync_fdget(int fd) | ||
191 | { | ||
192 | return nvhost_sync_fdget(fd); | ||
193 | } | ||
194 | |||
195 | int nvgpu_nvhost_sync_num_pts(struct sync_fence *fence) | ||
196 | { | ||
197 | return nvhost_sync_num_pts(fence); | ||
198 | } | ||
199 | |||
200 | struct sync_fence *nvgpu_nvhost_sync_create_fence( | ||
201 | struct nvgpu_nvhost_dev *nvhost_dev, | ||
202 | u32 id, u32 thresh, | ||
203 | u32 num_pts, const char *name) | ||
204 | { | ||
205 | struct nvhost_ctrl_sync_fence_info pt = { | ||
206 | .id = id, | ||
207 | .thresh = thresh, | ||
208 | }; | ||
209 | |||
210 | return nvhost_sync_create_fence(nvhost_dev->host1x_pdev, &pt, num_pts, name); | ||
211 | } | ||
212 | #endif /* CONFIG_SYNC */ | ||