• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "hdf_chip.h"
10 #include "hdf_chip_config.h"
11 #include "hdf_device_desc.h"
12 #include "hdf_power.h"
13 #include "hdf_reset.h"
14 #include "osal/osal_mem.h"
15 
CreateVirtualDevice(struct HdfChipConfig * config)16 struct HdfVirtualDevice *CreateVirtualDevice(struct HdfChipConfig *config) {
17     struct HdfVirtualDevice *device = NULL;
18     int32_t ret = HDF_SUCCESS;
19     if (config == NULL) {
20         return NULL;
21     }
22     device = (struct HdfVirtualDevice *)OsalMemCalloc(sizeof(struct HdfVirtualDevice));
23     if (device == NULL) {
24         return NULL;
25     }
26     do {
27         device->name = config->name;
28 
29         device->power = CreateVirtualPower(config->powers);
30         if (device->power == NULL) {
31             ret = HDF_FAILURE;
32             break;
33         }
34 
35         device->reset = CreateVirtualReset(&config->reset);
36         if (device->reset == NULL) {
37             ret = HDF_FAILURE;
38             break;
39         }
40     } while (false);
41 
42     if (ret != HDF_SUCCESS) {
43         ReleaseVirtualDevice(device);
44         device = NULL;
45     }
46     return device;
47 }
ReleaseVirtualDevice(struct HdfVirtualDevice * device)48 void ReleaseVirtualDevice(struct HdfVirtualDevice *device) {
49     if (device == NULL) {
50         return;
51     }
52     if (device->power != NULL && device->power->ops != NULL && device->power->ops->Release != NULL) {
53         device->power->ops->Release(device->power);
54         device->power = NULL;
55     }
56 
57     if (device->reset != NULL && device->reset->ops != NULL && device->reset->ops->Release != NULL) {
58         device->reset->ops->Release(device->reset);
59         device->reset = NULL;
60     }
61     OsalMemFree(device);
62 }
63