Changeset c593b21 in mainline for uspace


Ignore:
Timestamp:
2011-04-03T18:06:29Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c4e0b47
Parents:
0b4e7ca (diff), 0cec844d (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 development/ changes

Location:
uspace
Files:
9 added
1 deleted
46 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    r0b4e7ca rc593b21  
    3838#include <dirent.h>
    3939#include <fcntl.h>
     40#include <getopt.h>
    4041#include <sys/types.h>
    4142#include <sys/stat.h>
    4243#include <str.h>
     44#include <sort.h>
    4345
    4446#include "errors.h"
     
    4648#include "util.h"
    4749#include "entry.h"
    48 #include "ls.h"
    4950#include "cmds.h"
    5051
     52/* Various values that can be returned by ls_scope() */
     53#define LS_BOGUS 0
     54#define LS_FILE  1
     55#define LS_DIR   2
     56
     57/** Structure to represent a directory entry.
     58 *
     59 * Useful to keep together important information
     60 * for sorting directory entries.
     61 */
     62struct dir_elem_t {
     63        char *name;
     64        struct stat s;
     65};
     66
    5167static const char *cmdname = "ls";
    5268
    53 static void ls_scan_dir(const char *d, DIR *dirp)
    54 {
     69static struct option const long_options[] = {
     70        { "help", no_argument, 0, 'h' },
     71        { "unsort", no_argument, 0, 'u' },
     72        { 0, 0, 0, 0 }
     73};
     74
     75/** Print an entry.
     76 *
     77 * ls_print currently does nothing more than print the entry.
     78 * In the future, we will likely pass the absolute path, and
     79 * some sort of ls_options structure that controls how each
     80 * entry is printed and what is printed about it.
     81 *
     82 * Now we just print basic DOS style lists.
     83 *
     84 * @param de            Directory element.
     85 */
     86static void ls_print(struct dir_elem_t *de)
     87{
     88        if (de->s.is_file)
     89                printf("%-40s\t%llu\n", de->name, (long long) de->s.size);
     90        else if (de->s.is_directory)
     91                printf("%-40s\t<dir>\n", de->name);
     92        else
     93                printf("%-40s\n", de->name);
     94}
     95
     96
     97/** Compare 2 directory elements.
     98 *
     99 * It compares 2 elements of a directory : a file is considered
     100 * as bigger than a directory, and if they have the same type,
     101 * they are compared alphabetically.
     102 *
     103 * @param a             Pointer to the structure of the first element.
     104 * @param b             Pointer to the structure of the second element.
     105 * @param arg           Pointer for an other and optionnal argument.
     106 *
     107 * @return              -1 if a < b, 1 otherwise.
     108 */
     109static int ls_cmp(void *a, void *b, void *arg)
     110{
     111        struct dir_elem_t *da = a;
     112        struct dir_elem_t *db = b;
     113       
     114        if ((da->s.is_directory && db->s.is_file) ||
     115            ((da->s.is_directory == db->s.is_directory) &&
     116            str_cmp(da->name, db->name) < 0))
     117                return -1;
     118        else
     119                return 1;
     120}
     121
     122/** Scan a directory.
     123 *
     124 * Scan the content of a directory and print it.
     125 *
     126 * @param d             Name of the directory.
     127 * @param dirp  Directory stream.
     128 * @param sort  1 if the output must be sorted,
     129 *                              0 otherwise.
     130 */
     131static void ls_scan_dir(const char *d, DIR *dirp, int sort)
     132{
     133        int alloc_blocks = 20;
     134        int i;
     135        int nbdirs = 0;
     136        int rc;
     137        int len;
     138        char *buff;
     139        struct dir_elem_t *tmp;
     140        struct dir_elem_t *tosort;
    55141        struct dirent *dp;
    56         char *buff;
    57 
    58         if (! dirp)
     142       
     143        if (!dirp)
    59144                return;
    60145
    61         buff = (char *)malloc(PATH_MAX);
    62         if (NULL == buff) {
     146        buff = (char *) malloc(PATH_MAX);
     147        if (!buff) {
    63148                cli_error(CL_ENOMEM, "ls: failed to scan %s", d);
    64149                return;
    65150        }
    66 
     151       
     152        tosort = (struct dir_elem_t *) malloc(alloc_blocks * sizeof(*tosort));
     153        if (!tosort) {
     154                cli_error(CL_ENOMEM, "ls: failed to scan %s", d);
     155                free(buff);
     156                return;
     157        }
     158       
    67159        while ((dp = readdir(dirp))) {
    68                 memset(buff, 0, sizeof(buff));
    69                 /* Don't worry if inserting a double slash, this will be fixed by
    70                  * absolutize() later with subsequent calls to open() or readdir() */
    71                 snprintf(buff, PATH_MAX - 1, "%s/%s", d, dp->d_name);
    72                 ls_print(dp->d_name, buff);
    73         }
    74 
     160                if (nbdirs + 1 > alloc_blocks) {
     161                        alloc_blocks += alloc_blocks;
     162                       
     163                        tmp = (struct dir_elem_t *) realloc(tosort,
     164                            alloc_blocks * sizeof(struct dir_elem_t));
     165                        if (!tmp) {
     166                                cli_error(CL_ENOMEM, "ls: failed to scan %s", d);
     167                                goto out;
     168                        }
     169                        tosort = tmp;
     170                }
     171               
     172                /* fill the name field */
     173                tosort[nbdirs].name = (char *) malloc(str_length(dp->d_name) + 1);
     174                if (!tosort[nbdirs].name) {
     175                        cli_error(CL_ENOMEM, "ls: failed to scan %s", d);
     176                        goto out;
     177                }
     178               
     179                str_cpy(tosort[nbdirs].name, str_length(dp->d_name) + 1, dp->d_name);
     180                len = snprintf(buff, PATH_MAX - 1, "%s/%s", d, tosort[nbdirs].name);
     181                buff[len] = '\0';
     182
     183                rc = stat(buff, &tosort[nbdirs++].s);
     184                if (rc != 0) {
     185                        printf("ls: skipping bogus node %s\n", buff);
     186                        printf("rc=%d\n", rc);
     187                        goto out;
     188                }
     189        }
     190       
     191        if (sort) {
     192                if (!qsort(&tosort[0], nbdirs, sizeof(struct dir_elem_t),
     193                    ls_cmp, NULL)) {
     194                        printf("Sorting error.\n");
     195                }
     196        }
     197       
     198        for (i = 0; i < nbdirs; i++)
     199                ls_print(&tosort[i]);
     200       
     201out:
     202        for(i = 0; i < nbdirs; i++)
     203                free(tosort[i].name);
     204        free(tosort);
    75205        free(buff);
    76 
    77         return;
    78 }
    79 
    80 /* ls_print currently does nothing more than print the entry.
    81  * in the future, we will likely pass the absolute path, and
    82  * some sort of ls_options structure that controls how each
    83  * entry is printed and what is printed about it.
    84  *
    85  * Now we just print basic DOS style lists */
    86 
    87 static void ls_print(const char *name, const char *pathname)
    88 {
    89         struct stat s;
    90         int rc;
    91 
    92         rc = stat(pathname, &s);
    93         if (rc != 0) {
    94                 /* Odd chance it was deleted from the time readdir() found it */
    95                 printf("ls: skipping bogus node %s\n", pathname);
    96                 printf("rc=%d\n", rc);
    97                 return;
    98         }
    99        
    100         if (s.is_file)
    101                 printf("%-40s\t%llu\n", name, (long long) s.size);
    102         else if (s.is_directory)
    103                 printf("%-40s\t<dir>\n", name);
    104         else
    105                 printf("%-40s\n", name);
    106 
    107         return;
    108206}
    109207
     
    114212        } else {
    115213                help_cmd_ls(HELP_SHORT);
    116                 printf("  `%s' [path], if no path is given the current "
    117                                 "working directory is used.\n", cmdname);
     214                printf(
     215                "Usage:  %s [options] [path]\n"
     216                "If not path is given, the current working directory is used.\n"
     217                "Options:\n"
     218                "  -h, --help       A short option summary\n"
     219                "  -u, --unsort     Do not sort directory entries\n",
     220                cmdname);
    118221        }
    119222
     
    124227{
    125228        unsigned int argc;
    126         struct stat s;
    127         char *buff;
     229        struct dir_elem_t de;
    128230        DIR *dirp;
     231        int c, opt_ind;
     232        int sort = 1;
    129233
    130234        argc = cli_count_args(argv);
    131 
    132         buff = (char *) malloc(PATH_MAX);
    133         if (NULL == buff) {
     235       
     236        for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
     237                c = getopt_long(argc, argv, "hu", long_options, &opt_ind);
     238                switch (c) {
     239                case 'h':
     240                        help_cmd_ls(HELP_LONG);
     241                        return CMD_SUCCESS;
     242                case 'u':
     243                        sort = 0;
     244                        break;
     245                }
     246        }
     247       
     248        argc -= optind;
     249       
     250        de.name = (char *) malloc(PATH_MAX);
     251        if (!de.name) {
    134252                cli_error(CL_ENOMEM, "%s: ", cmdname);
    135253                return CMD_FAILURE;
    136254        }
    137         memset(buff, 0, sizeof(buff));
    138 
    139         if (argc == 1)
    140                 getcwd(buff, PATH_MAX);
     255        memset(de.name, 0, sizeof(PATH_MAX));
     256       
     257        if (argc == 0)
     258                getcwd(de.name, PATH_MAX);
    141259        else
    142                 str_cpy(buff, PATH_MAX, argv[1]);
    143 
    144         if (stat(buff, &s)) {
    145                 cli_error(CL_ENOENT, buff);
    146                 free(buff);
     260                str_cpy(de.name, PATH_MAX, argv[optind]);
     261       
     262        if (stat(de.name, &de.s)) {
     263                cli_error(CL_ENOENT, de.name);
     264                free(de.name);
    147265                return CMD_FAILURE;
    148266        }
    149267
    150         if (s.is_file) {
    151                 ls_print(buff, buff);
     268        if (de.s.is_file) {
     269                ls_print(&de);
    152270        } else {
    153                 dirp = opendir(buff);
     271                dirp = opendir(de.name);
    154272                if (!dirp) {
    155273                        /* May have been deleted between scoping it and opening it */
    156                         cli_error(CL_EFAIL, "Could not stat %s", buff);
    157                         free(buff);
     274                        cli_error(CL_EFAIL, "Could not stat %s", de.name);
     275                        free(de.name);
    158276                        return CMD_FAILURE;
    159277                }
    160                 ls_scan_dir(buff, dirp);
     278                ls_scan_dir(de.name, dirp, sort);
    161279                closedir(dirp);
    162280        }
    163281
    164         free(buff);
     282        free(de.name);
    165283
    166284        return CMD_SUCCESS;
  • uspace/app/init/init.c

    r0b4e7ca rc593b21  
    314314        getterm("term/vc6", "/app/klog", false);
    315315
     316#ifdef CONFIG_START_DEVMAN
     317
    316318#ifdef CONFIG_DEVMAN_EARLY_LAUNCH
    317319        spawn("/srv/devman");
     
    320322#endif
    321323
     324#endif
     325
    322326        return 0;
    323327}
  • uspace/app/tester/Makefile

    r0b4e7ca rc593b21  
    5454        mm/malloc1.c \
    5555        mm/mapping1.c \
     56        devs/devman1.c \
    5657        hw/misc/virtchar1.c \
    5758        hw/serial/serial1.c
  • uspace/app/tester/tester.c

    r0b4e7ca rc593b21  
    6666#include "adt/usbaddrkeep.def"
    6767#include "hw/misc/virtchar1.def"
     68#include "devs/devman1.def"
    6869        {NULL, NULL, NULL, false}
    6970};
  • uspace/app/tester/tester.h

    r0b4e7ca rc593b21  
    8282extern const char *test_usbaddrkeep(void);
    8383extern const char *test_virtchar1(void);
     84extern const char *test_devman1(void);
    8485
    8586extern test_t tests[];
  • uspace/drv/isa/isa.c

    r0b4e7ca rc593b21  
    5353
    5454#include <ddf/driver.h>
     55#include <ddf/log.h>
    5556#include <ops/hw_res.h>
    5657
     
    134135        fd = open(conf_path, O_RDONLY);
    135136        if (fd < 0) {
    136                 printf(NAME ": unable to open %s\n", conf_path);
     137                ddf_msg(LVL_ERROR, "Unable to open %s", conf_path);
    137138                goto cleanup;
    138139        }
     
    141142
    142143        len = lseek(fd, 0, SEEK_END);
    143         lseek(fd, 0, SEEK_SET); 
     144        lseek(fd, 0, SEEK_SET);
    144145        if (len == 0) {
    145                 printf(NAME ": fun_conf_read error: configuration file '%s' "
    146                     "is empty.\n", conf_path);
     146                ddf_msg(LVL_ERROR, "Configuration file '%s' is empty.",
     147                    conf_path);
    147148                goto cleanup;
    148149        }
     
    150151        buf = malloc(len + 1);
    151152        if (buf == NULL) {
    152                 printf(NAME ": fun_conf_read error: memory allocation failed.\n");
     153                ddf_msg(LVL_ERROR, "Memory allocation failed.");
    153154                goto cleanup;
    154155        }
    155156
    156157        if (0 >= read(fd, buf, len)) {
    157                 printf(NAME ": fun_conf_read error: unable to read file '%s'.\n",
    158                     conf_path);
     158                ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
    159159                goto cleanup;
    160160        }
     
    252252                fun->hw_resources.count++;
    253253
    254                 printf(NAME ": added irq 0x%x to function %s\n", irq,
     254                ddf_msg(LVL_NOTE, "Added irq 0x%x to function %s", irq,
    255255                    fun->fnode->name);
    256256        }
     
    270270                fun->hw_resources.count++;
    271271
    272                 printf(NAME ": added io range (addr=0x%x, size=0x%x) to "
    273                     "function %s\n", (unsigned int) addr, (unsigned int) len,
     272                ddf_msg(LVL_NOTE, "Added io range (addr=0x%x, size=0x%x) to "
     273                    "function %s", (unsigned int) addr, (unsigned int) len,
    274274                    fun->fnode->name);
    275275        }
     
    331331        score = (int)strtol(val, &end, 10);
    332332        if (val == end) {
    333                 printf(NAME " : error - could not read match score for "
    334                     "function %s.\n", fun->fnode->name);
     333                ddf_msg(LVL_ERROR, "Cannot read match score for function "
     334                    "%s.", fun->fnode->name);
    335335                return;
    336336        }
     
    339339        get_match_id(&id, val);
    340340        if (id == NULL) {
    341                 printf(NAME " : error - could not read match id for "
    342                     "function %s.\n", fun->fnode->name);
     341                ddf_msg(LVL_ERROR, "Cannot read match ID for function %s.",
     342                    fun->fnode->name);
    343343                return;
    344344        }
    345345
    346         printf(NAME ": adding match id '%s' with score %d to function %s\n", id,
    347             score, fun->fnode->name);
     346        ddf_msg(LVL_DEBUG, "Adding match id '%s' with score %d to "
     347            "function %s", id, score, fun->fnode->name);
    348348
    349349        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));
     350        if (rc != EOK) {
     351                ddf_msg(LVL_ERROR, "Failed adding match ID: %s",
     352                    str_error(rc));
     353        }
    352354}
    353355
     
    375377        if (!prop_parse(fun, line, "io_range", &fun_parse_io_range) &&
    376378            !prop_parse(fun, line, "irq", &fun_parse_irq) &&
    377             !prop_parse(fun, line, "match", &fun_parse_match_id))
    378         {
    379             printf(NAME " error undefined device property at line '%s'\n",
    380                 line);
     379            !prop_parse(fun, line, "match", &fun_parse_match_id)) {
     380
     381                ddf_msg(LVL_ERROR, "Undefined device property at line '%s'",
     382                    line);
    381383        }
    382384}
     
    439441        fun->fnode->ops = &isa_fun_ops;
    440442
    441         printf(NAME ": Binding function %s.\n", fun->fnode->name);
     443        ddf_msg(LVL_DEBUG, "Binding function %s.", fun->fnode->name);
    442444
    443445        /* XXX Handle error */
     
    467469static int isa_add_device(ddf_dev_t *dev)
    468470{
    469         printf(NAME ": isa_add_device, device handle = %d\n",
     471        ddf_msg(LVL_DEBUG, "isa_add_device, device handle = %d",
    470472            (int) dev->handle);
    471473
    472474        /* Make the bus device more visible. Does not do anything. */
    473         printf(NAME ": adding a 'ctl' function\n");
     475        ddf_msg(LVL_DEBUG, "Adding a 'ctl' function");
    474476
    475477        ddf_fun_t *ctl = ddf_fun_create(dev, fun_exposed, "ctl");
    476478        if (ctl == NULL) {
    477                 printf(NAME ": Error creating control function.\n");
     479                ddf_msg(LVL_ERROR, "Failed creating control function.");
    478480                return EXDEV;
    479481        }
    480482
    481483        if (ddf_fun_bind(ctl) != EOK) {
    482                 printf(NAME ": Error binding control function.\n");
     484                ddf_msg(LVL_ERROR, "Failed binding control function.");
    483485                return EXDEV;
    484486        }
     
    486488        /* Add functions as specified in the configuration file. */
    487489        isa_functions_add(dev);
    488         printf(NAME ": finished the enumeration of legacy functions\n");
     490        ddf_msg(LVL_NOTE, "Finished enumerating legacy functions");
    489491
    490492        return EOK;
     
    493495static void isa_init()
    494496{
     497        ddf_log_init(NAME, LVL_ERROR);
    495498        isa_fun_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops;
    496499}
  • uspace/drv/ns8250/ns8250.c

    r0b4e7ca rc593b21  
    5555#include <ddf/driver.h>
    5656#include <ddf/interrupt.h>
     57#include <ddf/log.h>
    5758#include <ops/char_dev.h>
    5859
     
    275276static bool ns8250_pio_enable(ns8250_t *ns)
    276277{
    277         printf(NAME ": ns8250_pio_enable %s\n", ns->dev->name);
     278        ddf_msg(LVL_DEBUG, "ns8250_pio_enable %s", ns->dev->name);
    278279       
    279280        /* Gain control over port's registers. */
    280281        if (pio_enable((void *)(uintptr_t) ns->io_addr, REG_COUNT,
    281282            (void **) &ns->port)) {
    282                 printf(NAME ": error - cannot gain the port %#" PRIx32 " for device "
    283                     "%s.\n", ns->io_addr, ns->dev->name);
     283                ddf_msg(LVL_ERROR, "Cannot map the port %#" PRIx32
     284                    " for device %s.", ns->io_addr, ns->dev->name);
    284285                return false;
    285286        }
     
    295296static bool ns8250_dev_probe(ns8250_t *ns)
    296297{
    297         printf(NAME ": ns8250_dev_probe %s\n", ns->dev->name);
     298        ddf_msg(LVL_DEBUG, "ns8250_dev_probe %s", ns->dev->name);
    298299       
    299300        ioport8_t *port_addr = ns->port;
     
    313314        pio_write_8(port_addr + 4, olddata);
    314315       
    315         if (!res)
    316                 printf(NAME ": device %s is not present.\n", ns->dev->name);
     316        if (!res) {
     317                ddf_msg(LVL_DEBUG, "Device %s is not present.",
     318                    ns->dev->name);
     319        }
    317320       
    318321        return res;
     
    326329static int ns8250_dev_initialize(ns8250_t *ns)
    327330{
    328         printf(NAME ": ns8250_dev_initialize %s\n", ns->dev->name);
     331        ddf_msg(LVL_DEBUG, "ns8250_dev_initialize %s", ns->dev->name);
    329332       
    330333        int ret = EOK;
     
    337340            IPC_FLAG_BLOCKING);
    338341        if (ns->dev->parent_phone < 0) {
    339                 printf(NAME ": failed to connect to the parent driver of the "
    340                     "device %s.\n", ns->dev->name);
     342                ddf_msg(LVL_ERROR, "Failed to connect to parent driver of "
     343                    "device %s.", ns->dev->name);
    341344                ret = ns->dev->parent_phone;
    342345                goto failed;
     
    346349        ret = hw_res_get_resource_list(ns->dev->parent_phone, &hw_resources);
    347350        if (ret != EOK) {
    348                 printf(NAME ": failed to get hw resources for the device "
    349                     "%s.\n", ns->dev->name);
     351                ddf_msg(LVL_ERROR, "Failed to get HW resources for device "
     352                    "%s.", ns->dev->name);
    350353                goto failed;
    351354        }
     
    362365                        ns->irq = res->res.interrupt.irq;
    363366                        irq = true;
    364                         printf(NAME ": the %s device was asigned irq = 0x%x.\n",
     367                        ddf_msg(LVL_NOTE, "Device %s was asigned irq = 0x%x.",
    365368                            ns->dev->name, ns->irq);
    366369                        break;
     
    369372                        ns->io_addr = res->res.io_range.address;
    370373                        if (res->res.io_range.size < REG_COUNT) {
    371                                 printf(NAME ": i/o range assigned to the device "
    372                                     "%s is too small.\n", ns->dev->name);
     374                                ddf_msg(LVL_ERROR, "I/O range assigned to "
     375                                    "device %s is too small.", ns->dev->name);
    373376                                ret = ELIMIT;
    374377                                goto failed;
    375378                        }
    376379                        ioport = true;
    377                         printf(NAME ": the %s device was asigned i/o address = "
    378                             "0x%x.\n", ns->dev->name, ns->io_addr);
    379                         break;
     380                        ddf_msg(LVL_NOTE, "Device %s was asigned I/O address = "
     381                            "0x%x.", ns->dev->name, ns->io_addr);
     382                        break;
    380383                       
    381384                default:
     
    385388       
    386389        if (!irq || !ioport) {
    387                 printf(NAME ": missing hw resource(s) for the device %s.\n",
     390                ddf_msg(LVL_ERROR, "Missing HW resource(s) for device %s.",
    388391                    ns->dev->name);
    389392                ret = ENOENT;
     
    470473       
    471474        if (baud_rate < 50 || MAX_BAUD_RATE % baud_rate != 0) {
    472                 printf(NAME ": error - somebody tried to set invalid baud rate "
    473                     "%d\n", baud_rate);
     475                ddf_msg(LVL_ERROR, "Invalid baud rate %d requested.",
     476                    baud_rate);
    474477                return EINVAL;
    475478        }
     
    654657                        if (ns->client_connected) {
    655658                                if (!buf_push_back(&ns->input_buffer, val)) {
    656                                         printf(NAME ": buffer overflow on "
    657                                             "%s.\n", ns->dev->name);
     659                                        ddf_msg(LVL_WARN, "Buffer overflow on "
     660                                            "%s.", ns->dev->name);
    658661                                } else {
    659                                         printf(NAME ": the character %c saved "
    660                                             "to the buffer of %s.\n",
     662                                        ddf_msg(LVL_DEBUG2, "Character %c saved "
     663                                            "to the buffer of %s.",
    661664                                            val, ns->dev->name);
    662665                                }
     
    714717        int rc;
    715718       
    716         printf(NAME ": ns8250_add_device %s (handle = %d)\n",
     719        ddf_msg(LVL_DEBUG, "ns8250_add_device %s (handle = %d)",
    717720            dev->name, (int) dev->handle);
    718721       
     
    749752        /* Register interrupt handler. */
    750753        if (ns8250_register_interrupt_handler(ns) != EOK) {
    751                 printf(NAME ": failed to register interrupt handler.\n");
     754                ddf_msg(LVL_ERROR, "Failed to register interrupt handler.");
    752755                rc = EADDRNOTAVAIL;
    753756                goto fail;
     
    757760        rc = ns8250_interrupt_enable(ns);
    758761        if (rc != EOK) {
    759                 printf(NAME ": failed to enable the interrupt. Error code = "
    760                     "%d.\n", rc);
     762                ddf_msg(LVL_ERROR, "Failed to enable the interrupt. Error code = "
     763                    "%d.", rc);
    761764                goto fail;
    762765        }
     
    764767        fun = ddf_fun_create(dev, fun_exposed, "a");
    765768        if (fun == NULL) {
    766                 printf(NAME ": error creating function.\n");
     769                ddf_msg(LVL_ERROR, "Failed creating function.");
    767770                goto fail;
    768771        }
     
    772775        rc = ddf_fun_bind(fun);
    773776        if (rc != EOK) {
    774                 printf(NAME ": error binding function.\n");
     777                ddf_msg(LVL_ERROR, "Failed binding function.");
    775778                goto fail;
    776779        }
     
    780783        ddf_fun_add_to_class(fun, "serial");
    781784       
    782         printf(NAME ": the %s device has been successfully initialized.\n",
     785        ddf_msg(LVL_NOTE, "Device %s successfully initialized.",
    783786            dev->name);
    784787       
     
    862865        fibril_mutex_unlock(&data->mutex);
    863866       
    864         printf(NAME ": ns8250_get_props: baud rate %d, parity 0x%x, word "
    865             "length %d, stop bits %d\n", *baud_rate, *parity, *word_length,
     867        ddf_msg(LVL_DEBUG, "ns8250_get_props: baud rate %d, parity 0x%x, word "
     868            "length %d, stop bits %d", *baud_rate, *parity, *word_length,
    866869            *stop_bits);
    867870}
     
    879882    unsigned int parity, unsigned int word_length, unsigned int stop_bits)
    880883{
    881         printf(NAME ": ns8250_set_props: baud rate %d, parity 0x%x, word "
    882             "length %d, stop bits %d\n", baud_rate, parity, word_length,
     884        ddf_msg(LVL_DEBUG, "ns8250_set_props: baud rate %d, parity 0x%x, word "
     885            "length %d, stop bits %d", baud_rate, parity, word_length,
    883886            stop_bits);
    884887       
     
    940943static void ns8250_init(void)
    941944{
     945        ddf_log_init(NAME, LVL_ERROR);
     946       
    942947        ns8250_dev_ops.open = &ns8250_open;
    943948        ns8250_dev_ops.close = &ns8250_close;
  • uspace/drv/ohci/hc.c

    r0b4e7ca rc593b21  
    4545
    4646static int interrupt_emulator(hc_t *instance);
     47static void hc_gain_control(hc_t *instance);
     48static void hc_init_hw(hc_t *instance);
    4749/*----------------------------------------------------------------------------*/
    4850int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun)
     
    5860
    5961        char *match_str = NULL;
    60         int ret = asprintf(&match_str, "usb&mid");
     62        int ret = asprintf(&match_str, "usb&class=hub");
    6163        ret = (match_str == NULL) ? ret : EOK;
    6264        if (ret < 0) {
     
    7779        assert(instance);
    7880        int ret = EOK;
     81#define CHECK_RET_RETURN(ret, message...) \
     82if (ret != EOK) { \
     83        usb_log_error(message); \
     84        return ret; \
     85} else (void)0
    7986
    8087        ret = pio_enable((void*)regs, reg_size, (void**)&instance->registers);
    81         if (ret != EOK) {
    82                 usb_log_error("Failed to gain access to device registers.\n");
    83                 return ret;
    84         }
     88        CHECK_RET_RETURN(ret,
     89            "Failed(%d) to gain access to device registers: %s.\n",
     90            ret, str_error(ret));
     91
    8592        instance->ddf_instance = fun;
    8693        usb_device_keeper_init(&instance->manager);
     94        ret = bandwidth_init(&instance->bandwidth, BANDWIDTH_AVAILABLE_USB11,
     95            bandwidth_count_usb11);
     96        CHECK_RET_RETURN(ret, "Failed to initialize bandwidth allocator: %s.\n",
     97            ret, str_error(ret));
    8798
    8899        if (!interrupts) {
     
    92103        }
    93104
     105        hc_gain_control(instance);
     106
    94107        rh_init(&instance->rh, dev, instance->registers);
     108
     109        hc_init_hw(instance);
    95110
    96111        /* TODO: implement */
     
    117132                rh_interrupt(&instance->rh);
    118133
     134        usb_log_info("OHCI interrupt: %x.\n", status);
     135
    119136        /* TODO: Check for further interrupt causes */
    120137        /* TODO: implement */
     
    126143        usb_log_info("Started interrupt emulator.\n");
    127144        while (1) {
    128                 uint32_t status = instance->registers->interrupt_status;
     145                const uint32_t status = instance->registers->interrupt_status;
    129146                instance->registers->interrupt_status = status;
    130147                hc_interrupt(instance, status);
     
    133150        return EOK;
    134151}
     152/*----------------------------------------------------------------------------*/
     153void hc_gain_control(hc_t *instance)
     154{
     155        assert(instance);
     156        /* Interrupt routing enabled => smm driver is active */
     157        if (instance->registers->control & C_IR) {
     158                usb_log_info("Found SMM driver requesting ownership change.\n");
     159                instance->registers->command_status |= CS_OCR;
     160                while (instance->registers->control & C_IR) {
     161                        async_usleep(1000);
     162                }
     163                usb_log_info("Ownership taken from SMM driver.\n");
     164                return;
     165        }
     166
     167        const unsigned hc_status =
     168            (instance->registers->control >> C_HCFS_SHIFT) & C_HCFS_MASK;
     169        /* Interrupt routing disabled && status != USB_RESET => BIOS active */
     170        if (hc_status != C_HCFS_RESET) {
     171                usb_log_info("Found BIOS driver.\n");
     172                if (hc_status == C_HCFS_OPERATIONAL) {
     173                        usb_log_info("HC operational(BIOS).\n");
     174                        return;
     175                }
     176                /* HC is suspended assert resume for 20ms */
     177                instance->registers->control &= (C_HCFS_RESUME << C_HCFS_SHIFT);
     178                async_usleep(20000);
     179                return;
     180        }
     181
     182        /* HC is in reset (hw startup) => no other driver
     183         * maintain reset for at least the time specified in USB spec (50 ms)*/
     184        async_usleep(50000);
     185}
     186/*----------------------------------------------------------------------------*/
     187void hc_init_hw(hc_t *instance)
     188{
     189        assert(instance);
     190        const uint32_t fm_interval = instance->registers->fm_interval;
     191        instance->registers->command_status = CS_HCR;
     192        async_usleep(10);
     193        instance->registers->fm_interval = fm_interval;
     194        assert((instance->registers->command_status & CS_HCR) == 0);
     195        /* hc is now in suspend state */
     196        /* TODO: init HCCA block */
     197        /* TODO: init queues */
     198        /* TODO: enable queues */
     199        /* TODO: enable interrupts */
     200        /* TODO: set periodic start to 90% */
     201
     202        instance->registers->control &= (C_HCFS_OPERATIONAL << C_HCFS_SHIFT);
     203        usb_log_info("OHCI HC up and running.\n");
     204}
    135205/**
    136206 * @}
  • uspace/drv/ohci/hc.h

    r0b4e7ca rc593b21  
    4242#include <usb/usb.h>
    4343#include <usb/host/device_keeper.h>
     44#include <usb/host/bandwidth.h>
    4445#include <usbhc_iface.h>
    4546
     
    5455        ddf_fun_t *ddf_instance;
    5556        usb_device_keeper_t manager;
     57        bandwidth_t bandwidth;
    5658        fid_t interrupt_emulator;
    5759} hc_t;
  • uspace/drv/ohci/iface.c

    r0b4e7ca rc593b21  
    151151    size_t max_packet_size, unsigned int interval)
    152152{
    153         UNSUPPORTED("register_endpoint");
    154 
    155         return ENOTSUP;
     153        assert(fun);
     154        hc_t *hc = fun_to_hc(fun);
     155        assert(hc);
     156        if (address == hc->rh.address)
     157                return EOK;
     158        const usb_speed_t speed =
     159                usb_device_keeper_get_speed(&hc->manager, address);
     160        const size_t size = max_packet_size;
     161        usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
     162            address, endpoint, usb_str_transfer_type(transfer_type),
     163            usb_str_speed(speed), direction, size, max_packet_size, interval);
     164        return bandwidth_reserve(&hc->bandwidth, address, endpoint, direction,
     165            speed, transfer_type, max_packet_size, size, interval);
    156166}
    157167/*----------------------------------------------------------------------------*/
     
    168178    usb_endpoint_t endpoint, usb_direction_t direction)
    169179{
    170         UNSUPPORTED("unregister_endpoint");
     180        assert(fun);
     181        hc_t *hc = fun_to_hc(fun);
     182        assert(hc);
     183        usb_log_debug("Unregister endpoint %d:%d %d.\n",
     184            address, endpoint, direction);
     185        return bandwidth_release(&hc->bandwidth, address, endpoint, direction);
    171186
    172187        return ENOTSUP;
  • uspace/drv/ohci/ohci.c

    r0b4e7ca rc593b21  
    3131 */
    3232/** @file
    33  * @brief UHCI driver
     33 * @brief OHCI driver
    3434 */
    3535#include <errno.h>
     
    117117/** Initialize hc and rh ddf structures and their respective drivers.
    118118 *
    119  * @param[in] instance UHCI structure to use.
     119 * @param[in] instance OHCI structure to use.
    120120 * @param[in] device DDF instance of the device to use.
    121121 *
    122122 * This function does all the preparatory work for hc and rh drivers:
    123123 *  - gets device hw resources
    124  *  - disables UHCI legacy support
     124 *  - disables OHCI legacy support
    125125 *  - asks for interrupt
    126126 *  - registers interrupt handler
     
    185185        ret = ddf_fun_bind(instance->hc_fun);
    186186        CHECK_RET_DEST_FUN_RETURN(ret,
    187             "Failed(%d) to bind UHCI device function: %s.\n",
     187            "Failed(%d) to bind OHCI device function: %s.\n",
    188188            ret, str_error(ret));
    189189#undef CHECK_RET_HC_RETURN
     
    216216        ret = ddf_fun_bind(instance->rh_fun);
    217217        CHECK_RET_FINI_RETURN(ret,
    218             "Failed(%d) to register UHCI root hub.\n", ret);
     218            "Failed(%d) to register OHCI root hub.\n", ret);
    219219
    220220        return EOK;
  • uspace/drv/ohci/ohci_regs.h

    r0b4e7ca rc593b21  
    3939typedef struct ohci_regs
    4040{
    41         volatile uint32_t revision;
     41        const volatile uint32_t revision;
    4242        volatile uint32_t control;
     43#define C_CSBR_MASK (0x3)
     44#define C_CSBR_SHIFT (0)
     45#define C_PLE (1 << 2)
     46#define C_IE (1 << 3)
     47#define C_CLE (1 << 4)
     48#define C_BLE (1 << 5)
     49
     50#define C_HCFS_MASK (0x3)
     51#define C_HCFS_SHIFT (6)
     52#define C_HCFS_RESET (0x0)
     53#define C_HCFS_OPERATIONAL (0x1)
     54#define C_HCFS_RESUME (0x2)
     55#define C_HCFS_SUSPEND (0x3)
     56
     57#define C_IR (1 << 8)
     58#define C_RWC (1 << 9)
     59#define C_RWE (1 << 10)
     60
    4361        volatile uint32_t command_status;
     62#define CS_HCR (1 << 0)
     63#define CS_CLF (1 << 1)
     64#define CS_BLF (1 << 2)
     65#define CS_OCR (1 << 3)
     66#define CS_SOC_MASK (0x3)
     67#define CS_SOC_SHIFT (16)
     68
    4469        volatile uint32_t interrupt_status;
    4570#define IS_SO (1 << 0)
     
    5176#define IS_RHSC (1 << 6)
    5277#define IS_OC (1 << 30)
     78
    5379        volatile uint32_t interupt_enable;
    5480#define IE_SO   (1 << 0)
  • uspace/drv/ohci/root_hub.c

    r0b4e7ca rc593b21  
    4040#include "root_hub.h"
    4141#include "usb/classes/classes.h"
     42#include "usb/devdrv.h"
    4243#include <usb/request.h>
    4344#include <usb/classes/hub.h>
     
    6162                /// \TODO these values migt be different
    6263                .str_serial_number = 0,
    63                 .usb_spec_version = 0,
     64                .usb_spec_version = 0x110,
    6465};
    6566
     
    110111};
    111112
    112 /** Root hub initialization
    113  * @return Error code.
    114  */
    115 int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs)
    116 {
    117         assert(instance);
    118         instance->address = -1;
    119         instance->registers = regs;
    120         instance->device = dev;
    121 
    122 
    123         usb_log_info("OHCI root hub with %d ports.\n", regs->rh_desc_a & 0xff);
    124 
    125         //start generic usb hub driver
     113static const uint32_t hub_clear_feature_valid_mask =
     114        (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) +
     115        (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
     116
     117static const uint32_t hub_clear_feature_by_writing_one_mask =
     118        1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER;
     119
     120static const uint32_t hub_set_feature_valid_mask =
     121        (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
     122
    126123       
    127         /* TODO: implement */
    128         return EOK;
    129 }
    130 /*----------------------------------------------------------------------------*/
    131 
    132 /**
    133  * create answer to port status_request
    134  *
    135  * Copy content of corresponding port status register to answer buffer.
    136  *
    137  * @param instance root hub instance
    138  * @param port port number, counted from 1
    139  * @param request structure containing both request and response information
    140  * @return error code
    141  */
    142 static int process_get_port_status_request(rh_t *instance, uint16_t port,
    143                 usb_transfer_batch_t * request){
    144         if(port<1 || port>instance->port_count)
    145                 return EINVAL;
    146         uint32_t * uint32_buffer = (uint32_t*)request->buffer;
    147         request->transfered_size = 4;
    148         uint32_buffer[0] = instance->registers->rh_port_status[port -1];
    149         return EOK;
    150 }
    151 
    152 /**
    153  * create answer to port status_request
    154  *
    155  * Copy content of hub status register to answer buffer.
    156  *
    157  * @param instance root hub instance
    158  * @param request structure containing both request and response information
    159  * @return error code
    160  */
    161 static int process_get_hub_status_request(rh_t *instance,
    162                 usb_transfer_batch_t * request){
    163         uint32_t * uint32_buffer = (uint32_t*)request->buffer;
    164         //bits, 0,1,16,17
    165         request->transfered_size = 4;
    166         uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17);
    167         uint32_buffer[0] = mask & instance->registers->rh_status;
    168         return EOK;
    169 
    170 }
     124static const uint32_t hub_set_feature_direct_mask =
     125        (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
     126
     127static const uint32_t port_set_feature_valid_mask =
     128        (1 << USB_HUB_FEATURE_PORT_ENABLE) +
     129        (1 << USB_HUB_FEATURE_PORT_SUSPEND) +
     130        (1 << USB_HUB_FEATURE_PORT_RESET) +
     131        (1 << USB_HUB_FEATURE_PORT_POWER);
     132
     133static const uint32_t port_clear_feature_valid_mask =
     134        (1 << USB_HUB_FEATURE_PORT_CONNECTION) +
     135        (1 << USB_HUB_FEATURE_PORT_SUSPEND) +
     136        (1 << USB_HUB_FEATURE_PORT_OVER_CURRENT) +
     137        (1 << USB_HUB_FEATURE_PORT_POWER) +
     138        (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) +
     139        (1 << USB_HUB_FEATURE_C_PORT_ENABLE) +
     140        (1 << USB_HUB_FEATURE_C_PORT_SUSPEND) +
     141        (1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) +
     142        (1 << USB_HUB_FEATURE_C_PORT_RESET);
     143//note that USB_HUB_FEATURE_PORT_POWER bit is translated into USB_HUB_FEATURE_PORT_LOW_SPEED
     144
     145
     146
    171147
    172148/**
    173149 * Create hub descriptor used in hub-driver <-> hub communication
    174  * 
     150 *
    175151 * This means creating byt array from data in root hub registers. For more
    176152 * info see usb hub specification.
     
    197173        result[2] = instance->port_count;
    198174        uint32_t hub_desc_reg = instance->registers->rh_desc_a;
    199         result[3] = 
     175        result[3] =
    200176                        ((hub_desc_reg >> 8) %2) +
    201177                        (((hub_desc_reg >> 9) %2) << 1) +
     
    219195        (*out_size) = size;
    220196}
     197
     198
     199/** initialize hub descriptors
     200 *
     201 * Initialized are device and full configuration descriptor. These need to
     202 * be initialized only once per hub.
     203 * @instance root hub instance
     204 */
     205static void rh_init_descriptors(rh_t *instance){
     206        memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor,
     207                sizeof(ohci_rh_device_descriptor)
     208        );
     209        usb_standard_configuration_descriptor_t descriptor;
     210        memcpy(&descriptor,&ohci_rh_conf_descriptor,
     211                        sizeof(ohci_rh_conf_descriptor));
     212        uint8_t * hub_descriptor;
     213        size_t hub_desc_size;
     214        usb_create_serialized_hub_descriptor(instance, &hub_descriptor,
     215                        &hub_desc_size);
     216
     217        descriptor.total_length =
     218                        sizeof(usb_standard_configuration_descriptor_t)+
     219                        sizeof(usb_standard_endpoint_descriptor_t)+
     220                        sizeof(usb_standard_interface_descriptor_t)+
     221                        hub_desc_size;
     222       
     223        uint8_t * full_config_descriptor =
     224                        (uint8_t*) malloc(descriptor.total_length);
     225        memcpy(full_config_descriptor, &descriptor, sizeof(descriptor));
     226        memcpy(full_config_descriptor + sizeof(descriptor),
     227                        &ohci_rh_iface_descriptor, sizeof(ohci_rh_iface_descriptor));
     228        memcpy(full_config_descriptor + sizeof(descriptor) +
     229                                sizeof(ohci_rh_iface_descriptor),
     230                        &ohci_rh_ep_descriptor, sizeof(ohci_rh_ep_descriptor));
     231        memcpy(full_config_descriptor + sizeof(descriptor) +
     232                                sizeof(ohci_rh_iface_descriptor) +
     233                                sizeof(ohci_rh_ep_descriptor),
     234                        hub_descriptor, hub_desc_size);
     235       
     236        instance->descriptors.configuration = full_config_descriptor;
     237        instance->descriptors.configuration_size = descriptor.total_length;
     238}
     239
     240/** Root hub initialization
     241 * @return Error code.
     242 */
     243int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs)
     244{
     245        assert(instance);
     246        instance->address = -1;
     247        instance->registers = regs;
     248        instance->device = dev;
     249        instance->port_count = instance->registers->rh_desc_a & 0xff;
     250        rh_init_descriptors(instance);
     251        /// \TODO set port power mode
     252
     253
     254        usb_log_info("OHCI root hub with %d ports.\n", instance->port_count);
     255
     256        //start generic usb hub driver
     257       
     258        /* TODO: implement */
     259        return EOK;
     260}
     261/*----------------------------------------------------------------------------*/
     262
     263/**
     264 * create answer to port status_request
     265 *
     266 * Copy content of corresponding port status register to answer buffer.
     267 *
     268 * @param instance root hub instance
     269 * @param port port number, counted from 1
     270 * @param request structure containing both request and response information
     271 * @return error code
     272 */
     273static int process_get_port_status_request(rh_t *instance, uint16_t port,
     274                usb_transfer_batch_t * request){
     275        if(port<1 || port>instance->port_count)
     276                return EINVAL;
     277        uint32_t * uint32_buffer = (uint32_t*)request->transport_buffer;
     278        request->transfered_size = 4;
     279        uint32_buffer[0] = instance->registers->rh_port_status[port -1];
     280        return EOK;
     281}
     282
     283/**
     284 * create answer to port status_request
     285 *
     286 * Copy content of hub status register to answer buffer.
     287 *
     288 * @param instance root hub instance
     289 * @param request structure containing both request and response information
     290 * @return error code
     291 */
     292static int process_get_hub_status_request(rh_t *instance,
     293                usb_transfer_batch_t * request){
     294        uint32_t * uint32_buffer = (uint32_t*)request->transport_buffer;
     295        //bits, 0,1,16,17
     296        request->transfered_size = 4;
     297        uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17);
     298        uint32_buffer[0] = mask & instance->registers->rh_status;
     299        return EOK;
     300
     301}
     302
    221303
    222304
     
    284366        }
    285367}
    286 
    287 /**
    288  * create standart configuration descriptor for the root hub instance
    289  * @param instance root hub instance
    290  * @return newly allocated descriptor
    291  */
    292 static usb_standard_configuration_descriptor_t *
    293 usb_ohci_rh_create_standart_configuration_descriptor(rh_t *instance){
    294         usb_standard_configuration_descriptor_t * descriptor =
    295                         malloc(sizeof(usb_standard_configuration_descriptor_t));
    296         memcpy(descriptor, &ohci_rh_conf_descriptor,
    297                 sizeof(usb_standard_configuration_descriptor_t));
    298         /// \TODO should this include device descriptor?
    299         const size_t hub_descriptor_size = 7 +
    300                         2* (instance->port_count / 8 +
    301                         ((instance->port_count % 8 > 0) ? 1 : 0));
    302         descriptor->total_length =
    303                         sizeof(usb_standard_configuration_descriptor_t)+
    304                         sizeof(usb_standard_endpoint_descriptor_t)+
    305                         sizeof(usb_standard_interface_descriptor_t)+
    306                         hub_descriptor_size;
    307         return descriptor;
    308 }
    309 
     368 
    310369/**
    311370 * create answer to a descriptor request
     
    344403                case USB_DESCTYPE_CONFIGURATION: {
    345404                        usb_log_debug("USB_DESCTYPE_CONFIGURATION\n");
    346                         usb_standard_configuration_descriptor_t * descriptor =
    347                                         usb_ohci_rh_create_standart_configuration_descriptor(
    348                                                 instance);
    349                         result_descriptor = descriptor;
    350                         size = sizeof(usb_standard_configuration_descriptor_t);
    351                         del = true;
     405                        result_descriptor = instance->descriptors.configuration;
     406                        size = instance->descriptors.configuration_size;
    352407                        break;
    353408                }
     
    380435        }
    381436        request->transfered_size = size;
    382         memcpy(request->buffer,result_descriptor,size);
     437        memcpy(request->transport_buffer,result_descriptor,size);
     438        usb_log_debug("sent desctiptor: %s\n",
     439                        usb_debug_str_buffer((uint8_t*)request->transport_buffer,size,size));
    383440        if (del)
    384441                free(result_descriptor);
     
    400457        if(request->buffer_size != 1)
    401458                return EINVAL;
    402         request->buffer[0] = 1;
     459        request->transport_buffer[0] = 1;
    403460        request->transfered_size = 1;
    404461        return EOK;
     
    406463
    407464/**
    408  * process feature-enabling/disabling request on hub
     465 * process feature-enabling request on hub
    409466 *
    410467 * @param instance root hub instance
    411468 * @param feature feature selector
    412  * @param enable enable or disable specified feature
    413469 * @return error code
    414470 */
    415471static int process_hub_feature_set_request(rh_t *instance,
    416                 uint16_t feature, bool enable){
    417         if(feature > USB_HUB_FEATURE_C_HUB_OVER_CURRENT)
     472                uint16_t feature){
     473        if(! ((1<<feature) & hub_set_feature_valid_mask))
    418474                return EINVAL;
    419475        instance->registers->rh_status =
    420                         enable ?
    421476                        (instance->registers->rh_status | (1<<feature))
    422                         :
    423                         (instance->registers->rh_status & (~(1<<feature)));
    424         /// \TODO any error?
    425         return EOK;
    426 }
    427 
    428 /**
    429  * process feature-enabling/disabling request on hub
     477                        & (~ hub_clear_feature_by_writing_one_mask);
     478        return EOK;
     479}
     480
     481/**
     482 * process feature-disabling request on hub
     483 *
     484 * @param instance root hub instance
     485 * @param feature feature selector
     486 * @return error code
     487 */
     488static int process_hub_feature_clear_request(rh_t *instance,
     489                uint16_t feature){
     490        if(! ((1<<feature) & hub_clear_feature_valid_mask))
     491                return EINVAL;
     492        //is the feature cleared directly?
     493        if ((1<<feature) & hub_set_feature_direct_mask){
     494                instance->registers->rh_status =
     495                        (instance->registers->rh_status & (~(1<<feature)))
     496                        & (~ hub_clear_feature_by_writing_one_mask);
     497        }else{//the feature is cleared by writing '1'
     498                instance->registers->rh_status =
     499                                (instance->registers->rh_status
     500                                & (~ hub_clear_feature_by_writing_one_mask))
     501                                | (1<<feature);
     502        }
     503        return EOK;
     504}
     505
     506
     507
     508/**
     509 * process feature-enabling request on hub
    430510 *
    431511 * @param instance root hub instance
     
    436516 */
    437517static int process_port_feature_set_request(rh_t *instance,
    438                 uint16_t feature, uint16_t port, bool enable){
    439         if(feature > USB_HUB_FEATURE_C_PORT_RESET)
     518                uint16_t feature, uint16_t port){
     519        if(!((1<<feature) & port_set_feature_valid_mask))
    440520                return EINVAL;
    441521        if(port<1 || port>instance->port_count)
    442522                return EINVAL;
    443523        instance->registers->rh_port_status[port - 1] =
    444                         enable ?
    445524                        (instance->registers->rh_port_status[port - 1] | (1<<feature))
    446                         :
    447                         (instance->registers->rh_port_status[port - 1] & (~(1<<feature)));
     525                        & (~port_clear_feature_valid_mask);
    448526        /// \TODO any error?
    449527        return EOK;
    450528}
     529
     530/**
     531 * process feature-disabling request on hub
     532 *
     533 * @param instance root hub instance
     534 * @param feature feature selector
     535 * @param port port number, counted from 1
     536 * @param enable enable or disable the specified feature
     537 * @return error code
     538 */
     539static int process_port_feature_clear_request(rh_t *instance,
     540                uint16_t feature, uint16_t port){
     541        if(!((1<<feature) & port_clear_feature_valid_mask))
     542                return EINVAL;
     543        if(port<1 || port>instance->port_count)
     544                return EINVAL;
     545        if(feature == USB_HUB_FEATURE_PORT_POWER)
     546                feature = USB_HUB_FEATURE_PORT_LOW_SPEED;
     547        if(feature == USB_HUB_FEATURE_PORT_SUSPEND)
     548                feature = USB_HUB_FEATURE_PORT_OVER_CURRENT;
     549        instance->registers->rh_port_status[port - 1] =
     550                        (instance->registers->rh_port_status[port - 1]
     551                        & (~port_clear_feature_valid_mask))
     552                        | (1<<feature);
     553        /// \TODO any error?
     554        return EOK;
     555}
     556
    451557
    452558/**
     
    530636                        (usb_device_request_setup_packet_t*)request->setup_buffer;
    531637        request->transfered_size = 0;
    532         if(setup_request->request == USB_DEVREQ_CLEAR_FEATURE
    533                                 || setup_request->request == USB_DEVREQ_SET_FEATURE){
     638        if(setup_request->request == USB_DEVREQ_CLEAR_FEATURE){
    534639                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){
    535640                        usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
    536                         return process_hub_feature_set_request(instance, setup_request->value,
    537                                         setup_request->request == USB_DEVREQ_SET_FEATURE);
     641                        return process_hub_feature_clear_request(instance,
     642                                        setup_request->value);
    538643                }
    539644                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){
    540645                        usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
    541                         return process_port_feature_set_request(instance, setup_request->value,
    542                                         setup_request->index,
    543                                         setup_request->request == USB_DEVREQ_SET_FEATURE);
     646                        return process_port_feature_clear_request(instance,
     647                                        setup_request->value,
     648                                        setup_request->index);
     649                }
     650                usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",
     651                                setup_request->request_type);
     652                return EINVAL;
     653        }
     654        if(setup_request->request == USB_DEVREQ_SET_FEATURE){
     655                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){
     656                        usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
     657                        return process_hub_feature_set_request(instance,
     658                                        setup_request->value);
     659                }
     660                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){
     661                        usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
     662                        return process_port_feature_set_request(instance,
     663                                        setup_request->value,
     664                                        setup_request->index);
    544665                }
    545666                usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",setup_request->request_type);
  • uspace/drv/ohci/root_hub.h

    r0b4e7ca rc593b21  
    3737
    3838#include <usb/usb.h>
     39#include <usb/devdrv.h>
    3940
    4041#include "ohci_regs.h"
     
    5354        /** hub port count */
    5455        int port_count;
     56        /** hubs descriptors */
     57        usb_device_descriptors_t descriptors;
    5558} rh_t;
    5659
  • uspace/drv/pciintel/pci.c

    r0b4e7ca rc593b21  
    4848
    4949#include <ddf/driver.h>
     50#include <ddf/log.h>
    5051#include <devman.h>
    5152#include <ipc/devman.h>
     
    325326
    326327        if (match_id_str == NULL) {
    327                 printf(NAME ": out of memory creating match ID.\n");
     328                ddf_msg(LVL_ERROR, "Out of memory creating match ID.");
    328329                return;
    329330        }
     
    331332        rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 90);
    332333        if (rc != EOK) {
    333                 printf(NAME ": error adding match ID: %s\n",
     334                ddf_msg(LVL_ERROR, "Failed adding match ID: %s",
    334335                    str_error(rc));
    335336        }
     
    428429       
    429430        if (range_addr != 0) {
    430                 printf(NAME ": function %s : ", fun->fnode->name);
    431                 printf("address = %" PRIx64, range_addr);
    432                 printf(", size = %x\n", (unsigned int) range_size);
     431                ddf_msg(LVL_DEBUG, "Function %s : address = %" PRIx64
     432                    ", size = %x", fun->fnode->name, range_addr,
     433                    (unsigned int) range_size);
    433434        }
    434435       
     
    455456        hw_res_list->count++;
    456457       
    457         printf(NAME ": function %s uses irq %x.\n", fun->fnode->name, irq);
     458        ddf_msg(LVL_NOTE, "Function %s uses irq %x.", fun->fnode->name, irq);
    458459}
    459460
     
    511512                        char *fun_name = pci_fun_create_name(fun);
    512513                        if (fun_name == NULL) {
    513                                 printf(NAME ": out of memory.\n");
     514                                ddf_msg(LVL_ERROR, "Out of memory.");
    514515                                return;
    515516                        }
     
    517518                        fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name);
    518519                        if (fnode == NULL) {
    519                                 printf(NAME ": error creating function.\n");
     520                                ddf_msg(LVL_ERROR, "Failed creating function.");
    520521                                return;
    521522                        }
     
    531532                        fnode->driver_data = fun;
    532533                       
    533                         printf(NAME ": adding new function %s.\n",
     534                        ddf_msg(LVL_DEBUG, "Adding new function %s.",
    534535                            fnode->name);
    535536                       
     
    548549                                child_bus = pci_conf_read_8(fun,
    549550                                    PCI_BRIDGE_SEC_BUS_NUM);
    550                                 printf(NAME ": device is pci-to-pci bridge, "
    551                                     "secondary bus number = %d.\n", bus_num);
     551                                ddf_msg(LVL_DEBUG, "Device is pci-to-pci "
     552                                    "bridge, secondary bus number = %d.",
     553                                    bus_num);
    552554                                if (child_bus > bus_num)
    553555                                        pci_bus_scan(bus, child_bus);
     
    571573        int rc;
    572574       
    573         printf(NAME ": pci_add_device\n");
     575        ddf_msg(LVL_DEBUG, "pci_add_device");
    574576        dnode->parent_phone = -1;
    575577       
    576578        bus = pci_bus_new();
    577579        if (bus == NULL) {
    578                 printf(NAME ": pci_add_device allocation failed.\n");
     580                ddf_msg(LVL_ERROR, "pci_add_device allocation failed.");
    579581                rc = ENOMEM;
    580582                goto fail;
     
    586588            IPC_FLAG_BLOCKING);
    587589        if (dnode->parent_phone < 0) {
    588                 printf(NAME ": pci_add_device failed to connect to the "
    589                     "parent's driver.\n");
     590                ddf_msg(LVL_ERROR, "pci_add_device failed to connect to the "
     591                    "parent's driver.");
    590592                rc = dnode->parent_phone;
    591593                goto fail;
     
    596598        rc = hw_res_get_resource_list(dnode->parent_phone, &hw_resources);
    597599        if (rc != EOK) {
    598                 printf(NAME ": pci_add_device failed to get hw resources for "
    599                     "the device.\n");
     600                ddf_msg(LVL_ERROR, "pci_add_device failed to get hw resources "
     601                    "for the device.");
    600602                goto fail;
    601603        }
    602604        got_res = true;
    603605       
    604         printf(NAME ": conf_addr = %" PRIx64 ".\n",
     606        ddf_msg(LVL_DEBUG, "conf_addr = %" PRIx64 ".",
    605607            hw_resources.resources[0].res.io_range.address);
    606608       
     
    614616        if (pio_enable((void *)(uintptr_t)bus->conf_io_addr, 8,
    615617            &bus->conf_addr_port)) {
    616                 printf(NAME ": failed to enable configuration ports.\n");
     618                ddf_msg(LVL_ERROR, "Failed to enable configuration ports.");
    617619                rc = EADDRNOTAVAIL;
    618620                goto fail;
     
    621623       
    622624        /* Make the bus device more visible. It has no use yet. */
    623         printf(NAME ": adding a 'ctl' function\n");
     625        ddf_msg(LVL_DEBUG, "Adding a 'ctl' function");
    624626       
    625627        ctl = ddf_fun_create(bus->dnode, fun_exposed, "ctl");
    626628        if (ctl == NULL) {
    627                 printf(NAME ": error creating control function.\n");
     629                ddf_msg(LVL_ERROR, "Failed creating control function.");
    628630                rc = ENOMEM;
    629631                goto fail;
     
    632634        rc = ddf_fun_bind(ctl);
    633635        if (rc != EOK) {
    634                 printf(NAME ": error binding control function.\n");
     636                ddf_msg(LVL_ERROR, "Failed binding control function.");
    635637                goto fail;
    636638        }
    637639       
    638640        /* Enumerate functions. */
    639         printf(NAME ": scanning the bus\n");
     641        ddf_msg(LVL_DEBUG, "Scanning the bus");
    640642        pci_bus_scan(bus, 0);
    641643       
     
    659661static void pciintel_init(void)
    660662{
     663        ddf_log_init(NAME, LVL_ERROR);
    661664        pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops;
    662665        pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops;
     
    738741int main(int argc, char *argv[])
    739742{
    740         printf(NAME ": HelenOS pci bus driver (intel method 1).\n");
     743        printf(NAME ": HelenOS PCI bus driver (Intel method 1).\n");
    741744        pciintel_init();
    742745        return ddf_driver_main(&pci_driver);
  • uspace/drv/root/root.c

    r0b4e7ca rc593b21  
    5252
    5353#include <ddf/driver.h>
     54#include <ddf/log.h>
    5455#include <devman.h>
    5556#include <ipc/devman.h>
     
    8990        int rc;
    9091
    91         printf(NAME ": adding new function for virtual devices.\n");
    92         printf(NAME ":   function node is `%s' (%d %s)\n", name,
     92        ddf_msg(LVL_DEBUG, "Adding new function for virtual devices. "
     93            "Function node is `%s' (%d %s)", name,
    9394            VIRTUAL_FUN_MATCH_SCORE, VIRTUAL_FUN_MATCH_ID);
    9495
    9596        fun = ddf_fun_create(dev, fun_inner, name);
    9697        if (fun == NULL) {
    97                 printf(NAME ": error creating function %s\n", name);
     98                ddf_msg(LVL_ERROR, "Failed creating function %s", name);
    9899                return ENOMEM;
    99100        }
     
    102103            VIRTUAL_FUN_MATCH_SCORE);
    103104        if (rc != EOK) {
    104                 printf(NAME ": error adding match IDs to function %s\n", name);
     105                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     106                    name);
    105107                ddf_fun_destroy(fun);
    106108                return rc;
     
    109111        rc = ddf_fun_bind(fun);
    110112        if (rc != EOK) {
    111                 printf(NAME ": error binding function %s: %s\n", name,
     113                ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    112114                    str_error(rc));
    113115                ddf_fun_destroy(fun);
     
    136138        platform = sysinfo_get_data("platform", &platform_size);
    137139        if (platform == NULL) {
    138                 printf(NAME ": Failed to obtain platform name.\n");
     140                ddf_msg(LVL_ERROR, "Failed to obtain platform name.");
    139141                return ENOENT;
    140142        }
     
    143145        platform = realloc(platform, platform_size + 1);
    144146        if (platform == NULL) {
    145                 printf(NAME ": Memory allocation failed.\n");
     147                ddf_msg(LVL_ERROR, "Memory allocation failed.");
    146148                return ENOMEM;
    147149        }
     
    151153        /* Construct match ID. */
    152154        if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) {
    153                 printf(NAME ": Memory allocation failed.\n");
     155                ddf_msg(LVL_ERROR, "Memory allocation failed.");
    154156                return ENOMEM;
    155157        }
    156158
    157159        /* Add function. */
    158         printf(NAME ": adding platform function\n");
    159         printf(NAME ":   function node is `%s' (%d %s)\n", PLATFORM_FUN_NAME,
    160             PLATFORM_FUN_MATCH_SCORE, match_id);
     160        ddf_msg(LVL_DEBUG, "Adding platform function. Function node is `%s' "
     161            " (%d %s)", PLATFORM_FUN_NAME, PLATFORM_FUN_MATCH_SCORE,
     162            match_id);
    161163
    162164        fun = ddf_fun_create(dev, fun_inner, name);
    163165        if (fun == NULL) {
    164                 printf(NAME ": error creating function %s\n", name);
     166                ddf_msg(LVL_ERROR, "Error creating function %s", name);
    165167                return ENOMEM;
    166168        }
     
    168170        rc = ddf_fun_add_match_id(fun, match_id, PLATFORM_FUN_MATCH_SCORE);
    169171        if (rc != EOK) {
    170                 printf(NAME ": error adding match IDs to function %s\n", name);
     172                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     173                    name);
    171174                ddf_fun_destroy(fun);
    172175                return rc;
     
    175178        rc = ddf_fun_bind(fun);
    176179        if (rc != EOK) {
    177                 printf(NAME ": error binding function %s: %s\n", name,
     180                ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    178181                    str_error(rc));
    179182                ddf_fun_destroy(fun);
     
    191194static int root_add_device(ddf_dev_t *dev)
    192195{
    193         printf(NAME ": root_add_device, device handle=%" PRIun "\n",
     196        ddf_msg(LVL_DEBUG, "root_add_device, device handle=%" PRIun,
    194197            dev->handle);
    195198
     
    204207        int res = add_platform_fun(dev);
    205208        if (EOK != res)
    206                 printf(NAME ": failed to add child device for platform.\n");
     209                ddf_msg(LVL_ERROR, "Failed adding child device for platform.");
    207210
    208211        return res;
     
    212215{
    213216        printf(NAME ": HelenOS root device driver\n");
     217
     218        ddf_log_init(NAME, LVL_ERROR);
    214219        return ddf_driver_main(&root_driver);
    215220}
  • uspace/drv/rootpc/rootpc.c

    r0b4e7ca rc593b21  
    4747
    4848#include <ddf/driver.h>
     49#include <ddf/log.h>
    4950#include <devman.h>
    5051#include <ipc/devman.h>
     
    119120    rootpc_fun_t *fun)
    120121{
    121         printf(NAME ": adding new function '%s'.\n", name);
     122        ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
    122123       
    123124        ddf_fun_t *fnode = NULL;
     
    145146        /* Register function. */
    146147        if (ddf_fun_bind(fnode) != EOK) {
    147                 printf(NAME ": error binding function %s.\n", name);
     148                ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
    148149                goto failure;
    149150        }
     
    158159                ddf_fun_destroy(fnode);
    159160       
    160         printf(NAME ": failed to add function '%s'.\n", name);
     161        ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
    161162       
    162163        return false;
     
    176177static int rootpc_add_device(ddf_dev_t *dev)
    177178{
    178         printf(NAME ": rootpc_add_device, device handle = %d\n",
     179        ddf_msg(LVL_DEBUG, "rootpc_add_device, device handle = %d",
    179180            (int)dev->handle);
    180181       
    181182        /* Register functions. */
    182183        if (!rootpc_add_functions(dev)) {
    183                 printf(NAME ": failed to add functions for PC platform.\n");
     184                ddf_msg(LVL_ERROR, "Failed to add functions for PC platform.");
    184185        }
    185186       
     
    189190static void root_pc_init(void)
    190191{
     192        ddf_log_init(NAME, LVL_ERROR);
    191193        rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
    192194}
  • uspace/drv/rootvirt/rootvirt.c

    r0b4e7ca rc593b21  
    4040#include <str_error.h>
    4141#include <ddf/driver.h>
     42#include <ddf/log.h>
    4243
    4344#define NAME "rootvirt"
     
    8384        int rc;
    8485
    85         printf(NAME ": registering function `%s' (match \"%s\")\n",
     86        ddf_msg(LVL_DEBUG, "Registering function `%s' (match \"%s\")",
    8687            vfun->name, vfun->match_id);
    8788
    8889        fun = ddf_fun_create(vdev, fun_inner, vfun->name);
    8990        if (fun == NULL) {
    90                 printf(NAME ": error creating function %s\n", vfun->name);
     91                ddf_msg(LVL_ERROR, "Failed creating function %s", vfun->name);
    9192                return ENOMEM;
    9293        }
     
    9495        rc = ddf_fun_add_match_id(fun, vfun->match_id, 10);
    9596        if (rc != EOK) {
    96                 printf(NAME ": error adding match IDs to function %s\n",
     97                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
    9798                    vfun->name);
    9899                ddf_fun_destroy(fun);
     
    102103        rc = ddf_fun_bind(fun);
    103104        if (rc != EOK) {
    104                 printf(NAME ": error binding function %s: %s\n", vfun->name,
    105                     str_error(rc));
     105                ddf_msg(LVL_ERROR, "Failed binding function %s: %s",
     106                    vfun->name, str_error(rc));
    106107                ddf_fun_destroy(fun);
    107108                return rc;
    108109        }
    109110
    110         printf(NAME ": registered child device `%s'\n", vfun->name);
     111        ddf_msg(LVL_NOTE, "Registered child device `%s'", vfun->name);
    111112        return EOK;
    112113}
     
    124125        }
    125126
    126         printf(NAME ": add_device(handle=%d)\n", (int)dev->handle);
     127        ddf_msg(LVL_DEBUG, "add_device(handle=%d)", (int)dev->handle);
    127128
    128129        /*
     
    142143{
    143144        printf(NAME ": HelenOS virtual devices root driver\n");
     145
     146        ddf_log_init(NAME, LVL_ERROR);
    144147        return ddf_driver_main(&rootvirt_driver);
    145148}
  • uspace/drv/test1/test1.c

    r0b4e7ca rc593b21  
    3535#include <str_error.h>
    3636#include <ddf/driver.h>
     37#include <ddf/log.h>
    3738
    3839#include "test1.h"
     
    5859 */
    5960static int register_fun_verbose(ddf_dev_t *parent, const char *message,
    60     const char *name, const char *match_id, int match_score)
     61    const char *name, const char *match_id, int match_score,
     62    int expected_rc)
    6163{
    62         ddf_fun_t *fun;
     64        ddf_fun_t *fun = NULL;
    6365        int rc;
    6466
    65         printf(NAME ": registering function `%s': %s.\n", name, message);
     67        ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message);
    6668
    6769        fun = ddf_fun_create(parent, fun_inner, name);
    6870        if (fun == NULL) {
    69                 printf(NAME ": error creating function %s\n", name);
    70                 return ENOMEM;
     71                ddf_msg(LVL_ERROR, "Failed creating function %s", name);
     72                rc = ENOMEM;
     73                goto leave;
    7174        }
    7275
    73         rc = ddf_fun_add_match_id(fun, match_id, match_score);
     76        rc = ddf_fun_add_match_id(fun, str_dup(match_id), match_score);
    7477        if (rc != EOK) {
    75                 printf(NAME ": error adding match IDs to function %s\n", name);
    76                 ddf_fun_destroy(fun);
    77                 return rc;
     78                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     79                    name);
     80                goto leave;
    7881        }
    7982
    8083        rc = ddf_fun_bind(fun);
    8184        if (rc != EOK) {
    82                 printf(NAME ": error binding function %s: %s\n", name,
     85                ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    8386                    str_error(rc));
    84                 ddf_fun_destroy(fun);
    85                 return rc;
     87                goto leave;
    8688        }
    8789
    88         printf(NAME ": registered child device `%s'\n", name);
    89         return EOK;
     90        ddf_msg(LVL_NOTE, "Registered child device `%s'", name);
     91        rc = EOK;
     92
     93leave:
     94        if (rc != expected_rc) {
     95                fprintf(stderr,
     96                    NAME ": Unexpected error registering function `%s'.\n"
     97                    NAME ":     Expected \"%s\" but got \"%s\".\n",
     98                    name, str_error(expected_rc), str_error(rc));
     99        }
     100
     101        if ((rc != EOK) && (fun != NULL)) {
     102                ddf_fun_destroy(fun);
     103        }
     104
     105        return rc;
    90106}
    91107
     
    112128        int rc;
    113129
    114         printf(NAME ": add_device(name=\"%s\", handle=%d)\n",
     130        ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)",
    115131            dev->name, (int) dev->handle);
    116132
    117133        fun_a = ddf_fun_create(dev, fun_exposed, "a");
    118134        if (fun_a == NULL) {
    119                 printf(NAME ": error creating function 'a'.\n");
     135                ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
    120136                return ENOMEM;
    121137        }
     
    123139        rc = ddf_fun_bind(fun_a);
    124140        if (rc != EOK) {
    125                 printf(NAME ": error binding function 'a'.\n");
     141                ddf_msg(LVL_ERROR, "Failed binding function 'a'.");
    126142                return rc;
    127143        }
     
    133149                ddf_fun_add_to_class(fun_a, "virt-null");
    134150        } else if (str_cmp(dev->name, "test1") == 0) {
    135                 (void) register_fun_verbose(dev, "cloning myself ;-)", "clone",
    136                     "virtual&test1", 10);
     151                (void) register_fun_verbose(dev,
     152                    "cloning myself ;-)", "clone",
     153                    "virtual&test1", 10, EOK);
     154                (void) register_fun_verbose(dev,
     155                    "cloning myself twice ;-)", "clone",
     156                    "virtual&test1", 10, EEXISTS);
    137157        } else if (str_cmp(dev->name, "clone") == 0) {
    138                 (void) register_fun_verbose(dev, "run by the same task", "child",
    139                     "virtual&test1&child", 10);
     158                (void) register_fun_verbose(dev,
     159                    "run by the same task", "child",
     160                    "virtual&test1&child", 10, EOK);
    140161        }
    141162
    142         printf(NAME ": device `%s' accepted.\n", dev->name);
     163        ddf_msg(LVL_DEBUG, "Device `%s' accepted.", dev->name);
    143164
    144165        return EOK;
     
    148169{
    149170        printf(NAME ": HelenOS test1 virtual device driver\n");
     171        ddf_log_init(NAME, LVL_ERROR);
    150172        return ddf_driver_main(&test1_driver);
    151173}
  • uspace/drv/test2/test2.c

    r0b4e7ca rc593b21  
    3636#include <str_error.h>
    3737#include <ddf/driver.h>
     38#include <ddf/log.h>
    3839
    3940#define NAME "test2"
     
    6465        int rc;
    6566
    66         printf(NAME ": registering function `%s': %s.\n", name, message);
     67        ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message);
    6768
    6869        fun = ddf_fun_create(parent, fun_inner, name);
    6970        if (fun == NULL) {
    70                 printf(NAME ": error creating function %s\n", name);
     71                ddf_msg(LVL_ERROR, "Failed creating function %s", name);
    7172                return ENOMEM;
    7273        }
     
    7475        rc = ddf_fun_add_match_id(fun, match_id, match_score);
    7576        if (rc != EOK) {
    76                 printf(NAME ": error adding match IDs to function %s\n", name);
     77                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     78                    name);
    7779                ddf_fun_destroy(fun);
    7880                return rc;
     
    8183        rc = ddf_fun_bind(fun);
    8284        if (rc != EOK) {
    83                 printf(NAME ": error binding function %s: %s\n", name,
     85                ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    8486                    str_error(rc));
    8587                ddf_fun_destroy(fun);
     
    8789        }
    8890
    89         printf(NAME ": registered child device `%s'\n", name);
     91        ddf_msg(LVL_NOTE, "Registered child device `%s'", name);
    9092        return EOK;
    9193}
     
    111113        fun_a = ddf_fun_create(dev, fun_exposed, "a");
    112114        if (fun_a == NULL) {
    113                 printf(NAME ": error creating function 'a'.\n");
     115                ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
    114116                return ENOMEM;
    115117        }
     
    117119        rc = ddf_fun_bind(fun_a);
    118120        if (rc != EOK) {
    119                 printf(NAME ": error binding function 'a'.\n");
     121                ddf_msg(LVL_ERROR, "Failed binding function 'a'.");
    120122                return rc;
    121123        }
     
    128130static int test2_add_device(ddf_dev_t *dev)
    129131{
    130         printf(NAME ": test2_add_device(name=\"%s\", handle=%d)\n",
     132        ddf_msg(LVL_DEBUG, "test2_add_device(name=\"%s\", handle=%d)",
    131133            dev->name, (int) dev->handle);
    132134
     
    134136                fid_t postpone = fibril_create(postponed_birth, dev);
    135137                if (postpone == 0) {
    136                         printf(NAME ": fibril_create() error\n");
     138                        ddf_msg(LVL_ERROR, "fibril_create() failed.");
    137139                        return ENOMEM;
    138140                }
     
    149151{
    150152        printf(NAME ": HelenOS test2 virtual device driver\n");
     153        ddf_log_init(NAME, LVL_ERROR);
    151154        return ddf_driver_main(&test2_driver);
    152155}
  • uspace/drv/uhci-hcd/hc.c

    r0b4e7ca rc593b21  
    239239        usb_log_debug("Initialized device manager.\n");
    240240
     241        ret = bandwidth_init(&instance->bandwidth, BANDWIDTH_AVAILABLE_USB11,
     242            bandwidth_count_usb11);
     243        assert(ret == EOK);
     244
    241245        return EOK;
    242246#undef CHECK_RET_DEST_CMDS_RETURN
     
    325329        if (!usb_is_allowed(
    326330            low_speed, batch->transfer_type, batch->max_packet_size)) {
    327                 usb_log_warning(
    328                     "Invalid USB transfer specified %s SPEED %d %zu.\n",
    329                     low_speed ? "LOW" : "FULL" , batch->transfer_type,
     331                usb_log_error("Invalid USB transfer specified %s %d %zu.\n",
     332                    usb_str_speed(batch->speed), batch->transfer_type,
    330333                    batch->max_packet_size);
    331334                return ENOTSUP;
    332335        }
    333         /* TODO: check available bandwidth here */
     336        /* Check available bandwidth */
     337        if (batch->transfer_type == USB_TRANSFER_INTERRUPT ||
     338            batch->transfer_type == USB_TRANSFER_ISOCHRONOUS) {
     339                int ret =
     340                    bandwidth_use(&instance->bandwidth, batch->target.address,
     341                    batch->target.endpoint, batch->direction);
     342                if (ret != EOK) {
     343                        usb_log_warning("Failed(%d) to use reserved bw: %s.\n",
     344                            ret, str_error(ret));
     345                }
     346        }
    334347
    335348        transfer_list_t *list =
     
    338351        if (batch->transfer_type == USB_TRANSFER_CONTROL) {
    339352                usb_device_keeper_use_control(
    340                     &instance->manager, batch->target.address);
     353                    &instance->manager, batch->target);
    341354        }
    342355        transfer_list_add_batch(list, batch);
     
    358371{
    359372        assert(instance);
     373//      status |= 1; //Uncomment to work around qemu hang
    360374        /* TODO: Resume interrupts are not supported */
    361375        /* Lower 2 bits are transaction error and transaction complete */
     
    376390                        usb_transfer_batch_t *batch =
    377391                            list_get_instance(item, usb_transfer_batch_t, link);
    378                         if (batch->transfer_type == USB_TRANSFER_CONTROL) {
     392                        switch (batch->transfer_type)
     393                        {
     394                        case USB_TRANSFER_CONTROL:
    379395                                usb_device_keeper_release_control(
    380                                     &instance->manager, batch->target.address);
     396                                    &instance->manager, batch->target);
     397                                break;
     398                        case USB_TRANSFER_INTERRUPT:
     399                        case USB_TRANSFER_ISOCHRONOUS: {
     400                                int ret = bandwidth_free(&instance->bandwidth,
     401                                    batch->target.address,
     402                                    batch->target.endpoint,
     403                                    batch->direction);
     404                                if (ret != EOK)
     405                                        usb_log_warning("Failed(%d) to free "
     406                                            "reserved bw: %s.\n", ret,
     407                                            str_error(ret));
     408                                }
     409                        default:
     410                                break;
    381411                        }
    382412                        batch->next_step(batch);
  • uspace/drv/uhci-hcd/hc.h

    r0b4e7ca rc593b21  
    4343#include <usbhc_iface.h>
    4444#include <usb/host/device_keeper.h>
     45#include <usb/host/bandwidth.h>
    4546
    4647#include "batch.h"
     
    8485typedef struct hc {
    8586        usb_device_keeper_t manager;
     87        bandwidth_t bandwidth;
    8688
    8789        regs_t *registers;
  • uspace/drv/uhci-hcd/iface.c

    r0b4e7ca rc593b21  
    128128}
    129129/*----------------------------------------------------------------------------*/
     130static int register_endpoint(
     131    ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint,
     132    usb_transfer_type_t transfer_type, usb_direction_t direction,
     133    size_t max_packet_size, unsigned int interval)
     134{
     135        hc_t *hc = fun_to_hc(fun);
     136        assert(hc);
     137        const usb_speed_t speed =
     138            usb_device_keeper_get_speed(&hc->manager, address);
     139        size_t size = max_packet_size;
     140
     141        usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
     142            address, endpoint, usb_str_transfer_type(transfer_type),
     143            usb_str_speed(speed), direction, size, max_packet_size, interval);
     144        return bandwidth_reserve(&hc->bandwidth, address, endpoint, direction,
     145            speed, transfer_type, max_packet_size, size, interval);
     146}
     147/*----------------------------------------------------------------------------*/
     148static int unregister_endpoint(
     149    ddf_fun_t *fun, usb_address_t address,
     150    usb_endpoint_t endpoint, usb_direction_t direction)
     151{
     152        hc_t *hc = fun_to_hc(fun);
     153        assert(hc);
     154        usb_log_debug("Unregister endpoint %d:%d %d.\n",
     155            address, endpoint, direction);
     156        return bandwidth_release(&hc->bandwidth, address, endpoint, direction);
     157}
     158/*----------------------------------------------------------------------------*/
    130159/** Interrupt out transaction interface function
    131160 *
     
    365394        .release_address = release_address,
    366395
     396        .register_endpoint = register_endpoint,
     397        .unregister_endpoint = unregister_endpoint,
     398
    367399        .interrupt_out = interrupt_out,
    368400        .interrupt_in = interrupt_in,
  • uspace/drv/usbhub/port_status.h

    r0b4e7ca rc593b21  
    9595}
    9696
     97/**
     98 * set the device request to be a port feature clear request
     99 * @param request
     100 * @param port
     101 * @param feature_selector
     102 */
     103static inline void usb_hub_set_disable_port_feature_request(
     104usb_device_request_setup_packet_t * request, uint16_t port,
     105                uint16_t feature_selector
     106){
     107        request->index = port;
     108        request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
     109        request->request = USB_HUB_REQUEST_CLEAR_FEATURE;
     110        request->value = feature_selector;
     111        request->length = 0;
     112}
    97113
    98114/**
  • uspace/drv/usbhub/usbhub.c

    r0b4e7ca rc593b21  
    7474
    7575        while(errorCode == EOK){
     76                async_usleep(1000 * 1000 * 10 );/// \TODO proper number once
    7677                errorCode = usb_hub_check_hub_changes(hub_info);
    77                 async_usleep(1000 * 1000 );/// \TODO proper number once
    7878        }
    7979        usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode);
     
    317317                        //set the status change bit, so it will be noticed in driver loop
    318318                        if(usb_port_dev_connected(&status)){
    319                                 usb_hub_set_enable_port_feature_request(&request, port,
    320                                                 USB_HUB_FEATURE_C_PORT_CONNECTION);
     319                                usb_hub_set_disable_port_feature_request(&request, port,
     320                                                USB_HUB_FEATURE_PORT_CONNECTION);
    321321                                opResult = usb_pipe_control_read(
    322322                                                hub->control_pipe,
     
    326326                                if (opResult != EOK) {
    327327                                        usb_log_warning(
    328                                                         "could not set port change on port %d errno:%d\n",
     328                                                        "could not clear port connection on port %d errno:%d\n",
    329329                                                        port, opResult);
    330330                                }
     331                                usb_log_debug("cleared port connection\n");
     332                                usb_hub_set_enable_port_feature_request(&request, port,
     333                                                USB_HUB_FEATURE_PORT_ENABLE);
     334                                opResult = usb_pipe_control_read(
     335                                                hub->control_pipe,
     336                                                &request, sizeof(usb_device_request_setup_packet_t),
     337                                                &status, 4, &rcvd_size
     338                                                );
     339                                if (opResult != EOK) {
     340                                        usb_log_warning(
     341                                                        "could not set port enabled on port %d errno:%d\n",
     342                                                        port, opResult);
     343                                }
     344                                usb_log_debug("port set to enabled - should lead to connection change\n");
    331345                        }
     346                }
     347        }
     348        /// \TODO this is just a debug code
     349        for(port=1;port<=descriptor->ports_count;++port){
     350                bool is_non_removable =
     351                                ((non_removable_dev_bitmap[port/8]) >> (port%8)) %2;
     352                if(is_non_removable){
     353                        usb_log_debug("port %d is non-removable\n",port);
     354                        usb_port_status_t status;
     355                        size_t rcvd_size;
     356                        usb_device_request_setup_packet_t request;
     357                        //int opResult;
     358                        usb_hub_set_port_status_request(&request, port);
     359                        //endpoint 0
     360                        opResult = usb_pipe_control_read(
     361                                        hub->control_pipe,
     362                                        &request, sizeof(usb_device_request_setup_packet_t),
     363                                        &status, 4, &rcvd_size
     364                                        );
     365                        if (opResult != EOK) {
     366                                usb_log_error("could not get port status %d\n",opResult);
     367                        }
     368                        if (rcvd_size != sizeof (usb_port_status_t)) {
     369                                usb_log_error("received status has incorrect size\n");
     370                        }
     371                        //something connected/disconnected
     372                        if (usb_port_connect_change(&status)) {
     373                                usb_log_debug("some connection changed\n");
     374                        }
     375                        usb_log_debug("status: %s\n",usb_debug_str_buffer(
     376                                        (uint8_t *)&status,4,4));
    332377                }
    333378        }
     
    582627        //something connected/disconnected
    583628        if (usb_port_connect_change(&status)) {
     629                usb_log_debug("connection change on port\n");
    584630                if (usb_port_dev_connected(&status)) {
    585631                        usb_log_debug("some connection changed\n");
     
    592638        if (usb_port_overcurrent_change(&status)) {
    593639                //check if it was not auto-resolved
     640                usb_log_debug("overcurrent change on port\n");
    594641                if(usb_port_over_current(&status)){
    595642                        usb_hub_over_current(hub,port);
     
    608655                }
    609656        }
     657        usb_log_debug("status %x\n ",status);
    610658
    611659        usb_port_set_connect_change(&status, false);
  • uspace/drv/usbkbd/kbddev.c

    r0b4e7ca rc593b21  
    5656#include <usb/classes/hidreq.h>
    5757#include <usb/classes/hidreport.h>
     58#include <usb/classes/hid/utled.h>
    5859
    5960#include <usb/devdrv.h>
     
    6970static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
    7071
    71 /** Boot protocol report size (key part). */
    72 static const size_t BOOTP_REPORT_SIZE = 6;
    73 
    74 /** Boot protocol total report size. */
    75 static const size_t BOOTP_BUFFER_SIZE = 8;
    76 
    77 /** Boot protocol output report size. */
    78 static const size_t BOOTP_BUFFER_OUT_SIZE = 1;
    79 
    80 /** Boot protocol error key code. */
    81 static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
     72///** Boot protocol report size (key part). */
     73//static const size_t BOOTP_REPORT_SIZE = 6;
     74
     75///** Boot protocol total report size. */
     76//static const size_t BOOTP_BUFFER_SIZE = 8;
     77
     78///** Boot protocol output report size. */
     79//static const size_t BOOTP_BUFFER_OUT_SIZE = 1;
     80
     81///** Boot protocol error key code. */
     82//static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
     83static const uint8_t ERROR_ROLLOVER = 1;
    8284
    8385/** Default idle rate for keyboards. */
     
    263265static void usb_kbd_set_led(usb_kbd_t *kbd_dev)
    264266{
    265         uint8_t buffer[BOOTP_BUFFER_OUT_SIZE];
    266         int rc= 0;
    267        
    268         memset(buffer, 0, BOOTP_BUFFER_OUT_SIZE);
    269         uint8_t leds = 0;
    270 
    271         if (kbd_dev->mods & KM_NUM_LOCK) {
    272                 leds |= USB_HID_LED_NUM_LOCK;
    273         }
    274        
    275         if (kbd_dev->mods & KM_CAPS_LOCK) {
    276                 leds |= USB_HID_LED_CAPS_LOCK;
    277         }
    278        
    279         if (kbd_dev->mods & KM_SCROLL_LOCK) {
    280                 leds |= USB_HID_LED_SCROLL_LOCK;
     267        unsigned i = 0;
     268       
     269        /* Reset the LED data. */
     270        memset(kbd_dev->led_data, 0, kbd_dev->led_output_size * sizeof(int32_t));
     271       
     272        if ((kbd_dev->mods & KM_NUM_LOCK) && (i < kbd_dev->led_output_size)) {
     273                kbd_dev->led_data[i++] = USB_HID_LED_NUM_LOCK;
     274        }
     275       
     276        if ((kbd_dev->mods & KM_CAPS_LOCK) && (i < kbd_dev->led_output_size)) {
     277                kbd_dev->led_data[i++] = USB_HID_LED_CAPS_LOCK;
     278        }
     279       
     280        if ((kbd_dev->mods & KM_SCROLL_LOCK)
     281            && (i < kbd_dev->led_output_size)) {
     282                kbd_dev->led_data[i++] = USB_HID_LED_SCROLL_LOCK;
    281283        }
    282284
     
    284286       
    285287        usb_log_debug("Creating output report.\n");
    286         usb_log_debug("Leds: 0x%x\n", leds);
    287         if ((rc = usb_hid_boot_keyboard_output_report(
    288             leds, buffer, BOOTP_BUFFER_OUT_SIZE)) != EOK) {
    289                 usb_log_warning("Error composing output report to the keyboard:"
    290                     "%s.\n", str_error(rc));
     288       
     289        int rc = usb_hid_report_output_translate(kbd_dev->parser,
     290            kbd_dev->led_path, USB_HID_PATH_COMPARE_END, kbd_dev->output_buffer,
     291            kbd_dev->output_size, kbd_dev->led_data, kbd_dev->led_output_size);
     292       
     293        if (rc != EOK) {
     294                usb_log_warning("Error translating LED output to output report"
     295                    ".\n");
    291296                return;
    292297        }
    293298       
    294299        usb_log_debug("Output report buffer: %s\n",
    295             usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0));
    296        
    297         assert(kbd_dev->usb_dev != NULL);
     300            usb_debug_str_buffer(kbd_dev->output_buffer, kbd_dev->output_size,
     301                0));
    298302       
    299303        usbhid_req_set_report(&kbd_dev->usb_dev->ctrl_pipe,
    300304            kbd_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT,
    301             buffer, BOOTP_BUFFER_OUT_SIZE);
     305            kbd_dev->output_buffer, kbd_dev->output_size);
    302306}
    303307
     
    450454         * First of all, check if the kbd have reported phantom state.
    451455         *
    452          *  this must be changed as we don't know which keys are modifiers
    453          *       and which are regular keys.
     456         * As there is no way to distinguish keys from modifiers, we do not have
     457         * a way to check that 'all keys report Error Rollover'. We thus check
     458         * if there is at least one such error and in such case we ignore the
     459         * whole input report.
    454460         */
    455461        i = 0;
    456         // all fields should report Error Rollover
    457         while (i < count &&
    458             key_codes[i] == BOOTP_ERROR_ROLLOVER) {
     462        while (i < count && key_codes[i] != ERROR_ROLLOVER) {
    459463                ++i;
    460464        }
    461         if (i == count) {
     465        if (i != count) {
    462466                usb_log_debug("Phantom state occured.\n");
    463467                // phantom state, do nothing
     
    586590 */
    587591static void usb_kbd_process_data(usb_kbd_t *kbd_dev,
    588                                     uint8_t *buffer, size_t actual_size)
     592                                 uint8_t *buffer, size_t actual_size)
    589593{
    590594        assert(kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED);
     
    760764        usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
    761765       
    762         kbd_dev->keys = (uint8_t *)calloc(
    763             kbd_dev->key_count, sizeof(uint8_t));
     766        kbd_dev->keys = (uint8_t *)calloc(kbd_dev->key_count, sizeof(uint8_t));
    764767       
    765768        if (kbd_dev->keys == NULL) {
     
    768771        }
    769772       
     773        /*
     774         * Output report
     775         */
     776        kbd_dev->output_size = 0;
     777        kbd_dev->output_buffer = usb_hid_report_output(kbd_dev->parser,
     778            &kbd_dev->output_size);
     779        if (kbd_dev->output_buffer == NULL) {
     780                usb_log_warning("Error creating output report buffer.\n");
     781                free(kbd_dev->keys);
     782                return ENOMEM;  /* TODO: other error code */
     783        }
     784       
     785        usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size);
     786       
     787        kbd_dev->led_path = usb_hid_report_path();
     788        usb_hid_report_path_append_item(
     789            kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
     790       
     791        kbd_dev->led_output_size = usb_hid_report_output_size(kbd_dev->parser,
     792            kbd_dev->led_path, USB_HID_PATH_COMPARE_END);
     793       
     794        usb_log_debug("Output report size (in items): %zu\n",
     795            kbd_dev->led_output_size);
     796       
     797        kbd_dev->led_data = (int32_t *)calloc(
     798            kbd_dev->led_output_size, sizeof(int32_t));
     799       
     800        if (kbd_dev->led_data == NULL) {
     801                usb_log_warning("Error creating buffer for LED output report."
     802                    "\n");
     803                free(kbd_dev->keys);
     804                usb_hid_report_output_free(kbd_dev->output_buffer);
     805                return ENOMEM;
     806        }
     807       
     808        /*
     809         * Modifiers and locks
     810         */     
    770811        kbd_dev->modifiers = 0;
    771812        kbd_dev->mods = DEFAULT_ACTIVE_MODS;
    772813        kbd_dev->lock_keys = 0;
    773814       
     815        /*
     816         * Autorepeat
     817         */     
    774818        kbd_dev->repeat.key_new = 0;
    775819        kbd_dev->repeat.key_repeated = 0;
     
    879923        }
    880924       
     925        // free the output buffer
     926        usb_hid_report_output_free((*kbd_dev)->output_buffer);
     927       
    881928        /* TODO: what about the USB device structure?? */
    882929
  • uspace/drv/usbkbd/kbddev.h

    r0b4e7ca rc593b21  
    9494        /** Report descriptor size. */
    9595        size_t report_desc_size;
     96       
     97        uint8_t *output_buffer;
     98       
     99        size_t output_size;
     100       
     101        size_t led_output_size;
     102       
     103        usb_hid_report_path_t *led_path;
     104       
     105        int32_t *led_data;
    96106
    97107        /** HID Report parser. */
  • uspace/lib/c/Makefile

    r0b4e7ca rc593b21  
    7777        generic/io/io.c \
    7878        generic/io/printf.c \
     79        generic/io/log.c \
    7980        generic/io/klog.c \
    8081        generic/io/snprintf.c \
  • uspace/lib/c/generic/adt/hash_table.c

    r0b4e7ca rc593b21  
    5454 *
    5555 */
    56 int hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys,
     56bool hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys,
    5757    hash_table_operations_t *op)
    5858{
  • uspace/lib/c/generic/devman.c

    r0b4e7ca rc593b21  
    147147                ret = devman_send_match_id(phone, match_id);
    148148                if (ret != EOK) {
    149                         printf("Driver failed to send match id, error %d\n",
    150                             ret);
    151149                        return ret;
    152150                }
     
    195193        }
    196194       
    197         devman_send_match_ids(phone, match_ids);
    198        
    199         async_wait_for(req, &retval);
    200        
    201         async_serialize_end();
    202        
     195        int match_ids_rc = devman_send_match_ids(phone, match_ids);
     196       
     197        async_wait_for(req, &retval);
     198       
     199        async_serialize_end();
     200       
     201        /* Prefer the answer to DEVMAN_ADD_FUNCTION in case of errors. */
     202        if ((match_ids_rc != EOK) && (retval == EOK)) {
     203                retval = match_ids_rc;
     204        }
     205
    203206        if (retval == EOK)
    204207                fun_handle = (int) IPC_GET_ARG1(answer);
     
    326329}
    327330
     331int devman_device_get_handle_by_class(const char *classname,
     332    const char *devname, devman_handle_t *handle, unsigned int flags)
     333{
     334        int phone = devman_get_phone(DEVMAN_CLIENT, flags);
     335
     336        if (phone < 0)
     337                return phone;
     338
     339        async_serialize_start();
     340
     341        ipc_call_t answer;
     342        aid_t req = async_send_1(phone, DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,
     343            flags, &answer);
     344
     345        sysarg_t retval = async_data_write_start(phone, classname,
     346            str_size(classname));
     347        if (retval != EOK) {
     348                async_wait_for(req, NULL);
     349                async_serialize_end();
     350                return retval;
     351        }
     352        retval = async_data_write_start(phone, devname,
     353            str_size(devname));
     354        if (retval != EOK) {
     355                async_wait_for(req, NULL);
     356                async_serialize_end();
     357                return retval;
     358        }
     359
     360        async_wait_for(req, &retval);
     361
     362        async_serialize_end();
     363
     364        if (retval != EOK) {
     365                if (handle != NULL)
     366                        *handle = (devman_handle_t) -1;
     367                return retval;
     368        }
     369
     370        if (handle != NULL)
     371                *handle = (devman_handle_t) IPC_GET_ARG1(answer);
     372
     373        return retval;
     374}
     375
    328376
    329377/** @}
  • uspace/lib/c/include/adt/hash_table.h

    r0b4e7ca rc593b21  
    3838#include <adt/list.h>
    3939#include <unistd.h>
     40#include <bool.h>
    4041
    4142typedef unsigned long hash_count_t;
     
    8384    list_get_instance((item), type, member)
    8485
    85 extern int hash_table_create(hash_table_t *, hash_count_t, hash_count_t,
     86extern bool hash_table_create(hash_table_t *, hash_count_t, hash_count_t,
    8687    hash_table_operations_t *);
    8788extern void hash_table_insert(hash_table_t *, unsigned long [], link_t *);
  • uspace/lib/c/include/devman.h

    r0b4e7ca rc593b21  
    5353extern int devman_device_get_handle(const char *, devman_handle_t *,
    5454    unsigned int);
     55extern int devman_device_get_handle_by_class(const char *, const char *,
     56    devman_handle_t *, unsigned int);
    5557
    5658extern int devman_add_device_to_class(devman_handle_t, const char *);
  • uspace/lib/c/include/ipc/devman.h

    r0b4e7ca rc593b21  
    148148
    149149typedef enum {
    150         DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD
     150        DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
     151        DEVMAN_DEVICE_GET_HANDLE_BY_CLASS
    151152} client_to_devman_t;
    152153
  • uspace/lib/drv/Makefile

    r0b4e7ca rc593b21  
    3636        generic/dev_iface.c \
    3737        generic/remote_char_dev.c \
     38        generic/log.c \
    3839        generic/remote_hw_res.c \
    3940        generic/remote_usb.c \
  • uspace/lib/drv/generic/driver.c

    r0b4e7ca rc593b21  
    273273       
    274274        res = driver->driver_ops->add_device(dev);
    275         if (res == EOK) {
    276                 printf("%s: new device with handle=%" PRIun " was added.\n",
    277                     driver->name, dev_handle);
    278         } else {
    279                 printf("%s: failed to add a new device with handle = %" PRIun ".\n",
    280                     driver->name, dev_handle);
     275        if (res != EOK)
    281276                delete_device(dev);
    282         }
    283277       
    284278        async_answer_0(iid, res);
  • uspace/lib/usb/Makefile

    r0b4e7ca rc593b21  
    5353        src/hidreport.c \
    5454        src/host/device_keeper.c \
    55         src/host/batch.c
     55        src/host/batch.c \
     56        src/host/bandwidth.c
    5657
    5758include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/usb/include/usb/classes/hidparser.h

    r0b4e7ca rc593b21  
    3131 */
    3232/** @file
    33  * @brief USB HID parser.
     33 * USB HID report descriptor and report data parser
    3434 */
    3535#ifndef LIBUSB_HIDPARSER_H_
     
    7474#define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY    4
    7575
     76/** */
    7677typedef struct {
     78        /** */
    7779        int32_t usage_page;
     80        /** */ 
    7881        int32_t usage;
    79 
     82        /** */
    8083        link_t link;
    8184} usb_hid_report_usage_path_t;
    8285
     86/** */
    8387typedef struct {
     88        /** */ 
    8489        int depth;     
     90       
     91        /** */ 
    8592        link_t link;
    8693} usb_hid_report_path_t;
     
    9097 */
    9198typedef struct {
     99        /** */ 
    92100        int32_t id;
     101        /** */ 
    93102        int32_t usage_minimum;
     103        /** */ 
    94104        int32_t usage_maximum;
     105        /** */ 
    95106        int32_t logical_minimum;
     107        /** */ 
    96108        int32_t logical_maximum;
     109        /** */ 
    97110        int32_t size;
     111        /** */ 
    98112        int32_t count;
     113        /** */ 
    99114        size_t offset;
     115        /** */ 
    100116        int32_t delimiter;
    101 
     117        /** */ 
    102118        int32_t unit_exponent;
     119        /** */ 
    103120        int32_t unit;
    104121
    105         /*
    106          * some not yet used fields
    107          */
     122        /** */
    108123        int32_t string_index;
     124        /** */ 
    109125        int32_t string_minimum;
     126        /** */ 
    110127        int32_t string_maximum;
     128        /** */ 
    111129        int32_t designator_index;
     130        /** */ 
    112131        int32_t designator_minimum;
     132        /** */ 
    113133        int32_t designator_maximum;
     134        /** */ 
    114135        int32_t physical_minimum;
     136        /** */ 
    115137        int32_t physical_maximum;
    116138
     139        /** */ 
    117140        uint8_t item_flags;
    118141
     142        /** */ 
    119143        usb_hid_report_path_t *usage_path;
     144        /** */ 
    120145        link_t link;
    121146} usb_hid_report_item_t;
     
    124149/** HID report parser structure. */
    125150typedef struct {       
     151        /** */ 
    126152        link_t input;
     153        /** */ 
    127154        link_t output;
     155        /** */ 
    128156        link_t feature;
    129157} usb_hid_report_parser_t;     
     
    154182} usb_hid_modifiers_t;
    155183
    156 typedef enum {
    157         USB_HID_LED_NUM_LOCK = 0x1,
    158         USB_HID_LED_CAPS_LOCK = 0x2,
    159         USB_HID_LED_SCROLL_LOCK = 0x4,
    160         USB_HID_LED_COMPOSE = 0x8,
    161         USB_HID_LED_KANA = 0x10,
    162         USB_HID_LED_COUNT = 5
    163 } usb_hid_led_t;
     184//typedef enum {
     185//      USB_HID_LED_NUM_LOCK = 0x1,
     186//      USB_HID_LED_CAPS_LOCK = 0x2,
     187//      USB_HID_LED_SCROLL_LOCK = 0x4,
     188//      USB_HID_LED_COMPOSE = 0x8,
     189//      USB_HID_LED_KANA = 0x10,
     190//      USB_HID_LED_COUNT = 5
     191//} usb_hid_led_t;
    164192
    165193static const usb_hid_modifiers_t
     
    190218
    191219/*
    192  * modifiers definitions
    193  */
    194 
     220 * Descriptor parser functions
     221 */
     222/** */
     223int usb_hid_parser_init(usb_hid_report_parser_t *parser);
     224
     225/** */
     226int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser,
     227    const uint8_t *data, size_t size);
     228
     229/** */
     230void usb_hid_free_report_parser(usb_hid_report_parser_t *parser);
     231
     232/** */
     233void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
     234
     235/*
     236 * Boot protocol functions
     237 */
     238/** */
    195239int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
    196240        const usb_hid_report_in_callbacks_t *callbacks, void *arg);
    197241
     242/** */
    198243int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);
    199244
    200 int usb_hid_parser_init(usb_hid_report_parser_t *parser);
    201 int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser,
    202     const uint8_t *data, size_t size);
    203 
     245
     246/*
     247 * Input report parser functions
     248 */
     249/** */
    204250int usb_hid_parse_report(const usb_hid_report_parser_t *parser, 
    205251    const uint8_t *data, size_t size,
     
    207253    const usb_hid_report_in_callbacks_t *callbacks, void *arg);
    208254
    209 int usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
     255/** */
     256size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
    210257        usb_hid_report_path_t *path, int flags);
    211258
    212259
    213 void usb_hid_free_report_parser(usb_hid_report_parser_t *parser);
    214 
    215 void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
    216 
    217 /* usage path functions */
     260
     261/*
     262 * usage path functions
     263 */
     264/** */
    218265usb_hid_report_path_t *usb_hid_report_path(void);
     266
     267/** */
    219268void usb_hid_report_path_free(usb_hid_report_path_t *path);
     269
     270/** */
    220271int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, int32_t usage_page, int32_t usage);
     272
     273/** */
    221274void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path);
     275
     276/** */
    222277void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path);
     278
     279/** */
    223280void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data);
     281
     282/** */
    224283int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, usb_hid_report_path_t *path, int flags);
    225 int     usb_hid_report_path_clone(usb_hid_report_path_t *new_usage_path, usb_hid_report_path_t *usage_path);
    226 
    227 
    228 // output
    229 //      - funkce co vrati cesty poli v output reportu
    230 //      - funkce co pro danou cestu nastavi data
    231 //      - finalize
    232 
     284
     285/** */
     286usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path);
     287
     288
     289/*
     290 * Output report parser functions
     291 */
     292/** Allocates output report buffer*/
     293uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser, size_t *size);
     294
     295/** Frees output report buffer*/
     296void usb_hid_report_output_free(uint8_t *output);
     297
     298/** Returns size of output for given usage path */
     299size_t usb_hid_report_output_size(usb_hid_report_parser_t *parser,
     300                                  usb_hid_report_path_t *path, int flags);
     301
     302/** Updates the output report buffer by translated given data */
     303int usb_hid_report_output_translate(usb_hid_report_parser_t *parser,
     304                                    usb_hid_report_path_t *path, int flags,
     305                                    uint8_t *buffer, size_t size,
     306                                    int32_t *data, size_t data_size);
    233307#endif
    234308/**
  • uspace/lib/usb/include/usb/host/device_keeper.h

    r0b4e7ca rc593b21  
    5151        usb_speed_t speed;
    5252        bool occupied;
    53         bool control_used;
     53        uint16_t control_used;
    5454        uint16_t toggle_status[2];
    5555        devman_handle_t handle;
     
    9999
    100100void usb_device_keeper_use_control(usb_device_keeper_t *instance,
    101     usb_address_t address);
     101    usb_target_t target);
    102102
    103103void usb_device_keeper_release_control(usb_device_keeper_t *instance,
    104     usb_address_t address);
     104    usb_target_t target);
    105105
    106106#endif
  • uspace/lib/usb/src/devdrv.c

    r0b4e7ca rc593b21  
    262262            &dev->descriptors.configuration_size);
    263263        if (rc != EOK) {
    264                 usb_log_error("Failed retrieving configuration descriptor: %s.\n",
     264                usb_log_error("Failed retrieving configuration descriptor: %s. %s\n",
    265265                    dev->ddf_dev->name, str_error(rc));
    266266                return rc;
  • uspace/lib/usb/src/hidparser.c

    r0b4e7ca rc593b21  
    3131 */
    3232/** @file
    33  * @brief HID parser implementation.
     33 * HID report descriptor and report data parser implementation.
    3434 */
    3535#include <usb/classes/hidparser.h>
     
    4040#include <usb/debug.h>
    4141
     42/** */
    4243#define USB_HID_NEW_REPORT_ITEM 1
     44
     45/** */
    4346#define USB_HID_NO_ACTION               2
     47
     48/** */
    4449#define USB_HID_UNKNOWN_TAG             -99
    4550
    46 #define BAD_HACK_USAGE_PAGE             0x07
    47 
     51/*
     52 * Private descriptor parser functions
     53 */
    4854int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
    4955                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
     
    5864int usb_hid_report_reset_local_items();
    5965void usb_hid_free_report_list(link_t *head);
     66
     67/*
     68 * Data translation private functions
     69 */
    6070int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size);
    6171inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset);
    6272int usb_hid_translate_data(usb_hid_report_item_t *item, const uint8_t *data, size_t j);
     73int32_t usb_hid_translate_data_reverse(usb_hid_report_item_t *item, int32_t value);
    6374int usb_pow(int a, int b);
    6475
    65 
     76// TODO: tohle ma bejt asi jinde
    6677int usb_pow(int a, int b)
    6778{
     
    8091
    8192/**
    82  *
     93 * Initialize the report descriptor parser structure
     94 *
     95 * @param parser Report descriptor parser structure
     96 * @return Error code
    8397 */
    8498int usb_hid_parser_init(usb_hid_report_parser_t *parser)
    8599{
    86    if(parser == NULL) {
    87         return EINVAL;
    88    }
    89 
    90     list_initialize(&(parser->input));
     100        if(parser == NULL) {
     101                return EINVAL;
     102        }
     103
     104        list_initialize(&(parser->input));
    91105    list_initialize(&(parser->output));
    92106    list_initialize(&(parser->feature));
     
    164178                                        // store current usage path
    165179                                        report_item->usage_path = usage_path;
    166 
    167                                         // new current usage path
    168                                         tmp_usage_path = usb_hid_report_path();
    169180                                       
    170                                         // copy old path to the new one
    171                                         usb_hid_report_path_clone(tmp_usage_path, usage_path);
     181                                        // clone path to the new one
     182                                        tmp_usage_path = usb_hid_report_path_clone(usage_path);
    172183
    173184                                        // swap
     
    304315
    305316/**
     317 * Parse one tag of the report descriptor
    306318 *
    307319 * @param Tag to parse
     
    391403 * @return Error code
    392404 */
    393 
    394405int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    395406                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
     
    520531 * Prints content of given list of report items.
    521532 *
    522  * @param List of report items
     533 * @param List of report items (usb_hid_report_item_t)
    523534 * @return void
    524535 */
     
    552563                        path = path->next;
    553564                }
    554                
    555                
    556 //              usb_log_debug("\tUSAGE: %X\n", report_item->usage);
    557 //              usb_log_debug("\tUSAGE PAGE: %X\n", report_item->usage_page);
     565                               
    558566                usb_log_debug("\tLOGMIN: %X\n", report_item->logical_minimum);
    559567                usb_log_debug("\tLOGMAX: %X\n", report_item->logical_maximum);         
     
    570578}
    571579/**
    572  * Prints content of given descriptor in human readable format.
    573  *
    574  * @param Parsed descriptor to print
     580 * Prints content of given report descriptor in human readable format.
     581 *
     582 * @param parser Parsed descriptor to print
    575583 * @return void
    576584 */
     
    595603 * Releases whole linked list of report items
    596604 *
    597  *
     605 * @param head Head of list of report descriptor items (usb_hid_report_item_t)
     606 * @return void
    598607 */
    599608void usb_hid_free_report_list(link_t *head)
     
    627636}
    628637
    629 /** Free the HID report parser structure
     638/** Frees the HID report descriptor parser structure
    630639 *
    631640 * @param parser Opaque HID report parser structure
    632  * @return Error code
     641 * @return void
    633642 */
    634643void usb_hid_free_report_parser(usb_hid_report_parser_t *parser)
     
    660669    const usb_hid_report_in_callbacks_t *callbacks, void *arg)
    661670{
    662         /*
    663          *
    664          * only key codes (usage page 0x07) will be processed
    665          * other usages will be ignored
    666          */
    667671        link_t *list_item;
    668672        usb_hid_report_item_t *item;
     
    676680                return EINVAL;
    677681        }
    678 
    679        
    680         // get the size of result keycodes array
     682       
     683        /* get the size of result array */
    681684        key_count = usb_hid_report_input_length(parser, path, flags);
    682685
     
    685688        }
    686689
    687         // read data           
     690        /* read data */
    688691        list_item = parser->input.next;   
    689692        while(list_item != &(parser->input)) {
     
    719722}
    720723
    721 
     724/**
     725 * Translate data from the report as specified in report descriptor
     726 *
     727 * @param item Report descriptor item with definition of translation
     728 * @param data Data to translate
     729 * @param j Index of processed field in report descriptor item
     730 * @return Translated data
     731 */
    722732int usb_hid_translate_data(usb_hid_report_item_t *item, const uint8_t *data, size_t j)
    723733{
     
    796806}
    797807
    798 int usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
     808/**
     809 *
     810 *
     811 * @param parser
     812 * @param path
     813 * @param flags
     814 * @return
     815 */
     816size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
    799817        usb_hid_report_path_t *path, int flags)
    800818{       
    801         int ret = 0;
     819        size_t ret = 0;
    802820        link_t *item;
    803821        usb_hid_report_item_t *report_item;
    804822
    805823        if(parser == NULL) {
    806                 return EINVAL;
    807         }
    808        
    809         item = (&parser->input)->next;
     824                return 0;
     825        }
     826       
     827        item = parser->input.next;
    810828        while(&parser->input != item) {
    811829                report_item = list_get_instance(item, usb_hid_report_item_t, link);
     
    824842/**
    825843 *
     844 * @param usage_path
     845 * @param usage_page
     846 * @param usage
     847 * @return
    826848 */
    827849int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path,
     
    845867/**
    846868 *
     869 * @param usage_path
     870 * @return
    847871 */
    848872void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path)
     
    860884/**
    861885 *
     886 * @param usage_path
     887 * @return
    862888 */
    863889void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path)
     
    873899/**
    874900 *
     901 * @param usage_path
     902 * @param tag
     903 * @param data
     904 * @return
    875905 */
    876906void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data)
     
    894924
    895925/**
    896  *
     926 *
     927 *
     928 * @param report_path
     929 * @param path
     930 * @param flags
     931 * @return
    897932 */
    898933int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path,
     
    949984                        break;
    950985
    951                 /* given path must be the end of the report one*/
     986                /* compare with only the end of path*/
    952987                case USB_HID_PATH_COMPARE_END:
    953988                                report_link = report_path->link.prev;
     
    9921027/**
    9931028 *
     1029 * @return
    9941030 */
    9951031usb_hid_report_path_t *usb_hid_report_path(void)
     
    10091045/**
    10101046 *
     1047 * @param path
     1048 * @return void
    10111049 */
    10121050void usb_hid_report_path_free(usb_hid_report_path_t *path)
     
    10191057
    10201058/**
    1021  *
    1022  */
    1023 int     usb_hid_report_path_clone(usb_hid_report_path_t *new_usage_path, usb_hid_report_path_t *usage_path)
     1059 * Clone content of given usage path to the new one
     1060 *
     1061 * @param usage_path
     1062 * @return
     1063 */
     1064usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path)
    10241065{
    10251066        usb_hid_report_usage_path_t *path_item;
    10261067        link_t *path_link;
    1027 
     1068        usb_hid_report_path_t *new_usage_path = usb_hid_report_path ();
     1069
     1070        if(new_usage_path == NULL){
     1071                return NULL;
     1072        }
    10281073       
    10291074        if(list_empty(&usage_path->link)){
    1030                 return EOK;
     1075                return new_usage_path;
    10311076        }
    10321077
     
    10391084        }
    10401085
     1086        return new_usage_path;
     1087}
     1088
     1089
     1090/*** OUTPUT API **/
     1091
     1092/** Allocates output report buffer
     1093 *
     1094 * @param parser
     1095 * @param size
     1096 * @return
     1097 */
     1098uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser, size_t *size)
     1099{
     1100        if(parser == NULL) {
     1101                *size = 0;
     1102                return NULL;
     1103        }
     1104       
     1105        // read the last output report item
     1106        usb_hid_report_item_t *last;
     1107        link_t *link;
     1108
     1109        link = parser->output.prev;
     1110        if(link != &parser->output) {
     1111                last = list_get_instance(link, usb_hid_report_item_t, link);
     1112                *size = (last->offset + (last->size * last->count)) / 8;
     1113
     1114                uint8_t *buffer = malloc(sizeof(uint8_t) * (*size));
     1115                memset(buffer, 0, sizeof(uint8_t) * (*size));
     1116                usb_log_debug("output buffer: %s\n", usb_debug_str_buffer(buffer, *size, 0));
     1117
     1118                return buffer;
     1119        }
     1120        else {
     1121                *size = 0;             
     1122                return NULL;
     1123        }
     1124}
     1125
     1126
     1127/** Frees output report buffer
     1128 *
     1129 * @param output Output report buffer
     1130 * @return
     1131 */
     1132void usb_hid_report_output_free(uint8_t *output)
     1133
     1134{
     1135        if(output != NULL) {
     1136                free (output);
     1137        }
     1138}
     1139
     1140/** Returns size of output for given usage path
     1141 *
     1142 * @param parser
     1143 * @param path
     1144 * @param flags
     1145 * @return
     1146 */
     1147size_t usb_hid_report_output_size(usb_hid_report_parser_t *parser,
     1148                                  usb_hid_report_path_t *path, int flags)
     1149{
     1150        size_t ret = 0;
     1151        link_t *item;
     1152        usb_hid_report_item_t *report_item;
     1153
     1154        if(parser == NULL) {
     1155                return 0;
     1156        }
     1157       
     1158        item = parser->output.next;
     1159        while(&parser->output != item) {
     1160                report_item = list_get_instance(item, usb_hid_report_item_t, link);
     1161                if(!USB_HID_ITEM_FLAG_CONSTANT(report_item->item_flags) &&
     1162                   (usb_hid_report_compare_usage_path(report_item->usage_path, path, flags) == EOK)) {
     1163                        ret += report_item->count;
     1164                }
     1165
     1166                item = item->next;
     1167        }
     1168
     1169        return ret;
     1170       
     1171}
     1172
     1173/** Updates the output report buffer by translated given data
     1174 *
     1175 * @param parser
     1176 * @param path
     1177 * @param flags
     1178 * @param buffer
     1179 * @param size
     1180 * @param data
     1181 * @param data_size
     1182 * @return
     1183 */
     1184int usb_hid_report_output_translate(usb_hid_report_parser_t *parser,
     1185                                    usb_hid_report_path_t *path, int flags,
     1186                                    uint8_t *buffer, size_t size,
     1187                                    int32_t *data, size_t data_size)
     1188{
     1189        usb_hid_report_item_t *report_item;
     1190        link_t *item;   
     1191        size_t idx=0;
     1192        int i=0;
     1193        int32_t value=0;
     1194        int offset;
     1195        int length;
     1196        int32_t tmp_value;
     1197       
     1198        if(parser == NULL) {
     1199                return EINVAL;
     1200        }
     1201
     1202        usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
     1203        usb_log_debug("OUTPUT DATA[0]: %d, DATA[1]: %d, DATA[2]: %d\n", data[0], data[1], data[2]);
     1204
     1205        item = parser->output.next;     
     1206        while(item != &parser->output) {
     1207                report_item = list_get_instance(item, usb_hid_report_item_t, link);
     1208
     1209                for(i=0; i<report_item->count; i++) {
     1210
     1211                        if(idx >= data_size) {
     1212                                break;
     1213                        }
     1214
     1215                        if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) ||
     1216                                ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
     1217                                       
     1218//                              // variable item
     1219                                value = usb_hid_translate_data_reverse(report_item, data[idx++]);
     1220                                offset = report_item->offset + (i * report_item->size);
     1221                                length = report_item->size;
     1222                        }
     1223                        else {
     1224                                //bitmap
     1225                                value += usb_hid_translate_data_reverse(report_item, data[idx++]);
     1226                                offset = report_item->offset;
     1227                                length = report_item->size * report_item->count;
     1228                        }
     1229
     1230                        if((offset/8) == ((offset+length-1)/8)) {
     1231                                // je to v jednom bytu
     1232                                if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) {
     1233                                        break; // TODO ErrorCode
     1234                                }
     1235
     1236                                size_t shift = offset%8;
     1237
     1238                                value = value << shift;                                                 
     1239                                value = value & (((1 << length)-1) << shift);
     1240                               
     1241                                uint8_t mask = 0;
     1242                                mask = 0xff - (((1 << length) - 1) << shift);
     1243                                buffer[offset/8] = (buffer[offset/8] & mask) | value;
     1244                        }
     1245                        else {
     1246                                // je to ve dvou!! FIXME: melo by to umet delsi jak 2
     1247
     1248                                // konec prvniho -- dolni x bitu
     1249                                tmp_value = value;
     1250                                tmp_value = tmp_value & ((1 << (8-(offset%8)))-1);                             
     1251                                tmp_value = tmp_value << (offset%8);
     1252
     1253                                uint8_t mask = 0;
     1254                                mask = ~(((1 << (8-(offset%8)))-1) << (offset%8));
     1255                                buffer[offset/8] = (buffer[offset/8] & mask) | tmp_value;
     1256
     1257                                // a ted druhej -- hornich length-x bitu
     1258                                value = value >> (8 - (offset % 8));
     1259                                value = value & ((1 << (length - (8 - (offset % 8)))) - 1);
     1260                               
     1261                                mask = ((1 << (length - (8 - (offset % 8)))) - 1);
     1262                                buffer[(offset+length-1)/8] = (buffer[(offset+length-1)/8] & mask) | value;
     1263                        }
     1264
     1265                }
     1266
     1267                item = item->next;
     1268        }
     1269
     1270        usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
     1271
    10411272        return EOK;
    10421273}
    10431274
     1275/**
     1276 *
     1277 * @param item
     1278 * @param value
     1279 * @return
     1280 */
     1281int32_t usb_hid_translate_data_reverse(usb_hid_report_item_t *item, int value)
     1282{
     1283        int ret=0;
     1284        int resolution;
     1285
     1286        if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags)) {
     1287                ret = item->logical_minimum;
     1288        }
     1289
     1290        if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0)) {
     1291
     1292                // variable item
     1293                if((item->physical_minimum == 0) && (item->physical_maximum == 0)) {
     1294                        item->physical_minimum = item->logical_minimum;
     1295                        item->physical_maximum = item->logical_maximum;
     1296                }
     1297
     1298                if(item->physical_maximum == item->physical_minimum){
     1299                    resolution = 1;
     1300                }
     1301                else {
     1302                    resolution = (item->logical_maximum - item->logical_minimum) /
     1303                        ((item->physical_maximum - item->physical_minimum) *
     1304                        (usb_pow(10,(item->unit_exponent))));
     1305                }
     1306
     1307                ret = ((value - item->physical_minimum) * resolution) + item->logical_minimum;
     1308        }
     1309        else {
     1310                // bitmapa
     1311                if(value == 0) {
     1312                        ret = 0;
     1313                }
     1314                else {
     1315                        size_t bitmap_idx = (value - item->usage_minimum);
     1316                        ret = 1 << bitmap_idx;
     1317                }
     1318        }
     1319
     1320
     1321        return ret;
     1322}
     1323
    10441324
    10451325/**
  • uspace/lib/usb/src/host/device_keeper.c

    r0b4e7ca rc593b21  
    5454        for (; i < USB_ADDRESS_COUNT; ++i) {
    5555                instance->devices[i].occupied = false;
    56                 instance->devices[i].control_used = false;
     56                instance->devices[i].control_used = 0;
    5757                instance->devices[i].handle = 0;
    5858                instance->devices[i].toggle_status[0] = 0;
     
    311311/*----------------------------------------------------------------------------*/
    312312void usb_device_keeper_use_control(usb_device_keeper_t *instance,
    313     usb_address_t address)
    314 {
    315         assert(instance);
    316         fibril_mutex_lock(&instance->guard);
    317         while (instance->devices[address].control_used) {
     313    usb_target_t target)
     314{
     315        assert(instance);
     316        const uint16_t ep = 1 << target.endpoint;
     317        fibril_mutex_lock(&instance->guard);
     318        while (instance->devices[target.address].control_used & ep) {
    318319                fibril_condvar_wait(&instance->change, &instance->guard);
    319320        }
    320         instance->devices[address].control_used = true;
     321        instance->devices[target.address].control_used |= ep;
    321322        fibril_mutex_unlock(&instance->guard);
    322323}
    323324/*----------------------------------------------------------------------------*/
    324325void usb_device_keeper_release_control(usb_device_keeper_t *instance,
    325     usb_address_t address)
    326 {
    327         assert(instance);
    328         fibril_mutex_lock(&instance->guard);
    329         instance->devices[address].control_used = false;
     326    usb_target_t target)
     327{
     328        assert(instance);
     329        const uint16_t ep = 1 << target.endpoint;
     330        fibril_mutex_lock(&instance->guard);
     331        assert((instance->devices[target.address].control_used & ep) != 0);
     332        instance->devices[target.address].control_used &= ~ep;
    330333        fibril_mutex_unlock(&instance->guard);
    331334        fibril_condvar_signal(&instance->change);
  • uspace/lib/usb/src/request.c

    r0b4e7ca rc593b21  
    529529                return rc;
    530530        }
    531 
    532531        if (bare_config.descriptor_type != USB_DESCTYPE_CONFIGURATION) {
    533532                return ENOENT;
  • uspace/srv/devman/devman.c

    r0b4e7ca rc593b21  
    3434#include <fcntl.h>
    3535#include <sys/stat.h>
     36#include <io/log.h>
    3637#include <ipc/driver.h>
    3738#include <ipc/devman.h>
     
    146147        fibril_mutex_unlock(&drivers_list->drivers_mutex);
    147148
    148         printf(NAME": the '%s' driver was added to the list of available "
    149             "drivers.\n", drv->name);
    150 
    151         printf(NAME ": match ids:");
    152         link_t *cur;
    153         for (cur = drv->match_ids.ids.next; cur != &drv->match_ids.ids; cur = cur->next) {
    154                 match_id_t *match_id = list_get_instance(cur, match_id_t, link);
    155                 printf(" %d:%s", match_id->score, match_id->id);
    156         }
    157         printf("\n");
     149        log_msg(LVL_NOTE, "Driver `%s' was added to the list of available "
     150            "drivers.", drv->name);
    158151}
    159152
     
    245238bool read_match_ids(const char *conf_path, match_id_list_t *ids)
    246239{
    247         printf(NAME ": read_match_ids conf_path = %s.\n", conf_path);
     240        log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);
    248241       
    249242        bool suc = false;
     
    255248        fd = open(conf_path, O_RDONLY);
    256249        if (fd < 0) {
    257                 printf(NAME ": unable to open %s\n", conf_path);
     250                log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.",
     251                    conf_path, str_error(fd));
    258252                goto cleanup;
    259253        }
     
    263257        lseek(fd, 0, SEEK_SET);
    264258        if (len == 0) {
    265                 printf(NAME ": configuration file '%s' is empty.\n", conf_path);
     259                log_msg(LVL_ERROR, "Configuration file '%s' is empty.",
     260                    conf_path);
    266261                goto cleanup;
    267262        }
     
    269264        buf = malloc(len + 1);
    270265        if (buf == NULL) {
    271                 printf(NAME ": memory allocation failed when parsing file "
    272                     "'%s'.\n", conf_path);
     266                log_msg(LVL_ERROR, "Memory allocation failed when parsing file "
     267                    "'%s'.", conf_path);
    273268                goto cleanup;
    274269        }
     
    276271        ssize_t read_bytes = safe_read(fd, buf, len);
    277272        if (read_bytes <= 0) {
    278                 printf(NAME ": unable to read file '%s'.\n", conf_path);
     273                log_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
    279274                goto cleanup;
    280275        }
     
    314309bool get_driver_info(const char *base_path, const char *name, driver_t *drv)
    315310{
    316         printf(NAME ": get_driver_info base_path = %s, name = %s.\n",
     311        log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")",
    317312            base_path, name);
    318313       
     
    346341        struct stat s;
    347342        if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */
    348                 printf(NAME ": driver not found at path %s.", drv->binary_path);
     343                log_msg(LVL_ERROR, "Driver not found at path `%s'.",
     344                    drv->binary_path);
    349345                goto cleanup;
    350346        }
     
    373369int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path)
    374370{
    375         printf(NAME ": lookup_available_drivers, dir = %s \n", dir_path);
     371        log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path);
    376372       
    377373        int drv_cnt = 0;
     
    407403        dev_node_t *dev;
    408404       
    409         printf(NAME ": create_root_nodes\n");
     405        log_msg(LVL_DEBUG, "create_root_nodes()");
    410406       
    411407        fibril_rwlock_write_lock(&tree->rwlock);
     
    492488void attach_driver(dev_node_t *dev, driver_t *drv)
    493489{
    494         printf(NAME ": attach_driver %s to device %s\n",
    495             drv->name, dev->pfun->pathname);
     490        log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")",
     491            dev->pfun->pathname, drv->name);
    496492       
    497493        fibril_mutex_lock(&drv->driver_mutex);
     
    515511        assert(fibril_mutex_is_locked(&drv->driver_mutex));
    516512       
    517         printf(NAME ": start_driver '%s'\n", drv->name);
     513        log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);
    518514       
    519515        rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL);
    520516        if (rc != EOK) {
    521                 printf(NAME ": error spawning %s (%s)\n",
    522                     drv->name, str_error(rc));
     517                log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",
     518                    drv->name, drv->binary_path, str_error(rc));
    523519                return false;
    524520        }
     
    582578        int phone;
    583579
    584         printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name);
     580        log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")",
     581            driver->name);
    585582
    586583        fibril_mutex_lock(&driver->driver_mutex);
     
    649646         * immediately and possibly started here as well.
    650647         */
    651         printf(NAME ": driver %s goes into running state.\n", driver->name);
     648        log_msg(LVL_DEBUG, "Driver `%s' enters running state.", driver->name);
    652649        driver->state = DRIVER_RUNNING;
    653650
     
    666663void initialize_running_driver(driver_t *driver, dev_tree_t *tree)
    667664{
    668         printf(NAME ": initialize_running_driver (`%s')\n", driver->name);
     665        log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")",
     666            driver->name);
    669667       
    670668        /*
     
    756754         * access any structures that would affect driver_t.
    757755         */
    758         printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
    759             dev->pfun->name);
     756        log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")",
     757            drv->name, dev->pfun->name);
    760758       
    761759        sysarg_t rc;
     
    818816        driver_t *drv = find_best_match_driver(drivers_list, dev);
    819817        if (drv == NULL) {
    820                 printf(NAME ": no driver found for device '%s'.\n",
     818                log_msg(LVL_ERROR, "No driver found for device `%s'.",
    821819                    dev->pfun->pathname);
    822820                return false;
     
    856854bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list)
    857855{
    858         printf(NAME ": init_device_tree.\n");
     856        log_msg(LVL_DEBUG, "init_device_tree()");
    859857       
    860858        tree->current_handle = 0;
     
    10351033        fun->pathname = (char *) malloc(pathsize);
    10361034        if (fun->pathname == NULL) {
    1037                 printf(NAME ": failed to allocate device path.\n");
     1035                log_msg(LVL_ERROR, "Failed to allocate device path.");
    10381036                return false;
    10391037        }
     
    10661064        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    10671065       
     1066        log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])",
     1067            dev, pfun, pfun->pathname);
     1068
    10681069        /* Add the node to the handle-to-node map. */
    10691070        dev->handle = ++tree->current_handle;
     
    10721073
    10731074        /* Add the node to the list of its parent's children. */
    1074         printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);
    10751075        dev->pfun = pfun;
    10761076        pfun->child = dev;
     
    11731173}
    11741174
     1175/** Find function with a specified name belonging to given device.
     1176 *
     1177 * Device tree rwlock should be held at least for reading.
     1178 *
     1179 * @param dev Device the function belongs to.
     1180 * @param name Function name (not path).
     1181 * @return Function node.
     1182 * @retval NULL No function with given name.
     1183 */
     1184fun_node_t *find_fun_node_in_device(dev_node_t *dev, const char *name)
     1185{
     1186        assert(dev != NULL);
     1187        assert(name != NULL);
     1188
     1189        fun_node_t *fun;
     1190        link_t *link;
     1191
     1192        for (link = dev->functions.next;
     1193            link != &dev->functions;
     1194            link = link->next) {
     1195                fun = list_get_instance(link, fun_node_t, dev_functions);
     1196
     1197                if (str_cmp(name, fun->name) == 0)
     1198                        return fun;
     1199        }
     1200
     1201        return NULL;
     1202}
     1203
     1204/** Find function node by its class name and index. */
     1205fun_node_t *find_fun_node_by_class(class_list_t *class_list,
     1206    const char *class_name, const char *dev_name)
     1207{
     1208        assert(class_list != NULL);
     1209        assert(class_name != NULL);
     1210        assert(dev_name != NULL);
     1211
     1212        fibril_rwlock_read_lock(&class_list->rwlock);
     1213
     1214        dev_class_t *cl = find_dev_class_no_lock(class_list, class_name);
     1215        if (cl == NULL) {
     1216                fibril_rwlock_read_unlock(&class_list->rwlock);
     1217                return NULL;
     1218        }
     1219
     1220        dev_class_info_t *dev = find_dev_in_class(cl, dev_name);
     1221        if (dev == NULL) {
     1222                fibril_rwlock_read_unlock(&class_list->rwlock);
     1223                return NULL;
     1224        }
     1225
     1226        fun_node_t *fun = dev->fun;
     1227
     1228        fibril_rwlock_read_unlock(&class_list->rwlock);
     1229
     1230        return fun;
     1231}
     1232
     1233
    11751234/** Find child function node with a specified name.
    11761235 *
     
    11831242fun_node_t *find_node_child(fun_node_t *pfun, const char *name)
    11841243{
    1185         fun_node_t *fun;
    1186         link_t *link;
    1187        
    1188         link = pfun->child->functions.next;
    1189        
    1190         while (link != &pfun->child->functions) {
    1191                 fun = list_get_instance(link, fun_node_t, dev_functions);
    1192                
    1193                 if (str_cmp(name, fun->name) == 0)
    1194                         return fun;
    1195                
    1196                 link = link->next;
    1197         }
    1198        
    1199         return NULL;
     1244        return find_fun_node_in_device(pfun->child, name);
    12001245}
    12011246
     
    13591404}
    13601405
     1406dev_class_info_t *find_dev_in_class(dev_class_t *dev_class, const char *dev_name)
     1407{
     1408        assert(dev_class != NULL);
     1409        assert(dev_name != NULL);
     1410
     1411        link_t *link;
     1412        for (link = dev_class->devices.next;
     1413            link != &dev_class->devices;
     1414            link = link->next) {
     1415                dev_class_info_t *dev = list_get_instance(link,
     1416                    dev_class_info_t, link);
     1417
     1418                if (str_cmp(dev->dev_name, dev_name) == 0) {
     1419                        return dev;
     1420                }
     1421        }
     1422
     1423        return NULL;
     1424}
     1425
    13611426void init_class_list(class_list_t *class_list)
    13621427{
  • uspace/srv/devman/devman.h

    r0b4e7ca rc593b21  
    338338extern fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle);
    339339extern fun_node_t *find_fun_node_by_path(dev_tree_t *, char *);
     340extern fun_node_t *find_fun_node_in_device(dev_node_t *, const char *);
     341extern fun_node_t *find_fun_node_by_class(class_list_t *, const char *, const char *);
    340342
    341343/* Device tree */
     
    359361extern dev_class_t *get_dev_class(class_list_t *, char *);
    360362extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
     363extern dev_class_info_t *find_dev_in_class(dev_class_t *, const char *);
    361364extern void add_dev_class_no_lock(class_list_t *, dev_class_t *);
    362365
  • uspace/srv/devman/main.c

    r0b4e7ca rc593b21  
    4343#include <stdio.h>
    4444#include <errno.h>
     45#include <str_error.h>
    4546#include <bool.h>
    4647#include <fibril_synch.h>
     
    5152#include <sys/stat.h>
    5253#include <ctype.h>
     54#include <io/log.h>
    5355#include <ipc/devman.h>
    5456#include <ipc/driver.h>
     
    7173        driver_t *driver = NULL;
    7274
    73         printf(NAME ": devman_driver_register \n");
     75        log_msg(LVL_DEBUG, "devman_driver_register");
    7476       
    7577        iid = async_get_call(&icall);
     
    8890        }
    8991
    90         printf(NAME ": the %s driver is trying to register by the service.\n",
     92        log_msg(LVL_DEBUG, "The `%s' driver is trying to register.",
    9193            drv_name);
    9294       
     
    9597       
    9698        if (driver == NULL) {
    97                 printf(NAME ": no driver named %s was found.\n", drv_name);
     99                log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name);
    98100                free(drv_name);
    99101                drv_name = NULL;
     
    106108       
    107109        /* Create connection to the driver. */
    108         printf(NAME ":  creating connection to the %s driver.\n", driver->name);
     110        log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.",
     111            driver->name);
    109112        ipc_call_t call;
    110113        ipc_callid_t callid = async_get_call(&call);
     
    118121        set_driver_phone(driver, IPC_GET_ARG5(call));
    119122       
    120         printf(NAME ": the %s driver was successfully registered as running.\n",
     123        log_msg(LVL_NOTE,
     124            "The `%s' driver was successfully registered as running.",
    121125            driver->name);
    122126       
     
    142146        callid = async_get_call(&call);
    143147        if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) {
    144                 printf(NAME ": ERROR: devman_receive_match_id - invalid "
    145                     "protocol.\n");
     148                log_msg(LVL_ERROR,
     149                    "Invalid protocol when trying to receive match id.");
    146150                async_answer_0(callid, EINVAL);
    147151                delete_match_id(match_id);
     
    150154       
    151155        if (match_id == NULL) {
    152                 printf(NAME ": ERROR: devman_receive_match_id - failed to "
    153                     "allocate match id.\n");
     156                log_msg(LVL_ERROR, "Failed to allocate match id.");
    154157                async_answer_0(callid, ENOMEM);
    155158                return ENOMEM;
     
    165168        if (rc != EOK) {
    166169                delete_match_id(match_id);
    167                 printf(NAME ": devman_receive_match_id - failed to receive "
    168                     "match id string.\n");
     170                log_msg(LVL_ERROR, "Failed to receive match id string: %s.",
     171                    str_error(rc));
    169172                return rc;
    170173        }
     
    172175        list_append(&match_id->link, &match_ids->ids);
    173176       
    174         printf(NAME ": received match id '%s', score = %d \n",
     177        log_msg(LVL_DEBUG, "Received match id `%s', score %d.",
    175178            match_id->id, match_id->score);
    176179        return rc;
     
    228231        if (ftype != fun_inner && ftype != fun_exposed) {
    229232                /* Unknown function type */
    230                 printf(NAME ": Error, unknown function type provided by driver!\n");
     233                log_msg(LVL_ERROR,
     234                    "Unknown function type %d provided by driver.",
     235                    (int) ftype);
    231236
    232237                fibril_rwlock_write_unlock(&tree->rwlock);
     
    243248        }
    244249       
     250        /* Check that function with same name is not there already. */
     251        if (find_fun_node_in_device(pdev, fun_name) != NULL) {
     252                fibril_rwlock_write_unlock(&tree->rwlock);
     253                async_answer_0(callid, EEXISTS);
     254                printf(NAME ": Warning, driver tried to register `%s' twice.\n",
     255                    fun_name);
     256                free(fun_name);
     257                return;
     258        }
     259
    245260        fun_node_t *fun = create_fun_node();
    246261        if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) {
     
    265280        fibril_rwlock_write_unlock(&tree->rwlock);
    266281       
    267         printf(NAME ": devman_add_function %s\n", fun->pathname);
     282        log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname);
    268283       
    269284        devman_receive_match_ids(match_count, &fun->match_ids);
     
    347362        devmap_register_class_dev(class_info);
    348363       
    349         printf(NAME ": function'%s' added to class '%s', class name '%s' was "
    350             "asigned to it\n", fun->pathname, class_name, class_info->dev_name);
     364        log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.",
     365            fun->pathname, class_name, class_info->dev_name);
    351366
    352367        async_answer_0(callid, EOK);
     
    363378       
    364379        initialize_running_driver(driver, &device_tree);
    365         printf(NAME ": the %s driver was successfully initialized. \n",
     380        log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.",
    366381            driver->name);
    367382        return 0;
     
    385400        fid_t fid = fibril_create(init_running_drv, driver);
    386401        if (fid == 0) {
    387                 printf(NAME ": Error creating fibril for the initialization of "
    388                     "the newly registered running driver.\n");
     402                log_msg(LVL_ERROR, "Failed to create initialization fibril " \
     403                    "for driver `%s'.", driver->name);
    389404                return;
    390405        }
     
    438453}
    439454
     455/** Find handle for the device instance identified by device class name. */
     456static void devman_function_get_handle_by_class(ipc_callid_t iid,
     457    ipc_call_t *icall)
     458{
     459        char *classname;
     460        char *devname;
     461
     462        int rc = async_data_write_accept((void **) &classname, true, 0, 0, 0, 0);
     463        if (rc != EOK) {
     464                async_answer_0(iid, rc);
     465                return;
     466        }
     467        rc = async_data_write_accept((void **) &devname, true, 0, 0, 0, 0);
     468        if (rc != EOK) {
     469                free(classname);
     470                async_answer_0(iid, rc);
     471                return;
     472        }
     473
     474
     475        fun_node_t *fun = find_fun_node_by_class(&class_list,
     476            classname, devname);
     477
     478        free(classname);
     479        free(devname);
     480
     481        if (fun == NULL) {
     482                async_answer_0(iid, ENOENT);
     483                return;
     484        }
     485
     486        async_answer_1(iid, EOK, fun->handle);
     487}
     488
    440489
    441490/** Function for handling connections from a client to the device manager. */
     
    457506                        devman_function_get_handle(callid, &call);
    458507                        break;
     508                case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:
     509                        devman_function_get_handle_by_class(callid, &call);
     510                        break;
    459511                default:
    460512                        async_answer_0(callid, ENOENT);
     
    484536         */
    485537        if (dev == NULL) {
    486                 printf(NAME ": devman_forward error - no device or function with "
    487                     "handle %" PRIun " was found.\n", handle);
     538                log_msg(LVL_ERROR, "IPC forwarding failed - no device or "
     539                    "function with handle %" PRIun " was found.", handle);
    488540                async_answer_0(iid, ENOENT);
    489541                return;
     
    491543
    492544        if (fun == NULL && !drv_to_parent) {
    493                 printf(NAME ": devman_forward error - cannot connect to "
    494                     "handle %" PRIun ", refers to a device.\n", handle);
     545                log_msg(LVL_ERROR, NAME ": devman_forward error - cannot "
     546                    "connect to handle %" PRIun ", refers to a device.",
     547                    handle);
    495548                async_answer_0(iid, ENOENT);
    496549                return;
     
    513566       
    514567        if (driver == NULL) {
    515                 printf(NAME ": devman_forward error - the device %" PRIun \
    516                     " (%s) is not in usable state.\n",
     568                log_msg(LVL_ERROR, "IPC forwarding refused - " \
     569                    "the device %" PRIun "(%s) is not in usable state.",
    517570                    handle, dev->pfun->pathname);
    518571                async_answer_0(iid, ENOENT);
     
    527580       
    528581        if (driver->phone <= 0) {
    529                 printf(NAME ": devman_forward: cound not forward to driver %s ",
    530                     driver->name);
    531                 printf("the driver's phone is %" PRIun ").\n", driver->phone);
     582                log_msg(LVL_ERROR,
     583                    "Could not forward to driver `%s' (phone is %d).",
     584                    driver->name, (int) driver->phone);
    532585                async_answer_0(iid, EINVAL);
    533586                return;
     
    535588
    536589        if (fun != NULL) {
    537                 printf(NAME ": devman_forward: forward connection to function %s to "
    538                     "driver %s.\n", fun->pathname, driver->name);
     590                log_msg(LVL_DEBUG,
     591                    "Forwarding request for `%s' function to driver `%s'.",
     592                    fun->pathname, driver->name);
    539593        } else {
    540                 printf(NAME ": devman_forward: forward connection to device %s to "
    541                     "driver %s.\n", dev->pfun->pathname, driver->name);
     594                log_msg(LVL_DEBUG,
     595                    "Forwarding request for `%s' device to driver `%s'.",
     596                    dev->pfun->pathname, driver->name);
    542597        }
    543598
     
    571626        async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0,
    572627            IPC_FF_NONE);
    573         printf(NAME ": devman_connection_devmapper: forwarded connection to "
    574             "device %s to driver %s.\n", fun->pathname, dev->drv->name);
     628        log_msg(LVL_DEBUG,
     629            "Forwarding devmapper request for `%s' function to driver `%s'.",
     630            fun->pathname, dev->drv->name);
    575631}
    576632
     
    607663static bool devman_init(void)
    608664{
    609         printf(NAME ": devman_init - looking for available drivers.\n");
     665        log_msg(LVL_DEBUG, "devman_init - looking for available drivers.");
    610666       
    611667        /* Initialize list of available drivers. */
     
    613669        if (lookup_available_drivers(&drivers_list,
    614670            DRIVER_DEFAULT_STORE) == 0) {
    615                 printf(NAME " no drivers found.");
     671                log_msg(LVL_FATAL, "No drivers found.");
    616672                return false;
    617673        }
    618674
    619         printf(NAME ": devman_init  - list of drivers has been initialized.\n");
     675        log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.");
    620676
    621677        /* Create root device node. */
    622678        if (!init_device_tree(&device_tree, &drivers_list)) {
    623                 printf(NAME " failed to initialize device tree.");
     679                log_msg(LVL_FATAL, "Failed to initialize device tree.");
    624680                return false;
    625681        }
     
    642698        printf(NAME ": HelenOS Device Manager\n");
    643699
     700        if (log_init(NAME, LVL_ERROR) != EOK) {
     701                printf(NAME ": Error initializing logging subsystem.\n");
     702                return -1;
     703        }
     704
    644705        if (!devman_init()) {
    645                 printf(NAME ": Error while initializing service\n");
     706                log_msg(LVL_ERROR, "Error while initializing service.");
    646707                return -1;
    647708        }
     
    651712
    652713        /* Register device manager at naming service. */
    653         if (service_register(SERVICE_DEVMAN) != EOK)
     714        if (service_register(SERVICE_DEVMAN) != EOK) {
     715                log_msg(LVL_ERROR, "Failed registering as a service.");
    654716                return -1;
    655 
    656         printf(NAME ": Accepting connections\n");
     717        }
     718
     719        printf(NAME ": Accepting connections.\n");
    657720        async_manager();
    658721
  • uspace/srv/devmap/devmap.c

    r0b4e7ca rc593b21  
    551551        if (devmap_device_find_name(namespace->name, device->name) != NULL) {
    552552                printf("%s: Device '%s/%s' already registered\n", NAME,
    553                     device->namespace->name, device->name);
     553                    namespace->name, device->name);
    554554                devmap_namespace_destroy(namespace);
    555555                fibril_mutex_unlock(&devices_list_mutex);
Note: See TracChangeset for help on using the changeset viewer.