Skip to contentSkip to conversation

nouveau: add secure boot support for dGPU and Tegra

PATCH Superseded Alexandre Courbot 4 participants 11 messages Jan 18, 2016 – Jan 25, 2016 6 messages not in the archive Tegra architecture support

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover nouveau: add secure boot support for dGPU and Tegra

This is a highly changed revision of the first patch series that adds secure boot support to Nouveau. This code still depends on NVIDIA releasing official firmware files, but the files released with SHIELD TV and Pixel C can already be used on a Jetson TX1.

As you know we are working hard to release the official firmware files, however in the meantime it doesn't hurt to review the code so it can be merged soon after the release! :)

This series depends on the previously-sent "Unified firmware loading functions" series.

Changes since v1:
- Moved secure boot into a subdev ("secboot") to integrate better with Nouveau
- Switched to more a flexible abstraction (clients can ask to reset a given set of falcons, and the secboot subdev decides how to do this).
- Added dGPU support. Nouveau can now initialize securely-managed falcons on all GM20X chips, provided adequate firmware is present, and GR can run on all GM20X as well.
- Plenty of small changes that hopefully make the code easier to read...

Notes:
- The GM20B secboot driver is currently tailored to work with the firmware files released with NVIDIA's SHIELD TV and Google's Pixel C. These files use a slightly different format than dGPU. Final official GM20B firmware may be aligned to the format used by dGPU, reducing the size of the GM20B driver.
- The current implementation monopolizes the PMU for doing secure boot. This will be fixed once the PMU secure firmware is released as well. It may or may not happen at the same time as the signed GR firmware, hence this currently limited implementation to allow GR to be used. The current abstraction for reseting securely-managed falcons should be suitable for both models.

Alexandre Courbot (5):
core: add gpuobj memcpy helper functions
core: add support for secure boot
gr: support for securely-booted FECS firmware
secboot/gm200: add secure-boot support
secboot/gm20b: add secure boot support

 drm/nouveau/include/nvkm/core/device.h    |    3 +
 drm/nouveau/include/nvkm/core/gpuobj.h    |    4 +
 drm/nouveau/include/nvkm/subdev/secboot.h |   59 ++
 drm/nouveau/nvkm/core/gpuobj.c            |   20 +
 drm/nouveau/nvkm/core/subdev.c            |    1 +
 drm/nouveau/nvkm/engine/device/base.c     |    5 +
 drm/nouveau/nvkm/engine/device/priv.h     |    1 +
 drm/nouveau/nvkm/engine/gr/gf100.c        |   46 +-
 drm/nouveau/nvkm/engine/gr/gm204.c        |    8 +-
 drm/nouveau/nvkm/engine/gr/gm20b.c        |    9 +-
 drm/nouveau/nvkm/subdev/Kbuild            |    1 +
 drm/nouveau/nvkm/subdev/secboot/Kbuild    |    3 +
 drm/nouveau/nvkm/subdev/secboot/base.c    |  284 +++++++
 drm/nouveau/nvkm/subdev/secboot/gm200.c   | 1308 +++++++++++++++++++++++++++++
 drm/nouveau/nvkm/subdev/secboot/gm20b.c   |  213 +++++
 drm/nouveau/nvkm/subdev/secboot/priv.h    |  187 +++++
 16 files changed, 2134 insertions(+), 18 deletions(-)
 create mode 100644 drm/nouveau/include/nvkm/subdev/secboot.h
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/Kbuild
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/base.c
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/gm200.c
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/gm20b.c
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/priv.h
Signature · 6 lines
2.7.0

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

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

#2 lore raw

PATCH v2 1/5 core: add gpuobj memcpy helper functions

Add memcpy functions that allow copying a buffer to a gpuobj and vice-versa.

---
 drm/nouveau/include/nvkm/core/gpuobj.h |  4 ++++
 drm/nouveau/nvkm/core/gpuobj.c         | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)
drm/nouveau/include/nvkm/core/gpuobj.h +4 -0
index d4f56eafb073..c23da4f05929 100644
@@ -37,4 +37,8 @@ int nvkm_gpuobj_wrap(struct nvkm_memory *, struct nvkm_gpuobj **);
 int nvkm_gpuobj_map(struct nvkm_gpuobj *, struct nvkm_vm *, u32 access,
 		    struct nvkm_vma *);
 void nvkm_gpuobj_unmap(struct nvkm_vma *);
