Changeset eb1a2f4 in mainline for uspace/lib


Ignore:
Timestamp:
2011-02-22T23:30:56Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3b5d1535, a9c674e0
Parents:
dbe25f1 (diff), 664af708 (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 (DDF refactoring)

This merge includes DDF refactoring that brought multifunctional devices
(i.e. ddf_dev_t and ddf_fun_t). Please, see ticket #295 at HelenOS
upstream Trac.

The conflicts themselves were easy to solve (merely several renamings).

Changes to USB subsystem:

  • drivers uses ddf_dev_t and ddf_fun_t
  • different signatures of many library functions
  • several hacks around communication with parent device (now the communication is clearer and somehow what we have now is hack about other hacks)
    • will repair and clean later
  • maybe added some extra debugging messages (the diff has about 240K, and I admit I have no energy to double check that)

WARNING:

  • the diff is VERY long, recommended is viewing partial diffs of the merge (i.e. merges in mainline branch that lead to the parent one)
  • merging with your branches might involve huge renamings, sorry, no other way is possible

BUGS:

  • hub driver will not work (no function created)

GOOD NEWS:

  • QEMU keyboard seems to work with QEMU 0.13 and 0.14
  • we are up-to-date with mainline again
Location:
uspace/lib
Files:
1 added
28 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/block/libblock.c

    rdbe25f1 reb1a2f4  
    626626                        unsigned long key = block->lba;
    627627                        hash_table_remove(&cache->block_hash, &key, 1);
     628                        fibril_mutex_unlock(&block->lock);
    628629                        free(block->data);
    629630                        free(block);
  • uspace/lib/c/Makefile

    rdbe25f1 reb1a2f4  
    9191        generic/loader.c \
    9292        generic/getopt.c \
    93         generic/adt/list.o \
    94         generic/adt/hash_table.o \
     93        generic/adt/list.c \
     94        generic/adt/hash_table.c \
    9595        generic/adt/dynamic_fifo.c \
    9696        generic/adt/measured_strings.c \
  • uspace/lib/c/generic/devman.c

    rdbe25f1 reb1a2f4  
    123123}
    124124
    125 static int devman_send_match_id(int phone, match_id_t *match_id) \
    126 {
    127         ipc_call_t answer;
    128         aid_t req = async_send_1(phone, DEVMAN_ADD_MATCH_ID, match_id->score, &answer);
    129         int retval = async_data_write_start(phone, match_id->id, str_size(match_id->id));
     125static int devman_send_match_id(int phone, match_id_t *match_id)
     126{
     127        ipc_call_t answer;
     128
     129        aid_t req = async_send_1(phone, DEVMAN_ADD_MATCH_ID, match_id->score,
     130            &answer);
     131        int retval = async_data_write_start(phone, match_id->id,
     132            str_size(match_id->id));
     133
    130134        async_wait_for(req, NULL);
    131135        return retval;
     
    133137
    134138
    135 static int devman_send_match_ids(int phone, match_id_list_t *match_ids) 
     139static int devman_send_match_ids(int phone, match_id_list_t *match_ids)
    136140{
    137141        link_t *link = match_ids->ids.next;
    138142        match_id_t *match_id = NULL;
    139143        int ret = EOK;
    140        
     144
    141145        while (link != &match_ids->ids) {
    142146                match_id = list_get_instance(link, match_id_t, link);
    143                 if (EOK != (ret = devman_send_match_id(phone, match_id)))
    144                 {
    145                         printf("Driver failed to send match id, error number = %d\n", ret);
    146                         return ret;                     
    147                 }
     147                ret = devman_send_match_id(phone, match_id);
     148                if (ret != EOK) {
     149                        printf("Driver failed to send match id, error %d\n",
     150                            ret);
     151                        return ret;
     152                }
     153
    148154                link = link->next;
    149155        }
    150         return ret;     
    151 }
    152 
    153 int devman_child_device_register(
    154         const char *name, match_id_list_t *match_ids, devman_handle_t parent_handle, devman_handle_t *handle)
    155 {               
     156
     157        return ret;
     158}
     159
     160/** Add function to a device.
     161 *
     162 * Request devman to add a new function to the specified device owned by
     163 * this driver task.
     164 *
     165 * @param name          Name of the new function
     166 * @param ftype         Function type, fun_inner or fun_exposed
     167 * @param match_ids     Match IDs (should be empty for fun_exposed)
     168 * @param devh          Devman handle of the device
     169 * @param funh          Place to store handle of the new function
     170 *
     171 * @return              EOK on success or negative error code.
     172 */
     173int devman_add_function(const char *name, fun_type_t ftype,
     174    match_id_list_t *match_ids, devman_handle_t devh, devman_handle_t *funh)
     175{
    156176        int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING);
     177        int fun_handle;
    157178       
    158179        if (phone < 0)
     
    161182        async_serialize_start();
    162183       
    163         int match_count = list_count(&match_ids->ids); 
    164         ipc_call_t answer;
    165         aid_t req = async_send_2(phone, DEVMAN_ADD_CHILD_DEVICE, parent_handle, match_count, &answer);
     184        int match_count = list_count(&match_ids->ids);
     185        ipc_call_t answer;
     186
     187        aid_t req = async_send_3(phone, DEVMAN_ADD_FUNCTION, (sysarg_t) ftype,
     188            devh, match_count, &answer);
    166189
    167190        sysarg_t retval = async_data_write_start(phone, name, str_size(name));
     
    178201        async_serialize_end();
    179202       
    180         if (retval != EOK) {
    181                 if (handle != NULL) {
    182                         *handle = -1;
    183                 }
    184                 return retval;
    185         }       
    186        
    187         if (handle != NULL)
    188                 *handle = (int) IPC_GET_ARG1(answer);   
    189                
    190         return retval;
    191 }
    192 
    193 int devman_add_device_to_class(devman_handle_t devman_handle, const char *class_name)
     203        if (retval == EOK)
     204                fun_handle = (int) IPC_GET_ARG1(answer);
     205        else
     206                fun_handle = -1;
     207       
     208        *funh = fun_handle;
     209
     210        return retval;
     211}
     212
     213int devman_add_device_to_class(devman_handle_t devman_handle,
     214    const char *class_name)
    194215{
    195216        int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING);
     
    200221        async_serialize_start();
    201222        ipc_call_t answer;
    202         aid_t req = async_send_1(phone, DEVMAN_ADD_DEVICE_TO_CLASS, devman_handle, &answer);
    203        
    204         sysarg_t retval = async_data_write_start(phone, class_name, str_size(class_name));
     223        aid_t req = async_send_1(phone, DEVMAN_ADD_DEVICE_TO_CLASS,
     224            devman_handle, &answer);
     225       
     226        sysarg_t retval = async_data_write_start(phone, class_name,
     227            str_size(class_name));
    205228        if (retval != EOK) {
    206229                async_wait_for(req, NULL);
     
    212235        async_serialize_end();
    213236       
    214         return retval; 
     237        return retval;
    215238}
    216239
     
    265288}
    266289
    267 int devman_device_get_handle(const char *pathname, devman_handle_t *handle, unsigned int flags)
     290int devman_device_get_handle(const char *pathname, devman_handle_t *handle,
     291    unsigned int flags)
    268292{
    269293        int phone = devman_get_phone(DEVMAN_CLIENT, flags);
     
    278302            &answer);
    279303       
    280         sysarg_t retval = async_data_write_start(phone, pathname, str_size(pathname));
     304        sysarg_t retval = async_data_write_start(phone, pathname,
     305            str_size(pathname));
    281306        if (retval != EOK) {
    282307                async_wait_for(req, NULL);
  • uspace/lib/c/generic/fibril.c

    rdbe25f1 reb1a2f4  
    115115        fibril->retval = 0;
    116116        fibril->flags = 0;
     117       
     118        fibril->waits_for = NULL;
    117119       
    118120        return fibril;
     
    276278        fibril->arg = arg;
    277279
    278         fibril->waits_for = NULL;
    279        
    280280        context_save(&fibril->ctx);
    281281        context_set(&fibril->ctx, FADDR(fibril_main), fibril->stack,
  • uspace/lib/c/include/devman.h

    rdbe25f1 reb1a2f4  
    4545
    4646extern int devman_driver_register(const char *, async_client_conn_t);
    47 extern int devman_child_device_register(const char *, match_id_list_t *,
     47extern int devman_add_function(const char *, fun_type_t, match_id_list_t *,
    4848    devman_handle_t, devman_handle_t *);
    4949
  • uspace/lib/c/include/ipc/devman.h

    rdbe25f1 reb1a2f4  
    4242
    4343typedef sysarg_t devman_handle_t;
     44
     45typedef enum {
     46        /** Invalid value for debugging purposes */
     47        fun_invalid = 0,
     48        /** Function to which child devices attach */
     49        fun_inner,
     50        /** Fuction exported to external clients (leaf function) */
     51        fun_exposed
     52} fun_type_t;
    4453
    4554/** Ids of device models used for device-to-driver matching.
     
    127136typedef enum {
    128137        DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
    129         DEVMAN_ADD_CHILD_DEVICE,
     138        DEVMAN_ADD_FUNCTION,
    130139        DEVMAN_ADD_MATCH_ID,
    131140        DEVMAN_ADD_DEVICE_TO_CLASS
  • uspace/lib/drv/generic/driver.c

    rdbe25f1 reb1a2f4  
    11/*
    22 * Copyright (c) 2010 Lenka Trochtova
     3 * Copyright (c) 2011 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    4950#include <errno.h>
    5051#include <inttypes.h>
     52#include <devman.h>
    5153
    5254#include <ipc/driver.h>
    5355
    5456#include "dev_iface.h"
    55 #include "driver.h"
     57#include "ddf/driver.h"
     58#include "ddf/interrupt.h"
    5659
    5760/** Driver structure */
     
    5962
    6063/** Devices */
    61 LIST_INITIALIZE(devices);
    62 FIBRIL_MUTEX_INITIALIZE(devices_mutex);
     64LIST_INITIALIZE(functions);
     65FIBRIL_MUTEX_INITIALIZE(functions_mutex);
    6366
    6467/** Interrupts */
     
    7679};
    7780
     81static ddf_dev_t *create_device(void);
     82static void delete_device(ddf_dev_t *);
     83static remote_handler_t *function_get_default_handler(ddf_fun_t *);
     84static void *function_get_ops(ddf_fun_t *, dev_inferface_idx_t);
    7885
    7986static void driver_irq_handler(ipc_callid_t iid, ipc_call_t *icall)
     
    150157
    151158interrupt_context_t *
    152 find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq)
     159find_interrupt_context(interrupt_context_list_t *list, ddf_dev_t *dev, int irq)
    153160{
    154161        fibril_mutex_lock(&list->mutex);
     
    172179
    173180int
    174 register_interrupt_handler(device_t *dev, int irq, interrupt_handler_t *handler,
     181register_interrupt_handler(ddf_dev_t *dev, int irq, interrupt_handler_t *handler,
    175182    irq_code_t *pseudocode)
    176183{
     
    195202}
    196203
    197 int unregister_interrupt_handler(device_t *dev, int irq)
     204int unregister_interrupt_handler(ddf_dev_t *dev, int irq)
    198205{
    199206        interrupt_context_t *ctx = find_interrupt_context(&interrupt_contexts,
     
    209216}
    210217
    211 static void add_to_devices_list(device_t *dev)
    212 {
    213         fibril_mutex_lock(&devices_mutex);
    214         list_append(&dev->link, &devices);
    215         fibril_mutex_unlock(&devices_mutex);
    216 }
    217 
    218 static void remove_from_devices_list(device_t *dev)
    219 {
    220         fibril_mutex_lock(&devices_mutex);
    221         list_remove(&dev->link);
    222         fibril_mutex_unlock(&devices_mutex);
    223 }
    224 
    225 static device_t *driver_get_device(link_t *devices, devman_handle_t handle)
    226 {
    227         device_t *dev = NULL;
    228        
    229         fibril_mutex_lock(&devices_mutex);
    230         link_t *link = devices->next;
    231        
    232         while (link != devices) {
    233                 dev = list_get_instance(link, device_t, link);
    234                 if (dev->handle == handle) {
    235                         fibril_mutex_unlock(&devices_mutex);
    236                         return dev;
     218static void add_to_functions_list(ddf_fun_t *fun)
     219{
     220        fibril_mutex_lock(&functions_mutex);
     221        list_append(&fun->link, &functions);
     222        fibril_mutex_unlock(&functions_mutex);
     223}
     224
     225static void remove_from_functions_list(ddf_fun_t *fun)
     226{
     227        fibril_mutex_lock(&functions_mutex);
     228        list_remove(&fun->link);
     229        fibril_mutex_unlock(&functions_mutex);
     230}
     231
     232static ddf_fun_t *driver_get_function(link_t *functions, devman_handle_t handle)
     233{
     234        ddf_fun_t *fun = NULL;
     235       
     236        fibril_mutex_lock(&functions_mutex);
     237        link_t *link = functions->next;
     238       
     239        while (link != functions) {
     240                fun = list_get_instance(link, ddf_fun_t, link);
     241                if (fun->handle == handle) {
     242                        fibril_mutex_unlock(&functions_mutex);
     243                        return fun;
    237244                }
     245               
    238246                link = link->next;
    239247        }
    240248       
    241         fibril_mutex_unlock(&devices_mutex);
     249        fibril_mutex_unlock(&functions_mutex);
    242250       
    243251        return NULL;
     
    250258       
    251259        devman_handle_t dev_handle = IPC_GET_ARG1(*icall);
    252         devman_handle_t parent_dev_handle = IPC_GET_ARG2(*icall);
    253        
    254         device_t *dev = create_device();
     260        devman_handle_t parent_fun_handle = IPC_GET_ARG2(*icall);
     261       
     262        ddf_dev_t *dev = create_device();
    255263        dev->handle = dev_handle;
    256        
     264
    257265        async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0);
    258266        dev->name = dev_name;
    259        
    260         add_to_devices_list(dev);
    261         dev->parent = driver_get_device(&devices, parent_dev_handle);
     267
     268        /*
     269         * Currently not used, parent fun handle is stored in context
     270         * of the connection to the parent device driver.
     271         */
     272        (void) parent_fun_handle;
    262273       
    263274        res = driver->driver_ops->add_device(dev);
     
    268279                printf("%s: failed to add a new device with handle = %" PRIun ".\n",
    269280                    driver->name, dev_handle);
    270                 remove_from_devices_list(dev);
    271281                delete_device(dev);
    272282        }
     
    311321         */
    312322        devman_handle_t handle = IPC_GET_ARG2(*icall);
    313         device_t *dev = driver_get_device(&devices, handle);
    314 
    315         if (dev == NULL) {
    316                 printf("%s: driver_connection_gen error - no device with handle"
     323        ddf_fun_t *fun = driver_get_function(&functions, handle);
     324
     325        if (fun == NULL) {
     326                printf("%s: driver_connection_gen error - no function with handle"
    317327                    " %" PRIun " was found.\n", driver->name, handle);
    318328                async_answer_0(iid, ENOENT);
     
    327337       
    328338        int ret = EOK;
    329         /* open the device */
    330         if (dev->ops != NULL && dev->ops->open != NULL)
    331                 ret = (*dev->ops->open)(dev);
     339        /* Open device function */
     340        if (fun->ops != NULL && fun->ops->open != NULL)
     341                ret = (*fun->ops->open)(fun);
    332342       
    333343        async_answer_0(iid, ret);
     
    344354                switch  (method) {
    345355                case IPC_M_PHONE_HUNGUP:
    346                         /* close the device */
    347                         if (dev->ops != NULL && dev->ops->close != NULL)
    348                                 (*dev->ops->close)(dev);
     356                        /* Close device function */
     357                        if (fun->ops != NULL && fun->ops->close != NULL)
     358                                (*fun->ops->close)(fun);
    349359                        async_answer_0(callid, EOK);
    350360                        return;
     
    356366                        if (!is_valid_iface_idx(iface_idx)) {
    357367                                remote_handler_t *default_handler =
    358                                     device_get_default_handler(dev);
     368                                    function_get_default_handler(fun);
    359369                                if (default_handler != NULL) {
    360                                         (*default_handler)(dev, callid, &call);
     370                                        (*default_handler)(fun, callid, &call);
    361371                                        break;
    362372                                }
     373                               
    363374                                /*
    364                                  * This is not device's interface and the
     375                                 * Function has no such interface and
    365376                                 * default handler is not provided.
    366377                                 */
     
    372383                        }
    373384                       
    374                         /* calling one of the device's interfaces */
     385                        /* calling one of the function's interfaces */
    375386                       
    376387                        /* Get the interface ops structure. */
    377                         void *ops = device_get_ops(dev, iface_idx);
     388                        void *ops = function_get_ops(fun, iface_idx);
    378389                        if (ops == NULL) {
    379390                                printf("%s: driver_connection_gen error - ",
    380391                                    driver->name);
    381                                 printf("device with handle %" PRIun " has no interface "
     392                                printf("Function with handle %" PRIun " has no interface "
    382393                                    "with id %d.\n", handle, iface_idx);
    383394                                async_answer_0(callid, ENOTSUP);
     
    408419                         * receive parameters from the remote client and it will
    409420                         * pass it to the corresponding local interface method
    410                          * associated with the device by its driver.
     421                         * associated with the function by its driver.
    411422                         */
    412                         (*iface_method_ptr)(dev, ops, callid, &call);
     423                        (*iface_method_ptr)(fun, ops, callid, &call);
    413424                        break;
    414425                }
     
    425436        driver_connection_gen(iid, icall, false);
    426437}
    427 
    428438
    429439/** Function for handling connections to device driver. */
     
    454464 * @return              The device structure.
    455465 */
    456 device_t *create_device(void)
    457 {
    458         device_t *dev = malloc(sizeof(device_t));
    459 
    460         if (dev != NULL) {
    461                 memset(dev, 0, sizeof(device_t));
    462                 init_match_ids(&dev->match_ids);
    463         }
    464 
     466static ddf_dev_t *create_device(void)
     467{
     468        ddf_dev_t *dev;
     469
     470        dev = malloc(sizeof(ddf_dev_t));
     471        if (dev == NULL)
     472                return NULL;
     473
     474        memset(dev, 0, sizeof(ddf_dev_t));
    465475        return dev;
    466476}
    467477
     478/** Create new function structure.
     479 *
     480 * @return              The device structure.
     481 */
     482static ddf_fun_t *create_function(void)
     483{
     484        ddf_fun_t *fun;
     485
     486        fun = calloc(1, sizeof(ddf_fun_t));
     487        if (fun == NULL)
     488                return NULL;
     489
     490        init_match_ids(&fun->match_ids);
     491        link_initialize(&fun->link);
     492
     493        return fun;
     494}
     495
    468496/** Delete device structure.
    469497 *
    470498 * @param dev           The device structure.
    471499 */
    472 void delete_device(device_t *dev)
    473 {
    474         clean_match_ids(&dev->match_ids);
    475         if (dev->name != NULL)
    476                 free(dev->name);
     500static void delete_device(ddf_dev_t *dev)
     501{
    477502        free(dev);
    478503}
    479504
    480 void *device_get_ops(device_t *dev, dev_inferface_idx_t idx)
     505/** Delete device structure.
     506 *
     507 * @param dev           The device structure.
     508 */
     509static void delete_function(ddf_fun_t *fun)
     510{
     511        clean_match_ids(&fun->match_ids);
     512        if (fun->name != NULL)
     513                free(fun->name);
     514        free(fun);
     515}
     516
     517/** Create a DDF function node.
     518 *
     519 * Create a DDF function (in memory). Both child devices and external clients
     520 * communicate with a device via its functions.
     521 *
     522 * The created function node is fully formed, but only exists in the memory
     523 * of the client task. In order to be visible to the system, the function
     524 * must be bound using ddf_fun_bind().
     525 *
     526 * This function should only fail if there is not enough free memory.
     527 * Specifically, this function succeeds even if @a dev already has
     528 * a (bound) function with the same name.
     529 *
     530 * Type: A function of type fun_inner indicates that DDF should attempt
     531 * to attach child devices to the function. fun_exposed means that
     532 * the function should be exported to external clients (applications).
     533 *
     534 * @param dev           Device to which we are adding function
     535 * @param ftype         Type of function (fun_inner or fun_exposed)
     536 * @param name          Name of function
     537 *
     538 * @return              New function or @c NULL if memory is not available
     539 */
     540ddf_fun_t *ddf_fun_create(ddf_dev_t *dev, fun_type_t ftype, const char *name)
     541{
     542        ddf_fun_t *fun;
     543
     544        fun = create_function();
     545        if (fun == NULL)
     546                return NULL;
     547
     548        fun->bound = false;
     549        fun->dev = dev;
     550        fun->ftype = ftype;
     551
     552        fun->name = str_dup(name);
     553        if (fun->name == NULL) {
     554                delete_function(fun);
     555                return NULL;
     556        }
     557
     558        return fun;
     559}
     560
     561/** Destroy DDF function node.
     562 *
     563 * Destroy a function previously created with ddf_fun_create(). The function
     564 * must not be bound.
     565 *
     566 * @param fun           Function to destroy
     567 */
     568void ddf_fun_destroy(ddf_fun_t *fun)
     569{
     570        assert(fun->bound == false);
     571        delete_function(fun);
     572}
     573
     574static void *function_get_ops(ddf_fun_t *fun, dev_inferface_idx_t idx)
    481575{
    482576        assert(is_valid_iface_idx(idx));
    483         if (dev->ops == NULL)
     577        if (fun->ops == NULL)
    484578                return NULL;
    485         return dev->ops->interfaces[idx];
    486 }
    487 
    488 int child_device_register(device_t *child, device_t *parent)
    489 {
    490         assert(child->name != NULL);
     579        return fun->ops->interfaces[idx];
     580}
     581
     582/** Bind a function node.
     583 *
     584 * Bind the specified function to the system. This effectively makes
     585 * the function visible to the system (uploads it to the server).
     586 *
     587 * This function can fail for several reasons. Specifically,
     588 * it will fail if the device already has a bound function of
     589 * the same name.
     590 *
     591 * @param fun           Function to bind
     592 * @return              EOK on success or negative error code
     593 */
     594int ddf_fun_bind(ddf_fun_t *fun)
     595{
     596        assert(fun->name != NULL);
    491597       
    492598        int res;
    493599       
    494         add_to_devices_list(child);
    495         res = devman_child_device_register(child->name, &child->match_ids,
    496             parent->handle, &child->handle);
     600        add_to_functions_list(fun);
     601        res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,
     602            fun->dev->handle, &fun->handle);
    497603        if (res != EOK) {
    498                 remove_from_devices_list(child);
     604                remove_from_functions_list(fun);
    499605                return res;
    500606        }
    501607       
     608        fun->bound = true;
    502609        return res;
    503610}
    504611
    505 /** Wrapper for child_device_register for devices with single match id.
    506  *
    507  * @param parent Parent device.
    508  * @param child_name Child device name.
    509  * @param child_match_id Child device match id.
    510  * @param child_match_score Child device match score.
    511  * @return Error code.
    512  */
    513 int child_device_register_wrapper(device_t *parent, const char *child_name,
    514     const char *child_match_id, int child_match_score,
    515     devman_handle_t *child_handle)
    516 {
    517         device_t *child = NULL;
    518         match_id_t *match_id = NULL;
    519         int rc;
    520        
    521         child = create_device();
    522         if (child == NULL) {
    523                 rc = ENOMEM;
    524                 goto failure;
    525         }
    526        
    527         child->name = child_name;
     612/** Add single match ID to inner function.
     613 *
     614 * Construct and add a single match ID to the specified function.
     615 * Cannot be called when the function node is bound.
     616 *
     617 * @param fun                   Function
     618 * @param match_id_str          Match string
     619 * @param match_score           Match score
     620 * @return                      EOK on success, ENOMEM if out of memory.
     621 */
     622int ddf_fun_add_match_id(ddf_fun_t *fun, const char *match_id_str,
     623    int match_score)
     624{
     625        match_id_t *match_id;
     626       
     627        assert(fun->bound == false);
     628        assert(fun->ftype == fun_inner);
    528629       
    529630        match_id = create_match_id();
    530         if (match_id == NULL) {
    531                 rc = ENOMEM;
    532                 goto failure;
    533         }
    534        
    535         match_id->id = child_match_id;
    536         match_id->score = child_match_score;
    537         add_match_id(&child->match_ids, match_id);
    538        
    539         rc = child_device_register(child, parent);
    540         if (rc != EOK)
    541                 goto failure;
    542 
    543         if (child_handle != NULL) {
    544                 *child_handle = child->handle;
    545         }
    546 
     631        if (match_id == NULL)
     632                return ENOMEM;
     633       
     634        match_id->id = match_id_str;
     635        match_id->score = 90;
     636       
     637        add_match_id(&fun->match_ids, match_id);
    547638        return EOK;
    548        
    549 failure:
    550         if (match_id != NULL) {
    551                 match_id->id = NULL;
    552                 delete_match_id(match_id);
    553         }
    554        
    555         if (child != NULL) {
    556                 child->name = NULL;
    557                 delete_device(child);
    558         }
    559        
    560         return rc;
    561639}
    562640
    563641/** Get default handler for client requests */
    564 remote_handler_t *device_get_default_handler(device_t *dev)
    565 {
    566         if (dev->ops == NULL)
     642static remote_handler_t *function_get_default_handler(ddf_fun_t *fun)
     643{
     644        if (fun->ops == NULL)
    567645                return NULL;
    568         return dev->ops->default_handler;
    569 }
    570 
    571 int add_device_to_class(device_t *dev, const char *class_name)
    572 {
    573         return devman_add_device_to_class(dev->handle, class_name);
    574 }
    575 
    576 int driver_main(driver_t *drv)
     646        return fun->ops->default_handler;
     647}
     648
     649/** Add exposed function to class.
     650 *
     651 * Must only be called when the function is bound.
     652 */
     653int ddf_fun_add_to_class(ddf_fun_t *fun, const char *class_name)
     654{
     655        assert(fun->bound == true);
     656        assert(fun->ftype == fun_exposed);
     657       
     658        return devman_add_device_to_class(fun->handle, class_name);
     659}
     660
     661int ddf_driver_main(driver_t *drv)
    577662{
    578663        /*
  • uspace/lib/drv/generic/remote_char_dev.c

    rdbe25f1 reb1a2f4  
    3737
    3838#include "ops/char_dev.h"
    39 #include "driver.h"
     39#include "ddf/driver.h"
    4040
    4141#define MAX_CHAR_RW_COUNT 256
    4242
    43 static void remote_char_read(device_t *, void *, ipc_callid_t, ipc_call_t *);
    44 static void remote_char_write(device_t *, void *, ipc_callid_t, ipc_call_t *);
     43static void remote_char_read(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     44static void remote_char_write(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    4545
    4646/** Remote character interface operations. */
     
    6767 * local interface to the remote client.
    6868 *
    69  * @param dev           The device from which the data are read.
     69 * @param fun           The function from which the data are read.
    7070 * @param ops           The local ops structure.
    7171 */
    7272static void
    73 remote_char_read(device_t *dev, void *ops, ipc_callid_t callid,
     73remote_char_read(ddf_fun_t *fun, void *ops, ipc_callid_t callid,
    7474    ipc_call_t *call)
    7575{
     
    9494       
    9595        char buf[MAX_CHAR_RW_COUNT];
    96         int ret = (*char_dev_ops->read)(dev, buf, len);
     96        int ret = (*char_dev_ops->read)(fun, buf, len);
    9797       
    9898        if (ret < 0) {
     
    114114 * local interface to the remote client.
    115115 *
    116  * @param dev           The device to which the data are written.
     116 * @param fun           The function to which the data are written.
    117117 * @param ops           The local ops structure.
    118118 */
    119119static void
    120 remote_char_write(device_t *dev, void *ops, ipc_callid_t callid,
     120remote_char_write(ddf_fun_t *fun, void *ops, ipc_callid_t callid,
    121121    ipc_call_t *call)
    122122{
     
    144144        async_data_write_finalize(cid, buf, len);
    145145       
    146         int ret = (*char_dev_ops->write)(dev, buf, len);
     146        int ret = (*char_dev_ops->write)(fun, buf, len);
    147147        if (ret < 0) {
    148148                /* Some error occured. */
  • uspace/lib/drv/generic/remote_hw_res.c

    rdbe25f1 reb1a2f4  
    3737
    3838#include "ops/hw_res.h"
    39 #include "driver.h"
     39#include "ddf/driver.h"
    4040
    41 static void remote_hw_res_get_resource_list(device_t *, void *, ipc_callid_t,
     41static void remote_hw_res_get_resource_list(ddf_fun_t *, void *, ipc_callid_t,
    4242    ipc_call_t *);
    43 static void remote_hw_res_enable_interrupt(device_t *, void *, ipc_callid_t,
     43static void remote_hw_res_enable_interrupt(ddf_fun_t *, void *, ipc_callid_t,
    4444    ipc_call_t *);
    4545
     
    5555};
    5656
    57 static void remote_hw_res_enable_interrupt(device_t *dev, void *ops,
     57static void remote_hw_res_enable_interrupt(ddf_fun_t *fun, void *ops,
    5858    ipc_callid_t callid, ipc_call_t *call)
    5959{
     
    6262        if (hw_res_ops->enable_interrupt == NULL)
    6363                async_answer_0(callid, ENOTSUP);
    64         else if (hw_res_ops->enable_interrupt(dev))
     64        else if (hw_res_ops->enable_interrupt(fun))
    6565                async_answer_0(callid, EOK);
    6666        else
     
    6868}
    6969
    70 static void remote_hw_res_get_resource_list(device_t *dev, void *ops,
     70static void remote_hw_res_get_resource_list(ddf_fun_t *fun, void *ops,
    7171    ipc_callid_t callid, ipc_call_t *call)
    7272{
     
    7878        }
    7979       
    80         hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list(dev);
     80        hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list(fun);
    8181        if (hw_resources == NULL){
    8282                async_answer_0(callid, ENOENT);
  • uspace/lib/drv/generic/remote_usb.c

    rdbe25f1 reb1a2f4  
    3737
    3838#include "usb_iface.h"
    39 #include "driver.h"
     39#include "ddf/driver.h"
    4040
    4141
    42 static void remote_usb_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    43 static void remote_usb_get_interface(device_t *, void *, ipc_callid_t, ipc_call_t *);
    44 static void remote_usb_get_hc_handle(device_t *, void *, ipc_callid_t, ipc_call_t *);
     42static void remote_usb_get_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     43static void remote_usb_get_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     44static void remote_usb_get_hc_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    4545//static void remote_usb(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4646
     
    6161
    6262
    63 void remote_usb_get_address(device_t *device, void *iface,
     63void remote_usb_get_address(ddf_fun_t *fun, void *iface,
    6464    ipc_callid_t callid, ipc_call_t *call)
    6565{
     
    7474
    7575        usb_address_t address;
    76         int rc = usb_iface->get_address(device, handle, &address);
     76        int rc = usb_iface->get_address(fun, handle, &address);
    7777        if (rc != EOK) {
    7878                async_answer_0(callid, rc);
     
    8282}
    8383
    84 void remote_usb_get_interface(device_t *device, void *iface,
     84void remote_usb_get_interface(ddf_fun_t *fun, void *iface,
    8585    ipc_callid_t callid, ipc_call_t *call)
    8686{
     
    9595
    9696        int iface_no;
    97         int rc = usb_iface->get_interface(device, handle, &iface_no);
     97        int rc = usb_iface->get_interface(fun, handle, &iface_no);
    9898        if (rc != EOK) {
    9999                async_answer_0(callid, rc);
     
    103103}
    104104
    105 void remote_usb_get_hc_handle(device_t *device, void *iface,
     105void remote_usb_get_hc_handle(ddf_fun_t *fun, void *iface,
    106106    ipc_callid_t callid, ipc_call_t *call)
    107107{
     
    114114
    115115        devman_handle_t handle;
    116         int rc = usb_iface->get_hc_handle(device, &handle);
     116        int rc = usb_iface->get_hc_handle(fun, &handle);
    117117        if (rc != EOK) {
    118118                async_answer_0(callid, rc);
  • uspace/lib/drv/generic/remote_usbhc.c

    rdbe25f1 reb1a2f4  
    3535#include <async.h>
    3636#include <errno.h>
     37#include <assert.h>
    3738
    3839#include "usbhc_iface.h"
    39 #include "driver.h"
     40#include "ddf/driver.h"
    4041
    4142#define USB_MAX_PAYLOAD_SIZE 1020
     
    4344#define HACK_MAX_PACKET_SIZE_INTERRUPT_IN 4
    4445
    45 static void remote_usbhc_interrupt_out(device_t *, void *, ipc_callid_t, ipc_call_t *);
    46 static void remote_usbhc_interrupt_in(device_t *, void *, ipc_callid_t, ipc_call_t *);
    47 static void remote_usbhc_bulk_out(device_t *, void *, ipc_callid_t, ipc_call_t *);
    48 static void remote_usbhc_bulk_in(device_t *, void *, ipc_callid_t, ipc_call_t *);
    49 static void remote_usbhc_control_write(device_t *, void *, ipc_callid_t, ipc_call_t *);
    50 static void remote_usbhc_control_read(device_t *, void *, ipc_callid_t, ipc_call_t *);
    51 static void remote_usbhc_reserve_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    52 static void remote_usbhc_release_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    53 static void remote_usbhc_request_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    54 static void remote_usbhc_bind_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    55 static void remote_usbhc_release_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    56 //static void remote_usbhc(device_t *, void *, ipc_callid_t, ipc_call_t *);
     46static void remote_usbhc_interrupt_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     47static void remote_usbhc_interrupt_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     48static void remote_usbhc_bulk_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     49static void remote_usbhc_bulk_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     50static void remote_usbhc_control_write(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     51static void remote_usbhc_control_read(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     52static void remote_usbhc_reserve_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     53static void remote_usbhc_release_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     54static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     55static void remote_usbhc_bind_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     56static void remote_usbhc_release_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     57//static void remote_usbhc(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    5758
    5859/** Remote USB host controller interface operations. */
     
    123124}
    124125
    125 void remote_usbhc_reserve_default_address(device_t *device, void *iface,
     126void remote_usbhc_reserve_default_address(ddf_fun_t *fun, void *iface,
    126127    ipc_callid_t callid, ipc_call_t *call)
    127128{
     
    135136        usb_speed_t speed = DEV_IPC_GET_ARG1(*call);
    136137       
    137         int rc = usb_iface->reserve_default_address(device, speed);
     138        int rc = usb_iface->reserve_default_address(fun, speed);
    138139
    139140        async_answer_0(callid, rc);
    140141}
    141142
    142 void remote_usbhc_release_default_address(device_t *device, void *iface,
     143void remote_usbhc_release_default_address(ddf_fun_t *fun, void *iface,
    143144    ipc_callid_t callid, ipc_call_t *call)
    144145{
     
    150151        }
    151152
    152         int rc = usb_iface->release_default_address(device);
     153        int rc = usb_iface->release_default_address(fun);
    153154
    154155        async_answer_0(callid, rc);
    155156}
    156157
    157 void remote_usbhc_request_address(device_t *device, void *iface,
     158void remote_usbhc_request_address(ddf_fun_t *fun, void *iface,
    158159    ipc_callid_t callid, ipc_call_t *call)
    159160{
     
    168169
    169170        usb_address_t address;
    170         int rc = usb_iface->request_address(device, speed, &address);
     171        int rc = usb_iface->request_address(fun, speed, &address);
    171172        if (rc != EOK) {
    172173                async_answer_0(callid, rc);
     
    176177}
    177178
    178 void remote_usbhc_bind_address(device_t *device, void *iface,
     179void remote_usbhc_bind_address(ddf_fun_t *fun, void *iface,
    179180    ipc_callid_t callid, ipc_call_t *call)
    180181{
     
    189190        devman_handle_t handle = (devman_handle_t) DEV_IPC_GET_ARG2(*call);
    190191
    191         int rc = usb_iface->bind_address(device, address, handle);
     192        int rc = usb_iface->bind_address(fun, address, handle);
    192193
    193194        async_answer_0(callid, rc);
    194195}
    195196
    196 void remote_usbhc_release_address(device_t *device, void *iface,
     197void remote_usbhc_release_address(ddf_fun_t *fun, void *iface,
    197198    ipc_callid_t callid, ipc_call_t *call)
    198199{
     
    206207        usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
    207208
    208         int rc = usb_iface->release_address(device, address);
     209        int rc = usb_iface->release_address(fun, address);
    209210
    210211        async_answer_0(callid, rc);
     
    212213
    213214
    214 static void callback_out(device_t *device,
     215static void callback_out(ddf_fun_t *fun,
    215216    int outcome, void *arg)
    216217{
     
    222223}
    223224
    224 static void callback_in(device_t *device,
     225static void callback_in(ddf_fun_t *fun,
    225226    int outcome, size_t actual_size, void *arg)
    226227{
     
    255256 * @param transfer_func Transfer function (might be NULL).
    256257 */
    257 static void remote_usbhc_out_transfer(device_t *device,
     258static void remote_usbhc_out_transfer(ddf_fun_t *fun,
    258259    ipc_callid_t callid, ipc_call_t *call,
    259260    usbhc_iface_transfer_out_t transfer_func)
     
    294295        trans->size = len;
    295296
    296         rc = transfer_func(device, target, max_packet_size,
     297        rc = transfer_func(fun, target, max_packet_size,
    297298            buffer, len,
    298299            callback_out, trans);
     
    311312 * @param transfer_func Transfer function (might be NULL).
    312313 */
    313 static void remote_usbhc_in_transfer(device_t *device,
     314static void remote_usbhc_in_transfer(ddf_fun_t *fun,
    314315    ipc_callid_t callid, ipc_call_t *call,
    315316    usbhc_iface_transfer_in_t transfer_func)
     
    342343        trans->size = len;
    343344
    344         int rc = transfer_func(device, target, max_packet_size,
     345        int rc = transfer_func(fun, target, max_packet_size,
    345346            trans->buffer, len,
    346347            callback_in, trans);
     
    352353}
    353354
    354 void remote_usbhc_interrupt_out(device_t *device, void *iface,
     355void remote_usbhc_interrupt_out(ddf_fun_t *fun, void *iface,
    355356    ipc_callid_t callid, ipc_call_t *call)
    356357{
     
    358359        assert(usb_iface != NULL);
    359360
    360         return remote_usbhc_out_transfer(device, callid, call,
     361        return remote_usbhc_out_transfer(fun, callid, call,
    361362            usb_iface->interrupt_out);
    362363}
    363364
    364 void remote_usbhc_interrupt_in(device_t *device, void *iface,
     365void remote_usbhc_interrupt_in(ddf_fun_t *fun, void *iface,
    365366    ipc_callid_t callid, ipc_call_t *call)
    366367{
     
    368369        assert(usb_iface != NULL);
    369370
    370         return remote_usbhc_in_transfer(device, callid, call,
     371        return remote_usbhc_in_transfer(fun, callid, call,
    371372            usb_iface->interrupt_in);
    372373}
    373374
    374 void remote_usbhc_bulk_out(device_t *device, void *iface,
     375void remote_usbhc_bulk_out(ddf_fun_t *fun, void *iface,
    375376    ipc_callid_t callid, ipc_call_t *call)
    376377{
     
    378379        assert(usb_iface != NULL);
    379380
    380         return remote_usbhc_out_transfer(device, callid, call,
     381        return remote_usbhc_out_transfer(fun, callid, call,
    381382            usb_iface->bulk_out);
    382383}
    383384
    384 void remote_usbhc_bulk_in(device_t *device, void *iface,
     385void remote_usbhc_bulk_in(ddf_fun_t *fun, void *iface,
    385386    ipc_callid_t callid, ipc_call_t *call)
    386387{
     
    388389        assert(usb_iface != NULL);
    389390
    390         return remote_usbhc_in_transfer(device, callid, call,
     391        return remote_usbhc_in_transfer(fun, callid, call,
    391392            usb_iface->bulk_in);
    392393}
    393394
    394 void remote_usbhc_control_write(device_t *device, void *iface,
     395void remote_usbhc_control_write(ddf_fun_t *fun, void *iface,
    395396ipc_callid_t callid, ipc_call_t *call)
    396397{
     
    444445        trans->size = data_buffer_len;
    445446
    446         rc = usb_iface->control_write(device, target, max_packet_size,
     447        rc = usb_iface->control_write(fun, target, max_packet_size,
    447448            setup_packet, setup_packet_len,
    448449            data_buffer, data_buffer_len,
     
    456457
    457458
    458 void remote_usbhc_control_read(device_t *device, void *iface,
     459void remote_usbhc_control_read(ddf_fun_t *fun, void *iface,
    459460ipc_callid_t callid, ipc_call_t *call)
    460461{
     
    509510        }
    510511
    511         rc = usb_iface->control_read(device, target, max_packet_size,
     512        rc = usb_iface->control_read(fun, target, max_packet_size,
    512513            setup_packet, setup_packet_len,
    513514            trans->buffer, trans->size,
  • uspace/lib/drv/include/ddf/driver.h

    rdbe25f1 reb1a2f4  
    11/*
    22 * Copyright (c) 2010 Lenka Trochtova
     3 * Copyright (c) 2011 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    3334 */
    3435
    35 #ifndef LIBDRV_DRIVER_H_
    36 #define LIBDRV_DRIVER_H_
     36#ifndef DDF_DRIVER_H_
     37#define DDF_DRIVER_H_
    3738
    38 #include <sys/types.h>
    39 #include <kernel/ddi/irq.h>
    40 #include <adt/list.h>
    41 #include <devman.h>
    4239#include <ipc/devman.h>
    4340#include <ipc/dev_iface.h>
    44 #include <assert.h>
    45 #include <ddi.h>
    46 #include <libarch/ddi.h>
    47 #include <fibril_synch.h>
    48 #include <malloc.h>
    4941
    50 #include "dev_iface.h"
     42#include "../dev_iface.h"
    5143
    52 struct device;
    53 typedef struct device device_t;
     44typedef struct ddf_dev ddf_dev_t;
     45typedef struct ddf_fun ddf_fun_t;
    5446
    5547/*
    56  * Device class
     48 * Device
    5749 */
    5850
    5951/** Devices operations */
    60 typedef struct device_ops {
     52typedef struct ddf_dev_ops {
    6153        /**
    6254         * Optional callback function called when a client is connecting to the
    6355         * device.
    6456         */
    65         int (*open)(device_t *);
     57        int (*open)(ddf_fun_t *);
    6658       
    6759        /**
     
    6961         * the device.
    7062         */
    71         void (*close)(device_t *);
     63        void (*close)(ddf_fun_t *);
    7264       
    7365        /** The table of standard interfaces implemented by the device. */
     
    8072         */
    8173        remote_handler_t *default_handler;
    82 } device_ops_t;
    83 
    84 
    85 /*
    86  * Device
    87  */
     74} ddf_dev_ops_t;
    8875
    8976/** Device structure */
    90 struct device {
     77struct ddf_dev {
    9178        /**
    9279         * Globally unique device identifier (assigned to the device by the
     
    10188        int parent_phone;
    10289       
    103         /** Parent device if handled by this driver, NULL otherwise */
    104         device_t *parent;
    10590        /** Device name */
    10691        const char *name;
    107         /** List of device ids for device-to-driver matching */
    108         match_id_list_t match_ids;
     92       
    10993        /** Driver-specific data associated with this device */
    11094        void *driver_data;
    111         /** The implementation of operations provided by this device */
    112         device_ops_t *ops;
    11395       
    11496        /** Link in the list of devices handled by the driver */
     97        link_t link;
     98};
     99
     100/** Function structure */
     101struct ddf_fun {
     102        /** True if bound to the device manager */
     103        bool bound;
     104        /** Function indentifier (asigned by device manager) */
     105        devman_handle_t handle;
     106       
     107        /** Device which this function belogs to */
     108        ddf_dev_t *dev;
     109       
     110        /** Function type */
     111        fun_type_t ftype;
     112        /** Function name */
     113        const char *name;
     114        /** List of device ids for driver matching */
     115        match_id_list_t match_ids;
     116        /** Driver-specific data associated with this function */
     117        void *driver_data;
     118        /** Implementation of operations provided by this function */
     119        ddf_dev_ops_t *ops;
     120       
     121        /** Link in the list of functions handled by the driver */
    115122        link_t link;
    116123};
     
    123130typedef struct driver_ops {
    124131        /** Callback method for passing a new device to the device driver */
    125         int (*add_device)(device_t *dev);
     132        int (*add_device)(ddf_dev_t *dev);
    126133        /* TODO: add other generic driver operations */
    127134} driver_ops_t;
     
    135142} driver_t;
    136143
    137 int driver_main(driver_t *);
     144extern int ddf_driver_main(driver_t *);
    138145
    139 /** Create new device structure.
    140  *
    141  * @return              The device structure.
    142  */
    143 extern device_t *create_device(void);
    144 extern void delete_device(device_t *);
    145 extern void *device_get_ops(device_t *, dev_inferface_idx_t);
     146extern ddf_fun_t *ddf_fun_create(ddf_dev_t *, fun_type_t, const char *);
     147extern void ddf_fun_destroy(ddf_fun_t *);
     148extern int ddf_fun_bind(ddf_fun_t *);
     149extern int ddf_fun_add_match_id(ddf_fun_t *, const char *, int);
    146150
    147 extern int child_device_register(device_t *, device_t *);
    148 extern int child_device_register_wrapper(device_t *, const char *, const char *,
    149     int, devman_handle_t *);
    150 
    151 /*
    152  * Interrupts
    153  */
    154 
    155 typedef void interrupt_handler_t(device_t *, ipc_callid_t, ipc_call_t *);
    156 
    157 typedef struct interrupt_context {
    158         int id;
    159         device_t *dev;
    160         int irq;
    161         interrupt_handler_t *handler;
    162         link_t link;
    163 } interrupt_context_t;
    164 
    165 typedef struct interrupt_context_list {
    166         int curr_id;
    167         link_t contexts;
    168         fibril_mutex_t mutex;
    169 } interrupt_context_list_t;
    170 
    171 extern interrupt_context_t *create_interrupt_context(void);
    172 extern void delete_interrupt_context(interrupt_context_t *);
    173 extern void init_interrupt_context_list(interrupt_context_list_t *);
    174 extern void add_interrupt_context(interrupt_context_list_t *,
    175     interrupt_context_t *);
    176 extern void remove_interrupt_context(interrupt_context_list_t *,
    177     interrupt_context_t *);
    178 extern interrupt_context_t *find_interrupt_context_by_id(
    179     interrupt_context_list_t *, int);
    180 extern interrupt_context_t *find_interrupt_context(
    181     interrupt_context_list_t *, device_t *, int);
    182 
    183 extern int register_interrupt_handler(device_t *, int, interrupt_handler_t *,
    184     irq_code_t *);
    185 extern int unregister_interrupt_handler(device_t *, int);
    186 
    187 extern remote_handler_t *device_get_default_handler(device_t *);
    188 extern int add_device_to_class(device_t *, const char *);
     151extern int ddf_fun_add_to_class(ddf_fun_t *, const char *);
    189152
    190153#endif
  • uspace/lib/drv/include/dev_iface.h

    rdbe25f1 reb1a2f4  
    4343 */
    4444
    45 struct device;
     45struct ddf_fun;
    4646
    4747/*
     
    4949 * devices driver.
    5050 */
    51 typedef void remote_iface_func_t(struct device *, void *, ipc_callid_t,
     51typedef void remote_iface_func_t(struct ddf_fun *, void *, ipc_callid_t,
    5252    ipc_call_t *);
    5353typedef remote_iface_func_t *remote_iface_func_ptr_t;
    54 typedef void remote_handler_t(struct device *, ipc_callid_t, ipc_call_t *);
     54typedef void remote_handler_t(struct ddf_fun *, ipc_callid_t, ipc_call_t *);
    5555
    5656typedef struct {
  • uspace/lib/drv/include/ops/char_dev.h

    rdbe25f1 reb1a2f4  
    3636#define LIBDRV_OPS_CHAR_DEV_H_
    3737
    38 #include "../driver.h"
     38#include "../ddf/driver.h"
    3939
    4040typedef struct {
    41         int (*read)(device_t *, char *, size_t);
    42         int (*write)(device_t *, char *, size_t);
     41        int (*read)(ddf_fun_t *, char *, size_t);
     42        int (*write)(ddf_fun_t *, char *, size_t);
    4343} char_dev_ops_t;
    4444
  • uspace/lib/drv/include/ops/hw_res.h

    rdbe25f1 reb1a2f4  
    3939#include <sys/types.h>
    4040
    41 #include "../driver.h"
     41#include "../ddf/driver.h"
    4242
    4343typedef struct {
    44          hw_resource_list_t *(*get_resource_list)(device_t *);
    45          bool (*enable_interrupt)(device_t *);
     44         hw_resource_list_t *(*get_resource_list)(ddf_fun_t *);
     45         bool (*enable_interrupt)(ddf_fun_t *);
    4646} hw_res_ops_t;
    4747
  • uspace/lib/drv/include/usb_iface.h

    rdbe25f1 reb1a2f4  
    3838#define LIBDRV_USB_IFACE_H_
    3939
    40 #include "driver.h"
     40#include "ddf/driver.h"
    4141#include <usb/usb.h>
    4242typedef enum {
     
    7575/** USB device communication interface. */
    7676typedef struct {
    77         int (*get_address)(device_t *, devman_handle_t, usb_address_t *);
    78         int (*get_interface)(device_t *, devman_handle_t, int *);
    79         int (*get_hc_handle)(device_t *, devman_handle_t *);
     77        int (*get_address)(ddf_fun_t *, devman_handle_t, usb_address_t *);
     78        int (*get_interface)(ddf_fun_t *, devman_handle_t, int *);
     79        int (*get_hc_handle)(ddf_fun_t *, devman_handle_t *);
    8080} usb_iface_t;
    8181
  • uspace/lib/drv/include/usbhc_iface.h

    rdbe25f1 reb1a2f4  
    3838#define LIBDRV_USBHC_IFACE_H_
    3939
    40 #include "driver.h"
     40#include "ddf/driver.h"
    4141#include <usb/usb.h>
    4242#include <bool.h>
     
    171171
    172172/** Callback for outgoing transfer. */
    173 typedef void (*usbhc_iface_transfer_out_callback_t)(device_t *,
     173typedef void (*usbhc_iface_transfer_out_callback_t)(ddf_fun_t *,
    174174    int, void *);
    175175
    176176/** Callback for incoming transfer. */
    177 typedef void (*usbhc_iface_transfer_in_callback_t)(device_t *,
     177typedef void (*usbhc_iface_transfer_in_callback_t)(ddf_fun_t *,
    178178    int, size_t, void *);
    179179
    180180
    181181/** Out transfer processing function prototype. */
    182 typedef int (*usbhc_iface_transfer_out_t)(device_t *, usb_target_t, size_t,
     182typedef int (*usbhc_iface_transfer_out_t)(ddf_fun_t *, usb_target_t, size_t,
    183183    void *, size_t,
    184184    usbhc_iface_transfer_out_callback_t, void *);
     
    188188
    189189/** In transfer processing function prototype. */
    190 typedef int (*usbhc_iface_transfer_in_t)(device_t *, usb_target_t, size_t,
     190typedef int (*usbhc_iface_transfer_in_t)(ddf_fun_t *, usb_target_t, size_t,
    191191    void *, size_t,
    192192    usbhc_iface_transfer_in_callback_t, void *);
     
    194194/** USB host controller communication interface. */
    195195typedef struct {
    196         int (*reserve_default_address)(device_t *, usb_speed_t);
    197         int (*release_default_address)(device_t *);
    198         int (*request_address)(device_t *, usb_speed_t, usb_address_t *);
    199         int (*bind_address)(device_t *, usb_address_t, devman_handle_t);
    200         int (*release_address)(device_t *, usb_address_t);
     196        int (*reserve_default_address)(ddf_fun_t *, usb_speed_t);
     197        int (*release_default_address)(ddf_fun_t *);
     198        int (*request_address)(ddf_fun_t *, usb_speed_t, usb_address_t *);
     199        int (*bind_address)(ddf_fun_t *, usb_address_t, devman_handle_t);
     200        int (*release_address)(ddf_fun_t *, usb_address_t);
    201201
    202202        usbhc_iface_transfer_out_t interrupt_out;
     
    206206        usbhc_iface_transfer_in_t bulk_in;
    207207
    208         int (*control_write)(device_t *, usb_target_t,
     208        int (*control_write)(ddf_fun_t *, usb_target_t,
    209209            size_t,
    210210            void *, size_t, void *, size_t,
    211211            usbhc_iface_transfer_out_callback_t, void *);
    212212
    213         int (*control_read)(device_t *, usb_target_t,
     213        int (*control_read)(ddf_fun_t *, usb_target_t,
    214214            size_t,
    215215            void *, size_t, void *, size_t,
  • uspace/lib/usb/include/usb/ddfiface.h

    rdbe25f1 reb1a2f4  
    4040#include <usb_iface.h>
    4141
    42 int usb_iface_get_hc_handle_hub_impl(device_t *, devman_handle_t *);
    43 int usb_iface_get_address_hub_impl(device_t *, devman_handle_t,
     42int usb_iface_get_hc_handle_hub_impl(ddf_fun_t *, devman_handle_t *);
     43int usb_iface_get_address_hub_impl(ddf_fun_t *, devman_handle_t,
    4444    usb_address_t *);
    4545extern usb_iface_t usb_iface_hub_impl;
    4646
    47 int usb_iface_get_hc_handle_hub_child_impl(device_t *, devman_handle_t *);
    48 int usb_iface_get_address_hub_child_impl(device_t *, devman_handle_t,
     47int usb_iface_get_hc_handle_hub_child_impl(ddf_fun_t *, devman_handle_t *);
     48int usb_iface_get_address_hub_child_impl(ddf_fun_t *, devman_handle_t,
    4949    usb_address_t *);
    5050extern usb_iface_t usb_iface_hub_child_impl;
    5151
    52 int usb_iface_get_hc_handle_hc_impl(device_t *, devman_handle_t *);
     52int usb_iface_get_hc_handle_hc_impl(ddf_fun_t *, devman_handle_t *);
    5353
    5454
  • uspace/lib/usb/include/usb/hub.h

    rdbe25f1 reb1a2f4  
    3939#include <usb/usbdevice.h>
    4040
    41 int usb_hc_new_device_wrapper(device_t *, usb_hc_connection_t *, usb_speed_t,
    42     int (*)(int, void *), int, void *, usb_address_t *, devman_handle_t *);
     41int usb_hc_new_device_wrapper(ddf_dev_t *, usb_hc_connection_t *, usb_speed_t,
     42    int (*)(int, void *), int, void *,
     43    usb_address_t *, devman_handle_t *,
     44    ddf_dev_ops_t *, void *, ddf_fun_t **);
    4345
    4446/** Info about device attached to host controller.
  • uspace/lib/usb/include/usb/pipes.h

    rdbe25f1 reb1a2f4  
    4141#include <usb/descriptor.h>
    4242#include <ipc/devman.h>
    43 #include <driver.h>
     43#include <ddf/driver.h>
    4444
    4545/**
     
    120120    usb_device_connection_t *, usb_hc_connection_t *);
    121121int usb_device_connection_initialize_from_device(usb_device_connection_t *,
    122     device_t *);
     122    ddf_dev_t *);
    123123int usb_device_connection_initialize(usb_device_connection_t *,
    124124    devman_handle_t, usb_address_t);
    125125
    126 int usb_device_get_assigned_interface(device_t *);
     126int usb_device_get_assigned_interface(ddf_dev_t *);
    127127
    128128int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *,
  • uspace/lib/usb/include/usb/recognise.h

    rdbe25f1 reb1a2f4  
    5050int usb_device_create_match_ids(usb_endpoint_pipe_t *, match_id_list_t *);
    5151
    52 int usb_device_register_child_in_devman(usb_address_t address, devman_handle_t hc_handle,
    53     device_t *parent, devman_handle_t *child_handle);
     52int usb_device_register_child_in_devman(usb_address_t, devman_handle_t,
     53    ddf_dev_t *, devman_handle_t *, ddf_dev_ops_t *, void *, ddf_fun_t **);
    5454
    5555#endif
  • uspace/lib/usb/include/usb/usbdevice.h

    rdbe25f1 reb1a2f4  
    3838#include <sys/types.h>
    3939#include <ipc/devman.h>
    40 #include <driver.h>
     40#include <ddf/driver.h>
    4141#include <bool.h>
    4242#include <usb/usb.h>
     
    5353
    5454int usb_hc_connection_initialize_from_device(usb_hc_connection_t *,
    55     device_t *);
     55    ddf_dev_t *);
    5656int usb_hc_connection_initialize(usb_hc_connection_t *, devman_handle_t);
    5757
  • uspace/lib/usb/src/ddfiface.c

    rdbe25f1 reb1a2f4  
    3434 */
    3535#include <ipc/devman.h>
     36#include <devman.h>
     37#include <async.h>
    3638#include <usb/ddfiface.h>
     39#include <usb/debug.h>
    3740#include <errno.h>
     41#include <assert.h>
    3842
    3943/** DDF interface for USB device, implementation for typical hub. */
     
    5660 * @return Error code.
    5761 */
    58 int usb_iface_get_hc_handle_hub_impl(device_t *device, devman_handle_t *handle)
     62int usb_iface_get_hc_handle_hub_impl(ddf_fun_t *fun, devman_handle_t *handle)
    5963{
    60         assert(device);
    61         return usb_hc_find(device->handle, handle);
     64        assert(fun);
     65        return usb_hc_find(fun->handle, handle);
    6266}
    6367
     
    6973 * @return Error code.
    7074 */
    71 int usb_iface_get_hc_handle_hub_child_impl(device_t *device,
     75int usb_iface_get_hc_handle_hub_child_impl(ddf_fun_t *fun,
    7276    devman_handle_t *handle)
    7377{
    74         assert(device);
    75         device_t *parent = device->parent;
     78        assert(fun != NULL);
    7679
    77         /* Default error, device does not support this operation. */
    78         int rc = ENOTSUP;
    79 
    80         if (parent && parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {
    81                 usb_iface_t *usb_iface
    82                     = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];
    83                 assert(usb_iface != NULL);
    84 
    85                 if (usb_iface->get_hc_handle) {
    86                         rc = usb_iface->get_hc_handle(parent, handle);
    87                 }
     80        int parent_phone = devman_parent_device_connect(fun->handle,
     81            IPC_FLAG_BLOCKING);
     82        if (parent_phone < 0) {
     83                return parent_phone;
    8884        }
    8985
    90         return rc;
     86        sysarg_t hc_handle;
     87        int rc = async_req_1_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
     88            IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &hc_handle);
     89
     90        if (rc != EOK) {
     91                return rc;
     92        }
     93
     94        *handle = hc_handle;
     95
     96        return EOK;
    9197}
    9298
     
    97103 * @return Always EOK.
    98104 */
    99 int usb_iface_get_hc_handle_hc_impl(device_t *device, devman_handle_t *handle)
     105int usb_iface_get_hc_handle_hc_impl(ddf_fun_t *fun, devman_handle_t *handle)
    100106{
    101         assert(device);
     107        assert(fun);
    102108
    103109        if (handle != NULL) {
    104                 *handle = device->handle;
     110                *handle = fun->handle;
    105111        }
    106112
     
    115121 * @return Error code.
    116122 */
    117 int usb_iface_get_address_hub_impl(device_t *device, devman_handle_t handle,
     123int usb_iface_get_address_hub_impl(ddf_fun_t *fun, devman_handle_t handle,
    118124    usb_address_t *address)
    119125{
    120         assert(device);
    121         int parent_phone = devman_parent_device_connect(device->handle,
     126        assert(fun);
     127        int parent_phone = devman_parent_device_connect(fun->handle,
    122128            IPC_FLAG_BLOCKING);
    123129        if (parent_phone < 0) {
     
    150156 * @return Error code.
    151157 */
    152 int usb_iface_get_address_hub_child_impl(device_t *device,
     158int usb_iface_get_address_hub_child_impl(ddf_fun_t *fun,
    153159    devman_handle_t handle, usb_address_t *address)
    154160{
    155         assert(device);
    156         device_t *parent = device->parent;
    157 
    158         /* Default error, device does not support this operation. */
    159         int rc = ENOTSUP;
    160 
    161         if (parent && parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {
    162                 usb_iface_t *usb_iface
    163                     = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];
    164                 assert(usb_iface != NULL);
    165 
    166                 if (usb_iface->get_address) {
    167                         rc = usb_iface->get_address(parent, handle, address);
    168                 }
     161        if (handle == 0) {
     162                handle = fun->handle;
    169163        }
    170 
    171         return rc;
     164        return usb_iface_get_address_hub_impl(fun, handle, address);
    172165}
    173166
  • uspace/lib/usb/src/hub.c

    rdbe25f1 reb1a2f4  
    3939#include <usbhc_iface.h>
    4040#include <errno.h>
     41#include <assert.h>
    4142
    4243/** Check that HC connection is alright.
     
    172173 *      request or requests for descriptors when creating match ids).
    173174 */
    174 int usb_hc_new_device_wrapper(device_t *parent, usb_hc_connection_t *connection,
     175int usb_hc_new_device_wrapper(ddf_dev_t *parent, usb_hc_connection_t *connection,
    175176    usb_speed_t dev_speed,
    176177    int (*enable_port)(int port_no, void *arg), int port_no, void *arg,
    177     usb_address_t *assigned_address, devman_handle_t *assigned_handle)
     178    usb_address_t *assigned_address, devman_handle_t *assigned_handle,
     179    ddf_dev_ops_t *dev_ops, void *new_dev_data, ddf_fun_t **new_fun)
    178180{
    179181        CHECK_CONNECTION(connection);
     
    251253        devman_handle_t child_handle;
    252254        rc = usb_device_register_child_in_devman(dev_addr, dev_conn.hc_handle,
    253             parent, &child_handle);
     255            parent, &child_handle,
     256            dev_ops, new_dev_data, new_fun);
    254257        if (rc != EOK) {
    255258                rc = ESTALL;
  • uspace/lib/usb/src/pipes.c

    rdbe25f1 reb1a2f4  
    3535#include <usb/usb.h>
    3636#include <usb/pipes.h>
     37#include <usb/debug.h>
    3738#include <usbhc_iface.h>
    3839#include <usb_iface.h>
     40#include <devman.h>
    3941#include <errno.h>
    4042#include <assert.h>
     
    4648 * @return USB address or error code.
    4749 */
    48 static usb_address_t get_my_address(int phone, device_t *dev)
     50static usb_address_t get_my_address(int phone, ddf_dev_t *dev)
    4951{
    5052        sysarg_t address;
     53
     54
     55        /*
     56         * We are sending special value as a handle - zero - to get
     57         * handle of the parent function (that handle was used
     58         * when registering our device @p dev.
     59         */
    5160        int rc = async_req_2_1(phone, DEV_IFACE_ID(USB_DEV_IFACE),
    5261            IPC_M_USB_GET_ADDRESS,
    53             dev->handle, &address);
     62            0, &address);
    5463
    5564        if (rc != EOK) {
     
    6574 * @return Interface number (negative code means any).
    6675 */
    67 int usb_device_get_assigned_interface(device_t *device)
     76int usb_device_get_assigned_interface(ddf_dev_t *device)
    6877{
    6978        int parent_phone = devman_parent_device_connect(device->handle,
     
    94103 */
    95104int usb_device_connection_initialize_from_device(
    96     usb_device_connection_t *connection, device_t *device)
     105    usb_device_connection_t *connection, ddf_dev_t *dev)
    97106{
    98107        assert(connection);
    99         assert(device);
     108        assert(dev);
    100109
    101110        int rc;
     
    103112        usb_address_t my_address;
    104113
    105         rc = usb_hc_find(device->handle, &hc_handle);
     114        rc = usb_hc_find(dev->handle, &hc_handle);
    106115        if (rc != EOK) {
    107116                return rc;
    108117        }
    109118
    110         int parent_phone = devman_parent_device_connect(device->handle,
     119        int parent_phone = devman_parent_device_connect(dev->handle,
    111120            IPC_FLAG_BLOCKING);
    112121        if (parent_phone < 0) {
     
    114123        }
    115124
    116         my_address = get_my_address(parent_phone, device);
     125        my_address = get_my_address(parent_phone, dev);
    117126        if (my_address < 0) {
    118127                rc = my_address;
  • uspace/lib/usb/src/recognise.c

    rdbe25f1 reb1a2f4  
    3434 */
    3535#include <sys/types.h>
     36#include <fibril_synch.h>
    3637#include <usb/pipes.h>
    3738#include <usb/recognise.h>
     
    4142#include <stdio.h>
    4243#include <errno.h>
     44#include <assert.h>
    4345
    4446static size_t device_name_index = 0;
    4547static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex);
    4648
    47 device_ops_t child_ops = {
     49ddf_dev_ops_t child_ops = {
    4850        .interfaces[USB_DEV_IFACE] = &usb_iface_hub_child_impl
    4951};
     
    326328int usb_device_register_child_in_devman(usb_address_t address,
    327329    devman_handle_t hc_handle,
    328     device_t *parent, devman_handle_t *child_handle)
     330    ddf_dev_t *parent, devman_handle_t *child_handle,
     331    ddf_dev_ops_t *dev_ops, void *dev_data, ddf_fun_t **child_fun)
    329332{
    330333        size_t this_device_name_index;
     
    335338        fibril_mutex_unlock(&device_name_index_mutex);
    336339
    337         device_t *child = NULL;
     340        ddf_fun_t *child = NULL;
    338341        char *child_name = NULL;
    339342        int rc;
     
    352355        }
    353356
    354         child = create_device();
     357        /*
     358         * TODO: Once the device driver framework support persistent
     359         * naming etc., something more descriptive could be created.
     360         */
     361        rc = asprintf(&child_name, "usbdev%02zu", this_device_name_index);
     362        if (rc < 0) {
     363                goto failure;
     364        }
     365
     366        child = ddf_fun_create(parent, fun_inner, child_name);
    355367        if (child == NULL) {
    356368                rc = ENOMEM;
     
    358370        }
    359371
    360         /*
    361          * TODO: Once the device driver framework support persistent
    362          * naming etc., something more descriptive could be created.
    363          */
    364         rc = asprintf(&child_name, "usbdev%02zu", this_device_name_index);
    365         if (rc < 0) {
    366                 goto failure;
    367         }
    368         child->parent = parent;
    369         child->name = child_name;
    370         child->ops = &child_ops;
     372        if (dev_ops != NULL) {
     373                child->ops = dev_ops;
     374        } else {
     375                child->ops = &child_ops;
     376        }
     377
     378        child->driver_data = dev_data;
    371379
    372380        rc = usb_endpoint_pipe_start_session(&ctrl_pipe);
     
    385393        }
    386394
    387         rc = child_device_register(child, parent);
     395        rc = ddf_fun_bind(child);
    388396        if (rc != EOK) {
    389397                goto failure;
     
    392400        if (child_handle != NULL) {
    393401                *child_handle = child->handle;
     402        }
     403
     404        if (child_fun != NULL) {
     405                *child_fun = child;
    394406        }
    395407
     
    400412                child->name = NULL;
    401413                /* This takes care of match_id deallocation as well. */
    402                 delete_device(child);
     414                ddf_fun_destroy(child);
    403415        }
    404416        if (child_name != NULL) {
  • uspace/lib/usb/src/request.c

    rdbe25f1 reb1a2f4  
    3535#include <usb/request.h>
    3636#include <errno.h>
     37#include <assert.h>
    3738
    3839#define MAX_DATA_LENGTH ((size_t)(0xFFFF))
  • uspace/lib/usb/src/usbdevice.c

    rdbe25f1 reb1a2f4  
    3737#include <usb_iface.h>
    3838#include <usb/usbdevice.h>
     39#include <usb/debug.h>
    3940#include <errno.h>
     41#include <assert.h>
    4042
    4143/** Find host controller handle that is ancestor of given device.
     
    5557
    5658        devman_handle_t h;
     59        usb_log_debug("asking for HC handle (my handle is %zu).\n", device_handle);
    5760        int rc = async_req_1_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
    5861            IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h);
     
    7881 */
    7982int usb_hc_connection_initialize_from_device(usb_hc_connection_t *connection,
    80     device_t *device)
     83    ddf_dev_t *device)
    8184{
    8285        assert(connection);
  • uspace/lib/usbvirt/src/main.c

    rdbe25f1 reb1a2f4  
    203203        }
    204204       
    205         const char *vhc_path = "/virt/usbhc";
     205        const char *vhc_path = "/virt/usbhc/hc";
    206206        int rc;
    207207        devman_handle_t handle;
Note: See TracChangeset for help on using the changeset viewer.