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