Skip to contentSkip to conversation

gpu: nova-core: migrate to `kernel::num::casts`

PATCH In review Gary Guo 2 participants 2 messages Nov 30 – Dec 2

Subsystems (4)
lore
Share & tools
lore

Gary Guo

author
#0 lore raw

PATCH 1/1 gpu: nova-core: migrate to `kernel::num::casts`

From: Gary Guo <[email protected]>

Migrate users of the Nova's internal num module over to the kernel::num::casts instead. FromSafeCast and IntoSafeCast are migrated to the same-named traits or their Arch variant; uX_as_uY methods are migrated to FromSafeCast/IntoSafeCast outside const contexts and migrated to cv! macro inside const context.

---
 drivers/gpu/nova-core/falcon.rs                    |   2 +-
 drivers/gpu/nova-core/falcon/fsp.rs                |   4 +-
 drivers/gpu/nova-core/fb.rs                        |   2 +-
 drivers/gpu/nova-core/firmware.rs                  |   2 +-
 drivers/gpu/nova-core/firmware/booter.rs           |   2 +-
 drivers/gpu/nova-core/firmware/fwsec.rs            |   2 +-
 drivers/gpu/nova-core/firmware/fwsec/bootloader.rs |   2 +-
 drivers/gpu/nova-core/firmware/gen_bootloader.rs   |   2 +-
 drivers/gpu/nova-core/firmware/gsp.rs              |   2 +-
 drivers/gpu/nova-core/firmware/radix3.rs           |   6 +-
 drivers/gpu/nova-core/firmware/tlv.rs              |   8 +-
 drivers/gpu/nova-core/gsp.rs                       |   4 +-
 drivers/gpu/nova-core/gsp/cmdq.rs                  |   3 +-
 drivers/gpu/nova-core/gsp/fw.rs                    |  14 +-
 drivers/gpu/nova-core/gsp/fw/commands.rs           |   2 +-
 drivers/gpu/nova-core/gsp/nvkv/decode.rs           |  18 ++-
 drivers/gpu/nova-core/gsp/sequencer.rs             |   2 +-
 drivers/gpu/nova-core/irq/interrupt_tree.rs        |  20 +--
 drivers/gpu/nova-core/mctp.rs                      |   7 +-
 drivers/gpu/nova-core/mm/bar_user.rs               |  20 ++-
 drivers/gpu/nova-core/mm/pagetable/map.rs          |  18 +--
 drivers/gpu/nova-core/mm/pagetable/walk.rs         |  24 ++--
 drivers/gpu/nova-core/mm/pramin.rs                 |   7 +-
 drivers/gpu/nova-core/mm/vmm.rs                    |  17 +--
 drivers/gpu/nova-core/num.rs                       | 158 ---------------------
 drivers/gpu/nova-core/vbios.rs                     |   2 +-
 26 files changed, 94 insertions(+), 256 deletions(-)
drivers/gpu/nova-core/falcon.rs +1 -1
index 8bcc9240d1bd..09c8fed9f924 100644
@@ -19,6 +19,7 @@
         Mmio, //
     },
     num::{
+        casts::FromSafeCast,
         Bounded,
         TryIntoBounded, //
     },
@@ -32,7 +33,6 @@
     driver::Bar0,
     falcon::hal::LoadMethod,
     gpu::Chipset,
-    num::FromSafeCast,
     regs, //
 };
 
drivers/gpu/nova-core/falcon/fsp.rs +2 -2
index d7c213848005..1296f8588eb3 100644
@@ -15,6 +15,7 @@
         Io,
         Mmio, //
     },
+    num::casts::FromSafeCast,
     prelude::*,
     sizes::SZ_1K,
     time::Delta,
@@ -29,7 +30,6 @@
         Falcon,
         FalconEngine, //
     },
-    num,
     regs, //
 };
 
@@ -166,7 +166,7 @@ pub(crate) fn recv_msg(&mut self) -> Result<KVec<u8>> {
             Delta::from_millis(10),
             Delta::from_millis(FSP_MSG_TIMEOUT_MS),
         )