+void nvkm_gpuobj_memcpy_to(struct nvkm_gpuobj *dst, u32 dstoffset, void *src,
+			   u32 length);
+void nvkm_gpuobj_memcpy_from(void *dst, struct nvkm_gpuobj *src, u32 srcoffset,
+			     u32 length);
 #endif
drm/nouveau/nvkm/core/gpuobj.c +20 -0
index c3a790eb8d6a..a7bd22706b2a 100644
@@ -253,3 +253,23 @@ nvkm_gpuobj_wrap(struct nvkm_memory *memory, struct nvkm_gpuobj **pgpuobj)
 	(*pgpuobj)->size = nvkm_memory_size(memory);
 	return 0;
 }
+
+void
+nvkm_gpuobj_memcpy_to(struct nvkm_gpuobj *dst, u32 dstoffset, void *src,
+		      u32 length)
+{
+	int i;
+
+	for (i = 0; i < length; i += 4)
+		nvkm_wo32(dst, dstoffset + i, *(u32 *)(src + i));
+}
+
+void
+nvkm_gpuobj_memcpy_from(void *dst, struct nvkm_gpuobj *src, u32 srcoffset,
+			u32 length)
+{
+	int i;
+
+	for (i = 0; i < length; i += 4)
+		((u32 *)src)[i / 4] = nvkm_ro32(src, srcoffset + i);
+}
Signature · 6 lines
2.7.0

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

PATCH v2 2/5 core: add support for secure boot

In reply to a message not in the archive

On GM20x and later GPUs, firmware for some essential falcons (notably FECS) must be authenticated by a NVIDIA-produced signature and loaded by a high-secure falcon in order to access certain registers, in a process known as Secure Boot.

Secure Boot requires the building of a binary blob containing the firmwares and signatures of the falcons to be loaded. This blob is then given to a high-secure falcon running a signed loader firmware that copies the blob into a write-protected region, checks that the signatures are valid, and finally loads the verified firmware into the managed falcons and switches them to a priviledged mode.

This patch adds infrastructure code to support this process on chips that require it.

