Changeset fd9b3a67 in mainline


Ignore:
Timestamp:
2013-01-27T00:44:23Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
71384bd3
Parents:
8b68bdf
Message:

libusbdev: Make usb_device_t opaque.

Location:
uspace/lib/usbdev
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/include/usb/dev/driver.h

    r8b68bdf rfd9b3a67  
    4343#include <usb_iface.h>
    4444
    45 /** USB device structure. */
    46 typedef struct {
    47         /** Connection to USB hc, used by wire and arbitrary requests. */
    48         usb_hc_connection_t hc_conn;
    49         /** Connection backing the pipes.
    50          * Typically, you will not need to use this attribute at all.
    51          */
    52         usb_device_connection_t wire;
    53         /** The default control pipe. */
    54         usb_pipe_t ctrl_pipe;
    55 
    56         /** Other endpoint pipes.
    57          * This is an array of other endpoint pipes in the same order as
    58          * in usb_driver_t.
    59          */
    60         usb_endpoint_mapping_t *pipes;
    61         /** Number of other endpoint pipes. */
    62         size_t pipes_count;
    63         /** Current interface.
    64          * Usually, drivers operate on single interface only.
    65          * This item contains the value of the interface or -1 for any.
    66          */
    67         int interface_no;
    68         /** Alternative interfaces. */
    69         usb_alternate_interfaces_t alternate_interfaces;
    70 
    71         /** Some useful descriptors for USB device. */
    72         struct {
    73                 /** Standard device descriptor. */
    74                 usb_standard_device_descriptor_t device;
    75                 /** Full configuration descriptor of current configuration. */
    76                 const uint8_t *configuration;
    77                 size_t configuration_size;
    78         } descriptors;
    79 
    80         /** Generic DDF device backing this one. DO NOT TOUCH! */
    81         ddf_dev_t *ddf_dev;
    82         /** Custom driver data.
    83          * Do not use the entry in generic device, that is already used
    84          * by the framework.
    85          */
    86         void *driver_data;
    87 
    88         usb_dev_session_t *bus_session;
    89 } usb_device_t;
     45typedef struct usb_device usb_device_t;
    9046
    9147/** USB driver ops. */
     
    14298int usb_driver_main(const usb_driver_t *);
    14399
    144 int usb_device_init(usb_device_t *, ddf_dev_t *,
    145     const usb_endpoint_description_t **, const char **);
    146 void usb_device_deinit(usb_device_t *);
     100int usb_device_create_ddf(ddf_dev_t *, const usb_endpoint_description_t **, const char **);
     101void usb_device_destroy_ddf(ddf_dev_t *);
    147102
    148103const char* usb_device_get_name(usb_device_t *);
  • uspace/lib/usbdev/src/devdrv.c

    r8b68bdf rfd9b3a67  
    4040#include <str_error.h>
    4141#include <assert.h>
     42
     43/** USB device structure. */
     44typedef struct usb_device {
     45        /** Connection to USB hc, used by wire and arbitrary requests. */
     46        usb_hc_connection_t hc_conn;
     47        /** Connection backing the pipes.
     48         * Typically, you will not need to use this attribute at all.
     49         */
     50        usb_device_connection_t wire;
     51        /** The default control pipe. */
     52        usb_pipe_t ctrl_pipe;
     53
     54        /** Other endpoint pipes.
     55         * This is an array of other endpoint pipes in the same order as
     56         * in usb_driver_t.
     57         */
     58        usb_endpoint_mapping_t *pipes;
     59        /** Number of other endpoint pipes. */
     60        size_t pipes_count;
     61        /** Current interface.
     62         * Usually, drivers operate on single interface only.
     63         * This item contains the value of the interface or -1 for any.
     64         */
     65        int interface_no;
     66        /** Alternative interfaces. */
     67        usb_alternate_interfaces_t alternate_interfaces;
     68
     69        /** Some useful descriptors for USB device. */
     70        struct {
     71                /** Standard device descriptor. */
     72                usb_standard_device_descriptor_t device;
     73                /** Full configuration descriptor of current configuration. */
     74                const uint8_t *configuration;
     75                size_t configuration_size;
     76        } descriptors;
     77
     78        /** Generic DDF device backing this one. DO NOT TOUCH! */
     79        ddf_dev_t *ddf_dev;
     80        /** Custom driver data.
     81         * Do not use the entry in generic device, that is already used
     82         * by the framework.
     83         */
     84        void *driver_data;
     85
     86        usb_dev_session_t *bus_session;
     87} usb_device_t;
    4288
    4389/** Count number of pipes the driver expects.
     
    350396 * @return Error code.
    351397 */
    352 int usb_device_init(usb_device_t *usb_dev, ddf_dev_t *ddf_dev,
     398static int usb_device_init(usb_device_t *usb_dev, ddf_dev_t *ddf_dev,
    353399    const usb_endpoint_description_t **endpoints, const char **errstr_ptr)
    354400{
     
    446492 * Does not free/destroy supplied pointer.
    447493 */
    448 void usb_device_deinit(usb_device_t *dev)
     494static void usb_device_fini(usb_device_t *dev)
    449495{
    450496        if (dev) {
     
    461507}
    462508
     509int usb_device_create_ddf(ddf_dev_t *ddf_dev,
     510    const usb_endpoint_description_t **desc, const char **err)
     511{
     512        assert(ddf_dev);
     513        assert(err);
     514        usb_device_t *dev = ddf_dev_data_alloc(ddf_dev, sizeof(usb_device_t));
     515        if (dev == NULL) {
     516                *err = "DDF data alloc";
     517                return ENOMEM;
     518        }
     519        return usb_device_init(dev, ddf_dev, desc, err);
     520}
     521
     522void usb_device_destroy_ddf(ddf_dev_t *ddf_dev)
     523{
     524        assert(ddf_dev);
     525        usb_device_t *dev = ddf_dev_data_get(ddf_dev);
     526        assert(dev);
     527        usb_device_fini(dev);
     528        return;
     529}
     530
    463531const char *usb_device_get_name(usb_device_t *usb_dev)
    464532{
  • uspace/lib/usbdev/src/driver.c

    r8b68bdf rfd9b3a67  
    5454        assert(driver->ops->device_add);
    5555
    56         /* Get place for driver data. */
    57         usb_device_t *dev = ddf_dev_data_alloc(gen_dev, sizeof(usb_device_t));
    58         if (dev == NULL) {
    59                 usb_log_error("USB device `%s' structure allocation failed.\n",
    60                     ddf_dev_get_name(gen_dev));
    61                 return ENOMEM;
    62         }
    63 
    6456        /* Initialize generic USB driver data. */
    6557        const char *err_msg = NULL;
    66         int rc = usb_device_init(dev, gen_dev, driver->endpoints, &err_msg);
     58        int rc = usb_device_create_ddf(gen_dev, driver->endpoints, &err_msg);
    6759        if (rc != EOK) {
    6860                usb_log_error("USB device `%s' init failed (%s): %s.\n",
     
    7264
    7365        /* Start USB driver specific initialization. */
    74         rc = driver->ops->device_add(dev);
     66        rc = driver->ops->device_add(ddf_dev_data_get(gen_dev));
    7567        if (rc != EOK)
    76                 usb_device_deinit(dev);
     68                usb_device_destroy_ddf(gen_dev);
    7769        return rc;
    7870}
     
    9688        if (ret != EOK)
    9789                return ret;
    98         usb_device_deinit(usb_dev);
     90        usb_device_destroy_ddf(gen_dev);
    9991        return EOK;
    10092}
     
    116108        const int ret = driver->ops->device_gone(usb_dev);
    117109        if (ret == EOK)
    118                 usb_device_deinit(usb_dev);
     110                usb_device_destroy_ddf(gen_dev);
    119111
    120112        return ret;
Note: See TracChangeset for help on using the changeset viewer.