1
/*
2
 * Copyright (C) 2009-2010 Felipe Contreras
3
 *
4
 * Author: Felipe Contreras <felipe.contreras@gmail.com>
5
 *
6
 * This file may be used under the terms of the GNU Lesser General Public
7
 * License version 2.1, a copy of which is found in LICENSE included in the
8
 * packaging of this file.
9
 */
10
11
#ifndef DSP_BRIDGE_H
12
#define DSP_BRIDGE_H
13
14
#include <stdbool.h>
15
#include <stdint.h>
16
#include <stdlib.h>
17
18
#define ALLOCATE_HEAP
19
20
#define DSP_MMUFAULT 0x00000010
21
#define DSP_SYSERROR 0x00000020
22
#define DSP_NODEMESSAGEREADY 0x00000200
23
24
#define MAX_PROFILES 16
25
#define DSP_MAXNAMELEN 32
26
27
struct dsp_uuid {
28
	uint32_t field_1;
29
	uint16_t field_2;
30
	uint16_t field_3;
31
	uint8_t field_4;
32
	uint8_t field_5;
33
	uint8_t field_6[6];
34
};
35
36
struct dsp_node {
37
	void *handle;
38
	void *heap;
39
	void *msgbuf_addr;
40
	size_t msgbuf_size;
41
};
42
43
/* note: cmd = 0x20000000 has special handling */
44
struct dsp_msg {
45
	uint32_t cmd;
46
	uint32_t arg_1;
47
	uint32_t arg_2;
48
};
49
50
struct dsp_notification {
51
	char *name;
52
	void *handle;
53
};
54
55
struct dsp_node_attr_in {
56
	unsigned long cb;
57
	int priority;
58
	unsigned int timeout;
59
	unsigned int profile_id;
60
	unsigned int heap_size;
61
	void *gpp_va;
62
};
63
64
enum dsp_dcd_object_type {
65
	DSP_DCD_NODETYPE,
66
	DSP_DCD_PROCESSORTYPE,
67
	DSP_DCD_LIBRARYTYPE,
68
	DSP_DCD_CREATELIBTYPE,
69
	DSP_DCD_EXECUTELIBTYPE,
70
	DSP_DCD_DELETELIBTYPE,
71
};
72
73
enum dsp_node_type {
74
	DSP_NODE_DEVICE,
75
	DSP_NODE_TASK,
76
	DSP_NODE_DAISSOCKET,
77
	DSP_NODE_MESSAGE,
78
};
79
80
#ifdef ALLOCATE_HEAP
81
/* The dsp_resourcereqmts structure for node's resource requirements */
82
struct dsp_resourcereqmts {
83
	uint32_t cb_struct;
84
	uint32_t static_data_size;
85
	uint32_t global_data_size;
86
	uint32_t program_mem_size;
87
	uint32_t uwc_execution_time;
88
	uint32_t uwc_period;
89
	uint32_t uwc_deadline;
90
	uint32_t avg_exection_time;
91
	uint32_t minimum_period;
92
};
93
94
struct dsp_nodeprofs {
95
	uint32_t heap_size;
96
};
97
98
/* The dsp_ndb_props structure reports the attributes of a node */
99
struct dsp_ndb_props {
100
	uint32_t cb_struct;
101
	struct dsp_uuid node_id;
102
	char ac_name[DSP_MAXNAMELEN];
103
	enum dsp_node_type ntype;
104
	uint32_t cache_on_gpp;
105
	struct dsp_resourcereqmts dsp_resource_reqmts;
106
	int32_t prio;
107
	uint32_t stack_size;
108
	uint32_t sys_stack_size;
109
	uint32_t stack_seg;
110
	uint32_t message_depth;
111
	uint32_t num_input_streams;
112
	uint32_t num_output_streams;
113
	uint32_t timeout;
114
	uint32_t count_profiles; /* Number of supported profiles */
115
	struct dsp_nodeprofs node_profiles[MAX_PROFILES]; /* Array of profiles */
116
	uint32_t stack_seg_name; /* Stack Segment Name */
117
};
118
#endif
119
120
enum dsp_resource {
121
	DSP_RESOURCE_DYNDARAM = 0,
122
	DSP_RESOURCE_DYNSARAM,
123
	DSP_RESOURCE_DYNEXTERNAL,
124
	DSP_RESOURCE_DYNSRAM,
125
	DSP_RESOURCE_PROCLOAD,
126
};
127
128
struct dsp_info {
129
	unsigned long cb;
130
	enum dsp_resource type;
131
	union {
132
		unsigned long resource;
133
		struct {
134
			unsigned long size;
135
			unsigned long total_free_size;
136
			unsigned long len_max_free_block;
137
			unsigned long free_blocks;
138
			unsigned long alloc_blocks;
139
		} mem;
140
		struct {
141
			unsigned long load;
142
			unsigned long pred_load;
143
			unsigned long freq;
144
			unsigned long pred_freq;
145
		} proc;
146
	} result;
147
};
148
149
enum dsp_connect_type {
150
	CONNECTTYPE_NODEOUTPUT,
151
	CONNECTTYPE_GPPOUTPUT,
152
	CONNECTTYPE_NODEINPUT,
153
	CONNECTTYPE_GPPINPUT
154
};
155
156
struct dsp_stream_connect {
157
	unsigned long cb;
158
	enum dsp_connect_type type;
159
	unsigned int index;
160
	void *node_handle;
161
	struct dsp_uuid node_id;
162
	unsigned int stream_index;
163
};
164
165
enum dsp_stream_mode {
166
	STRMMODE_PROCCOPY,
167
	STRMMODE_ZEROCOPY,
168
	STRMMODE_LDMA,
169
	STRMMODE_RDMA
170
};
171
172
struct dsp_stream_attr {
173
	unsigned int seg_id;
174
	unsigned int buf_size;
175
	unsigned int num_bufs;
176
	unsigned int alignment;
177
	unsigned int timeout;
178
	enum dsp_stream_mode mode;
179
	unsigned int dma_chnl_id;
180
	unsigned int dma_priority;
181
};
182
183
struct dsp_stream_attr_in {
184
	unsigned long cb;
185
	unsigned int timeout;
186
	unsigned int segment;
187
	unsigned int alignment;
188
	unsigned int num_bufs;
189
	enum dsp_stream_mode mode;
190
	unsigned int dma_chnl_id;
191
	unsigned int dma_priority;
192
};
193
194
enum dsp_stream_state {
195
	STREAM_IDLE,
196
	STREAM_READY,
197
	STREAM_PENDING,
198
	STREAM_DONE
199
};
200
201
struct dsp_stream_info {
202
	unsigned long cb;
203
	unsigned int num_bufs_allowed;
204
	unsigned int num_bufs_in_stream;
205
	unsigned long num_bytes;
206
	void *sync_handle;
207
	enum dsp_stream_state state;
208
};
209
210
enum dsp_node_state {
211
	NODE_ALLOCATED,
212
	NODE_CREATED,
213
	NODE_RUNNING,
214
	NODE_PAUSED,
215
	NODE_DONE
216
};
217
218
struct dsp_node_info {
219
	unsigned long cb;
220
	struct dsp_ndb_props props;
221
	unsigned int priority;
222
	enum dsp_node_state state;
223
	void *owner;
224
	unsigned int num_streams;
225
	struct dsp_stream_connect streams[16];
226
	unsigned int node_env;
227
};
228
229
struct dsp_node_attr {
230
	unsigned long cb;
231
	struct dsp_node_attr_in attr_in;
232
	unsigned long inputs;
233
	unsigned long outputs;
234
	struct dsp_node_info info;
235
};
236
237
int dsp_open(void);
238
239
int dsp_close(int handle);
240
241
bool dsp_attach(int handle,
242
		unsigned int num,
243
		const void *info,
244
		void **ret_handle);
