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