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


Ignore:
Location:
uspace
Files:
5 edited

Legend:

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

    r423e8c81 r62066b4  
    4343#include <usb/recognise.h>
    4444#include <usb/devreq.h>
     45#include <usb/request.h>
    4546#include <usb/classes/hub.h>
    4647
     
    4950#include "port_status.h"
    5051#include "usb/usb.h"
     52#include "usb/pipes.h"
    5153
    5254static int iface_get_hc_handle(device_t *device, devman_handle_t *handle)
     
    6971//*********************************************
    7072
    71 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc) {
     73usb_hub_info_t * usb_create_hub_info(device_t * device) {
    7274        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
    7383        //result->device = device;
    7484        result->port_count = -1;
     
    7686        result->device = device;
    7787
    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 
     88        //result->usb_device = usb_new(usb_hcd_attached_device_info_t);
     89       
    9390        // get hub descriptor
    9491
     
    9996        int opResult;
    10097        dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction");
    101        
    102         opResult = usb_drv_req_get_descriptor(hc, addr,
     98        usb_endpoint_pipe_start_session(&result->endpoints.control);
     99        opResult = usb_request_get_descriptor(&result->endpoints.control,
    103100                        USB_REQUEST_TYPE_CLASS,
    104101                        USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
    105102                        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
    106111
    107112        if (opResult != EOK) {
     
    119124        dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count);
    120125        result->port_count = descriptor->ports_count;
    121         result->attached_devs = (usb_hub_attached_device_t*)
    122             malloc((result->port_count+1) * sizeof(usb_hub_attached_device_t));
     126        result->attached_devs = (usb_hc_attached_device_t*)
     127            malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t));
    123128        int i;
    124129        for(i=0;i<result->port_count+1;++i){
    125                 result->attached_devs[i].devman_handle=0;
     130                result->attached_devs[i].handle=0;
    126131                result->attached_devs[i].address=0;
    127132        }
     
    148153        dev->ops = &hub_device_ops;
    149154
    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);
     155
     156        usb_hub_info_t * hub_info = usb_create_hub_info(dev);
     157        usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
     158
    158159        int port;
    159160        int opResult;
    160         usb_target_t target;
    161         target.address = hub_info->address;
    162         target.endpoint = 0;
     161        //usb_target_t target;
     162        //target.address = hub_info->usb_device->address;
     163        //target.endpoint = 0;
    163164
    164165        //get configuration descriptor
     
    166167        // and all should be checked
    167168        usb_standard_device_descriptor_t std_descriptor;
    168         opResult = usb_drv_req_get_device_descriptor(hc, target.address,
     169        opResult = usb_request_get_device_descriptor(&hub_info->endpoints.control,
    169170            &std_descriptor);
    170171        if(opResult!=EOK){
     
    179180        /// \TODO check other configurations
    180181        usb_standard_configuration_descriptor_t config_descriptor;
    181         opResult = usb_drv_req_get_bare_configuration_descriptor(hc,
    182         target.address, 0,
     182        opResult = usb_request_get_bare_configuration_descriptor(
     183            &hub_info->endpoints.control, 0,
    183184        &config_descriptor);
    184185        if(opResult!=EOK){
     
    187188        }
    188189        //set configuration
    189         opResult = usb_drv_req_set_configuration(hc, target.address,
     190        opResult = usb_request_set_configuration(&hub_info->endpoints.control,
    190191    config_descriptor.configuration_number);
    191192
     
    197198        for (port = 1; port < hub_info->port_count+1; ++port) {
    198199                usb_hub_set_power_port_request(&request, port);
    199                 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
     200                opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,
     201                                &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);
    200202                dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port);
    201203                if (opResult != EOK) {
     
    205207        //ports powered, hub seems to be enabled
    206208
    207         async_hangup(hc);
     209        usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
     210        //async_hangup(hc);
    208211
    209212        //add the hub to list
     
    219222
    220223        dprintf(USB_LOG_LEVEL_INFO, "hub dev added");
     224        //address is lost...
    221225        dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ",
    222                         hub_info->address,
     226                        //hub_info->endpoints.control.,
    223227                        hub_info->port_count);
    224228        dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number);
     
    257261 * @param target
    258262 */
    259 static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) {
     263static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) {
    260264        usb_device_request_setup_packet_t request;
    261265        int opResult;
    262266        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
     267        assert(hub->endpoints.control.hc_phone);
    263268        //get default address
    264         opResult = usb_drv_reserve_default_address(hc);
     269        //opResult = usb_drv_reserve_default_address(hc);
     270        opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW);
    265271        if (opResult != EOK) {
    266272                dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used");
     
    269275        //reset port
    270276        usb_hub_set_reset_port_request(&request, port);
    271         opResult = usb_drv_sync_control_write(
    272                         hc, target,
    273                         &request,
     277        opResult = usb_endpoint_pipe_control_write(
     278                        &hub->endpoints.control,
     279                        &request,sizeof(usb_device_request_setup_packet_t),
    274280                        NULL, 0
    275281                        );
    276282        if (opResult != EOK) {
    277283                dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port");
    278                 usb_hub_release_default_address(hc);
     284                //usb_hub_release_default_address(hc);
     285                usb_hc_release_default_address(&hub->connection);
    279286        }
    280287}
     
    287294 */
    288295static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
    289                 int hc, uint16_t port, usb_target_t target) {
     296                uint16_t port) {
    290297
    291298        int opResult;
    292299        dprintf(USB_LOG_LEVEL_INFO, "finalizing add device");
    293         opResult = usb_hub_clear_port_feature(hc, target.address,
     300        opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
    294301            port, USB_HUB_FEATURE_C_PORT_RESET);
     302
    295303        if (opResult != EOK) {
    296304                dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature");
    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);
     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                        );
    303329        if (new_device_address < 0) {
    304330                dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address");
    305331                opResult = new_device_address;
    306                 usb_hub_release_default_address(hc);
     332                usb_hc_release_default_address(&hub->connection);
    307333                return;
    308334        }
    309335        dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address);
    310         opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    311             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);
    312339
    313340        if (opResult != EOK) {
    314341                dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device");
    315                 usb_hub_release_default_address(hc);
    316                 return;
    317         }
    318 
    319 
    320         opResult = usb_hub_release_default_address(hc);
     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);
    321349        if(opResult!=EOK){
    322350                return;
    323351        }
    324352
    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 
    333353        devman_handle_t child_handle;
    334         opResult = usb_device_register_child_in_devman(new_device_address,
    335             hc_handle, hub->device, &child_handle);
     354        //??
     355    opResult = usb_device_register_child_in_devman(new_device_address,
     356            hub->connection.hc_handle, hub->device, &child_handle);
     357
    336358        if (opResult != EOK) {
    337359                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
    338360                return;
    339361        }
    340         hub->attached_devs[port].devman_handle = child_handle;
     362        hub->attached_devs[port].handle = child_handle;
    341363        hub->attached_devs[port].address = new_device_address;
    342364
    343         opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
     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]);
    344369        if (opResult != EOK) {
    345370                dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd");
     
    358383 */
    359384static void usb_hub_removed_device(
    360     usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {
     385    usb_hub_info_t * hub,uint16_t port) {
    361386        //usb_device_request_setup_packet_t request;
    362387        int opResult;
     
    365390         * devide manager
    366391         */
    367 
    368         hub->attached_devs[port].devman_handle=0;
     392       
    369393        //close address
    370394        if(hub->attached_devs[port].address!=0){
    371                 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
     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);
    372398                if(opResult != EOK) {
    373399                        dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \
     
    375401                }
    376402                hub->attached_devs[port].address = 0;
     403                hub->attached_devs[port].handle = 0;
    377404        }else{
    378405                dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address");
    379406                //device was disconnected before it`s port was reset - return default address
    380                 usb_drv_release_default_address(hc);
     407                //usb_drv_release_default_address(hc);
     408                usb_hc_release_default_address(&hub->connection);
    381409        }
    382410}
     
    388416 * @param target
    389417 */
    390 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,
    391         uint16_t port, usb_address_t address) {
     418static void usb_hub_process_interrupt(usb_hub_info_t * hub,
     419        uint16_t port) {
    392420        dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);
    393421        //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        /*
    394430        usb_target_t target;
    395431        target.address=address;
    396432        target.endpoint=0;
     433        */
     434
    397435        usb_port_status_t status;
    398436        size_t rcvd_size;
    399437        usb_device_request_setup_packet_t request;
    400         int opResult;
     438        //int opResult;
    401439        usb_hub_set_port_status_request(&request, port);
    402440        //endpoint 0
    403441
    404         opResult = usb_drv_sync_control_read(
    405                         hc, target,
    406                         &request,
     442        opResult = usb_endpoint_pipe_control_read(
     443                        pipe,
     444                        &request, sizeof(usb_device_request_setup_packet_t),
    407445                        &status, 4, &rcvd_size
    408446                        );
     
    417455        //something connected/disconnected
    418456        if (usb_port_connect_change(&status)) {
    419                 opResult = usb_hub_clear_port_feature(hc, target.address,
     457                opResult = usb_hub_clear_port_feature(pipe,
    420458                    port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    421459                // TODO: check opResult
    422460                if (usb_port_dev_connected(&status)) {
    423461                        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    424                         usb_hub_init_add_device(hc, port, target);
     462                        usb_hub_init_add_device(hub, port);
    425463                } else {
    426                         usb_hub_removed_device(hub, hc, port, target);
     464                        usb_hub_removed_device(hub, port);
    427465                }
    428466        }
     
    431469                dprintf(USB_LOG_LEVEL_INFO, "port reset complete");
    432470                if (usb_port_enabled(&status)) {
    433                         usb_hub_finalize_add_device(hub, hc, port, target);
     471                        usb_hub_finalize_add_device(hub, port);
    434472                } else {
    435473                        dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled");
     
    447485        /// \TODO handle other changes
    448486        /// \TODO debug log for various situations
     487        usb_endpoint_pipe_end_session(pipe);
     488
    449489
    450490}
     
    464504                fibril_mutex_unlock(&usb_hub_list_lock);
    465505                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                }
    466512                /*
    467513                 * Check status change pipe of this hub.
    468514                 */
    469 
     515                /*
    470516                usb_target_t target;
    471517                target.address = hub_info->address;
     
    473519                dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d",
    474520                    target.address);
    475 
     521                */
    476522                size_t port_count = hub_info->port_count;
    477523
    478524                /*
    479525                 * Connect to respective HC.
    480                  */
     526                 *
    481527                int hc = usb_drv_hc_connect_auto(hub_info->device, 0);
    482528                if (hc < 0) {
    483529                        continue;
    484                 }
     530                }*/
    485531
    486532                /// FIXME: count properly
     
    489535                void *change_bitmap = malloc(byte_length);
    490536                size_t actual_size;
    491                 usb_handle_t handle;
     537                //usb_handle_t handle;
    492538
    493539                /*
    494540                 * Send the request.
    495541                 */
    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);
     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);
    501548
    502549                if (opResult != EOK) {
     
    511558                        if (interrupt) {
    512559                                usb_hub_process_interrupt(
    513                                         hub_info, hc, port, hub_info->address);
     560                                        hub_info, port);
    514561                        }
    515562                }
     563                usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    516564                free(change_bitmap);
    517 
    518                 async_hangup(hc);
     565               
     566
     567                //async_hangup(hc);
    519568                fibril_mutex_lock(&usb_hub_list_lock);
    520569        }
  • uspace/drv/usbhub/usbhub.h

    r423e8c81 r62066b4  
    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

    r423e8c81 r62066b4  
    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

    r423e8c81 r62066b4  
    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

    r423e8c81 r62066b4  
    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.