-        .map(num::u32_as_usize)?;
+        .map(usize::from_safe_cast)?;
 
         // Don't blindly allocate more than the maximum we expect from FSP.
         if msg_size > FSP_EMEM_CHANNEL_0_SIZE {
drivers/gpu/nova-core/fb.rs +1 -1
index 5ceb7760c78e..e87bacdcb317 100644
@@ -10,6 +10,7 @@
     dma::CoherentHandle,
     fmt,
     io::Io,
+    num::casts::FromSafeCast,
     prelude::*,
     ptr::{
         Alignable,
@@ -23,7 +24,6 @@
     firmware::gsp::GspFirmware,
     gpu::Chipset,
     gsp,
-    num::FromSafeCast,
     vgpu::VgpuState, //
 };
 
drivers/gpu/nova-core/firmware.rs +1 -1
index 358c9b8db0b8..030bb35dfded 100644
@@ -9,6 +9,7 @@
 
 use kernel::{
     firmware,
+    num::casts::IntoSafeCast,
     prelude::*, //
 };
 
@@ -19,7 +20,6 @@
     },
     gpu,
     gsp::boot_firmware_files,
-    num::IntoSafeCast, //
 };
 
 pub(crate) mod booter;
drivers/gpu/nova-core/firmware/booter.rs +1 -1
index aa4458bb3312..460a0fd2ff21 100644
@@ -10,6 +10,7 @@
 use kernel::{
     device,
     dma::Coherent,
+    num::casts::IntoSafeCast,
     prelude::*, //
 };
 
@@ -33,7 +34,6 @@
         Unsigned, //
     },
     gpu::Chipset,
-    num::IntoSafeCast,
 };
 
 /// Signature for Booter firmware. Their size is encoded into the header and not known a compile
drivers/gpu/nova-core/firmware/fwsec.rs +1 -1
index 7a931f22f629..7f7ca3ba2298 100644
@@ -19,6 +19,7 @@
         self,
         Device, //
     },
+    num::casts::FromSafeCast,
     prelude::*,
     transmute::{
         AsBytes,
@@ -42,7 +43,6 @@
         Signed,
         Unsigned, //
     },
-    num::FromSafeCast,
     vbios::Vbios,
 };
 
drivers/gpu/nova-core/firmware/fwsec/bootloader.rs +1 -1
index 461e5e6f7899..384a9f025a4b 100644
@@ -12,6 +12,7 @@
         Device, //
     },
     dma::Coherent,
+    num::casts::FromSafeCast,
     prelude::*, //
 };
 
@@ -30,7 +31,6 @@
         },
     },
     gpu::Chipset,
-    num::FromSafeCast, //
 };
 
 /// Wrapper for [`FwsecFirmware`] that includes the bootloader performing the actual load
drivers/gpu/nova-core/firmware/gen_bootloader.rs +1 -1
index 751335c97e35..266f1f6354ec 100644
@@ -8,6 +8,7 @@
 use kernel::{
     device,
     num::{
+        casts::FromSafeCast,
         Bounded,
         TryIntoBounded, //
     },
@@ -35,7 +36,6 @@
         Tlv,
     },
     gpu::Chipset,
-    num::FromSafeCast, //
 };
 
 /// Structure used by the boot-loader to load the rest of the code.
drivers/gpu/nova-core/firmware/gsp.rs +1 -1
index 1cf17d0fb36b..f608a8cce141 100644
@@ -7,6 +7,7 @@
         DmaAddress, //
     },
     firmware,
+    num::casts::FromSafeCast,
     prelude::*,
     str::CString,
 };
@@ -21,7 +22,6 @@
         },
     },
     gpu::Chipset,
-    num::FromSafeCast,
 };
 
 /// The GSP firmware image, its signatures, and the GSP bootloader.
drivers/gpu/nova-core/firmware/radix3.rs +2 -4
index b17d1363e48f..f90b359ef90f 100644
@@ -19,6 +19,7 @@
         DataDirection,
         DmaAddress, //
     },
+    num::casts::FromSafeCast,
     prelude::*,
     scatterlist::{
         Owned,
@@ -26,10 +27,7 @@
     },
 };
 
-use crate::{
-    gsp::GSP_PAGE_SIZE,
-    num::FromSafeCast, //
-};
+use crate::gsp::GSP_PAGE_SIZE;
 
 /// A radix3 page table and the data it maps.
 pub(crate) struct Radix3<'a> {
drivers/gpu/nova-core/firmware/tlv.rs +3 -5
index 7b879f13a61e..ac376bd35f84 100644
@@ -4,14 +4,12 @@
 use kernel::{
     device,
     firmware,
+    num::casts::IntoSafeCast,
     prelude::*,
     str::CString, //
 };
 
