mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-06 18:26:11 +00:00
feat(code): introduce dma2d syscalls
[no changelog]
This commit is contained in:
parent
39245206f4
commit
19ba854c69
@ -17,7 +17,9 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "dma2d_bitblt.h"
|
#include <gfx/dma2d_bitblt.h>
|
||||||
|
|
||||||
|
#ifdef KERNEL_MODE
|
||||||
|
|
||||||
void gfx_bitblt_init(void) {
|
void gfx_bitblt_init(void) {
|
||||||
#if defined(USE_DMA2D) && !defined(TREZOR_EMULATOR)
|
#if defined(USE_DMA2D) && !defined(TREZOR_EMULATOR)
|
||||||
@ -31,6 +33,8 @@ void gfx_bitblt_deinit(void) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // KERNEL_MODE
|
||||||
|
|
||||||
void gfx_bitblt_wait(void) {
|
void gfx_bitblt_wait(void) {
|
||||||
#if defined(USE_DMA2D) && !defined(TREZOR_EMULATOR)
|
#if defined(USE_DMA2D) && !defined(TREZOR_EMULATOR)
|
||||||
dma2d_wait();
|
dma2d_wait();
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <gfx/gfx_bitblt.h>
|
#include <gfx/gfx_bitblt.h>
|
||||||
|
|
||||||
#if USE_DMA2D
|
#if USE_DMA2D
|
||||||
#include "dma2d_bitblt.h"
|
#include <gfx/dma2d_bitblt.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void gfx_rgb565_fill(const gfx_bitblt_t* bb) {
|
void gfx_rgb565_fill(const gfx_bitblt_t* bb) {
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <gfx/gfx_bitblt.h>
|
#include <gfx/gfx_bitblt.h>
|
||||||
|
|
||||||
#if USE_DMA2D
|
#if USE_DMA2D
|
||||||
#include "dma2d_bitblt.h"
|
#include <gfx/dma2d_bitblt.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void gfx_rgba8888_fill(const gfx_bitblt_t* bb) {
|
void gfx_rgba8888_fill(const gfx_bitblt_t* bb) {
|
||||||
|
@ -17,13 +17,14 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef KERNEL_MODE
|
||||||
|
|
||||||
#include <trezor_bsp.h>
|
#include <trezor_bsp.h>
|
||||||
#include <trezor_rtl.h>
|
#include <trezor_rtl.h>
|
||||||
|
|
||||||
|
#include <gfx/dma2d_bitblt.h>
|
||||||
#include <gfx/gfx_color.h>
|
#include <gfx/gfx_color.h>
|
||||||
|
|
||||||
#include "../dma2d_bitblt.h"
|
|
||||||
|
|
||||||
// Number of DMA2D layers - background (0) and foreground (1)
|
// Number of DMA2D layers - background (0) and foreground (1)
|
||||||
#define DMA2D_LAYER_COUNT 2
|
#define DMA2D_LAYER_COUNT 2
|
||||||
|
|
||||||
@ -907,14 +908,6 @@ bool dma2d_rgba8888_copy_y(const gfx_bitblt_t* bb) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temporary hack to invalidate CLUT cache used in jpeg decoder.
|
|
||||||
// This function should be removed in the future with DMA2D syscalls.
|
|
||||||
void dma2d_invalidate_clut(void) {
|
|
||||||
dma2d_driver_t* drv = &g_dma2d_driver;
|
|
||||||
if (!drv->initialized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
drv->clut_valid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // USE_HW_JPEG_DECODER
|
#endif // USE_HW_JPEG_DECODER
|
||||||
|
|
||||||
|
#endif // KERNEL_MODE
|
||||||
|
@ -21,12 +21,16 @@
|
|||||||
|
|
||||||
#include <gfx/gfx_bitblt.h>
|
#include <gfx/gfx_bitblt.h>
|
||||||
|
|
||||||
|
#ifdef KERNEL_MODE
|
||||||
|
|
||||||
// Initializes DMA2D peripheral
|
// Initializes DMA2D peripheral
|
||||||
void dma2d_init(void);
|
void dma2d_init(void);
|
||||||
|
|
||||||
// Deinitializes DMA2D peripheral
|
// Deinitializes DMA2D peripheral
|
||||||
void dma2d_deinit(void);
|
void dma2d_deinit(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// Waits until any pending DMA2D operation is finished
|
// Waits until any pending DMA2D operation is finished
|
||||||
void dma2d_wait(void);
|
void dma2d_wait(void);
|
||||||
|
|
@ -17,8 +17,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef GFX_BITBLT_H
|
#pragma once
|
||||||
#define GFX_BITBLT_H
|
|
||||||
|
|
||||||
#include <trezor_types.h>
|
#include <trezor_types.h>
|
||||||
|
|
||||||
@ -78,12 +77,16 @@ typedef struct {
|
|||||||
|
|
||||||
} gfx_bitblt_t;
|
} gfx_bitblt_t;
|
||||||
|
|
||||||
|
#ifdef KERNEL_MODE
|
||||||
|
|
||||||
// Initializes bitblt operations
|
// Initializes bitblt operations
|
||||||
void gfx_bitblt_init(void);
|
void gfx_bitblt_init(void);
|
||||||
|
|
||||||
// Deinitializes bitblt operations
|
// Deinitializes bitblt operations
|
||||||
void gfx_bitblt_deinit(void);
|
void gfx_bitblt_deinit(void);
|
||||||
|
|
||||||
|
#endif // KERNEL_MODE
|
||||||
|
|
||||||
// If the bitblt operation is asynchronous, waits until it's finished
|
// If the bitblt operation is asynchronous, waits until it's finished
|
||||||
void gfx_bitblt_wait(void);
|
void gfx_bitblt_wait(void);
|
||||||
|
|
||||||
@ -133,5 +136,3 @@ void gfx_mono8_blend_mono1p(const gfx_bitblt_t* bb);
|
|||||||
// Blends a mono bitmap (with 4-bit alpha channel)
|
// Blends a mono bitmap (with 4-bit alpha channel)
|
||||||
// with the destination bitmap
|
// with the destination bitmap
|
||||||
void gfx_mono8_blend_mono4(const gfx_bitblt_t* bb);
|
void gfx_mono8_blend_mono4(const gfx_bitblt_t* bb);
|
||||||
|
|
||||||
#endif // GFX_BITBLT_H
|
|
||||||
|
@ -22,14 +22,11 @@
|
|||||||
#include <trezor_bsp.h>
|
#include <trezor_bsp.h>
|
||||||
#include <trezor_rtl.h>
|
#include <trezor_rtl.h>
|
||||||
|
|
||||||
|
#include <gfx/dma2d_bitblt.h>
|
||||||
#include <gfx/jpegdec.h>
|
#include <gfx/jpegdec.h>
|
||||||
#include <rtl/sizedefs.h>
|
#include <rtl/sizedefs.h>
|
||||||
#include <sys/systick.h>
|
#include <sys/systick.h>
|
||||||
|
|
||||||
#include <../bitblt/dma2d_bitblt.h>
|
|
||||||
|
|
||||||
#include <sys/trustzone.h>
|
|
||||||
|
|
||||||
// Fixes of STMicro bugs in cmsis-device-u5
|
// Fixes of STMicro bugs in cmsis-device-u5
|
||||||
#undef JPEG_BASE_S
|
#undef JPEG_BASE_S
|
||||||
#define JPEG_BASE_S (AHB1PERIPH_BASE_S + 0x0A000UL)
|
#define JPEG_BASE_S (AHB1PERIPH_BASE_S + 0x0A000UL)
|
||||||
@ -441,10 +438,6 @@ bool jpegdec_get_slice_rgba8888(uint32_t *rgba8888, jpegdec_slice_t *slice) {
|
|||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
tz_set_dma2d_unpriv(false);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (dec->image.format) {
|
switch (dec->image.format) {
|
||||||
case JPEGDEC_IMAGE_YCBCR420:
|
case JPEGDEC_IMAGE_YCBCR420:
|
||||||
result = dma2d_rgba8888_copy_ycbcr420(&bb);
|
result = dma2d_rgba8888_copy_ycbcr420(&bb);
|
||||||
@ -467,10 +460,6 @@ bool jpegdec_get_slice_rgba8888(uint32_t *rgba8888, jpegdec_slice_t *slice) {
|
|||||||
// data in the `rgba8888` buffer immediately.
|
// data in the `rgba8888` buffer immediately.
|
||||||
dma2d_wait();
|
dma2d_wait();
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
tz_set_dma2d_unpriv(true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,10 +69,6 @@ void display_set_unpriv_access(bool unpriv) {
|
|||||||
tz_set_gfxmmu_unpriv(unpriv);
|
tz_set_gfxmmu_unpriv(unpriv);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_DMA2D
|
|
||||||
tz_set_dma2d_unpriv(unpriv);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif // USE_TRUSTZONE
|
#endif // USE_TRUSTZONE
|
||||||
|
|
||||||
@ -121,11 +117,11 @@ bool display_get_frame_buffer(display_fb_info_t *fb) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fb->addr = get_fb_ptr(fb_idx);
|
fb->ptr = get_fb_ptr(fb_idx);
|
||||||
fb->stride = FRAME_BUFFER_PIXELS_PER_LINE * FB_PIXEL_SIZE;
|
fb->stride = FRAME_BUFFER_PIXELS_PER_LINE * FB_PIXEL_SIZE;
|
||||||
fb->size = fb->stride * DISPLAY_RESY;
|
fb->size = fb->stride * DISPLAY_RESY;
|
||||||
|
|
||||||
mpu_set_active_fb(fb->addr, fb->size);
|
mpu_set_active_fb(fb->ptr, fb->size);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -84,10 +84,6 @@ void display_set_unpriv_access(bool unpriv) {
|
|||||||
tz_set_sram_unpriv((uint32_t)physical_frame_buffer_1,
|
tz_set_sram_unpriv((uint32_t)physical_frame_buffer_1,
|
||||||
PHYSICAL_FRAME_BUFFER_SIZE, unpriv);
|
PHYSICAL_FRAME_BUFFER_SIZE, unpriv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_DMA2D
|
|
||||||
tz_set_dma2d_unpriv(unpriv);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif // USE_TRUSTZONE
|
#endif // USE_TRUSTZONE
|
||||||
|
|
||||||
|
@ -45,9 +45,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(uint32_t cmd, void *arg) {
|
int main(uint32_t cmd, void *arg) {
|
||||||
// This call will be removed in the future with DMA2D syscalls.
|
|
||||||
gfx_bitblt_init();
|
|
||||||
|
|
||||||
if (cmd == 1) {
|
if (cmd == 1) {
|
||||||
systask_postmortem_t *info = (systask_postmortem_t *)arg;
|
systask_postmortem_t *info = (systask_postmortem_t *)arg;
|
||||||
rsod_gui(info);
|
rsod_gui(info);
|
||||||
|
@ -76,7 +76,11 @@ void mpu_restore(mpu_mode_t mode);
|
|||||||
//
|
//
|
||||||
// Addr and size must be aligned to the 32-byte boundary.
|
// Addr and size must be aligned to the 32-byte boundary.
|
||||||
// If addr == 0, the framebuffer is not accessible.
|
// If addr == 0, the framebuffer is not accessible.
|
||||||
void mpu_set_active_fb(void* addr, size_t size);
|
void mpu_set_active_fb(const void* addr, size_t size);
|
||||||
|
|
||||||
|
// Returns true if the given address and size are inside
|
||||||
|
// the active framebuffer previously set by `mpu_set_active_fb()`.
|
||||||
|
bool mpu_inside_active_fb(const void* addr, size_t size);
|
||||||
|
|
||||||
#endif // KERNEL_MODE
|
#endif // KERNEL_MODE
|
||||||
|
|
||||||
|
@ -198,10 +198,15 @@ mpu_mode_t mpu_get_mode(void) {
|
|||||||
return drv->mode;
|
return drv->mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mpu_set_active_fb(void* addr, size_t size) {
|
void mpu_set_active_fb(const void* addr, size_t size) {
|
||||||
// Not implemented on STM32F4
|
// Not implemented on STM32F4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool mpu_inside_active_fb(const void* addr, size_t size) {
|
||||||
|
// Not implemented on STM32F4
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// STM32F4xx memory map
|
// STM32F4xx memory map
|
||||||
//
|
//
|
||||||
// 0x08000000 2MB FLASH
|
// 0x08000000 2MB FLASH
|
||||||
@ -347,11 +352,6 @@ mpu_mode_t mpu_reconfig(mpu_mode_t mode) {
|
|||||||
SET_REGION( 7, 0x00000000, SIZE_4GB, 0xBB, SRAM, FULL_ACCESS );
|
SET_REGION( 7, 0x00000000, SIZE_4GB, 0xBB, SRAM, FULL_ACCESS );
|
||||||
break;
|
break;
|
||||||
#else
|
#else
|
||||||
case MPU_MODE_APP:
|
|
||||||
// Dma2D (Unprivileged, Read-Write, Non-Executable)
|
|
||||||
// 3KB = 4KB except 1/4 at end
|
|
||||||
SET_REGION( 7, 0x4002B000, SIZE_4KB, 0xC0, PERIPH, FULL_ACCESS );
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
// All Peripherals (Privileged, Read-Write, Non-Executable)
|
// All Peripherals (Privileged, Read-Write, Non-Executable)
|
||||||
SET_REGION( 7, PERIPH_BASE, SIZE_1GB, 0x00, PERIPH, PRIV_RW );
|
SET_REGION( 7, PERIPH_BASE, SIZE_1GB, 0x00, PERIPH, PRIV_RW );
|
||||||
|
@ -262,7 +262,7 @@ mpu_mode_t mpu_get_mode(void) {
|
|||||||
return drv->mode;
|
return drv->mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mpu_set_active_fb(void* addr, size_t size) {
|
void mpu_set_active_fb(const void* addr, size_t size) {
|
||||||
mpu_driver_t* drv = &g_mpu_driver;
|
mpu_driver_t* drv = &g_mpu_driver;
|
||||||
|
|
||||||
if (!drv->initialized) {
|
if (!drv->initialized) {
|
||||||
@ -279,6 +279,24 @@ void mpu_set_active_fb(void* addr, size_t size) {
|
|||||||
mpu_reconfig(drv->mode);
|
mpu_reconfig(drv->mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool mpu_inside_active_fb(const void* addr, size_t size) {
|
||||||
|
mpu_driver_t* drv = &g_mpu_driver;
|
||||||
|
|
||||||
|
if (!drv->initialized) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
irq_key_t lock = irq_lock();
|
||||||
|
|
||||||
|
bool result =
|
||||||
|
((uintptr_t)addr >= drv->active_fb_addr) &&
|
||||||
|
((uintptr_t)addr + size <= drv->active_fb_addr + drv->active_fb_size);
|
||||||
|
|
||||||
|
irq_unlock(lock);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
mpu_mode_t mpu_reconfig(mpu_mode_t mode) {
|
mpu_mode_t mpu_reconfig(mpu_mode_t mode) {
|
||||||
mpu_driver_t* drv = &g_mpu_driver;
|
mpu_driver_t* drv = &g_mpu_driver;
|
||||||
|
|
||||||
@ -368,10 +386,6 @@ mpu_mode_t mpu_reconfig(mpu_mode_t mode) {
|
|||||||
SET_REGION( 7, SAES_RAM_START, SAES_RAM_SIZE, SRAM, YES, YES ); // Unprivileged kernel SRAM
|
SET_REGION( 7, SAES_RAM_START, SAES_RAM_SIZE, SRAM, YES, YES ); // Unprivileged kernel SRAM
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case MPU_MODE_APP:
|
|
||||||
// DMA2D peripherals (Unprivileged, Read-Write, Non-Executable)
|
|
||||||
SET_REGION( 7, 0x5002B000, SIZE_3K, PERIPHERAL, YES, YES );
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
// All peripherals (Privileged, Read-Write, Non-Executable)
|
// All peripherals (Privileged, Read-Write, Non-Executable)
|
||||||
SET_REGION( 7, PERIPH_BASE_NS, PERIPH_SIZE, PERIPHERAL, YES, NO );
|
SET_REGION( 7, PERIPH_BASE_NS, PERIPH_SIZE, PERIPHERAL, YES, NO );
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <trezor_rtl.h>
|
#include <trezor_rtl.h>
|
||||||
|
|
||||||
|
#include <gfx/dma2d_bitblt.h>
|
||||||
#include <io/display.h>
|
#include <io/display.h>
|
||||||
#include <io/usb.h>
|
#include <io/usb.h>
|
||||||
#include <io/usb_hid.h>
|
#include <io/usb_hid.h>
|
||||||
@ -762,6 +763,67 @@ __attribute((no_stack_protector)) void syscall_handler(uint32_t *args,
|
|||||||
}
|
}
|
||||||
#endif // USE_HW_JPEG_DECODER
|
#endif // USE_HW_JPEG_DECODER
|
||||||
|
|
||||||
|
#ifdef USE_DMA2D
|
||||||
|
case SYSCALL_DMA2D_WAIT: {
|
||||||
|
dma2d_wait();
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case SYSCALL_DMA2D_RGB565_FILL: {
|
||||||
|
const gfx_bitblt_t *bb = (const gfx_bitblt_t *)args[0];
|
||||||
|
args[0] = dma2d_rgb565_fill__verified(bb);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case SYSCALL_DMA2D_RGB565_COPY_MONO4: {
|
||||||
|
const gfx_bitblt_t *bb = (const gfx_bitblt_t *)args[0];
|
||||||
|
args[0] = dma2d_rgb565_copy_mono4__verified(bb);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case SYSCALL_DMA2D_RGB565_COPY_RGB565: {
|
||||||
|
const gfx_bitblt_t *bb = (const gfx_bitblt_t *)args[0];
|
||||||
|
args[0] = dma2d_rgb565_copy_rgb565__verified(bb);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case SYSCALL_DMA2D_RGB565_BLEND_MONO4: {
|
||||||
|
const gfx_bitblt_t *bb = (const gfx_bitblt_t *)args[0];
|
||||||
|
args[0] = dma2d_rgb565_blend_mono4__verified(bb);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case SYSCALL_DMA2D_RGB565_BLEND_MONO8: {
|
||||||
|
const gfx_bitblt_t *bb = (const gfx_bitblt_t *)args[0];
|
||||||
|
args[0] = dma2d_rgb565_blend_mono8__verified(bb);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case SYSCALL_DMA2D_RGBA8888_FILL: {
|
||||||
|
const gfx_bitblt_t *bb = (const gfx_bitblt_t *)args[0];
|
||||||
|
args[0] = dma2d_rgba8888_fill__verified(bb);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case SYSCALL_DMA2D_RGBA8888_COPY_MONO4: {
|
||||||
|
const gfx_bitblt_t *bb = (const gfx_bitblt_t *)args[0];
|
||||||
|
args[0] = dma2d_rgba8888_copy_mono4__verified(bb);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case SYSCALL_DMA2D_RGBA8888_COPY_RGB565: {
|
||||||
|
const gfx_bitblt_t *bb = (const gfx_bitblt_t *)args[0];
|
||||||
|
args[0] = dma2d_rgba8888_copy_rgb565__verified(bb);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case SYSCALL_DMA2D_RGBA8888_COPY_RGBA8888: {
|
||||||
|
const gfx_bitblt_t *bb = (const gfx_bitblt_t *)args[0];
|
||||||
|
args[0] = dma2d_rgba8888_copy_rgba8888__verified(bb);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case SYSCALL_DMA2D_RGBA8888_BLEND_MONO4: {
|
||||||
|
const gfx_bitblt_t *bb = (const gfx_bitblt_t *)args[0];
|
||||||
|
args[0] = dma2d_rgba8888_blend_mono4__verified(bb);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case SYSCALL_DMA2D_RGBA8888_BLEND_MONO8: {
|
||||||
|
const gfx_bitblt_t *bb = (const gfx_bitblt_t *)args[0];
|
||||||
|
args[0] = dma2d_rgba8888_blend_mono8__verified(bb);
|
||||||
|
} break;
|
||||||
|
#endif // USE_DMA2D
|
||||||
|
|
||||||
default:
|
default:
|
||||||
system_exit_fatal("Invalid syscall", __FILE__, __LINE__);
|
system_exit_fatal("Invalid syscall", __FILE__, __LINE__);
|
||||||
break;
|
break;
|
||||||
|
@ -156,4 +156,17 @@ typedef enum {
|
|||||||
SYSCALL_JPEGDEC_GET_INFO,
|
SYSCALL_JPEGDEC_GET_INFO,
|
||||||
SYSCALL_JPEGDEC_GET_SLICE_RGBA8888,
|
SYSCALL_JPEGDEC_GET_SLICE_RGBA8888,
|
||||||
|
|
||||||
|
SYSCALL_DMA2D_WAIT,
|
||||||
|
SYSCALL_DMA2D_RGB565_FILL,
|
||||||
|
SYSCALL_DMA2D_RGB565_COPY_MONO4,
|
||||||
|
SYSCALL_DMA2D_RGB565_COPY_RGB565,
|
||||||
|
SYSCALL_DMA2D_RGB565_BLEND_MONO4,
|
||||||
|
SYSCALL_DMA2D_RGB565_BLEND_MONO8,
|
||||||
|
SYSCALL_DMA2D_RGBA8888_FILL,
|
||||||
|
SYSCALL_DMA2D_RGBA8888_COPY_MONO4,
|
||||||
|
SYSCALL_DMA2D_RGBA8888_COPY_RGB565,
|
||||||
|
SYSCALL_DMA2D_RGBA8888_COPY_RGBA8888,
|
||||||
|
SYSCALL_DMA2D_RGBA8888_BLEND_MONO4,
|
||||||
|
SYSCALL_DMA2D_RGBA8888_BLEND_MONO8,
|
||||||
|
|
||||||
} syscall_number_t;
|
} syscall_number_t;
|
||||||
|
@ -55,6 +55,12 @@ bool probe_read_access(const void *addr, size_t len) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef FRAMEBUFFER
|
||||||
|
if (mpu_inside_active_fb(addr, len)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (inside_area(addr, len, &applet->layout.code1)) {
|
if (inside_area(addr, len, &applet->layout.code1)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -99,6 +105,12 @@ bool probe_write_access(void *addr, size_t len) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef FRAMEBUFFER
|
||||||
|
if (mpu_inside_active_fb(addr, len)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -705,15 +705,7 @@ bool powerctl_get_status(powerctl_status_t *status) {
|
|||||||
|
|
||||||
bool jpegdec_open(void) { return (bool)syscall_invoke0(SYSCALL_JPEGDEC_OPEN); }
|
bool jpegdec_open(void) { return (bool)syscall_invoke0(SYSCALL_JPEGDEC_OPEN); }
|
||||||
|
|
||||||
void jpegdec_close(void) {
|
void jpegdec_close(void) { syscall_invoke0(SYSCALL_JPEGDEC_CLOSE); }
|
||||||
{
|
|
||||||
// Temporary hack to fix the problem with dual DMA2D driver in
|
|
||||||
// user/kernel space - will be removed in the future with DMA2D syscalls
|
|
||||||
extern void dma2d_invalidate_clut();
|
|
||||||
dma2d_invalidate_clut();
|
|
||||||
}
|
|
||||||
syscall_invoke0(SYSCALL_JPEGDEC_CLOSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
jpegdec_state_t jpegdec_process(jpegdec_input_t *input) {
|
jpegdec_state_t jpegdec_process(jpegdec_input_t *input) {
|
||||||
return (jpegdec_state_t)syscall_invoke1((uint32_t)input,
|
return (jpegdec_state_t)syscall_invoke1((uint32_t)input,
|
||||||
@ -731,4 +723,64 @@ bool jpegdec_get_slice_rgba8888(uint32_t *rgba8888, jpegdec_slice_t *slice) {
|
|||||||
|
|
||||||
#endif // USE_HW_JPEG_DECODER
|
#endif // USE_HW_JPEG_DECODER
|
||||||
|
|
||||||
|
// =============================================================================
|
||||||
|
// gfx_bitblt.h
|
||||||
|
// =============================================================================
|
||||||
|
|
||||||
|
#ifdef USE_DMA2D
|
||||||
|
|
||||||
|
#include <gfx/dma2d_bitblt.h>
|
||||||
|
|
||||||
|
void dma2d_wait(void) { syscall_invoke0(SYSCALL_DMA2D_WAIT); }
|
||||||
|
|
||||||
|
bool dma2d_rgb565_fill(const gfx_bitblt_t *bb) {
|
||||||
|
return (bool)syscall_invoke1((uint32_t)bb, SYSCALL_DMA2D_RGB565_FILL);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgb565_copy_mono4(const gfx_bitblt_t *bb) {
|
||||||
|
return (bool)syscall_invoke1((uint32_t)bb, SYSCALL_DMA2D_RGB565_COPY_MONO4);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgb565_copy_rgb565(const gfx_bitblt_t *bb) {
|
||||||
|
return (bool)syscall_invoke1((uint32_t)bb, SYSCALL_DMA2D_RGB565_COPY_RGB565);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgb565_blend_mono4(const gfx_bitblt_t *bb) {
|
||||||
|
return (bool)syscall_invoke1((uint32_t)bb, SYSCALL_DMA2D_RGB565_BLEND_MONO4);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgb565_blend_mono8(const gfx_bitblt_t *bb) {
|
||||||
|
return (bool)syscall_invoke1((uint32_t)bb, SYSCALL_DMA2D_RGB565_BLEND_MONO8);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_fill(const gfx_bitblt_t *bb) {
|
||||||
|
return (bool)syscall_invoke1((uint32_t)bb, SYSCALL_DMA2D_RGBA8888_FILL);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_copy_mono4(const gfx_bitblt_t *bb) {
|
||||||
|
return (bool)syscall_invoke1((uint32_t)bb, SYSCALL_DMA2D_RGBA8888_COPY_MONO4);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_copy_rgb565(const gfx_bitblt_t *bb) {
|
||||||
|
return (bool)syscall_invoke1((uint32_t)bb,
|
||||||
|
SYSCALL_DMA2D_RGBA8888_COPY_RGB565);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_copy_rgba8888(const gfx_bitblt_t *bb) {
|
||||||
|
return (bool)syscall_invoke1((uint32_t)bb,
|
||||||
|
SYSCALL_DMA2D_RGBA8888_COPY_RGBA8888);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_blend_mono4(const gfx_bitblt_t *bb) {
|
||||||
|
return (bool)syscall_invoke1((uint32_t)bb,
|
||||||
|
SYSCALL_DMA2D_RGBA8888_BLEND_MONO4);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_blend_mono8(const gfx_bitblt_t *bb) {
|
||||||
|
return (bool)syscall_invoke1((uint32_t)bb,
|
||||||
|
SYSCALL_DMA2D_RGBA8888_BLEND_MONO8);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // USE_DMA2D
|
||||||
|
|
||||||
#endif // KERNEL_MODE
|
#endif // KERNEL_MODE
|
||||||
|
@ -26,6 +26,19 @@
|
|||||||
|
|
||||||
#ifdef SYSCALL_DISPATCH
|
#ifdef SYSCALL_DISPATCH
|
||||||
|
|
||||||
|
// Checks if bitblt destination is accessible
|
||||||
|
#define CHECK_BB_DST(_bb) \
|
||||||
|
if (!probe_write_access((_bb)->dst_row, \
|
||||||
|
(_bb)->dst_stride * (_bb)->height)) { \
|
||||||
|
goto access_violation; \
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks if bitblt source is accessible
|
||||||
|
#define CHECK_BB_SRC(_bb) \
|
||||||
|
if (!probe_read_access((_bb)->src_row, (_bb)->src_stride * (_bb)->height)) { \
|
||||||
|
goto access_violation; \
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
void system_exit__verified(int exit_code) {
|
void system_exit__verified(int exit_code) {
|
||||||
@ -176,15 +189,9 @@ void display_copy_rgb565__verified(const gfx_bitblt_t *bb) {
|
|||||||
|
|
||||||
gfx_bitblt_t bb_copy = *bb;
|
gfx_bitblt_t bb_copy = *bb;
|
||||||
|
|
||||||
uint8_t *src_ptr = (uint8_t *)bb_copy.src_row;
|
CHECK_BB_SRC(&bb_copy);
|
||||||
size_t src_len = bb_copy.src_stride * bb_copy.height;
|
|
||||||
|
|
||||||
if (!probe_read_access(src_ptr, src_len)) {
|
|
||||||
goto access_violation;
|
|
||||||
}
|
|
||||||
|
|
||||||
display_copy_rgb565(&bb_copy);
|
display_copy_rgb565(&bb_copy);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
access_violation:
|
access_violation:
|
||||||
@ -850,4 +857,193 @@ access_violation:
|
|||||||
|
|
||||||
#endif // USE_HW_JPEG_DECODER
|
#endif // USE_HW_JPEG_DECODER
|
||||||
|
|
||||||
|
#ifdef USE_DMA2D
|
||||||
|
|
||||||
|
bool dma2d_rgb565_fill__verified(const gfx_bitblt_t *bb) {
|
||||||
|
if (!probe_read_access(bb, sizeof(*bb))) {
|
||||||
|
goto access_violation;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_bitblt_t bb_copy = *bb;
|
||||||
|
|
||||||
|
CHECK_BB_DST(&bb_copy);
|
||||||
|
|
||||||
|
return dma2d_rgb565_fill(&bb_copy);
|
||||||
|
|
||||||
|
access_violation:
|
||||||
|
apptask_access_violation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgb565_copy_mono4__verified(const gfx_bitblt_t *bb) {
|
||||||
|
if (!probe_read_access(bb, sizeof(*bb))) {
|
||||||
|
goto access_violation;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_bitblt_t bb_copy = *bb;
|
||||||
|
|
||||||
|
CHECK_BB_DST(&bb_copy);
|
||||||
|
CHECK_BB_SRC(&bb_copy);
|
||||||
|
|
||||||
|
return dma2d_rgb565_copy_mono4(&bb_copy);
|
||||||
|
|
||||||
|
access_violation:
|
||||||
|
apptask_access_violation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgb565_copy_rgb565__verified(const gfx_bitblt_t *bb) {
|
||||||
|
if (!probe_read_access(bb, sizeof(*bb))) {
|
||||||
|
goto access_violation;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_bitblt_t bb_copy = *bb;
|
||||||
|
|
||||||
|
CHECK_BB_DST(&bb_copy);
|
||||||
|
CHECK_BB_SRC(&bb_copy);
|
||||||
|
|
||||||
|
return dma2d_rgb565_copy_rgb565(&bb_copy);
|
||||||
|
|
||||||
|
access_violation:
|
||||||
|
apptask_access_violation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgb565_blend_mono4__verified(const gfx_bitblt_t *bb) {
|
||||||
|
if (!probe_read_access(bb, sizeof(*bb))) {
|
||||||
|
goto access_violation;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_bitblt_t bb_copy = *bb;
|
||||||
|
|
||||||
|
CHECK_BB_DST(&bb_copy);
|
||||||
|
CHECK_BB_SRC(&bb_copy);
|
||||||
|
|
||||||
|
return dma2d_rgb565_blend_mono4(&bb_copy);
|
||||||
|
|
||||||
|
access_violation:
|
||||||
|
apptask_access_violation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgb565_blend_mono8__verified(const gfx_bitblt_t *bb) {
|
||||||
|
if (!probe_read_access(bb, sizeof(*bb))) {
|
||||||
|
goto access_violation;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_bitblt_t bb_copy = *bb;
|
||||||
|
|
||||||
|
CHECK_BB_DST(&bb_copy);
|
||||||
|
CHECK_BB_SRC(&bb_copy);
|
||||||
|
|
||||||
|
return dma2d_rgb565_blend_mono8(&bb_copy);
|
||||||
|
|
||||||
|
access_violation:
|
||||||
|
apptask_access_violation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_fill__verified(const gfx_bitblt_t *bb) {
|
||||||
|
if (!probe_read_access(bb, sizeof(*bb))) {
|
||||||
|
goto access_violation;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_bitblt_t bb_copy = *bb;
|
||||||
|
|
||||||
|
CHECK_BB_DST(&bb_copy);
|
||||||
|
|
||||||
|
return dma2d_rgba8888_fill(&bb_copy);
|
||||||
|
|
||||||
|
access_violation:
|
||||||
|
apptask_access_violation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_copy_mono4__verified(const gfx_bitblt_t *bb) {
|
||||||
|
if (!probe_read_access(bb, sizeof(*bb))) {
|
||||||
|
goto access_violation;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_bitblt_t bb_copy = *bb;
|
||||||
|
|
||||||
|
CHECK_BB_DST(&bb_copy);
|
||||||
|
CHECK_BB_SRC(&bb_copy);
|
||||||
|
|
||||||
|
return dma2d_rgba8888_copy_mono4(&bb_copy);
|
||||||
|
|
||||||
|
access_violation:
|
||||||
|
apptask_access_violation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_copy_rgb565__verified(const gfx_bitblt_t *bb) {
|
||||||
|
if (!probe_read_access(bb, sizeof(*bb))) {
|
||||||
|
goto access_violation;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_bitblt_t bb_copy = *bb;
|
||||||
|
|
||||||
|
CHECK_BB_DST(&bb_copy);
|
||||||
|
CHECK_BB_SRC(&bb_copy);
|
||||||
|
|
||||||
|
return dma2d_rgba8888_copy_rgb565(&bb_copy);
|
||||||
|
|
||||||
|
access_violation:
|
||||||
|
apptask_access_violation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_copy_rgba8888__verified(const gfx_bitblt_t *bb) {
|
||||||
|
if (!probe_read_access(bb, sizeof(*bb))) {
|
||||||
|
goto access_violation;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_bitblt_t bb_copy = *bb;
|
||||||
|
|
||||||
|
CHECK_BB_DST(&bb_copy);
|
||||||
|
CHECK_BB_SRC(&bb_copy);
|
||||||
|
|
||||||
|
return dma2d_rgba8888_copy_rgba8888(&bb_copy);
|
||||||
|
|
||||||
|
access_violation:
|
||||||
|
apptask_access_violation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_blend_mono4__verified(const gfx_bitblt_t *bb) {
|
||||||
|
if (!probe_read_access(bb, sizeof(*bb))) {
|
||||||
|
goto access_violation;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_bitblt_t bb_copy = *bb;
|
||||||
|
|
||||||
|
CHECK_BB_DST(&bb_copy);
|
||||||
|
CHECK_BB_SRC(&bb_copy);
|
||||||
|
|
||||||
|
return dma2d_rgba8888_blend_mono4(&bb_copy);
|
||||||
|
|
||||||
|
access_violation:
|
||||||
|
apptask_access_violation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_blend_mono8__verified(const gfx_bitblt_t *bb) {
|
||||||
|
if (!probe_read_access(bb, sizeof(*bb))) {
|
||||||
|
goto access_violation;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_bitblt_t bb_copy = *bb;
|
||||||
|
|
||||||
|
CHECK_BB_DST(&bb_copy);
|
||||||
|
CHECK_BB_SRC(&bb_copy);
|
||||||
|
|
||||||
|
return dma2d_rgba8888_blend_mono8(&bb_copy);
|
||||||
|
|
||||||
|
access_violation:
|
||||||
|
apptask_access_violation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // SYSCALL_DISPATCH
|
#endif // SYSCALL_DISPATCH
|
||||||
|
@ -226,4 +226,33 @@ bool jpegdec_get_slice_rgba8888__verified(void *rgba8888,
|
|||||||
|
|
||||||
#endif // USE_HW_JPEG_DECODER
|
#endif // USE_HW_JPEG_DECODER
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
#ifdef USE_DMA2D
|
||||||
|
|
||||||
|
#include <gfx/dma2d_bitblt.h>
|
||||||
|
|
||||||
|
bool dma2d_rgb565_fill__verified(const gfx_bitblt_t *bb);
|
||||||
|
|
||||||
|
bool dma2d_rgb565_copy_mono4__verified(const gfx_bitblt_t *bb);
|
||||||
|
|
||||||
|
bool dma2d_rgb565_copy_rgb565__verified(const gfx_bitblt_t *bb);
|
||||||
|
|
||||||
|
bool dma2d_rgb565_blend_mono4__verified(const gfx_bitblt_t *bb);
|
||||||
|
|
||||||
|
bool dma2d_rgb565_blend_mono8__verified(const gfx_bitblt_t *bb);
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_fill__verified(const gfx_bitblt_t *bb);
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_copy_mono4__verified(const gfx_bitblt_t *bb);
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_copy_rgb565__verified(const gfx_bitblt_t *bb);
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_copy_rgba8888__verified(const gfx_bitblt_t *bb);
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_blend_mono4__verified(const gfx_bitblt_t *bb);
|
||||||
|
|
||||||
|
bool dma2d_rgba8888_blend_mono8__verified(const gfx_bitblt_t *bb);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // SYSCALL_DISPATCH
|
#endif // SYSCALL_DISPATCH
|
||||||
|
@ -55,9 +55,6 @@ void tz_set_saes_unpriv(bool unpriv);
|
|||||||
// Sets unprivileged access to the TAMP peripheral.
|
// Sets unprivileged access to the TAMP peripheral.
|
||||||
void tz_set_tamper_unpriv(bool unpriv);
|
void tz_set_tamper_unpriv(bool unpriv);
|
||||||
|
|
||||||
// Sets unprivileged access to the DMA2D peripheral.
|
|
||||||
void tz_set_dma2d_unpriv(bool unpriv);
|
|
||||||
|
|
||||||
// Sets unprivileged access to the GFXMMU peripheral.
|
// Sets unprivileged access to the GFXMMU peripheral.
|
||||||
void tz_set_gfxmmu_unpriv(bool unpriv);
|
void tz_set_gfxmmu_unpriv(bool unpriv);
|
||||||
|
|
||||||
|
@ -349,12 +349,6 @@ void tz_set_tamper_unpriv(bool unpriv) {
|
|||||||
unpriv ? GTZC_TZSC_PERIPH_NPRIV : GTZC_TZSC_PERIPH_PRIV);
|
unpriv ? GTZC_TZSC_PERIPH_NPRIV : GTZC_TZSC_PERIPH_PRIV);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tz_set_dma2d_unpriv(bool unpriv) {
|
|
||||||
HAL_GTZC_TZSC_ConfigPeriphAttributes(
|
|
||||||
GTZC_PERIPH_DMA2D,
|
|
||||||
unpriv ? GTZC_TZSC_PERIPH_NPRIV : GTZC_TZSC_PERIPH_PRIV);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined STM32U5A9xx || defined STM32U5G9xx
|
#if defined STM32U5A9xx || defined STM32U5G9xx
|
||||||
void tz_set_gfxmmu_unpriv(bool unpriv) {
|
void tz_set_gfxmmu_unpriv(bool unpriv) {
|
||||||
HAL_GTZC_TZSC_ConfigPeriphAttributes(
|
HAL_GTZC_TZSC_ConfigPeriphAttributes(
|
||||||
|
Loading…
Reference in New Issue
Block a user