Changeset cd0684d in mainline


Ignore:
Timestamp:
2011-02-14T22:14:52Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
659ca07
Parents:
97a62fe
Message:

Remove register_function_wrapper() since it became practically useless.
Provide ddf_fun_add_match_id() instead.

Location:
uspace
Files:
7 edited

Legend:

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

    r97a62fe rcd0684d  
    4444#include <stdlib.h>
    4545#include <str.h>
     46#include <str_error.h>
    4647#include <ctype.h>
    4748#include <macros.h>
     
    324325        int score = 0;
    325326        char *end = NULL;
     327        int rc;
    326328
    327329        val = skip_spaces(val);
     
    334336        }
    335337
    336         match_id_t *match_id = create_match_id();
    337         if (match_id == NULL) {
    338                 printf(NAME " : failed to allocate match id for function %s.\n",
    339                     fun->fnode->name);
    340                 return;
    341         }
    342 
    343338        val = skip_spaces(end);
    344339        get_match_id(&id, val);
     
    346341                printf(NAME " : error - could not read match id for "
    347342                    "function %s.\n", fun->fnode->name);
    348                 delete_match_id(match_id);
    349343                return;
    350344        }
    351 
    352         match_id->id = id;
    353         match_id->score = score;
    354345
    355346        printf(NAME ": adding match id '%s' with score %d to function %s\n", id,
    356347            score, fun->fnode->name);
    357         add_match_id(&fun->fnode->match_ids, match_id);
     348
     349        rc = ddf_fun_add_match_id(fun->fnode, id, score);
     350        if (rc != EOK)
     351                printf(NAME ": error adding match ID: %s\n", str_error(rc));
    358352}
    359353
  • uspace/drv/pciintel/pci.c

    r97a62fe rcd0684d  
    4545#include <ctype.h>
    4646#include <macros.h>
     47#include <str_error.h>
    4748
    4849#include <driver.h>
     
    217218void pci_fun_create_match_ids(pci_fun_t *fun)
    218219{
    219         match_id_t *match_id = NULL;
    220220        char *match_id_str;
    221        
    222         match_id = create_match_id();
    223         if (match_id != NULL) {
    224                 asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
    225                     fun->vendor_id, fun->device_id);
    226                 match_id->id = match_id_str;
    227                 match_id->score = 90;
    228                 add_match_id(&fun->fnode->match_ids, match_id);
     221        int rc;
     222       
     223        asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
     224            fun->vendor_id, fun->device_id);
     225
     226        if (match_id_str == NULL) {
     227                printf(NAME ": out of memory creating match ID.\n");
     228                return;
     229        }
     230
     231        rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 90);
     232        if (rc != EOK) {
     233                printf(NAME ": error adding match ID: %s\n",
     234                    str_error(rc));
    229235        }
    230236       
  • uspace/drv/rootvirt/rootvirt.c

    r97a62fe rcd0684d  
    8080static int rootvirt_add_fun(device_t *vdev, virtual_function_t *vfun)
    8181{
     82        function_t *fun;
     83        int rc;
     84
    8285        printf(NAME ": registering function `%s' (match \"%s\")\n",
    8386            vfun->name, vfun->match_id);
    8487
    85         int rc = register_function_wrapper(vdev, vfun->name,
    86             vfun->match_id, 10);
    87 
    88         if (rc == EOK) {
    89                 printf(NAME ": registered child device `%s'\n",
    90                     vfun->name);
    91         } else {
    92                 printf(NAME ": failed to register child device `%s': %s\n",
    93                     vfun->name, str_error(rc));
     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;
    9492        }
    9593
    96         return rc;
     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;
    97112}
    98113
  • uspace/drv/test1/test1.c

    r97a62fe rcd0684d  
    5555 * @param score Device match score.
    5656 */
    57 static void register_fun_verbose(device_t *parent, const char *message,
     57static int register_fun_verbose(device_t *parent, const char *message,
    5858    const char *name, const char *match_id, int match_score)
    5959{
    60         printf(NAME ": registering child device `%s': %s.\n",
    61            name, message);
     60        function_t *fun;
     61        int rc;
    6262
    63         int rc = register_function_wrapper(parent, name,
    64             match_id, match_score);
     63        printf(NAME ": registering function `%s': %s.\n", name, message);
    6564
    66         if (rc == EOK) {
    67                 printf(NAME ": registered function `%s'.\n", name);
    68         } else {
    69                 printf(NAME ": failed to register function `%s' (%s).\n",
    70                     name, str_error(rc));
     65        fun = ddf_fun_create(parent, fun_inner, name);
     66        if (fun == NULL) {
     67                printf(NAME ": error creating function %s\n", name);
     68                return ENOMEM;
    7169        }
     70
     71        rc = ddf_fun_add_match_id(fun, match_id, match_score);
     72        if (rc != EOK) {
     73                printf(NAME ": error adding match IDs to function %s\n", name);
     74                ddf_fun_destroy(fun);
     75                return rc;
     76        }
     77
     78        rc = ddf_fun_bind(fun);
     79        if (rc != EOK) {
     80                printf(NAME ": error binding function %s: %s\n", name,
     81                    str_error(rc));
     82                ddf_fun_destroy(fun);
     83                return rc;
     84        }
     85
     86        printf(NAME ": registered child device `%s'\n", name);
     87        return EOK;
    7288}
    7389
     
    115131                add_function_to_class(fun_a, "virt-null");
    116132        } else if (str_cmp(dev->name, "test1") == 0) {
    117                 register_fun_verbose(dev, "cloning myself ;-)", "clone",
     133                (void) register_fun_verbose(dev, "cloning myself ;-)", "clone",
    118134                    "virtual&test1", 10);
    119135        } else if (str_cmp(dev->name, "clone") == 0) {
    120                 register_fun_verbose(dev, "run by the same task", "child",
     136                (void) register_fun_verbose(dev, "run by the same task", "child",
    121137                    "virtual&test1&child", 10);
    122138        }
  • uspace/drv/test2/test2.c

    r97a62fe rcd0684d  
    5757 * @param score Device match score.
    5858 */
    59 static void register_child_verbose(device_t *parent, const char *message,
     59static int register_fun_verbose(device_t *parent, const char *message,
    6060    const char *name, const char *match_id, int match_score)
    6161{
    62         printf(NAME ": registering child device `%s': %s.\n",
    63            name, message);
     62        function_t *fun;
     63        int rc;
    6464
    65         int rc = register_function_wrapper(parent, name,
    66             match_id, match_score);
     65        printf(NAME ": registering function `%s': %s.\n", name, message);
    6766
    68         if (rc == EOK) {
    69                 printf(NAME ": registered child device `%s'.\n", name);
    70         } else {
    71                 printf(NAME ": failed to register child `%s' (%s).\n",
    72                     name, str_error(rc));
     67        fun = ddf_fun_create(parent, fun_inner, name);
     68        if (fun == NULL) {
     69                printf(NAME ": error creating function %s\n", name);
     70                return ENOMEM;
    7371        }
     72
     73        rc = ddf_fun_add_match_id(fun, match_id, match_score);
     74        if (rc != EOK) {
     75                printf(NAME ": error adding match IDs to function %s\n", name);
     76                ddf_fun_destroy(fun);
     77                return rc;
     78        }
     79
     80        rc = ddf_fun_bind(fun);
     81        if (rc != EOK) {
     82                printf(NAME ": error binding function %s: %s\n", name,
     83                    str_error(rc));
     84                ddf_fun_destroy(fun);
     85                return rc;
     86        }
     87
     88        printf(NAME ": registered child device `%s'\n", name);
     89        return EOK;
    7490}
    7591
     
    87103        async_usleep(1000);
    88104
    89         register_child_verbose(dev, "child driven by the same task",
     105        (void) register_fun_verbose(dev, "child driven by the same task",
    90106            "child", "virtual&test2", 10);
    91         register_child_verbose(dev, "child driven by test1",
     107        (void) register_fun_verbose(dev, "child driven by test1",
    92108            "test1", "virtual&test1", 10);
    93109
     
    122138                fibril_add_ready(postpone);
    123139        } else {
    124                 register_child_verbose(dev, "child without available driver",
     140                (void) register_fun_verbose(dev, "child without available driver",
    125141                    "ERROR", "non-existent.match.id", 10);
    126142        }
  • uspace/lib/drv/generic/driver.c

    r97a62fe rcd0684d  
    607607}
    608608
     609/** Add single match ID to function.
     610 *
     611 * Construct and add a single match ID to the specified function.
     612 *
     613 * @param fun                   Function
     614 * @param match_id_str          Match string
     615 * @param match_score           Match score
     616 * @return                      EOK on success, ENOMEM if out of memory.
     617 */
     618int ddf_fun_add_match_id(function_t *fun, const char *match_id_str,
     619    int match_score)
     620{
     621        match_id_t *match_id;
     622       
     623        match_id = create_match_id();
     624        if (match_id == NULL)
     625                return ENOMEM;
     626       
     627        match_id->id = match_id_str;
     628        match_id->score = 90;
     629       
     630        add_match_id(&fun->match_ids, match_id);
     631        return EOK;
     632}
     633
     634
    609635/** Wrapper for child_device_register for devices with single match id.
    610636 *
  • uspace/lib/drv/include/driver.h

    r97a62fe rcd0684d  
    162162extern void ddf_fun_destroy(function_t *);
    163163extern int ddf_fun_bind(function_t *);
     164extern int ddf_fun_add_match_id(function_t *, const char *, int);
    164165
    165166extern void *function_get_ops(function_t *, dev_inferface_idx_t);
Note: See TracChangeset for help on using the changeset viewer.