regs.rs 13 KB

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