---
 drm/nouveau/include/nvkm/core/device.h    |   3 +
 drm/nouveau/include/nvkm/subdev/secboot.h |  56 ++++++
 drm/nouveau/nvkm/core/subdev.c            |   1 +
 drm/nouveau/nvkm/engine/device/base.c     |   2 +
 drm/nouveau/nvkm/engine/device/priv.h     |   1 +
 drm/nouveau/nvkm/subdev/Kbuild            |   1 +
 drm/nouveau/nvkm/subdev/secboot/Kbuild    |   1 +
 drm/nouveau/nvkm/subdev/secboot/base.c    | 284 ++++++++++++++++++++++++++++++
 drm/nouveau/nvkm/subdev/secboot/priv.h    |  46 +++++
 9 files changed, 395 insertions(+)
 create mode 100644 drm/nouveau/include/nvkm/subdev/secboot.h
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/Kbuild
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/base.c
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/priv.h
drm/nouveau/include/nvkm/core/device.h +3 -0
index 913192c94876..d154a75e93a9 100644
@@ -24,6 +24,7 @@ enum nvkm_devidx {
 	NVKM_SUBDEV_VOLT,
 	NVKM_SUBDEV_THERM,
 	NVKM_SUBDEV_CLK,
+	NVKM_SUBDEV_SECBOOT,
 
 	NVKM_ENGINE_DMAOBJ,
 	NVKM_ENGINE_IFB,
@@ -119,6 +120,7 @@ struct nvkm_device {
 	struct nvkm_therm *therm;
 	struct nvkm_timer *timer;
 	struct nvkm_volt *volt;
+	struct nvkm_secboot *secboot;
 
 	struct nvkm_engine *bsp;
 	struct nvkm_engine *ce[3];
@@ -184,6 +186,7 @@ struct nvkm_device_chip {
 	int (*therm  )(struct nvkm_device *, int idx, struct nvkm_therm **);
 	int (*timer  )(struct nvkm_device *, int idx, struct nvkm_timer **);
 	int (*volt   )(struct nvkm_device *, int idx, struct nvkm_volt **);
+	int (*secboot)(struct nvkm_device *, int idx, struct nvkm_secboot **);
 
 	int (*bsp    )(struct nvkm_device *, int idx, struct nvkm_engine **);
 	int (*ce[3]  )(struct nvkm_device *, int idx, struct nvkm_engine **);
drm/nouveau/include/nvkm/subdev/secboot.h new file +56 -0

56 lines not on this page · raw message

drm/nouveau/nvkm/core/subdev.c +1 -0
index 7de98470a2a0..d8b3d2a362ad 100644
@@ -49,6 +49,7 @@ nvkm_subdev_name[NVKM_SUBDEV_NR] = {
 	[NVKM_SUBDEV_THERM  ] = "therm",
 	[NVKM_SUBDEV_TIMER  ] = "tmr",
 	[NVKM_SUBDEV_VOLT   ] = "volt",
+	[NVKM_SUBDEV_SECBOOT] = "secboot",
 	[NVKM_ENGINE_BSP    ] = "bsp",
 	[NVKM_ENGINE_CE0    ] = "ce0",
 	[NVKM_ENGINE_CE1    ] = "ce1",
drm/nouveau/nvkm/engine/device/base.c +2 -0
index b1ba1c782a2b..95fc9a69d322 100644
@@ -2092,6 +2092,7 @@ nvkm_device_subdev(struct nvkm_device *device, int index)
 	_(THERM  , device->therm  , &device->therm->subdev);
 	_(TIMER  , device->timer  , &device->timer->subdev);
 	_(VOLT   , device->volt   , &device->volt->subdev);
+	_(SECBOOT, device->secboot, &device->secboot->subdev);
 #undef _
 	default:
 		engine = nvkm_device_engine(device, index);
@@ -2538,6 +2539,7 @@ nvkm_device_ctor(const struct nvkm_device_func *func,
 		_(NVKM_SUBDEV_THERM  ,   therm);
 		_(NVKM_SUBDEV_TIMER  ,   timer);
 		_(NVKM_SUBDEV_VOLT   ,    volt);
+		_(NVKM_SUBDEV_SECBOOT, secboot);
 		_(NVKM_ENGINE_BSP    ,     bsp);
 		_(NVKM_ENGINE_CE0    ,   ce[0]);
 		_(NVKM_ENGINE_CE1    ,   ce[1]);
drm/nouveau/nvkm/engine/device/priv.h +1 -0
index ed3ad2c30e17..03fe0afbf6bf 100644
@@ -22,6 +22,7 @@
 #include <subdev/therm.h>
 #include <subdev/timer.h>
 #include <subdev/volt.h>
+#include <subdev/secboot.h>
 
 #include <engine/bsp.h>
 #include <engine/ce.h>
drm/nouveau/nvkm/subdev/Kbuild +1 -0
index ee2c38f50ef5..ec8c5eb30653 100644
@@ -15,6 +15,7 @@ include $(src)/nvkm/subdev/mmu/Kbuild
 include $(src)/nvkm/subdev/mxm/Kbuild
 include $(src)/nvkm/subdev/pci/Kbuild
 include $(src)/nvkm/subdev/pmu/Kbuild
+include $(src)/nvkm/subdev/secboot/Kbuild
 include $(src)/nvkm/subdev/therm/Kbuild
 include $(src)/nvkm/subdev/timer/Kbuild
 include $(src)/nvkm/subdev/volt/Kbuild
drm/nouveau/nvkm/subdev/secboot/Kbuild new file +1 -0
new file mode 100644
index 000000000000..e757096b2ff0
@@ -0,0 +1 @@
+nvkm-y += nvkm/subdev/secboot/base.o
drm/nouveau/nvkm/subdev/secboot/base.c new file +284 -0

284 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/priv.h new file +46 -0

46 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

A message that is not in the archive (sent off-list or not yet received): 1453097447-12152-3-git-send-email-acourbot-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org

#5 lore raw

Re: [Nouveau] [PATCH v2 2/5] core: add support for secure boot

Hi Alexandre,

On 18 January 2016 at 06:10, Alexandre Courbot <[email protected]> wrote:

[snip]

drm/nouveau/nvkm/subdev/secboot/base.c line 29

Quoted 4 lines
drm/nouveau/nvkm/subdev/secboot/base.c new file +4 -0
+static const char *
+managed_falcons_names[] = {
+       [NVKM_SECBOOT_FALCON_PMU] = "PMU",
+       [NVKM_SECBOOT_FALCON_RESERVED] = "<invalid>",

"<reserved>" perhaps ? we already have one invalid below.

Quoted 5 lines
drm/nouveau/nvkm/subdev/secboot/base.c new file +5 -0
+       [NVKM_SECBOOT_FALCON_FECS] = "FECS",
+       [NVKM_SECBOOT_FALCON_GPCCS] = "GPCCS",
+       [NVKM_SECBOOT_FALCON_END] = "<invalid>",
+};
+

[snip]

drm/nouveau/nvkm/subdev/secboot/base.c line 265

Quoted 10 lines
drm/nouveau/nvkm/subdev/secboot/base.c new file +10 -0
+int
+nvkm_secboot_ctor(const struct nvkm_secboot_func *func,
+                 struct nvkm_device *device, int index,
+                 struct nvkm_secboot *sb)
+{
+       unsigned long fid;
+
+       nvkm_subdev_ctor(&nvkm_secboot, device, index, 0, &sb->subdev);
+       sb->func = func;
+

Move these two after the switch statement ?

Quoted 9 lines
drm/nouveau/nvkm/subdev/secboot/base.c new file +9 -0
+       /* setup the performing falcon's base address and masks */
+       switch (func->boot_falcon) {
+       case NVKM_SECBOOT_FALCON_PMU:
+               sb->base = 0x10a000;
+               sb->irq_mask = 0x1000000;
+               sb->enable_mask = 0x2000;
+               break;
+       default:
+               nvdev_error(device, "invalid secure boot falcon\n");

drm/nouveau/nvkm/subdev/secboot/base.c line 284

Quoted 10 lines
drm/nouveau/nvkm/subdev/secboot/base.c new file +10 -0
+               return -EINVAL;
+       };
+
+       nvkm_info(&sb->subdev, "securely managed falcons:\n");
+       for_each_set_bit(fid, &sb->func->managed_falcons,
+                        NVKM_SECBOOT_FALCON_END)
+               nvkm_info(&sb->subdev, "- %s\n", managed_falcons_names[fid]);
+
+       return 0;
+}

Cheers,
Emil

A message that is not in the archive (sent off-list or not yet received): CACvgo50P8JQ5EkCEMmnGQGO4jMsc0O4cRB1QO04V0KQS7Y8AYA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#7 lore raw

Re: [Nouveau] [PATCH v2 2/5] core: add support for secure boot

Quoted 10 lines · Emil Velikov

Hi Alexandre,

On 18 January 2016 at 06:10, Alexandre Courbot <[email protected]> wrote:

[snip]

drm/nouveau/nvkm/subdev/secboot/base.c line 29

Quoted 4 lines
drm/nouveau/nvkm/subdev/secboot/base.c new file +4 -0
+static const char *
+managed_falcons_names[] = {
+       [NVKM_SECBOOT_FALCON_PMU] = "PMU",
+       [NVKM_SECBOOT_FALCON_RESERVED] = "<invalid>",

"<reserved>" perhaps ? we already have one invalid below.

Does <reserved> really mean: "we don't want to tell you?" here? :)

Quoted 8 lines
Quoted 6 lines
drm/nouveau/nvkm/subdev/secboot/base.c new file +5 -0
+       [NVKM_SECBOOT_FALCON_FECS] = "FECS",
+       [NVKM_SECBOOT_FALCON_GPCCS] = "GPCCS",
+       [NVKM_SECBOOT_FALCON_END] = "<invalid>",
+};
+

[snip]

Quoted 11 lines

drm/nouveau/nvkm/subdev/secboot/base.c line 265

Quoted 10 lines
drm/nouveau/nvkm/subdev/secboot/base.c new file +10 -0
+int
+nvkm_secboot_ctor(const struct nvkm_secboot_func *func,
+                 struct nvkm_device *device, int index,
+                 struct nvkm_secboot *sb)
+{
+       unsigned long fid;
+
+       nvkm_subdev_ctor(&nvkm_secboot, device, index, 0, &sb->subdev);
+       sb->func = func;
+

Move these two after the switch statement ?

They need to be done here to make the failure path cleanup stuff work correctly, so it's correct as-is.

Quoted 24 lines
Quoted 10 lines
drm/nouveau/nvkm/subdev/secboot/base.c new file +9 -0
+       /* setup the performing falcon's base address and masks */
+       switch (func->boot_falcon) {
+       case NVKM_SECBOOT_FALCON_PMU:
+               sb->base = 0x10a000;
+               sb->irq_mask = 0x1000000;
+               sb->enable_mask = 0x2000;
+               break;
+       default:
+               nvdev_error(device, "invalid secure boot falcon\n");

drm/nouveau/nvkm/subdev/secboot/base.c line 284

Quoted 10 lines
drm/nouveau/nvkm/subdev/secboot/base.c new file +10 -0
+               return -EINVAL;
+       };
+
+       nvkm_info(&sb->subdev, "securely managed falcons:\n");
+       for_each_set_bit(fid, &sb->func->managed_falcons,
+                        NVKM_SECBOOT_FALCON_END)
+               nvkm_info(&sb->subdev, "- %s\n", managed_falcons_names[fid]);
+
+       return 0;
+}

Cheers,
Emil

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

Re: [PATCH v2 2/5] core: add support for secure boot

Quoted 5 lines · Ben Skeggs
Quoted 4 lines · Emil Velikov

Hi Alexandre,

On 18 January 2016 at 06:10, Alexandre Courbot <[email protected]> wrote:

Quoted 8 lines
Quoted 6 lines

[snip]

drm/nouveau/nvkm/subdev/secboot/base.c line 29

Quoted 4 lines
drm/nouveau/nvkm/subdev/secboot/base.c new file +4 -0
+static const char *
+managed_falcons_names[] = {
+       [NVKM_SECBOOT_FALCON_PMU] = "PMU",
+       [NVKM_SECBOOT_FALCON_RESERVED] = "<invalid>",

"<reserved>" perhaps ? we already have one invalid below.

Does <reserved> really mean: "we don't want to tell you?" here? :)

That or we have some secret WIP that we're haven't decided if it'll work out :-)

Quoted 19 lines
Quoted 8 lines
Quoted 6 lines
drm/nouveau/nvkm/subdev/secboot/base.c new file +5 -0
+       [NVKM_SECBOOT_FALCON_FECS] = "FECS",
+       [NVKM_SECBOOT_FALCON_GPCCS] = "GPCCS",
+       [NVKM_SECBOOT_FALCON_END] = "<invalid>",
+};
+

[snip]

Quoted 11 lines

drm/nouveau/nvkm/subdev/secboot/base.c line 265

Quoted 10 lines
drm/nouveau/nvkm/subdev/secboot/base.c new file +10 -0
+int
+nvkm_secboot_ctor(const struct nvkm_secboot_func *func,
+                 struct nvkm_device *device, int index,
+                 struct nvkm_secboot *sb)
+{
+       unsigned long fid;
+
+       nvkm_subdev_ctor(&nvkm_secboot, device, index, 0, &sb->subdev);
+       sb->func = func;
+

Move these two after the switch statement ?

Quoted 3 lines

They need to be done here to make the failure path cleanup stuff work correctly, so it's correct as-is.

| always get confused which ones needed to setup their own dtors and which ones didn't. Thanks !

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

A message that is not in the archive (sent off-list or not yet received): CACvgo53cqvn73=Ks-syi=12eO7vrjRcwKJHpgfHh75hHT0sPkQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#11 lore raw

Re: [Nouveau] [PATCH v2 2/5] core: add support for secure boot

Quoted 7 lines · Emil Velikov
Quoted 6 lines · Ben Skeggs
Quoted 5 lines · Emil Velikov

Hi Alexandre,

On 18 January 2016 at 06:10, Alexandre Courbot <[email protected]> wrote:

[snip]

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+static const char *
+managed_falcons_names[] = {
+       [NVKM_SECBOOT_FALCON_PMU] = "PMU",
+       [NVKM_SECBOOT_FALCON_RESERVED] = "<invalid>",

"<reserved>" perhaps ? we already have one invalid below.

Does <reserved> really mean: "we don't want to tell you?" here? :)

That or we have some secret WIP that we're haven't decided if it'll work out :-)

That's just how it appears on our end. :) But since this enum does not seem to be used by the hardware anyway, I will simply remove the "_RESERVED" entry. Thanks.

A message that is not in the archive (sent off-list or not yet received): CAAVeFuLXwo0hb7Z_h3+gOA4u+fp0u=zLPuGxFBW+uY0MsQY-aQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#13 lore raw

Re: [Nouveau] [PATCH v2 2/5] core: add support for secure boot

Quoted 13 lines · Alexandre Courbot
Quoted 12 lines · Emil Velikov
Quoted 11 lines · Ben Skeggs
Quoted 10 lines · Emil Velikov

Hi Alexandre,

On 18 January 2016 at 06:10, Alexandre Courbot <[email protected]> wrote:

[snip]

Review

Quoted 4 lines
(quoted diff) +4 -0
+static const char *
+managed_falcons_names[] = {
+       [NVKM_SECBOOT_FALCON_PMU] = "PMU",
+       [NVKM_SECBOOT_FALCON_RESERVED] = "<invalid>",

"<reserved>" perhaps ? we already have one invalid below.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Does <reserved> really mean: "we don't want to tell you?" here? :)

That or we have some secret WIP that we're haven't decided if it'll work out :-)

That's just how it appears on our end. :) But since this enum does not seem to be used by the hardware anyway, I will simply remove the "_RESERVED" entry. Thanks.

Meh, stupid me - these values also appear in the firmware files, so I must keep the same numbering, and thus the _RESERVED entry. Sorry for the noise.

#14 lore raw

PATCH v2 3/5 gr: support for securely-booted FECS firmware

In reply to a message not in the archive

Trigger the loading of FECS/GPCCS using secure boot if required, and start managed falcons using the CPUCTL_ALIAS register since CPUCTL is protected in that case.

This solution (doing secure boot in GR) is temporary. In the future the PMU firmware will be able to reboot falcons on demand, but this requires the PMU firmware to be released first. This solution at least allows GR to be enabled.

---
 drm/nouveau/nvkm/engine/gr/gf100.c | 46 +++++++++++++++++++++++++++++++-------
 1 file changed, 38 insertions(+), 8 deletions(-)
drm/nouveau/nvkm/engine/gr/gf100.c +38 -8
index f2410aff07cf..a09859491670 100644
@@ -28,6 +28,7 @@
 #include <core/client.h>
 #include <core/option.h>
 #include <core/firmware.h>
+#include <subdev/secboot.h>
 #include <subdev/fb.h>
 #include <subdev/mc.h>
 #include <subdev/pmu.h>
@@ -1428,21 +1429,46 @@ gf100_gr_init_ctxctl(struct gf100_gr *gr)
 	const struct gf100_grctx_func *grctx = gr->func->grctx;
 	struct nvkm_subdev *subdev = &gr->base.engine.subdev;
 	struct nvkm_device *device = subdev->device;
+	u32 sec_flcns = 0;
+	int ret = 0;
 	int i;
 
 	if (gr->firmware) {
 		/* load fuc microcode */
 		nvkm_mc_unk260(device->mc, 0);
-		gf100_gr_init_fw(gr, 0x409000, &gr->fuc409c, &gr->fuc409d);
-		gf100_gr_init_fw(gr, 0x41a000, &gr->fuc41ac, &gr->fuc41ad);
+
+		/* securely-managed falcons must be reset using secure boot */
+		if (nvkm_secboot_is_managed(device, NVKM_SECBOOT_FALCON_FECS))
+			sec_flcns |= BIT(NVKM_SECBOOT_FALCON_FECS);
+		else
+			gf100_gr_init_fw(gr, 0x409000, &gr->fuc409c,
+					 &gr->fuc409d);
+		if (nvkm_secboot_is_managed(device, NVKM_SECBOOT_FALCON_GPCCS))
+			sec_flcns |= BIT(NVKM_SECBOOT_FALCON_GPCCS);
+		else
+			gf100_gr_init_fw(gr, 0x41a000, &gr->fuc41ac,
+					 &gr->fuc41ad);
+		if (sec_flcns)
+			ret = nvkm_secboot_reset(device->secboot, sec_flcns);
+		if (ret)
+			return ret;
+
 		nvkm_mc_unk260(device->mc, 1);
 
 		/* start both of them running */
 		nvkm_wr32(device, 0x409840, 0xffffffff);
 		nvkm_wr32(device, 0x41a10c, 0x00000000);
 		nvkm_wr32(device, 0x40910c, 0x00000000);
-		nvkm_wr32(device, 0x41a100, 0x00000002);
-		nvkm_wr32(device, 0x409100, 0x00000002);
+
+		/* Use FALCON_CPUCTL_ALIAS if falcon is in secure mode */
+		if (nvkm_rd32(device, 0x41a100) & 0x40)
+			nvkm_wr32(device, 0x41a130, 0x00000002);
+		else
+			nvkm_wr32(device, 0x41a100, 0x00000002);
+		if (nvkm_rd32(device, 0x409100) & 0x40)
+			nvkm_wr32(device, 0x409130, 0x00000002);
+		else
+			nvkm_wr32(device, 0x409100, 0x00000002);
 		if (nvkm_msec(device, 2000,
 			if (nvkm_rd32(device, 0x409800) & 0x00000001)
 				break;
@@ -1753,10 +1779,14 @@ gf100_gr_ctor(const struct gf100_gr_func *func, struct nvkm_device *device,
 
 	if (gr->firmware) {
 		nvkm_info(&gr->base.engine.subdev, "using external firmware\n");
-		if (gf100_gr_ctor_fw(gr, "fecs_inst", &gr->fuc409c) ||
-		    gf100_gr_ctor_fw(gr, "fecs_data", &gr->fuc409d) ||
-		    gf100_gr_ctor_fw(gr, "gpccs_inst", &gr->fuc41ac) ||
-		    gf100_gr_ctor_fw(gr, "gpccs_data", &gr->fuc41ad))
+		if (!nvkm_secboot_is_managed(device, NVKM_SECBOOT_FALCON_FECS)
+		     && (gf100_gr_ctor_fw(gr, "fecs_inst", &gr->fuc409c) ||
+			 gf100_gr_ctor_fw(gr, "fecs_data", &gr->fuc409d)))
+			return -ENODEV;
+
+		if (!nvkm_secboot_is_managed(device, NVKM_SECBOOT_FALCON_GPCCS)
+		     && (gf100_gr_ctor_fw(gr, "gpccs_inst", &gr->fuc41ac) ||
+			 gf100_gr_ctor_fw(gr, "gpccs_data", &gr->fuc41ad)))
 			return -ENODEV;
 	}
 
Signature · 6 lines
2.7.0

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

PATCH v2 4/5 secboot/gm200: add secure-boot support

In reply to a message not in the archive

This patch adds secure-boot for the dGPU set of GM20X chips, using the PMU as the high-secure falcon.

This work is based on Deepak Goyal's initial port of Secure Boot to Nouveau.

---
 drm/nouveau/include/nvkm/subdev/secboot.h |    2 +
 drm/nouveau/nvkm/engine/device/base.c     |    2 +
 drm/nouveau/nvkm/engine/gr/gm204.c        |    8 +-
 drm/nouveau/nvkm/subdev/secboot/Kbuild    |    1 +
 drm/nouveau/nvkm/subdev/secboot/gm200.c   | 1308 +++++++++++++++++++++++++++++
 drm/nouveau/nvkm/subdev/secboot/priv.h    |  141 ++++
 6 files changed, 1455 insertions(+), 7 deletions(-)
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/gm200.c
drm/nouveau/include/nvkm/subdev/secboot.h +2 -0
index 0691db24be47..da3895f955ce 100644
@@ -53,4 +53,6 @@ struct nvkm_secboot {
 bool nvkm_secboot_is_managed(struct nvkm_device *, enum nvkm_secboot_falcon);
 int nvkm_secboot_reset(struct nvkm_secboot *, u32 falcons_mask);
 
+int gm200_secboot_new(struct nvkm_device *, int, struct nvkm_secboot **);
+
 #endif
drm/nouveau/nvkm/engine/device/base.c +2 -0
index 95fc9a69d322..770d3ec130a3 100644
@@ -1991,6 +1991,7 @@ nv124_chipset = {
 	.fifo = gm204_fifo_new,
 	.gr = gm204_gr_new,
 	.sw = gf100_sw_new,
+	.secboot = gm200_secboot_new,
 };
 
 static const struct nvkm_device_chip
@@ -2022,6 +2023,7 @@ nv126_chipset = {
 	.fifo = gm204_fifo_new,
 	.gr = gm206_gr_new,
 	.sw = gf100_sw_new,
+	.secboot = gm200_secboot_new,
 };
 
 static const struct nvkm_device_chip
drm/nouveau/nvkm/engine/gr/gm204.c +1 -7
index 90381dde451a..69a3218bf49c 100644
@@ -229,12 +229,6 @@ gm204_gr_data[] = {
  * PGRAPH engine/subdev functions
  ******************************************************************************/
 
-static int
-gm204_gr_init_ctxctl(struct gf100_gr *gr)
-{
-	return 0;
-}
-
 int
 gm204_gr_init(struct gf100_gr *gr)
 {
@@ -348,7 +342,7 @@ gm204_gr_init(struct gf100_gr *gr)
 
 	gf100_gr_zbc_init(gr);
 
-	return gm204_gr_init_ctxctl(gr);
+	return gf100_gr_init_ctxctl(gr);
 }
 
 static const struct gf100_gr_func
drm/nouveau/nvkm/subdev/secboot/Kbuild +1 -0
index e757096b2ff0..c1abf59410d1 100644
@@ -1 +1,2 @@
 nvkm-y += nvkm/subdev/secboot/base.o
+nvkm-y += nvkm/subdev/secboot/gm200.o
drm/nouveau/nvkm/subdev/secboot/gm200.c new file +1308 -0

1,308 lines not on this page · raw message

drm/nouveau/nvkm/subdev/secboot/priv.h +141 -0

145 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
#16 lore raw

PATCH v2 5/5 secboot/gm20b: add secure boot support

In reply to a message not in the archive

Add secure boot support for the GM20B chip found in Tegra X1. Secure boot on Tegra works slightly differently from desktop, notably in the way the WPR region is set up.

In addition, the firmware bootloaders use a slightly different header format. This last point may be fixed when the actual firmware release occurs, but for now this code makes it possible to load the firmware released with SHIELD TV and Google Pixel C.

---
 drm/nouveau/include/nvkm/subdev/secboot.h |   1 +
 drm/nouveau/nvkm/engine/device/base.c     |   1 +
 drm/nouveau/nvkm/engine/gr/gm20b.c        |   9 +-
 drm/nouveau/nvkm/subdev/secboot/Kbuild    |   1 +
 drm/nouveau/nvkm/subdev/secboot/gm20b.c   | 213 ++++++++++++++++++++++++++++++
 5 files changed, 222 insertions(+), 3 deletions(-)
 create mode 100644 drm/nouveau/nvkm/subdev/secboot/gm20b.c
drm/nouveau/include/nvkm/subdev/secboot.h +1 -0
index da3895f955ce..386a7afba3ff 100644
@@ -54,5 +54,6 @@ bool nvkm_secboot_is_managed(struct nvkm_device *, enum nvkm_secboot_falcon);
 int nvkm_secboot_reset(struct nvkm_secboot *, u32 falcons_mask);
 
 int gm200_secboot_new(struct nvkm_device *, int, struct nvkm_secboot **);
+int gm20b_secboot_new(struct nvkm_device *, int, struct nvkm_secboot **);
 
 #endif
drm/nouveau/nvkm/engine/device/base.c +1 -0
index 770d3ec130a3..6e1380b6f0a3 100644
@@ -2044,6 +2044,7 @@ nv12b_chipset = {
 	.fifo = gm20b_fifo_new,
 	.gr = gm20b_gr_new,
 	.sw = gf100_sw_new,
+	.secboot = gm20b_secboot_new,
 };
 
 static int
drm/nouveau/nvkm/engine/gr/gm20b.c +6 -3
index 65b6e3d1e90d..9f804c7ae2a0 100644
@@ -32,12 +32,15 @@ gm20b_gr_init_gpc_mmu(struct gf100_gr *gr)
 	struct nvkm_device *device = gr->base.engine.subdev.device;
 	u32 val;
 
-	/* TODO this needs to be removed once secure boot works */
-	if (1) {
+	/* Bypass MMU check for non-secure boot */
+	if (!device->secboot) {
 		nvkm_wr32(device, 0x100ce4, 0xffffffff);
+
+		if (nvkm_rd32(device, 0x100ce4) != 0xffffffff)
+			nvdev_warn(device,
+			  "cannot bypass secure boot - expect failure soon!\n");
 	}
 
-	/* TODO update once secure boot works */
 	val = nvkm_rd32(device, 0x100c80);
 	val &= 0xf000087f;
 	nvkm_wr32(device, 0x418880, val);
drm/nouveau/nvkm/subdev/secboot/Kbuild +1 -0
index c1abf59410d1..b02b868a6589 100644
@@ -1,2 +1,3 @@
 nvkm-y += nvkm/subdev/secboot/base.o
 nvkm-y += nvkm/subdev/secboot/gm200.o
+nvkm-y += nvkm/subdev/secboot/gm20b.o
drm/nouveau/nvkm/subdev/secboot/gm20b.c new file +213 -0

213 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