summaryrefslogtreecommitdiff
path: root/drivers/staging/nmf-cm/cm/engine/component/inc/bind.h
blob: 325703e33675c2ba3a1b912101bffa9931e1dc80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
/*
 * Copyright (C) ST-Ericsson SA 2010
 * Author: Jean-Philippe FASSINO <jean-philippe.fassino@stericsson.com> for ST-Ericsson.
 * License terms: GNU General Public License (GPL) version 2.
 */
/**
 * \internal
 * \brief Binding Factories internal API.
 *
 * \defgroup BF_COMMON Binding factories: Common API
 * \defgroup BF_PRIMITIVE Binding Factories: Primitive API
 * \defgroup BF_TRACE Binding Factories: Trace API
 * \defgroup BF_ASYNCHRONOUS Binding Factories: Asynchronous API
 * \defgroup BF_DISTRIBUTED Binding Factories: Distributed API
 */
#ifndef __INC_CM_BIND_H
#define __INC_CM_BIND_H

#include <cm/engine/component/inc/introspection.h>
#include <cm/engine/communication/inc/communication.h>
#include <cm/engine/utils/inc/table.h>

/**
 * \internal
 * \ingroup BF_COMMON
 *
 * \brief Identification number of prefedined Binding Factories
 */
typedef enum {
    BF_SYNCHRONOUS,     //!< Intra-DSP Synchronous Binding Factory Identifier
    BF_TRACE,           //!< Intra-DSP trace synchronous Binding Factory Identifier
    BF_ASYNCHRONOUS, 	//!< Intra-DSP Asynchronous Binding Factory Identifier
    BF_DSP2HOST,        //!< DSP to Host Binding Factory Identifier
    BF_HOST2DSP,        //!< Host to DSP Binding Factory Identifier
    BF_DSP2DSP,         //!< DSP to DSP Binding Factory Identifier
} t_bf_info_ID;

/*!
 * \internal
 * \brief Description of a provided interface
 *
 * \ingroup COMPONENT_INTERNAL
 */
typedef struct _t_interface_reference {
	const t_component_instance          *instance;      //!< Component instance that provide this interface
    t_uint8                             provideIndex;   //!< Index of the interface in the provide array
    t_uint8                             collectionIndex;//!< Index in the collection if provided interface is a collection
    t_bf_info_ID                        bfInfoID;       //!< Identification of BF used for creating binding
    void*                               bfInfo;         //!< Storage of the binding factory info
} t_interface_reference;

/**
 * \internal
 * \ingroup BF_COMMON
 *
 * Make some basic sanity check for a client:
 *  - component stopped
 *  - Interface really required
 *
 * \param[in] client The client component instance handle.
 * \param[in] requiredItfClientName The client required interface name
 * \param[out] requiredItf return the required interface (avoid user searching)
 */
t_cm_error cm_checkValidClient(
        const t_component_instance* client,
        const char* requiredItfClientName,
        t_interface_require_description *itfRequire,
        t_bool *bindable);
/**
 * \internal
 * \ingroup BF_COMMON
 *
 * Make some basic sanity check for a server:
 *  - Interface really provided
 *
 * \param[in] server The server component instance handle.
 * \param[in] providedItfServerName The server provided interface name
 * \param[out] itf return the provided interface (avoid user searching)
 */
t_cm_error cm_checkValidServer(
        const t_component_instance* server,
        const char* providedItfServerName,
        t_interface_provide_description *itfProvide);

/**
 * \internal
 * \ingroup BF_COMMON
 *
 * Make some basic sanity check for a binding:
 *  - Sanity check for a server
 *  - Sanity check for a client (and potentially wait initialisation)
 *  - Provided and required interface matches
 *
 * \param[in] client The client component instance handle
 * \param[in] requiredItfClientName The client required interface name
 * \param[in] server The server component instance handle
 * \param[in] providedItfServerName The server provided interface name
 * \param[out] requiredItf return the required interface (avoid user searching)
 * \param[out] itf return the provided interface (avoid user searching)
 */
t_cm_error cm_checkValidBinding(
        const t_component_instance* client,
        const char* requiredItfClientName,
        const t_component_instance* server,
        const char* requiredItfServerName,
        t_interface_require_description *itfRequire,
        t_interface_provide_description *itfProvide,
        t_bool *bindable);

/**
 * \internal
 * \ingroup BF_COMMON
 *
 * Make some basic sanity check for each unbinding:
 *  - Interface really required
 *  - Component stopped
 *
 * \param[in] client The client component instance handle
 * \param[in] requiredItfClientName The client required interface name
 * \param[out] itfRequire return the previously binded required interface (avoid user searching)
 * \param[out] itfProvide return the previously binded provided interface (avoid user searching)
 * \param[out] bfInfoID return the binding factory identifiant which done the previously bind
 * \param[out] bfInfo return the binding factory information which done the previously bind
 */
t_cm_error cm_checkValidUnbinding(
        const t_component_instance* client,
        const char* requiredItfClientName,
        t_interface_require_description *itfRequire,
        t_interface_provide_description *itfProvide);

