Ignore:
File:
1 edited

Legend:

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

    raf6b5157 r6f9e7fea  
    3939#include <errno.h>
    4040#include <str_error.h>
    41 #include <ddf/driver.h>
     41#include <driver.h>
    4242
    4343#define NAME "rootvirt"
    4444
    45 /** Virtual function entry */
     45/** Virtual device entry. */
    4646typedef struct {
    47         /** Function name */
     47        /** Device name. */
    4848        const char *name;
    49         /** Function match ID */
     49        /** Device match id. */
    5050        const char *match_id;
    51 } virtual_function_t;
     51} virtual_device_t;
    5252
    53 /** List of existing virtual functions */
    54 virtual_function_t virtual_functions[] = {
     53/** List of existing virtual devices. */
     54virtual_device_t virtual_devices[] = {
    5555#include "devices.def"
    56         /* Terminating item */
     56        /* Terminating item. */
    5757        {
    5858                .name = NULL,
     
    6161};
    6262
    63 static int rootvirt_add_device(ddf_dev_t *dev);
     63static int add_device(device_t *dev);
    6464
    6565static driver_ops_t rootvirt_ops = {
    66         .add_device = &rootvirt_add_device
     66        .add_device = &add_device
    6767};
    6868
     
    7272};
    7373
    74 /** Add function to the virtual device.
     74/** Add child device.
    7575 *
    76  * @param vdev          The virtual device
    77  * @param vfun          Virtual function description
    78  * @return              EOK on success or negative error code.
     76 * @param parent Parent device.
     77 * @param virt_dev Virtual device to add.
     78 * @return Error code.
    7979 */
    80 static int rootvirt_add_fun(ddf_dev_t *vdev, virtual_function_t *vfun)
     80static int add_child(device_t *parent, virtual_device_t *virt_dev)
    8181{
    82         ddf_fun_t *fun;
    83         int rc;
     82        printf(NAME ": registering child device `%s' (match \"%s\")\n",
     83            virt_dev->name, virt_dev->match_id);
    8484
    85         printf(NAME ": registering function `%s' (match \"%s\")\n",
    86             vfun->name, vfun->match_id);
     85        int rc = child_device_register_wrapper(parent, virt_dev->name,
     86            virt_dev->match_id, 10);
    8787
    88         fun = ddf_fun_create(vdev, fun_inner, vfun->name);
    89         if (fun == NULL) {
    90                 printf(NAME ": error creating function %s\n", vfun->name);
    91                 return ENOMEM;
     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));
    9294        }
    9395
    94         rc = ddf_fun_add_match_id(fun, vfun->match_id, 10);
    95         if (rc != EOK) {
    96                 printf(NAME ": error adding match IDs to function %s\n",
    97                     vfun->name);
    98                 ddf_fun_destroy(fun);
    99                 return rc;
    100         }
    101 
    102         rc = ddf_fun_bind(fun);
    103         if (rc != EOK) {
    104                 printf(NAME ": error binding function %s: %s\n", vfun->name,
    105                     str_error(rc));
    106                 ddf_fun_destroy(fun);
    107                 return rc;
    108         }
    109 
    110         printf(NAME ": registered child device `%s'\n", vfun->name);
    111         return EOK;
     96        return rc;
    11297}
    11398
    114 static int rootvirt_add_device(ddf_dev_t *dev)
     99static int add_device(device_t *dev)
    115100{
    116101        static int instances = 0;
     
    124109        }
    125110
    126         printf(NAME ": add_device(handle=%d)\n", (int)dev->handle);
    127 
     111        printf(NAME ": add_device(name=\"%s\", handle=%d)\n",
     112            dev->name, dev->handle);
     113       
    128114        /*
    129          * Go through all virtual functions and try to add them.
     115         * Go through all virtual devices and try to add them.
    130116         * We silently ignore failures.
    131117         */
    132         virtual_function_t *vfun = virtual_functions;
    133         while (vfun->name != NULL) {
    134                 (void) rootvirt_add_fun(dev, vfun);
    135                 vfun++;
     118        virtual_device_t *virt_dev = virtual_devices;
     119        while (virt_dev->name != NULL) {
     120                (void) add_child(dev, virt_dev);
     121                virt_dev++;
    136122        }
    137123
     
    142128{
    143129        printf(NAME ": HelenOS virtual devices root driver\n");
    144         return ddf_driver_main(&rootvirt_driver);
     130        return driver_main(&rootvirt_driver);
    145131}
    146132
Note: See TracChangeset for help on using the changeset viewer.