>> +/// Maps a physical address range into the page table at the specified
>> virtual address.
>> +///
>> +/// This function maps `len` bytes of physical memory starting at `paddr`
>> to the
>> +/// virtual address `iova`, using the protection flags specified in `prot`.
>> It
>> +/// automatically selects optimal page sizes to minimize page table
>> overhead.
>> +///
>> +/// If the mapping fails partway through, all successfully mapped pages are
>> +/// unmapped before returning an error.
>> +///
>> +/// Returns the number of bytes successfully mapped.
>> +fn pt_map(
>> + pt: &IoPageTable<'_, ARM64LPAES1>,
>> + iova: u64,
>> + paddr: u64,
>> + len: u64,
>> + prot: u32,
>> +) -> Result<u64> {
>> + let mut segment_mapped = 0u64;
>> + while segment_mapped < len {
>> + let remaining = len - segment_mapped;
>> + let curr_iova = iova + segment_mapped;
>> + let curr_paddr = paddr + segment_mapped;
>> +
>> + let (pgsize, pgcount) = get_pgsize(curr_iova | curr_paddr,
>> remaining);
>> +
>> + // SAFETY:
>> + // No other io-pgtable operation can currently access this range
>> because Tyr holds
>> + // the gpuvm_unique mutex for the entire sm_map() operation.
>> + // The addresses being mapped won't overlap any existing mappings
>> in this
>> + // page table because drm_gpuvm_sm_map() checks each requested
>> mapping and either unmaps
>> + // or remaps any overlap before creating the new mapping.
>> + let (mapped, result) = unsafe {
>> + pt.map_pages(
>> + curr_iova as usize,
>> + (curr_paddr as usize).try_into().unwrap(),
Let’s please not have unwraps() anywhere. We really don’t want to panic.