-use crate::{
-    gpu,
-    num::*, //
-};
+use crate::gpu;
 
 /// Requests the GPU firmware TLV `name` suitable for `chipset`.
 pub(crate) fn request_tlv(
@@ -51,7 +49,7 @@ fn parse(hdr: &[u8]) -> Option<Self> {
             return None;
         }
         let len_arr = <[u8; 4]>::try_from(hdr.get(4..Self::SIZE)?).ok()?;
-        let length = u32_as_usize(u32::from_le_bytes(len_arr));
+        let length = u32::from_le_bytes(len_arr).into_safe_cast();
         Some(Self { tag, length })
     }
 }
drivers/gpu/nova-core/gsp.rs +2 -2
index 2f1cdf8b7bec..bc77a491d233 100644
@@ -13,6 +13,7 @@
         DmaAddress, //
     },
     io::io_write,
+    num::casts::FromSafeCast,
     pci,
     prelude::*, //
 };
@@ -49,7 +50,6 @@
         cmdq::Cmdq,
         fw::GspArgumentsPadded, //
     },
-    num,
     vgpu::VgpuManager, //
 };
 
@@ -89,7 +89,7 @@ fn init(view: CoherentView<'_, Self>, start: DmaAddress) -> Result<()> {
         for i in 0..NUM_PAGES {
             io_write!(view, .0[build: i],
                 start
-                    .checked_add(num::usize_as_u64(i) << GSP_PAGE_SHIFT)
+                    .checked_add(u64::from_safe_cast(i) << GSP_PAGE_SHIFT)
                     .ok_or(EOVERFLOW)?
             );
         }
drivers/gpu/nova-core/gsp/cmdq.rs +1 -2
index e2b9a5383a66..c95a2d2aacea 100644
@@ -60,7 +60,6 @@
         GSP_PAGE_SHIFT,
         GSP_PAGE_SIZE, //
     },
-    num,
     sbuffer::SBufferIter, //
 };
 
@@ -239,7 +238,7 @@ fn cpuq_free_slots(&self) -> u32 {
     /// Returns the size of the region of the CPU message queue that the driver is currently allowed
     /// to write to, in bytes.
     fn driver_write_area_size(&self) -> usize {
-        num::u32_as_usize(self.cpuq_free_slots()) * GSP_PAGE_SIZE
+        usize::from_safe_cast(self.cpuq_free_slots()) * GSP_PAGE_SIZE
     }
 
     /// Returns the number of slots of the GSP message queue that the driver is currently allowed
drivers/gpu/nova-core/gsp/fw.rs +7 -7
index 5c216d777dff..66a777d16898 100644
@@ -20,6 +20,10 @@
         io_read,
         io_write, //
     },
+    num::casts::{
+        FromSafeCast,
+        IntoSafeCast, //
+    },
     prelude::*,
     ptr::{
         Alignable,
@@ -48,10 +52,6 @@
         cmdq::Cmdq, //
         GSP_PAGE_SIZE,
     },
-    num::{
-        self,
-        FromSafeCast, //
-    },
 };
 
 /// Maximum size of a single GSP message queue element in bytes.
