• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-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 #ifndef HDF_DEVICE_H
10 #define HDF_DEVICE_H
11 
12 #include "hdf_dlist.h"
13 #include "hdf_object.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif /* __cplusplus */
18 
19 /*
20  * -----------------+----------------+----------------+----------------+
21  * |      BYTE      |      BYTE      |      BYTE      |      BYTE      |
22  * +---------------------------------+---------------------------------+
23  * |    host id     |             device id           | device node id |
24  * -----------------+---------------------------------+----------------+
25  */
26 typedef uint32_t devid_t;
27 
28 #define HOSTID_BITS 8
29 #define DEVICEID_BITS 16
30 #define DEVNODEID_BITS 8
31 #define DEVNODEID_MASK ((1 << DEVNODEID_BITS) - 1)
32 #define DEVICEID_MASK ((1 << DEVICEID_BITS) - 1)
33 
34 #define HOSTID(devid) (((uint32_t)(devid)) >> (DEVICEID_BITS + DEVNODEID_BITS))
35 #define DEVICEID(devid) ((((uint32_t)(devid)) >> DEVNODEID_BITS) & DEVICEID_MASK)
36 #define DEVNODEID(devid) (((uint32_t)(devid)) & DEVNODEID_MASK)
37 
38 #define MK_DEVID(hostId, deviceId, devnodeId) \
39     (((uint16_t)(hostId) << (DEVICEID_BITS + DEVNODEID_BITS)) | ((deviceId) << DEVNODEID_BITS) | (devnodeId))
40 
41 struct HdfDeviceNode;
42 
43 struct IHdfDevice {
44     struct HdfObject object;
45     int (*Attach)(struct IHdfDevice *device, struct HdfDeviceNode *deviceNode);
46     int (*Detach)(struct IHdfDevice *device, struct HdfDeviceNode *deviceNode);
47     struct HdfDeviceNode *(*GetDeviceNode)(struct IHdfDevice *device, devid_t devid);
48     int (*DetachWithDevid)(struct IHdfDevice *device, devid_t devid);
49 };
50 
51 struct HdfDevice {
52     struct IHdfDevice super;
53     struct DListHead node;
54     struct DListHead devNodes;
55     devid_t deviceId;
56     uint16_t devidIndex;
57 };
58 int HdfDeviceDetach(struct IHdfDevice *devInst, struct HdfDeviceNode *devNode);
59 void HdfDeviceConstruct(struct HdfDevice *device);
60 void HdfDeviceDestruct(struct HdfDevice *device);
61 struct HdfObject *HdfDeviceCreate(void);
62 void HdfDeviceRelease(struct HdfObject *object);
63 struct HdfDevice *HdfDeviceNewInstance(void);
64 void HdfDeviceFreeInstance(struct HdfDevice *device);
65 
66 #ifdef __cplusplus
67 }
68 #endif /* __cplusplus */
69 
70 #endif /* HDF_DEVICE_H */
71