forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/gpu/drm/nouveau/nvkm/core/firmware.c
....@@ -22,9 +22,43 @@
2222 #include <core/device.h>
2323 #include <core/firmware.h>
2424
25
+int
26
+nvkm_firmware_load_name(const struct nvkm_subdev *subdev, const char *base,
27
+ const char *name, int ver, const struct firmware **pfw)
28
+{
29
+ char path[64];
30
+ int ret;
31
+
32
+ snprintf(path, sizeof(path), "%s%s", base, name);
33
+ ret = nvkm_firmware_get(subdev, path, ver, pfw);
34
+ if (ret < 0)
35
+ return ret;
36
+
37
+ return 0;
38
+}
39
+
40
+int
41
+nvkm_firmware_load_blob(const struct nvkm_subdev *subdev, const char *base,
42
+ const char *name, int ver, struct nvkm_blob *blob)
43
+{
44
+ const struct firmware *fw;
45
+ int ret;
46
+
47
+ ret = nvkm_firmware_load_name(subdev, base, name, ver, &fw);
48
+ if (ret == 0) {
49
+ blob->data = kmemdup(fw->data, fw->size, GFP_KERNEL);
50
+ blob->size = fw->size;
51
+ nvkm_firmware_put(fw);
52
+ if (!blob->data)
53
+ return -ENOMEM;
54
+ }
55
+
56
+ return ret;
57
+}
58
+
2559 /**
2660 * nvkm_firmware_get - load firmware from the official nvidia/chip/ directory
27
- * @device device that will use that firmware
61
+ * @subdev subdevice that will use that firmware
2862 * @fwname name of firmware file to load
2963 * @fw firmware structure to load to
3064 *
....@@ -32,9 +66,10 @@
3266 * Firmware files released by NVIDIA will always follow this format.
3367 */
3468 int
35
-nvkm_firmware_get(struct nvkm_device *device, const char *fwname,
69
+nvkm_firmware_get(const struct nvkm_subdev *subdev, const char *fwname, int ver,
3670 const struct firmware **fw)
3771 {
72
+ struct nvkm_device *device = subdev->device;
3873 char f[64];
3974 char cname[16];
4075 int i;
....@@ -48,8 +83,19 @@
4883 cname[i] = tolower(cname[i]);
4984 }
5085
51
- snprintf(f, sizeof(f), "nvidia/%s/%s.bin", cname, fwname);
52
- return request_firmware(fw, f, device->dev);
86
+ if (ver != 0)
87
+ snprintf(f, sizeof(f), "nvidia/%s/%s-%d.bin", cname, fwname, ver);
88
+ else
89
+ snprintf(f, sizeof(f), "nvidia/%s/%s.bin", cname, fwname);
90
+
91
+ if (!firmware_request_nowarn(fw, f, device->dev)) {
92
+ nvkm_debug(subdev, "firmware \"%s\" loaded - %zu byte(s)\n",
93
+ f, (*fw)->size);
94
+ return 0;
95
+ }
96
+
97
+ nvkm_debug(subdev, "firmware \"%s\" unavailable\n", f);
98
+ return -ENOENT;
5399 }
54100
55101 /**