| 1 | |
| 2 | |
| 3 |
|
| 4 | use kernel::{
|
| 5 | io::{
|
| 6 | register,
|
| 7 | register::WithBase,
|
| 8 | Io, |
| 9 | },
|
| 10 | prelude::*,
|
| 11 | sizes::SizeConstants,
|
| 12 | time, |
| 13 | };
|
| 14 |
|
| 15 | use crate::{
|
| 16 | driver::Bar0,
|
| 17 | falcon::{
|
| 18 | DmaTrfCmdSize,
|
| 19 | FalconCoreRev,
|
| 20 | FalconCoreRevSubversion,
|
| 21 | FalconEngine,
|
| 22 | FalconFbifMemType,
|
| 23 | FalconFbifTarget,
|
| 24 | FalconMem,
|
| 25 | FalconModSelAlgo,
|
| 26 | FalconSecurityModel,
|
| 27 | PFalcon2Base,
|
| 28 | PFalconBase,
|
| 29 | PeregrineCoreSelect, |
| 30 | },
|
| 31 | gpu::{
|
| 32 | Architecture,
|
| 33 | Chipset, |
| 34 | },
|
| 35 | };
|
| 36 |
|
| 37 | |
| 38 |
|
| 39 | register! {
|
| 40 | |
| 41 | pub(crate) NV_PMC_BOOT_0(u32) @ 0x00000000 {
|
| 42 | |
| 43 | 28:24 architecture_0;
|
| 44 | |
| 45 | 23:20 implementation;
|
| 46 | |
| 47 | 8:8 architecture_1;
|
| 48 | |
| 49 | 7:4 major_revision;
|
| 50 | |
| 51 | 3:0 minor_revision;
|
| 52 | }
|
| 53 |
|
| 54 | |
| 55 | pub(crate) NV_PMC_BOOT_42(u32) @ 0x00000a00 {
|
| 56 | |
| 57 | 29:24 architecture ?=> Architecture;
|
| 58 | |
| 59 | 23:20 implementation;
|
| 60 | |
| 61 | 19:16 major_revision;
|
| 62 | |
| 63 | 15:12 minor_revision;
|
| 64 | }
|
| 65 | }
|
| 66 |
|
| 67 | impl NV_PMC_BOOT_0 {
|
| 68 | pub(crate) fn is_older_than_fermi(self) -> bool {
|
| 69 | |
| 70 | const NV_PMC_BOOT_0_ARCHITECTURE_GF100: u32 = 0xc;
|
| 71 |
|
| 72 | |
| 73 | |
| 74 | self.architecture_1() == 0 && self.architecture_0() < NV_PMC_BOOT_0_ARCHITECTURE_GF100
|
| 75 | }
|
| 76 | }
|
| 77 |
|
| 78 | impl NV_PMC_BOOT_42 {
|
| 79 | |
| 80 | pub(crate) fn chipset(self) -> Result<Chipset> {
|
| 81 | self.architecture()
|
| 82 | .map(|arch| {
|
| 83 | ((arch as u32) << Self::IMPLEMENTATION_RANGE.len())
|
| 84 | | u32::from(self.implementation())
|
| 85 | })
|
| 86 | .and_then(Chipset::try_from)
|
| 87 | }
|
| 88 |
|
| 89 | |
| 90 | fn architecture_raw(self) -> u8 {
|
| 91 | ((self.into_raw() >> Self::ARCHITECTURE_RANGE.start())
|
| 92 | & ((1 << Self::ARCHITECTURE_RANGE.len()) - 1)) as u8
|
| 93 | }
|
| 94 | }
|
| 95 |
|
| 96 | impl kernel::fmt::Display for NV_PMC_BOOT_42 {
|
| 97 | fn fmt(&self, f: &mut kernel::fmt::Formatter<'_>) -> kernel::fmt::Result {
|
| 98 | write!(
|
| 99 | f,
|
| 100 | "boot42 = 0x{:08x} (architecture 0x{:x}, implementation 0x{:x})",
|
| 101 | self.inner,
|
| 102 | self.architecture_raw(),
|
| 103 | self.implementation()
|
| 104 | )
|
| 105 | }
|
| 106 | }
|
| 107 |
|
| 108 | |
| 109 |
|
| 110 | register! {
|
| 111 | pub(crate) NV_PBUS_SW_SCRATCH(u32)[64] @ 0x00001400 {}
|
| 112 | }
|
| 113 |
|
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 |
|
| 123 | register! {
|
| 124 | |
| 125 | |
| 126 | pub(crate) NV_PGC6_BSI_SECURE_SCRATCH_14(u32) @ 0x001180f8 {
|
| 127 | 26:26 boot_stage_3_handoff => bool;
|
| 128 | }
|
| 129 |
|
| 130 | |
| 131 | |
| 132 | pub(crate) NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK(u32) @ 0x00118128 {
|
| 133 | |
| 134 | 0:0 read_protection_level0 => bool;
|
| 135 | }
|
| 136 |
|
| 137 | |
| 138 | |
| 139 | pub(crate) NV_PGC6_AON_SECURE_SCRATCH_GROUP_05(u32)[1] @ 0x00118234 {}
|
| 140 |
|
| 141 | |
| 142 | pub(crate) NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT(u32)
|
| 143 | => NV_PGC6_AON_SECURE_SCRATCH_GROUP_05[0] {
|
| 144 | |
| 145 | 7:0 progress;
|
| 146 | }
|
| 147 |
|
| 148 | pub(crate) NV_PGC6_AON_SECURE_SCRATCH_GROUP_42(u32) @ 0x001183a4 {
|
| 149 | 31:0 value;
|
| 150 | }
|
| 151 |
|
| 152 | |
| 153 | pub(crate) NV_USABLE_FB_SIZE_IN_MB(u32) => NV_PGC6_AON_SECURE_SCRATCH_GROUP_42 {
|
| 154 | |
| 155 | 31:0 value;
|
| 156 | }
|
| 157 | }
|
| 158 |
|
| 159 | impl NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT {
|
| 160 | |
| 161 | pub(crate) fn completed(self) -> bool {
|
| 162 | self.progress() == 0xff
|
| 163 | }
|
| 164 | }
|
| 165 |
|
| 166 | impl NV_USABLE_FB_SIZE_IN_MB {
|
| 167 | |
| 168 | pub(crate) fn usable_fb_size(self) -> u64 {
|
| 169 | u64::from(self.value()) * u64::SZ_1M
|
| 170 | }
|
| 171 | }
|
| 172 |
|
| 173 | |
| 174 |
|
| 175 | pub(crate) const NV_FUSE_OPT_FPF_SIZE: usize = 16;
|
| 176 |
|
| 177 | register! {
|
| 178 | pub(crate) NV_FUSE_OPT_FPF_NVDEC_UCODE1_VERSION(u32)[NV_FUSE_OPT_FPF_SIZE] @ 0x00824100 {
|
| 179 | 15:0 data => u16;
|
| 180 | }
|
| 181 |
|
| 182 | pub(crate) NV_FUSE_OPT_FPF_SEC2_UCODE1_VERSION(u32)[NV_FUSE_OPT_FPF_SIZE] @ 0x00824140 {
|
| 183 | 15:0 data => u16;
|
| 184 | }
|
| 185 |
|
| 186 | pub(crate) NV_FUSE_OPT_FPF_GSP_UCODE1_VERSION(u32)[NV_FUSE_OPT_FPF_SIZE] @ 0x008241c0 {
|
| 187 | 15:0 data => u16;
|
| 188 | }
|
| 189 | }
|
| 190 |
|
| 191 | |
| 192 |
|
| 193 | register! {
|
| 194 | pub(crate) NV_PFALCON_FALCON_IRQSCLR(u32) @ PFalconBase + 0x00000004 {
|
| 195 | 6:6 swgen0 => bool;
|
| 196 | 4:4 halt => bool;
|
| 197 | }
|
| 198 |
|
| 199 | pub(crate) NV_PFALCON_FALCON_MAILBOX0(u32) @ PFalconBase + 0x00000040 {
|
| 200 | 31:0 value => u32;
|
| 201 | }
|
| 202 |
|
| 203 | pub(crate) NV_PFALCON_FALCON_MAILBOX1(u32) @ PFalconBase + 0x00000044 {
|
| 204 | 31:0 value => u32;
|
| 205 | }
|
| 206 |
|
| 207 | |
| 208 | |
| 209 | pub(crate) NV_PFALCON_FALCON_OS(u32) @ PFalconBase + 0x00000080 {
|
| 210 | 31:0 value => u32;
|
| 211 | }
|
| 212 |
|
| 213 | pub(crate) NV_PFALCON_FALCON_RM(u32) @ PFalconBase + 0x00000084 {
|
| 214 | 31:0 value => u32;
|
| 215 | }
|
| 216 |
|
| 217 | pub(crate) NV_PFALCON_FALCON_HWCFG2(u32) @ PFalconBase + 0x000000f4 {
|
| 218 | |
| 219 | 31:31 reset_ready => bool;
|
| 220 | |
| 221 | 13:13 riscv_br_priv_lockdown => bool;
|
| 222 | |
| 223 | 12:12 mem_scrubbing => bool;
|
| 224 | 10:10 riscv => bool;
|
| 225 | }
|
| 226 |
|
| 227 | pub(crate) NV_PFALCON_FALCON_CPUCTL(u32) @ PFalconBase + 0x00000100 {
|
| 228 | 6:6 alias_en => bool;
|
| 229 | 4:4 halted => bool;
|
| 230 | 1:1 startcpu => bool;
|
| 231 | }
|
| 232 |
|
| 233 | pub(crate) NV_PFALCON_FALCON_BOOTVEC(u32) @ PFalconBase + 0x00000104 {
|
| 234 | 31:0 value => u32;
|
| 235 | }
|
| 236 |
|
| 237 | pub(crate) NV_PFALCON_FALCON_DMACTL(u32) @ PFalconBase + 0x0000010c {
|
| 238 | 7:7 secure_stat => bool;
|
| 239 | 6:3 dmaq_num;
|
| 240 | 2:2 imem_scrubbing => bool;
|
| 241 | 1:1 dmem_scrubbing => bool;
|
| 242 | 0:0 require_ctx => bool;
|
| 243 | }
|
| 244 |
|
| 245 | pub(crate) NV_PFALCON_FALCON_DMATRFBASE(u32) @ PFalconBase + 0x00000110 {
|
| 246 | 31:0 base => u32;
|
| 247 | }
|
| 248 |
|
| 249 | pub(crate) NV_PFALCON_FALCON_DMATRFMOFFS(u32) @ PFalconBase + 0x00000114 {
|
| 250 | 23:0 offs;
|
| 251 | }
|
| 252 |
|
| 253 | pub(crate) NV_PFALCON_FALCON_DMATRFCMD(u32) @ PFalconBase + 0x00000118 {
|
| 254 | 16:16 set_dmtag;
|
| 255 | 14:12 ctxdma;
|
| 256 | 10:8 size ?=> DmaTrfCmdSize;
|
| 257 | 5:5 is_write => bool;
|
| 258 | 4:4 imem => bool;
|
| 259 | 3:2 sec;
|
| 260 | 1:1 idle => bool;
|
| 261 | 0:0 full => bool;
|
| 262 | }
|
| 263 |
|
| 264 | pub(crate) NV_PFALCON_FALCON_DMATRFFBOFFS(u32) @ PFalconBase + 0x0000011c {
|
| 265 | 31:0 offs => u32;
|
| 266 | }
|
| 267 |
|
| 268 | pub(crate) NV_PFALCON_FALCON_DMATRFBASE1(u32) @ PFalconBase + 0x00000128 {
|
| 269 | 8:0 base;
|
| 270 | }
|
| 271 |
|
| 272 | pub(crate) NV_PFALCON_FALCON_HWCFG1(u32) @ PFalconBase + 0x0000012c {
|
| 273 | |
| 274 | 7:6 core_rev_subversion => FalconCoreRevSubversion;
|
| 275 | |
| 276 | 5:4 security_model ?=> FalconSecurityModel;
|
| 277 | |
| 278 | 3:0 core_rev ?=> FalconCoreRev;
|
| 279 | }
|
| 280 |
|
| 281 | pub(crate) NV_PFALCON_FALCON_CPUCTL_ALIAS(u32) @ PFalconBase + 0x00000130 {
|
| 282 | 1:1 startcpu => bool;
|
| 283 | }
|
| 284 |
|
| 285 | |
| 286 | pub(crate) NV_PFALCON_FALCON_IMEMC(u32)[4, stride = 16] @ PFalconBase + 0x00000180 {
|
| 287 | |
| 288 | 28:28 secure => bool;
|
| 289 | |
| 290 | 24:24 aincw => bool;
|
| 291 | |
| 292 | 15:0 offs;
|
| 293 | }
|
| 294 |
|
| 295 | |
| 296 | |
| 297 | pub(crate) NV_PFALCON_FALCON_IMEMD(u32)[4, stride = 16] @ PFalconBase + 0x00000184 {
|
| 298 | 31:0 data;
|
| 299 | }
|
| 300 |
|
| 301 | |
| 302 | pub(crate) NV_PFALCON_FALCON_IMEMT(u32)[4, stride = 16] @ PFalconBase + 0x00000188 {
|
| 303 | 15:0 tag;
|
| 304 | }
|
| 305 |
|
| 306 | |
| 307 | pub(crate) NV_PFALCON_FALCON_DMEMC(u32)[8, stride = 8] @ PFalconBase + 0x000001c0 {
|
| 308 | |
| 309 | 24:24 aincw => bool;
|
| 310 | |
| 311 | 15:0 offs;
|
| 312 | }
|
| 313 |
|
| 314 | |
| 315 | |
| 316 | pub(crate) NV_PFALCON_FALCON_DMEMD(u32)[8, stride = 8] @ PFalconBase + 0x000001c4 {
|
| 317 | 31:0 data;
|
| 318 | }
|
| 319 |
|
| 320 | |
| 321 | |
| 322 | pub(crate) NV_PFALCON_FALCON_ENGINE(u32) @ PFalconBase + 0x000003c0 {
|
| 323 | 0:0 reset => bool;
|
| 324 | }
|
| 325 |
|
| 326 | pub(crate) NV_PFALCON_FBIF_TRANSCFG(u32)[8] @ PFalconBase + 0x00000600 {
|
| 327 | 2:2 mem_type => FalconFbifMemType;
|
| 328 | 1:0 target ?=> FalconFbifTarget;
|
| 329 | }
|
| 330 |
|
| 331 | pub(crate) NV_PFALCON_FBIF_CTL(u32) @ PFalconBase + 0x00000624 {
|
| 332 | 7:7 allow_phys_no_ctx => bool;
|
| 333 | }
|
| 334 |
|
| 335 | |
| 336 | |
| 337 |
|
| 338 | pub(crate) NV_PFALCON_FALCON_EMEMC(u32) @ PFalconBase + 0x00000ac0 {
|
| 339 | |
| 340 | 7:2 offs;
|
| 341 | |
| 342 | 15:8 blk;
|
| 343 | |
| 344 | 24:24 aincw => bool;
|
| 345 | |
| 346 | 25:25 aincr => bool;
|
| 347 | }
|
| 348 |
|
| 349 | pub(crate) NV_PFALCON_FALCON_EMEMD(u32) @ PFalconBase + 0x00000ac4 {
|
| 350 | 31:0 data => u32;
|
| 351 | }
|
| 352 | }
|
| 353 |
|
| 354 | impl NV_PFALCON_FALCON_DMACTL {
|
| 355 | |
| 356 | pub(crate) fn mem_scrubbing_done(self) -> bool {
|
| 357 | !self.dmem_scrubbing() && !self.imem_scrubbing()
|
| 358 | }
|
| 359 | }
|
| 360 |
|
| 361 | impl NV_PFALCON_FALCON_DMATRFCMD {
|
| 362 | |
| 363 | pub(crate) fn with_falcon_mem(self, mem: FalconMem) -> Self {
|
| 364 | let this = self.with_imem(mem != FalconMem::Dmem);
|
| 365 |
|
| 366 | match mem {
|
| 367 | FalconMem::ImemSecure => this.with_const_sec::<1>(),
|
| 368 | _ => this.with_const_sec::<0>(),
|
| 369 | }
|
| 370 | }
|
| 371 | }
|
| 372 |
|
| 373 | impl NV_PFALCON_FALCON_ENGINE {
|
| 374 | |
| 375 | pub(crate) fn reset_engine<E: FalconEngine>(bar: Bar0<'_>) {
|
| 376 | bar.update(Self::of::<E>(), |r| r.with_reset(true));
|
| 377 |
|
| 378 | |
| 379 | time::delay::fsleep(time::Delta::from_micros(10));
|
| 380 |
|
| 381 | bar.update(Self::of::<E>(), |r| r.with_reset(false));
|
| 382 | }
|
| 383 | }
|
| 384 |
|
| 385 | impl NV_PFALCON_FALCON_HWCFG2 {
|
| 386 | |
| 387 | pub(crate) fn mem_scrubbing_done(self) -> bool {
|
| 388 | !self.mem_scrubbing()
|
| 389 | }
|
| 390 | }
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 | register! {
|
| 395 | pub(crate) NV_PFALCON2_FALCON_MOD_SEL(u32) @ PFalcon2Base + 0x00000180 {
|
| 396 | 7:0 algo ?=> FalconModSelAlgo;
|
| 397 | }
|
| 398 |
|
| 399 | pub(crate) NV_PFALCON2_FALCON_BROM_CURR_UCODE_ID(u32) @ PFalcon2Base + 0x00000198 {
|
| 400 | 7:0 ucode_id => u8;
|
| 401 | }
|
| 402 |
|
| 403 | pub(crate) NV_PFALCON2_FALCON_BROM_ENGIDMASK(u32) @ PFalcon2Base + 0x0000019c {
|
| 404 | 31:0 value => u32;
|
| 405 | }
|
| 406 |
|
| 407 | |
| 408 | |
| 409 | pub(crate) NV_PFALCON2_FALCON_BROM_PARAADDR(u32)[1] @ PFalcon2Base + 0x00000210 {
|
| 410 | 31:0 value => u32;
|
| 411 | }
|
| 412 | }
|
| 413 |
|
| 414 | |
| 415 |
|
| 416 | register! {
|
| 417 | |
| 418 | |
| 419 | pub(crate) NV_PRISCV_RISCV_CORE_SWITCH_RISCV_STATUS(u32) @ PFalcon2Base + 0x00000240 {
|
| 420 | |
| 421 | 0:0 active_stat => bool;
|
| 422 | }
|
| 423 |
|
| 424 | |
| 425 | pub(crate) NV_PRISCV_RISCV_CPUCTL(u32) @ PFalcon2Base + 0x00000388 {
|
| 426 | 7:7 active_stat => bool;
|
| 427 | 4:4 halted => bool;
|
| 428 | }
|
| 429 |
|
| 430 | |
| 431 | pub(crate) NV_PRISCV_RISCV_BCR_CTRL(u32) @ PFalcon2Base + 0x00000668 {
|
| 432 | 8:8 br_fetch => bool;
|
| 433 | 4:4 core_select => PeregrineCoreSelect;
|
| 434 | 0:0 valid => bool;
|
| 435 | }
|
| 436 | }
|
| 437 |
|
| 438 | |
| 439 | |
| 440 |
|
| 441 | register! {
|
| 442 | pub(crate) NV_PFSP_QUEUE_HEAD(u32)[8] @ 0x008f2c00 {
|
| 443 | 31:0 address => u32;
|
| 444 | }
|
| 445 |
|
| 446 | pub(crate) NV_PFSP_QUEUE_TAIL(u32)[8] @ 0x008f2c04 {
|
| 447 | 31:0 address => u32;
|
| 448 | }
|
| 449 |
|
| 450 | pub(crate) NV_PFSP_MSGQ_HEAD(u32)[8] @ 0x008f2c80 {
|
| 451 | 31:0 val => u32;
|
| 452 | }
|
| 453 |
|
| 454 | pub(crate) NV_PFSP_MSGQ_TAIL(u32)[8] @ 0x008f2c84 {
|
| 455 | 31:0 val => u32;
|
| 456 | }
|
| 457 | }
|
| 458 |
|
| 459 | |
| 460 | |
| 461 |
|
| 462 | pub(crate) mod gm107 {
|
| 463 | use kernel::io::register;
|
| 464 |
|
| 465 | |
| 466 |
|
| 467 | register! {
|
| 468 | pub(crate) NV_FUSE_STATUS_OPT_DISPLAY(u32) @ 0x00021c04 {
|
| 469 | 0:0 display_disabled => bool;
|
| 470 | }
|
| 471 | }
|
| 472 | }
|
| 473 |
|
| 474 | pub(crate) mod ga100 {
|
| 475 | use kernel::io::register;
|
| 476 |
|
| 477 | |
| 478 |
|
| 479 | register! {
|
| 480 | pub(crate) NV_FUSE_STATUS_OPT_DISPLAY(u32) @ 0x00820c04 {
|
| 481 | 0:0 display_disabled => bool;
|
| 482 | }
|
| 483 | }
|
| 484 | }
|
| 485 |
|
| 486 | pub(crate) const NV_THERM_I2CS_SCRATCH_FSP_BOOT_COMPLETE_STATUS_SUCCESS: u32 = 0xff;
|
| 487 |
|
| 488 | pub(crate) mod gh100 {
|
| 489 | use kernel::io::register;
|
| 490 |
|
| 491 | |
| 492 |
|
| 493 | register! {
|
| 494 | pub(crate) NV_THERM_I2CS_SCRATCH(u32) @ 0x000200bc {
|
| 495 | 31:0 data;
|
| 496 | }
|
| 497 |
|
| 498 | |
| 499 | pub(crate) NV_THERM_I2CS_SCRATCH_FSP_BOOT_COMPLETE(u32) => NV_THERM_I2CS_SCRATCH {
|
| 500 | 31:0 fsp_boot_complete;
|
| 501 | }
|
| 502 | }
|
| 503 | }
|
| 504 |
|
| 505 | pub(crate) mod gb202 {
|
| 506 | use kernel::io::register;
|
| 507 |
|
| 508 | |
| 509 |
|
| 510 | register! {
|
| 511 | pub(crate) NV_THERM_I2CS_SCRATCH(u32) @ 0x00ad00bc {
|
| 512 | 31:0 data;
|
| 513 | }
|
| 514 |
|
| 515 | |
| 516 | pub(crate) NV_THERM_I2CS_SCRATCH_FSP_BOOT_COMPLETE(u32) => NV_THERM_I2CS_SCRATCH {
|
| 517 | 31:0 fsp_boot_complete;
|
| 518 | }
|
| 519 | }
|
| 520 | }
|