Changeset 4e8e1f5 in mainline


Ignore:
Timestamp:
2011-02-11T18:10:21Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d321cd7
Parents:
79d2987
Message:

Device recognition uses pipe API

Location:
uspace
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/usbinfo/info.c

    r79d2987 r4e8e1f5  
    3939#include <usb/usbdrv.h>
    4040#include <usb/pipes.h>
     41#include <usb/recognise.h>
    4142#include <usb/request.h>
    4243#include "usbinfo.h"
     
    4748        usb_device_connection_t wire;
    4849        usb_endpoint_pipe_t ctrl_pipe;
    49         ctrl_pipe.hc_phone = -1;
    50 
    51         int hc_phone = devman_device_connect(hc_handle, 0);
    52         if (hc_phone < 0) {
    53                 fprintf(stderr,
    54                     NAME ": failed to connect to host controller (%zu): %s.\n",
    55                         (size_t) hc_handle, str_error(hc_phone));
    56                 return hc_phone;
    57         }
    58 
    59         /*
    60          * Dump information about possible match ids.
    61          */
    62         match_id_list_t match_id_list;
    63         init_match_ids(&match_id_list);
    64         rc = usb_drv_create_device_match_ids(hc_phone, &match_id_list, address);
    65         if (rc != EOK) {
    66                 fprintf(stderr,
    67                     NAME ": failed to fetch match ids of the device: %s.\n",
    68                     str_error(rc));
    69                 goto leave;
    70         }
    71         dump_match_ids(&match_id_list);
    7250
    7351        /*
     
    9573                goto leave;
    9674        }
     75
     76        /*
     77         * Dump information about possible match ids.
     78         */
     79        match_id_list_t match_id_list;
     80        init_match_ids(&match_id_list);
     81        rc = usb_device_create_match_ids(&ctrl_pipe, &match_id_list);
     82        if (rc != EOK) {
     83                fprintf(stderr,
     84                    NAME ": failed to fetch match ids of the device: %s.\n",
     85                    str_error(rc));
     86                goto leave;
     87        }
     88        dump_match_ids(&match_id_list);
    9789
    9890        /*
     
    141133leave:
    142134        /* Ignoring errors here. */
    143         async_hangup(hc_phone);
    144135        usb_endpoint_pipe_end_session(&ctrl_pipe);
    145136
  • uspace/drv/uhci-rhd/port.c

    r79d2987 r4e8e1f5  
    3333 */
    3434#include <errno.h>
     35#include <str_error.h>
    3536
    3637#include <usb/usb.h>    /* usb_address_t */
    3738#include <usb/usbdrv.h> /* usb_drv_*     */
    3839#include <usb/debug.h>
     40#include <usb/recognise.h>
    3941
    4042#include "port.h"
     
    204206        assert(port->attached_device == 0);
    205207
    206         ret = usb_drv_register_child_in_devman(port->hc_phone, port->rh,
    207           usb_address, &port->attached_device);
    208 
     208        devman_handle_t hc_handle;
     209        ret = usb_drv_find_hc(port->rh, &hc_handle);
     210        if (ret != EOK) {
     211                usb_log_error("Failed to get handle of host controller: %s.\n",
     212                    str_error(ret));
     213                uhci_port_set_enabled(port, false);
     214                return ENOMEM;
     215        }
     216
     217        ret = usb_device_register_child_in_devman(usb_address, hc_handle,
     218            port->rh, &port->attached_device);
    209219        if (ret != EOK) { /* something went wrong */
    210220                usb_log_error("Failed(%d) in usb_drv_register_child.\n", ret);
  • uspace/drv/usbhub/usbhub.c

    r79d2987 r4e8e1f5  
    3636#include <bool.h>
    3737#include <errno.h>
     38#include <str_error.h>
    3839
    3940#include <usb_iface.h>
    4041#include <usb/usbdrv.h>
    4142#include <usb/descriptor.h>
     43#include <usb/recognise.h>
    4244#include <usb/devreq.h>
    4345#include <usb/classes/hub.h>
     
    317319        }
    318320
     321        devman_handle_t hc_handle;
     322        opResult = usb_drv_find_hc(hub->device, &hc_handle);
     323        if (opResult != EOK) {
     324                usb_log_error("Failed to get handle of host controller: %s.\n",
     325                    str_error(opResult));
     326                return;
     327        }
     328
    319329        devman_handle_t child_handle;
    320         opResult = usb_drv_register_child_in_devman(hc, hub->device,
    321             new_device_address, &child_handle);
     330        opResult = usb_device_register_child_in_devman(new_device_address,
     331            hc_handle, hub->device, &child_handle);
    322332        if (opResult != EOK) {
    323333                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
  • uspace/drv/vhc/hub.c

    r79d2987 r4e8e1f5  
    4141#include <driver.h>
    4242#include <usb/usbdrv.h>
     43#include <usb/recognise.h>
    4344
    4445#include "hub.h"
     
    9394
    9495        devman_handle_t hub_handle;
    95         usb_drv_register_child_in_devman(hc, hc_dev, hub_address, &hub_handle);
     96        usb_device_register_child_in_devman(hub_address, hc_dev->handle,
     97            hc_dev, &hub_handle);
     98        //usb_drv_register_child_in_devman(hc, hc_dev, hub_address, &hub_handle);
    9699        usb_drv_bind_address(hc, hub_address, hub_handle);
    97100
  • uspace/lib/usb/include/usb/usbdrv.h

    r79d2987 r4e8e1f5  
    106106    const void *, size_t);
    107107
    108 int usb_drv_create_device_match_ids(int, match_id_list_t *, usb_address_t);
    109 int usb_drv_register_child_in_devman(int, device_t *, usb_address_t,
    110     devman_handle_t *);
    111 
    112108
    113109#endif
  • uspace/lib/usb/src/recognise.c

    r79d2987 r4e8e1f5  
    3636#include <usb_iface.h>
    3737#include <usb/usbdrv.h>
     38#include <usb/pipes.h>
     39#include <usb/recognise.h>
     40#include <usb/request.h>
    3841#include <usb/classes/classes.h>
    3942#include <stdio.h>
    4043#include <errno.h>
     44
     45static size_t device_name_index = 0;
     46static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex);
    4147
    4248/** Callback for getting host controller handle.
     
    241247/** Add match ids based on configuration descriptor.
    242248 *
    243  * @param hc Open phone to host controller.
     249 * @param pipe Control pipe to the device.
    244250 * @param matches Match ids list to add matches to.
    245  * @param address USB address of the attached device.
    246251 * @param config_count Number of configurations the device has.
    247252 * @return Error code.
    248253 */
    249 static int usb_add_config_descriptor_match_ids(int hc,
    250     match_id_list_t *matches, usb_address_t address,
    251     int config_count)
     254static int usb_add_config_descriptor_match_ids(usb_endpoint_pipe_t *pipe,
     255    match_id_list_t *matches, int config_count)
    252256{
    253257        int final_rc = EOK;
     
    257261                int rc;
    258262                usb_standard_configuration_descriptor_t config_descriptor;
    259                 rc = usb_drv_req_get_bare_configuration_descriptor(hc,
    260                     address,  config_index, &config_descriptor);
     263                rc = usb_request_get_bare_configuration_descriptor(pipe,
     264                    config_index, &config_descriptor);
    261265                if (rc != EOK) {
    262266                        final_rc = rc;
     
    267271                void *full_config_descriptor
    268272                    = malloc(config_descriptor.total_length);
    269                 rc = usb_drv_req_get_full_configuration_descriptor(hc,
    270                     address, config_index,
     273                rc = usb_request_get_full_configuration_descriptor(pipe,
     274                    config_index,
    271275                    full_config_descriptor, config_descriptor.total_length,
    272276                    &full_config_descriptor_size);
     
    299303 * function exits with error.
    300304 *
    301  * @param hc Open phone to host controller.
     305 * @param ctrl_pipe Control pipe to given device (session must be already
     306 *      started).
    302307 * @param matches Initialized list of match ids.
    303  * @param address USB address of the attached device.
    304  * @return Error code.
    305  */
    306 int usb_drv_create_device_match_ids(int hc, match_id_list_t *matches,
    307     usb_address_t address)
     308 * @return Error code.
     309 */
     310int usb_device_create_match_ids(usb_endpoint_pipe_t *ctrl_pipe,
     311    match_id_list_t *matches)
    308312{
    309313        int rc;
    310        
    311314        /*
    312315         * Retrieve device descriptor and add matches from it.
     
    314317        usb_standard_device_descriptor_t device_descriptor;
    315318
    316         rc = usb_drv_req_get_device_descriptor(hc, address,
    317             &device_descriptor);
     319        rc = usb_request_get_device_descriptor(ctrl_pipe, &device_descriptor);
    318320        if (rc != EOK) {
    319321                return rc;
    320322        }
    321        
     323
    322324        rc = usb_drv_create_match_ids_from_device_descriptor(matches,
    323325            &device_descriptor);
     
    325327                return rc;
    326328        }
    327        
     329
    328330        /*
    329331         * Go through all configurations and add matches
    330332         * based on interface class.
    331333         */
    332         rc = usb_add_config_descriptor_match_ids(hc, matches,
    333             address, device_descriptor.configuration_count);
     334        rc = usb_add_config_descriptor_match_ids(ctrl_pipe, matches,
     335            device_descriptor.configuration_count);
    334336        if (rc != EOK) {
    335337                return rc;
     
    347349}
    348350
    349 
    350351/** Probe for device kind and register it in devman.
    351352 *
    352  * @param[in] hc Open phone to the host controller.
     353 * @param[in] address Address of the (unknown) attached device.
     354 * @param[in] hc_handle Handle of the host controller.
    353355 * @param[in] parent Parent device.
    354  * @param[in] address Address of the (unknown) attached device.
    355356 * @param[out] child_handle Handle of the child device.
    356357 * @return Error code.
    357358 */
    358 int usb_drv_register_child_in_devman(int hc, device_t *parent,
    359     usb_address_t address, devman_handle_t *child_handle)
    360 {
    361         static size_t device_name_index = 0;
    362         static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex);
    363 
     359int usb_device_register_child_in_devman(usb_address_t address,
     360    devman_handle_t hc_handle,
     361    device_t *parent, devman_handle_t *child_handle)
     362{
    364363        size_t this_device_name_index;
    365364
     
    369368        fibril_mutex_unlock(&device_name_index_mutex);
    370369
    371 
    372370        device_t *child = NULL;
    373371        char *child_name = NULL;
    374372        int rc;
     373        usb_device_connection_t dev_connection;
     374        usb_endpoint_pipe_t ctrl_pipe;
     375
     376        rc = usb_device_connection_initialize(&dev_connection, hc_handle, address);
     377        if (rc != EOK) {
     378                goto failure;
     379        }
     380
     381        rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe,
     382            &dev_connection);
     383        if (rc != EOK) {
     384                goto failure;
     385        }
    375386
    376387        child = create_device();
     
    391402        child->name = child_name;
    392403        child->ops = &child_ops;
    393        
    394         rc = usb_drv_create_device_match_ids(hc, &child->match_ids, address);
     404
     405        rc = usb_endpoint_pipe_start_session(&ctrl_pipe);
     406        if (rc != EOK) {
     407                goto failure;
     408        }
     409
     410        rc = usb_device_create_match_ids(&ctrl_pipe, &child->match_ids);
     411        if (rc != EOK) {
     412                goto failure;
     413        }
     414
     415        rc = usb_endpoint_pipe_end_session(&ctrl_pipe);
    395416        if (rc != EOK) {
    396417                goto failure;
     
    405426                *child_handle = child->handle;
    406427        }
    407        
     428
    408429        return EOK;
    409430
     
    419440
    420441        return rc;
    421 
    422442}
    423443
Note: See TracChangeset for help on using the changeset viewer.