Changeset 4267908 in mainline


Ignore:
Timestamp:
2011-10-27T10:45:08Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update
Children:
83c3123
Parents:
069b80d
Message:

libusbhost: Merge find_by_address and get_speed.

These functions were almost identical.
Clear handle on address release.

Location:
uspace
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/ohci.c

    r069b80d r4267908  
    8989            &dev_to_ohci(fun->dev)->hc.generic.dev_manager;
    9090
    91         const usb_address_t addr = usb_device_manager_find(manager, handle);
     91        const usb_address_t addr =
     92            usb_device_manager_find_address(manager, handle);
    9293        if (addr < 0) {
    9394                return addr;
  • uspace/drv/bus/usb/uhci/uhci.c

    r069b80d r4267908  
    101101        usb_device_manager_t *manager =
    102102            &dev_to_uhci(fun->dev)->hc.generic.dev_manager;
    103         const usb_address_t addr = usb_device_manager_find(manager, handle);
     103        const usb_address_t addr =
     104            usb_device_manager_find_address(manager, handle);
    104105
    105106        if (addr < 0) {
  • uspace/drv/bus/usb/vhc/connhost.c

    r069b80d r4267908  
    104104{
    105105        VHC_DATA(vhc, fun);
    106         bool found =
    107             usb_device_manager_find_by_address(&vhc->dev_manager, address, handle);
    108         return found ? EOK : ENOENT;
     106        return usb_device_manager_get_info_by_address(
     107            &vhc->dev_manager, address, handle, NULL);
    109108}
    110109
     
    518517
    519518        usb_log_debug("tell_address_rh(handle=%" PRIun ")\n", handle);
    520         usb_address_t addr = usb_device_manager_find(&vhc->dev_manager, handle);
     519        const usb_address_t addr =
     520            usb_device_manager_find_address(&vhc->dev_manager, handle);
    521521        if (addr < 0) {
    522522                return addr;
  • uspace/lib/usbhost/include/usb/host/usb_device_manager.h

    r069b80d r4267908  
    4949#define USB_ADDRESS_COUNT (USB11_ADDRESS_MAX + 1)
    5050
    51 /** Information about attached USB device. */
    52 struct usb_device_info {
    53         usb_speed_t speed;
    54         bool occupied;
    55         devman_handle_t handle;
    56 };
    57 
    5851/** Host controller device manager.
    59  * You shall not access members directly but only using functions below.
     52 * You shall not access members directly.
    6053 */
    6154typedef struct {
    62         struct usb_device_info devices[USB_ADDRESS_COUNT];
     55        /** Information about attached USB devices. */
     56        struct {
     57                usb_speed_t speed;      /**< Device speed */
     58                bool occupied;          /**< The address is in use. */
     59                devman_handle_t handle; /**< Devman handle of the device. */
     60        } devices[USB_ADDRESS_COUNT];
    6361        fibril_mutex_t guard;
     62        /** The last reserved address */
    6463        usb_address_t last_address;
    6564} usb_device_manager_t;
     
    7675    usb_address_t address);
    7776
    78 usb_address_t usb_device_manager_find(usb_device_manager_t *instance,
     77usb_address_t usb_device_manager_find_address(usb_device_manager_t *instance,
    7978    devman_handle_t handle);
    8079
    81 bool usb_device_manager_find_by_address(usb_device_manager_t *instance,
    82     usb_address_t address, devman_handle_t *handle);
    83 
    84 usb_speed_t usb_device_manager_get_speed(usb_device_manager_t *instance,
    85     usb_address_t address);
     80int usb_device_manager_get_info_by_address(usb_device_manager_t *instance,
     81    usb_address_t address, devman_handle_t *handle, usb_speed_t *speed);
    8682#endif
    8783/**
  • uspace/lib/usbhost/src/iface.c

    r069b80d r4267908  
    147147        hcd_t *hcd = fun_to_hcd(fun);
    148148        assert(hcd);
    149         const bool found =
    150             usb_device_manager_find_by_address(&hcd->dev_manager, address, handle);
    151         return found ? EOK : ENOENT;
     149        return usb_device_manager_get_info_by_address(
     150            &hcd->dev_manager, address, handle, NULL);
    152151}
    153152/*----------------------------------------------------------------------------*/
     
    180179        /* Default address is not bound or registered,
    181180         * thus it does not provide speed info. */
    182         const usb_speed_t speed = (address == 0) ? ep_speed :
    183             usb_device_manager_get_speed(&hcd->dev_manager, address);
     181        usb_speed_t speed = ep_speed;
     182        /* NOTE The function will return EINVAL and won't
     183         * touch speed variable for default address */
     184        usb_device_manager_get_info_by_address(
     185            &hcd->dev_manager, address, NULL, &speed);
    184186
    185187        usb_log_debug("Register endpoint %d:%d %s-%s %s %zuB %ums.\n",
     
    192194        if (!ep)
    193195                return ENOMEM;
    194         int ret = EOK;
    195196
    196197        if (hcd->ep_add_hook) {
    197                 ret = hcd->ep_add_hook(hcd, ep);
    198         }
    199         if (ret != EOK) {
    200                 endpoint_destroy(ep);
    201                 return ret;
    202         }
    203 
    204         ret = usb_endpoint_manager_register_ep(&hcd->ep_manager, ep, size);
     198                const int ret = hcd->ep_add_hook(hcd, ep);
     199                if (ret != EOK) {
     200                        endpoint_destroy(ep);
     201                        return ret;
     202                }
     203        }
     204
     205        const int ret =
     206            usb_endpoint_manager_register_ep(&hcd->ep_manager, ep, size);
    205207        if (ret != EOK) {
    206208                endpoint_destroy(ep);
  • uspace/lib/usbhost/src/usb_device_manager.c

    r069b80d r4267908  
    3838#include <usb/host/usb_device_manager.h>
    3939
    40 /*----------------------------------------------------------------------------*/
    4140/** Initialize device manager structure.
    4241 *
     
    7776                ++new_address;
    7877                if (new_address > USB11_ADDRESS_MAX)
    79                         new_address = 1;
     78                        new_address = 1; // NOTE it should be safe to put 0 here
     79                                         // TODO Use mod
    8080                if (new_address == instance->last_address) {
    8181                        fibril_mutex_unlock(&instance->guard);
     
    8686        assert(new_address != USB_ADDRESS_DEFAULT);
    8787        assert(instance->devices[new_address].occupied == false);
     88        assert(instance->devices[new_address].handle == 0);
    8889
    8990        instance->devices[new_address].occupied = true;
     
    131132
    132133        instance->devices[address].occupied = false;
     134        instance->devices[address].handle = 0;
    133135        fibril_mutex_unlock(&instance->guard);
    134136}
     
    140142 * @return USB Address, or error code.
    141143 */
    142 usb_address_t usb_device_manager_find(
     144usb_address_t usb_device_manager_find_address(
    143145    usb_device_manager_t *instance, devman_handle_t handle)
    144146{
     
    157159        return ENOENT;
    158160}
    159 
    160 /** Find devman handle assigned to USB address.
    161  * Intentionally refuse to find handle of default address.
     161/*----------------------------------------------------------------------------*/
     162/** Find devman handle and speed assigned to USB address.
     163 * Intentionally refuse to work on default address.
    162164 *
    163165 * @param[in] instance Device manager structure to use.
    164166 * @param[in] address Address the caller wants to find.
    165167 * @param[out] handle Where to store found handle.
    166  * @return Whether such address is currently occupied.
     168 * @param[out] speed Assigned speed.
     169 * @return Error code.
    167170 */
    168 bool usb_device_manager_find_by_address(usb_device_manager_t *instance,
    169     usb_address_t address, devman_handle_t *handle)
     171int usb_device_manager_get_info_by_address(usb_device_manager_t *instance,
     172    usb_address_t address, devman_handle_t *handle, usb_speed_t *speed)
    170173{
    171174        assert(instance);
     175        if ((address <= 0) || (address >= USB_ADDRESS_COUNT)) {
     176                return EINVAL;
     177        }
     178
    172179        fibril_mutex_lock(&instance->guard);
    173         if ((address <= 0) || (address >= USB_ADDRESS_COUNT)) {
    174                 fibril_mutex_unlock(&instance->guard);
    175                 return false;
    176         }
    177180        if (!instance->devices[address].occupied) {
    178181                fibril_mutex_unlock(&instance->guard);
    179                 return false;
     182                return ENOENT;
    180183        }
    181184
     
    183186                *handle = instance->devices[address].handle;
    184187        }
     188        if (speed != NULL) {
     189                *speed = instance->devices[address].speed;
     190        }
    185191
    186192        fibril_mutex_unlock(&instance->guard);
    187         return true;
    188 }
    189 
    190 /*----------------------------------------------------------------------------*/
    191 /** Get speed associated with the address
    192  *
    193  * @param[in] instance Device manager structure to use.
    194  * @param[in] address Address of the device.
    195  * @return USB speed.
    196  */
    197 usb_speed_t usb_device_manager_get_speed(
    198     usb_device_manager_t *instance, usb_address_t address)
    199 {
    200         assert(instance);
    201         assert(address >= 0);
    202         assert(address <= USB11_ADDRESS_MAX);
    203 
    204         return instance->devices[address].speed;
     193        return EOK;
    205194}
    206195/**
Note: See TracChangeset for help on using the changeset viewer.