From 643d8c6df138f7ce5cce5b2158ab82091a9be038 Mon Sep 17 00:00:00 2001 From: guowen666 Date: Wed, 17 May 2023 14:04:48 +0800 Subject: [PATCH] fixed ed75674 from https://gitee.com/guowen666/drivers_hdf_core/pulls/1878 fix input event report bug Signed-off-by: guowen666 --- framework/model/input/driver/event_hub.c | 28 ++++++++---- .../model/input/driver/hdf_hid_adapter.c | 23 ++++++---- .../input/driver/hdf_input_device_manager.c | 45 ++++++++++++++++++- .../input/driver/hdf_input_device_manager.h | 5 +++ 4 files changed, 82 insertions(+), 19 deletions(-) diff --git a/framework/model/input/driver/event_hub.c b/framework/model/input/driver/event_hub.c index dc2f52a6d..7c291c782 100644 --- a/framework/model/input/driver/event_hub.c +++ b/framework/model/input/driver/event_hub.c @@ -12,27 +12,29 @@ #define SEC_TO_USEC 1000000 -static void SendFramePackages(InputDevice *inputDev) +static void EventQueueWorkEntry(void *arg) { - struct HdfDeviceObject *hdfDev = inputDev->hdfDevObj; - if (hdfDev == NULL || inputDev->pkgBuf == NULL) { - HDF_LOGE("%s: hdf dev is null", __func__); + InputDevice *inputDev = (InputDevice *)arg; + if (inputDev == NULL) { + HDF_LOGE("%s: inputDev is NULL", __func__); return; } - HdfDeviceSendEvent(hdfDev, 0, inputDev->pkgBuf); + HdfDeviceSendEvent(inputDev->hdfDevObj, 0, inputDev->pkgBuf); + HdfSbufFlush(inputDev->pkgBuf); } void PushOnePackage(InputDevice *inputDev, uint32_t type, uint32_t code, int32_t value) { OsalTimespec time; EventPackage package = {0}; + uint32_t flag; InputManager *inputManager = GetInputManager(); if (inputDev == NULL) { HDF_LOGE("%s: parm is null", __func__); return; } - OsalMutexLock(&inputManager->mutex); + OsalSpinLockIrqSave(&inputManager->lock, &flag); package.type = type; package.code = code; package.value = value; @@ -59,12 +61,20 @@ void PushOnePackage(InputDevice *inputDev, uint32_t type, uint32_t code, int32_t } if (!inputDev->errFrameFlag) { - SendFramePackages(inputDev); + if (HdfWorkInit(inputDev->eventWork, EventQueueWorkEntry, inputDev) != HDF_SUCCESS) { + HDF_LOGE("%s: create event thread failed", __func__); + OsalSpinUnlockIrqRestore(&inputManager->lock, &flag); + return; + } + if (!HdfAddWork(&inputDev->eventWorkQueue, inputDev->eventWork)) { + HDF_LOGE("%s: Add event work queue failed", __func__); + OsalSpinUnlockIrqRestore(&inputManager->lock, &flag); + return; + } } inputDev->pkgCount = 0; - HdfSbufFlush(inputDev->pkgBuf); inputDev->errFrameFlag = false; } - OsalMutexUnlock(&inputManager->mutex); + OsalSpinUnlockIrqRestore(&inputManager->lock, &flag); } \ No newline at end of file diff --git a/framework/model/input/driver/hdf_hid_adapter.c b/framework/model/input/driver/hdf_hid_adapter.c index a54cdb5ee..a5f714c62 100644 --- a/framework/model/input/driver/hdf_hid_adapter.c +++ b/framework/model/input/driver/hdf_hid_adapter.c @@ -33,6 +33,15 @@ HidInfo *g_cachedInfo[MAX_INPUT_DEV_NUM]; uint32_t g_kbdcode = 0; OsalTimer g_timer; +static bool InputDriverLoaded(void) +{ + InputManager* g_inputManager = GetInputManager(); + if ((g_inputManager != NULL) && (g_inputManager->initialized != false)) { + return true; + } + return false; +} + static bool HaveHidCache(void) { if (cachedHid[0] == NULL) { @@ -224,15 +233,6 @@ static void CacheHid(InputDevice* inputDev) } } -static bool InputDriverLoaded(void) -{ - InputManager* g_inputManager = GetInputManager(); - if ((g_inputManager != NULL) && (g_inputManager->initialized != false)) { - return true; - } - return false; -} - void* HidRegisterHdfInputDev(HidInfo *info) { InputDevice* inputDev = HidConstructInputDev(info); @@ -288,6 +288,11 @@ static void RepateEvent(const InputDevice *device) void HidReportEvent(const void *inputDev, uint32_t type, uint32_t code, int32_t value) { + bool loaded = InputDriverLoaded(); + if (!loaded) { + HDF_LOGD("%s: device not loaded", __func__); + return; + } #ifdef CONFIG_DFX_ZEROHUNG if (type == EV_KEY && code == KEY_POWER) hung_wp_screen_powerkey_ncb(value); diff --git a/framework/model/input/driver/hdf_input_device_manager.c b/framework/model/input/driver/hdf_input_device_manager.c index 9a4f60ebd..bef957660 100644 --- a/framework/model/input/driver/hdf_input_device_manager.c +++ b/framework/model/input/driver/hdf_input_device_manager.c @@ -16,6 +16,7 @@ #define NODE_MODE 0660 #define SERVICE_NAME_LEN 24 +#define QUEUE_NAME_LEN 18 #define INPUT_DEV_EXIST 1 #define INPUT_DEV_NOT_EXIST 0 #define INPUTDEV_FIRST_ID 2 @@ -286,10 +287,32 @@ static int32_t AllocDeviceID(InputDevice *inputDev) return HDF_FAILURE; } +static int32_t InitEventWorkQueue(InputDevice *inputDev) +{ + char queueName[QUEUE_NAME_LEN] = {0}; + + int32_t len = (inputDev->devId < PLACEHOLDER_LIMIT) ? 1 : PLACEHOLDER_LENGTH; + int32_t ret = snprintf_s(queueName, QUEUE_NAME_LEN, strlen("hdf_event") + len + strlen("_queue"), "%s%u%s", + "hdf_event", inputDev->devId, "_queue"); + if (ret < 0) { + HDF_LOGE("%s: snprintf_s failed", __func__); + return HDF_FAILURE; + } + if (HdfWorkQueueInit(&inputDev->eventWorkQueue, queueName) != HDF_SUCCESS) { + HDF_LOGE("%s: device %s init work queue failed", __func__, inputDev->devName); + return HDF_FAILURE; + } + inputDev->eventWork = (HdfWork *)OsalMemCalloc(sizeof(HdfWork)); + if (inputDev->eventWork == NULL) { + HDF_LOGE("%s: calloc event work failed", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + int32_t RegisterInputDevice(InputDevice *inputDev) { int32_t ret; - HDF_LOGI("%s: enter", __func__); if (inputDev == NULL) { HDF_LOGE("%s: inputdev is null", __func__); @@ -315,6 +338,10 @@ int32_t RegisterInputDevice(InputDevice *inputDev) if (ret != HDF_SUCCESS) { goto EXIT1; } + ret = InitEventWorkQueue(inputDev); + if (ret != HDF_SUCCESS) { + goto EXIT1; + } AddInputDevice(inputDev); OsalMutexUnlock(&g_inputManager->mutex); @@ -357,7 +384,15 @@ void UnregisterInputDevice(InputDevice *inputDev) } HdfSbufRecycle(inputDev->eventBuf); inputDev->eventBuf = NULL; + HdfWorkQueueDestroy(&inputDev->eventWorkQueue); + + if (inputDev->eventWork->realWork != NULL) { + HdfWorkDestroy(inputDev->eventWork); + } + OsalMemFree(inputDev->eventWork); + inputDev->eventWork = NULL; OsalMemFree(inputDev); + inputDev = NULL; OsalMutexUnlock(&g_inputManager->mutex); HDF_LOGI("%s: exit succ, devCount is %d", __func__, g_inputManager->devCount); return; @@ -453,6 +488,13 @@ static int32_t HdfInputManagerInit(struct HdfDeviceObject *device) g_inputManager = NULL; return HDF_FAILURE; } + + if (OsalSpinInit(&g_inputManager->lock) != HDF_SUCCESS) { + HDF_LOGE("%s: spin lock init failed", __func__); + OsalMemFree(g_inputManager); + g_inputManager = NULL; + return HDF_FAILURE; + } g_inputManager->initialized = true; g_inputManager->hdfDevObj = device; HDF_LOGI("%s: exit succ", __func__); @@ -467,6 +509,7 @@ static void HdfInputManagerRelease(struct HdfDeviceObject *device) } if (g_inputManager != NULL) { OsalMutexDestroy(&g_inputManager->mutex); + OsalSpinDestroy(&g_inputManager->lock); OsalMemFree(g_inputManager); g_inputManager = NULL; } diff --git a/framework/model/input/driver/hdf_input_device_manager.h b/framework/model/input/driver/hdf_input_device_manager.h index 00d5e1655..e9ab4fee2 100644 --- a/framework/model/input/driver/hdf_input_device_manager.h +++ b/framework/model/input/driver/hdf_input_device_manager.h @@ -11,8 +11,10 @@ #include "input-event-codes.h" #include "osal_mutex.h" +#include "osal_spinlock.h" #include "hdf_types.h" #include "hdf_device_desc.h" +#include "hdf_workqueue.h" #ifdef HDF_LOG_TAG #undef HDF_LOG_TAG @@ -103,6 +105,8 @@ typedef struct { typedef struct InputDeviceInfo { struct HdfDeviceObject *hdfDevObj; + HdfWorkQueue eventWorkQueue; + HdfWork *eventWork; uint32_t devId; uint32_t devType; const char *devName; @@ -121,6 +125,7 @@ typedef struct { struct HdfDeviceObject *hdfDevObj; uint32_t devCount; struct OsalMutex mutex; + OsalSpinlock lock; bool initialized; InputDevice *inputDevList; } InputManager; -- Gitee