245
246
bool dsp_detach(int handle,
247
		void *proc_handle);
248
249
bool dsp_start(int handle,
250
		void *proc_handle);
251
252
bool dsp_stop(int handle,
253
		void *proc_handle);
254
255
bool dsp_load(int handle,
256
		void *proc_handle,
257
		int argc, char **argv,
258
		char **env);
259
260
bool dsp_node_allocate(int handle,
261
		void *proc_handle,
262
		const struct dsp_uuid *node_uuid,
263
		const void *cb_data,
264
		struct dsp_node_attr_in *attrs,
265
		struct dsp_node **ret_node);
266
267
bool dsp_node_free(int handle,
268
		struct dsp_node *node);
269
270
bool dsp_node_connect(int handle,
271
		struct dsp_node *node,
272
		unsigned int stream,
273
		struct dsp_node *other_node,
274
		unsigned int other_stream,
275
		struct dsp_stream_attr *attrs,
276
		void *params);
277
278
bool dsp_node_create(int handle,
279
		struct dsp_node *node);
280
281
bool dsp_node_run(int handle,
282
		struct dsp_node *node);
283
284
bool dsp_node_terminate(int handle,
285
		struct dsp_node *node,
286
		unsigned long *status);
287
288
bool dsp_node_put_message(int handle,
289
		struct dsp_node *node,
290
		const struct dsp_msg *message,
291
		unsigned int timeout);