@@ -675,7 +675,7 @@ fn id8(name: &str) -> u64 {
         let init_inner = init!(bindings::LibosMemoryRegionInitArgument {
             id8: id8(name),
             pa: obj.dma_address(),
-            size: num::usize_as_u64(obj.size()),
+            size: obj.size().into_safe_cast(),
             kind: cv!(bindings::LibosMemoryRegionKind_LIBOS_MEMORY_REGION_CONTIGUOUS),
             loc: cv!(bindings::LibosMemoryRegionLoc_LIBOS_MEMORY_REGION_LOC_SYSMEM),
             ..Zeroable::init_zeroed()
@@ -883,7 +883,7 @@ pub(crate) fn init(cmd_size: usize, function: MsgFunction) -> impl Init<Self, Er
     /// Returns the length of the RPC's payload, not including the message and RPC headers.
     pub(crate) fn rpc_length(&self) -> usize {
         // `length` includes the length of the RPC message header.
-        num::u32_as_usize(self.inner.length).saturating_sub(size_of::<Self>())
+        usize::from_safe_cast(self.inner.length).saturating_sub(size_of::<Self>())
     }
 
     /// Returns the sequence number of the message.
@@ -980,7 +980,7 @@ pub(crate) fn sequence(&self) -> u64 {
 
     /// Returns the size in bytes of the payload following the header.
     pub(crate) fn payload_size(&self) -> usize {
-        num::u32_as_usize(self.inner.size)
+        self.inner.size.into_safe_cast()
     }
 
     /// Returns the `NV_STATUS` carried by a response to a command.
drivers/gpu/nova-core/gsp/fw/commands.rs +1 -1
index b4bdbddad79f..e0d8edd73017 100644
@@ -7,6 +7,7 @@
     alloc::ArrayVec,
     bitfield,
     device,
+    num::casts::IntoSafeCast,
     pci,
     prelude::*,
     transmute::{
@@ -30,7 +31,6 @@
         },
         GSP_PAGE_SIZE, //
     },
-    num::IntoSafeCast,
     vgpu::VgpuState, //
 };
 
drivers/gpu/nova-core/gsp/nvkv/decode.rs +8 -10
index 84c0c998b2c9..8d227fc26ba0 100644
@@ -7,6 +7,7 @@
 
 use kernel::{
     alloc::ArrayVec,
+    num::casts::IntoSafeCast,
     prelude::*, //
 };
 use pin_init::{
@@ -14,16 +15,13 @@
     stack_try_pin_init, //
 };
 
-use crate::{
-    gsp::nvkv::{
-        Array,
-        Index,
-        Key,
-        KeyId,
-        Op,
-        Opcode, //
-    },
-    num::IntoSafeCast, //
+use crate::gsp::nvkv::{
+    Array,
+    Index,
+    Key,
+    KeyId,
+    Op,
+    Opcode, //
 };
 
 /// Defines a schema struct together with its [`Schema`] and [`Visit`] implementations that decode
drivers/gpu/nova-core/gsp/sequencer.rs +1 -1
index 23b09fb875e9..3217cde4e9c9 100644
@@ -11,6 +11,7 @@
         poll::read_poll_timeout,
         Io, //
     },
+    num::casts::FromSafeCast,
     prelude::*,
     time::{
         delay::fsleep,
@@ -35,7 +36,6 @@
         GspBootContext,
         LibosMemoryRegionInitArgument, //
     },
-    num::FromSafeCast,
     sbuffer::SBufferIter,
 };
 
drivers/gpu/nova-core/irq/interrupt_tree.rs +11 -9
index 590f921894b6..bd52b77da688 100644
@@ -20,7 +20,10 @@
         Io, //
     },
     irq,
