Skip to contentSkip to conversation

nouveau: unified firmware loading functions

PATCH In review Alexandre Courbot 5 participants 13 messages Jan 18, 2016 – Jan 27, 2016 7 messages not in the archive

lore
Share & tools
lore
#0 lore raw

cover nouveau: unified firmware loading functions

This patchset centralizes the firmware-loading procedure to one set of functions instead of having each engine load its firmware as it pleases. This helps ensure that all firmware comes from the same place, namely nvidia/<chip>/.

This changes where the firmware is fetched from for falcon/xtensa/bios, but these locations never seemed to have been official anyway. Also for most (all?) chips supported by Nouveau there is corresponding internal firmware, so disruption should be minimal/non-existent. If this assumption is wrong, feel free to drop patches 3-5. At the very least, firmware officially provided by NVIDIA should be looked up using the new functions for consistency.

These new functions are also used by the secure boot series, which will follow shortly.

Alexandre Courbot (5):
core: add firmware handling functions
gr/gf100: use the nvkm_firmware functions
falcon: use the nvkm_firmware functions
xtensa: use the nvkm_firmware functions
bios: use the nvkm_firmware functions

 drm/nouveau/include/nvkm/core/firmware.h | 11 ++++++
 drm/nouveau/nvkm/core/Kbuild             |  1 +
 drm/nouveau/nvkm/core/firmware.c         | 64 ++++++++++++++++++++++++++++++++
 drm/nouveau/nvkm/engine/falcon.c         | 22 +++++------
 drm/nouveau/nvkm/engine/gr/gf100.c       | 18 ++-------
 drm/nouveau/nvkm/engine/xtensa.c         | 12 +++---
 drm/nouveau/nvkm/subdev/bios/shadow.c    |  7 ++--
 7 files changed, 99 insertions(+), 36 deletions(-)
 create mode 100644 drm/nouveau/include/nvkm/core/firmware.h
 create mode 100644 drm/nouveau/nvkm/core/firmware.c
Signature · 6 lines
2.7.0

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
#2 lore raw

PATCH 1/5 core: add firmware handling functions

In reply to a message not in the archive

Add two functions nvkm_firmware_get() and nvkm_firmware_put() to load a firmware file and free its resources, respectively. Since firmware files are becoming a necessity for new GPUs, and their location has been standardized to nvidia/chip/, this will prevent duplicate and error-prone name-generation code.

---
 drm/nouveau/include/nvkm/core/firmware.h | 11 ++++++
 drm/nouveau/nvkm/core/Kbuild             |  1 +
 drm/nouveau/nvkm/core/firmware.c         | 64 ++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 drm/nouveau/include/nvkm/core/firmware.h
 create mode 100644 drm/nouveau/nvkm/core/firmware.c
drm/nouveau/include/nvkm/core/firmware.h new file +11 -0
new file mode 100644
index 000000000000..a626ce378f04
@@ -0,0 +1,11 @@
+#ifndef __NVKM_FIRMWARE_H__
+#define __NVKM_FIRMWARE_H__
+
+#include <core/device.h>
+
+int nvkm_firmware_get(struct nvkm_device *device, const char *fwname,
+		      const struct firmware **fw);
+
+void nvkm_firmware_put(const struct firmware *fw);
+
+#endif
drm/nouveau/nvkm/core/Kbuild +1 -0
index 7f66963f305c..86a31a8e1e51 100644
@@ -2,6 +2,7 @@ nvkm-y := nvkm/core/client.o
 nvkm-y += nvkm/core/engine.o
 nvkm-y += nvkm/core/enum.o
 nvkm-y += nvkm/core/event.o
+nvkm-y += nvkm/core/firmware.o
 nvkm-y += nvkm/core/gpuobj.o
 nvkm-y += nvkm/core/ioctl.o
 nvkm-y += nvkm/core/memory.o
drm/nouveau/nvkm/core/firmware.c new file +64 -0

