1*4b569dedSBen Skeggs /*
2*4b569dedSBen Skeggs * Copyright 2021 Red Hat Inc.
3*4b569dedSBen Skeggs *
4*4b569dedSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5*4b569dedSBen Skeggs * copy of this software and associated documentation files (the "Software"),
6*4b569dedSBen Skeggs * to deal in the Software without restriction, including without limitation
7*4b569dedSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4b569dedSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9*4b569dedSBen Skeggs * Software is furnished to do so, subject to the following conditions:
10*4b569dedSBen Skeggs *
11*4b569dedSBen Skeggs * The above copyright notice and this permission notice shall be included in
12*4b569dedSBen Skeggs * all copies or substantial portions of the Software.
13*4b569dedSBen Skeggs *
14*4b569dedSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*4b569dedSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*4b569dedSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17*4b569dedSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*4b569dedSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*4b569dedSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*4b569dedSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21*4b569dedSBen Skeggs */
22*4b569dedSBen Skeggs #include "priv.h"
23*4b569dedSBen Skeggs #include <subdev/acr.h>
24*4b569dedSBen Skeggs #include <subdev/vfn.h>
25*4b569dedSBen Skeggs
26*4b569dedSBen Skeggs #include <nvfw/flcn.h>
27*4b569dedSBen Skeggs #include <nvfw/sec2.h>
28*4b569dedSBen Skeggs
29*4b569dedSBen Skeggs static int
ga102_sec2_initmsg(struct nvkm_sec2 * sec2)30*4b569dedSBen Skeggs ga102_sec2_initmsg(struct nvkm_sec2 *sec2)
31*4b569dedSBen Skeggs {
32*4b569dedSBen Skeggs struct nv_sec2_init_msg_v1 msg;
33*4b569dedSBen Skeggs int ret, i;
34*4b569dedSBen Skeggs
35*4b569dedSBen Skeggs ret = nvkm_falcon_msgq_recv_initmsg(sec2->msgq, &msg, sizeof(msg));
36*4b569dedSBen Skeggs if (ret)
37*4b569dedSBen Skeggs return ret;
38*4b569dedSBen Skeggs
39*4b569dedSBen Skeggs if (msg.hdr.unit_id != NV_SEC2_UNIT_INIT ||
40*4b569dedSBen Skeggs msg.msg_type != NV_SEC2_INIT_MSG_INIT)
41*4b569dedSBen Skeggs return -EINVAL;
42*4b569dedSBen Skeggs
43*4b569dedSBen Skeggs for (i = 0; i < ARRAY_SIZE(msg.queue_info); i++) {
44*4b569dedSBen Skeggs if (msg.queue_info[i].id == NV_SEC2_INIT_MSG_QUEUE_ID_MSGQ) {
45*4b569dedSBen Skeggs nvkm_falcon_msgq_init(sec2->msgq, msg.queue_info[i].index,
46*4b569dedSBen Skeggs msg.queue_info[i].offset,
47*4b569dedSBen Skeggs msg.queue_info[i].size);
48*4b569dedSBen Skeggs } else {
49*4b569dedSBen Skeggs nvkm_falcon_cmdq_init(sec2->cmdq, msg.queue_info[i].index,
50*4b569dedSBen Skeggs msg.queue_info[i].offset,
51*4b569dedSBen Skeggs msg.queue_info[i].size);
52*4b569dedSBen Skeggs }
53*4b569dedSBen Skeggs }
54*4b569dedSBen Skeggs
55*4b569dedSBen Skeggs return 0;
56*4b569dedSBen Skeggs }
57*4b569dedSBen Skeggs
58*4b569dedSBen Skeggs static struct nvkm_intr *
ga102_sec2_intr_vector(struct nvkm_sec2 * sec2,enum nvkm_intr_type * pvector)59*4b569dedSBen Skeggs ga102_sec2_intr_vector(struct nvkm_sec2 *sec2, enum nvkm_intr_type *pvector)
60*4b569dedSBen Skeggs {
61*4b569dedSBen Skeggs struct nvkm_device *device = sec2->engine.subdev.device;
62*4b569dedSBen Skeggs struct nvkm_falcon *falcon = &sec2->falcon;
63*4b569dedSBen Skeggs int ret;
64*4b569dedSBen Skeggs
65*4b569dedSBen Skeggs ret = ga102_flcn_select(falcon);
66*4b569dedSBen Skeggs if (ret)
67*4b569dedSBen Skeggs return ERR_PTR(ret);
68*4b569dedSBen Skeggs
69*4b569dedSBen Skeggs *pvector = nvkm_rd32(device, 0x8403e0) & 0x000000ff;
70*4b569dedSBen Skeggs return &device->vfn->intr;
71*4b569dedSBen Skeggs }
72*4b569dedSBen Skeggs
73*4b569dedSBen Skeggs static int
ga102_sec2_acr_bootstrap_falcon_callback(void * priv,struct nvfw_falcon_msg * hdr)74*4b569dedSBen Skeggs ga102_sec2_acr_bootstrap_falcon_callback(void *priv, struct nvfw_falcon_msg *hdr)
75*4b569dedSBen Skeggs {
76*4b569dedSBen Skeggs struct nv_sec2_acr_bootstrap_falcon_msg_v1 *msg =
77*4b569dedSBen Skeggs container_of(hdr, typeof(*msg), msg.hdr);
78*4b569dedSBen Skeggs struct nvkm_subdev *subdev = priv;
79*4b569dedSBen Skeggs const char *name = nvkm_acr_lsf_id(msg->falcon_id);
80*4b569dedSBen Skeggs
81*4b569dedSBen Skeggs if (msg->error_code) {
82*4b569dedSBen Skeggs nvkm_error(subdev, "ACR_BOOTSTRAP_FALCON failed for falcon %d [%s]: %08x %08x\n",
83*4b569dedSBen Skeggs msg->falcon_id, name, msg->error_code, msg->unkn08);
84*4b569dedSBen Skeggs return -EINVAL;
85*4b569dedSBen Skeggs }
86*4b569dedSBen Skeggs
87*4b569dedSBen Skeggs nvkm_debug(subdev, "%s booted\n", name);
88*4b569dedSBen Skeggs return 0;
89*4b569dedSBen Skeggs }
90*4b569dedSBen Skeggs
91*4b569dedSBen Skeggs static int
ga102_sec2_acr_bootstrap_falcon(struct nvkm_falcon * falcon,enum nvkm_acr_lsf_id id)92*4b569dedSBen Skeggs ga102_sec2_acr_bootstrap_falcon(struct nvkm_falcon *falcon, enum nvkm_acr_lsf_id id)
93*4b569dedSBen Skeggs {
94*4b569dedSBen Skeggs struct nvkm_sec2 *sec2 = container_of(falcon, typeof(*sec2), falcon);
95*4b569dedSBen Skeggs struct nv_sec2_acr_bootstrap_falcon_cmd_v1 cmd = {
96*4b569dedSBen Skeggs .cmd.hdr.unit_id = sec2->func->unit_acr,
97*4b569dedSBen Skeggs .cmd.hdr.size = sizeof(cmd),
98*4b569dedSBen Skeggs .cmd.cmd_type = NV_SEC2_ACR_CMD_BOOTSTRAP_FALCON,
99*4b569dedSBen Skeggs .flags = NV_SEC2_ACR_BOOTSTRAP_FALCON_FLAGS_RESET_YES,
100*4b569dedSBen Skeggs .falcon_id = id,
101*4b569dedSBen Skeggs };
102*4b569dedSBen Skeggs
103*4b569dedSBen Skeggs return nvkm_falcon_cmdq_send(sec2->cmdq, &cmd.cmd.hdr,
104*4b569dedSBen Skeggs ga102_sec2_acr_bootstrap_falcon_callback,
105*4b569dedSBen Skeggs &sec2->engine.subdev,
106*4b569dedSBen Skeggs msecs_to_jiffies(1000));
107*4b569dedSBen Skeggs }
108*4b569dedSBen Skeggs
109*4b569dedSBen Skeggs static const struct nvkm_acr_lsf_func
110*4b569dedSBen Skeggs ga102_sec2_acr_0 = {
111*4b569dedSBen Skeggs .bld_size = sizeof(struct flcn_bl_dmem_desc_v2),
112*4b569dedSBen Skeggs .bld_write = gp102_sec2_acr_bld_write_1,
113*4b569dedSBen Skeggs .bld_patch = gp102_sec2_acr_bld_patch_1,
114*4b569dedSBen Skeggs .bootstrap_falcons = BIT_ULL(NVKM_ACR_LSF_FECS) |
115*4b569dedSBen Skeggs BIT_ULL(NVKM_ACR_LSF_GPCCS) |
116*4b569dedSBen Skeggs BIT_ULL(NVKM_ACR_LSF_SEC2),
117*4b569dedSBen Skeggs .bootstrap_falcon = ga102_sec2_acr_bootstrap_falcon,
118*4b569dedSBen Skeggs };
119*4b569dedSBen Skeggs
120*4b569dedSBen Skeggs static const struct nvkm_falcon_func
121*4b569dedSBen Skeggs ga102_sec2_flcn = {
122*4b569dedSBen Skeggs .disable = gm200_flcn_disable,
123*4b569dedSBen Skeggs .enable = gm200_flcn_enable,
124*4b569dedSBen Skeggs .select = ga102_flcn_select,
125*4b569dedSBen Skeggs .addr2 = 0x1000,
126*4b569dedSBen Skeggs .reset_pmc = true,
127*4b569dedSBen Skeggs .reset_eng = gp102_flcn_reset_eng,
128*4b569dedSBen Skeggs .reset_prep = ga102_flcn_reset_prep,
129*4b569dedSBen Skeggs .reset_wait_mem_scrubbing = ga102_flcn_reset_wait_mem_scrubbing,
130*4b569dedSBen Skeggs .imem_dma = &ga102_flcn_dma,
131*4b569dedSBen Skeggs .dmem_pio = &gm200_flcn_dmem_pio,
132*4b569dedSBen Skeggs .dmem_dma = &ga102_flcn_dma,
133*4b569dedSBen Skeggs .emem_addr = 0x01000000,
134*4b569dedSBen Skeggs .emem_pio = &gp102_flcn_emem_pio,
135*4b569dedSBen Skeggs .start = nvkm_falcon_v1_start,
136*4b569dedSBen Skeggs .cmdq = { 0xc00, 0xc04, 8 },
137*4b569dedSBen Skeggs .msgq = { 0xc80, 0xc84, 8 },
138*4b569dedSBen Skeggs };
139*4b569dedSBen Skeggs
140*4b569dedSBen Skeggs static const struct nvkm_sec2_func
141*4b569dedSBen Skeggs ga102_sec2 = {
142*4b569dedSBen Skeggs .flcn = &ga102_sec2_flcn,
143*4b569dedSBen Skeggs .intr_vector = ga102_sec2_intr_vector,
144*4b569dedSBen Skeggs .intr = gp102_sec2_intr,
145*4b569dedSBen Skeggs .initmsg = ga102_sec2_initmsg,
146*4b569dedSBen Skeggs .unit_acr = NV_SEC2_UNIT_V2_ACR,
147*4b569dedSBen Skeggs .unit_unload = NV_SEC2_UNIT_V2_UNLOAD,
148*4b569dedSBen Skeggs };
149*4b569dedSBen Skeggs
150*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga102/sec2/desc.bin");
151*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga102/sec2/image.bin");
152*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga102/sec2/sig.bin");
153*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga102/sec2/hs_bl_sig.bin");
154*4b569dedSBen Skeggs
155*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga103/sec2/desc.bin");
156*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga103/sec2/image.bin");
157*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga103/sec2/sig.bin");
158*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga103/sec2/hs_bl_sig.bin");
159*4b569dedSBen Skeggs
160*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga104/sec2/desc.bin");
161*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga104/sec2/image.bin");
162*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga104/sec2/sig.bin");
163*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga104/sec2/hs_bl_sig.bin");
164*4b569dedSBen Skeggs
165*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga106/sec2/desc.bin");
166*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga106/sec2/image.bin");
167*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga106/sec2/sig.bin");
168*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga106/sec2/hs_bl_sig.bin");
169*4b569dedSBen Skeggs
170*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga107/sec2/desc.bin");
171*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga107/sec2/image.bin");
172*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga107/sec2/sig.bin");
173*4b569dedSBen Skeggs MODULE_FIRMWARE("nvidia/ga107/sec2/hs_bl_sig.bin");
174*4b569dedSBen Skeggs
175*4b569dedSBen Skeggs static int
ga102_sec2_load(struct nvkm_sec2 * sec2,int ver,const struct nvkm_sec2_fwif * fwif)176*4b569dedSBen Skeggs ga102_sec2_load(struct nvkm_sec2 *sec2, int ver,
177*4b569dedSBen Skeggs const struct nvkm_sec2_fwif *fwif)
178*4b569dedSBen Skeggs {
179*4b569dedSBen Skeggs return nvkm_acr_lsfw_load_sig_image_desc_v2(&sec2->engine.subdev, &sec2->falcon,
180*4b569dedSBen Skeggs NVKM_ACR_LSF_SEC2, "sec2/", ver, fwif->acr);
181*4b569dedSBen Skeggs }
182*4b569dedSBen Skeggs
183*4b569dedSBen Skeggs static const struct nvkm_sec2_fwif
184*4b569dedSBen Skeggs ga102_sec2_fwif[] = {
185*4b569dedSBen Skeggs { 0, ga102_sec2_load, &ga102_sec2, &ga102_sec2_acr_0 },
186*4b569dedSBen Skeggs { -1, gp102_sec2_nofw, &ga102_sec2 }
187*4b569dedSBen Skeggs };
188*4b569dedSBen Skeggs
189*4b569dedSBen Skeggs int
ga102_sec2_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_sec2 ** psec2)190*4b569dedSBen Skeggs ga102_sec2_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
191*4b569dedSBen Skeggs struct nvkm_sec2 **psec2)
192*4b569dedSBen Skeggs {
193*4b569dedSBen Skeggs /* TOP info wasn't updated on Turing to reflect the PRI
194*4b569dedSBen Skeggs * address change for some reason. We override it here.
195*4b569dedSBen Skeggs */
196*4b569dedSBen Skeggs return nvkm_sec2_new_(ga102_sec2_fwif, device, type, inst, 0x840000, psec2);
197*4b569dedSBen Skeggs }
198