Skip to main content

V2D

Introduction to the functions and usage of the spacemit platform V2D module.

Module Introduction

The spacemit platform V2D driver provides hardware acceleration for 2D graphics.

Function Introduction

v2d

Driver Model The V2D driver uses a character device driver model and communicates with user space via the /dev/v2d_dev device file.

open: Function called when the device is opened.
read: Function to read data from the device.
write(): Function to write data to the device.
ioctl(): Function to handle control commands.
release(): Function called when the device is closed.

Basic Functions The V2D driver supports 2D graphics fill, scaling, rotation, cropping, format conversion, and other functions.

Source Code Structure Introduction

The spacemit platform V2D driver source code structure, under the kernel directory:

drivers/soc/spacemit$ tree v2d
v2d
|-- csc_matrix.h
|-- Kconfig
|-- Makefile
|-- v2d_drv.c // v2d 驱动
|-- v2d_drv.h
|-- v2d_hw.c
|-- v2d_iommu.c // v2d iommu 驱动
|-- v2d_priv.h
|-- v2d_reg.h

关键特性

特性

特性特性说明
颜色填充支持图像颜色填充功能。
旋转支持图像0°,90°,180°,270°旋转,及镜像功能。
裁剪支持图像裁剪功能。
缩放支持图像1/8~8倍的缩放功能功能。
格式转换支持YUV,RGB颜色空间转换功能。

性能参数

功能性能规格
颜色填充1920x1080@200 FPS
格式转换1920x1080@200 FPS

配置介绍

主要包括V2D驱动使能配置和dts配置。

CONFIG配置

CONFIG_SPACEMIT_V2D:spacemit平台V2D驱动配置选项,默认情况,此选项为Y。

 Device Drivers  --->
SOC (System On Chip) specific Drivers --->
<*> Spacemit V2D Engine Driver

dts配置

clock配置

V2D相关clock配置,包括v2d-io 和 v2d-core clock配置,reset配置。v2d-io clock可配置为204800000 HZ,307200000 HZ,409600000 HZ,409600000 HZ四个不同挡位。默认使用409600000 HZ,可通过写节点/sys/bus/platform/devices/c0100000.v2d/clkrate进行动态配置。

配置平台V2D相关clock和reset。

// linux-6.6\arch\riscv\boot\dts\spacemit\k1-x.dtsi
v2d@c0100000 {
compatible = "spacemit,v2d";
reg = <0x0 0xc0100000 0x0 0x1000>;
reg-names = "v2dreg";
clocks = <&ccu CLK_DPU_MCLK>, // v2d clock 配置
<&ccu CLK_V2D>;
clock-names = "v2d-io", "v2d-core";
resets = <&reset RESET_V2D>; // v2d reset 配置
reset-names= "v2d_reset";
interrupt-parent = <&intc>;
interrupts = <86>;
interconnects = <&dram_range3>;
interconnect-names = "dma-mem";
status = "ok";
};

接口描述

API介绍

应用端通过API调用实现V2D功能。主要实现2D图形的Fill,Bitblit,Blend三个功能。

V2D_BeginJob

int32_t V2D_BeginJob(V2D_HANDLE *phHandle);
功能说明创建一个V2D工作队列。
参数定义phHandle:句柄指针
返回值0:成功; -1:失败

V2D_EndJob

int32_t V2D_EndJob(V2D_HANDLE hHandle);
功能说明提交工作队列到V2D驱动,并启动工作。
参数定义hHandle:句柄
返回值0:成功; -1:失败

V2D_AddFillTask

int32_t V2D_AddFillTask(V2D_HANDLE hHandle, 
V2D_SURFACE_S *pstDst,
V2D_AREA_S *pstDstRect,
V2D_FILLCOLOR_S *pstFillColor);

功能说明提交任务到V2D工作队列,向目标位图的操作区填充颜色。
参数定义hHandle:句柄;pstDst:目标位图;pstDstRect:目标位图操作区;pstFillColor:颜色填充结构体
返回值0:成功; -1:失败

V2D_AddBitblitTask

int32_t V2D_AddBitblitTask(V2D_HANDLE hHandle, 
V2D_SURFACE_S *pstDst,
V2D_AREA_S *pstDstRect,
V2D_SURFACE_S *pstSrc,
V2D_AREA_S *pstSrcRect, V2D_CSC_MODE_E enCSCMode);

功能说明提交任务到V2D工作队列,源位图的操作区域搬运到目标位图的操作区域。
参数定义hHandle:句柄;pstDst:目标位图;pstDstRect:目标位图操作区;pstSrc: 源位图;pstSrcRect:源位图操作区;enCSCMode:是否需要进行色域转换标志
返回值0:成功; -1:失败

V2D_AddBlendTask

int32_t V2D_AddBlendTask(V2D_HANDLE hHandle, 
V2D_SURFACE_S *pstBackGround,
V2D_AREA_S *pstBackGroundRect,
V2D_SURFACE_S *pstForeGround,
V2D_AREA_S *pstForeGroundRect,
V2D_SURFACE_S *pstMask,
V2D_AREA_S *pstMaskRect,
V2D_SURFACE_S *pstDst,
V2D_AREA_S *pstDstRect,
V2D_BLEND_CONF_S *pstBlendConf,
V2D_ROTATE_ANGLE_E enForeRotateAngle,
V2D_ROTATE_ANGLE_E enBackRotateAngle,
V2D_CSC_MODE_E enForeCSCMode,
V2D_CSC_MODE_E enBackCSCMode,
V2D_PALETTE_S *pstPalette,
V2D_DITHER_E dither);

功能说明提交任务到V2D工作队列,源位图到目标位图完成裁剪,旋转,格式转换,缩放等功能。
参数定义hHandle:句柄;pstBackGround:背景位图;pstBackGroundRect:背景位图操作区;pstForeGround: 前景位图;pstForeGroundRect:前景位图操作区;pstMask:Mask位图;pstMaskRect:Mask位图操作区;pstDst: 目标位图;pstDstRect:目标位图操作区;pstBlendConf:blend配置结构体;enForeRotateAngle:前景操作旋转角度;enBackRotateAngle:背景操作旋转角度;enForeCSCMode:前景CSC转换模式;enBackCSCMode:背景CSC转换模式;pstPalette:L8格式调色板数据结构指针;dither:选择dither模式
返回值0:成功; -1:失败

Debug介绍

查看v2d io clock频率

# cat /sys/bus/platform/devices/c0100000.v2d/clkrate
409600000

测试介绍

Fill测试用例

# cd /usr/share/v2d
# v2d_test --fill
v2d fill test case successful!

Bitblit测试用例

# cd /usr/share/v2d
# v2d_test --blit
v2d blit test case successful!

Blend测试用例

# cd /usr/share/v2d
# v2d_test --blend
v2d blend test case successful!

FAQ