summaryrefslogtreecommitdiff
path: root/bridge/dsp_bridge.h
blob: c5acaa4bafa72bcd0cea0b7f4acb386feac850e1 (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
/*
 * Copyright (C) 2009-2010 Felipe Contreras
 *
 * Author: Felipe Contreras <felipe.contreras@gmail.com>
 *
 * This file may be used under the terms of the GNU Lesser General Public
 * License version 2.1, a copy of which is found in LICENSE included in the
 * packaging of this file.
 */

#ifndef DSP_BRIDGE_H
#define DSP_BRIDGE_H

#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#define ALLOCATE_HEAP

#define DSP_MMUFAULT 0x00000010
#define DSP_SYSERROR 0x00000020
#define DSP_NODEMESSAGEREADY 0x00000200

#define MAX_PROFILES 16
#define DSP_MAXNAMELEN 32

struct dsp_uuid {
	uint32_t field_1;
	uint16_t field_2;
	uint16_t field_3;
	uint8_t field_4;
	uint8_t field_5;
	uint8_t field_6[6];
};

struct dsp_node {
	void *handle;
	void *heap;
	void *msgbuf_addr;
	size_t msgbuf_size;
};

/* note: cmd = 0x20000000 has special handling */
struct dsp_msg {
	uint32_t cmd;
	uint32_t arg_1;
	uint32_t arg_2;
};

struct dsp_notification {
	char *name;
	void *handle;
};

struct dsp_node_attr_in {
	unsigned long cb;
	int priority;
	unsigned int timeout;
	unsigned int profile_id;
	unsigned int heap_size;
	void *gpp_va;
};

enum dsp_dcd_object_type {
	DSP_DCD_NODETYPE,
	DSP_DCD_PROCESSORTYPE,
	DSP_DCD_LIBRARYTYPE,
	DSP_DCD_CREATELIBTYPE,
	DSP_DCD_EXECUTELIBTYPE,
	DSP_DCD_DELETELIBTYPE,
};

enum dsp_node_type {
	DSP_NODE_DEVICE,
	DSP_NODE_TASK,
	DSP_NODE_DAISSOCKET,
	DSP_NODE_MESSAGE,
};

#ifdef ALLOCATE_HEAP
/* The dsp_resourcereqmts structure for node's resource requirements */
struct dsp_resourcereqmts {
	uint32_t cb_struct;
	uint32_t static_data_size;
	uint32_t global_data_size;
	uint32_t program_mem_size;
	uint32_t uwc_execution_time;
	uint32_t uwc_period;
	uint32_t uwc_deadline;
	uint32_t avg_exection_time;
	uint32_t minimum_period;
};

struct dsp_nodeprofs {
	uint32_t heap_size;
};

/* The dsp_ndb_props structure reports the attributes of a node */
struct dsp_ndb_props {
	uint32_t cb_struct;
	struct dsp_uuid node_id;
	char ac_name[DSP_MAXNAMELEN];
	enum dsp_node_type ntype;
	uint32_t cache_on_gpp;
	struct dsp_resourcereqmts dsp_resource_reqmts;
	int32_t prio;
	uint32_t stack_size;
	uint32_t sys_stack_size;
	uint32_t stack_seg;
	uint32_t message_depth;
	uint32_t num_input_streams;
	uint32_t num_output_streams;
	uint32_t timeout;
	uint32_t count_profiles; /* Number of supported profiles */
	struct dsp_nodeprofs node_profiles[MAX_PROFILES]; /* Array of profiles */
	uint32_t stack_seg_name; /* Stack Segment Name */
};
#endif

enum dsp_resource {
	DSP_RESOURCE_DYNDARAM = 0,
	DSP_RESOURCE_DYNSARAM,
	DSP_RESOURCE_DYNEXTERNAL,
	DSP_RESOURCE_DYNSRAM,
	DSP_RESOURCE_PROCLOAD,
};

struct dsp_info {
	unsigned long cb;
	enum dsp_resource type;
	union {
		unsigned long resource;
		struct {
			unsigned long size;
			unsigned long total_free_size;
			unsigned long len_max_free_block;
			unsigned long free_blocks;
			unsigned long alloc_blocks;
		} mem;
		struct {
			unsigned long load;
			unsigned long pred_load;
			unsigned long freq;
			unsigned long pred_freq;
		} proc;
	} result;
};

enum dsp_connect_type {
	CONNECTTYPE_NODEOUTPUT,
	CONNECTTYPE_GPPOUTPUT,
	CONNECTTYPE_NODEINPUT,
	CONNECTTYPE_GPPINPUT
};

struct dsp_stream_connect {
	unsigned long cb;
	enum dsp_connect_type type;
	unsigned int index;
	void *node_handle;
	struct dsp_uuid node_id;
	unsigned int stream_index;
};

enum dsp_stream_mode {
	STRMMODE_PROCCOPY,
	STRMMODE_ZEROCOPY,
	STRMMODE_LDMA,
	STRMMODE_RDMA
};

struct dsp_stream_attr {
	unsigned int seg_id;
	unsigned int buf_size;
	unsigned int num_bufs;
	unsigned int alignment;
	unsigned int timeout;
	enum dsp_stream_mode mode;
	unsigned int dma_chnl_id;
	unsigned int dma_priority;
};

struct dsp_stream_attr_in {
	unsigned long cb;
	unsigned int timeout;
	unsigned int segment;
	unsigned int alignment;
	unsigned int num_bufs;
	enum dsp_stream_mode mode;
	unsigned int dma_chnl_id;
	unsigned int dma_priority;
};

enum dsp_stream_state {
	STREAM_IDLE,
	STREAM_READY,
	STREAM_PENDING,
	STREAM_DONE
};

struct dsp_stream_info {
	unsigned long cb;
	unsigned int num_bufs_allowed;
	unsigned int num_bufs_in_stream;
	unsigned long num_bytes;
	void *sync_handle;
	enum dsp_stream_state state;
};

enum dsp_node_state {
	NODE_ALLOCATED,
	NODE_CREATED,
	NODE_RUNNING,
	NODE_PAUSED,
	NODE_DONE
};

struct dsp_node_info {
	unsigned long cb;
	struct dsp_ndb_props props;
	unsigned int priority;
	enum dsp_node_state state;
	void *owner;
	unsigned int num_streams;
	struct dsp_stream_connect streams[16];
	unsigned int node_env;
};

struct dsp_node_attr {
	unsigned long cb;
	struct dsp_node_attr_in attr_in;
	unsigned long inputs;
	unsigned long outputs;
	struct dsp_node_info info;
};

int dsp_open(void);

int dsp_close(int handle);

bool dsp_attach(int handle,
		unsigned int num,
		const void *info,
		void **ret_handle);

bool dsp_detach(int handle,
		void *proc_handle);

bool dsp_start(int handle,
		void *proc_handle);

bool dsp_stop(int handle,
		void *proc_handle);

bool dsp_load(int handle,
		void *proc_handle,
		int argc, char **argv,
		char **env);

bool dsp_node_allocate(int handle,
		void *proc_handle,
		const struct dsp_uuid *node_uuid,
		const void *cb_data,
		struct dsp_node_attr_in *attrs,
		struct dsp_node **ret_node);

bool dsp_node_free(int handle,
		struct dsp_node *node);

bool dsp_node_connect(int handle,
		struct dsp_node *node,
		unsigned int stream,
		struct dsp_node *other_node,
		unsigned int other_stream,
		struct dsp_stream_attr *attrs,
		void *params);

bool dsp_node_create(int handle,
		struct dsp_node *node);

bool dsp_node_run(int handle,
		struct dsp_node *node);

bool dsp_node_terminate(int handle,
		struct dsp_node *node,
		unsigned long *status);

bool dsp_node_put_message(int handle,
		struct dsp_node *node,
		const struct dsp_msg *message,
		unsigned int timeout);

bool dsp_node_get_message(int handle,
		struct dsp_node *node,
		struct dsp_msg *message,
		unsigned int timeout);

bool dsp_reserve(int handle,
		void *proc_handle,
		unsigned long size,
		void **addr);

bool dsp_unreserve(int handle,
		void *proc_handle,
		void *addr);

bool dsp_map(int handle,
		void *proc_handle,
		void *mpu_addr,
		unsigned long size,
		void *req_addr,
		void *ret_map_addr,
		unsigned long attr);

bool dsp_unmap(int handle,
		void *proc_handle,
		void *map_addr);

bool dsp_flush(int handle,
		void *proc_handle,
		void *mpu_addr,
		unsigned long size,
		unsigned long flags);

bool dsp_invalidate(int handle,
		void *proc_handle,
		void *mpu_addr,
		unsigned long size);

bool dsp_register_notify(int handle,
		void *proc_handle,
		unsigned int event_mask,
		unsigned int notify_type,
		struct dsp_notification *info);

bool dsp_node_register_notify(int handle,
		struct dsp_node *node,
		unsigned int event_mask,
		unsigned int notify_type,
		struct dsp_notification *info);

bool dsp_wait_for_events(int handle,
		struct dsp_notification **notifications,
		unsigned int count,
		unsigned int *ret_index,
		unsigned int timeout);

bool dsp_enum(int handle,
		unsigned int num,
		struct dsp_ndb_props *info,
		size_t info_size,
		unsigned int *ret_num);

bool dsp_register(int handle,
		const struct dsp_uuid *uuid,
		enum dsp_dcd_object_type type,
		const char *path);

bool dsp_unregister(int handle,
		const struct dsp_uuid *uuid,
		enum dsp_dcd_object_type type);

bool dsp_proc_get_info(int handle,
		void *proc_handle,
		enum dsp_resource type,
		struct dsp_info *info,
		unsigned size);

static inline bool
dsp_send_message(int handle,
		struct dsp_node *node,
		uint32_t cmd,
		uint32_t arg_1,
		uint32_t arg_2)
{
	struct dsp_msg msg;

	msg.cmd = cmd;
	msg.arg_1 = arg_1;
	msg.arg_2 = arg_2;

	return dsp_node_put_message(handle, node, &msg, -1);
}

bool dsp_node_get_attr(int handle,
		struct dsp_node *node,
		struct dsp_node_attr *attr,
		size_t attr_size);

bool dsp_enum_nodes(int handle,
		void *proc_handle,
		void **node_table,
		unsigned node_table_size,
		unsigned *num_nodes,
		unsigned *allocated);

bool dsp_stream_open(int handle,
		struct dsp_node *node,
		unsigned int direction,
		unsigned int index,
		struct dsp_stream_attr_in *attrin,
		void *stream);

bool dsp_stream_close(int handle,
		void *stream);

bool dsp_stream_idle(int handle,
		void *stream,
		bool flush);

bool dsp_stream_reclaim(int handle,
		void *stream,
		unsigned char **buff,
		unsigned long *data_size,
		unsigned long *buff_size,
		unsigned long *args);

bool dsp_stream_issue(int handle,
		void *stream,
		unsigned char *buff,
		unsigned long data_size,
		unsigned long buff_size,
		unsigned long arg);

bool dsp_stream_get_info(int handle,
		void *stream,
		struct dsp_stream_info *info,
		unsigned int size);

bool dsp_stream_allocate_buffers(int handle,
		void *stream,
		unsigned int size,
		unsigned char **buff,
		unsigned int num_buf);

bool dsp_stream_free_buffers(int handle,
		void *stream,
		unsigned char **buff,
		unsigned int num_buf);

#endif /* DSP_BRIDGE_H */