Changeset 6843a9c in mainline for uspace/lib/drv/generic


Ignore:
Timestamp:
2012-06-29T13:02:14Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
722912e
Parents:
ba72f2b (diff), 0bbd13e (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 mainline changes

Trivial conflicts.

Location:
uspace/lib/drv/generic
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/driver.c

    rba72f2b r6843a9c  
    7070FIBRIL_MUTEX_INITIALIZE(functions_mutex);
    7171
    72 /** Interrupts */
    73 static interrupt_context_list_t interrupt_contexts;
    74 
    75 static irq_cmd_t default_cmds[] = {
    76         {
    77                 .cmd = CMD_ACCEPT
    78         }
    79 };
    80 
    81 static irq_code_t default_pseudocode = {
    82         sizeof(default_cmds) / sizeof(irq_cmd_t),
    83         default_cmds
    84 };
    85 
    8672static ddf_dev_t *create_device(void);
    8773static void delete_device(ddf_dev_t *);
     
    9379static void *function_get_ops(ddf_fun_t *, dev_inferface_idx_t);
    9480
    95 static void driver_irq_handler(ipc_callid_t iid, ipc_call_t *icall)
    96 {
    97         int id = (int)IPC_GET_IMETHOD(*icall);
    98         interrupt_context_t *ctx;
    99        
    100         ctx = find_interrupt_context_by_id(&interrupt_contexts, id);
    101         if (ctx != NULL && ctx->handler != NULL)
    102                 (*ctx->handler)(ctx->dev, iid, icall);
    103 }
    104 
    105 interrupt_context_t *create_interrupt_context(void)
    106 {
    107         interrupt_context_t *ctx;
    108        
    109         ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t));
    110         if (ctx != NULL)
    111                 memset(ctx, 0, sizeof(interrupt_context_t));
    112        
    113         return ctx;
    114 }
    115 
    116 void delete_interrupt_context(interrupt_context_t *ctx)
    117 {
    118         if (ctx != NULL)
    119                 free(ctx);
    120 }
    121 
    122 void init_interrupt_context_list(interrupt_context_list_t *list)
    123 {
    124         memset(list, 0, sizeof(interrupt_context_list_t));
    125         fibril_mutex_initialize(&list->mutex);
    126         list_initialize(&list->contexts);
    127 }
    128 
    129 void
    130 add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx)
    131 {
    132         fibril_mutex_lock(&list->mutex);
    133         ctx->id = list->curr_id++;
    134         list_append(&ctx->link, &list->contexts);
    135         fibril_mutex_unlock(&list->mutex);
    136 }
    137 
    138 void remove_interrupt_context(interrupt_context_list_t *list,
    139     interrupt_context_t *ctx)
    140 {
    141         fibril_mutex_lock(&list->mutex);
    142         list_remove(&ctx->link);
    143         fibril_mutex_unlock(&list->mutex);
    144 }
    145 
    146 interrupt_context_t *
    147 find_interrupt_context_by_id(interrupt_context_list_t *list, int id)
    148 {
    149         interrupt_context_t *ctx;
    150        
    151         fibril_mutex_lock(&list->mutex);
    152        
    153         list_foreach(list->contexts, link) {
    154                 ctx = list_get_instance(link, interrupt_context_t, link);
    155                 if (ctx->id == id) {
    156                         fibril_mutex_unlock(&list->mutex);
    157                         return ctx;
    158                 }
    159         }
    160        
    161         fibril_mutex_unlock(&list->mutex);
    162         return NULL;
    163 }
    164 
    165 interrupt_context_t *
    166 find_interrupt_context(interrupt_context_list_t *list, ddf_dev_t *dev, int irq)
    167 {
    168         interrupt_context_t *ctx;
    169        
    170         fibril_mutex_lock(&list->mutex);
    171        
    172         list_foreach(list->contexts, link) {
    173                 ctx = list_get_instance(link, interrupt_context_t, link);
    174                 if (ctx->irq == irq && ctx->dev == dev) {
    175                         fibril_mutex_unlock(&list->mutex);
    176                         return ctx;
    177                 }
    178         }
    179        
    180         fibril_mutex_unlock(&list->mutex);
    181         return NULL;
    182 }
    183 
    184 
    185 int
    186 register_interrupt_handler(ddf_dev_t *dev, int irq, interrupt_handler_t *handler,
    187     irq_code_t *pseudocode)
    188 {
    189         interrupt_context_t *ctx = create_interrupt_context();
    190        
    191         ctx->dev = dev;
    192         ctx->irq = irq;
    193         ctx->handler = handler;
    194        
    195         add_interrupt_context(&interrupt_contexts, ctx);
    196        
    197         if (pseudocode == NULL)
    198                 pseudocode = &default_pseudocode;
    199        
    200         int res = register_irq(irq, dev->handle, ctx->id, pseudocode);
    201         if (res != EOK) {
    202                 remove_interrupt_context(&interrupt_contexts, ctx);
    203                 delete_interrupt_context(ctx);
    204         }
    205 
    206         return res;
    207 }
    208 
    209 int unregister_interrupt_handler(ddf_dev_t *dev, int irq)
    210 {
    211         interrupt_context_t *ctx = find_interrupt_context(&interrupt_contexts,
    212             dev, irq);
    213         int res = unregister_irq(irq, dev->handle);
    214        
    215         if (ctx != NULL) {
    216                 remove_interrupt_context(&interrupt_contexts, ctx);
    217                 delete_interrupt_context(ctx);
    218         }
    219        
    220         return res;
    221 }
    222 
    22381static void add_to_functions_list(ddf_fun_t *fun)
    22482{
     
    267125static void driver_dev_add(ipc_callid_t iid, ipc_call_t *icall)
    268126{
    269         char *dev_name = NULL;
    270         int res;
    271        
    272127        devman_handle_t dev_handle = IPC_GET_ARG1(*icall);
    273128        devman_handle_t parent_fun_handle = IPC_GET_ARG2(*icall);
    274129       
    275130        ddf_dev_t *dev = create_device();
    276 
     131       
    277132        /* Add one reference that will be dropped by driver_dev_remove() */
    278133        dev_add_ref(dev);
    279134        dev->handle = dev_handle;
    280 
     135       
     136        char *dev_name = NULL;
    281137        async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0);
    282138        dev->name = dev_name;
    283 
     139       
    284140        /*
    285141         * Currently not used, parent fun handle is stored in context
     
    288144        (void) parent_fun_handle;
    289145       
    290         res = driver->driver_ops->add_device(dev);
     146        int res = driver->driver_ops->dev_add(dev);
    291147       
    292148        if (res != EOK) {
     
    303159}
    304160
    305 static void driver_dev_added(ipc_callid_t iid, ipc_call_t *icall)
    306 {
     161static void driver_dev_remove(ipc_callid_t iid, ipc_call_t *icall)
     162{
     163        devman_handle_t devh = IPC_GET_ARG1(*icall);
     164       
    307165        fibril_mutex_lock(&devices_mutex);
    308         ddf_dev_t *dev = driver_get_device(IPC_GET_ARG1(*icall));
    309         fibril_mutex_unlock(&devices_mutex);
    310        
    311         if (dev != NULL && driver->driver_ops->device_added != NULL)
    312                 driver->driver_ops->device_added(dev);
    313 }
    314 
    315 static void driver_dev_remove(ipc_callid_t iid, ipc_call_t *icall)
    316 {
    317         devman_handle_t devh;
    318         ddf_dev_t *dev;
    319         int rc;
    320        
    321         devh = IPC_GET_ARG1(*icall);
    322        
    323         fibril_mutex_lock(&devices_mutex);
    324         dev = driver_get_device(devh);
     166        ddf_dev_t *dev = driver_get_device(devh);
    325167        if (dev != NULL)
    326168                dev_add_ref(dev);
     
    331173                return;
    332174        }
     175       
     176        int rc;
    333177       
    334178        if (driver->driver_ops->dev_remove != NULL)
     
    345189static void driver_dev_gone(ipc_callid_t iid, ipc_call_t *icall)
    346190{
    347         devman_handle_t devh;
    348         ddf_dev_t *dev;
    349         int rc;
    350        
    351         devh = IPC_GET_ARG1(*icall);
     191        devman_handle_t devh = IPC_GET_ARG1(*icall);
    352192       
    353193        fibril_mutex_lock(&devices_mutex);
    354         dev = driver_get_device(devh);
     194        ddf_dev_t *dev = driver_get_device(devh);
    355195        if (dev != NULL)
    356196                dev_add_ref(dev);
     
    361201                return;
    362202        }
     203       
     204        int rc;
    363205       
    364206        if (driver->driver_ops->dev_gone != NULL)
     
    375217static void driver_fun_online(ipc_callid_t iid, ipc_call_t *icall)
    376218{
    377         devman_handle_t funh;
    378         ddf_fun_t *fun;
    379         int rc;
    380        
    381         funh = IPC_GET_ARG1(*icall);
     219        devman_handle_t funh = IPC_GET_ARG1(*icall);
    382220       
    383221        /*
     
    388226        fibril_mutex_lock(&functions_mutex);
    389227       
    390         fun = driver_get_function(funh);
     228        ddf_fun_t *fun = driver_get_function(funh);
    391229        if (fun != NULL)
    392230                fun_add_ref(fun);
     
    400238       
    401239        /* Call driver entry point */
     240        int rc;
     241       
    402242        if (driver->driver_ops->fun_online != NULL)
    403243                rc = driver->driver_ops->fun_online(fun);
     
    412252static void driver_fun_offline(ipc_callid_t iid, ipc_call_t *icall)
    413253{
    414         devman_handle_t funh;
    415         ddf_fun_t *fun;
    416         int rc;
    417        
    418         funh = IPC_GET_ARG1(*icall);
     254        devman_handle_t funh = IPC_GET_ARG1(*icall);
    419255       
    420256        /*
     
    425261        fibril_mutex_lock(&functions_mutex);
    426262       
    427         fun = driver_get_function(funh);
     263        ddf_fun_t *fun = driver_get_function(funh);
    428264        if (fun != NULL)
    429265                fun_add_ref(fun);
     
    437273       
    438274        /* Call driver entry point */
     275        int rc;
     276       
    439277        if (driver->driver_ops->fun_offline != NULL)
    440278                rc = driver->driver_ops->fun_offline(fun);
     
    460298                case DRIVER_DEV_ADD:
    461299                        driver_dev_add(callid, &call);
    462                         break;
    463                 case DRIVER_DEV_ADDED:
    464                         async_answer_0(callid, EOK);
    465                         driver_dev_added(callid, &call);
    466300                        break;
    467301                case DRIVER_DEV_REMOVE:
     
    751585
    752586/** Allocate driver-specific device data. */
    753 extern void *ddf_dev_data_alloc(ddf_dev_t *dev, size_t size)
    754 {
    755         void *data;
    756 
     587void *ddf_dev_data_alloc(ddf_dev_t *dev, size_t size)
     588{
    757589        assert(dev->driver_data == NULL);
    758 
    759         data = calloc(1, size);
     590       
     591        void *data = calloc(1, size);
    760592        if (data == NULL)
    761593                return NULL;
    762 
     594       
    763595        dev->driver_data = data;
    764596        return data;
     
    790622ddf_fun_t *ddf_fun_create(ddf_dev_t *dev, fun_type_t ftype, const char *name)
    791623{
    792         ddf_fun_t *fun;
    793 
    794         fun = create_function();
     624        ddf_fun_t *fun = create_function();
    795625        if (fun == NULL)
    796626                return NULL;
    797 
     627       
    798628        /* Add one reference that will be dropped by ddf_fun_destroy() */
    799629        fun->dev = dev;
    800630        fun_add_ref(fun);
    801 
     631       
    802632        fun->bound = false;
    803633        fun->ftype = ftype;
    804 
     634       
    805635        fun->name = str_dup(name);
    806636        if (fun->name == NULL) {
     
    808638                return NULL;
    809639        }
    810 
     640       
    811641        return fun;
    812642}
    813643
    814644/** Allocate driver-specific function data. */
    815 extern void *ddf_fun_data_alloc(ddf_fun_t *fun, size_t size)
    816 {
    817         void *data;
    818 
     645void *ddf_fun_data_alloc(ddf_fun_t *fun, size_t size)
     646{
    819647        assert(fun->bound == false);
    820648        assert(fun->driver_data == NULL);
    821 
    822         data = calloc(1, size);
     649       
     650        void *data = calloc(1, size);
    823651        if (data == NULL)
    824652                return NULL;
    825 
     653       
    826654        fun->driver_data = data;
    827655        return data;
     
    833661 * must not be bound.
    834662 *
    835  * @param fun           Function to destroy
     663 * @param fun Function to destroy
     664 *
    836665 */
    837666void ddf_fun_destroy(ddf_fun_t *fun)
    838667{
    839668        assert(fun->bound == false);
    840 
     669       
    841670        /*
    842671         * Drop the reference added by ddf_fun_create(). This will deallocate
     
    853682        if (fun->ops == NULL)
    854683                return NULL;
     684       
    855685        return fun->ops->interfaces[idx];
    856686}
     
    865695 * the same name.
    866696 *
    867  * @param fun           Function to bind
    868  * @return              EOK on success or negative error code
     697 * @param fun Function to bind
     698 *
     699 * @return EOK on success or negative error code
     700 *
    869701 */
    870702int ddf_fun_bind(ddf_fun_t *fun)
     
    873705        assert(fun->name != NULL);
    874706       
    875         int res;
    876        
    877707        add_to_functions_list(fun);
    878         res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,
     708        int res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,
    879709            fun->dev->handle, &fun->handle);
    880710        if (res != EOK) {
     
    892722 * the function invisible to the system.
    893723 *
    894  * @param fun           Function to unbind
    895  * @return              EOK on success or negative error code
     724 * @param fun Function to unbind
     725 *
     726 * @return EOK on success or negative error code
     727 *
    896728 */
    897729int ddf_fun_unbind(ddf_fun_t *fun)
    898730{
    899         int res;
    900        
    901731        assert(fun->bound == true);
    902732       
    903         res = devman_remove_function(fun->handle);
     733        int res = devman_remove_function(fun->handle);
    904734        if (res != EOK)
    905735                return res;
    906 
     736       
    907737        remove_from_functions_list(fun);
    908738       
     
    913743/** Online function.
    914744 *
    915  * @param fun           Function to online
    916  * @return              EOK on success or negative error code
     745 * @param fun Function to online
     746 *
     747 * @return EOK on success or negative error code
     748 *
    917749 */
    918750int ddf_fun_online(ddf_fun_t *fun)
    919751{
    920         int res;
    921        
    922752        assert(fun->bound == true);
    923753       
    924         res = devman_drv_fun_online(fun->handle);
     754        int res = devman_drv_fun_online(fun->handle);
    925755        if (res != EOK)
    926756                return res;
     
    931761/** Offline function.
    932762 *
    933  * @param fun           Function to offline
    934  * @return              EOK on success or negative error code
     763 * @param fun Function to offline
     764 *
     765 * @return EOK on success or negative error code
     766 *
    935767 */
    936768int ddf_fun_offline(ddf_fun_t *fun)
    937769{
    938         int res;
    939        
    940770        assert(fun->bound == true);
    941771       
    942         res = devman_drv_fun_offline(fun->handle);
     772        int res = devman_drv_fun_offline(fun->handle);
    943773        if (res != EOK)
    944774                return res;
     
    952782 * Cannot be called when the function node is bound.
    953783 *
    954  * @param fun                   Function
    955  * @param match_id_str          Match string
    956  * @param match_score           Match score
    957  * @return                      EOK on success, ENOMEM if out of memory.
     784 * @param fun          Function
     785 * @param match_id_str Match string
     786 * @param match_score  Match score
     787 *
     788 * @return EOK on success.
     789 * @return ENOMEM if out of memory.
     790 *
    958791 */
    959792int ddf_fun_add_match_id(ddf_fun_t *fun, const char *match_id_str,
    960793    int match_score)
    961794{
    962         match_id_t *match_id;
    963        
    964795        assert(fun->bound == false);
    965796        assert(fun->ftype == fun_inner);
    966797       
    967         match_id = create_match_id();
     798        match_id_t *match_id = create_match_id();
    968799        if (match_id == NULL)
    969800                return ENOMEM;
    970801       
    971802        match_id->id = str_dup(match_id_str);
    972         match_id->score = 90;
     803        match_id->score = match_score;
    973804       
    974805        add_match_id(&fun->match_ids, match_id);
     
    987818 *
    988819 * Must only be called when the function is bound.
     820 *
    989821 */
    990822int ddf_fun_add_to_category(ddf_fun_t *fun, const char *cat_name)
     
    998830int ddf_driver_main(driver_t *drv)
    999831{
    1000         int rc;
    1001 
    1002832        /*
    1003833         * Remember the driver structure - driver_ops will be called by generic
     
    1006836        driver = drv;
    1007837       
    1008         /* Initialize the list of interrupt contexts. */
    1009         init_interrupt_context_list(&interrupt_contexts);
    1010        
    1011         /* Set generic interrupt handler. */
    1012         async_set_interrupt_received(driver_irq_handler);
     838        /* Initialize interrupt module */
     839        interrupt_init();
    1013840       
    1014841        /*
     
    1016843         * incoming connections.
    1017844         */
    1018         rc = devman_driver_register(driver->name, driver_connection);
     845        async_set_client_connection(driver_connection);
     846        int rc = devman_driver_register(driver->name);
    1019847        if (rc != EOK) {
    1020848                printf("Error: Failed to register driver with device manager "
     
    1022850                    str_error(rc));
    1023851               
    1024                 return 1;
     852                return rc;
    1025853        }
    1026854       
     
    1028856        rc = task_retval(0);
    1029857        if (rc != EOK)
    1030                 return 1;
    1031 
     858                return rc;
     859       
    1032860        async_manager();
    1033861       
    1034862        /* Never reached. */
    1035         return 0;
     863        return EOK;
    1036864}
    1037865
  • uspace/lib/drv/generic/log.c

    rba72f2b r6843a9c  
    3333#include <io/log.h>
    3434#include <stdarg.h>
    35 
    3635#include <ddf/log.h>
    3736
    3837/** Initialize the logging system.
    3938 *
    40  * @param drv_name      Driver name, will be printed as part of message
    41  * @param level         Minimum message level to print
     39 * @param drv_name Driver name, will be printed as part of message
     40 * @param level    Minimum message level to print
     41 *
    4242 */
    4343int ddf_log_init(const char *drv_name, log_level_t level)
     
    4848/** Log a driver message.
    4949 *
    50  * @param level         Message verbosity level. Message is only printed
    51  *                      if verbosity is less than or equal to current
    52  *                      reporting level.
    53  * @param fmt           Format string (no trailing newline)
     50 * @param level Message verbosity level. Message is only printed
     51 *              if verbosity is less than or equal to current
     52 *              reporting level.
     53 * @param fmt   Format string (no trailing newline)
     54 *
    5455 */
    5556void ddf_msg(log_level_t level, const char *fmt, ...)
    5657{
    5758        va_list args;
    58 
     59       
    5960        va_start(args, fmt);
    6061        log_msgv(level, fmt, args);
  • uspace/lib/drv/generic/logbuf.c

    rba72f2b r6843a9c  
    3535#include <ddf/log.h>
    3636#include <assert.h>
     37#include <unistd.h>
    3738
    3839/** Formatting string for printing number of not-printed items. */
  • uspace/lib/drv/generic/remote_nic.c

    rba72f2b r6843a9c  
    3939#include <errno.h>
    4040#include <ipc/services.h>
    41 #include <adt/measured_strings.h>
    4241#include <sys/time.h>
    4342#include "ops/nic.h"
    4443
    45 static void remote_nic_send_message(ddf_fun_t *dev, void *iface,
    46     ipc_callid_t callid, ipc_call_t *call)
    47 {
    48         nic_iface_t *nic_iface = (nic_iface_t *) iface;
    49         assert(nic_iface->send_message);
    50        
    51         packet_id_t packet_id = (packet_id_t) IPC_GET_ARG2(*call);
    52        
    53         int rc = nic_iface->send_message(dev, packet_id);
    54         async_answer_0(callid, rc);
    55 }
    56 
    57 static void remote_nic_connect_to_nil(ddf_fun_t *dev, void *iface,
    58     ipc_callid_t callid, ipc_call_t *call)
    59 {
    60         nic_iface_t *nic_iface = (nic_iface_t *) iface;
    61         assert(nic_iface->connect_to_nil);
    62        
    63         services_t nil_service = (services_t) IPC_GET_ARG2(*call);
    64         nic_device_id_t device_id = (nic_device_id_t) IPC_GET_ARG3(*call);
    65        
    66         int rc = nic_iface->connect_to_nil(dev, nil_service, device_id);
     44static void remote_nic_send_frame(ddf_fun_t *dev, void *iface,
     45    ipc_callid_t callid, ipc_call_t *call)
     46{
     47        nic_iface_t *nic_iface = (nic_iface_t *) iface;
     48        assert(nic_iface->send_frame);
     49       
     50        void *data;
     51        size_t size;
     52        int rc;
     53       
     54        rc = async_data_write_accept(&data, false, 0, 0, 0, &size);
     55        if (rc != EOK) {
     56                async_answer_0(callid, EINVAL);
     57                return;
     58        }
     59       
     60        rc = nic_iface->send_frame(dev, data, size);
     61        async_answer_0(callid, rc);
     62        free(data);
     63}
     64
     65static void remote_nic_callback_create(ddf_fun_t *dev, void *iface,
     66    ipc_callid_t callid, ipc_call_t *call)
     67{
     68        nic_iface_t *nic_iface = (nic_iface_t *) iface;
     69        assert(nic_iface->callback_create);
     70       
     71        int rc = nic_iface->callback_create(dev);
    6772        async_answer_0(callid, rc);
    6873}
     
    829834       
    830835        uint16_t tag = (uint16_t) IPC_GET_ARG2(*call);
    831         int add = (int) IPC_GET_ARG3(*call);
    832         int strip = (int) IPC_GET_ARG4(*call);
     836        bool add = (int) IPC_GET_ARG3(*call);
     837        bool strip = (int) IPC_GET_ARG4(*call);
    833838       
    834839        int rc = nic_iface->vlan_set_tag(dev, tag, add, strip);
     
    11941199 */
    11951200static remote_iface_func_ptr_t remote_nic_iface_ops[] = {
    1196         &remote_nic_send_message,
    1197         &remote_nic_connect_to_nil,
     1201        &remote_nic_send_frame,
     1202        &remote_nic_callback_create,
    11981203        &remote_nic_get_state,
    11991204        &remote_nic_set_state,
  • uspace/lib/drv/generic/remote_pci.c

    rba72f2b r6843a9c  
    3232/** @file
    3333 */
     34
    3435#include <assert.h>
    3536#include <async.h>
  • uspace/lib/drv/generic/remote_usb.c

    rba72f2b r6843a9c  
    11/*
    22 * Copyright (c) 2010 Vojtech Horky
     3 * Copyright (c) 2011 Jan Vesely
    34 * All rights reserved.
    45 *
     
    3940#include "ddf/driver.h"
    4041
     42typedef enum {
     43        IPC_M_USB_GET_MY_ADDRESS,
     44        IPC_M_USB_GET_MY_INTERFACE,
     45        IPC_M_USB_GET_HOST_CONTROLLER_HANDLE,
     46} usb_iface_funcs_t;
    4147
    42 static void remote_usb_get_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    43 static void remote_usb_get_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     48/** Tell USB address assigned to device.
     49 * @param exch Vaid IPC exchange
     50 * @param address Pointer to address storage place.
     51 * @return Error code.
     52 *
     53 * Exch param is an open communication to device implementing usb_iface.
     54 */
     55int usb_get_my_address(async_exch_t *exch, usb_address_t *address)
     56{
     57        if (!exch)
     58                return EINVAL;
     59        sysarg_t addr;
     60        const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     61            IPC_M_USB_GET_MY_ADDRESS, &addr);
     62
     63        if (ret == EOK && address != NULL)
     64                *address = (usb_address_t) addr;
     65        return ret;
     66}
     67/*----------------------------------------------------------------------------*/
     68/** Tell interface number given device can use.
     69 * @param[in] exch IPC communication exchange
     70 * @param[in] handle Id of the device
     71 * @param[out] usb_iface Assigned USB interface
     72 * @return Error code.
     73 */
     74int usb_get_my_interface(async_exch_t *exch, int *usb_iface)
     75{
     76        if (!exch)
     77                return EINVAL;
     78        sysarg_t iface_no;
     79        const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     80            IPC_M_USB_GET_MY_INTERFACE, &iface_no);
     81        if (ret == EOK && usb_iface)
     82                *usb_iface = (int)iface_no;
     83        return ret;
     84}
     85/*----------------------------------------------------------------------------*/
     86/** Tell devman handle of device host controller.
     87 * @param[in] exch IPC communication exchange
     88 * @param[out] hc_handle devman handle of the HC used by the target device.
     89 * @return Error code.
     90 */
     91int usb_get_hc_handle(async_exch_t *exch, devman_handle_t *hc_handle)
     92{
     93        if (!exch)
     94                return EINVAL;
     95        devman_handle_t h;
     96        const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     97            IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h);
     98        if (ret == EOK && hc_handle)
     99                *hc_handle = (devman_handle_t)h;
     100        return ret;
     101}
     102
     103
     104static void remote_usb_get_my_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     105static void remote_usb_get_my_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    44106static void remote_usb_get_hc_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    45 //static void remote_usb(device_t *, void *, ipc_callid_t, ipc_call_t *);
    46107
    47108/** Remote USB interface operations. */
    48109static remote_iface_func_ptr_t remote_usb_iface_ops [] = {
    49         remote_usb_get_address,
    50         remote_usb_get_interface,
    51         remote_usb_get_hc_handle
     110        [IPC_M_USB_GET_MY_ADDRESS] = remote_usb_get_my_address,
     111        [IPC_M_USB_GET_MY_INTERFACE] = remote_usb_get_my_interface,
     112        [IPC_M_USB_GET_HOST_CONTROLLER_HANDLE] = remote_usb_get_hc_handle,
    52113};
    53114
     
    60121};
    61122
    62 
    63 void remote_usb_get_address(ddf_fun_t *fun, void *iface,
     123/*----------------------------------------------------------------------------*/
     124void remote_usb_get_my_address(ddf_fun_t *fun, void *iface,
    64125    ipc_callid_t callid, ipc_call_t *call)
    65126{
    66         usb_iface_t *usb_iface = (usb_iface_t *) iface;
     127        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
    67128
    68         if (usb_iface->get_address == NULL) {
     129        if (usb_iface->get_my_address == NULL) {
    69130                async_answer_0(callid, ENOTSUP);
    70131                return;
    71132        }
    72133
    73         devman_handle_t handle = DEV_IPC_GET_ARG1(*call);
    74 
    75134        usb_address_t address;
    76         int rc = usb_iface->get_address(fun, handle, &address);
    77         if (rc != EOK) {
    78                 async_answer_0(callid, rc);
     135        const int ret = usb_iface->get_my_address(fun, &address);
     136        if (ret != EOK) {
     137                async_answer_0(callid, ret);
    79138        } else {
    80139                async_answer_1(callid, EOK, address);
    81140        }
    82141}
    83 
    84 void remote_usb_get_interface(ddf_fun_t *fun, void *iface,
     142/*----------------------------------------------------------------------------*/
     143void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface,
    85144    ipc_callid_t callid, ipc_call_t *call)
    86145{
    87         usb_iface_t *usb_iface = (usb_iface_t *) iface;
     146        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
    88147
    89         if (usb_iface->get_interface == NULL) {
     148        if (usb_iface->get_my_interface == NULL) {
    90149                async_answer_0(callid, ENOTSUP);
    91150                return;
    92151        }
    93152
    94         devman_handle_t handle = DEV_IPC_GET_ARG1(*call);
    95 
    96153        int iface_no;
    97         int rc = usb_iface->get_interface(fun, handle, &iface_no);
    98         if (rc != EOK) {
    99                 async_answer_0(callid, rc);
     154        const int ret = usb_iface->get_my_interface(fun, &iface_no);
     155        if (ret != EOK) {
     156                async_answer_0(callid, ret);
    100157        } else {
    101158                async_answer_1(callid, EOK, iface_no);
    102159        }
    103160}
    104 
     161/*----------------------------------------------------------------------------*/
    105162void remote_usb_get_hc_handle(ddf_fun_t *fun, void *iface,
    106163    ipc_callid_t callid, ipc_call_t *call)
    107164{
    108         usb_iface_t *usb_iface = (usb_iface_t *) iface;
     165        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
    109166
    110167        if (usb_iface->get_hc_handle == NULL) {
     
    114171
    115172        devman_handle_t handle;
    116         int rc = usb_iface->get_hc_handle(fun, &handle);
    117         if (rc != EOK) {
    118                 async_answer_0(callid, rc);
     173        const int ret = usb_iface->get_hc_handle(fun, &handle);
     174        if (ret != EOK) {
     175                async_answer_0(callid, ret);
    119176        }
    120177
    121178        async_answer_1(callid, EOK, (sysarg_t) handle);
    122179}
    123 
    124 
    125 
    126180/**
    127181 * @}
  • uspace/lib/drv/generic/remote_usbhc.c

    rba72f2b r6843a9c  
    11/*
    22 * Copyright (c) 2010-2011 Vojtech Horky
     3 * Copyright (c) 2011 Jan Vesely
    34 * All rights reserved.
    45 *
     
    4243#define USB_MAX_PAYLOAD_SIZE 1020
    4344
     45/** IPC methods for communication with HC through DDF interface.
     46 *
     47 * Notes for async methods:
     48 *
     49 * Methods for sending data to device (OUT transactions)
     50 * - e.g. IPC_M_USBHC_INTERRUPT_OUT -
     51 * always use the same semantics:
     52 * - first, IPC call with given method is made
     53 *   - argument #1 is target address
     54 *   - argument #2 is target endpoint
     55 *   - argument #3 is max packet size of the endpoint
     56 * - this call is immediately followed by IPC data write (from caller)
     57 * - the initial call (and the whole transaction) is answer after the
     58 *   transaction is scheduled by the HC and acknowledged by the device
     59 *   or immediately after error is detected
     60 * - the answer carries only the error code
     61 *
     62 * Methods for retrieving data from device (IN transactions)
     63 * - e.g. IPC_M_USBHC_INTERRUPT_IN -
     64 * also use the same semantics:
     65 * - first, IPC call with given method is made
     66 *   - argument #1 is target address
     67 *   - argument #2 is target endpoint
     68 * - this call is immediately followed by IPC data read (async version)
     69 * - the call is not answered until the device returns some data (or until
     70 *   error occurs)
     71 *
     72 * Some special methods (NO-DATA transactions) do not send any data. These
     73 * might behave as both OUT or IN transactions because communication parts
     74 * where actual buffers are exchanged are omitted.
     75 **
     76 * For all these methods, wrap functions exists. Important rule: functions
     77 * for IN transactions have (as parameters) buffers where retrieved data
     78 * will be stored. These buffers must be already allocated and shall not be
     79 * touch until the transaction is completed
     80 * (e.g. not before calling usb_wait_for() with appropriate handle).
     81 * OUT transactions buffers can be freed immediately after call is dispatched
     82 * (i.e. after return from wrapping function).
     83 *
     84 */
     85typedef enum {
     86        /** Asks for address assignment by host controller.
     87         * Answer:
     88         * - ELIMIT - host controller run out of address
     89         * - EOK - address assigned
     90         * Answer arguments:
     91         * - assigned address
     92         *
     93         * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS.
     94         */
     95        IPC_M_USBHC_REQUEST_ADDRESS,
     96
     97        /** Bind USB address with devman handle.
     98         * Parameters:
     99         * - USB address
     100         * - devman handle
     101         * Answer:
     102         * - EOK - address binded
     103         * - ENOENT - address is not in use
     104         */
     105        IPC_M_USBHC_BIND_ADDRESS,
     106
     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
     116        /** Release address in use.
     117         * Arguments:
     118         * - address to be released
     119         * Answer:
     120         * - ENOENT - address not in use
     121         * - EPERM - trying to release default USB address
     122         */
     123        IPC_M_USBHC_RELEASE_ADDRESS,
     124
     125        /** Register endpoint attributes at host controller.
     126         * This is used to reserve portion of USB bandwidth.
     127         * When speed is invalid, speed of the device is used.
     128         * Parameters:
     129         * - USB address + endpoint number
     130         *   - packed as ADDR << 16 + EP
     131         * - speed + transfer type + direction
     132         *   - packed as ( SPEED << 8 + TYPE ) << 8 + DIR
     133         * - maximum packet size + interval (in milliseconds)
     134         *   - packed as MPS << 16 + INT
     135         * Answer:
     136         * - EOK - reservation successful
     137         * - ELIMIT - not enough bandwidth to satisfy the request
     138         */
     139        IPC_M_USBHC_REGISTER_ENDPOINT,
     140
     141        /** Revert endpoint registration.
     142         * Parameters:
     143         * - USB address
     144         * - endpoint number
     145         * - data direction
     146         * Answer:
     147         * - EOK - endpoint unregistered
     148         * - ENOENT - unknown endpoint
     149         */
     150        IPC_M_USBHC_UNREGISTER_ENDPOINT,
     151
     152        /** Get data from device.
     153         * See explanation at usb_iface_funcs_t (IN transaction).
     154         */
     155        IPC_M_USBHC_READ,
     156
     157        /** Send data to device.
     158         * See explanation at usb_iface_funcs_t (OUT transaction).
     159         */
     160        IPC_M_USBHC_WRITE,
     161} usbhc_iface_funcs_t;
     162
     163int usbhc_request_address(async_exch_t *exch, usb_address_t *address,
     164    bool strict, usb_speed_t speed)
     165{
     166        if (!exch || !address)
     167                return EINVAL;
     168        sysarg_t new_address;
     169        const int ret = async_req_4_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     170            IPC_M_USBHC_REQUEST_ADDRESS, *address, strict, speed, &new_address);
     171        if (ret == EOK)
     172                *address = (usb_address_t)new_address;
     173        return ret;
     174}
     175/*----------------------------------------------------------------------------*/
     176int usbhc_bind_address(async_exch_t *exch, usb_address_t address,
     177    devman_handle_t handle)
     178{
     179        if (!exch)
     180                return EINVAL;
     181        return async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     182            IPC_M_USBHC_BIND_ADDRESS, address, handle);
     183}
     184/*----------------------------------------------------------------------------*/
     185int usbhc_get_handle(async_exch_t *exch, usb_address_t address,
     186    devman_handle_t *handle)
     187{
     188        if (!exch)
     189                return EINVAL;
     190        sysarg_t h;
     191        const int ret = async_req_2_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     192            IPC_M_USBHC_GET_HANDLE_BY_ADDRESS, address, &h);
     193        if (ret == EOK && handle)
     194                *handle = (devman_handle_t)h;
     195        return ret;
     196}
     197/*----------------------------------------------------------------------------*/
     198int usbhc_release_address(async_exch_t *exch, usb_address_t address)
     199{
     200        if (!exch)
     201                return EINVAL;
     202        return async_req_2_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     203            IPC_M_USBHC_RELEASE_ADDRESS, address);
     204}
     205/*----------------------------------------------------------------------------*/
     206int usbhc_register_endpoint(async_exch_t *exch, usb_address_t address,
     207    usb_endpoint_t endpoint, usb_transfer_type_t type,
     208    usb_direction_t direction, size_t mps, unsigned interval)
     209{
     210        if (!exch)
     211                return EINVAL;
     212        const usb_target_t target =
     213            {{ .address = address, .endpoint = endpoint }};
     214#define _PACK2(high, low) (((high & 0xffff) << 16) | (low & 0xffff))
     215
     216        return async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     217            IPC_M_USBHC_REGISTER_ENDPOINT, target.packed,
     218            _PACK2(type, direction), _PACK2(mps, interval));
     219
     220#undef _PACK2
     221}
     222/*----------------------------------------------------------------------------*/
     223int usbhc_unregister_endpoint(async_exch_t *exch, usb_address_t address,
     224    usb_endpoint_t endpoint, usb_direction_t direction)
     225{
     226        if (!exch)
     227                return EINVAL;
     228        return async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     229            IPC_M_USBHC_UNREGISTER_ENDPOINT, address, endpoint, direction);
     230}
     231/*----------------------------------------------------------------------------*/
     232int usbhc_read(async_exch_t *exch, usb_address_t address,
     233    usb_endpoint_t endpoint, uint64_t setup, void *data, size_t size,
     234    size_t *rec_size)
     235{
     236        if (size == 0 && setup == 0)
     237                return EOK;
     238
     239        if (!exch)
     240                return EINVAL;
     241        const usb_target_t target =
     242            {{ .address = address, .endpoint = endpoint }};
     243
     244        /* Make call identifying target USB device and type of transfer. */
     245        aid_t opening_request = async_send_4(exch,
     246            DEV_IFACE_ID(USBHC_DEV_IFACE),
     247            IPC_M_USBHC_READ, target.packed,
     248            (setup & UINT32_MAX), (setup >> 32), NULL);
     249
     250        if (opening_request == 0) {
     251                return ENOMEM;
     252        }
     253
     254        /* Retrieve the data. */
     255        ipc_call_t data_request_call;
     256        aid_t data_request =
     257            async_data_read(exch, data, size, &data_request_call);
     258
     259        if (data_request == 0) {
     260                // FIXME: How to let the other side know that we want to abort?
     261                async_forget(opening_request);
     262                return ENOMEM;
     263        }
     264
     265        /* Wait for the answer. */
     266        sysarg_t data_request_rc;
     267        sysarg_t opening_request_rc;
     268        async_wait_for(data_request, &data_request_rc);
     269        async_wait_for(opening_request, &opening_request_rc);
     270
     271        if (data_request_rc != EOK) {
     272                /* Prefer the return code of the opening request. */
     273                if (opening_request_rc != EOK) {
     274                        return (int) opening_request_rc;
     275                } else {
     276                        return (int) data_request_rc;
     277                }
     278        }
     279        if (opening_request_rc != EOK) {
     280                return (int) opening_request_rc;
     281        }
     282
     283        *rec_size = IPC_GET_ARG2(data_request_call);
     284        return EOK;
     285}
     286/*----------------------------------------------------------------------------*/
     287int usbhc_write(async_exch_t *exch, usb_address_t address,
     288    usb_endpoint_t endpoint, uint64_t setup, const void *data, size_t size)
     289{
     290        if (size == 0 && setup == 0)
     291                return EOK;
     292
     293        if (!exch)
     294                return EINVAL;
     295        const usb_target_t target =
     296            {{ .address = address, .endpoint = endpoint }};
     297
     298        aid_t opening_request = async_send_5(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     299            IPC_M_USBHC_WRITE, target.packed, size,
     300            (setup & UINT32_MAX), (setup >> 32), NULL);
     301
     302        if (opening_request == 0) {
     303                return ENOMEM;
     304        }
     305
     306        /* Send the data if any. */
     307        if (size > 0) {
     308                const int ret = async_data_write_start(exch, data, size);
     309                if (ret != EOK) {
     310                        async_forget(opening_request);
     311                        return ret;
     312                }
     313        }
     314
     315        /* Wait for the answer. */
     316        sysarg_t opening_request_rc;
     317        async_wait_for(opening_request, &opening_request_rc);
     318
     319        return (int) opening_request_rc;
     320}
     321/*----------------------------------------------------------------------------*/
     322
    44323static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    45324static void remote_usbhc_bind_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    46 static void remote_usbhc_find_by_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     325static void remote_usbhc_get_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    47326static void remote_usbhc_release_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    48327static void remote_usbhc_register_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     
    55334static remote_iface_func_ptr_t remote_usbhc_iface_ops[] = {
    56335        [IPC_M_USBHC_REQUEST_ADDRESS] = remote_usbhc_request_address,
     336        [IPC_M_USBHC_RELEASE_ADDRESS] = remote_usbhc_release_address,
    57337        [IPC_M_USBHC_BIND_ADDRESS] = remote_usbhc_bind_address,
    58         [IPC_M_USBHC_GET_HANDLE_BY_ADDRESS] = remote_usbhc_find_by_address,
    59         [IPC_M_USBHC_RELEASE_ADDRESS] = remote_usbhc_release_address,
     338        [IPC_M_USBHC_GET_HANDLE_BY_ADDRESS] = remote_usbhc_get_handle,
    60339
    61340        [IPC_M_USBHC_REGISTER_ENDPOINT] = remote_usbhc_register_endpoint,
     
    78357        ipc_callid_t data_caller;
    79358        void *buffer;
    80         size_t size;
    81359} async_transaction_t;
    82360
     
    103381        trans->data_caller = 0;
    104382        trans->buffer = NULL;
    105         trans->size = 0;
    106383
    107384        return trans;
    108385}
    109 
     386/*----------------------------------------------------------------------------*/
    110387void remote_usbhc_request_address(ddf_fun_t *fun, void *iface,
    111388    ipc_callid_t callid, ipc_call_t *call)
    112389{
    113         usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     390        const usbhc_iface_t *usb_iface = iface;
    114391
    115392        if (!usb_iface->request_address) {
     
    118395        }
    119396
    120         usb_speed_t speed = DEV_IPC_GET_ARG1(*call);
    121 
    122         usb_address_t address;
    123         int rc = usb_iface->request_address(fun, speed, &address);
     397        usb_address_t address = DEV_IPC_GET_ARG1(*call);
     398        const bool strict = DEV_IPC_GET_ARG2(*call);
     399        const usb_speed_t speed = DEV_IPC_GET_ARG3(*call);
     400
     401        const int rc = usb_iface->request_address(fun, &address, strict, speed);
    124402        if (rc != EOK) {
    125403                async_answer_0(callid, rc);
     
    128406        }
    129407}
    130 
     408/*----------------------------------------------------------------------------*/
    131409void remote_usbhc_bind_address(ddf_fun_t *fun, void *iface,
    132410    ipc_callid_t callid, ipc_call_t *call)
    133411{
    134         usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     412        const usbhc_iface_t *usb_iface = iface;
    135413
    136414        if (!usb_iface->bind_address) {
     
    139417        }
    140418
    141         usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
    142         devman_handle_t handle = (devman_handle_t) DEV_IPC_GET_ARG2(*call);
    143 
    144         int rc = usb_iface->bind_address(fun, address, handle);
    145 
    146         async_answer_0(callid, rc);
    147 }
    148 
    149 void remote_usbhc_find_by_address(ddf_fun_t *fun, void *iface,
     419        const usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
     420        const devman_handle_t handle = (devman_handle_t) DEV_IPC_GET_ARG2(*call);
     421
     422        const int ret = usb_iface->bind_address(fun, address, handle);
     423        async_answer_0(callid, ret);
     424}
     425/*----------------------------------------------------------------------------*/
     426void remote_usbhc_get_handle(ddf_fun_t *fun, void *iface,
    150427    ipc_callid_t callid, ipc_call_t *call)
    151428{
    152         usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
    153 
    154         if (!usb_iface->find_by_address) {
    155                 async_answer_0(callid, ENOTSUP);
    156                 return;
    157         }
    158 
    159         usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
     429        const usbhc_iface_t *usb_iface = iface;
     430
     431        if (!usb_iface->get_handle) {
     432                async_answer_0(callid, ENOTSUP);
     433                return;
     434        }
     435
     436        const usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
    160437        devman_handle_t handle;
    161         int rc = usb_iface->find_by_address(fun, address, &handle);
    162 
    163         if (rc == EOK) {
    164                 async_answer_1(callid, EOK, handle);
     438        const int ret = usb_iface->get_handle(fun, address, &handle);
     439
     440        if (ret == EOK) {
     441                async_answer_1(callid, ret, handle);
    165442        } else {
    166                 async_answer_0(callid, rc);
    167         }
    168 }
    169 
     443                async_answer_0(callid, ret);
     444        }
     445}
     446/*----------------------------------------------------------------------------*/
    170447void remote_usbhc_release_address(ddf_fun_t *fun, void *iface,
    171448    ipc_callid_t callid, ipc_call_t *call)
    172449{
    173         usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     450        const usbhc_iface_t *usb_iface = iface;
    174451
    175452        if (!usb_iface->release_address) {
     
    178455        }
    179456
    180         usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
    181 
    182         int rc = usb_iface->release_address(fun, address);
    183 
    184         async_answer_0(callid, rc);
    185 }
    186 
    187 
     457        const usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
     458
     459        const int ret = usb_iface->release_address(fun, address);
     460        async_answer_0(callid, ret);
     461}
     462/*----------------------------------------------------------------------------*/
    188463static void callback_out(ddf_fun_t *fun,
    189464    int outcome, void *arg)
    190465{
    191         async_transaction_t *trans = (async_transaction_t *)arg;
     466        async_transaction_t *trans = arg;
    192467
    193468        async_answer_0(trans->caller, outcome);
     
    195470        async_transaction_destroy(trans);
    196471}
    197 
     472/*----------------------------------------------------------------------------*/
    198473static void callback_in(ddf_fun_t *fun,
    199474    int outcome, size_t actual_size, void *arg)
     
    210485        }
    211486
    212         trans->size = actual_size;
    213 
    214487        if (trans->data_caller) {
    215488                async_data_read_finalize(trans->data_caller,
     
    221494        async_transaction_destroy(trans);
    222495}
    223 
     496/*----------------------------------------------------------------------------*/
    224497void remote_usbhc_register_endpoint(ddf_fun_t *fun, void *iface,
    225498    ipc_callid_t callid, ipc_call_t *call)
     
    233506
    234507#define _INIT_FROM_HIGH_DATA2(type, var, arg_no) \
    235         type var = (type) DEV_IPC_GET_ARG##arg_no(*call) / (1 << 16)
     508        type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) >> 16)
    236509#define _INIT_FROM_LOW_DATA2(type, var, arg_no) \
    237         type var = (type) DEV_IPC_GET_ARG##arg_no(*call) % (1 << 16)
    238 #define _INIT_FROM_HIGH_DATA3(type, var, arg_no) \
    239         type var = (type) DEV_IPC_GET_ARG##arg_no(*call) / (1 << 16)
    240 #define _INIT_FROM_MIDDLE_DATA3(type, var, arg_no) \
    241         type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) / (1 << 8)) % (1 << 8)
    242 #define _INIT_FROM_LOW_DATA3(type, var, arg_no) \
    243         type var = (type) DEV_IPC_GET_ARG##arg_no(*call) % (1 << 8)
     510        type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) & 0xffff)
    244511
    245512        const usb_target_t target = { .packed = DEV_IPC_GET_ARG1(*call) };
    246513
    247         _INIT_FROM_HIGH_DATA3(usb_speed_t, speed, 2);
    248         _INIT_FROM_MIDDLE_DATA3(usb_transfer_type_t, transfer_type, 2);
    249         _INIT_FROM_LOW_DATA3(usb_direction_t, direction, 2);
     514        _INIT_FROM_HIGH_DATA2(usb_transfer_type_t, transfer_type, 2);
     515        _INIT_FROM_LOW_DATA2(usb_direction_t, direction, 2);
    250516
    251517        _INIT_FROM_HIGH_DATA2(size_t, max_packet_size, 3);
     
    254520#undef _INIT_FROM_HIGH_DATA2
    255521#undef _INIT_FROM_LOW_DATA2
    256 #undef _INIT_FROM_HIGH_DATA3
    257 #undef _INIT_FROM_MIDDLE_DATA3
    258 #undef _INIT_FROM_LOW_DATA3
    259 
    260         int rc = usb_iface->register_endpoint(fun, target.address, speed,
     522
     523        int rc = usb_iface->register_endpoint(fun, target.address,
    261524            target.endpoint, transfer_type, direction, max_packet_size, interval);
    262525
     
    309572        }
    310573
    311         if (!async_data_read_receive(&trans->data_caller, &trans->size)) {
     574        size_t size = 0;
     575        if (!async_data_read_receive(&trans->data_caller, &size)) {
    312576                async_answer_0(callid, EPARTY);
    313577                return;
    314578        }
    315579
    316         trans->buffer = malloc(trans->size);
     580        trans->buffer = malloc(size);
    317581        if (trans->buffer == NULL) {
    318582                async_answer_0(trans->data_caller, ENOMEM);
     
    322586
    323587        const int rc = hc_iface->read(
    324             fun, target, setup, trans->buffer, trans->size, callback_in, trans);
     588            fun, target, setup, trans->buffer, size, callback_in, trans);
    325589
    326590        if (rc != EOK) {
     
    330594        }
    331595}
    332 
     596/*----------------------------------------------------------------------------*/
    333597void remote_usbhc_write(
    334598    ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
     
    357621        }
    358622
     623        size_t size = 0;
    359624        if (data_buffer_len > 0) {
    360                 int rc = async_data_write_accept(&trans->buffer, false,
     625                const int rc = async_data_write_accept(&trans->buffer, false,
    361626                    1, USB_MAX_PAYLOAD_SIZE,
    362                     0, &trans->size);
     627                    0, &size);
    363628
    364629                if (rc != EOK) {
     
    369634        }
    370635
    371         int rc = hc_iface->write(
    372             fun, target, setup, trans->buffer, trans->size, callback_out, trans);
     636        const int rc = hc_iface->write(
     637            fun, target, setup, trans->buffer, size, callback_out, trans);
    373638
    374639        if (rc != EOK) {
     
    377642        }
    378643}
    379 
    380 
    381644/**
    382645 * @}
Note: See TracChangeset for help on using the changeset viewer.