Changeset 113093a in mainline


Ignore:
Timestamp:
2011-09-24T21:39:41Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1924bd43, f9d8c3a
Parents:
b3bf143 (diff), 024fcc5 (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.
Message:

Merge from lp:~vojtech-horky/helenos/usb

  • Fixed #349 (usbhid hit a malloc assertion when mouse is moved for the first time)
  • Fixed #377 (Console dies on a keypress of USB keyboard when in kconsole)
  • Added another virtual USB HID (Logitech Wireless)
Location:
uspace
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/vuhid/Makefile

    rb3bf143 r113093a  
    4747
    4848SOURCES_INTERFACES = \
    49         hids/bootkbd.c
     49        hids/bootkbd.c \
     50        hids/logitech_wireless.c
    5051
    5152SOURCES = \
     
    5354        device.c \
    5455        ifaces.c \
     56        life.c \
    5557        stdreq.c \
    5658        $(SOURCES_INTERFACES)
  • uspace/app/vuhid/hids/bootkbd.c

    rb3bf143 r113093a  
    9393             0, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    9494};
    95 static size_t in_data_count = sizeof(in_data)/INPUT_SIZE;
    96 // FIXME - locking
    97 static size_t in_data_position = 0;
    98 
    99 static int on_data_in(vuhid_interface_t *iface,
    100     void *buffer, size_t buffer_size, size_t *act_buffer_size)
    101 {
    102         static size_t last_pos = (size_t) -1;
    103         size_t pos = in_data_position;
    104         if (pos >= in_data_count) {
    105                 return EBADCHECKSUM;
    106         }
    107 
    108         if (last_pos == pos) {
    109                 return ENAK;
    110         }
    111 
    112         if (buffer_size > INPUT_SIZE) {
    113                 buffer_size = INPUT_SIZE;
    114         }
    115 
    116         if (act_buffer_size != NULL) {
    117                 *act_buffer_size = buffer_size;
    118         }
    119 
    120         memcpy(buffer, in_data + pos * INPUT_SIZE, buffer_size);
    121         last_pos = pos;
    122 
    123         return EOK;
    124 }
     95static vuhid_interface_life_t boot_life = {
     96        .data_in = in_data,
     97        .data_in_count = sizeof(in_data)/INPUT_SIZE,
     98        .data_in_pos_change_delay = 500,
     99        .msg_born = "Boot keyboard comes to life...",
     100        .msg_die = "Boot keyboard died."
     101};
    125102
    126103static int on_data_out(vuhid_interface_t *iface,
     
    141118}
    142119
    143 
    144 static void live(vuhid_interface_t *iface)
    145 {
    146         async_usleep(1000 * 1000 * 5);
    147         usb_log_debug("Boot keyboard comes to life...\n");
    148         while (in_data_position < in_data_count) {
    149                 async_usleep(1000 * 500);
    150                 in_data_position++;
    151         }
    152         usb_log_debug("Boot keyboard died.\n");
    153 }
    154 
    155 
    156120vuhid_interface_t vuhid_interface_bootkbd = {
    157121        .id = "boot",
     
    164128
    165129        .in_data_size = INPUT_SIZE,
    166         .on_data_in = on_data_in,
     130        .on_data_in = interface_live_on_data_in,
    167131
    168132        .out_data_size = 1,
    169133        .on_data_out = on_data_out,
    170134
    171         .live = live,
     135        .live = interface_life_live,
    172136
     137        .interface_data = &boot_life,
    173138        .vuhid_data = NULL
    174139};
  • uspace/app/vuhid/ifaces.c

    rb3bf143 r113093a  
    3838
    3939extern vuhid_interface_t vuhid_interface_bootkbd;
     40extern vuhid_interface_t vuhid_interface_logitech_wireless_1;
    4041
    4142vuhid_interface_t *available_hid_interfaces[] = {
    4243        &vuhid_interface_bootkbd,
     44        &vuhid_interface_logitech_wireless_1,
    4345        NULL
    4446};
  • uspace/app/vuhid/virthid.h

    rb3bf143 r113093a  
    8282
    8383typedef struct {
     84        /** Buffer with data from device to the host. */
     85        uint8_t *data_in;
     86        /** Number of items in @c data_in.
     87         * The total size of @c data_in buffer shall be
     88         * <code>data_in_count * vuhid_interface_t.in_data_size</code>.
     89         */
     90        size_t data_in_count;
     91
     92        /** Current position in the data buffer. */
     93        size_t data_in_pos;
     94        /** Previous position. */
     95        size_t data_in_last_pos;
     96
     97        /** Delay between transition to "next" input buffer (in ms). */
     98        size_t data_in_pos_change_delay;
     99
     100        /** Message to print when interface becomes alive. */
     101        const char *msg_born;
     102        /** Message to print when interface dies. */
     103        const char *msg_die;
     104} vuhid_interface_life_t;
     105
     106typedef struct {
    84107        uint8_t length;
    85108        uint8_t type;
     
    94117void wait_for_interfaces_death(usbvirt_device_t *);
    95118
     119void interface_life_live(vuhid_interface_t *);
     120int interface_live_on_data_in(vuhid_interface_t *, void *, size_t, size_t *);
     121
     122
    96123#endif
    97124/**
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.c

    rb3bf143 r113093a  
    7575/** Default idle rate for mouses. */
    7676static const uint8_t IDLE_RATE = 0;
    77 static const size_t USB_MOUSE_BUTTON_COUNT = 3;
    7877
    7978/*----------------------------------------------------------------------------*/
     
    397396/*----------------------------------------------------------------------------*/
    398397
     398/** Get highest index of a button mentioned in given report.
     399 *
     400 * @param report HID report.
     401 * @param report_id Report id we are interested in.
     402 * @return Highest button mentioned in the report.
     403 * @retval 1 No button was mentioned.
     404 *
     405 */
     406static size_t usb_mouse_get_highest_button(usb_hid_report_t *report, uint8_t report_id)
     407{
     408        size_t highest_button = 0;
     409
     410        usb_hid_report_path_t *path = usb_hid_report_path();
     411        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
     412        usb_hid_report_path_set_report_id(path, report_id);
     413
     414        usb_hid_report_field_t *field = NULL;
     415
     416        /* Break from within. */
     417        while (1) {
     418                field = usb_hid_report_get_sibling(
     419                    report, field, path,
     420                    USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     421                    USB_HID_REPORT_TYPE_INPUT);
     422                /* No more buttons? */
     423                if (field == NULL) {
     424                        break;
     425                }
     426
     427                size_t current_button = field->usage - field->usage_minimum;
     428                if (current_button > highest_button) {
     429                        highest_button = current_button;
     430                }
     431        }
     432
     433        usb_hid_report_path_free(path);
     434
     435        return highest_button;
     436}
     437
     438/*----------------------------------------------------------------------------*/
     439
    399440int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data)
    400441{
     
    414455        }
    415456       
    416         mouse_dev->buttons = (int32_t *)calloc(USB_MOUSE_BUTTON_COUNT,
    417             sizeof(int32_t));
     457        // FIXME: This may not be optimal since stupid hardware vendor may
     458        // use buttons 1, 2, 3 and 6000 and we would allocate array of
     459        // 6001*4B and use only 4 items in it.
     460        // Since I doubt that hardware producers would do that, I think
     461        // that the current solution is good enough.
     462        /* Adding 1 because we will be accessing buttons[highest]. */
     463        mouse_dev->buttons_count = usb_mouse_get_highest_button(hid_dev->report,
     464            hid_dev->report_id) + 1;
     465        mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t));
    418466       
    419467        if (mouse_dev->buttons == NULL) {
    420                 usb_log_fatal("No memory!\n");
     468                usb_log_error(NAME ": out of memory, giving up on device!\n");
    421469                free(mouse_dev);
    422470                return ENOMEM;
    423471        }
    424        
     472
     473
    425474        // save the Mouse device structure into the HID device structure
    426475        *data = mouse_dev;
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.h

    rb3bf143 r113093a  
    5050        async_sess_t *wheel_sess;
    5151       
     52        /* Mouse buttons statuses. */
    5253        int32_t *buttons;
     54        size_t buttons_count;
    5355       
    5456        ddf_dev_ops_t ops;
  • uspace/drv/bus/usb/vhc/connhost.c

    rb3bf143 r113093a  
    440440        int rc = vhc_virtdev_add_transfer(vhc, transfer);
    441441        if (rc != EOK) {
    442                 free(transfer->setup_buffer);
     442                if (transfer->setup_buffer != NULL) {
     443                        free(transfer->setup_buffer);
     444                }
    443445                free(transfer);
    444446                return rc;
  • uspace/lib/usbhid/src/hidpath.c

    rb3bf143 r113093a  
    7676                                    int32_t usage_page, int32_t usage)
    7777{       
    78         usb_hid_report_usage_path_t *item;
    79 
    80         if(!(item=malloc(sizeof(usb_hid_report_usage_path_t)))) {
     78        usb_hid_report_usage_path_t *item
     79                = malloc(sizeof(usb_hid_report_usage_path_t));
     80
     81        if (item == NULL) {
    8182                return ENOMEM;
    8283        }
  • uspace/srv/hid/console/console.c

    rb3bf143 r113093a  
    344344}
    345345
     346static console_t *cons_get_active_uspace(void)
     347{
     348        fibril_mutex_lock(&switch_mtx);
     349
     350        console_t *active_uspace = active_console;
     351        if (active_uspace == kernel_console) {
     352                active_uspace = prev_console;
     353        }
     354        assert(active_uspace != kernel_console);
     355
     356        fibril_mutex_unlock(&switch_mtx);
     357
     358        return active_uspace;
     359}
     360
    346361static ssize_t limit(ssize_t val, ssize_t lo, ssize_t hi)
    347362{
     
    466481                                event->c = c;
    467482                               
    468                                 prodcons_produce(&active_console->input_pc, &event->link);
     483                                /* Kernel console does not read events
     484                                 * from us, so we will redirect them
     485                                 * to the (last) active userspace console
     486                                 * if necessary.
     487                                 */
     488                                console_t *target_console = cons_get_active_uspace();
     489
     490                                prodcons_produce(&target_console->input_pc,
     491                                    &event->link);
    469492                        }
    470493                       
     
    904927                atomic_set(&consoles[i].refcnt, 0);
    905928                fibril_mutex_initialize(&consoles[i].mtx);
     929                prodcons_initialize(&consoles[i].input_pc);
    906930               
    907931                if (graphics_state == GRAPHICS_FULL) {
     
    942966                }
    943967               
    944                 prodcons_initialize(&consoles[i].input_pc);
    945968                cons_redraw_state(&consoles[i]);
    946969               
Note: See TracChangeset for help on using the changeset viewer.