[IE][VPU][XLink]: XLink semaphore wrappers impl (#3079)
[platform/upstream/dldt.git] / inference-engine / thirdparty / movidius / XLink / shared / include / XLinkPrivateDefines.h
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 ///
6 /// @file
7 ///
8 /// @brief     Application configuration Leon header
9 ///
10 #ifndef _XLINKPRIVATEDEFINES_H
11 #define _XLINKPRIVATEDEFINES_H
12
13 #include "XLinkStream.h"
14
15 #if !defined(XLINK_ALIGN_TO_BOUNDARY)
16 # if defined(_WIN32) && !defined(__GNUC__)
17 #  define XLINK_ALIGN_TO_BOUNDARY(_n) __declspec(align(_n))
18 # else
19 #  define XLINK_ALIGN_TO_BOUNDARY(_n) __attribute__((aligned(_n)))
20 # endif
21 #endif  // XLINK_ALIGN_TO_BOUNDARY
22
23 #ifdef __cplusplus
24 extern "C"
25 {
26 #endif
27
28 #define MAXIMUM_SEMAPHORES 32
29 #define __CACHE_LINE_SIZE 64
30
31 typedef int32_t eventId_t;
32
33 /**
34  * @brief State for xLinkDesc_t
35  */
36 typedef enum {
37     XLINK_NOT_INIT,
38     XLINK_UP,
39     XLINK_DOWN,
40 }xLinkState_t;
41
42 /**
43  * @brief Device description
44  */
45 typedef struct xLinkDeviceHandle_t {
46     XLinkProtocol_t protocol;
47     void* xLinkFD;
48 } xLinkDeviceHandle_t;
49
50 /**
51  * @brief XLink primitive for each device
52  */
53 typedef struct xLinkDesc_t {
54     // Incremental number, doesn't get decremented.
55     uint32_t nextUniqueStreamId;
56     streamDesc_t availableStreams[XLINK_MAX_STREAMS];
57     xLinkState_t peerState;
58     xLinkDeviceHandle_t deviceHandle;
59     linkId_t id;
60     XLink_sem_t dispatcherClosedSem;
61
62     //Deprecated fields. Begin.
63     int hostClosedFD;
64     //Deprecated fields. End.
65
66 } xLinkDesc_t;
67
68 streamId_t XLinkAddOrUpdateStream(void *fd, const char *name,
69                                   uint32_t writeSize, uint32_t readSize, streamId_t forcedId);
70
71 //events which are coming from remote
72 typedef enum
73 {
74     /*USB-X_LINK_PCIE related events*/
75     XLINK_WRITE_REQ,
76     XLINK_READ_REQ,
77     XLINK_READ_REL_REQ,
78     XLINK_CREATE_STREAM_REQ,
79     XLINK_CLOSE_STREAM_REQ,
80     XLINK_PING_REQ,
81     XLINK_RESET_REQ,
82     XLINK_REQUEST_LAST,
83     //note that is important to separate request and response
84     XLINK_WRITE_RESP,
85     XLINK_READ_RESP,
86     XLINK_READ_REL_RESP,
87     XLINK_CREATE_STREAM_RESP,
88     XLINK_CLOSE_STREAM_RESP,
89     XLINK_PING_RESP,
90     XLINK_RESET_RESP,
91     XLINK_RESP_LAST,
92
93     /*X_LINK_IPC related events*/
94     IPC_WRITE_REQ,
95     IPC_READ_REQ,
96     IPC_CREATE_STREAM_REQ,
97     IPC_CLOSE_STREAM_REQ,
98     //
99     IPC_WRITE_RESP,
100     IPC_READ_RESP,
101     IPC_CREATE_STREAM_RESP,
102     IPC_CLOSE_STREAM_RESP,
103 } xLinkEventType_t;
104
105 typedef enum
106 {
107     EVENT_LOCAL,
108     EVENT_REMOTE,
109 } xLinkEventOrigin_t;
110
111 #ifdef __PC__
112 #define MAX_LINKS 32
113 #else
114 #define MAX_LINKS 1
115 #endif
116
117 #define MAX_EVENTS 64
118 #define MAX_SCHEDULERS MAX_LINKS
119 #define XLINK_MAX_DEVICES MAX_LINKS
120
121 typedef struct xLinkEventHeader_t{
122     eventId_t           id;
123     xLinkEventType_t    type;
124     char                streamName[MAX_STREAM_NAME_LENGTH];
125     streamId_t          streamId;
126     uint32_t            size;
127     union{
128         uint32_t raw;
129         struct{
130             uint32_t ack : 1;
131             uint32_t nack : 1;
132             uint32_t block : 1;
133             uint32_t localServe : 1;
134             uint32_t terminate : 1;
135             uint32_t bufferFull : 1;
136             uint32_t sizeTooBig : 1;
137             uint32_t noSuchStream : 1;
138         }bitField;
139     }flags;
140 }xLinkEventHeader_t;
141
142 typedef struct xLinkEvent_t {
143     XLINK_ALIGN_TO_BOUNDARY(64) xLinkEventHeader_t header;
144     xLinkDeviceHandle_t deviceHandle;
145     void* data;
146 }xLinkEvent_t;
147
148 #define XLINK_INIT_EVENT(event, in_streamId, in_type, in_size, in_data, in_deviceHandle) do { \
149     (event).header.streamId = (in_streamId); \
150     (event).header.type = (in_type); \
151     (event).header.size = (in_size); \
152     (event).data = (in_data); \
153     (event).deviceHandle = (in_deviceHandle); \
154 } while(0)
155
156 #define XLINK_EVENT_ACKNOWLEDGE(event) do { \
157     (event)->header.flags.bitField.ack = 1; \
158     (event)->header.flags.bitField.nack = 0; \
159 } while(0)
160
161 #define XLINK_EVENT_NOT_ACKNOWLEDGE(event) do { \
162     (event)->header.flags.bitField.ack = 0; \
163     (event)->header.flags.bitField.nack = 1; \
164 } while(0)
165
166 #define XLINK_SET_EVENT_FAILED_AND_SERVE(event) do { \
167     XLINK_EVENT_NOT_ACKNOWLEDGE(event); \
168     (event)->header.flags.bitField.localServe = 1; \
169 } while(0)
170
171 #ifdef __cplusplus
172 }
173 #endif
174
175 #endif
176
177 /* end of include file */