ipc.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Ondrej Palkovsky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef __IPC_H__
00036 #define __IPC_H__
00037 
00038 /* Length of data being transfered with IPC call */
00039 /* - the uspace may not be able to utilize full length */
00040 #define IPC_CALL_LEN    4
00041 
00043 #ifdef CONFIG_DEBUG
00044 # define IPC_MAX_ASYNC_CALLS  4
00045 #else
00046 # define IPC_MAX_ASYNC_CALLS  4000
00047 #endif
00048 
00049 /* Flags for calls */
00050 #define IPC_CALL_ANSWERED       (1<<0) 
00051 #define IPC_CALL_STATIC_ALLOC   (1<<1) 
00052 #define IPC_CALL_DISCARD_ANSWER (1<<2) 
00054 #define IPC_CALL_FORWARDED      (1<<3) /* Call was forwarded */
00055 #define IPC_CALL_CONN_ME_TO     (1<<4) /* Identify connect_me_to answer */
00056 #define IPC_CALL_NOTIF          (1<<5) /* Interrupt notification */
00057 
00058 /* Flags of callid (the addresses are aligned at least to 4, 
00059  * that is why we can use bottom 2 bits of the call address
00060  */
00061 #define IPC_CALLID_ANSWERED       1 
00062 #define IPC_CALLID_NOTIFICATION   2 
00064 /* Return values from IPC_ASYNC */
00065 #define IPC_CALLRET_FATAL         -1
00066 #define IPC_CALLRET_TEMPORARY     -2
00067 
00068 
00069 /* Macros for manipulating calling data */
00070 #define IPC_SET_RETVAL(data, retval)   ((data).args[0] = (retval))
00071 #define IPC_SET_METHOD(data, val)   ((data).args[0] = (val))
00072 #define IPC_SET_ARG1(data, val)   ((data).args[1] = (val))
00073 #define IPC_SET_ARG2(data, val)   ((data).args[2] = (val))
00074 #define IPC_SET_ARG3(data, val)   ((data).args[3] = (val))
00075 
00076 #define IPC_GET_METHOD(data)           ((data).args[0])
00077 #define IPC_GET_RETVAL(data)           ((data).args[0])
00078 
00079 #define IPC_GET_ARG1(data)              ((data).args[1])
00080 #define IPC_GET_ARG2(data)              ((data).args[2])
00081 #define IPC_GET_ARG3(data)              ((data).args[3])
00082 
00083 /* Well known phone descriptors */
00084 #define PHONE_NS              0
00085 
00086 /* System-specific methods - only through special syscalls
00087  * These methods have special behaviour
00088  */
00106 #define IPC_M_CONNECT_TO_ME     1
00107 
00125 #define IPC_M_CONNECT_ME_TO     2
00126 
00129 #define IPC_M_PHONE_HUNGUP      3
00130 
00137 #define IPC_M_AS_AREA_SEND      5
00138 
00147 #define IPC_M_AS_AREA_RECV      6
00148 
00149 
00150 /* Well-known methods */
00151 #define IPC_M_LAST_SYSTEM     511
00152 #define IPC_M_PING            512
00153 /* User methods */
00154 #define FIRST_USER_METHOD     1024
00155 
00156 #ifdef KERNEL
00157 
00158 #include <synch/mutex.h>
00159 #include <synch/condvar.h>
00160 #include <adt/list.h>
00161 
00162 #define IPC_MAX_PHONES  16
00163 
00164 typedef struct answerbox_s answerbox_t;
00165 typedef struct phone_s phone_t;
00166 typedef struct {
00167         __native args[IPC_CALL_LEN];
00168         phone_t *phone;
00169 }ipc_data_t;
00170 
00171 struct answerbox_s {
00172         SPINLOCK_DECLARE(lock);
00173 
00174         task_t *task;
00175 
00176         waitq_t wq;
00177 
00178         link_t connected_phones; 
00179         link_t calls;            
00180         link_t dispatched_calls; /* Should be hash table in the future */
00181 
00182         link_t answers;          
00184         SPINLOCK_DECLARE(irq_lock);
00185         link_t irq_notifs;       
00186 };
00187 
00188 typedef enum {
00189         IPC_PHONE_FREE = 0,     
00190         IPC_PHONE_CONNECTING,   
00191         IPC_PHONE_CONNECTED,    
00192         IPC_PHONE_HUNGUP,  
00193         IPC_PHONE_SLAMMED       
00194 } ipc_phone_state_t;
00195 
00197 struct phone_s {
00198         SPINLOCK_DECLARE(lock);
00199         link_t link;
00200         answerbox_t *callee;
00201         ipc_phone_state_t state;
00202         atomic_t active_calls;
00203 };
00204 
00205 typedef struct {
00206         link_t link;
00207 
00208         int flags;
00209 
00210         /* Identification of the caller */
00211         task_t *sender;
00212         /* The caller box is different from sender->answerbox
00213          * for synchronous calls
00214          */
00215         answerbox_t *callerbox;
00216 
00217         __native private; 
00219         ipc_data_t data;  
00220 }call_t;
00221 
00222 extern void ipc_init(void);
00223 extern call_t * ipc_wait_for_call(answerbox_t *box, __u32 usec, int flags);
00224 extern void ipc_answer(answerbox_t *box, call_t *request);
00225 extern int ipc_call(phone_t *phone, call_t *call);
00226 extern void ipc_call_sync(phone_t *phone, call_t *request);
00227 extern void ipc_phone_init(phone_t *phone);
00228 extern void ipc_phone_connect(phone_t *phone, answerbox_t *box);
00229 extern void ipc_call_free(call_t *call);
00230 extern call_t * ipc_call_alloc(int flags);
00231 extern void ipc_answerbox_init(answerbox_t *box);
00232 extern void ipc_call_static_init(call_t *call);
00233 extern void task_print_list(void);
00234 extern int ipc_forward(call_t *call, phone_t *newphone, answerbox_t *oldbox);
00235 void ipc_cleanup(void);
00236 int ipc_phone_hangup(phone_t *phone);
00237 extern void ipc_backsend_err(phone_t *phone, call_t *call, __native err);
00238 extern void ipc_print_task(task_id_t taskid);
00239 
00240 extern answerbox_t *ipc_phone_0;
00241 
00242 #endif
00243 
00244 #endif
00245 

Generated on Sun Jun 18 17:28:03 2006 for HelenOS Kernel (ppc64) by  doxygen 1.4.6