dsp_bridge.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*
  2. * Copyright (C) 2009 Felipe Contreras
  3. *
  4. * Author: Felipe Contreras <felipe.contreras@gmail.com>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation
  9. * version 2.1 of the License.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. */
  21. #ifndef DSP_BRIDGE_H
  22. #define DSP_BRIDGE_H
  23. #include <stdbool.h>
  24. #include <stdint.h>
  25. #include <stdlib.h>
  26. #define ALLOCATE_HEAP
  27. #define DSP_SUCCEEDED(x) ((int)(x) >= 0)
  28. #define DSP_FAILED(x) ((int)(x) < 0)
  29. #define DSP_MMUFAULT 0x00000010
  30. #define DSP_SYSERROR 0x00000020
  31. #define DSP_NODEMESSAGEREADY 0x00000200
  32. typedef struct {
  33. uint32_t field_1;
  34. uint16_t field_2;
  35. uint16_t field_3;
  36. uint8_t field_4;
  37. uint8_t field_5;
  38. uint8_t field_6[6];
  39. } dsp_uuid_t;
  40. typedef struct {
  41. void *handle;
  42. void *heap;
  43. void *msgbuf_addr;
  44. size_t msgbuf_size;
  45. } dsp_node_t;
  46. /* note: cmd = 0x20000000 has special handling */
  47. typedef struct {
  48. uint32_t cmd;
  49. uint32_t arg_1;
  50. uint32_t arg_2;
  51. } dsp_msg_t;
  52. struct dsp_notification {
  53. char *name;
  54. void *handle;
  55. };
  56. struct dsp_node_attr_in {
  57. unsigned long cb;
  58. int priority;
  59. unsigned int timeout;
  60. unsigned int profile_id;
  61. unsigned int heap_size;
  62. void *gpp_va;
  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. enum dsp_node_type {
  73. DSP_NODE_DEVICE,
  74. DSP_NODE_TASK,
  75. DSP_NODE_DAISSOCKET,
  76. DSP_NODE_MESSAGE,
  77. };
  78. #ifdef ALLOCATE_HEAP
  79. struct DSP_RESOURCEREQMTS {
  80. unsigned long cbStruct;
  81. unsigned int uStaticDataSize;
  82. unsigned int uGlobalDataSize;
  83. unsigned int uProgramMemSize;
  84. unsigned int uWCExecutionTime;
  85. unsigned int uWCPeriod;
  86. unsigned int uWCDeadline;
  87. unsigned int uAvgExectionTime;
  88. unsigned int uMinimumPeriod;
  89. };
  90. struct DSP_NODEPROFS {
  91. unsigned int ulHeapSize;
  92. };
  93. struct dsp_ndb_props {
  94. unsigned long cbStruct;
  95. dsp_uuid_t uiNodeID;
  96. char acName[32];
  97. enum dsp_node_type uNodeType;
  98. unsigned int bCacheOnGPP;
  99. struct DSP_RESOURCEREQMTS dspResourceReqmts;
  100. int iPriority;
  101. unsigned int uStackSize;
  102. unsigned int uSysStackSize;
  103. unsigned int uStackSeg;
  104. unsigned int uMessageDepth;
  105. unsigned int uNumInputStreams;
  106. unsigned int uNumOutputStreams;
  107. unsigned int uTimeout;
  108. unsigned int uCountProfiles; /* Number of supported profiles */
  109. struct DSP_NODEPROFS aProfiles[16]; /* Array of profiles */
  110. unsigned int uStackSegName; /* Stack Segment Name */
  111. };
  112. #endif
  113. enum dsp_resource {
  114. DSP_RESOURCE_DYNDARAM = 0,
  115. DSP_RESOURCE_DYNSARAM,
  116. DSP_RESOURCE_DYNEXTERNAL,
  117. DSP_RESOURCE_DYNSRAM,
  118. DSP_RESOURCE_PROCLOAD,
  119. };
  120. struct dsp_info {
  121. unsigned long cb;
  122. enum dsp_resource type;
  123. union {
  124. unsigned long resource;
  125. struct {
  126. unsigned long size;
  127. unsigned long total_free_size;
  128. unsigned long len_max_free_block;
  129. unsigned long free_blocks;
  130. unsigned long alloc_blocks;
  131. } mem;
  132. struct {
  133. unsigned long load;
  134. unsigned long pred_load;
  135. unsigned long freq;
  136. unsigned long pred_freq;
  137. } proc;
  138. } result;
  139. };
  140. enum dsp_connect_type {
  141. CONNECTTYPE_NODEOUTPUT,
  142. CONNECTTYPE_GPPOUTPUT,
  143. CONNECTTYPE_NODEINPUT,
  144. CONNECTTYPE_GPPINPUT
  145. };
  146. struct dsp_stream_connect {
  147. unsigned long cb;
  148. enum dsp_connect_type type;
  149. unsigned int index;
  150. void *node_handle;
  151. dsp_uuid_t node_id;
  152. unsigned int stream_index;
  153. };
  154. enum dsp_node_state {
  155. NODE_ALLOCATED,
  156. NODE_CREATED,
  157. NODE_RUNNING,
  158. NODE_PAUSED,
  159. NODE_DONE
  160. };
  161. struct dsp_node_info {
  162. unsigned long cb;
  163. struct dsp_ndb_props props;
  164. unsigned int priority;
  165. enum dsp_node_state state;
  166. void *owner;
  167. unsigned int num_streams;
  168. struct dsp_stream_connect streams[16];
  169. unsigned int node_env;
  170. };
  171. struct dsp_node_attr {
  172. unsigned long cb;
  173. struct dsp_node_attr_in attr_in;
  174. unsigned long inputs;
  175. unsigned long outputs;
  176. struct dsp_node_info info;
  177. };
  178. int dsp_open(void);
  179. int dsp_close(int handle);
  180. bool dsp_attach(int handle,
  181. unsigned int num,
  182. const void *info,
  183. void **ret_handle);
  184. bool dsp_detach(int handle,
  185. void *proc_handle);
  186. bool dsp_node_allocate(int handle,
  187. void *proc_handle,
  188. const dsp_uuid_t *node_uuid,
  189. const void *cb_data,
  190. struct dsp_node_attr_in *attrs,
  191. dsp_node_t **ret_node);
  192. bool dsp_node_free(int handle,
  193. dsp_node_t *node);
  194. bool dsp_node_create(int handle,
  195. dsp_node_t *node);
  196. bool dsp_node_run(int handle,
  197. dsp_node_t *node);
  198. bool dsp_node_terminate(int handle,
  199. dsp_node_t *node,
  200. unsigned long *status);
  201. bool dsp_node_put_message(int handle,
  202. dsp_node_t *node,
  203. const dsp_msg_t *message,
  204. unsigned int timeout);
  205. bool dsp_node_get_message(int handle,
  206. dsp_node_t *node,
  207. dsp_msg_t *message,
  208. unsigned int timeout);
  209. bool dsp_reserve(int handle,
  210. void *proc_handle,
  211. unsigned long size,
  212. void **addr);
  213. bool dsp_unreserve(int handle,
  214. void *proc_handle,
  215. void *addr);
  216. bool dsp_map(int handle,
  217. void *proc_handle,
  218. void *mpu_addr,
  219. unsigned long size,
  220. void *req_addr,
  221. void *ret_map_addr,
  222. unsigned long attr);
  223. bool dsp_unmap(int handle,
  224. void *proc_handle,
  225. void *map_addr);
  226. bool dsp_flush(int handle,
  227. void *proc_handle,
  228. void *mpu_addr,
  229. unsigned long size,
  230. unsigned long flags);
  231. bool dsp_invalidate(int handle,
  232. void *proc_handle,
  233. void *mpu_addr,
  234. unsigned long size);
  235. bool dsp_register_notify(int handle,
  236. void *proc_handle,
  237. unsigned int event_mask,
  238. unsigned int notify_type,
  239. struct dsp_notification *info);
  240. bool dsp_node_register_notify(int handle,
  241. dsp_node_t *node,
  242. unsigned int event_mask,
  243. unsigned int notify_type,
  244. struct dsp_notification *info);
  245. bool dsp_wait_for_events(int handle,
  246. struct dsp_notification **notifications,
  247. unsigned int count,
  248. unsigned int *ret_index,
  249. unsigned int timeout);
  250. bool dsp_enum(int handle,
  251. unsigned int num,
  252. struct dsp_ndb_props *info,
  253. unsigned int info_size,
  254. unsigned int *ret_num);
  255. bool dsp_register(int handle,
  256. const dsp_uuid_t *uuid,
  257. enum dsp_dcd_object_type type,
  258. const char *path);
  259. bool dsp_unregister(int handle,
  260. dsp_uuid_t *uuid,
  261. enum dsp_dcd_object_type type);
  262. bool dsp_proc_get_info(int handle,
  263. void *proc_handle,
  264. enum dsp_resource type,
  265. struct dsp_info *info,
  266. unsigned size);
  267. static inline bool
  268. dsp_send_message(int handle,
  269. dsp_node_t *node,
  270. uint32_t cmd,
  271. uint32_t arg_1,
  272. uint32_t arg_2)
  273. {
  274. dsp_msg_t msg;
  275. msg.cmd = cmd;
  276. msg.arg_1 = arg_1;
  277. msg.arg_2 = arg_2;
  278. return dsp_node_put_message(handle, node, &msg, -1);
  279. }
  280. bool dsp_node_get_attr(int handle,
  281. dsp_node_t *node,
  282. struct dsp_node_attr *attr,
  283. size_t attr_size);
  284. bool dsp_enum_nodes(int handle,
  285. void *proc_handle,
  286. void **node_table,
  287. unsigned node_table_size,
  288. unsigned *num_nodes,
  289. unsigned *allocated);
  290. #endif /* DSP_BRIDGE_H */