Skip to content

Commit ebe52a5

Browse files
author
Ben Skeggs
committed
drm/nouveau/fb/gp102-: unlock VPR as part of FB init
We perform memory allocations long before we hit the code in SECBOOT that would unlock the VPR, which could potentially result in memory allocation within the locked region. Run the scrubber binary right after VRAM init to ensure we don't. Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
1 parent ff213b6 commit ebe52a5

10 files changed

Lines changed: 226 additions & 121 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* SPDX-License-Identifier: MIT */
2+
#ifndef __NVFW_HS_H__
3+
#define __NVFW_HS_H__
4+
#include <core/os.h>
5+
struct nvkm_subdev;
6+
7+
struct nvfw_hs_header {
8+
u32 sig_dbg_offset;
9+
u32 sig_dbg_size;
10+
u32 sig_prod_offset;
11+
u32 sig_prod_size;
12+
u32 patch_loc;
13+
u32 patch_sig;
14+
u32 hdr_offset;
15+
u32 hdr_size;
16+
};
17+
18+
const struct nvfw_hs_header *nvfw_hs_header(struct nvkm_subdev *, const void *);
19+
20+
struct nvfw_hs_load_header {
21+
u32 non_sec_code_off;
22+
u32 non_sec_code_size;
23+
u32 data_dma_base;
24+
u32 data_size;
25+
u32 num_apps;
26+
u32 apps[0];
27+
};
28+
29+
const struct nvfw_hs_load_header *
30+
nvfw_hs_load_header(struct nvkm_subdev *, const void *);
31+
#endif

‎drivers/gpu/drm/nouveau/include/nvkm/subdev/fb.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ struct nvkm_fb {
3333
const struct nvkm_fb_func *func;
3434
struct nvkm_subdev subdev;
3535

36+
struct nvkm_blob vpr_scrubber;
37+
3638
struct nvkm_ram *ram;
3739
struct nvkm_mm tags;
3840

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# SPDX-License-Identifier: MIT
22
nvkm-y += nvkm/nvfw/fw.o
3+
nvkm-y += nvkm/nvfw/hs.o
34
nvkm-y += nvkm/nvfw/ls.o
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2019 Red Hat Inc.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
#include <core/subdev.h>
23+
#include <nvfw/hs.h>
24+
25+
const struct nvfw_hs_header *
26+
nvfw_hs_header(struct nvkm_subdev *subdev, const void *data)
27+
{
28+
const struct nvfw_hs_header *hdr = data;
29+
nvkm_debug(subdev, "hsHeader:\n");
30+
nvkm_debug(subdev, "\tsigDbgOffset : 0x%x\n", hdr->sig_dbg_offset);
31+
nvkm_debug(subdev, "\tsigDbgSize : 0x%x\n", hdr->sig_dbg_size);
32+
nvkm_debug(subdev, "\tsigProdOffset : 0x%x\n", hdr->sig_prod_offset);
33+
nvkm_debug(subdev, "\tsigProdSize : 0x%x\n", hdr->sig_prod_size);
34+
nvkm_debug(subdev, "\tpatchLoc : 0x%x\n", hdr->patch_loc);
35+
nvkm_debug(subdev, "\tpatchSig : 0x%x\n", hdr->patch_sig);
36+
nvkm_debug(subdev, "\thdrOffset : 0x%x\n", hdr->hdr_offset);
37+
nvkm_debug(subdev, "\thdrSize : 0x%x\n", hdr->hdr_size);
38+
return hdr;
39+
}
40+
41+
const struct nvfw_hs_load_header *
42+
nvfw_hs_load_header(struct nvkm_subdev *subdev, const void *data)
43+
{
44+
const struct nvfw_hs_load_header *hdr = data;
45+
int i;
46+
47+
nvkm_debug(subdev, "hsLoadHeader:\n");
48+
nvkm_debug(subdev, "\tnonSecCodeOff : 0x%x\n",
49+
hdr->non_sec_code_off);
50+
nvkm_debug(subdev, "\tnonSecCodeSize : 0x%x\n",
51+
hdr->non_sec_code_size);
52+
nvkm_debug(subdev, "\tdataDmaBase : 0x%x\n", hdr->data_dma_base);
53+
nvkm_debug(subdev, "\tdataSize : 0x%x\n", hdr->data_size);
54+
nvkm_debug(subdev, "\tnumApps : 0x%x\n", hdr->num_apps);
55+
for (i = 0; i < hdr->num_apps; i++) {
56+
nvkm_debug(subdev,
57+
"\tApp[%d] : offset 0x%x size 0x%x\n", i,
58+
hdr->apps[(i * 2) + 0], hdr->apps[(i * 2) + 1]);
59+
}
60+
61+
return hdr;
62+
}

‎drivers/gpu/drm/nouveau/nvkm/subdev/fb/base.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,23 @@ nvkm_fb_init(struct nvkm_subdev *subdev)
154154

155155
if (fb->func->init_unkn)
156156
fb->func->init_unkn(fb);
157+
158+
if (fb->func->vpr.scrub_required &&
159+
fb->func->vpr.scrub_required(fb)) {
160+
nvkm_debug(subdev, "VPR locked, running scrubber binary\n");
161+
162+
ret = fb->func->vpr.scrub(fb);
163+
if (ret)
164+
return ret;
165+
166+
if (fb->func->vpr.scrub_required(fb)) {
167+
nvkm_error(subdev, "VPR still locked after scrub!\n");
168+
return -EIO;
169+
}
170+
171+
nvkm_debug(subdev, "VPR scrubber binary successful\n");
172+
}
173+
157174
return 0;
158175
}
159176

