Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset da1bafb in mainline for kernel/generic/include/ipc/ipc.h


Ignore:
Timestamp:
2010-05-24T18:57:31Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
0095368
Parents:
666f492
Message:

major code revision

  • replace spinlocks taken with interrupts disabled with irq_spinlocks
  • change spacing (not indendation) to be tab-size independent
  • use unsigned integer types where appropriate (especially bit flags)
  • visual separation
  • remove argument names in function prototypes
  • string changes
  • correct some formating directives
  • replace various cryptic single-character variables (t, a, m, c, b, etc.) with proper identifiers (thread, task, timeout, as, itm, itc, etc.)
  • unify some assembler constructs
  • unused page table levels are now optimized out in compile time
  • replace several ints (with boolean semantics) with bools
  • use specifically sized types instead of generic types where appropriate (size_t, uint32_t, btree_key_t)
  • improve comments
  • split asserts with conjuction into multiple independent asserts
File:
1 edited

Legend:

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

    r666f492 rda1bafb  
    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       
     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
    4144
    4245/** Maximum active async calls per thread */
    4346#ifdef CONFIG_DEBUG
    44 #define IPC_MAX_ASYNC_CALLS     4
     47        #define IPC_MAX_ASYNC_CALLS  4
    4548#else
    46 #define IPC_MAX_ASYNC_CALLS     4000
     49        #define IPC_MAX_ASYNC_CALLS  4000
    4750#endif
    4851
     
    5053
    5154/** This is answer to a call */
    52 #define IPC_CALL_ANSWERED       (1 << 0)
     55#define IPC_CALL_ANSWERED  (1 << 0)
     56
    5357/** Answer will not be passed to userspace, will be discarded */
    54 #define IPC_CALL_DISCARD_ANSWER (1 << 1)
     58#define IPC_CALL_DISCARD_ANSWER  (1 << 1)
     59
    5560/** Call was forwarded */
    56 #define IPC_CALL_FORWARDED      (1 << 2)
     61#define IPC_CALL_FORWARDED  (1 << 2)
     62
    5763/** Identify connect_me_to answer */
    58 #define IPC_CALL_CONN_ME_TO     (1 << 3)
     64#define IPC_CALL_CONN_ME_TO  (1 << 3)
     65
    5966/** Interrupt notification */
    60 #define IPC_CALL_NOTIF          (1 << 4)
    61 
    62 /*
    63  * Bits used in call hashes.
     67#define IPC_CALL_NOTIF  (1 << 4)
     68
     69
     70/** Bits used in call hashes.
     71 *
    6472 * The addresses are aligned at least to 4 that is why we can use the 2 least
    6573 * significant bits of the call address.
    66  */
     74 *
     75 */
     76
    6777/** Type of this call is 'answer' */
    68 #define IPC_CALLID_ANSWERED     1
     78#define IPC_CALLID_ANSWERED  1
     79
    6980/** Type of this call is 'notification' */
    70 #define IPC_CALLID_NOTIFICATION 2
     81#define IPC_CALLID_NOTIFICATION  2
    7182
    7283/* Return values from sys_ipc_call_async(). */
    73 #define IPC_CALLRET_FATAL       -1
    74 #define IPC_CALLRET_TEMPORARY   -2
     84#define IPC_CALLRET_FATAL      -1
     85#define IPC_CALLRET_TEMPORARY  -2
    7586
    7687
    7788/* Macros for manipulating calling data */
    78 #define IPC_SET_RETVAL(data, retval)    ((data).args[0] = (retval))
    79 #define IPC_SET_METHOD(data, val)       ((data).args[0] = (val))
    80 #define IPC_SET_ARG1(data, val)         ((data).args[1] = (val))
    81 #define IPC_SET_ARG2(data, val)         ((data).args[2] = (val))
    82 #define IPC_SET_ARG3(data, val)         ((data).args[3] = (val))
    83 #define IPC_SET_ARG4(data, val)         ((data).args[4] = (val))
    84 #define IPC_SET_ARG5(data, val)         ((data).args[5] = (val))
    85 
    86 #define IPC_GET_METHOD(data)            ((data).args[0])
    87 #define IPC_GET_RETVAL(data)            ((data).args[0])
    88 
    89 #define IPC_GET_ARG1(data)              ((data).args[1])
    90 #define IPC_GET_ARG2(data)              ((data).args[2])
    91 #define IPC_GET_ARG3(data)              ((data).args[3])
    92 #define IPC_GET_ARG4(data)              ((data).args[4])
    93 #define IPC_GET_ARG5(data)              ((data).args[5])
     89#define IPC_SET_RETVAL(data, retval)  ((data).args[0] = (retval))
     90#define IPC_SET_METHOD(data, val)     ((data).args[0] = (val))
     91#define IPC_SET_ARG1(data, val)       ((data).args[1] = (val))
     92#define IPC_SET_ARG2(data, val)       ((data).args[2] = (val))
     93#define IPC_SET_ARG3(data, val)       ((data).args[3] = (val))
     94#define IPC_SET_ARG4(data, val)       ((data).args[4] = (val))
     95#define IPC_SET_ARG5(data, val)       ((data).args[5] = (val))
     96
     97#define IPC_GET_METHOD(data)  ((data).args[0])
     98#define IPC_GET_RETVAL(data)  ((data).args[0])
     99
     100#define IPC_GET_ARG1(data)  ((data).args[1])
     101#define IPC_GET_ARG2(data)  ((data).args[2])
     102#define IPC_GET_ARG3(data)  ((data).args[3])
     103#define IPC_GET_ARG4(data)  ((data).args[4])
     104#define IPC_GET_ARG5(data)  ((data).args[5])
    94105
    95106/* Well known phone descriptors */
    96 #define PHONE_NS        0
     107#define PHONE_NS  0
    97108
    98109/* Forwarding flags. */
    99 #define IPC_FF_NONE             0
     110#define IPC_FF_NONE  0
     111
    100112/**
    101113 * The call will be routed as though it was initially sent via the phone used to
     
    104116 * calls that were initially sent by the forwarder to the same destination. This
    105117 * flag has no imapct on routing replies.
    106  */
    107 #define IPC_FF_ROUTE_FROM_ME    (1 << 0)
    108 
    109 /* System-specific methods - only through special syscalls
     118 *
     119 */
     120#define IPC_FF_ROUTE_FROM_ME  (1 << 0)
     121
     122/** System-specific methods - only through special syscalls
    110123 * These methods have special behaviour
    111  */
     124 *
     125 */
     126
    112127/** Clone connection.
    113128 *
     
    115130 *
    116131 * - ARG1 - The caller sets ARG1 to the phone of the cloned connection.
    117  *        - The callee gets the new phone from ARG1.
     132 *        - The callee gets the new phone from ARG1.
     133 *
    118134 * - on answer, the callee acknowledges the new connection by sending EOK back
    119135 *   or the kernel closes it
    120  */
    121 #define IPC_M_CONNECTION_CLONE  1
     136 *
     137 */
     138#define IPC_M_CONNECTION_CLONE  1
     139
    122140/** Protocol for CONNECT - ME
    123141 *
    124142 * Through this call, the recipient learns about the new cloned connection.
    125  * 
     143 *
    126144 * - ARG5 - the kernel sets ARG5 to contain the hash of the used phone
    127145 * - on asnwer, the callee acknowledges the new connection by sending EOK back
    128146 *   or the kernel closes it
    129  */
    130 #define IPC_M_CONNECT_ME        2
    131 /** Protocol for CONNECT - TO - ME
     147 *
     148 */
     149#define IPC_M_CONNECT_ME  2
     150
     151/** Protocol for CONNECT - TO - ME
    132152 *
    133153 * Calling process asks the callee to create a callback connection,
     
    144164 *                     - the allocated phoneid is passed to userspace
    145165 *                       (on the receiving side) as ARG5 of the call.
    146  */
    147 #define IPC_M_CONNECT_TO_ME     3       
     166 *
     167 */
     168#define IPC_M_CONNECT_TO_ME  3
     169
    148170/** Protocol for CONNECT - ME - TO
    149171 *
     
    163185 *
    164186 */
    165 #define IPC_M_CONNECT_ME_TO     4       
    166 /** This message is sent to answerbox when the phone
    167  * is hung up
    168  */
    169 #define IPC_M_PHONE_HUNGUP      5
     187#define IPC_M_CONNECT_ME_TO  4
     188
     189/** This message is sent to answerbox when the phone is hung up
     190 *
     191 */
     192#define IPC_M_PHONE_HUNGUP  5
    170193
    171194/** Send as_area over IPC.
     
    173196 * - ARG2 - size of source as_area (filled automatically by kernel)
    174197 * - ARG3 - flags of the as_area being sent
    175  * 
     198 *
    176199 * on answer, the recipient must set:
    177200 * - ARG1 - dst as_area base adress
    178  */
    179 #define IPC_M_SHARE_OUT         6       
     201 *
     202 */
     203#define IPC_M_SHARE_OUT  6
    180204
    181205/** Receive as_area over IPC.
     
    183207 * - ARG2 - destination as_area size
    184208 * - ARG3 - user defined argument
    185  * 
     209 *
    186210 * on answer, the recipient must set:
    187211 *
    188212 * - ARG1 - source as_area base address
    189213 * - ARG2 - flags that will be used for sharing
    190  */
    191 #define IPC_M_SHARE_IN          7       
     214 *
     215 */
     216#define IPC_M_SHARE_IN  7
    192217
    193218/** Send data to another address space over IPC.
     
    199224 * - ARG1 - final destination address space virtual address
    200225 * - ARG2 - final size of data to be copied
    201  */
    202 #define IPC_M_DATA_WRITE        8
     226 *
     227 */
     228#define IPC_M_DATA_WRITE  8
    203229
    204230/** Receive data from another address space over IPC.
     
    210236 * - ARG1 - source virtual address in the destination address space
    211237 * - ARG2 - final size of data to be copied
    212  */
    213 #define IPC_M_DATA_READ         9
     238 *
     239 */
     240#define IPC_M_DATA_READ  9
    214241
    215242/** Debug the recipient.
    216243 * - ARG1 - specifies the debug method (from udebug_method_t)
    217244 * - other arguments are specific to the debug method
    218  */
    219 #define IPC_M_DEBUG_ALL         10
     245 *
     246 */
     247#define IPC_M_DEBUG_ALL  10
    220248
    221249/* Well-known methods */
    222 #define IPC_M_LAST_SYSTEM       511
    223 #define IPC_M_PING              512
     250#define IPC_M_LAST_SYSTEM  511
     251#define IPC_M_PING         512
     252
    224253/* User methods */
    225 #define IPC_FIRST_USER_METHOD   1024
     254#define IPC_FIRST_USER_METHOD  1024
    226255
    227256#ifdef KERNEL
     
    259288
    260289typedef struct answerbox {
    261         SPINLOCK_DECLARE(lock);
    262 
     290        IRQ_SPINLOCK_DECLARE(lock);
     291       
    263292        struct task *task;
    264 
     293       
    265294        waitq_t wq;
    266 
     295       
    267296        /** Linkage for the list of task's synchronous answerboxes. */
    268297        link_t sync_box_link;
    269 
     298       
    270299        /** Phones connected to this answerbox. */
    271300        link_t connected_phones;
    272301        /** Received calls. */
    273         link_t calls;                   
    274         link_t dispatched_calls;        /* Should be hash table in the future */
    275 
     302        link_t calls;
     303        link_t dispatched_calls;  /* Should be hash table in the future */
     304       
    276305        /** Answered calls. */
    277306        link_t answers;
    278 
    279         SPINLOCK_DECLARE(irq_lock);
     307       
     308        IRQ_SPINLOCK_DECLARE(irq_lock);
     309       
    280310        /** Notifications from IRQ handlers. */
    281311        link_t irq_notifs;
     
    291321typedef struct {
    292322        link_t link;
    293 
    294         int flags;
    295 
     323       
     324        unsigned int flags;
     325       
    296326        /** Identification of the caller. */
    297327        struct task *sender;
    298         /** The caller box is different from sender->answerbox for synchronous
    299          *  calls. */
     328       
     329        /*
     330         * The caller box is different from sender->answerbox
     331         * for synchronous calls.
     332         *
     333         */
    300334        answerbox_t *callerbox;
    301 
     335       
    302336        /** Private data to internal IPC. */
    303337        unative_t priv;
    304 
     338       
    305339        /** Data passed from/to userspace. */
    306340        ipc_data_t data;
    307 
     341       
    308342        /** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
    309343        uint8_t *buffer;
    310 
     344       
    311345        /*
    312346         * The forward operation can masquerade the caller phone. For those
    313347         * cases, we must keep it aside so that the answer is processed
    314348         * correctly.
     349         *
    315350         */
    316351        phone_t *caller_phone;
    317352} call_t;
    318353
    319 
    320354extern answerbox_t *ipc_phone_0;
    321355
    322 
    323356extern void ipc_init(void);
    324357
    325 extern call_t * ipc_call_alloc(int);
     358extern call_t *ipc_call_alloc(unsigned int);
    326359extern void ipc_call_free(call_t *);
    327360
    328361extern int ipc_call(phone_t *, call_t *);
    329362extern int ipc_call_sync(phone_t *, call_t *);
    330 extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, int);
    331 extern int ipc_forward(call_t *, phone_t *, answerbox_t *, int);
     363extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int);
     364extern int ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
    332365extern void ipc_answer(answerbox_t *, call_t *);
    333366
     
    345378extern void ipc_print_task(task_id_t);
    346379
     380#endif /* KERNEL */
     381
    347382#endif
    348383
    349 #endif
    350 
    351384/** @}
    352385 */
Note: See TracChangeset for help on using the changeset viewer.