Changes in / [da7c0a9:063ead6f] in mainline


Ignore:
Location:
uspace
Files:
5 edited

Legend:

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

    rda7c0a9 r063ead6f  
    4444#include <usb/recognise.h>
    4545#include <usb/devreq.h>
    46 #include <usb/request.h>
    4746#include <usb/classes/hub.h>
    4847
     
    5150#include "port_status.h"
    5251#include "usb/usb.h"
    53 #include "usb/pipes.h"
    5452
    5553static device_ops_t hub_device_ops = {
     
    6361//*********************************************
    6462
    65 usb_hub_info_t * usb_create_hub_info(device_t * device) {
     63usb_hub_info_t * usb_create_hub_info(device_t * device, int hc) {
    6664        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 
    7565        //result->device = device;
    7666        result->port_count = -1;
     
    7868        result->device = device;
    7969
    80         //result->usb_device = usb_new(usb_hcd_attached_device_info_t);
    81        
     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
    8285        // get hub descriptor
    8386
     
    8891        int opResult;
    8992        dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction");
    90         usb_endpoint_pipe_start_session(&result->endpoints.control);
    91         opResult = usb_request_get_descriptor(&result->endpoints.control,
     93       
     94        opResult = usb_drv_req_get_descriptor(hc, addr,
    9295                        USB_REQUEST_TYPE_CLASS,
    9396                        USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
    9497                        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
    10398
    10499        if (opResult != EOK) {
     
    116111        dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count);
    117112        result->port_count = descriptor->ports_count;
    118         result->attached_devs = (usb_hc_attached_device_t*)
    119             malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t));
     113        result->attached_devs = (usb_hub_attached_device_t*)
     114            malloc((result->port_count+1) * sizeof(usb_hub_attached_device_t));
    120115        int i;
    121116        for(i=0;i<result->port_count+1;++i){
    122                 result->attached_devs[i].handle=0;
     117                result->attached_devs[i].devman_handle=0;
    123118                result->attached_devs[i].address=0;
    124119        }
     
    145140        dev->ops = &hub_device_ops;
    146141
    147 
    148         usb_hub_info_t * hub_info = usb_create_hub_info(dev);
    149         usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
    150 
     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);
    151150        int port;
    152151        int opResult;
    153         //usb_target_t target;
    154         //target.address = hub_info->usb_device->address;
    155         //target.endpoint = 0;
     152        usb_target_t target;
     153        target.address = hub_info->address;
     154        target.endpoint = 0;
    156155
    157156        //get configuration descriptor
     
    159158        // and all should be checked
    160159        usb_standard_device_descriptor_t std_descriptor;
    161         opResult = usb_request_get_device_descriptor(&hub_info->endpoints.control,
     160        opResult = usb_drv_req_get_device_descriptor(hc, target.address,
    162161            &std_descriptor);
    163162        if(opResult!=EOK){
     
    172171        /// \TODO check other configurations
    173172        usb_standard_configuration_descriptor_t config_descriptor;
    174         opResult = usb_request_get_bare_configuration_descriptor(
    175             &hub_info->endpoints.control, 0,
     173        opResult = usb_drv_req_get_bare_configuration_descriptor(hc,
     174        target.address, 0,
    176175        &config_descriptor);
    177176        if(opResult!=EOK){
     
    180179        }
    181180        //set configuration
    182         opResult = usb_request_set_configuration(&hub_info->endpoints.control,
     181        opResult = usb_drv_req_set_configuration(hc, target.address,
    183182    config_descriptor.configuration_number);
    184183
     
    190189        for (port = 1; port < hub_info->port_count+1; ++port) {
    191190                usb_hub_set_power_port_request(&request, port);
    192                 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,
    193                                 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);
     191                opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
    194192                dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port);
    195193                if (opResult != EOK) {
     
    199197        //ports powered, hub seems to be enabled
    200198
    201         usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
    202         //async_hangup(hc);
     199        async_hangup(hc);
    203200
    204201        //add the hub to list
     
    214211
    215212        dprintf(USB_LOG_LEVEL_INFO, "hub dev added");
    216         //address is lost...
    217213        dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ",
    218                         //hub_info->endpoints.control.,
     214                        hub_info->address,
    219215                        hub_info->port_count);
    220216        dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number);
     
    253249 * @param target
    254250 */
    255 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) {
     251static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) {
    256252        usb_device_request_setup_packet_t request;
    257253        int opResult;
    258254        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    259         assert(hub->endpoints.control.hc_phone);
    260255        //get default address
    261         //opResult = usb_drv_reserve_default_address(hc);
    262         opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW);
    263 
     256        opResult = usb_drv_reserve_default_address(hc);
    264257        if (opResult != EOK) {
    265258                dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used");
     
    268261        //reset port
    269262        usb_hub_set_reset_port_request(&request, port);
    270         opResult = usb_endpoint_pipe_control_write(
    271                         &hub->endpoints.control,
    272                         &request,sizeof(usb_device_request_setup_packet_t),
     263        opResult = usb_drv_sync_control_write(
     264                        hc, target,
     265                        &request,
    273266                        NULL, 0
    274267                        );
    275268        if (opResult != EOK) {
    276269                dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port");
    277                 //usb_hub_release_default_address(hc);
    278                 usb_hc_release_default_address(&hub->connection);
     270                usb_hub_release_default_address(hc);
    279271        }
    280272}
     
    287279 */
    288280static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
    289                 uint16_t port) {
     281                int hc, uint16_t port, usb_target_t target) {
    290282
    291283        int opResult;
    292284        dprintf(USB_LOG_LEVEL_INFO, "finalizing add device");
    293         opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
     285        opResult = usb_hub_clear_port_feature(hc, target.address,
    294286            port, USB_HUB_FEATURE_C_PORT_RESET);
    295 
    296287        if (opResult != EOK) {
    297288                dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature");
    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                         );
     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);
    322295        if (new_device_address < 0) {
    323296                dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address");
    324297                opResult = new_device_address;
    325                 usb_hc_release_default_address(&hub->connection);
     298                usb_hub_release_default_address(hc);
    326299                return;
    327300        }
    328301        dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",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);
     302        opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
     303            new_device_address);
    332304
    333305        if (opResult != EOK) {
    334306                dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device");
    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);
     307                usb_hub_release_default_address(hc);
     308                return;
     309        }
     310
     311
     312        opResult = usb_hub_release_default_address(hc);
    342313        if(opResult!=EOK){
    343314                return;
    344315        }
    345316
     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
    346325        devman_handle_t child_handle;
    347         //??
    348     opResult = usb_device_register_child_in_devman(new_device_address,
    349             hub->connection.hc_handle, hub->device, &child_handle);
    350 
     326        opResult = usb_device_register_child_in_devman(new_device_address,
     327            hc_handle, hub->device, &child_handle);
    351328        if (opResult != EOK) {
    352329                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
    353330                return;
    354331        }
    355         hub->attached_devs[port].handle = child_handle;
     332        hub->attached_devs[port].devman_handle = child_handle;
    356333        hub->attached_devs[port].address = new_device_address;
    357334
    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]);
     335        opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
    362336        if (opResult != EOK) {
    363337                dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd");
     
    376350 */
    377351static void usb_hub_removed_device(
    378     usb_hub_info_t * hub,uint16_t port) {
     352    usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {
    379353        //usb_device_request_setup_packet_t request;
    380354        int opResult;
     
    383357         * devide manager
    384358         */
    385        
     359
     360        hub->attached_devs[port].devman_handle=0;
    386361        //close address
    387362        if(hub->attached_devs[port].address!=0){
    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);
     363                opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
    391364                if(opResult != EOK) {
    392365                        dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \
     
    394367                }
    395368                hub->attached_devs[port].address = 0;
    396                 hub->attached_devs[port].handle = 0;
    397369        }else{
    398370                dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address");
    399371                //device was disconnected before it`s port was reset - return default address
    400                 //usb_drv_release_default_address(hc);
    401                 usb_hc_release_default_address(&hub->connection);
     372                usb_drv_release_default_address(hc);
    402373        }
    403374}
     
    409380 * @param target
    410381 */
    411 static void usb_hub_process_interrupt(usb_hub_info_t * hub,
    412         uint16_t port) {
     382static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,
     383        uint16_t port, usb_address_t address) {
    413384        dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);
    414385        //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         /*
    423386        usb_target_t target;
    424387        target.address=address;
    425388        target.endpoint=0;
    426         */
    427 
    428389        usb_port_status_t status;
    429390        size_t rcvd_size;
    430391        usb_device_request_setup_packet_t request;
    431         //int opResult;
     392        int opResult;
    432393        usb_hub_set_port_status_request(&request, port);
    433394        //endpoint 0
    434395
    435         opResult = usb_endpoint_pipe_control_read(
    436                         pipe,
    437                         &request, sizeof(usb_device_request_setup_packet_t),
     396        opResult = usb_drv_sync_control_read(
     397                        hc, target,
     398                        &request,
    438399                        &status, 4, &rcvd_size
    439400                        );
     
    448409        //something connected/disconnected
    449410        if (usb_port_connect_change(&status)) {
    450                 opResult = usb_hub_clear_port_feature(pipe,
     411                opResult = usb_hub_clear_port_feature(hc, target.address,
    451412                    port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    452413                // TODO: check opResult
    453414                if (usb_port_dev_connected(&status)) {
    454415                        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    455                         usb_hub_init_add_device(hub, port);
     416                        usb_hub_init_add_device(hc, port, target);
    456417                } else {
    457                         usb_hub_removed_device(hub, port);
     418                        usb_hub_removed_device(hub, hc, port, target);
    458419                }
    459420        }
     
    462423                dprintf(USB_LOG_LEVEL_INFO, "port reset complete");
    463424                if (usb_port_enabled(&status)) {
    464                         usb_hub_finalize_add_device(hub, port);
     425                        usb_hub_finalize_add_device(hub, hc, port, target);
    465426                } else {
    466427                        dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled");
     
    478439        /// \TODO handle other changes
    479440        /// \TODO debug log for various situations
    480         usb_endpoint_pipe_end_session(pipe);
    481 
    482441
    483442}
     
    497456                fibril_mutex_unlock(&usb_hub_list_lock);
    498457                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                 }
    505458                /*
    506459                 * Check status change pipe of this hub.
    507460                 */
    508                 /*
     461
    509462                usb_target_t target;
    510463                target.address = hub_info->address;
     
    512465                dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d",
    513466                    target.address);
    514                 */
     467
    515468                size_t port_count = hub_info->port_count;
    516469
    517470                /*
    518471                 * Connect to respective HC.
    519                  *
     472                 */
    520473                int hc = usb_drv_hc_connect_auto(hub_info->device, 0);
    521474                if (hc < 0) {
    522475                        continue;
    523                 }*/
     476                }
    524477
    525478                /// FIXME: count properly
     
    528481                void *change_bitmap = malloc(byte_length);
    529482                size_t actual_size;
    530                 //usb_handle_t handle;
     483                usb_handle_t handle;
    531484
    532485                /*
    533486                 * Send the request.
    534487                 */
    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);
     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);
    541493
    542494                if (opResult != EOK) {
     
    551503                        if (interrupt) {
    552504                                usb_hub_process_interrupt(
    553                                         hub_info, port);
     505                                        hub_info, hc, port, hub_info->address);
    554506                        }
    555507                }
    556                 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    557508                free(change_bitmap);
    558                
    559 
    560                 //async_hangup(hc);
     509
     510                async_hangup(hc);
    561511                fibril_mutex_lock(&usb_hub_list_lock);
    562512        }
  • uspace/drv/usbhub/usbhub.h

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

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

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

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