@@ -172,6 +189,8 @@ nvkm_fb_dtor(struct nvkm_subdev *subdev)
172189
nvkm_mm_fini(&fb->tags);
173190
nvkm_ram_del(&fb->ram);
174191

192+
nvkm_blob_dtor(&fb->vpr_scrubber);
193+
175194
if (fb->func->dtor)
176195
return fb->func->dtor(fb);
177196
return fb;

‎drivers/gpu/drm/nouveau/nvkm/subdev/fb/gp102.c‎

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,81 @@
2424
#include "gf100.h"
2525
#include "ram.h"
2626

27+
#include <core/firmware.h>
2728
#include <core/memory.h>
29+
#include <nvfw/fw.h>
30+
#include <nvfw/hs.h>
31+
#include <engine/nvdec.h>
32+
33+
int
34+
gp102_fb_vpr_scrub(struct nvkm_fb *fb)
35+
{
36+
struct nvkm_subdev *subdev = &fb->subdev;
37+
struct nvkm_device *device = subdev->device;
38+
struct nvkm_falcon *falcon = &device->nvdec[0]->falcon;
39+
struct nvkm_blob *blob = &fb->vpr_scrubber;
40+
const struct nvfw_bin_hdr *hsbin_hdr;
41+
const struct nvfw_hs_header *fw_hdr;
42+
const struct nvfw_hs_load_header *lhdr;
43+
void *scrub_data;
44+
u32 patch_loc, patch_sig;
45+
int ret;
46+
47+
nvkm_falcon_get(falcon, subdev);
48+
49+
hsbin_hdr = nvfw_bin_hdr(subdev, blob->data);
50+
fw_hdr = nvfw_hs_header(subdev, blob->data + hsbin_hdr->header_offset);
51+
lhdr = nvfw_hs_load_header(subdev, blob->data + fw_hdr->hdr_offset);
52+
scrub_data = blob->data + hsbin_hdr->data_offset;
53+
54+
patch_loc = *(u32 *)(blob->data + fw_hdr->patch_loc);
55+
patch_sig = *(u32 *)(blob->data + fw_hdr->patch_sig);
56+
if (falcon->debug) {
57+
memcpy(scrub_data + patch_loc,
58+
blob->data + fw_hdr->sig_dbg_offset + patch_sig,
59+
fw_hdr->sig_dbg_size);
60+
} else {
61+
memcpy(scrub_data + patch_loc,
62+
blob->data + fw_hdr->sig_prod_offset + patch_sig,
63+
fw_hdr->sig_prod_size);
64+
}
65+
66+
nvkm_falcon_reset(falcon);
67+
nvkm_falcon_bind_context(falcon, NULL);
68+
69+
nvkm_falcon_load_imem(falcon, scrub_data, lhdr->non_sec_code_off,
70+
lhdr->non_sec_code_size,
71+
lhdr->non_sec_code_off >> 8, 0, false);
72+
nvkm_falcon_load_imem(falcon, scrub_data + lhdr->apps[0],
73+
ALIGN(lhdr->apps[0], 0x100),
74+
lhdr->apps[1],
75+
lhdr->apps[0] >> 8, 0, true);
76+
nvkm_falcon_load_dmem(falcon, scrub_data + lhdr->data_dma_base, 0,
77+
lhdr->data_size, 0);
78+
79+
nvkm_falcon_set_start_addr(falcon, 0x0);
80+
nvkm_falcon_start(falcon);
81+
82+
ret = nvkm_falcon_wait_for_halt(falcon, 500);
83+
if (ret < 0) {
84+
ret = -ETIMEDOUT;
85+
goto end;
86+
}
87+
88+
/* put nvdec in clean state - without reset it will remain in HS mode */
89+
nvkm_falcon_reset(falcon);
90+
end:
91+
nvkm_falcon_put(falcon, subdev);
92+
return ret;
93+
}
94+
95+
bool
96+
gp102_fb_vpr_scrub_required(struct nvkm_fb *fb)
97+
{
98+
struct nvkm_device *device = fb->subdev.device;
99+
nvkm_wr32(device, 0x100cd0, 0x2);
100+
return (nvkm_rd32(device, 0x100cd0) & 0x00000010) != 0;
101+
}
28102

