• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "pcie_test.h"
10 #include "device_resource_if.h"
11 #include "hdf_base.h"
12 #include "hdf_device_desc.h"
13 #include "hdf_log.h"
14 
15 #define HDF_LOG_TAG pcie_test_driver_c
16 
17 static struct PcieTestConfig g_config;
18 
PcieTestDispatch(struct HdfDeviceIoClient * client,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)19 static int32_t PcieTestDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
20 {
21     (void)data;
22     (void)client;
23 
24     if (cmd == 0) {
25         if (reply == NULL) {
26             HDF_LOGE("PcieTestDispatch: reply is null!");
27             return HDF_ERR_INVALID_PARAM;
28         }
29         if (!HdfSbufWriteUint32(reply, g_config.busNum)) {
30             HDF_LOGE("PcieTestDispatch: write busNum fail!");
31             return HDF_ERR_IO;
32         }
33     } else {
34         HDF_LOGE("PcieTestDispatch: cmd %d is not support!", cmd);
35         return HDF_ERR_NOT_SUPPORT;
36     }
37 
38     return HDF_SUCCESS;
39 }
40 
PcieTestReadConfig(const struct DeviceResourceNode * node)41 static int32_t PcieTestReadConfig(const struct DeviceResourceNode *node)
42 {
43     int32_t ret;
44     struct DeviceResourceIface *drsOps = NULL;
45 
46     drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
47     if (drsOps == NULL || drsOps->GetUint32 == NULL) {
48         HDF_LOGE("PcieTestReadConfig: invalid drs ops!");
49         return HDF_FAILURE;
50     }
51 
52     ret = drsOps->GetUint32(node, "busNum", &(g_config.busNum), 0);
53     if (ret != HDF_SUCCESS) {
54         HDF_LOGE("PcieTestReadConfig: read bus num fail!");
55         return ret;
56     }
57 
58     return HDF_SUCCESS;
59 }
60 
PcieTestBind(struct HdfDeviceObject * device)61 static int32_t PcieTestBind(struct HdfDeviceObject *device)
62 {
63     static struct IDeviceIoService service;
64 
65     if (device == NULL || device->property == NULL) {
66         HDF_LOGE("PcieTestBind: device or config is null!");
67         return HDF_ERR_IO;
68     }
69 
70     service.Dispatch = PcieTestDispatch;
71     device->service = &service;
72     HDF_LOGI("PcieTestBind: done!");
73     return HDF_SUCCESS;
74 }
75 
PcieTestInit(struct HdfDeviceObject * device)76 static int32_t PcieTestInit(struct HdfDeviceObject *device)
77 {
78     int32_t ret = PcieTestReadConfig(device->property);
79     if (ret != HDF_SUCCESS) {
80         HDF_LOGE("PcieTestInit: read config fail!");
81         return ret;
82     }
83     HDF_LOGI("PcieTestInit: done!");
84     return HDF_SUCCESS;
85 }
86 
PcieTestRelease(struct HdfDeviceObject * device)87 static void PcieTestRelease(struct HdfDeviceObject *device)
88 {
89     if (device != NULL) {
90         device->service = NULL;
91     }
92     HDF_LOGI("PcieTestRelease: done!");
93     return;
94 }
95 
96 struct HdfDriverEntry g_pcieTestEntry = {
97     .moduleVersion = 1,
98     .Bind = PcieTestBind,
99     .Init = PcieTestInit,
100     .Release = PcieTestRelease,
101     .moduleName = "PLATFORM_PCIE_TEST",
102 };
103 HDF_INIT(g_pcieTestEntry);
104