-    num::Bounded,
+    num::{
+        casts::IntoSafeCast,
+        Bounded, //
+    },
     pci::{
         self,
         IrqType, //
@@ -30,8 +33,7 @@
 
 use crate::{
     driver::Bar0,
-    gpu::Chipset,
-    num, //
+    gpu::Chipset, //
 };
 
 use super::{
@@ -59,10 +61,10 @@
 const VECTOR_BITS: u32 = (MAX_NUM_LEAVES * VECTORS_PER_LEAF).ilog2();
 
 /// Width of the vector field in the leaf trigger register.
-const TRIGGER_VECTOR_BITS: u32 = {
+const TRIGGER_VECTOR_BITS: u32 = cv!({
     let range = NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_TRIGGER::VECTOR_RANGE;
-    num::u8_as_u32(*range.end() - *range.start() + 1)
-};
+    *range.end() - *range.start() + 1
+});
 
 /// Index of a leaf register within the widest supported tree. An 8-leaf tree implements only the
 /// lower half of the range.
@@ -85,8 +87,8 @@ pub(super) const fn into_u32(self) -> u32 {
         self as u32
     }
 
-    pub(super) const fn into_raw(self) -> usize {
-        num::u32_as_usize(self.into_u32())
+    pub(super) fn into_raw(self) -> usize {
+        self.into_u32().into_safe_cast()
     }
 
     /// Returns the number of subtrees a tree of this size implements.
@@ -368,7 +370,7 @@ pub(super) fn request_for(&self, subtree: Subtree) -> Result<irq::IrqRequest<'_>
         }
 
         let entry = match self.msi_type {
-            MsiType::MsiX => num::u32_as_usize(subtree.index()),
+            MsiType::MsiX => subtree.index().into_safe_cast(),
             MsiType::Msi => 0,
         };
 
drivers/gpu/nova-core/mctp.rs +2 -5
index f62e79f56b05..12536ec82060 100644
@@ -13,10 +13,7 @@
     prelude::*, //
 };
 
-use crate::{
-    bounded_enum,
-    num, //
-};
+use crate::bounded_enum;
 
 bounded_enum! {
     /// NVDM message type identifiers carried over MCTP.
@@ -88,7 +85,7 @@ impl NvdmHeader {
     /// Builds an NVDM header for the given message type.
     pub(crate) fn new(nvdm_type: NvdmType) -> Self {
         Self::zeroed()
-            .with_const_msg_type::<{ num::u8_as_u32(MSG_TYPE_VENDOR_PCI) }>()
+            .with_const_msg_type::<{ cv!(MSG_TYPE_VENDOR_PCI) }>()
             .with_vendor_id(Vendor::NVIDIA.as_raw())
             .with_nvdm_type(nvdm_type)
     }
drivers/gpu/nova-core/mm/bar_user.rs +13 -7
index 2e8bd2a8ed91..eb46bd311335 100644
@@ -6,6 +6,7 @@
 use kernel::{
     io::Io,
     new_mutex,
+    num::casts::arch::IntoSafeCastArch,
     prelude::*,
     sync::Mutex, //
 };
@@ -25,11 +26,16 @@
         VramAddress,
         PAGE_SIZE, //
     },
-    num::IntoSafeCast,
 };
 
 #[cfg(CONFIG_NOVA_CORE_SELFTESTS)]
-use kernel::device;
+use kernel::{
+    device,
+    num::casts::{
+        arch::FromSafeCastArch,
+        IntoSafeCast, //
+    }, //
+};
 
 /// BAR1 user interface for virtual memory mappings.
 ///
@@ -131,7 +137,7 @@ fn bar_offset(&self, offset: usize) -> Result<usize> {
             return Err(EINVAL);
         }
 
-        let base_vfn: usize = self.mapped().vfn_start.raw().into_safe_cast();
+        let base_vfn: usize = self.mapped().vfn_start.raw().into_safe_cast_arch();
         let base = base_vfn.checked_mul(PAGE_SIZE).ok_or(EOVERFLOW)?;
         base.checked_add(offset).ok_or(EOVERFLOW)
     }
