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