Changeset 72af8da in mainline for uspace/drv/uhci-hcd/iface.c


Ignore:
Timestamp:
2011-03-16T18:50:17Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
42a3a57
Parents:
3e7b7cd (diff), fcf07e6 (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 from usb/development

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/iface.c

    r3e7b7cd r72af8da  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver
     32 * @brief UHCI driver hc interface implementation
    3333 */
    3434#include <ddf/driver.h>
     
    4040
    4141#include "iface.h"
    42 #include "uhci.h"
     42#include "uhci_hc.h"
    4343#include "utils/device_keeper.h"
    4444
     45/** Reserve default address interface function
     46 *
     47 * @param[in] fun DDF function that was called.
     48 * @param[in] speed Speed to associate with the new default address.
     49 * @return Error code.
     50 */
    4551/*----------------------------------------------------------------------------*/
    4652static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
    4753{
    4854        assert(fun);
    49         uhci_t *hc = fun_to_uhci(fun);
     55        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    5056        assert(hc);
    5157        usb_log_debug("Default address request with speed %d.\n", speed);
     
    5460}
    5561/*----------------------------------------------------------------------------*/
     62/** Release default address interface function
     63 *
     64 * @param[in] fun DDF function that was called.
     65 * @return Error code.
     66 */
    5667static int release_default_address(ddf_fun_t *fun)
    5768{
    5869        assert(fun);
    59         uhci_t *hc = fun_to_uhci(fun);
     70        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    6071        assert(hc);
    6172        usb_log_debug("Default address release.\n");
     
    6475}
    6576/*----------------------------------------------------------------------------*/
     77/** Request address interface function
     78 *
     79 * @param[in] fun DDF function that was called.
     80 * @param[in] speed Speed to associate with the new default address.
     81 * @param[out] address Place to write a new address.
     82 * @return Error code.
     83 */
    6684static int request_address(ddf_fun_t *fun, usb_speed_t speed,
    6785    usb_address_t *address)
    6886{
    6987        assert(fun);
    70         uhci_t *hc = fun_to_uhci(fun);
     88        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    7189        assert(hc);
    7290        assert(address);
     
    8098}
    8199/*----------------------------------------------------------------------------*/
     100/** Bind address interface function
     101 *
     102 * @param[in] fun DDF function that was called.
     103 * @param[in] address Address of the device
     104 * @param[in] handle Devman handle of the device driver.
     105 * @return Error code.
     106 */
    82107static int bind_address(
    83108  ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
    84109{
    85110        assert(fun);
    86         uhci_t *hc = fun_to_uhci(fun);
     111        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    87112        assert(hc);
    88113        usb_log_debug("Address bind %d-%d.\n", address, handle);
     
    91116}
    92117/*----------------------------------------------------------------------------*/
     118/** Release address interface function
     119 *
     120 * @param[in] fun DDF function that was called.
     121 * @param[in] address USB address to be released.
     122 * @return Error code.
     123 */
    93124static int release_address(ddf_fun_t *fun, usb_address_t address)
    94125{
    95126        assert(fun);
    96         uhci_t *hc = fun_to_uhci(fun);
     127        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    97128        assert(hc);
    98129        usb_log_debug("Address release %d.\n", address);
     
    101132}
    102133/*----------------------------------------------------------------------------*/
     134/** Interrupt out transaction interface function
     135 *
     136 * @param[in] fun DDF function that was called.
     137 * @param[in] target USB device to write to.
     138 * @param[in] max_packet_size maximum size of data packet the device accepts
     139 * @param[in] data Source of data.
     140 * @param[in] size Size of data source.
     141 * @param[in] callback Function to call on transaction completion
     142 * @param[in] arg Additional for callback function.
     143 * @return Error code.
     144 */
    103145static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
    104146    size_t max_packet_size, void *data, size_t size,
     
    106148{
    107149        assert(fun);
    108         uhci_t *hc = fun_to_uhci(fun);
     150        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    109151        assert(hc);
    110152        usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     
    114156
    115157        batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    116             max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
     158            max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
     159            &hc->device_manager);
    117160        if (!batch)
    118161                return ENOMEM;
    119162        batch_interrupt_out(batch);
    120         return EOK;
    121 }
    122 /*----------------------------------------------------------------------------*/
     163        const int ret = uhci_hc_schedule(hc, batch);
     164        if (ret != EOK) {
     165                batch_dispose(batch);
     166                return ret;
     167        }
     168        return EOK;
     169}
     170/*----------------------------------------------------------------------------*/
     171/** Interrupt in transaction interface function
     172 *
     173 * @param[in] fun DDF function that was called.
     174 * @param[in] target USB device to write to.
     175 * @param[in] max_packet_size maximum size of data packet the device accepts
     176 * @param[out] data Data destination.
     177 * @param[in] size Size of data source.
     178 * @param[in] callback Function to call on transaction completion
     179 * @param[in] arg Additional for callback function.
     180 * @return Error code.
     181 */
    123182static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
    124183    size_t max_packet_size, void *data, size_t size,
     
    126185{
    127186        assert(fun);
    128         uhci_t *hc = fun_to_uhci(fun);
     187        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    129188        assert(hc);
    130189        usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     
    133192
    134193        batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    135             max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
     194            max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
     195                        &hc->device_manager);
    136196        if (!batch)
    137197                return ENOMEM;
    138198        batch_interrupt_in(batch);
    139         return EOK;
    140 }
    141 /*----------------------------------------------------------------------------*/
     199        const int ret = uhci_hc_schedule(hc, batch);
     200        if (ret != EOK) {
     201                batch_dispose(batch);
     202                return ret;
     203        }
     204        return EOK;
     205}
     206/*----------------------------------------------------------------------------*/
     207/** Bulk out transaction interface function
     208 *
     209 * @param[in] fun DDF function that was called.
     210 * @param[in] target USB device to write to.
     211 * @param[in] max_packet_size maximum size of data packet the device accepts
     212 * @param[in] data Source of data.
     213 * @param[in] size Size of data source.
     214 * @param[in] callback Function to call on transaction completion
     215 * @param[in] arg Additional for callback function.
     216 * @return Error code.
     217 */
     218static int bulk_out(ddf_fun_t *fun, usb_target_t target,
     219    size_t max_packet_size, void *data, size_t size,
     220    usbhc_iface_transfer_out_callback_t callback, void *arg)
     221{
     222        assert(fun);
     223        uhci_hc_t *hc = fun_to_uhci_hc(fun);
     224        assert(hc);
     225        usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     226
     227        usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
     228            target.address, target.endpoint, size, max_packet_size);
     229
     230        batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
     231            max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
     232            &hc->device_manager);
     233        if (!batch)
     234                return ENOMEM;
     235        batch_bulk_out(batch);
     236        const int ret = uhci_hc_schedule(hc, batch);
     237        if (ret != EOK) {
     238                batch_dispose(batch);
     239                return ret;
     240        }
     241        return EOK;
     242}
     243/*----------------------------------------------------------------------------*/
     244/** Bulk in transaction interface function
     245 *
     246 * @param[in] fun DDF function that was called.
     247 * @param[in] target USB device to write to.
     248 * @param[in] max_packet_size maximum size of data packet the device accepts
     249 * @param[out] data Data destination.
     250 * @param[in] size Size of data source.
     251 * @param[in] callback Function to call on transaction completion
     252 * @param[in] arg Additional for callback function.
     253 * @return Error code.
     254 */
     255static int bulk_in(ddf_fun_t *fun, usb_target_t target,
     256    size_t max_packet_size, void *data, size_t size,
     257    usbhc_iface_transfer_in_callback_t callback, void *arg)
     258{
     259        assert(fun);
     260        uhci_hc_t *hc = fun_to_uhci_hc(fun);
     261        assert(hc);
     262        usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     263        usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
     264            target.address, target.endpoint, size, max_packet_size);
     265
     266        batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
     267            max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
     268            &hc->device_manager);
     269        if (!batch)
     270                return ENOMEM;
     271        batch_bulk_in(batch);
     272        const int ret = uhci_hc_schedule(hc, batch);
     273        if (ret != EOK) {
     274                batch_dispose(batch);
     275                return ret;
     276        }
     277        return EOK;
     278}
     279/*----------------------------------------------------------------------------*/
     280/** Control write transaction interface function
     281 *
     282 * @param[in] fun DDF function that was called.
     283 * @param[in] target USB device to write to.
     284 * @param[in] max_packet_size maximum size of data packet the device accepts.
     285 * @param[in] setup_data Data to send with SETUP packet.
     286 * @param[in] setup_size Size of data to send with SETUP packet (should be 8B).
     287 * @param[in] data Source of data.
     288 * @param[in] size Size of data source.
     289 * @param[in] callback Function to call on transaction completion.
     290 * @param[in] arg Additional for callback function.
     291 * @return Error code.
     292 */
    142293static int control_write(ddf_fun_t *fun, usb_target_t target,
    143294    size_t max_packet_size,
     
    146297{
    147298        assert(fun);
    148         uhci_t *hc = fun_to_uhci(fun);
    149         assert(hc);
    150         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
    151         usb_log_debug("Control WRITE %d:%d %zu(%zu).\n",
    152             target.address, target.endpoint, size, max_packet_size);
     299        uhci_hc_t *hc = fun_to_uhci_hc(fun);
     300        assert(hc);
     301        usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     302        usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
     303            speed, target.address, target.endpoint, size, max_packet_size);
     304
     305        if (setup_size != 8)
     306                return EINVAL;
    153307
    154308        batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    155309            max_packet_size, speed, data, size, setup_data, setup_size,
    156             NULL, callback, arg);
    157         if (!batch)
    158                 return ENOMEM;
     310            NULL, callback, arg, &hc->device_manager);
     311        if (!batch)
     312                return ENOMEM;
     313        device_keeper_reset_if_need(&hc->device_manager, target, setup_data);
    159314        batch_control_write(batch);
    160         return EOK;
    161 }
    162 /*----------------------------------------------------------------------------*/
     315        const int ret = uhci_hc_schedule(hc, batch);
     316        if (ret != EOK) {
     317                batch_dispose(batch);
     318                return ret;
     319        }
     320        return EOK;
     321}
     322/*----------------------------------------------------------------------------*/
     323/** Control read transaction interface function
     324 *
     325 * @param[in] fun DDF function that was called.
     326 * @param[in] target USB device to write to.
     327 * @param[in] max_packet_size maximum size of data packet the device accepts.
     328 * @param[in] setup_data Data to send with SETUP packet.
     329 * @param[in] setup_size Size of data to send with SETUP packet (should be 8B).
     330 * @param[out] data Source of data.
     331 * @param[in] size Size of data source.
     332 * @param[in] callback Function to call on transaction completion.
     333 * @param[in] arg Additional for callback function.
     334 * @return Error code.
     335 */
    163336static int control_read(ddf_fun_t *fun, usb_target_t target,
    164337    size_t max_packet_size,
     
    167340{
    168341        assert(fun);
    169         uhci_t *hc = fun_to_uhci(fun);
    170         assert(hc);
    171         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
    172 
    173         usb_log_debug("Control READ %d:%d %zu(%zu).\n",
    174             target.address, target.endpoint, size, max_packet_size);
     342        uhci_hc_t *hc = fun_to_uhci_hc(fun);
     343        assert(hc);
     344        usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     345
     346        usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
     347            speed, target.address, target.endpoint, size, max_packet_size);
    175348        batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    176349            max_packet_size, speed, data, size, setup_data, setup_size, callback,
    177             NULL, arg);
     350            NULL, arg, &hc->device_manager);
    178351        if (!batch)
    179352                return ENOMEM;
    180353        batch_control_read(batch);
    181         return EOK;
    182 }
    183 
    184 
    185 /*----------------------------------------------------------------------------*/
    186 usbhc_iface_t uhci_iface = {
     354        const int ret = uhci_hc_schedule(hc, batch);
     355        if (ret != EOK) {
     356                batch_dispose(batch);
     357                return ret;
     358        }
     359        return EOK;
     360}
     361/*----------------------------------------------------------------------------*/
     362usbhc_iface_t uhci_hc_iface = {
    187363        .reserve_default_address = reserve_default_address,
    188364        .release_default_address = release_default_address,
     
    194370        .interrupt_in = interrupt_in,
    195371
     372        .bulk_in = bulk_in,
     373        .bulk_out = bulk_out,
     374
    196375        .control_read = control_read,
    197376        .control_write = control_write,
Note: See TracChangeset for help on using the changeset viewer.