Changes in uspace/lib/drv/generic/driver.c [26fa82bc:b72efe8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/driver.c
r26fa82bc rb72efe8 139 139 find_interrupt_context_by_id(interrupt_context_list_t *list, int id) 140 140 { 141 interrupt_context_t *ctx; 142 141 143 fibril_mutex_lock(&list->mutex); 142 144 143 link_t *link = list->contexts.next; 144 interrupt_context_t *ctx; 145 146 while (link != &list->contexts) { 145 list_foreach(list->contexts, link) { 147 146 ctx = list_get_instance(link, interrupt_context_t, link); 148 147 if (ctx->id == id) { … … 150 149 return ctx; 151 150 } 152 link = link->next;153 151 } 154 152 … … 160 158 find_interrupt_context(interrupt_context_list_t *list, ddf_dev_t *dev, int irq) 161 159 { 160 interrupt_context_t *ctx; 161 162 162 fibril_mutex_lock(&list->mutex); 163 163 164 link_t *link = list->contexts.next; 165 interrupt_context_t *ctx; 166 167 while (link != &list->contexts) { 164 list_foreach(list->contexts, link) { 168 165 ctx = list_get_instance(link, interrupt_context_t, link); 169 166 if (ctx->irq == irq && ctx->dev == dev) { … … 171 168 return ctx; 172 169 } 173 link = link->next;174 170 } 175 171 … … 231 227 } 232 228 233 static ddf_fun_t *driver_get_function(li nk_t *functions, devman_handle_t handle)229 static ddf_fun_t *driver_get_function(list_t *functions, devman_handle_t handle) 234 230 { 235 231 ddf_fun_t *fun = NULL; 236 232 237 233 fibril_mutex_lock(&functions_mutex); 238 link_t *link = functions->next; 239 240 while (link != functions) { 234 235 list_foreach(*functions, link) { 241 236 fun = list_get_instance(link, ddf_fun_t, link); 242 237 if (fun->handle == handle) { … … 244 239 return fun; 245 240 } 246 247 link = link->next;248 241 } 249 242 … … 285 278 async_answer_0(iid, EOK); 286 279 287 bool cont = true; 288 while (cont) { 280 while (true) { 289 281 ipc_call_t call; 290 282 ipc_callid_t callid = async_get_call(&call); 291 283 284 if (!IPC_GET_IMETHOD(call)) 285 break; 286 292 287 switch (IPC_GET_IMETHOD(call)) { 293 case IPC_M_PHONE_HUNGUP:294 cont = false;295 continue;296 288 case DRIVER_ADD_DEVICE: 297 289 driver_add_device(callid, &call); … … 303 295 } 304 296 305 /** 306 * Generic client connection handler both for applications and drivers.307 * 308 * @param drv True for driver client, false for other clients309 * (applications, services etc.).297 /** Generic client connection handler both for applications and drivers. 298 * 299 * @param drv True for driver client, false for other clients 300 * (applications, services, etc.). 301 * 310 302 */ 311 303 static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool drv) … … 317 309 devman_handle_t handle = IPC_GET_ARG2(*icall); 318 310 ddf_fun_t *fun = driver_get_function(&functions, handle); 319 311 320 312 if (fun == NULL) { 321 313 printf("%s: driver_connection_gen error - no function with handle" … … 325 317 } 326 318 327 328 319 /* 329 320 * TODO - if the client is not a driver, check whether it is allowed to … … 340 331 return; 341 332 342 while ( 1) {333 while (true) { 343 334 ipc_callid_t callid; 344 335 ipc_call_t call; 345 336 callid = async_get_call(&call); 346 337 sysarg_t method = IPC_GET_IMETHOD(call); 347 int iface_idx; 348 349 switch (method) { 350 case IPC_M_PHONE_HUNGUP: 338 339 if (!method) { 351 340 /* Close device function */ 352 341 if (fun->ops != NULL && fun->ops->close != NULL) … … 354 343 async_answer_0(callid, EOK); 355 344 return; 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; 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; 391 357 } 392 358 393 359 /* 394 * Get the corresponding interface for remote request395 * handling ("remote interface").360 * Function has no such interface and 361 * default handler is not provided. 396 362 */ 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; 420 } 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; 368 } 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 request 384 * 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 will 403 * receive parameters from the remote client and it will 404 * pass it to the corresponding local interface method 405 * associated with the function by its driver. 406 */ 407 (*iface_method_ptr)(fun, ops, callid, &call); 421 408 } 422 409 } … … 433 420 434 421 /** Function for handling connections to device driver. */ 435 static void driver_connection(ipc_callid_t iid, ipc_call_t *icall )422 static void driver_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 436 423 { 437 424 /* Select interface */
Note:
See TracChangeset
for help on using the changeset viewer.