/**
 * \internal
 * \ingroup BF_PRIMITIVE
 *
 * Create a primitive binding between a client to a server interface.
 *
 * \param[in] itfRequire The client required interface description
 * \param[in] itfProvide The server provided interface description
 */
t_cm_error cm_bindInterface(
        const t_interface_require_description *itfRequire,
        const t_interface_provide_description *itfProvide);

/**
 * \internal
 * \ingroup BF_PRIMITIVE
 *
 * Unbind a previously binded client.
 *
 * \param[in] itfRequire The client required interafce description
 */
void cm_unbindInterface(
        const t_interface_require_description *itfRequire);

/**
 * \internal
 * \ingroup BF_PRIMITIVE
 *
 * Get a server interface previouly binded to a client
 *
 * \param[in] client The client component instance handle
 * \param[in] requiredItfClientName The client required interface name
 * \param[out] itf The server interface
 */
t_cm_error cm_lookupInterface(
        const t_interface_require_description *itfRequire,
        t_interface_provide_description *itfProvide);

/**
 * \internal
 * \ingroup BF_PRIMITIVE
 *
 * Create a void binding.
 *
 * \param[in] client The client component instance handle
 * \param[in] requiredItfClientName The client required interface name
 */
t_cm_error cm_bindInterfaceToVoid(
        const t_interface_require_description *itfRequire);

/**
 * \internal
 * \ingroup BF_TRACE
 *
 * Trace synchronous binding factory Information
 */
typedef struct {
    t_component_instance    *traceInstance;   //!< Trace binding component instance
} t_trace_bf_info;

/**
 * \internal
 * \ingroup BF_TRACE
 *
 * Create a traced binding between a client to a server interface.
 *
 * \param[in] itfRequire The client required interface description
 * \param[in] itfProvide The server provided interface description
 */
t_cm_error cm_bindInterfaceTrace(
        const t_interface_require_description *itfRequire,
        const t_interface_provide_description *itfProvide,
        t_elfdescription *elfhandleTrace);

/**
 * \internal
 * \ingroup BF_TRACE
 *
 * Unbind a previously binded client.
 *
 * \param[in] itfRequire The client required interafce description
 */
void cm_unbindInterfaceTrace(
        const t_interface_require_description *itfRequire,
        t_trace_bf_info                       *bfInfo);


/**
 * \internal
 * \ingroup BF_ASYNCHRONOUS
 *
 * Asynchronous binding factory Information
 */
typedef struct {
    t_component_instance 	*eventInstance;   //!< Event binding component instance
    t_memory_handle 		dspfifoHandle;    //!< Memory handle of allocated event fifo (pass to the event binding component)
} t_async_bf_info;

/**
 * \internal
 * \ingroup BF_ASYNCHRONOUS
 *
 * Create a asynchronous binding between a client to a server interface.
 * \param[in] client The client component instance handle
 * \param[in] requiredItfClientName The client required interface name
 * \param[in] itf The server interface
 * \param[in] fifosize Number of waited event in the fifo
 */
t_cm_error cm_bindInterfaceAsynchronous(
        const t_interface_require_description *itfRequire,
        const t_interface_provide_description *itfProvide,
        t_uint32 fifosize,
        t_dsp_memory_type_id dspEventMemType,
        t_elfdescription *elfhandleEvent);
/**
 * \internal
 * \ingroup BF_ASYNCHRONOUS
 *
 * Destroy a asynchronous binding between a client to a server interface.
 * \param[in] itfRequire the required interface
 */
void cm_unbindInterfaceAsynchronous(
        const t_interface_require_description   *itfRequire,
        t_async_bf_info                         *bfInfo);

/**
 * \internal
 * \ingroup BF_DISTRIBUTED
 *
 * Stub information in distributed binding factory (client side)
 */
typedef struct {
    t_component_instance    *stubInstance;      //!< Stub
} t_dspstub_bf_info;

/**
 * \internal
 * \ingroup BF_DISTRIBUTED
 *
 * Skeleton information in distributed binding factory (server side)
 */
typedef struct {
    t_component_instance    *skelInstance;      //!< Skeleton binding component instance
    t_memory_handle         dspfifoHandle;      //!< Memory handle of allocated event fifo (pass to the event binding component)
} t_dspskel_bf_info;

/**
 * \internal
 * \ingroup BF_DISTRIBUTED
 *
 * Host to DSP distributed binding factory Information
 */
typedef struct {
    t_dspskel_bf_info       dspskeleton;            //!< Information about the DSP skeleton (server side)
    t_nmf_fifo_arm_desc*    fifo;                   //!< Handle of the fifo params
    t_nmf_client_id         clientId;               //!< Client ID of the host client
} t_host2mpc_bf_info;

/*
 * Table of instantiated of host2mpc bindings
 */
extern t_nmf_table Host2MpcBindingTable; /**< list (table) of host2mpc bindings */

/**
 * \internal
 * \ingroup BF_DISTRIBUTED
 *
 * Create a Host to DSP distributed binding between a host client interface to a server interface.
 * (Not manage in the same way as distributed binding since the Host programming model is not component aware).
 * \param[in] itfServer The server interface
 * \param[in] fifosize Number of waited event in the fifo
 * \param[in] dspEventMemType The type of memory to use
 * \param[in] bfInfo info structure
 */