@@ -240,7 +246,7 @@ pub(crate) fn run_self_test(
     let test_vfn = mapped.vfn_start;
 
     // Pre-compute test addresses for the PRAMIN to BAR1 read test.
-    let vfn_offset: usize = test_vfn.raw().into_safe_cast();
+    let vfn_offset: usize = test_vfn.raw().into_safe_cast_arch();
     let bar1_base_offset = vfn_offset.checked_mul(PAGE_SIZE).ok_or(EOVERFLOW)?;
     let bar1_read_offset: usize = bar1_base_offset + 0x100;
     let vram_read_addr = test_vram + 0x100;
@@ -322,11 +328,11 @@ pub(crate) fn run_self_test(
     let mut total_size = 0usize;
 
     for block in blocks.iter() {
-        total_size += IntoSafeCast::<usize>::into_safe_cast(block.size());
+        total_size += usize::from_safe_cast_arch(block.size());
 
         // Map all pages of this block.
         let page_size: u64 = PAGE_SIZE.into_safe_cast();
-        let num_pages: usize = (block.size() / page_size).into_safe_cast();
+        let num_pages: usize = (block.size() / page_size).into_safe_cast_arch();
 
         let mut pfns = KVec::new();
         for j in 0..num_pages {
@@ -340,7 +346,7 @@ pub(crate) fn run_self_test(
         }
 
         let mapped = vmm.map_pages(mm, &pfns, None, true)?;
-        let bar1_base_vfn: usize = mapped.vfn_start.raw().into_safe_cast();
+        let bar1_base_vfn: usize = mapped.vfn_start.raw().into_safe_cast_arch();
         let bar1_base = bar1_base_vfn.checked_mul(PAGE_SIZE).ok_or(EOVERFLOW)?;
 
         for j in 0..num_pages {
drivers/gpu/nova-core/mm/pagetable/map.rs +7 -11
index f7774b9cc972..0307541463f3 100644
@@ -11,6 +11,7 @@
         GpuBuddyAllocMode, //
     },
     io::io_write,
+    num::casts::IntoSafeCast,
     prelude::*,
     ptr::Alignment,
     rbtree::{
@@ -40,17 +41,12 @@
     PdeOps,
     PteOps, //
 };
-use crate::{
-    mm::{
-        GpuMm,
-        Pfn,
-        Vfn,
-        VramAddress,
-        PAGE_SIZE, //
-    },
-    num::{
-        IntoSafeCast, //
-    },
+use crate::mm::{
+    GpuMm,
+    Pfn,
+    Vfn,
+    VramAddress,
+    PAGE_SIZE, //
 };
 
 /// A pre-allocated and zeroed page table page.
drivers/gpu/nova-core/mm/pagetable/walk.rs +11 -13
index 76c1729971f5..80e29d9babba 100644
@@ -36,7 +36,10 @@
 
 use core::marker::PhantomData;
 
-use kernel::prelude::*;
+use kernel::{
+    num::casts::IntoSafeCast,
+    prelude::*, //
+};
 
 use super::{
     DualPdeOps,
@@ -48,18 +51,13 @@
     PdeOps,
     PteOps, //
 };
-use crate::{
-    mm::{
-        pramin,
-        GpuMm,
-        Pfn,
-        Vfn,
-        VirtualAddress,
-        VramAddress, //
-    },
-    num::{
-        IntoSafeCast, //
-    },
+use crate::mm::{
+    pramin,
+    GpuMm,
+    Pfn,
+    Vfn,
+    VirtualAddress,
+    VramAddress, //
 };
 
 /// Result of walking to a PTE.
drivers/gpu/nova-core/mm/pramin.rs +5 -2
index c83b1681d241..d712dbdb82f5 100644
@@ -13,6 +13,10 @@
         Io,
         Mmio, //
     },
+    num::casts::{
+        arch::IntoSafeCastArch,
+        IntoSafeCast, //
+    },
     prelude::*,
     ptr::{
         Alignable,
@@ -37,7 +41,6 @@
         },
         VramAddress, //
     },
-    num::IntoSafeCast, //
 };
 
 /// Size of the PRAMIN window (1 MiB).
@@ -156,7 +159,7 @@ fn window_offset(&mut self, addr: VramAddress, len: usize) -> Result<usize> {
             self.window_range = window_range;
         }
 
-        Ok((addr - self.window_range.start).into_safe_cast())
+        Ok((addr - self.window_range.start).into_safe_cast_arch())
     }
 
     /// Return a typed MMIO view of a `T` at `vram_addr`.
drivers/gpu/nova-core/mm/vmm.rs +9 -8
index 51b500a27233..585f747058c5 100644
@@ -8,6 +8,10 @@
 use kernel::{
     gpu::buddy::AllocatedBlocks,
     maple_tree::MapleTreeAlloc,
+    num::casts::{
+        arch::IntoSafeCastArch,
+        IntoSafeCast, //
+    },
     prelude::*,
     rbtree::RBTree, //
 };
@@ -34,10 +38,7 @@
         Vfn,
         VramAddress,
         PAGE_SIZE, //
-    },
-    num::{
-        IntoSafeCast, //
-    },
+    }, //
 };
 
 /// Multi-page prepared mapping -- VA range allocated, ready for execute.
