Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | /* * Copyright 2022 Red Hat Inc. * * 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. */ #include "priv.h" #include <core/memory.h> #include <subdev/mc.h> #include <subdev/timer.h> void gm200_flcn_tracepc(struct nvkm_falcon *falcon) { u32 sctl = nvkm_falcon_rd32(falcon, 0x240); u32 tidx = nvkm_falcon_rd32(falcon, 0x148); int nr = (tidx & 0x00ff0000) >> 16, sp, ip; FLCN_ERR(falcon, "TRACEPC SCTL %08x TIDX %08x", sctl, tidx); for (sp = 0; sp < nr; sp++) { nvkm_falcon_wr32(falcon, 0x148, sp); ip = nvkm_falcon_rd32(falcon, 0x14c); FLCN_ERR(falcon, "TRACEPC: %08x", ip); } } static void gm200_flcn_pio_dmem_rd(struct nvkm_falcon *falcon, u8 port, const u8 *img, int len) { while (len >= 4) { *(u32 *)img = nvkm_falcon_rd32(falcon, 0x1c4 + (port * 8)); img += 4; len -= 4; } /* Sigh. Tegra PMU FW's init message... */ if (len) { u32 data = nvkm_falcon_rd32(falcon, 0x1c4 + (port * 8)); while (len--) { *(u8 *)img++ = data & 0xff; data >>= 8; } } } static void gm200_flcn_pio_dmem_rd_init(struct nvkm_falcon *falcon, u8 port, u32 dmem_base) { nvkm_falcon_wr32(falcon, 0x1c0 + (port * 8), BIT(25) | dmem_base); } static void gm200_flcn_pio_dmem_wr(struct nvkm_falcon *falcon, u8 port, const u8 *img, int len, u16 tag) { while (len >= 4) { nvkm_falcon_wr32(falcon, 0x1c4 + (port * 8), *(u32 *)img); img += 4; len -= 4; } WARN_ON(len); } static void gm200_flcn_pio_dmem_wr_init(struct nvkm_falcon *falcon, u8 port, bool sec, u32 dmem_base) { nvkm_falcon_wr32(falcon, 0x1c0 + (port * 8), BIT(24) | dmem_base); } const struct nvkm_falcon_func_pio gm200_flcn_dmem_pio = { .min = 1, .max = 0x100, .wr_init = gm200_flcn_pio_dmem_wr_init, .wr = gm200_flcn_pio_dmem_wr, .rd_init = gm200_flcn_pio_dmem_rd_init, .rd = gm200_flcn_pio_dmem_rd, }; static void gm200_flcn_pio_imem_wr_init(struct nvkm_falcon *falcon, u8 port, bool sec, u32 imem_base) { nvkm_falcon_wr32(falcon, 0x180 + (port * 0x10), (sec ? BIT(28) : 0) | BIT(24) | imem_base); } static void gm200_flcn_pio_imem_wr(struct nvkm_falcon *falcon, u8 port, const u8 *img, int len, u16 tag) { nvkm_falcon_wr32(falcon, 0x188 + (port * 0x10), tag++); while (len >= 4) { nvkm_falcon_wr32(falcon, 0x184 + (port * 0x10), *(u32 *)img); img += 4; len -= 4; } } const struct nvkm_falcon_func_pio gm200_flcn_imem_pio = { .min = 0x100, .max = 0x100, .wr_init = gm200_flcn_pio_imem_wr_init, .wr = gm200_flcn_pio_imem_wr, }; int gm200_flcn_bind_stat(struct nvkm_falcon *falcon, bool intr) { if (intr && !(nvkm_falcon_rd32(falcon, 0x008) & 0x00000008)) return -1; return (nvkm_falcon_rd32(falcon, 0x0dc) & 0x00007000) >> 12; } void gm200_flcn_bind_inst(struct nvkm_falcon *falcon, int target, u64 addr) { nvkm_falcon_mask(falcon, 0x604, 0x00000007, 0x00000000); /* DMAIDX_VIRT */ nvkm_falcon_wr32(falcon, 0x054, (1 << 30) | (target << 28) | (addr >> 12)); nvkm_falcon_mask(falcon, 0x090, 0x00010000, 0x00010000); nvkm_falcon_mask(falcon, 0x0a4, 0x00000008, 0x00000008); } int gm200_flcn_reset_wait_mem_scrubbing(struct nvkm_falcon *falcon) { nvkm_falcon_mask(falcon, 0x040, 0x00000000, 0x00000000); if (nvkm_msec(falcon->owner->device, 10, if (!(nvkm_falcon_rd32(falcon, 0x10c) & 0x00000006)) break; ) < 0) return -ETIMEDOUT; return 0; } int gm200_flcn_enable(struct nvkm_falcon *falcon) { struct nvkm_device *device = falcon->owner->device; int ret; if (falcon->func->reset_eng) { ret = falcon->func->reset_eng(falcon); if (ret) return ret; } if (falcon->func->select) { ret = falcon->func->select(falcon); if (ret) return ret; } if (falcon->func->reset_pmc) nvkm_mc_enable(device, falcon->owner->type, falcon->owner->inst); ret = falcon->func->reset_wait_mem_scrubbing(falcon); if (ret) return ret; nvkm_falcon_wr32(falcon, 0x084, nvkm_rd32(device, 0x000000)); return 0; } int gm200_flcn_disable(struct nvkm_falcon *falcon) { struct nvkm_device *device = falcon->owner->device; int ret; if (falcon->func->select) { ret = falcon->func->select(falcon); if (ret) return ret; } nvkm_falcon_mask(falcon, 0x048, 0x00000003, 0x00000000); nvkm_falcon_wr32(falcon, 0x014, 0xffffffff); if (falcon->func->reset_pmc) { if (falcon->func->reset_prep) { ret = falcon->func->reset_prep(falcon); if (ret) return ret; } nvkm_mc_disable(device, falcon->owner->type, falcon->owner->inst); } if (falcon->func->reset_eng) { ret = falcon->func->reset_eng(falcon); if (ret) return ret; } return 0; } int gm200_flcn_fw_boot(struct nvkm_falcon_fw *fw, u32 *pmbox0, u32 *pmbox1, u32 mbox0_ok, u32 irqsclr) { struct nvkm_falcon *falcon = fw->falcon; u32 mbox0, mbox1; int ret = 0; nvkm_falcon_wr32(falcon, 0x040, pmbox0 ? *pmbox0 : 0xcafebeef); if (pmbox1) nvkm_falcon_wr32(falcon, 0x044, *pmbox1); nvkm_falcon_wr32(falcon, 0x104, fw->boot_addr); nvkm_falcon_wr32(falcon, 0x100, 0x00000002); if (nvkm_msec(falcon->owner->device, 2000, if (nvkm_falcon_rd32(falcon, 0x100) & 0x00000010) break; ) < 0) ret = -ETIMEDOUT; mbox0 = nvkm_falcon_rd32(falcon, 0x040); mbox1 = nvkm_falcon_rd32(falcon, 0x044); if (FLCN_ERRON(falcon, ret || mbox0 != mbox0_ok, "mbox %08x %08x", mbox0, mbox1)) ret = ret ?: -EIO; if (irqsclr) nvkm_falcon_mask(falcon, 0x004, 0xffffffff, irqsclr); return ret; } int gm200_flcn_fw_load(struct nvkm_falcon_fw *fw) { struct nvkm_falcon *falcon = fw->falcon; int target, ret; if (fw->inst) { nvkm_falcon_mask(falcon, 0x048, 0x00000001, 0x00000001); switch (nvkm_memory_target(fw->inst)) { case NVKM_MEM_TARGET_VRAM: target = 0; break; case NVKM_MEM_TARGET_HOST: target = 2; break; case NVKM_MEM_TARGET_NCOH: target = 3; break; default: WARN_ON(1); return -EINVAL; } falcon->func->bind_inst(falcon, target, nvkm_memory_addr(fw->inst)); if (nvkm_msec(falcon->owner->device, 10, if (falcon->func->bind_stat(falcon, falcon->func->bind_intr) == 5) break; ) < 0) return -ETIMEDOUT; nvkm_falcon_mask(falcon, 0x004, 0x00000008, 0x00000008); nvkm_falcon_mask(falcon, 0x058, 0x00000002, 0x00000002); if (nvkm_msec(falcon->owner->device, 10, if (falcon->func->bind_stat(falcon, false) == 0) break; ) < 0) return -ETIMEDOUT; } else { nvkm_falcon_mask(falcon, 0x624, 0x00000080, 0x00000080); nvkm_falcon_wr32(falcon, 0x10c, 0x00000000); } if (fw->boot) { switch (nvkm_memory_target(&fw->fw.mem.memory)) { case NVKM_MEM_TARGET_VRAM: target = 4; break; case NVKM_MEM_TARGET_HOST: target = 5; break; case NVKM_MEM_TARGET_NCOH: target = 6; break; default: WARN_ON(1); return -EINVAL; } ret = nvkm_falcon_pio_wr(falcon, fw->boot, 0, 0, IMEM, falcon->code.limit - fw->boot_size, fw->boot_size, fw->boot_addr >> 8, false); if (ret) return ret; return fw->func->load_bld(fw); } ret = nvkm_falcon_pio_wr(falcon, fw->fw.img + fw->nmem_base_img, fw->nmem_base_img, 0, IMEM, fw->nmem_base, fw->nmem_size, fw->nmem_base >> 8, false); if (ret) return ret; ret = nvkm_falcon_pio_wr(falcon, fw->fw.img + fw->imem_base_img, fw->imem_base_img, 0, IMEM, fw->imem_base, fw->imem_size, fw->imem_base >> 8, true); if (ret) return ret; ret = nvkm_falcon_pio_wr(falcon, fw->fw.img + fw->dmem_base_img, fw->dmem_base_img, 0, DMEM, fw->dmem_base, fw->dmem_size, 0, false); if (ret) return ret; return 0; } int gm200_flcn_fw_reset(struct nvkm_falcon_fw *fw) { return nvkm_falcon_reset(fw->falcon); } int gm200_flcn_fw_signature(struct nvkm_falcon_fw *fw, u32 *sig_base_src) { struct nvkm_falcon *falcon = fw->falcon; u32 addr = falcon->func->debug; int ret = 0; if (addr) { ret = nvkm_falcon_enable(falcon); if (ret) return ret; if (nvkm_falcon_rd32(falcon, addr) & 0x00100000) { *sig_base_src = fw->sig_base_dbg; return 1; } } return ret; } const struct nvkm_falcon_fw_func gm200_flcn_fw = { .signature = gm200_flcn_fw_signature, .reset = gm200_flcn_fw_reset, .load = gm200_flcn_fw_load, .boot = gm200_flcn_fw_boot, }; |