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