Subversion Repositories HelenOS

Rev

Rev 3535 | Rev 4345 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2006 Ondrej Palkovsky
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup libcipc
  30.  * @{
  31.  */
  32. /** @file
  33.  */
  34.  
  35. #ifndef LIBIPC_IPC_H_
  36. #define LIBIPC_IPC_H_
  37.  
  38. #include <kernel/ipc/ipc.h>
  39. #include <kernel/ddi/irq.h>
  40. #include <sys/types.h>
  41. #include <kernel/synch/synch.h>
  42.  
  43. typedef sysarg_t ipcarg_t;
  44. typedef struct {
  45.     ipcarg_t args[IPC_CALL_LEN];
  46.     ipcarg_t in_phone_hash;
  47. } ipc_call_t;
  48. typedef sysarg_t ipc_callid_t;
  49.  
  50. typedef void (* ipc_async_callback_t)(void *, int, ipc_call_t *);
  51.  
  52. /*
  53.  * User-friendly wrappers for ipc_call_sync_fast() and ipc_call_sync_slow().
  54.  * They are in the form ipc_call_sync_m_n(), where m denotes the number of
  55.  * arguments of payload and n denotes number of return values. Whenever
  56.  * possible, the fast version is used.
  57.  */
  58. #define ipc_call_sync_0_0(phoneid, method) \
  59.     ipc_call_sync_fast((phoneid), (method), 0, 0, 0, 0, 0, 0, 0, 0)
  60. #define ipc_call_sync_0_1(phoneid, method, res1) \
  61.     ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), 0, 0, 0, 0)
  62. #define ipc_call_sync_0_2(phoneid, method, res1, res2) \
  63.     ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), 0, 0, 0)
  64. #define ipc_call_sync_0_3(phoneid, method, res1, res2, res3) \
  65.     ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), (res3), \
  66.         0, 0)
  67. #define ipc_call_sync_0_4(phoneid, method, res1, res2, res3, res4) \
  68.     ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), (res3), \
  69.         (res4), 0)
  70. #define ipc_call_sync_0_5(phoneid, method, res1, res2, res3, res4, res5) \
  71.     ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), (res3), \
  72.         (res4), (res5))
  73. #define ipc_call_sync_1_0(phoneid, method, arg1) \
  74.     ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, 0, 0, 0, 0, 0)
  75. #define ipc_call_sync_1_1(phoneid, method, arg1, res1) \
  76.     ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), 0, 0, 0, 0)
  77. #define ipc_call_sync_1_2(phoneid, method, arg1, res1, res2) \
  78.     ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), 0, \
  79.     0, 0)
  80. #define ipc_call_sync_1_3(phoneid, method, arg1, res1, res2, res3) \
  81.     ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), \
  82.     (res3), 0, 0)
  83. #define ipc_call_sync_1_4(phoneid, method, arg1, res1, res2, res3, res4) \
  84.     ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), \
  85.     (res3), (res4), 0)
  86. #define ipc_call_sync_1_5(phoneid, method, arg1, res1, res2, res3, res4, \
  87.     res5) \
  88.     ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), \
  89.         (res3), (res4), (res5))
  90. #define ipc_call_sync_2_0(phoneid, method, arg1, arg2) \
  91.     ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, 0, 0, 0, \
  92.     0, 0)
  93. #define ipc_call_sync_2_1(phoneid, method, arg1, arg2, res1) \
  94.     ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), 0, 0, \
  95.     0, 0)
  96. #define ipc_call_sync_2_2(phoneid, method, arg1, arg2, res1, res2) \
  97.     ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
  98.     (res2), 0, 0, 0)
  99. #define ipc_call_sync_2_3(phoneid, method, arg1, arg2, res1, res2, res3) \
  100.     ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
  101.     (res2), (res3), 0, 0)
  102. #define ipc_call_sync_2_4(phoneid, method, arg1, arg2, res1, res2, res3, \
  103.     res4) \
  104.     ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
  105.         (res2), (res3), (res4), 0)
  106. #define ipc_call_sync_2_5(phoneid, method, arg1, arg2, res1, res2, res3, \
  107.     res4, res5)\
  108.     ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
  109.         (res2), (res3), (res4), (res5))
  110. #define ipc_call_sync_3_0(phoneid, method, arg1, arg2, arg3) \
  111.     ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, 0, 0, \
  112.     0, 0)
  113. #define ipc_call_sync_3_1(phoneid, method, arg1, arg2, arg3, res1) \
  114.     ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), (res1), \
  115.     0, 0, 0, 0)
  116. #define ipc_call_sync_3_2(phoneid, method, arg1, arg2, arg3, res1, res2) \
  117.     ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), (res1), \
  118.     (res2), 0, 0, 0)
  119. #define ipc_call_sync_3_3(phoneid, method, arg1, arg2, arg3, res1, res2, \
  120.     res3) \
  121.     ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), \
  122.         (res1), (res2), (res3), 0, 0)
  123. #define ipc_call_sync_3_4(phoneid, method, arg1, arg2, arg3, res1, res2, \
  124.     res3, res4) \
  125.     ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), \
  126.         (res1), (res2), (res3), (res4), 0)
  127. #define ipc_call_sync_3_5(phoneid, method, arg1, arg2, arg3, res1, res2, \
  128.     res3, res4, res5) \
  129.     ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), \
  130.         (res1), (res2), (res3), (res4), (res5))
  131. #define ipc_call_sync_4_0(phoneid, method, arg1, arg2, arg3, arg4) \
  132.     ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), 0, \
  133.     0, 0, 0, 0, 0)
  134. #define ipc_call_sync_4_1(phoneid, method, arg1, arg2, arg3, arg4, res1) \
  135.     ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), 0, \
  136.     (res1), 0, 0, 0, 0)
  137. #define ipc_call_sync_4_2(phoneid, method, arg1, arg2, arg3, arg4, res1, res2) \
  138.     ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), 0, \
  139.     (res1), (res2), 0, 0, 0)
  140. #define ipc_call_sync_4_3(phoneid, method, arg1, arg2, arg3, arg4, res1, res2, \
  141.     res3) \
  142.     ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
  143.         (arg4), 0, (res1), (res2), (res3), 0, 0)
  144. #define ipc_call_sync_4_4(phoneid, method, arg1, arg2, arg3, arg4, res1, res2, \
  145.     res3, res4) \
  146.     ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
  147.         (arg4), 0, (res1), (res2), (res3), (res4), 0)
  148. #define ipc_call_sync_4_5(phoneid, method, arg1, arg2, arg3, arg4, res1, res2, \
  149.     res3, res4, res5) \
  150.     ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
  151.         (arg4), 0, (res1), (res2), (res3), (res4), (res5))
  152. #define ipc_call_sync_5_0(phoneid, method, arg1, arg2, arg3, arg4, arg5) \
  153.     ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), \
  154.         (arg5), 0, 0, 0, 0, 0)
  155. #define ipc_call_sync_5_1(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1) \
  156.     ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), \
  157.         (arg5), (res1), 0, 0, 0, 0)
  158. #define ipc_call_sync_5_2(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
  159.     res2) \
  160.     ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
  161.         (arg4), (arg5), (res1), (res2), 0, 0, 0)
  162. #define ipc_call_sync_5_3(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
  163.     res2, res3) \
  164.     ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
  165.         (arg4), (arg5), (res1), (res2), (res3), 0, 0)
  166. #define ipc_call_sync_5_4(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
  167.     res2, res3, res4) \
  168.     ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
  169.         (arg4), (arg5), (res1), (res2), (res3), (res4), 0)
  170. #define ipc_call_sync_5_5(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
  171.     res2, res3, res4, res5) \
  172.     ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
  173.         (arg4), (arg5), (res1), (res2), (res3), (res4), (res5))
  174.  
  175. extern int ipc_call_sync_fast(int, ipcarg_t, ipcarg_t, ipcarg_t, ipcarg_t,
  176.     ipcarg_t *, ipcarg_t *, ipcarg_t *, ipcarg_t *, ipcarg_t *);
  177.  
  178. extern int ipc_call_sync_slow(int, ipcarg_t, ipcarg_t, ipcarg_t, ipcarg_t,
  179.     ipcarg_t, ipcarg_t, ipcarg_t *, ipcarg_t *, ipcarg_t *, ipcarg_t *,
  180.     ipcarg_t *);
  181.  
  182. extern ipc_callid_t ipc_wait_cycle(ipc_call_t *, uint32_t, int);
  183. extern ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *, uint32_t);
  184. static inline ipc_callid_t ipc_wait_for_call(ipc_call_t *data)
  185. {
  186.     return ipc_wait_for_call_timeout(data, SYNCH_NO_TIMEOUT);
  187. }
  188. extern ipc_callid_t ipc_trywait_for_call(ipc_call_t *);
  189.  
  190. /*
  191.  * User-friendly wrappers for ipc_answer_fast() and ipc_answer_slow().
  192.  * They are in the form of ipc_answer_m(), where m is the number of return
  193.  * arguments. The macros decide between the fast and the slow version according
  194.  * to m.
  195.  */
  196. #define ipc_answer_0(callid, retval) \
  197.     ipc_answer_fast((callid), (retval), 0, 0, 0, 0)
  198. #define ipc_answer_1(callid, retval, arg1) \
  199.     ipc_answer_fast((callid), (retval), (arg1), 0, 0, 0)
  200. #define ipc_answer_2(callid, retval, arg1, arg2) \
  201.     ipc_answer_fast((callid), (retval), (arg1), (arg2), 0, 0)
  202. #define ipc_answer_3(callid, retval, arg1, arg2, arg3) \
  203.     ipc_answer_fast((callid), (retval), (arg1), (arg2), (arg3), 0)
  204. #define ipc_answer_4(callid, retval, arg1, arg2, arg3, arg4) \
  205.     ipc_answer_fast((callid), (retval), (arg1), (arg2), (arg3), (arg4))
  206. #define ipc_answer_5(callid, retval, arg1, arg2, arg3, arg4, arg5) \
  207.     ipc_answer_slow((callid), (retval), (arg1), (arg2), (arg3), (arg4), (arg5))
  208.  
  209. extern ipcarg_t ipc_answer_fast(ipc_callid_t, ipcarg_t, ipcarg_t, ipcarg_t,
  210.     ipcarg_t, ipcarg_t);
  211. extern ipcarg_t ipc_answer_slow(ipc_callid_t, ipcarg_t, ipcarg_t, ipcarg_t,
  212.     ipcarg_t, ipcarg_t, ipcarg_t);
  213.  
  214. /*
  215.  * User-friendly wrappers for ipc_call_async_fast() and ipc_call_async_slow().
  216.  * They are in the form of ipc_call_async_m(), where m is the number of payload
  217.  * arguments. The macros decide between the fast and the slow version according
  218.  * to m.
  219.  */
  220. #define ipc_call_async_0(phoneid, method, private, callback, can_preempt) \
  221.     ipc_call_async_fast((phoneid), (method), 0, 0, 0, 0, (private), \
  222.         (callback), (can_preempt))
  223. #define ipc_call_async_1(phoneid, method, arg1, private, callback, \
  224.     can_preempt) \
  225.     ipc_call_async_fast((phoneid), (method), (arg1), 0, 0, 0, (private), \
  226.         (callback), (can_preempt))
  227. #define ipc_call_async_2(phoneid, method, arg1, arg2, private, callback, \
  228.     can_preempt) \
  229.     ipc_call_async_fast((phoneid), (method), (arg1), (arg2), 0, 0, \
  230.         (private), (callback), (can_preempt))
  231. #define ipc_call_async_3(phoneid, method, arg1, arg2, arg3, private, callback, \
  232.     can_preempt) \
  233.     ipc_call_async_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, \
  234.         (private), (callback), (can_preempt))
  235. #define ipc_call_async_4(phoneid, method, arg1, arg2, arg3, arg4, private, \
  236.     callback, can_preempt) \
  237.     ipc_call_async_fast((phoneid), (method), (arg1), (arg2), (arg3), \
  238.         (arg4), (private), (callback), (can_preempt))
  239. #define ipc_call_async_5(phoneid, method, arg1, arg2, arg3, arg4, arg5, \
  240.     private, callback, can_preempt) \
  241.     ipc_call_async_slow((phoneid), (method), (arg1), (arg2), (arg3), \
  242.         (arg4), (arg5), (private), (callback), (can_preempt))
  243.  
  244. extern void ipc_call_async_fast(int, ipcarg_t, ipcarg_t, ipcarg_t, ipcarg_t,
  245.     ipcarg_t, void *, ipc_async_callback_t, int);
  246. extern void ipc_call_async_slow(int, ipcarg_t, ipcarg_t, ipcarg_t, ipcarg_t,
  247.     ipcarg_t, ipcarg_t, void *, ipc_async_callback_t, int);
  248.  
  249. extern int ipc_connect_to_me(int, int, int, int, ipcarg_t *);
  250. extern int ipc_connect_me_to(int, int, int, int);
  251. extern int ipc_hangup(int);
  252. extern int ipc_register_irq(int, int, int, irq_code_t *);
  253. extern int ipc_unregister_irq(int, int);
  254. extern int ipc_forward_fast(ipc_callid_t, int, int, ipcarg_t, ipcarg_t, int);
  255. extern int ipc_forward_slow(ipc_callid_t, int, int, ipcarg_t, ipcarg_t,
  256.     ipcarg_t, ipcarg_t, ipcarg_t, int);
  257.  
  258.  
  259. /*
  260.  * User-friendly wrappers for ipc_share_in_start().
  261.  */
  262. #define ipc_share_in_start_0_0(phoneid, dst, size) \
  263.     ipc_share_in_start((phoneid), (dst), (size), 0, NULL)
  264. #define ipc_share_in_start_0_1(phoneid, dst, size, flags) \
  265.     ipc_share_in_start((phoneid), (dst), (size), 0, (flags))
  266. #define ipc_share_in_start_1_0(phoneid, dst, size, arg) \
  267.     ipc_share_in_start((phoneid), (dst), (size), (arg), NULL)
  268. #define ipc_share_in_start_1_1(phoneid, dst, size, arg, flags) \
  269.     ipc_share_in_start((phoneid), (dst), (size), (arg), (flags))
  270.  
  271. extern int ipc_share_in_start(int, void *, size_t, ipcarg_t, int *);
  272. extern int ipc_share_in_receive(ipc_callid_t *, size_t *);
  273. extern int ipc_share_in_finalize(ipc_callid_t, void *, int );
  274. extern int ipc_share_out_start(int, void *, int);
  275. extern int ipc_share_out_receive(ipc_callid_t *, size_t *, int *);
  276. extern int ipc_share_out_finalize(ipc_callid_t, void *);
  277. extern int ipc_data_read_start(int, void *, size_t);
  278. extern int ipc_data_read_receive(ipc_callid_t *, size_t *);
  279. extern int ipc_data_read_finalize(ipc_callid_t, const void *, size_t);
  280. extern int ipc_data_write_start(int, const void *, size_t);
  281. extern int ipc_data_write_receive(ipc_callid_t *, size_t *);
  282. extern int ipc_data_write_finalize(ipc_callid_t, void *, size_t);
  283.  
  284. #include <task.h>
  285.  
  286. extern int ipc_connect_kbox(task_id_t);
  287.  
  288. #endif
  289.  
  290. /** @}
  291.  */
  292.