Skip to content

Commit 30b7471

Browse files
author
Diego Ferrari
committed
[VIDEOCORE] buffer swap
1 parent 676b3e2 commit 30b7471

5 files changed

Lines changed: 57 additions & 16 deletions

File tree

kernel/graph/drivers/framebuffer_gpus/videocore/videocore.cpp

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@ VideoCoreGPUDriver* VideoCoreGPUDriver::try_init(gpu_size preferred_screen_size)
2323
}
2424

2525
volatile uint32_t rmbox[40] __attribute__((aligned(16))) = {
26-
30 * 4,// Buf size
26+
24 * 4,// Buf size
27+
0,// Request. Code 0
28+
MBOX_VC_PHYS_SIZE_TAG, 8, 0, 0, 0,
29+
MBOX_VC_VIRT_SIZE_TAG, 8, 0, 0, 0,
30+
MBOX_VC_DEPTH_TAG | MBOX_SET_VALUE, 4, 4, 32,
31+
MBOX_VC_PITCH_TAG, 4, 0, 0,
32+
MBOX_VC_FORMAT_TAG | MBOX_SET_VALUE, 4, 4, 0,
33+
0,// End
34+
};
35+
36+
volatile uint32_t rmbox2[40] __attribute__((aligned(16))) = {
37+
12 * 4,// Buf size
2738
0,// Request. Code 0
28-
MBOX_VC_PHYS_SIZE_TAG, 8, 0, 0, 0,// Physical size
29-
MBOX_VC_VIRT_SIZE_TAG, 8, 0, 0, 0,// Virtual size
30-
MBOX_VC_DEPTH_TAG | MBOX_SET_VALUE, 4, 4, 32,// Depth
31-
MBOX_VC_PITCH_TAG, 4, 0, 0,//Pitch
32-
MBOX_VC_FORMAT_TAG | MBOX_SET_VALUE, 4, 4, 0, //BGR
39+
MBOX_VC_VIRT_SIZE_TAG | MBOX_SET_VALUE, 8, 0, 0, 0,
3340
MBOX_VC_FRAMEBUFFER_TAG, 8, 0, 16, 0,
3441
0,// End
3542
};
@@ -48,6 +55,16 @@ bool VideoCoreGPUDriver::init(gpu_size preferred_screen_size){
4855
uint32_t depth = rmbox[15];
4956
stride = rmbox[19];
5057

58+
rmbox2[5] = virt_w;
59+
rmbox2[6] = virt_h*2;
60+
61+
if (!mailbox_call(rmbox2, 8)) {
62+
kprintf("[VIDEOCORE] Failed updating mailbox");
63+
return false;
64+
}
65+
66+
virt_h = rmbox2[6];
67+
5168
if (bpp != depth/8){
5269
kprintf("[VIDEOCORE] failed to initialize. Wrong BPP (%i), should be %i. Check your config.txt file",depth/8, bpp);
5370
return false;
@@ -56,15 +73,16 @@ bool VideoCoreGPUDriver::init(gpu_size preferred_screen_size){
5673
screen_size = (gpu_size){phys_w,phys_h};
5774
kprintf("[VIDEOCORE] Size %ix%i (%ix%i) (%ix%i) | %i (%i)",phys_w,phys_h,virt_w,virt_h,screen_size.width,screen_size.height,depth, stride);
5875

59-
framebuffer = (uint32_t*)(uintptr_t)rmbox[27];
60-
framebuffer_size = rmbox[28];
76+
framebuffer = (uint32_t*)(uintptr_t)rmbox2[10];
77+
framebuffer_size = rmbox2[11]/2;
6178
mem_page = palloc(0x1000, MEM_PRIV_KERNEL, MEM_RW | MEM_DEV, false);
62-
back_framebuffer = (uint32_t*)palloc(framebuffer_size, MEM_PRIV_SHARED, MEM_RW, true);
63-
//TODO: make backbuffer just framebuffer + bf_size/2
64-
kprintf("[VIDEOCORE] Framebuffer allocated to %x (%i). BPP %i. Stride %i",framebuffer, framebuffer_size, bpp, stride/bpp);
65-
mark_used((uintptr_t)framebuffer,count_pages(framebuffer_size,PAGE_SIZE));
66-
for (size_t i = (uintptr_t)framebuffer; i < (uintptr_t)framebuffer + framebuffer_size; i += GRANULE_4KB)
79+
back_framebuffer = (uint32_t*)((uintptr_t)framebuffer + framebuffer_size);
80+
81+
kprintf("[VIDEOCORE] Framebuffer allocated to %x (%i). BPP %i. Stride %i. Backbuffer at %x",framebuffer, framebuffer_size, bpp, stride/bpp,back_framebuffer);
82+
mark_used((uintptr_t)framebuffer,count_pages(rmbox2[11],PAGE_SIZE));
83+
for (size_t i = (uintptr_t)framebuffer; i < (uintptr_t)framebuffer + rmbox2[11]; i += GRANULE_4KB){
6784
register_device_memory(i,i);
85+
}
6886

6987
ctx = {
7088
.dirty_rects = {},
@@ -79,9 +97,20 @@ bool VideoCoreGPUDriver::init(gpu_size preferred_screen_size){
7997
return true;
8098
}
8199

100+
101+
volatile uint32_t swbox[40] __attribute__((aligned(16))) = {
102+
30 * 4,// Buf size
103+
0,// Request. Code 0
104+
MBOX_VC_OFFSET_TAG | MBOX_SET_VALUE, 8, 8, 0, 0,
105+
0,
106+
};
107+
82108
void VideoCoreGPUDriver::update_gpu_fb(){
83-
// memcpy(void *dest, const void *src, uint64_t count)
84-
//TODO: set fb offset to fb_size/2
109+
last_offset = screen_size.height - last_offset;
110+
swbox[6] = last_offset;
111+
if (!mailbox_call(swbox, 8)){
112+
kprintf("[VIDEOCORE] failed to swap buffer");
113+
}
85114
}
86115

87116
gpu_size VideoCoreGPUDriver::get_screen_size(){

kernel/graph/drivers/framebuffer_gpus/videocore/videocore.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ class VideoCoreGPUDriver : public FBGPUDriver {
1414

1515
~VideoCoreGPUDriver() = default;
1616

17+
protected:
18+
uintptr_t original_fb;
19+
uint32_t last_offset;
1720
};

kernel/kernel.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@
1717
#include "filesystem/filesystem.h"
1818
#include "dev/module_loader.h"
1919
#include "audio/audio.h"
20+
#include "mailbox/mailbox.h"
2021

2122
void kernel_main() {
2223

2324
detect_hardware();
2425

2526
mmu_alloc();
2627

28+
mailbox_init();
29+
2730
page_allocator_init();
2831

2932
set_exception_vectors();
3033

3134
init_main_process();
3235

33-
disable_visual();
36+
if (BOARD_TYPE == 1) disable_visual();
3437

3538
load_module(&console_module);
3639

kernel/mailbox/mailbox.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#include "mailbox.h"
2+
#include "memory/mmu.h"
3+
4+
void mailbox_init(){
5+
register_device_memory(MAILBOX_BASE, MAILBOX_BASE);
6+
}
27

38
int mailbox_call(volatile uint32_t* mbox, uint8_t channel) {
49
uint32_t addr = ((uint32_t)(uintptr_t)mbox) & ~0xF;

kernel/mailbox/mailbox.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#ifdef __cplusplus
2828
extern "C" {
2929
#endif
30+
void mailbox_init();
3031
int mailbox_call(volatile uint32_t* mbox, uint8_t channel);
3132
#ifdef __cplusplus
3233
}

0 commit comments

Comments
 (0)