• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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(const struct HdfChipConfig * config)16 struct HdfVirtualDevice *CreateVirtualDevice(const struct HdfChipConfig *config)
17 {
18     struct HdfVirtualDevice *device = NULL;
19     int32_t ret = HDF_SUCCESS;
20     if (config == NULL) {
21         return NULL;
22     }
23     device = (struct HdfVirtualDevice *)OsalMemCalloc(sizeof(struct HdfVirtualDevice));
24     if (device == NULL) {
25         return NULL;
26     }
27     do {
28         device->name = config->name;
29 
30         device->power = CreateVirtualPower(config->powers);
31         if (device->power == NULL) {
32             ret = HDF_FAILURE;
33             break;
34         }
35 
36         device->reset = CreateVirtualReset(&config->reset);
37         if (device->reset == NULL) {
38             ret = HDF_FAILURE;
39             break;
40         }
41     } while (false);
42 
43     if (ret != HDF_SUCCESS) {
44         ReleaseVirtualDevice(device);
45         device = NULL;
46     }
47     return device;
48 }
ReleaseVirtualDevice(struct HdfVirtualDevice * device)49 void ReleaseVirtualDevice(struct HdfVirtualDevice *device)
50 {
51     if (device == NULL) {
52         return;
53     }
54     if (device->power != NULL && device->power->ops != NULL && device->power->ops->Release != NULL) {
55         device->power->ops->Release(device->power);
56         device->power = NULL;
57     }
58 
59     if (device->reset != NULL && device->reset->ops != NULL && device->reset->ops->Release != NULL) {
60         device->reset->ops->Release(device->reset);
61         device->reset = NULL;
62     }
63     OsalMemFree(device);
64 }
65