• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * test_helper_driver.c
3  *
4  * test helper driver on linux
5  *
6  * Copyright (c) 2022 Huawei Device Co., Ltd.
7  *
8  * This software is licensed under the terms of the GNU General Public
9  * License version 2, as published by the Free Software Foundation, and
10  * may be copied, distributed, and modified under those terms.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  */
18 
19 #include "devmgr_service.h"
20 #include "devsvc_manager_clnt.h"
21 #include "hdf_device_object.h"
22 #include "hdf_driver_module.h"
23 #include "hdf_log.h"
24 #include "hdf_pm.h"
25 #include "osal_file.h"
26 #include "osal_mem.h"
27 #include "sample_driver_test.h"
28 
29 #define HDF_LOG_TAG test_help_driver
30 
HelperDriverDispatch(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)31 static int32_t HelperDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
32 {
33     int32_t num = 0;
34     if (cmdId != 1) {
35         HDF_LOGE("%s:unknown comd id %d", __func__, cmdId);
36         return HDF_ERR_NOT_SUPPORT;
37     }
38     if (!HdfSbufReadInt32(data, &num)) {
39         HDF_LOGE("%s:failed to read parm", __func__);
40         return HDF_FAILURE;
41     }
42 
43     if (!HdfSbufWriteInt32(reply, num)) {
44         HDF_LOGE("%s:failed to write parm", __func__);
45         return HDF_FAILURE;
46     }
47 
48     return HDF_SUCCESS;
49 }
50 
HdfHelperDriverBind(struct HdfDeviceObject * deviceObject)51 static int32_t HdfHelperDriverBind(struct HdfDeviceObject *deviceObject)
52 {
53     static struct IDeviceIoService testService = {
54         .Open = NULL,
55         .Dispatch = HelperDriverDispatch,
56         .Release = NULL,
57     };
58     HDF_LOGI("%s: called", __func__);
59     if (deviceObject == NULL) {
60         return HDF_FAILURE;
61     }
62 
63     deviceObject->service = &testService;
64     return HDF_SUCCESS;
65 }
66 
HdfHelperDriverInit(struct HdfDeviceObject * deviceObject)67 static int32_t HdfHelperDriverInit(struct HdfDeviceObject *deviceObject)
68 {
69     (void)deviceObject;
70     HDF_LOGI("%s: called", __func__);
71     return HDF_SUCCESS;
72 }
73 
HdfHelperDriverRelease(struct HdfDeviceObject * deviceObject)74 static void HdfHelperDriverRelease(struct HdfDeviceObject *deviceObject)
75 {
76     (void)deviceObject;
77     HDF_LOGI("%s: called", __func__);
78 }
79 
80 static struct HdfDriverEntry g_helperDriverEntry = {
81     .moduleVersion = 1,
82     .moduleName = "hdf_test_helper",
83     .Bind = HdfHelperDriverBind,
84     .Init = HdfHelperDriverInit,
85     .Release = HdfHelperDriverRelease,
86 };
87 
88 HDF_DRIVER_MODULE(g_helperDriverEntry);
89