Changeset 2568c94 in mainline for uspace/lib/drv


Ignore:
Timestamp:
2012-08-17T17:15:19Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1789023
Parents:
4f351432 (diff), 01e397ac (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

Location:
uspace/lib/drv
Files:
1 added
4 edited

Legend:

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

    r4f351432 r2568c94  
    3636/** @file
    3737 */
     38
     39#define _DDF_DATA_IMPLANT
    3840
    3941#include <assert.h>
     
    5860#include "ddf/driver.h"
    5961#include "ddf/interrupt.h"
     62#include "private/driver.h"
    6063
    6164/** Driver structure */
     
    523526static void delete_device(ddf_dev_t *dev)
    524527{
     528        if (dev->parent_sess)
     529                async_hangup(dev->parent_sess);
    525530        if (dev->driver_data != NULL)
    526531                free(dev->driver_data);
     
    597602}
    598603
     604/** Implant foreign driver-specific device data.
     605 *
     606 * XXX This is used to transition USB to new interface. Do not use
     607 * in new code. Use of this function must be removed.
     608 */
     609void ddf_fun_data_implant(ddf_fun_t *fun, void *data)
     610{
     611        assert(fun->driver_data == NULL);
     612        fun->driver_data = data;
     613}
     614
     615/** Return driver-specific device data. */
     616void *ddf_dev_data_get(ddf_dev_t *dev)
     617{
     618        return dev->driver_data;
     619}
     620
     621/** Get device handle. */
     622devman_handle_t ddf_dev_get_handle(ddf_dev_t *dev)
     623{
     624        return dev->handle;
     625}
     626
     627/** Return device name.
     628 *
     629 * @param dev   Device
     630 * @return      Device name. Valid as long as @a dev is valid.
     631 */
     632const char *ddf_dev_get_name(ddf_dev_t *dev)
     633{
     634        return dev->name;
     635}
     636
     637/** Create session with the parent function.
     638 *
     639 * The session will be automatically closed when @a dev is destroyed.
     640 *
     641 * @param dev   Device
     642 * @param mgmt  Exchange management style
     643 * @return      New session or NULL if session could not be created
     644 */
     645async_sess_t *ddf_dev_parent_sess_create(ddf_dev_t *dev, exch_mgmt_t mgmt)
     646{
     647        assert(dev->parent_sess == NULL);
     648        dev->parent_sess = devman_parent_device_connect(mgmt, dev->handle,
     649            IPC_FLAG_BLOCKING);
     650
     651        return dev->parent_sess;
     652}
     653
     654/** Return existing session with the parent function.
     655 *
     656 * @param dev   Device
     657 * @return      Existing session or NULL if there is no session
     658 */
     659async_sess_t *ddf_dev_parent_sess_get(ddf_dev_t *dev)
     660{
     661        return dev->parent_sess;
     662}
     663
     664/** Set function name (if it was not specified when node was created.)
     665 *
     666 * @param dev   Device whose name has not been set yet
     667 * @param name  Name, will be copied
     668 * @return      EOK on success, ENOMEM if out of memory
     669 */
     670int ddf_fun_set_name(ddf_fun_t *dev, const char *name)
     671{
     672        assert(dev->name == NULL);
     673
     674        dev->name = str_dup(name);
     675        if (dev->name == NULL)
     676                return ENOENT;
     677
     678        return EOK;
     679}
     680
     681/** Get device to which function belongs. */
     682ddf_dev_t *ddf_fun_get_dev(ddf_fun_t *fun)
     683{
     684        return fun->dev;
     685}
     686
     687/** Get function handle.
     688 *
     689 * XXX USB uses this, but its use should be eliminated.
     690 */
     691devman_handle_t ddf_fun_get_handle(ddf_fun_t *fun)
     692{
     693        return fun->handle;
     694}
     695
    599696/** Create a DDF function node.
    600697 *
     
    608705 * This function should only fail if there is not enough free memory.
    609706 * Specifically, this function succeeds even if @a dev already has
    610  * a (bound) function with the same name.
     707 * a (bound) function with the same name. @a name can be NULL in which
     708 * case the caller will set the name later using ddf_fun_set_name().
     709 * He must do this before binding the function.
    611710 *
    612711 * Type: A function of type fun_inner indicates that DDF should attempt
     
    616715 * @param dev           Device to which we are adding function
    617716 * @param ftype         Type of function (fun_inner or fun_exposed)
    618  * @param name          Name of function
     717 * @param name          Name of function or NULL
    619718 *
    620719 * @return              New function or @c NULL if memory is not available
     
    633732        fun->ftype = ftype;
    634733       
    635         fun->name = str_dup(name);
    636         if (fun->name == NULL) {
    637                 delete_function(fun);
    638                 return NULL;
     734        if (name != NULL) {
     735                fun->name = str_dup(name);
     736                if (fun->name == NULL) {
     737                        delete_function(fun);
     738                        return NULL;
     739                }
    639740        }
    640741       
     
    654755        fun->driver_data = data;
    655756        return data;
     757}
     758
     759/** Return driver-specific function data. */
     760void *ddf_fun_data_get(ddf_fun_t *fun)
     761{
     762        return fun->driver_data;
     763}
     764
     765/** Return function name.
     766 *
     767 * @param fun   Function
     768 * @return      Function name. Valid as long as @a fun is valid.
     769 */
     770const char *ddf_fun_get_name(ddf_fun_t *fun)
     771{
     772        return fun->name;
    656773}
    657774
     
    805922        add_match_id(&fun->match_ids, match_id);
    806923        return EOK;
     924}
     925
     926/** Set function ops. */
     927void ddf_fun_set_ops(ddf_fun_t *fun, ddf_dev_ops_t *dev_ops)
     928{
     929        assert(fun->conn_handler == NULL);
     930        fun->ops = dev_ops;
     931}
     932
     933/** Set user-defined connection handler.
     934 *
     935 * This allows handling connections the non-devman way.
     936 */
     937void ddf_fun_set_conn_handler(ddf_fun_t *fun, async_client_conn_t conn)
     938{
     939        assert(fun->ops == NULL);
     940        fun->conn_handler = conn;
    807941}
    808942
  • uspace/lib/drv/generic/interrupt.c

    r4f351432 r2568c94  
    4141
    4242#include "ddf/interrupt.h"
     43#include "private/driver.h"
    4344
    4445static void driver_irq_handler(ipc_callid_t iid, ipc_call_t *icall);
  • uspace/lib/drv/generic/remote_graph_dev.c

    r4f351432 r2568c94  
    5656        graph_dev_ops_t *graph_dev_ops = (graph_dev_ops_t *) ops;
    5757
    58         if (!graph_dev_ops->connect || !fun->driver_data) {
     58        if (!graph_dev_ops->connect || !ddf_fun_data_get(fun)) {
    5959                async_answer_0(callid, ENOTSUP);
    6060                return;
    6161        }
    6262
    63         (*graph_dev_ops->connect)(fun->driver_data, callid, call, NULL);
     63        (*graph_dev_ops->connect)(ddf_fun_data_get(fun), callid, call, NULL);
    6464}
    6565
  • uspace/lib/drv/include/ddf/driver.h

    r4f351432 r2568c94  
    4242#include "../dev_iface.h"
    4343
    44 typedef struct ddf_dev ddf_dev_t;
    45 typedef struct ddf_fun ddf_fun_t;
    4644
    4745/*
    4846 * Device
    4947 */
     48
     49typedef struct ddf_dev ddf_dev_t;
     50typedef struct ddf_fun ddf_fun_t;
    5051
    5152/** Devices operations */
     
    7576
    7677/** Device structure */
    77 struct ddf_dev {
    78         /**
    79          * Globally unique device identifier (assigned to the device by the
    80          * device manager).
    81          */
    82         devman_handle_t handle;
    83        
    84         /** Reference count */
    85         atomic_t refcnt;
    86        
    87         /**
    88          * Session to the parent device driver (if it is different from this
    89          * driver)
    90          */
    91         async_sess_t *parent_sess;
    92        
    93         /** Device name */
    94         const char *name;
    95        
    96         /** Driver-specific data associated with this device */
    97         void *driver_data;
    98        
    99         /** Link in the list of devices handled by the driver */
    100         link_t link;
    101 };
     78struct ddf_dev;
    10279
    10380/** Function structure */
    104 struct ddf_fun {
    105         /** True if bound to the device manager */
    106         bool bound;
    107        
    108         /** Function indentifier (asigned by device manager) */
    109         devman_handle_t handle;
    110        
    111         /** Reference count */
    112         atomic_t refcnt;
    113        
    114         /** Device which this function belogs to */
    115         ddf_dev_t *dev;
    116        
    117         /** Function type */
    118         fun_type_t ftype;
    119        
    120         /** Function name */
    121         const char *name;
    122        
    123         /** List of device ids for driver matching */
    124         match_id_list_t match_ids;
    125        
    126         /** Driver-specific data associated with this function */
    127         void *driver_data;
    128        
    129         /** Implementation of operations provided by this function */
    130         ddf_dev_ops_t *ops;
    131        
    132         /** Connection handler or @c NULL to use the DDF default handler. */
    133         async_client_conn_t conn_handler;
    134        
    135         /** Link in the list of functions handled by the driver */
    136         link_t link;
    137 };
     81struct ddf_fun;
    13882
    13983/*
     
    167111} driver_t;
    168112
     113/** XXX Only to transition USB */
     114#ifdef _DDF_DATA_IMPLANT
     115extern void ddf_fun_data_implant(ddf_fun_t *, void *);
     116#endif
     117
    169118extern int ddf_driver_main(driver_t *);
    170119
    171120extern void *ddf_dev_data_alloc(ddf_dev_t *, size_t);
     121extern void *ddf_dev_data_get(ddf_dev_t *);
     122extern devman_handle_t ddf_dev_get_handle(ddf_dev_t *);
     123extern const char *ddf_dev_get_name(ddf_dev_t *);
     124extern async_sess_t *ddf_dev_parent_sess_create(ddf_dev_t *, exch_mgmt_t);
     125extern async_sess_t *ddf_dev_parent_sess_get(ddf_dev_t *);
    172126extern ddf_fun_t *ddf_fun_create(ddf_dev_t *, fun_type_t, const char *);
     127extern devman_handle_t ddf_fun_get_handle(ddf_fun_t *);
    173128extern void ddf_fun_destroy(ddf_fun_t *);
    174129extern void *ddf_fun_data_alloc(ddf_fun_t *, size_t);
     130extern void *ddf_fun_data_get(ddf_fun_t *);
     131extern const char *ddf_fun_get_name(ddf_fun_t *);
     132extern int ddf_fun_set_name(ddf_fun_t *, const char *);
     133extern ddf_dev_t *ddf_fun_get_dev(ddf_fun_t *);
    175134extern int ddf_fun_bind(ddf_fun_t *);
    176135extern int ddf_fun_unbind(ddf_fun_t *);
     
    178137extern int ddf_fun_offline(ddf_fun_t *);
    179138extern int ddf_fun_add_match_id(ddf_fun_t *, const char *, int);
    180 
     139extern void ddf_fun_set_ops(ddf_fun_t *, ddf_dev_ops_t *);
     140extern void ddf_fun_set_conn_handler(ddf_fun_t *, async_client_conn_t);
    181141extern int ddf_fun_add_to_category(ddf_fun_t *, const char *);
    182142
Note: See TracChangeset for help on using the changeset viewer.