Changes in uspace/lib/drv/generic/driver.c [b72efe8:26fa82bc] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/driver.c
rb72efe8 r26fa82bc 139 139 find_interrupt_context_by_id(interrupt_context_list_t *list, int id) 140 140 { 141 fibril_mutex_lock(&list->mutex); 142 143 link_t *link = list->contexts.next; 141 144 interrupt_context_t *ctx; 142 145 143 fibril_mutex_lock(&list->mutex); 144 145 list_foreach(list->contexts, link) { 146 while (link != &list->contexts) { 146 147 ctx = list_get_instance(link, interrupt_context_t, link); 147 148 if (ctx->id == id) { … … 149 150 return ctx; 150 151 } 152 link = link->next; 151 153 } 152 154 … … 158 160 find_interrupt_context(interrupt_context_list_t *list, ddf_dev_t *dev, int irq) 159 161 { 162 fibril_mutex_lock(&list->mutex); 163 164 link_t *link = list->contexts.next; 160 165 interrupt_context_t *ctx; 161 166 162 fibril_mutex_lock(&list->mutex); 163 164 list_foreach(list->contexts, link) { 167 while (link != &list->contexts) { 165 168 ctx = list_get_instance(link, interrupt_context_t, link); 166 169 if (ctx->irq == irq && ctx->dev == dev) { … … 168 171 return ctx; 169 172 } 173 link = link->next; 170 174 } 171 175 … … 227 231 } 228 232 229 static ddf_fun_t *driver_get_function(li st_t *functions, devman_handle_t handle)233 static ddf_fun_t *driver_get_function(link_t *functions, devman_handle_t handle) 230 234 { 231 235 ddf_fun_t *fun = NULL; 232 236 233 237 fibril_mutex_lock(&functions_mutex); 234 235 list_foreach(*functions, link) { 238 link_t *link = functions->next; 239 240 while (link != functions) { 236 241 fun = list_get_instance(link, ddf_fun_t, link); 237 242 if (fun->handle == handle) { … … 239 244 return fun; 240 245 } 246 247 link = link->next; 241 248 } 242 249 … … 278 285 async_answer_0(iid, EOK); 279 286 280 while (true) { 287 bool cont = true; 288 while (cont) { 281 289 ipc_call_t call; 282 290 ipc_callid_t callid = async_get_call(&call); 283 291 284 if (!IPC_GET_IMETHOD(call))285 break;286 287 292 switch (IPC_GET_IMETHOD(call)) { 293 case IPC_M_PHONE_HUNGUP: 294 cont = false; 295 continue; 288 296 case DRIVER_ADD_DEVICE: 289 297 driver_add_device(callid, &call); … … 295 303 } 296 304 297 /** Generic client connection handler both for applications and drivers.298 * 299 * @param drv True for driver client, false for other clients300 * (applications, services, etc.).301 * 305 /** 306 * Generic client connection handler both for applications and drivers. 307 * 308 * @param drv True for driver client, false for other clients 309 * (applications, services etc.). 302 310 */ 303 311 static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool drv) … … 309 317 devman_handle_t handle = IPC_GET_ARG2(*icall); 310 318 ddf_fun_t *fun = driver_get_function(&functions, handle); 311 319 312 320 if (fun == NULL) { 313 321 printf("%s: driver_connection_gen error - no function with handle" … … 317 325 } 318 326 327 319 328 /* 320 329 * TODO - if the client is not a driver, check whether it is allowed to … … 331 340 return; 332 341 333 while ( true) {342 while (1) { 334 343 ipc_callid_t callid; 335 344 ipc_call_t call; 336 345 callid = async_get_call(&call); 337 346 sysarg_t method = IPC_GET_IMETHOD(call); 347 int iface_idx; 338 348 339 if (!method) { 349 switch (method) { 350 case IPC_M_PHONE_HUNGUP: 340 351 /* Close device function */ 341 352 if (fun->ops != NULL && fun->ops->close != NULL) … … 343 354 async_answer_0(callid, EOK); 344 355 return; 345 } 346 347 /* Convert ipc interface id to interface index */ 348 349 int iface_idx = DEV_IFACE_IDX(method); 350 351 if (!is_valid_iface_idx(iface_idx)) { 352 remote_handler_t *default_handler = 353 function_get_default_handler(fun); 354 if (default_handler != NULL) { 355 (*default_handler)(fun, callid, &call); 356 continue; 356 default: 357 /* convert ipc interface id to interface index */ 358 359 iface_idx = DEV_IFACE_IDX(method); 360 361 if (!is_valid_iface_idx(iface_idx)) { 362 remote_handler_t *default_handler = 363 function_get_default_handler(fun); 364 if (default_handler != NULL) { 365 (*default_handler)(fun, callid, &call); 366 break; 367 } 368 369 /* 370 * Function has no such interface and 371 * default handler is not provided. 372 */ 373 printf("%s: driver_connection_gen error - " 374 "invalid interface id %d.", 375 driver->name, iface_idx); 376 async_answer_0(callid, ENOTSUP); 377 break; 378 } 379 380 /* calling one of the function's interfaces */ 381 382 /* Get the interface ops structure. */ 383 void *ops = function_get_ops(fun, iface_idx); 384 if (ops == NULL) { 385 printf("%s: driver_connection_gen error - ", 386 driver->name); 387 printf("Function with handle %" PRIun " has no interface " 388 "with id %d.\n", handle, iface_idx); 389 async_answer_0(callid, ENOTSUP); 390 break; 357 391 } 358 392 359 393 /* 360 * Function has no such interface and361 * default handler is not provided.394 * Get the corresponding interface for remote request 395 * handling ("remote interface"). 362 396 */ 363 printf("%s: driver_connection_gen error - " 364 "invalid interface id %d.", 365 driver->name, iface_idx); 366 async_answer_0(callid, ENOTSUP); 367 continue; 397 remote_iface_t *rem_iface = get_remote_iface(iface_idx); 398 assert(rem_iface != NULL); 399 400 /* get the method of the remote interface */ 401 sysarg_t iface_method_idx = IPC_GET_ARG1(call); 402 remote_iface_func_ptr_t iface_method_ptr = 403 get_remote_method(rem_iface, iface_method_idx); 404 if (iface_method_ptr == NULL) { 405 /* The interface has not such method */ 406 printf("%s: driver_connection_gen error - " 407 "invalid interface method.", driver->name); 408 async_answer_0(callid, ENOTSUP); 409 break; 410 } 411 412 /* 413 * Call the remote interface's method, which will 414 * receive parameters from the remote client and it will 415 * pass it to the corresponding local interface method 416 * associated with the function by its driver. 417 */ 418 (*iface_method_ptr)(fun, ops, callid, &call); 419 break; 368 420 } 369 370 /* Calling one of the function's interfaces */371 372 /* Get the interface ops structure. */373 void *ops = function_get_ops(fun, iface_idx);374 if (ops == NULL) {375 printf("%s: driver_connection_gen error - ", driver->name);376 printf("Function with handle %" PRIun " has no interface "377 "with id %d.\n", handle, iface_idx);378 async_answer_0(callid, ENOTSUP);379 continue;380 }381 382 /*383 * Get the corresponding interface for remote request384 * handling ("remote interface").385 */386 remote_iface_t *rem_iface = get_remote_iface(iface_idx);387 assert(rem_iface != NULL);388 389 /* get the method of the remote interface */390 sysarg_t iface_method_idx = IPC_GET_ARG1(call);391 remote_iface_func_ptr_t iface_method_ptr =392 get_remote_method(rem_iface, iface_method_idx);393 if (iface_method_ptr == NULL) {394 /* The interface has not such method */395 printf("%s: driver_connection_gen error - "396 "invalid interface method.", driver->name);397 async_answer_0(callid, ENOTSUP);398 continue;399 }400 401 /*402 * Call the remote interface's method, which will403 * receive parameters from the remote client and it will404 * pass it to the corresponding local interface method405 * associated with the function by its driver.406 */407 (*iface_method_ptr)(fun, ops, callid, &call);408 421 } 409 422 } … … 420 433 421 434 /** Function for handling connections to device driver. */ 422 static void driver_connection(ipc_callid_t iid, ipc_call_t *icall , void *arg)435 static void driver_connection(ipc_callid_t iid, ipc_call_t *icall) 423 436 { 424 437 /* Select interface */
Note:
See TracChangeset
for help on using the changeset viewer.