diff --git a/drivers/graphics/ihdgd/src/device/mod.rs b/drivers/graphics/ihdgd/src/device/mod.rs index b1c1259125..16fe6851ec 100644 --- a/drivers/graphics/ihdgd/src/device/mod.rs +++ b/drivers/graphics/ihdgd/src/device/mod.rs @@ -13,6 +13,7 @@ mod aux; mod bios; use self::bios::*; mod buffer; +use self::buffer::*; mod ddi; use self::ddi::*; mod dpll; @@ -436,7 +437,7 @@ impl Device { }) } - fn add_kms_pipe(objects: &mut KmsObjects, pipe_idx: usize, fb: DeviceFb) { + fn add_kms_pipe(objects: &mut KmsObjects, pipe_idx: usize, fb: KmsFramebuffer) { let crtc_id = objects.add_crtc(Crtc { pipe_idx }, ()); let connector_id = objects.add_connector((), (), &[crtc_id]); @@ -445,15 +446,7 @@ impl Device { connector.update_from_size(fb.width, fb.height); drop(connector); - let fb_id = objects.add_framebuffer(KmsFramebuffer { - width: fb.width, - height: fb.height, - pitch: fb.stride, - bpp: 32, - depth: 24, - buffer: Arc::new(fb), - driver_data: (), - }); + let fb_id = objects.add_framebuffer(fb); objects .get_crtc(crtc_id) .unwrap() @@ -758,7 +751,18 @@ impl Device { let width = timing.horizontal_active_pixels as u32; let height = timing.vertical_active_lines as u32; - let fb = DeviceFb::alloc(&self.gm, &mut self.ggtt, width, height)?; + let (buffer, stride) = + GpuBuffer::alloc_dumb(&self.gm, &mut self.ggtt, width, height)?; + + let fb = KmsFramebuffer { + width, + height, + pitch: stride, + bpp: 32, + depth: 32, + buffer: Arc::new(buffer), + driver_data: (), + }; plane.modeset(&mut self.alloc_buffers)?; plane.set_framebuffer(Some(&fb)); diff --git a/drivers/graphics/ihdgd/src/device/pipe.rs b/drivers/graphics/ihdgd/src/device/pipe.rs index a060aa65aa..f36b0730a5 100644 --- a/drivers/graphics/ihdgd/src/device/pipe.rs +++ b/drivers/graphics/ihdgd/src/device/pipe.rs @@ -1,58 +1,19 @@ +use std::sync::Arc; + use common::io::{Io, MmioPtr}; +use driver_graphics::kms::objects::KmsFramebuffer; use range_alloc::RangeAllocator; use syscall::error::Result; use syscall::{Error, EIO}; use super::buffer::GpuBuffer; -use super::{GlobalGtt, MmioRegion}; +use super::{Device, GlobalGtt, MmioRegion}; pub const PLANE_CTL_ENABLE: u32 = 1 << 31; pub const PLANE_WM_ENABLE: u32 = 1 << 31; pub const PLANE_WM_LINES_SHIFT: u32 = 14; -#[derive(Debug)] -pub struct DeviceFb { - pub buffer: GpuBuffer, - pub width: u32, - pub height: u32, - pub stride: u32, -} - -impl DeviceFb { - pub unsafe fn new( - gm: &MmioRegion, - surf: u32, - width: u32, - height: u32, - stride: u32, - clear: bool, - ) -> Self { - Self { - buffer: unsafe { GpuBuffer::new(gm, surf, stride * height, clear) }, - width, - height, - stride, - } - } - - pub fn alloc( - gm: &MmioRegion, - ggtt: &mut GlobalGtt, - width: u32, - height: u32, - ) -> syscall::Result { - let (buffer, stride) = GpuBuffer::alloc_dumb(gm, ggtt, width, height)?; - - Ok(DeviceFb { - buffer, - width, - height, - stride, - }) - } -} - pub struct Plane { pub name: &'static str, pub index: usize, @@ -112,7 +73,11 @@ impl Plane { Ok(()) } - pub fn fetch_framebuffer(&self, gm: &MmioRegion, ggtt: &mut GlobalGtt) -> DeviceFb { + pub fn fetch_framebuffer( + &self, + gm: &MmioRegion, + ggtt: &mut GlobalGtt, + ) -> KmsFramebuffer { let size = self.size.read(); let width = (size & 0xFFFF) + 1; let height = ((size >> 16) & 0xFFFF) + 1; @@ -124,17 +89,27 @@ impl Plane { let surf_size = (stride * height).next_multiple_of(4096); ggtt.reserve(surf, surf_size); - unsafe { DeviceFb::new(gm, surf, width, height, stride, true) } + let buffer = unsafe { GpuBuffer::new(gm, surf, stride * height, true) }; + + KmsFramebuffer { + width, + height, + pitch: stride, + bpp: 32, + depth: 32, + buffer: Arc::new(buffer), + driver_data: (), + } } - pub fn set_framebuffer(&mut self, fb: Option<&DeviceFb>) { + pub fn set_framebuffer(&mut self, fb: Option<&KmsFramebuffer>) { let Some(fb) = fb else { self.ctl.write(0); // Disable plane return; }; //TODO: documentation on this is not great - let stride_64 = fb.stride / 64; + let stride_64 = fb.pitch / 64; self.size.write((fb.width - 1) | ((fb.height - 1) << 16)); self.stride.write(stride_64); diff --git a/drivers/graphics/ihdgd/src/device/scheme.rs b/drivers/graphics/ihdgd/src/device/scheme.rs index dbe1814380..e2655aae27 100644 --- a/drivers/graphics/ihdgd/src/device/scheme.rs +++ b/drivers/graphics/ihdgd/src/device/scheme.rs @@ -10,7 +10,7 @@ use drm_sys::{ }; use syscall::error::EINVAL; -use super::pipe::DeviceFb; +use super::buffer::GpuBuffer; use super::Device; #[derive(Debug)] @@ -22,9 +22,9 @@ impl KmsCrtcDriver for Crtc { type State = (); } -impl Buffer for DeviceFb { +impl Buffer for GpuBuffer { fn size(&self) -> usize { - (self.stride * self.height) as usize + self.size as usize } } @@ -32,7 +32,7 @@ impl GraphicsAdapter for Device { type Connector = (); type Crtc = Crtc; - type Buffer = DeviceFb; + type Buffer = GpuBuffer; type Framebuffer = (); fn name(&self) -> &'static [u8] { @@ -70,13 +70,11 @@ impl GraphicsAdapter for Device { } fn create_dumb_buffer(&mut self, width: u32, height: u32) -> (Self::Buffer, u32) { - let fb = DeviceFb::alloc(&self.gm, &mut self.ggtt, width, height).unwrap(); - let stride = fb.stride; - (fb, stride) + GpuBuffer::alloc_dumb(&self.gm, &mut self.ggtt, width, height).unwrap() } - fn map_dumb_buffer(&mut self, framebuffer: &Self::Buffer) -> *mut u8 { - framebuffer.buffer.virt + fn map_dumb_buffer(&mut self, buffer: &Self::Buffer) -> *mut u8 { + buffer.virt } fn create_framebuffer(&mut self, _buffer: &Self::Buffer) -> Self::Framebuffer { @@ -98,7 +96,7 @@ impl GraphicsAdapter for Device { crtc.state = state; if let Some(primary_plane) = self.pipes[crtc.driver_data.pipe_idx].planes.first_mut() { - primary_plane.set_framebuffer(fb.as_ref().map(|fb| &*fb.buffer)); + primary_plane.set_framebuffer(fb); } Ok(())