drivers/graphics/ihdgd: Introduce helpers to fetch current plane state

This commit is contained in:
bjorn3
2026-03-21 13:20:13 +01:00
parent 36a9669c57
commit 56552cc6b3
2 changed files with 43 additions and 27 deletions
+3 -27
View File
@@ -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));
}
}
}
+40
View File
@@ -64,6 +64,20 @@ pub struct Plane {
}
impl Plane {
pub fn fetch_modeset(&self, alloc_buffers: &mut RangeAllocator<u32>) {
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<u32>) -> 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<u32>,
) -> 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;