Changeset 070f11e in mainline


Ignore:
Timestamp:
2011-02-20T21:55:21Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d37b235
Parents:
41e645c (diff), 6bb83c7 (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 /usb/smekideki: usb hub uses pipe API

Location:
uspace
Files:
5 edited

Legend:

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

    r41e645c r070f11e  
    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, false);
    257263        if (opResult != EOK) {
    258264                dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used");
     
    261267        //reset port
    262268        usb_hub_set_reset_port_request(&request, port);
    263         opResult = usb_drv_sync_control_write(
    264                         hc, target,
    265                         &request,
     269        opResult = usb_endpoint_pipe_control_write(
     270                        &hub->endpoints.control,
     271                        &request,sizeof(usb_device_request_setup_packet_t),
    266272                        NULL, 0
    267273                        );
    268274        if (opResult != EOK) {
    269275                dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port");
    270                 usb_hub_release_default_address(hc);
     276                //usb_hub_release_default_address(hc);
     277                usb_hc_release_default_address(&hub->connection);
    271278        }
    272279}
     
    279286 */
    280287static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
    281                 int hc, uint16_t port, usb_target_t target) {
     288                uint16_t port) {
    282289
    283290        int opResult;
    284291        dprintf(USB_LOG_LEVEL_INFO, "finalizing add device");
    285         opResult = usb_hub_clear_port_feature(hc, target.address,
     292        opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
    286293            port, USB_HUB_FEATURE_C_PORT_RESET);
     294
    287295        if (opResult != EOK) {
    288296                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);
     297                usb_hc_release_default_address(&hub->connection);
     298                return;
     299        }
     300        //create connection to device
     301        usb_endpoint_pipe_t new_device_pipe;
     302        usb_device_connection_t new_device_connection;
     303        usb_device_connection_initialize_on_default_address(
     304                        &new_device_connection,
     305                        &hub->connection
     306                        );
     307        usb_endpoint_pipe_initialize_default_control(
     308                        &new_device_pipe,
     309                        &new_device_connection);
     310        /// \TODO get highspeed info
     311
     312
     313
     314
     315
     316        /* Request address from host controller. */
     317        usb_address_t new_device_address = usb_hc_request_address(
     318                        &hub->connection,
     319                        false/// \TODO fullspeed??
     320                        );
    295321        if (new_device_address < 0) {
    296322                dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address");
    297323                opResult = new_device_address;
    298                 usb_hub_release_default_address(hc);
     324                usb_hc_release_default_address(&hub->connection);
    299325                return;
    300326        }
    301327        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);
     328        //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
     329        //    new_device_address);
     330        opResult = usb_request_set_address(&new_device_pipe,new_device_address);
    304331
    305332        if (opResult != EOK) {
    306333                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);
     334                usb_hc_release_default_address(&hub->connection);
     335                return;
     336        }
     337
     338
     339        //opResult = usb_hub_release_default_address(hc);
     340        opResult = usb_hc_release_default_address(&hub->connection);
    313341        if(opResult!=EOK){
    314342                return;
    315343        }
    316344
    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 
    325345        devman_handle_t child_handle;
    326         opResult = usb_device_register_child_in_devman(new_device_address,
    327             hc_handle, hub->device, &child_handle);
     346        //??
     347    opResult = usb_device_register_child_in_devman(new_device_address,
     348            hub->connection.hc_handle, hub->device, &child_handle);
     349
    328350        if (opResult != EOK) {
    329351                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
    330352                return;
    331353        }
    332         hub->attached_devs[port].devman_handle = child_handle;
     354        hub->attached_devs[port].handle = child_handle;
    333355        hub->attached_devs[port].address = new_device_address;
    334356
    335         opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
     357        //opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
     358        opResult = usb_hc_register_device(
     359                        &hub->connection,
     360                        &hub->attached_devs[port]);
    336361        if (opResult != EOK) {
    337362                dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd");
     
    350375 */
    351376static void usb_hub_removed_device(
    352     usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {
     377    usb_hub_info_t * hub,uint16_t port) {
    353378        //usb_device_request_setup_packet_t request;
    354379        int opResult;
     
    357382         * devide manager
    358383         */
    359 
    360         hub->attached_devs[port].devman_handle=0;
     384       
    361385        //close address
    362386        if(hub->attached_devs[port].address!=0){
    363                 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
     387                //opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
     388                opResult = usb_hc_unregister_device(
     389                                &hub->connection, hub->attached_devs[port].address);
    364390                if(opResult != EOK) {
    365391                        dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \
     
    367393                }
    368394                hub->attached_devs[port].address = 0;
     395                hub->attached_devs[port].handle = 0;
    369396        }else{
    370397                dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address");
    371398                //device was disconnected before it`s port was reset - return default address
    372                 usb_drv_release_default_address(hc);
     399                //usb_drv_release_default_address(hc);
     400                usb_hc_release_default_address(&hub->connection);
    373401        }
    374402}
     
    380408 * @param target
    381409 */
    382 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,
    383         uint16_t port, usb_address_t address) {
     410static void usb_hub_process_interrupt(usb_hub_info_t * hub,
     411        uint16_t port) {
    384412        dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);
    385413        //determine type of change
     414        usb_endpoint_pipe_t *pipe = &hub->endpoints.control;
     415        int opResult = usb_endpoint_pipe_start_session(pipe);
     416       
     417        if(opResult != EOK){
     418                dprintf(USB_LOG_LEVEL_ERROR, "cannot open pipe %d", opResult);
     419        }
     420
     421        /*
    386422        usb_target_t target;
    387423        target.address=address;
    388424        target.endpoint=0;
     425        */
     426
    389427        usb_port_status_t status;
    390428        size_t rcvd_size;
    391429        usb_device_request_setup_packet_t request;
    392         int opResult;
     430        //int opResult;
    393431        usb_hub_set_port_status_request(&request, port);
    394432        //endpoint 0
    395433
    396         opResult = usb_drv_sync_control_read(
    397                         hc, target,
    398                         &request,
     434        opResult = usb_endpoint_pipe_control_read(
     435                        pipe,
     436                        &request, sizeof(usb_device_request_setup_packet_t),
    399437                        &status, 4, &rcvd_size
    400438                        );
     
    409447        //something connected/disconnected
    410448        if (usb_port_connect_change(&status)) {
    411                 opResult = usb_hub_clear_port_feature(hc, target.address,
     449                opResult = usb_hub_clear_port_feature(pipe,
    412450                    port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    413451                // TODO: check opResult
    414452                if (usb_port_dev_connected(&status)) {
    415453                        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    416                         usb_hub_init_add_device(hc, port, target);
     454                        usb_hub_init_add_device(hub, port);
    417455                } else {
    418                         usb_hub_removed_device(hub, hc, port, target);
     456                        usb_hub_removed_device(hub, port);
    419457                }
    420458        }
     
    423461                dprintf(USB_LOG_LEVEL_INFO, "port reset complete");
    424462                if (usb_port_enabled(&status)) {
    425                         usb_hub_finalize_add_device(hub, hc, port, target);
     463                        usb_hub_finalize_add_device(hub, port);
    426464                } else {
    427465                        dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled");
     
    439477        /// \TODO handle other changes
    440478        /// \TODO debug log for various situations
     479        usb_endpoint_pipe_end_session(pipe);
     480
    441481
    442482}
     
    456496                fibril_mutex_unlock(&usb_hub_list_lock);
    457497                usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data);
     498                int opResult;
     499
     500                opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);
     501                if(opResult != EOK){
     502                        continue;
     503                }
    458504                /*
    459505                 * Check status change pipe of this hub.
    460506                 */
    461 
     507                /*
    462508                usb_target_t target;
    463509                target.address = hub_info->address;
     
    465511                dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d",
    466512                    target.address);
    467 
     513                */
    468514                size_t port_count = hub_info->port_count;
    469515
    470516                /*
    471517                 * Connect to respective HC.
    472                  */
     518                 *
    473519                int hc = usb_drv_hc_connect_auto(hub_info->device, 0);
    474520                if (hc < 0) {
    475521                        continue;
    476                 }
     522                }*/
    477523
    478524                /// FIXME: count properly
     
    481527                void *change_bitmap = malloc(byte_length);
    482528                size_t actual_size;
    483                 usb_handle_t handle;
     529                //usb_handle_t handle;
    484530
    485531                /*
    486532                 * Send the request.
    487533                 */
    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);
     534                opResult = usb_endpoint_pipe_read(
     535                                &hub_info->endpoints.status_change,
     536                                change_bitmap, byte_length, &actual_size
     537                                );
     538
     539                //usb_drv_async_wait_for(handle);
    493540
    494541                if (opResult != EOK) {
     
    503550                        if (interrupt) {
    504551                                usb_hub_process_interrupt(
    505                                         hub_info, hc, port, hub_info->address);
     552                                        hub_info, port);
    506553                        }
    507554                }
     555                usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    508556                free(change_bitmap);
    509 
    510                 async_hangup(hc);
     557               
     558
     559                //async_hangup(hc);
    511560                fibril_mutex_lock(&usb_hub_list_lock);
    512561        }
  • uspace/drv/usbhub/usbhub.h

    r41e645c r070f11e  
    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

    r41e645c r070f11e  
    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

    r41e645c r070f11e  
    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

    r41e645c r070f11e  
    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.