diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/driver_common.c | 66 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/firmware.c | 114 |
2 files changed, 114 insertions, 66 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/driver_common.c b/drivers/gpu/nvgpu/common/linux/driver_common.c index 5c96b4e8..af26996b 100644 --- a/drivers/gpu/nvgpu/common/linux/driver_common.c +++ b/drivers/gpu/nvgpu/common/linux/driver_common.c | |||
@@ -15,7 +15,6 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <linux/dma-mapping.h> | 17 | #include <linux/dma-mapping.h> |
18 | #include <linux/firmware.h> | ||
19 | 18 | ||
20 | #include <nvgpu/kmem.h> | 19 | #include <nvgpu/kmem.h> |
21 | #include <nvgpu/nvgpu_common.h> | 20 | #include <nvgpu/nvgpu_common.h> |
@@ -201,71 +200,6 @@ int nvgpu_probe(struct gk20a *g, | |||
201 | return 0; | 200 | return 0; |
202 | } | 201 | } |
203 | 202 | ||
204 | static const struct firmware *do_request_firmware(struct device *dev, | ||
205 | const char *prefix, const char *fw_name, int flags) | ||
206 | { | ||
207 | const struct firmware *fw; | ||
208 | char *fw_path = NULL; | ||
209 | int path_len, err; | ||
210 | |||
211 | if (prefix) { | ||
212 | path_len = strlen(prefix) + strlen(fw_name); | ||
213 | path_len += 2; /* for the path separator and zero terminator*/ | ||
214 | |||
215 | fw_path = nvgpu_kzalloc(get_gk20a(dev), | ||
216 | sizeof(*fw_path) * path_len); | ||
217 | if (!fw_path) | ||
218 | return NULL; | ||
219 | |||
220 | sprintf(fw_path, "%s/%s", prefix, fw_name); | ||
221 | fw_name = fw_path; | ||
222 | } | ||
223 | |||
224 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,18,0) | ||
225 | err = request_firmware(&fw, fw_name, dev); | ||
226 | #else | ||
227 | if (flags & NVGPU_REQUEST_FIRMWARE_NO_WARN) | ||
228 | err = request_firmware_direct(&fw, fw_name, dev); | ||
229 | else | ||
230 | err = request_firmware(&fw, fw_name, dev); | ||
231 | #endif | ||
232 | |||
233 | nvgpu_kfree(get_gk20a(dev), fw_path); | ||
234 | if (err) | ||
235 | return NULL; | ||
236 | return fw; | ||
237 | } | ||
238 | |||
239 | /* This is a simple wrapper around request_firmware that takes 'fw_name' and | ||
240 | * applies an IP specific relative path prefix to it. The caller is | ||
241 | * responsible for calling release_firmware later. */ | ||
242 | const struct firmware *nvgpu_request_firmware(struct gk20a *g, | ||
243 | const char *fw_name, | ||
244 | int flags) | ||
245 | { | ||
246 | struct device *dev = g->dev; | ||
247 | const struct firmware *fw; | ||
248 | |||
249 | /* current->fs is NULL when calling from SYS_EXIT. | ||
250 | Add a check here to prevent crash in request_firmware */ | ||
251 | if (!current->fs || !fw_name) | ||
252 | return NULL; | ||
253 | |||
254 | BUG_ON(!g->name); | ||
255 | fw = do_request_firmware(dev, g->name, fw_name, flags); | ||
256 | |||
257 | #ifdef CONFIG_TEGRA_GK20A | ||
258 | /* TO BE REMOVED - Support loading from legacy SOC specific path. */ | ||
259 | if (!fw && !(flags & NVGPU_REQUEST_FIRMWARE_NO_SOC)) { | ||
260 | struct gk20a_platform *platform = gk20a_get_platform(dev); | ||
261 | fw = do_request_firmware(dev, | ||
262 | platform->soc_name, fw_name, flags); | ||
263 | } | ||
264 | #endif | ||
265 | |||
266 | return fw; | ||
267 | } | ||
268 | |||
269 | /** | 203 | /** |
270 | * cyclic_delta - Returns delta of cyclic integers a and b. | 204 | * cyclic_delta - Returns delta of cyclic integers a and b. |
271 | * | 205 | * |
diff --git a/drivers/gpu/nvgpu/common/linux/firmware.c b/drivers/gpu/nvgpu/common/linux/firmware.c new file mode 100644 index 00000000..32b1e61f --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/firmware.c | |||
@@ -0,0 +1,114 @@ | |||
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/firmware.h> | ||
18 | |||
19 | #include <nvgpu/kmem.h> | ||
20 | #include <nvgpu/bug.h> | ||
21 | #include <nvgpu/firmware.h> | ||
22 | |||
23 | #include "gk20a/gk20a.h" | ||
24 | |||
25 | static const struct firmware *do_request_firmware(struct device *dev, | ||
26 | const char *prefix, const char *fw_name, int flags) | ||
27 | { | ||
28 | const struct firmware *fw; | ||
29 | char *fw_path = NULL; | ||
30 | int path_len, err; | ||
31 | |||
32 | if (prefix) { | ||
33 | path_len = strlen(prefix) + strlen(fw_name); | ||
34 | path_len += 2; /* for the path separator and zero terminator*/ | ||
35 | |||
36 | fw_path = nvgpu_kzalloc(get_gk20a(dev), | ||
37 | sizeof(*fw_path) * path_len); | ||
38 | if (!fw_path) | ||
39 | return NULL; | ||
40 | |||
41 | sprintf(fw_path, "%s/%s", prefix, fw_name); | ||
42 | fw_name = fw_path; | ||
43 | } | ||
44 | |||
45 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,18,0) | ||
46 | err = request_firmware(&fw, fw_name, dev); | ||
47 | #else | ||
48 | if (flags & NVGPU_REQUEST_FIRMWARE_NO_WARN) | ||
49 | err = request_firmware_direct(&fw, fw_name, dev); | ||
50 | else | ||
51 | err = request_firmware(&fw, fw_name, dev); | ||
52 | #endif | ||
53 | |||
54 | nvgpu_kfree(get_gk20a(dev), fw_path); | ||
55 | if (err) | ||
56 | return NULL; | ||
57 | return fw; | ||
58 | } | ||
59 | |||
60 | /* This is a simple wrapper around request_firmware that takes 'fw_name' and | ||
61 | * applies an IP specific relative path prefix to it. The caller is | ||
62 | * responsible for calling nvgpu_release_firmware later. */ | ||
63 | struct nvgpu_firmware *nvgpu_request_firmware(struct gk20a *g, | ||
64 | const char *fw_name, | ||
65 | int flags) | ||
66 | { | ||
67 | struct device *dev = g->dev; | ||
68 | struct nvgpu_firmware *fw; | ||
69 | const struct firmware *linux_fw; | ||
70 | |||
71 | /* current->fs is NULL when calling from SYS_EXIT. | ||
72 | Add a check here to prevent crash in request_firmware */ | ||
73 | if (!current->fs || !fw_name) | ||
74 | return NULL; | ||
75 | |||
76 | fw = nvgpu_kzalloc(g, sizeof(*fw)); | ||
77 | if (!fw) | ||
78 | return NULL; | ||
79 | |||
80 | linux_fw = do_request_firmware(dev, g->name, fw_name, flags); | ||
81 | |||
82 | #ifdef CONFIG_TEGRA_GK20A | ||
83 | /* TO BE REMOVED - Support loading from legacy SOC specific path. */ | ||
84 | if (!linux_fw && !(flags & NVGPU_REQUEST_FIRMWARE_NO_SOC)) { | ||
85 | struct gk20a_platform *platform = gk20a_get_platform(dev); | ||
86 | linux_fw = do_request_firmware(dev, | ||
87 | platform->soc_name, fw_name, flags); | ||
88 | } | ||
89 | #endif | ||
90 | |||
91 | if (!linux_fw) | ||
92 | goto err; | ||
93 | |||
94 | fw->data = nvgpu_kmalloc(g, linux_fw->size); | ||
95 | if (!fw->data) | ||
96 | goto err; | ||
97 | |||
98 | memcpy(fw->data, linux_fw->data, linux_fw->size); | ||
99 | fw->size = linux_fw->size; | ||
100 | |||
101 | release_firmware(linux_fw); | ||
102 | |||
103 | return fw; | ||
104 | |||
105 | err: | ||
106 | nvgpu_kfree(g, fw); | ||
107 | return NULL; | ||
108 | } | ||
109 | |||
110 | void nvgpu_release_firmware(struct gk20a *g, struct nvgpu_firmware *fw) | ||
111 | { | ||
112 | nvgpu_kfree(g, fw->data); | ||
113 | nvgpu_kfree(g, fw); | ||
114 | } | ||