Changeset 67f11a0 in mainline for kernel/generic/src/ipc/ipcrsc.c
- Timestamp:
- 2018-03-15T17:40:20Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 530f2de, e9e4068
- Parents:
- 30f1a25 (diff), a36f442 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Jakub Jermar <jakub@…> (2018-03-15 17:25:56)
- git-committer:
- Jakub Jermar <jakub@…> (2018-03-15 17:40:20)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/ipc/ipcrsc.c
r30f1a25 r67f11a0 39 39 * 40 40 * The pattern of usage of the resources is: 41 * - allocate empty phone capability slot, connect | deallocate slot 41 * - allocate a capability and phone kernel object (do not publish yet), 42 * connect to the answerbox, and finally publish the capability 42 43 * - disconnect connected phone (some messages might be on the fly) 43 * - find phone in slotand send a message using phone44 * - find phone capability and send a message using phone 44 45 * - answer message to phone 45 46 * - hangup phone (the caller has hung up) … … 53 54 * atomic on all platforms) 54 55 * 55 * - To find an empty phone capability slot, the TASK must be locked56 56 * - To answer a message, the answerbox must be locked 57 57 * - The locking of phone and answerbox is done at the ipc_ level. … … 73 73 * *** Connect_me_to *** 74 74 * The caller sends IPC_M_CONNECT_ME_TO to an answerbox. The server receives 75 * 'phoneid' of the connecting phone as an ARG5. If it answers with RETVAL= 0,76 * the phone call is accepted, otherwise it is refused.75 * 'phoneid' of the connecting phone as an ARG5. If it answers with RETVAL=EOK, 76 * the phone call is accepted, otherwise it is refused. 77 77 * 78 78 * *** Connect_to_me *** 79 79 * The caller sends IPC_M_CONNECT_TO_ME. 80 80 * The server receives an automatically opened phoneid. If it accepts 81 * (RETVAL= 0), it can use the phoneid immediately.Possible race condition can81 * (RETVAL=EOK), it can use the phoneid immediately. Possible race condition can 82 82 * arise, when the client receives messages from new connection before getting 83 83 * response for connect_to_me message. Userspace should implement handshake … … 95 95 * - The phone is disconnected. EHANGUP response code is sent to the calling 96 96 * task. All new calls through this phone get a EHUNGUP error code, the task 97 * is expected to send ansys_ipc_hangup after cleaning up its internal97 * is expected to call sys_ipc_hangup after cleaning up its internal 98 98 * structures. 99 99 * … … 137 137 #include <mm/slab.h> 138 138 139 static bool phone_reclaim(kobject_t *kobj)140 {141 bool gc = false;142 143 mutex_lock(&kobj->phone->lock);144 if (kobj->phone->state == IPC_PHONE_HUNGUP &&145 atomic_get(&kobj->phone->active_calls) == 0)146 gc = true;147 mutex_unlock(&kobj->phone->lock);148 149 return gc;150 }151 152 139 static void phone_destroy(void *arg) 153 140 { … … 157 144 158 145 static kobject_ops_t phone_kobject_ops = { 159 .reclaim = phone_reclaim,160 146 .destroy = phone_destroy 161 147 }; … … 164 150 /** Allocate new phone in the specified task. 165 151 * 166 * @param task Task for which to allocate a new phone. 167 * 168 * @param[out] out_handle New phone capability handle. 152 * @param[in] task Task for which to allocate a new phone. 153 * @param[in] publish If true, the new capability will be published. 154 * @param[out] phandle New phone capability handle. 155 * @param[out] kobject New phone kobject. 169 156 * 170 157 * @return An error code if a new capability cannot be allocated. 171 158 */ 172 errno_t phone_alloc(task_t *task, cap_handle_t *out_handle) 159 errno_t phone_alloc(task_t *task, bool publish, cap_handle_t *phandle, 160 kobject_t **kobject) 173 161 { 174 162 cap_handle_t handle; … … 180 168 return ENOMEM; 181 169 } 182 kobject_t *kobj ect= malloc(sizeof(kobject_t), FRAME_ATOMIC);183 if (!kobj ect) {170 kobject_t *kobj = malloc(sizeof(kobject_t), FRAME_ATOMIC); 171 if (!kobj) { 184 172 cap_free(TASK, handle); 185 173 slab_free(phone_cache, phone); … … 190 178 phone->state = IPC_PHONE_CONNECTING; 191 179 192 kobject_initialize(kobj ect, KOBJECT_TYPE_PHONE, phone,180 kobject_initialize(kobj, KOBJECT_TYPE_PHONE, phone, 193 181 &phone_kobject_ops); 194 phone->kobject = kobject; 195 196 cap_publish(task, handle, kobject); 197 198 *out_handle = handle; 182 phone->kobject = kobj; 183 184 if (publish) 185 cap_publish(task, handle, kobj); 186 187 *phandle = handle; 188 if (kobject) 189 *kobject = kobj; 199 190 } 200 191 return rc; … … 214 205 return; 215 206 216 assert(kobj->phone);217 assert(kobj->phone->state == IPC_PHONE_CONNECTING);218 219 207 kobject_put(kobj); 220 208 cap_free(TASK, handle); 221 209 } 222 210 223 /** Connect phone to a given answerbox.224 *225 * @param handle Capability handle of the phone to be connected.226 * @param box Answerbox to which to connect the phone.227 * @return True if the phone was connected, false otherwise.228 */229 bool phone_connect(cap_handle_t handle, answerbox_t *box)230 {231 kobject_t *phone_obj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);232 if (!phone_obj)233 return false;234 235 assert(phone_obj->phone->state == IPC_PHONE_CONNECTING);236 237 /* Hand over phone_obj reference to the answerbox */238 return ipc_phone_connect(phone_obj->phone, box);239 }240 241 211 /** @} 242 212 */
Note:
See TracChangeset
for help on using the changeset viewer.