Changeset b00849e in mainline for uspace/app


Ignore:
Timestamp:
2011-02-02T00:57:32Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1537ba6, 3597dab
Parents:
2cea1045 (diff), 2f4438f5 (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:

Merged pipe API

The pipe API shall eventually replace USB device drivers API explicitly
using phones. This API uses extra abstraction level by introducing
device connection (the wire) and endpoint pipe.

The USB HID driver uses the new API, hub driver does not.

Location:
uspace/app/usbinfo
Files:
4 edited

Legend:

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

    r2cea1045 rb00849e  
    9696void dump_usb_descriptor(uint8_t *descriptor, size_t size)
    9797{
     98        printf("Device descriptor:\n");
    9899        usb_dump_standard_descriptor(stdout, get_indent(0), "\n",
    99100            descriptor, size);
  • uspace/app/usbinfo/info.c

    r2cea1045 rb00849e  
    3838#include <errno.h>
    3939#include <usb/usbdrv.h>
     40#include <usb/pipes.h>
     41#include <usb/request.h>
    4042#include "usbinfo.h"
    4143
    42 int dump_device(int hc_phone, usb_address_t address)
     44int dump_device(devman_handle_t hc_handle, usb_address_t address)
    4345{
     46        int rc;
     47        usb_device_connection_t wire;
     48        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
    4459        /*
    4560         * Dump information about possible match ids.
     
    4762        match_id_list_t match_id_list;
    4863        init_match_ids(&match_id_list);
    49         int rc = usb_drv_create_device_match_ids(hc_phone, &match_id_list, address);
     64        rc = usb_drv_create_device_match_ids(hc_phone, &match_id_list, address);
    5065        if (rc != EOK) {
    5166                fprintf(stderr,
    5267                    NAME ": failed to fetch match ids of the device: %s.\n",
    5368                    str_error(rc));
    54                 return rc;
     69                goto leave;
    5570        }
    5671        dump_match_ids(&match_id_list);
     72
     73        /*
     74         * Initialize pipes.
     75         */
     76        rc = usb_device_connection_initialize(&wire, hc_handle, address);
     77        if (rc != EOK) {
     78                fprintf(stderr,
     79                    NAME ": failed to create connection to the device: %s.\n",
     80                    str_error(rc));
     81                goto leave;
     82        }
     83        rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe, &wire);
     84        if (rc != EOK) {
     85                fprintf(stderr,
     86                    NAME ": failed to create default control pipe: %s.\n",
     87                    str_error(rc));
     88                goto leave;
     89        }
     90        rc = usb_endpoint_pipe_start_session(&ctrl_pipe);
     91        if (rc != EOK) {
     92                fprintf(stderr,
     93                    NAME ": failed to start session on control pipe: %s.\n",
     94                    str_error(rc));
     95                goto leave;
     96        }
    5797
    5898        /*
     
    60100         */
    61101        usb_standard_device_descriptor_t device_descriptor;
    62         usb_dprintf(NAME, 1,
    63             "usb_drv_req_get_device_descriptor(%d, %d, %p)\n",
    64             hc_phone, (int) address, &device_descriptor);
    65 
    66         rc = usb_drv_req_get_device_descriptor(hc_phone, address,
    67             &device_descriptor);
     102        rc = usb_request_get_device_descriptor(&ctrl_pipe, &device_descriptor);
    68103        if (rc != EOK) {
    69104                fprintf(stderr,
    70105                    NAME ": failed to fetch standard device descriptor: %s.\n",
    71106                    str_error(rc));
    72                 return rc;
     107                goto leave;
    73108        }
    74109        dump_usb_descriptor((uint8_t *)&device_descriptor, sizeof(device_descriptor));
     
    79114        usb_standard_configuration_descriptor_t config_descriptor;
    80115        int config_index = 0;
    81         usb_dprintf(NAME, 1,
    82             "usb_drv_req_get_bare_configuration_descriptor(%d, %d, %d, %p)\n",
    83             hc_phone, (int) address, config_index, &config_descriptor);
    84 
    85         rc = usb_drv_req_get_bare_configuration_descriptor(hc_phone, address,
    86             config_index, &config_descriptor );
     116        rc = usb_request_get_bare_configuration_descriptor(&ctrl_pipe,
     117            config_index, &config_descriptor);
    87118        if (rc != EOK) {
    88119                fprintf(stderr,
    89120                    NAME ": failed to fetch standard configuration descriptor: %s.\n",
    90121                    str_error(rc));
    91                 return rc;
     122                goto leave;
    92123        }
    93124        //dump_standard_configuration_descriptor(config_index, &config_descriptor);
    94125
    95126        void *full_config_descriptor = malloc(config_descriptor.total_length);
    96         usb_dprintf(NAME, 1,
    97             "usb_drv_req_get_full_configuration_descriptor(%d, %d, %d, %p, %zu)\n",
    98             hc_phone, (int) address, config_index,
    99             full_config_descriptor, config_descriptor.total_length);
    100 
    101         rc = usb_drv_req_get_full_configuration_descriptor(hc_phone, address,
     127        rc = usb_request_get_full_configuration_descriptor(&ctrl_pipe,
    102128            config_index,
    103129            full_config_descriptor, config_descriptor.total_length, NULL);
     
    106132                    NAME ": failed to fetch full configuration descriptor: %s.\n",
    107133                    str_error(rc));
    108                 return rc;
     134                goto leave;
    109135        }
    110136
     
    112138            config_descriptor.total_length);
    113139
    114         return EOK;
     140        rc = EOK;
     141leave:
     142        /* Ignoring errors here. */
     143        ipc_hangup(hc_phone);
     144        usb_endpoint_pipe_end_session(&ctrl_pipe);
     145
     146        return rc;
    115147}
    116148
  • uspace/app/usbinfo/main.c

    r2cea1045 rb00849e  
    7777}
    7878
    79 static int set_new_host_controller(int *phone, const char *path)
     79static int get_host_controller_handle(const char *path,
     80    devman_handle_t *hc_handle)
    8081{
    8182        int rc;
    82         int tmp_phone;
    8383
    84         if (path[0] != '/') {
    85                 int hc_class_index = (int) strtol(path, NULL, 10);
    86                 char *dev_path;
    87                 rc = asprintf(&dev_path, "class/usbhc\\%d", hc_class_index);
    88                 if (rc < 0) {
    89                         internal_error(rc);
    90                         return rc;
    91                 }
    92                 devmap_handle_t handle;
    93                 rc = devmap_device_get_handle(dev_path, &handle, 0);
    94                 if (rc < 0) {
    95                         fprintf(stderr,
    96                             NAME ": failed getting handle of `devman://%s'.\n",
    97                             dev_path);
    98                         free(dev_path);
    99                         return rc;
    100                 }
    101                 tmp_phone = devmap_device_connect(handle, 0);
    102                 if (tmp_phone < 0) {
    103                         fprintf(stderr,
    104                             NAME ": could not connect to `%s'.\n",
    105                             dev_path);
    106                         free(dev_path);
    107                         return tmp_phone;
    108                 }
    109                 free(dev_path);
    110         } else {
    111                 devman_handle_t handle;
    112                 rc = devman_device_get_handle(path, &handle, 0);
    113                 if (rc != EOK) {
    114                         fprintf(stderr,
    115                             NAME ": failed getting handle of `devmap::/%s'.\n",
    116                             path);
    117                         return rc;
    118                 }
    119                 tmp_phone = devman_device_connect(handle, 0);
    120                 if (tmp_phone < 0) {
    121                         fprintf(stderr,
    122                             NAME ": could not connect to `%s'.\n",
    123                             path);
    124                         return tmp_phone;
    125                 }
     84        devman_handle_t handle;
     85        rc = devman_device_get_handle(path, &handle, 0);
     86        if (rc != EOK) {
     87                fprintf(stderr,
     88                    NAME ": failed getting handle of `devman::/%s'.\n",
     89                    path);
     90                return rc;
    12691        }
    127 
    128         *phone = tmp_phone;
     92        *hc_handle = handle;
    12993
    13094        return EOK;
    13195}
    13296
    133 static int connect_with_address(int hc_phone, const char *str_address)
     97static int get_device_address(const char *str_address, usb_address_t *address)
    13498{
    135         usb_address_t address = (usb_address_t) strtol(str_address, NULL, 0);
    136         if ((address < 0) || (address >= USB11_ADDRESS_MAX)) {
     99        usb_address_t addr = (usb_address_t) strtol(str_address, NULL, 0);
     100        if ((addr < 0) || (addr >= USB11_ADDRESS_MAX)) {
    137101                fprintf(stderr, NAME ": USB address out of range.\n");
    138102                return ERANGE;
    139103        }
    140104
    141         if (hc_phone < 0) {
    142                 fprintf(stderr, NAME ": no active host controller.\n");
    143                 return ENOENT;
    144         }
    145 
    146         return dump_device(hc_phone, address);
     105        *address = addr;
     106        return EOK;
    147107}
    148108
     
    150110int main(int argc, char *argv[])
    151111{
    152         int hc_phone = -1;
     112        devman_handle_t hc_handle = (devman_handle_t) -1;
     113        usb_address_t device_address = (usb_address_t) -1;
    153114
    154115        if (argc <= 1) {
     
    175136                        case 'a':
    176137                        case ACTION_DEVICE_ADDRESS: {
    177                                 int rc = connect_with_address(hc_phone, optarg);
     138                                int rc = get_device_address(optarg,
     139                                    &device_address);
    178140                                if (rc != EOK) {
    179141                                        return rc;
     
    184146                        case 't':
    185147                        case ACTION_HOST_CONTROLLER: {
    186                                 int rc = set_new_host_controller(&hc_phone,
    187                                     optarg);
     148                                int rc = get_host_controller_handle(optarg,
     149                                   &hc_handle);
    188150                                if (rc != EOK) {
    189151                                        return rc;
     
    202164        } while (i != -1);
    203165
     166        if ((hc_handle == (devman_handle_t) -1)
     167            || (device_address == (usb_address_t) -1)) {
     168                fprintf(stderr, NAME ": no target specified.\n");
     169                return EINVAL;
     170        }
     171
     172        dump_device(hc_handle, device_address);
     173
    204174        return 0;
    205175}
  • uspace/app/usbinfo/usbinfo.h

    r2cea1045 rb00849e  
    4747void dump_match_ids(match_id_list_t *matches);
    4848void dump_usb_descriptor(uint8_t *, size_t);
    49 int dump_device(int, usb_address_t);
     49int dump_device(devman_handle_t, usb_address_t);
    5050void dump_descriptor_tree(uint8_t *, size_t);
    5151
Note: See TracChangeset for help on using the changeset viewer.