dsp_bridge.h 9.0 KB

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