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