drivers/gpu/nova-core/sbuffer.rs

Source file repositories/reference/linux-study-clean/drivers/gpu/nova-core/sbuffer.rs

File Facts

System
Linux kernel
Corpus path
drivers/gpu/nova-core/sbuffer.rs
Extension
.rs
Size
7072 bytes
Lines
225
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if let Some(slice) = core::mem::take(&mut self.cur_slice) {
            buf.extend_from_slice(slice, flags)?;
        }
        for slice in &mut self.slices {
            buf.extend_from_slice(slice, flags)?;
        }

        Ok(buf)
    }
}

/// Provides a way to get mutable slices of data to write into.
impl<'a, I> SBufferIter<I>
where
    I: Iterator<Item = &'a mut [u8]>,
{
    /// Returns a mutable slice of at most `len` bytes, or [`None`] if we are at the end of the
    /// data.
    ///
    /// If a slice shorter than `len` bytes has been returned, the caller can call this method
    /// again until it returns `None` to try and obtain the remainder of the data.
    fn get_slice_mut(&mut self, len: usize) -> Option<&'a mut [u8]> {
        self.get_slice_internal(len, |s, pos| s.split_at_mut(pos))
    }

    /// Ideally we would implement [`Write`], but it is not available in `core`.
    /// So mimic `std::io::Write::write_all`.
    pub(crate) fn write_all(&mut self, mut src: &[u8]) -> Result {
        while !src.is_empty() {
            match self.get_slice_mut(src.len()) {
                None => return Err(ETOOSMALL),
                Some(dst) => {
                    let src_slice;
                    (src_slice, src) = src.split_at(dst.len());
                    dst.copy_from_slice(src_slice);
                }
            }
        }

        Ok(())
    }
}

impl<'a, I> Iterator for SBufferIter<I>
where
    I: Iterator<Item = &'a [u8]>,
{
    type Item = u8;

    fn next(&mut self) -> Option<Self::Item> {
        // Returned slices are guaranteed to not be empty so we can safely index the first entry.
        self.get_slice(1).map(|s| s[0])
    }
}

Annotation

Implementation Notes