Changeset 7fc092a in mainline for uspace/drv


Ignore:
Timestamp:
2011-01-27T22:09:29Z (15 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
db7ed07
Parents:
9ee87f6 (diff), 6265a2b (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:

Changes from development branch

Location:
uspace/drv
Files:
3 added
28 edited
1 moved

Legend:

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

    r9ee87f6 r7fc092a  
    431431{
    432432        ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data;
    433         int res;
    434        
    435         /* Enable interrupt globally. */
    436         res = interrupt_enable(data->irq);
    437         if (res != EOK)
    438                 return res;
    439433       
    440434        /* Enable interrupt on the serial port. */
  • uspace/drv/usbhub/main.c

    r9ee87f6 r7fc092a  
    2727 */
    2828
     29/** @addtogroup drvusbhub
     30 * @{
     31 */
     32
    2933#include <driver.h>
    3034#include <errno.h>
     
    5256        while(true){
    5357                usb_hub_check_hub_changes();
    54                 async_usleep(1000 * 1000);
     58                async_usleep(1000 * 1000 );/// \TODO proper number once
    5559        }
    5660        return 0;
     
    6064int main(int argc, char *argv[])
    6165{
    62         usb_dprintf_enable(NAME,1);
     66        usb_dprintf_enable(NAME, 0);
     67
    6368        futex_initialize(&usb_hub_list_lock, 0);
    6469        usb_lst_init(&usb_hub_list);
    6570        futex_up(&usb_hub_list_lock);
     71
    6672        fid_t fid = fibril_create(usb_hub_control_loop, NULL);
    6773        if (fid == 0) {
    68                 dprintf(1, "failed to start fibril for HUB devices");
    69                 //printf("%s: failed to start fibril for HUB devices\n", NAME);
     74                fprintf(stderr, NAME ": failed to start monitoring fibril," \
     75                    " driver aborting.\n");
    7076                return ENOMEM;
    7177        }
     
    7480        return driver_main(&hub_driver);
    7581}
     82
     83/**
     84 * @}
     85 */
     86
  • uspace/drv/usbhub/port_status.h

    r9ee87f6 r7fc092a  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28/** @addtogroup drvusbhub
     29 * @{
     30 */
    2831
    2932#ifndef PORT_STATUS_H
     
    302305#endif  /* PORT_STATUS_H */
    303306
     307/**
     308 * @}
     309 */
  • uspace/drv/usbhub/usbhub.c

    r9ee87f6 r7fc092a  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb hub driver
     28/** @addtogroup drvusbhub
    2929 * @{
    3030 */
     
    4646#include "usbhub_private.h"
    4747#include "port_status.h"
     48#include "usb/usb.h"
    4849
    4950static usb_iface_t hub_usb_iface = {
     
    7576        //get some hub info
    7677        usb_address_t addr = usb_drv_get_my_address(hc, device);
    77         dprintf(1,"[usb_hub] address of newly created hub = %d", addr);
     78        dprintf(1, "address of newly created hub = %d", addr);
    7879        /*if(addr<0){
    7980                //return result;
     
    8586
    8687        // get hub descriptor
    87         usb_target_t target;
    88         target.address = addr;
    89         target.endpoint = 0;
    90         usb_device_request_setup_packet_t request;
    91         //printf("[usb_hub] creating descriptor request\n");
    92         usb_hub_set_descriptor_request(&request);
    9388
    9489        //printf("[usb_hub] creating serialized descriptor\n");
     
    9893        int opResult;
    9994        //printf("[usb_hub] starting control transaction\n");
    100         opResult = usb_drv_sync_control_read(
    101                         hc, target, &request, serialized_descriptor,
     95       
     96        opResult = usb_drv_req_get_descriptor(hc, addr,
     97                        USB_REQUEST_TYPE_CLASS,
     98                        USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
    10299                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
    103         if (opResult != EOK) {
    104                 dprintf(1,"[usb_hub] failed when receiving hub descriptor, badcode = %d",opResult);
     100
     101        if (opResult != EOK) {
     102                dprintf(1, "failed when receiving hub descriptor, badcode = %d",opResult);
    105103                free(serialized_descriptor);
    106104                return result;
     
    109107        descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
    110108        if(descriptor==NULL){
    111                 dprintf(1,"[usb_hub] could not deserialize descriptor ");
     109                dprintf(1, "could not deserialize descriptor ");
    112110                result->port_count = 1;///\TODO this code is only for debug!!!
    113111                return result;
     
    129127        //finish
    130128
    131         dprintf(1,"[usb_hub] hub info created");
     129        dprintf(1, "hub info created");
    132130
    133131        return result;
     
    136134int usb_add_hub_device(device_t *dev) {
    137135        dprintf(1, "add_hub_device(handle=%d)", (int) dev->handle);
    138         dprintf(1,"[usb_hub] hub device");
     136        dprintf(1, "hub device");
    139137
    140138        /*
     
    155153        int port;
    156154        int opResult;
    157         usb_device_request_setup_packet_t request;
    158155        usb_target_t target;
    159156        target.address = hub_info->usb_device->address;
     
    165162        usb_standard_device_descriptor_t std_descriptor;
    166163        opResult = usb_drv_req_get_device_descriptor(hc, target.address,
    167     &std_descriptor);
     164            &std_descriptor);
    168165        if(opResult!=EOK){
    169                 dprintf(1,"[usb_hub] could not get device descriptor, %d",opResult);
     166                dprintf(1, "could not get device descriptor, %d",opResult);
    170167                return opResult;
    171168        }
    172         dprintf(1,"[usb_hub] hub has %d configurations",std_descriptor.configuration_count);
     169        dprintf(1, "hub has %d configurations",std_descriptor.configuration_count);
    173170        if(std_descriptor.configuration_count<1){
    174                 dprintf(1,"[usb_hub] THERE ARE NO CONFIGURATIONS AVAILABLE");
     171                dprintf(1, "THERE ARE NO CONFIGURATIONS AVAILABLE");
     172                //shouldn`t I return?
    175173        }
    176174        /// \TODO check other configurations
     
    180178        &config_descriptor);
    181179        if(opResult!=EOK){
    182                 dprintf(1,"[usb_hub] could not get configuration descriptor, %d",opResult);
     180                dprintf(1, "could not get configuration descriptor, %d",opResult);
    183181                return opResult;
    184182        }
    185183        //set configuration
    186         request.request_type = 0;
    187         request.request = USB_DEVREQ_SET_CONFIGURATION;
    188         request.index=0;
    189         request.length=0;
    190         request.value_high=0;
    191         request.value_low = config_descriptor.configuration_number;
    192         opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
    193         if (opResult != EOK) {
    194                 dprintf(1,"[usb_hub]something went wrong when setting hub`s configuration, %d", opResult);
    195         }
    196 
     184        opResult = usb_drv_req_set_configuration(hc, target.address,
     185    config_descriptor.configuration_number);
     186
     187        if (opResult != EOK) {
     188                dprintf(1, "something went wrong when setting hub`s configuration, %d", opResult);
     189        }
     190
     191        usb_device_request_setup_packet_t request;
    197192        for (port = 1; port < hub_info->port_count+1; ++port) {
    198193                usb_hub_set_power_port_request(&request, port);
    199194                opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
    200                 dprintf(1,"[usb_hub] powering port %d",port);
     195                dprintf(1, "powering port %d",port);
    201196                if (opResult != EOK) {
    202                         dprintf(1,"[usb_hub]something went wrong when setting hub`s %dth port", port);
     197                        dprintf(1, "something went wrong when setting hub`s %dth port", port);
    203198                }
    204199        }
     
    212207        futex_up(&usb_hub_list_lock);
    213208
    214         dprintf(1,"[usb_hub] hub info added to list");
     209        dprintf(1, "hub info added to list");
    215210        //(void)hub_info;
    216211        usb_hub_check_hub_changes();
     
    218213       
    219214
    220         dprintf(1,"[usb_hub] hub dev added");
    221         dprintf(1,"\taddress %d, has %d ports ",
     215        dprintf(1, "hub dev added");
     216        dprintf(1, "\taddress %d, has %d ports ",
    222217                        hub_info->usb_device->address,
    223218                        hub_info->port_count);
    224         dprintf(1,"\tused configuration %d",config_descriptor.configuration_number);
     219        dprintf(1, "\tused configuration %d",config_descriptor.configuration_number);
    225220
    226221        return EOK;
    227222        //return ENOTSUP;
    228223}
    229 
    230224
    231225
     
    237231
    238232/**
    239  * convenience function for releasing default address and writing debug info
    240  * (these few lines are used too often to be written again and again)
     233 * Convenience function for releasing default address and writing debug info
     234 * (these few lines are used too often to be written again and again).
    241235 * @param hc
    242236 * @return
     
    244238inline static int usb_hub_release_default_address(int hc){
    245239        int opResult;
    246         dprintf(1,"[usb_hub] releasing default address");
     240        dprintf(1, "releasing default address");
    247241        opResult = usb_drv_release_default_address(hc);
    248242        if (opResult != EOK) {
    249                 dprintf(1,"[usb_hub] failed to release default address");
     243                dprintf(1, "failed to release default address");
    250244        }
    251245        return opResult;
     
    253247
    254248/**
    255  * reset the port with new device and reserve the default address
     249 * Reset the port with new device and reserve the default address.
    256250 * @param hc
    257251 * @param port
     
    261255        usb_device_request_setup_packet_t request;
    262256        int opResult;
    263         dprintf(1,"[usb_hub] some connection changed");
     257        dprintf(1, "some connection changed");
    264258        //get default address
    265259        opResult = usb_drv_reserve_default_address(hc);
    266260        if (opResult != EOK) {
    267                 dprintf(1,"[usb_hub] cannot assign default address, it is probably used");
     261                dprintf(1, "cannot assign default address, it is probably used");
    268262                return;
    269263        }
     
    276270                        );
    277271        if (opResult != EOK) {
    278                 dprintf(1,"[usb_hub] something went wrong when reseting a port");
     272                dprintf(1, "something went wrong when reseting a port");
    279273                usb_hub_release_default_address(hc);
    280274        }
     
    282276
    283277/**
    284  * finalize adding new device after port reset
     278 * Finalize adding new device after port reset
    285279 * @param hc
    286280 * @param port
     
    291285
    292286        int opResult;
    293         dprintf(1,"[usb_hub] finalizing add device");
     287        dprintf(1, "finalizing add device");
    294288        opResult = usb_hub_clear_port_feature(hc, target.address,
    295289            port, USB_HUB_FEATURE_C_PORT_RESET);
    296290        if (opResult != EOK) {
    297                 dprintf(1,"[usb_hub] failed to clear port reset feature");
     291                dprintf(1, "failed to clear port reset feature");
    298292                usb_hub_release_default_address(hc);
    299293                return;
     
    303297        usb_address_t new_device_address = usb_drv_request_address(hc);
    304298        if (new_device_address < 0) {
    305                 dprintf(1,"[usb_hub] failed to get free USB address");
     299                dprintf(1, "failed to get free USB address");
    306300                opResult = new_device_address;
    307301                usb_hub_release_default_address(hc);
    308302                return;
    309303        }
    310         dprintf(1,"[usb_hub] setting new address");
     304        dprintf(1, "setting new address");
    311305        opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    312306            new_device_address);
    313307
    314308        if (opResult != EOK) {
    315                 dprintf(1,"[usb_hub] could not set address for new device");
     309                dprintf(1, "could not set address for new device");
    316310                usb_hub_release_default_address(hc);
    317311                return;
     
    328322            new_device_address, &child_handle);
    329323        if (opResult != EOK) {
    330                 dprintf(1,"[usb_hub] could not start driver for new device");
     324                dprintf(1, "could not start driver for new device");
    331325                return;
    332326        }
     
    336330        opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
    337331        if (opResult != EOK) {
    338                 dprintf(1,"[usb_hub] could not assign address of device in hcd");
    339                 return;
    340         }
    341         dprintf(1,"[usb_hub] new device address %d, handle %zu",
     332                dprintf(1, "could not assign address of device in hcd");
     333                return;
     334        }
     335        dprintf(1, "new device address %d, handle %zu",
    342336            new_device_address, child_handle);
    343337
     
    345339
    346340/**
    347  * unregister device address in hc
     341 * Unregister device address in hc
    348342 * @param hc
    349343 * @param port
     
    355349        int opResult;
    356350       
    357         /// \TODO remove device
     351        /** \TODO remove device from device manager - not yet implemented in
     352         * devide manager
     353         */
    358354
    359355        hub->attached_devs[port].devman_handle=0;
     
    362358                opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
    363359                if(opResult != EOK) {
    364                         dprintf(1,
    365                                         "[usb_hub] could not release address of removed device: %d"
    366                                         ,opResult);
     360                        dprintf(1, "could not release address of " \
     361                            "removed device: %d", opResult);
    367362                }
    368363                hub->attached_devs[port].address = 0;
    369364        }else{
    370                 dprintf(1,
    371                                 "[usb_hub] this is strange, disconnected device had no address");
     365                dprintf(1, "this is strange, disconnected device had no address");
    372366                //device was disconnected before it`s port was reset - return default address
    373367                usb_drv_release_default_address(hc);
     
    376370
    377371/**
    378  * process interrupts on given hub port
     372 * Process interrupts on given hub port
    379373 * @param hc
    380374 * @param port
     
    383377static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,
    384378        uint16_t port, usb_address_t address) {
    385         dprintf(1,"[usb_hub] interrupt at port %d", port);
     379        dprintf(1, "interrupt at port %d", port);
    386380        //determine type of change
    387381        usb_target_t target;
     
    401395                        );
    402396        if (opResult != EOK) {
    403                 dprintf(1,"[usb_hub] ERROR: could not get port status");
     397                dprintf(1, "ERROR: could not get port status");
    404398                return;
    405399        }
    406400        if (rcvd_size != sizeof (usb_port_status_t)) {
    407                 dprintf(1,"[usb_hub] ERROR: received status has incorrect size");
     401                dprintf(1, "ERROR: received status has incorrect size");
    408402                return;
    409403        }
     
    414408                // TODO: check opResult
    415409                if (usb_port_dev_connected(&status)) {
    416                         dprintf(1,"[usb_hub] some connection changed");
     410                        dprintf(1, "some connection changed");
    417411                        usb_hub_init_add_device(hc, port, target);
    418412                } else {
     
    422416        //port reset
    423417        if (usb_port_reset_completed(&status)) {
    424                 dprintf(1,"[usb_hub] port reset complete");
     418                dprintf(1, "port reset complete");
    425419                if (usb_port_enabled(&status)) {
    426420                        usb_hub_finalize_add_device(hub, hc, port, target);
    427421                } else {
    428                         dprintf(1,"[usb_hub] ERROR: port reset, but port still not enabled");
     422                        dprintf(1, "ERROR: port reset, but port still not enabled");
    429423                }
    430424        }
     
    434428        usb_port_set_reset_completed(&status, false);
    435429        usb_port_set_dev_connected(&status, false);
    436         if (status) {
    437                 dprintf(1,"[usb_hub]there was some unsupported change on port %d",port);
     430        if (status>>16) {
     431                dprintf(1, "there was some unsupported change on port %d: %X",port,status);
     432
    438433        }
    439434        /// \TODO handle other changes
     
    442437}
    443438
    444 /* Check changes on all known hubs.
     439/**
     440 * Check changes on all known hubs.
    445441 */
    446442void usb_hub_check_hub_changes(void) {
     
    462458                target.address = hub_info->usb_device->address;
    463459                target.endpoint = 1;/// \TODO get from endpoint descriptor
    464                 dprintf(1,"[usb_hub] checking changes for hub at addr %d",
     460                dprintf(1, "checking changes for hub at addr %d",
    465461                    target.address);
    466462
     
    492488
    493489                if (opResult != EOK) {
    494                         dprintf(1,"[usb_hub] something went wrong while getting status of hub");
     490                        dprintf(1, "something went wrong while getting status of hub");
    495491                        continue;
    496492                }
  • uspace/drv/usbhub/usbhub.h

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbhub
    3030 * @{
    3131 */
  • uspace/drv/usbhub/usbhub_private.h

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbhub
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief Hub driver.
     33 * @brief Hub driver private definitions
    3434 */
    3535
     
    6868
    6969/**
    70  * create hub structure instance
     70 * Create hub structure instance
    7171 *
    7272 * Set the address and port count information most importantly.
     
    7878usb_hub_info_t * usb_create_hub_info(device_t * device, int hc);
    7979
    80 /** list of hubs maanged by this driver */
     80/** List of hubs maanged by this driver */
    8181extern usb_general_list_t usb_hub_list;
    8282
    83 /** lock for hub list*/
     83/** Lock for hub list*/
    8484extern futex_t usb_hub_list_lock;
    8585
    8686
    8787/**
    88  * perform complete control read transaction
     88 * Perform complete control read transaction
    8989 *
    90  * manages all three steps of transaction: setup, read and finalize
     90 * Manages all three steps of transaction: setup, read and finalize
    9191 * @param phone
    9292 * @param target
    93  * @param request request for data
    94  * @param rcvd_buffer received data
     93 * @param request Request packet
     94 * @param rcvd_buffer Received data
    9595 * @param rcvd_size
    96  * @param actual_size actual size of received data
     96 * @param actual_size Actual size of received data
    9797 * @return error code
    9898 */
     
    104104
    105105/**
    106  * perform complete control write transaction
     106 * Perform complete control write transaction
    107107 *
    108  * manages all three steps of transaction: setup, write and finalize
     108 * Manages all three steps of transaction: setup, write and finalize
    109109 * @param phone
    110110 * @param target
    111  * @param request request to send data
     111 * @param request Request packet to send data
    112112 * @param sent_buffer
    113113 * @param sent_size
     
    121121
    122122/**
    123  * set the device request to be a get hub descriptor request.
     123 * Set the device request to be a get hub descriptor request.
    124124 * @warning the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE
    125125 * @param request
     
    137137}
    138138
     139/**
     140 * Clear feature on hub port.
     141 *
     142 * @param hc Host controller telephone
     143 * @param address Hub address
     144 * @param port_index Port
     145 * @param feature Feature selector
     146 * @return Operation result
     147 */
    139148static inline int usb_hub_clear_port_feature(int hc, usb_address_t address,
    140149    int port_index,
  • uspace/drv/usbhub/usblist.c

    r9ee87f6 r7fc092a  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb hub driver
     28/** @addtogroup drvusbhub
    2929 * @{
    3030 */
  • uspace/drv/usbhub/usblist.h

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 
    30 #ifndef USBLIST_H
    31 #define USBLIST_H
    32 /** @addtogroup usb hub driver
     29/** @addtogroup drvusbhub
    3330 * @{
    3431 */
     
    4037 * much simpler and more straight-forward semantics.
    4138 */
     39#ifndef USBLIST_H
     40#define USBLIST_H
    4241
    4342/**
     
    7877}
    7978
    80 
     79#endif  /* USBLIST_H */
    8180/**
    8281 * @}
    8382 */
    84 
    85 
    86 
    87 #endif  /* USBLIST_H */
    88 
  • uspace/drv/usbhub/utils.c

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup drvusbhub
    3030 * @{
    3131 */
  • uspace/drv/usbkbd/Makefile

    r9ee87f6 r7fc092a  
    3333
    3434SOURCES = \
    35         main.c
     35        main.c \
     36        descparser.c \
     37        descdump.c
    3638
    3739include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/usbkbd/descparser.h

    r9ee87f6 r7fc092a  
    11/*
    2  * Copyright (c) 2009 Lukas Mejdrech
     2 * Copyright (c) 2010 Lubos Slovak
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 
    29 /** @addtogroup ip
     28/** @addtogroup drvusbhid
    3029 * @{
    3130 */
    3231
    33 /** @file
    34  * IP module functions.
    35  * The functions are used as IP module entry points.
    36  */
     32#ifndef USBHID_DESCPARSER_H_
     33#define USBHID_DESCPARSER_H_
    3734
    38 #ifndef NET_IP_MODULE_H_
    39 #define NET_IP_MODULE_H_
     35#include <usb/classes/hid.h>
    4036
    41 #include <ipc/ipc.h>
     37int usbkbd_parse_descriptors(const uint8_t *data, size_t size,
     38                             usb_hid_configuration_t *config);
    4239
    43 extern int ip_initialize(async_client_conn_t);
    44 extern int ip_message_standalone(ipc_callid_t, ipc_call_t *, ipc_call_t *,
    45     size_t *);
     40void usbkbd_print_config(const usb_hid_configuration_t *config);
    4641
    4742#endif
    4843
    49 /** @}
     44/**
     45 * @}
    5046 */
  • uspace/drv/usbkbd/main.c

    r9ee87f6 r7fc092a  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28/** @addtogroup drvusbhid
     29 * @{
     30 */
    2831#include <usb/usbdrv.h>
    2932#include <driver.h>
     
    3841#include <usb/devreq.h>
    3942#include <usb/descriptor.h>
     43#include "descparser.h"
     44#include "descdump.h"
    4045
    4146#define BUFFER_SIZE 32
     
    8893 * Callbacks for parser
    8994 */
    90 static void usbkbd_process_keycodes(const uint16_t *key_codes, size_t count,
    91                                     void *arg)
    92 {
    93 
     95static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count,
     96                                    uint8_t modifiers, void *arg)
     97{
     98        printf("Got keys: ");
     99        unsigned i;
     100        for (i = 0; i < count; ++i) {
     101                printf("%d ", key_codes[i]);
     102        }
     103        printf("\n");
    94104}
    95105
     
    97107 * Kbd functions
    98108 */
    99 static int usbkbd_parse_descriptors(usb_hid_dev_kbd_t *kbd_dev,
    100                                     const uint8_t *data, size_t size)
    101 {
    102 //      const uint8_t *pos = data;
    103        
    104 //      // get the configuration descriptor (should be first)
    105 //      if (*pos != sizeof(usb_standard_configuration_descriptor_t)
    106 //          || *(pos + 1) != USB_DESCTYPE_CONFIGURATION) {
    107 //              fprintf(stderr, "Wrong format of configuration descriptor");
    108 //              return EINVAL;
    109 //      }
    110        
    111 //      usb_standard_configuration_descriptor_t config_descriptor;
    112 //      memcpy(&config_descriptor, pos,
    113 //          sizeof(usb_standard_configuration_descriptor_t));
    114 //      pos += sizeof(usb_standard_configuration_descriptor_t);
    115        
    116 //      // parse other descriptors
    117 //      while (pos - data < size) {
    118 //              //uint8_t desc_size = *pos;
    119 //              uint8_t desc_type = *(pos + 1);
    120 //              switch (desc_type) {
    121 //              case USB_DESCTYPE_INTERFACE:
    122 //                      break;
    123 //              case USB_DESCTYPE_ENDPOINT:
    124 //                      break;
    125 //              case USB_DESCTYPE_HID:
    126 //                      break;
    127 //              case USB_DESCTYPE_HID_REPORT:
    128 //                      break;
    129 //              case USB_DESCTYPE_HID_PHYSICAL:
    130 //                      break;
    131 //              }
    132 //      }
    133        
     109static int usbkbd_get_report_descriptor(usb_hid_dev_kbd_t *kbd_dev)
     110{
     111        // iterate over all configurations and interfaces
     112        // TODO: more configurations!!
     113        unsigned i;
     114        for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) {
     115                // TODO: endianness
     116                uint16_t length =
     117                    kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length;
     118                size_t actual_size = 0;
     119
     120                // allocate space for the report descriptor
     121                kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length);
     122               
     123                // get the descriptor from the device
     124                int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone,
     125                    kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,
     126                    0, i, kbd_dev->conf->interfaces[i].report_desc, length,
     127                    &actual_size);
     128
     129                if (rc != EOK) {
     130                        return rc;
     131                }
     132
     133                assert(actual_size == length);
     134
     135                //dump_hid_class_descriptor(0, USB_DESCTYPE_HID_REPORT,
     136                //    kbd_dev->conf->interfaces[i].report_desc, length);
     137        }
     138
    134139        return EOK;
    135140}
    136141
    137 static int usbkbd_get_descriptors(usb_hid_dev_kbd_t *kbd_dev)
    138 {
    139         // get the first configuration descriptor (TODO: or some other??)
     142static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev)
     143{
     144        // get the first configuration descriptor (TODO: parse also other!)
    140145        usb_standard_configuration_descriptor_t config_desc;
    141146       
     
    166171        }
    167172       
    168         rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred);
     173        kbd_dev->conf = (usb_hid_configuration_t *)calloc(1,
     174            sizeof(usb_hid_configuration_t));
     175        if (kbd_dev->conf == NULL) {
     176                free(descriptors);
     177                return ENOMEM;
     178        }
     179       
     180        rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
    169181        free(descriptors);
    170        
    171         return rc;
     182        if (rc != EOK) {
     183                printf("Problem with parsing standard descriptors.\n");
     184                return rc;
     185        }
     186
     187        // get and report descriptors
     188        rc = usbkbd_get_report_descriptor(kbd_dev);
     189        if (rc != EOK) {
     190                printf("Problem with parsing HID REPORT descriptor.\n");
     191                return rc;
     192        }
     193       
     194        //usbkbd_print_config(kbd_dev->conf);
     195
     196        /*
     197         * TODO:
     198         * 1) select one configuration (lets say the first)
     199         * 2) how many interfaces?? how to select one??
     200     *    ("The default setting for an interface is always alternate setting zero.")
     201         * 3) find endpoint which is IN and INTERRUPT (parse), save its number
     202     *    as the endpoint for polling
     203         */
     204       
     205        return EOK;
    172206}
    173207
    174208static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    175209{
    176         usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)malloc(
    177                         sizeof(usb_hid_dev_kbd_t));
     210        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
     211            sizeof(usb_hid_dev_kbd_t));
    178212
    179213        if (kbd_dev == NULL) {
     
    186220        // get phone to my HC and save it as my parent's phone
    187221        // TODO: maybe not a good idea if DDF will use parent_phone
    188         kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
    189 
    190         kbd_dev->address = usb_drv_get_my_address(dev->parent_phone,
    191             dev);
     222        int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
     223        if (rc < 0) {
     224                printf("Problem setting phone to HC.\n");
     225                free(kbd_dev);
     226                return NULL;
     227        }
     228
     229        rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev);
     230        if (rc < 0) {
     231                printf("Problem getting address of the device.\n");
     232                free(kbd_dev);
     233                return NULL;
     234        }
    192235
    193236        // doesn't matter now that we have no address
     
    208251         */
    209252
    210         // TODO: get descriptors
    211         usbkbd_get_descriptors(kbd_dev);
    212         // TODO: parse descriptors and save endpoints
     253        // TODO: get descriptors, parse descriptors and save endpoints
     254        usbkbd_process_descriptors(kbd_dev);
    213255
    214256        return kbd_dev;
     
    218260                                        uint8_t *buffer, size_t actual_size)
    219261{
    220         /*
    221          * here, the parser will be called, probably with some callbacks
    222          * now only take last 6 bytes and process, i.e. send to kbd
    223          */
    224 
    225262        usb_hid_report_in_callbacks_t *callbacks =
    226263            (usb_hid_report_in_callbacks_t *)malloc(
     
    228265        callbacks->keyboard = usbkbd_process_keycodes;
    229266
    230         usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
    231             NULL);
     267        //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
     268        //    NULL);
     269        printf("Calling usb_hid_boot_keyboard_input_report()...\n)");
     270        usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL);
    232271}
    233272
    234273static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
    235274{
     275        return;
     276       
    236277        int rc;
    237278        usb_handle_t handle;
     
    356397        return driver_main(&kbd_driver);
    357398}
     399
     400/**
     401 * @}
     402 */
  • uspace/drv/vhc/conn.h

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
     
    5151
    5252void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
     53void on_client_close(device_t *);
    5354
    5455
  • uspace/drv/vhc/conndev.c

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
     
    8888                int callback = IPC_GET_ARG5(*icall);
    8989                virtdev_connection_t *dev
    90                     = virtdev_add_device(callback);
     90                    = virtdev_add_device(callback, (sysarg_t)fibril_get_id());
    9191                if (!dev) {
    9292                        ipc_answer_0(icallid, EEXISTS);
     
    9999                int rc = get_device_name(callback, devname, DEVICE_NAME_MAXLENGTH);
    100100
    101                 dprintf(0, "virtual device connected (name: %s)",
    102                     rc == EOK ? devname : "<unknown>");
    103 
    104                 /* FIXME: destroy the device when the client disconnects. */
     101                dprintf(0, "virtual device connected (name: %s, id: %x)",
     102                    rc == EOK ? devname : "<unknown>", dev->id);
    105103
    106104                return;
     
    110108}
    111109
     110/** Callback for DDF when client disconnects.
     111 *
     112 * @param d Device the client was connected to.
     113 */
     114void on_client_close(device_t *d)
     115{
     116        /*
     117         * Maybe a virtual device is being unplugged.
     118         */
     119        virtdev_connection_t *dev = virtdev_find((sysarg_t)fibril_get_id());
     120        if (dev == NULL) {
     121                return;
     122        }
     123
     124        dprintf(0, "virtual device disconnected (id: %x)", dev->id);
     125        virtdev_destroy_device(dev);
     126}
     127
    112128
    113129/**
  • uspace/drv/vhc/connhost.c

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
  • uspace/drv/vhc/debug.c

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
  • uspace/drv/vhc/devices.c

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
     
    5858/** Create virtual device.
    5959 *
    60  * @param address USB address.
    6160 * @param phone Callback phone.
     61 * @param id Device id.
    6262 * @return New device.
    63  * @retval NULL Out of memory or address already occupied.
    64  */
    65 virtdev_connection_t *virtdev_add_device(int phone)
     63 * @retval NULL Out of memory.
     64 */
     65virtdev_connection_t *virtdev_add_device(int phone, sysarg_t id)
    6666{
    6767        virtdev_connection_t *dev = (virtdev_connection_t *)
    6868            malloc(sizeof(virtdev_connection_t));
     69        if (dev == NULL) {
     70                return NULL;
     71        }
     72
    6973        dev->phone = phone;
     74        dev->id = id;
    7075        list_append(&dev->link, &devices);
    7176       
     
    7378       
    7479        return dev;
     80}
     81
     82/** Find virtual device by id.
     83 *
     84 * @param id Device id.
     85 * @return Device with given id.
     86 * @retval NULL No such device.
     87 */
     88virtdev_connection_t *virtdev_find(sysarg_t id)
     89{
     90        link_t *pos;
     91        list_foreach(pos, &devices) {
     92                virtdev_connection_t *dev
     93                    = list_get_instance(pos, virtdev_connection_t, link);
     94                if (dev->id == id) {
     95                        return dev;
     96                }
     97        }
     98
     99        return NULL;
    75100}
    76101
     
    90115usb_transaction_outcome_t virtdev_send_to_all(transaction_t *transaction)
    91116{
     117        /* For easier debugging. */
     118        switch (transaction->type) {
     119                case USBVIRT_TRANSACTION_SETUP:
     120                case USBVIRT_TRANSACTION_OUT:
     121                        transaction->actual_len = transaction->len;
     122                        break;
     123                case USBVIRT_TRANSACTION_IN:
     124                        transaction->actual_len = 0;
     125                        break;
     126                default:
     127                        assert(false && "unreachable branch in switch()");
     128        }
     129        usb_transaction_outcome_t outcome = USB_OUTCOME_BABBLE;
     130
    92131        link_t *pos;
    93132        list_foreach(pos, &devices) {
     
    138177                } else {
    139178                        async_wait_for(req, &answer_rc);
     179                        transaction->actual_len = IPC_GET_ARG1(answer_data);
    140180                        rc = (int)answer_rc;
     181                }
     182
     183                /*
     184                 * If at least one device was able to accept this
     185                 * transaction and process it, we can announce success.
     186                 */
     187                if (rc == EOK) {
     188                        outcome = USB_OUTCOME_OK;
    141189                }
    142190        }
     
    164212                                    transaction->buffer, transaction->len,
    165213                                    &tmp);
    166                                 if (tmp < transaction->len) {
    167                                         transaction->len = tmp;
    168                                 }
     214                                transaction->actual_len = tmp;
    169215                                break;
    170216                               
     
    177223                }
    178224                dprintf(4, "transaction on hub processed...");
     225                outcome = USB_OUTCOME_OK;
    179226        }
    180227       
     
    183230         * real-life image.
    184231         */
    185         return USB_OUTCOME_OK;
     232        return outcome;
    186233}
    187234
  • uspace/drv/vhc/devices.h

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
     
    4545        /** Phone used when sending data to device. */
    4646        int phone;
     47        /** Unique identification. */
     48        sysarg_t id;
    4749        /** Linked-list handle. */
    4850        link_t link;
    4951} virtdev_connection_t;
    5052
    51 virtdev_connection_t *virtdev_add_device(int);
    52 virtdev_connection_t *virtdev_get_mine(void);
     53virtdev_connection_t *virtdev_add_device(int, sysarg_t);
     54virtdev_connection_t *virtdev_find(sysarg_t);
    5355void virtdev_destroy_device(virtdev_connection_t *);
    5456usb_transaction_outcome_t virtdev_send_to_all(transaction_t *);
  • uspace/drv/vhc/hc.c

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
     
    9696            usb_str_transaction_outcome(outcome));
    9797       
    98         transaction->callback(transaction->buffer, transaction->len, outcome,
    99             transaction->callback_arg);
     98        transaction->callback(transaction->buffer, transaction->actual_len,
     99            outcome, transaction->callback_arg);
    100100}
    101101
     
    169169        transaction->buffer = buffer;
    170170        transaction->len = len;
     171        transaction->actual_len = len;
    171172        transaction->callback = callback;
    172173        transaction->callback_arg = arg;
  • uspace/drv/vhc/hc.h

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
     
    6565        /** Transaction data length. */
    6666        size_t len;
     67        /** Data length actually transfered. */
     68        size_t actual_len;
    6769        /** Callback after transaction is done. */
    6870        hc_transaction_done_callback_t callback;
  • uspace/drv/vhc/hcd.c

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
     
    6969        .interfaces[USBHC_DEV_IFACE] = &vhc_iface,
    7070        .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
     71        .close = on_client_close,
    7172        .default_handler = default_connection_handler
    7273};
     
    116117        sleep(5);
    117118
    118         usb_dprintf_enable(NAME, 0);
     119        usb_dprintf_enable(NAME, -1);
    119120
    120121        printf(NAME ": virtual USB host controller driver.\n");
  • uspace/drv/vhc/hub.c

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
  • uspace/drv/vhc/hub.h

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
  • uspace/drv/vhc/hub/hub.c

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
     
    155155}
    156156
     157/** Disconnects a device from a hub.
     158 *
     159 * @param hub Hub the device was connected to.
     160 * @param device Device to be disconnected.
     161 * @return Error code.
     162 */
     163int hub_disconnect_device(hub_t *hub, void *device)
     164{
     165        size_t index = hub_find_device(hub, device);
     166        if (index == (size_t) -1) {
     167                return ENOENT;
     168        }
     169
     170        hub_port_t *port = &hub->ports[index];
     171
     172        port->connected_device = NULL;
     173        port->state = HUB_PORT_STATE_DISCONNECTED;
     174        set_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
     175
     176        return EOK;
     177}
     178
    157179/** Find port device is connected to.
    158180 *
     
    173195        }
    174196
    175         return 0;
     197        return -1;
    176198}
    177199
  • uspace/drv/vhc/hub/hub.h

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
     
    9494void hub_init(hub_t *);
    9595size_t hub_connect_device(hub_t *, void *);
     96int hub_disconnect_device(hub_t *, void *);
    9697size_t hub_find_device(hub_t *, void *);
    9798void hub_acquire(hub_t *);
  • uspace/drv/vhc/hub/virthub.c

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
     
    203203
    204204        hub_acquire(hub);
    205         /* TODO: implement. */
     205        hub_disconnect_device(hub, conn);
    206206        hub_release(hub);
    207207
  • uspace/drv/vhc/hub/virthub.h

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
  • uspace/drv/vhc/hub/virthubops.c

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
  • uspace/drv/vhc/vhcd.h

    r9ee87f6 r7fc092a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
Note: See TracChangeset for help on using the changeset viewer.