@@ -155,7 +156,7 @@ pub(crate) fn new(
         va_size: u64,
     ) -> Result<Self> {
         let page_size: u64 = PAGE_SIZE.into_safe_cast();
-        let va_pages: usize = (va_size / page_size).into_safe_cast();
+        let va_pages: usize = (va_size / page_size).into_safe_cast_arch();
         let virt_alloc = KBox::pin_init(MapleTreeAlloc::<()>::new(), GFP_KERNEL)?;
 
         Ok(Self {
@@ -181,8 +182,8 @@ fn alloc_vfn_range(&self, num_pages: usize, va_range: Option<Range<u64>>) -> Res
                 if range_size != size {
                     return Err(EINVAL);
                 }
-                let start_vfn: usize = (r.start / page_size).into_safe_cast();
-                let end_vfn: usize = (r.end / page_size).into_safe_cast();
+                let start_vfn: usize = (r.start / page_size).into_safe_cast_arch();
+                let end_vfn: usize = (r.end / page_size).into_safe_cast_arch();
                 self.virt_alloc
                     .insert_range(start_vfn..end_vfn, (), GFP_KERNEL)?;
                 start_vfn
@@ -197,7 +198,7 @@ fn alloc_vfn_range(&self, num_pages: usize, va_range: Option<Range<u64>>) -> Res
 
     /// Free a virtual frame number range back to the maple tree.
     fn free_vfn(&self, vfn: Vfn) {
-        let vfn_index: usize = vfn.raw().into_safe_cast();
+        let vfn_index: usize = vfn.raw().into_safe_cast_arch();
         if self.virt_alloc.erase(vfn_index).is_none() {
             kernel::pr_warn!("free_vfn: VFN {} not found in maple tree\n", vfn_index);
         }
drivers/gpu/nova-core/num.rs +0 -158

164 lines not on this page · raw message

drivers/gpu/nova-core/vbios.rs +1 -1
index a2d2d170b501..a32ef135f879 100644
@@ -5,6 +5,7 @@
 use kernel::{
     device,
     io::Io,
+    num::casts::FromSafeCast,
     prelude::*,
     ptr::{
         Alignable,
@@ -29,7 +30,6 @@
         FalconUCodeDescV2,
         FalconUCodeDescV3, //
     },
-    num::FromSafeCast,
 };
 
 /// BIOS Image Type from PCI Data Structure code_type field.

---
base-commit: e5aad2bdbbee783611d32599f89cea3f12f9593d
change-id: 20261130-dev-nova-num-22acabc345ad

Best regards,

Signature · 1 line
Gary Guo <[email protected]>
#1 lore raw
Quoted 29 lines · Gary Guo

From: Gary Guo <[email protected]>

Migrate users of the Nova's internal num module over to the kernel::num::casts instead. FromSafeCast and IntoSafeCast are migrated to the same-named traits or their Arch variant; uX_as_uY methods are migrated to FromSafeCast/IntoSafeCast outside const contexts and migrated to cv! macro inside const context.

---
 drivers/gpu/nova-core/falcon.rs                    |   2 +-
 drivers/gpu/nova-core/falcon/fsp.rs                |   4 +-
 drivers/gpu/nova-core/fb.rs                        |   2 +-
 drivers/gpu/nova-core/firmware.rs                  |   2 +-
 drivers/gpu/nova-core/firmware/booter.rs           |   2 +-
 drivers/gpu/nova-core/firmware/fwsec.rs            |   2 +-
 drivers/gpu/nova-core/firmware/fwsec/bootloader.rs |   2 +-
 drivers/gpu/nova-core/firmware/gen_bootloader.rs   |   2 +-
 drivers/gpu/nova-core/firmware/gsp.rs              |   2 +-
 drivers/gpu/nova-core/firmware/radix3.rs           |   6 +-
 drivers/gpu/nova-core/firmware/tlv.rs              |   8 +-
 drivers/gpu/nova-core/gsp.rs                       |   4 +-
 drivers/gpu/nova-core/gsp/cmdq.rs                  |   3 +-
 drivers/gpu/nova-core/gsp/fw.rs                    |  14 +-
 drivers/gpu/nova-core/gsp/fw/commands.rs           |   2 +-
 drivers/gpu/nova-core/gsp/nvkv/decode.rs           |  18 ++-
 drivers/gpu/nova-core/gsp/sequencer.rs             |   2 +-
 drivers/gpu/nova-core/irq/interrupt_tree.rs        |  20 +--
 drivers/gpu/nova-core/mctp.rs                      |   7 +-
Quoted 8 lines
 drivers/gpu/nova-core/mm/bar_user.rs               |  20 ++-
 drivers/gpu/nova-core/mm/pagetable/map.rs          |  18 +--
 drivers/gpu/nova-core/mm/pagetable/walk.rs         |  24 ++--
 drivers/gpu/nova-core/mm/pramin.rs                 |   7 +-
 drivers/gpu/nova-core/mm/vmm.rs                    |  17 +--
 drivers/gpu/nova-core/num.rs                       | 158 ---------------------
 drivers/gpu/nova-core/vbios.rs                     |   2 +-
 26 files changed, 94 insertions(+), 256 deletions(-)

There have been a couple of efforts to do that already (most recent being [1] IIRC), but landing it has been tricky and pending on the availability of cv!.

And with all the code landing in Nova at the moment this is going to be difficult to apply, actually this already results in lots of conflicts on today's drm-rust-next.

If we want to get this in soon, I think a good point to land this would be after the r000 switch and before we start landing the vGPU patches. I can point you to the tree once I have a better idea of what it will look like, or I can revive my own patch if you prefer.

[1] https://lore.kernel.org/all/[email protected]/