1 /*
2 * Copyright (c) 2021-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_if.h"
10 #include "devsvc_manager_clnt.h"
11 #include "pcie_core.h"
12 #include "hdf_base.h"
13 #include "hdf_log.h"
14 #include "osal_mem.h"
15
16 #define HDF_LOG_TAG pcie_if_c
17
18 #define PCIE_SERVICE_NAME_LEN 32
19
PcieCntlrObjGet(uint16_t busNum)20 static struct PcieCntlr *PcieCntlrObjGet(uint16_t busNum)
21 {
22 char serviceName[PCIE_SERVICE_NAME_LEN + 1] = {0};
23 struct PcieCntlr *obj = NULL;
24
25 if (snprintf_s(serviceName, (PCIE_SERVICE_NAME_LEN + 1),
26 PCIE_SERVICE_NAME_LEN, "HDF_PLATFORM_PCIE_%hu", busNum) < 0) {
27 HDF_LOGE("PcieCntlrObjGet: get PCIE service name fail.");
28 return NULL;
29 }
30 obj = PcieCntlrGetByBusNum(busNum);
31 return obj;
32 }
33
PcieOpen(uint16_t busNum)34 DevHandle PcieOpen(uint16_t busNum)
35 {
36 return (DevHandle)PcieCntlrObjGet(busNum);
37 }
38
PcieRead(DevHandle handle,uint32_t mode,uint32_t pos,uint8_t * data,uint32_t len)39 int32_t PcieRead(DevHandle handle, uint32_t mode, uint32_t pos, uint8_t *data, uint32_t len)
40 {
41 return PcieCntlrRead((struct PcieCntlr *)handle, mode, pos, data, len);
42 }
43
PcieWrite(DevHandle handle,uint32_t mode,uint32_t pos,uint8_t * data,uint32_t len)44 int32_t PcieWrite(DevHandle handle, uint32_t mode, uint32_t pos, uint8_t *data, uint32_t len)
45 {
46 return PcieCntlrWrite((struct PcieCntlr *)handle, mode, pos, data, len);
47 }
48
PcieDmaMap(DevHandle handle,PcieCallbackFunc cb,uintptr_t addr,uint32_t len,uint8_t dir)49 int32_t PcieDmaMap(DevHandle handle, PcieCallbackFunc cb, uintptr_t addr, uint32_t len, uint8_t dir)
50 {
51 return PcieCntlrDmaMap((struct PcieCntlr *)handle, cb, addr, len, dir);
52 }
53
PcieDmaUnmap(DevHandle handle,uintptr_t addr,uint32_t len,uint8_t dir)54 void PcieDmaUnmap(DevHandle handle, uintptr_t addr, uint32_t len, uint8_t dir)
55 {
56 PcieCntlrDmaUnmap((struct PcieCntlr *)handle, addr, len, dir);
57 }
58
PcieRegisterIrq(DevHandle handle,PcieCallbackFunc cb)59 int32_t PcieRegisterIrq(DevHandle handle, PcieCallbackFunc cb)
60 {
61 return PcieCntlrRegisterIrq((struct PcieCntlr *)handle, cb);
62 }
63
PcieUnregisterIrq(DevHandle handle)64 void PcieUnregisterIrq(DevHandle handle)
65 {
66 PcieCntlrUnregisterIrq((struct PcieCntlr *)handle);
67 }
68
PcieClose(DevHandle handle)69 void PcieClose(DevHandle handle)
70 {
71 (void)handle;
72 }
73