64 lines not on this page · raw message

Signature · 6 lines
2.7.0

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
#9 lore raw

PATCH 2/5 gr/gf100: use the nvkm_firmware functions

In reply to a message not in the archive

Use the nvkm_firmware_* functions when loading external firmware to avoid duplicate code.

---
 drm/nouveau/nvkm/engine/gr/gf100.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)
drm/nouveau/nvkm/engine/gr/gf100.c +3 -15
index 1f81069edc58..f2410aff07cf 100644
@@ -27,6 +27,7 @@
 
 #include <core/client.h>
 #include <core/option.h>
+#include <core/firmware.h>
 #include <subdev/fb.h>
 #include <subdev/mc.h>
 #include <subdev/pmu.h>
@@ -1720,22 +1721,9 @@ gf100_gr_ctor_fw(struct gf100_gr *gr, const char *fwname,
 	struct nvkm_subdev *subdev = &gr->base.engine.subdev;
 	struct nvkm_device *device = subdev->device;
 	const struct firmware *fw;
-	char f[64];
-	char cname[16];
 	int ret;
-	int i;
-
-	/* Convert device name to lowercase */
-	strncpy(cname, device->chip->name, sizeof(cname));
-	cname[sizeof(cname) - 1] = '\0';
-	i = strlen(cname);
-	while (i) {
-		--i;
-		cname[i] = tolower(cname[i]);
-	}
 
-	snprintf(f, sizeof(f), "nvidia/%s/%s.bin", cname, fwname);
-	ret = request_firmware(&fw, f, device->dev);
+	ret = nvkm_firmware_get(device, fwname, &fw);
 	if (ret) {
 		nvkm_error(subdev, "failed to load %s\n", fwname);
 		return ret;
@@ -1743,7 +1731,7 @@ gf100_gr_ctor_fw(struct gf100_gr *gr, const char *fwname,
 
 	fuc->size = fw->size;
 	fuc->data = kmemdup(fw->data, fuc->size, GFP_KERNEL);
-	release_firmware(fw);
+	nvkm_firmware_put(fw);
 	return (fuc->data != NULL) ? 0 : -ENOMEM;
 }
 
Signature · 6 lines
2.7.0

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
#10 lore raw

PATCH 3/5 falcon: use the nvkm_firmware functions

In reply to a message not in the archive

Use the newly-introduced nvkm_firmware functions. Note that this will change the expected location of firmware files.

---
 drm/nouveau/nvkm/engine/falcon.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drm/nouveau/nvkm/engine/falcon.c +10 -12
index 74000602fbb1..028113c6f82d 100644
@@ -22,6 +22,7 @@
 #include <engine/falcon.h>
 
 #include <core/gpuobj.h>
+#include <core/firmware.h>
 #include <subdev/timer.h>
 #include <engine/fifo.h>
 
@@ -187,16 +188,15 @@ nvkm_falcon_init(struct nvkm_engine *engine)
 	 * locate a "self-bootstrapping" firmware image for the engine
 	 */
 	if (!falcon->code.data) {
-		snprintf(name, sizeof(name), "nouveau/nv%02x_fuc%03x",
-			 device->chipset, falcon->addr >> 12);
+		snprintf(name, sizeof(name), "fuc%03x", falcon->addr >> 12);
 
-		ret = request_firmware(&fw, name, device->dev);
+		ret = nvkm_firmware_get(device, name, &fw);
 		if (ret == 0) {
 			falcon->code.data = vmemdup(fw->data, fw->size);
 			falcon->code.size = fw->size;
 			falcon->data.data = NULL;
 			falcon->data.size = 0;
-			release_firmware(fw);
+			nvkm_firmware_put(fw);
 		}
 
 		falcon->external = true;
@@ -206,10 +206,9 @@ nvkm_falcon_init(struct nvkm_engine *engine)
 	 * images for the engine
 	 */
 	if (!falcon->code.data) {
-		snprintf(name, sizeof(name), "nouveau/nv%02x_fuc%03xd",
-			 device->chipset, falcon->addr >> 12);
+		snprintf(name, sizeof(name), "fuc%03xd", falcon->addr >> 12);
 
-		ret = request_firmware(&fw, name, device->dev);
+		ret = nvkm_firmware_get(device, name, &fw);
 		if (ret) {
 			nvkm_error(subdev, "unable to load firmware data\n");
 			return -ENODEV;
@@ -217,14 +216,13 @@ nvkm_falcon_init(struct nvkm_engine *engine)
 
 		falcon->data.data = vmemdup(fw->data, fw->size);
 		falcon->data.size = fw->size;
-		release_firmware(fw);
+		nvkm_firmware_put(fw);
 		if (!falcon->data.data)
 			return -ENOMEM;
 
-		snprintf(name, sizeof(name), "nouveau/nv%02x_fuc%03xc",
-			 device->chipset, falcon->addr >> 12);
+		snprintf(name, sizeof(name), "fuc%03xc", falcon->addr >> 12);
 
-		ret = request_firmware(&fw, name, device->dev);
+		ret = nvkm_firmware_get(device, name, &fw);
 		if (ret) {
 			nvkm_error(subdev, "unable to load firmware code\n");
 			return -ENODEV;
@@ -232,7 +230,7 @@ nvkm_falcon_init(struct nvkm_engine *engine)
 
 		falcon->code.data = vmemdup(fw->data, fw->size);
 		falcon->code.size = fw->size;
-		release_firmware(fw);
+		nvkm_firmware_put(fw);
 		if (!falcon->code.data)
 			return -ENOMEM;
 	}
Signature · 6 lines
2.7.0

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
#11 lore raw

PATCH 4/5 xtensa: use the nvkm_firmware functions

In reply to a message not in the archive

Use the newly-introduced nvkm_firmware functions. Note that this will change the expected location of firmware files.

---
 drm/nouveau/nvkm/engine/xtensa.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drm/nouveau/nvkm/engine/xtensa.c +6 -6
index a3d4f5bcec7a..608741a52fed 100644
@@ -22,6 +22,7 @@
 #include <engine/xtensa.h>
 
 #include <core/gpuobj.h>
+#include <core/firmware.h>
 #include <engine/fifo.h>
 
 static int
@@ -104,10 +105,9 @@ nvkm_xtensa_init(struct nvkm_engine *engine)
 	u32 tmp;
 
 	if (!xtensa->gpu_fw) {
-		snprintf(name, sizeof(name), "nouveau/nv84_xuc%03x",
-			 xtensa->addr >> 12);
+		snprintf(name, sizeof(name), "xuc%03x", xtensa->addr >> 12);
 
-		ret = request_firmware(&fw, name, device->dev);
+		ret = nvkm_firmware_get(device, name, &fw);
 		if (ret) {
 			nvkm_warn(subdev, "unable to load firmware %s\n", name);
 			return ret;
@@ -115,7 +115,7 @@ nvkm_xtensa_init(struct nvkm_engine *engine)
 
 		if (fw->size > 0x40000) {
 			nvkm_warn(subdev, "firmware %s too large\n", name);
-			release_firmware(fw);
+			nvkm_firmware_put(fw);
 			return -EINVAL;
 		}
 
@@ -123,7 +123,7 @@ nvkm_xtensa_init(struct nvkm_engine *engine)
 				      0x40000, 0x1000, false,
 				      &xtensa->gpu_fw);
 		if (ret) {
-			release_firmware(fw);
+			nvkm_firmware_put(fw);
 			return ret;
 		}
 
@@ -131,7 +131,7 @@ nvkm_xtensa_init(struct nvkm_engine *engine)
 		for (i = 0; i < fw->size / 4; i++)
 			nvkm_wo32(xtensa->gpu_fw, i * 4, *((u32 *)fw->data + i));
 		nvkm_done(xtensa->gpu_fw);
-		release_firmware(fw);
+		nvkm_firmware_put(fw);
 	}
 
 	addr = nvkm_memory_addr(xtensa->gpu_fw);
Signature · 6 lines
2.7.0

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
#12 lore raw

PATCH 5/5 bios: use the nvkm_firmware functions

In reply to a message not in the archive

Use the newly-introduced nvkm_firmware functions. Note that this will change the expected location of firmware files.

---
 drm/nouveau/nvkm/subdev/bios/shadow.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drm/nouveau/nvkm/subdev/bios/shadow.c +4 -3
index b2557e87afdd..20814fc4dc1a 100644
@@ -24,6 +24,7 @@
 #include "priv.h"
 
 #include <core/option.h>
+#include <core/firmware.h>
 #include <subdev/bios.h>
 #include <subdev/bios/image.h>
 
@@ -143,9 +144,9 @@ shadow_fw_read(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
 static void *
 shadow_fw_init(struct nvkm_bios *bios, const char *name)
 {
-	struct device *dev = bios->subdev.device->dev;
+	struct nvkm_device *device = bios->subdev.device;
 	const struct firmware *fw;
-	int ret = request_firmware(&fw, name, dev);
+	int ret = nvkm_firmware_get(device, name, &fw);
 	if (ret)
 		return ERR_PTR(-ENOENT);
 	return (void *)fw;
@@ -155,7 +156,7 @@ static const struct nvbios_source
 shadow_fw = {
 	.name = "firmware",
 	.init = shadow_fw_init,
-	.fini = (void(*)(void *))release_firmware,
+	.fini = (void(*)(void *))nvkm_firmware_put,
 	.read = shadow_fw_read,
 	.rw = false,
 };
Signature · 6 lines
2.7.0

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
#13 lore raw
In reply to a message not in the archive

All the video decoding firmware was *pretty* standard... I suspect ~everyone used my extraction script and it's sitting in /lib/firmware/nouveau for everyone who uses VDPAU. There are packages in several distributions which grab the nvidia blob, my script, and run the extraction on the end user's computer to avoid licensing complications. Please support the existing locations.

Thanks,

-ilia

Quoted 32 lines · Alexandre Courbot

This patchset centralizes the firmware-loading procedure to one set of functions instead of having each engine load its firmware as it pleases. This helps ensure that all firmware comes from the same place, namely nvidia/<chip>/.

This changes where the firmware is fetched from for falcon/xtensa/bios, but these locations never seemed to have been official anyway. Also for most (all?) chips supported by Nouveau there is corresponding internal firmware, so disruption should be minimal/non-existent. If this assumption is wrong, feel free to drop patches 3-5. At the very least, firmware officially provided by NVIDIA should be looked up using the new functions for consistency.

These new functions are also used by the secure boot series, which will follow shortly.

Alexandre Courbot (5):
core: add firmware handling functions
gr/gf100: use the nvkm_firmware functions
falcon: use the nvkm_firmware functions
xtensa: use the nvkm_firmware functions
bios: use the nvkm_firmware functions

 drm/nouveau/include/nvkm/core/firmware.h | 11 ++++++
 drm/nouveau/nvkm/core/Kbuild             |  1 +
 drm/nouveau/nvkm/core/firmware.c         | 64 ++++++++++++++++++++++++++++++++
 drm/nouveau/nvkm/engine/falcon.c         | 22 +++++------
 drm/nouveau/nvkm/engine/gr/gf100.c       | 18 ++-------
 drm/nouveau/nvkm/engine/xtensa.c         | 12 +++---
 drm/nouveau/nvkm/subdev/bios/shadow.c    |  7 ++--
 7 files changed, 99 insertions(+), 36 deletions(-)
 create mode 100644 drm/nouveau/include/nvkm/core/firmware.h
 create mode 100644 drm/nouveau/nvkm/core/firmware.c
Quoted 7 lines

--
2.7.0

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

#15 lore raw
In reply to a message not in the archive
Quoted 6 lines · Ilia Mirkin

All the video decoding firmware was *pretty* standard... I suspect ~everyone used my extraction script and it's sitting in /lib/firmware/nouveau for everyone who uses VDPAU. There are packages in several distributions which grab the nvidia blob, my script, and run the extraction on the end user's computer to avoid licensing complications. Please support the existing locations.

Ok, so there *are* some end-users (not developers) relying on these external firmwares?

In that case probably the best thing to do is to not use these new functions for video - at least for chips that do not require signed firmware. All I'd like to do is reduce the number of occurences of the "build path - load firmware" logic.
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

#17 lore raw
In reply to a message not in the archive
Quoted 8 lines · Alexandre Courbot
Quoted 6 lines · Ilia Mirkin

All the video decoding firmware was *pretty* standard... I suspect ~everyone used my extraction script and it's sitting in /lib/firmware/nouveau for everyone who uses VDPAU. There are packages in several distributions which grab the nvidia blob, my script, and run the extraction on the end user's computer to avoid licensing complications. Please support the existing locations.

Quoted 7 lines

Ok, so there *are* some end-users (not developers) relying on these external firmwares?

In that case probably the best thing to do is to not use these new functions for video - at least for chips that do not require signed firmware. All I'd like to do is reduce the number of occurences of the "build path - load firmware" logic.

Yep. And FWIW there were users of pgraph firmware loading with the old paths too :( For some users, the blob pgraph fw is stable while nouveau one isn't. But hopefully not that many, I think VDPAU has a lot more. VDPAU is currently supported through Kepler.

-ilia
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

#19 lore raw
In reply to a message not in the archive
Quoted 17 lines · Ilia Mirkin
Quoted 8 lines · Alexandre Courbot
Quoted 6 lines · Ilia Mirkin

All the video decoding firmware was *pretty* standard... I suspect ~everyone used my extraction script and it's sitting in /lib/firmware/nouveau for everyone who uses VDPAU. There are packages in several distributions which grab the nvidia blob, my script, and run the extraction on the end user's computer to avoid licensing complications. Please support the existing locations.

Quoted 7 lines

Ok, so there *are* some end-users (not developers) relying on these external firmwares?

In that case probably the best thing to do is to not use these new functions for video - at least for chips that do not require signed firmware. All I'd like to do is reduce the number of occurences of the "build path - load firmware" logic.

Quoted 4 lines

Yep. And FWIW there were users of pgraph firmware loading with the old paths too :( For some users, the blob pgraph fw is stable while nouveau one isn't. But hopefully not that many, I think VDPAU has a lot more. VDPAU is currently supported through Kepler.

I don't think it's worth supporting the soon-to-be-old gr ucode paths going forward. Our implementation of using the binary driver gr firmware is pretty broken anyway (outside of Tegra), and works by accident mostly. I suspect most (if not all) of the issues with our ucode have been ironed out now too, no?

There's probably a legitimate case for keeping support for the video paths, especially since we don't know if/when/what-form nvidia will distrubute them in.

Ben.

Quoted 3 lines

-ilia

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

#4 lore raw

Re: [PATCH 1/5] core: add firmware handling functions

In reply to a message not in the archive

Hi Alexandre,

Quoted 6 lines · Alexandre Courbot

Add two functions nvkm_firmware_get() and nvkm_firmware_put() to load a firmware file and free its resources, respectively. Since firmware files are becoming a necessity for new GPUs, and their location has been standardized to nvidia/chip/, this will prevent duplicate and error-prone name-generation code.

Strictly speaking this will break video decoding (and maybe others) although I'm not sure how much one could care. Then again pinging people to update the scripts [1] will be good :)

[1] http://nouveau.freedesktop.org/wiki/VideoAcceleration/#firmware

Quoted 86 lines
---
 drm/nouveau/include/nvkm/core/firmware.h | 11 ++++++
 drm/nouveau/nvkm/core/Kbuild             |  1 +
 drm/nouveau/nvkm/core/firmware.c         | 64 ++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 drm/nouveau/include/nvkm/core/firmware.h
 create mode 100644 drm/nouveau/nvkm/core/firmware.c
drm/nouveau/include/nvkm/core/firmware.h new file +11 -0
new file mode 100644
index 000000000000..a626ce378f04
@@ -0,0 +1,11 @@
+#ifndef __NVKM_FIRMWARE_H__
+#define __NVKM_FIRMWARE_H__
+
+#include <core/device.h>
+
+int nvkm_firmware_get(struct nvkm_device *device, const char *fwname,
+                     const struct firmware **fw);
+
+void nvkm_firmware_put(const struct firmware *fw);
+
+#endif
drm/nouveau/nvkm/core/Kbuild +1 -0
index 7f66963f305c..86a31a8e1e51 100644
@@ -2,6 +2,7 @@ nvkm-y := nvkm/core/client.o
 nvkm-y += nvkm/core/engine.o
 nvkm-y += nvkm/core/enum.o
 nvkm-y += nvkm/core/event.o
+nvkm-y += nvkm/core/firmware.o
 nvkm-y += nvkm/core/gpuobj.o
 nvkm-y += nvkm/core/ioctl.o
 nvkm-y += nvkm/core/memory.o
drm/nouveau/nvkm/core/firmware.c new file +42 -0
new file mode 100644
index 000000000000..4a4b4a5d55a8
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <core/device.h>
+
+#include <linux/firmware.h>
+
+/**
+ * nvkm_firmware_get - load firmware from the official nvidia/chip/ directory
+ * @device     device that will use that firmware
+ * @fwname     name of firmware file to load
+ * @fw         firmware structure to load to
+ *
+ * Use this function to load firmware files in the form nvidia/chip/fwname.bin.
+ * Firmware files released by NVIDIA will always follow this format.
+ */
+int
+nvkm_firmware_get(struct nvkm_device *device, const char *fwname,
+                 const struct firmware **fw)
+{
+       char f[64];
+       char cname[16];
+       int i;

drm/nouveau/nvkm/core/firmware.c line 52

Quoted 10 lines
drm/nouveau/nvkm/core/firmware.c new file +10 -0
+
+       /* Convert device name to lowercase */
+       strncpy(cname, device->chip->name, sizeof(cname));
+       cname[sizeof(cname) - 1] = '\0';
+       i = strlen(cname);
+       while (i) {
+               --i;
+               cname[i] = tolower(cname[i]);
+       }
+

Considering there's only one user that might need this, is it worth adding it here or just keeping it where needed ?

drm/nouveau/nvkm/core/firmware.c line 63

Quoted 11 lines
drm/nouveau/nvkm/core/firmware.c new file +11 -0
+       snprintf(f, sizeof(f), "nvidia/%s/%s.bin", cname, fwname);
+       return request_firmware(fw, f, device->dev);
+}
+
+/**
+ * nvkm_firmware_put - release firmware loaded with nvkm_firmware_get
+ */
+void
+nvkm_firmware_put(const struct firmware *fw)
+{
+       release_firmware(fw);

If the above suggestion makes sense, then it might be better to keep these two in the header as static inlines ?

Not that either of the two is a hot path, then again having a one/two liner as separate function feels odd.

Cheers,
Emil
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

#6 lore raw

Re: [PATCH 1/5] core: add firmware handling functions

In reply to a message not in the archive
Quoted 9 lines · Emil Velikov

Hi Alexandre,

Quoted 6 lines · Alexandre Courbot

Add two functions nvkm_firmware_get() and nvkm_firmware_put() to load a firmware file and free its resources, respectively. Since firmware files are becoming a necessity for new GPUs, and their location has been standardized to nvidia/chip/, this will prevent duplicate and error-prone name-generation code.

Quoted 5 lines

Strictly speaking this will break video decoding (and maybe others) although I'm not sure how much one could care. Then again pinging people to update the scripts [1] will be good :)

[1] http://nouveau.freedesktop.org/wiki/VideoAcceleration/#firmware

Yeah, these functions are actually designed to load NVIDIA-provided firmware. I thought it would be nice to have a single function for all of Nouveau's firmware needs though.

Quoted 91 lines
Quoted 91 lines
---
 drm/nouveau/include/nvkm/core/firmware.h | 11 ++++++
 drm/nouveau/nvkm/core/Kbuild             |  1 +
 drm/nouveau/nvkm/core/firmware.c         | 64 ++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 drm/nouveau/include/nvkm/core/firmware.h
 create mode 100644 drm/nouveau/nvkm/core/firmware.c
drm/nouveau/include/nvkm/core/firmware.h new file +11 -0
new file mode 100644
index 000000000000..a626ce378f04
@@ -0,0 +1,11 @@
+#ifndef __NVKM_FIRMWARE_H__
+#define __NVKM_FIRMWARE_H__
+
+#include <core/device.h>
+
+int nvkm_firmware_get(struct nvkm_device *device, const char *fwname,
+                     const struct firmware **fw);
+
+void nvkm_firmware_put(const struct firmware *fw);
+
+#endif
drm/nouveau/nvkm/core/Kbuild +1 -0
index 7f66963f305c..86a31a8e1e51 100644
@@ -2,6 +2,7 @@ nvkm-y := nvkm/core/client.o
 nvkm-y += nvkm/core/engine.o
 nvkm-y += nvkm/core/enum.o
 nvkm-y += nvkm/core/event.o
+nvkm-y += nvkm/core/firmware.o
 nvkm-y += nvkm/core/gpuobj.o
 nvkm-y += nvkm/core/ioctl.o
 nvkm-y += nvkm/core/memory.o
drm/nouveau/nvkm/core/firmware.c new file +46 -0
new file mode 100644
index 000000000000..4a4b4a5d55a8
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <core/device.h>
+
+#include <linux/firmware.h>
+
+/**
+ * nvkm_firmware_get - load firmware from the official nvidia/chip/ directory
+ * @device     device that will use that firmware
+ * @fwname     name of firmware file to load
+ * @fw         firmware structure to load to
+ *
+ * Use this function to load firmware files in the form nvidia/chip/fwname.bin.
+ * Firmware files released by NVIDIA will always follow this format.
+ */
+int
+nvkm_firmware_get(struct nvkm_device *device, const char *fwname,
+                 const struct firmware **fw)
+{
+       char f[64];
+       char cname[16];
+       int i;
+
+       /* Convert device name to lowercase */
+       strncpy(cname, device->chip->name, sizeof(cname));
+       cname[sizeof(cname) - 1] = '\0';
Quoted 8 lines

drm/nouveau/nvkm/core/firmware.c line 52

Quoted 6 lines
drm/nouveau/nvkm/core/firmware.c new file +6 -0
+       i = strlen(cname);
+       while (i) {
+               --i;
+               cname[i] = tolower(cname[i]);
+       }
+

Considering there's only one user that might need this, is it worth adding it here or just keeping it where needed ?

So for now GR uses it as GK20A (and hopefully soon, all GM20Xs) have firmware provided by NVIDIA. GR is the only user currently, but the secure-boot feature also makes heavy use of this.

Depending on how much firmware we can release, we may also update other firmware consumers to use these. As far as I understand, there is real "official" location for firmware files at the moment.
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

#8 lore raw

Re: [PATCH 1/5] core: add firmware handling functions

In reply to a message not in the archive
Quoted 120 lines · Alexandre Courbot
Quoted 9 lines · Emil Velikov

Hi Alexandre,

Quoted 6 lines · Alexandre Courbot

Add two functions nvkm_firmware_get() and nvkm_firmware_put() to load a firmware file and free its resources, respectively. Since firmware files are becoming a necessity for new GPUs, and their location has been standardized to nvidia/chip/, this will prevent duplicate and error-prone name-generation code.

Quoted 5 lines

Strictly speaking this will break video decoding (and maybe others) although I'm not sure how much one could care. Then again pinging people to update the scripts [1] will be good :)

[1] http://nouveau.freedesktop.org/wiki/VideoAcceleration/#firmware

Yeah, these functions are actually designed to load NVIDIA-provided firmware. I thought it would be nice to have a single function for all of Nouveau's firmware needs though.

Quoted 91 lines
Quoted 91 lines
---
 drm/nouveau/include/nvkm/core/firmware.h | 11 ++++++
 drm/nouveau/nvkm/core/Kbuild             |  1 +
 drm/nouveau/nvkm/core/firmware.c         | 64 ++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 drm/nouveau/include/nvkm/core/firmware.h
 create mode 100644 drm/nouveau/nvkm/core/firmware.c
drm/nouveau/include/nvkm/core/firmware.h new file +11 -0
new file mode 100644
index 000000000000..a626ce378f04
@@ -0,0 +1,11 @@
+#ifndef __NVKM_FIRMWARE_H__
+#define __NVKM_FIRMWARE_H__
+
+#include <core/device.h>
+
+int nvkm_firmware_get(struct nvkm_device *device, const char *fwname,
+                     const struct firmware **fw);
+
+void nvkm_firmware_put(const struct firmware *fw);
+
+#endif
drm/nouveau/nvkm/core/Kbuild +1 -0
index 7f66963f305c..86a31a8e1e51 100644
@@ -2,6 +2,7 @@ nvkm-y := nvkm/core/client.o
 nvkm-y += nvkm/core/engine.o
 nvkm-y += nvkm/core/enum.o
 nvkm-y += nvkm/core/event.o
+nvkm-y += nvkm/core/firmware.o
 nvkm-y += nvkm/core/gpuobj.o
 nvkm-y += nvkm/core/ioctl.o
 nvkm-y += nvkm/core/memory.o
drm/nouveau/nvkm/core/firmware.c new file +46 -0
new file mode 100644
index 000000000000..4a4b4a5d55a8
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <core/device.h>
+
+#include <linux/firmware.h>
+
+/**
+ * nvkm_firmware_get - load firmware from the official nvidia/chip/ directory
+ * @device     device that will use that firmware
+ * @fwname     name of firmware file to load
+ * @fw         firmware structure to load to
+ *
+ * Use this function to load firmware files in the form nvidia/chip/fwname.bin.
+ * Firmware files released by NVIDIA will always follow this format.
+ */
+int
+nvkm_firmware_get(struct nvkm_device *device, const char *fwname,
+                 const struct firmware **fw)
+{
+       char f[64];
+       char cname[16];
+       int i;
+
+       /* Convert device name to lowercase */
+       strncpy(cname, device->chip->name, sizeof(cname));
+       cname[sizeof(cname) - 1] = '\0';
Quoted 8 lines

drm/nouveau/nvkm/core/firmware.c line 52

Quoted 6 lines
drm/nouveau/nvkm/core/firmware.c new file +6 -0
+       i = strlen(cname);
+       while (i) {
+               --i;
+               cname[i] = tolower(cname[i]);
+       }
+

Considering there's only one user that might need this, is it worth adding it here or just keeping it where needed ?

Quoted 7 lines

So for now GR uses it as GK20A (and hopefully soon, all GM20Xs) have firmware provided by NVIDIA. GR is the only user currently, but the secure-boot feature also makes heavy use of this.

Depending on how much firmware we can release, we may also update other firmware consumers to use these. As far as I understand, there is real "official" location for firmware files at the moment.

Silly brain - managed to get cname, fwname and name all in the wrong order.

Pardon for the noise.
Emil
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau