Ignore:
File:
1 edited

Legend:

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

    r5378f99 r2c0e5d2  
    3636#define KERN_IPC_H_
    3737
    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
     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
    4748
    4849/* Flags for calls */
    4950
    5051/** This is answer to a call */
    51 #define IPC_CALL_ANSWERED  (1 << 0)
    52 
     52#define IPC_CALL_ANSWERED       (1 << 0)
     53/** This call will not be freed on error */
     54#define IPC_CALL_STATIC_ALLOC   (1 << 1)
    5355/** Answer will not be passed to userspace, will be discarded */
    54 #define IPC_CALL_DISCARD_ANSWER  (1 << 1)
    55 
     56#define IPC_CALL_DISCARD_ANSWER (1 << 2)
    5657/** Call was forwarded */
    57 #define IPC_CALL_FORWARDED  (1 << 2)
    58 
     58#define IPC_CALL_FORWARDED      (1 << 3)
    5959/** Identify connect_me_to answer */
    60 #define IPC_CALL_CONN_ME_TO  (1 << 3)
    61 
     60#define IPC_CALL_CONN_ME_TO     (1 << 4)
    6261/** Interrupt notification */
    63 #define IPC_CALL_NOTIF  (1 << 4)
    64 
    65 
    66 /** Bits used in call hashes.
    67  *
     62#define IPC_CALL_NOTIF          (1 << 5)
     63
     64/*
     65 * Bits used in call hashes.
    6866 * The addresses are aligned at least to 4 that is why we can use the 2 least
    6967 * significant bits of the call address.
    70  *
    71  */
    72 
     68 */
    7369/** Type of this call is 'answer' */
    74 #define IPC_CALLID_ANSWERED  1
    75 
     70#define IPC_CALLID_ANSWERED     1
    7671/** Type of this call is 'notification' */
    77 #define IPC_CALLID_NOTIFICATION  2
     72#define IPC_CALLID_NOTIFICATION 2
    7873
    7974/* Return values from sys_ipc_call_async(). */
    80 #define IPC_CALLRET_FATAL      -1
    81 #define IPC_CALLRET_TEMPORARY  -2
     75#define IPC_CALLRET_FATAL       -1
     76#define IPC_CALLRET_TEMPORARY   -2
    8277
    8378
    8479/* Macros for manipulating calling data */
    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])
     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])
    10196
    10297/* Well known phone descriptors */
    103 #define PHONE_NS  0
     98#define PHONE_NS        0
    10499
    105100/* Forwarding flags. */
    106 #define IPC_FF_NONE  0
    107 
     101#define IPC_FF_NONE             0
    108102/**
    109103 * The call will be routed as though it was initially sent via the phone used to
     
    112106 * calls that were initially sent by the forwarder to the same destination. This
    113107 * flag has no imapct on routing replies.
    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 
     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 */
    130114/** Clone connection.
    131115 *
     
    133117 *
    134118 * - ARG1 - The caller sets ARG1 to the phone of the cloned connection.
    135  *        - The callee gets the new phone from ARG1.
    136  *
     119 *        - The callee gets the new phone from ARG1.
    137120 * - on answer, the callee acknowledges the new connection by sending EOK back
    138121 *   or the kernel closes it
    139  *
    140  */
    141 #define IPC_M_CONNECTION_CLONE  1
    142 
     122 */
     123#define IPC_M_CONNECTION_CLONE  1
    143124/** Protocol for CONNECT - ME
    144125 *
    145126 * Through this call, the recipient learns about the new cloned connection.
    146  *
     127 * 
    147128 * - ARG5 - the kernel sets ARG5 to contain the hash of the used phone
    148129 * - on asnwer, the callee acknowledges the new connection by sending EOK back
    149130 *   or the kernel closes it
    150  *
    151  */
    152 #define IPC_M_CONNECT_ME  2
    153 
    154 /** Protocol for CONNECT - TO - ME
     131 */
     132#define IPC_M_CONNECT_ME        2
     133/** Protocol for CONNECT - TO - ME
    155134 *
    156135 * Calling process asks the callee to create a callback connection,
     
    165144 *                       error is sent back to caller. Otherwise
    166145 *                       the call is accepted and the response is sent back.
    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
     146 *                     - the allocated phoneid is passed to userspace
    170147 *                       (on the receiving side) as ARG5 of the call.
    171  *
    172  */
    173 #define IPC_M_CONNECT_TO_ME  3
    174 
     148 */
     149#define IPC_M_CONNECT_TO_ME     3       
    175150/** Protocol for CONNECT - ME - TO
    176151 *
     
    190165 *
    191166 */
    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
     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
    198172
    199173/** Send as_area over IPC.
     
    201175 * - ARG2 - size of source as_area (filled automatically by kernel)
    202176 * - ARG3 - flags of the as_area being sent
    203  *
     177 * 
    204178 * on answer, the recipient must set:
    205179 * - ARG1 - dst as_area base adress
    206  *
    207  */
    208 #define IPC_M_SHARE_OUT  6
     180 */
     181#define IPC_M_SHARE_OUT         6       
    209182
    210183/** Receive as_area over IPC.
     
    212185 * - ARG2 - destination as_area size
    213186 * - ARG3 - user defined argument
    214  *
     187 * 
    215188 * on answer, the recipient must set:
    216189 *
    217190 * - ARG1 - source as_area base address
    218191 * - ARG2 - flags that will be used for sharing
    219  *
    220  */
    221 #define IPC_M_SHARE_IN  7
     192 */
     193#define IPC_M_SHARE_IN          7       
    222194
    223195/** Send data to another address space over IPC.
     
    229201 * - ARG1 - final destination address space virtual address
    230202 * - ARG2 - final size of data to be copied
    231  *
    232  */
    233 #define IPC_M_DATA_WRITE  8
     203 */
     204#define IPC_M_DATA_WRITE        8
    234205
    235206/** Receive data from another address space over IPC.
     
    241212 * - ARG1 - source virtual address in the destination address space
    242213 * - ARG2 - final size of data to be copied
    243  *
    244  */
    245 #define IPC_M_DATA_READ  9
     214 */
     215#define IPC_M_DATA_READ         9
    246216
    247217/** Debug the recipient.
    248218 * - ARG1 - specifies the debug method (from udebug_method_t)
    249219 * - other arguments are specific to the debug method
    250  *
    251  */
    252 #define IPC_M_DEBUG_ALL  10
     220 */
     221#define IPC_M_DEBUG_ALL         10
    253222
    254223/* Well-known methods */
    255 #define IPC_M_LAST_SYSTEM  511
    256 #define IPC_M_PING         512
    257 
     224#define IPC_M_LAST_SYSTEM       511
     225#define IPC_M_PING              512
    258226/* User methods */
    259 #define IPC_FIRST_USER_METHOD  1024
     227#define IPC_FIRST_USER_METHOD   1024
    260228
    261229#ifdef KERNEL
    262230
    263 #define IPC_MAX_PHONES  32
     231#define IPC_MAX_PHONES  16
    264232
    265233#include <synch/spinlock.h>
     
    293261
    294262typedef struct answerbox {
    295         IRQ_SPINLOCK_DECLARE(lock);
    296        
     263        SPINLOCK_DECLARE(lock);
     264
    297265        struct task *task;
    298        
     266
    299267        waitq_t wq;
    300        
    301         /** Linkage for the list of task's synchronous answerboxes. */
    302         link_t sync_box_link;
    303        
     268
    304269        /** Phones connected to this answerbox. */
    305270        link_t connected_phones;
    306271        /** Received calls. */
    307         link_t calls;
    308         link_t dispatched_calls;  /* Should be hash table in the future */
    309        
     272        link_t calls;                   
     273        link_t dispatched_calls;        /* Should be hash table in the future */
     274
    310275        /** Answered calls. */
    311276        link_t answers;
    312        
    313         IRQ_SPINLOCK_DECLARE(irq_lock);
    314        
     277
     278        SPINLOCK_DECLARE(irq_lock);
    315279        /** Notifications from IRQ handlers. */
    316280        link_t irq_notifs;
     
    320284
    321285typedef struct {
    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. */
     286        unative_t args[IPC_CALL_LEN];
    326287        phone_t *phone;
    327288} ipc_data_t;
     
    329290typedef struct {
    330291        link_t link;
    331        
    332         unsigned int flags;
    333        
     292
     293        int flags;
     294
    334295        /** Identification of the caller. */
    335296        struct task *sender;
    336        
    337         /*
    338          * The caller box is different from sender->answerbox
    339          * for synchronous calls.
    340          */
     297        /** The caller box is different from sender->answerbox for synchronous
     298         *  calls. */
    341299        answerbox_t *callerbox;
    342        
     300
    343301        /** Private data to internal IPC. */
    344         sysarg_t priv;
    345        
     302        unative_t priv;
     303
    346304        /** Data passed from/to userspace. */
    347305        ipc_data_t data;
    348        
     306
    349307        /** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
    350308        uint8_t *buffer;
    351        
     309
    352310        /*
    353311         * The forward operation can masquerade the caller phone. For those
     
    358316} call_t;
    359317
    360 extern answerbox_t *ipc_phone_0;
    361 
    362318extern void ipc_init(void);
    363 
    364 extern call_t *ipc_call_alloc(unsigned int);
    365 extern void ipc_call_free(call_t *);
    366 
     319extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, int);
     320extern void ipc_answer(answerbox_t *, call_t *);
    367321extern int ipc_call(phone_t *, call_t *);
    368322extern int ipc_call_sync(phone_t *, call_t *);
    369 extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int);
    370 extern int ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
    371 extern void ipc_answer(answerbox_t *, call_t *);
    372 
    373323extern void ipc_phone_init(phone_t *);
    374324extern void ipc_phone_connect(phone_t *, answerbox_t *);
     325extern void ipc_call_free(call_t *);
     326extern call_t * ipc_call_alloc(int);
     327extern void ipc_answerbox_init(answerbox_t *, struct task *);
     328extern void ipc_call_static_init(call_t *);
     329extern void task_print_list(void);
     330extern int ipc_forward(call_t *, phone_t *, answerbox_t *, int);
     331extern void ipc_cleanup(void);
    375332extern int ipc_phone_hangup(phone_t *);
    376 
    377 extern void ipc_answerbox_init(answerbox_t *, struct task *);
    378 
    379 extern void ipc_cleanup(void);
    380 extern void ipc_backsend_err(phone_t *, call_t *, sysarg_t);
     333extern void ipc_backsend_err(phone_t *, call_t *, unative_t);
     334extern void ipc_print_task(task_id_t);
    381335extern void ipc_answerbox_slam_phones(answerbox_t *, bool);
    382336extern void ipc_cleanup_call_list(link_t *);
    383337
    384 extern void ipc_print_task(task_id_t);
    385 
    386 #endif /* KERNEL */
     338extern answerbox_t *ipc_phone_0;
    387339
    388340#endif
    389341
     342#endif
     343
    390344/** @}
    391345 */
Note: See TracChangeset for help on using the changeset viewer.