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 /* PFB */ 46 47 register!(NV_PFB_NISO_FLUSH_SYSMEM_ADDR @ 0x00100c10 { 48 31:0 adr_39_08 as u32; 49 }); 50 51 register!(NV_PFB_NISO_FLUSH_SYSMEM_ADDR_HI @ 0x00100c40 { 52 23:0 adr_63_40 as u32; 53 }); 54 55 /* PGC6 */ 56 57 register!(NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK @ 0x00118128 { 58 0:0 read_protection_level0 as bool, "Set after FWSEC lowers its protection level"; 59 }); 60 61 // TODO: This is an array of registers. 62 register!(NV_PGC6_AON_SECURE_SCRATCH_GROUP_05 @ 0x00118234 { 63 31:0 value as u32; 64 }); 65 66 register!( 67 NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT => NV_PGC6_AON_SECURE_SCRATCH_GROUP_05, 68 "Scratch group 05 register 0 used as GFW boot progress indicator" { 69 7:0 progress as u8, "Progress of GFW boot (0xff means completed)"; 70 } 71 ); 72 73 impl NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT { 74 /// Returns `true` if GFW boot is completed. 75 pub(crate) fn completed(self) -> bool { 76 self.progress() == 0xff 77 } 78 } 79 80 /* FUSE */ 81 82 register!(NV_FUSE_OPT_FPF_NVDEC_UCODE1_VERSION @ 0x00824100 { 83 15:0 data as u16; 84 }); 85 86 register!(NV_FUSE_OPT_FPF_SEC2_UCODE1_VERSION @ 0x00824140 { 87 15:0 data as u16; 88 }); 89 90 register!(NV_FUSE_OPT_FPF_GSP_UCODE1_VERSION @ 0x008241c0 { 91 15:0 data as u16; 92 }); 93 94 /* PFALCON */ 95 96 register!(NV_PFALCON_FALCON_IRQSCLR @ +0x00000004 { 97 4:4 halt as bool; 98 6:6 swgen0 as bool; 99 }); 100 101 register!(NV_PFALCON_FALCON_MAILBOX0 @ +0x00000040 { 102 31:0 value as u32; 103 }); 104 105 register!(NV_PFALCON_FALCON_MAILBOX1 @ +0x00000044 { 106 31:0 value as u32; 107 }); 108 109 register!(NV_PFALCON_FALCON_RM @ +0x00000084 { 110 31:0 value as u32; 111 }); 112 113 register!(NV_PFALCON_FALCON_HWCFG2 @ +0x000000f4 { 114 10:10 riscv as bool; 115 12:12 mem_scrubbing as bool, "Set to 0 after memory scrubbing is completed"; 116 31:31 reset_ready as bool, "Signal indicating that reset is completed (GA102+)"; 117 }); 118 119 impl NV_PFALCON_FALCON_HWCFG2 { 120 /// Returns `true` if memory scrubbing is completed. 121 pub(crate) fn mem_scrubbing_done(self) -> bool { 122 !self.mem_scrubbing() 123 } 124 } 125 126 register!(NV_PFALCON_FALCON_CPUCTL @ +0x00000100 { 127 1:1 startcpu as bool; 128 4:4 halted as bool; 129 6:6 alias_en as bool; 130 }); 131 132 register!(NV_PFALCON_FALCON_BOOTVEC @ +0x00000104 { 133 31:0 value as u32; 134 }); 135 136 register!(NV_PFALCON_FALCON_DMACTL @ +0x0000010c { 137 0:0 require_ctx as bool; 138 1:1 dmem_scrubbing as bool; 139 2:2 imem_scrubbing as bool; 140 6:3 dmaq_num as u8; 141 7:7 secure_stat as bool; 142 }); 143 144 register!(NV_PFALCON_FALCON_DMATRFBASE @ +0x00000110 { 145 31:0 base as u32; 146 }); 147 148 register!(NV_PFALCON_FALCON_DMATRFMOFFS @ +0x00000114 { 149 23:0 offs as u32; 150 }); 151 152 register!(NV_PFALCON_FALCON_DMATRFCMD @ +0x00000118 { 153 0:0 full as bool; 154 1:1 idle as bool; 155 3:2 sec as u8; 156 4:4 imem as bool; 157 5:5 is_write as bool; 158 10:8 size as u8 ?=> DmaTrfCmdSize; 159 14:12 ctxdma as u8; 160 16:16 set_dmtag as u8; 161 }); 162 163 register!(NV_PFALCON_FALCON_DMATRFFBOFFS @ +0x0000011c { 164 31:0 offs as u32; 165 }); 166 167 register!(NV_PFALCON_FALCON_DMATRFBASE1 @ +0x00000128 { 168 8:0 base as u16; 169 }); 170 171 register!(NV_PFALCON_FALCON_HWCFG1 @ +0x0000012c { 172 3:0 core_rev as u8 ?=> FalconCoreRev, "Core revision"; 173 5:4 security_model as u8 ?=> FalconSecurityModel, "Security model"; 174 7:6 core_rev_subversion as u8 ?=> FalconCoreRevSubversion, "Core revision subversion"; 175 }); 176 177 register!(NV_PFALCON_FALCON_CPUCTL_ALIAS @ +0x00000130 { 178 1:1 startcpu as bool; 179 }); 180 181 // Actually known as `NV_PSEC_FALCON_ENGINE` and `NV_PGSP_FALCON_ENGINE` depending on the falcon 182 // instance. 183 register!(NV_PFALCON_FALCON_ENGINE @ +0x000003c0 { 184 0:0 reset as bool; 185 }); 186 187 // TODO: this is an array of registers. 188 register!(NV_PFALCON_FBIF_TRANSCFG @ +0x00000600 { 189 1:0 target as u8 ?=> FalconFbifTarget; 190 2:2 mem_type as bool => FalconFbifMemType; 191 }); 192 193 register!(NV_PFALCON_FBIF_CTL @ +0x00000624 { 194 7:7 allow_phys_no_ctx as bool; 195 }); 196 197 register!(NV_PFALCON2_FALCON_MOD_SEL @ +0x00001180 { 198 7:0 algo as u8 ?=> FalconModSelAlgo; 199 }); 200 201 register!(NV_PFALCON2_FALCON_BROM_CURR_UCODE_ID @ +0x00001198 { 202 7:0 ucode_id as u8; 203 }); 204 205 register!(NV_PFALCON2_FALCON_BROM_ENGIDMASK @ +0x0000119c { 206 31:0 value as u32; 207 }); 208 209 // TODO: this is an array of registers. 210 register!(NV_PFALCON2_FALCON_BROM_PARAADDR @ +0x00001210 { 211 31:0 value as u32; 212 }); 213 214 /* PRISCV */ 215 216 register!(NV_PRISCV_RISCV_BCR_CTRL @ +0x00001668 { 217 0:0 valid as bool; 218 4:4 core_select as bool => PeregrineCoreSelect; 219 8:8 br_fetch as bool; 220 }); 221