Changeset 00aece0 in mainline for uspace/drv/infrastructure


Ignore:
Timestamp:
2012-02-18T16:47:38Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4449c6c
Parents:
bd5f3b7 (diff), f943dd3 (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/drv/infrastructure
Files:
5 edited

Legend:

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

    rbd5f3b7 r00aece0  
    6666#define VIRTUAL_FUN_MATCH_SCORE 100
    6767
    68 static int root_add_device(ddf_dev_t *dev);
     68static int root_dev_add(ddf_dev_t *dev);
     69static int root_fun_online(ddf_fun_t *fun);
     70static int root_fun_offline(ddf_fun_t *fun);
    6971
    7072/** The root device driver's standard operations. */
    7173static driver_ops_t root_ops = {
    72         .add_device = &root_add_device
     74        .dev_add = &root_dev_add,
     75        .fun_online = &root_fun_online,
     76        .fun_offline = &root_fun_offline
    7377};
    7478
     
    154158        if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) {
    155159                ddf_msg(LVL_ERROR, "Memory allocation failed.");
    156                 return ENOMEM;
    157         }
     160                free(platform);
     161                return ENOMEM;
     162        }
     163
     164        free(platform);
    158165
    159166        /* Add function. */
     
    165172        if (fun == NULL) {
    166173                ddf_msg(LVL_ERROR, "Error creating function %s", name);
     174                free(match_id);
    167175                return ENOMEM;
    168176        }
     
    172180                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
    173181                    name);
     182                free(match_id);
    174183                ddf_fun_destroy(fun);
    175184                return rc;
     
    194203 *                      of HW and pseudo devices).
    195204 */
    196 static int root_add_device(ddf_dev_t *dev)
    197 {
    198         ddf_msg(LVL_DEBUG, "root_add_device, device handle=%" PRIun,
     205static int root_dev_add(ddf_dev_t *dev)
     206{
     207        ddf_msg(LVL_DEBUG, "root_dev_add, device handle=%" PRIun,
    199208            dev->handle);
    200209
     
    204213         * vital for the system.
    205214         */
    206         add_virtual_root_fun(dev);
     215        (void) add_virtual_root_fun(dev);
    207216
    208217        /* Register root device's children. */
     
    214223}
    215224
     225static int root_fun_online(ddf_fun_t *fun)
     226{
     227        ddf_msg(LVL_DEBUG, "root_fun_online()");
     228        return ddf_fun_online(fun);
     229}
     230
     231static int root_fun_offline(ddf_fun_t *fun)
     232{
     233        ddf_msg(LVL_DEBUG, "root_fun_offline()");
     234        return ddf_fun_offline(fun);
     235}
     236
    216237int main(int argc, char *argv[])
    217238{
  • uspace/drv/infrastructure/rootmac/rootmac.c

    rbd5f3b7 r00aece0  
    125125 *
    126126 */
    127 static int rootmac_add_device(ddf_dev_t *dev)
     127static int rootmac_dev_add(ddf_dev_t *dev)
    128128{
    129129        /* Register functions */
     
    136136/** The root device driver's standard operations. */
    137137static driver_ops_t rootmac_ops = {
    138         .add_device = &rootmac_add_device
     138        .dev_add = &rootmac_dev_add
    139139};
    140140
     
    161161
    162162static hw_res_ops_t fun_hw_res_ops = {
    163         &rootmac_get_resources,
    164         &rootmac_enable_interrupt
     163        .get_resource_list = &rootmac_get_resources,
     164        .enable_interrupt = &rootmac_enable_interrupt
    165165};
    166166
  • uspace/drv/infrastructure/rootpc/rootpc.c

    rbd5f3b7 r00aece0  
    6363} rootpc_fun_t;
    6464
    65 static int rootpc_add_device(ddf_dev_t *dev);
     65static int rootpc_dev_add(ddf_dev_t *dev);
    6666static void root_pc_init(void);
    6767
    6868/** The root device driver's standard operations. */
    6969static driver_ops_t rootpc_ops = {
    70         .add_device = &rootpc_add_device
     70        .dev_add = &rootpc_dev_add
    7171};
    7272
     
    109109
    110110static hw_res_ops_t fun_hw_res_ops = {
    111         &rootpc_get_resources,
    112         &rootpc_enable_interrupt
     111        .get_resource_list = &rootpc_get_resources,
     112        .enable_interrupt = &rootpc_enable_interrupt,
    113113};
    114114
     
    175175 * @return              Zero on success, negative error number otherwise.
    176176 */
    177 static int rootpc_add_device(ddf_dev_t *dev)
    178 {
    179         ddf_msg(LVL_DEBUG, "rootpc_add_device, device handle = %d",
     177static int rootpc_dev_add(ddf_dev_t *dev)
     178{
     179        ddf_msg(LVL_DEBUG, "rootpc_dev_add, device handle = %d",
    180180            (int)dev->handle);
    181181       
  • uspace/drv/infrastructure/rootvirt/devices.def

    rbd5f3b7 r00aece0  
    44 * Unless the list is empty, the last item shall be followed by a comma.
    55 */
     6
     7/* Loopback network interface */
     8{
     9    .name = "lo",
     10    .match_id = "virtual&loopback"
     11},
     12
    613#ifdef CONFIG_TEST_DRIVERS
     14
    715{
    816        .name = "test1",
     
    2533        .match_id = "virtual&test3"
    2634},
     35
    2736#endif
     37
    2838#ifdef CONFIG_RUN_VIRTUAL_USB_HC
     39
    2940/* Virtual USB host controller. */
    3041{
     
    3243        .match_id = "usb&hc=vhc"
    3344},
     45
    3446#endif
  • uspace/drv/infrastructure/rootvirt/rootvirt.c

    rbd5f3b7 r00aece0  
    6262};
    6363
    64 static int rootvirt_add_device(ddf_dev_t *dev);
     64static int rootvirt_dev_add(ddf_dev_t *dev);
     65static int rootvirt_dev_remove(ddf_dev_t *dev);
     66static int rootvirt_fun_online(ddf_fun_t *fun);
     67static int rootvirt_fun_offline(ddf_fun_t *fun);
    6568
    6669static driver_ops_t rootvirt_ops = {
    67         .add_device = &rootvirt_add_device
     70        .dev_add = &rootvirt_dev_add,
     71        .dev_remove = &rootvirt_dev_remove,
     72        .fun_online = &rootvirt_fun_online,
     73        .fun_offline = &rootvirt_fun_offline
    6874};
    6975
     
    7379};
    7480
     81/* Device soft state */
     82typedef struct {
     83        ddf_dev_t *dev;
     84        list_t functions;
     85} rootvirt_t;
     86
     87/* Function soft state */
     88typedef struct {
     89        ddf_fun_t *fun;
     90        link_t dev_link;
     91} rootvirt_fun_t;
     92
     93static int instances = 0;
     94
     95
    7596/** Add function to the virtual device.
    7697 *
     
    79100 * @return              EOK on success or negative error code.
    80101 */
    81 static int rootvirt_add_fun(ddf_dev_t *vdev, virtual_function_t *vfun)
    82 {
     102static int rootvirt_add_fun(rootvirt_t *rootvirt, virtual_function_t *vfun)
     103{
     104        ddf_dev_t *vdev = rootvirt->dev;
    83105        ddf_fun_t *fun;
     106        rootvirt_fun_t *rvfun;
    84107        int rc;
    85108
     
    93116        }
    94117
     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;
     127
    95128        rc = ddf_fun_add_match_id(fun, vfun->match_id, 10);
    96129        if (rc != EOK) {
     
    109142        }
    110143
     144        list_append(&rvfun->dev_link, &rootvirt->functions);
     145
    111146        ddf_msg(LVL_NOTE, "Registered child device `%s'", vfun->name);
    112147        return EOK;
    113148}
    114149
    115 static int rootvirt_add_device(ddf_dev_t *dev)
    116 {
    117         static int instances = 0;
     150static 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
     174static int rootvirt_dev_add(ddf_dev_t *dev)
     175{
     176        rootvirt_t *rootvirt;
    118177
    119178        /*
    120179         * Allow only single instance of root virtual device.
    121180         */
    122         instances++;
    123         if (instances > 1) {
     181        if (++instances > 1) {
    124182                return ELIMIT;
    125183        }
    126184
    127         ddf_msg(LVL_DEBUG, "add_device(handle=%d)", (int)dev->handle);
     185        ddf_msg(LVL_DEBUG, "dev_add(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);
    128193
    129194        /*
     
    133198        virtual_function_t *vfun = virtual_functions;
    134199        while (vfun->name != NULL) {
    135                 (void) rootvirt_add_fun(dev, vfun);
     200                (void) rootvirt_add_fun(rootvirt, vfun);
    136201                vfun++;
    137202        }
    138203
    139204        return EOK;
     205}
     206
     207static 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
     226static 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
     232static int rootvirt_fun_offline(ddf_fun_t *fun)
     233{
     234        ddf_msg(LVL_DEBUG, "rootvirt_fun_offline()");
     235        return ddf_fun_offline(fun);
    140236}
    141237
Note: See TracChangeset for help on using the changeset viewer.