Changeset e74cb73 in mainline
- Timestamp:
- 2006-03-14T09:30:07Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d1f8a87
- Parents:
- 27810c5
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile
r27810c5 re74cb73 135 135 generic/src/synch/waitq.c \ 136 136 generic/src/smp/ipi.c \ 137 generic/src/ipc/ipc.c 137 generic/src/ipc/ipc.c \ 138 generic/src/ipc/ns.c 138 139 139 140 ## Test sources -
generic/include/ipc/ipc.h
r27810c5 re74cb73 30 30 #define __IPC_H__ 31 31 32 #define IPC_CALL_LEN 2 32 /* Length of data being transfered with IPC call */ 33 /* - the uspace may not be able to utilize full length */ 34 #define IPC_CALL_LEN 4 33 35 34 36 /* Flags for calls */ 35 #define IPC_CALL_ANSWERED 1 37 #define IPC_CALL_ANSWERED 1 /**< This is answer to a call */ 38 #define IPC_CALL_STATIC_ALLOC 2 /**< This call will not be freed on error */ 39 36 40 /* Flags for ipc_wait_for_call */ 37 #define IPC_WAIT_NONBLOCKING 1 41 #define IPC_WAIT_NONBLOCKING 1 42 43 /* Flags of callid */ 44 #define IPC_CALLID_ANSWERED 1 45 46 /* Return values from IPC_ASYNC */ 47 #define IPC_CALLRET_FATAL -1 48 #define IPC_CALLRET_TEMPORARY -2 49 50 51 /* Macros for manipulating calling data */ 52 #define IPC_SET_RETVAL(data, retval) ((data)[0] = (retval)) 53 #define IPC_SET_METHOD(data, val) ((data)[0] = (val)) 54 #define IPC_SET_ARG1(data, val) ((data)[1] = (val)) 55 #define IPC_SET_ARG2(data, val) ((data)[2] = (val)) 56 #define IPC_SET_ARG3(data, val) ((data)[3] = (val)) 57 58 #define IPC_GET_METHOD(data) ((data)[0]) 59 #define IPC_GET_RETVAL(data) ((data)[0]) 60 61 #define IPC_GET_ARG1(data) ((data)[1]) 62 #define IPC_GET_ARG2(data) ((data)[2]) 63 #define IPC_GET_ARG3(data) ((data)[3]) 64 65 /* Well known phone descriptors */ 66 #define PHONE_NS 0 38 67 39 68 #ifdef KERNEL 40 69 41 #include <synch/ waitq.h>42 #include <synch/ spinlock.h>70 #include <synch/mutex.h> 71 #include <synch/condvar.h> 43 72 #include <adt/list.h> 44 73 … … 58 87 SPINLOCK_DECLARE(lock); 59 88 60 waitq_t wq; 89 mutex_t mutex; 90 condvar_t cv; 61 91 62 92 link_t connected_phones; /**< Phones connected to this answerbox */ … … 73 103 } phone_t; 74 104 75 extern void ipc_create_phonecompany(void);76 105 extern void ipc_init(void); 77 106 extern call_t * ipc_wait_for_call(answerbox_t *box, int flags); … … 83 112 extern void ipc_call_free(call_t *call); 84 113 extern call_t * ipc_call_alloc(void); 85 void ipc_answerbox_init(answerbox_t *box); 86 void ipc_phone_init(phone_t *phone, answerbox_t *box); 114 extern void ipc_answerbox_init(answerbox_t *box); 115 extern void ipc_phone_init(phone_t *phone, answerbox_t *box); 116 extern void ipc_call_init(call_t *call); 87 117 88 extern answerbox_t *ipc_ central_box;118 extern answerbox_t *ipc_phone_0; 89 119 90 120 #endif -
generic/include/mm/page.h
r27810c5 re74cb73 68 68 } 69 69 70 static inline void copy_ to_kernel(void *dst, void *src, count_t cnt)70 static inline void copy_from_uspace(void *dst, void *src, count_t cnt) 71 71 { 72 72 memcpy(dst, src, cnt); -
generic/include/syscall/syscall.h
r27810c5 re74cb73 34 34 SYS_IO, 35 35 SYS_IPC_CALL_SYNC, 36 SYS_IPC_CALL_SYNC_MEDIUM, 36 37 SYS_IPC_CALL_ASYNC, 37 38 SYS_IPC_ANSWER, -
generic/src/ipc/ipc.c
r27810c5 re74cb73 32 32 */ 33 33 34 #include <synch/waitq.h> 34 #include <synch/condvar.h> 35 #include <synch/mutex.h> 35 36 #include <ipc/ipc.h> 36 37 #include <errno.h> … … 44 45 #include <proc/thread.h> 45 46 46 answerbox_t *ipc_central_box; 47 /* Open channel that is assigned automatically to new tasks */ 48 answerbox_t *ipc_phone_0 = NULL; 47 49 48 50 static slab_cache_t *ipc_call_slab; … … 64 66 } 65 67 68 /** Initialize allocated call */ 69 void ipc_call_init(call_t *call) 70 { 71 call->callerbox = &TASK->answerbox; 72 call->flags = IPC_CALL_STATIC_ALLOC; 73 } 74 66 75 /** Deallocate call stracuture */ 67 76 void ipc_call_free(call_t *call) … … 74 83 void ipc_answerbox_init(answerbox_t *box) 75 84 { 76 spinlock_initialize(&box->lock, "abox_lock");77 waitq_initialize(&box->wq);85 mutex_initialize(&box->mutex); 86 condvar_initialize(&box->cv); 78 87 list_initialize(&box->connected_phones); 79 88 list_initialize(&box->calls); … … 89 98 90 99 phone->callee = box; 91 spinlock_lock(&box->lock); 100 101 mutex_lock(&box->mutex); 92 102 list_append(&phone->list, &box->connected_phones); 93 spinlock_unlock(&box->lock);103 mutex_unlock(&box->mutex); 94 104 } 95 105 … … 101 111 ASSERT(box); 102 112 103 spinlock_lock(&box->lock);113 mutex_lock(&box->mutex); 104 114 list_remove(&phone->list); 105 spinlock_unlock(&box->lock);115 mutex_unlock(&box->mutex); 106 116 } 107 117 … … 131 141 ASSERT(box); 132 142 133 spinlock_lock(&box->lock);143 mutex_lock(&box->mutex); 134 144 list_append(&request->list, &box->calls); 135 spinlock_unlock(&box->lock);136 waitq_wakeup(&box->wq, 0);145 mutex_unlock(&box->mutex); 146 condvar_signal(&box->cv); 137 147 } 138 148 … … 148 158 request->flags |= IPC_CALL_ANSWERED; 149 159 150 spinlock_lock(&box->lock); 151 spinlock_lock(&callerbox->lock); 152 160 mutex_lock(&box->mutex); 153 161 list_remove(&request->list); 162 mutex_unlock(&box->mutex); 163 164 mutex_lock(&callerbox->mutex); 154 165 list_append(&request->list, &callerbox->answers); 155 waitq_wakeup(&callerbox->wq, 0); 156 157 spinlock_unlock(&callerbox->lock); 158 spinlock_unlock(&box->lock); 166 mutex_unlock(&callerbox->mutex); 167 condvar_signal(&callerbox->cv); 159 168 } 160 169 … … 168 177 call_t *request; 169 178 170 if ((flags & IPC_WAIT_NONBLOCKING)) { 171 if (waitq_sleep_timeout(&box->wq,SYNCH_NO_TIMEOUT,SYNCH_NON_BLOCKING) == ESYNCH_WOULD_BLOCK) 172 return 0; 173 } else { 174 waitq_sleep(&box->wq); 179 mutex_lock(&box->mutex); 180 while (1) { 181 if (!list_empty(&box->answers)) { 182 /* Handle asynchronous answers */ 183 request = list_get_instance(box->answers.next, call_t, list); 184 list_remove(&request->list); 185 } else if (!list_empty(&box->calls)) { 186 /* Handle requests */ 187 request = list_get_instance(box->calls.next, call_t, list); 188 list_remove(&request->list); 189 /* Append request to dispatch queue */ 190 list_append(&request->list, &box->dispatched_calls); 191 } else { 192 if (!(flags & IPC_WAIT_NONBLOCKING)) { 193 condvar_wait(&box->cv, &box->mutex); 194 continue; 195 } 196 if (condvar_trywait(&box->cv, &box->mutex) != ESYNCH_WOULD_BLOCK) 197 continue; 198 request = NULL; 199 } 200 break; 175 201 } 176 177 178 // TODO - might need condition variable+mutex if we want to support 179 // removing of requests from queue before dispatch 180 spinlock_lock(&box->lock); 181 /* Handle answers first */ 182 if (!list_empty(&box->answers)) { 183 request = list_get_instance(box->answers.next, call_t, list); 184 list_remove(&request->list); 185 } else { 186 ASSERT (! list_empty(&box->calls)); 187 request = list_get_instance(box->calls.next, call_t, list); 188 list_remove(&request->list); 189 /* Append request to dispatch queue */ 190 list_append(&request->list, &box->dispatched_calls); 191 } 192 spinlock_unlock(&box->lock); 193 202 mutex_unlock(&box->mutex); 194 203 return request; 195 204 } … … 203 212 NULL, NULL, 0); 204 213 } 205 206 static void ipc_phonecompany_thread(void *data)207 {208 call_t *call;209 210 printf("Phone company started.\n");211 while (1) {212 call = ipc_wait_for_call(&TASK->answerbox, 0);213 printf("Received phone call - %P %P\n",214 call->data[0], call->data[1]);215 call->data[0] = 0xbabaaaee;;216 call->data[1] = 0xaaaaeeee;217 ipc_answer(&TASK->answerbox, call);218 printf("Call answered.\n");219 }220 }221 222 void ipc_create_phonecompany(void)223 {224 thread_t *t;225 226 if ((t = thread_create(ipc_phonecompany_thread, "phonecompany",227 TASK, 0)))228 thread_ready(t);229 else230 panic("thread_create/phonecompany");231 232 ipc_central_box = &TASK->answerbox;233 } -
generic/src/main/kinit.c
r27810c5 re74cb73 48 48 #include <console/kconsole.h> 49 49 #include <elf.h> 50 #include <ipc/ns.h> 50 51 51 52 #ifdef CONFIG_SMP … … 139 140 interrupts_enable(); 140 141 141 ipc_create_phonecompany(); 142 /* Initialize name service */ 143 ns_start(); 142 144 143 145 if (config.init_size > 0) { -
generic/src/proc/task.c
r27810c5 re74cb73 37 37 #include <adt/list.h> 38 38 #include <ipc/ipc.h> 39 #include <ipc/ns.h> 39 40 #include <memstr.h> 40 41 … … 76 77 ipc_answerbox_init(&ta->answerbox); 77 78 memsetb((__address)&ta->phones, sizeof(ta->phones[0])*IPC_MAX_PHONES, 0); 78 if (ipc_ central_box)79 ipc_phone_init(&ta->phones[0], ipc_ central_box);79 if (ipc_phone_0) 80 ipc_phone_init(&ta->phones[0], ipc_phone_0); 80 81 81 82 ipl = interrupts_disable(); -
generic/src/syscall/syscall.c
r27810c5 re74cb73 61 61 -2 on 'Too many async request, handle answers first 62 62 */ 63 static __native sys_ipc_call_sync(__native phoneid, __native arg1,64 __native arg 2, __native *respdata)63 static __native sys_ipc_call_sync(__native phoneid, __native method, 64 __native arg1, __native *data) 65 65 { 66 call_t *call;66 call_t call; 67 67 phone_t *phone; 68 68 /* Special answerbox for synchronous messages */ 69 69 70 70 if (phoneid >= IPC_MAX_PHONES) 71 return -ENOENT;71 return IPC_CALLRET_FATAL; 72 72 73 73 phone = &TASK->phones[phoneid]; 74 74 if (!phone->callee) 75 return -ENOENT;75 return IPC_CALLRET_FATAL; 76 76 77 call = ipc_call_alloc();78 call->data[0] = arg1;79 call->data[1] = arg2;77 ipc_call_init(&call); 78 IPC_SET_METHOD(call.data, method); 79 IPC_SET_ARG1(call.data, arg1); 80 80 81 ipc_call_sync(phone, call);81 ipc_call_sync(phone, &call); 82 82 83 copy_to_uspace( respdata, &call->data, sizeof(__native) * IPC_CALL_LEN);83 copy_to_uspace(data, &call.data, sizeof(call.data)); 84 84 85 85 return 0; 86 86 } 87 88 static __native sys_ipc_call_sync_medium(__native phoneid, __native *data) 89 { 90 call_t call; 91 phone_t *phone; 92 /* Special answerbox for synchronous messages */ 93 94 if (phoneid >= IPC_MAX_PHONES) 95 return IPC_CALLRET_FATAL; 96 97 phone = &TASK->phones[phoneid]; 98 if (!phone->callee) 99 return IPC_CALLRET_FATAL; 100 101 ipc_call_init(&call); 102 copy_from_uspace(&call.data, data, sizeof(call.data)); 103 104 ipc_call_sync(phone, &call); 105 106 copy_to_uspace(data, &call.data, sizeof(call.data)); 107 108 return 0; 109 } 110 87 111 88 112 /** Send an asynchronous call over ipc … … 91 115 -2 on 'Too many async request, handle answers first 92 116 */ 93 static __native sys_ipc_call_async(__native phoneid, __native arg1,94 __native arg 2)117 static __native sys_ipc_call_async(__native phoneid, __native method, 118 __native arg1, __native arg2) 95 119 { 96 120 call_t *call; … … 98 122 99 123 if (phoneid >= IPC_MAX_PHONES) 100 return -ENOENT;124 return IPC_CALLRET_FATAL; 101 125 102 126 phone = &TASK->phones[phoneid]; 103 127 if (!phone->callee) 104 return -ENOENT; 105 128 return IPC_CALLRET_FATAL; 106 129 107 130 /* TODO: Check that we did not exceed system imposed maximum … … 110 133 */ 111 134 call = ipc_call_alloc(); 112 call->data[0] = arg1; 113 call->data[1] = arg2; 135 IPC_SET_METHOD(call->data, method); 136 IPC_SET_ARG1(call->data, arg1); 137 IPC_SET_ARG2(call->data, arg2); 138 114 139 ipc_call(phone, call); 115 140 … … 118 143 119 144 /** Send IPC answer */ 120 static __native sys_ipc_answer(__native callid, __native arg1, __native arg2) 145 static __native sys_ipc_answer(__native callid, __native retval, __native arg1, 146 __native arg2) 121 147 { 122 148 call_t *call; … … 127 153 call = (call_t *) callid; 128 154 129 call->data[0] = arg1; 130 call->data[1] = arg2; 155 IPC_SET_RETVAL(call->data, retval); 156 IPC_SET_ARG1(call->data, arg1); 157 IPC_SET_ARG2(call->data, arg2); 131 158 132 159 ipc_answer(&TASK->answerbox, call); … … 145 172 146 173 call = ipc_wait_for_call(&TASK->answerbox, flags); 147 copy_to_uspace(calldata, &call->data, sizeof(__native) * IPC_CALL_LEN);148 174 149 if (call->flags & IPC_CALL_ANSWERED) 150 return ((__native)call) | 1; 175 copy_to_uspace(calldata, &call->data, sizeof(call->data)); 176 if (call->flags & IPC_CALL_ANSWERED) { 177 ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC)); 178 ipc_call_free(call); 179 return ((__native)call) | IPC_CALLID_ANSWERED; 180 } 151 181 return (__native)call; 152 182 } … … 157 187 sys_io, 158 188 sys_ipc_call_sync, 189 sys_ipc_call_sync_medium, 159 190 sys_ipc_call_async, 160 191 sys_ipc_answer,
Note:
See TracChangeset
for help on using the changeset viewer.