Skip to content

Commit

Permalink
framebuffer: Support nonstandard stride
Browse files Browse the repository at this point in the history
- Add new (optional) stride field in the fb_ctx_t description, pass it to the FDT
- Calculate framebuffer region size accordingly
- This allows direct mapping of unusual framebuffers on the host
  • Loading branch information
LekKit authored Oct 21, 2023
1 parent 18a9281 commit a01b956
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/devices/framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/devices/framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef struct {
void* buffer;
uint32_t width;
uint32_t height;
uint32_t stride;
rgb_fmt_t format;
} fb_ctx_t;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a01b956

Please sign in to comment.