Skip to contentSkip to conversation

Secure Boot refactoring

PATCH Superseded Alexandre Courbot 2 participants 12 messages Oct 11, 2016 3 messages not in the archive

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Secure Boot refactoring

Hi everyone,

Apologies for the big patchset. This is a rework of the secure boot code that moves the building of the blob into its own set of source files (and own hooks), making the code more flexible and (hopefully) easier to understand as well.

This rework is needed to support more signed firmware for existing and new chips. Since the firmwares in question are not available yet I cannot send the code for them yet, but hopefully the gain in clarity will be enough to merge this series ahead of the rest.

Patch 1 is just to make nv*_printk() more tolerent of my use of const pointers. Patch 2 lays the foundation of a small common falcon library that could avoid duplicated code in various parts of the driver. Right now only secure boot makes use of it (patch 3), but there are many potential users (GR, PMU, etc). I will test users and send further patches making use of it.

Patch 4 renames a hook to something better describing its actual use.

Patch 5 is where the big refactoring occurs. It looks scary, but is really just moving code (and introducing the nvkm_acr structures).

Patch 6, 7 and 8 remove a few HS hooks that turn out to be unneeded, and add support for LS hooks.

The end result can be observed by looking at acr_v1_gm20b.c: all the specifics of GM20B's firmware are handled in a single file, with no data structures shared with acr_v1.c. The gm20b_acr_v1_ls_func variable also describes clearly what LS firmwares are to be loaded and how.

Alexandre Courbot (8):
core: constify nv*_printk macros
core: add falcon library
secboot: use falcon library's IMEM/DMEM loading functions
secboot: rename init() hook to oneinit()
secboot: move ACR building logic into own source files
secboot: remove fixup_hs_desc hook
secboot: add low-secure firmware hooks
secboot: generate HS BL descriptor in hook

 drm/nouveau/include/nvkm/core/client.h         |    4 +-
 drm/nouveau/include/nvkm/core/device.h         |    2 +-
 drm/nouveau/include/nvkm/core/falcon.h         |   50 +
 drm/nouveau/include/nvkm/core/subdev.h         |    2 +-
 drm/nouveau/include/nvkm/subdev/secboot.h      |   33 +-
 drm/nouveau/nvkm/core/Kbuild                   |    1 +
 drm/nouveau/nvkm/core/falcon.c                 |   62 ++
 drm/nouveau/nvkm/engine/gr/gf100.c             |   16 +-
 drm/nouveau/nvkm/engine/gr/gm200.c             |    6 +-
 drm/nouveau/nvkm/subdev/secboot/Kbuild         |    2 +
 drm/nouveau/nvkm/subdev/secboot/acr.h          |   67 ++
 drm/nouveau/nvkm/subdev/secboot/acr_v1.c       | 1193 ++++++++++++++++++++
 drm/nouveau/nvkm/subdev/secboot/acr_v1.h       |  346 ++++++
 drm/nouveau/nvkm/subdev/secboot/acr_v1_gm20b.c |  135 +++
 drm/nouveau/nvkm/subdev/secboot/base.c         |  113 +-
 drm/nouveau/nvkm/subdev/secboot/gm200.c        | 1386 +-----------------------
 drm/nouveau/nvkm/subdev/secboot/gm200.h        |   43 +
 drm/nouveau/nvkm/subdev/secboot/gm20b.c        |  141 +--
 drm/nouveau/nvkm/subdev/secboot/priv.h         |  208 +---
 19 files changed, 2072 insertions(+), 1738 deletions(-)
 create mode 100644 drm/nouveau/include/nvkm/core/falcon.h
 create mode 100644 drm/nouveau/nvkm/core/falcon.c
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/acr.h
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/acr_v1.c
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/acr_v1.h
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/acr_v1_gm20b.c
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/gm200.h
Signature · 6 lines
2.10.0

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

A message that is not in the archive (sent off-list or not yet received): 20161011064553.10616-1-acourbot-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org

#2 lore raw

PATCH 1/8 core: constify nv*_printk macros

Constify the local variables declared in these macros so we can pass const pointers to them.

---
 drm/nouveau/include/nvkm/core/client.h | 4 ++--
 drm/nouveau/include/nvkm/core/device.h | 2 +-
 drm/nouveau/include/nvkm/core/subdev.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drm/nouveau/include/nvkm/core/client.h +2 -2
index eaf5905a87a3..99083349c3d4 100644
@@ -37,8 +37,8 @@ int nvkm_client_notify_put(struct nvkm_client *, int index);
 
 /* logging for client-facing objects */
 #define nvif_printk(o,l,p,f,a...) do {                                         \