29103
static const struct nvkm_fb_func
30104
gp102_fb = {
@@ -33,11 +107,31 @@ gp102_fb = {
33107
.init = gp100_fb_init,
34108
.init_remapper = gp100_fb_init_remapper,
35109
.init_page = gm200_fb_init_page,
110+
.vpr.scrub_required = gp102_fb_vpr_scrub_required,
111+
.vpr.scrub = gp102_fb_vpr_scrub,
36112
.ram_new = gp100_ram_new,
37113
};
38114

115+
int
116+
gp102_fb_new_(const struct nvkm_fb_func *func, struct nvkm_device *device,
117+
int index, struct nvkm_fb **pfb)
118+
{
119+
int ret = gf100_fb_new_(func, device, index, pfb);
120+
if (ret)
121+
return ret;
122+
123+
return nvkm_firmware_load_blob(&(*pfb)->subdev, "nvdec/scrubber", "", 0,
124+
&(*pfb)->vpr_scrubber);
125+
}
126+
39127
int
40128
gp102_fb_new(struct nvkm_device *device, int index, struct nvkm_fb **pfb)
41129
{
42-
return gf100_fb_new_(&gp102_fb, device, index, pfb);
130+
return gp102_fb_new_(&gp102_fb, device, index, pfb);
43131
}
132+
133+
MODULE_FIRMWARE("nvidia/gp102/nvdec/scrubber.bin");
134+
MODULE_FIRMWARE("nvidia/gp104/nvdec/scrubber.bin");
135+
MODULE_FIRMWARE("nvidia/gp106/nvdec/scrubber.bin");
136+
MODULE_FIRMWARE("nvidia/gp107/nvdec/scrubber.bin");
137+
MODULE_FIRMWARE("nvidia/gp108/nvdec/scrubber.bin");

‎drivers/gpu/drm/nouveau/nvkm/subdev/fb/gv100.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ gv100_fb = {
3535
.init = gp100_fb_init,
3636
.init_page = gv100_fb_init_page,
3737
.init_unkn = gp100_fb_init_unkn,
38+
.vpr.scrub_required = gp102_fb_vpr_scrub_required,
39+
.vpr.scrub = gp102_fb_vpr_scrub,
3840
.ram_new = gp100_ram_new,
3941
.default_bigpage = 16,
4042
};
4143

4244
int
4345
gv100_fb_new(struct nvkm_device *device, int index, struct nvkm_fb **pfb)
4446
{
45-
return gf100_fb_new_(&gv100_fb, device, index, pfb);
47+
return gp102_fb_new_(&gv100_fb, device, index, pfb);
4648
}
49+
50+
MODULE_FIRMWARE("nvidia/gv100/nvdec/scrubber.bin");

‎drivers/gpu/drm/nouveau/nvkm/subdev/fb/priv.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ struct nvkm_fb_func {
1616
void (*init_unkn)(struct nvkm_fb *);
1717
void (*intr)(struct nvkm_fb *);
1818

19+
struct {
20+
bool (*scrub_required)(struct nvkm_fb *);
21+
int (*scrub)(struct nvkm_fb *);
22+
} vpr;
23+
1924
struct {
2025
int regions;
2126
void (*init)(struct nvkm_fb *, int i, u32 addr, u32 size,
@@ -72,4 +77,9 @@ int gm200_fb_init_page(struct nvkm_fb *);
7277

7378
void gp100_fb_init_remapper(struct nvkm_fb *);
7479
void gp100_fb_init_unkn(struct nvkm_fb *);
80+
81+
int gp102_fb_new_(const struct nvkm_fb_func *, struct nvkm_device *, int,
82+
struct nvkm_fb **);
83+
bool gp102_fb_vpr_scrub_required(struct nvkm_fb *);
84+
int gp102_fb_vpr_scrub(struct nvkm_fb *);
7585
#endif

0 commit comments

Comments
 (0)