Changeset eb1a2f4 in mainline for uspace/lib/drv
- Timestamp:
- 2011-02-22T23:30:56Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3b5d1535, a9c674e0
- Parents:
- dbe25f1 (diff), 664af708 (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. - Location:
- uspace/lib/drv
- Files:
-
- 1 added
- 10 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/driver.c
rdbe25f1 reb1a2f4 1 1 /* 2 2 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 2011 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 49 50 #include <errno.h> 50 51 #include <inttypes.h> 52 #include <devman.h> 51 53 52 54 #include <ipc/driver.h> 53 55 54 56 #include "dev_iface.h" 55 #include "driver.h" 57 #include "ddf/driver.h" 58 #include "ddf/interrupt.h" 56 59 57 60 /** Driver structure */ … … 59 62 60 63 /** Devices */ 61 LIST_INITIALIZE( devices);62 FIBRIL_MUTEX_INITIALIZE( devices_mutex);64 LIST_INITIALIZE(functions); 65 FIBRIL_MUTEX_INITIALIZE(functions_mutex); 63 66 64 67 /** Interrupts */ … … 76 79 }; 77 80 81 static ddf_dev_t *create_device(void); 82 static void delete_device(ddf_dev_t *); 83 static remote_handler_t *function_get_default_handler(ddf_fun_t *); 84 static void *function_get_ops(ddf_fun_t *, dev_inferface_idx_t); 78 85 79 86 static void driver_irq_handler(ipc_callid_t iid, ipc_call_t *icall) … … 150 157 151 158 interrupt_context_t * 152 find_interrupt_context(interrupt_context_list_t *list, d evice_t *dev, int irq)159 find_interrupt_context(interrupt_context_list_t *list, ddf_dev_t *dev, int irq) 153 160 { 154 161 fibril_mutex_lock(&list->mutex); … … 172 179 173 180 int 174 register_interrupt_handler(d evice_t *dev, int irq, interrupt_handler_t *handler,181 register_interrupt_handler(ddf_dev_t *dev, int irq, interrupt_handler_t *handler, 175 182 irq_code_t *pseudocode) 176 183 { … … 195 202 } 196 203 197 int unregister_interrupt_handler(d evice_t *dev, int irq)204 int unregister_interrupt_handler(ddf_dev_t *dev, int irq) 198 205 { 199 206 interrupt_context_t *ctx = find_interrupt_context(&interrupt_contexts, … … 209 216 } 210 217 211 static void add_to_ devices_list(device_t *dev)212 { 213 fibril_mutex_lock(& devices_mutex);214 list_append(& dev->link, &devices);215 fibril_mutex_unlock(& devices_mutex);216 } 217 218 static void remove_from_ devices_list(device_t *dev)219 { 220 fibril_mutex_lock(& devices_mutex);221 list_remove(& dev->link);222 fibril_mutex_unlock(& devices_mutex);223 } 224 225 static d evice_t *driver_get_device(link_t *devices, devman_handle_t handle)226 { 227 d evice_t *dev= NULL;228 229 fibril_mutex_lock(& devices_mutex);230 link_t *link = devices->next;231 232 while (link != devices) {233 dev = list_get_instance(link, device_t, link);234 if ( dev->handle == handle) {235 fibril_mutex_unlock(& devices_mutex);236 return dev;218 static void add_to_functions_list(ddf_fun_t *fun) 219 { 220 fibril_mutex_lock(&functions_mutex); 221 list_append(&fun->link, &functions); 222 fibril_mutex_unlock(&functions_mutex); 223 } 224 225 static void remove_from_functions_list(ddf_fun_t *fun) 226 { 227 fibril_mutex_lock(&functions_mutex); 228 list_remove(&fun->link); 229 fibril_mutex_unlock(&functions_mutex); 230 } 231 232 static ddf_fun_t *driver_get_function(link_t *functions, devman_handle_t handle) 233 { 234 ddf_fun_t *fun = NULL; 235 236 fibril_mutex_lock(&functions_mutex); 237 link_t *link = functions->next; 238 239 while (link != functions) { 240 fun = list_get_instance(link, ddf_fun_t, link); 241 if (fun->handle == handle) { 242 fibril_mutex_unlock(&functions_mutex); 243 return fun; 237 244 } 245 238 246 link = link->next; 239 247 } 240 248 241 fibril_mutex_unlock(& devices_mutex);249 fibril_mutex_unlock(&functions_mutex); 242 250 243 251 return NULL; … … 250 258 251 259 devman_handle_t dev_handle = IPC_GET_ARG1(*icall); 252 devman_handle_t parent_ dev_handle = IPC_GET_ARG2(*icall);253 254 d evice_t *dev = create_device();260 devman_handle_t parent_fun_handle = IPC_GET_ARG2(*icall); 261 262 ddf_dev_t *dev = create_device(); 255 263 dev->handle = dev_handle; 256 264 257 265 async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0); 258 266 dev->name = dev_name; 259 260 add_to_devices_list(dev); 261 dev->parent = driver_get_device(&devices, parent_dev_handle); 267 268 /* 269 * Currently not used, parent fun handle is stored in context 270 * of the connection to the parent device driver. 271 */ 272 (void) parent_fun_handle; 262 273 263 274 res = driver->driver_ops->add_device(dev); … … 268 279 printf("%s: failed to add a new device with handle = %" PRIun ".\n", 269 280 driver->name, dev_handle); 270 remove_from_devices_list(dev);271 281 delete_device(dev); 272 282 } … … 311 321 */ 312 322 devman_handle_t handle = IPC_GET_ARG2(*icall); 313 d evice_t *dev = driver_get_device(&devices, handle);314 315 if ( dev== NULL) {316 printf("%s: driver_connection_gen error - no devicewith handle"323 ddf_fun_t *fun = driver_get_function(&functions, handle); 324 325 if (fun == NULL) { 326 printf("%s: driver_connection_gen error - no function with handle" 317 327 " %" PRIun " was found.\n", driver->name, handle); 318 328 async_answer_0(iid, ENOENT); … … 327 337 328 338 int ret = EOK; 329 /* open the device*/330 if ( dev->ops != NULL && dev->ops->open != NULL)331 ret = (* dev->ops->open)(dev);339 /* Open device function */ 340 if (fun->ops != NULL && fun->ops->open != NULL) 341 ret = (*fun->ops->open)(fun); 332 342 333 343 async_answer_0(iid, ret); … … 344 354 switch (method) { 345 355 case IPC_M_PHONE_HUNGUP: 346 /* close the device*/347 if ( dev->ops != NULL && dev->ops->close != NULL)348 (* dev->ops->close)(dev);356 /* Close device function */ 357 if (fun->ops != NULL && fun->ops->close != NULL) 358 (*fun->ops->close)(fun); 349 359 async_answer_0(callid, EOK); 350 360 return; … … 356 366 if (!is_valid_iface_idx(iface_idx)) { 357 367 remote_handler_t *default_handler = 358 device_get_default_handler(dev);368 function_get_default_handler(fun); 359 369 if (default_handler != NULL) { 360 (*default_handler)( dev, callid, &call);370 (*default_handler)(fun, callid, &call); 361 371 break; 362 372 } 373 363 374 /* 364 * This is not device's interface and the375 * Function has no such interface and 365 376 * default handler is not provided. 366 377 */ … … 372 383 } 373 384 374 /* calling one of the device's interfaces */385 /* calling one of the function's interfaces */ 375 386 376 387 /* Get the interface ops structure. */ 377 void *ops = device_get_ops(dev, iface_idx);388 void *ops = function_get_ops(fun, iface_idx); 378 389 if (ops == NULL) { 379 390 printf("%s: driver_connection_gen error - ", 380 391 driver->name); 381 printf(" devicewith handle %" PRIun " has no interface "392 printf("Function with handle %" PRIun " has no interface " 382 393 "with id %d.\n", handle, iface_idx); 383 394 async_answer_0(callid, ENOTSUP); … … 408 419 * receive parameters from the remote client and it will 409 420 * pass it to the corresponding local interface method 410 * associated with the deviceby its driver.421 * associated with the function by its driver. 411 422 */ 412 (*iface_method_ptr)( dev, ops, callid, &call);423 (*iface_method_ptr)(fun, ops, callid, &call); 413 424 break; 414 425 } … … 425 436 driver_connection_gen(iid, icall, false); 426 437 } 427 428 438 429 439 /** Function for handling connections to device driver. */ … … 454 464 * @return The device structure. 455 465 */ 456 device_t *create_device(void)457 { 458 d evice_t *dev = malloc(sizeof(device_t));459 460 if (dev != NULL) {461 memset(dev, 0, sizeof(device_t));462 init_match_ids(&dev->match_ids);463 } 464 466 static ddf_dev_t *create_device(void) 467 { 468 ddf_dev_t *dev; 469 470 dev = malloc(sizeof(ddf_dev_t)); 471 if (dev == NULL) 472 return NULL; 473 474 memset(dev, 0, sizeof(ddf_dev_t)); 465 475 return dev; 466 476 } 467 477 478 /** Create new function structure. 479 * 480 * @return The device structure. 481 */ 482 static ddf_fun_t *create_function(void) 483 { 484 ddf_fun_t *fun; 485 486 fun = calloc(1, sizeof(ddf_fun_t)); 487 if (fun == NULL) 488 return NULL; 489 490 init_match_ids(&fun->match_ids); 491 link_initialize(&fun->link); 492 493 return fun; 494 } 495 468 496 /** Delete device structure. 469 497 * 470 498 * @param dev The device structure. 471 499 */ 472 void delete_device(device_t *dev) 473 { 474 clean_match_ids(&dev->match_ids); 475 if (dev->name != NULL) 476 free(dev->name); 500 static void delete_device(ddf_dev_t *dev) 501 { 477 502 free(dev); 478 503 } 479 504 480 void *device_get_ops(device_t *dev, dev_inferface_idx_t idx) 505 /** Delete device structure. 506 * 507 * @param dev The device structure. 508 */ 509 static void delete_function(ddf_fun_t *fun) 510 { 511 clean_match_ids(&fun->match_ids); 512 if (fun->name != NULL) 513 free(fun->name); 514 free(fun); 515 } 516 517 /** Create a DDF function node. 518 * 519 * Create a DDF function (in memory). Both child devices and external clients 520 * communicate with a device via its functions. 521 * 522 * The created function node is fully formed, but only exists in the memory 523 * of the client task. In order to be visible to the system, the function 524 * must be bound using ddf_fun_bind(). 525 * 526 * This function should only fail if there is not enough free memory. 527 * Specifically, this function succeeds even if @a dev already has 528 * a (bound) function with the same name. 529 * 530 * Type: A function of type fun_inner indicates that DDF should attempt 531 * to attach child devices to the function. fun_exposed means that 532 * the function should be exported to external clients (applications). 533 * 534 * @param dev Device to which we are adding function 535 * @param ftype Type of function (fun_inner or fun_exposed) 536 * @param name Name of function 537 * 538 * @return New function or @c NULL if memory is not available 539 */ 540 ddf_fun_t *ddf_fun_create(ddf_dev_t *dev, fun_type_t ftype, const char *name) 541 { 542 ddf_fun_t *fun; 543 544 fun = create_function(); 545 if (fun == NULL) 546 return NULL; 547 548 fun->bound = false; 549 fun->dev = dev; 550 fun->ftype = ftype; 551 552 fun->name = str_dup(name); 553 if (fun->name == NULL) { 554 delete_function(fun); 555 return NULL; 556 } 557 558 return fun; 559 } 560 561 /** Destroy DDF function node. 562 * 563 * Destroy a function previously created with ddf_fun_create(). The function 564 * must not be bound. 565 * 566 * @param fun Function to destroy 567 */ 568 void ddf_fun_destroy(ddf_fun_t *fun) 569 { 570 assert(fun->bound == false); 571 delete_function(fun); 572 } 573 574 static void *function_get_ops(ddf_fun_t *fun, dev_inferface_idx_t idx) 481 575 { 482 576 assert(is_valid_iface_idx(idx)); 483 if ( dev->ops == NULL)577 if (fun->ops == NULL) 484 578 return NULL; 485 return dev->ops->interfaces[idx]; 486 } 487 488 int child_device_register(device_t *child, device_t *parent) 489 { 490 assert(child->name != NULL); 579 return fun->ops->interfaces[idx]; 580 } 581 582 /** Bind a function node. 583 * 584 * Bind the specified function to the system. This effectively makes 585 * the function visible to the system (uploads it to the server). 586 * 587 * This function can fail for several reasons. Specifically, 588 * it will fail if the device already has a bound function of 589 * the same name. 590 * 591 * @param fun Function to bind 592 * @return EOK on success or negative error code 593 */ 594 int ddf_fun_bind(ddf_fun_t *fun) 595 { 596 assert(fun->name != NULL); 491 597 492 598 int res; 493 599 494 add_to_ devices_list(child);495 res = devman_ child_device_register(child->name, &child->match_ids,496 parent->handle, &child->handle);600 add_to_functions_list(fun); 601 res = devman_add_function(fun->name, fun->ftype, &fun->match_ids, 602 fun->dev->handle, &fun->handle); 497 603 if (res != EOK) { 498 remove_from_ devices_list(child);604 remove_from_functions_list(fun); 499 605 return res; 500 606 } 501 607 608 fun->bound = true; 502 609 return res; 503 610 } 504 611 505 /** Wrapper for child_device_register for devices with single match id. 506 * 507 * @param parent Parent device. 508 * @param child_name Child device name. 509 * @param child_match_id Child device match id. 510 * @param child_match_score Child device match score. 511 * @return Error code. 512 */ 513 int child_device_register_wrapper(device_t *parent, const char *child_name, 514 const char *child_match_id, int child_match_score, 515 devman_handle_t *child_handle) 516 { 517 device_t *child = NULL; 518 match_id_t *match_id = NULL; 519 int rc; 520 521 child = create_device(); 522 if (child == NULL) { 523 rc = ENOMEM; 524 goto failure; 525 } 526 527 child->name = child_name; 612 /** Add single match ID to inner function. 613 * 614 * Construct and add a single match ID to the specified function. 615 * Cannot be called when the function node is bound. 616 * 617 * @param fun Function 618 * @param match_id_str Match string 619 * @param match_score Match score 620 * @return EOK on success, ENOMEM if out of memory. 621 */ 622 int ddf_fun_add_match_id(ddf_fun_t *fun, const char *match_id_str, 623 int match_score) 624 { 625 match_id_t *match_id; 626 627 assert(fun->bound == false); 628 assert(fun->ftype == fun_inner); 528 629 529 630 match_id = create_match_id(); 530 if (match_id == NULL) { 531 rc = ENOMEM; 532 goto failure; 533 } 534 535 match_id->id = child_match_id; 536 match_id->score = child_match_score; 537 add_match_id(&child->match_ids, match_id); 538 539 rc = child_device_register(child, parent); 540 if (rc != EOK) 541 goto failure; 542 543 if (child_handle != NULL) { 544 *child_handle = child->handle; 545 } 546 631 if (match_id == NULL) 632 return ENOMEM; 633 634 match_id->id = match_id_str; 635 match_id->score = 90; 636 637 add_match_id(&fun->match_ids, match_id); 547 638 return EOK; 548 549 failure:550 if (match_id != NULL) {551 match_id->id = NULL;552 delete_match_id(match_id);553 }554 555 if (child != NULL) {556 child->name = NULL;557 delete_device(child);558 }559 560 return rc;561 639 } 562 640 563 641 /** Get default handler for client requests */ 564 remote_handler_t *device_get_default_handler(device_t *dev)565 { 566 if ( dev->ops == NULL)642 static remote_handler_t *function_get_default_handler(ddf_fun_t *fun) 643 { 644 if (fun->ops == NULL) 567 645 return NULL; 568 return dev->ops->default_handler; 569 } 570 571 int add_device_to_class(device_t *dev, const char *class_name) 572 { 573 return devman_add_device_to_class(dev->handle, class_name); 574 } 575 576 int driver_main(driver_t *drv) 646 return fun->ops->default_handler; 647 } 648 649 /** Add exposed function to class. 650 * 651 * Must only be called when the function is bound. 652 */ 653 int ddf_fun_add_to_class(ddf_fun_t *fun, const char *class_name) 654 { 655 assert(fun->bound == true); 656 assert(fun->ftype == fun_exposed); 657 658 return devman_add_device_to_class(fun->handle, class_name); 659 } 660 661 int ddf_driver_main(driver_t *drv) 577 662 { 578 663 /* -
uspace/lib/drv/generic/remote_char_dev.c
rdbe25f1 reb1a2f4 37 37 38 38 #include "ops/char_dev.h" 39 #include "d river.h"39 #include "ddf/driver.h" 40 40 41 41 #define MAX_CHAR_RW_COUNT 256 42 42 43 static void remote_char_read(d evice_t *, void *, ipc_callid_t, ipc_call_t *);44 static void remote_char_write(d evice_t *, void *, ipc_callid_t, ipc_call_t *);43 static void remote_char_read(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 44 static void remote_char_write(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 45 45 46 46 /** Remote character interface operations. */ … … 67 67 * local interface to the remote client. 68 68 * 69 * @param dev The devicefrom which the data are read.69 * @param fun The function from which the data are read. 70 70 * @param ops The local ops structure. 71 71 */ 72 72 static void 73 remote_char_read(d evice_t *dev, void *ops, ipc_callid_t callid,73 remote_char_read(ddf_fun_t *fun, void *ops, ipc_callid_t callid, 74 74 ipc_call_t *call) 75 75 { … … 94 94 95 95 char buf[MAX_CHAR_RW_COUNT]; 96 int ret = (*char_dev_ops->read)( dev, buf, len);96 int ret = (*char_dev_ops->read)(fun, buf, len); 97 97 98 98 if (ret < 0) { … … 114 114 * local interface to the remote client. 115 115 * 116 * @param dev The deviceto which the data are written.116 * @param fun The function to which the data are written. 117 117 * @param ops The local ops structure. 118 118 */ 119 119 static void 120 remote_char_write(d evice_t *dev, void *ops, ipc_callid_t callid,120 remote_char_write(ddf_fun_t *fun, void *ops, ipc_callid_t callid, 121 121 ipc_call_t *call) 122 122 { … … 144 144 async_data_write_finalize(cid, buf, len); 145 145 146 int ret = (*char_dev_ops->write)( dev, buf, len);146 int ret = (*char_dev_ops->write)(fun, buf, len); 147 147 if (ret < 0) { 148 148 /* Some error occured. */ -
uspace/lib/drv/generic/remote_hw_res.c
rdbe25f1 reb1a2f4 37 37 38 38 #include "ops/hw_res.h" 39 #include "d river.h"39 #include "ddf/driver.h" 40 40 41 static void remote_hw_res_get_resource_list(d evice_t *, void *, ipc_callid_t,41 static void remote_hw_res_get_resource_list(ddf_fun_t *, void *, ipc_callid_t, 42 42 ipc_call_t *); 43 static void remote_hw_res_enable_interrupt(d evice_t *, void *, ipc_callid_t,43 static void remote_hw_res_enable_interrupt(ddf_fun_t *, void *, ipc_callid_t, 44 44 ipc_call_t *); 45 45 … … 55 55 }; 56 56 57 static void remote_hw_res_enable_interrupt(d evice_t *dev, void *ops,57 static void remote_hw_res_enable_interrupt(ddf_fun_t *fun, void *ops, 58 58 ipc_callid_t callid, ipc_call_t *call) 59 59 { … … 62 62 if (hw_res_ops->enable_interrupt == NULL) 63 63 async_answer_0(callid, ENOTSUP); 64 else if (hw_res_ops->enable_interrupt( dev))64 else if (hw_res_ops->enable_interrupt(fun)) 65 65 async_answer_0(callid, EOK); 66 66 else … … 68 68 } 69 69 70 static void remote_hw_res_get_resource_list(d evice_t *dev, void *ops,70 static void remote_hw_res_get_resource_list(ddf_fun_t *fun, void *ops, 71 71 ipc_callid_t callid, ipc_call_t *call) 72 72 { … … 78 78 } 79 79 80 hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list( dev);80 hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list(fun); 81 81 if (hw_resources == NULL){ 82 82 async_answer_0(callid, ENOENT); -
uspace/lib/drv/generic/remote_usb.c
rdbe25f1 reb1a2f4 37 37 38 38 #include "usb_iface.h" 39 #include "d river.h"39 #include "ddf/driver.h" 40 40 41 41 42 static void remote_usb_get_address(d evice_t *, void *, ipc_callid_t, ipc_call_t *);43 static void remote_usb_get_interface(d evice_t *, void *, ipc_callid_t, ipc_call_t *);44 static void remote_usb_get_hc_handle(d evice_t *, void *, ipc_callid_t, ipc_call_t *);42 static void remote_usb_get_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 43 static void remote_usb_get_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 44 static void remote_usb_get_hc_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 45 45 //static void remote_usb(device_t *, void *, ipc_callid_t, ipc_call_t *); 46 46 … … 61 61 62 62 63 void remote_usb_get_address(d evice_t *device, void *iface,63 void remote_usb_get_address(ddf_fun_t *fun, void *iface, 64 64 ipc_callid_t callid, ipc_call_t *call) 65 65 { … … 74 74 75 75 usb_address_t address; 76 int rc = usb_iface->get_address( device, handle, &address);76 int rc = usb_iface->get_address(fun, handle, &address); 77 77 if (rc != EOK) { 78 78 async_answer_0(callid, rc); … … 82 82 } 83 83 84 void remote_usb_get_interface(d evice_t *device, void *iface,84 void remote_usb_get_interface(ddf_fun_t *fun, void *iface, 85 85 ipc_callid_t callid, ipc_call_t *call) 86 86 { … … 95 95 96 96 int iface_no; 97 int rc = usb_iface->get_interface( device, handle, &iface_no);97 int rc = usb_iface->get_interface(fun, handle, &iface_no); 98 98 if (rc != EOK) { 99 99 async_answer_0(callid, rc); … … 103 103 } 104 104 105 void remote_usb_get_hc_handle(d evice_t *device, void *iface,105 void remote_usb_get_hc_handle(ddf_fun_t *fun, void *iface, 106 106 ipc_callid_t callid, ipc_call_t *call) 107 107 { … … 114 114 115 115 devman_handle_t handle; 116 int rc = usb_iface->get_hc_handle( device, &handle);116 int rc = usb_iface->get_hc_handle(fun, &handle); 117 117 if (rc != EOK) { 118 118 async_answer_0(callid, rc); -
uspace/lib/drv/generic/remote_usbhc.c
rdbe25f1 reb1a2f4 35 35 #include <async.h> 36 36 #include <errno.h> 37 #include <assert.h> 37 38 38 39 #include "usbhc_iface.h" 39 #include "d river.h"40 #include "ddf/driver.h" 40 41 41 42 #define USB_MAX_PAYLOAD_SIZE 1020 … … 43 44 #define HACK_MAX_PACKET_SIZE_INTERRUPT_IN 4 44 45 45 static void remote_usbhc_interrupt_out(d evice_t *, void *, ipc_callid_t, ipc_call_t *);46 static void remote_usbhc_interrupt_in(d evice_t *, void *, ipc_callid_t, ipc_call_t *);47 static void remote_usbhc_bulk_out(d evice_t *, void *, ipc_callid_t, ipc_call_t *);48 static void remote_usbhc_bulk_in(d evice_t *, void *, ipc_callid_t, ipc_call_t *);49 static void remote_usbhc_control_write(d evice_t *, void *, ipc_callid_t, ipc_call_t *);50 static void remote_usbhc_control_read(d evice_t *, void *, ipc_callid_t, ipc_call_t *);51 static void remote_usbhc_reserve_default_address(d evice_t *, void *, ipc_callid_t, ipc_call_t *);52 static void remote_usbhc_release_default_address(d evice_t *, void *, ipc_callid_t, ipc_call_t *);53 static void remote_usbhc_request_address(d evice_t *, void *, ipc_callid_t, ipc_call_t *);54 static void remote_usbhc_bind_address(d evice_t *, void *, ipc_callid_t, ipc_call_t *);55 static void remote_usbhc_release_address(d evice_t *, void *, ipc_callid_t, ipc_call_t *);56 //static void remote_usbhc(d evice_t *, void *, ipc_callid_t, ipc_call_t *);46 static void remote_usbhc_interrupt_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 47 static void remote_usbhc_interrupt_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 48 static void remote_usbhc_bulk_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 49 static void remote_usbhc_bulk_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 50 static void remote_usbhc_control_write(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 51 static void remote_usbhc_control_read(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 52 static void remote_usbhc_reserve_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 53 static void remote_usbhc_release_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 54 static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 55 static void remote_usbhc_bind_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 56 static void remote_usbhc_release_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 57 //static void remote_usbhc(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 57 58 58 59 /** Remote USB host controller interface operations. */ … … 123 124 } 124 125 125 void remote_usbhc_reserve_default_address(d evice_t *device, void *iface,126 void remote_usbhc_reserve_default_address(ddf_fun_t *fun, void *iface, 126 127 ipc_callid_t callid, ipc_call_t *call) 127 128 { … … 135 136 usb_speed_t speed = DEV_IPC_GET_ARG1(*call); 136 137 137 int rc = usb_iface->reserve_default_address( device, speed);138 int rc = usb_iface->reserve_default_address(fun, speed); 138 139 139 140 async_answer_0(callid, rc); 140 141 } 141 142 142 void remote_usbhc_release_default_address(d evice_t *device, void *iface,143 void remote_usbhc_release_default_address(ddf_fun_t *fun, void *iface, 143 144 ipc_callid_t callid, ipc_call_t *call) 144 145 { … … 150 151 } 151 152 152 int rc = usb_iface->release_default_address( device);153 int rc = usb_iface->release_default_address(fun); 153 154 154 155 async_answer_0(callid, rc); 155 156 } 156 157 157 void remote_usbhc_request_address(d evice_t *device, void *iface,158 void remote_usbhc_request_address(ddf_fun_t *fun, void *iface, 158 159 ipc_callid_t callid, ipc_call_t *call) 159 160 { … … 168 169 169 170 usb_address_t address; 170 int rc = usb_iface->request_address( device, speed, &address);171 int rc = usb_iface->request_address(fun, speed, &address); 171 172 if (rc != EOK) { 172 173 async_answer_0(callid, rc); … … 176 177 } 177 178 178 void remote_usbhc_bind_address(d evice_t *device, void *iface,179 void remote_usbhc_bind_address(ddf_fun_t *fun, void *iface, 179 180 ipc_callid_t callid, ipc_call_t *call) 180 181 { … … 189 190 devman_handle_t handle = (devman_handle_t) DEV_IPC_GET_ARG2(*call); 190 191 191 int rc = usb_iface->bind_address( device, address, handle);192 int rc = usb_iface->bind_address(fun, address, handle); 192 193 193 194 async_answer_0(callid, rc); 194 195 } 195 196 196 void remote_usbhc_release_address(d evice_t *device, void *iface,197 void remote_usbhc_release_address(ddf_fun_t *fun, void *iface, 197 198 ipc_callid_t callid, ipc_call_t *call) 198 199 { … … 206 207 usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call); 207 208 208 int rc = usb_iface->release_address( device, address);209 int rc = usb_iface->release_address(fun, address); 209 210 210 211 async_answer_0(callid, rc); … … 212 213 213 214 214 static void callback_out(d evice_t *device,215 static void callback_out(ddf_fun_t *fun, 215 216 int outcome, void *arg) 216 217 { … … 222 223 } 223 224 224 static void callback_in(d evice_t *device,225 static void callback_in(ddf_fun_t *fun, 225 226 int outcome, size_t actual_size, void *arg) 226 227 { … … 255 256 * @param transfer_func Transfer function (might be NULL). 256 257 */ 257 static void remote_usbhc_out_transfer(d evice_t *device,258 static void remote_usbhc_out_transfer(ddf_fun_t *fun, 258 259 ipc_callid_t callid, ipc_call_t *call, 259 260 usbhc_iface_transfer_out_t transfer_func) … … 294 295 trans->size = len; 295 296 296 rc = transfer_func( device, target, max_packet_size,297 rc = transfer_func(fun, target, max_packet_size, 297 298 buffer, len, 298 299 callback_out, trans); … … 311 312 * @param transfer_func Transfer function (might be NULL). 312 313 */ 313 static void remote_usbhc_in_transfer(d evice_t *device,314 static void remote_usbhc_in_transfer(ddf_fun_t *fun, 314 315 ipc_callid_t callid, ipc_call_t *call, 315 316 usbhc_iface_transfer_in_t transfer_func) … … 342 343 trans->size = len; 343 344 344 int rc = transfer_func( device, target, max_packet_size,345 int rc = transfer_func(fun, target, max_packet_size, 345 346 trans->buffer, len, 346 347 callback_in, trans); … … 352 353 } 353 354 354 void remote_usbhc_interrupt_out(d evice_t *device, void *iface,355 void remote_usbhc_interrupt_out(ddf_fun_t *fun, void *iface, 355 356 ipc_callid_t callid, ipc_call_t *call) 356 357 { … … 358 359 assert(usb_iface != NULL); 359 360 360 return remote_usbhc_out_transfer( device, callid, call,361 return remote_usbhc_out_transfer(fun, callid, call, 361 362 usb_iface->interrupt_out); 362 363 } 363 364 364 void remote_usbhc_interrupt_in(d evice_t *device, void *iface,365 void remote_usbhc_interrupt_in(ddf_fun_t *fun, void *iface, 365 366 ipc_callid_t callid, ipc_call_t *call) 366 367 { … … 368 369 assert(usb_iface != NULL); 369 370 370 return remote_usbhc_in_transfer( device, callid, call,371 return remote_usbhc_in_transfer(fun, callid, call, 371 372 usb_iface->interrupt_in); 372 373 } 373 374 374 void remote_usbhc_bulk_out(d evice_t *device, void *iface,375 void remote_usbhc_bulk_out(ddf_fun_t *fun, void *iface, 375 376 ipc_callid_t callid, ipc_call_t *call) 376 377 { … … 378 379 assert(usb_iface != NULL); 379 380 380 return remote_usbhc_out_transfer( device, callid, call,381 return remote_usbhc_out_transfer(fun, callid, call, 381 382 usb_iface->bulk_out); 382 383 } 383 384 384 void remote_usbhc_bulk_in(d evice_t *device, void *iface,385 void remote_usbhc_bulk_in(ddf_fun_t *fun, void *iface, 385 386 ipc_callid_t callid, ipc_call_t *call) 386 387 { … … 388 389 assert(usb_iface != NULL); 389 390 390 return remote_usbhc_in_transfer( device, callid, call,391 return remote_usbhc_in_transfer(fun, callid, call, 391 392 usb_iface->bulk_in); 392 393 } 393 394 394 void remote_usbhc_control_write(d evice_t *device, void *iface,395 void remote_usbhc_control_write(ddf_fun_t *fun, void *iface, 395 396 ipc_callid_t callid, ipc_call_t *call) 396 397 { … … 444 445 trans->size = data_buffer_len; 445 446 446 rc = usb_iface->control_write( device, target, max_packet_size,447 rc = usb_iface->control_write(fun, target, max_packet_size, 447 448 setup_packet, setup_packet_len, 448 449 data_buffer, data_buffer_len, … … 456 457 457 458 458 void remote_usbhc_control_read(d evice_t *device, void *iface,459 void remote_usbhc_control_read(ddf_fun_t *fun, void *iface, 459 460 ipc_callid_t callid, ipc_call_t *call) 460 461 { … … 509 510 } 510 511 511 rc = usb_iface->control_read( device, target, max_packet_size,512 rc = usb_iface->control_read(fun, target, max_packet_size, 512 513 setup_packet, setup_packet_len, 513 514 trans->buffer, trans->size, -
uspace/lib/drv/include/ddf/driver.h
rdbe25f1 reb1a2f4 1 1 /* 2 2 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 2011 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 33 34 */ 34 35 35 #ifndef LIBDRV_DRIVER_H_36 #define LIBDRV_DRIVER_H_36 #ifndef DDF_DRIVER_H_ 37 #define DDF_DRIVER_H_ 37 38 38 #include <sys/types.h>39 #include <kernel/ddi/irq.h>40 #include <adt/list.h>41 #include <devman.h>42 39 #include <ipc/devman.h> 43 40 #include <ipc/dev_iface.h> 44 #include <assert.h>45 #include <ddi.h>46 #include <libarch/ddi.h>47 #include <fibril_synch.h>48 #include <malloc.h>49 41 50 #include " dev_iface.h"42 #include "../dev_iface.h" 51 43 52 struct device;53 typedef struct d evice device_t;44 typedef struct ddf_dev ddf_dev_t; 45 typedef struct ddf_fun ddf_fun_t; 54 46 55 47 /* 56 * Device class48 * Device 57 49 */ 58 50 59 51 /** Devices operations */ 60 typedef struct d evice_ops {52 typedef struct ddf_dev_ops { 61 53 /** 62 54 * Optional callback function called when a client is connecting to the 63 55 * device. 64 56 */ 65 int (*open)(d evice_t *);57 int (*open)(ddf_fun_t *); 66 58 67 59 /** … … 69 61 * the device. 70 62 */ 71 void (*close)(d evice_t *);63 void (*close)(ddf_fun_t *); 72 64 73 65 /** The table of standard interfaces implemented by the device. */ … … 80 72 */ 81 73 remote_handler_t *default_handler; 82 } device_ops_t; 83 84 85 /* 86 * Device 87 */ 74 } ddf_dev_ops_t; 88 75 89 76 /** Device structure */ 90 struct d evice{77 struct ddf_dev { 91 78 /** 92 79 * Globally unique device identifier (assigned to the device by the … … 101 88 int parent_phone; 102 89 103 /** Parent device if handled by this driver, NULL otherwise */104 device_t *parent;105 90 /** Device name */ 106 91 const char *name; 107 /** List of device ids for device-to-driver matching */ 108 match_id_list_t match_ids; 92 109 93 /** Driver-specific data associated with this device */ 110 94 void *driver_data; 111 /** The implementation of operations provided by this device */112 device_ops_t *ops;113 95 114 96 /** Link in the list of devices handled by the driver */ 97 link_t link; 98 }; 99 100 /** Function structure */ 101 struct ddf_fun { 102 /** True if bound to the device manager */ 103 bool bound; 104 /** Function indentifier (asigned by device manager) */ 105 devman_handle_t handle; 106 107 /** Device which this function belogs to */ 108 ddf_dev_t *dev; 109 110 /** Function type */ 111 fun_type_t ftype; 112 /** Function name */ 113 const char *name; 114 /** List of device ids for driver matching */ 115 match_id_list_t match_ids; 116 /** Driver-specific data associated with this function */ 117 void *driver_data; 118 /** Implementation of operations provided by this function */ 119 ddf_dev_ops_t *ops; 120 121 /** Link in the list of functions handled by the driver */ 115 122 link_t link; 116 123 }; … … 123 130 typedef struct driver_ops { 124 131 /** Callback method for passing a new device to the device driver */ 125 int (*add_device)(d evice_t *dev);132 int (*add_device)(ddf_dev_t *dev); 126 133 /* TODO: add other generic driver operations */ 127 134 } driver_ops_t; … … 135 142 } driver_t; 136 143 137 intdriver_main(driver_t *);144 extern int ddf_driver_main(driver_t *); 138 145 139 /** Create new device structure. 140 * 141 * @return The device structure. 142 */ 143 extern device_t *create_device(void); 144 extern void delete_device(device_t *); 145 extern void *device_get_ops(device_t *, dev_inferface_idx_t); 146 extern ddf_fun_t *ddf_fun_create(ddf_dev_t *, fun_type_t, const char *); 147 extern void ddf_fun_destroy(ddf_fun_t *); 148 extern int ddf_fun_bind(ddf_fun_t *); 149 extern int ddf_fun_add_match_id(ddf_fun_t *, const char *, int); 146 150 147 extern int child_device_register(device_t *, device_t *); 148 extern int child_device_register_wrapper(device_t *, const char *, const char *, 149 int, devman_handle_t *); 150 151 /* 152 * Interrupts 153 */ 154 155 typedef void interrupt_handler_t(device_t *, ipc_callid_t, ipc_call_t *); 156 157 typedef struct interrupt_context { 158 int id; 159 device_t *dev; 160 int irq; 161 interrupt_handler_t *handler; 162 link_t link; 163 } interrupt_context_t; 164 165 typedef struct interrupt_context_list { 166 int curr_id; 167 link_t contexts; 168 fibril_mutex_t mutex; 169 } interrupt_context_list_t; 170 171 extern interrupt_context_t *create_interrupt_context(void); 172 extern void delete_interrupt_context(interrupt_context_t *); 173 extern void init_interrupt_context_list(interrupt_context_list_t *); 174 extern void add_interrupt_context(interrupt_context_list_t *, 175 interrupt_context_t *); 176 extern void remove_interrupt_context(interrupt_context_list_t *, 177 interrupt_context_t *); 178 extern interrupt_context_t *find_interrupt_context_by_id( 179 interrupt_context_list_t *, int); 180 extern interrupt_context_t *find_interrupt_context( 181 interrupt_context_list_t *, device_t *, int); 182 183 extern int register_interrupt_handler(device_t *, int, interrupt_handler_t *, 184 irq_code_t *); 185 extern int unregister_interrupt_handler(device_t *, int); 186 187 extern remote_handler_t *device_get_default_handler(device_t *); 188 extern int add_device_to_class(device_t *, const char *); 151 extern int ddf_fun_add_to_class(ddf_fun_t *, const char *); 189 152 190 153 #endif -
uspace/lib/drv/include/dev_iface.h
rdbe25f1 reb1a2f4 43 43 */ 44 44 45 struct d evice;45 struct ddf_fun; 46 46 47 47 /* … … 49 49 * devices driver. 50 50 */ 51 typedef void remote_iface_func_t(struct d evice*, void *, ipc_callid_t,51 typedef void remote_iface_func_t(struct ddf_fun *, void *, ipc_callid_t, 52 52 ipc_call_t *); 53 53 typedef remote_iface_func_t *remote_iface_func_ptr_t; 54 typedef void remote_handler_t(struct d evice*, ipc_callid_t, ipc_call_t *);54 typedef void remote_handler_t(struct ddf_fun *, ipc_callid_t, ipc_call_t *); 55 55 56 56 typedef struct { -
uspace/lib/drv/include/ops/char_dev.h
rdbe25f1 reb1a2f4 36 36 #define LIBDRV_OPS_CHAR_DEV_H_ 37 37 38 #include "../d river.h"38 #include "../ddf/driver.h" 39 39 40 40 typedef struct { 41 int (*read)(d evice_t *, char *, size_t);42 int (*write)(d evice_t *, char *, size_t);41 int (*read)(ddf_fun_t *, char *, size_t); 42 int (*write)(ddf_fun_t *, char *, size_t); 43 43 } char_dev_ops_t; 44 44 -
uspace/lib/drv/include/ops/hw_res.h
rdbe25f1 reb1a2f4 39 39 #include <sys/types.h> 40 40 41 #include "../d river.h"41 #include "../ddf/driver.h" 42 42 43 43 typedef struct { 44 hw_resource_list_t *(*get_resource_list)(d evice_t *);45 bool (*enable_interrupt)(d evice_t *);44 hw_resource_list_t *(*get_resource_list)(ddf_fun_t *); 45 bool (*enable_interrupt)(ddf_fun_t *); 46 46 } hw_res_ops_t; 47 47 -
uspace/lib/drv/include/usb_iface.h
rdbe25f1 reb1a2f4 38 38 #define LIBDRV_USB_IFACE_H_ 39 39 40 #include "d river.h"40 #include "ddf/driver.h" 41 41 #include <usb/usb.h> 42 42 typedef enum { … … 75 75 /** USB device communication interface. */ 76 76 typedef struct { 77 int (*get_address)(d evice_t *, devman_handle_t, usb_address_t *);78 int (*get_interface)(d evice_t *, devman_handle_t, int *);79 int (*get_hc_handle)(d evice_t *, devman_handle_t *);77 int (*get_address)(ddf_fun_t *, devman_handle_t, usb_address_t *); 78 int (*get_interface)(ddf_fun_t *, devman_handle_t, int *); 79 int (*get_hc_handle)(ddf_fun_t *, devman_handle_t *); 80 80 } usb_iface_t; 81 81 -
uspace/lib/drv/include/usbhc_iface.h
rdbe25f1 reb1a2f4 38 38 #define LIBDRV_USBHC_IFACE_H_ 39 39 40 #include "d river.h"40 #include "ddf/driver.h" 41 41 #include <usb/usb.h> 42 42 #include <bool.h> … … 171 171 172 172 /** Callback for outgoing transfer. */ 173 typedef void (*usbhc_iface_transfer_out_callback_t)(d evice_t *,173 typedef void (*usbhc_iface_transfer_out_callback_t)(ddf_fun_t *, 174 174 int, void *); 175 175 176 176 /** Callback for incoming transfer. */ 177 typedef void (*usbhc_iface_transfer_in_callback_t)(d evice_t *,177 typedef void (*usbhc_iface_transfer_in_callback_t)(ddf_fun_t *, 178 178 int, size_t, void *); 179 179 180 180 181 181 /** Out transfer processing function prototype. */ 182 typedef int (*usbhc_iface_transfer_out_t)(d evice_t *, usb_target_t, size_t,182 typedef int (*usbhc_iface_transfer_out_t)(ddf_fun_t *, usb_target_t, size_t, 183 183 void *, size_t, 184 184 usbhc_iface_transfer_out_callback_t, void *); … … 188 188 189 189 /** In transfer processing function prototype. */ 190 typedef int (*usbhc_iface_transfer_in_t)(d evice_t *, usb_target_t, size_t,190 typedef int (*usbhc_iface_transfer_in_t)(ddf_fun_t *, usb_target_t, size_t, 191 191 void *, size_t, 192 192 usbhc_iface_transfer_in_callback_t, void *); … … 194 194 /** USB host controller communication interface. */ 195 195 typedef struct { 196 int (*reserve_default_address)(d evice_t *, usb_speed_t);197 int (*release_default_address)(d evice_t *);198 int (*request_address)(d evice_t *, usb_speed_t, usb_address_t *);199 int (*bind_address)(d evice_t *, usb_address_t, devman_handle_t);200 int (*release_address)(d evice_t *, usb_address_t);196 int (*reserve_default_address)(ddf_fun_t *, usb_speed_t); 197 int (*release_default_address)(ddf_fun_t *); 198 int (*request_address)(ddf_fun_t *, usb_speed_t, usb_address_t *); 199 int (*bind_address)(ddf_fun_t *, usb_address_t, devman_handle_t); 200 int (*release_address)(ddf_fun_t *, usb_address_t); 201 201 202 202 usbhc_iface_transfer_out_t interrupt_out; … … 206 206 usbhc_iface_transfer_in_t bulk_in; 207 207 208 int (*control_write)(d evice_t *, usb_target_t,208 int (*control_write)(ddf_fun_t *, usb_target_t, 209 209 size_t, 210 210 void *, size_t, void *, size_t, 211 211 usbhc_iface_transfer_out_callback_t, void *); 212 212 213 int (*control_read)(d evice_t *, usb_target_t,213 int (*control_read)(ddf_fun_t *, usb_target_t, 214 214 size_t, 215 215 void *, size_t, void *, size_t,
Note:
See TracChangeset
for help on using the changeset viewer.