Skip to content

Commit a01b956

Browse files
authored
framebuffer: Support nonstandard stride
- 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
1 parent 18a9281 commit a01b956

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/devices/framebuffer.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static rvvm_mmio_type_t fb_dev_type = {
3636
PUBLIC void framebuffer_init(rvvm_machine_t* machine, rvvm_addr_t addr, const fb_ctx_t* fb)
3737
{
3838
rvvm_mmio_dev_t fb_region = {0};
39-
39+
4040
// Map the framebuffer into physical memory
4141
fb_region.data = fb->buffer;
4242
fb_region.addr = addr;
@@ -66,7 +66,7 @@ PUBLIC void framebuffer_init(rvvm_machine_t* machine, rvvm_addr_t addr, const fb
6666
}
6767
fdt_node_add_prop_u32(fb_fdt, "width", fb->width);
6868
fdt_node_add_prop_u32(fb_fdt, "height", fb->height);
69-
fdt_node_add_prop_u32(fb_fdt, "stride", fb->width * rgb_format_bytes(fb->format));
69+
fdt_node_add_prop_u32(fb_fdt, "stride", framebuffer_stride(fb));
7070

7171
fdt_node_add_child(rvvm_get_fdt_soc(machine), fb_fdt);
7272
#endif

src/devices/framebuffer.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ typedef struct {
3333
void* buffer;
3434
uint32_t width;
3535
uint32_t height;
36+
uint32_t stride;
3637
rgb_fmt_t format;
3738
} fb_ctx_t;
3839

@@ -64,9 +65,14 @@ static inline size_t rgb_format_from_bpp(size_t bpp)
6465
return RGB_FMT_INVALID;
6566
}
6667

68+
static inline uint32_t framebuffer_stride(const fb_ctx_t* fb)
69+
{
70+
return fb->stride ? fb->stride : fb->width * rgb_format_bytes(fb->format);
71+
}
72+
6773
static inline size_t framebuffer_size(const fb_ctx_t* fb)
6874
{
69-
return rgb_format_bytes(fb->format) * fb->width * fb->height;
75+
return framebuffer_stride(fb) * fb->height;
7076
}
7177

7278
// Attach initialized framebuffer context to the machine

0 commit comments

Comments
 (0)