Linux显示(四):libdrm及相关测试工具
关键词:libdrm、drm等。
libdrm基于内核DRM,尤其对ioctl命令进行包裹,向上层显示框架提供更易使用的API。
1 libdrm
libdrm来自于MESA项目,对open/read/write/ioctl/mmap/close等系统调用进行封装,尤其是对繁杂ioctl的命令调用封装。
libdrm是一个用户空间访问DRM设备的库文件,常被一些图形显示框架调用,比如Mesa DRI drivers、X drivers等。
关于libdrm的使用可以通过一下命令获取参考信息:
man drm
man drm-kms:对显示Pipeline进行模式设置,包括Mode-Setting、Page-Flipping、Planes、Cursors。
man drm-memory:DRM内存管理,比如Dumb-BUffers、TTM、GEM。
2 DRM相关测试工具
参考文档:《DRM KMS overview - modetest》《DRM KMS overview - kmscube》。
2.1 libdrm测试工具
Buildroot配置libdrm:
Target packages
->Libraries
->Graphics
->libdrm
->Install test programs--编译libdrm相关测试工具。
对libdrm调试,可以通过export LIBGL_DEBUG=verbose打开调试开关。
2.1.1 modetest
modetest指定plane/crtc/connector/mode进行测试。命令说明如下:
usage: modetest [-acDdefMPpsCvrw]
Query options:
-c list connectors
-e list encoders
-f list framebuffers
-p list CRTCs and planes (pipes)
Test options:
-P <plane_id>@<crtc_id>:<w>x<h>[+<x>+<y>][*<scale>][@<format>] set a plane
-s <connector_id>[,<connector_id>][@<crtc_id>]:[#<mode index>]<mode>[-<vrefresh>][@<format>] set a mode
-C test hw cursor
-v test vsynced page flipping
-r set the preferred mode for all connectors
-w <obj_id>:<prop_name>:<value> set property
-a use atomic API
-F pattern1,pattern2 specify fill patterns--支持的pattern有tiles,smpte,plain,gradient。
Generic options:
-d drop master after mode set
-M module use the given driver
-D device use the given device
Default is to dump all info.
使用modetest -m stm查看信息:
Encoders:
id crtc type possible crtcs possible clones
31 35 DPI 0x00000001 0x00000000--Encoder类型为DPI,和CRTC 35绑定。
Connectors:
id encoder status name size (mm) modes encoders
32 31 connected DPI-1 0x0 1 31--Connector名称为DPI-1,和Encoder 31绑定,使用模式1.下面是模式列表。
modes:
index name refresh (Hz) hdisp hss hse htot vdisp vss vse vtot
#0 800x480 64.62 800 888 936 976 480 512 515 528 33300 flags: phsync, pvsync; type: preferred, driver--第一个模式的时序配置和标志。
props:
1 EDID:
flags: immutable blob
blobs:
value:
2 DPMS:
flags: enum
enums: On=0 Standby=1 Suspend=2 Off=3
value: 0
5 link-status:
flags: enum
enums: Good=0 Bad=1
value: 0
6 non-desktop:
flags: immutable range
values: 0 1
value: 0
4 TILE:
flags: immutable blob
blobs:
value:
CRTCs:
id fb pos size
35 38 (0,0) (800x480)--列出CRTC对应fb 38信息。
#0 800x480 64.62 800 888 936 976 480 512 515 528 33300 flags: phsync, pvsync; type: preferred, driver
props:
24 VRR_ENABLED:
flags: range
values: 0 1
value: 0
28 GAMMA_LUT:
flags: blob
blobs:
value:
29 GAMMA_LUT_SIZE:
flags: immutable range
values: 0 4294967295
value: 256
Planes:
id crtc fb CRTC x,y x,y gamma size possible crtcs
33 35 38 0,0 0,0 0 0x00000001--Plane对应fb 38,输入到CRTC 35。
formats: AR24 XR24 RG24 RG16 AR15 XR15 AR12 XR12 C8
props:
8 type:
flags: immutable enum
enums: Overlay=0 Primary=1 Cursor=2
value: 1
30 IN_FORMATS:
flags: immutable blob
blobs:
value:
01000000000000000900000018000000
01000000400000004152323458523234
52473234524731364152313558523135
41523132585231324338202000000000
ff010000000000000000000000000000
0000000000000000
in_formats blob decoded:
AR24: LINEAR
XR24: LINEAR
RG24: LINEAR
RG16: LINEAR
AR15: LINEAR
XR15: LINEAR
AR12: LINEAR
XR12: LINEAR
C8 : LINEAR
36 0 0 0,0 0,0 0 0x00000001--第二个Plane信息。
formats: AR24 RG24 RG16 AR15 AR12 C8
props:
8 type:
flags: immutable enum
enums: Overlay=0 Primary=1 Cursor=2
value: 0
30 IN_FORMATS:
flags: immutable blob
blobs:
value:
01000000000000000600000018000000
01000000300000004152323452473234
52473136415231354152313243382020
3f000000000000000000000000000000
0000000000000000
in_formats blob decoded:
AR24: LINEAR
RG24: LINEAR
RG16: LINEAR
AR15: LINEAR
AR12: LINEAR
C8 : LINEAR
Frame buffers:--Framebuffer信息。
id size pitch
测试命令:
modetest -M stm -D 0 -a -s 32@35:800x480 -P 33@35:800x480 -Fsmpte
更多参考《libdrm-modetest原理及图显系统验证方法》。
2.1.2 drmdevice
显现系统当前DRM设备信息:
--- Checking the number of DRM device available ---
--- Devices reported 1 ---
--- Retrieving devices information (PCI device revision is ignored) ---
device[0]
+-> available_nodes 0x01
+-> nodes
| +-> nodes[0] /dev/dri/card0
+-> bustype 0002
| +-> platform
| +-> fullname /soc/display-controller@5a001000
+-> deviceinfo
+-> platform
+-> compatible
st,stm32-ltdc
--- Opening device node /dev/dri/card0 ---
--- Retrieving device info, for node /dev/dri/card0 ---
device[0]
+-> available_nodes 0x01
+-> nodes
| +-> nodes[0] /dev/dri/card0
+-> bustype 0002
| +-> platform
| +-> fullname /soc/display-controller@5a001000
+-> deviceinfo
+-> platform
+-> compatible
st,stm32-ltdc
7.2.1.3 proptest
Connector 32 (DPI-1)
1 EDID:
flags: immutable blob
blobs:
value:
2 DPMS:
flags: enum
enums: On=0 Standby=1 Suspend=2 Off=3
value: 0
5 link-status:
flags: enum
enums: Good=0 Bad=1
value: 0
6 non-desktop:
flags: immutable range
values: 0 1
value: 0
4 TILE:
flags: immutable blob
blobs:
value:
CRTC 35
24 VRR_ENABLED:
flags: range
values: 0 1
value: 0
28 GAMMA_LUT:
flags: blob
blobs:
value:
29 GAMMA_LUT_SIZE:
flags: immutable range
values: 0 4294967295
value: 256
2.1.4 vbltest
Vertical Blank测试, 显示帧率。
vbltest -M stm
starting count: 448229
freq: 64.57Hz
freq: 64.03Hz
freq: 64.04Hz
2.1.5 modeprint
count_connectors : 1
count_encoders : 1
count_crtcs : 1
count_fbs : 0
Connector: DPI-1
id : 32
encoder id : 31
conn : connected
size : 0x0 (mm)
count_modes : 1
count_props : 5
props : 1 2 5 6 4
count_encoders : 1
encoders : 31
Mode: "800x480" 800x480 60
Encoder: DPI
id :31
crtc_id :35
type :8
possible_crtcs :0x1
possible_clones :0x0
Crtc
id : 35
x : 0
y : 0
width : 800
height : 480
mode : 0x43c2ac
gamma size : 256
2.2 kmscube
kmscube是基于DRM/KMS、GBM(Graphics Buffer Management)、EGL进行OpenGL或OpenGL ES进行渲染的一个演示程序。
2.3 igt-gpu-tools
IGT GPU是一组基于DRM驱动开发和测试工具集。