Changes in / [37f7cfe:682b697] in mainline


Ignore:
Location:
uspace
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/virtusbkbd/virtusbkbd.c

    r37f7cfe r682b697  
    5555#include "stdreq.h"
    5656
    57 /** Pause between individual key-presses in seconds. */
    58 #define KEY_PRESS_DELAY 2
     57#define LOOPS 5
    5958#define NAME "virt-usb-kbd"
    6059
     
    8483}
    8584
    86 /** Compares current and last status of pressed keys.
    87  *
    88  * @warning Has side-efect - changes status_last field.
    89  *
    90  * @param status_now Status now.
    91  * @param status_last Last status.
    92  * @param len Size of status.
    93  * @return Whether they are the same.
    94  */
    95 static bool keypress_check_with_last_request(uint8_t *status_now,
    96     uint8_t *status_last, size_t len)
    97 {
    98         bool same = true;
    99         size_t i;
    100         for (i = 0; i < len; i++) {
    101                 if (status_now[i] != status_last[i]) {
    102                         status_last[i] = status_now[i];
    103                         same = false;
    104                 }
    105         }
    106         return same;
    107 }
    108 
    10985static int on_request_for_data(struct usbvirt_device *dev,
    11086    usb_endpoint_t endpoint, void *buffer, size_t size, size_t *actual_size)
    11187{
    112         static uint8_t last_data[2 + KB_MAX_KEYS_AT_ONCE];
    113 
    11488        if (size < 2 + KB_MAX_KEYS_AT_ONCE) {
    11589                return EINVAL;
     
    127101        }
    128102       
    129         if (keypress_check_with_last_request(data, last_data,
    130             2 + KB_MAX_KEYS_AT_ONCE)) {
    131                 *actual_size = 0;
    132                 return EOK;
    133         }
    134 
    135103        memcpy(buffer, &data, *actual_size);
    136104       
     
    184152        .ops = &keyboard_ops,
    185153        .descriptors = &descriptors,
    186         .lib_debug_level = 3,
    187         .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL,
    188154        .name = "keyboard"
    189155};
     
    211177        printf("\n");
    212178       
    213         fibril_sleep(KEY_PRESS_DELAY);
     179        fibril_sleep(1);
    214180}
    215181
     
    257223       
    258224        printf("%s: Simulating keyboard events...\n", NAME);
    259         while (1) {
     225        while(1){
    260226                kb_process_events(&status, keyboard_events, keyboard_events_count,
    261227                        on_keyboard_change);
  • uspace/drv/usbhub/main.c

    r37f7cfe r682b697  
    5050        while(true){
    5151                usb_hub_check_hub_changes();
    52                 async_usleep(1000 * 1000);
     52                async_usleep(10000000);
    5353        }
    5454        return 0;
  • uspace/drv/usbhub/usbhub_private.h

    r37f7cfe r682b697  
    182182}
    183183
    184 static inline int usb_hub_clear_port_feature(int hc, usb_address_t address,
    185     int port_index,
    186     usb_hub_class_feature_t feature) {
    187         usb_target_t target = {
    188                 .address = address,
    189                 .endpoint = 0
    190         };
    191         usb_device_request_setup_packet_t clear_request = {
    192                 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
    193                 .request = USB_DEVREQ_CLEAR_FEATURE,
    194                 .length = 0,
    195                 .index = port_index
    196         };
    197         clear_request.value = feature;
    198         return usb_drv_psync_control_write(hc, target, &clear_request,
    199             sizeof(clear_request), NULL, 0);
    200 }
    201 
    202184
    203185
  • uspace/drv/usbhub/utils.c

    r37f7cfe r682b697  
    506506                int hc, uint16_t port, usb_target_t target) {
    507507
     508        usb_device_request_setup_packet_t request;
    508509        int opResult;
    509510        printf("[usb_hub] finalizing add device\n");
    510         opResult = usb_hub_clear_port_feature(hc, target.address,
    511             port, USB_HUB_FEATURE_C_PORT_RESET);
    512         if (opResult != EOK) {
    513                 goto release;
    514         }
    515 
    516         /* Request address at from host controller. */
    517         usb_address_t new_device_address = usb_drv_request_address(hc);
    518         if (new_device_address < 0) {
    519                 printf("[usb_hub] failed to get free USB address\n");
    520                 opResult = new_device_address;
    521                 goto release;
    522         }
    523         printf("[usb_hub] setting new address\n");
    524         opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    525             new_device_address);
    526 
     511        usb_address_t new_device_address =
     512                        usb_drv_request_address(hc);
     513        usb_hub_set_set_address_request
     514                        (&request, new_device_address);
     515        opResult = usb_drv_sync_control_write(
     516                        hc, target,
     517                        &request,
     518                        NULL, 0
     519                        );
    527520        if (opResult != EOK) {
    528521                printf("[usb_hub] could not set address for new device\n");
    529                 goto release;
    530         }
    531 
    532 release:
    533         printf("[usb_hub] releasing default address\n");
     522                //will retry later...
     523                return;
     524        }
     525
    534526        usb_drv_release_default_address(hc);
    535         if (opResult != EOK) {
    536                 return;
    537         }
    538527
    539528        devman_handle_t child_handle;
    540529        opResult = usb_drv_register_child_in_devman(hc, hub->device,
    541             new_device_address, &child_handle);
     530        new_device_address, &child_handle);
    542531        if (opResult != EOK) {
    543532                printf("[usb_hub] could not start driver for new device \n");
     
    554543        printf("[usb_hub] new device address %d, handle %d\n",
    555544            new_device_address, child_handle);
     545        sleep(60);
    556546       
    557547}
     
    630620        //something connected/disconnected
    631621        if (usb_port_connect_change(&status)) {
    632                 opResult = usb_hub_clear_port_feature(hc, target.address,
    633                     port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    634                 // TODO: check opResult
    635622                if (usb_port_dev_connected(&status)) {
    636623                        printf("[usb_hub] some connection changed\n");
     
    642629        //port reset
    643630        if (usb_port_reset_completed(&status)) {
    644                 printf("[usb_hub] port reset complete\n");
     631                printf("[usb_hub] finalizing add device\n");
    645632                if (usb_port_enabled(&status)) {
    646633                        usb_hub_finalize_add_device(hub, hc, port, target);
     
    683670                        lst_item != &usb_hub_list;
    684671                        lst_item = lst_item->next) {
     672                printf("[usb_hub] checking hub changes\n");
    685673                usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data);
    686674                /*
     
    691679                target.address = hub_info->usb_device->address;
    692680                target.endpoint = 1;/// \TODO get from endpoint descriptor
    693                 printf("[usb_hub] checking changes for hub at addr %d\n",
    694                     target.address);
     681                printf("checking changes for hub at addr %d \n",target.address);
    695682
    696683                size_t port_count = hub_info->port_count;
  • uspace/drv/usbkbd/main.c

    r37f7cfe r682b697  
    3939#define NAME "usbkbd"
    4040
    41 #define GUESSED_POLL_ENDPOINT 1
     41static const usb_endpoint_t CONTROL_EP = 0;
    4242
    4343/*
     
    155155
    156156        // default endpoint
    157         kbd_dev->poll_endpoint = GUESSED_POLL_ENDPOINT;
     157        kbd_dev->default_ep = CONTROL_EP;
    158158       
    159159        /*
     
    204204        usb_target_t poll_target = {
    205205                .address = kbd_dev->address,
    206                 .endpoint = kbd_dev->poll_endpoint
     206                .endpoint = kbd_dev->default_ep
    207207        };
    208208
    209209        while (true) {
    210                 async_usleep(1000 * 1000);
    211210                rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone,
    212211                    poll_target, buffer, BUFFER_SIZE, &actual_size, &handle);
  • uspace/drv/vhc/hc.c

    r37f7cfe r682b697  
    5050#include "hub.h"
    5151
    52 #define USLEEP_BASE (0 * 5 * 1000)
     52#define USLEEP_BASE (0 * 500 * 1000)
    5353
    54 #define USLEEP_VAR 50
     54#define USLEEP_VAR 5000
    5555
    5656#define SHORTENING_VAR 15
     
    8989    usb_transaction_outcome_t outcome)
    9090{
    91         dprintf(3, "transaction " TRANSACTION_FORMAT " done, outcome: %s",
     91        dprintf(3, "processing transaction " TRANSACTION_FORMAT ", outcome: %s",
    9292            TRANSACTION_PRINTF(*transaction),
    9393            usb_str_transaction_outcome(outcome));
     
    116116                char ports[HUB_PORT_COUNT + 2];
    117117                hub_get_port_statuses(ports, HUB_PORT_COUNT + 1);
    118                 dprintf(4, "virtual hub: addr=%d ports=%s",
     118                dprintf(0, "virtual hub: addr=%d ports=%s",
    119119                    virthub_dev.address, ports);
    120120               
     
    124124                list_remove(first_transaction_link);
    125125               
    126 
    127                 dprintf(0, "about to process " TRANSACTION_FORMAT " (vhub:%s)",
    128                     TRANSACTION_PRINTF(*transaction), ports);
    129 
    130126                dprintf(3, "processing transaction " TRANSACTION_FORMAT "",
    131127                    TRANSACTION_PRINTF(*transaction));
  • uspace/drv/vhc/hcd.c

    r37f7cfe r682b697  
    110110        printf("%s: virtual USB host controller driver.\n", NAME);
    111111
    112         usb_dprintf_enable(NAME, 0);
     112        usb_dprintf_enable(NAME, 2);
    113113
    114114        fid_t fid = fibril_create(hc_manager_fibril, NULL);
  • uspace/drv/vhc/hub.c

    r37f7cfe r682b697  
    144144        .ops = &hub_ops,
    145145        .descriptors = &descriptors,
    146         .lib_debug_level = 0,
     146        .lib_debug_level = 1,
    147147        .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL
    148148};
     
    181181                hub_port_t *port = &hub_dev.ports[i];
    182182               
    183                 port->index = (int) i + 1;
     183                port->index = (int) i;
    184184                port->device = NULL;
    185185                port->state = HUB_PORT_STATE_NOT_CONFIGURED;
    186186                port->status_change = 0;
    187                 fibril_mutex_initialize(&port->guard);
    188187        }
    189188       
     
    226225        for (i = 0; i < HUB_PORT_COUNT; i++) {
    227226                hub_port_t *port = &hub_dev.ports[i];
    228                 fibril_mutex_lock(&port->guard);
    229227               
    230228                if (port->device != NULL) {
    231                         fibril_mutex_unlock(&port->guard);
    232229                        continue;
    233230                }
     
    244241                //if (port->state == HUB_PORT_STATE_DISCONNECTED) {
    245242                        port->state = HUB_PORT_STATE_DISABLED;
    246                         set_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION);
     243                        set_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
    247244                //}
    248245               
    249                 fibril_mutex_unlock(&port->guard);
    250 
    251246                return i;
    252247        }
  • uspace/drv/vhc/hubintern.h

    r37f7cfe r682b697  
    3737
    3838#include "hub.h"
    39 #include <fibril_synch.h>
    4039
    4140/** Endpoint number for status change pipe. */
     
    125124        hub_port_state_t state;
    126125        uint16_t status_change;
    127         fibril_mutex_t guard;
    128126} hub_port_t;
    129127
     
    141139void clear_port_status_change(hub_port_t *, uint16_t);
    142140void set_port_status_change(hub_port_t *, uint16_t);
    143 void set_port_status_change_nl(hub_port_t *, uint16_t);
    144141
    145142
  • uspace/drv/vhc/hubops.c

    r37f7cfe r682b697  
    6767    void *buffer, size_t size, size_t *actual_size);
    6868static void set_port_state(hub_port_t *, hub_port_state_t);
    69 static void clear_port_status_change_nl(hub_port_t *, uint16_t);
    70 static void set_port_state_nl(hub_port_t *, hub_port_state_t);
    7169
    7270/** Standard USB requests. */
     
    137135        async_usleep(change->delay);
    138136       
    139         fibril_mutex_lock(&change->port->guard);
    140137        if (change->port->state == change->old_state) {
    141                 set_port_state_nl(change->port, change->new_state);
    142         }
    143         fibril_mutex_unlock(&change->port->guard);
     138                set_port_state(change->port, change->new_state);
     139        }
    144140       
    145141        free(change);
     
    170166void set_port_state(hub_port_t *port, hub_port_state_t state)
    171167{
    172         fibril_mutex_lock(&port->guard);
    173         set_port_state_nl(port, state);
    174         fibril_mutex_unlock(&port->guard);
    175 }
    176 
    177 void set_port_state_nl(hub_port_t *port, hub_port_state_t state)
    178 {
    179 
    180         dprintf(2, "setting port %d state to %d (%c) from %c (change=%u)",
    181             port->index,
    182             state, hub_port_state_as_char(state),
    183             hub_port_state_as_char(port->state),
    184             (unsigned int) port->status_change);
     168        dprintf(1, "setting port %d state to %d (%c)", port->index,
     169            state, hub_port_state_as_char(state));
    185170       
    186171        if (state == HUB_PORT_STATE_POWERED_OFF) {
    187                 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION);
    188                 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_ENABLE);
    189                 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET);
     172                clear_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
     173                clear_port_status_change(port, HUB_STATUS_C_PORT_ENABLE);
     174                clear_port_status_change(port, HUB_STATUS_C_PORT_RESET);
    190175        }
    191176        if (state == HUB_PORT_STATE_RESUMING) {
     
    199184        if ((port->state == HUB_PORT_STATE_RESETTING)
    200185            && (state == HUB_PORT_STATE_ENABLED)) {
    201                 set_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET);
     186                set_port_status_change(port, HUB_STATUS_C_PORT_RESET);
    202187        }
    203188       
     
    227212        _GET_PORT(port, portindex);
    228213       
    229         fibril_mutex_lock(&port->guard);
    230         int rc = ENOTSUP;
    231 
    232214        switch (feature) {
    233215                case USB_HUB_FEATURE_PORT_ENABLE:
    234216                        if ((port->state != HUB_PORT_STATE_NOT_CONFIGURED)
    235217                            && (port->state != HUB_PORT_STATE_POWERED_OFF)) {
    236                                 set_port_state_nl(port, HUB_PORT_STATE_DISABLED);
    237                         }
    238                         rc = EOK;
    239                         break;
     218                                set_port_state(port, HUB_PORT_STATE_DISABLED);
     219                        }
     220                        return EOK;
    240221               
    241222                case USB_HUB_FEATURE_PORT_SUSPEND:
    242223                        if (port->state != HUB_PORT_STATE_SUSPENDED) {
    243                                 rc = EOK;
    244                                 break;
    245                         }
    246                         set_port_state_nl(port, HUB_PORT_STATE_RESUMING);
    247                         rc = EOK;
    248                         break;
     224                                return EOK;
     225                        }
     226                        set_port_state(port, HUB_PORT_STATE_RESUMING);
     227                        return EOK;
    249228                       
    250229                case USB_HUB_FEATURE_PORT_POWER:
    251230                        if (port->state != HUB_PORT_STATE_NOT_CONFIGURED) {
    252                                 set_port_state_nl(port, HUB_PORT_STATE_POWERED_OFF);
    253                         }
    254                         rc = EOK;
    255                         break;
     231                                set_port_state(port, HUB_PORT_STATE_POWERED_OFF);
     232                        }
     233                        return EOK;
    256234               
    257235                case USB_HUB_FEATURE_C_PORT_CONNECTION:
    258                         clear_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION);
    259                         rc = EOK;
    260                         break;
     236                        clear_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
     237                        return EOK;
    261238               
    262239                case USB_HUB_FEATURE_C_PORT_ENABLE:
    263                         clear_port_status_change_nl(port, HUB_STATUS_C_PORT_ENABLE);
    264                         rc = EOK;
    265                         break;
     240                        clear_port_status_change(port, HUB_STATUS_C_PORT_ENABLE);
     241                        return EOK;
    266242               
    267243                case USB_HUB_FEATURE_C_PORT_SUSPEND:
    268                         clear_port_status_change_nl(port, HUB_STATUS_C_PORT_SUSPEND);
    269                         rc = EOK;
    270                         break;
     244                        clear_port_status_change(port, HUB_STATUS_C_PORT_SUSPEND);
     245                        return EOK;
    271246                       
    272247                case USB_HUB_FEATURE_C_PORT_OVER_CURRENT:
    273                         clear_port_status_change_nl(port, HUB_STATUS_C_PORT_OVER_CURRENT);
    274                         rc = EOK;
    275                         break;
    276 
    277                 case USB_HUB_FEATURE_C_PORT_RESET:
    278                         clear_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET);
    279                         rc = EOK;
    280                         break;
    281         }
    282        
    283         fibril_mutex_unlock(&port->guard);
    284 
    285         return rc;
     248                        clear_port_status_change(port, HUB_STATUS_C_PORT_OVER_CURRENT);
     249                        return EOK;
     250        }
     251       
     252        return ENOTSUP;
    286253}
    287254
     
    318285        _GET_PORT(port, portindex);
    319286       
    320         fibril_mutex_lock(&port->guard);
    321 
    322287        uint32_t status;
    323288        status = MAKE_BYTE(
     
    347312        status |= (port->status_change << 16);
    348313       
    349         fibril_mutex_unlock(&port->guard);
    350 
    351314        dprintf(2, "GetPortStatus(port=%d, status=%u)\n", (int)portindex,
    352315            (unsigned int) status);
     
    364327        _GET_PORT(port, portindex);
    365328       
    366         fibril_mutex_lock(&port->guard);
    367 
    368         int rc = ENOTSUP;
    369 
    370329        switch (feature) {
    371330                case USB_HUB_FEATURE_PORT_RESET:
    372331                        if (port->state != HUB_PORT_STATE_POWERED_OFF) {
    373                                 set_port_state_nl(port, HUB_PORT_STATE_RESETTING);
    374                         }
    375                         rc = EOK;
    376                         break;
     332                                set_port_state(port, HUB_PORT_STATE_RESETTING);
     333                        }
     334                        return EOK;
    377335               
    378336                case USB_HUB_FEATURE_PORT_SUSPEND:
    379337                        if (port->state == HUB_PORT_STATE_ENABLED) {
    380                                 set_port_state_nl(port, HUB_PORT_STATE_SUSPENDED);
    381                         }
    382                         rc = EOK;
    383                         break;
     338                                set_port_state(port, HUB_PORT_STATE_SUSPENDED);
     339                        }
     340                        return EOK;
    384341               
    385342                case USB_HUB_FEATURE_PORT_POWER:
    386343                        if (port->state == HUB_PORT_STATE_POWERED_OFF) {
    387                                 set_port_state_nl(port, HUB_PORT_STATE_DISCONNECTED);
    388                         }
    389                         rc = EOK;
    390                         break;
    391         }
    392 
    393         fibril_mutex_unlock(&port->guard);
    394         return rc;
     344                                set_port_state(port, HUB_PORT_STATE_DISCONNECTED);
     345                        }
     346                        return EOK;
     347        }
     348        return ENOTSUP;
    395349}
    396350
     
    462416}
    463417
    464 void clear_port_status_change_nl(hub_port_t *port, uint16_t change)
     418void clear_port_status_change(hub_port_t *port, uint16_t change)
    465419{
    466420        port->status_change &= (~change);
    467         dprintf(2, "cleared port %d status change %d (%u)", port->index,
    468             (int)change, (unsigned int) port->status_change);
    469 }
    470 
    471 void set_port_status_change_nl(hub_port_t *port, uint16_t change)
     421}
     422
     423void set_port_status_change(hub_port_t *port, uint16_t change)
    472424{
    473425        port->status_change |= change;
    474         dprintf(2, "set port %d status change %d (%u)", port->index,
    475             (int)change, (unsigned int) port->status_change);
    476 
    477 }
    478 
    479 void clear_port_status_change(hub_port_t *port, uint16_t change)
    480 {
    481         fibril_mutex_lock(&port->guard);
    482         clear_port_status_change_nl(port, change);
    483         fibril_mutex_unlock(&port->guard);
    484 }
    485 
    486 void set_port_status_change(hub_port_t *port, uint16_t change)
    487 {
    488         fibril_mutex_lock(&port->guard);
    489         set_port_status_change_nl(port, change);
    490         fibril_mutex_unlock(&port->guard);
    491426}
    492427
     
    506441                hub_port_t *port = &hub_dev.ports[i];
    507442               
    508                 fibril_mutex_lock(&port->guard);
    509443                if (port->status_change != 0) {
    510444                        change_map |= (1 << (i + 1));
    511445                }
    512                 fibril_mutex_unlock(&port->guard);
    513446        }
    514447       
  • uspace/lib/usb/include/usb/classes/hid.h

    r37f7cfe r682b697  
    100100        device_t *device;
    101101        usb_address_t address;
    102         usb_endpoint_t poll_endpoint;
     102        usb_endpoint_t default_ep;
    103103        usb_hid_report_parser_t *parser;
    104104} usb_hid_dev_kbd_t;
  • uspace/lib/usbvirt/callback.c

    r37f7cfe r682b697  
    155155         * If the request was processed, we will send data back.
    156156         */
    157         if ((rc == EOK) && (expected_len > 0)) {
     157        if (rc == EOK) {
    158158                size_t receive_len;
    159159                ipc_callid_t callid;
Note: See TracChangeset for help on using the changeset viewer.