Changeset 00b13408 in mainline


Ignore:
Timestamp:
2011-03-18T17:17:04Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
18b3cfd, 3746bfe
Parents:
4fec9ee
Message:

Fixed destroying of KBD structure when polling ended.

The structure must be destroyed in the autorepeat fibril, as there is
no nice way to stop the fibril on demand.

Location:
uspace/drv/usbhid
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/hiddev.c

    r4fec9ee r00b13408  
    440440        if (rc != EOK) {
    441441                /* TODO: end session?? */
     442                usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
    442443                usb_log_error("Failed to process descriptors: %s.\n",
    443444                    str_error(rc));
  • uspace/drv/usbhid/hiddev.h

    r4fec9ee r00b13408  
    3232/** @file
    3333 * Generic USB HID device structure and API.
     34 *
     35 * @todo Add function for parsing report - this is generic HID function, not
     36 *       keyboard-specific, as the report parser is also generic.
     37 * @todo Add function for polling as that is also a generic HID process.
     38 * @todo Add interrupt in pipe to the structure.
    3439 */
    3540
  • uspace/drv/usbhid/kbddev.c

    r4fec9ee r00b13408  
    9494        .flags = 0
    9595};
     96
     97typedef enum usbhid_kbd_flags {
     98        USBHID_KBD_STATUS_UNINITIALIZED = 0,
     99        USBHID_KBD_STATUS_INITIALIZED = 1,
     100        USBHID_KBD_STATUS_TO_DESTROY = -1
     101} usbhid_kbd_flags;
    96102
    97103/*----------------------------------------------------------------------------*/
     
    232238       
    233239        assert(kbd_dev->hid_dev != NULL);
    234         assert(kbd_dev->hid_dev->initialized);
     240        assert(kbd_dev->hid_dev->initialized == USBHID_KBD_STATUS_INITIALIZED);
    235241        usbhid_req_set_report(kbd_dev->hid_dev, USB_HID_REPORT_TYPE_OUTPUT,
    236242            buffer, BOOTP_BUFFER_OUT_SIZE);
     
    565571                                    uint8_t *buffer, size_t actual_size)
    566572{
    567         assert(kbd_dev->initialized);
     573        assert(kbd_dev->initialized == USBHID_KBD_STATUS_INITIALIZED);
    568574        assert(kbd_dev->hid_dev->parser != NULL);
    569575       
     
    619625       
    620626        kbd_dev->console_phone = -1;
    621         kbd_dev->initialized = 0;
     627        kbd_dev->initialized = USBHID_KBD_STATUS_UNINITIALIZED;
    622628       
    623629        return kbd_dev;
     
    625631
    626632/*----------------------------------------------------------------------------*/
    627 /**
    628  * Properly destroys the USB/HID keyboard structure.
    629  *
    630  * @param kbd_dev Pointer to the structure to be destroyed.
    631  */
    632 static void usbhid_kbd_free(usbhid_kbd_t **kbd_dev)
    633 {
    634         if (kbd_dev == NULL || *kbd_dev == NULL) {
    635                 return;
    636         }
    637        
    638         // hangup phone to the console
    639         async_hangup((*kbd_dev)->console_phone);
    640        
    641         if ((*kbd_dev)->hid_dev != NULL) {
    642                 usbhid_dev_free(&(*kbd_dev)->hid_dev);
    643                 assert((*kbd_dev)->hid_dev == NULL);
    644         }
    645        
    646         if ((*kbd_dev)->repeat_mtx != NULL) {
    647                 /* TODO: replace by some check and wait */
    648                 assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
    649                 free((*kbd_dev)->repeat_mtx);
    650         }
    651 
    652         free(*kbd_dev);
    653         *kbd_dev = NULL;
     633
     634static void usbhid_kbd_mark_unusable(usbhid_kbd_t *kbd_dev)
     635{
     636        kbd_dev->initialized = USBHID_KBD_STATUS_TO_DESTROY;
    654637}
    655638
     
    693676        }
    694677       
    695         if (kbd_dev->initialized) {
     678        if (kbd_dev->initialized == USBHID_KBD_STATUS_INITIALIZED) {
    696679                usb_log_warning("Keyboard structure already initialized.\n");
    697680                return EINVAL;
     
    706689        }
    707690       
    708         assert(kbd_dev->hid_dev->initialized);
     691        assert(kbd_dev->hid_dev->initialized == USBHID_KBD_STATUS_INITIALIZED);
    709692       
    710693        // save the size of the report (boot protocol report by default)
     
    758741        usbhid_req_set_idle(kbd_dev->hid_dev, IDLE_RATE);
    759742       
    760         kbd_dev->initialized = 1;
     743        kbd_dev->initialized = USBHID_KBD_STATUS_INITIALIZED;
    761744        usb_log_info("HID/KBD device structure initialized.\n");
    762745       
     
    872855        usbhid_kbd_poll(kbd_dev);
    873856       
     857        // as there is another fibril using this device, so we must leave the
     858        // structure to it, but mark it for destroying.
     859        usbhid_kbd_mark_unusable(kbd_dev);
    874860        // at the end, properly destroy the KBD structure
    875         usbhid_kbd_free(&kbd_dev);
    876         assert(kbd_dev == NULL);
     861//      usbhid_kbd_free(&kbd_dev);
     862//      assert(kbd_dev == NULL);
    877863
    878864        return EOK;
     
    996982}
    997983
     984/*----------------------------------------------------------------------------*/
     985
     986int usbhid_kbd_is_usable(const usbhid_kbd_t *kbd_dev)
     987{
     988        return (kbd_dev->initialized == USBHID_KBD_STATUS_INITIALIZED);
     989}
     990
     991/*----------------------------------------------------------------------------*/
     992/**
     993 * Properly destroys the USB/HID keyboard structure.
     994 *
     995 * @param kbd_dev Pointer to the structure to be destroyed.
     996 */
     997void usbhid_kbd_free(usbhid_kbd_t **kbd_dev)
     998{
     999        if (kbd_dev == NULL || *kbd_dev == NULL) {
     1000                return;
     1001        }
     1002       
     1003        // hangup phone to the console
     1004        async_hangup((*kbd_dev)->console_phone);
     1005       
     1006        if ((*kbd_dev)->hid_dev != NULL) {
     1007                usbhid_dev_free(&(*kbd_dev)->hid_dev);
     1008                assert((*kbd_dev)->hid_dev == NULL);
     1009        }
     1010       
     1011        if ((*kbd_dev)->repeat_mtx != NULL) {
     1012                /* TODO: replace by some check and wait */
     1013                assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
     1014                free((*kbd_dev)->repeat_mtx);
     1015        }
     1016
     1017        free(*kbd_dev);
     1018        *kbd_dev = NULL;
     1019}
     1020
    9981021/**
    9991022 * @}
  • uspace/drv/usbhid/kbddev.h

    r4fec9ee r00b13408  
    101101        fibril_mutex_t *repeat_mtx;
    102102       
    103         /** State of the structure (for checking before use). */
     103        /** State of the structure (for checking before use).
     104         *
     105         * 0 - not initialized
     106         * 1 - initialized
     107         * -1 - ready for destroying
     108         */
    104109        int initialized;
    105110} usbhid_kbd_t;
     
    108113
    109114int usbhid_kbd_try_add_device(ddf_dev_t *dev);
     115
     116int usbhid_kbd_is_usable(const usbhid_kbd_t *kbd_dev);
     117
     118void usbhid_kbd_free(usbhid_kbd_t **kbd_dev);
    110119
    111120void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key);
  • uspace/drv/usbhid/kbdrepeat.c

    r4fec9ee r00b13408  
    7777
    7878        while (true) {
     79                // check if the kbd structure is usable
     80                if (!usbhid_kbd_is_usable(kbd)) {
     81                        usbhid_kbd_free(&kbd);
     82                        assert(kbd == NULL);
     83                        return;
     84                }
     85               
    7986                fibril_mutex_lock(kbd->repeat_mtx);
    8087
Note: See TracChangeset for help on using the changeset viewer.