Changeset da7c0a9 in mainline


Ignore:
Timestamp:
2011-02-20T22:51:44Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b476347
Parents:
063ead6f (diff), d37b235 (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 development/ changes

Location:
uspace
Files:
5 edited

Legend:

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

    r063ead6f rda7c0a9  
    4444#include <usb/recognise.h>
    4545#include <usb/devreq.h>
     46#include <usb/request.h>
    4647#include <usb/classes/hub.h>
    4748
     
    5051#include "port_status.h"
    5152#include "usb/usb.h"
     53#include "usb/pipes.h"
    5254
    5355static device_ops_t hub_device_ops = {
     
    6163//*********************************************
    6264
    63 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc) {
     65usb_hub_info_t * usb_create_hub_info(device_t * device) {
    6466        usb_hub_info_t* result = usb_new(usb_hub_info_t);
     67        usb_device_connection_initialize_from_device(&result->device_connection,
     68                        device);
     69        usb_hc_connection_initialize_from_device(&result->connection,
     70                        device);
     71        usb_endpoint_pipe_initialize_default_control(&result->endpoints.control,
     72            &result->device_connection);
     73       
     74
    6575        //result->device = device;
    6676        result->port_count = -1;
     
    6878        result->device = device;
    6979
    70 
    71         dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc);
    72         if (hc < 0) {
    73                 return result;
    74         }
    75         //get some hub info
    76         usb_address_t addr = usb_drv_get_my_address(hc, device);
    77         dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr);
    78         /*if(addr<0){
    79                 //return result;
    80 
    81         }*/
    82 
    83         result->address = addr;
    84 
     80        //result->usb_device = usb_new(usb_hcd_attached_device_info_t);
     81       
    8582        // get hub descriptor
    8683
     
    9188        int opResult;
    9289        dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction");
    93        
    94         opResult = usb_drv_req_get_descriptor(hc, addr,
     90        usb_endpoint_pipe_start_session(&result->endpoints.control);
     91        opResult = usb_request_get_descriptor(&result->endpoints.control,
    9592                        USB_REQUEST_TYPE_CLASS,
    9693                        USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
    9794                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
     95        usb_endpoint_pipe_end_session(&result->endpoints.control);
     96
     97        /* Initialize the interrupt endpoint.
     98        usb_endpoint_pipe_initalize(
     99                &hub_data->endpoints->status_change,
     100                &endpiont_descriptor, &hub_data->connection);
     101
     102         */ /// \TODO add this call
    98103
    99104        if (opResult != EOK) {
     
    111116        dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count);
    112117        result->port_count = descriptor->ports_count;
    113         result->attached_devs = (usb_hub_attached_device_t*)
    114             malloc((result->port_count+1) * sizeof(usb_hub_attached_device_t));
     118        result->attached_devs = (usb_hc_attached_device_t*)
     119            malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t));
    115120        int i;
    116121        for(i=0;i<result->port_count+1;++i){
    117                 result->attached_devs[i].devman_handle=0;
     122                result->attached_devs[i].handle=0;
    118123                result->attached_devs[i].address=0;
    119124        }
     
    140145        dev->ops = &hub_device_ops;
    141146
    142         //create the hub structure
    143         //get hc connection
    144         int hc = usb_drv_hc_connect_auto(dev, 0);
    145         if (hc < 0) {
    146                 return hc;
    147         }
    148 
    149         usb_hub_info_t * hub_info = usb_create_hub_info(dev, hc);
     147
     148        usb_hub_info_t * hub_info = usb_create_hub_info(dev);
     149        usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
     150
    150151        int port;
    151152        int opResult;
    152         usb_target_t target;
    153         target.address = hub_info->address;
    154         target.endpoint = 0;
     153        //usb_target_t target;
     154        //target.address = hub_info->usb_device->address;
     155        //target.endpoint = 0;
    155156
    156157        //get configuration descriptor
     
    158159        // and all should be checked
    159160        usb_standard_device_descriptor_t std_descriptor;
    160         opResult = usb_drv_req_get_device_descriptor(hc, target.address,
     161        opResult = usb_request_get_device_descriptor(&hub_info->endpoints.control,
    161162            &std_descriptor);
    162163        if(opResult!=EOK){
     
    171172        /// \TODO check other configurations
    172173        usb_standard_configuration_descriptor_t config_descriptor;
    173         opResult = usb_drv_req_get_bare_configuration_descriptor(hc,
    174         target.address, 0,
     174        opResult = usb_request_get_bare_configuration_descriptor(
     175            &hub_info->endpoints.control, 0,
    175176        &config_descriptor);
    176177        if(opResult!=EOK){
     
    179180        }
    180181        //set configuration
    181         opResult = usb_drv_req_set_configuration(hc, target.address,
     182        opResult = usb_request_set_configuration(&hub_info->endpoints.control,
    182183    config_descriptor.configuration_number);
    183184
     
    189190        for (port = 1; port < hub_info->port_count+1; ++port) {
    190191                usb_hub_set_power_port_request(&request, port);
    191                 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
     192                opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,
     193                                &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);
    192194                dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port);
    193195                if (opResult != EOK) {
     
    197199        //ports powered, hub seems to be enabled
    198200
    199         async_hangup(hc);
     201        usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
     202        //async_hangup(hc);
    200203
    201204        //add the hub to list
     
    211214
    212215        dprintf(USB_LOG_LEVEL_INFO, "hub dev added");
     216        //address is lost...
    213217        dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ",
    214                         hub_info->address,
     218                        //hub_info->endpoints.control.,
    215219                        hub_info->port_count);
    216220        dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number);
     
    249253 * @param target
    250254 */
    251 static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) {
     255static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) {
    252256        usb_device_request_setup_packet_t request;
    253257        int opResult;
    254258        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
     259        assert(hub->endpoints.control.hc_phone);
    255260        //get default address
    256         opResult = usb_drv_reserve_default_address(hc);
     261        //opResult = usb_drv_reserve_default_address(hc);
     262        opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW);
     263
    257264        if (opResult != EOK) {
    258265                dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used");
     
    261268        //reset port
    262269        usb_hub_set_reset_port_request(&request, port);
    263         opResult = usb_drv_sync_control_write(
    264                         hc, target,
    265                         &request,
     270        opResult = usb_endpoint_pipe_control_write(
     271                        &hub->endpoints.control,
     272                        &request,sizeof(usb_device_request_setup_packet_t),
    266273                        NULL, 0
    267274                        );
    268275        if (opResult != EOK) {
    269276                dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port");
    270                 usb_hub_release_default_address(hc);
     277                //usb_hub_release_default_address(hc);
     278                usb_hc_release_default_address(&hub->connection);
    271279        }
    272280}
     
    279287 */
    280288static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
    281                 int hc, uint16_t port, usb_target_t target) {
     289                uint16_t port) {
    282290
    283291        int opResult;
    284292        dprintf(USB_LOG_LEVEL_INFO, "finalizing add device");
    285         opResult = usb_hub_clear_port_feature(hc, target.address,
     293        opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
    286294            port, USB_HUB_FEATURE_C_PORT_RESET);
     295
    287296        if (opResult != EOK) {
    288297                dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature");
    289                 usb_hub_release_default_address(hc);
    290                 return;
    291         }
    292 
    293         /* Request address at from host controller. */
    294         usb_address_t new_device_address = usb_drv_request_address(hc);
     298                usb_hc_release_default_address(&hub->connection);
     299                return;
     300        }
     301        //create connection to device
     302        usb_endpoint_pipe_t new_device_pipe;
     303        usb_device_connection_t new_device_connection;
     304        usb_device_connection_initialize_on_default_address(
     305                        &new_device_connection,
     306                        &hub->connection
     307                        );
     308        usb_endpoint_pipe_initialize_default_control(
     309                        &new_device_pipe,
     310                        &new_device_connection);
     311        /// \TODO get highspeed info
     312
     313
     314
     315
     316
     317        /* Request address from host controller. */
     318        usb_address_t new_device_address = usb_hc_request_address(
     319                        &hub->connection,
     320                        USB_SPEED_LOW/// \TODO fullspeed??
     321                        );
    295322        if (new_device_address < 0) {
    296323                dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address");
    297324                opResult = new_device_address;
    298                 usb_hub_release_default_address(hc);
     325                usb_hc_release_default_address(&hub->connection);
    299326                return;
    300327        }
    301328        dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address);
    302         opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    303             new_device_address);
     329        //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
     330        //    new_device_address);
     331        opResult = usb_request_set_address(&new_device_pipe,new_device_address);
    304332
    305333        if (opResult != EOK) {
    306334                dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device");
    307                 usb_hub_release_default_address(hc);
    308                 return;
    309         }
    310 
    311 
    312         opResult = usb_hub_release_default_address(hc);
     335                usb_hc_release_default_address(&hub->connection);
     336                return;
     337        }
     338
     339
     340        //opResult = usb_hub_release_default_address(hc);
     341        opResult = usb_hc_release_default_address(&hub->connection);
    313342        if(opResult!=EOK){
    314343                return;
    315344        }
    316345
    317         devman_handle_t hc_handle;
    318         opResult = usb_drv_find_hc(hub->device, &hc_handle);
    319         if (opResult != EOK) {
    320                 usb_log_error("Failed to get handle of host controller: %s.\n",
    321                     str_error(opResult));
    322                 return;
    323         }
    324 
    325346        devman_handle_t child_handle;
    326         opResult = usb_device_register_child_in_devman(new_device_address,
    327             hc_handle, hub->device, &child_handle);
     347        //??
     348    opResult = usb_device_register_child_in_devman(new_device_address,
     349            hub->connection.hc_handle, hub->device, &child_handle);
     350
    328351        if (opResult != EOK) {
    329352                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
    330353                return;
    331354        }
    332         hub->attached_devs[port].devman_handle = child_handle;
     355        hub->attached_devs[port].handle = child_handle;
    333356        hub->attached_devs[port].address = new_device_address;
    334357
    335         opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
     358        //opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
     359        opResult = usb_hc_register_device(
     360                        &hub->connection,
     361                        &hub->attached_devs[port]);
    336362        if (opResult != EOK) {
    337363                dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd");
     
    350376 */
    351377static void usb_hub_removed_device(
    352     usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {
     378    usb_hub_info_t * hub,uint16_t port) {
    353379        //usb_device_request_setup_packet_t request;
    354380        int opResult;
     
    357383         * devide manager
    358384         */
    359 
    360         hub->attached_devs[port].devman_handle=0;
     385       
    361386        //close address
    362387        if(hub->attached_devs[port].address!=0){
    363                 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
     388                //opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
     389                opResult = usb_hc_unregister_device(
     390                                &hub->connection, hub->attached_devs[port].address);
    364391                if(opResult != EOK) {
    365392                        dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \
     
    367394                }
    368395                hub->attached_devs[port].address = 0;
     396                hub->attached_devs[port].handle = 0;
    369397        }else{
    370398                dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address");
    371399                //device was disconnected before it`s port was reset - return default address
    372                 usb_drv_release_default_address(hc);
     400                //usb_drv_release_default_address(hc);
     401                usb_hc_release_default_address(&hub->connection);
    373402        }
    374403}
     
    380409 * @param target
    381410 */
    382 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,
    383         uint16_t port, usb_address_t address) {
     411static void usb_hub_process_interrupt(usb_hub_info_t * hub,
     412        uint16_t port) {
    384413        dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);
    385414        //determine type of change
     415        usb_endpoint_pipe_t *pipe = &hub->endpoints.control;
     416        int opResult = usb_endpoint_pipe_start_session(pipe);
     417       
     418        if(opResult != EOK){
     419                dprintf(USB_LOG_LEVEL_ERROR, "cannot open pipe %d", opResult);
     420        }
     421
     422        /*
    386423        usb_target_t target;
    387424        target.address=address;
    388425        target.endpoint=0;
     426        */
     427
    389428        usb_port_status_t status;
    390429        size_t rcvd_size;
    391430        usb_device_request_setup_packet_t request;
    392         int opResult;
     431        //int opResult;
    393432        usb_hub_set_port_status_request(&request, port);
    394433        //endpoint 0
    395434
    396         opResult = usb_drv_sync_control_read(
    397                         hc, target,
    398                         &request,
     435        opResult = usb_endpoint_pipe_control_read(
     436                        pipe,
     437                        &request, sizeof(usb_device_request_setup_packet_t),
    399438                        &status, 4, &rcvd_size
    400439                        );
     
    409448        //something connected/disconnected
    410449        if (usb_port_connect_change(&status)) {
    411                 opResult = usb_hub_clear_port_feature(hc, target.address,
     450                opResult = usb_hub_clear_port_feature(pipe,
    412451                    port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    413452                // TODO: check opResult
    414453                if (usb_port_dev_connected(&status)) {
    415454                        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    416                         usb_hub_init_add_device(hc, port, target);
     455                        usb_hub_init_add_device(hub, port);
    417456                } else {
    418                         usb_hub_removed_device(hub, hc, port, target);
     457                        usb_hub_removed_device(hub, port);
    419458                }
    420459        }
     
    423462                dprintf(USB_LOG_LEVEL_INFO, "port reset complete");
    424463                if (usb_port_enabled(&status)) {
    425                         usb_hub_finalize_add_device(hub, hc, port, target);
     464                        usb_hub_finalize_add_device(hub, port);
    426465                } else {
    427466                        dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled");
     
    439478        /// \TODO handle other changes
    440479        /// \TODO debug log for various situations
     480        usb_endpoint_pipe_end_session(pipe);
     481
    441482
    442483}
     
    456497                fibril_mutex_unlock(&usb_hub_list_lock);
    457498                usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data);
     499                int opResult;
     500
     501                opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);
     502                if(opResult != EOK){
     503                        continue;
     504                }
    458505                /*
    459506                 * Check status change pipe of this hub.
    460507                 */
    461 
     508                /*
    462509                usb_target_t target;
    463510                target.address = hub_info->address;
     
    465512                dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d",
    466513                    target.address);
    467 
     514                */
    468515                size_t port_count = hub_info->port_count;
    469516
    470517                /*
    471518                 * Connect to respective HC.
    472                  */
     519                 *
    473520                int hc = usb_drv_hc_connect_auto(hub_info->device, 0);
    474521                if (hc < 0) {
    475522                        continue;
    476                 }
     523                }*/
    477524
    478525                /// FIXME: count properly
     
    481528                void *change_bitmap = malloc(byte_length);
    482529                size_t actual_size;
    483                 usb_handle_t handle;
     530                //usb_handle_t handle;
    484531
    485532                /*
    486533                 * Send the request.
    487534                 */
    488                 int opResult = usb_drv_async_interrupt_in(hc, target,
    489                                 change_bitmap, byte_length, &actual_size,
    490                                 &handle);
    491 
    492                 usb_drv_async_wait_for(handle);
     535                opResult = usb_endpoint_pipe_read(
     536                                &hub_info->endpoints.status_change,
     537                                change_bitmap, byte_length, &actual_size
     538                                );
     539
     540                //usb_drv_async_wait_for(handle);
    493541
    494542                if (opResult != EOK) {
     
    503551                        if (interrupt) {
    504552                                usb_hub_process_interrupt(
    505                                         hub_info, hc, port, hub_info->address);
     553                                        hub_info, port);
    506554                        }
    507555                }
     556                usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    508557                free(change_bitmap);
    509 
    510                 async_hangup(hc);
     558               
     559
     560                //async_hangup(hc);
    511561                fibril_mutex_lock(&usb_hub_list_lock);
    512562        }
  • uspace/drv/usbhub/usbhub.h

    r063ead6f rda7c0a9  
    4242#define NAME "usbhub"
    4343
    44 /** basic information about device attached to hub */
    45 typedef struct{
    46         usb_address_t address;
    47         devman_handle_t devman_handle;
    48 }usb_hub_attached_device_t;
     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. */
     51typedef struct {
     52        usb_endpoint_pipe_t control;
     53        usb_endpoint_pipe_t status_change;
     54} usb_hub_endpoints_t;
     55
     56
    4957
    5058/** Information about attached hub. */
     
    5260        /** Number of ports. */
    5361        int port_count;
    54         /** attached device handles */
    55         usb_hub_attached_device_t * attached_devs;
    56         /** USB address of the hub. */
    57         usb_address_t address;
     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;
    5866        /** General device info*/
    5967        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;
    6075} usb_hub_info_t;
    6176
  • uspace/drv/usbhub/usbhub_private.h

    r063ead6f rda7c0a9  
    4545#include <fibril_synch.h>
    4646
     47#include <usb/classes/hub.h>
    4748#include <usb/usb.h>
    4849#include <usb/usbdrv.h>
    49 #include <usb/classes/hub.h>
    50 #include <usb/devreq.h>
     50
     51//#include <usb/devreq.h>
    5152#include <usb/debug.h>
    5253
     
    7778 * @return
    7879 */
    79 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc);
     80usb_hub_info_t * usb_create_hub_info(device_t * device);
    8081
    8182/** List of hubs maanged by this driver */
     
    9899 * @return error code
    99100 */
     101/*
    100102int usb_drv_sync_control_read(
    101     int phone, usb_target_t target,
     103    usb_endpoint_pipe_t *pipe,
    102104    usb_device_request_setup_packet_t * request,
    103105    void * rcvd_buffer, size_t rcvd_size, size_t * actual_size
    104 );
     106);*/
    105107
    106108/**
     
    115117 * @return error code
    116118 */
    117 int usb_drv_sync_control_write(
    118     int phone, usb_target_t target,
     119/*int usb_drv_sync_control_write(
     120    usb_endpoint_pipe_t *pipe,
    119121    usb_device_request_setup_packet_t * request,
    120122    void * sent_buffer, size_t sent_size
    121 );
     123);*/
    122124
    123125/**
     
    147149 * @return Operation result
    148150 */
    149 static inline int usb_hub_clear_port_feature(int hc, usb_address_t address,
     151static inline int usb_hub_clear_port_feature(usb_endpoint_pipe_t *pipe,
    150152    int port_index,
    151153    usb_hub_class_feature_t feature) {
    152         usb_target_t target = {
    153                 .address = address,
    154                 .endpoint = 0
    155         };
     154       
    156155        usb_device_request_setup_packet_t clear_request = {
    157156                .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
     
    161160        };
    162161        clear_request.value = feature;
    163         return usb_drv_psync_control_write(hc, target, &clear_request,
     162        return usb_endpoint_pipe_control_write(pipe, &clear_request,
    164163            sizeof(clear_request), NULL, 0);
    165164}
  • uspace/drv/usbhub/utils.c

    r063ead6f rda7c0a9  
    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

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