1 /* 2 * Copyright (c) 2022-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 #ifndef PLATFORM_LISTENER_U_H 10 #define PLATFORM_LISTENER_U_H 11 12 #include "gpio_if.h" 13 #include "hdf_base.h" 14 #include "hdf_dlist.h" 15 #include "hdf_io_service_if.h" 16 #include "osal_mutex.h" 17 #include "pcie_if.h" 18 #include "platform_core.h" 19 #include "rtc_if.h" 20 #include "timer_if.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif /* __cplusplus */ 25 26 struct PlatformUserListener { 27 enum PlatformModuleType moudle; 28 uint32_t num; 29 struct HdfDevEventlistener *listener; 30 void *data; 31 struct DListHead node; 32 }; 33 34 struct PlatformUserListenerManager { 35 struct HdfIoService *service; 36 enum PlatformModuleType moudle; 37 struct DListHead listeners; 38 struct OsalMutex lock; 39 }; 40 41 struct PlatformUserListenerGpioParam { 42 uint16_t gpio; 43 void *data; 44 GpioIrqFunc func; 45 }; 46 47 struct PlatformUserListenerRtcParam { 48 enum RtcAlarmIndex index; 49 RtcAlarmCallback func; 50 }; 51 52 struct PlatformUserListenerTimerParam { 53 uint32_t handle; 54 bool isOnce; 55 TimerHandleCb func; 56 struct PlatformUserListenerManager *manager; 57 }; 58 59 struct PlatformUserListenerPcieParam { 60 DevHandle handle; 61 PcieCallbackFunc func; 62 uintptr_t dmaData; 63 uint32_t len; 64 uint8_t dir; 65 struct PlatformUserListenerManager *manager; 66 }; 67 68 struct PlatformUserListenerManager *PlatformUserListenerManagerGet(enum PlatformModuleType moudle); 69 int32_t PlatformUserListenerReg( 70 struct PlatformUserListenerManager *manager, uint32_t num, void *data, OnEventReceived callback); 71 void PlatformUserListenerDestory(struct PlatformUserListenerManager *manager, uint32_t num); 72 void PlatformUserListenerManagerDestory(struct PlatformUserListenerManager *manager); 73 74 int GpioOnDevEventReceive(void *priv, uint32_t id, struct HdfSBuf *data); 75 int TimerOnDevEventReceive(void *priv, uint32_t id, struct HdfSBuf *data); 76 int RtcOnDevEventReceive(void *priv, uint32_t id, struct HdfSBuf *data); 77 int PcieOnDevEventReceive(void *priv, uint32_t id, struct HdfSBuf *data); 78 79 #ifdef __cplusplus 80 } 81 #endif /* __cplusplus */ 82 83 #endif /* PLATFORM_LISTENER_U_H */ 84