1 // SPDX-License-Identifier: GPL-2.0 2 3 // Required to retain the original register names used by OpenRM, which are all capital snake case 4 // but are mapped to types. 5 #![allow(non_camel_case_types)] 6 7 #[macro_use] 8 pub(crate) mod macros; 9 10 use kernel::prelude::*; 11 12 use crate::{ 13 falcon::{ 14 DmaTrfCmdSize, 15 FalconCoreRev, 16 FalconCoreRevSubversion, 17 FalconFbifMemType, 18 FalconFbifTarget, 19 FalconModSelAlgo, 20 FalconSecurityModel, 21 PFalcon2Base, 22 PFalconBase, 23 PeregrineCoreSelect, // 24 }, 25 gpu::{ 26 Architecture, 27 Chipset, // 28 }, 29 }; 30 31 // PMC 32 33 register!(NV_PMC_BOOT_0 @ 0x00000000, "Basic revision information about the GPU" { 34 3:0 minor_revision as u8, "Minor revision of the chip"; 35 7:4 major_revision as u8, "Major revision of the chip"; 36 8:8 architecture_1 as u8, "MSB of the architecture"; 37 23:20 implementation as u8, "Implementation version of the architecture"; 38 28:24 architecture_0 as u8, "Lower bits of the architecture"; 39 }); 40 41 impl NV_PMC_BOOT_0 { 42 /// Combines `architecture_0` and `architecture_1` to obtain the architecture of the chip. 43 pub(crate) fn architecture(self) -> Result<Architecture> { 44 Architecture::try_from( 45 self.architecture_0() | (self.architecture_1() << Self::ARCHITECTURE_0_RANGE.len()), 46 ) 47 } 48 49 /// Combines `architecture` and `implementation` to obtain a code unique to the chipset. 50 pub(crate) fn chipset(self) -> Result<Chipset> { 51 self.architecture() 52 .map(|arch| { 53 ((arch as u32) << Self::IMPLEMENTATION_RANGE.len()) 54 | u32::from(self.implementation()) 55 }) 56 .and_then(Chipset::try_from) 57 } 58 } 59 60 // PBUS 61 62 register!(NV_PBUS_SW_SCRATCH @ 0x00001400[64] {}); 63 64 register!(NV_PBUS_SW_SCRATCH_0E_FRTS_ERR => NV_PBUS_SW_SCRATCH[0xe], 65 "scratch register 0xe used as FRTS firmware error code" { 66 31:16 frts_err_code as u16; 67 }); 68 69 // PFB 70 71 // The following two registers together hold the physical system memory address that is used by the 72 // GPU to perform sysmembar operations (see `fb::SysmemFlush`). 73 74 register!(NV_PFB_NISO_FLUSH_SYSMEM_ADDR @ 0x00100c10 { 75 31:0 adr_39_08 as u32; 76 }); 77 78 register!(NV_PFB_NISO_FLUSH_SYSMEM_ADDR_HI @ 0x00100c40 { 79 23:0 adr_63_40 as u32; 80 }); 81 82 register!(NV_PFB_PRI_MMU_LOCAL_MEMORY_RANGE @ 0x00100ce0 { 83 3:0 lower_scale as u8; 84 9:4 lower_mag as u8; 85 30:30 ecc_mode_enabled as bool; 86 }); 87 88 impl NV_PFB_PRI_MMU_LOCAL_MEMORY_RANGE { 89 /// Returns the usable framebuffer size, in bytes. 90 pub(crate) fn usable_fb_size(self) -> u64 { 91 let size = (u64::from(self.lower_mag()) << u64::from(self.lower_scale())) 92 * kernel::sizes::SZ_1M as u64; 93 94 if self.ecc_mode_enabled() { 95 // Remove the amount of memory reserved for ECC (one per 16 units). 96 size / 16 * 15 97 } else { 98 size 99 } 100 } 101 } 102 103 register!(NV_PFB_PRI_MMU_WPR2_ADDR_LO@0x001fa824 { 104 31:4 lo_val as u32, "Bits 12..40 of the lower (inclusive) bound of the WPR2 region"; 105 }); 106 107 impl NV_PFB_PRI_MMU_WPR2_ADDR_LO { 108 /// Returns the lower (inclusive) bound of the WPR2 region. 109 pub(crate) fn lower_bound(self) -> u64 { 110 u64::from(self.lo_val()) << 12 111 } 112 } 113 114 register!(NV_PFB_PRI_MMU_WPR2_ADDR_HI@0x001fa828 { 115 31:4 hi_val as u32, "Bits 12..40 of the higher (exclusive) bound of the WPR2 region"; 116 }); 117 118 impl NV_PFB_PRI_MMU_WPR2_ADDR_HI { 119 /// Returns the higher (exclusive) bound of the WPR2 region. 120 /// 121 /// A value of zero means the WPR2 region is not set. 122 pub(crate) fn higher_bound(self) -> u64 { 123 u64::from(self.hi_val()) << 12 124 } 125 } 126 127 // PGC6 register space. 128 // 129 // `GC6` is a GPU low-power state where VRAM is in self-refresh and the GPU is powered down (except 130 // for power rails needed to keep self-refresh working and important registers and hardware 131 // blocks). 132 // 133 // These scratch registers remain powered on even in a low-power state and have a designated group 134 // number. 135 136 // Privilege level mask register. It dictates whether the host CPU has privilege to access the 137 // `PGC6_AON_SECURE_SCRATCH_GROUP_05` register (which it needs to read GFW_BOOT). 138 register!(NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK @ 0x00118128, 139 "Privilege level mask register" { 140 0:0 read_protection_level0 as bool, "Set after FWSEC lowers its protection level"; 141 }); 142 143 // OpenRM defines this as a register array, but doesn't specify its size and only uses its first 144 // element. Be conservative until we know the actual size or need to use more registers. 145 register!(NV_PGC6_AON_SECURE_SCRATCH_GROUP_05 @ 0x00118234[1] {}); 146 147 register!( 148 NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT => NV_PGC6_AON_SECURE_SCRATCH_GROUP_05[0], 149 "Scratch group 05 register 0 used as GFW boot progress indicator" { 150 7:0 progress as u8, "Progress of GFW boot (0xff means completed)"; 151 } 152 ); 153 154 impl NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT { 155 /// Returns `true` if GFW boot is completed. 156 pub(crate) fn completed(self) -> bool { 157 self.progress() == 0xff 158 } 159 } 160 161 register!(NV_PGC6_AON_SECURE_SCRATCH_GROUP_42 @ 0x001183a4 { 162 31:0 value as u32; 163 }); 164 165 register!( 166 NV_USABLE_FB_SIZE_IN_MB => NV_PGC6_AON_SECURE_SCRATCH_GROUP_42, 167 "Scratch group 42 register used as framebuffer size" { 168 31:0 value as u32, "Usable framebuffer size, in megabytes"; 169 } 170 ); 171 172 impl NV_USABLE_FB_SIZE_IN_MB { 173 /// Returns the usable framebuffer size, in bytes. 174 pub(crate) fn usable_fb_size(self) -> u64 { 175 u64::from(self.value()) * kernel::sizes::SZ_1M as u64 176 } 177 } 178 179 // PDISP 180 181 register!(NV_PDISP_VGA_WORKSPACE_BASE @ 0x00625f04 { 182 3:3 status_valid as bool, "Set if the `addr` field is valid"; 183 31:8 addr as u32, "VGA workspace base address divided by 0x10000"; 184 }); 185 186 impl NV_PDISP_VGA_WORKSPACE_BASE { 187 /// Returns the base address of the VGA workspace, or `None` if none exists. 188 pub(crate) fn vga_workspace_addr(self) -> Option<u64> { 189 if self.status_valid() { 190 Some(u64::from(self.addr()) << 16) 191 } else { 192 None 193 } 194 } 195 } 196 197 // FUSE 198 199 pub(crate) const NV_FUSE_OPT_FPF_SIZE: usize = 16; 200 201 register!(NV_FUSE_OPT_FPF_NVDEC_UCODE1_VERSION @ 0x00824100[NV_FUSE_OPT_FPF_SIZE] { 202 15:0 data as u16; 203 }); 204 205 register!(NV_FUSE_OPT_FPF_SEC2_UCODE1_VERSION @ 0x00824140[NV_FUSE_OPT_FPF_SIZE] { 206 15:0 data as u16; 207 }); 208 209 register!(NV_FUSE_OPT_FPF_GSP_UCODE1_VERSION @ 0x008241c0[NV_FUSE_OPT_FPF_SIZE] { 210 15:0 data as u16; 211 }); 212 213 // PFALCON 214 215 register!(NV_PFALCON_FALCON_IRQSCLR @ PFalconBase[0x00000004] { 216 4:4 halt as bool; 217 6:6 swgen0 as bool; 218 }); 219 220 register!(NV_PFALCON_FALCON_MAILBOX0 @ PFalconBase[0x00000040] { 221 31:0 value as u32; 222 }); 223 224 register!(NV_PFALCON_FALCON_MAILBOX1 @ PFalconBase[0x00000044] { 225 31:0 value as u32; 226 }); 227 228 register!(NV_PFALCON_FALCON_RM @ PFalconBase[0x00000084] { 229 31:0 value as u32; 230 }); 231 232 register!(NV_PFALCON_FALCON_HWCFG2 @ PFalconBase[0x000000f4] { 233 10:10 riscv as bool; 234 12:12 mem_scrubbing as bool, "Set to 0 after memory scrubbing is completed"; 235 31:31 reset_ready as bool, "Signal indicating that reset is completed (GA102+)"; 236 }); 237 238 impl NV_PFALCON_FALCON_HWCFG2 { 239 /// Returns `true` if memory scrubbing is completed. 240 pub(crate) fn mem_scrubbing_done(self) -> bool { 241 !self.mem_scrubbing() 242 } 243 } 244 245 register!(NV_PFALCON_FALCON_CPUCTL @ PFalconBase[0x00000100] { 246 1:1 startcpu as bool; 247 4:4 halted as bool; 248 6:6 alias_en as bool; 249 }); 250 251 register!(NV_PFALCON_FALCON_BOOTVEC @ PFalconBase[0x00000104] { 252 31:0 value as u32; 253 }); 254 255 register!(NV_PFALCON_FALCON_DMACTL @ PFalconBase[0x0000010c] { 256 0:0 require_ctx as bool; 257 1:1 dmem_scrubbing as bool; 258 2:2 imem_scrubbing as bool; 259 6:3 dmaq_num as u8; 260 7:7 secure_stat as bool; 261 }); 262 263 register!(NV_PFALCON_FALCON_DMATRFBASE @ PFalconBase[0x00000110] { 264 31:0 base as u32; 265 }); 266 267 register!(NV_PFALCON_FALCON_DMATRFMOFFS @ PFalconBase[0x00000114] { 268 23:0 offs as u32; 269 }); 270 271 register!(NV_PFALCON_FALCON_DMATRFCMD @ PFalconBase[0x00000118] { 272 0:0 full as bool; 273 1:1 idle as bool; 274 3:2 sec as u8; 275 4:4 imem as bool; 276 5:5 is_write as bool; 277 10:8 size as u8 ?=> DmaTrfCmdSize; 278 14:12 ctxdma as u8; 279 16:16 set_dmtag as u8; 280 }); 281 282 register!(NV_PFALCON_FALCON_DMATRFFBOFFS @ PFalconBase[0x0000011c] { 283 31:0 offs as u32; 284 }); 285 286 register!(NV_PFALCON_FALCON_DMATRFBASE1 @ PFalconBase[0x00000128] { 287 8:0 base as u16; 288 }); 289 290 register!(NV_PFALCON_FALCON_HWCFG1 @ PFalconBase[0x0000012c] { 291 3:0 core_rev as u8 ?=> FalconCoreRev, "Core revision"; 292 5:4 security_model as u8 ?=> FalconSecurityModel, "Security model"; 293 7:6 core_rev_subversion as u8 ?=> FalconCoreRevSubversion, "Core revision subversion"; 294 }); 295 296 register!(NV_PFALCON_FALCON_CPUCTL_ALIAS @ PFalconBase[0x00000130] { 297 1:1 startcpu as bool; 298 }); 299 300 // Actually known as `NV_PSEC_FALCON_ENGINE` and `NV_PGSP_FALCON_ENGINE` depending on the falcon 301 // instance. 302 register!(NV_PFALCON_FALCON_ENGINE @ PFalconBase[0x000003c0] { 303 0:0 reset as bool; 304 }); 305 306 register!(NV_PFALCON_FBIF_TRANSCFG @ PFalconBase[0x00000600[8]] { 307 1:0 target as u8 ?=> FalconFbifTarget; 308 2:2 mem_type as bool => FalconFbifMemType; 309 }); 310 311 register!(NV_PFALCON_FBIF_CTL @ PFalconBase[0x00000624] { 312 7:7 allow_phys_no_ctx as bool; 313 }); 314 315 /* PFALCON2 */ 316 317 register!(NV_PFALCON2_FALCON_MOD_SEL @ PFalcon2Base[0x00000180] { 318 7:0 algo as u8 ?=> FalconModSelAlgo; 319 }); 320 321 register!(NV_PFALCON2_FALCON_BROM_CURR_UCODE_ID @ PFalcon2Base[0x00000198] { 322 7:0 ucode_id as u8; 323 }); 324 325 register!(NV_PFALCON2_FALCON_BROM_ENGIDMASK @ PFalcon2Base[0x0000019c] { 326 31:0 value as u32; 327 }); 328 329 // OpenRM defines this as a register array, but doesn't specify its size and only uses its first 330 // element. Be conservative until we know the actual size or need to use more registers. 331 register!(NV_PFALCON2_FALCON_BROM_PARAADDR @ PFalcon2Base[0x00000210[1]] { 332 31:0 value as u32; 333 }); 334 335 // PRISCV 336 337 register!(NV_PRISCV_RISCV_BCR_CTRL @ PFalconBase[0x00001668] { 338 0:0 valid as bool; 339 4:4 core_select as bool => PeregrineCoreSelect; 340 8:8 br_fetch as bool; 341 }); 342 343 // The modules below provide registers that are not identical on all supported chips. They should 344 // only be used in HAL modules. 345 346 pub(crate) mod gm107 { 347 // FUSE 348 349 register!(NV_FUSE_STATUS_OPT_DISPLAY @ 0x00021c04 { 350 0:0 display_disabled as bool; 351 }); 352 } 353 354 pub(crate) mod ga100 { 355 // FUSE 356 357 register!(NV_FUSE_STATUS_OPT_DISPLAY @ 0x00820c04 { 358 0:0 display_disabled as bool; 359 }); 360 } 361