Changeset d9b2c73 in mainline


Ignore:
Timestamp:
2012-12-20T13:22:34Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d09791e6
Parents:
8f68913f
Message:

libusbhost: Add hcd parameter to batch scheduling and move implementaiotn to hcd.c

Location:
uspace/lib/usbhost
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/hcd.h

    r8f68913f rd9b2c73  
    9797}
    9898
     99int hcd_send_batch(
     100    hcd_t *hcd, ddf_fun_t *fun, usb_target_t target, usb_direction_t direction,
     101    void *data, size_t size, uint64_t setup_data,
     102    usbhc_iface_transfer_in_callback_t in,
     103    usbhc_iface_transfer_out_callback_t out, void *arg, const char* name);
    99104
    100105int hcd_add_device(hcd_t *instance, ddf_dev_t *parent,
  • uspace/lib/usbhost/src/hcd.c

    r8f68913f rd9b2c73  
    184184}
    185185
     186/** Prepare generic usb_transfer_batch and schedule it.
     187 * @param hcd Host controller driver.
     188 * @param fun DDF fun
     189 * @param target address and endpoint number.
     190 * @param setup_data Data to use in setup stage (Control communication type)
     191 * @param in Callback for device to host communication.
     192 * @param out Callback for host to device communication.
     193 * @param arg Callback parameter.
     194 * @param name Communication identifier (for nicer output).
     195 * @return Error code.
     196 */
     197int hcd_send_batch(
     198    hcd_t *hcd, ddf_fun_t *fun, usb_target_t target, usb_direction_t direction,
     199    void *data, size_t size, uint64_t setup_data,
     200    usbhc_iface_transfer_in_callback_t in,
     201    usbhc_iface_transfer_out_callback_t out, void *arg, const char* name)
     202{
     203        assert(hcd);
     204
     205        endpoint_t *ep = usb_endpoint_manager_find_ep(&hcd->ep_manager,
     206            target.address, target.endpoint, direction);
     207        if (ep == NULL) {
     208                usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
     209                    target.address, target.endpoint, name);
     210                return ENOENT;
     211        }
     212
     213        usb_log_debug2("%s %d:%d %zu(%zu).\n",
     214            name, target.address, target.endpoint, size, ep->max_packet_size);
     215
     216        const size_t bw = bandwidth_count_usb11(
     217            ep->speed, ep->transfer_type, size, ep->max_packet_size);
     218        /* Check if we have enough bandwidth reserved */
     219        if (ep->bandwidth < bw) {
     220                usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
     221                    "but only %zu is reserved.\n",
     222                    ep->address, ep->endpoint, name, bw, ep->bandwidth);
     223                return ENOSPC;
     224        }
     225        if (!hcd->schedule) {
     226                usb_log_error("HCD does not implement scheduler.\n");
     227                return ENOTSUP;
     228        }
     229
     230        /* No private data and no private data dtor */
     231        usb_transfer_batch_t *batch =
     232            usb_transfer_batch_create(ep, data, size, setup_data,
     233            in, out, arg, fun, NULL, NULL);
     234        if (!batch) {
     235                return ENOMEM;
     236        }
     237
     238        const int ret = hcd->schedule(hcd, batch);
     239        if (ret != EOK)
     240                usb_transfer_batch_destroy(batch);
     241
     242        return ret;
     243}
     244
     245
    186246/** Announce root hub to the DDF
    187247 *
  • uspace/lib/usbhost/src/iface.c

    r8f68913f rd9b2c73  
    4141#include <usb/host/hcd.h>
    4242
    43 /** Prepare generic usb_transfer_batch and schedule it.
    44  * @param fun DDF fun
    45  * @param target address and endpoint number.
    46  * @param setup_data Data to use in setup stage (Control communication type)
    47  * @param in Callback for device to host communication.
    48  * @param out Callback for host to device communication.
    49  * @param arg Callback parameter.
    50  * @param name Communication identifier (for nicer output).
    51  * @return Error code.
    52  */
    53 static inline int send_batch(
    54     ddf_fun_t *fun, usb_target_t target, usb_direction_t direction,
    55     void *data, size_t size, uint64_t setup_data,
    56     usbhc_iface_transfer_in_callback_t in,
    57     usbhc_iface_transfer_out_callback_t out, void *arg, const char* name)
    58 {
    59         assert(fun);
    60         hcd_t *hcd = fun_to_hcd(fun);
    61         assert(hcd);
    62 
    63         endpoint_t *ep = usb_endpoint_manager_find_ep(&hcd->ep_manager,
    64             target.address, target.endpoint, direction);
    65         if (ep == NULL) {
    66                 usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
    67                     target.address, target.endpoint, name);
    68                 return ENOENT;
    69         }
    70 
    71         usb_log_debug2("%s %d:%d %zu(%zu).\n",
    72             name, target.address, target.endpoint, size, ep->max_packet_size);
    73 
    74         const size_t bw = bandwidth_count_usb11(
    75             ep->speed, ep->transfer_type, size, ep->max_packet_size);
    76         /* Check if we have enough bandwidth reserved */
    77         if (ep->bandwidth < bw) {
    78                 usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
    79                     "but only %zu is reserved.\n",
    80                     ep->address, ep->endpoint, name, bw, ep->bandwidth);
    81                 return ENOSPC;
    82         }
    83         if (!hcd->schedule) {
    84                 usb_log_error("HCD does not implement scheduler.\n");
    85                 return ENOTSUP;
    86         }
    87 
    88         /* No private data and no private data dtor */
    89         usb_transfer_batch_t *batch =
    90             usb_transfer_batch_create(ep, data, size, setup_data,
    91             in, out, arg, fun, NULL, NULL);
    92         if (!batch) {
    93                 return ENOMEM;
    94         }
    95 
    96         const int ret = hcd->schedule(hcd, batch);
    97         if (ret != EOK)
    98                 usb_transfer_batch_destroy(batch);
    99 
    100         return ret;
    101 }
    102 
    10343/** Calls ep_add_hook upon endpoint registration.
    10444 * @param ep Endpoint to be registered.
     
    291231    void *arg)
    292232{
    293         return send_batch(fun, target, USB_DIRECTION_IN, data, size,
    294             setup_data, callback, NULL, arg, "READ");
     233        return hcd_send_batch(fun_to_hcd(fun), fun, target, USB_DIRECTION_IN,
     234            data, size, setup_data, callback, NULL, arg, "READ");
    295235}
    296236
     
    309249    usbhc_iface_transfer_out_callback_t callback, void *arg)
    310250{
    311         return send_batch(fun, target, USB_DIRECTION_OUT, (uint8_t*)data, size,
    312             setup_data, NULL, callback, arg, "WRITE");
     251        return hcd_send_batch(fun_to_hcd(fun), fun, target, USB_DIRECTION_OUT,
     252            (uint8_t*)data, size, setup_data, NULL, callback, arg, "WRITE");
    313253}
    314254
Note: See TracChangeset for help on using the changeset viewer.