diff --git a/drivers/graphics/ihdgd/src/device/mod.rs b/drivers/graphics/ihdgd/src/device/mod.rs index e45a2d1b6e..92ecd65ce0 100644 --- a/drivers/graphics/ihdgd/src/device/mod.rs +++ b/drivers/graphics/ihdgd/src/device/mod.rs @@ -719,26 +719,7 @@ impl Device { let width = timing.horizontal_active_pixels as u32; let height = timing.vertical_active_lines as u32; - //TODO: documentation on this is not great - let stride_16 = (width + 15) / 16; - let stride = stride_16 * 16; - - //TODO: how is memory allocated for PLANE_SURF? - let surf_size = (stride * height * 4).next_multiple_of(4096); - let surf = self - .alloc_surfaces - .allocate_range(surf_size) - .map_err(|err| { - log::warn!( - "failed to allocate surface of size {}: {:?}", - surf_size, - err - ); - Error::new(EIO) - })?; - - let fb = - unsafe { DeviceFb::new(&self.gm, surf.start, width, height, stride, true) }; + let fb = DeviceFb::alloc(&self.gm, &mut self.alloc_surfaces, width, height)?; plane.modeset(&mut self.alloc_buffers)?; plane.set_framebuffer(&fb); diff --git a/drivers/graphics/ihdgd/src/device/pipe.rs b/drivers/graphics/ihdgd/src/device/pipe.rs index 4d326310ab..4ac2395c71 100644 --- a/drivers/graphics/ihdgd/src/device/pipe.rs +++ b/drivers/graphics/ihdgd/src/device/pipe.rs @@ -43,6 +43,30 @@ impl DeviceFb { stride, } } + + pub fn alloc( + gm: &MmioRegion, + alloc_surfaces: &mut RangeAllocator, + width: u32, + height: u32, + ) -> syscall::Result { + //TODO: documentation on this is not great + let stride_16 = (width + 15) / 16; + let stride = stride_16 * 16; + + //TODO: how is memory allocated for PLANE_SURF? + let surf_size = (stride * height * 4).next_multiple_of(4096); + let surf = alloc_surfaces.allocate_range(surf_size).map_err(|err| { + log::warn!( + "failed to allocate surface of size {}: {:?}", + surf_size, + err + ); + Error::new(EIO) + })?; + + Ok(unsafe { DeviceFb::new(gm, surf.start, width, height, stride, true) }) + } } pub struct Plane {