Changeset 925a21e in mainline for uspace/drv/bus/usb/usbhid/kbd/kbddev.c
- Timestamp:
- 2011-09-24T14:20:29Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5bf76c1
- Parents:
- 867e2555 (diff), 1ab4aca (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/drv/bus/usb/usbhid/kbd/kbddev.c
r867e2555 r925a21e 43 43 #include <ipc/kbdev.h> 44 44 #include <async.h> 45 #include <async_obsolete.h>46 45 #include <fibril.h> 47 46 #include <fibril_synch.h> … … 71 70 #include "../usbhid.h" 72 71 73 // FIXME: remove this header74 #include <kernel/ipc/ipc_methods.h>75 76 72 /*----------------------------------------------------------------------------*/ 77 73 … … 102 98 103 99 const char *HID_KBD_FUN_NAME = "keyboard"; 104 const char *HID_KBD_C LASS_NAME = "keyboard";100 const char *HID_KBD_CATEGORY_NAME = "keyboard"; 105 101 106 102 static void usb_kbd_set_led(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev); … … 167 163 * 168 164 * Currently recognizes only one method (IPC_M_CONNECT_TO_ME), in which case it 169 * assumes the caller is the console and thus it stores IPC phone to it for165 * assumes the caller is the console and thus it stores IPC session to it for 170 166 * later use by the driver to notify about key events. 171 167 * … … 178 174 { 179 175 sysarg_t method = IPC_GET_IMETHOD(*icall); 180 int callback; 181 182 usb_kbd_t *kbd_dev = (usb_kbd_t *)fun->driver_data; 176 177 usb_kbd_t *kbd_dev = (usb_kbd_t *) fun->driver_data; 183 178 if (kbd_dev == NULL) { 184 179 usb_log_debug("default_connection_handler: " … … 187 182 return; 188 183 } 189 190 switch (method) { 191 case IPC_M_CONNECT_TO_ME: 192 callback = IPC_GET_ARG5(*icall); 193 194 if (kbd_dev->console_phone != -1) { 184 185 async_sess_t *sess = 186 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); 187 if (sess != NULL) { 188 if (kbd_dev->console_sess == NULL) { 189 kbd_dev->console_sess = sess; 190 usb_log_debug("default_connection_handler: OK\n"); 191 async_answer_0(icallid, EOK); 192 } else { 195 193 usb_log_debug("default_connection_handler: " 196 "console phonealready set\n");194 "console session already set\n"); 197 195 async_answer_0(icallid, ELIMIT); 198 return; 199 } 200 201 kbd_dev->console_phone = callback; 202 203 usb_log_debug("default_connection_handler: OK\n"); 204 async_answer_0(icallid, EOK); 205 break; 206 case KBDEV_SET_IND: 207 kbd_dev->mods = IPC_GET_ARG1(*icall); 208 usb_kbd_set_led(kbd_dev->hid_dev, kbd_dev); 209 async_answer_0(icallid, EOK); 210 break; 211 default: 212 usb_log_debug("default_connection_handler: Wrong function.\n"); 213 async_answer_0(icallid, EINVAL); 214 break; 196 } 197 } else { 198 switch (method) { 199 case KBDEV_SET_IND: 200 kbd_dev->mods = IPC_GET_ARG1(*icall); 201 usb_kbd_set_led(kbd_dev->hid_dev, kbd_dev); 202 async_answer_0(icallid, EOK); 203 break; 204 default: 205 usb_log_debug("default_connection_handler: Wrong function.\n"); 206 async_answer_0(icallid, EINVAL); 207 break; 208 } 215 209 } 216 210 } … … 301 295 { 302 296 usb_log_debug2("Sending kbdev event %d/%d to the console\n", type, key); 303 if (kbd_dev->console_ phone < 0) {297 if (kbd_dev->console_sess == NULL) { 304 298 usb_log_warning( 305 299 "Connection to console not ready, key discarded.\n"); … … 307 301 } 308 302 309 async_obsolete_msg_2(kbd_dev->console_phone, KBDEV_EVENT, type, key); 303 async_exch_t *exch = async_exchange_begin(kbd_dev->console_sess); 304 async_msg_2(exch, KBDEV_EVENT, type, key); 305 async_exchange_end(exch); 310 306 } 311 307 … … 510 506 } 511 507 512 kbd_dev->console_ phone = -1;508 kbd_dev->console_sess = NULL; 513 509 kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED; 514 510 … … 524 520 assert(kbd_dev != NULL); 525 521 526 /* Create the function exposed under /dev/devices. */522 /* Create the exposed function. */ 527 523 usb_log_debug("Creating DDF function %s...\n", HID_KBD_FUN_NAME); 528 524 ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, … … 551 547 HID_KBD_FUN_NAME, fun->handle); 552 548 553 usb_log_debug("Adding DDF function to c lass%s...\n",549 usb_log_debug("Adding DDF function to category %s...\n", 554 550 HID_KBD_CLASS_NAME); 555 rc = ddf_fun_add_to_c lass(fun, HID_KBD_CLASS_NAME);551 rc = ddf_fun_add_to_category(fun, HID_KBD_CATEGORY_NAME); 556 552 if (rc != EOK) { 557 553 usb_log_error( 558 "Could not add DDF function to c lass%s: %s.\n",554 "Could not add DDF function to category %s: %s.\n", 559 555 HID_KBD_CLASS_NAME, str_error(rc)); 560 556 ddf_fun_destroy(fun); … … 734 730 int rc = usb_kbd_create_function(hid_dev, kbd_dev); 735 731 if (rc != EOK) { 736 usb_kbd_ free(&kbd_dev);732 usb_kbd_destroy(kbd_dev); 737 733 return rc; 738 734 } … … 779 775 * @param kbd_dev Pointer to the structure to be destroyed. 780 776 */ 781 void usb_kbd_ free(usb_kbd_t **kbd_dev)782 { 783 if (kbd_dev == NULL || *kbd_dev == NULL) {777 void usb_kbd_destroy(usb_kbd_t *kbd_dev) 778 { 779 if (kbd_dev == NULL) { 784 780 return; 785 781 } 786 782 787 // hangup phoneto the console788 async_ obsolete_hangup((*kbd_dev)->console_phone);789 790 if ( (*kbd_dev)->repeat_mtx != NULL) {783 // hangup session to the console 784 async_hangup(kbd_dev->console_sess); 785 786 if (kbd_dev->repeat_mtx != NULL) { 791 787 //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx)); 792 788 // FIXME - the fibril_mutex_is_locked may not cause 793 789 // fibril scheduling 794 while (fibril_mutex_is_locked( (*kbd_dev)->repeat_mtx)) {}795 free( (*kbd_dev)->repeat_mtx);790 while (fibril_mutex_is_locked(kbd_dev->repeat_mtx)) {} 791 free(kbd_dev->repeat_mtx); 796 792 } 797 793 798 794 // free all buffers 799 if ((*kbd_dev)->keys != NULL) { 800 free((*kbd_dev)->keys); 801 } 802 if ((*kbd_dev)->keys_old != NULL) { 803 free((*kbd_dev)->keys_old); 804 } 805 if ((*kbd_dev)->led_data != NULL) { 806 free((*kbd_dev)->led_data); 807 } 808 if ((*kbd_dev)->led_path != NULL) { 809 usb_hid_report_path_free((*kbd_dev)->led_path); 810 } 811 if ((*kbd_dev)->output_buffer != NULL) { 812 usb_hid_report_output_free((*kbd_dev)->output_buffer); 813 } 814 815 free(*kbd_dev); 816 *kbd_dev = NULL; 795 if (kbd_dev->keys != NULL) { 796 free(kbd_dev->keys); 797 } 798 if (kbd_dev->keys_old != NULL) { 799 free(kbd_dev->keys_old); 800 } 801 if (kbd_dev->led_data != NULL) { 802 free(kbd_dev->led_data); 803 } 804 if (kbd_dev->led_path != NULL) { 805 usb_hid_report_path_free(kbd_dev->led_path); 806 } 807 if (kbd_dev->output_buffer != NULL) { 808 usb_hid_report_output_free(kbd_dev->output_buffer); 809 } 817 810 } 818 811 … … 830 823 usb_kbd_mark_unusable(kbd_dev); 831 824 } else { 832 usb_kbd_ free(&kbd_dev);825 usb_kbd_destroy(kbd_dev); 833 826 } 834 827 }
Note:
See TracChangeset
for help on using the changeset viewer.