1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 06:18:07 +00:00

refactor(core): adjust display api for syscall verifier

[no changelog]
This commit is contained in:
cepetr 2024-09-27 12:43:33 +02:00 committed by cepetr
parent 305f16c86b
commit 0312158aa1
11 changed files with 77 additions and 98 deletions

View File

@ -185,7 +185,12 @@ pub fn clear() {
#[cfg(feature = "xframebuffer")]
pub fn get_frame_buffer() -> (&'static mut [u8], usize) {
let fb_info = unsafe { ffi::display_get_frame_buffer() };
let mut fb_info = ffi::display_fb_info_t {
ptr: ptr::null_mut(),
stride: 0,
};
unsafe { ffi::display_get_frame_buffer(&mut fb_info) };
let fb = unsafe {
core::slice::from_raw_parts_mut(

View File

@ -177,8 +177,8 @@ __attribute((no_stack_protector)) void syscall_handler(uint32_t *args,
#if XFRAMEBUFFER
case SYSCALL_DISPLAY_GET_FB_INFO: {
display_fb_info_t *info = (display_fb_info_t *)args[0];
*info = display_get_frame_buffer();
display_fb_info_t *fb = (display_fb_info_t *)args[0];
args[0] = (uint32_t)display_get_frame_buffer(fb);
} break;
#else
case SYSCALL_DISPLAY_WAIT_FOR_SYNC: {

View File

@ -148,10 +148,8 @@ int display_get_orientation(void) {
#ifdef XFRAMEBUFFER
display_fb_info_t display_get_frame_buffer(void) {
display_fb_info_t info;
syscall_invoke1((uint32_t)&info, SYSCALL_DISPLAY_GET_FB_INFO);
return info;
bool display_get_frame_buffer(display_fb_info_t *fb) {
return (bool)syscall_invoke1((uint32_t)fb, SYSCALL_DISPLAY_GET_FB_INFO);
}
#else // XFRAMEBUFFER

View File

@ -144,15 +144,13 @@ void DISPLAY_TE_INTERRUPT_HANDLER(void) {
}
#endif
display_fb_info_t display_get_frame_buffer(void) {
bool display_get_frame_buffer(display_fb_info_t *fb) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
display_fb_info_t fb = {
.ptr = NULL,
.stride = 0,
};
return fb;
fb->ptr = NULL;
fb->stride = 0;
return false;
}
frame_buffer_state_t state;
@ -177,12 +175,10 @@ display_fb_info_t display_get_frame_buffer(void) {
drv->queue.entry[drv->queue.wix] = FB_STATE_PREPARING;
display_fb_info_t fb = {
.ptr = get_fb_ptr(drv->queue.wix),
.stride = DISPLAY_RESX * sizeof(uint16_t),
};
fb->ptr = get_fb_ptr(drv->queue.wix);
fb->stride = DISPLAY_RESX * sizeof(uint16_t);
return fb;
return true;
}
// Copies the frame buffer with the given index to the display
@ -289,9 +285,9 @@ void display_ensure_refreshed(void) {
}
void display_fill(const gfx_bitblt_t *bb) {
display_fb_info_t fb = display_get_frame_buffer();
display_fb_info_t fb;
if (fb.ptr == NULL) {
if (!display_get_frame_buffer(&fb)) {
return;
}
@ -303,9 +299,9 @@ void display_fill(const gfx_bitblt_t *bb) {
}
void display_copy_rgb565(const gfx_bitblt_t *bb) {
display_fb_info_t fb = display_get_frame_buffer();
display_fb_info_t fb;
if (fb.ptr == NULL) {
if (!display_get_frame_buffer(&fb)) {
return;
}
@ -317,9 +313,9 @@ void display_copy_rgb565(const gfx_bitblt_t *bb) {
}
void display_copy_mono1p(const gfx_bitblt_t *bb) {
display_fb_info_t fb = display_get_frame_buffer();
display_fb_info_t fb;
if (fb.ptr == NULL) {
if (!display_get_frame_buffer(&fb)) {
return;
}
@ -331,9 +327,9 @@ void display_copy_mono1p(const gfx_bitblt_t *bb) {
}
void display_copy_mono4(const gfx_bitblt_t *bb) {
display_fb_info_t fb = display_get_frame_buffer();
display_fb_info_t fb;
if (fb.ptr == NULL) {
if (!display_get_frame_buffer(&fb)) {
return;
}

View File

@ -123,21 +123,17 @@ int display_get_orientation(void) {
return drv->orientation_angle;
}
display_fb_info_t display_get_frame_buffer(void) {
bool display_get_frame_buffer(display_fb_info_t *fb) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
display_fb_info_t fb = {
.ptr = NULL,
.stride = 0,
};
return fb;
fb->ptr = NULL;
fb->stride = 0;
return false;
} else {
display_fb_info_t fb = {
.ptr = (void *)drv->framebuf,
.stride = DISPLAY_RESX * sizeof(uint16_t),
};
return fb;
fb->ptr = (void *)drv->framebuf;
fb->stride = DISPLAY_RESX * sizeof(uint16_t);
return true;
}
}

View File

@ -390,21 +390,17 @@ int display_get_orientation(void) {
return drv->orientation_angle;
}
display_fb_info_t display_get_frame_buffer(void) {
bool display_get_frame_buffer(display_fb_info_t *fb) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
const static display_fb_info_t fb = {
.ptr = NULL,
.stride = 0,
};
return fb;
fb->ptr = NULL;
fb->stride = 0;
return false;
} else {
display_fb_info_t fb = {
.ptr = &drv->framebuf[0],
.stride = DISPLAY_RESX,
};
return fb;
fb->ptr = &drv->framebuf[0];
fb->stride = DISPLAY_RESX;
return true;
}
}

View File

@ -359,21 +359,17 @@ int display_get_orientation(void) {
return drv->orientation_angle;
}
display_fb_info_t display_get_frame_buffer(void) {
bool display_get_frame_buffer(display_fb_info_t *fb) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
static const display_fb_info_t fb = {
.ptr = NULL,
.stride = 0,
};
return fb;
fb->ptr = NULL;
fb->stride = 0;
return false;
} else {
display_fb_info_t fb = {
.ptr = &drv->framebuf[0],
.stride = DISPLAY_RESX,
};
return fb;
fb->ptr = &drv->framebuf[0];
fb->stride = DISPLAY_RESX;
return true;
}
}
@ -395,9 +391,9 @@ void display_refresh(void) {
}
void display_fill(const gfx_bitblt_t *bb) {
display_fb_info_t fb = display_get_frame_buffer();
display_fb_info_t fb;
if (fb.ptr == NULL) {
if (!display_get_frame_buffer(&fb)) {
return;
}
@ -409,9 +405,9 @@ void display_fill(const gfx_bitblt_t *bb) {
}
void display_copy_mono1p(const gfx_bitblt_t *bb) {
display_fb_info_t fb = display_get_frame_buffer();
display_fb_info_t fb;
if (fb.ptr == NULL) {
if (!display_get_frame_buffer(&fb)) {
return;
}

View File

@ -161,9 +161,9 @@ int display_get_orientation(void) {
}
void display_fill(const gfx_bitblt_t *bb) {
display_fb_info_t fb = display_get_frame_buffer();
display_fb_info_t fb;
if (fb.ptr == NULL) {
if (!display_get_frame_buffer(&fb)) {
return;
}
@ -175,9 +175,9 @@ void display_fill(const gfx_bitblt_t *bb) {
}
void display_copy_rgb565(const gfx_bitblt_t *bb) {
display_fb_info_t fb = display_get_frame_buffer();
display_fb_info_t fb;
if (fb.ptr == NULL) {
if (!display_get_frame_buffer(&fb)) {
return;
}
@ -189,9 +189,9 @@ void display_copy_rgb565(const gfx_bitblt_t *bb) {
}
void display_copy_mono1p(const gfx_bitblt_t *bb) {
display_fb_info_t fb = display_get_frame_buffer();
display_fb_info_t fb;
if (fb.ptr == NULL) {
if (!display_get_frame_buffer(&fb)) {
return;
}
@ -203,9 +203,9 @@ void display_copy_mono1p(const gfx_bitblt_t *bb) {
}
void display_copy_mono4(const gfx_bitblt_t *bb) {
display_fb_info_t fb = display_get_frame_buffer();
display_fb_info_t fb;
if (fb.ptr == NULL) {
if (!display_get_frame_buffer(&fb)) {
return;
}

View File

@ -40,15 +40,13 @@ ALIGN_32BYTES(uint32_t physical_frame_buffer_1[PHYSICAL_FRAME_BUFFER_SIZE]);
__attribute__((section(".framebuffer_select"))) uint32_t current_frame_buffer =
0;
display_fb_info_t display_get_frame_buffer(void) {
bool display_get_frame_buffer(display_fb_info_t *fb) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
display_fb_info_t fb = {
.ptr = NULL,
.stride = 0,
};
return fb;
fb->ptr = NULL;
fb->stride = 0;
return false;
}
uintptr_t addr;
@ -66,12 +64,10 @@ display_fb_info_t display_get_frame_buffer(void) {
addr += (480 - DISPLAY_RESY) / 2 * sizeof(uint32_t);
addr += (480 - DISPLAY_RESX) / 2 * fb_stride;
display_fb_info_t fb = {
.ptr = (void *)addr,
.stride = fb_stride,
};
fb->ptr = (void *)addr;
fb->stride = fb_stride;
return fb;
return true;
}
void display_refresh(void) {

View File

@ -245,28 +245,22 @@ int display_get_orientation(void) {
}
#ifdef XFRAMEBUFFER
display_fb_info_t display_get_frame_buffer(void) {
bool display_get_frame_buffer(display_fb_info_t *fb) {
display_driver_t *drv = &g_display_driver;
if (!drv->initialized) {
display_fb_info_t fb = {
.ptr = NULL,
.stride = 0,
};
return fb;
fb->ptr = NULL;
fb->stride = 0;
return false;
} else {
#ifdef DISPLAY_MONO
display_fb_info_t fb = {
.ptr = drv->mono_framebuf,
.stride = DISPLAY_RESX,
};
fb->ptr = drv->mono_framebuf;
fb->stride = DISPLAY_RESX;
#else
display_fb_info_t fb = {
.ptr = drv->buffer->pixels,
.stride = DISPLAY_RESX * sizeof(uint16_t),
};
fb->ptr = drv->buffer->pixels;
fb->stride = DISPLAY_RESX * sizeof(uint16_t);
#endif
return fb;
return true;
}
}

View File

@ -114,7 +114,9 @@ typedef struct {
//
// If framebuffer is not available yet due to display refreshing etc.,
// the function may block until the buffer is ready to write.
display_fb_info_t display_get_frame_buffer(void);
//
// Return `false` if the framebuffer is not available.
bool display_get_frame_buffer(display_fb_info_t *fb);
#else // XFRAMEBUFFER