1176fdcbdSBen Skeggs /*
2176fdcbdSBen Skeggs * Copyright 2023 Red Hat Inc.
3176fdcbdSBen Skeggs *
4176fdcbdSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5176fdcbdSBen Skeggs * copy of this software and associated documentation files (the "Software"),
6176fdcbdSBen Skeggs * to deal in the Software without restriction, including without limitation
7176fdcbdSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8176fdcbdSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9176fdcbdSBen Skeggs * Software is furnished to do so, subject to the following conditions:
10176fdcbdSBen Skeggs *
11176fdcbdSBen Skeggs * The above copyright notice and this permission notice shall be included in
12176fdcbdSBen Skeggs * all copies or substantial portions of the Software.
13176fdcbdSBen Skeggs *
14176fdcbdSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15176fdcbdSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16176fdcbdSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17176fdcbdSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18176fdcbdSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19176fdcbdSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20176fdcbdSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21176fdcbdSBen Skeggs */
22176fdcbdSBen Skeggs #include "priv.h"
23176fdcbdSBen Skeggs
24176fdcbdSBen Skeggs #include <subdev/bios.h>
25176fdcbdSBen Skeggs #include <subdev/bios/pmu.h>
26176fdcbdSBen Skeggs
27176fdcbdSBen Skeggs #include <nvfw/fw.h>
28176fdcbdSBen Skeggs
29176fdcbdSBen Skeggs union nvfw_falcon_appif_hdr {
30176fdcbdSBen Skeggs struct nvfw_falcon_appif_hdr_v1 {
31176fdcbdSBen Skeggs u8 ver;
32176fdcbdSBen Skeggs u8 hdr;
33176fdcbdSBen Skeggs u8 len;
34176fdcbdSBen Skeggs u8 cnt;
35176fdcbdSBen Skeggs } v1;
36176fdcbdSBen Skeggs };
37176fdcbdSBen Skeggs
38176fdcbdSBen Skeggs union nvfw_falcon_appif {
39176fdcbdSBen Skeggs struct nvfw_falcon_appif_v1 {
40176fdcbdSBen Skeggs #define NVFW_FALCON_APPIF_ID_DMEMMAPPER 0x00000004
41176fdcbdSBen Skeggs u32 id;
42176fdcbdSBen Skeggs u32 dmem_base;
43176fdcbdSBen Skeggs } v1;
44176fdcbdSBen Skeggs };
45176fdcbdSBen Skeggs
46176fdcbdSBen Skeggs union nvfw_falcon_appif_dmemmapper {
47176fdcbdSBen Skeggs struct {
48176fdcbdSBen Skeggs u32 signature;
49176fdcbdSBen Skeggs u16 version;
50176fdcbdSBen Skeggs u16 size;
51176fdcbdSBen Skeggs u32 cmd_in_buffer_offset;
52176fdcbdSBen Skeggs u32 cmd_in_buffer_size;
53176fdcbdSBen Skeggs u32 cmd_out_buffer_offset;
54176fdcbdSBen Skeggs u32 cmd_out_buffer_size;
55176fdcbdSBen Skeggs u32 nvf_img_data_buffer_offset;
56176fdcbdSBen Skeggs u32 nvf_img_data_buffer_size;
57176fdcbdSBen Skeggs u32 printf_buffer_hdr;
58176fdcbdSBen Skeggs u32 ucode_build_time_stamp;
59176fdcbdSBen Skeggs u32 ucode_signature;
60176fdcbdSBen Skeggs #define NVFW_FALCON_APPIF_DMEMMAPPER_CMD_FRTS 0x00000015
61176fdcbdSBen Skeggs #define NVFW_FALCON_APPIF_DMEMMAPPER_CMD_SB 0x00000019
62176fdcbdSBen Skeggs u32 init_cmd;
63176fdcbdSBen Skeggs u32 ucode_feature;
64176fdcbdSBen Skeggs u32 ucode_cmd_mask0;
65176fdcbdSBen Skeggs u32 ucode_cmd_mask1;
66176fdcbdSBen Skeggs u32 multi_tgt_tbl;
67176fdcbdSBen Skeggs } v3;
68176fdcbdSBen Skeggs };
69176fdcbdSBen Skeggs
70176fdcbdSBen Skeggs struct nvfw_fwsec_frts_cmd {
71176fdcbdSBen Skeggs struct {
72176fdcbdSBen Skeggs u32 ver;
73176fdcbdSBen Skeggs u32 hdr;
74176fdcbdSBen Skeggs u64 addr;
75176fdcbdSBen Skeggs u32 size;
76176fdcbdSBen Skeggs u32 flags;
77176fdcbdSBen Skeggs } read_vbios;
78176fdcbdSBen Skeggs struct {
79176fdcbdSBen Skeggs u32 ver;
80176fdcbdSBen Skeggs u32 hdr;
81176fdcbdSBen Skeggs u32 addr;
82176fdcbdSBen Skeggs u32 size;
83176fdcbdSBen Skeggs #define NVFW_FRTS_CMD_REGION_TYPE_FB 0x00000002
84176fdcbdSBen Skeggs u32 type;
85176fdcbdSBen Skeggs } frts_region;
86176fdcbdSBen Skeggs };
87176fdcbdSBen Skeggs
88176fdcbdSBen Skeggs static int
nvkm_gsp_fwsec_patch(struct nvkm_gsp * gsp,struct nvkm_falcon_fw * fw,u32 if_offset,u32 init_cmd)89176fdcbdSBen Skeggs nvkm_gsp_fwsec_patch(struct nvkm_gsp *gsp, struct nvkm_falcon_fw *fw, u32 if_offset, u32 init_cmd)
90176fdcbdSBen Skeggs {
91176fdcbdSBen Skeggs union nvfw_falcon_appif_hdr *hdr = (void *)(fw->fw.img + fw->dmem_base_img + if_offset);
92176fdcbdSBen Skeggs const u8 *dmem = fw->fw.img + fw->dmem_base_img;
93176fdcbdSBen Skeggs int i;
94176fdcbdSBen Skeggs
95176fdcbdSBen Skeggs if (WARN_ON(hdr->v1.ver != 1))
96176fdcbdSBen Skeggs return -EINVAL;
97176fdcbdSBen Skeggs
98176fdcbdSBen Skeggs for (i = 0; i < hdr->v1.cnt; i++) {
99176fdcbdSBen Skeggs union nvfw_falcon_appif *app = (void *)((u8 *)hdr + hdr->v1.hdr + i * hdr->v1.len);
100176fdcbdSBen Skeggs union nvfw_falcon_appif_dmemmapper *dmemmap;
101176fdcbdSBen Skeggs struct nvfw_fwsec_frts_cmd *frtscmd;
102176fdcbdSBen Skeggs
103176fdcbdSBen Skeggs if (app->v1.id != NVFW_FALCON_APPIF_ID_DMEMMAPPER)
104176fdcbdSBen Skeggs continue;
105176fdcbdSBen Skeggs
106176fdcbdSBen Skeggs dmemmap = (void *)(dmem + app->v1.dmem_base);
107176fdcbdSBen Skeggs dmemmap->v3.init_cmd = init_cmd;
108176fdcbdSBen Skeggs
109176fdcbdSBen Skeggs frtscmd = (void *)(dmem + dmemmap->v3.cmd_in_buffer_offset);
110176fdcbdSBen Skeggs
111176fdcbdSBen Skeggs frtscmd->read_vbios.ver = 1;
112176fdcbdSBen Skeggs frtscmd->read_vbios.hdr = sizeof(frtscmd->read_vbios);
113176fdcbdSBen Skeggs frtscmd->read_vbios.addr = 0;
114176fdcbdSBen Skeggs frtscmd->read_vbios.size = 0;
115176fdcbdSBen Skeggs frtscmd->read_vbios.flags = 2;
116176fdcbdSBen Skeggs
117176fdcbdSBen Skeggs if (init_cmd == NVFW_FALCON_APPIF_DMEMMAPPER_CMD_FRTS) {
118176fdcbdSBen Skeggs frtscmd->frts_region.ver = 1;
119176fdcbdSBen Skeggs frtscmd->frts_region.hdr = sizeof(frtscmd->frts_region);
120176fdcbdSBen Skeggs frtscmd->frts_region.addr = gsp->fb.wpr2.frts.addr >> 12;
121176fdcbdSBen Skeggs frtscmd->frts_region.size = gsp->fb.wpr2.frts.size >> 12;
122176fdcbdSBen Skeggs frtscmd->frts_region.type = NVFW_FRTS_CMD_REGION_TYPE_FB;
123176fdcbdSBen Skeggs }
124176fdcbdSBen Skeggs
125176fdcbdSBen Skeggs break;
126176fdcbdSBen Skeggs }
127176fdcbdSBen Skeggs
128176fdcbdSBen Skeggs if (WARN_ON(i == hdr->v1.cnt))
129176fdcbdSBen Skeggs return -EINVAL;
130176fdcbdSBen Skeggs
131176fdcbdSBen Skeggs return 0;
132176fdcbdSBen Skeggs }
133176fdcbdSBen Skeggs
134176fdcbdSBen Skeggs union nvfw_falcon_ucode_desc {
135176fdcbdSBen Skeggs struct nvkm_falcon_ucode_desc_v2 {
136176fdcbdSBen Skeggs u32 Hdr;
137176fdcbdSBen Skeggs u32 StoredSize;
138176fdcbdSBen Skeggs u32 UncompressedSize;
139176fdcbdSBen Skeggs u32 VirtualEntry;
140176fdcbdSBen Skeggs u32 InterfaceOffset;
141176fdcbdSBen Skeggs u32 IMEMPhysBase;
142176fdcbdSBen Skeggs u32 IMEMLoadSize;
143176fdcbdSBen Skeggs u32 IMEMVirtBase;
144176fdcbdSBen Skeggs u32 IMEMSecBase;
145176fdcbdSBen Skeggs u32 IMEMSecSize;
146176fdcbdSBen Skeggs u32 DMEMOffset;
147176fdcbdSBen Skeggs u32 DMEMPhysBase;
148176fdcbdSBen Skeggs u32 DMEMLoadSize;
149176fdcbdSBen Skeggs u32 altIMEMLoadSize;
150176fdcbdSBen Skeggs u32 altDMEMLoadSize;
151176fdcbdSBen Skeggs } v2;
152176fdcbdSBen Skeggs
153176fdcbdSBen Skeggs struct nvkm_falcon_ucode_desc_v3 {
154176fdcbdSBen Skeggs u32 Hdr;
155176fdcbdSBen Skeggs u32 StoredSize;
156176fdcbdSBen Skeggs u32 PKCDataOffset;
157176fdcbdSBen Skeggs u32 InterfaceOffset;
158176fdcbdSBen Skeggs u32 IMEMPhysBase;
159176fdcbdSBen Skeggs u32 IMEMLoadSize;
160176fdcbdSBen Skeggs u32 IMEMVirtBase;
161176fdcbdSBen Skeggs u32 DMEMPhysBase;
162176fdcbdSBen Skeggs u32 DMEMLoadSize;
163176fdcbdSBen Skeggs u16 EngineIdMask;
164176fdcbdSBen Skeggs u8 UcodeId;
165176fdcbdSBen Skeggs u8 SignatureCount;
166176fdcbdSBen Skeggs u16 SignatureVersions;
167176fdcbdSBen Skeggs u16 Reserved;
168176fdcbdSBen Skeggs } v3;
169176fdcbdSBen Skeggs };
170176fdcbdSBen Skeggs
171176fdcbdSBen Skeggs static int
nvkm_gsp_fwsec_v2(struct nvkm_gsp * gsp,const char * name,const struct nvkm_falcon_ucode_desc_v2 * desc,u32 size,u32 init_cmd,struct nvkm_falcon_fw * fw)172176fdcbdSBen Skeggs nvkm_gsp_fwsec_v2(struct nvkm_gsp *gsp, const char *name,
173176fdcbdSBen Skeggs const struct nvkm_falcon_ucode_desc_v2 *desc, u32 size, u32 init_cmd,
174176fdcbdSBen Skeggs struct nvkm_falcon_fw *fw)
175176fdcbdSBen Skeggs {
176176fdcbdSBen Skeggs struct nvkm_subdev *subdev = &gsp->subdev;
177176fdcbdSBen Skeggs const struct firmware *bl;
178176fdcbdSBen Skeggs const struct nvfw_bin_hdr *hdr;
179176fdcbdSBen Skeggs const struct nvfw_bl_desc *bld;
180176fdcbdSBen Skeggs int ret;
181176fdcbdSBen Skeggs
182176fdcbdSBen Skeggs /* Build ucode. */
183176fdcbdSBen Skeggs ret = nvkm_falcon_fw_ctor(gsp->func->fwsec, name, subdev->device, true,
184176fdcbdSBen Skeggs (u8 *)desc + size, desc->IMEMLoadSize + desc->DMEMLoadSize,
185176fdcbdSBen Skeggs &gsp->falcon, fw);
186176fdcbdSBen Skeggs if (WARN_ON(ret))
187176fdcbdSBen Skeggs return ret;
188176fdcbdSBen Skeggs
189176fdcbdSBen Skeggs fw->nmem_base_img = 0;
190176fdcbdSBen Skeggs fw->nmem_base = desc->IMEMPhysBase;
191176fdcbdSBen Skeggs fw->nmem_size = desc->IMEMLoadSize - desc->IMEMSecSize;
192176fdcbdSBen Skeggs
193176fdcbdSBen Skeggs fw->imem_base_img = 0;
194176fdcbdSBen Skeggs fw->imem_base = desc->IMEMSecBase;
195176fdcbdSBen Skeggs fw->imem_size = desc->IMEMSecSize;
196176fdcbdSBen Skeggs
197176fdcbdSBen Skeggs fw->dmem_base_img = desc->DMEMOffset;
198176fdcbdSBen Skeggs fw->dmem_base = desc->DMEMPhysBase;
199176fdcbdSBen Skeggs fw->dmem_size = desc->DMEMLoadSize;
200176fdcbdSBen Skeggs
201176fdcbdSBen Skeggs /* Bootloader. */
202176fdcbdSBen Skeggs ret = nvkm_firmware_get(subdev, "acr/bl", 0, &bl);
203176fdcbdSBen Skeggs if (ret)
204176fdcbdSBen Skeggs return ret;
205176fdcbdSBen Skeggs
206176fdcbdSBen Skeggs hdr = nvfw_bin_hdr(subdev, bl->data);
207176fdcbdSBen Skeggs bld = nvfw_bl_desc(subdev, bl->data + hdr->header_offset);
208176fdcbdSBen Skeggs
209176fdcbdSBen Skeggs fw->boot_addr = bld->start_tag << 8;
210176fdcbdSBen Skeggs fw->boot_size = bld->code_size;
211176fdcbdSBen Skeggs fw->boot = kmemdup(bl->data + hdr->data_offset + bld->code_off, fw->boot_size, GFP_KERNEL);
212176fdcbdSBen Skeggs if (!fw->boot)
213176fdcbdSBen Skeggs ret = -ENOMEM;
214176fdcbdSBen Skeggs
215176fdcbdSBen Skeggs nvkm_firmware_put(bl);
216176fdcbdSBen Skeggs
217176fdcbdSBen Skeggs /* Patch in interface data. */
218176fdcbdSBen Skeggs return nvkm_gsp_fwsec_patch(gsp, fw, desc->InterfaceOffset, init_cmd);
219176fdcbdSBen Skeggs }
220176fdcbdSBen Skeggs
221176fdcbdSBen Skeggs static int
nvkm_gsp_fwsec_v3(struct nvkm_gsp * gsp,const char * name,const struct nvkm_falcon_ucode_desc_v3 * desc,u32 size,u32 init_cmd,struct nvkm_falcon_fw * fw)222176fdcbdSBen Skeggs nvkm_gsp_fwsec_v3(struct nvkm_gsp *gsp, const char *name,
223176fdcbdSBen Skeggs const struct nvkm_falcon_ucode_desc_v3 *desc, u32 size, u32 init_cmd,
224176fdcbdSBen Skeggs struct nvkm_falcon_fw *fw)
225176fdcbdSBen Skeggs {
226176fdcbdSBen Skeggs struct nvkm_device *device = gsp->subdev.device;
227176fdcbdSBen Skeggs struct nvkm_bios *bios = device->bios;
228176fdcbdSBen Skeggs int ret;
229176fdcbdSBen Skeggs
230176fdcbdSBen Skeggs /* Build ucode. */
231176fdcbdSBen Skeggs ret = nvkm_falcon_fw_ctor(gsp->func->fwsec, name, device, true,
232176fdcbdSBen Skeggs (u8 *)desc + size, desc->IMEMLoadSize + desc->DMEMLoadSize,
233176fdcbdSBen Skeggs &gsp->falcon, fw);
234176fdcbdSBen Skeggs if (WARN_ON(ret))
235176fdcbdSBen Skeggs return ret;
236176fdcbdSBen Skeggs
237176fdcbdSBen Skeggs fw->imem_base_img = 0;
238176fdcbdSBen Skeggs fw->imem_base = desc->IMEMPhysBase;
239176fdcbdSBen Skeggs fw->imem_size = desc->IMEMLoadSize;
240176fdcbdSBen Skeggs fw->dmem_base_img = desc->IMEMLoadSize;
241176fdcbdSBen Skeggs fw->dmem_base = desc->DMEMPhysBase;
242176fdcbdSBen Skeggs fw->dmem_size = ALIGN(desc->DMEMLoadSize, 256);
243176fdcbdSBen Skeggs fw->dmem_sign = desc->PKCDataOffset;
244176fdcbdSBen Skeggs fw->boot_addr = 0;
245176fdcbdSBen Skeggs fw->fuse_ver = desc->SignatureVersions;
246176fdcbdSBen Skeggs fw->ucode_id = desc->UcodeId;
247176fdcbdSBen Skeggs fw->engine_id = desc->EngineIdMask;
248176fdcbdSBen Skeggs
249176fdcbdSBen Skeggs /* Patch in signature. */
250176fdcbdSBen Skeggs ret = nvkm_falcon_fw_sign(fw, fw->dmem_base_img + desc->PKCDataOffset, 96 * 4,
251176fdcbdSBen Skeggs nvbios_pointer(bios, 0), desc->SignatureCount,
252176fdcbdSBen Skeggs (u8 *)desc + 0x2c - (u8 *)nvbios_pointer(bios, 0), 0, 0);
253176fdcbdSBen Skeggs if (WARN_ON(ret))
254176fdcbdSBen Skeggs return ret;
255176fdcbdSBen Skeggs
256176fdcbdSBen Skeggs /* Patch in interface data. */
257176fdcbdSBen Skeggs return nvkm_gsp_fwsec_patch(gsp, fw, desc->InterfaceOffset, init_cmd);
258176fdcbdSBen Skeggs }
259176fdcbdSBen Skeggs
260176fdcbdSBen Skeggs static int
nvkm_gsp_fwsec(struct nvkm_gsp * gsp,const char * name,u32 init_cmd)261176fdcbdSBen Skeggs nvkm_gsp_fwsec(struct nvkm_gsp *gsp, const char *name, u32 init_cmd)
262176fdcbdSBen Skeggs {
263176fdcbdSBen Skeggs struct nvkm_subdev *subdev = &gsp->subdev;
264176fdcbdSBen Skeggs struct nvkm_device *device = subdev->device;
265176fdcbdSBen Skeggs struct nvkm_bios *bios = device->bios;
266176fdcbdSBen Skeggs const union nvfw_falcon_ucode_desc *desc;
267176fdcbdSBen Skeggs struct nvbios_pmuE flcn_ucode;
268176fdcbdSBen Skeggs u8 idx, ver, hdr;
269176fdcbdSBen Skeggs u32 data;
270176fdcbdSBen Skeggs u16 size, vers;
271176fdcbdSBen Skeggs struct nvkm_falcon_fw fw = {};
272176fdcbdSBen Skeggs u32 mbox0 = 0;
273176fdcbdSBen Skeggs int ret;
274176fdcbdSBen Skeggs
275176fdcbdSBen Skeggs /* Lookup in VBIOS. */
276176fdcbdSBen Skeggs for (idx = 0; (data = nvbios_pmuEp(bios, idx, &ver, &hdr, &flcn_ucode)); idx++) {
277176fdcbdSBen Skeggs if (flcn_ucode.type == 0x85)
278176fdcbdSBen Skeggs break;
279176fdcbdSBen Skeggs }
280176fdcbdSBen Skeggs
281176fdcbdSBen Skeggs if (WARN_ON(!data))
282176fdcbdSBen Skeggs return -EINVAL;
283176fdcbdSBen Skeggs
284176fdcbdSBen Skeggs /* Deteremine version. */
285176fdcbdSBen Skeggs desc = nvbios_pointer(bios, flcn_ucode.data);
286176fdcbdSBen Skeggs if (WARN_ON(!(desc->v2.Hdr & 0x00000001)))
287176fdcbdSBen Skeggs return -EINVAL;
288176fdcbdSBen Skeggs
289176fdcbdSBen Skeggs size = (desc->v2.Hdr & 0xffff0000) >> 16;
290176fdcbdSBen Skeggs vers = (desc->v2.Hdr & 0x0000ff00) >> 8;
291176fdcbdSBen Skeggs
292176fdcbdSBen Skeggs switch (vers) {
293176fdcbdSBen Skeggs case 2: ret = nvkm_gsp_fwsec_v2(gsp, name, &desc->v2, size, init_cmd, &fw); break;
294176fdcbdSBen Skeggs case 3: ret = nvkm_gsp_fwsec_v3(gsp, name, &desc->v3, size, init_cmd, &fw); break;
295176fdcbdSBen Skeggs default:
296176fdcbdSBen Skeggs nvkm_error(subdev, "%s(v%d): version unknown\n", name, vers);
297176fdcbdSBen Skeggs return -EINVAL;
298176fdcbdSBen Skeggs }
299176fdcbdSBen Skeggs
300176fdcbdSBen Skeggs if (ret) {
301176fdcbdSBen Skeggs nvkm_error(subdev, "%s(v%d): %d\n", name, vers, ret);
302176fdcbdSBen Skeggs return ret;
303176fdcbdSBen Skeggs }
304176fdcbdSBen Skeggs
305176fdcbdSBen Skeggs /* Boot. */
306176fdcbdSBen Skeggs ret = nvkm_falcon_fw_boot(&fw, subdev, true, &mbox0, NULL, 0, 0);
307176fdcbdSBen Skeggs nvkm_falcon_fw_dtor(&fw);
308176fdcbdSBen Skeggs if (ret)
309176fdcbdSBen Skeggs return ret;
310176fdcbdSBen Skeggs
311176fdcbdSBen Skeggs return 0;
312176fdcbdSBen Skeggs }
313176fdcbdSBen Skeggs
314176fdcbdSBen Skeggs int
nvkm_gsp_fwsec_sb(struct nvkm_gsp * gsp)315176fdcbdSBen Skeggs nvkm_gsp_fwsec_sb(struct nvkm_gsp *gsp)
316176fdcbdSBen Skeggs {
317176fdcbdSBen Skeggs struct nvkm_subdev *subdev = &gsp->subdev;
318176fdcbdSBen Skeggs struct nvkm_device *device = subdev->device;
319176fdcbdSBen Skeggs int ret;
320176fdcbdSBen Skeggs u32 err;
321176fdcbdSBen Skeggs
322176fdcbdSBen Skeggs ret = nvkm_gsp_fwsec(gsp, "fwsec-sb", NVFW_FALCON_APPIF_DMEMMAPPER_CMD_SB);
323176fdcbdSBen Skeggs if (ret)
324176fdcbdSBen Skeggs return ret;
325176fdcbdSBen Skeggs
326176fdcbdSBen Skeggs /* Verify. */
327*f33b9ab0SDave Airlie err = nvkm_rd32(device, 0x001400 + (0x15 * 4)) & 0x0000ffff;
328176fdcbdSBen Skeggs if (err) {
329176fdcbdSBen Skeggs nvkm_error(subdev, "fwsec-sb: 0x%04x\n", err);
330176fdcbdSBen Skeggs return -EIO;
331176fdcbdSBen Skeggs }
332176fdcbdSBen Skeggs
333176fdcbdSBen Skeggs return 0;
334176fdcbdSBen Skeggs }
335176fdcbdSBen Skeggs
336176fdcbdSBen Skeggs int
nvkm_gsp_fwsec_frts(struct nvkm_gsp * gsp)337176fdcbdSBen Skeggs nvkm_gsp_fwsec_frts(struct nvkm_gsp *gsp)
338176fdcbdSBen Skeggs {
339176fdcbdSBen Skeggs struct nvkm_subdev *subdev = &gsp->subdev;
340176fdcbdSBen Skeggs struct nvkm_device *device = subdev->device;
341176fdcbdSBen Skeggs int ret;
342176fdcbdSBen Skeggs u32 err, wpr2_lo, wpr2_hi;
343176fdcbdSBen Skeggs
344176fdcbdSBen Skeggs ret = nvkm_gsp_fwsec(gsp, "fwsec-frts", NVFW_FALCON_APPIF_DMEMMAPPER_CMD_FRTS);
345176fdcbdSBen Skeggs if (ret)
346176fdcbdSBen Skeggs return ret;
347176fdcbdSBen Skeggs
348176fdcbdSBen Skeggs /* Verify. */
349176fdcbdSBen Skeggs err = nvkm_rd32(device, 0x001400 + (0xe * 4)) >> 16;
350176fdcbdSBen Skeggs if (err) {
351176fdcbdSBen Skeggs nvkm_error(subdev, "fwsec-frts: 0x%04x\n", err);
352176fdcbdSBen Skeggs return -EIO;
353176fdcbdSBen Skeggs }
354176fdcbdSBen Skeggs
355176fdcbdSBen Skeggs wpr2_lo = nvkm_rd32(device, 0x1fa824);
356176fdcbdSBen Skeggs wpr2_hi = nvkm_rd32(device, 0x1fa828);
357176fdcbdSBen Skeggs nvkm_debug(subdev, "fwsec-frts: WPR2 @ %08x - %08x\n", wpr2_lo, wpr2_hi);
358176fdcbdSBen Skeggs return 0;
359176fdcbdSBen Skeggs }
360