Ignore:
File:
1 edited

Legend:

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

    rdeac215e r5203e256  
    6363
    6464static int rootvirt_add_device(ddf_dev_t *dev);
    65 static int rootvirt_dev_remove(ddf_dev_t *dev);
    66 static int rootvirt_fun_online(ddf_fun_t *fun);
    67 static int rootvirt_fun_offline(ddf_fun_t *fun);
    6865
    6966static driver_ops_t rootvirt_ops = {
    70         .add_device = &rootvirt_add_device,
    71         .dev_remove = &rootvirt_dev_remove,
    72         .fun_online = &rootvirt_fun_online,
    73         .fun_offline = &rootvirt_fun_offline
     67        .add_device = &rootvirt_add_device
    7468};
    7569
     
    7973};
    8074
    81 /* Device soft state */
    82 typedef struct {
    83         ddf_dev_t *dev;
    84         list_t functions;
    85 } rootvirt_t;
    86 
    87 /* Function soft state */
    88 typedef struct {
    89         ddf_fun_t *fun;
    90         link_t dev_link;
    91 } rootvirt_fun_t;
    92 
    93 static int instances = 0;
    94 
    95 
    9675/** Add function to the virtual device.
    9776 *
     
    10079 * @return              EOK on success or negative error code.
    10180 */
    102 static int rootvirt_add_fun(rootvirt_t *rootvirt, virtual_function_t *vfun)
     81static int rootvirt_add_fun(ddf_dev_t *vdev, virtual_function_t *vfun)
    10382{
    104         ddf_dev_t *vdev = rootvirt->dev;
    10583        ddf_fun_t *fun;
    106         rootvirt_fun_t *rvfun;
    10784        int rc;
    10885
     
    11592                return ENOMEM;
    11693        }
    117 
    118         rvfun = ddf_fun_data_alloc(fun, sizeof(rootvirt_fun_t));
    119         if (rvfun == NULL) {
    120                 ddf_msg(LVL_ERROR, "Failed allocating soft state for %s.",
    121                     vfun->name);
    122                 ddf_fun_destroy(fun);
    123                 return ENOMEM;
    124         }
    125 
    126         rvfun->fun = fun;
    12794
    12895        rc = ddf_fun_add_match_id(fun, vfun->match_id, 10);
     
    142109        }
    143110
    144         list_append(&rvfun->dev_link, &rootvirt->functions);
    145 
    146111        ddf_msg(LVL_NOTE, "Registered child device `%s'", vfun->name);
    147112        return EOK;
    148113}
    149114
    150 static int rootvirt_fun_remove(rootvirt_fun_t *rvfun)
    151 {
    152         int rc;
    153         const char *name = rvfun->fun->name;
    154 
    155         ddf_msg(LVL_DEBUG, "rootvirt_fun_remove('%s')", name);
    156         rc = ddf_fun_offline(rvfun->fun);
    157         if (rc != EOK) {
    158                 ddf_msg(LVL_ERROR, "Error offlining function '%s'.", name);
    159                 return rc;
    160         }
    161 
    162         rc = ddf_fun_unbind(rvfun->fun);
    163         if (rc != EOK) {
    164                 ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", name);
    165                 return rc;
    166         }
    167 
    168         list_remove(&rvfun->dev_link);
    169         ddf_fun_destroy(rvfun->fun);
    170         return EOK;
    171 }
    172 
    173 
    174115static int rootvirt_add_device(ddf_dev_t *dev)
    175116{
    176         rootvirt_t *rootvirt;
     117        static int instances = 0;
    177118
    178119        /*
    179120         * Allow only single instance of root virtual device.
    180121         */
    181         if (++instances > 1) {
     122        instances++;
     123        if (instances > 1) {
    182124                return ELIMIT;
    183125        }
    184126
    185127        ddf_msg(LVL_DEBUG, "add_device(handle=%d)", (int)dev->handle);
    186 
    187         rootvirt = ddf_dev_data_alloc(dev, sizeof(rootvirt_t));
    188         if (rootvirt == NULL)
    189                 return ENOMEM;
    190 
    191         rootvirt->dev = dev;
    192         list_initialize(&rootvirt->functions);
    193128
    194129        /*
     
    198133        virtual_function_t *vfun = virtual_functions;
    199134        while (vfun->name != NULL) {
    200                 (void) rootvirt_add_fun(rootvirt, vfun);
     135                (void) rootvirt_add_fun(dev, vfun);
    201136                vfun++;
    202137        }
    203138
    204139        return EOK;
    205 }
    206 
    207 static int rootvirt_dev_remove(ddf_dev_t *dev)
    208 {
    209         rootvirt_t *rootvirt = (rootvirt_t *)dev->driver_data;
    210         int rc;
    211 
    212         while (!list_empty(&rootvirt->functions)) {
    213                 rootvirt_fun_t *rvfun = list_get_instance(
    214                     list_first(&rootvirt->functions), rootvirt_fun_t,
    215                         dev_link);
    216 
    217                 rc = rootvirt_fun_remove(rvfun);
    218                 if (rc != EOK)
    219                         return rc;
    220         }
    221 
    222         --instances;
    223         return EOK;
    224 }
    225 
    226 static int rootvirt_fun_online(ddf_fun_t *fun)
    227 {
    228         ddf_msg(LVL_DEBUG, "rootvirt_fun_online()");
    229         return ddf_fun_online(fun);
    230 }
    231 
    232 static int rootvirt_fun_offline(ddf_fun_t *fun)
    233 {
    234         ddf_msg(LVL_DEBUG, "rootvirt_fun_offline()");
    235         return ddf_fun_offline(fun);
    236140}
    237141
Note: See TracChangeset for help on using the changeset viewer.