t_cm_error cm_bindComponentFromCMCore(
        const t_interface_provide_description *itfProvide,
        t_uint32 fifosize,
        t_dsp_memory_type_id dspEventMemType,
        t_elfdescription *elfhandleSkeleton,
        t_host2mpc_bf_info **bfInfo);

/**
 * \internal
 * \ingroup BF_DISTRIBUTED
 *
 * Destroy a Host to DSP distributed binding between a host client interface to a server interface.
 * \param[in] bfInfo The Host to DSP distributed binding factory information
 */
void cm_unbindComponentFromCMCore(
        t_host2mpc_bf_info *bfInfo);

/**
 * \internal
 * \ingroup BF_DISTRIBUTED
 *
 * DSP to Host distributed binding factory Information
 */
typedef struct {
    t_dspstub_bf_info           dspstub;            //!< Information about the DSP stub (client side)
    t_nmf_fifo_arm_desc*        fifo;               //!< Handle of the fifo params
    t_uint32                    context;
} t_mpc2host_bf_info;

/**
 * \internal
 * \ingroup BF_DISTRIBUTED
 *
 * Create a DSP to Host distributed binding between a client interface to a host server interface.
 * (Not manage in the same way as distributed binding since the Host programming model is not component aware).
 * \param[in] client The client component instance handle
 * \param[in] requiredItfClientName The client required interface name
 * \param[in] itfref The host server interface to be called
 * \param[in] fifosize Number of waited event in the fifo
 */
t_cm_error cm_bindComponentToCMCore(
        const t_interface_require_description   *itfRequire,
        t_uint32                                fifosize,
        t_uint32                                context,
        t_elfdescription                        *elfhandleStub,
        t_mpc2host_bf_info                      ** bfInfo);

/**
 * \internal
 * \ingroup BF_DISTRIBUTED
 *
 * Destroy a DSP to Host distributed binding between a client interface to a server interface.
 * \param[in] itfRequire The required interface
 * \param[out] upLayerThis The 'THIS' context of upper layer
 */
void cm_unbindComponentToCMCore(
        const t_interface_require_description   *itfRequire,
        t_mpc2host_bf_info                      *bfInfo);

/**
 * \internal
 * \ingroup BF_DISTRIBUTED
 *
 * Asynchronous distributed binding factory Information
 */
typedef struct {
    t_nmf_fifo_arm_desc*    fifo;                   //!< Handle of the fifo params
    t_dspstub_bf_info       dspstub;                //!< Information about the DSP stub (client side)
    t_dspskel_bf_info       dspskeleton;            //!< Information about the DSP skeleton (server side)
} t_mpc2mpc_bf_info;

/**
 * \internal
 * \ingroup BF_DISTRIBUTED
 *
 * Create a asynchronous distributed binding between a client interface to a server interface.
 * \param[in] client The client component instance handle
 * \param[in] requiredItfClientName The client required interface name
 * \param[in] itf The server interface
 * \param[in] fifosize Number of waited event in the fifo
 */
t_cm_error cm_bindInterfaceDistributed(
        const t_interface_require_description *itfRequire,
        const t_interface_provide_description *itfProvide,
        t_uint32 fifosize,
        t_dsp_memory_type_id dspEventMemType,
        t_elfdescription                        *elfhandleSkeleton,
        t_elfdescription                        *elfhandleStub);

/**
 * \internal
 * \ingroup BF_DISTRIBUTED
 *
 * Destroy a asynchronous distributed binding between a client interface to a server interface.
 * \param[in] itfRequire The required interface
 */
void cm_unbindInterfaceDistributed(
        const t_interface_require_description   *itfRequire,
        t_mpc2mpc_bf_info                       *bfInfo);

/**
 * \internal
 *
 * Bind a static interrupt to server provide interface name.
 * \param[in] coreId The core to which component is loaded
 * \param[in] interruptLine Interrupt line number to use
 * \param[in] server Server instance that provide interrupt service
 * \param[in] providedItfServerName Interface name hat provide interrupt service
 */
t_cm_error cm_bindInterfaceStaticInterrupt(
        const t_nmf_core_id coreId,
        const int interruptLine,
        const t_component_instance *server,
        const char* providedItfServerName);

/**
 * \internal
 *
 * Unbind a static interrupt.
 * \param[in] coreId The core to which component is loaded
 * \param[in] interruptLine Interrupt line number to use
 */
t_cm_error cm_unbindInterfaceStaticInterrupt(
        const t_nmf_core_id coreId,
        const int interruptLine);

void cm_destroyRequireInterface(t_component_instance* component, t_nmf_client_id clientId);
void cm_registerSingletonBinding(
        t_component_instance*                   component,
        t_interface_require_description*        itfRequire,
        t_interface_provide_description*        itfProvide,
        t_nmf_client_id                         clientId);
t_bool cm_unregisterSingletonBinding(
        t_component_instance*                   component,
        t_interface_require_description*        itfRequire,
        t_interface_provide_description*        itfProvide,
        t_nmf_client_id                         clientId);

#endif