-	struct nvkm_object *_object = (o);                                     \
-	struct nvkm_client *_client = _object->client;                         \
+	const struct nvkm_object *_object = (o);                               \
+	const struct nvkm_client *_client = _object->client;                   \
 	if (_client->debug >= NV_DBG_##l)                                      \
 		printk(KERN_##p "nouveau: %s:%08x:%08x: "f, _client->name,     \
 		       _object->handle, _object->oclass, ##a);                 \
drm/nouveau/include/nvkm/core/device.h +1 -1
index 6bc712f32c8b..d426b86e2712 100644
@@ -262,7 +262,7 @@ extern const struct nvkm_sclass nvkm_udevice_sclass;
 
 /* device logging */
 #define nvdev_printk_(d,l,p,f,a...) do {                                       \
-	struct nvkm_device *_device = (d);                                     \
+	const struct nvkm_device *_device = (d);                               \
 	if (_device->debug >= (l))                                             \
 		dev_##p(_device->dev, f, ##a);                                 \
 } while(0)
drm/nouveau/include/nvkm/core/subdev.h +1 -1
index 57adefa8b08e..ca9ed3d68f44 100644
@@ -32,7 +32,7 @@ void nvkm_subdev_intr(struct nvkm_subdev *);
 
 /* subdev logging */
 #define nvkm_printk_(s,l,p,f,a...) do {                                        \
-	struct nvkm_subdev *_subdev = (s);                                     \
+	const struct nvkm_subdev *_subdev = (s);                               \
 	if (_subdev->debug >= (l)) {                                           \
 		dev_##p(_subdev->device->dev, "%s: "f,                         \
 			nvkm_subdev_name[_subdev->index], ##a);                \
Signature · 6 lines
2.10.0

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

PATCH 2/8 core: add falcon library

In reply to a message not in the archive

Some falcon functionality, like loading code/data into IMEM/DMEM, is re-implemented in various parts of the driver. Create a small falcon library that will contain most common operations in order to avoid duplicate code.

For now this library contains various defines that are used in secure boot code, plus IMEM and DMEM loading functions.

In addition to the library itself, this patch updates users of the previously secure-boot only definitions to use the new global ones.

---
 drm/nouveau/include/nvkm/core/falcon.h    | 50 +++++++++++++++++++++++++
 drm/nouveau/include/nvkm/subdev/secboot.h | 16 ++------
 drm/nouveau/nvkm/core/Kbuild              |  1 +
 drm/nouveau/nvkm/core/falcon.c            | 62 +++++++++++++++++++++++++++++++
 drm/nouveau/nvkm/engine/gr/gf100.c        | 16 ++++----
 drm/nouveau/nvkm/engine/gr/gm200.c        |  6 +--
 drm/nouveau/nvkm/subdev/secboot/base.c    | 23 +++---------
 drm/nouveau/nvkm/subdev/secboot/gm200.c   | 48 ++++++++++--------------
 drm/nouveau/nvkm/subdev/secboot/gm20b.c   |  4 +-
 drm/nouveau/nvkm/subdev/secboot/priv.h    |  8 ++--
 10 files changed, 159 insertions(+), 75 deletions(-)
 create mode 100644 drm/nouveau/include/nvkm/core/falcon.h
 create mode 100644 drm/nouveau/nvkm/core/falcon.c
drm/nouveau/include/nvkm/core/falcon.h new file +50 -0
new file mode 100644
index 000000000000..530119847163
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+#ifndef __NVKM_FALCON_H__
+#define __NVKM_FALCON_H__
+
+#include <core/device.h>
+
+enum nvkm_falconidx {
+	NVKM_FALCON_PMU		= 0,
+	NVKM_FALCON_RESERVED	= 1,
+	NVKM_FALCON_FECS	= 2,
+	NVKM_FALCON_GPCCS	= 3,
+	NVKM_FALCON_END		= 4,
+	NVKM_FALCON_INVALID	= 0xffffffff,
+};
+
+enum nvkm_falcon_dmaidx {
+	FALCON_DMAIDX_UCODE		= 0,
+	FALCON_DMAIDX_VIRT		= 1,
+	FALCON_DMAIDX_PHYS_VID		= 2,
+	FALCON_DMAIDX_PHYS_SYS_COH	= 3,
+	FALCON_DMAIDX_PHYS_SYS_NCOH	= 4,
+};
+
+extern const char *nvkm_falcon_name[];
+
+void nvkm_falcon_load_imem(struct nvkm_device *, u32, void *, u32, u32, u32);
+void nvkm_falcon_load_dmem(struct nvkm_device *, u32, void *, u32, u32);
+
+#endif
drm/nouveau/include/nvkm/subdev/secboot.h +4 -12
index b04c38c07761..ffc2204d2a50 100644
@@ -24,15 +24,7 @@
 #define __NVKM_SECURE_BOOT_H__
 
 #include <core/subdev.h>
-
-enum nvkm_secboot_falcon {
-	NVKM_SECBOOT_FALCON_PMU	= 0,
-	NVKM_SECBOOT_FALCON_RESERVED = 1,
-	NVKM_SECBOOT_FALCON_FECS = 2,
-	NVKM_SECBOOT_FALCON_GPCCS = 3,
-	NVKM_SECBOOT_FALCON_END = 4,
-	NVKM_SECBOOT_FALCON_INVALID = 0xffffffff,
-};
+#include <core/falcon.h>
 
 /**
  * @base:		base IO address of the falcon performing secure boot
@@ -48,9 +40,9 @@ struct nvkm_secboot {
 };
 #define nvkm_secboot(p) container_of((p), struct nvkm_secboot, subdev)
 
-bool nvkm_secboot_is_managed(struct nvkm_secboot *, enum nvkm_secboot_falcon);
-int nvkm_secboot_reset(struct nvkm_secboot *, u32 falcon);
-int nvkm_secboot_start(struct nvkm_secboot *, u32 falcon);
+bool nvkm_secboot_is_managed(struct nvkm_secboot *, enum nvkm_falconidx);
+int nvkm_secboot_reset(struct nvkm_secboot *, enum nvkm_falconidx);
+int nvkm_secboot_start(struct nvkm_secboot *, enum nvkm_falconidx);
 
 int gm200_secboot_new(struct nvkm_device *, int, struct nvkm_secboot **);
 int gm20b_secboot_new(struct nvkm_device *, int, struct nvkm_secboot **);
drm/nouveau/nvkm/core/Kbuild +1 -0
index 86a31a8e1e51..4196e4620c3b 100644
@@ -13,3 +13,4 @@ nvkm-y += nvkm/core/oproxy.o
 nvkm-y += nvkm/core/option.o
 nvkm-y += nvkm/core/ramht.o
 nvkm-y += nvkm/core/subdev.o
+nvkm-y += nvkm/core/falcon.o
drm/nouveau/nvkm/core/falcon.c new file +62 -0

62 lines not on this page · raw message

drm/nouveau/nvkm/engine/gr/gf100.c +8 -8
index 157919c788e6..f0dafe666a5a 100644
@@ -1464,16 +1464,16 @@ gf100_gr_init_ctxctl(struct gf100_gr *gr)
 		nvkm_mc_unk260(device, 0);
 
 		/* securely-managed falcons must be reset using secure boot */
-		if (nvkm_secboot_is_managed(sb, NVKM_SECBOOT_FALCON_FECS))
-			ret = nvkm_secboot_reset(sb, NVKM_SECBOOT_FALCON_FECS);
+		if (nvkm_secboot_is_managed(sb, NVKM_FALCON_FECS))
+			ret = nvkm_secboot_reset(sb, NVKM_FALCON_FECS);
 		else
 			gf100_gr_init_fw(gr, 0x409000, &gr->fuc409c,
 					 &gr->fuc409d);
 		if (ret)
 			return ret;
 
-		if (nvkm_secboot_is_managed(sb, NVKM_SECBOOT_FALCON_GPCCS))
-			ret = nvkm_secboot_reset(sb, NVKM_SECBOOT_FALCON_GPCCS);
+		if (nvkm_secboot_is_managed(sb, NVKM_FALCON_GPCCS))
+			ret = nvkm_secboot_reset(sb, NVKM_FALCON_GPCCS);
 		else
 			gf100_gr_init_fw(gr, 0x41a000, &gr->fuc41ac,
 					 &gr->fuc41ad);
@@ -1487,12 +1487,12 @@ gf100_gr_init_ctxctl(struct gf100_gr *gr)
 		nvkm_wr32(device, 0x41a10c, 0x00000000);
 		nvkm_wr32(device, 0x40910c, 0x00000000);
 
-		if (nvkm_secboot_is_managed(sb, NVKM_SECBOOT_FALCON_GPCCS))
-			nvkm_secboot_start(sb, NVKM_SECBOOT_FALCON_GPCCS);
+		if (nvkm_secboot_is_managed(sb, NVKM_FALCON_GPCCS))
+			nvkm_secboot_start(sb, NVKM_FALCON_GPCCS);
 		else
 			nvkm_wr32(device, 0x41a100, 0x00000002);
-		if (nvkm_secboot_is_managed(sb, NVKM_SECBOOT_FALCON_FECS))
-			nvkm_secboot_start(sb, NVKM_SECBOOT_FALCON_FECS);
+		if (nvkm_secboot_is_managed(sb, NVKM_FALCON_FECS))
+			nvkm_secboot_start(sb, NVKM_FALCON_FECS);
 		else
 			nvkm_wr32(device, 0x409100, 0x00000002);
 		if (nvkm_msec(device, 2000,
drm/nouveau/nvkm/engine/gr/gm200.c +2 -4
index 6435f1257572..7f4de8e3c643 100644
@@ -184,14 +184,12 @@ gm200_gr_new_(const struct gf100_gr_func *func, struct nvkm_device *device,
 		return ret;
 
 	/* Load firmwares for non-secure falcons */
-	if (!nvkm_secboot_is_managed(device->secboot,
-				     NVKM_SECBOOT_FALCON_FECS)) {
+	if (!nvkm_secboot_is_managed(device->secboot, NVKM_FALCON_FECS)) {
 		if ((ret = gf100_gr_ctor_fw(gr, "gr/fecs_inst", &gr->fuc409c)) ||
 		    (ret = gf100_gr_ctor_fw(gr, "gr/fecs_data", &gr->fuc409d)))
 			return ret;
 	}
-	if (!nvkm_secboot_is_managed(device->secboot,
-				     NVKM_SECBOOT_FALCON_GPCCS)) {
+	if (!nvkm_secboot_is_managed(device->secboot, NVKM_FALCON_GPCCS)) {
 		if ((ret = gf100_gr_ctor_fw(gr, "gr/gpccs_inst", &gr->fuc41ac)) ||
 		    (ret = gf100_gr_ctor_fw(gr, "gr/gpccs_data", &gr->fuc41ad)))
 			return ret;
drm/nouveau/nvkm/subdev/secboot/base.c +6 -17
index 314be2192b7d..6b3346ff0253 100644
@@ -21,18 +21,10 @@
  */
 #include "priv.h"
 
+#include <core/falcon.h>
 #include <subdev/mc.h>
 #include <subdev/timer.h>
 
-static const char *
-managed_falcons_names[] = {
-	[NVKM_SECBOOT_FALCON_PMU] = "PMU",
-	[NVKM_SECBOOT_FALCON_RESERVED] = "<reserved>",
-	[NVKM_SECBOOT_FALCON_FECS] = "FECS",
-	[NVKM_SECBOOT_FALCON_GPCCS] = "GPCCS",
-	[NVKM_SECBOOT_FALCON_END] = "<invalid>",
-};
-
 /*
  * Helper falcon functions
  */
@@ -155,7 +147,6 @@ nvkm_secboot_falcon_run(struct nvkm_secboot *sb)
 	return 0;
 }
 
-
 /**
  * nvkm_secboot_reset() - reset specified falcon
  */
@@ -190,8 +181,7 @@ nvkm_secboot_start(struct nvkm_secboot *sb, u32 falcon)
  * nvkm_secboot_is_managed() - check whether a given falcon is securely-managed
  */
 bool
-nvkm_secboot_is_managed(struct nvkm_secboot *secboot,
-			enum nvkm_secboot_falcon fid)
+nvkm_secboot_is_managed(struct nvkm_secboot *secboot, enum nvkm_falconidx fid)
 {
 	if (!secboot)
 		return false;
@@ -253,14 +243,14 @@ nvkm_secboot_ctor(const struct nvkm_secboot_func *func,
 		  struct nvkm_device *device, int index,
 		  struct nvkm_secboot *sb)
 {
-	unsigned long fid;
+	unsigned long id;
 
 	nvkm_subdev_ctor(&nvkm_secboot, device, index, &sb->subdev);
 	sb->func = func;
 
 	/* setup the performing falcon's base address and masks */
 	switch (func->boot_falcon) {
-	case NVKM_SECBOOT_FALCON_PMU:
+	case NVKM_FALCON_PMU:
 		sb->devidx = NVKM_SUBDEV_PMU;
 		sb->base = 0x10a000;
 		break;
@@ -270,9 +260,8 @@ nvkm_secboot_ctor(const struct nvkm_secboot_func *func,
 	};
 
 	nvkm_debug(&sb->subdev, "securely managed falcons:\n");
-	for_each_set_bit(fid, &sb->func->managed_falcons,
-			 NVKM_SECBOOT_FALCON_END)
-		nvkm_debug(&sb->subdev, "- %s\n", managed_falcons_names[fid]);
+	for_each_set_bit(id, &sb->func->managed_falcons, NVKM_FALCON_END)
+		nvkm_debug(&sb->subdev, "- %s\n", nvkm_falcon_name[id]);
 
 	return 0;
 }
drm/nouveau/nvkm/subdev/secboot/gm200.c +20 -28

140 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/gm20b.c +2 -2
index d5395ebfe8d3..66a1d01f45ce 100644
@@ -192,8 +192,8 @@ gm20b_secboot = {
 	.init = gm20b_secboot_init,
 	.reset = gm200_secboot_reset,
 	.start = gm200_secboot_start,
-	.managed_falcons = BIT(NVKM_SECBOOT_FALCON_FECS),
-	.boot_falcon = NVKM_SECBOOT_FALCON_PMU,
+	.managed_falcons = BIT(NVKM_FALCON_FECS),
+	.boot_falcon = NVKM_FALCON_PMU,
 };
 
 int
drm/nouveau/nvkm/subdev/secboot/priv.h +4 -4
index a9a8a0e1017e..b1ef3d1b4c9d 100644
@@ -30,11 +30,11 @@ struct nvkm_secboot_func {
 	int (*init)(struct nvkm_secboot *);
 	int (*fini)(struct nvkm_secboot *, bool suspend);
 	void *(*dtor)(struct nvkm_secboot *);
-	int (*reset)(struct nvkm_secboot *, enum nvkm_secboot_falcon);
-	int (*start)(struct nvkm_secboot *, enum nvkm_secboot_falcon);
+	int (*reset)(struct nvkm_secboot *, enum nvkm_falconidx);
+	int (*start)(struct nvkm_secboot *, enum nvkm_falconidx);
 
 	/* ID of the falcon that will perform secure boot */
-	enum nvkm_secboot_falcon boot_falcon;
+	enum nvkm_falconidx boot_falcon;
 	/* Bit-mask of IDs of managed falcons */
 	unsigned long managed_falcons;
 };
@@ -191,7 +191,7 @@ struct gm200_secboot {
 		RESET,
 		/* In low-secure mode and running */
 		RUNNING,
-	} falcon_state[NVKM_SECBOOT_FALCON_END];
+	} falcon_state[NVKM_FALCON_END];
 
 	bool firmware_ok;
 };
Signature · 6 lines
2.10.0

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

PATCH 3/8 secboot: use falcon library's IMEM/DMEM loading functions

In reply to a message not in the archive

Replace the falcon loading functions with calls to the equivalent functions of the falcon library.

---
 drm/nouveau/nvkm/subdev/secboot/gm200.c | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)
drm/nouveau/nvkm/subdev/secboot/gm200.c +9 -22
index e387673e13a6..8067d29f526f 100644
@@ -1103,39 +1103,26 @@ gm200_secboot_load_hs_bl(struct gm200_secboot *gsb, void *data, u32 data_size)
 	void *hsbl_data = blob_data + hsbl_desc->data_off;
 	u32 code_size = ALIGN(hsbl_desc->code_size, 256);
 	const u32 base = gsb->base.base;
-	u32 blk;
-	u32 tag;
-	int i;
+	u32 code_start;
 
 	/*
 	 * Copy HS bootloader data
 	 */
-	nvkm_wr32(device, base + 0x1c0, (0x00000000 | (0x1 << 24)));
-	for (i = 0; i < hsbl_desc->data_size / 4; i++)
-		nvkm_wr32(device, base + 0x1c4, ((u32 *)hsbl_data)[i]);
+	nvkm_falcon_load_dmem(device, gsb->base.base, hsbl_data, 0x00000,
+			      hsbl_desc->data_size);
 
 	/*
 	 * Copy HS bootloader interface structure where the HS descriptor
 	 * expects it to be
 	 */
-	nvkm_wr32(device, base + 0x1c0,
-		  (hsbl_desc->dmem_load_off | (0x1 << 24)));
-	for (i = 0; i < data_size / 4; i++)
-		nvkm_wr32(device, base + 0x1c4, ((u32 *)data)[i]);
+	nvkm_falcon_load_dmem(device, gsb->base.base, data,
+			      hsbl_desc->dmem_load_off, data_size);
 
 	/* Copy HS bootloader code to end of IMEM */
-	blk = (nvkm_rd32(device, base + 0x108) & 0x1ff) - (code_size >> 8);
-	tag = hsbl_desc->start_tag;
-	nvkm_wr32(device, base + 0x180, ((blk & 0xff) << 8) | (0x1 << 24));
-	for (i = 0; i < code_size / 4; i++) {
-		/* write new tag every 256B */
-		if ((i & 0x3f) == 0) {
-			nvkm_wr32(device, base + 0x188, tag & 0xffff);
-			tag++;
-		}
-		nvkm_wr32(device, base + 0x184, ((u32 *)hsbl_code)[i]);
-	}
-	nvkm_wr32(device, base + 0x188, 0);
+	code_start = (nvkm_rd32(device, base + 0x108) & 0x1ff) << 8;
+	code_start -= code_size;
+	nvkm_falcon_load_imem(device, gsb->base.base, hsbl_code, code_start,
+			      code_size, hsbl_desc->start_tag);
 }
 
 /**
Signature · 6 lines
2.10.0

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

PATCH 4/8 secboot: rename init() hook to oneinit()

In reply to a message not in the archive

The init() hook is called by the subdev's oneinit(). Rename it accordingly to avoid confusion about the lifetime of objects allocated in it.

---
 drm/nouveau/nvkm/subdev/secboot/base.c  | 4 ++--
 drm/nouveau/nvkm/subdev/secboot/gm200.c | 4 ++--
 drm/nouveau/nvkm/subdev/secboot/gm20b.c | 6 +++---
 drm/nouveau/nvkm/subdev/secboot/priv.h  | 4 ++--
 4 files changed, 9 insertions(+), 9 deletions(-)
drm/nouveau/nvkm/subdev/secboot/base.c +2 -2
index 6b3346ff0253..ea36851358ea 100644
@@ -196,8 +196,8 @@ nvkm_secboot_oneinit(struct nvkm_subdev *subdev)
 	int ret = 0;
 
 	/* Call chip-specific init function */
-	if (sb->func->init)
-		ret = sb->func->init(sb);
+	if (sb->func->oneinit)
+		ret = sb->func->oneinit(sb);
 	if (ret) {
 		nvkm_error(subdev, "Secure Boot initialization failed: %d\n",
 			   ret);
drm/nouveau/nvkm/subdev/secboot/gm200.c +2 -2
index 8067d29f526f..b020e41d2391 100644
@@ -1305,7 +1305,7 @@ gm200_secboot_start(struct nvkm_secboot *sb, enum nvkm_falconidx falcon)
 
 
 int
-gm200_secboot_init(struct nvkm_secboot *sb)
+gm200_secboot_oneinit(struct nvkm_secboot *sb)
 {
 	struct gm200_secboot *gsb = gm200_secboot(sb);
 	struct nvkm_device *device = sb->subdev.device;
@@ -1384,7 +1384,7 @@ gm200_secboot_dtor(struct nvkm_secboot *sb)
 static const struct nvkm_secboot_func
 gm200_secboot = {
 	.dtor = gm200_secboot_dtor,
-	.init = gm200_secboot_init,
+	.oneinit = gm200_secboot_oneinit,
 	.fini = gm200_secboot_fini,
 	.reset = gm200_secboot_reset,
 	.start = gm200_secboot_start,
drm/nouveau/nvkm/subdev/secboot/gm20b.c +3 -3
index 66a1d01f45ce..1cb663c31e17 100644
@@ -174,7 +174,7 @@ gm20b_tegra_read_wpr(struct gm200_secboot *gsb)
 #endif
 
 static int
-gm20b_secboot_init(struct nvkm_secboot *sb)
+gm20b_secboot_oneinit(struct nvkm_secboot *sb)
 {
 	struct gm200_secboot *gsb = gm200_secboot(sb);
 	int ret;
@@ -183,13 +183,13 @@ gm20b_secboot_init(struct nvkm_secboot *sb)
 	if (ret)
 		return ret;
 
-	return gm200_secboot_init(sb);
+	return gm200_secboot_oneinit(sb);
 }
 
 static const struct nvkm_secboot_func
 gm20b_secboot = {
 	.dtor = gm200_secboot_dtor,
-	.init = gm20b_secboot_init,
+	.oneinit = gm20b_secboot_oneinit,
 	.reset = gm200_secboot_reset,
 	.start = gm200_secboot_start,
 	.managed_falcons = BIT(NVKM_FALCON_FECS),
drm/nouveau/nvkm/subdev/secboot/priv.h +2 -2
index b1ef3d1b4c9d..baa802b1e9d2 100644
@@ -27,7 +27,7 @@
 #include <subdev/mmu.h>
 
 struct nvkm_secboot_func {
-	int (*init)(struct nvkm_secboot *);
+	int (*oneinit)(struct nvkm_secboot *);
 	int (*fini)(struct nvkm_secboot *, bool suspend);
 	void *(*dtor)(struct nvkm_secboot *);
 	int (*reset)(struct nvkm_secboot *, enum nvkm_falconidx);
@@ -224,7 +224,7 @@ struct gm200_secboot_func {
 	int (*prepare_blobs)(struct gm200_secboot *);
 };
 
-int gm200_secboot_init(struct nvkm_secboot *);
+int gm200_secboot_oneinit(struct nvkm_secboot *);
 void *gm200_secboot_dtor(struct nvkm_secboot *);
 int gm200_secboot_reset(struct nvkm_secboot *, u32);
 int gm200_secboot_start(struct nvkm_secboot *, u32);
Signature · 6 lines
2.10.0

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

PATCH 5/8 secboot: move ACR building logic into own source files

In reply to a message not in the archive

Separate the ACR management logic (which blobs are to be used, and how to load them) from the secure boot code (which is concerned with executing these blobs on a given hardware). This gives us more flexibility as to how ACR and secure boot implementations can be combined, and also splits the code into more digestible source files.

This split is also necessary for further changes that add some more abstractions to the ACR interface and better separate implementations.

The current ACR implementation used by GM20x is called "acr_v1".

This commit looks pretty big, but it really mostly moves code around.

---
 drm/nouveau/include/nvkm/subdev/secboot.h      |   17 +-
 drm/nouveau/nvkm/subdev/secboot/Kbuild         |    2 +
 drm/nouveau/nvkm/subdev/secboot/acr.h          |   67 ++
 drm/nouveau/nvkm/subdev/secboot/acr_v1.c       | 1313 +++++++++++++++++++++++
 drm/nouveau/nvkm/subdev/secboot/acr_v1.h       |  183 ++++
 drm/nouveau/nvkm/subdev/secboot/acr_v1_gm20b.c |  130 +++
 drm/nouveau/nvkm/subdev/secboot/base.c         |   90 +-
 drm/nouveau/nvkm/subdev/secboot/gm200.c        | 1361 +-----------------------
 drm/nouveau/nvkm/subdev/secboot/gm200.h        |   43 +
 drm/nouveau/nvkm/subdev/secboot/gm20b.c        |  135 +--
 drm/nouveau/nvkm/subdev/secboot/priv.h         |  206 +---
 11 files changed, 1881 insertions(+), 1666 deletions(-)
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/acr.h
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/acr_v1.c
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/acr_v1.h
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/acr_v1_gm20b.c
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/gm200.h
drm/nouveau/include/nvkm/subdev/secboot.h +12 -5
index ffc2204d2a50..bca482d27a33 100644
@@ -26,17 +26,24 @@
 #include <core/subdev.h>
 #include <core/falcon.h>
 
-/**
- * @base:		base IO address of the falcon performing secure boot
- * @irq_mask:		IRQ mask of the falcon performing secure boot
- * @enable_mask:	enable mask of the falcon performing secure boot
-*/
 struct nvkm_secboot {
 	const struct nvkm_secboot_func *func;
+	struct nvkm_acr *acr;
 	struct nvkm_subdev subdev;
 
 	enum nvkm_devidx devidx;
 	u32 base;
+
+	/*
+	 * Address and size of the WPR region. On dGPU this can be set to the
+	 * address of the LS blob, but on Tegra this is a fixed region set by
+	 * the bootloader.
+	 *
+	 * If wpr_size == 0, this means the WPR region is dynamically managed
+	 * by the ACR.
+	 */
+	u64 wpr_addr;
+	u32 wpr_size;
 };
 #define nvkm_secboot(p) container_of((p), struct nvkm_secboot, subdev)
 
drm/nouveau/nvkm/subdev/secboot/Kbuild +2 -0
index b02b868a6589..b783f6d68927 100644
@@ -1,3 +1,5 @@
 nvkm-y += nvkm/subdev/secboot/base.o
+nvkm-y += nvkm/subdev/secboot/acr_v1.o
+nvkm-y += nvkm/subdev/secboot/acr_v1_gm20b.o
 nvkm-y += nvkm/subdev/secboot/gm200.o
 nvkm-y += nvkm/subdev/secboot/gm20b.o
drm/nouveau/nvkm/subdev/secboot/acr.h new file +67 -0

67 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/acr_v1.c new file +1313 -0

1,313 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/acr_v1.h new file +183 -0

183 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/acr_v1_gm20b.c new file +130 -0

130 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/base.c +80 -10

148 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/gm200.c +27 -1334

1,125 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/gm200.h new file +43 -0

43 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/gm20b.c +15 -120

135 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/priv.h +9 -197

206 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 6 lines
2.10.0

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

Part of the diff is not shown here. View the raw message.

#7 lore raw

PATCH 6/8 secboot: remove fixup_hs_desc hook

In reply to a message not in the archive

This hook can be removed if the function writing the HS descriptor is aware of WPR settings. Let's do that as it allows us to make the ACR descriptor structure private and save some code.

---
 drm/nouveau/nvkm/subdev/secboot/acr_v1.c       | 106 +++++++++++++++++--------
 drm/nouveau/nvkm/subdev/secboot/acr_v1.h       |  45 -----------
 drm/nouveau/nvkm/subdev/secboot/acr_v1_gm20b.c |  11 ---
 3 files changed, 75 insertions(+), 87 deletions(-)
drm/nouveau/nvkm/subdev/secboot/acr_v1.c +75 -31
index d7405f8f7c63..db0fb3338398 100644
@@ -298,6 +298,49 @@ struct hsf_load_header {
 	} app[0];
 };
 
+/**
+ * struct hsflcn_acr_desc - data section of the HS firmware
+ *
+ * This header is to be copied at the beginning of DMEM by the HS bootloader.
+ *
+ * @signature:		signature of ACR ucode
+ * @wpr_region_id:	region ID holding the WPR header and its details
+ * @wpr_offset:		offset from the WPR region holding the wpr header
+ * @regions:		region descriptors
+ * @nonwpr_ucode_blob_size:	size of LS blob
+ * @nonwpr_ucode_blob_start:	FB location of LS blob is
+ */
+struct hsflcn_acr_desc {
+	union {
+		u8 reserved_dmem[0x200];
+		u32 signatures[4];
+	} ucode_reserved_space;
+	u32 wpr_region_id;
+	u32 wpr_offset;
+	u32 mmu_mem_range;
+#define FLCN_ACR_MAX_REGIONS 2
+	struct {
+		u32 no_regions;
+		struct {
+			u32 start_addr;
+			u32 end_addr;
+			u32 region_id;
+			u32 read_mask;
+			u32 write_mask;
+			u32 client_mask;
+		} region_props[FLCN_ACR_MAX_REGIONS];
+	} regions;
+	u32 ucode_blob_size;
+	u64 ucode_blob_base __aligned(8);
+	struct {
+		u32 vpr_enabled;
+		u32 vpr_start;
+		u32 vpr_end;
+		u32 hdcp_policies;
+	} vpr_desc;
+};
+
+
 static inline u64 flcn64_to_u64(const struct flcn_u64 f)
 {
 	return ((u64)f.hi) << 32 | f.lo;
@@ -879,6 +922,31 @@ acr_v1_populate_hsf_bl_desc(void *acr_image, struct acr_v1_bl_desc *bl_desc)
 	bl_desc->data_size = load_hdr->data_size;
 }
 
+static void
+acr_v1_fixup_hs_desc(struct nvkm_acr_v1 *acr, struct nvkm_secboot *sb,
+			    struct hsflcn_acr_desc *desc)
+{
+	struct nvkm_gpuobj *ls_blob = acr->ls_blob;
+
+	desc->ucode_blob_base = acr->ls_blob->addr;
+	desc->ucode_blob_size = acr->ls_blob->size;
+
+	desc->wpr_offset = 0;
+
+	/*
+	 * WPR region information for the HS binary to set up, if WPR is not
+	 * fixed
+	 */
+	if (sb->wpr_size == 0) {
+		desc->wpr_region_id = 1;
+		desc->regions.no_regions = 1;
+		desc->regions.region_props[0].region_id = 1;
+		desc->regions.region_props[0].start_addr = ls_blob->addr >> 8;
+		desc->regions.region_props[0].end_addr =
+			(ls_blob->addr + ls_blob->size) >> 8;
+	}
+}
+
 /**
  * acr_v1_prepare_hs_blob - load and prepare a HS blob and BL descriptor
  *
@@ -889,9 +957,9 @@ acr_v1_populate_hsf_bl_desc(void *acr_image, struct acr_v1_bl_desc *bl_desc)
  * @patch whether we should patch the HS descriptor (only for HS loaders)
  */
 static int
-acr_v1_prepare_hs_blob(struct nvkm_acr_v1 *acr, const char *fw,
-			      struct nvkm_gpuobj **blob,
-			      struct acr_v1_bl_desc *bl_desc, bool patch)
+acr_v1_prepare_hs_blob(struct nvkm_acr_v1 *acr, struct nvkm_secboot *sb,
+		       const char *fw, struct nvkm_gpuobj **blob,
+		       struct acr_v1_bl_desc *bl_desc, bool patch)
 {
 	const struct nvkm_subdev *subdev = acr->base.subdev;
 	void *acr_image;
@@ -909,7 +977,7 @@ acr_v1_prepare_hs_blob(struct nvkm_acr_v1 *acr, const char *fw,
 
 	acr_data = acr_image + hsbin_hdr->data_offset;
 
-	/* Patch descriptor? */
+	/* Patch descriptor with WPR information? */
 	if (patch) {
 		struct hsf_fw_header *fw_hdr;
 		struct hsf_load_header *load_hdr;
@@ -918,7 +986,7 @@ acr_v1_prepare_hs_blob(struct nvkm_acr_v1 *acr, const char *fw,
 		fw_hdr = acr_image + hsbin_hdr->header_offset;
 		load_hdr = acr_image + fw_hdr->hdr_offset;
 		desc = acr_data + load_hdr->data_dma_base;
-		acr->func->fixup_hs_desc(acr, desc);
+		acr_v1_fixup_hs_desc(acr, sb, desc);
 	}
 
 	/* Generate HS BL descriptor */
@@ -990,14 +1058,14 @@ acr_v1_load_blobs(struct nvkm_acr_v1 *acr, struct nvkm_secboot *sb)
 		return ret;
 
 	/* Load the HS firmware that will load the LS firmwares */
-	ret = acr_v1_prepare_hs_blob(acr, "acr/ucode_load", &acr->load_blob,
+	ret = acr_v1_prepare_hs_blob(acr, sb, "acr/ucode_load", &acr->load_blob,
 				     &acr->load_bl_desc, true);
 	if (ret)
 		return ret;
 
 	/* If the ACR region is dynamically programmed, we need an unload FW */
 	if (sb->wpr_size == 0) {
-		ret = acr_v1_prepare_hs_blob(acr, "acr/ucode_unload",
+		ret = acr_v1_prepare_hs_blob(acr, sb, "acr/ucode_unload",
 					     &acr->unload_blob,
 					     &acr->unload_bl_desc, false);
 		if (ret)
@@ -1084,29 +1152,6 @@ acr_v1_generate_bl_desc(const struct acr_v1_bl_desc *desc, void *ret)
 	memcpy(ret, desc, sizeof(*desc));
 }
 
-static void
-acr_v1_fixup_hs_desc(struct nvkm_acr_v1 *acr,
-			    struct hsflcn_acr_desc *desc)
-{
-	struct nvkm_gpuobj *ls_blob = acr->ls_blob;
-
-	desc->ucode_blob_base = acr->ls_blob->addr;
-	desc->ucode_blob_size = acr->ls_blob->size;
-
-	desc->wpr_offset = 0;
-
-	/*
-	 * WPR region information for the HS binary to set up, if WPR is not
-	 * fixed
-	 */
-	desc->wpr_region_id = 1;
-	desc->regions.no_regions = 1;
-	desc->regions.region_props[0].region_id = 1;
-	desc->regions.region_props[0].start_addr = ls_blob->addr >> 8;
-	desc->regions.region_props[0].end_addr =
-		(ls_blob->addr + ls_blob->size) >> 8;
-}
-
 /*
  * acr_v1_reset() - execute secure boot from the prepared state
  *
@@ -1218,7 +1263,6 @@ static const struct nvkm_acr_v1_func
 gm200_acr_v1_func = {
 	.bl_desc_size = sizeof(struct acr_v1_bl_desc),
 	.generate_bl_desc = acr_v1_generate_bl_desc,
-	.fixup_hs_desc = acr_v1_fixup_hs_desc,
 };
 
 static const struct nvkm_acr_func
drm/nouveau/nvkm/subdev/secboot/acr_v1.h +0 -45

61 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/acr_v1_gm20b.c +0 -11
index 4cfc175accdd..fcf644b9656c 100644
@@ -73,21 +73,10 @@ gm20b_acr_v1_generate_bl_desc(const struct acr_v1_bl_desc *desc, void *ret)
 	gdesc->data_size = desc->data_size;
 }
 
-static void
-gm20b_secboot_fixup_hs_desc(struct nvkm_acr_v1 *acr,
-			    struct hsflcn_acr_desc *desc)
-{
-	desc->ucode_blob_base = acr->ls_blob->addr;
-	desc->ucode_blob_size = acr->ls_blob->size;
-
-	desc->wpr_offset = 0;
-}
-
 static const struct nvkm_acr_v1_func
 gm20b_acr_v1_func = {
 	.bl_desc_size = sizeof(struct acr_v1_gm20b_bl_desc),
 	.generate_bl_desc = gm20b_acr_v1_generate_bl_desc,
-	.fixup_hs_desc = gm20b_secboot_fixup_hs_desc,
 };
 
 static const struct nvkm_acr_func
Signature · 6 lines
2.10.0

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

PATCH 7/8 secboot: add low-secure firmware hooks

In reply to a message not in the archive

Secure firmwares provided by NVIDIA will follow the same overall principle, but may slightly differ in format, or not use the same bootloader descriptor even on the same chip. In order to handle this as gracefully as possible, turn the LS firmware functions into hooks that can be overloaded as needed.

The current hooks cover the external firmware loading as well as the bootloader descriptor generation.

---
 drm/nouveau/nvkm/subdev/secboot/acr_v1.c       | 243 ++++---------------------
 drm/nouveau/nvkm/subdev/secboot/acr_v1.h       | 210 +++++++++++++++++++++
 drm/nouveau/nvkm/subdev/secboot/acr_v1_gm20b.c |  31 +++-
 3 files changed, 279 insertions(+), 205 deletions(-)
drm/nouveau/nvkm/subdev/secboot/acr_v1.c +39 -204
index db0fb3338398..68bb3113fd23 100644
@@ -70,175 +70,6 @@ struct fw_bl_desc {
 };
 
 
-/*
- *
- * LS blob structures
- *
- */
-
-/**
- * struct lsf_ucode_desc - LS falcon signatures
- * @prd_keys:		signature to use when the GPU is in production mode
- * @dgb_keys:		signature to use when the GPU is in debug mode
- * @b_prd_present:	whether the production key is present
- * @b_dgb_present:	whether the debug key is present
- * @falcon_id:		ID of the falcon the ucode applies to
- *
- * Directly loaded from a signature file.
- */
-struct lsf_ucode_desc {
-	u8  prd_keys[2][16];
-	u8  dbg_keys[2][16];
-	u32 b_prd_present;
-	u32 b_dbg_present;
-	u32 falcon_id;
-};
-
-/**
- * struct lsf_lsb_header - LS firmware header
- * @signature:		signature to verify the firmware against
- * @ucode_off:		offset of the ucode blob in the WPR region. The ucode
- *                      blob contains the bootloader, code and data of the
- *                      LS falcon
- * @ucode_size:		size of the ucode blob, including bootloader
- * @data_size:		size of the ucode blob data
- * @bl_code_size:	size of the bootloader code
- * @bl_imem_off:	offset in imem of the bootloader
- * @bl_data_off:	offset of the bootloader data in WPR region
- * @bl_data_size:	size of the bootloader data
- * @app_code_off:	offset of the app code relative to ucode_off
- * @app_code_size:	size of the app code
- * @app_data_off:	offset of the app data relative to ucode_off
- * @app_data_size:	size of the app data
- * @flags:		flags for the secure bootloader
- *
- * This structure is written into the WPR region for each managed falcon. Each
- * instance is referenced by the lsb_offset member of the corresponding
- * lsf_wpr_header.
- */
-struct lsf_lsb_header {
-	struct lsf_ucode_desc signature;
-	u32 ucode_off;
-	u32 ucode_size;
-	u32 data_size;
-	u32 bl_code_size;
-	u32 bl_imem_off;
-	u32 bl_data_off;
-	u32 bl_data_size;
-	u32 app_code_off;
-	u32 app_code_size;
-	u32 app_data_off;
-	u32 app_data_size;
-	u32 flags;
-#define LSF_FLAG_LOAD_CODE_AT_0		1
-#define LSF_FLAG_DMACTL_REQ_CTX		4
-#define LSF_FLAG_FORCE_PRIV_LOAD	8
-};
-
-/**
- * struct lsf_wpr_header - LS blob WPR Header
- * @falcon_id:		LS falcon ID
- * @lsb_offset:		offset of the lsb_lsf_header in the WPR region
- * @bootstrap_owner:	secure falcon reponsible for bootstrapping the LS falcon
- * @lazy_bootstrap:	skip bootstrapping by ACR
- * @status:		bootstrapping status
- *
- * An array of these is written at the beginning of the WPR region, one for
- * each managed falcon. The array is terminated by an instance which falcon_id
- * is LSF_FALCON_ID_INVALID.
- */
-struct lsf_wpr_header {
-	u32  falcon_id;
-	u32  lsb_offset;
-	u32  bootstrap_owner;
-	u32  lazy_bootstrap;
-	u32  status;
-#define LSF_IMAGE_STATUS_NONE				0
-#define LSF_IMAGE_STATUS_COPY				1
-#define LSF_IMAGE_STATUS_VALIDATION_CODE_FAILED		2
-#define LSF_IMAGE_STATUS_VALIDATION_DATA_FAILED		3
-#define LSF_IMAGE_STATUS_VALIDATION_DONE		4
-#define LSF_IMAGE_STATUS_VALIDATION_SKIPPED		5
-#define LSF_IMAGE_STATUS_BOOTSTRAP_READY		6
-};
-
-
-/**
- * struct ls_ucode_img_desc - descriptor of firmware image
- * @descriptor_size:		size of this descriptor
- * @image_size:			size of the whole image
- * @bootloader_start_offset:	start offset of the bootloader in ucode image
- * @bootloader_size:		size of the bootloader
- * @bootloader_imem_offset:	start off set of the bootloader in IMEM
- * @bootloader_entry_point:	entry point of the bootloader in IMEM
- * @app_start_offset:		start offset of the LS firmware
- * @app_size:			size of the LS firmware's code and data
- * @app_imem_offset:		offset of the app in IMEM
- * @app_imem_entry:		entry point of the app in IMEM
- * @app_dmem_offset:		offset of the data in DMEM
- * @app_resident_code_offset:	offset of app code from app_start_offset
- * @app_resident_code_size:	size of the code
- * @app_resident_data_offset:	offset of data from app_start_offset
- * @app_resident_data_size:	size of data
- *
- * A firmware image contains the code, data, and bootloader of a given LS
- * falcon in a single blob. This structure describes where everything is.
- *
- * This can be generated from a (bootloader, code, data) set if they have
- * been loaded separately, or come directly from a file.
- */
-struct ls_ucode_img_desc {
-	u32 descriptor_size;
-	u32 image_size;
-	u32 tools_version;
-	u32 app_version;
-	char date[64];
-	u32 bootloader_start_offset;
-	u32 bootloader_size;
-	u32 bootloader_imem_offset;
-	u32 bootloader_entry_point;
-	u32 app_start_offset;
-	u32 app_size;
-	u32 app_imem_offset;
-	u32 app_imem_entry;
-	u32 app_dmem_offset;
-	u32 app_resident_code_offset;
-	u32 app_resident_code_size;
-	u32 app_resident_data_offset;
-	u32 app_resident_data_size;
-	u32 nb_overlays;
-	struct {u32 start; u32 size; } load_ovl[64];
-	u32 compressed;
-};
-
-/**
- * struct ls_ucode_img - temporary storage for loaded LS firmwares
- * @node:		to link within lsf_ucode_mgr
- * @falcon_id:		ID of the falcon this LS firmware is for
- * @ucode_desc:		loaded or generated map of ucode_data
- * @ucode_header:	header of the firmware
- * @ucode_data:		firmware payload (code and data)
- * @ucode_size:		size in bytes of data in ucode_data
- * @wpr_header:		WPR header to be written to the LS blob
- * @lsb_header:		LSB header to be written to the LS blob
- *
- * Preparing the WPR LS blob requires information about all the LS firmwares
- * (size, etc) to be known. This structure contains all the data of one LS
- * firmware.
- */
-struct ls_ucode_img {
-	struct list_head node;
-	enum nvkm_falconidx falcon_id;
-
-	struct ls_ucode_img_desc ucode_desc;
-	u32 *ucode_header;
-	u8 *ucode_data;
-	u32 ucode_size;
-
-	struct lsf_wpr_header wpr_header;
-	struct lsf_lsb_header lsb_header;
-};
-
 /**
  * struct ls_ucode_mgr - manager for all LS falcon firmwares
  * @count:	number of managed LS falcons
@@ -340,12 +171,6 @@ struct hsflcn_acr_desc {
 	} vpr_desc;
 };
 
-
-static inline u64 flcn64_to_u64(const struct flcn_u64 f)
-{
-	return ((u64)f.hi) << 32 | f.lo;
-}
-
 /**
  * Convenience function to duplicate a firmware file in memory and check that
  * it has the required minimum size.
@@ -507,16 +332,14 @@ error:
 
 typedef int (*lsf_load_func)(const struct nvkm_subdev *, struct ls_ucode_img *);
 
-static int
-ls_ucode_img_load_fecs(const struct nvkm_subdev *subdev,
-		       struct ls_ucode_img *img)
+int
+acr_v1_ls_load_fecs(const struct nvkm_subdev *subdev, struct ls_ucode_img *img)
 {
 	return ls_ucode_img_load_generic(subdev, img, "fecs", NVKM_FALCON_FECS);
 }
 
-static int
-ls_ucode_img_load_gpccs(const struct nvkm_subdev *subdev,
-			struct ls_ucode_img *img)
+int
+acr_v1_ls_load_gpccs(const struct nvkm_subdev *subdev, struct ls_ucode_img *img)
 {
 	return ls_ucode_img_load_generic(subdev, img, "gpccs",
 					 NVKM_FALCON_GPCCS);
@@ -544,14 +367,8 @@ ls_ucode_img_load(const struct nvkm_subdev *subdev, lsf_load_func load_func)
 	return img;
 }
 
-static const lsf_load_func lsf_load_funcs[] = {
-	[NVKM_FALCON_END] = NULL, /* reserve enough space */
-	[NVKM_FALCON_FECS] = ls_ucode_img_load_fecs,
-	[NVKM_FALCON_GPCCS] = ls_ucode_img_load_gpccs,
-};
-
 /**
- * ls_ucode_img_populate_bl_desc() - populate a DMEM BL descriptor for LS image
+ * acr_v1_ls_generic_bl_desc() - populate a generic BL descriptor for LS image
  * @img:	ucode image to generate against
  * @desc:	descriptor to populate
  * @sb:		secure boot state to use for base addresses
@@ -561,10 +378,11 @@ static const lsf_load_func lsf_load_funcs[] = {
  *
  */
 static void
-ls_ucode_img_populate_bl_desc(struct ls_ucode_img *img, u64 wpr_addr,
-			      struct acr_v1_bl_desc *desc)
+acr_v1_ls_generic_bl_desc(const struct ls_ucode_img *img, u64 wpr_addr,
+			  void *_desc)
 {
-	struct ls_ucode_img_desc *pdesc = &img->ucode_desc;
+	struct acr_v1_bl_desc *desc = _desc;
+	const struct ls_ucode_img_desc *pdesc = &img->ucode_desc;
 	u64 addr_base;
 
 	addr_base = wpr_addr + img->lsb_header.ucode_off +
@@ -573,14 +391,14 @@ ls_ucode_img_populate_bl_desc(struct ls_ucode_img *img, u64 wpr_addr,
 	memset(desc, 0, sizeof(*desc));
 	desc->ctx_dma = FALCON_DMAIDX_UCODE;
 	desc->code_dma_base.lo = lower_32_bits(
-		(addr_base + pdesc->app_resident_code_offset));
+				 (addr_base + pdesc->app_resident_code_offset));
 	desc->code_dma_base.hi = upper_32_bits(
-		(addr_base + pdesc->app_resident_code_offset));
+				 (addr_base + pdesc->app_resident_code_offset));
 	desc->non_sec_code_size = pdesc->app_resident_code_size;
 	desc->data_dma_base.lo = lower_32_bits(
-		(addr_base + pdesc->app_resident_data_offset));
+				 (addr_base + pdesc->app_resident_data_offset));
 	desc->data_dma_base.hi = upper_32_bits(
-		(addr_base + pdesc->app_resident_data_offset));
+				 (addr_base + pdesc->app_resident_data_offset));
 	desc->data_size = pdesc->app_resident_data_size;
 	desc->code_entry_point = pdesc->app_imem_entry;
 }
@@ -609,6 +427,8 @@ ls_ucode_img_fill_headers(struct nvkm_acr_v1 *acr, struct ls_ucode_img *img,
 	struct lsf_wpr_header *whdr = &img->wpr_header;
 	struct lsf_lsb_header *lhdr = &img->lsb_header;
 	struct ls_ucode_img_desc *desc = &img->ucode_desc;
+	const struct nvkm_acr_v1_ls_single_func *func =
+						(*acr->ls_func)[img->falcon_id];
 
 	if (img->ucode_header) {
 		nvkm_fatal(acr->base.subdev,
@@ -669,9 +489,8 @@ ls_ucode_img_fill_headers(struct nvkm_acr_v1 *acr, struct ls_ucode_img *img,
 	if (img->falcon_id == NVKM_FALCON_GPCCS)
 		lhdr->flags |= LSF_FLAG_FORCE_PRIV_LOAD;
 
-	/* Align (size bloat) and save off BL descriptor size */
-	lhdr->bl_data_size = ALIGN(sizeof(struct acr_v1_bl_desc),
-				   LSF_BL_DATA_SIZE_ALIGN);
+	/* Align and save off BL descriptor size */
+	lhdr->bl_data_size = ALIGN(func->bl_desc_size, LSF_BL_DATA_SIZE_ALIGN);
 	/*
 	 * Align, save off, and include the additional BL data
 	 */
@@ -757,14 +576,14 @@ ls_ucode_mgr_write_wpr(struct nvkm_acr_v1 *acr, struct ls_ucode_mgr *mgr,
 
 		/* Generate and write BL descriptor */
 		if (!img->ucode_header) {
-			u8 desc[acr->func->bl_desc_size];
-			struct acr_v1_bl_desc gdesc;
+			const struct nvkm_acr_v1_ls_single_func *ls_func =
+				(*acr->ls_func)[img->falcon_id];
+			u8 gdesc[ls_func->bl_desc_size];
 
-			ls_ucode_img_populate_bl_desc(img, wpr_addr, &gdesc);
-			acr->func->generate_bl_desc(&gdesc, &desc);
+			ls_func->generate_bl_desc(img, wpr_addr, &gdesc);
 			nvkm_gpuobj_memcpy_to(wpr_blob,
 					      img->lsb_header.bl_data_off,
-					      &desc, acr->func->bl_desc_size);
+					      &gdesc, ls_func->bl_desc_size);
 		}
 
 		/* Copy ucode */
@@ -809,7 +628,8 @@ acr_v1_prepare_ls_blob(struct nvkm_acr_v1 *acr, u64 wpr_addr, u32 wpr_size)
 	for_each_set_bit(falcon_id, &managed_falcons, NVKM_FALCON_END) {
 		struct ls_ucode_img *img;
 
-		img = ls_ucode_img_load(subdev, lsf_load_funcs[falcon_id]);
+		img = ls_ucode_img_load(subdev,
+					(*acr->ls_func)[falcon_id]->load);
 		if (IS_ERR(img)) {
 			ret = PTR_ERR(img);
 			goto cleanup;
@@ -1265,6 +1085,20 @@ gm200_acr_v1_func = {
 	.generate_bl_desc = acr_v1_generate_bl_desc,
 };
 
+static const nvkm_acr_v1_ls_func
+acr_v1_ls_func = {
+	[NVKM_FALCON_FECS] = &(struct nvkm_acr_v1_ls_single_func) {
+		.load = acr_v1_ls_load_fecs,
+		.generate_bl_desc = acr_v1_ls_generic_bl_desc,
+		.bl_desc_size = sizeof(struct acr_v1_bl_desc),
+	},
+	[NVKM_FALCON_GPCCS] = &(struct nvkm_acr_v1_ls_single_func) {
+		.load = acr_v1_ls_load_gpccs,
+		.generate_bl_desc = acr_v1_ls_generic_bl_desc,
+		.bl_desc_size = sizeof(struct acr_v1_bl_desc),
+	},
+};
+
 static const struct nvkm_acr_func
 acr_v1_func = {
 	.managed_falcons = BIT(NVKM_FALCON_FECS) |
@@ -1288,6 +1122,7 @@ nvkm_acr_v1_new(void)
 
 	acr->base.func = &acr_v1_func;
 	acr->func = &gm200_acr_v1_func;
+	acr->ls_func = &acr_v1_ls_func;
 
 	return &acr->base;
 }
drm/nouveau/nvkm/subdev/secboot/acr_v1.h +210 -0

239 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/acr_v1_gm20b.c +30 -1
index fcf644b9656c..1062d4f6a1ff 100644
@@ -26,7 +26,7 @@
 
 /*
  * The BL header format used by GM20B's firmware is slightly different
- * from the one of GM200. Fix the differences here.
+ * from the one of GM200. Handle the differences here.
  */
 struct acr_v1_gm20b_bl_desc {
 	u32 reserved[4];
@@ -73,6 +73,25 @@ gm20b_acr_v1_generate_bl_desc(const struct acr_v1_bl_desc *desc, void *ret)
 	gdesc->data_size = desc->data_size;
 }
 
+static void
+acr_v1_gm20b_ls_generic_bl_desc(const struct ls_ucode_img *img, u64 wpr_addr,
+				void *_desc)
+{
+	struct acr_v1_gm20b_bl_desc *desc = _desc;
+	const struct ls_ucode_img_desc *pdesc = &img->ucode_desc;
+	u64 base;
+
+	base = wpr_addr + img->lsb_header.ucode_off + pdesc->app_start_offset;
+
+	memset(desc, 0, sizeof(*desc));
+	desc->ctx_dma = FALCON_DMAIDX_UCODE;
+	desc->code_dma_base = (base + pdesc->app_resident_code_offset) >> 8;
+	desc->non_sec_code_size = pdesc->app_resident_code_size;
+	desc->data_dma_base = (base + pdesc->app_resident_data_offset) >> 8;
+	desc->data_size = pdesc->app_resident_data_size;
+	desc->code_entry_point = pdesc->app_imem_entry;
+}
+
 static const struct nvkm_acr_v1_func
 gm20b_acr_v1_func = {
 	.bl_desc_size = sizeof(struct acr_v1_gm20b_bl_desc),
@@ -90,6 +109,15 @@ gm20b_acr_func = {
 	.start = acr_v1_start,
 };
 
+static const nvkm_acr_v1_ls_func
+gm20b_acr_v1_ls_func = {
+	[NVKM_FALCON_FECS] = &(struct nvkm_acr_v1_ls_single_func) {
+		.load = acr_v1_ls_load_fecs,
+		.generate_bl_desc = acr_v1_gm20b_ls_generic_bl_desc,
+		.bl_desc_size = sizeof(struct acr_v1_gm20b_bl_desc),
+	},
+};
+
 struct nvkm_acr *
 nvkm_acr_v1_gm20b_new(void)
 {
@@ -101,6 +129,7 @@ nvkm_acr_v1_gm20b_new(void)
 
 	acr->base.func = &gm20b_acr_func;
 	acr->func = &gm20b_acr_v1_func;
+	acr->ls_func = &gm20b_acr_v1_ls_func;
 
 	return &acr->base;
 }
Signature · 6 lines
2.10.0

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

PATCH 8/8 secboot: generate HS BL descriptor in hook

In reply to a message not in the archive

Use the HS hook to completely generate the HS BL descriptor, similarly to what is done in the LS hook, instead of (arbitrarily) using the the acr_v1 format as an intermediate.

This allows us to make the bootloader descriptor structures private to each implementation, resulting in a cleaner an more consistent design.

---
 drm/nouveau/nvkm/subdev/secboot/acr_v1.c       | 145 +++++++++++++------------
 drm/nouveau/nvkm/subdev/secboot/acr_v1.h       | 142 ++++++++++++------------
 drm/nouveau/nvkm/subdev/secboot/acr_v1_gm20b.c |  57 ++++------
 3 files changed, 165 insertions(+), 179 deletions(-)
drm/nouveau/nvkm/subdev/secboot/acr_v1.c +73 -72
index 68bb3113fd23..486327e5441a 100644
@@ -82,6 +82,42 @@ struct ls_ucode_mgr {
 	struct list_head img_list;
 };
 
+/**
+ * struct acr_v1_bl_desc - DMEM bootloader descriptor
+ * @signature:		16B signature for secure code. 0s if no secure code
+ * @ctx_dma:		DMA context to be used by BL while loading code/data
+ * @code_dma_base:	256B-aligned Physical FB Address where code is located
+ *			(falcon's $xcbase register)
+ * @non_sec_code_off:	offset from code_dma_base where the non-secure code is
+ *                      located. The offset must be multiple of 256 to help perf
+ * @non_sec_code_size:	the size of the nonSecure code part.
+ * @sec_code_off:	offset from code_dma_base where the secure code is
+ *                      located. The offset must be multiple of 256 to help perf
+ * @sec_code_size:	offset from code_dma_base where the secure code is
+ *                      located. The offset must be multiple of 256 to help perf
+ * @code_entry_point:	code entry point which will be invoked by BL after
+ *                      code is loaded.
+ * @data_dma_base:	256B aligned Physical FB Address where data is located.
+ *			(falcon's $xdbase register)
+ * @data_size:		size of data block. Should be multiple of 256B
+ *
+ * Structure used by the bootloader to load the rest of the code. This has
+ * to be filled by host and copied into DMEM at offset provided in the
+ * hsflcn_bl_desc.bl_desc_dmem_load_off.
+ */
+struct acr_v1_bl_desc {
+	u32 reserved[4];
+	u32 signature[4];
+	u32 ctx_dma;
+	struct flcn_u64 code_dma_base;
+	u32 non_sec_code_off;
+	u32 non_sec_code_size;
+	u32 sec_code_off;
+	u32 sec_code_size;
+	u32 code_entry_point;
+	struct flcn_u64 data_dma_base;
+	u32 data_size;
+};
 
 /*
  *
@@ -115,21 +151,6 @@ struct hsf_fw_header {
 };
 
 /**
- * struct hsf_load_header - HS firmware load header
- */
-struct hsf_load_header {
-	u32 non_sec_code_off;
-	u32 non_sec_code_size;
-	u32 data_dma_base;
-	u32 data_size;
-	u32 num_apps;
-	struct {
-		u32 sec_code_off;
-		u32 sec_code_size;
-	} app[0];
-};
-
-/**
  * struct hsflcn_acr_desc - data section of the HS firmware
  *
  * This header is to be copied at the beginning of DMEM by the HS bootloader.
@@ -714,32 +735,21 @@ acr_v1_hsf_patch_signature(struct nvkm_acr_v1 *acr, void *acr_image)
  * acr_v1_populate_hsf_bl_desc() - populate BL descriptor for HS image
  */
 static void
-acr_v1_populate_hsf_bl_desc(void *acr_image, struct acr_v1_bl_desc *bl_desc)
+acr_v1_generate_hsf_bl_desc(const struct hsf_load_header *hdr, void *_bl_desc,
+			    u64 offset)
 {
-	struct fw_bin_header *hsbin_hdr = acr_image;
-	struct hsf_fw_header *fw_hdr = acr_image + hsbin_hdr->header_offset;
-	struct hsf_load_header *load_hdr = acr_image + fw_hdr->hdr_offset;
+	struct acr_v1_bl_desc *bl_desc = _bl_desc;
 
-	/*
-	 * Descriptor for the bootloader that will load the ACR image into
-	 * IMEM/DMEM memory.
-	 */
-	fw_hdr = acr_image + hsbin_hdr->header_offset;
-	load_hdr = acr_image + fw_hdr->hdr_offset;
 	memset(bl_desc, 0, sizeof(*bl_desc));
 	bl_desc->ctx_dma = FALCON_DMAIDX_VIRT;
-	bl_desc->non_sec_code_off = load_hdr->non_sec_code_off;
-	bl_desc->non_sec_code_size = load_hdr->non_sec_code_size;
-	bl_desc->sec_code_off = load_hdr->app[0].sec_code_off;
-	bl_desc->sec_code_size = load_hdr->app[0].sec_code_size;
+	bl_desc->non_sec_code_off = hdr->non_sec_code_off;
+	bl_desc->non_sec_code_size = hdr->non_sec_code_size;
+	bl_desc->sec_code_off = hdr->app[0].sec_code_off;
+	bl_desc->sec_code_size = hdr->app[0].sec_code_size;
 	bl_desc->code_entry_point = 0;
-	/*
-	 * We need to set code_dma_base to the virtual address of the acr_blob,
-	 * and add this address to data_dma_base before writing it into DMEM
-	 */
-	bl_desc->code_dma_base.lo = 0;
-	bl_desc->data_dma_base.lo = load_hdr->data_dma_base;
-	bl_desc->data_size = load_hdr->data_size;
+	bl_desc->code_dma_base = u64_to_flcn64(offset);
+	bl_desc->data_dma_base = u64_to_flcn64(offset + hdr->data_dma_base);
+	bl_desc->data_size = hdr->data_size;
 }
 
 static void
@@ -779,38 +789,44 @@ acr_v1_fixup_hs_desc(struct nvkm_acr_v1 *acr, struct nvkm_secboot *sb,
 static int
 acr_v1_prepare_hs_blob(struct nvkm_acr_v1 *acr, struct nvkm_secboot *sb,
 		       const char *fw, struct nvkm_gpuobj **blob,
-		       struct acr_v1_bl_desc *bl_desc, bool patch)
+		       struct hsf_load_header *load_header, bool patch)
 {
 	const struct nvkm_subdev *subdev = acr->base.subdev;
 	void *acr_image;
 	struct fw_bin_header *hsbin_hdr;
+	struct hsf_fw_header *fw_hdr;
+	struct hsf_load_header *load_hdr;
 	void *acr_data;
 	int ret;
 
 	acr_image = acr_v1_load_firmware(subdev, fw, 0);
 	if (IS_ERR(acr_image))
 		return PTR_ERR(acr_image);
+
 	hsbin_hdr = acr_image;
+	fw_hdr = acr_image + hsbin_hdr->header_offset;
+	load_hdr = acr_image + fw_hdr->hdr_offset;
+	acr_data = acr_image + hsbin_hdr->data_offset;
 
 	/* Patch signature */
 	acr_v1_hsf_patch_signature(acr, acr_image);
 
-	acr_data = acr_image + hsbin_hdr->data_offset;
-
 	/* Patch descriptor with WPR information? */
 	if (patch) {
-		struct hsf_fw_header *fw_hdr;
-		struct hsf_load_header *load_hdr;
 		struct hsflcn_acr_desc *desc;
 
-		fw_hdr = acr_image + hsbin_hdr->header_offset;
-		load_hdr = acr_image + fw_hdr->hdr_offset;
 		desc = acr_data + load_hdr->data_dma_base;
 		acr_v1_fixup_hs_desc(acr, sb, desc);
 	}
 
-	/* Generate HS BL descriptor */
-	acr_v1_populate_hsf_bl_desc(acr_image, bl_desc);
+	if (load_hdr->num_apps > ACR_V1_MAX_APPS) {
+		nvkm_error(subdev, "more apps (%d) than supported (%d)!",
+			   load_hdr->num_apps, ACR_V1_MAX_APPS);
+		ret = -EINVAL;
+		goto cleanup;
+	}
+	memcpy(load_header, load_hdr, sizeof(*load_header) +
+			       (sizeof(load_hdr->app[0]) * load_hdr->num_apps));
 
 	/* Create ACR blob and copy HS data to it */
 	ret = nvkm_gpuobj_new(subdev->device, ALIGN(hsbin_hdr->data_size, 256),
@@ -879,7 +895,7 @@ acr_v1_load_blobs(struct nvkm_acr_v1 *acr, struct nvkm_secboot *sb)
 
 	/* Load the HS firmware that will load the LS firmwares */
 	ret = acr_v1_prepare_hs_blob(acr, sb, "acr/ucode_load", &acr->load_blob,
-				     &acr->load_bl_desc, true);
+				     &acr->load_bl_header, true);
 	if (ret)
 		return ret;
 
@@ -887,7 +903,7 @@ acr_v1_load_blobs(struct nvkm_acr_v1 *acr, struct nvkm_secboot *sb)
 	if (sb->wpr_size == 0) {
 		ret = acr_v1_prepare_hs_blob(acr, sb, "acr/ucode_unload",
 					     &acr->unload_blob,
-					     &acr->unload_bl_desc, false);
+					     &acr->unload_bl_header, false);
 		if (ret)
 			return ret;
 	}
@@ -918,30 +934,21 @@ acr_v1_load(struct nvkm_acr *_acr, struct nvkm_secboot *sb,
 	void *hsbl_data = blob_data + hsbl_desc->data_off;
 	u32 code_size = ALIGN(hsbl_desc->code_size, 256);
 	const u32 base = sb->base;
-	const u32 bl_desc_size = acr->func->bl_desc_size;
-	struct acr_v1_bl_desc desc;
+	const u32 bl_desc_size = acr->hs_func->bl_desc_size;
+	const struct hsf_load_header *load_hdr;
 	u8 bl_desc[bl_desc_size];
-	u64 vma_addr;
 	u32 code_start;
 
 	/* Find the bootloader descriptor for our blob and copy it */
 	if (blob == acr->load_blob) {
-		desc = acr->load_bl_desc;
+		load_hdr = &acr->load_bl_header;
 	} else if (blob == acr->unload_blob) {
-		desc = acr->unload_bl_desc;
+		load_hdr = &acr->unload_bl_header;
 	} else {
 		nvkm_error(_acr->subdev, "invalid secure boot blob!\n");
 		return -EINVAL;
 	}
 
-	/* Patch the descriptor's load addresses */
-	vma_addr = flcn64_to_u64(desc.code_dma_base) + offset;
-	desc.code_dma_base.lo = lower_32_bits(vma_addr);
-	desc.code_dma_base.hi = upper_32_bits(vma_addr);
-	vma_addr = flcn64_to_u64(desc.data_dma_base) + offset;
-	desc.data_dma_base.lo = lower_32_bits(vma_addr);
-	desc.data_dma_base.hi = upper_32_bits(vma_addr);
-
 	/*
 	 * Copy HS bootloader data
 	 */
@@ -954,8 +961,8 @@ acr_v1_load(struct nvkm_acr *_acr, struct nvkm_secboot *sb,
 	nvkm_falcon_load_imem(device, sb->base, hsbl_code, code_start,
 			      code_size, hsbl_desc->start_tag);
 
-	/* Fixup the BL header */
-	acr->func->generate_bl_desc(&desc, &bl_desc);
+	/* Generate the BL header */
+	acr->hs_func->generate_bl_desc(load_hdr, bl_desc, offset);
 
 	/*
 	 * Copy HS BL header where the HS descriptor expects it to be
@@ -966,12 +973,6 @@ acr_v1_load(struct nvkm_acr *_acr, struct nvkm_secboot *sb,
 	return 0;
 }
 
-static void
-acr_v1_generate_bl_desc(const struct acr_v1_bl_desc *desc, void *ret)
-{
-	memcpy(ret, desc, sizeof(*desc));
-}
-
 /*
  * acr_v1_reset() - execute secure boot from the prepared state
  *
@@ -1079,10 +1080,10 @@ acr_v1_dtor(struct nvkm_acr *_acr)
 	kfree(acr);
 }
 
-static const struct nvkm_acr_v1_func
-gm200_acr_v1_func = {
+static const struct nvkm_acr_v1_hs_func
+gm200_acr_v1_hs_func = {
+	.generate_bl_desc = acr_v1_generate_hsf_bl_desc,
 	.bl_desc_size = sizeof(struct acr_v1_bl_desc),
-	.generate_bl_desc = acr_v1_generate_bl_desc,
 };
 
 static const nvkm_acr_v1_ls_func
@@ -1121,7 +1122,7 @@ nvkm_acr_v1_new(void)
 		return ERR_PTR(-ENOMEM);
 
 	acr->base.func = &acr_v1_func;
-	acr->func = &gm200_acr_v1_func;
+	acr->hs_func = &gm200_acr_v1_hs_func;
 	acr->ls_func = &acr_v1_ls_func;
 
 	return &acr->base;
drm/nouveau/nvkm/subdev/secboot/acr_v1.h +70 -72

193 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/acr_v1_gm20b.c +22 -35

76 lines not on this page · raw message

Signature · 6 lines
2.10.0

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

Is it just me or is the 5th patch lost?

Am Dienstag, 11. Oktober 2016 schrieb Alexandre Courbot :

Quoted 83 lines

Hi everyone,

Apologies for the big patchset. This is a rework of the secure boot code that
moves the building of the blob into its own set of source files (and own hooks),
making the code more flexible and (hopefully) easier to understand as well.

This rework is needed to support more signed firmware for existing and new chips. Since the firmwares in question are not available yet I cannot send the
code for them yet, but hopefully the gain in clarity will be enough to merge
this series ahead of the rest.

Patch 1 is just to make nv*_printk() more tolerent of my use of const pointers.
Patch 2 lays the foundation of a small common falcon library that could avoid
duplicated code in various parts of the driver. Right now only secure boot makes
use of it (patch 3), but there are many potential users (GR, PMU, etc). I will
test users and send further patches making use of it.

Patch 4 renames a hook to something better describing its actual use.

Patch 5 is where the big refactoring occurs. It looks scary, but is really just
moving code (and introducing the nvkm_acr structures).

Patch 6, 7 and 8 remove a few HS hooks that turn out to be unneeded, and add
support for LS hooks.

The end result can be observed by looking at acr_v1_gm20b.c: all the specifics
of GM20B's firmware are handled in a single file, with no data structures shared
with acr_v1.c. The gm20b_acr_v1_ls_func variable also describes clearly what
LS firmwares are to be loaded and how.

Alexandre Courbot (8):
core: constify nv*_printk macros
core: add falcon library
secboot: use falcon library's IMEM/DMEM loading functions
secboot: rename init() hook to oneinit()
secboot: move ACR building logic into own source files
secboot: remove fixup_hs_desc hook
secboot: add low-secure firmware hooks
secboot: generate HS BL descriptor in hook

 drm/nouveau/include/nvkm/core/client.h         |    4 +-
 drm/nouveau/include/nvkm/core/device.h         |    2 +-
 drm/nouveau/include/nvkm/core/falcon.h         |   50 +
 drm/nouveau/include/nvkm/core/subdev.h         |    2 +-
 drm/nouveau/include/nvkm/subdev/secboot.h      |   33 +-
 drm/nouveau/nvkm/core/Kbuild                   |    1 +
 drm/nouveau/nvkm/core/falcon.c                 |   62 ++
 drm/nouveau/nvkm/engine/gr/gf100.c             |   16 +-
 drm/nouveau/nvkm/engine/gr/gm200.c             |    6 +-
 drm/nouveau/nvkm/subdev/secboot/Kbuild         |    2 +
 drm/nouveau/nvkm/subdev/secboot/acr.h          |   67 ++
 drm/nouveau/nvkm/subdev/secboot/acr_v1.c       | 1193
++++++++++++++++++++
 drm/nouveau/nvkm/subdev/secboot/acr_v1.h       |  346 ++++++
 drm/nouveau/nvkm/subdev/secboot/acr_v1_gm20b.c |  135 +++
 drm/nouveau/nvkm/subdev/secboot/base.c         |  113 +-
 drm/nouveau/nvkm/subdev/secboot/gm200.c        | 1386
+-----------------------
 drm/nouveau/nvkm/subdev/secboot/gm200.h        |   43 +
 drm/nouveau/nvkm/subdev/secboot/gm20b.c        |  141 +--
 drm/nouveau/nvkm/subdev/secboot/priv.h         |  208 +---
 19 files changed, 2072 insertions(+), 1738 deletions(-)
 create mode 100644 drm/nouveau/include/nvkm/core/falcon.h
 create mode 100644 drm/nouveau/nvkm/core/falcon.c
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/acr.h
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/acr_v1.c
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/acr_v1.h
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/acr_v1_gm20b.c
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/gm200.h
Quoted 8 lines

--
2.10.0

_______________________________________________
Nouveau mailing list [email protected] <javascript:;>
https://lists.freedesktop.org/mailman/listinfo/nouveau

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

A message that is not in the archive (sent off-list or not yet received): CAEXux-bmd-wKceqgZTP0P=Vj2uva1MqJ=xhPEPrh_BswAOtH5g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

A message that is not in the archive (sent off-list or not yet received): 0f006b0c-e46d-cac4-d3e2-124bd36e9b15-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org