1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <hdf_base.h>
17 #include <hdf_log.h>
18 #include <hdf_device_desc.h>
19 #include <osal_mem.h>
20 #include "video_layer_stub.h"
21
22 #define HDF_LOG_TAG display_hdi_service
23
24 using HdfDisplayHdiService = struct _HdfDisplayHdiService {
25 struct IDeviceIoService ioservice;
26 void *instance;
27 };
28
DisplayHdiServiceDispatch(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)29 static int32_t DisplayHdiServiceDispatch(struct HdfDeviceIoClient *client, int cmdId,
30 struct HdfSBuf *data, struct HdfSBuf *reply)
31 {
32 HdfDisplayHdiService *displayHdiService = CONTAINER_OF(client->device->service, HdfDisplayHdiService, ioservice);
33 return LayerServiceOnRemoteRequest(displayHdiService->instance, cmdId, data, reply);
34 }
35
HdfDisplayHostDriverInit(struct HdfDeviceObject * deviceObject)36 static int32_t HdfDisplayHostDriverInit(struct HdfDeviceObject *deviceObject)
37 {
38 (void)deviceObject;
39 HDF_LOGI("%{public}s: enter", __func__);
40 return HDF_SUCCESS;
41 }
42
HdfDisplayHostDriverBind(struct HdfDeviceObject * deviceObject)43 static int32_t HdfDisplayHostDriverBind(struct HdfDeviceObject *deviceObject)
44 {
45 HdfDisplayHdiService *displayHdiService =
46 reinterpret_cast<HdfDisplayHdiService *>(OsalMemAlloc(sizeof(HdfDisplayHdiService)));
47 if (displayHdiService == nullptr) {
48 HDF_LOGE("%{public}s: OsalMemAlloc HdfDisplayHdiService failed", __func__);
49 return HDF_FAILURE;
50 }
51
52 displayHdiService->ioservice.Dispatch = DisplayHdiServiceDispatch;
53 displayHdiService->ioservice.Open = NULL;
54 displayHdiService->ioservice.Release = NULL;
55 displayHdiService->instance = LayerStubInstance();
56
57 deviceObject->service = &displayHdiService->ioservice;
58 HDF_LOGI("%{public}s: exit succ", __func__);
59 return HDF_SUCCESS;
60 }
61
HdfDisplayHostDriverRelease(HdfDeviceObject * deviceObject)62 static void HdfDisplayHostDriverRelease(HdfDeviceObject *deviceObject)
63 {
64 HdfDisplayHdiService *displayHdiService = CONTAINER_OF(deviceObject->service, HdfDisplayHdiService, ioservice);
65 OsalMemFree(displayHdiService);
66 }
67
68 struct HdfDriverEntry g_displayHostDriverEntry = {
69 .moduleVersion = 1,
70 .moduleName = "hdi_video_layer_service",
71 .Bind = HdfDisplayHostDriverBind,
72 .Init = HdfDisplayHostDriverInit,
73 .Release = HdfDisplayHostDriverRelease,
74 };
75
76 #ifdef __cplusplus
77 extern "C" {
78 #endif /* __cplusplus */
79
80 HDF_INIT(g_displayHostDriverEntry);
81
82 #ifdef __cplusplus
83 }
84 #endif /* __cplusplus */
85