Changeset 511cfc8 in mainline


Ignore:
Timestamp:
2011-05-08T19:06:32Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
23f40280, ebf6a40
Parents:
11349a85 (diff), 7b6f116 (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:

Development branch changes

Location:
uspace
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/lsusb/main.c

    r11349a85 r511cfc8  
    4444#include <devman.h>
    4545#include <devmap.h>
     46#include <usb/hub.h>
    4647#include <usb/host.h>
    4748
    4849#define NAME "lsusb"
    4950
    50 #define MAX_FAILED_ATTEMPTS 4
     51#define MAX_FAILED_ATTEMPTS 10
    5152#define MAX_PATH_LENGTH 1024
     53
     54static void print_found_hc(size_t class_index, const char *path)
     55{
     56        // printf(NAME ": host controller %zu is `%s'.\n", class_index, path);
     57        printf("Bus %02zu: %s\n", class_index, path);
     58}
     59static void print_found_dev(usb_address_t addr, const char *path)
     60{
     61        // printf(NAME ":     device with address %d is `%s'.\n", addr, path);
     62        printf("  Device %02d: %s\n", addr, path);
     63}
     64
     65static void print_hc_devices(devman_handle_t hc_handle)
     66{
     67        int rc;
     68        usb_hc_connection_t conn;
     69
     70        usb_hc_connection_initialize(&conn, hc_handle);
     71        rc = usb_hc_connection_open(&conn);
     72        if (rc != EOK) {
     73                printf(NAME ": failed to connect to HC: %s.\n",
     74                    str_error(rc));
     75                return;
     76        }
     77        usb_address_t addr;
     78        for (addr = 1; addr < 5; addr++) {
     79                devman_handle_t dev_handle;
     80                rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle);
     81                if (rc != EOK) {
     82                        continue;
     83                }
     84                char path[MAX_PATH_LENGTH];
     85                rc = devman_get_device_path(dev_handle, path, MAX_PATH_LENGTH);
     86                if (rc != EOK) {
     87                        continue;
     88                }
     89                print_found_dev(addr, path);
     90        }
     91        usb_hc_connection_close(&conn);
     92}
    5293
    5394int main(int argc, char *argv[])
     
    69110                        continue;
    70111                }
    71                 printf(NAME ": host controller %zu is `%s'.\n",
    72                     class_index, path);
     112                print_found_hc(class_index, path);
     113                print_hc_devices(hc_handle);
    73114        }
    74115
  • uspace/drv/ehci-hcd/hc_iface.c

    r11349a85 r511cfc8  
    106106}
    107107
     108/** Find device handle by USB address.
     109 *
     110 * @param[in] fun DDF function that was called.
     111 * @param[in] address Address in question.
     112 * @param[out] handle Where to store device handle if found.
     113 * @return Error code.
     114 */
     115static int find_by_address(ddf_fun_t *fun, usb_address_t address,
     116    devman_handle_t *handle)
     117{
     118        UNSUPPORTED("find_by_address");
     119
     120        return ENOTSUP;
     121}
     122
    108123/** Release previously requested address.
    109124 *
     
    321336        .request_address = request_address,
    322337        .bind_address = bind_address,
     338        .find_by_address = find_by_address,
    323339        .release_address = release_address,
    324340
  • uspace/drv/ohci/iface.c

    r11349a85 r511cfc8  
    122122        return EOK;
    123123}
     124
     125
     126/** Find device handle by address interface function.
     127 *
     128 * @param[in] fun DDF function that was called.
     129 * @param[in] address Address in question.
     130 * @param[out] handle Where to store device handle if found.
     131 * @return Error code.
     132 */
     133static int find_by_address(ddf_fun_t *fun, usb_address_t address,
     134    devman_handle_t *handle)
     135{
     136        assert(fun);
     137        hc_t *hc = fun_to_hc(fun);
     138        assert(hc);
     139        bool found =
     140            usb_device_keeper_find_by_address(&hc->manager, address, handle);
     141        return found ? EOK : ENOENT;
     142}
     143
    124144/*----------------------------------------------------------------------------*/
    125145/** Release address interface function
     
    402422        .request_address = request_address,
    403423        .bind_address = bind_address,
     424        .find_by_address = find_by_address,
    404425        .release_address = release_address,
    405426
  • uspace/drv/ohci/root_hub.c

    r11349a85 r511cfc8  
    237237                return ENOMEM;
    238238
    239         usb_log_info("OHCI root hub with %d ports initialized.\n",
     239        usb_log_info("OHCI root hub with %zu ports initialized.\n",
    240240            instance->port_count);
    241241
  • uspace/drv/uhci-hcd/iface.c

    r11349a85 r511cfc8  
    122122        return EOK;
    123123}
     124
     125/** Find device handle by address interface function.
     126 *
     127 * @param[in] fun DDF function that was called.
     128 * @param[in] address Address in question.
     129 * @param[out] handle Where to store device handle if found.
     130 * @return Error code.
     131 */
     132static int find_by_address(ddf_fun_t *fun, usb_address_t address,
     133    devman_handle_t *handle)
     134{
     135        assert(fun);
     136        hc_t *hc = fun_to_hc(fun);
     137        assert(hc);
     138        bool found =
     139            usb_device_keeper_find_by_address(&hc->manager, address, handle);
     140        return found ? EOK : ENOENT;
     141}
     142
    124143/*----------------------------------------------------------------------------*/
    125144/** Release address interface function
     
    352371        .request_address = request_address,
    353372        .bind_address = bind_address,
     373        .find_by_address = find_by_address,
    354374        .release_address = release_address,
    355375
  • uspace/drv/vhc/connhost.c

    r11349a85 r511cfc8  
    9494}
    9595
     96/** Find device handle by address interface function.
     97 *
     98 * @param[in] fun DDF function that was called.
     99 * @param[in] address Address in question.
     100 * @param[out] handle Where to store device handle if found.
     101 * @return Error code.
     102 */
     103static int find_by_address(ddf_fun_t *fun, usb_address_t address,
     104    devman_handle_t *handle)
     105{
     106        VHC_DATA(vhc, fun);
     107        bool found =
     108            usb_device_keeper_find_by_address(&vhc->dev_keeper, address, handle);
     109        return found ? EOK : ENOENT;
     110}
     111
    96112/** Release previously requested address.
    97113 *
     
    444460        .request_address = request_address,
    445461        .bind_address = bind_address,
     462        .find_by_address = find_by_address,
    446463        .release_address = release_address,
    447464
  • uspace/lib/drv/generic/remote_usbhc.c

    r11349a85 r511cfc8  
    5252static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    5353static void remote_usbhc_bind_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     54static void remote_usbhc_find_by_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    5455static void remote_usbhc_release_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    5556static void remote_usbhc_register_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     
    6162        remote_usbhc_request_address,
    6263        remote_usbhc_bind_address,
     64        remote_usbhc_find_by_address,
    6365        remote_usbhc_release_address,
    6466
     
    161163
    162164        async_answer_0(callid, rc);
     165}
     166
     167void remote_usbhc_find_by_address(ddf_fun_t *fun, void *iface,
     168    ipc_callid_t callid, ipc_call_t *call)
     169{
     170        usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     171
     172        if (!usb_iface->find_by_address) {
     173                async_answer_0(callid, ENOTSUP);
     174                return;
     175        }
     176
     177        usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
     178        devman_handle_t handle;
     179        int rc = usb_iface->find_by_address(fun, address, &handle);
     180
     181        if (rc == EOK) {
     182                async_answer_1(callid, EOK, handle);
     183        } else {
     184                async_answer_0(callid, rc);
     185        }
    163186}
    164187
  • uspace/lib/drv/include/usb_iface.h

    r11349a85 r511cfc8  
    4949         * - arbitrary error code if returned by remote implementation
    5050         * - EOK - handle found, first parameter contains the USB address
     51         *
     52         * The handle must be the one used for binding USB address with
     53         * it (IPC_M_USBHC_BIND_ADDRESS), otherwise the host controller
     54         * (that this request would eventually reach) would not be able
     55         * to find it.
     56         * The problem is that this handle is actually assigned to the
     57         * function inside driver of the parent device (usually hub driver).
     58         * To bypass this problem, the initial caller specify handle as
     59         * zero and the first parent assigns the actual value.
     60         * See usb_iface_get_address_hub_child_impl() implementation
     61         * that could be assigned to device ops of a child device of in a
     62         * hub driver.
     63         * For example, the USB multi interface device driver (MID)
     64         * passes this initial zero without any modification because the
     65         * handle must be resolved by its parent.
    5166         */
    5267        IPC_M_USB_GET_ADDRESS,
  • uspace/lib/drv/include/usbhc_iface.h

    r11349a85 r511cfc8  
    105105        IPC_M_USBHC_BIND_ADDRESS,
    106106
     107        /** Get handle binded with given USB address.
     108         * Parameters
     109         * - USB address
     110         * Answer:
     111         * - EOK - address binded, first parameter is the devman handle
     112         * - ENOENT - address is not in use at the moment
     113         */
     114        IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,
     115
    107116        /** Release address in use.
    108117         * Arguments:
     
    207216        int (*request_address)(ddf_fun_t *, usb_speed_t, usb_address_t *);
    208217        int (*bind_address)(ddf_fun_t *, usb_address_t, devman_handle_t);
     218        int (*find_by_address)(ddf_fun_t *, usb_address_t, devman_handle_t *);
    209219        int (*release_address)(ddf_fun_t *, usb_address_t);
    210220
  • uspace/lib/usb/include/usb/host/device_keeper.h

    r11349a85 r511cfc8  
    8080    devman_handle_t handle);
    8181
     82bool usb_device_keeper_find_by_address(usb_device_keeper_t *instance,
     83    usb_address_t address, devman_handle_t *handle);
     84
    8285usb_speed_t usb_device_keeper_get_speed(usb_device_keeper_t *instance,
    8386    usb_address_t address);
  • uspace/lib/usb/include/usb/hub.h

    r11349a85 r511cfc8  
    6363    const usb_hc_attached_device_t *);
    6464int usb_hc_unregister_device(usb_hc_connection_t *, usb_address_t);
     65int usb_hc_get_handle_by_address(usb_hc_connection_t *, usb_address_t,
     66    devman_handle_t *);
    6567
    6668#endif
  • uspace/lib/usb/src/host/device_keeper.c

    r11349a85 r511cfc8  
    157157        return ENOENT;
    158158}
     159
     160/** Find devman handled assigned to USB address.
     161 *
     162 * @param[in] instance Device keeper structure to use.
     163 * @param[in] address Address the caller wants to find.
     164 * @param[out] handle Where to store found handle.
     165 * @return Whether such address is currently occupied.
     166 */
     167bool usb_device_keeper_find_by_address(usb_device_keeper_t *instance,
     168    usb_address_t address, devman_handle_t *handle)
     169{
     170        assert(instance);
     171        fibril_mutex_lock(&instance->guard);
     172        if ((address < 0) || (address >= USB_ADDRESS_COUNT)) {
     173                fibril_mutex_unlock(&instance->guard);
     174                return false;
     175        }
     176        if (!instance->devices[address].occupied) {
     177                fibril_mutex_unlock(&instance->guard);
     178                return false;
     179        }
     180
     181        if (handle != NULL) {
     182                *handle = instance->devices[address].handle;
     183        }
     184
     185        fibril_mutex_unlock(&instance->guard);
     186        return true;
     187}
     188
    159189/*----------------------------------------------------------------------------*/
    160190/** Get speed associated with the address
  • uspace/lib/usb/src/hub.c

    r11349a85 r511cfc8  
    117117            DEV_IFACE_ID(USBHC_DEV_IFACE),
    118118            IPC_M_USBHC_RELEASE_ADDRESS, address);
     119}
     120
     121/** Get handle of USB device with given address.
     122 *
     123 * @param[in] connection Opened connection to host controller.
     124 * @param[in] address Address of device in question.
     125 * @param[out] handle Where to write the device handle.
     126 * @return Error code.
     127 */
     128int usb_hc_get_handle_by_address(usb_hc_connection_t *connection,
     129    usb_address_t address, devman_handle_t *handle)
     130{
     131        CHECK_CONNECTION(connection);
     132
     133        sysarg_t tmp;
     134        int rc = async_req_2_1(connection->hc_phone,
     135            DEV_IFACE_ID(USBHC_DEV_IFACE),
     136            IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,
     137            address, &tmp);
     138        if ((rc == EOK) && (handle != NULL)) {
     139                *handle = tmp;
     140        }
     141
     142        return rc;
    119143}
    120144
Note: See TracChangeset for help on using the changeset viewer.