diff --git a/src/devices/framebuffer.c b/src/devices/framebuffer.c index cd6762a87..fe28ad4ec 100644 --- a/src/devices/framebuffer.c +++ b/src/devices/framebuffer.c @@ -36,7 +36,7 @@ static rvvm_mmio_type_t fb_dev_type = { PUBLIC void framebuffer_init(rvvm_machine_t* machine, rvvm_addr_t addr, const fb_ctx_t* fb) { rvvm_mmio_dev_t fb_region = {0}; - + // Map the framebuffer into physical memory fb_region.data = fb->buffer; fb_region.addr = addr; @@ -66,7 +66,7 @@ PUBLIC void framebuffer_init(rvvm_machine_t* machine, rvvm_addr_t addr, const fb } fdt_node_add_prop_u32(fb_fdt, "width", fb->width); fdt_node_add_prop_u32(fb_fdt, "height", fb->height); - fdt_node_add_prop_u32(fb_fdt, "stride", fb->width * rgb_format_bytes(fb->format)); + fdt_node_add_prop_u32(fb_fdt, "stride", framebuffer_stride(fb)); fdt_node_add_child(rvvm_get_fdt_soc(machine), fb_fdt); #endif diff --git a/src/devices/framebuffer.h b/src/devices/framebuffer.h index dc51a5506..a44f45238 100644 --- a/src/devices/framebuffer.h +++ b/src/devices/framebuffer.h @@ -33,6 +33,7 @@ typedef struct { void* buffer; uint32_t width; uint32_t height; + uint32_t stride; rgb_fmt_t format; } fb_ctx_t; @@ -64,9 +65,14 @@ static inline size_t rgb_format_from_bpp(size_t bpp) return RGB_FMT_INVALID; } +static inline uint32_t framebuffer_stride(const fb_ctx_t* fb) +{ + return fb->stride ? fb->stride : fb->width * rgb_format_bytes(fb->format); +} + static inline size_t framebuffer_size(const fb_ctx_t* fb) { - return rgb_format_bytes(fb->format) * fb->width * fb->height; + return framebuffer_stride(fb) * fb->height; } // Attach initialized framebuffer context to the machine