Changeset c9256c5 in mainline


Ignore:
Timestamp:
2011-05-20T20:37:06Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1889786, fcbcaae9
Parents:
74b1e40 (diff), e8f826b (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:

Minor fixes and improvements

  • Ensure linking against libusb is static only.
  • Generic HC communication moved into libusb.
  • Headers clean-up.
  • Add function for resolving USB device path.
Files:
1 added
4 deleted
13 edited
2 moved

Legend:

Unmodified
Added
Removed
  • .bzrignore

    r74b1e40 rc9256c5  
    77*.map
    88*.disasm
     9*.lo
     10*.la
     11*.so.*
     12*.so0
    913_link.ld
    1014./*.iso
  • uspace/Makefile.common

    r74b1e40 rc9256c5  
    131131        endif
    132132endif
     133# Build static whenever we use libusb because that library uses
     134# thread local variables
     135ifneq ($(findstring usb, $(LIBS)),)
     136        STATIC_BUILD = y
     137endif
    133138
    134139ifeq ($(STATIC_BUILD), y)
  • uspace/app/lsusb/main.c

    r74b1e40 rc9256c5  
    4545#include <devmap.h>
    4646#include <usb/dev/hub.h>
    47 #include <usb/host.h>
     47#include <usb/hc.h>
    4848
    4949#define NAME "lsusb"
  • uspace/app/mkbd/main.c

    r74b1e40 rc9256c5  
    4545#include <devmap.h>
    4646#include <usb/dev/hub.h>
    47 #include <usb/host.h>
    48 #include <usb/driver.h>
     47#include <usb/hc.h>
    4948#include <usb/dev/pipes.h>
    5049
     
    173172                /* Try to get its address. */
    174173                if (!addr_found) {
    175                         addr = usb_device_get_assigned_address(dev_handle);
     174                        addr = usb_hc_get_address_by_handle(dev_handle);
    176175                        if (addr >= 0) {
    177176                                addr_found = true;
  • uspace/app/usbinfo/main.c

    r74b1e40 rc9256c5  
    4343#include <devman.h>
    4444#include <devmap.h>
    45 #include <usb/dev/hc.h>
     45#include <usb/hc.h>
    4646#include <usb/dev/pipes.h>
    47 #include <usb/host.h>
    48 #include <usb/driver.h>
    4947#include "usbinfo.h"
    50 
    51 static bool try_parse_class_and_address(const char *path,
    52     devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
    53 {
    54         size_t class_index;
    55         size_t address;
    56         int rc;
    57         char *ptr;
    58 
    59         rc = str_size_t(path, &ptr, 10, false, &class_index);
    60         if (rc != EOK) {
    61                 return false;
    62         }
    63         if ((*ptr == ':') || (*ptr == '.')) {
    64                 ptr++;
    65         } else {
    66                 return false;
    67         }
    68         rc = str_size_t(ptr, NULL, 10, true, &address);
    69         if (rc != EOK) {
    70                 return false;
    71         }
    72         rc = usb_ddf_get_hc_handle_by_class(class_index, out_hc_handle);
    73         if (rc != EOK) {
    74                 return false;
    75         }
    76         if (out_device_address != NULL) {
    77                 *out_device_address = (usb_address_t) address;
    78         }
    79         return true;
    80 }
    81 
    82 static bool resolve_hc_handle_and_dev_addr(const char *devpath,
    83     devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
    84 {
    85         int rc;
    86 
    87         /* Hack for QEMU to save-up on typing ;-). */
    88         if (str_cmp(devpath, "qemu") == 0) {
    89                 devpath = "/hw/pci0/00:01.2/uhci-rh/usb00_a1";
    90         }
    91 
    92         /* Hack for virtual keyboard. */
    93         if (str_cmp(devpath, "virt") == 0) {
    94                 devpath = "/virt/usbhc/usb00_a1/usb00_a2";
    95         }
    96 
    97         if (try_parse_class_and_address(devpath,
    98             out_hc_handle, out_device_address)) {
    99                 return true;
    100         }
    101 
    102         char *path = str_dup(devpath);
    103         if (path == NULL) {
    104                 return ENOMEM;
    105         }
    106 
    107         devman_handle_t hc = 0;
    108         bool hc_found = false;
    109         usb_address_t addr = 0;
    110         bool addr_found = false;
    111 
    112         /* Remove suffixes and hope that we will encounter device node. */
    113         while (str_length(path) > 0) {
    114                 /* Get device handle first. */
    115                 devman_handle_t dev_handle;
    116                 rc = devman_device_get_handle(path, &dev_handle, 0);
    117                 if (rc != EOK) {
    118                         free(path);
    119                         return false;
    120                 }
    121 
    122                 /* Try to find its host controller. */
    123                 if (!hc_found) {
    124                         rc = usb_hc_find(dev_handle, &hc);
    125                         if (rc == EOK) {
    126                                 hc_found = true;
    127                         }
    128                 }
    129                 /* Try to get its address. */
    130                 if (!addr_found) {
    131                         addr = usb_device_get_assigned_address(dev_handle);
    132                         if (addr >= 0) {
    133                                 addr_found = true;
    134                         }
    135                 }
    136 
    137                 /* Speed-up. */
    138                 if (hc_found && addr_found) {
    139                         break;
    140                 }
    141 
    142                 /* Remove the last suffix. */
    143                 char *slash_pos = str_rchr(path, '/');
    144                 if (slash_pos != NULL) {
    145                         *slash_pos = 0;
    146                 }
    147         }
    148 
    149         free(path);
    150 
    151         if (hc_found && addr_found) {
    152                 if (out_hc_handle != NULL) {
    153                         *out_hc_handle = hc;
    154                 }
    155                 if (out_device_address != NULL) {
    156                         *out_device_address = addr;
    157                 }
    158                 return true;
    159         } else {
    160                 return false;
    161         }
    162 }
    16348
    16449static void print_usage(char *app_name)
     
    300185                devman_handle_t hc_handle = 0;
    301186                usb_address_t dev_addr = 0;
    302                 bool found = resolve_hc_handle_and_dev_addr(devpath,
    303                     &hc_handle, &dev_addr);
    304                 if (!found) {
     187                int rc = usb_resolve_device_handle(devpath,
     188                    &hc_handle, &dev_addr, NULL);
     189                if (rc != EOK) {
    305190                        fprintf(stderr, NAME ": device `%s' not found "
    306191                            "or not of USB kind, skipping.\n",
  • uspace/drv/uhci-rhd/port.h

    r74b1e40 rc9256c5  
    3838#include <fibril.h>
    3939#include <ddf/driver.h>
    40 #include <usb/dev/hc.h> /* usb_hc_connection_t */
     40#include <usb/hc.h> /* usb_hc_connection_t */
    4141
    4242typedef uint16_t port_status_t;
  • uspace/lib/usb/Makefile

    r74b1e40 rc9256c5  
    3737        src/ddfiface.c \
    3838        src/debug.c \
    39         src/driver.c \
    4039        src/dump.c \
    41         src/host.c \
     40        src/hc.c \
     41        src/resolve.c \
    4242        src/usb.c
    4343
  • uspace/lib/usb/include/usb/hc.h

    r74b1e40 rc9256c5  
    2727 */
    2828
    29 /** @addtogroup libusbdev
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * General communication between device drivers and host controller driver.
     33 * General communication with host controller driver.
    3434 */
    35 #ifndef LIBUSBDEV_HC_H_
    36 #define LIBUSBDEV_HC_H_
     35#ifndef LIBUSB_HC_H_
     36#define LIBUSB_HC_H_
    3737
    3838#include <sys/types.h>
     
    5757bool usb_hc_connection_is_opened(const usb_hc_connection_t *);
    5858int usb_hc_connection_close(usb_hc_connection_t *);
     59int usb_hc_get_handle_by_address(usb_hc_connection_t *, usb_address_t,
     60    devman_handle_t *);
    5961
     62int usb_hc_get_address_by_handle(devman_handle_t);
     63
     64int usb_hc_find(devman_handle_t, devman_handle_t *);
     65
     66int usb_resolve_device_handle(const char *, devman_handle_t *, usb_address_t *,
     67    devman_handle_t *);
     68
     69int usb_ddf_get_hc_handle_by_class(size_t, devman_handle_t *);
    6070
    6171
  • uspace/lib/usb/src/ddfiface.c

    r74b1e40 rc9256c5  
    3737#include <async.h>
    3838#include <usb/ddfiface.h>
    39 #include <usb/driver.h>
     39#include <usb/hc.h>
    4040#include <usb/debug.h>
    4141#include <errno.h>
  • uspace/lib/usb/src/hc.c

    r74b1e40 rc9256c5  
    2727 */
    2828
    29 /** @addtogroup libusbdev
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * General communication between device drivers and host controller driver.
     33 * General communication with host controller driver (implementation).
    3434 */
    3535#include <devman.h>
    3636#include <async.h>
     37#include <dev_iface.h>
    3738#include <usb_iface.h>
    38 #include <usb/dev/hc.h>
    39 #include <usb/driver.h>
     39#include <usbhc_iface.h>
     40#include <usb/hc.h>
    4041#include <usb/debug.h>
    4142#include <errno.h>
     
    143144}
    144145
     146/** Get handle of USB device with given address.
     147 *
     148 * @param[in] connection Opened connection to host controller.
     149 * @param[in] address Address of device in question.
     150 * @param[out] handle Where to write the device handle.
     151 * @return Error code.
     152 */
     153int usb_hc_get_handle_by_address(usb_hc_connection_t *connection,
     154    usb_address_t address, devman_handle_t *handle)
     155{
     156        if (!usb_hc_connection_is_opened(connection)) {
     157                return ENOENT;
     158        }
     159
     160        sysarg_t tmp;
     161        int rc = async_req_2_1(connection->hc_phone,
     162            DEV_IFACE_ID(USBHC_DEV_IFACE),
     163            IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,
     164            address, &tmp);
     165        if ((rc == EOK) && (handle != NULL)) {
     166                *handle = tmp;
     167        }
     168
     169        return rc;
     170}
     171
     172/** Tell USB address assigned to device with given handle.
     173 *
     174 * @param dev_handle Devman handle of the USB device in question.
     175 * @return USB address or negative error code.
     176 */
     177usb_address_t usb_hc_get_address_by_handle(devman_handle_t dev_handle)
     178{
     179        int parent_phone = devman_parent_device_connect(dev_handle,
     180            IPC_FLAG_BLOCKING);
     181        if (parent_phone < 0) {
     182                return parent_phone;
     183        }
     184
     185        sysarg_t address;
     186
     187        int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
     188            IPC_M_USB_GET_ADDRESS,
     189            dev_handle, &address);
     190
     191        if (rc != EOK) {
     192                return rc;
     193        }
     194
     195        async_hangup(parent_phone);
     196
     197        return (usb_address_t) address;
     198}
     199
     200
     201/** Get host controller handle by its class index.
     202 *
     203 * @param class_index Class index for the host controller.
     204 * @param hc_handle Where to store the HC handle
     205 *      (can be NULL for existence test only).
     206 * @return Error code.
     207 */
     208int usb_ddf_get_hc_handle_by_class(size_t class_index,
     209    devman_handle_t *hc_handle)
     210{
     211        char *class_index_str;
     212        devman_handle_t hc_handle_tmp;
     213        int rc;
     214
     215        rc = asprintf(&class_index_str, "%zu", class_index);
     216        if (rc < 0) {
     217                return ENOMEM;
     218        }
     219        rc = devman_device_get_handle_by_class("usbhc", class_index_str,
     220            &hc_handle_tmp, 0);
     221        free(class_index_str);
     222        if (rc != EOK) {
     223                return rc;
     224        }
     225
     226        if (hc_handle != NULL) {
     227                *hc_handle = hc_handle_tmp;
     228        }
     229
     230        return EOK;
     231}
     232
     233/** Find host controller handle that is ancestor of given device.
     234 *
     235 * @param[in] device_handle Device devman handle.
     236 * @param[out] hc_handle Where to store handle of host controller
     237 *      controlling device with @p device_handle handle.
     238 * @return Error code.
     239 */
     240int usb_hc_find(devman_handle_t device_handle, devman_handle_t *hc_handle)
     241{
     242        int parent_phone = devman_parent_device_connect(device_handle,
     243            IPC_FLAG_BLOCKING);
     244        if (parent_phone < 0) {
     245                return parent_phone;
     246        }
     247
     248        devman_handle_t h;
     249        int rc = async_req_1_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
     250            IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h);
     251
     252        async_hangup(parent_phone);
     253
     254        if (rc != EOK) {
     255                return rc;
     256        }
     257
     258        if (hc_handle != NULL) {
     259                *hc_handle = h;
     260        }
     261
     262        return EOK;
     263}
     264
    145265/**
    146266 * @}
  • uspace/lib/usbdev/Makefile

    r74b1e40 rc9256c5  
    4646        src/pipesio.c \
    4747        src/recognise.c \
    48         src/request.c \
    49         src/usbdevice.c
     48        src/request.c
    5049
    5150include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/usbdev/include/usb/dev/hub.h

    r74b1e40 rc9256c5  
    3939
    4040#include <sys/types.h>
    41 #include <usb/dev/hc.h>
     41#include <usb/hc.h>
    4242
    4343int usb_hc_new_device_wrapper(ddf_dev_t *, usb_hc_connection_t *, usb_speed_t,
     
    6363    const usb_hc_attached_device_t *);
    6464int usb_hc_unregister_device(usb_hc_connection_t *, usb_address_t);
    65 int usb_hc_get_handle_by_address(usb_hc_connection_t *, usb_address_t,
    66     devman_handle_t *);
    6765
    6866#endif
  • uspace/lib/usbdev/include/usb/dev/pipes.h

    r74b1e40 rc9256c5  
    3838#include <sys/types.h>
    3939#include <usb/usb.h>
    40 #include <usb/dev/hc.h>
     40#include <usb/hc.h>
    4141#include <usb/descriptor.h>
    4242#include <ipc/devman.h>
     
    163163
    164164int usb_device_get_assigned_interface(ddf_dev_t *);
    165 usb_address_t usb_device_get_assigned_address(devman_handle_t);
    166165
    167166int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *,
  • uspace/lib/usbdev/src/hub.c

    r74b1e40 rc9256c5  
    120120}
    121121
    122 /** Get handle of USB device with given address.
    123  *
    124  * @param[in] connection Opened connection to host controller.
    125  * @param[in] address Address of device in question.
    126  * @param[out] handle Where to write the device handle.
    127  * @return Error code.
    128  */
    129 int usb_hc_get_handle_by_address(usb_hc_connection_t *connection,
    130     usb_address_t address, devman_handle_t *handle)
    131 {
    132         CHECK_CONNECTION(connection);
    133 
    134         sysarg_t tmp;
    135         int rc = async_req_2_1(connection->hc_phone,
    136             DEV_IFACE_ID(USBHC_DEV_IFACE),
    137             IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,
    138             address, &tmp);
    139         if ((rc == EOK) && (handle != NULL)) {
    140                 *handle = tmp;
    141         }
    142 
    143         return rc;
    144 }
    145122
    146123static void unregister_control_endpoint_on_default_address(
  • uspace/lib/usbdev/src/pipes.c

    r74b1e40 rc9256c5  
    3636#include <usb/dev/pipes.h>
    3737#include <usb/debug.h>
    38 #include <usb/driver.h>
     38#include <usb/hc.h>
    3939#include <usbhc_iface.h>
    4040#include <usb_iface.h>
     
    9797
    9898        return (int) iface_no;
    99 }
    100 
    101 /** Tell USB address assigned to given device.
    102  *
    103  * @param dev_handle Devman handle of the USB device in question.
    104  * @return USB address or negative error code.
    105  */
    106 usb_address_t usb_device_get_assigned_address(devman_handle_t dev_handle)
    107 {
    108         int parent_phone = devman_parent_device_connect(dev_handle,
    109             IPC_FLAG_BLOCKING);
    110         if (parent_phone < 0) {
    111                 return parent_phone;
    112         }
    113 
    114         sysarg_t address;
    115 
    116         int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
    117             IPC_M_USB_GET_ADDRESS,
    118             dev_handle, &address);
    119 
    120         if (rc != EOK) {
    121                 return rc;
    122         }
    123 
    124         async_hangup(parent_phone);
    125 
    126         return (usb_address_t) address;
    12799}
    128100
Note: See TracChangeset for help on using the changeset viewer.