292
293
bool dsp_node_get_message(int handle,
294
		struct dsp_node *node,
295
		struct dsp_msg *message,
296
		unsigned int timeout);
297
298
bool dsp_reserve(int handle,
299
		void *proc_handle,
300
		unsigned long size,
301
		void **addr);
302
303
bool dsp_unreserve(int handle,
304
		void *proc_handle,
305
		void *addr);
306
307
bool dsp_map(int handle,
308
		void *proc_handle,
309
		void *mpu_addr,
310
		unsigned long size,
311
		void *req_addr,
312
		void *ret_map_addr,
313
		unsigned long attr);
314
315
bool dsp_unmap(int handle,
316
		void *proc_handle,
317
		void *map_addr);
318
319
bool dsp_flush(int handle,
320
		void *proc_handle,
321
		void *mpu_addr,
322
		unsigned long size,
323
		unsigned long flags);
324
325
bool dsp_invalidate(int handle,
326
		void *proc_handle,
327
		void *mpu_addr,
328
		unsigned long size);
329
330
bool dsp_register_notify(int handle,
331
		void *proc_handle,
332
		unsigned int event_mask,
333
		unsigned int notify_type,
334
		struct dsp_notification *info);
335
336
bool dsp_node_register_notify(int handle,
337
		struct dsp_node *node,
338
		unsigned int event_mask,
339
		unsigned int notify_type,
340
		struct dsp_notification *info);
341
342
bool dsp_wait_for_events(int handle,
343
		struct dsp_notification **notifications,
344
		unsigned int count,
345
		unsigned int *ret_index,
346
		unsigned int timeout);
347
348
bool dsp_enum(int handle,
349
		unsigned int num,
350
		struct dsp_ndb_props *info,
351
		size_t info_size,
352
		unsigned int *ret_num);
353
354
bool dsp_register(int handle,
355
		const struct dsp_uuid *uuid,
356
		enum dsp_dcd_object_type type,
357
		const char *path);
358
359
bool dsp_unregister(int handle,
360
		const struct dsp_uuid *uuid,
361
		enum dsp_dcd_object_type type);
362
363
bool dsp_proc_get_info(int handle,
364
		void *proc_handle,
365
		enum dsp_resource type,
366
		struct dsp_info *info,
367
		unsigned size);
368
369
static inline bool
370
dsp_send_message(int handle,
371
		struct dsp_node *node,
372
		uint32_t cmd,
373
		uint32_t arg_1,
374
		uint32_t arg_2)
375
{
376
	struct dsp_msg msg;
377
378
	msg.cmd = cmd;
379
	msg.arg_1 = arg_1;
380
	msg.arg_2 = arg_2;
381
382
	return dsp_node_put_message(handle, node, &msg, -1);
383
}
384
385
bool dsp_node_get_attr(int handle,
386
		struct dsp_node *node,
387
		struct dsp_node_attr *attr,
388
		size_t attr_size);
389
390
bool dsp_enum_nodes(int handle,
391
		void *proc_handle,
392
		void **node_table,
393
		unsigned node_table_size,
394
		unsigned *num_nodes,
395
		unsigned *allocated);
396
397
bool dsp_stream_open(int handle,
398
		struct dsp_node *node,
399
		unsigned int direction,
400
		unsigned int index,
401
		struct dsp_stream_attr_in *attrin,
402
		void *stream);
403
404
bool dsp_stream_close(int handle,
405
		void *stream);
406
407
bool dsp_stream_idle(int handle,
408
		void *stream,
409
		bool flush);
410
411
bool dsp_stream_reclaim(int handle,
412
		void *stream,
413
		unsigned char **buff,
414
		unsigned long *data_size,
415
		unsigned long *buff_size,
416
		unsigned long *args);
417
418
bool dsp_stream_issue(int handle,
419
		void *stream,
420
		unsigned char *buff,
421
		unsigned long data_size,
422
		unsigned long buff_size,
423
		unsigned long arg);
424
425
bool dsp_stream_get_info(int handle,
426
		void *stream,
427
		struct dsp_stream_info *info,
428
		unsigned int size);
429
430
bool dsp_stream_allocate_buffers(int handle,
431
		void *stream,
432
		unsigned int size,
433
		unsigned char **buff,
434
		unsigned int num_buf);
435
436
bool dsp_stream_free_buffers(int handle,
437
		void *stream,
438
		unsigned char **buff,
439
		unsigned int num_buf);
440
441
#endif /* DSP_BRIDGE_H */