Changes in / [62066b4:423e8c81] in mainline


Ignore:
Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhub/usbhub.c

    r62066b4 r423e8c81  
    4343#include <usb/recognise.h>
    4444#include <usb/devreq.h>
    45 #include <usb/request.h>
    4645#include <usb/classes/hub.h>
    4746
     
    5049#include "port_status.h"
    5150#include "usb/usb.h"
    52 #include "usb/pipes.h"
    5351
    5452static int iface_get_hc_handle(device_t *device, devman_handle_t *handle)
     
    7169//*********************************************
    7270
    73 usb_hub_info_t * usb_create_hub_info(device_t * device) {
     71usb_hub_info_t * usb_create_hub_info(device_t * device, int hc) {
    7472        usb_hub_info_t* result = usb_new(usb_hub_info_t);
    75         usb_device_connection_initialize_from_device(&result->device_connection,
    76                         device);
    77         usb_hc_connection_initialize_from_device(&result->connection,
    78                         device);
    79         usb_endpoint_pipe_initialize_default_control(&result->endpoints.control,
    80             &result->device_connection);
    81        
    82 
    8373        //result->device = device;
    8474        result->port_count = -1;
     
    8676        result->device = device;
    8777
    88         //result->usb_device = usb_new(usb_hcd_attached_device_info_t);
    89        
     78
     79        dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc);
     80        if (hc < 0) {
     81                return result;
     82        }
     83        //get some hub info
     84        usb_address_t addr = usb_drv_get_my_address(hc, device);
     85        dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr);
     86        /*if(addr<0){
     87                //return result;
     88
     89        }*/
     90
     91        result->address = addr;
     92
    9093        // get hub descriptor
    9194
     
    9699        int opResult;
    97100        dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction");
    98         usb_endpoint_pipe_start_session(&result->endpoints.control);
    99         opResult = usb_request_get_descriptor(&result->endpoints.control,
     101       
     102        opResult = usb_drv_req_get_descriptor(hc, addr,
    100103                        USB_REQUEST_TYPE_CLASS,
    101104                        USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
    102105                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
    103         usb_endpoint_pipe_end_session(&result->endpoints.control);
    104 
    105         /* Initialize the interrupt endpoint.
    106         usb_endpoint_pipe_initalize(
    107                 &hub_data->endpoints->status_change,
    108                 &endpiont_descriptor, &hub_data->connection);
    109 
    110          */ /// \TODO add this call
    111106
    112107        if (opResult != EOK) {
     
    124119        dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count);
    125120        result->port_count = descriptor->ports_count;
    126         result->attached_devs = (usb_hc_attached_device_t*)
    127             malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t));
     121        result->attached_devs = (usb_hub_attached_device_t*)
     122            malloc((result->port_count+1) * sizeof(usb_hub_attached_device_t));
    128123        int i;
    129124        for(i=0;i<result->port_count+1;++i){
    130                 result->attached_devs[i].handle=0;
     125                result->attached_devs[i].devman_handle=0;
    131126                result->attached_devs[i].address=0;
    132127        }
     
    153148        dev->ops = &hub_device_ops;
    154149
    155 
    156         usb_hub_info_t * hub_info = usb_create_hub_info(dev);
    157         usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
    158 
     150        //create the hub structure
     151        //get hc connection
     152        int hc = usb_drv_hc_connect_auto(dev, 0);
     153        if (hc < 0) {
     154                return hc;
     155        }
     156
     157        usb_hub_info_t * hub_info = usb_create_hub_info(dev, hc);
    159158        int port;
    160159        int opResult;
    161         //usb_target_t target;
    162         //target.address = hub_info->usb_device->address;
    163         //target.endpoint = 0;
     160        usb_target_t target;
     161        target.address = hub_info->address;
     162        target.endpoint = 0;
    164163
    165164        //get configuration descriptor
     
    167166        // and all should be checked
    168167        usb_standard_device_descriptor_t std_descriptor;
    169         opResult = usb_request_get_device_descriptor(&hub_info->endpoints.control,
     168        opResult = usb_drv_req_get_device_descriptor(hc, target.address,
    170169            &std_descriptor);
    171170        if(opResult!=EOK){
     
    180179        /// \TODO check other configurations
    181180        usb_standard_configuration_descriptor_t config_descriptor;
    182         opResult = usb_request_get_bare_configuration_descriptor(
    183             &hub_info->endpoints.control, 0,
     181        opResult = usb_drv_req_get_bare_configuration_descriptor(hc,
     182        target.address, 0,
    184183        &config_descriptor);
    185184        if(opResult!=EOK){
     
    188187        }
    189188        //set configuration
    190         opResult = usb_request_set_configuration(&hub_info->endpoints.control,
     189        opResult = usb_drv_req_set_configuration(hc, target.address,
    191190    config_descriptor.configuration_number);
    192191
     
    198197        for (port = 1; port < hub_info->port_count+1; ++port) {
    199198                usb_hub_set_power_port_request(&request, port);
    200                 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,
    201                                 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);
     199                opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
    202200                dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port);
    203201                if (opResult != EOK) {
     
    207205        //ports powered, hub seems to be enabled
    208206
    209         usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
    210         //async_hangup(hc);
     207        async_hangup(hc);
    211208
    212209        //add the hub to list
     
    222219
    223220        dprintf(USB_LOG_LEVEL_INFO, "hub dev added");
    224         //address is lost...
    225221        dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ",
    226                         //hub_info->endpoints.control.,
     222                        hub_info->address,
    227223                        hub_info->port_count);
    228224        dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number);
     
    261257 * @param target
    262258 */
    263 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) {
     259static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) {
    264260        usb_device_request_setup_packet_t request;
    265261        int opResult;
    266262        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    267         assert(hub->endpoints.control.hc_phone);
    268263        //get default address
    269         //opResult = usb_drv_reserve_default_address(hc);
    270         opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW);
     264        opResult = usb_drv_reserve_default_address(hc);
    271265        if (opResult != EOK) {
    272266                dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used");
     
    275269        //reset port
    276270        usb_hub_set_reset_port_request(&request, port);
    277         opResult = usb_endpoint_pipe_control_write(
    278                         &hub->endpoints.control,
    279                         &request,sizeof(usb_device_request_setup_packet_t),
     271        opResult = usb_drv_sync_control_write(
     272                        hc, target,
     273                        &request,
    280274                        NULL, 0
    281275                        );
    282276        if (opResult != EOK) {
    283277                dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port");
    284                 //usb_hub_release_default_address(hc);
    285                 usb_hc_release_default_address(&hub->connection);
     278                usb_hub_release_default_address(hc);
    286279        }
    287280}
     
    294287 */
    295288static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
    296                 uint16_t port) {
     289                int hc, uint16_t port, usb_target_t target) {
    297290
    298291        int opResult;
    299292        dprintf(USB_LOG_LEVEL_INFO, "finalizing add device");
    300         opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
     293        opResult = usb_hub_clear_port_feature(hc, target.address,
    301294            port, USB_HUB_FEATURE_C_PORT_RESET);
    302 
    303295        if (opResult != EOK) {
    304296                dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature");
    305                 usb_hc_release_default_address(&hub->connection);
    306                 return;
    307         }
    308         //create connection to device
    309         usb_endpoint_pipe_t new_device_pipe;
    310         usb_device_connection_t new_device_connection;
    311         usb_device_connection_initialize_on_default_address(
    312                         &new_device_connection,
    313                         &hub->connection
    314                         );
    315         usb_endpoint_pipe_initialize_default_control(
    316                         &new_device_pipe,
    317                         &new_device_connection);
    318         /// \TODO get highspeed info
    319 
    320 
    321 
    322 
    323 
    324         /* Request address from host controller. */
    325         usb_address_t new_device_address = usb_hc_request_address(
    326                         &hub->connection,
    327                         USB_SPEED_LOW/// \TODO fullspeed??
    328                         );
     297                usb_hub_release_default_address(hc);
     298                return;
     299        }
     300
     301        /* Request address at from host controller. */
     302        usb_address_t new_device_address = usb_drv_request_address(hc);
    329303        if (new_device_address < 0) {
    330304                dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address");
    331305                opResult = new_device_address;
    332                 usb_hc_release_default_address(&hub->connection);
     306                usb_hub_release_default_address(hc);
    333307                return;
    334308        }
    335309        dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address);
    336         //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    337         //    new_device_address);
    338         opResult = usb_request_set_address(&new_device_pipe,new_device_address);
     310        opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
     311            new_device_address);
    339312
    340313        if (opResult != EOK) {
    341314                dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device");
    342                 usb_hc_release_default_address(&hub->connection);
    343                 return;
    344         }
    345 
    346 
    347         //opResult = usb_hub_release_default_address(hc);
    348         opResult = usb_hc_release_default_address(&hub->connection);
     315                usb_hub_release_default_address(hc);
     316                return;
     317        }
     318
     319
     320        opResult = usb_hub_release_default_address(hc);
    349321        if(opResult!=EOK){
    350322                return;
    351323        }
    352324
     325        devman_handle_t hc_handle;
     326        opResult = usb_drv_find_hc(hub->device, &hc_handle);
     327        if (opResult != EOK) {
     328                usb_log_error("Failed to get handle of host controller: %s.\n",
     329                    str_error(opResult));
     330                return;
     331        }
     332
    353333        devman_handle_t child_handle;
    354         //??
    355     opResult = usb_device_register_child_in_devman(new_device_address,
    356             hub->connection.hc_handle, hub->device, &child_handle);
    357 
     334        opResult = usb_device_register_child_in_devman(new_device_address,
     335            hc_handle, hub->device, &child_handle);
    358336        if (opResult != EOK) {
    359337                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
    360338                return;
    361339        }
    362         hub->attached_devs[port].handle = child_handle;
     340        hub->attached_devs[port].devman_handle = child_handle;
    363341        hub->attached_devs[port].address = new_device_address;
    364342
    365         //opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
    366         opResult = usb_hc_register_device(
    367                         &hub->connection,
    368                         &hub->attached_devs[port]);
     343        opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
    369344        if (opResult != EOK) {
    370345                dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd");
     
    383358 */
    384359static void usb_hub_removed_device(
    385     usb_hub_info_t * hub,uint16_t port) {
     360    usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {
    386361        //usb_device_request_setup_packet_t request;
    387362        int opResult;
     
    390365         * devide manager
    391366         */
    392        
     367
     368        hub->attached_devs[port].devman_handle=0;
    393369        //close address
    394370        if(hub->attached_devs[port].address!=0){
    395                 //opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
    396                 opResult = usb_hc_unregister_device(
    397                                 &hub->connection, hub->attached_devs[port].address);
     371                opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
    398372                if(opResult != EOK) {
    399373                        dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \
     
    401375                }
    402376                hub->attached_devs[port].address = 0;
    403                 hub->attached_devs[port].handle = 0;
    404377        }else{
    405378                dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address");
    406379                //device was disconnected before it`s port was reset - return default address
    407                 //usb_drv_release_default_address(hc);
    408                 usb_hc_release_default_address(&hub->connection);
     380                usb_drv_release_default_address(hc);
    409381        }
    410382}
     
    416388 * @param target
    417389 */
    418 static void usb_hub_process_interrupt(usb_hub_info_t * hub,
    419         uint16_t port) {
     390static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,
     391        uint16_t port, usb_address_t address) {
    420392        dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);
    421393        //determine type of change
    422         usb_endpoint_pipe_t *pipe = &hub->endpoints.control;
    423         int opResult = usb_endpoint_pipe_start_session(pipe);
    424        
    425         if(opResult != EOK){
    426                 dprintf(USB_LOG_LEVEL_ERROR, "cannot open pipe %d", opResult);
    427         }
    428 
    429         /*
    430394        usb_target_t target;
    431395        target.address=address;
    432396        target.endpoint=0;
    433         */
    434 
    435397        usb_port_status_t status;
    436398        size_t rcvd_size;
    437399        usb_device_request_setup_packet_t request;
    438         //int opResult;
     400        int opResult;
    439401        usb_hub_set_port_status_request(&request, port);
    440402        //endpoint 0
    441403
    442         opResult = usb_endpoint_pipe_control_read(
    443                         pipe,
    444                         &request, sizeof(usb_device_request_setup_packet_t),
     404        opResult = usb_drv_sync_control_read(
     405                        hc, target,
     406                        &request,
    445407                        &status, 4, &rcvd_size
    446408                        );
     
    455417        //something connected/disconnected
    456418        if (usb_port_connect_change(&status)) {
    457                 opResult = usb_hub_clear_port_feature(pipe,
     419                opResult = usb_hub_clear_port_feature(hc, target.address,
    458420                    port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    459421                // TODO: check opResult
    460422                if (usb_port_dev_connected(&status)) {
    461423                        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    462                         usb_hub_init_add_device(hub, port);
     424                        usb_hub_init_add_device(hc, port, target);
    463425                } else {
    464                         usb_hub_removed_device(hub, port);
     426                        usb_hub_removed_device(hub, hc, port, target);
    465427                }
    466428        }
     
    469431                dprintf(USB_LOG_LEVEL_INFO, "port reset complete");
    470432                if (usb_port_enabled(&status)) {
    471                         usb_hub_finalize_add_device(hub, port);
     433                        usb_hub_finalize_add_device(hub, hc, port, target);
    472434                } else {
    473435                        dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled");
     
    485447        /// \TODO handle other changes
    486448        /// \TODO debug log for various situations
    487         usb_endpoint_pipe_end_session(pipe);
    488 
    489449
    490450}
     
    504464                fibril_mutex_unlock(&usb_hub_list_lock);
    505465                usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data);
    506                 int opResult;
    507 
    508                 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);
    509                 if(opResult != EOK){
    510                         continue;
    511                 }
    512466                /*
    513467                 * Check status change pipe of this hub.
    514468                 */
    515                 /*
     469
    516470                usb_target_t target;
    517471                target.address = hub_info->address;
     
    519473                dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d",
    520474                    target.address);
    521                 */
     475
    522476                size_t port_count = hub_info->port_count;
    523477
    524478                /*
    525479                 * Connect to respective HC.
    526                  *
     480                 */
    527481                int hc = usb_drv_hc_connect_auto(hub_info->device, 0);
    528482                if (hc < 0) {
    529483                        continue;
    530                 }*/
     484                }
    531485
    532486                /// FIXME: count properly
     
    535489                void *change_bitmap = malloc(byte_length);
    536490                size_t actual_size;
    537                 //usb_handle_t handle;
     491                usb_handle_t handle;
    538492
    539493                /*
    540494                 * Send the request.
    541495                 */
    542                 opResult = usb_endpoint_pipe_read(
    543                                 &hub_info->endpoints.status_change,
    544                                 change_bitmap, byte_length, &actual_size
    545                                 );
    546 
    547                 //usb_drv_async_wait_for(handle);
     496                int opResult = usb_drv_async_interrupt_in(hc, target,
     497                                change_bitmap, byte_length, &actual_size,
     498                                &handle);
     499
     500                usb_drv_async_wait_for(handle);
    548501
    549502                if (opResult != EOK) {
     
    558511                        if (interrupt) {
    559512                                usb_hub_process_interrupt(
    560                                         hub_info, port);
     513                                        hub_info, hc, port, hub_info->address);
    561514                        }
    562515                }
    563                 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    564516                free(change_bitmap);
    565                
    566 
    567                 //async_hangup(hc);
     517
     518                async_hangup(hc);
    568519                fibril_mutex_lock(&usb_hub_list_lock);
    569520        }
  • uspace/drv/usbhub/usbhub.h

    r62066b4 r423e8c81  
    4242#define NAME "usbhub"
    4343
    44 //#include "usb/hcdhubd.h"
    45 #include <usb/usbdrv.h>
    46 #include <usb/hub.h>
    47 
    48 #include <usb/pipes.h>
    49 
    50 /* Hub endpoints. */
    51 typedef struct {
    52         usb_endpoint_pipe_t control;
    53         usb_endpoint_pipe_t status_change;
    54 } usb_hub_endpoints_t;
    55 
    56 
     44/** basic information about device attached to hub */
     45typedef struct{
     46        usb_address_t address;
     47        devman_handle_t devman_handle;
     48}usb_hub_attached_device_t;
    5749
    5850/** Information about attached hub. */
     
    6052        /** Number of ports. */
    6153        int port_count;
    62         /** attached device handles, for each port one */
    63         usb_hc_attached_device_t * attached_devs;
    64         /** General usb device info. */
    65         //usb_hcd_attached_device_info_t * usb_device;
     54        /** attached device handles */
     55        usb_hub_attached_device_t * attached_devs;
     56        /** USB address of the hub. */
     57        usb_address_t address;
    6658        /** General device info*/
    6759        device_t * device;
    68         /** connection to hcd */
    69         //usb_device_connection_t connection;
    70         usb_hc_connection_t connection;
    71         /** */
    72         usb_device_connection_t device_connection;
    73         /** hub endpoints */
    74         usb_hub_endpoints_t endpoints;
    7560} usb_hub_info_t;
    7661
  • uspace/drv/usbhub/usbhub_private.h

    r62066b4 r423e8c81  
    4545#include <fibril_synch.h>
    4646
    47 #include <usb/classes/hub.h>
    4847#include <usb/usb.h>
    4948#include <usb/usbdrv.h>
    50 
    51 //#include <usb/devreq.h>
     49#include <usb/classes/hub.h>
     50#include <usb/devreq.h>
    5251#include <usb/debug.h>
    5352
     
    7877 * @return
    7978 */
    80 usb_hub_info_t * usb_create_hub_info(device_t * device);
     79usb_hub_info_t * usb_create_hub_info(device_t * device, int hc);
    8180
    8281/** List of hubs maanged by this driver */
     
    9998 * @return error code
    10099 */
    101 /*
    102100int usb_drv_sync_control_read(
    103     usb_endpoint_pipe_t *pipe,
     101    int phone, usb_target_t target,
    104102    usb_device_request_setup_packet_t * request,
    105103    void * rcvd_buffer, size_t rcvd_size, size_t * actual_size
    106 );*/
     104);
    107105
    108106/**
     
    117115 * @return error code
    118116 */
    119 /*int usb_drv_sync_control_write(
    120     usb_endpoint_pipe_t *pipe,
     117int usb_drv_sync_control_write(
     118    int phone, usb_target_t target,
    121119    usb_device_request_setup_packet_t * request,
    122120    void * sent_buffer, size_t sent_size
    123 );*/
     121);
    124122
    125123/**
     
    149147 * @return Operation result
    150148 */
    151 static inline int usb_hub_clear_port_feature(usb_endpoint_pipe_t *pipe,
     149static inline int usb_hub_clear_port_feature(int hc, usb_address_t address,
    152150    int port_index,
    153151    usb_hub_class_feature_t feature) {
    154        
     152        usb_target_t target = {
     153                .address = address,
     154                .endpoint = 0
     155        };
    155156        usb_device_request_setup_packet_t clear_request = {
    156157                .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
     
    160161        };
    161162        clear_request.value = feature;
    162         return usb_endpoint_pipe_control_write(pipe, &clear_request,
     163        return usb_drv_psync_control_write(hc, target, &clear_request,
    163164            sizeof(clear_request), NULL, 0);
    164165}
  • uspace/drv/usbhub/utils.c

    r62066b4 r423e8c81  
    114114
    115115//control transactions
    116 /*
     116
    117117int usb_drv_sync_control_read(
    118118    int phone, usb_target_t target,
     
    199199}
    200200
    201 */
     201
    202202
    203203
  • uspace/lib/usb/include/usb/classes/hub.h

    r62066b4 r423e8c81  
    11/*
    2  * Copyright (c) 2010 Matus Dekanek
     2 * Copyright (c) 2010 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    3333 * @brief USB hub related structures.
    3434 */
    35 #ifndef LIBUSB_CLASS_HUB_H_
    36 #define LIBUSB_CLASS_HUB_H_
     35#ifndef LIBUSB_HUB_H_
     36#define LIBUSB_HUB_H_
    3737
    3838#include <sys/types.h>
Note: See TracChangeset for help on using the changeset viewer.