Changeset 50114ef in mainline for uspace/drv/ohci/iface.c


Ignore:
Timestamp:
2011-03-24T13:45:48Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
915a851
Parents:
5f80527 (diff), e18e0d6 (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:

Merge development/ changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/iface.c

    r5f80527 r50114ef  
    3333 */
    3434#include <ddf/driver.h>
    35 #include <ddf/interrupt.h>
    36 #include <device/hw_res.h>
    3735#include <errno.h>
    38 #include <str_error.h>
    39 
    40 #include <usb_iface.h>
    41 #include <usb/ddfiface.h>
     36
    4237#include <usb/debug.h>
    4338
     
    6055static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
    6156{
    62   assert(fun);
    63   hc_t *hc = fun_to_hc(fun);
    64   assert(hc);
    65   usb_log_debug("Default address request with speed %d.\n", speed);
    66   usb_device_keeper_reserve_default_address(&hc->manager, speed);
    67   return EOK;
     57        assert(fun);
     58        hc_t *hc = fun_to_hc(fun);
     59        assert(hc);
     60        usb_log_debug("Default address request with speed %d.\n", speed);
     61        usb_device_keeper_reserve_default_address(&hc->manager, speed);
     62        return EOK;
    6863}
    6964/*----------------------------------------------------------------------------*/
     
    7570static int release_default_address(ddf_fun_t *fun)
    7671{
    77   assert(fun);
    78   hc_t *hc = fun_to_hc(fun);
    79   assert(hc);
    80   usb_log_debug("Default address release.\n");
    81   usb_device_keeper_release_default_address(&hc->manager);
    82   return EOK;
     72        assert(fun);
     73        hc_t *hc = fun_to_hc(fun);
     74        assert(hc);
     75        usb_log_debug("Default address release.\n");
     76        usb_device_keeper_release_default_address(&hc->manager);
     77        return EOK;
    8378}
    8479/*----------------------------------------------------------------------------*/
     
    9085 * @return Error code.
    9186 */
    92 static int request_address(ddf_fun_t *fun, usb_speed_t speed,
    93     usb_address_t *address)
    94 {
    95   assert(fun);
    96   hc_t *hc = fun_to_hc(fun);
    97   assert(hc);
    98   assert(address);
    99 
    100   usb_log_debug("Address request with speed %d.\n", speed);
    101   *address = device_keeper_get_free_address(&hc->manager, speed);
    102   usb_log_debug("Address request with result: %d.\n", *address);
    103   if (*address <= 0)
    104     return *address;
    105   return EOK;
     87static int request_address(
     88    ddf_fun_t *fun, usb_speed_t speed, usb_address_t *address)
     89{
     90        assert(fun);
     91        hc_t *hc = fun_to_hc(fun);
     92        assert(hc);
     93        assert(address);
     94
     95        usb_log_debug("Address request with speed %d.\n", speed);
     96        *address = device_keeper_get_free_address(&hc->manager, speed);
     97        usb_log_debug("Address request with result: %d.\n", *address);
     98        if (*address <= 0)
     99                return *address;
     100        return EOK;
    106101}
    107102/*----------------------------------------------------------------------------*/
     
    113108 * @return Error code.
    114109 */
    115 static int bind_address(ddf_fun_t *fun,
    116     usb_address_t address, devman_handle_t handle)
    117 {
    118   assert(fun);
    119   hc_t *hc = fun_to_hc(fun);
    120   assert(hc);
    121   usb_log_debug("Address bind %d-%d.\n", address, handle);
    122   usb_device_keeper_bind(&hc->manager, address, handle);
    123   return EOK;
     110static int bind_address(
     111    ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
     112{
     113        assert(fun);
     114        hc_t *hc = fun_to_hc(fun);
     115        assert(hc);
     116        usb_log_debug("Address bind %d-%d.\n", address, handle);
     117        usb_device_keeper_bind(&hc->manager, address, handle);
     118        return EOK;
    124119}
    125120/*----------------------------------------------------------------------------*/
     
    132127static int release_address(ddf_fun_t *fun, usb_address_t address)
    133128{
    134   assert(fun);
    135   hc_t *hc = fun_to_hc(fun);
    136   assert(hc);
    137   usb_log_debug("Address release %d.\n", address);
    138   usb_device_keeper_release(&hc->manager, address);
    139   return EOK;
    140 }
    141 
     129        assert(fun);
     130        hc_t *hc = fun_to_hc(fun);
     131        assert(hc);
     132        usb_log_debug("Address release %d.\n", address);
     133        usb_device_keeper_release(&hc->manager, address);
     134        return EOK;
     135}
     136/*----------------------------------------------------------------------------*/
    142137/** Register endpoint for bandwidth reservation.
    143138 *
     
    151146 * @return Error code.
    152147 */
    153 static int register_endpoint(ddf_fun_t *fun,
    154     usb_address_t address, usb_endpoint_t endpoint,
     148static int register_endpoint(
     149    ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint,
    155150    usb_transfer_type_t transfer_type, usb_direction_t direction,
    156151    size_t max_packet_size, unsigned int interval)
     
    160155        return ENOTSUP;
    161156}
    162 
     157/*----------------------------------------------------------------------------*/
    163158/** Unregister endpoint (free some bandwidth reservation).
    164159 *
     
    169164 * @return Error code.
    170165 */
    171 static int unregister_endpoint(ddf_fun_t *fun, usb_address_t address,
     166static int unregister_endpoint(
     167    ddf_fun_t *fun, usb_address_t address,
    172168    usb_endpoint_t endpoint, usb_direction_t direction)
    173169{
     
    194190 * @return Error code.
    195191 */
    196 static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
    197     size_t max_packet_size, void *data, size_t size,
    198     usbhc_iface_transfer_out_callback_t callback, void *arg)
    199 {
    200   hc_t *hc = fun_to_hc(fun);
    201   assert(hc);
    202   usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
    203 
    204   usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
    205       target.address, target.endpoint, size, max_packet_size);
    206 
    207   usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    208       max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    209       &hc->manager);
    210   if (!batch)
    211     return ENOMEM;
    212   batch_interrupt_out(batch);
    213   const int ret = hc_schedule(hc, batch);
    214   if (ret != EOK) {
    215     batch_dispose(batch);
    216     return ret;
    217   }
    218   return EOK;
     192static int interrupt_out(
     193    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     194    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
     195{
     196        assert(fun);
     197        hc_t *hc = fun_to_hc(fun);
     198        assert(hc);
     199        usb_speed_t speed =
     200            usb_device_keeper_get_speed(&hc->manager, target.address);
     201
     202        usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
     203            target.address, target.endpoint, size, max_packet_size);
     204
     205        usb_transfer_batch_t *batch =
     206            batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
     207                speed, data, size, NULL, 0, NULL, callback, arg, &hc->manager);
     208        if (!batch)
     209                return ENOMEM;
     210        batch_interrupt_out(batch);
     211        const int ret = hc_schedule(hc, batch);
     212        if (ret != EOK) {
     213                batch_dispose(batch);
     214        }
     215        return ret;
    219216}
    220217/*----------------------------------------------------------------------------*/
     
    236233 * @return Error code.
    237234 */
    238 static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
    239     size_t max_packet_size, void *data, size_t size,
    240     usbhc_iface_transfer_in_callback_t callback, void *arg)
    241 {
    242   assert(fun);
    243   hc_t *hc = fun_to_hc(fun);
    244   assert(hc);
    245   usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
    246   usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
    247       target.address, target.endpoint, size, max_packet_size);
    248 
    249   usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    250       max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    251       &hc->manager);
    252   if (!batch)
    253     return ENOMEM;
    254   batch_interrupt_in(batch);
    255   const int ret = hc_schedule(hc, batch);
    256   if (ret != EOK) {
    257     batch_dispose(batch);
    258     return ret;
    259   }
    260   return EOK;
     235static int interrupt_in(
     236    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     237    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
     238{
     239        assert(fun);
     240        hc_t *hc = fun_to_hc(fun);
     241        assert(hc);
     242        usb_speed_t speed =
     243            usb_device_keeper_get_speed(&hc->manager, target.address);
     244        usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
     245            target.address, target.endpoint, size, max_packet_size);
     246
     247        usb_transfer_batch_t *batch =
     248            batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
     249                speed, data, size, NULL, 0, callback, NULL, arg, &hc->manager);
     250        if (!batch)
     251                return ENOMEM;
     252        batch_interrupt_in(batch);
     253        const int ret = hc_schedule(hc, batch);
     254        if (ret != EOK) {
     255                batch_dispose(batch);
     256        }
     257        return ret;
    261258}
    262259/*----------------------------------------------------------------------------*/
     
    278275 * @return Error code.
    279276 */
    280 static int bulk_out(ddf_fun_t *fun, usb_target_t target,
    281     size_t max_packet_size, void *data, size_t size,
    282     usbhc_iface_transfer_out_callback_t callback, void *arg)
    283 {
    284   assert(fun);
    285   hc_t *hc = fun_to_hc(fun);
    286   assert(hc);
    287   usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
    288 
    289   usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
    290       target.address, target.endpoint, size, max_packet_size);
    291 
    292   usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    293       max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    294       &hc->manager);
    295   if (!batch)
    296     return ENOMEM;
    297   batch_bulk_out(batch);
    298   const int ret = hc_schedule(hc, batch);
    299   if (ret != EOK) {
    300     batch_dispose(batch);
    301     return ret;
    302   }
    303   return EOK;
    304 
     277static int bulk_out(
     278    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     279    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
     280{
     281        assert(fun);
     282        hc_t *hc = fun_to_hc(fun);
     283        assert(hc);
     284        usb_speed_t speed =
     285            usb_device_keeper_get_speed(&hc->manager, target.address);
     286
     287        usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
     288            target.address, target.endpoint, size, max_packet_size);
     289
     290        usb_transfer_batch_t *batch =
     291            batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
     292                data, size, NULL, 0, NULL, callback, arg, &hc->manager);
     293        if (!batch)
     294                return ENOMEM;
     295        batch_bulk_out(batch);
     296        const int ret = hc_schedule(hc, batch);
     297        if (ret != EOK) {
     298                batch_dispose(batch);
     299        }
     300        return ret;
    305301}
    306302/*----------------------------------------------------------------------------*/
     
    322318 * @return Error code.
    323319 */
    324 static int bulk_in(ddf_fun_t *fun, usb_target_t target,
    325     size_t max_packet_size, void *data, size_t size,
    326     usbhc_iface_transfer_in_callback_t callback, void *arg)
    327 {
    328   assert(fun);
    329   hc_t *hc = fun_to_hc(fun);
    330   assert(hc);
    331   usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
    332   usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
    333       target.address, target.endpoint, size, max_packet_size);
    334 
    335   usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    336       max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    337       &hc->manager);
    338   if (!batch)
    339     return ENOMEM;
    340   batch_bulk_in(batch);
    341   const int ret = hc_schedule(hc, batch);
    342   if (ret != EOK) {
    343     batch_dispose(batch);
    344     return ret;
    345   }
    346   return EOK;
     320static int bulk_in(
     321    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     322    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
     323{
     324        assert(fun);
     325        hc_t *hc = fun_to_hc(fun);
     326        assert(hc);
     327        usb_speed_t speed =
     328            usb_device_keeper_get_speed(&hc->manager, target.address);
     329        usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
     330            target.address, target.endpoint, size, max_packet_size);
     331
     332        usb_transfer_batch_t *batch =
     333            batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
     334                data, size, NULL, 0, callback, NULL, arg, &hc->manager);
     335        if (!batch)
     336                return ENOMEM;
     337        batch_bulk_in(batch);
     338        const int ret = hc_schedule(hc, batch);
     339        if (ret != EOK) {
     340                batch_dispose(batch);
     341        }
     342        return ret;
    347343}
    348344/*----------------------------------------------------------------------------*/
     
    367363 * @return Error code.
    368364 */
    369 static int control_write(ddf_fun_t *fun, usb_target_t target,
    370     size_t max_packet_size,
    371     void *setup_data, size_t setup_size,
    372     void *data, size_t size,
     365static int control_write(
     366    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
     367    void *setup_data, size_t setup_size, void *data, size_t size,
    373368    usbhc_iface_transfer_out_callback_t callback, void *arg)
    374369{
    375   assert(fun);
    376   hc_t *hc = fun_to_hc(fun);
    377   assert(hc);
    378   usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
    379   usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
    380       speed, target.address, target.endpoint, size, max_packet_size);
    381 
    382   if (setup_size != 8)
    383     return EINVAL;
    384 
    385   usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    386       max_packet_size, speed, data, size, setup_data, setup_size,
    387       NULL, callback, arg, &hc->manager);
    388   if (!batch)
    389     return ENOMEM;
    390   usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
    391   batch_control_write(batch);
    392   const int ret = hc_schedule(hc, batch);
    393   if (ret != EOK) {
    394     batch_dispose(batch);
    395     return ret;
    396   }
    397   return EOK;
     370        assert(fun);
     371        hc_t *hc = fun_to_hc(fun);
     372        assert(hc);
     373        usb_speed_t speed =
     374            usb_device_keeper_get_speed(&hc->manager, target.address);
     375        usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
     376            speed, target.address, target.endpoint, size, max_packet_size);
     377
     378        if (setup_size != 8)
     379                return EINVAL;
     380
     381        usb_transfer_batch_t *batch =
     382            batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size,
     383                speed, data, size, setup_data, setup_size, NULL, callback, arg,
     384                &hc->manager);
     385        if (!batch)
     386                return ENOMEM;
     387        usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
     388        batch_control_write(batch);
     389        const int ret = hc_schedule(hc, batch);
     390        if (ret != EOK) {
     391                batch_dispose(batch);
     392        }
     393        return ret;
    398394}
    399395/*----------------------------------------------------------------------------*/
     
    418414 * @return Error code.
    419415 */
    420 static int control_read(ddf_fun_t *fun, usb_target_t target,
    421     size_t max_packet_size,
    422     void *setup_data, size_t setup_size,
    423     void *data, size_t size,
     416static int control_read(
     417    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
     418    void *setup_data, size_t setup_size, void *data, size_t size,
    424419    usbhc_iface_transfer_in_callback_t callback, void *arg)
    425420{
    426   assert(fun);
    427   hc_t *hc = fun_to_hc(fun);
    428   assert(hc);
    429   usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
    430 
    431   usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
    432       speed, target.address, target.endpoint, size, max_packet_size);
    433   usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    434       max_packet_size, speed, data, size, setup_data, setup_size, callback,
    435       NULL, arg, &hc->manager);
    436   if (!batch)
    437     return ENOMEM;
    438   batch_control_read(batch);
    439   const int ret = hc_schedule(hc, batch);
    440   if (ret != EOK) {
    441     batch_dispose(batch);
    442     return ret;
    443   }
    444   return EOK;
     421        assert(fun);
     422        hc_t *hc = fun_to_hc(fun);
     423        assert(hc);
     424        usb_speed_t speed =
     425            usb_device_keeper_get_speed(&hc->manager, target.address);
     426
     427        usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
     428            speed, target.address, target.endpoint, size, max_packet_size);
     429        usb_transfer_batch_t *batch =
     430            batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size,
     431                speed, data, size, setup_data, setup_size, callback, NULL, arg,
     432                &hc->manager);
     433        if (!batch)
     434                return ENOMEM;
     435        batch_control_read(batch);
     436        const int ret = hc_schedule(hc, batch);
     437        if (ret != EOK) {
     438                batch_dispose(batch);
     439        }
     440        return ret;
    445441}
    446442/*----------------------------------------------------------------------------*/
     
    463459
    464460        .control_write = control_write,
    465         .control_read = control_read
     461        .control_read = control_read,
    466462};
    467463
Note: See TracChangeset for help on using the changeset viewer.