Changeset 8b655705 in mainline for uspace/drv/rootvirt/rootvirt.c


Ignore:
Timestamp:
2011-04-15T19:38:07Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9dd730d1
Parents:
6b9e85b (diff), b2fb47f (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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/rootvirt/rootvirt.c

    r6b9e85b r8b655705  
    3939#include <errno.h>
    4040#include <str_error.h>
    41 #include <driver.h>
     41#include <ddf/driver.h>
     42#include <ddf/log.h>
    4243
    4344#define NAME "rootvirt"
    4445
    45 /** Virtual device entry. */
     46/** Virtual function entry */
    4647typedef struct {
    47         /** Device name. */
     48        /** Function name */
    4849        const char *name;
    49         /** Device match id. */
     50        /** Function match ID */
    5051        const char *match_id;
    51 } virtual_device_t;
     52} virtual_function_t;
    5253
    53 /** List of existing virtual devices. */
    54 virtual_device_t virtual_devices[] = {
     54/** List of existing virtual functions */
     55virtual_function_t virtual_functions[] = {
    5556#include "devices.def"
    56         /* Terminating item. */
     57        /* Terminating item */
    5758        {
    5859                .name = NULL,
     
    6162};
    6263
    63 static int add_device(device_t *dev);
     64static int rootvirt_add_device(ddf_dev_t *dev);
    6465
    6566static driver_ops_t rootvirt_ops = {
    66         .add_device = &add_device
     67        .add_device = &rootvirt_add_device
    6768};
    6869
     
    7273};
    7374
    74 /** Add child device.
     75/** Add function to the virtual device.
    7576 *
    76  * @param parent Parent device.
    77  * @param virt_dev Virtual device to add.
    78  * @return Error code.
     77 * @param vdev          The virtual device
     78 * @param vfun          Virtual function description
     79 * @return              EOK on success or negative error code.
    7980 */
    80 static int add_child(device_t *parent, virtual_device_t *virt_dev)
     81static int rootvirt_add_fun(ddf_dev_t *vdev, virtual_function_t *vfun)
    8182{
    82         printf(NAME ": registering child device `%s' (match \"%s\")\n",
    83             virt_dev->name, virt_dev->match_id);
     83        ddf_fun_t *fun;
     84        int rc;
    8485
    85         int rc = child_device_register_wrapper(parent, virt_dev->name,
    86             virt_dev->match_id, 10);
     86        ddf_msg(LVL_DEBUG, "Registering function `%s' (match \"%s\")",
     87            vfun->name, vfun->match_id);
    8788
    88         if (rc == EOK) {
    89                 printf(NAME ": registered child device `%s'\n",
    90                     virt_dev->name);
    91         } else {
    92                 printf(NAME ": failed to register child device `%s': %s\n",
    93                     virt_dev->name, str_error(rc));
     89        fun = ddf_fun_create(vdev, fun_inner, vfun->name);
     90        if (fun == NULL) {
     91                ddf_msg(LVL_ERROR, "Failed creating function %s", vfun->name);
     92                return ENOMEM;
    9493        }
    9594
    96         return rc;
     95        rc = ddf_fun_add_match_id(fun, vfun->match_id, 10);
     96        if (rc != EOK) {
     97                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     98                    vfun->name);
     99                ddf_fun_destroy(fun);
     100                return rc;
     101        }
     102
     103        rc = ddf_fun_bind(fun);
     104        if (rc != EOK) {
     105                ddf_msg(LVL_ERROR, "Failed binding function %s: %s",
     106                    vfun->name, str_error(rc));
     107                ddf_fun_destroy(fun);
     108                return rc;
     109        }
     110
     111        ddf_msg(LVL_NOTE, "Registered child device `%s'", vfun->name);
     112        return EOK;
    97113}
    98114
    99 static int add_device(device_t *dev)
     115static int rootvirt_add_device(ddf_dev_t *dev)
    100116{
    101117        static int instances = 0;
     
    109125        }
    110126
    111         printf(NAME ": add_device(name=\"%s\", handle=%d)\n",
    112             dev->name, (int)dev->handle);
    113        
     127        ddf_msg(LVL_DEBUG, "add_device(handle=%d)", (int)dev->handle);
     128
    114129        /*
    115          * Go through all virtual devices and try to add them.
     130         * Go through all virtual functions and try to add them.
    116131         * We silently ignore failures.
    117132         */
    118         virtual_device_t *virt_dev = virtual_devices;
    119         while (virt_dev->name != NULL) {
    120                 (void) add_child(dev, virt_dev);
    121                 virt_dev++;
     133        virtual_function_t *vfun = virtual_functions;
     134        while (vfun->name != NULL) {
     135                (void) rootvirt_add_fun(dev, vfun);
     136                vfun++;
    122137        }
    123138
     
    128143{
    129144        printf(NAME ": HelenOS virtual devices root driver\n");
    130         return driver_main(&rootvirt_driver);
     145
     146        ddf_log_init(NAME, LVL_ERROR);
     147        return ddf_driver_main(&rootvirt_driver);
    131148}
    132149
Note: See TracChangeset for help on using the changeset viewer.