aboutsummaryrefslogtreecommitdiffstats
path: root/include/os/linux/firmware.c
diff options
context:
space:
mode:
Diffstat (limited to 'include/os/linux/firmware.c')
-rw-r--r--include/os/linux/firmware.c117
1 files changed, 0 insertions, 117 deletions
diff --git a/include/os/linux/firmware.c b/include/os/linux/firmware.c
deleted file mode 100644
index 8f0344b..0000000
--- a/include/os/linux/firmware.c
+++ /dev/null
@@ -1,117 +0,0 @@
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 * 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#include <nvgpu/gk20a.h>
23
24#include "platform_gk20a.h"
25#include "os_linux.h"
26
27static const struct firmware *do_request_firmware(struct device *dev,
28 const char *prefix, const char *fw_name, int flags)
29{
30 const struct firmware *fw;
31 char *fw_path = NULL;
32 int path_len, err;
33
34 if (prefix) {
35 path_len = strlen(prefix) + strlen(fw_name);
36 path_len += 2; /* for the path separator and zero terminator*/
37
38 fw_path = nvgpu_kzalloc(get_gk20a(dev),
39 sizeof(*fw_path) * path_len);
40 if (!fw_path)
41 return NULL;
42
43 sprintf(fw_path, "%s/%s", prefix, fw_name);
44 fw_name = fw_path;
45 }
46
47 if (flags & NVGPU_REQUEST_FIRMWARE_NO_WARN)
48 err = request_firmware_direct(&fw, fw_name, dev);
49 else
50 err = request_firmware(&fw, fw_name, dev);
51
52 nvgpu_kfree(get_gk20a(dev), fw_path);
53 if (err)
54 return NULL;
55 return fw;
56}
57
58/* This is a simple wrapper around request_firmware that takes 'fw_name' and
59 * applies an IP specific relative path prefix to it. The caller is
60 * responsible for calling nvgpu_release_firmware later. */
61struct nvgpu_firmware *nvgpu_request_firmware(struct gk20a *g,
62 const char *fw_name,
63 int flags)
64{
65 struct device *dev = dev_from_gk20a(g);
66 struct nvgpu_firmware *fw;
67 const struct firmware *linux_fw;
68
69 /* current->fs is NULL when calling from SYS_EXIT.
70 Add a check here to prevent crash in request_firmware */
71 if (!current->fs || !fw_name)
72 return NULL;
73
74 fw = nvgpu_kzalloc(g, sizeof(*fw));
75 if (!fw)
76 return NULL;
77
78 linux_fw = do_request_firmware(dev, g->name, fw_name, flags);
79
80#ifdef CONFIG_TEGRA_GK20A
81 /* TO BE REMOVED - Support loading from legacy SOC specific path. */
82 if (!linux_fw && !(flags & NVGPU_REQUEST_FIRMWARE_NO_SOC)) {
83 struct gk20a_platform *platform = gk20a_get_platform(dev);
84 linux_fw = do_request_firmware(dev,
85 platform->soc_name, fw_name, flags);
86 }
87#endif
88
89 if (!linux_fw)
90 goto err;
91
92 fw->data = nvgpu_kmalloc(g, linux_fw->size);
93 if (!fw->data)
94 goto err_release;
95
96 memcpy(fw->data, linux_fw->data, linux_fw->size);
97 fw->size = linux_fw->size;
98
99 release_firmware(linux_fw);
100
101 return fw;
102
103err_release:
104 release_firmware(linux_fw);
105err:
106 nvgpu_kfree(g, fw);
107 return NULL;
108}
109
110void nvgpu_release_firmware(struct gk20a *g, struct nvgpu_firmware *fw)
111{
112 if(!fw)
113 return;
114
115 nvgpu_kfree(g, fw->data);
116 nvgpu_kfree(g, fw);
117}