From 00c8284ada9f32e588c4b2968bcd79e199c10092 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Tue, 16 Nov 2021 10:49:27 +0800 Subject: [PATCH] support union device id Signed-off-by: yuanbo --- khdf/liteos/BUILD.gn | 2 +- khdf/liteos/Makefile | 2 +- khdf/liteos_m/core/BUILD.gn | 2 +- .../core/common/src/hdf_device_node_ext.c | 46 ++---------- uhdf2/host/BUILD.gn | 1 - uhdf2/host/src/devhost_service_full.c | 22 +++--- uhdf2/host/src/devhost_service_stub.c | 3 +- uhdf2/host/src/device_service_stub.c | 16 +++-- uhdf2/host/src/devmgr_service_proxy.c | 43 +++++++---- uhdf2/host/src/driver_loader_full.c | 71 +++++++++++++------ uhdf2/host/src/hdf_device_full.c | 19 ++--- uhdf2/host/src/hdf_device_thread.c | 6 +- uhdf2/manager/include/devmgr_service_stub.h | 1 + uhdf2/manager/src/devhost_service_proxy.c | 32 +++++---- uhdf2/manager/src/devmgr_pnp_service.c | 4 +- uhdf2/manager/src/devmgr_service_stub.c | 27 +++++-- uhdf2/manager/src/hdf_get_attribute.c | 5 +- uhdf2/shared/src/hdf_device_info_full.c | 5 +- 18 files changed, 173 insertions(+), 134 deletions(-) mode change 100755 => 100644 uhdf2/host/src/devmgr_service_proxy.c mode change 100755 => 100644 uhdf2/manager/src/devmgr_pnp_service.c mode change 100755 => 100644 uhdf2/manager/src/devmgr_service_stub.c mode change 100755 => 100644 uhdf2/shared/src/hdf_device_info_full.c diff --git a/khdf/liteos/BUILD.gn b/khdf/liteos/BUILD.gn index 75bf0e2..55371bd 100644 --- a/khdf/liteos/BUILD.gn +++ b/khdf/liteos/BUILD.gn @@ -38,7 +38,6 @@ hdf_driver(module_name) { "$HDF_FRAMEWORKS_PATH/core/common/src/devmgr_service_start.c", "$HDF_FRAMEWORKS_PATH/core/common/src/hdf_attribute.c", "$HDF_FRAMEWORKS_PATH/core/common/src/hdf_device_node_ext.c", - "$HDF_FRAMEWORKS_PATH/core/common/src/load_driver_entry.c", "$HDF_FRAMEWORKS_PATH/core/host/src/devhost_service.c", "$HDF_FRAMEWORKS_PATH/core/host/src/devmgr_service_clnt.c", "$HDF_FRAMEWORKS_PATH/core/host/src/devsvc_manager_clnt.c", @@ -55,6 +54,7 @@ hdf_driver(module_name) { "$HDF_FRAMEWORKS_PATH/core/manager/src/device_token_clnt.c", "$HDF_FRAMEWORKS_PATH/core/manager/src/devmgr_service.c", "$HDF_FRAMEWORKS_PATH/core/manager/src/devsvc_manager.c", + "$HDF_FRAMEWORKS_PATH/core/manager/src/driver_manager.c", "$HDF_FRAMEWORKS_PATH/core/manager/src/hdf_driver_installer.c", "$HDF_FRAMEWORKS_PATH/core/manager/src/hdf_host_info.c", "$HDF_FRAMEWORKS_PATH/core/manager/src/power_state_token_clnt.c", diff --git a/khdf/liteos/Makefile b/khdf/liteos/Makefile index 9bb0e5a..5342dcb 100644 --- a/khdf/liteos/Makefile +++ b/khdf/liteos/Makefile @@ -70,6 +70,7 @@ LOCAL_SRCS := ./osal/src/osal_timer.c \ $(HDF_FRAMEWORKS)/core/manager/src/hdf_driver_installer.c \ $(HDF_FRAMEWORKS)/core/manager/src/hdf_host_info.c \ $(HDF_FRAMEWORKS)/core/manager/src/power_state_token_clnt.c \ + $(HDF_FRAMEWORKS)/core/manager/src/driver_manager.c \ $(HDF_FRAMEWORKS)/core/shared/src/hdf_service_record.c \ $(HDF_FRAMEWORKS)/core/shared/src/hdf_device_info.c \ $(HDF_FRAMEWORKS)/core/shared/src/hdf_object_manager.c \ @@ -77,7 +78,6 @@ LOCAL_SRCS := ./osal/src/osal_timer.c \ $(HDF_FRAMEWORKS)/core/adapter/vnode/src/hdf_vnode_adapter.c \ $(HDF_FRAMEWORKS)/core/common/src/devlite_object_config.c \ $(HDF_FRAMEWORKS)/core/common/src/hdf_attribute.c \ - $(HDF_FRAMEWORKS)/core/common/src/load_driver_entry.c \ $(HDF_FRAMEWORKS)/core/common/src/devmgr_service_start.c \ $(HDF_FRAMEWORKS)/core/common/src/hdf_device_node_ext.c \ $(HDF_FRAMEWORKS)/utils/src/hcs_parser/hcs_blob_if.c \ diff --git a/khdf/liteos_m/core/BUILD.gn b/khdf/liteos_m/core/BUILD.gn index 98e8e23..9d5beda 100644 --- a/khdf/liteos_m/core/BUILD.gn +++ b/khdf/liteos_m/core/BUILD.gn @@ -34,7 +34,6 @@ hdf_driver("hdf_core") { sources = [ "$HDF_FRAMEWORKS_PATH/core/common/src/devlite_object_config.c", "$HDF_FRAMEWORKS_PATH/core/common/src/hdf_attribute.c", - "$HDF_FRAMEWORKS_PATH/core/common/src/load_driver_entry.c", "$HDF_FRAMEWORKS_PATH/core/host/src/devhost_service.c", "$HDF_FRAMEWORKS_PATH/core/host/src/devmgr_service_clnt.c", "$HDF_FRAMEWORKS_PATH/core/host/src/devsvc_manager_clnt.c", @@ -51,6 +50,7 @@ hdf_driver("hdf_core") { "$HDF_FRAMEWORKS_PATH/core/manager/src/device_token_clnt.c", "$HDF_FRAMEWORKS_PATH/core/manager/src/devmgr_service.c", "$HDF_FRAMEWORKS_PATH/core/manager/src/devsvc_manager.c", + "$HDF_FRAMEWORKS_PATH/core/manager/src/driver_manager.c", "$HDF_FRAMEWORKS_PATH/core/manager/src/hdf_driver_installer.c", "$HDF_FRAMEWORKS_PATH/core/manager/src/hdf_host_info.c", "$HDF_FRAMEWORKS_PATH/core/manager/src/power_state_token_clnt.c", diff --git a/khdf/liteos_m/core/common/src/hdf_device_node_ext.c b/khdf/liteos_m/core/common/src/hdf_device_node_ext.c index 168d8b4..7487726 100644 --- a/khdf/liteos_m/core/common/src/hdf_device_node_ext.c +++ b/khdf/liteos_m/core/common/src/hdf_device_node_ext.c @@ -39,52 +39,14 @@ #define HDF_LOG_TAG device_node_ext -static int DeviceNodeExtDispatch(struct HdfObject *stub, int code, struct HdfSBuf *data, struct HdfSBuf *reply) +static int DeviceNodeExtPublishService(struct HdfDeviceNode *inst) { - struct IDeviceIoService *deviceMethod = NULL; - const struct HdfDeviceInfo *deviceInfo = NULL; - struct HdfDeviceNode *devNode = NULL; - - if (stub == NULL) { - HDF_LOGE("input ioService null"); - return HDF_FAILURE; - } - uint64_t ioClientPtr = 0; - if (!HdfSbufReadUint64(reply, &ioClientPtr) || ioClientPtr == 0) { - HDF_LOGE("input ioClient null"); - return HDF_FAILURE; - } - HdfSbufFlush(reply); - devNode = CONTAINER_OF(stub, struct HdfDeviceNode, deviceObject); - deviceMethod = devNode->deviceObject.service; - if (deviceMethod == NULL) { - HDF_LOGE("Device service interface is null"); - return HDF_FAILURE; - } - deviceInfo = devNode->deviceInfo; - if (deviceInfo == NULL) { - HDF_LOGE("Device deviceInfo is null"); - return HDF_FAILURE; - } - if (deviceInfo->policy == SERVICE_POLICY_CAPACITY) { - if (deviceMethod->Dispatch == NULL) { - HDF_LOGE("Remote service dispatch is null"); - return HDF_FAILURE; - } - return deviceMethod->Dispatch((struct HdfDeviceIoClient *)((uintptr_t)ioClientPtr), code, data, reply); - } - return HDF_FAILURE; -} - -static int DeviceNodeExtPublishService(struct HdfDeviceNode *inst, const char *serviceName) -{ - const struct HdfDeviceInfo *deviceInfo = NULL; - struct HdfDeviceObject *deviceObject = NULL; struct DeviceNodeExt *devNodeExt = (struct DeviceNodeExt *)inst; if (devNodeExt == NULL) { return HDF_FAILURE; } - int ret = HdfDeviceNodePublishPublicService(inst, serviceName); + + int ret = HdfDeviceNodePublishPublicService(inst); if (ret != HDF_SUCCESS) { HDF_LOGE("Device publish service failed, ret is: %d", ret); } @@ -101,7 +63,7 @@ static void DeviceNodeExtConstruct(struct DeviceNodeExt *inst) } } -struct HdfObject *DeviceNodeExtCreate() +struct HdfObject *DeviceNodeExtCreate(void) { struct DeviceNodeExt *instance = (struct DeviceNodeExt *)OsalMemCalloc(sizeof(struct DeviceNodeExt)); diff --git a/uhdf2/host/BUILD.gn b/uhdf2/host/BUILD.gn index a9dc2b7..a2a3adf 100755 --- a/uhdf2/host/BUILD.gn +++ b/uhdf2/host/BUILD.gn @@ -56,7 +56,6 @@ ohos_shared_library("libhdf_host") { "$hdf_framework_path/core/host/src/hdf_device_node.c", "$hdf_framework_path/core/host/src/hdf_device_object.c", "$hdf_framework_path/core/host/src/hdf_device_token.c", - "$hdf_framework_path/core/host/src/hdf_driver_loader.c", "$hdf_framework_path/core/host/src/hdf_observer_record.c", "$hdf_framework_path/core/host/src/hdf_service_observer.c", "$hdf_framework_path/core/host/src/hdf_service_subscriber.c", diff --git a/uhdf2/host/src/devhost_service_full.c b/uhdf2/host/src/devhost_service_full.c index b0c8095..0eab2aa 100644 --- a/uhdf2/host/src/devhost_service_full.c +++ b/uhdf2/host/src/devhost_service_full.c @@ -41,12 +41,11 @@ static int32_t DevHostServiceFullDispatchMessage(struct HdfMessageTask *task, st break; } case DEVHOST_MESSAGE_DEL_DEVICE: { - struct HdfDeviceInfo *attribute = (struct HdfDeviceInfo *)msg->data[0]; - status = DevHostServiceDelDevice(&hostService->super.super, attribute); + devid_t devid = (devid_t)((uintptr_t)msg->data[0]); + status = DevHostServiceDelDevice(&hostService->super.super, devid); if (status != HDF_SUCCESS) { HDF_LOGE("DevHostServiceDelDevice failed and return %{public}d", status); } - HdfDeviceInfoFullFreeInstance((struct HdfDeviceInfoFull *)attribute); break; } default: { @@ -59,9 +58,9 @@ static int32_t DevHostServiceFullDispatchMessage(struct HdfMessageTask *task, st } static int DevHostServiceFullOpsDevice( - struct IDevHostService *devHostService, const struct HdfDeviceInfo *attribute, int cmdCode) + struct IDevHostService *devHostService, uintptr_t parm, int cmdCode) { - if (devHostService == NULL || attribute == NULL) { + if (devHostService == NULL) { HDF_LOGE("input is null"); return HDF_FAILURE; } @@ -74,20 +73,19 @@ static int DevHostServiceFullOpsDevice( } message->messageId = cmdCode; - message->data[0] = (void *)attribute; + message->data[0] = (void *)parm; return task->SendMessage(task, message, true); } static int DevHostServiceFullAddDevice( struct IDevHostService *devHostService, const struct HdfDeviceInfo *attribute) { - return DevHostServiceFullOpsDevice(devHostService, attribute, DEVHOST_MESSAGE_ADD_DEVICE); + return DevHostServiceFullOpsDevice(devHostService, (uintptr_t)attribute, DEVHOST_MESSAGE_ADD_DEVICE); } -static int DevHostServiceFullDelDevice( - struct IDevHostService *devHostService, const struct HdfDeviceInfo *attribute) +static int DevHostServiceFullDelDevice(struct IDevHostService *devHostService, devid_t devid) { - return DevHostServiceFullOpsDevice(devHostService, attribute, DEVHOST_MESSAGE_DEL_DEVICE); + return DevHostServiceFullOpsDevice(devHostService, (uintptr_t)devid, DEVHOST_MESSAGE_DEL_DEVICE); } static int DevHostServiceFullDispatchPowerState(struct HdfDevice *device, uint32_t state) @@ -102,7 +100,7 @@ static int DevHostServiceFullDispatchPowerState(struct HdfDevice *device, uint32 ret = PowerStateChange(deviceNode->powerToken, state); if (ret != HDF_SUCCESS) { HDF_LOGE("device %{public}s failed to resume(%{public}d) %{public}d", - deviceNode->driverEntry->moduleName, state, ret); + deviceNode->driver->entry->moduleName, state, ret); result = HDF_FAILURE; } } @@ -113,7 +111,7 @@ static int DevHostServiceFullDispatchPowerState(struct HdfDevice *device, uint32 ret = PowerStateChange(deviceNode->powerToken, state); if (ret != HDF_SUCCESS) { HDF_LOGE("device %{public}s failed to suspend(%{public}d) %{public}d", - deviceNode->driverEntry->moduleName, state, ret); + deviceNode->driver->entry->moduleName, state, ret); result = HDF_FAILURE; } } diff --git a/uhdf2/host/src/devhost_service_stub.c b/uhdf2/host/src/devhost_service_stub.c index aaceea3..5a721c0 100644 --- a/uhdf2/host/src/devhost_service_stub.c +++ b/uhdf2/host/src/devhost_service_stub.c @@ -57,6 +57,7 @@ static int DevHostServiceStubDispatch( if (ret != HDF_SUCCESS) { HDF_LOGE("Dispatch failed, add service failed and ret is %{public}d", ret); } + HdfDeviceInfoFullFreeInstance(attribute); break; } case DEVHOST_SERVICE_DEL_DEVICE: { @@ -69,7 +70,7 @@ static int DevHostServiceStubDispatch( HDF_LOGE("Dispatch failed, attribute is null"); break; } - ret = serviceIf->DelDevice(serviceIf, &attribute->super); + ret = serviceIf->DelDevice(serviceIf, attribute->super.deviceId); if (ret != HDF_SUCCESS) { HDF_LOGE("Dispatch failed, del service failed and ret is %{public}d", ret); } diff --git a/uhdf2/host/src/device_service_stub.c b/uhdf2/host/src/device_service_stub.c index f63c1aa..4191424 100644 --- a/uhdf2/host/src/device_service_stub.c +++ b/uhdf2/host/src/device_service_stub.c @@ -46,18 +46,22 @@ static struct HdfRemoteDispatcher g_deviceServiceDispatcher = { .Dispatch = DeviceServiceStubDispatch }; -int DeviceServiceStubPublishService(struct HdfDeviceNode *service, const char *serviceName) +int DeviceServiceStubPublishService(struct HdfDeviceNode *service) { int status = HDF_FAILURE; struct DeviceServiceStub *fullService = (struct DeviceServiceStub *)service; - const struct HdfDeviceInfo *deviceInfo = service->deviceInfo; + + if (service->servName == NULL) { + HDF_LOGE("device %x miss service name", service->devId); + return HDF_ERR_INVALID_OBJECT; + } if (fullService->remote != NULL) { - HDF_LOGE("%{public}s:service %{public}s already published", __func__, serviceName); + HDF_LOGE("%{public}s:service %{public}s already published", __func__, service->servName); return HDF_ERR_INVALID_OBJECT; } - if (deviceInfo->policy == SERVICE_POLICY_PUBLIC || deviceInfo->policy == SERVICE_POLICY_CAPACITY) { + if (service->policy == SERVICE_POLICY_PUBLIC || service->policy == SERVICE_POLICY_CAPACITY) { fullService->remote = HdfRemoteServiceObtain((struct HdfObject *)fullService, &g_deviceServiceDispatcher); if (fullService->remote == NULL) { return HDF_ERR_MALLOC_FAIL; @@ -65,7 +69,7 @@ int DeviceServiceStubPublishService(struct HdfDeviceNode *service, const char *s struct DevSvcManagerClnt *serviceManager = (struct DevSvcManagerClnt *)DevSvcManagerClntGetInstance(); if (serviceManager != NULL) { - status = DevSvcManagerClntAddService(serviceName, &fullService->super.deviceObject); + status = DevSvcManagerClntAddService(service->servName, &fullService->super.deviceObject); } } @@ -81,7 +85,7 @@ void DeviceServiceStubConstruct(struct DeviceServiceStub *inst) } } -struct HdfObject *DeviceServiceStubCreate() +struct HdfObject *DeviceServiceStubCreate(void) { struct DeviceServiceStub *instance = (struct DeviceServiceStub *)OsalMemCalloc(sizeof(struct DeviceServiceStub)); diff --git a/uhdf2/host/src/devmgr_service_proxy.c b/uhdf2/host/src/devmgr_service_proxy.c old mode 100755 new mode 100644 index 3f180d7..2618d9e --- a/uhdf2/host/src/devmgr_service_proxy.c +++ b/uhdf2/host/src/devmgr_service_proxy.c @@ -57,25 +57,43 @@ finished: } int DevmgrServiceProxyAttachDevice( - struct IDevmgrService *inst, const struct HdfDeviceInfo *deviceInfo, struct IHdfDeviceToken *token) + struct IDevmgrService *inst, struct IHdfDeviceToken *token) { int status = HDF_FAILURE; struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC); struct HdfSBuf *reply = HdfSBufTypedObtain(SBUF_IPC); - struct HdfRemoteDispatcher *dipatcher = NULL; - struct HdfRemoteService *remoteService = NULL; struct DevmgrServiceProxy *serviceProxy = (struct DevmgrServiceProxy *)inst; - struct DeviceTokenStub *tokenStub = (struct DeviceTokenStub *)token; - if ((serviceProxy == NULL) || (serviceProxy->remote == NULL) || (deviceInfo == NULL) || (data == NULL) || - (reply == NULL) || (tokenStub == NULL)) { + if (serviceProxy == NULL || serviceProxy->remote == NULL || data == NULL || + reply == NULL || token == NULL) { HDF_LOGE("DevmgrServiceProxyAttachDevice failed"); goto finished; } - remoteService = serviceProxy->remote; - dipatcher = remoteService->dispatcher; - HdfSbufWriteInt32(data, deviceInfo->hostId); - HdfSbufWriteInt32(data, deviceInfo->deviceId); - status = dipatcher->Dispatch(remoteService, DEVMGR_SERVICE_ATTACH_DEVICE, data, reply); + struct HdfRemoteService *remoteService = serviceProxy->remote; + HdfSbufWriteInt32(data, token->devid); + status = remoteService->dispatcher->Dispatch(remoteService, DEVMGR_SERVICE_ATTACH_DEVICE, data, reply); +finished: + if (reply != NULL) { + HdfSBufRecycle(reply); + } + if (data != NULL) { + HdfSBufRecycle(data); + } + return status; +} + +int DevmgrServiceProxyDetachDevice(struct IDevmgrService *inst, devid_t devid) +{ + int status = HDF_FAILURE; + struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSBufTypedObtain(SBUF_IPC); + struct DevmgrServiceProxy *serviceProxy = (struct DevmgrServiceProxy *)inst; + if (serviceProxy == NULL || serviceProxy->remote == NULL || data == NULL || reply == NULL) { + HDF_LOGE("DevmgrServiceProxyDetachDevice failed"); + goto finished; + } + struct HdfRemoteService *remoteService = serviceProxy->remote; + HdfSbufWriteInt32(data, devid); + status = remoteService->dispatcher->Dispatch(remoteService, DEVMGR_SERVICE_DETACH_DEVICE, data, reply); finished: if (reply != NULL) { HdfSBufRecycle(reply); @@ -91,6 +109,7 @@ static void DevmgrServiceProxyConstruct(struct DevmgrServiceProxy *inst) struct IDevmgrService *pvtbl = (struct IDevmgrService *)inst; pvtbl->AttachDeviceHost = DevmgrServiceProxyAttachDeviceHost; pvtbl->AttachDevice = DevmgrServiceProxyAttachDevice; + pvtbl->DetachDevice = DevmgrServiceProxyDetachDevice; pvtbl->StartService = NULL; } @@ -110,7 +129,7 @@ static struct IDevmgrService *DevmgrServiceProxyObtain(struct HdfRemoteService * return NULL; } -struct HdfObject *DevmgrServiceProxyCreate() +struct HdfObject *DevmgrServiceProxyCreate(void) { static struct IDevmgrService *instance = NULL; if (instance == NULL) { diff --git a/uhdf2/host/src/driver_loader_full.c b/uhdf2/host/src/driver_loader_full.c index b078acc..99f81b4 100644 --- a/uhdf2/host/src/driver_loader_full.c +++ b/uhdf2/host/src/driver_loader_full.c @@ -23,6 +23,7 @@ #include "hdf_device_info_full.h" #include "hdf_device_node.h" #include "hdf_log.h" +#include "hdf_object_manager.h" #include "osal_mem.h" #include "securec.h" @@ -36,24 +37,19 @@ static struct DriverLoaderFull *g_fullLoader = NULL; -struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo *deviceInfo) +struct HdfDriver *HdfDriverLoaderGetDriver(const char *moduleName) { - void *deviceHandle = NULL; - struct HdfDriverEntry **deviceEntry = NULL; - struct HdfDeviceInfoFull *fullAttribute = (struct HdfDeviceInfoFull *)deviceInfo; char realPath[PATH_MAX] = { 0 }; char driverPath[PATH_MAX] = { 0 }; - if (deviceInfo == NULL || deviceInfo->moduleName == NULL) { + if (moduleName == NULL) { return NULL; } if (strcat_s(driverPath, sizeof(driverPath) - 1, DRIVER_PATH) != EOK) { - HDF_LOGE("%{public}s get driver path failed", __func__); return NULL; } - if (strcat_s(driverPath, (sizeof(driverPath) - 1 - sizeof(DRIVER_PATH)), deviceInfo->moduleName) != EOK) { - HDF_LOGE("%{public}s get full driver path failed", __func__); + if (strcat_s(driverPath, (sizeof(driverPath) - 1 - sizeof(DRIVER_PATH)), moduleName) != EOK) { return NULL; } @@ -61,27 +57,53 @@ struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo HDF_LOGE("%{public}s no valid, errno:%{public}d", driverPath, errno); return NULL; } - deviceHandle = dlopen(realPath, RTLD_LAZY); - if (deviceHandle == NULL) { - HDF_LOGE("Get device entry failed, %{public}s load fail, %{public}s", realPath, dlerror()); + + struct HdfDriver *driver = OsalMemAlloc(sizeof(struct HdfDriver)); + if (driver == NULL) { return NULL; } - fullAttribute->deviceHandle = deviceHandle; - deviceEntry = (struct HdfDriverEntry **)dlsym(deviceHandle, DRIVER_DESC); - if (deviceEntry == NULL) { - HDF_LOGE("Get device entry failed, dlsym failed"); - dlclose(deviceHandle); - fullAttribute->deviceHandle = NULL; + + void *handle = dlopen(realPath, RTLD_LAZY); + if (handle == NULL) { + HDF_LOGE("get driver entry failed, %{public}s load fail, %{public}s", realPath, dlerror()); + OsalMemFree(driver); + return NULL; + } + + struct HdfDriverEntry **driverEntry = (struct HdfDriverEntry **)dlsym(handle, DRIVER_DESC); + if (driverEntry == NULL) { + HDF_LOGE("driver entry %{public}s dlsym failed", realPath); + dlclose(handle); + OsalMemFree(driver); return NULL; } - return *deviceEntry; + + driver->entry = *driverEntry; + driver->priv = handle; + + return driver; } +void HdfDriverLoaderFullReclaimDriver(struct HdfDriver *driver) +{ + if (driver == NULL) { + return; + } + + if (driver->priv != NULL) { + dlclose(driver->priv); + driver->priv = NULL; + } + + OsalMemFree(driver); +} + + void HdfDriverLoaderFullConstruct(struct DriverLoaderFull *inst) { struct HdfDriverLoader *pvtbl = (struct HdfDriverLoader *)inst; - HdfDriverLoaderConstruct(pvtbl); - pvtbl->super.GetDriverEntry = HdfDriverLoaderGetDriverEntry; + pvtbl->super.GetDriver = HdfDriverLoaderGetDriver; + pvtbl->super.ReclaimDriver = HdfDriverLoaderFullReclaimDriver; } struct HdfObject *HdfDriverLoaderFullCreate() @@ -107,3 +129,12 @@ void HdfDriverLoaderFullRelease(struct HdfObject *object) OsalMemFree(instance); } } + +struct IDriverLoader *HdfDriverLoaderGetInstance(void) +{ + static struct IDriverLoader *instance = NULL; + if (instance == NULL) { + instance = (struct IDriverLoader *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DRIVER_LOADER); + } + return instance; +} diff --git a/uhdf2/host/src/hdf_device_full.c b/uhdf2/host/src/hdf_device_full.c index bcb29bb..b9526c5 100644 --- a/uhdf2/host/src/hdf_device_full.c +++ b/uhdf2/host/src/hdf_device_full.c @@ -17,8 +17,10 @@ #include "device_service_stub.h" #include "hdf_base.h" #include "hdf_device_info_full.h" +#include "devhost_service.h" #include "hdf_log.h" #include "osal_mem.h" +#include "hdf_service_observer.h" #define HDF_LOG_TAG hdf_device_full @@ -54,29 +56,30 @@ static int HdfDeviceFullAttach( return HDF_SUCCESS; } -static void HdfDeviceFullDettach(struct IHdfDevice *device, struct HdfDeviceNode *devNode) +static int HdfDeviceFullDettach(struct IHdfDevice *device, struct HdfDeviceNode *devNode) { struct HdfDeviceFull *fullDevice = HdfDeviceFullReinterpretCast(device); if (fullDevice == NULL || devNode == NULL) { HDF_LOGE("%{public}s input is null", __func__); - return; + return HDF_ERR_INVALID_PARAM; } - if (devNode->driverEntry != NULL && devNode->driverEntry->Release != NULL) { - devNode->driverEntry->Release(&devNode->deviceObject); + if (devNode->driver->entry != NULL && devNode->driver->entry->Release != NULL) { + devNode->driver->entry->Release(&devNode->deviceObject); } struct DevHostService *hostService = devNode->hostService; if (hostService != NULL) { - HdfServiceObserverRemoveRecord(&hostService->observer, devNode->deviceInfo->svcName); + HdfServiceObserverRemoveRecord(&hostService->observer, devNode->servName); } - HdfDeviceInfoFullFreeInstance((struct HdfDeviceInfoFull *)devNode->deviceInfo); - DeviceServiceStubRelease(&devNode->super.object); + DeviceServiceStubRelease(&devNode->super.object); if (fullDevice->deviceThread != NULL) { fullDevice->deviceThread->looper.Stop(&fullDevice->deviceThread->looper); DeviceThreadFreeInstance(fullDevice->deviceThread); fullDevice->deviceThread = NULL; } + + return HDF_SUCCESS; } void HdfDeviceFullConstruct(struct HdfDeviceFull *inst) @@ -89,7 +92,7 @@ void HdfDeviceFullConstruct(struct HdfDeviceFull *inst) } } -struct HdfObject *HdfDeviceFullCreate() +struct HdfObject *HdfDeviceFullCreate(void) { struct HdfDeviceFull *device = (struct HdfDeviceFull *)OsalMemCalloc(sizeof(struct HdfDeviceFull)); diff --git a/uhdf2/host/src/hdf_device_thread.c b/uhdf2/host/src/hdf_device_thread.c index eb96e8a..f835404 100644 --- a/uhdf2/host/src/hdf_device_thread.c +++ b/uhdf2/host/src/hdf_device_thread.c @@ -26,10 +26,10 @@ int32_t DeviceThreadMessageHandler(struct HdfMessageTask *task, struct HdfMessag struct HdfDevice *device = (struct HdfDevice *)msg->data[0]; switch (msg->messageId) { case DEVICE_SERVICE_MESSAGE_LAUNCH: { + (void)device; struct HdfDeviceNode *devService = (struct HdfDeviceNode *)msg->data[1]; - struct IDeviceNode *serviceIf = (struct IDeviceNode *)devService; - if ((serviceIf != NULL) && (serviceIf->LaunchNode != NULL)) { - serviceIf->LaunchNode(devService, &device->super); + if (devService != NULL && devService->super.LaunchNode != NULL) { + devService->super.LaunchNode(devService); } break; } diff --git a/uhdf2/manager/include/devmgr_service_stub.h b/uhdf2/manager/include/devmgr_service_stub.h index 425b6f1..cde0960 100755 --- a/uhdf2/manager/include/devmgr_service_stub.h +++ b/uhdf2/manager/include/devmgr_service_stub.h @@ -31,6 +31,7 @@ struct DevmgrServiceStub { enum { DEVMGR_SERVICE_ATTACH_DEVICE_HOST = 1, DEVMGR_SERVICE_ATTACH_DEVICE, + DEVMGR_SERVICE_DETACH_DEVICE, DEVMGR_SERVICE_REGIST_PNP_DEVICE, DEVMGR_SERVICE_UNREGIST_PNP_DEVICE, DEVMGR_SERVICE_QUERY_DEVICE, diff --git a/uhdf2/manager/src/devhost_service_proxy.c b/uhdf2/manager/src/devhost_service_proxy.c index 63cc772..7986b99 100755 --- a/uhdf2/manager/src/devhost_service_proxy.c +++ b/uhdf2/manager/src/devhost_service_proxy.c @@ -31,22 +31,15 @@ static int32_t DevHostServiceProxyOpsDevice( int status = HDF_FAILURE; const struct HdfDeviceInfoFull *fullAttribute = HdfDeviceInfoFullReinterpretCast(attribute); struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSBufTypedObtain(SBUF_IPC); - struct HdfRemoteDispatcher *dipatcher = NULL; - struct HdfRemoteService *remoteService = NULL; struct DevHostServiceProxy *hostClnt = (struct DevHostServiceProxy *)inst; - if ((hostClnt->remote == NULL) || (data == NULL) || (reply == NULL)) { + if (hostClnt->remote == NULL || data == NULL) { HDF_LOGE("Adding device failed, hostClnt->remote or data or reply is null"); goto finished; } - remoteService = hostClnt->remote; - dipatcher = remoteService->dispatcher; + DeviceAttributeFullWrite(fullAttribute, data); - status = dipatcher->Dispatch(remoteService, opsCode, data, reply); + status = hostClnt->remote->dispatcher->Dispatch(hostClnt->remote, DEVHOST_SERVICE_ADD_DEVICE, data, NULL); finished: - if (reply != NULL) { - HdfSBufRecycle(reply); - } if (data != NULL) { HdfSBufRecycle(data); } @@ -60,9 +53,24 @@ static int32_t DevHostServiceProxyAddDevice( } static int32_t DevHostServiceProxyDelDevice( - struct IDevHostService *inst, const struct HdfDeviceInfo *attribute) + struct IDevHostService *inst, devid_t devid) { - return DevHostServiceProxyOpsDevice(inst, attribute, DEVHOST_SERVICE_DEL_DEVICE); + int status = HDF_FAILURE; + struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC); + struct DevHostServiceProxy *hostClnt = (struct DevHostServiceProxy *)inst; + if (hostClnt->remote == NULL || data == NULL) { + HDF_LOGE("Del device failed, hostClnt->remote or data is null"); + goto finished; + } + + HdfSbufWriteUint32(data, devid); + status = hostClnt->remote->dispatcher->Dispatch(hostClnt->remote, DEVHOST_SERVICE_DEL_DEVICE, data, NULL); + +finished: + if (data != NULL) { + HdfSBufRecycle(data); + } + return status; } void DevHostServiceProxyOnRemoteDied(struct HdfDeathRecipient *recipient, struct HdfRemoteService *service) diff --git a/uhdf2/manager/src/devmgr_pnp_service.c b/uhdf2/manager/src/devmgr_pnp_service.c old mode 100755 new mode 100644 index 9dd0cd4..0134215 --- a/uhdf2/manager/src/devmgr_pnp_service.c +++ b/uhdf2/manager/src/devmgr_pnp_service.c @@ -29,7 +29,7 @@ static struct HdfSList *g_deviceInfos = NULL; static uint16_t g_hostId = 0xFFFF; static uint32_t g_deviceId = 0; -struct HdfSList *DevmgrServiceGetPnpDeviceInfo() +struct HdfSList *DevmgrServiceGetPnpDeviceInfo(void) { return g_deviceInfos; } @@ -275,7 +275,7 @@ int32_t DevmgrServiceUnRegPnpDevice( if ((strcmp(deviceInfo->moduleName, moduleName) == 0) && (strcmp(deviceInfo->svcName, serviceName) == 0)) { deviceInfo->status = HDF_SERVICE_UNUSABLE; - ret = devHostSvcIf->DelDevice(devHostSvcIf, deviceInfo); + ret = devHostSvcIf->DelDevice(devHostSvcIf, deviceInfo->deviceId); DevmgrServiceDelPnpDevice(moduleName, serviceName); } } diff --git a/uhdf2/manager/src/devmgr_service_stub.c b/uhdf2/manager/src/devmgr_service_stub.c old mode 100755 new mode 100644 index 9e0b09d..2577d88 --- a/uhdf2/manager/src/devmgr_service_stub.c +++ b/uhdf2/manager/src/devmgr_service_stub.c @@ -33,9 +33,8 @@ static int32_t DevmgrServiceStubDispatchAttachDevice( struct IDevmgrService *devmgrSvc, struct HdfSBuf *data) { - uint32_t hostId; uint32_t deviceId; - if (!HdfSbufReadUint32(data, &hostId) || !HdfSbufReadUint32(data, &deviceId)) { + if (!HdfSbufReadUint32(data, &deviceId)) { HDF_LOGE("%{public}s:failed to get host id and device id", __func__); return HDF_ERR_INVALID_PARAM; } @@ -44,12 +43,22 @@ static int32_t DevmgrServiceStubDispatchAttachDevice( if (tokenClnt == NULL) { return HDF_FAILURE; } - struct HdfDeviceInfo deviceInfo; - deviceInfo.deviceId = deviceId; - deviceInfo.hostId = hostId; - return devmgrSvc->AttachDevice(devmgrSvc, &deviceInfo, &tokenClnt->super); + tokenClnt->super.devid = deviceId; + return devmgrSvc->AttachDevice(devmgrSvc, &tokenClnt->super); } +static int32_t DevmgrServiceStubDispatchDetachDevice(struct IDevmgrService *devmgrSvc, struct HdfSBuf *data) +{ + uint32_t deviceId; + if (!HdfSbufReadUint32(data, &deviceId)) { + HDF_LOGE("%{public}s:failed to get host id and device id", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return devmgrSvc->DetachDevice(devmgrSvc, deviceId); +} + + static int32_t DevmgrServiceStubDispatchPnpDevice( struct IDevmgrService *devmgrSvc, struct HdfSBuf *data, bool isReg) { @@ -98,6 +107,10 @@ int32_t DevmgrServiceStubDispatch( ret = DevmgrServiceStubDispatchAttachDevice(super, data); break; } + case DEVMGR_SERVICE_DETACH_DEVICE: { + ret = DevmgrServiceStubDispatchDetachDevice(super, data); + break; + } case DEVMGR_SERVICE_REGIST_PNP_DEVICE: { ret = DevmgrServiceStubDispatchPnpDevice(super, data, true); break; @@ -183,7 +196,7 @@ static void DevmgrServiceStubConstruct(struct DevmgrServiceStub *inst) OsalMutexInit(&inst->devmgrStubMutx); } -struct HdfObject *DevmgrServiceStubCreate() +struct HdfObject *DevmgrServiceStubCreate(void) { static struct DevmgrServiceStub *instance = NULL; if (instance == NULL) { diff --git a/uhdf2/manager/src/hdf_get_attribute.c b/uhdf2/manager/src/hdf_get_attribute.c index d29bc64..9ae8abe 100644 --- a/uhdf2/manager/src/hdf_get_attribute.c +++ b/uhdf2/manager/src/hdf_get_attribute.c @@ -234,6 +234,7 @@ struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *h while (device != NULL) { const struct DeviceResourceNode *deviceNode = device->child; while (deviceNode != NULL) { + uint8_t deviceNnodeIdx = 0; struct HdfDeviceInfoFull *deviceNodeInfo = HdfDeviceInfoFullNewInstance(); if (deviceNodeInfo == NULL) { HdfSListFlush(deviceList, HdfDeviceInfoDelete); @@ -255,10 +256,12 @@ struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *h deviceNode = deviceNode->sibling; continue; } - deviceNodeInfo->super.deviceId = deviceIdx++; + deviceNodeInfo->super.deviceId = MK_DEVID(hostId, deviceIdx, deviceNnodeIdx); + deviceNnodeIdx++; deviceNode = deviceNode->sibling; } device = device->sibling; + deviceIdx++; } if (HdfSListCount(deviceList) == 0) { OsalMemFree(deviceList); diff --git a/uhdf2/shared/src/hdf_device_info_full.c b/uhdf2/shared/src/hdf_device_info_full.c old mode 100755 new mode 100644 index 33bd376..60413f1 --- a/uhdf2/shared/src/hdf_device_info_full.c +++ b/uhdf2/shared/src/hdf_device_info_full.c @@ -28,7 +28,7 @@ void HdfDeviceInfoFullConstruct(struct HdfDeviceInfoFull *attribute) attribute->deviceHandle = NULL; } -struct HdfDeviceInfoFull* HdfDeviceInfoFullNewInstance() +struct HdfDeviceInfoFull* HdfDeviceInfoFullNewInstance(void) { struct HdfDeviceInfoFull *fullAttribute = (struct HdfDeviceInfoFull *)OsalMemCalloc(sizeof(struct HdfDeviceInfoFull)); @@ -53,9 +53,6 @@ void HdfDeviceInfoFullFreeInstance(struct HdfDeviceInfoFull *attribute) if (attribute->super.private != NULL) { OsalMemFree((void *)attribute->super.private); } - if (attribute->deviceHandle != NULL) { - dlclose(attribute->deviceHandle); - } OsalMemFree(attribute); } } -- Gitee