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 mod macros; 9 10 use crate::falcon::{ 11 DmaTrfCmdSize, FalconCoreRev, FalconCoreRevSubversion, FalconFbifMemType, FalconFbifTarget, 12 FalconModSelAlgo, FalconSecurityModel, 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.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.len()) | self.implementation() as u32 40 }) 41 .and_then(Chipset::try_from) 42 } 43 } 44 45 /* PBUS */ 46 47 // TODO[REGA]: this is an array of registers. 48 register!(NV_PBUS_SW_SCRATCH_0E@0x00001438 { 49 31:16 frts_err_code as u16; 50 }); 51 52 /* PFB */ 53 54 register!(NV_PFB_NISO_FLUSH_SYSMEM_ADDR @ 0x00100c10 { 55 31:0 adr_39_08 as u32; 56 }); 57 58 register!(NV_PFB_NISO_FLUSH_SYSMEM_ADDR_HI @ 0x00100c40 { 59 23:0 adr_63_40 as u32; 60 }); 61 62 register!(NV_PFB_PRI_MMU_LOCAL_MEMORY_RANGE @ 0x00100ce0 { 63 3:0 lower_scale as u8; 64 9:4 lower_mag as u8; 65 30:30 ecc_mode_enabled as bool; 66 }); 67 68 impl NV_PFB_PRI_MMU_LOCAL_MEMORY_RANGE { 69 /// Returns the usable framebuffer size, in bytes. 70 pub(crate) fn usable_fb_size(self) -> u64 { 71 let size = ((self.lower_mag() as u64) << (self.lower_scale() as u64)) 72 * kernel::sizes::SZ_1M as u64; 73 74 if self.ecc_mode_enabled() { 75 // Remove the amount of memory reserved for ECC (one per 16 units). 76 size / 16 * 15 77 } else { 78 size 79 } 80 } 81 } 82 83 register!(NV_PFB_PRI_MMU_WPR2_ADDR_LO@0x001fa824 { 84 31:4 lo_val as u32, "Bits 12..40 of the lower (inclusive) bound of the WPR2 region"; 85 }); 86 87 impl NV_PFB_PRI_MMU_WPR2_ADDR_LO { 88 /// Returns the lower (inclusive) bound of the WPR2 region. 89 pub(crate) fn lower_bound(self) -> u64 { 90 (self.lo_val() as u64) << 12 91 } 92 } 93 94 register!(NV_PFB_PRI_MMU_WPR2_ADDR_HI@0x001fa828 { 95 31:4 hi_val as u32, "Bits 12..40 of the higher (exclusive) bound of the WPR2 region"; 96 }); 97 98 impl NV_PFB_PRI_MMU_WPR2_ADDR_HI { 99 /// Returns the higher (exclusive) bound of the WPR2 region. 100 /// 101 /// A value of zero means the WPR2 region is not set. 102 pub(crate) fn higher_bound(self) -> u64 { 103 (self.hi_val() as u64) << 12 104 } 105 } 106 107 /* PGC6 */ 108 109 register!(NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK @ 0x00118128 { 110 0:0 read_protection_level0 as bool, "Set after FWSEC lowers its protection level"; 111 }); 112 113 // TODO[REGA]: This is an array of registers. 114 register!(NV_PGC6_AON_SECURE_SCRATCH_GROUP_05 @ 0x00118234 { 115 31:0 value as u32; 116 }); 117 118 register!( 119 NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT => NV_PGC6_AON_SECURE_SCRATCH_GROUP_05, 120 "Scratch group 05 register 0 used as GFW boot progress indicator" { 121 7:0 progress as u8, "Progress of GFW boot (0xff means completed)"; 122 } 123 ); 124 125 impl NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT { 126 /// Returns `true` if GFW boot is completed. 127 pub(crate) fn completed(self) -> bool { 128 self.progress() == 0xff 129 } 130 } 131 132 register!(NV_PGC6_AON_SECURE_SCRATCH_GROUP_42 @ 0x001183a4 { 133 31:0 value as u32; 134 }); 135 136 register!( 137 NV_USABLE_FB_SIZE_IN_MB => NV_PGC6_AON_SECURE_SCRATCH_GROUP_42, 138 "Scratch group 42 register used as framebuffer size" { 139 31:0 value as u32, "Usable framebuffer size, in megabytes"; 140 } 141 ); 142 143 impl NV_USABLE_FB_SIZE_IN_MB { 144 /// Returns the usable framebuffer size, in bytes. 145 pub(crate) fn usable_fb_size(self) -> u64 { 146 u64::from(self.value()) * kernel::sizes::SZ_1M as u64 147 } 148 } 149 150 /* PDISP */ 151 152 register!(NV_PDISP_VGA_WORKSPACE_BASE @ 0x00625f04 { 153 3:3 status_valid as bool, "Set if the `addr` field is valid"; 154 31:8 addr as u32, "VGA workspace base address divided by 0x10000"; 155 }); 156 157 impl NV_PDISP_VGA_WORKSPACE_BASE { 158 /// Returns the base address of the VGA workspace, or `None` if none exists. 159 pub(crate) fn vga_workspace_addr(self) -> Option<u64> { 160 if self.status_valid() { 161 Some((self.addr() as u64) << 16) 162 } else { 163 None 164 } 165 } 166 } 167 168 /* FUSE */ 169 170 register!(NV_FUSE_OPT_FPF_NVDEC_UCODE1_VERSION @ 0x00824100 { 171 15:0 data as u16; 172 }); 173 174 register!(NV_FUSE_OPT_FPF_SEC2_UCODE1_VERSION @ 0x00824140 { 175 15:0 data as u16; 176 }); 177 178 register!(NV_FUSE_OPT_FPF_GSP_UCODE1_VERSION @ 0x008241c0 { 179 15:0 data as u16; 180 }); 181 182 /* PFALCON */ 183 184 register!(NV_PFALCON_FALCON_IRQSCLR @ +0x00000004 { 185 4:4 halt as bool; 186 6:6 swgen0 as bool; 187 }); 188 189 register!(NV_PFALCON_FALCON_MAILBOX0 @ +0x00000040 { 190 31:0 value as u32; 191 }); 192 193 register!(NV_PFALCON_FALCON_MAILBOX1 @ +0x00000044 { 194 31:0 value as u32; 195 }); 196 197 register!(NV_PFALCON_FALCON_RM @ +0x00000084 { 198 31:0 value as u32; 199 }); 200 201 register!(NV_PFALCON_FALCON_HWCFG2 @ +0x000000f4 { 202 10:10 riscv as bool; 203 12:12 mem_scrubbing as bool, "Set to 0 after memory scrubbing is completed"; 204 31:31 reset_ready as bool, "Signal indicating that reset is completed (GA102+)"; 205 }); 206 207 impl NV_PFALCON_FALCON_HWCFG2 { 208 /// Returns `true` if memory scrubbing is completed. 209 pub(crate) fn mem_scrubbing_done(self) -> bool { 210 !self.mem_scrubbing() 211 } 212 } 213 214 register!(NV_PFALCON_FALCON_CPUCTL @ +0x00000100 { 215 1:1 startcpu as bool; 216 4:4 halted as bool; 217 6:6 alias_en as bool; 218 }); 219 220 register!(NV_PFALCON_FALCON_BOOTVEC @ +0x00000104 { 221 31:0 value as u32; 222 }); 223 224 register!(NV_PFALCON_FALCON_DMACTL @ +0x0000010c { 225 0:0 require_ctx as bool; 226 1:1 dmem_scrubbing as bool; 227 2:2 imem_scrubbing as bool; 228 6:3 dmaq_num as u8; 229 7:7 secure_stat as bool; 230 }); 231 232 register!(NV_PFALCON_FALCON_DMATRFBASE @ +0x00000110 { 233 31:0 base as u32; 234 }); 235 236 register!(NV_PFALCON_FALCON_DMATRFMOFFS @ +0x00000114 { 237 23:0 offs as u32; 238 }); 239 240 register!(NV_PFALCON_FALCON_DMATRFCMD @ +0x00000118 { 241 0:0 full as bool; 242 1:1 idle as bool; 243 3:2 sec as u8; 244 4:4 imem as bool; 245 5:5 is_write as bool; 246 10:8 size as u8 ?=> DmaTrfCmdSize; 247 14:12 ctxdma as u8; 248 16:16 set_dmtag as u8; 249 }); 250 251 register!(NV_PFALCON_FALCON_DMATRFFBOFFS @ +0x0000011c { 252 31:0 offs as u32; 253 }); 254 255 register!(NV_PFALCON_FALCON_DMATRFBASE1 @ +0x00000128 { 256 8:0 base as u16; 257 }); 258 259 register!(NV_PFALCON_FALCON_HWCFG1 @ +0x0000012c { 260 3:0 core_rev as u8 ?=> FalconCoreRev, "Core revision"; 261 5:4 security_model as u8 ?=> FalconSecurityModel, "Security model"; 262 7:6 core_rev_subversion as u8 ?=> FalconCoreRevSubversion, "Core revision subversion"; 263 }); 264 265 register!(NV_PFALCON_FALCON_CPUCTL_ALIAS @ +0x00000130 { 266 1:1 startcpu as bool; 267 }); 268 269 // Actually known as `NV_PSEC_FALCON_ENGINE` and `NV_PGSP_FALCON_ENGINE` depending on the falcon 270 // instance. 271 register!(NV_PFALCON_FALCON_ENGINE @ +0x000003c0 { 272 0:0 reset as bool; 273 }); 274 275 // TODO[REGA]: this is an array of registers. 276 register!(NV_PFALCON_FBIF_TRANSCFG @ +0x00000600 { 277 1:0 target as u8 ?=> FalconFbifTarget; 278 2:2 mem_type as bool => FalconFbifMemType; 279 }); 280 281 register!(NV_PFALCON_FBIF_CTL @ +0x00000624 { 282 7:7 allow_phys_no_ctx as bool; 283 }); 284 285 register!(NV_PFALCON2_FALCON_MOD_SEL @ +0x00001180 { 286 7:0 algo as u8 ?=> FalconModSelAlgo; 287 }); 288 289 register!(NV_PFALCON2_FALCON_BROM_CURR_UCODE_ID @ +0x00001198 { 290 7:0 ucode_id as u8; 291 }); 292 293 register!(NV_PFALCON2_FALCON_BROM_ENGIDMASK @ +0x0000119c { 294 31:0 value as u32; 295 }); 296 297 // TODO[REGA]: this is an array of registers. 298 register!(NV_PFALCON2_FALCON_BROM_PARAADDR @ +0x00001210 { 299 31:0 value as u32; 300 }); 301 302 /* PRISCV */ 303 304 register!(NV_PRISCV_RISCV_BCR_CTRL @ +0x00001668 { 305 0:0 valid as bool; 306 4:4 core_select as bool => PeregrineCoreSelect; 307 8:8 br_fetch as bool; 308 }); 309 310 // The modules below provide registers that are not identical on all supported chips. They should 311 // only be used in HAL modules. 312 313 pub(crate) mod gm107 { 314 /* FUSE */ 315 316 register!(NV_FUSE_STATUS_OPT_DISPLAY @ 0x00021c04 { 317 0:0 display_disabled as bool; 318 }); 319 } 320 321 pub(crate) mod ga100 { 322 /* FUSE */ 323 324 register!(NV_FUSE_STATUS_OPT_DISPLAY @ 0x00820c04 { 325 0:0 display_disabled as bool; 326 }); 327 } 328