Changeset 80a96d2 in mainline for uspace/drv/test/test2/test2.c


Ignore:
Timestamp:
2011-09-05T21:26:47Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b33870b
Parents:
16cc9a6
Message:

DDF support for surprise removal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/test/test2/test2.c

    r16cc9a6 r80a96d2  
    4242static int test2_add_device(ddf_dev_t *dev);
    4343static int test2_dev_remove(ddf_dev_t *dev);
     44static int test2_dev_gone(ddf_dev_t *dev);
    4445static int test2_fun_online(ddf_fun_t *fun);
    4546static int test2_fun_offline(ddf_fun_t *fun);
     
    4849        .add_device = &test2_add_device,
    4950        .dev_remove = &test2_dev_remove,
     51        .dev_gone = &test2_dev_gone,
    5052        .fun_online = &test2_fun_online,
    5153        .fun_offline = &test2_fun_offline
     
    111113}
    112114
    113 /** Add child devices after some sleep.
     115/** Simulate plugging and surprise unplugging.
    114116 *
    115117 * @param arg Parent device structure (ddf_dev_t *).
    116118 * @return Always EOK.
    117119 */
    118 static int postponed_birth(void *arg)
     120static int plug_unplug(void *arg)
    119121{
    120122        test2_t *test2 = (test2_t *) arg;
     
    144146        test2->fun_a = fun_a;
    145147
     148        async_usleep(10000000);
     149
     150        ddf_msg(LVL_NOTE, "Unbinding function test1.");
     151        ddf_fun_unbind(test2->test1);
     152        async_usleep(1000000);
     153        ddf_msg(LVL_NOTE, "Unbinding function child.");
     154        ddf_fun_unbind(test2->child);
     155
    146156        return EOK;
    147157}
     
    158168        }
    159169
     170        rc = ddf_fun_unbind(fun);
     171        if (rc != EOK) {
     172                ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", name);
     173                return rc;
     174        }
     175
     176        ddf_fun_destroy(fun);
     177        return EOK;
     178}
     179
     180static int fun_unbind(ddf_fun_t *fun, const char *name)
     181{
     182        int rc;
     183
     184        ddf_msg(LVL_DEBUG, "fun_unbind(%p, '%s')", fun, name);
    160185        rc = ddf_fun_unbind(fun);
    161186        if (rc != EOK) {
     
    184209
    185210        if (str_cmp(dev->name, "child") != 0) {
    186                 fid_t postpone = fibril_create(postponed_birth, test2);
     211                fid_t postpone = fibril_create(plug_unplug, test2);
    187212                if (postpone == 0) {
    188213                        ddf_msg(LVL_ERROR, "fibril_create() failed.");
     
    232257}
    233258
     259static int test2_dev_gone(ddf_dev_t *dev)
     260{
     261        test2_t *test2 = (test2_t *)dev->driver_data;
     262        int rc;
     263
     264        ddf_msg(LVL_DEBUG, "test2_dev_gone(%p)", dev);
     265
     266        if (test2->fun_a != NULL) {
     267                rc = fun_unbind(test2->fun_a, "a");
     268                if (rc != EOK)
     269                        return rc;
     270        }
     271
     272        if (test2->fun_err != NULL) {
     273                rc = fun_unbind(test2->fun_err, "ERROR");
     274                if (rc != EOK)
     275                        return rc;
     276        }
     277
     278        if (test2->child != NULL) {
     279                rc = fun_unbind(test2->child, "child");
     280                if (rc != EOK)
     281                        return rc;
     282        }
     283
     284        if (test2->test1 != NULL) {
     285                rc = fun_unbind(test2->test1, "test1");
     286                if (rc != EOK)
     287                        return rc;
     288        }
     289
     290        return EOK;
     291}
     292
    234293
    235294static int test2_fun_online(ddf_fun_t *fun)
     
    248307{
    249308        printf(NAME ": HelenOS test2 virtual device driver\n");
    250         ddf_log_init(NAME, LVL_ERROR);
     309        ddf_log_init(NAME, LVL_NOTE);
    251310        return ddf_driver_main(&test2_driver);
    252311}
Note: See TracChangeset for help on using the changeset viewer.