Changeset b4ca0a9c in mainline for uspace/lib/drv/generic/driver.c
- Timestamp:
- 2012-07-10T11:53:50Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1e01a35
- Parents:
- a33706e (diff), 33fc3ae (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
ra33706e rb4ca0a9c 125 125 static void driver_dev_add(ipc_callid_t iid, ipc_call_t *icall) 126 126 { 127 char *dev_name = NULL;128 int res;129 130 127 devman_handle_t dev_handle = IPC_GET_ARG1(*icall); 131 128 devman_handle_t parent_fun_handle = IPC_GET_ARG2(*icall); 132 129 133 130 ddf_dev_t *dev = create_device(); 134 131 135 132 /* Add one reference that will be dropped by driver_dev_remove() */ 136 133 dev_add_ref(dev); 137 134 dev->handle = dev_handle; 138 135 136 char *dev_name = NULL; 139 137 async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0); 140 138 dev->name = dev_name; 141 139 142 140 /* 143 141 * Currently not used, parent fun handle is stored in context … … 146 144 (void) parent_fun_handle; 147 145 148 res = driver->driver_ops->dev_add(dev);146 int res = driver->driver_ops->dev_add(dev); 149 147 150 148 if (res != EOK) { … … 163 161 static void driver_dev_remove(ipc_callid_t iid, ipc_call_t *icall) 164 162 { 165 devman_handle_t devh; 166 ddf_dev_t *dev; 167 int rc; 168 169 devh = IPC_GET_ARG1(*icall); 163 devman_handle_t devh = IPC_GET_ARG1(*icall); 170 164 171 165 fibril_mutex_lock(&devices_mutex); 172 d ev = driver_get_device(devh);166 ddf_dev_t *dev = driver_get_device(devh); 173 167 if (dev != NULL) 174 168 dev_add_ref(dev); … … 179 173 return; 180 174 } 175 176 int rc; 181 177 182 178 if (driver->driver_ops->dev_remove != NULL) … … 193 189 static void driver_dev_gone(ipc_callid_t iid, ipc_call_t *icall) 194 190 { 195 devman_handle_t devh; 196 ddf_dev_t *dev; 197 int rc; 198 199 devh = IPC_GET_ARG1(*icall); 191 devman_handle_t devh = IPC_GET_ARG1(*icall); 200 192 201 193 fibril_mutex_lock(&devices_mutex); 202 d ev = driver_get_device(devh);194 ddf_dev_t *dev = driver_get_device(devh); 203 195 if (dev != NULL) 204 196 dev_add_ref(dev); … … 209 201 return; 210 202 } 203 204 int rc; 211 205 212 206 if (driver->driver_ops->dev_gone != NULL) … … 223 217 static void driver_fun_online(ipc_callid_t iid, ipc_call_t *icall) 224 218 { 225 devman_handle_t funh; 226 ddf_fun_t *fun; 227 int rc; 228 229 funh = IPC_GET_ARG1(*icall); 219 devman_handle_t funh = IPC_GET_ARG1(*icall); 230 220 231 221 /* … … 236 226 fibril_mutex_lock(&functions_mutex); 237 227 238 fun = driver_get_function(funh);228 ddf_fun_t *fun = driver_get_function(funh); 239 229 if (fun != NULL) 240 230 fun_add_ref(fun); … … 248 238 249 239 /* Call driver entry point */ 240 int rc; 241 250 242 if (driver->driver_ops->fun_online != NULL) 251 243 rc = driver->driver_ops->fun_online(fun); … … 260 252 static void driver_fun_offline(ipc_callid_t iid, ipc_call_t *icall) 261 253 { 262 devman_handle_t funh; 263 ddf_fun_t *fun; 264 int rc; 265 266 funh = IPC_GET_ARG1(*icall); 254 devman_handle_t funh = IPC_GET_ARG1(*icall); 267 255 268 256 /* … … 273 261 fibril_mutex_lock(&functions_mutex); 274 262 275 fun = driver_get_function(funh);263 ddf_fun_t *fun = driver_get_function(funh); 276 264 if (fun != NULL) 277 265 fun_add_ref(fun); … … 285 273 286 274 /* Call driver entry point */ 275 int rc; 276 287 277 if (driver->driver_ops->fun_offline != NULL) 288 278 rc = driver->driver_ops->fun_offline(fun); … … 597 587 void *ddf_dev_data_alloc(ddf_dev_t *dev, size_t size) 598 588 { 599 void *data;600 601 589 assert(dev->driver_data == NULL); 602 603 data = calloc(1, size);590 591 void *data = calloc(1, size); 604 592 if (data == NULL) 605 593 return NULL; 606 594 607 595 dev->driver_data = data; 608 596 return data; … … 634 622 ddf_fun_t *ddf_fun_create(ddf_dev_t *dev, fun_type_t ftype, const char *name) 635 623 { 636 ddf_fun_t *fun; 637 638 fun = create_function(); 624 ddf_fun_t *fun = create_function(); 639 625 if (fun == NULL) 640 626 return NULL; 641 627 642 628 /* Add one reference that will be dropped by ddf_fun_destroy() */ 643 629 fun->dev = dev; 644 630 fun_add_ref(fun); 645 631 646 632 fun->bound = false; 647 633 fun->ftype = ftype; 648 634 649 635 fun->name = str_dup(name); 650 636 if (fun->name == NULL) { … … 652 638 return NULL; 653 639 } 654 640 655 641 return fun; 656 642 } … … 659 645 void *ddf_fun_data_alloc(ddf_fun_t *fun, size_t size) 660 646 { 661 void *data;662 663 647 assert(fun->bound == false); 664 648 assert(fun->driver_data == NULL); 665 666 data = calloc(1, size);649 650 void *data = calloc(1, size); 667 651 if (data == NULL) 668 652 return NULL; 669 653 670 654 fun->driver_data = data; 671 655 return data; … … 677 661 * must not be bound. 678 662 * 679 * @param fun Function to destroy 663 * @param fun Function to destroy 664 * 680 665 */ 681 666 void ddf_fun_destroy(ddf_fun_t *fun) 682 667 { 683 668 assert(fun->bound == false); 684 669 685 670 /* 686 671 * Drop the reference added by ddf_fun_create(). This will deallocate … … 697 682 if (fun->ops == NULL) 698 683 return NULL; 684 699 685 return fun->ops->interfaces[idx]; 700 686 } … … 709 695 * the same name. 710 696 * 711 * @param fun Function to bind 712 * @return EOK on success or negative error code 697 * @param fun Function to bind 698 * 699 * @return EOK on success or negative error code 700 * 713 701 */ 714 702 int ddf_fun_bind(ddf_fun_t *fun) … … 717 705 assert(fun->name != NULL); 718 706 719 int res;720 721 707 add_to_functions_list(fun); 722 res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,708 int res = devman_add_function(fun->name, fun->ftype, &fun->match_ids, 723 709 fun->dev->handle, &fun->handle); 724 710 if (res != EOK) { … … 736 722 * the function invisible to the system. 737 723 * 738 * @param fun Function to unbind 739 * @return EOK on success or negative error code 724 * @param fun Function to unbind 725 * 726 * @return EOK on success or negative error code 727 * 740 728 */ 741 729 int ddf_fun_unbind(ddf_fun_t *fun) 742 730 { 743 int res;744 745 731 assert(fun->bound == true); 746 732 747 res = devman_remove_function(fun->handle);733 int res = devman_remove_function(fun->handle); 748 734 if (res != EOK) 749 735 return res; 750 736 751 737 remove_from_functions_list(fun); 752 738 … … 757 743 /** Online function. 758 744 * 759 * @param fun Function to online 760 * @return EOK on success or negative error code 745 * @param fun Function to online 746 * 747 * @return EOK on success or negative error code 748 * 761 749 */ 762 750 int ddf_fun_online(ddf_fun_t *fun) 763 751 { 764 int res;765 766 752 assert(fun->bound == true); 767 753 768 res = devman_drv_fun_online(fun->handle);754 int res = devman_drv_fun_online(fun->handle); 769 755 if (res != EOK) 770 756 return res; … … 775 761 /** Offline function. 776 762 * 777 * @param fun Function to offline 778 * @return EOK on success or negative error code 763 * @param fun Function to offline 764 * 765 * @return EOK on success or negative error code 766 * 779 767 */ 780 768 int ddf_fun_offline(ddf_fun_t *fun) 781 769 { 782 int res;783 784 770 assert(fun->bound == true); 785 771 786 res = devman_drv_fun_offline(fun->handle);772 int res = devman_drv_fun_offline(fun->handle); 787 773 if (res != EOK) 788 774 return res; … … 796 782 * Cannot be called when the function node is bound. 797 783 * 798 * @param fun Function 799 * @param match_id_str Match string 800 * @param match_score Match score 801 * @return EOK on success, ENOMEM if out of memory. 784 * @param fun Function 785 * @param match_id_str Match string 786 * @param match_score Match score 787 * 788 * @return EOK on success. 789 * @return ENOMEM if out of memory. 790 * 802 791 */ 803 792 int ddf_fun_add_match_id(ddf_fun_t *fun, const char *match_id_str, 804 793 int match_score) 805 794 { 806 match_id_t *match_id;807 808 795 assert(fun->bound == false); 809 796 assert(fun->ftype == fun_inner); 810 797 811 match_id = create_match_id();798 match_id_t *match_id = create_match_id(); 812 799 if (match_id == NULL) 813 800 return ENOMEM; … … 831 818 * 832 819 * Must only be called when the function is bound. 820 * 833 821 */ 834 822 int ddf_fun_add_to_category(ddf_fun_t *fun, const char *cat_name) … … 842 830 int ddf_driver_main(driver_t *drv) 843 831 { 844 int rc;845 846 832 /* 847 833 * Remember the driver structure - driver_ops will be called by generic … … 858 844 */ 859 845 async_set_client_connection(driver_connection); 860 rc = devman_driver_register(driver->name);846 int rc = devman_driver_register(driver->name); 861 847 if (rc != EOK) { 862 848 printf("Error: Failed to register driver with device manager " … … 864 850 str_error(rc)); 865 851 866 return 1;852 return rc; 867 853 } 868 854 … … 870 856 rc = task_retval(0); 871 857 if (rc != EOK) 872 return 1;873 858 return rc; 859 874 860 async_manager(); 875 861 876 862 /* Never reached. */ 877 return 0;863 return EOK; 878 864 } 879 865
Note:
See TracChangeset
for help on using the changeset viewer.