mirror of
https://github.com/openharmony/drivers_framework.git
synced 2026-07-21 03:35:25 -04:00
support dynamic register device
Signed-off-by: yuanbo <yuanbo@huawei.com>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "hcs_tree_if.h"
|
||||
|
||||
const struct DeviceResourceNode *HdfGetHcsRootNode(void)
|
||||
{
|
||||
return HcsGetRootNode();
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "devmgr_service_start.h"
|
||||
#include "devhost_service_clnt.h"
|
||||
#include "devmgr_service.h"
|
||||
#include "devsvc_manager.h"
|
||||
#include "devsvc_manager_clnt.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_node.h"
|
||||
@@ -20,30 +21,14 @@
|
||||
|
||||
static int g_isQuickLoad = DEV_MGR_SLOW_LOAD;
|
||||
|
||||
static void GetDeviceServiceNameByClass(DeviceClass deviceClass, struct HdfSBuf *reply)
|
||||
static void GetDeviceServiceNameByClass(struct HdfSBuf *reply, DeviceClass deviceClass)
|
||||
{
|
||||
struct HdfSListIterator itDeviceInfo;
|
||||
struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
|
||||
if (devMgrSvc == NULL || reply == NULL) {
|
||||
if (reply == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
HdfSbufFlush(reply);
|
||||
DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
|
||||
HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
|
||||
while (HdfSListIteratorHasNext(&itDeviceInfo)) {
|
||||
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
|
||||
if (deviceInfo->policy == SERVICE_POLICY_CAPACITY) {
|
||||
struct HdfDeviceObject *deviceObject = DevSvcManagerClntGetDeviceObject(deviceInfo->svcName);
|
||||
if (deviceObject == NULL || (deviceObject->deviceClass != deviceClass)) {
|
||||
continue;
|
||||
}
|
||||
HdfSbufWriteString(reply, deviceInfo->svcName);
|
||||
}
|
||||
}
|
||||
}
|
||||
DevSvcManagerListService(reply, deviceClass);
|
||||
HdfSbufWriteString(reply, NULL);
|
||||
}
|
||||
|
||||
@@ -84,7 +69,7 @@ int DeviceManagerDispatch(struct HdfObject *stub, int code, struct HdfSBuf *data
|
||||
HDF_LOGE("%s: failed to get deviceClass", __func__);
|
||||
break;
|
||||
}
|
||||
GetDeviceServiceNameByClass(deviceClass, reply);
|
||||
GetDeviceServiceNameByClass(reply, deviceClass);
|
||||
ret = HDF_SUCCESS;
|
||||
break;
|
||||
default:
|
||||
|
||||
+64
-202
@@ -32,37 +32,7 @@
|
||||
#define ATTR_DEV_MATCHATTR "deviceMatchAttr"
|
||||
#define MANAGER_NODE_MATCH_ATTR "hdf_manager"
|
||||
|
||||
static struct DeviceResourceNode *g_hcsTreeRoot = NULL;
|
||||
|
||||
void HdfGetBuildInConfigData(const unsigned char **data, unsigned int *size);
|
||||
|
||||
static bool CreateHcsToTree(void)
|
||||
{
|
||||
uint32_t length;
|
||||
const unsigned char *hcsBlob = NULL;
|
||||
HdfGetBuildInConfigData(&hcsBlob, &length);
|
||||
if (!HcsCheckBlobFormat((const char *)hcsBlob, length)) {
|
||||
return false;
|
||||
}
|
||||
if (!HcsDecompile((const char *)hcsBlob, HBC_HEADER_LENGTH, &g_hcsTreeRoot)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const struct DeviceResourceNode *HcsGetRootNode(void)
|
||||
{
|
||||
if ((g_hcsTreeRoot == NULL) && !CreateHcsToTree()) {
|
||||
HDF_LOGE("%s: failed", __func__);
|
||||
return NULL;
|
||||
}
|
||||
return g_hcsTreeRoot;
|
||||
}
|
||||
|
||||
const struct DeviceResourceNode *HdfGetRootNode(void)
|
||||
{
|
||||
return HcsGetRootNode();
|
||||
}
|
||||
#define DEFATLT_DEV_PRIORITY 100
|
||||
|
||||
static bool HdfHostListCompare(struct HdfSListNode *listEntryFirst, struct HdfSListNode *listEntrySecond)
|
||||
{
|
||||
@@ -107,14 +77,14 @@ bool HdfAttributeManagerGetHostList(struct HdfSList *hostList)
|
||||
return false;
|
||||
}
|
||||
|
||||
hdfManagerNode = GetHdfManagerNode(HcsGetRootNode());
|
||||
hdfManagerNode = GetHdfManagerNode(HdfGetHcsRootNode());
|
||||
if (hdfManagerNode == NULL) {
|
||||
HDF_LOGE("%s: get hdf manager node is null", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
hostNode = hdfManagerNode->child;
|
||||
while (hostNode != NULL) {
|
||||
for (; hostNode != NULL; hostNode = hostNode->sibling) {
|
||||
struct HdfHostInfo *hostInfo = HdfHostInfoNewInstance();
|
||||
if (hostInfo == NULL) {
|
||||
HdfSListFlush(hostList, HdfHostInfoDelete);
|
||||
@@ -123,17 +93,14 @@ bool HdfAttributeManagerGetHostList(struct HdfSList *hostList)
|
||||
}
|
||||
if (!GetHostInfo(hostNode, hostInfo)) {
|
||||
HdfHostInfoFreeInstance(hostInfo);
|
||||
hostNode = hostNode->sibling;
|
||||
continue;
|
||||
}
|
||||
hostInfo->hostId = hostId;
|
||||
if (!HdfSListAddOrder(hostList, &hostInfo->node, HdfHostListCompare)) {
|
||||
HdfHostInfoFreeInstance(hostInfo);
|
||||
hostNode = hostNode->sibling;
|
||||
continue;
|
||||
}
|
||||
hostId++;
|
||||
hostNode = hostNode->sibling;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -158,7 +125,7 @@ static const struct DeviceResourceNode *GetHostNode(const char *inHostName)
|
||||
if (inHostName == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
hdfManagerNode = GetHdfManagerNode(HcsGetRootNode());
|
||||
hdfManagerNode = GetHdfManagerNode(HdfGetHcsRootNode());
|
||||
if (hdfManagerNode == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -178,7 +145,7 @@ static const struct DeviceResourceNode *GetHostNode(const char *inHostName)
|
||||
|
||||
static bool CheckDeviceInfo(const struct HdfDeviceInfo *deviceNodeInfo)
|
||||
{
|
||||
if (deviceNodeInfo->policy > SERVICE_POLICY_PRIVATE) {
|
||||
if (deviceNodeInfo->policy >= SERVICE_POLICY_INVALID) {
|
||||
HDF_LOGE("%s: policy %u is invalid", __func__, deviceNodeInfo->policy);
|
||||
return false;
|
||||
}
|
||||
@@ -188,7 +155,7 @@ static bool CheckDeviceInfo(const struct HdfDeviceInfo *deviceNodeInfo)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (deviceNodeInfo->preload > DEVICE_PRELOAD_DISABLE) {
|
||||
if (deviceNodeInfo->preload >= DEVICE_PRELOAD_INVALID) {
|
||||
HDF_LOGE("%s: preload %u is invalid", __func__, deviceNodeInfo->preload);
|
||||
return false;
|
||||
}
|
||||
@@ -198,187 +165,82 @@ static bool CheckDeviceInfo(const struct HdfDeviceInfo *deviceNodeInfo)
|
||||
|
||||
static bool GetDeviceNodeInfo(const struct DeviceResourceNode *deviceNode, struct HdfDeviceInfo *deviceNodeInfo)
|
||||
{
|
||||
uint16_t readNum = 0;
|
||||
const char *readString = NULL;
|
||||
if (HcsGetUint16(deviceNode, ATTR_DEV_POLICY, &readNum, 0) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: failed to get policy", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->policy = readNum;
|
||||
HcsGetUint16(deviceNode, ATTR_DEV_POLICY, &deviceNodeInfo->policy, 0);
|
||||
HcsGetUint16(deviceNode, ATTR_DEV_PRIORITY, &deviceNodeInfo->priority, DEFATLT_DEV_PRIORITY);
|
||||
HcsGetUint16(deviceNode, ATTR_DEV_PRELOAD, &deviceNodeInfo->preload, 0);
|
||||
HcsGetUint16(deviceNode, ATTR_DEV_PERMISSION, &deviceNodeInfo->permission, 0);
|
||||
HcsGetString(deviceNode, ATTR_DEV_MATCHATTR, &deviceNodeInfo->deviceMatchAttr, NULL);
|
||||
|
||||
if (HcsGetUint16(deviceNode, ATTR_DEV_PRIORITY, &readNum, 0) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: failed to get priority", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->priority = readNum;
|
||||
|
||||
if (HcsGetUint16(deviceNode, ATTR_DEV_PRELOAD, &readNum, 0) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: failed to get preload", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->preload = readNum;
|
||||
|
||||
if (HcsGetUint16(deviceNode, ATTR_DEV_PERMISSION, &readNum, 0) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: failed to get permission", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->permission = readNum;
|
||||
|
||||
if (HcsGetString(deviceNode, ATTR_DEV_MODULENAME, &readString, NULL) != HDF_SUCCESS) {
|
||||
if (HcsGetString(deviceNode, ATTR_DEV_MODULENAME, &deviceNodeInfo->moduleName, NULL) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: failed to get module name", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->moduleName = readString;
|
||||
|
||||
if (HcsGetString(deviceNode, ATTR_DEV_SVCNAME, &readString, NULL) != HDF_SUCCESS) {
|
||||
if (HcsGetString(deviceNode, ATTR_DEV_SVCNAME, &deviceNodeInfo->svcName, NULL) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: failed to get service name", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->svcName = readString;
|
||||
|
||||
if (HcsGetString(deviceNode, ATTR_DEV_MATCHATTR, &readString, NULL) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: failed to get matchattr name", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->deviceMatchAttr = readString;
|
||||
return CheckDeviceInfo(deviceNodeInfo);
|
||||
}
|
||||
|
||||
struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *hostName)
|
||||
static bool GetDevcieNodeList(const struct DeviceResourceNode *device,
|
||||
struct DevHostServiceClnt *hostClnt, uint16_t deviceIdx)
|
||||
{
|
||||
uint8_t deviceNnodeIdx = 0;
|
||||
uint16_t hostId = hostClnt->hostId;
|
||||
struct HdfDeviceInfo *deviceNodeInfo = NULL;
|
||||
const struct DeviceResourceNode *devNodeResource = device->child;
|
||||
|
||||
for (; devNodeResource != NULL; devNodeResource = devNodeResource->sibling) {
|
||||
deviceNodeInfo = HdfDeviceInfoNewInstance();
|
||||
if (deviceNodeInfo == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (!GetDeviceNodeInfo(devNodeResource, deviceNodeInfo)) {
|
||||
HdfDeviceInfoFreeInstance(deviceNodeInfo);
|
||||
HDF_LOGE("%s: failed to parse device node info, ignore", __func__);
|
||||
continue;
|
||||
}
|
||||
|
||||
deviceNodeInfo->hostId = hostId;
|
||||
deviceNodeInfo->deviceId = MK_DEVID(hostId, deviceIdx, deviceNnodeIdx);
|
||||
if (deviceNodeInfo->preload != DEVICE_PRELOAD_DISABLE) {
|
||||
if (!HdfSListAddOrder(&hostClnt->unloadDevInfos, &deviceNodeInfo->node, HdfDeviceListCompare)) {
|
||||
HDF_LOGE("%s: failed to add device info to list %s", __func__, deviceNodeInfo->svcName);
|
||||
HdfDeviceInfoFreeInstance(deviceNodeInfo);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
HdfSListAdd(&hostClnt->dynamicDevInfos, &deviceNodeInfo->node);
|
||||
}
|
||||
|
||||
deviceNnodeIdx++;
|
||||
}
|
||||
return deviceNnodeIdx > 0;
|
||||
}
|
||||
|
||||
int HdfAttributeManagerGetDeviceList(struct DevHostServiceClnt *hostClnt)
|
||||
{
|
||||
uint16_t deviceIdx = 0;
|
||||
uint8_t deviceNnodeIdx = 0;
|
||||
struct HdfDeviceInfo *deviceNodeInfo = NULL;
|
||||
const struct DeviceResourceNode *hostNode = GetHostNode(hostName);
|
||||
struct HdfSList *deviceList = NULL;
|
||||
const struct DeviceResourceNode *hostNode = NULL;
|
||||
const struct DeviceResourceNode *device = NULL;
|
||||
int ret = HDF_DEV_ERR_NO_DEVICE;
|
||||
|
||||
if (hostClnt == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
hostNode = GetHostNode(hostClnt->hostName);
|
||||
if (hostNode == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
deviceList = (struct HdfSList *)OsalMemCalloc(sizeof(struct HdfSList));
|
||||
if (deviceList == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
device = hostNode->child;
|
||||
while (device != NULL) {
|
||||
const struct DeviceResourceNode *deviceNode = device->child;
|
||||
while (deviceNode != NULL) {
|
||||
deviceNnodeIdx = 0;
|
||||
deviceNodeInfo = HdfDeviceInfoNewInstance();
|
||||
if (deviceNodeInfo == NULL) {
|
||||
HdfSListFlush(deviceList, HdfDeviceInfoDelete);
|
||||
OsalMemFree(deviceList);
|
||||
return NULL;
|
||||
}
|
||||
deviceNodeInfo->hostId = hostId;
|
||||
if (!GetDeviceNodeInfo(deviceNode, deviceNodeInfo)) {
|
||||
HdfDeviceInfoFreeInstance(deviceNodeInfo);
|
||||
HDF_LOGE("%s: failed to get device", __func__);
|
||||
deviceNodeInfo = NULL;
|
||||
deviceNode = deviceNode->sibling;
|
||||
continue;
|
||||
}
|
||||
if (!HdfSListAddOrder(deviceList, &deviceNodeInfo->node, HdfDeviceListCompare)) {
|
||||
HDF_LOGE("%s: failed to add device %s", __func__, deviceNodeInfo->svcName);
|
||||
HdfDeviceInfoFreeInstance(deviceNodeInfo);
|
||||
deviceNodeInfo = NULL;
|
||||
deviceNode = deviceNode->sibling;
|
||||
continue;
|
||||
}
|
||||
deviceNodeInfo->deviceId = MK_DEVID(hostId, deviceIdx, deviceNnodeIdx);
|
||||
deviceNnodeIdx++;
|
||||
deviceNode = deviceNode->sibling;
|
||||
}
|
||||
device = device->sibling;
|
||||
deviceIdx++;
|
||||
}
|
||||
if (HdfSListCount(deviceList) == 0) {
|
||||
OsalMemFree(deviceList);
|
||||
return NULL;
|
||||
}
|
||||
return deviceList;
|
||||
}
|
||||
|
||||
bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const void *privateData)
|
||||
{
|
||||
struct HdfSListIterator itDeviceInfo;
|
||||
struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
|
||||
struct HdfDeviceInfo *deviceNodeInfo = NULL;
|
||||
char *svcName = NULL;
|
||||
if (devMgrSvc == NULL || moduleName == NULL || serviceName == NULL) {
|
||||
return false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
deviceNodeInfo = HdfDeviceInfoNewInstance();
|
||||
if (deviceNodeInfo == NULL) {
|
||||
return false;
|
||||
}
|
||||
DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
|
||||
HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
|
||||
while (HdfSListIteratorHasNext(&itDeviceInfo)) {
|
||||
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
|
||||
if (deviceInfo->moduleName == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (strcmp(deviceInfo->moduleName, moduleName) == 0) {
|
||||
deviceInfo->isDynamic = true;
|
||||
deviceNodeInfo->hostId = deviceInfo->hostId;
|
||||
deviceNodeInfo->deviceId = hostClnt->devCount;
|
||||
deviceNodeInfo->policy = deviceInfo->policy;
|
||||
deviceNodeInfo->priority = deviceInfo->priority;
|
||||
deviceNodeInfo->preload = DEVICE_PRELOAD_DISABLE;
|
||||
deviceNodeInfo->permission = deviceInfo->permission;
|
||||
deviceNodeInfo->deviceMatchAttr = deviceInfo->deviceMatchAttr;
|
||||
deviceNodeInfo->moduleName = deviceInfo->moduleName;
|
||||
svcName = OsalMemCalloc(strlen(serviceName) + 1);
|
||||
if (svcName == NULL) {
|
||||
break;
|
||||
}
|
||||
if (strcpy_s(svcName, strlen(serviceName) + 1, serviceName) != EOK) {
|
||||
HDF_LOGE("%s: failed to copy string", __func__);
|
||||
OsalMemFree(svcName);
|
||||
break;
|
||||
}
|
||||
deviceNodeInfo->svcName = svcName;
|
||||
#ifdef LOSCFG_DRIVERS_HDF_USB_PNP_NOTIFY
|
||||
if (!UsbPnpManagerAddPrivateData(deviceNodeInfo, privateData)) {
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
HdfSListAdd(hostClnt->deviceInfos, &deviceNodeInfo->node);
|
||||
hostClnt->devCount++;
|
||||
return true;
|
||||
}
|
||||
for(device = hostNode->child; device != NULL; device = device->sibling, deviceIdx++) {
|
||||
if (!GetDevcieNodeList(device, hostClnt, deviceIdx)) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
HdfDeviceInfoFreeInstance(deviceNodeInfo);
|
||||
return false;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
void HdfDeviceListDel(const char *moduleName, const char *serviceName)
|
||||
{
|
||||
struct HdfSListIterator itDeviceInfo;
|
||||
struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
|
||||
if (devMgrSvc == NULL || moduleName == NULL || serviceName == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
|
||||
HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
|
||||
while (HdfSListIteratorHasNext(&itDeviceInfo)) {
|
||||
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
|
||||
if ((strcmp(deviceInfo->moduleName, moduleName) == 0) &&
|
||||
(strcmp(deviceInfo->svcName, serviceName) == 0)) {
|
||||
HdfSListRemove(hostClnt->deviceInfos, &deviceInfo->node);
|
||||
HdfDeviceInfoFreeInstance(deviceInfo);
|
||||
hostClnt->devCount--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,5 @@ int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *ser
|
||||
void DevSvcManagerClntRemoveService(const char *svcName);
|
||||
int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback);
|
||||
int DevSvcManagerClntUnsubscribeService(const char *svcName);
|
||||
struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName, const void *privateData);
|
||||
void HdfUnregisterDevice(const char *moduleName, const char *serviceName);
|
||||
|
||||
#endif /* DEVSVC_MANAGER_CLNT_H */
|
||||
|
||||
@@ -52,6 +52,7 @@ struct HdfDevice {
|
||||
uint16_t deviceId;
|
||||
uint16_t hostId;
|
||||
};
|
||||
int HdfDeviceDetach(struct IHdfDevice *devInst, struct HdfDeviceNode *devNode);
|
||||
void HdfDeviceConstruct(struct HdfDevice *device);
|
||||
void HdfDeviceDestruct(struct HdfDevice *device);
|
||||
struct HdfObject *HdfDeviceCreate(void);
|
||||
|
||||
@@ -24,7 +24,7 @@ struct IDeviceNode {
|
||||
int (*PublishService)(struct HdfDeviceNode *devNode);
|
||||
int (*RemoveService)(struct HdfDeviceNode *devNode);
|
||||
int (*LaunchNode)(struct HdfDeviceNode *devNode);
|
||||
int (*ReleaseNode)(struct HdfDeviceNode *devNode);
|
||||
void (*UnlaunchNode)(struct HdfDeviceNode *devNode);
|
||||
};
|
||||
|
||||
struct HdfDeviceNode {
|
||||
@@ -35,8 +35,9 @@ struct HdfDeviceNode {
|
||||
struct HdfDeviceObject deviceObject;
|
||||
struct IHdfDeviceToken *token;
|
||||
struct HdfDriver *driver;
|
||||
const struct HdfDevice *device;
|
||||
struct HdfDevice *device;
|
||||
char *servName;
|
||||
char *driverName;
|
||||
devid_t devId;
|
||||
uint16_t policy;
|
||||
uint16_t permission;
|
||||
@@ -61,5 +62,6 @@ void HdfDeviceNodeFreeInstance(struct HdfDeviceNode *devNode);
|
||||
void HdfDeviceNodeDelete(struct HdfDeviceNode *devNode);
|
||||
int HdfDeviceNodePublishPublicService(struct HdfDeviceNode *devNode);
|
||||
int HdfDeviceNodeRemoveService(struct HdfDeviceNode *devNode);
|
||||
int DeviveDriverBind(struct HdfDeviceNode *devNode);
|
||||
|
||||
#endif /* HDF_DEVICE_NODE_H */
|
||||
|
||||
@@ -12,5 +12,12 @@
|
||||
#include "hdf_device_desc.h"
|
||||
|
||||
void HdfDeviceObjectConstruct(struct HdfDeviceObject *deviceObject);
|
||||
struct HdfDeviceObject *HdfDeviceObjectAlloc(struct HdfDeviceObject *parent, const char *driverName);
|
||||
void HdfDeviceObjectRelease(struct HdfDeviceObject *deviceObject);
|
||||
int HdfDeviceObjectRegister(struct HdfDeviceObject *deviceObject);
|
||||
int HdfDeviceObjectUnRegister(struct HdfDeviceObject *deviceObject);
|
||||
int HdfDeviceObjectPublishService(struct HdfDeviceObject *deviceObject,
|
||||
const char *servName, uint8_t policy, uint32_t perm);
|
||||
int HdfDeviceObjectRemoveService(struct HdfDeviceObject *deviceObject);
|
||||
|
||||
#endif /* HDF_DEVICE_OBJECT_H */
|
||||
|
||||
@@ -21,15 +21,15 @@
|
||||
|
||||
static struct HdfDevice *DevHostServiceFindDevice(struct DevHostService *hostService, uint16_t deviceId)
|
||||
{
|
||||
struct HdfDevice *deviceNode = NULL;
|
||||
struct HdfDevice *device = NULL;
|
||||
if (hostService == NULL) {
|
||||
HDF_LOGE("failed to find driver, hostService is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DLIST_FOR_EACH_ENTRY(deviceNode, &hostService->devices, struct HdfDevice, node) {
|
||||
if (deviceNode->deviceId == deviceId) {
|
||||
return deviceNode;
|
||||
DLIST_FOR_EACH_ENTRY(device, &hostService->devices, struct HdfDevice, node) {
|
||||
if (DEVICEID(device->deviceId) == deviceId) {
|
||||
return device;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
@@ -53,7 +53,7 @@ static struct HdfDevice *DevHostServiceQueryOrAddDevice(struct DevHostService *i
|
||||
return NULL;
|
||||
}
|
||||
device->hostId = inst->hostId;
|
||||
device->deviceId = deviceId;
|
||||
device->deviceId = MK_DEVID(inst->hostId, deviceId, 0);
|
||||
DListInsertHead(&device->node, &inst->devices);
|
||||
}
|
||||
return device;
|
||||
@@ -88,8 +88,7 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice
|
||||
devNode = HdfDeviceNodeNewInstance(deviceInfo, driver);
|
||||
if (devNode == NULL) {
|
||||
driverLoader->ReclaimDriver(driver);
|
||||
ret = HDF_DEV_ERR_NO_MEMORY;
|
||||
goto error;
|
||||
return HDF_DEV_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
devNode->hostService = hostService;
|
||||
@@ -103,8 +102,10 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice
|
||||
return HDF_SUCCESS;
|
||||
|
||||
error:
|
||||
driverLoader->ReclaimDriver(driver);
|
||||
DevHostServiceFreeDevice(hostService, device);
|
||||
if (DListIsEmpty(&device->devNodes)) {
|
||||
DevHostServiceFreeDevice(hostService, device);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -113,13 +114,6 @@ int DevHostServiceDelDevice(struct IDevHostService *inst, devid_t devId)
|
||||
struct HdfDevice *device = NULL;
|
||||
struct DevHostService *hostService = (struct DevHostService *)inst;
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
struct HdfDriver *driver = NULL;
|
||||
struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
|
||||
|
||||
if (driverLoader == NULL || driverLoader->ReclaimDriver == NULL) {
|
||||
HDF_LOGE("failed to del device, input param is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
device = DevHostServiceFindDevice(hostService, DEVICEID(devId));
|
||||
if (device == NULL) {
|
||||
@@ -129,20 +123,20 @@ int DevHostServiceDelDevice(struct IDevHostService *inst, devid_t devId)
|
||||
|
||||
devNode = device->super.GetDeviceNode(&device->super, devId);
|
||||
if (devNode == NULL) {
|
||||
HDF_LOGI("failed to del device %u, not exist", devId);
|
||||
return HDF_DEV_ERR_NO_DEVICE;
|
||||
}
|
||||
driver = devNode->driver;
|
||||
|
||||
// device detach will release device node, do not use devNode after this
|
||||
if (device->super.Detach != NULL) {
|
||||
if (device->super.Detach(&device->super, devNode) != HDF_SUCCESS) {
|
||||
HDF_LOGE("failed to del device %x", devId);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (device->super.Detach == NULL) {
|
||||
HDF_LOGE("failed to del device %u, invalid device", devId);
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
// remove driver instance or close driver library
|
||||
driverLoader->ReclaimDriver(driver);
|
||||
if (device->super.Detach(&device->super, devNode) != HDF_SUCCESS) {
|
||||
HDF_LOGE("failed to detach device %u", devId);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfDeviceNodeFreeInstance(devNode);
|
||||
|
||||
if (DListIsEmpty(&device->devNodes)) {
|
||||
DevHostServiceFreeDevice(hostService, device);
|
||||
|
||||
@@ -47,6 +47,7 @@ int DevmgrServiceClntAttachDevice(struct IHdfDeviceToken *deviceToken)
|
||||
}
|
||||
return devMgrSvcIf->AttachDevice(devMgrSvcIf, deviceToken);
|
||||
}
|
||||
|
||||
int DevmgrServiceClntDetachDevice(devid_t devid)
|
||||
{
|
||||
struct IDevmgrService *devMgrSvcIf = NULL;
|
||||
|
||||
@@ -67,30 +67,6 @@ struct HdfDeviceObject *DevSvcManagerClntGetDeviceObject(const char *svcName)
|
||||
return serviceManager->GetObject(serviceManager, svcName);
|
||||
}
|
||||
|
||||
struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName, const void *privateData)
|
||||
{
|
||||
int ret;
|
||||
if (!HdfDeviceListAdd(moduleName, serviceName, privateData)) {
|
||||
HDF_LOGE("%s device info add failed!", __func__);
|
||||
return NULL;
|
||||
}
|
||||
ret = DevmgrServiceLoadDevice(serviceName);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s load device %s failed!", __func__, serviceName);
|
||||
HdfDeviceListDel(moduleName, serviceName);
|
||||
return NULL;
|
||||
}
|
||||
return DevSvcManagerClntGetDeviceObject(serviceName);
|
||||
}
|
||||
|
||||
void HdfUnregisterDevice(const char *moduleName, const char *serviceName)
|
||||
{
|
||||
if (DevmgrServiceUnLoadDevice(serviceName) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s:failed to unload device %s !", __func__, serviceName);
|
||||
}
|
||||
HdfDeviceListDel(moduleName, serviceName);
|
||||
}
|
||||
|
||||
int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
|
||||
@@ -28,6 +28,13 @@ static int HdfDeviceAttach(struct IHdfDevice *devInst, struct HdfDeviceNode *dev
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
// for dynamic added device node, assign device id here
|
||||
if (devNode->devId == 0) {
|
||||
devNode->devId = MK_DEVID(HOSTID(device->deviceId), DEVICEID(device->deviceId),
|
||||
DlistGetCount(&device->devNodes));
|
||||
devNode->token->devid = devNode->devId;
|
||||
}
|
||||
|
||||
ret = nodeIf->LaunchNode(devNode);
|
||||
if (ret == HDF_SUCCESS) {
|
||||
DListInsertTail(&devNode->entry, &device->devNodes);
|
||||
@@ -36,7 +43,7 @@ static int HdfDeviceAttach(struct IHdfDevice *devInst, struct HdfDeviceNode *dev
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int HdfDeviceDetach(struct IHdfDevice *devInst, struct HdfDeviceNode *devNode)
|
||||
int HdfDeviceDetach(struct IHdfDevice *devInst, struct HdfDeviceNode *devNode)
|
||||
{
|
||||
struct HdfDevice *device = NULL;
|
||||
if (devInst == NULL || devNode == NULL) {
|
||||
@@ -48,8 +55,13 @@ static int HdfDeviceDetach(struct IHdfDevice *devInst, struct HdfDeviceNode *dev
|
||||
HDF_LOGE("%s: device %x detach unknown devnode %x", __func__, device->deviceId, devNode->devId);
|
||||
return HDF_DEV_ERR_NO_DEVICE;
|
||||
}
|
||||
DListRemove(&devNode->entry);
|
||||
HdfDeviceNodeFreeInstance(devNode);
|
||||
|
||||
if (devNode->entry.next != NULL) {
|
||||
DListRemove(&devNode->entry);
|
||||
}
|
||||
if (devNode->super.UnlaunchNode != NULL) {
|
||||
devNode->super.UnlaunchNode(devNode);
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -100,8 +112,7 @@ void HdfDeviceDestruct(struct HdfDevice *device)
|
||||
|
||||
struct HdfObject *HdfDeviceCreate()
|
||||
{
|
||||
struct HdfDevice *device =
|
||||
(struct HdfDevice *)OsalMemCalloc(sizeof(struct HdfDevice));
|
||||
struct HdfDevice *device = (struct HdfDevice *)OsalMemCalloc(sizeof(struct HdfDevice));
|
||||
if (device != NULL) {
|
||||
HdfDeviceConstruct(device);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "hdf_cstring.h"
|
||||
#include "hdf_device_object.h"
|
||||
#include "hdf_device_token.h"
|
||||
#include "hdf_driver_loader.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
#include "hdf_observer_record.h"
|
||||
@@ -59,6 +60,31 @@ static int HdfDeviceNodePublishService(struct HdfDeviceNode *devNode)
|
||||
return status;
|
||||
}
|
||||
|
||||
int DeviveDriverBind(struct HdfDeviceNode *devNode)
|
||||
{
|
||||
int ret;
|
||||
const struct HdfDriverEntry *driverEntry = NULL;
|
||||
if (devNode == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
driverEntry = devNode->driver->entry;
|
||||
if (devNode->policy == SERVICE_POLICY_PUBLIC || devNode->policy == SERVICE_POLICY_CAPACITY) {
|
||||
if (driverEntry->Bind == NULL) {
|
||||
HDF_LOGE("driver %s bind method not implement", driverEntry->moduleName);
|
||||
devNode->devStatus = DEVNODE_NONE;
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
ret = driverEntry->Bind(&devNode->deviceObject);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("bind driver %s failed", driverEntry->moduleName);
|
||||
return HDF_DEV_ERR_DEV_INIT_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode)
|
||||
{
|
||||
const struct HdfDriverEntry *driverEntry = NULL;
|
||||
@@ -68,25 +94,17 @@ int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode)
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
HDF_LOGI("launch devnode %s", devNode->servName);
|
||||
HDF_LOGI("launch devnode %s", devNode->servName ? devNode->servName : "");
|
||||
driverEntry = devNode->driver->entry;
|
||||
if (driverEntry == NULL || driverEntry->Init == NULL) {
|
||||
HDF_LOGE("failed to launch service, deviceEntry invalid");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
devNode->devStatus = DEVNODE_LAUNCHED;
|
||||
if (devNode->policy == SERVICE_POLICY_PUBLIC || devNode->policy == SERVICE_POLICY_CAPACITY) {
|
||||
if (driverEntry->Bind == NULL) {
|
||||
HDF_LOGE("driver %s bind method is null, ignore device service publish", driverEntry->moduleName);
|
||||
devNode->devStatus = DEVNODE_NONE;
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
ret = driverEntry->Bind(&devNode->deviceObject);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("bind driver %s failed", driverEntry->moduleName);
|
||||
return HDF_DEV_ERR_DEV_INIT_FAIL;
|
||||
}
|
||||
|
||||
ret = DeviveDriverBind(devNode);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = driverEntry->Init(&devNode->deviceObject);
|
||||
@@ -133,9 +151,10 @@ int HdfDeviceNodePublishPublicService(struct HdfDeviceNode *devNode)
|
||||
{
|
||||
int ret;
|
||||
if (devNode == NULL || devNode->deviceObject.service == NULL) {
|
||||
HDF_LOGE("failed to publish public service: devNode is NULL");
|
||||
HDF_LOGE("failed to publish public service, devNode is NULL");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = DevSvcManagerClntAddService(devNode->servName, &devNode->deviceObject);
|
||||
if (ret == HDF_SUCCESS) {
|
||||
devNode->servStatus = true;
|
||||
@@ -154,22 +173,11 @@ int HdfDeviceNodeRemoveService(struct HdfDeviceNode *devNode)
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
void HdfDeviceNodeConstruct(struct HdfDeviceNode *devNode)
|
||||
{
|
||||
if (devNode != NULL) {
|
||||
struct IDeviceNode *nodeIf = &devNode->super;
|
||||
HdfDeviceObjectConstruct(&devNode->deviceObject);
|
||||
devNode->token = HdfDeviceTokenNewInstance();
|
||||
nodeIf->LaunchNode = HdfDeviceLaunchNode;
|
||||
nodeIf->PublishService = HdfDeviceNodePublishPublicService;
|
||||
nodeIf->RemoveService = HdfDeviceNodeRemoveService;
|
||||
}
|
||||
}
|
||||
|
||||
void HdfDeviceReleaseNode(struct HdfDeviceNode *devNode)
|
||||
static void HdfDeviceUnlaunchNode(struct HdfDeviceNode *devNode)
|
||||
{
|
||||
const struct HdfDriverEntry *driverEntry = NULL;
|
||||
if (devNode == NULL) {
|
||||
struct IDriverLoader *driverLoader = NULL;
|
||||
if (devNode == NULL || devNode->devStatus != DEVNODE_LAUNCHED) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -182,8 +190,31 @@ void HdfDeviceReleaseNode(struct HdfDeviceNode *devNode)
|
||||
}
|
||||
|
||||
if (devNode->servStatus) {
|
||||
HdfDeviceNodeRemoveService(devNode);
|
||||
DevmgrServiceClntDetachDevice(devNode->devId);
|
||||
devNode->super.RemoveService(devNode);
|
||||
}
|
||||
DevmgrServiceClntDetachDevice(devNode->devId);
|
||||
|
||||
// release driver object or close driver library
|
||||
driverLoader = HdfDriverLoaderGetInstance();
|
||||
if (driverLoader != NULL) {
|
||||
driverLoader->ReclaimDriver(devNode->driver);
|
||||
devNode->driver = NULL;
|
||||
} else {
|
||||
HDF_LOGE("failed to get driver loader");
|
||||
}
|
||||
devNode->devStatus = DEVNODE_INITED;
|
||||
}
|
||||
|
||||
void HdfDeviceNodeConstruct(struct HdfDeviceNode *devNode)
|
||||
{
|
||||
if (devNode != NULL) {
|
||||
struct IDeviceNode *nodeIf = &devNode->super;
|
||||
HdfDeviceObjectConstruct(&devNode->deviceObject);
|
||||
devNode->token = HdfDeviceTokenNewInstance();
|
||||
nodeIf->LaunchNode = HdfDeviceLaunchNode;
|
||||
nodeIf->PublishService = HdfDeviceNodePublishPublicService;
|
||||
nodeIf->RemoveService = HdfDeviceNodeRemoveService;
|
||||
nodeIf->UnlaunchNode = HdfDeviceUnlaunchNode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,13 +226,14 @@ void HdfDeviceNodeDestruct(struct HdfDeviceNode *devNode)
|
||||
HDF_LOGI("release devnode %s", devNode->servName);
|
||||
switch (devNode->devStatus) {
|
||||
case DEVNODE_LAUNCHED:
|
||||
HdfDeviceReleaseNode(devNode);
|
||||
HdfDeviceUnlaunchNode(devNode);
|
||||
case DEVNODE_INITED: // fall-through
|
||||
HdfDeviceTokenFreeInstance(devNode->token);
|
||||
devNode->token = NULL;
|
||||
case DEVNODE_INITED: // fall-through
|
||||
PowerStateTokenFreeInstance(devNode->powerToken);
|
||||
devNode->powerToken = NULL;
|
||||
OsalMemFree(devNode->servName);
|
||||
OsalMemFree(devNode->driverName);
|
||||
devNode->servName = NULL;
|
||||
break;
|
||||
case DEVNODE_NONE:
|
||||
@@ -231,8 +263,7 @@ struct HdfDeviceNode *HdfDeviceNodeNewInstance(const struct HdfDeviceInfo *devic
|
||||
if (devNode->servName == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
devNode->deviceObject.property = HcsGetNodeByMatchAttr(HdfGetRootNode(), deviceInfo->deviceMatchAttr);
|
||||
devNode->deviceObject.priv = (void *)(deviceInfo->private);
|
||||
devNode->deviceObject.property = HcsGetNodeByMatchAttr(HdfGetHcsRootNode(), deviceInfo->deviceMatchAttr);
|
||||
if (devNode->deviceObject.property == NULL) {
|
||||
HDF_LOGD("node %s property empty, match attr: %s", deviceInfo->moduleName, deviceInfo->deviceMatchAttr);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,13 @@
|
||||
*/
|
||||
|
||||
#include "hdf_device_object.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_node.h"
|
||||
#include "devhost_service.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_cstring.h"
|
||||
#include "hdf_device_node.h"
|
||||
#include "hdf_driver_loader.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
#include "hdf_observer_record.h"
|
||||
#include "hdf_service_observer.h"
|
||||
#include "power_state_token.h"
|
||||
@@ -121,8 +124,7 @@ void HdfPmSetMode(struct HdfDeviceObject *deviceObject, uint32_t mode)
|
||||
|
||||
bool HdfDeviceSetClass(struct HdfDeviceObject *deviceObject, DeviceClass deviceClass)
|
||||
{
|
||||
if ((deviceObject == NULL) || (deviceClass >= DEVICE_CLASS_MAX) ||
|
||||
(deviceClass >= DEVICE_CLASS_MAX)) {
|
||||
if ((deviceObject == NULL) || (deviceClass >= DEVICE_CLASS_MAX) || (deviceClass >= DEVICE_CLASS_MAX)) {
|
||||
return false;
|
||||
}
|
||||
deviceObject->deviceClass = deviceClass;
|
||||
@@ -137,3 +139,125 @@ void HdfDeviceObjectConstruct(struct HdfDeviceObject *deviceObject)
|
||||
deviceObject->deviceClass = DEVICE_CLASS_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
struct HdfDeviceObject *HdfDeviceObjectAlloc(struct HdfDeviceObject *parent, const char *driverName)
|
||||
{
|
||||
struct HdfDeviceNode *newNode = NULL;
|
||||
struct HdfDeviceNode *parentDevNode = CONTAINER_OF(parent, struct HdfDeviceNode, deviceObject);
|
||||
|
||||
if (parent == NULL) {
|
||||
HDF_LOGE("failed to alloc device, parent invalid");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (parentDevNode->devStatus != DEVNODE_LAUNCHED) {
|
||||
HDF_LOGE("failed to alloc device, parent status invalid %u", parentDevNode->devStatus);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
newNode = (struct HdfDeviceNode *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DEVICE_SERVICE);
|
||||
if (newNode == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
newNode->driverName = HdfStringCopy(driverName);
|
||||
if (newNode->driverName == NULL) {
|
||||
HdfDeviceNodeFreeInstance(newNode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
newNode->hostService = parentDevNode->hostService;
|
||||
newNode->device = parentDevNode->device;
|
||||
|
||||
return &newNode->deviceObject;
|
||||
}
|
||||
|
||||
void HdfDeviceObjectRelease(struct HdfDeviceObject *dev)
|
||||
{
|
||||
struct HdfDeviceNode *devNode = CONTAINER_OF(dev, struct HdfDeviceNode, deviceObject);
|
||||
if (dev == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (devNode->device != NULL && devNode->device->super.Detach != NULL) {
|
||||
devNode->device->super.Detach(&devNode->device->super, devNode);
|
||||
}
|
||||
HdfDeviceNodeFreeInstance(devNode);
|
||||
}
|
||||
|
||||
int HdfDeviceObjectRegister(struct HdfDeviceObject *dev)
|
||||
{
|
||||
int ret = HDF_FAILURE;
|
||||
struct HdfDeviceNode *devNode = CONTAINER_OF(dev, struct HdfDeviceNode, deviceObject);
|
||||
struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
|
||||
|
||||
if (dev == NULL || devNode->driverName == NULL || devNode->device == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
devNode->driver = driverLoader->GetDriver(devNode->driverName);
|
||||
if (devNode->driver == NULL) {
|
||||
HDF_LOGE("can not found driver %s", devNode->driverName);
|
||||
return HDF_DEV_ERR_NO_DEVICE;
|
||||
}
|
||||
|
||||
ret = devNode->device->super.Attach(&devNode->device->super, devNode);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("faild to attach device %s", devNode->driverName);
|
||||
return HDF_DEV_ERR_ATTACHDEV_FAIL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int HdfDeviceObjectUnRegister(struct HdfDeviceObject *dev)
|
||||
{
|
||||
struct HdfDeviceNode *devNode = CONTAINER_OF(dev, struct HdfDeviceNode, deviceObject);
|
||||
if (devNode == NULL || devNode->device == NULL) {
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
return devNode->device->super.Detach(&devNode->device->super, devNode);
|
||||
}
|
||||
|
||||
int HdfDeviceObjectPublishService(struct HdfDeviceObject *dev, const char *servName, uint8_t policy, uint32_t perm)
|
||||
{
|
||||
int ret;
|
||||
struct HdfDeviceNode *devNode = CONTAINER_OF(dev, struct HdfDeviceNode, deviceObject);
|
||||
if (dev == NULL || servName == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (policy <= SERVICE_POLICY_NONE || policy >= SERVICE_POLICY_INVALID) {
|
||||
return HDF_DEV_ERR_NO_DEVICE_SERVICE;
|
||||
}
|
||||
|
||||
if (devNode->servStatus) {
|
||||
HDF_LOGE("failed to publish public service, repeat publish");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
devNode->servName = HdfStringCopy(servName);
|
||||
if (devNode->servName == NULL) {
|
||||
return HDF_DEV_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
devNode->policy = policy;
|
||||
devNode->permission = perm;
|
||||
|
||||
ret = DeviveDriverBind(devNode);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return devNode->super.PublishService(devNode);
|
||||
}
|
||||
|
||||
int HdfDeviceObjectRemoveService(struct HdfDeviceObject *dev)
|
||||
{
|
||||
struct HdfDeviceNode *devNode = CONTAINER_OF(dev, struct HdfDeviceNode, deviceObject);
|
||||
if (dev == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
return devNode->super.RemoveService(devNode);
|
||||
}
|
||||
@@ -16,7 +16,8 @@
|
||||
struct DevHostServiceClnt {
|
||||
struct DListHead node;
|
||||
struct HdfSList devices;
|
||||
struct HdfSList *deviceInfos;
|
||||
struct HdfSList unloadDevInfos;
|
||||
struct HdfSList dynamicDevInfos;
|
||||
Map *deviceHashMap;
|
||||
struct IDevHostService *hostService;
|
||||
uint16_t devCount;
|
||||
|
||||
@@ -24,8 +24,6 @@ bool DevmgrServiceConstruct(struct DevmgrService *inst);
|
||||
struct HdfObject *DevmgrServiceCreate(void);
|
||||
void DevmgrServiceRelease(struct HdfObject *object);
|
||||
struct IDevmgrService *DevmgrServiceGetInstance(void);
|
||||
int DevmgrServiceLoadDevice(const char *svcName);
|
||||
int DevmgrServiceUnLoadDevice(const char *svcName);
|
||||
int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc);
|
||||
|
||||
#endif /* DEVICE_MANAGER_SERVICE_H */
|
||||
|
||||
@@ -28,6 +28,7 @@ struct IDevSvcManager *DevSvcManagerGetInstance(void);
|
||||
int DevSvcManagerAddService(struct IDevSvcManager *manager, const char *svcName, struct HdfDeviceObject *service);
|
||||
struct HdfObject *DevSvcManagerGetService(struct IDevSvcManager *manager, const char *svcName);
|
||||
void DevSvcManagerRemoveService(struct IDevSvcManager *manager, const char *svcName);
|
||||
void DevSvcManagerListService(struct HdfSBuf *serviecNameSet, DeviceClass deviceClass);
|
||||
|
||||
int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback);
|
||||
int DevSvcManagerClntUnsubscribeService(const char *svcName);
|
||||
|
||||
@@ -32,20 +32,26 @@ int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt)
|
||||
HDF_LOGE("devHostSvcIf or devHostSvcIf->AddDevice is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfSListIteratorInit(&it, hostClnt->deviceInfos);
|
||||
HdfSListIteratorInit(&it, &hostClnt->unloadDevInfos);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&it);
|
||||
if ((deviceInfo == NULL) || (deviceInfo->preload == DEVICE_PRELOAD_DISABLE)) {
|
||||
continue;
|
||||
}
|
||||
if ((DeviceManagerIsQuickLoad() == DEV_MGR_QUICK_LOAD) &&
|
||||
(deviceInfo->preload == DEVICE_PRELOAD_ENABLE_STEP2)) {
|
||||
/*
|
||||
* If quick start feature enable, the device which 'preload' attribute set as
|
||||
* DEVICE_PRELOAD_ENABLE_STEP2 will be loaded later
|
||||
*/
|
||||
if (DeviceManagerIsQuickLoad() == DEV_MGR_QUICK_LOAD &&
|
||||
deviceInfo->preload == DEVICE_PRELOAD_ENABLE_STEP2) {
|
||||
continue;
|
||||
}
|
||||
ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("failed to install driver %s, ret = %d", deviceInfo->svcName, ret);
|
||||
continue;
|
||||
}
|
||||
HdfSListIteratorRemove(&it);
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -69,6 +75,7 @@ struct DevHostServiceClnt *DevHostServiceClntNewInstance(uint16_t hostId, const
|
||||
hostClnt->hostId = hostId;
|
||||
hostClnt->hostName = hostName;
|
||||
hostClnt->devCount = 0;
|
||||
hostClnt->hostPid = -1;
|
||||
DevHostServiceClntConstruct(hostClnt);
|
||||
}
|
||||
return hostClnt;
|
||||
@@ -78,7 +85,8 @@ void DevHostServiceClntFreeInstance(struct DevHostServiceClnt *hostClnt)
|
||||
{
|
||||
if (hostClnt != NULL) {
|
||||
HdfSListFlush(&hostClnt->devices, DeviceTokenClntDelete);
|
||||
HdfSListFlush(hostClnt->deviceInfos, HdfDeviceInfoDelete);
|
||||
HdfSListFlush(&hostClnt->unloadDevInfos, HdfDeviceInfoDelete);
|
||||
HdfSListFlush(&hostClnt->dynamicDevInfos, HdfDeviceInfoDelete);
|
||||
OsalMemFree(hostClnt->deviceHashMap);
|
||||
OsalMemFree(hostClnt);
|
||||
}
|
||||
|
||||
@@ -15,53 +15,116 @@
|
||||
#include "hdf_host_info.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
#include "osal_time.h"
|
||||
|
||||
#define HDF_LOG_TAG devmgr_service
|
||||
|
||||
static int DevmgrServiceActiveDevice(struct DevHostServiceClnt *hostClnt,
|
||||
struct HdfDeviceInfo *deviceInfo, bool isLoad)
|
||||
{
|
||||
struct IDevHostService *devHostSvcIf = (struct IDevHostService *)hostClnt->hostService;
|
||||
if (devHostSvcIf == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (isLoad && (deviceInfo->preload != DEVICE_PRELOAD_ENABLE)) {
|
||||
int ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo);
|
||||
if (ret == HDF_SUCCESS) {
|
||||
deviceInfo->preload = DEVICE_PRELOAD_ENABLE;
|
||||
}
|
||||
return ret;
|
||||
} else if (!isLoad && (deviceInfo->preload != DEVICE_PRELOAD_DISABLE)) {
|
||||
devHostSvcIf->DelDevice(devHostSvcIf, deviceInfo->deviceId);
|
||||
deviceInfo->preload = DEVICE_PRELOAD_DISABLE;
|
||||
return HDF_SUCCESS;
|
||||
} else {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
static int DevmgrServiceFindAndActiveDevice(const char *svcName, bool isLoad)
|
||||
static bool DevmgrServiceDynamicDevInfoFound(const char *svcName, struct DevHostServiceClnt **targetHostClnt,
|
||||
struct HdfDeviceInfo **targetDeviceInfo)
|
||||
{
|
||||
struct HdfSListIterator itDeviceInfo;
|
||||
struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
|
||||
if (devMgrSvc == NULL || svcName == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
if (devMgrSvc == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
|
||||
HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
|
||||
HdfSListIteratorInit(&itDeviceInfo, &hostClnt->dynamicDevInfos);
|
||||
while (HdfSListIteratorHasNext(&itDeviceInfo)) {
|
||||
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
|
||||
if (strcmp(deviceInfo->svcName, svcName) == 0) {
|
||||
return DevmgrServiceActiveDevice(hostClnt, deviceInfo, isLoad);
|
||||
*targetDeviceInfo = deviceInfo;
|
||||
*targetHostClnt = hostClnt;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return HDF_FAILURE;
|
||||
return false;
|
||||
}
|
||||
|
||||
#define WAIT_HOST_SLEEP_TIME 1 // ms
|
||||
#define WAIT_HOST_SLEEP_CNT 100
|
||||
static int DevmgrServiceStartHostProcess(struct DevHostServiceClnt *hostClnt, bool sync)
|
||||
{
|
||||
int waitCount = WAIT_HOST_SLEEP_CNT;
|
||||
struct IDriverInstaller *installer = DriverInstallerGetInstance();
|
||||
if (installer == NULL || installer->StartDeviceHost == NULL) {
|
||||
HDF_LOGE("invalid installer");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
hostClnt->hostPid = installer->StartDeviceHost(hostClnt->hostId, hostClnt->hostName);
|
||||
if (hostClnt->hostPid == HDF_FAILURE) {
|
||||
HDF_LOGW("failed to start device host(%s, %u)", hostClnt->hostName, hostClnt->hostId);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (!sync) {
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
while (hostClnt->hostService == NULL && waitCount-- > 0) {
|
||||
OsalMSleep(WAIT_HOST_SLEEP_TIME);
|
||||
}
|
||||
|
||||
if (waitCount <= 0) {
|
||||
HDF_LOGE("wait host(%s, %d) attach timeout", hostClnt->hostName, hostClnt->hostId);
|
||||
return HDF_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int DevmgrServiceLoadDevice(struct IDevmgrService *devMgrSvc, const char *serviceName)
|
||||
{
|
||||
struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
(void)devMgrSvc;
|
||||
|
||||
if (serviceName == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!DevmgrServiceDynamicDevInfoFound(serviceName, &hostClnt, &deviceInfo)) {
|
||||
HDF_LOGE("device %s not in configed device list", serviceName);
|
||||
return HDF_DEV_ERR_NO_DEVICE;
|
||||
}
|
||||
|
||||
if (deviceInfo->preload != DEVICE_PRELOAD_DISABLE) {
|
||||
HDF_LOGE("device %s not an dynamic load device", serviceName);
|
||||
return HDF_DEV_ERR_NORANGE;
|
||||
}
|
||||
|
||||
if (hostClnt->hostPid < 0 && DevmgrServiceStartHostProcess(hostClnt, true) != HDF_SUCCESS) {
|
||||
HDF_LOGW("failed to start device host(%s, %u)", hostClnt->hostName, hostClnt->hostId);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return hostClnt->hostService->AddDevice(hostClnt->hostService, deviceInfo);
|
||||
}
|
||||
|
||||
static int DevmgrServiceUnloadDevice(struct IDevmgrService *devMgrSvc, const char *serviceName)
|
||||
{
|
||||
struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
(void)devMgrSvc;
|
||||
|
||||
if (serviceName == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!DevmgrServiceDynamicDevInfoFound(serviceName, &hostClnt, &deviceInfo) ||
|
||||
deviceInfo->preload != DEVICE_PRELOAD_DISABLE) {
|
||||
HDF_LOGE("device %s not in configed dynamic device list", serviceName);
|
||||
return HDF_DEV_ERR_NO_DEVICE;
|
||||
}
|
||||
|
||||
if (hostClnt->hostService == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return hostClnt->hostService->DelDevice(hostClnt->hostService, deviceInfo->deviceId);
|
||||
}
|
||||
|
||||
int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc)
|
||||
@@ -75,30 +138,22 @@ int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc)
|
||||
}
|
||||
|
||||
DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
|
||||
HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
|
||||
HdfSListIteratorInit(&itDeviceInfo, &hostClnt->unloadDevInfos);
|
||||
while (HdfSListIteratorHasNext(&itDeviceInfo)) {
|
||||
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
|
||||
if (deviceInfo->preload == DEVICE_PRELOAD_ENABLE_STEP2) {
|
||||
ret = DevmgrServiceActiveDevice(hostClnt, deviceInfo, true);
|
||||
ret = hostClnt->hostService->AddDevice(hostClnt->hostService, deviceInfo);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s:failed to load driver %s", __func__, deviceInfo->moduleName);
|
||||
continue;
|
||||
}
|
||||
HdfSListIteratorRemove(&itDeviceInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int DevmgrServiceLoadDevice(const char *svcName)
|
||||
{
|
||||
return DevmgrServiceFindAndActiveDevice(svcName, true);
|
||||
}
|
||||
|
||||
int DevmgrServiceUnLoadDevice(const char *svcName)
|
||||
{
|
||||
return DevmgrServiceFindAndActiveDevice(svcName, false);
|
||||
}
|
||||
|
||||
static struct DevHostServiceClnt *DevmgrServiceFindDeviceHost(struct IDevmgrService *inst, uint16_t hostId)
|
||||
{
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
@@ -113,29 +168,10 @@ static struct DevHostServiceClnt *DevmgrServiceFindDeviceHost(struct IDevmgrServ
|
||||
return hostClnt;
|
||||
}
|
||||
}
|
||||
HDF_LOGE("failed to find host, host id is %u", hostId);
|
||||
HDF_LOGE("cannot find host %u", hostId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void DevmgrServiceUpdateStatus(struct DevHostServiceClnt *hostClnt, devid_t devId, uint16_t status)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
|
||||
HdfSListIteratorInit(&it, hostClnt->deviceInfos);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&it);
|
||||
if (deviceInfo->deviceId == devId) {
|
||||
deviceInfo->status = status;
|
||||
HDF_LOGD("%s host:%s %u device:%s %u status:%u", __func__, hostClnt->hostName,
|
||||
hostClnt->hostId, deviceInfo->svcName, devId, deviceInfo->status);
|
||||
return;
|
||||
}
|
||||
}
|
||||
HDF_LOGE("%s: not find device %u in host %u", __func__, devId, hostClnt->hostId);
|
||||
return;
|
||||
}
|
||||
|
||||
static int DevmgrServiceAttachDevice(struct IDevmgrService *inst, struct IHdfDeviceToken *token)
|
||||
{
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
@@ -152,7 +188,6 @@ static int DevmgrServiceAttachDevice(struct IDevmgrService *inst, struct IHdfDev
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
DevmgrServiceUpdateStatus(hostClnt, token->devid, HDF_SERVICE_USABLE);
|
||||
HdfSListAdd(&hostClnt->devices, &tokenClnt->node);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -180,7 +215,6 @@ static int DevmgrServiceDetachDevice(struct IDevmgrService *inst, devid_t devid)
|
||||
return HDF_DEV_ERR_NO_DEVICE;
|
||||
}
|
||||
tokenClnt = CONTAINER_OF(tokenClntNode, struct DeviceTokenClnt, node);
|
||||
DevmgrServiceUpdateStatus(hostClnt, devid, HDF_SERVICE_UNUSABLE);
|
||||
HdfSListRemove(&hostClnt->devices, &tokenClnt->node);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -199,13 +233,36 @@ static int DevmgrServiceAttachDeviceHost(
|
||||
}
|
||||
|
||||
hostClnt->hostService = hostService;
|
||||
hostClnt->deviceInfos = HdfAttributeManagerGetDeviceList(hostClnt->hostId, hostClnt->hostName);
|
||||
if (hostClnt->deviceInfos == NULL) {
|
||||
HDF_LOGW("failed to get device list ");
|
||||
return DevHostServiceClntInstallDriver(hostClnt);
|
||||
}
|
||||
|
||||
static int DevmgrServiceStartDeviceHost(struct DevmgrService *devmgr, struct HdfHostInfo *hostAttr)
|
||||
{
|
||||
struct DevHostServiceClnt *hostClnt = DevHostServiceClntNewInstance(hostAttr->hostId, hostAttr->hostName);
|
||||
if (hostClnt == NULL) {
|
||||
HDF_LOGW("failed to create new device host client");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (HdfAttributeManagerGetDeviceList(hostClnt) != HDF_SUCCESS) {
|
||||
HDF_LOGW("failed to get device list for host %s", hostClnt->hostName);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
DListInsertTail(&hostClnt->node, &devmgr->hosts);
|
||||
|
||||
// not start the host which only have dynamic deivces
|
||||
if (HdfSListIsEmpty(&hostClnt->unloadDevInfos)) {
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
hostClnt->devCount = HdfSListCount(hostClnt->deviceInfos);
|
||||
return DevHostServiceClntInstallDriver(hostClnt);
|
||||
|
||||
if (DevmgrServiceStartHostProcess(hostClnt, false) != HDF_SUCCESS) {
|
||||
HDF_LOGW("failed to start device host, host id is %u", hostAttr->hostId);
|
||||
DListRemove(&hostClnt->node);
|
||||
DevHostServiceClntFreeInstance(hostClnt);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst)
|
||||
@@ -213,13 +270,7 @@ static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst)
|
||||
struct HdfSList hostList;
|
||||
struct HdfSListIterator it;
|
||||
struct HdfHostInfo *hostAttr = NULL;
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
struct IDriverInstaller *installer = NULL;
|
||||
installer = DriverInstallerGetInstance();
|
||||
if (installer == NULL || installer->StartDeviceHost == NULL) {
|
||||
HDF_LOGE("installer or installer->StartDeviceHost is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
HdfSListInit(&hostList);
|
||||
if (!HdfAttributeManagerGetHostList(&hostList)) {
|
||||
HDF_LOGW("%s: host list is null", __func__);
|
||||
@@ -228,18 +279,7 @@ static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst)
|
||||
HdfSListIteratorInit(&it, &hostList);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
hostAttr = (struct HdfHostInfo *)HdfSListIteratorNext(&it);
|
||||
hostClnt = DevHostServiceClntNewInstance(hostAttr->hostId, hostAttr->hostName);
|
||||
if (hostClnt == NULL) {
|
||||
HDF_LOGW("failed to create new device host client");
|
||||
continue;
|
||||
}
|
||||
DListInsertTail(&hostClnt->node, &inst->hosts);
|
||||
hostClnt->hostPid = installer->StartDeviceHost(hostAttr->hostId, hostAttr->hostName);
|
||||
if (hostClnt->hostPid == HDF_FAILURE) {
|
||||
HDF_LOGW("failed to start device host, host id is %u", hostAttr->hostId);
|
||||
DListRemove(&hostClnt->node);
|
||||
DevHostServiceClntFreeInstance(hostClnt);
|
||||
}
|
||||
DevmgrServiceStartDeviceHost(inst, hostAttr);
|
||||
}
|
||||
HdfSListFlush(&hostList, HdfHostInfoDelete);
|
||||
return HDF_SUCCESS;
|
||||
@@ -305,6 +345,8 @@ bool DevmgrServiceConstruct(struct DevmgrService *inst)
|
||||
if (devMgrSvcIf != NULL) {
|
||||
devMgrSvcIf->AttachDevice = DevmgrServiceAttachDevice;
|
||||
devMgrSvcIf->DetachDevice = DevmgrServiceDetachDevice;
|
||||
devMgrSvcIf->LoadDevice = DevmgrServiceLoadDevice;
|
||||
devMgrSvcIf->UnloadDevice = DevmgrServiceUnloadDevice;
|
||||
devMgrSvcIf->AttachDeviceHost = DevmgrServiceAttachDeviceHost;
|
||||
devMgrSvcIf->StartService = DevmgrServiceStartService;
|
||||
devMgrSvcIf->PowerStateChange = DevmgrServicePowerStateChange;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
#include "hdf_service_record.h"
|
||||
#include "hdf_device_node.h"
|
||||
|
||||
#define HDF_LOG_TAG devsvc_manager
|
||||
|
||||
@@ -65,11 +66,10 @@ int DevSvcManagerAddService(struct IDevSvcManager *inst, const char *svcName, st
|
||||
|
||||
int DevSvcManagerSubscribeService(struct IDevSvcManager *inst, const char *svcName, struct SubscriberCallback callBack)
|
||||
{
|
||||
int ret = HDF_FAILURE;
|
||||
struct DevSvcManager *devSvcMgr = (struct DevSvcManager *)inst;
|
||||
struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();;
|
||||
struct HdfObject *deviceService = NULL;
|
||||
if (svcName == NULL || devSvcMgr == NULL) {
|
||||
return ret;
|
||||
if (inst == NULL || svcName == NULL || devMgrSvc == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
deviceService = DevSvcManagerGetService(inst, svcName);
|
||||
@@ -80,7 +80,7 @@ int DevSvcManagerSubscribeService(struct IDevSvcManager *inst, const char *svcNa
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
return DevmgrServiceLoadDevice(svcName);
|
||||
return devMgrSvc->super.LoadDevice(&devMgrSvc->super, svcName);
|
||||
}
|
||||
|
||||
void DevSvcManagerRemoveService(struct IDevSvcManager *inst, const char *svcName)
|
||||
@@ -115,6 +115,33 @@ struct HdfDeviceObject *DevSvcManagerGetObject(struct IDevSvcManager *inst, cons
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// only use for kernel space
|
||||
void DevSvcManagerListService(struct HdfSBuf *serviecNameSet, DeviceClass deviceClass)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
struct DevSvcRecord *record = NULL;
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)DevSvcManagerGetInstance();
|
||||
if (devSvcManager == NULL) {
|
||||
HDF_LOGE("failed to list service, devSvcManager is null");
|
||||
return;
|
||||
}
|
||||
|
||||
OsalMutexLock(&devSvcManager->mutex);
|
||||
HdfSListIteratorInit(&it, &devSvcManager->services);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
record = (struct DevSvcRecord *)HdfSListIteratorNext(&it);
|
||||
if (record == NULL) {
|
||||
continue;
|
||||
}
|
||||
devNode = CONTAINER_OF(record->value, struct HdfDeviceNode, deviceObject);
|
||||
if (devNode->deviceObject.deviceClass == deviceClass) {
|
||||
HdfSbufWriteString(serviecNameSet, devNode->servName);
|
||||
}
|
||||
}
|
||||
OsalMutexUnlock(&devSvcManager->mutex);
|
||||
}
|
||||
|
||||
struct HdfObject *DevSvcManagerGetService(struct IDevSvcManager *inst, const char *svcName)
|
||||
{
|
||||
struct HdfDeviceObject *deviceObject = DevSvcManagerGetObject(inst, svcName);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "hdf_attribute_manager.h"
|
||||
#include "hdf_driver_installer.h"
|
||||
#include "devhost_service.h"
|
||||
#include "hdf_base.h"
|
||||
|
||||
@@ -96,7 +96,7 @@ HWTEST_F(HdfManagerTest, HdfRegisterDevice001, TestSize.Level0)
|
||||
EXPECT_TRUE((timeAfter - timeBefore) < 100);
|
||||
|
||||
struct HdfIoService *ioService1 = HdfIoServiceBind("sample_service1");
|
||||
EXPECT_TRUE(ioService1 != NULL);
|
||||
ASSERT_TRUE(ioService1 != NULL);
|
||||
HdfIoServiceRecycle(ioService1);
|
||||
|
||||
ret = ioService->dispatcher->Dispatch(&ioService->object, SAMPLE_DRIVER_UNREGISTER_DEVICE, data, NULL);
|
||||
@@ -117,21 +117,26 @@ HWTEST_F(HdfManagerTest, HdfRegisterDevice001, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(HdfManagerTest, HdfGetServiceNameByDeviceClass001, TestSize.Level0)
|
||||
{
|
||||
struct HdfSBuf *data = HdfSBufObtain(1000);
|
||||
struct HdfSBuf *data = HdfSBufObtain(2000);
|
||||
ASSERT_TRUE(data != NULL);
|
||||
int32_t ret = HdfGetServiceNameByDeviceClass(DEVICE_CLASS_DEFAULT, data);
|
||||
EXPECT_TRUE(ret == HDF_SUCCESS);
|
||||
|
||||
bool flag = false;
|
||||
const char *svcName = NULL;
|
||||
while(true) {
|
||||
svcName = HdfSbufReadString(data);
|
||||
if (svcName == NULL) {
|
||||
break;
|
||||
}
|
||||
if (strcmp(svcName, "sample_service") == 0) {
|
||||
flag = true;
|
||||
break;
|
||||
for (size_t i = DEVICE_CLASS_DEFAULT; i < DEVICE_CLASS_MAX; i++) {
|
||||
int32_t ret = HdfGetServiceNameByDeviceClass((DeviceClass)i, data);
|
||||
std::cout << "clasee " << i << " device list:" << std::endl;
|
||||
EXPECT_TRUE(ret == HDF_SUCCESS);
|
||||
const char *svcName = NULL;
|
||||
while(true) {
|
||||
svcName = HdfSbufReadString(data);
|
||||
if (svcName == NULL) {
|
||||
break;
|
||||
}
|
||||
std::cout << svcName << std::endl;
|
||||
if (strcmp(svcName, "sample_service") == 0) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
HdfSbufFlush(data);
|
||||
}
|
||||
HdfSBufRecycle(data);
|
||||
EXPECT_TRUE(flag);
|
||||
|
||||
@@ -21,6 +21,8 @@ struct IDevmgrService {
|
||||
int (*AttachDeviceHost)(struct IDevmgrService *, uint16_t, struct IDevHostService *);
|
||||
int (*AttachDevice)(struct IDevmgrService *, struct IHdfDeviceToken *);
|
||||
int (*DetachDevice)(struct IDevmgrService *, devid_t);
|
||||
int (*LoadDevice)(struct IDevmgrService *, const char *);
|
||||
int (*UnloadDevice)(struct IDevmgrService *, const char *);
|
||||
int (*StartService)(struct IDevmgrService *);
|
||||
int (*PowerStateChange)(struct IDevmgrService *, enum HdfPowerState pEvent);
|
||||
};
|
||||
|
||||
@@ -10,11 +10,10 @@
|
||||
#define HDF_ATTRIBUTE_MANAGER_H
|
||||
|
||||
#include "hdf_slist.h"
|
||||
#include "devhost_service_clnt.h"
|
||||
|
||||
const struct DeviceResourceNode *HdfGetRootNode(void);
|
||||
const struct DeviceResourceNode *HdfGetHcsRootNode(void);
|
||||
bool HdfAttributeManagerGetHostList(struct HdfSList *hostList);
|
||||
struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *hostName);
|
||||
bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const void *privateData);
|
||||
void HdfDeviceListDel(const char *moduleName, const char *serviceName);
|
||||
int HdfAttributeManagerGetDeviceList(struct DevHostServiceClnt *hostClnt);
|
||||
|
||||
#endif /* HDF_ATTRIBUTE_MANAGER_H */
|
||||
|
||||
Executable → Regular
-1
@@ -36,7 +36,6 @@ struct HdfDeviceInfo {
|
||||
const char *moduleName;
|
||||
const char *svcName;
|
||||
const char *deviceMatchAttr;
|
||||
const void *private;
|
||||
};
|
||||
|
||||
struct HdfPrivateInfo {
|
||||
|
||||
Executable → Regular
+1
-8
@@ -29,7 +29,6 @@ void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo)
|
||||
deviceInfo->svcName = NULL;
|
||||
deviceInfo->moduleName = NULL;
|
||||
deviceInfo->deviceMatchAttr = NULL;
|
||||
deviceInfo->private = NULL;
|
||||
}
|
||||
|
||||
struct HdfDeviceInfo *HdfDeviceInfoNewInstance()
|
||||
@@ -40,19 +39,13 @@ struct HdfDeviceInfo *HdfDeviceInfoNewInstance()
|
||||
HdfDeviceInfoConstruct(deviceInfo);
|
||||
return deviceInfo;
|
||||
}
|
||||
HDF_LOGE("Create device deviceInfo failed");
|
||||
HDF_LOGE("failed to create deviceInfo, oom");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void HdfDeviceInfoFreeInstance(struct HdfDeviceInfo *deviceInfo)
|
||||
{
|
||||
if (deviceInfo != NULL) {
|
||||
if (deviceInfo->isDynamic && deviceInfo->svcName != NULL) {
|
||||
OsalMemFree((void *)deviceInfo->svcName);
|
||||
}
|
||||
if (deviceInfo->private != NULL) {
|
||||
OsalMemFree((void *)deviceInfo->private);
|
||||
}
|
||||
OsalMemFree(deviceInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,14 @@
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include <securec.h>
|
||||
#include "osal_mem.h"
|
||||
#include "devsvc_manager_clnt.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_log.h"
|
||||
#include "event_hub.h"
|
||||
#include "hdf_input_device_manager.h"
|
||||
#include "devsvc_manager_clnt.h"
|
||||
#include "event_hub.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_object.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
#include <securec.h>
|
||||
|
||||
#define NODE_MODE 0660
|
||||
#define SERVICE_NAME_LEN 24
|
||||
@@ -52,10 +53,24 @@ static struct HdfDeviceObject *HidRegisterHdfDevice(InputDevice *inputDev)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hdfDev = HdfRegisterDevice(moduleName, svcName, NULL);
|
||||
hdfDev = HdfDeviceObjectAlloc(g_inputManager->hdfDevObj, moduleName);
|
||||
if (hdfDev == NULL) {
|
||||
HDF_LOGE("%s: HdfRegisterDevice failed", __func__);
|
||||
HDF_LOGE("%s: failed to alloc device object", __func__);
|
||||
return NULL;
|
||||
}
|
||||
ret = HdfDeviceObjectRegister(hdfDev);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: failed to regitst device %s", __func__, moduleName);
|
||||
HdfDeviceObjectRelease(hdfDev);
|
||||
return NULL;
|
||||
}
|
||||
ret = HdfDeviceObjectPublishService(hdfDev, svcName, SERVICE_POLICY_CAPACITY, 0664);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: failed to regitst device %s", __func__, moduleName);
|
||||
HdfDeviceObjectRelease(hdfDev);
|
||||
return NULL;
|
||||
}
|
||||
inputDev->hdfDevObj = hdfDev;
|
||||
HDF_LOGI("%s: svcName is %s, devName = %s", __func__, svcName, inputDev->devName);
|
||||
return hdfDev;
|
||||
}
|
||||
@@ -103,21 +118,9 @@ static int32_t CreateDeviceNode(InputDevice *inputDev)
|
||||
|
||||
static void DeleteDeviceNode(InputDevice *inputDev)
|
||||
{
|
||||
int32_t len;
|
||||
int32_t ret;
|
||||
if (IsHidDevice(inputDev->devType)) {
|
||||
char svcName[SERVICE_NAME_LEN] = {0};
|
||||
const char *moduleName = "HDF_HID";
|
||||
|
||||
len = (inputDev->devId < PLACEHOLDER_LIMIT) ? 1 : PLACEHOLDER_LENGTH;
|
||||
ret = snprintf_s(svcName, SERVICE_NAME_LEN, strlen("hdf_input_event") + len, "%s%u",
|
||||
"hdf_input_event", inputDev->devId);
|
||||
if (ret < 0) {
|
||||
HDF_LOGE("%s: snprintf_s failed", __func__);
|
||||
return;
|
||||
}
|
||||
HDF_LOGI("%s: svcName is %s, devName = %s", __func__, svcName, inputDev->devName);
|
||||
HdfUnregisterDevice(moduleName, svcName);
|
||||
HDF_LOGI("remove input device: hdf_input_event%u", inputDev->devId);
|
||||
HdfDeviceObjectRelease(inputDev->hdfDevObj);
|
||||
}
|
||||
|
||||
HDF_LOGI("%s: delete node succ, devId is %d", __func__, inputDev->devId);
|
||||
|
||||
Executable → Regular
+1
-1
@@ -78,7 +78,7 @@ struct UsbPnpRemoveInfo {
|
||||
uint8_t interfaceNum;
|
||||
};
|
||||
|
||||
int UsbDdkPnpLoaderEventReceived(void *priv, uint32_t id, struct HdfSBuf *data);
|
||||
int UsbDdkPnpLoaderEventReceived(void *usbPnpManagerPtr, uint32_t id, struct HdfSBuf *data);
|
||||
int UsbDdkPnpLoaderEventHandle(void);
|
||||
|
||||
#endif /* USB_DDK_PNP_LOADER_H */
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef USB_PNP_MANAGE_H
|
||||
#define USB_PNP_MANAGE_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_sbuf.h"
|
||||
|
||||
struct UsbPnpManagerDeviceInfo {
|
||||
struct HdfDeviceObject *usbPnpManager;
|
||||
const char *moduleName;
|
||||
const char *serviceName;
|
||||
const char *deviceMatchAttr;
|
||||
const void *privateData;
|
||||
bool isReg;
|
||||
};
|
||||
|
||||
bool UsbPnpManagerWriteModuleName(struct HdfSBuf *sbuf, const char *moduleName);
|
||||
int32_t UsbPnpManagerRegisterOrUnregisterDevice(struct UsbPnpManagerDeviceInfo *managerInfo);
|
||||
|
||||
#endif /* USB_PNP_MANAGE_H */
|
||||
Executable → Regular
+101
-22
@@ -12,6 +12,7 @@
|
||||
#include "hcs_tree_if.h"
|
||||
#include "hdf_attribute_manager.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_object.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_sbuf.h"
|
||||
#include "osal_mem.h"
|
||||
@@ -106,6 +107,84 @@ static bool UsbDdkPnpLoaderMatchDevice(const struct UsbPnpNotifyMatchInfoTable *
|
||||
return true;
|
||||
}
|
||||
|
||||
// Need optimize this device object array later, should bind device object to usb deivce
|
||||
#define REGISTER_DEV_MAX 16
|
||||
static struct HdfDeviceObject *g_resistedDevice[REGISTER_DEV_MAX] = {0};
|
||||
static int SaveRegistedDevice(struct HdfDeviceObject *dev)
|
||||
{
|
||||
for (size_t i = 0; i < REGISTER_DEV_MAX; i++) {
|
||||
if (g_resistedDevice[i] == NULL) {
|
||||
g_resistedDevice[i] = dev;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
static struct HdfDeviceObject *GetRegistedDevice(const char *serviceName)
|
||||
{
|
||||
struct HdfDeviceObject *dev = NULL;
|
||||
for (size_t i = 0; i < REGISTER_DEV_MAX; i++) {
|
||||
if (g_resistedDevice[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(HdfDeviceGetServiceName(g_resistedDevice[i]), serviceName)) {
|
||||
dev = g_resistedDevice[i];
|
||||
g_resistedDevice[i] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
int32_t UsbPnpManagerRegisterDevice(struct UsbPnpManagerDeviceInfo *managerInfo)
|
||||
{
|
||||
int ret = HDF_FAILURE;
|
||||
struct HdfDeviceObject *devObj = HdfDeviceObjectAlloc(managerInfo->usbPnpManager, managerInfo->moduleName);
|
||||
if (devObj == NULL) {
|
||||
HDF_LOGE("%s: failed to alloc device object", __func__);
|
||||
return HDF_DEV_ERR_NO_DEVICE;
|
||||
}
|
||||
|
||||
devObj->priv = (void *)managerInfo->privateData;
|
||||
ret = HdfDeviceObjectRegister(devObj);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: failed to regitst device %s", __func__, managerInfo->serviceName);
|
||||
HdfDeviceObjectRelease(devObj);
|
||||
return ret;
|
||||
}
|
||||
ret = HdfDeviceObjectPublishService(devObj, managerInfo->serviceName, SERVICE_POLICY_CAPACITY, 0664);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: failed to regitst device %s", __func__, managerInfo->serviceName);
|
||||
HdfDeviceObjectRelease(devObj);
|
||||
}
|
||||
// need optimize this code to remove SaveRegistedDevice function later
|
||||
SaveRegistedDevice(devObj);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UsbPnpManagerUnregisterDevice(struct UsbPnpManagerDeviceInfo *managerInfo)
|
||||
{
|
||||
// need optimize this code to remove GetRegistedDevice function later
|
||||
struct HdfDeviceObject *devObj = GetRegistedDevice(managerInfo->serviceName);
|
||||
if (devObj == NULL) {
|
||||
return HDF_DEV_ERR_NO_DEVICE;
|
||||
}
|
||||
HdfDeviceObjectRelease(devObj);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t UsbPnpManagerRegisterOrUnregisterDevice(struct UsbPnpManagerDeviceInfo *managerInfo)
|
||||
{
|
||||
if (managerInfo == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
return managerInfo->isReg ? UsbPnpManagerRegisterDevice(managerInfo) : UsbPnpManagerUnregisterDevice(managerInfo);
|
||||
}
|
||||
|
||||
static void UsbDdkPnpLoaderMatchHandle(const struct UsbPnpNotifyMatchInfoTable *dev,
|
||||
int8_t index, struct UsbPnpMatchIdTable *id, bool flag)
|
||||
{
|
||||
@@ -212,7 +291,7 @@ OUT:
|
||||
static bool UsbDdkPnpLoaderMatchInterface(const struct UsbPnpNotifyMatchInfoTable *dev,
|
||||
int8_t index, struct UsbPnpMatchIdTable *id)
|
||||
{
|
||||
uint32_t i;
|
||||
int32_t i;
|
||||
bool maskFlag = true;
|
||||
|
||||
if (id->matchFlag & USB_PNP_NOTIFY_MATCH_INT_CLASS) {
|
||||
@@ -585,8 +664,8 @@ static struct UsbPnpMatchIdTable **UsbDdkPnpLoaderPnpMatch(void)
|
||||
return UsbDdkPnpLoaderParseDeviceId(usbPnpNode);
|
||||
}
|
||||
|
||||
static int32_t UsbDdkPnpLoaderDispatchPnpDevice(
|
||||
const struct IDevmgrService *devmgrSvc, struct HdfSBuf *data, bool isReg)
|
||||
static int32_t UsbDdkPnpLoaderDispatchPnpDevice(struct HdfDeviceObject *usbPnpManagerDevice,
|
||||
struct HdfSBuf *data, bool isReg)
|
||||
{
|
||||
uint32_t infoSize = 0;
|
||||
struct UsbPnpNotifyServiceInfo *privateData = NULL;
|
||||
@@ -611,14 +690,14 @@ static int32_t UsbDdkPnpLoaderDispatchPnpDevice(
|
||||
privateData = NULL;
|
||||
}
|
||||
|
||||
managerInfo.devmgrSvc = (struct IDevmgrService *)devmgrSvc;
|
||||
managerInfo.usbPnpManager = usbPnpManagerDevice;
|
||||
managerInfo.moduleName = moduleName;
|
||||
managerInfo.serviceName = serviceName;
|
||||
managerInfo.deviceMatchAttr = deviceMatchAttr;
|
||||
managerInfo.privateData = privateData;
|
||||
managerInfo.isReg = isReg;
|
||||
|
||||
return UsbPnpManagerRegisterOrUnregisterDevice(managerInfo);
|
||||
return UsbPnpManagerRegisterOrUnregisterDevice(&managerInfo);
|
||||
}
|
||||
|
||||
static int UsbDdkPnpLoaderDeviceListAdd(const struct UsbPnpNotifyMatchInfoTable *info,
|
||||
@@ -685,7 +764,7 @@ static struct UsbPnpDeviceListTable *UsbDdkPnpLoaderAddInterface(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int UsbDdkPnpLoaderrAddPnpDevice(const struct IDevmgrService *devmgrSvc,
|
||||
static int UsbDdkPnpLoaderrAddPnpDevice(struct HdfDeviceObject *usbPnpManagerDevice,
|
||||
const struct UsbPnpNotifyMatchInfoTable *infoTable, const struct UsbPnpMatchIdTable *idTable, uint32_t cmdId)
|
||||
{
|
||||
int ret;
|
||||
@@ -700,8 +779,8 @@ static int UsbDdkPnpLoaderrAddPnpDevice(const struct IDevmgrService *devmgrSvc,
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
serviceInfo.length = sizeof(struct UsbPnpNotifyServiceInfo) - (USB_PNP_INFO_MAX_INTERFACES
|
||||
- idTable->interfaceLength);
|
||||
serviceInfo.length = sizeof(struct UsbPnpNotifyServiceInfo) -
|
||||
(USB_PNP_INFO_MAX_INTERFACES - idTable->interfaceLength);
|
||||
serviceInfo.devNum = infoTable->devNum;
|
||||
serviceInfo.busNum = infoTable->busNum;
|
||||
serviceInfo.interfaceLength = idTable->interfaceLength;
|
||||
@@ -715,7 +794,7 @@ static int UsbDdkPnpLoaderrAddPnpDevice(const struct IDevmgrService *devmgrSvc,
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
ret = UsbDdkPnpLoaderDispatchPnpDevice(devmgrSvc, pnpData, true);
|
||||
ret = UsbDdkPnpLoaderDispatchPnpDevice(usbPnpManagerDevice, pnpData, true);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s:%d handle failed, %s-%s cmdId is %d, ret=%d",
|
||||
__func__, __LINE__, idTable->moduleName, idTable->serviceName, cmdId, ret);
|
||||
@@ -740,7 +819,7 @@ ERROR:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void UsbDdkPnpLoaderAddDevice(uint32_t cmdId, uint8_t index, const struct IDevmgrService *devmgrSvc,
|
||||
static void UsbDdkPnpLoaderAddDevice(uint32_t cmdId, uint8_t index, struct HdfDeviceObject *usbPnpManagerDevice,
|
||||
const struct UsbPnpNotifyMatchInfoTable *infoTable, struct UsbPnpMatchIdTable **matchIdTable)
|
||||
{
|
||||
int ret;
|
||||
@@ -760,14 +839,14 @@ static void UsbDdkPnpLoaderAddDevice(uint32_t cmdId, uint8_t index, const struct
|
||||
idTable=%p, moduleName=%s, serviceName=%s",
|
||||
__func__, __LINE__, index, tableCount, idTable, idTable->moduleName, idTable->serviceName);
|
||||
|
||||
ret = UsbDdkPnpLoaderrAddPnpDevice(devmgrSvc, infoTable, idTable, cmdId);
|
||||
ret = UsbDdkPnpLoaderrAddPnpDevice(usbPnpManagerDevice, infoTable, idTable, cmdId);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int UsbDdkPnpLoaderRemoveHandle(const struct IDevmgrService *devmgrSvc,
|
||||
static int UsbDdkPnpLoaderRemoveHandle(struct HdfDeviceObject *usbPnpManager,
|
||||
struct UsbPnpDeviceListTable *deviceListTablePos)
|
||||
{
|
||||
struct UsbPnpNotifyServiceInfo serviceInfo;
|
||||
@@ -789,7 +868,7 @@ static int UsbDdkPnpLoaderRemoveHandle(const struct IDevmgrService *devmgrSvc,
|
||||
}
|
||||
|
||||
if (deviceListTablePos->status != USB_PNP_REMOVE_STATUS) {
|
||||
ret = UsbDdkPnpLoaderDispatchPnpDevice(devmgrSvc, pnpData, false);
|
||||
ret = UsbDdkPnpLoaderDispatchPnpDevice(usbPnpManager, pnpData, false);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s:%d UsbDdkPnpLoaderDispatchPnpDevice faile ret=%d",
|
||||
__func__, __LINE__, ret);
|
||||
@@ -803,7 +882,7 @@ ERROR:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int UsbDdkPnpLoaderRemoveDevice(const struct IDevmgrService *devmgrSvc,
|
||||
static int UsbDdkPnpLoaderRemoveDevice(struct HdfDeviceObject *usbPnpManager,
|
||||
struct UsbPnpRemoveInfo removeInfo, uint32_t cmdId)
|
||||
{
|
||||
int ret = HDF_SUCCESS;
|
||||
@@ -833,7 +912,7 @@ static int UsbDdkPnpLoaderRemoveDevice(const struct IDevmgrService *devmgrSvc,
|
||||
}
|
||||
findFlag = true;
|
||||
|
||||
ret = UsbDdkPnpLoaderRemoveHandle(devmgrSvc, deviceListTablePos);
|
||||
ret = UsbDdkPnpLoaderRemoveHandle(usbPnpManager, deviceListTablePos);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
@@ -855,8 +934,8 @@ static int UsbDdkPnpLoaderRemoveDevice(const struct IDevmgrService *devmgrSvc,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int UsbDdkPnpLoaderDevice(const struct UsbPnpNotifyMatchInfoTable *infoTable,
|
||||
const struct IDevmgrService *super, uint32_t id)
|
||||
static int UsbDdkPnpLoaderDevice(struct HdfDeviceObject *usbPnpManagerDevice,
|
||||
const struct UsbPnpNotifyMatchInfoTable *infoTable, uint32_t id)
|
||||
{
|
||||
int8_t i;
|
||||
int32_t tableCount;
|
||||
@@ -868,7 +947,7 @@ static int UsbDdkPnpLoaderDevice(const struct UsbPnpNotifyMatchInfoTable *infoTa
|
||||
}
|
||||
|
||||
for (i = 0; i < infoTable->numInfos; i++) {
|
||||
UsbDdkPnpLoaderAddDevice(id, i, super, infoTable, g_usbPnpMatchIdTable);
|
||||
UsbDdkPnpLoaderAddDevice(id, i, usbPnpManagerDevice, infoTable, g_usbPnpMatchIdTable);
|
||||
}
|
||||
|
||||
for (tableCount = 0, idTable = g_usbPnpMatchIdTable[0]; idTable != NULL;
|
||||
@@ -942,14 +1021,14 @@ OUT:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int UsbDdkPnpLoaderEventReceived(void *priv, uint32_t id, struct HdfSBuf *data)
|
||||
int UsbDdkPnpLoaderEventReceived(void *usbPnpManagerPtr, uint32_t id, struct HdfSBuf *data)
|
||||
{
|
||||
int ret;
|
||||
bool flag = false;
|
||||
uint32_t infoSize;
|
||||
struct UsbPnpNotifyMatchInfoTable *infoTable = NULL;
|
||||
struct IDevmgrService *super = (struct IDevmgrService *)priv;
|
||||
struct UsbPnpRemoveInfo removeInfo;
|
||||
struct HdfDeviceObject *usbPnpManagerDevice = (struct HdfDeviceObject *)usbPnpManagerPtr;
|
||||
|
||||
flag = HdfSbufReadBuffer(data, (const void **)(&infoTable), &infoSize);
|
||||
if ((flag == false) || (infoTable == NULL)) {
|
||||
@@ -971,7 +1050,7 @@ int UsbDdkPnpLoaderEventReceived(void *priv, uint32_t id, struct HdfSBuf *data)
|
||||
#if USB_PNP_NOTIFY_TEST_MODE == true
|
||||
case USB_PNP_NOTIFY_ADD_TEST:
|
||||
#endif
|
||||
ret = UsbDdkPnpLoaderDevice(infoTable, super, id);
|
||||
ret = UsbDdkPnpLoaderDevice(usbPnpManagerDevice, infoTable, id);
|
||||
break;
|
||||
case USB_PNP_NOTIFY_REMOVE_INTERFACE:
|
||||
case USB_PNP_NOTIFY_REMOVE_DEVICE:
|
||||
@@ -983,7 +1062,7 @@ int UsbDdkPnpLoaderEventReceived(void *priv, uint32_t id, struct HdfSBuf *data)
|
||||
removeInfo.devNum = infoTable->devNum;
|
||||
removeInfo.busNum = infoTable->busNum;
|
||||
removeInfo.interfaceNum = infoTable->interfaceInfo[0].interfaceNumber;
|
||||
ret = UsbDdkPnpLoaderRemoveDevice(super, removeInfo, id);
|
||||
ret = UsbDdkPnpLoaderRemoveDevice(usbPnpManagerDevice, removeInfo, id);
|
||||
break;
|
||||
default:
|
||||
ret = HDF_ERR_INVALID_PARAM;
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
#include "sample_driver_test.h"
|
||||
#include "devsvc_manager_clnt.h"
|
||||
#include "devmgr_service.h"
|
||||
#include "devsvc_manager_clnt.h"
|
||||
#include "hdf_device_object.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_pm.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG sample_driver_test
|
||||
|
||||
@@ -18,17 +19,58 @@
|
||||
#define INT32_MAX 0x7fffffff
|
||||
#endif
|
||||
|
||||
struct SampleTestDevice {
|
||||
struct DListHead listNode;
|
||||
struct HdfDeviceObject *devobj;
|
||||
};
|
||||
|
||||
struct DListHead g_sampleDeviceList = { NULL };
|
||||
|
||||
#define REGISTER_DEV_MAX 16
|
||||
struct HdfDeviceObject *g_resistedDevice[REGISTER_DEV_MAX] = { 0 };
|
||||
|
||||
static void SaveRegistedDevice(struct SampleTestDevice *sampleDev)
|
||||
{
|
||||
if (g_sampleDeviceList.next == NULL) {
|
||||
DListHeadInit(&g_sampleDeviceList);
|
||||
}
|
||||
DListInsertTail(&sampleDev->listNode, &g_sampleDeviceList);
|
||||
}
|
||||
|
||||
struct SampleTestDevice *GetRegistedDevice(const char *serviceName)
|
||||
{
|
||||
struct SampleTestDevice *sampleDev = NULL;
|
||||
struct SampleTestDevice *sampleDevTmp = NULL;
|
||||
DLIST_FOR_EACH_ENTRY_SAFE(sampleDev, sampleDevTmp, &g_sampleDeviceList, struct SampleTestDevice, listNode) {
|
||||
if (sampleDev->devobj == NULL || HdfDeviceGetServiceName(sampleDev->devobj) == NULL) {
|
||||
DListRemove(&sampleDev->listNode);
|
||||
OsalMemFree(sampleDev);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strcmp(HdfDeviceGetServiceName(sampleDev->devobj), serviceName) == 0) {
|
||||
return sampleDev;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void HdfSampleDriverRelease(struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
(void)deviceObject;
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t SampleDriverRegisterDevice(struct HdfSBuf *data)
|
||||
int32_t SampleDriverRegisterDevice(struct HdfDeviceObject *dev, struct HdfSBuf *data)
|
||||
{
|
||||
const char *moduleName = NULL;
|
||||
const char *serviceName = NULL;
|
||||
struct HdfDeviceObject *devObj = NULL;
|
||||
struct SampleTestDevice *sampleDev = NULL;
|
||||
int ret;
|
||||
|
||||
HDF_LOGI("%s:called", __func__);
|
||||
if (data == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
@@ -42,17 +84,42 @@ int32_t SampleDriverRegisterDevice(struct HdfSBuf *data)
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
devObj = HdfRegisterDevice(moduleName, serviceName, NULL);
|
||||
devObj = HdfDeviceObjectAlloc(dev, moduleName);
|
||||
if (devObj == NULL) {
|
||||
HDF_LOGE("faild to alloc new device for %s", moduleName);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
|
||||
ret = HdfDeviceObjectRegister(devObj);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("faild to register device for %s", moduleName);
|
||||
HdfDeviceObjectRelease(devObj);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = HdfDeviceObjectPublishService(devObj, serviceName, SERVICE_POLICY_CAPACITY, 0664);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("faild to publish service for %s", serviceName);
|
||||
HdfDeviceObjectRelease(devObj);
|
||||
return ret;
|
||||
}
|
||||
|
||||
sampleDev = OsalMemAlloc(sizeof(struct SampleTestDevice));
|
||||
if (sampleDev == NULL) {
|
||||
HdfDeviceObjectRelease(devObj);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
sampleDev->devobj = devObj;
|
||||
SaveRegistedDevice(sampleDev);
|
||||
HDF_LOGI("register device %s:%s success", moduleName, serviceName);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t SampleDriverUnregisterDevice(struct HdfSBuf *data)
|
||||
{
|
||||
const char *moduleName = NULL;
|
||||
const char *serviceName = NULL;
|
||||
struct SampleTestDevice *dev = NULL;
|
||||
if (data == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
@@ -65,7 +132,15 @@ int32_t SampleDriverUnregisterDevice(struct HdfSBuf *data)
|
||||
if (serviceName == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfUnregisterDevice(moduleName, serviceName);
|
||||
dev = GetRegistedDevice(serviceName);
|
||||
if (dev == NULL) {
|
||||
HDF_LOGE("failed to found device %s", serviceName);
|
||||
return HDF_DEV_ERR_NO_DEVICE;
|
||||
}
|
||||
HdfDeviceObjectRelease(dev->devobj);
|
||||
DListRemove(&dev->listNode);
|
||||
OsalMemFree(dev);
|
||||
HDF_LOGI("unregister device %s:%s success", moduleName, serviceName);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -96,7 +171,7 @@ int32_t SampleDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct
|
||||
}
|
||||
switch (cmdId) {
|
||||
case SAMPLE_DRIVER_REGISTER_DEVICE: {
|
||||
ret = SampleDriverRegisterDevice(data);
|
||||
ret = SampleDriverRegisterDevice(client->device, data);
|
||||
HdfSbufWriteInt32(reply, ret);
|
||||
break;
|
||||
}
|
||||
@@ -105,7 +180,7 @@ int32_t SampleDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct
|
||||
HdfSbufWriteInt32(reply, ret);
|
||||
break;
|
||||
case SAMPLE_DRIVER_SENDEVENT_SINGLE_DEVICE:
|
||||
ret = SampleDriverSendEvent(client, cmdId, data, false);
|
||||
ret = SampleDriverSendEvent(client, cmdId, data, false);
|
||||
HdfSbufWriteInt32(reply, INT32_MAX);
|
||||
break;
|
||||
case SAMPLE_DRIVER_SENDEVENT_BROADCAST_DEVICE:
|
||||
@@ -169,7 +244,7 @@ struct SampleDriverPmListener {
|
||||
|
||||
int HdfSampleDriverInit(struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
static struct SampleDriverPmListener pmListener = {0};
|
||||
static struct SampleDriverPmListener pmListener = { 0 };
|
||||
int ret;
|
||||
HDF_LOGI("%s::enter!", __func__);
|
||||
if (deviceObject == NULL) {
|
||||
@@ -189,7 +264,6 @@ int HdfSampleDriverInit(struct HdfDeviceObject *deviceObject)
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
struct HdfDriverEntry g_sampleDriverEntry = {
|
||||
.moduleVersion = 1,
|
||||
.moduleName = "sample_driver",
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "hcs_parser.h"
|
||||
#include "hcs_blob_if.h"
|
||||
#include "hcs_generate_tree.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG hcs_parser
|
||||
|
||||
#include "hcs_blob_if.h"
|
||||
#include "hcs_parser.h"
|
||||
#include "hcs_tree_if.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_log.h"
|
||||
|
||||
static struct DeviceResourceNode *g_hcsTreeRoot = NULL;
|
||||
|
||||
void __attribute__((weak)) HdfGetBuildInConfigData(const unsigned char **data, unsigned int *size);
|
||||
|
||||
static bool BuildHcsTree(void)
|
||||
{
|
||||
uint32_t length;
|
||||
const unsigned char *hcsBlob = NULL;
|
||||
if (HdfGetBuildInConfigData == NULL) {
|
||||
HDF_LOGE("no build-in hdf config");
|
||||
return false;
|
||||
}
|
||||
HdfGetBuildInConfigData(&hcsBlob, &length);
|
||||
if (!HcsCheckBlobFormat((const char *)hcsBlob, length)) {
|
||||
return false;
|
||||
}
|
||||
if (!HcsDecompile((const char *)hcsBlob, HBC_HEADER_LENGTH, &g_hcsTreeRoot)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const struct DeviceResourceNode *HcsGetRootNode(void)
|
||||
{
|
||||
if (g_hcsTreeRoot == NULL && !BuildHcsTree()) {
|
||||
HDF_LOGE("failed to rebuild config tree");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (g_hcsTreeRoot == NULL) {
|
||||
HDF_LOGE("failed to get build-in hcs root node");
|
||||
}
|
||||
return g_hcsTreeRoot;
|
||||
}
|
||||
@@ -767,4 +767,5 @@ HWTEST_F(HdfConfigTest, HslTestMacroTraversalOneFile, TestSize.Level1)
|
||||
printf("HdfConfigTest last enter\n\r");
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -225,7 +225,7 @@ bool HdfSListIteratorHasNext(struct HdfSListIterator *iterator)
|
||||
|
||||
struct HdfSListNode *HdfSListIteratorNext(struct HdfSListIterator *iterator)
|
||||
{
|
||||
if ((iterator == NULL) || (iterator->curr == NULL) || (iterator->prev == NULL)) {
|
||||
if (iterator == NULL || iterator->curr == NULL || iterator->prev == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ struct HdfSListNode *HdfSListIteratorNext(struct HdfSListIterator *iterator)
|
||||
|
||||
void HdfSListIteratorRemove(struct HdfSListIterator *iterator)
|
||||
{
|
||||
if ((iterator == NULL) || (iterator->curr == NULL) || (iterator->prev == NULL)) {
|
||||
if (iterator == NULL || iterator->curr == NULL || iterator->prev == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user