Changeset c028b22 in mainline for uspace/lib/drv/generic/driver.c
- Timestamp:
- 2011-07-08T17:01:01Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cc1a727
- Parents:
- 4e36219 (diff), 026793d (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/driver.c
r4e36219 rc028b22 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 319 if (fun->conn_handler != NULL) { 320 /* Driver has a custom connection handler. */ 321 (*fun->conn_handler)(iid, icall, (void *)fun); 322 return; 323 } 327 324 328 325 /* … … 340 337 return; 341 338 342 while ( 1) {339 while (true) { 343 340 ipc_callid_t callid; 344 341 ipc_call_t call; 345 342 callid = async_get_call(&call); 346 343 sysarg_t method = IPC_GET_IMETHOD(call); 347 int iface_idx; 348 349 switch (method) { 350 case IPC_M_PHONE_HUNGUP: 344 345 if (!method) { 351 346 /* Close device function */ 352 347 if (fun->ops != NULL && fun->ops->close != NULL) … … 354 349 async_answer_0(callid, EOK); 355 350 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; 351 } 352 353 /* Convert ipc interface id to interface index */ 354 355 int iface_idx = DEV_IFACE_IDX(method); 356 357 if (!is_valid_iface_idx(iface_idx)) { 358 remote_handler_t *default_handler = 359 function_get_default_handler(fun); 360 if (default_handler != NULL) { 361 (*default_handler)(fun, callid, &call); 362 continue; 391 363 } 392 364 393 365 /* 394 * Get the corresponding interface for remote request395 * handling ("remote interface").366 * Function has no such interface and 367 * default handler is not provided. 396 368 */ 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 } 369 printf("%s: driver_connection_gen error - " 370 "invalid interface id %d.", 371 driver->name, iface_idx); 372 async_answer_0(callid, ENOTSUP); 373 continue; 374 } 375 376 /* Calling one of the function's interfaces */ 377 378 /* Get the interface ops structure. */ 379 void *ops = function_get_ops(fun, iface_idx); 380 if (ops == NULL) { 381 printf("%s: driver_connection_gen error - ", driver->name); 382 printf("Function with handle %" PRIun " has no interface " 383 "with id %d.\n", handle, iface_idx); 384 async_answer_0(callid, ENOTSUP); 385 continue; 386 } 387 388 /* 389 * Get the corresponding interface for remote request 390 * handling ("remote interface"). 391 */ 392 remote_iface_t *rem_iface = get_remote_iface(iface_idx); 393 assert(rem_iface != NULL); 394 395 /* get the method of the remote interface */ 396 sysarg_t iface_method_idx = IPC_GET_ARG1(call); 397 remote_iface_func_ptr_t iface_method_ptr = 398 get_remote_method(rem_iface, iface_method_idx); 399 if (iface_method_ptr == NULL) { 400 /* The interface has not such method */ 401 printf("%s: driver_connection_gen error - " 402 "invalid interface method.", driver->name); 403 async_answer_0(callid, ENOTSUP); 404 continue; 405 } 406 407 /* 408 * Call the remote interface's method, which will 409 * receive parameters from the remote client and it will 410 * pass it to the corresponding local interface method 411 * associated with the function by its driver. 412 */ 413 (*iface_method_ptr)(fun, ops, callid, &call); 421 414 } 422 415 } … … 433 426 434 427 /** Function for handling connections to device driver. */ 435 static void driver_connection(ipc_callid_t iid, ipc_call_t *icall )428 static void driver_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 436 429 { 437 430 /* Select interface */
Note:
See TracChangeset
for help on using the changeset viewer.