From 56552cc6b382167f8c4730f293c640361aec8de2 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 21 Mar 2026 13:20:13 +0100 Subject: [PATCH] drivers/graphics/ihdgd: Introduce helpers to fetch current plane state --- drivers/graphics/ihdgd/src/device/mod.rs | 30 ++--------------- drivers/graphics/ihdgd/src/device/pipe.rs | 40 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/drivers/graphics/ihdgd/src/device/mod.rs b/drivers/graphics/ihdgd/src/device/mod.rs index 43a982d731..e45a2d1b6e 100644 --- a/drivers/graphics/ihdgd/src/device/mod.rs +++ b/drivers/graphics/ihdgd/src/device/mod.rs @@ -432,34 +432,10 @@ impl Device { for pipe in self.pipes.iter() { for plane in pipe.planes.iter() { if plane.ctl.readf(PLANE_CTL_ENABLE) { - let buf_cfg = plane.buf_cfg.read(); - let buffer_start = buf_cfg & 0x7FF; - let buffer_end = (buf_cfg >> 16) & 0x7FF; - self.alloc_buffers - .allocate_exact_range(buffer_start..(buffer_end + 1)) - .unwrap_or_else(|err| { - panic!( - "failed to allocate pre-existing buffer blocks {} to {}: {:?}", - buffer_start, buffer_end, err - ); - }); + plane.fetch_modeset(&mut self.alloc_buffers); - let size = plane.size.read(); - let width = (size & 0xFFFF) + 1; - let height = ((size >> 16) & 0xFFFF) + 1; - let stride_16 = plane.stride.read() & 0x7FF; - //TODO: this will be wrong for tiled planes - let stride = stride_16 * 16; - let surf = plane.surf.read() & 0xFFFFF000; - //TODO: read bits per pixel - let surf_size = (stride * height * 4).next_multiple_of(4096); - self.alloc_surfaces.allocate_exact_range(surf .. (surf + surf_size)).unwrap_or_else(|err| { - panic!("failed to allocate pre-existing surface at 0x{:x} of size {}: {:?}", surf, surf_size, err); - }); - - self.framebuffers.push(unsafe { - DeviceFb::new(&self.gm, surf, width, height, stride, false) - }); + self.framebuffers + .push(plane.fetch_framebuffer(&self.gm, &mut self.alloc_surfaces)); } } } diff --git a/drivers/graphics/ihdgd/src/device/pipe.rs b/drivers/graphics/ihdgd/src/device/pipe.rs index 15d3232bf4..4d326310ab 100644 --- a/drivers/graphics/ihdgd/src/device/pipe.rs +++ b/drivers/graphics/ihdgd/src/device/pipe.rs @@ -64,6 +64,20 @@ pub struct Plane { } impl Plane { + pub fn fetch_modeset(&self, alloc_buffers: &mut RangeAllocator) { + let buf_cfg = self.buf_cfg.read(); + let buffer_start = buf_cfg & 0x7FF; + let buffer_end = (buf_cfg >> 16) & 0x7FF; + alloc_buffers + .allocate_exact_range(buffer_start..(buffer_end + 1)) + .unwrap_or_else(|err| { + panic!( + "failed to allocate pre-existing buffer blocks {} to {}: {:?}", + buffer_start, buffer_end, err + ); + }); + } + pub fn modeset(&mut self, alloc_buffers: &mut RangeAllocator) -> syscall::Result<()> { // FIXME handle runtime buffer reconfiguration //TODO: enable DBUF if more buffers needed @@ -90,6 +104,32 @@ impl Plane { Ok(()) } + pub fn fetch_framebuffer( + &self, + gm: &MmioRegion, + alloc_surfaces: &mut RangeAllocator, + ) -> DeviceFb { + let size = self.size.read(); + let width = (size & 0xFFFF) + 1; + let height = ((size >> 16) & 0xFFFF) + 1; + let stride_16 = self.stride.read() & 0x7FF; + //TODO: this will be wrong for tiled planes + let stride = stride_16 * 16; + let surf = self.surf.read() & 0xFFFFF000; + //TODO: read bits per pixel + let surf_size = (stride * height * 4).next_multiple_of(4096); + alloc_surfaces + .allocate_exact_range(surf..(surf + surf_size)) + .unwrap_or_else(|err| { + panic!( + "failed to allocate pre-existing surface at 0x{:x} of size {}: {:?}", + surf, surf_size, err + ); + }); + + unsafe { DeviceFb::new(gm, surf, width, height, stride, true) } + } + pub fn set_framebuffer(&mut self, fb: &DeviceFb) { //TODO: documentation on this is not great let stride_16 = fb.stride / 16;