Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/ipc/ipc.h

    r2c0e5d2 r5378f99  
    3636#define KERN_IPC_H_
    3737
    38 /* Length of data being transfered with IPC call */
    39 /* - the uspace may not be able to utilize full length */
    40 #define IPC_CALL_LEN            6       
    41 
    42 /** Maximum active async calls per thread */
    43 #ifdef CONFIG_DEBUG
    44 #define IPC_MAX_ASYNC_CALLS     4
    45 #else
    46 #define IPC_MAX_ASYNC_CALLS     4000
    47 #endif
     38/** Length of data being transfered with IPC call
     39 *
     40 * The uspace may not be able to utilize full length
     41 *
     42 */
     43#define IPC_CALL_LEN  6
     44
     45/** Maximum active async calls per phone */
     46#define IPC_MAX_ASYNC_CALLS  4
    4847
    4948/* Flags for calls */
    5049
    5150/** This is answer to a call */
    52 #define IPC_CALL_ANSWERED       (1 << 0)
    53 /** This call will not be freed on error */
    54 #define IPC_CALL_STATIC_ALLOC   (1 << 1)
     51#define IPC_CALL_ANSWERED  (1 << 0)
     52
    5553/** Answer will not be passed to userspace, will be discarded */
    56 #define IPC_CALL_DISCARD_ANSWER (1 << 2)
     54#define IPC_CALL_DISCARD_ANSWER  (1 << 1)
     55
    5756/** Call was forwarded */
    58 #define IPC_CALL_FORWARDED      (1 << 3)
     57#define IPC_CALL_FORWARDED  (1 << 2)
     58
    5959/** Identify connect_me_to answer */
    60 #define IPC_CALL_CONN_ME_TO     (1 << 4)
     60#define IPC_CALL_CONN_ME_TO  (1 << 3)
     61
    6162/** Interrupt notification */
    62 #define IPC_CALL_NOTIF          (1 << 5)
    63 
    64 /*
    65  * Bits used in call hashes.
     63#define IPC_CALL_NOTIF  (1 << 4)
     64
     65
     66/** Bits used in call hashes.
     67 *
    6668 * The addresses are aligned at least to 4 that is why we can use the 2 least
    6769 * significant bits of the call address.
    68  */
     70 *
     71 */
     72
    6973/** Type of this call is 'answer' */
    70 #define IPC_CALLID_ANSWERED     1
     74#define IPC_CALLID_ANSWERED  1
     75
    7176/** Type of this call is 'notification' */
    72 #define IPC_CALLID_NOTIFICATION 2
     77#define IPC_CALLID_NOTIFICATION  2
    7378
    7479/* Return values from sys_ipc_call_async(). */
    75 #define IPC_CALLRET_FATAL       -1
    76 #define IPC_CALLRET_TEMPORARY   -2
     80#define IPC_CALLRET_FATAL      -1
     81#define IPC_CALLRET_TEMPORARY  -2
    7782
    7883
    7984/* Macros for manipulating calling data */
    80 #define IPC_SET_RETVAL(data, retval)    ((data).args[0] = (retval))
    81 #define IPC_SET_METHOD(data, val)       ((data).args[0] = (val))
    82 #define IPC_SET_ARG1(data, val)         ((data).args[1] = (val))
    83 #define IPC_SET_ARG2(data, val)         ((data).args[2] = (val))
    84 #define IPC_SET_ARG3(data, val)         ((data).args[3] = (val))
    85 #define IPC_SET_ARG4(data, val)         ((data).args[4] = (val))
    86 #define IPC_SET_ARG5(data, val)         ((data).args[5] = (val))
    87 
    88 #define IPC_GET_METHOD(data)            ((data).args[0])
    89 #define IPC_GET_RETVAL(data)            ((data).args[0])
    90 
    91 #define IPC_GET_ARG1(data)              ((data).args[1])
    92 #define IPC_GET_ARG2(data)              ((data).args[2])
    93 #define IPC_GET_ARG3(data)              ((data).args[3])
    94 #define IPC_GET_ARG4(data)              ((data).args[4])
    95 #define IPC_GET_ARG5(data)              ((data).args[5])
     85#define IPC_SET_RETVAL(data, retval)  ((data).args[0] = (retval))
     86#define IPC_SET_IMETHOD(data, val)    ((data).args[0] = (val))
     87#define IPC_SET_ARG1(data, val)       ((data).args[1] = (val))
     88#define IPC_SET_ARG2(data, val)       ((data).args[2] = (val))
     89#define IPC_SET_ARG3(data, val)       ((data).args[3] = (val))
     90#define IPC_SET_ARG4(data, val)       ((data).args[4] = (val))
     91#define IPC_SET_ARG5(data, val)       ((data).args[5] = (val))
     92
     93#define IPC_GET_IMETHOD(data)  ((data).args[0])
     94#define IPC_GET_RETVAL(data)   ((data).args[0])
     95
     96#define IPC_GET_ARG1(data)  ((data).args[1])
     97#define IPC_GET_ARG2(data)  ((data).args[2])
     98#define IPC_GET_ARG3(data)  ((data).args[3])
     99#define IPC_GET_ARG4(data)  ((data).args[4])
     100#define IPC_GET_ARG5(data)  ((data).args[5])
    96101
    97102/* Well known phone descriptors */
    98 #define PHONE_NS        0
     103#define PHONE_NS  0
    99104
    100105/* Forwarding flags. */
    101 #define IPC_FF_NONE             0
     106#define IPC_FF_NONE  0
     107
    102108/**
    103109 * The call will be routed as though it was initially sent via the phone used to
     
    106112 * calls that were initially sent by the forwarder to the same destination. This
    107113 * flag has no imapct on routing replies.
    108  */
    109 #define IPC_FF_ROUTE_FROM_ME    (1 << 0)
    110 
    111 /* System-specific methods - only through special syscalls
    112  * These methods have special behaviour
    113  */
     114 *
     115 */
     116#define IPC_FF_ROUTE_FROM_ME  (1 << 0)
     117
     118/** Kernel IPC interfaces
     119 *
     120 */
     121#define IPC_IF_KERNEL  0
     122
     123/** System-specific methods - only through special syscalls
     124 *
     125 * These methods have special behaviour. These methods also
     126 * have the implicit kernel interface 0.
     127 *
     128 */
     129
    114130/** Clone connection.
    115131 *
     
    117133 *
    118134 * - ARG1 - The caller sets ARG1 to the phone of the cloned connection.
    119  *        - The callee gets the new phone from ARG1.
     135 *        - The callee gets the new phone from ARG1.
     136 *
    120137 * - on answer, the callee acknowledges the new connection by sending EOK back
    121138 *   or the kernel closes it
    122  */
    123 #define IPC_M_CONNECTION_CLONE  1
     139 *
     140 */
     141#define IPC_M_CONNECTION_CLONE  1
     142
    124143/** Protocol for CONNECT - ME
    125144 *
    126145 * Through this call, the recipient learns about the new cloned connection.
    127  * 
     146 *
    128147 * - ARG5 - the kernel sets ARG5 to contain the hash of the used phone
    129148 * - on asnwer, the callee acknowledges the new connection by sending EOK back
    130149 *   or the kernel closes it
    131  */
    132 #define IPC_M_CONNECT_ME        2
    133 /** Protocol for CONNECT - TO - ME
     150 *
     151 */
     152#define IPC_M_CONNECT_ME  2
     153
     154/** Protocol for CONNECT - TO - ME
    134155 *
    135156 * Calling process asks the callee to create a callback connection,
     
    144165 *                       error is sent back to caller. Otherwise
    145166 *                       the call is accepted and the response is sent back.
    146  *                     - the allocated phoneid is passed to userspace
     167 *                     - the hash of the client task is passed to userspace
     168 *                       (on the receiving side) as ARG4 of the call.
     169 *                     - the hash of the allocated phone is passed to userspace
    147170 *                       (on the receiving side) as ARG5 of the call.
    148  */
    149 #define IPC_M_CONNECT_TO_ME     3       
     171 *
     172 */
     173#define IPC_M_CONNECT_TO_ME  3
     174
    150175/** Protocol for CONNECT - ME - TO
    151176 *
     
    165190 *
    166191 */
    167 #define IPC_M_CONNECT_ME_TO     4       
    168 /** This message is sent to answerbox when the phone
    169  * is hung up
    170  */
    171 #define IPC_M_PHONE_HUNGUP      5
     192#define IPC_M_CONNECT_ME_TO  4
     193
     194/** This message is sent to answerbox when the phone is hung up
     195 *
     196 */
     197#define IPC_M_PHONE_HUNGUP  5
    172198
    173199/** Send as_area over IPC.
     
    175201 * - ARG2 - size of source as_area (filled automatically by kernel)
    176202 * - ARG3 - flags of the as_area being sent
    177  * 
     203 *
    178204 * on answer, the recipient must set:
    179205 * - ARG1 - dst as_area base adress
    180  */
    181 #define IPC_M_SHARE_OUT         6       
     206 *
     207 */
     208#define IPC_M_SHARE_OUT  6
    182209
    183210/** Receive as_area over IPC.
     
    185212 * - ARG2 - destination as_area size
    186213 * - ARG3 - user defined argument
    187  * 
     214 *
    188215 * on answer, the recipient must set:
    189216 *
    190217 * - ARG1 - source as_area base address
    191218 * - ARG2 - flags that will be used for sharing
    192  */
    193 #define IPC_M_SHARE_IN          7       
     219 *
     220 */
     221#define IPC_M_SHARE_IN  7
    194222
    195223/** Send data to another address space over IPC.
     
    201229 * - ARG1 - final destination address space virtual address
    202230 * - ARG2 - final size of data to be copied
    203  */
    204 #define IPC_M_DATA_WRITE        8
     231 *
     232 */
     233#define IPC_M_DATA_WRITE  8
    205234
    206235/** Receive data from another address space over IPC.
     
    212241 * - ARG1 - source virtual address in the destination address space
    213242 * - ARG2 - final size of data to be copied
    214  */
    215 #define IPC_M_DATA_READ         9
     243 *
     244 */
     245#define IPC_M_DATA_READ  9
    216246
    217247/** Debug the recipient.
    218248 * - ARG1 - specifies the debug method (from udebug_method_t)
    219249 * - other arguments are specific to the debug method
    220  */
    221 #define IPC_M_DEBUG_ALL         10
     250 *
     251 */
     252#define IPC_M_DEBUG_ALL  10
    222253
    223254/* Well-known methods */
    224 #define IPC_M_LAST_SYSTEM       511
    225 #define IPC_M_PING              512
     255#define IPC_M_LAST_SYSTEM  511
     256#define IPC_M_PING         512
     257
    226258/* User methods */
    227 #define IPC_FIRST_USER_METHOD   1024
     259#define IPC_FIRST_USER_METHOD  1024
    228260
    229261#ifdef KERNEL
    230262
    231 #define IPC_MAX_PHONES  16
     263#define IPC_MAX_PHONES  32
    232264
    233265#include <synch/spinlock.h>
     
    261293
    262294typedef struct answerbox {
    263         SPINLOCK_DECLARE(lock);
    264 
     295        IRQ_SPINLOCK_DECLARE(lock);
     296       
    265297        struct task *task;
    266 
     298       
    267299        waitq_t wq;
    268 
     300       
     301        /** Linkage for the list of task's synchronous answerboxes. */
     302        link_t sync_box_link;
     303       
    269304        /** Phones connected to this answerbox. */
    270305        link_t connected_phones;
    271306        /** Received calls. */
    272         link_t calls;                   
    273         link_t dispatched_calls;        /* Should be hash table in the future */
    274 
     307        link_t calls;
     308        link_t dispatched_calls;  /* Should be hash table in the future */
     309       
    275310        /** Answered calls. */
    276311        link_t answers;
    277 
    278         SPINLOCK_DECLARE(irq_lock);
     312       
     313        IRQ_SPINLOCK_DECLARE(irq_lock);
     314       
    279315        /** Notifications from IRQ handlers. */
    280316        link_t irq_notifs;
     
    284320
    285321typedef struct {
    286         unative_t args[IPC_CALL_LEN];
     322        sysarg_t args[IPC_CALL_LEN];
     323        /** Task which made or forwarded the call with IPC_FF_ROUTE_FROM_ME. */
     324        struct task *task;
     325        /** Phone which made or last masqueraded this call. */
    287326        phone_t *phone;
    288327} ipc_data_t;
     
    290329typedef struct {
    291330        link_t link;
    292 
    293         int flags;
    294 
     331       
     332        unsigned int flags;
     333       
    295334        /** Identification of the caller. */
    296335        struct task *sender;
    297         /** The caller box is different from sender->answerbox for synchronous
    298          *  calls. */
     336       
     337        /*
     338         * The caller box is different from sender->answerbox
     339         * for synchronous calls.
     340         */
    299341        answerbox_t *callerbox;
    300 
     342       
    301343        /** Private data to internal IPC. */
    302         unative_t priv;
    303 
     344        sysarg_t priv;
     345       
    304346        /** Data passed from/to userspace. */
    305347        ipc_data_t data;
    306 
     348       
    307349        /** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
    308350        uint8_t *buffer;
    309 
     351       
    310352        /*
    311353         * The forward operation can masquerade the caller phone. For those
     
    316358} call_t;
    317359
     360extern answerbox_t *ipc_phone_0;
     361
    318362extern void ipc_init(void);
    319 extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, int);
    320 extern void ipc_answer(answerbox_t *, call_t *);
     363
     364extern call_t *ipc_call_alloc(unsigned int);
     365extern void ipc_call_free(call_t *);
     366
    321367extern int ipc_call(phone_t *, call_t *);
    322368extern int ipc_call_sync(phone_t *, call_t *);
     369extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int);
     370extern int ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
     371extern void ipc_answer(answerbox_t *, call_t *);
     372
    323373extern void ipc_phone_init(phone_t *);
    324374extern void ipc_phone_connect(phone_t *, answerbox_t *);
    325 extern void ipc_call_free(call_t *);
    326 extern call_t * ipc_call_alloc(int);
     375extern int ipc_phone_hangup(phone_t *);
     376
    327377extern void ipc_answerbox_init(answerbox_t *, struct task *);
    328 extern void ipc_call_static_init(call_t *);
    329 extern void task_print_list(void);
    330 extern int ipc_forward(call_t *, phone_t *, answerbox_t *, int);
     378
    331379extern void ipc_cleanup(void);
    332 extern int ipc_phone_hangup(phone_t *);
    333 extern void ipc_backsend_err(phone_t *, call_t *, unative_t);
    334 extern void ipc_print_task(task_id_t);
     380extern void ipc_backsend_err(phone_t *, call_t *, sysarg_t);
    335381extern void ipc_answerbox_slam_phones(answerbox_t *, bool);
    336382extern void ipc_cleanup_call_list(link_t *);
    337383
    338 extern answerbox_t *ipc_phone_0;
     384extern void ipc_print_task(task_id_t);
     385
     386#endif /* KERNEL */
    339387
    340388#endif
    341389
    342 #endif
    343 
    344390/** @}
    345391 */
Note: See TracChangeset for help on using the changeset viewer.