• Home
Name Date Size #Lines LOC

..--

figures/12-May-2024-

hievent/12-May-2024-1,151804

tzdriver/12-May-2024-13,65610,533

.gitignoreD12-May-202414 32

BUILD.gnD12-May-20241.8 KiB4541

LICENSED12-May-20241.6 KiB2923

OAT.xmlD12-May-20245.3 KiB7830

README.mdD12-May-202413.8 KiB300210

README_zh.mdD12-May-202412 KiB300210

README.md

1# Drivers<a name="EN-US_TOPIC_0000001096875497"></a>
2
3-   [Introduction](#section7301810197)
4-   [Directory Structure](#section161941989596)
5-   [Constraints](#section119744591305)
6    -   [Available APIs](#section1551164914237)
7    -   [Usage](#section129654513264)
8
9-   [Repositories Involved](#section1371113476307)
10
11## Introduction<a name="section7301810197"></a>
12
13A kernel driver acts as a bridge between software and hardware. It allows accessing hardware resources of the OpenHarmony kernel through file system APIs, providing a mode of communication between the user space and kernel space and between processes. The main kernel drivers include  **mem**,  **random**,  **video**,  **quickstart**,  **hievent**, and  **tzdriver**. The preceding four types of drivers are stored in the  **kernel/liteos\_a/drivers/char**  directory, and the last two types  **hievent**  and  **tzdriver**  are stored in the  **drivers/liteos**  directory. Each type of driver represents a capability. You can select a driver as required to transmit data. The following figure shows the kernel driver architecture.
14
15**Figure  1**  Kernel driver architecture<a name="fig2996151913212"></a>
16![](figures/kernel-driver-architecture.png "kernel-driver-architecture")
17
18Wherein:
19
20-   **mem**  indicates the driver for accessing physical input/output \(I/O\) devices in user space. It is used together with the  **mmap**  function.
21-   **random**  indicates the driver for devices to obtain random numbers, including true random number generators \(TRNGs\) and pseudorandom number generators \(PRNGs\). The device nodes for a TRNG and a PRNG are  **/dev/random**  and  **/dev/urandom**, respectively. Comparatively, TRNGs provide a higher randomness.
22-   **video**  indicates the framebuffer driver framework. You need to initialize APIs, register the framebuffer driver, and operate the framebuffer driver through file system APIs.
23
24## Directory Structure<a name="section161941989596"></a>
25
26```
27/drivers/liteos
28├── hievent         # Driver for event log management
29├── include         # Header files exposed externally
30├── tzdriver        # Used for switching and communication between the rich execution environment (REE) and trusted execution environment (TEE) and provides device nodes that can be accessed from the application layer.
31```
32
33## Constraints<a name="section119744591305"></a>
34
35Since the  **tzdriver**  implementation is not completely open-source, third-party vendors need to obtain the support for it through cooperation.
36
37The hievent-related capabilities are not supported currently and will be opened in the future. In addition, do not modify APIs and the format of their parameters defined in the  **hievent**  folder.
38
39The video-related source code is stored in the  **video/fb.c**  and  **video/fb.h**  files under the  **third\_party/NuttX**  directory.
40
41### Available APIs<a name="section1551164914237"></a>
42
43As shown in the preceding kernel driver architecture, a kernel driver can be taken as a special file. You can call standard file system APIs, such as  **open**,  **close**,  **read**,  **write**, and  **ioctl**  to perform operations on the driver. The following lists related APIs:
44
45-   fb\_register
46
47    **Function prototype:**
48
49    int fb\_register\(int display, int plane\);
50
51    **Function description:**  Loads the framebuffer driver and registers the  **/dev/fb0**  device node. If the operation is successful,  **0**  is returned. Otherwise, an error code is returned.
52
53    **Parameter description**
54
55    <a name="table13709103919318"></a>
56    <table><thead align="left"><tr id="row1170923910316"><th class="cellrowborder" valign="top" width="11.92%" id="mcps1.1.3.1.1"><p id="p1709123911313"><a name="p1709123911313"></a><a name="p1709123911313"></a>Parameter</p>
57    </th>
58    <th class="cellrowborder" valign="top" width="88.08%" id="mcps1.1.3.1.2"><p id="p1970910395313"><a name="p1970910395313"></a><a name="p1970910395313"></a>Description</p>
59    </th>
60    </tr>
61    </thead>
62    <tbody><tr id="row7709113923117"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p1870983993114"><a name="p1870983993114"></a><a name="p1870983993114"></a>display</p>
63    </td>
64    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p870963913111"><a name="p870963913111"></a><a name="p870963913111"></a>Indicates the display layer number. The value is usually <strong id="b832218348241"><a name="b832218348241"></a><a name="b832218348241"></a>0</strong>. If the hardware supports multiple display layers, this parameter can be set to other values.</p>
65    </td>
66    </tr>
67    <tr id="row0709163973120"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p170993918319"><a name="p170993918319"></a><a name="p170993918319"></a>plane</p>
68    </td>
69    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p9294182194420"><a name="p9294182194420"></a><a name="p9294182194420"></a>Indicates the color plane. The value is usually <strong id="b135661135142019"><a name="b135661135142019"></a><a name="b135661135142019"></a>0</strong>.</p>
70    </td>
71    </tr>
72    </tbody>
73    </table>
74
75
76-   fb\_unregister
77
78    **Function prototype:**
79
80    int fb\_unregister\(int display\);
81
82    **Function description:**  Uninstalls the framebuffer driver. If the operation is successful,  **0**  is returned. Otherwise, an error code is returned.
83
84    **Parameter description**
85
86    <a name="table1616493545014"></a>
87    <table><thead align="left"><tr id="row181651335105012"><th class="cellrowborder" valign="top" width="11.92%" id="mcps1.1.3.1.1"><p id="p4165123514507"><a name="p4165123514507"></a><a name="p4165123514507"></a>Parameter</p>
88    </th>
89    <th class="cellrowborder" valign="top" width="88.08%" id="mcps1.1.3.1.2"><p id="p6165103514502"><a name="p6165103514502"></a><a name="p6165103514502"></a>Description</p>
90    </th>
91    </tr>
92    </thead>
93    <tbody><tr id="row71650351503"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p11651835145015"><a name="p11651835145015"></a><a name="p11651835145015"></a>display</p>
94    </td>
95    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p16165183519506"><a name="p16165183519506"></a><a name="p16165183519506"></a>Indicates the display layer number.</p>
96    </td>
97    </tr>
98    </tbody>
99    </table>
100
101
102-   up\_fbinitialize
103
104    **Function prototype:**
105
106    int up\_fbinitialize\(int display\);
107
108    **Function description:**  Initializes the framebuffer driver. This function needs your implementation by calling  **fb\_register**  to register a device node for providing the framebuffer hardware driver capability. If the operation is successful,  **0**  is returned. Otherwise, an error code is returned.
109
110    **Parameter description**
111
112    <a name="table6333115110543"></a>
113    <table><thead align="left"><tr id="row1333315117540"><th class="cellrowborder" valign="top" width="11.92%" id="mcps1.1.3.1.1"><p id="p1233320514548"><a name="p1233320514548"></a><a name="p1233320514548"></a>Parameter</p>
114    </th>
115    <th class="cellrowborder" valign="top" width="88.08%" id="mcps1.1.3.1.2"><p id="p12334125165413"><a name="p12334125165413"></a><a name="p12334125165413"></a>Description</p>
116    </th>
117    </tr>
118    </thead>
119    <tbody><tr id="row16334155113548"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p18334145115546"><a name="p18334145115546"></a><a name="p18334145115546"></a>display</p>
120    </td>
121    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p15334951125417"><a name="p15334951125417"></a><a name="p15334951125417"></a>Indicates the display layer number.</p>
122    </td>
123    </tr>
124    </tbody>
125    </table>
126
127
128-   up\_fbuninitialize
129
130    **Function prototype:**
131
132    void up\_fbuninitialize\(int display\);
133
134    **Function description:**  Uninstalls the framebuffer driver. This function needs your implementation by calling  **fb\_unregister**  to unregister the device node. No value is returned for this function.
135
136    **Parameter description**
137
138    <a name="table18929574553"></a>
139    <table><thead align="left"><tr id="row1993012716553"><th class="cellrowborder" valign="top" width="11.92%" id="mcps1.1.3.1.1"><p id="p1593012795510"><a name="p1593012795510"></a><a name="p1593012795510"></a>Parameter</p>
140    </th>
141    <th class="cellrowborder" valign="top" width="88.08%" id="mcps1.1.3.1.2"><p id="p1693014715516"><a name="p1693014715516"></a><a name="p1693014715516"></a>Description</p>
142    </th>
143    </tr>
144    </thead>
145    <tbody><tr id="row4930076554"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p18930147105517"><a name="p18930147105517"></a><a name="p18930147105517"></a>display</p>
146    </td>
147    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p89309705512"><a name="p89309705512"></a><a name="p89309705512"></a>Indicates the display layer number.</p>
148    </td>
149    </tr>
150    </tbody>
151    </table>
152
153
154-   up\_fbgetvplane
155
156    **Function prototype:**
157
158    struct fb\_vtable\_s \*up\_fbgetvplane\(int display, int vplane\);
159
160    **Function description:**  Obtains a framebuffer driver handle, which needs your implementation. If the operation is successful, a valid pointer is returned. Otherwise,  **NULL**  is returned.
161
162    **Parameter description**
163
164    <a name="table0350124169"></a>
165    <table><thead align="left"><tr id="row183519416611"><th class="cellrowborder" valign="top" width="11.92%" id="mcps1.1.3.1.1"><p id="p7351184160"><a name="p7351184160"></a><a name="p7351184160"></a>Parameter</p>
166    </th>
167    <th class="cellrowborder" valign="top" width="88.08%" id="mcps1.1.3.1.2"><p id="p18351347614"><a name="p18351347614"></a><a name="p18351347614"></a>Description</p>
168    </th>
169    </tr>
170    </thead>
171    <tbody><tr id="row8351174461"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p143519414618"><a name="p143519414618"></a><a name="p143519414618"></a>display</p>
172    </td>
173    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p1035110419612"><a name="p1035110419612"></a><a name="p1035110419612"></a>Indicates the display layer number.</p>
174    </td>
175    </tr>
176    <tr id="row187413238610"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p118752231869"><a name="p118752231869"></a><a name="p118752231869"></a>vplane</p>
177    </td>
178    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p16875102311611"><a name="p16875102311611"></a><a name="p16875102311611"></a>Indicates the specified color plane.</p>
179    </td>
180    </tr>
181    </tbody>
182    </table>
183
184
185-   pse\_ran\_dev\_register
186
187    **Function prototype:**
188
189    int pse\_ran\_dev\_register\(void\);
190
191    **Function description:**  Initializes the PRNG device driver and registers the  **/dev/random**  device node. If the operation is successful,  **0**  is returned. Otherwise, an error code is returned.
192
193    **Parameter description:**  none
194
195
196-   ran\_dev\_register
197
198    **Function prototype:**
199
200    int ran\_dev\_register\(void\);
201
202    **Function description:**  Initializes the TRNG driver and registers the  **/dev/urandom**  device node. If the operation is successful,  **0**  is returned. Otherwise, an error code is returned.
203
204    **Parameter description:**  none
205
206
207-   mem\_dev\_register
208
209    **Function prototype:**
210
211    int mem\_dev\_register\(void\);
212
213    **Function description:**  Initializes the mem driver and registers the  **/dev/mem**  device node. If the operation is successful,  **0**  is returned. Otherwise, an error code is returned.
214
215    **Parameter description:**  none
216
217
218### Usage<a name="section129654513264"></a>
219
220-   The following uses the framebuffer driver as an example:
221
222```
223int up_fbinitialize(int display)
224{
225    // Provide framebuffer hardware driver capabilities. The specific code logic needs your implementation.
226}
227
228void up_fbuninitialize(int display)
229{
230    // This function is used together with up_fbinitialize. The specific code logic needs your implementation.
231}
232
233struct fb_vtable_s *up_fbgetvplane(int display, int vplane)
234{
235    // Register a hardware driver based on information described by the fb_vtable_s structure. You can use the driver capabilities through the video framework layer. The specific code logic needs your implementation.
236}
237
238int FrameBufferFunc(void)
239{
240    int ret;
241    int fd = -1;
242    struct hifb_info info;
243    char *pShowScreen = NULL;
244
245    ret = fb_register(0, 0); // Register the /dev/fb0 device node. This function will call the preceding functions to enable hardware driver capabilities.
246    if (ret != 0) {
247        return -1;
248    }
249
250    fd = open(file, O_RDWR, 0);
251    if (fd < 0) {
252        return -1;
253    }
254
255    if (ioctl(fd, FBIOGET_SCREENINFO_HIFB, &info) < 0) {
256        return -1;
257    }
258    info.vinfo.xres = 1920;
259    info.vinfo.yres = 1080;
260    info.oinfo.sarea.w = 1920;
261    info.oinfo.sarea.h = 1080;
262    info.oinfo.bpp = 16;
263    info.activate = 0;
264    info.vinfo.fmt = HIFB_FMT_ARGB1555;
265
266    if (ioctl(fd, FBIOPUT_SCREENINFO_HIFB, &info) < 0) {
267        return -1;
268    }
269
270    if (ioctl(fd, FBIOGET_SCREENINFO_HIFB, &info) < 0) {
271        return -1;
272    }
273
274    pShowScreen = mmap(HI_NULL, info.oinfo.fblen, PROT_READ | PROT_WRITE, MAP_SHARED, pstInfo->fd, 0);
275    if (pShowScreen == -1) {
276        return -1;
277    }
278
279    // Fill in the memory to which pShowScreen points and display the graphics through the ioctl call.
280
281    munmap(pShowScreen, info.oinfo.fblen);
282
283    close(fd);
284
285    ret = fb_unregister(0);
286    if (ret != 0) {
287        return -1;
288    }
289}
290```
291
292## Repositories Involved<a name="section1371113476307"></a>
293
294[Kernel subsystem](https://gitee.com/openharmony/docs/blob/HEAD/en/readme/kernel.md)
295
296[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README.md)
297
298[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/HEAD/README.md)
299
300

README_zh.md

1# 驱动<a name="ZH-CN_TOPIC_0000001096875497"></a>
2
3-   [简介](#section7301810197)
4-   [目录](#section161941989596)
5-   [约束](#section119744591305)
6    -   [接口说明](#section1551164914237)
7    -   [使用说明](#section129654513264)
8
9-   [相关仓](#section1371113476307)
10
11## 简介<a name="section7301810197"></a>
12
13内核驱动是软件与硬件交互的桥梁,通过文件系统接口访问OpenHarmony内核的硬件资源,是用户与内核之间、进程与进程之间通信的一种方式。每类驱动代表一种能力,用户可以根据需求选择对应驱动,完成数据的传输。内核初始化驱动并注册设备节点,用户通过文件系统接口操作该设备节点。内核驱动主要包括mem、random、video、quickstart、hievent和tzdriver,其中mem、random、video和quickstart位于kernel/liteos\_a/drivers/char目录下,hievent和tzdrivert位于drivers/liteos目录下。驱动架构图如下所示:
14
15**图 1**  内核驱动架构图<a name="fig2996151913212"></a>
16![](figures/内核驱动架构图.png "内核驱动架构图")
17
18其中:
19
20-   mem驱动用于用户态访问物理IO设备,与mmap接口结合使用;
21-   random驱动用于获取随机数,包括真随机和伪随机两种设备驱动,设备节点分别为/dev/random/dev/urandom,通过真随机设备节点获取的数据随机性相对较高;
22-   video相关实现是framebuffer驱动框架,用户需要实现初始化接口完成驱动注册,通过文件系统接口操作framebuffer驱动。
23
24## 目录<a name="section161941989596"></a>
25
26```
27/drivers/liteos
28├── hievent         # 事件日志管理驱动
29├── include         # 对外头文件存放目录
30├── tzdriver        # 用于ree/tee切换、通讯,提供应用层访问的设备节点
31```
32
33## 约束<a name="section119744591305"></a>
34
35tzdriver驱动实现部分尚未开源,三方厂商需要通过合作方式获取该组件的支持。
36
37hievent驱动的配套功能暂不支持,待后续开源,请勿修改该驱动定义的接口和接口参数格式。
38
39video源码实现在third\_party/NuttX下面:video/fb.cvideo/fb.h40
41### 接口说明<a name="section1551164914237"></a>
42
43由上文内核驱动框架图可以看出,内核驱动可以看成特殊的文件,用户调用文件系统标准接口,即可完成对驱动的读写操作,有open、close、read、write和ioctl等标准接口,不再阐述。下面列举各个驱动相关接口:
44
45-   fb\_register
46
47    **函数原型:**
48
49    int fb\_register\(int display, int plane\);
50
51    **函数功能:** 加载framebuffer驱动,注册设备节点/dev/fb0;若成功则返回0, 否则返回相应的错误码。
52
53    **参数说明:**
54
55    <a name="table13709103919318"></a>
56    <table><thead align="left"><tr id="row1170923910316"><th class="cellrowborder" valign="top" width="11.92%" id="mcps1.1.3.1.1"><p id="p1709123911313"><a name="p1709123911313"></a><a name="p1709123911313"></a>参数</p>
57    </th>
58    <th class="cellrowborder" valign="top" width="88.08%" id="mcps1.1.3.1.2"><p id="p1970910395313"><a name="p1970910395313"></a><a name="p1970910395313"></a>描述</p>
59    </th>
60    </tr>
61    </thead>
62    <tbody><tr id="row7709113923117"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p1870983993114"><a name="p1870983993114"></a><a name="p1870983993114"></a>display</p>
63    </td>
64    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p870963913111"><a name="p870963913111"></a><a name="p870963913111"></a>显示层编号,通常为0。若硬件支持多显示层,该变量可设置成其他值。</p>
65    </td>
66    </tr>
67    <tr id="row0709163973120"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p170993918319"><a name="p170993918319"></a><a name="p170993918319"></a>plane</p>
68    </td>
69    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p9294182194420"><a name="p9294182194420"></a><a name="p9294182194420"></a>标识颜色平面,通常为0。</p>
70    </td>
71    </tr>
72    </tbody>
73    </table>
74
75
76-   fb\_unregister
77
78    **函数原型:**
79
80    int fb\_unregister\(int display\);
81
82    **函数功能:** 卸载framebuffer驱动;若成功则返回0, 否则返回相应的错误码。
83
84    **参数说明:**
85
86    <a name="table1616493545014"></a>
87    <table><thead align="left"><tr id="row181651335105012"><th class="cellrowborder" valign="top" width="11.92%" id="mcps1.1.3.1.1"><p id="p4165123514507"><a name="p4165123514507"></a><a name="p4165123514507"></a>参数</p>
88    </th>
89    <th class="cellrowborder" valign="top" width="88.08%" id="mcps1.1.3.1.2"><p id="p6165103514502"><a name="p6165103514502"></a><a name="p6165103514502"></a>描述</p>
90    </th>
91    </tr>
92    </thead>
93    <tbody><tr id="row71650351503"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p11651835145015"><a name="p11651835145015"></a><a name="p11651835145015"></a>display</p>
94    </td>
95    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p16165183519506"><a name="p16165183519506"></a><a name="p16165183519506"></a>显示层编号。</p>
96    </td>
97    </tr>
98    </tbody>
99    </table>
100
101
102-   up\_fbinitialize
103
104    **函数原型:**
105
106    int up\_fbinitialize\(int display\);
107
108    **函数功能:** 初始化framebuffer驱动,这个接口需要用户通过调用fb\_register注册设备节点来实现,以提供framebuffer硬件驱动功能;若成功则返回0,否则返回相应的错误码。
109
110    **参数说明:**
111
112    <a name="table6333115110543"></a>
113    <table><thead align="left"><tr id="row1333315117540"><th class="cellrowborder" valign="top" width="11.92%" id="mcps1.1.3.1.1"><p id="p1233320514548"><a name="p1233320514548"></a><a name="p1233320514548"></a>参数</p>
114    </th>
115    <th class="cellrowborder" valign="top" width="88.08%" id="mcps1.1.3.1.2"><p id="p12334125165413"><a name="p12334125165413"></a><a name="p12334125165413"></a>描述</p>
116    </th>
117    </tr>
118    </thead>
119    <tbody><tr id="row16334155113548"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p18334145115546"><a name="p18334145115546"></a><a name="p18334145115546"></a>display</p>
120    </td>
121    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p15334951125417"><a name="p15334951125417"></a><a name="p15334951125417"></a>显示层编号。</p>
122    </td>
123    </tr>
124    </tbody>
125    </table>
126
127
128-   up\_fbuninitialize
129
130    **函数原型:**
131
132    void up\_fbuninitialize\(int display\);
133
134    **函数功能:** 卸载framebuffer硬件驱动,这个接口需要用户通过调用fb\_unregister注销设备节点来实现;无返回值。
135
136    **参数说明:**
137
138    <a name="table18929574553"></a>
139    <table><thead align="left"><tr id="row1993012716553"><th class="cellrowborder" valign="top" width="11.92%" id="mcps1.1.3.1.1"><p id="p1593012795510"><a name="p1593012795510"></a><a name="p1593012795510"></a>参数</p>
140    </th>
141    <th class="cellrowborder" valign="top" width="88.08%" id="mcps1.1.3.1.2"><p id="p1693014715516"><a name="p1693014715516"></a><a name="p1693014715516"></a>描述</p>
142    </th>
143    </tr>
144    </thead>
145    <tbody><tr id="row4930076554"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p18930147105517"><a name="p18930147105517"></a><a name="p18930147105517"></a>display</p>
146    </td>
147    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p89309705512"><a name="p89309705512"></a><a name="p89309705512"></a>显示层编号。</p>
148    </td>
149    </tr>
150    </tbody>
151    </table>
152
153
154-   up\_fbgetvplane
155
156    **函数原型:**
157
158    struct fb\_vtable\_s \*up\_fbgetvplane\(int display, int vplane\);
159
160    **函数功能:** 获取framebuffer硬件驱动的句柄,这个接口需要用户实现;若成功则返回有效指针,否则返回NULL。
161
162    **参数说明:**
163
164    <a name="table0350124169"></a>
165    <table><thead align="left"><tr id="row183519416611"><th class="cellrowborder" valign="top" width="11.92%" id="mcps1.1.3.1.1"><p id="p7351184160"><a name="p7351184160"></a><a name="p7351184160"></a>参数</p>
166    </th>
167    <th class="cellrowborder" valign="top" width="88.08%" id="mcps1.1.3.1.2"><p id="p18351347614"><a name="p18351347614"></a><a name="p18351347614"></a>描述</p>
168    </th>
169    </tr>
170    </thead>
171    <tbody><tr id="row8351174461"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p143519414618"><a name="p143519414618"></a><a name="p143519414618"></a>display</p>
172    </td>
173    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p1035110419612"><a name="p1035110419612"></a><a name="p1035110419612"></a>显示层编号。</p>
174    </td>
175    </tr>
176    <tr id="row187413238610"><td class="cellrowborder" valign="top" width="11.92%" headers="mcps1.1.3.1.1 "><p id="p118752231869"><a name="p118752231869"></a><a name="p118752231869"></a>vplane</p>
177    </td>
178    <td class="cellrowborder" valign="top" width="88.08%" headers="mcps1.1.3.1.2 "><p id="p16875102311611"><a name="p16875102311611"></a><a name="p16875102311611"></a>指定的颜色平面。</p>
179    </td>
180    </tr>
181    </tbody>
182    </table>
183
184
185-   pse\_ran\_dev\_register
186
187    **函数原型:**
188
189    int pse\_ran\_dev\_register\(void\);
190
191    **函数功能:** 初始化软随机设备驱动,注册设备节点/dev/random;若成功则返回0, 否则返回相应的错误码。
192
193    **参数说明:** 无
194
195
196-   ran\_dev\_register
197
198    **函数原型:**
199
200    int ran\_dev\_register\(void\);
201
202    **函数功能:** 初始化硬随机设备驱动,注册设备节点/dev/urandom;若成功则返回0, 否则返回相应的错误码。
203
204    **参数说明:** 无
205
206
207-   mem\_dev\_register
208
209    **函数原型:**
210
211    int mem\_dev\_register\(void\);
212
213    **函数功能:** 初始化mem驱动,注册设备节点/dev/mem;若成功则返回0,否则返回相应的错误码。
214
215    **参数说明:** 无
216
217
218### 使用说明<a name="section129654513264"></a>
219
220-   以framebuffer驱动操作为例:
221
222```
223int up_fbinitialize(int display)
224{
225    //具体代码逻辑由用户实现,提供framebuffer硬件驱动能力;
226}
227
228void up_fbuninitialize(int display)
229{
230    //具体代码逻辑由用户实现,与up_fbinitialize匹配;
231}
232
233struct fb_vtable_s *up_fbgetvplane(int display, int vplane)
234{
235    //具体代码逻辑由用户实现,根据fb_vtable_s结构体类型信息注册硬件设备驱动,用户通过video框架层调用这些能力;
236}
237
238int FrameBufferFunc(void)
239{
240    int ret;
241    int fd = -1;
242    struct hifb_info info;
243    char *pShowScreen = NULL;
244
245    ret = fb_register(0, 0); //注册/dev/fb0设备节点,该接口会调用上述接口,完成硬件驱动能力使能;
246    if (ret != 0) {
247        return -1;
248    }
249
250    fd = open(file, O_RDWR, 0);
251    if (fd < 0) {
252        return -1;
253    }
254
255    if (ioctl(fd, FBIOGET_SCREENINFO_HIFB, &info) < 0) {
256        return -1;
257    }
258    info.vinfo.xres = 1920;
259    info.vinfo.yres = 1080;
260    info.oinfo.sarea.w = 1920;
261    info.oinfo.sarea.h = 1080;
262    info.oinfo.bpp = 16;
263    info.activate = 0;
264    info.vinfo.fmt = HIFB_FMT_ARGB1555;
265
266    if (ioctl(fd, FBIOPUT_SCREENINFO_HIFB, &info) < 0) {
267        return -1;
268    }
269
270    if (ioctl(fd, FBIOGET_SCREENINFO_HIFB, &info) < 0) {
271        return -1;
272    }
273
274    pShowScreen = mmap(HI_NULL, info.oinfo.fblen, PROT_READ | PROT_WRITE, MAP_SHARED, pstInfo->fd, 0);
275    if (pShowScreen == -1) {
276        return -1;
277    }
278
279    //填充pShowScreen指针指向的内存,通过ioctl命令,显示图形;
280
281    munmap(pShowScreen, info.oinfo.fblen);
282
283    close(fd);
284
285    ret = fb_unregister(0);
286    if (ret != 0) {
287        return -1;
288    }
289}
290```
291
292## 相关仓<a name="section1371113476307"></a>
293
294[内核子系统](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/readme/%E5%86%85%E6%A0%B8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
295
296[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README_zh.md)
297
298[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/HEAD/README_zh.md)
299
300