Changes in / [0053fa38:d773285] in mainline
- Files:
-
- 1 added
- 7 deleted
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
HelenOS.config
r0053fa38 rd773285 528 528 ! [PLATFORM=sparc64&MACHINE=generic] CONFIG_AOUT_ISOFS_B (y) 529 529 530 % Run devman on startup531 ! CONFIG_START_DEVMAN (y)532 533 % Launch (devman) test drivers534 ! [CONFIG_START_DEVMAN=y&CONFIG_DEBUG=y] CONFIG_TEST_DRIVERS (y/n)535 536 530 % Load disk drivers on startup 537 531 ! CONFIG_START_BD (n/y) … … 555 549 ! [CONFIG_STRIP_BINARIES!=y] CONFIG_LINE_DEBUG (n/y) 556 550 551 % Launch (devman) test drivers 552 ! [CONFIG_DEBUG=y] CONFIG_TEST_DRIVERS (n/y) 553 557 554 % Start virtual USB host controller 558 555 ! CONFIG_RUN_VIRTUAL_USB_HC (n/y) … … 563 560 % Run devman in kconsole (not recommended) 564 561 ! CONFIG_DEVMAN_EARLY_LAUNCH (n/y) 562 -
uspace/app/bdsh/cmds/modules/ls/ls.c
r0053fa38 rd773285 38 38 #include <dirent.h> 39 39 #include <fcntl.h> 40 #include <getopt.h>41 40 #include <sys/types.h> 42 41 #include <sys/stat.h> 43 42 #include <str.h> 44 #include <sort.h>45 43 46 44 #include "errors.h" … … 48 46 #include "util.h" 49 47 #include "entry.h" 48 #include "ls.h" 50 49 #include "cmds.h" 51 52 /* Various values that can be returned by ls_scope() */53 #define LS_BOGUS 054 #define LS_FILE 155 #define LS_DIR 256 57 /** Structure to represent a directory entry.58 *59 * Useful to keep together important information60 * for sorting directory entries.61 */62 struct dir_elem_t {63 char *name;64 struct stat s;65 };66 50 67 51 static const char *cmdname = "ls"; 68 52 69 static struct option const long_options[] = { 70 { "help", no_argument, 0, 'h' }, 71 { "unsort", no_argument, 0, 'u' }, 72 { 0, 0, 0, 0 } 73 }; 53 static void ls_scan_dir(const char *d, DIR *dirp) 54 { 55 struct dirent *dp; 56 char *buff; 74 57 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 58 if (! dirp) 59 return; 60 61 buff = (char *)malloc(PATH_MAX); 62 if (NULL == buff) { 63 cli_error(CL_ENOMEM, "ls: failed to scan %s", d); 64 return; 65 } 66 67 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 75 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 79 82 * some sort of ls_options structure that controls how each 80 83 * entry is printed and what is printed about it. 81 84 * 82 * Now we just print basic DOS style lists. 83 * 84 * @param de Directory element. 85 */ 86 static void ls_print(struct dir_elem_t *de) 85 * Now we just print basic DOS style lists */ 86 87 static void ls_print(const char *name, const char *pathname) 87 88 { 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 } 89 struct stat s; 90 int rc; 95 91 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 */ 109 static 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 */ 131 static 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; 141 struct dirent *dp; 142 143 if (!dirp) 144 return; 145 146 buff = (char *) malloc(PATH_MAX); 147 if (!buff) { 148 cli_error(CL_ENOMEM, "ls: failed to scan %s", d); 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); 149 97 return; 150 98 } 151 99 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 159 while ((dp = readdir(dirp))) { 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'; 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); 182 106 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 201 out: 202 for(i = 0; i < nbdirs; i++) 203 free(tosort[i].name); 204 free(tosort); 205 free(buff); 107 return; 206 108 } 207 109 … … 212 114 } else { 213 115 help_cmd_ls(HELP_SHORT); 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); 116 printf(" `%s' [path], if no path is given the current " 117 "working directory is used.\n", cmdname); 221 118 } 222 119 … … 227 124 { 228 125 unsigned int argc; 229 struct dir_elem_t de; 126 struct stat s; 127 char *buff; 230 128 DIR *dirp; 231 int c, opt_ind;232 int sort = 1;233 129 234 130 argc = cli_count_args(argv); 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) { 131 132 buff = (char *) malloc(PATH_MAX); 133 if (NULL == buff) { 252 134 cli_error(CL_ENOMEM, "%s: ", cmdname); 253 135 return CMD_FAILURE; 254 136 } 255 memset( de.name, 0, sizeof(PATH_MAX));256 257 if (argc == 0)258 getcwd( de.name, PATH_MAX);137 memset(buff, 0, sizeof(buff)); 138 139 if (argc == 1) 140 getcwd(buff, PATH_MAX); 259 141 else 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);142 str_cpy(buff, PATH_MAX, argv[1]); 143 144 if (stat(buff, &s)) { 145 cli_error(CL_ENOENT, buff); 146 free(buff); 265 147 return CMD_FAILURE; 266 148 } 267 149 268 if ( de.s.is_file) {269 ls_print( &de);150 if (s.is_file) { 151 ls_print(buff, buff); 270 152 } else { 271 dirp = opendir( de.name);153 dirp = opendir(buff); 272 154 if (!dirp) { 273 155 /* May have been deleted between scoping it and opening it */ 274 cli_error(CL_EFAIL, "Could not stat %s", de.name);275 free( de.name);156 cli_error(CL_EFAIL, "Could not stat %s", buff); 157 free(buff); 276 158 return CMD_FAILURE; 277 159 } 278 ls_scan_dir( de.name, dirp, sort);160 ls_scan_dir(buff, dirp); 279 161 closedir(dirp); 280 162 } 281 163 282 free( de.name);164 free(buff); 283 165 284 166 return CMD_SUCCESS; -
uspace/app/init/init.c
r0053fa38 rd773285 314 314 getterm("term/vc6", "/app/klog", false); 315 315 316 #ifdef CONFIG_START_DEVMAN317 318 316 #ifdef CONFIG_DEVMAN_EARLY_LAUNCH 319 317 spawn("/srv/devman"); … … 322 320 #endif 323 321 324 #endif325 326 322 return 0; 327 323 } -
uspace/app/tester/Makefile
r0053fa38 rd773285 54 54 mm/malloc1.c \ 55 55 mm/mapping1.c \ 56 devs/devman1.c \57 56 hw/misc/virtchar1.c \ 58 57 hw/serial/serial1.c -
uspace/app/tester/tester.c
r0053fa38 rd773285 66 66 #include "adt/usbaddrkeep.def" 67 67 #include "hw/misc/virtchar1.def" 68 #include "devs/devman1.def"69 68 {NULL, NULL, NULL, false} 70 69 }; -
uspace/app/tester/tester.h
r0053fa38 rd773285 82 82 extern const char *test_usbaddrkeep(void); 83 83 extern const char *test_virtchar1(void); 84 extern const char *test_devman1(void);85 84 86 85 extern test_t tests[]; -
uspace/drv/isa/isa.c
r0053fa38 rd773285 53 53 54 54 #include <ddf/driver.h> 55 #include <ddf/log.h>56 55 #include <ops/hw_res.h> 57 56 … … 135 134 fd = open(conf_path, O_RDONLY); 136 135 if (fd < 0) { 137 ddf_msg(LVL_ERROR, "Unable to open %s", conf_path);136 printf(NAME ": unable to open %s\n", conf_path); 138 137 goto cleanup; 139 138 } … … 142 141 143 142 len = lseek(fd, 0, SEEK_END); 144 lseek(fd, 0, SEEK_SET); 143 lseek(fd, 0, SEEK_SET); 145 144 if (len == 0) { 146 ddf_msg(LVL_ERROR, "Configuration file '%s' is empty.",147 conf_path);145 printf(NAME ": fun_conf_read error: configuration file '%s' " 146 "is empty.\n", conf_path); 148 147 goto cleanup; 149 148 } … … 151 150 buf = malloc(len + 1); 152 151 if (buf == NULL) { 153 ddf_msg(LVL_ERROR, "Memory allocation failed.");152 printf(NAME ": fun_conf_read error: memory allocation failed.\n"); 154 153 goto cleanup; 155 154 } 156 155 157 156 if (0 >= read(fd, buf, len)) { 158 ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path); 157 printf(NAME ": fun_conf_read error: unable to read file '%s'.\n", 158 conf_path); 159 159 goto cleanup; 160 160 } … … 252 252 fun->hw_resources.count++; 253 253 254 ddf_msg(LVL_NOTE, "Added irq 0x%x to function %s", irq,254 printf(NAME ": added irq 0x%x to function %s\n", irq, 255 255 fun->fnode->name); 256 256 } … … 270 270 fun->hw_resources.count++; 271 271 272 ddf_msg(LVL_NOTE, "Added io range (addr=0x%x, size=0x%x) to "273 "function %s ", (unsigned int) addr, (unsigned int) len,272 printf(NAME ": added io range (addr=0x%x, size=0x%x) to " 273 "function %s\n", (unsigned int) addr, (unsigned int) len, 274 274 fun->fnode->name); 275 275 } … … 331 331 score = (int)strtol(val, &end, 10); 332 332 if (val == end) { 333 ddf_msg(LVL_ERROR, "Cannot read match score for function"334 " %s.", fun->fnode->name);333 printf(NAME " : error - could not read match score for " 334 "function %s.\n", fun->fnode->name); 335 335 return; 336 336 } … … 339 339 get_match_id(&id, val); 340 340 if (id == NULL) { 341 ddf_msg(LVL_ERROR, "Cannot read match ID for function %s.",342 fun->fnode->name);341 printf(NAME " : error - could not read match id for " 342 "function %s.\n", fun->fnode->name); 343 343 return; 344 344 } 345 345 346 ddf_msg(LVL_DEBUG, "Adding match id '%s' with score %d to "347 "function %s", id,score, fun->fnode->name);346 printf(NAME ": adding match id '%s' with score %d to function %s\n", id, 347 score, fun->fnode->name); 348 348 349 349 rc = ddf_fun_add_match_id(fun->fnode, id, score); 350 if (rc != EOK) { 351 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", 352 str_error(rc)); 353 } 350 if (rc != EOK) 351 printf(NAME ": error adding match ID: %s\n", str_error(rc)); 354 352 } 355 353 … … 377 375 if (!prop_parse(fun, line, "io_range", &fun_parse_io_range) && 378 376 !prop_parse(fun, line, "irq", &fun_parse_irq) && 379 !prop_parse(fun, line, "match", &fun_parse_match_id)) {380 381 ddf_msg(LVL_ERROR, "Undefined device property at line '%s'",382 377 !prop_parse(fun, line, "match", &fun_parse_match_id)) 378 { 379 printf(NAME " error undefined device property at line '%s'\n", 380 line); 383 381 } 384 382 } … … 441 439 fun->fnode->ops = &isa_fun_ops; 442 440 443 ddf_msg(LVL_DEBUG, "Binding function %s.", fun->fnode->name);441 printf(NAME ": Binding function %s.\n", fun->fnode->name); 444 442 445 443 /* XXX Handle error */ … … 469 467 static int isa_add_device(ddf_dev_t *dev) 470 468 { 471 ddf_msg(LVL_DEBUG, "isa_add_device, device handle = %d",469 printf(NAME ": isa_add_device, device handle = %d\n", 472 470 (int) dev->handle); 473 471 474 472 /* Make the bus device more visible. Does not do anything. */ 475 ddf_msg(LVL_DEBUG, "Adding a 'ctl' function");473 printf(NAME ": adding a 'ctl' function\n"); 476 474 477 475 ddf_fun_t *ctl = ddf_fun_create(dev, fun_exposed, "ctl"); 478 476 if (ctl == NULL) { 479 ddf_msg(LVL_ERROR, "Failed creating control function.");477 printf(NAME ": Error creating control function.\n"); 480 478 return EXDEV; 481 479 } 482 480 483 481 if (ddf_fun_bind(ctl) != EOK) { 484 ddf_msg(LVL_ERROR, "Failed binding control function.");482 printf(NAME ": Error binding control function.\n"); 485 483 return EXDEV; 486 484 } … … 488 486 /* Add functions as specified in the configuration file. */ 489 487 isa_functions_add(dev); 490 ddf_msg(LVL_NOTE, "Finished enumerating legacy functions");488 printf(NAME ": finished the enumeration of legacy functions\n"); 491 489 492 490 return EOK; … … 495 493 static void isa_init() 496 494 { 497 ddf_log_init(NAME, LVL_ERROR);498 495 isa_fun_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops; 499 496 } -
uspace/drv/ns8250/ns8250.c
r0053fa38 rd773285 55 55 #include <ddf/driver.h> 56 56 #include <ddf/interrupt.h> 57 #include <ddf/log.h>58 57 #include <ops/char_dev.h> 59 58 … … 276 275 static bool ns8250_pio_enable(ns8250_t *ns) 277 276 { 278 ddf_msg(LVL_DEBUG, "ns8250_pio_enable %s", ns->dev->name);277 printf(NAME ": ns8250_pio_enable %s\n", ns->dev->name); 279 278 280 279 /* Gain control over port's registers. */ 281 280 if (pio_enable((void *)(uintptr_t) ns->io_addr, REG_COUNT, 282 281 (void **) &ns->port)) { 283 ddf_msg(LVL_ERROR, "Cannot map the port %#" PRIx32284 " for device %s.", ns->io_addr, ns->dev->name);282 printf(NAME ": error - cannot gain the port %#" PRIx32 " for device " 283 "%s.\n", ns->io_addr, ns->dev->name); 285 284 return false; 286 285 } … … 296 295 static bool ns8250_dev_probe(ns8250_t *ns) 297 296 { 298 ddf_msg(LVL_DEBUG, "ns8250_dev_probe %s", ns->dev->name);297 printf(NAME ": ns8250_dev_probe %s\n", ns->dev->name); 299 298 300 299 ioport8_t *port_addr = ns->port; … … 314 313 pio_write_8(port_addr + 4, olddata); 315 314 316 if (!res) { 317 ddf_msg(LVL_DEBUG, "Device %s is not present.", 318 ns->dev->name); 319 } 315 if (!res) 316 printf(NAME ": device %s is not present.\n", ns->dev->name); 320 317 321 318 return res; … … 329 326 static int ns8250_dev_initialize(ns8250_t *ns) 330 327 { 331 ddf_msg(LVL_DEBUG, "ns8250_dev_initialize %s", ns->dev->name);328 printf(NAME ": ns8250_dev_initialize %s\n", ns->dev->name); 332 329 333 330 int ret = EOK; … … 340 337 IPC_FLAG_BLOCKING); 341 338 if (ns->dev->parent_phone < 0) { 342 ddf_msg(LVL_ERROR, "Failed to connect to parent driver of"343 "device %s. ", ns->dev->name);339 printf(NAME ": failed to connect to the parent driver of the " 340 "device %s.\n", ns->dev->name); 344 341 ret = ns->dev->parent_phone; 345 342 goto failed; … … 349 346 ret = hw_res_get_resource_list(ns->dev->parent_phone, &hw_resources); 350 347 if (ret != EOK) { 351 ddf_msg(LVL_ERROR, "Failed to get HW resources fordevice "352 "%s. ", ns->dev->name);348 printf(NAME ": failed to get hw resources for the device " 349 "%s.\n", ns->dev->name); 353 350 goto failed; 354 351 } … … 365 362 ns->irq = res->res.interrupt.irq; 366 363 irq = true; 367 ddf_msg(LVL_NOTE, "Device %s was asigned irq = 0x%x.",364 printf(NAME ": the %s device was asigned irq = 0x%x.\n", 368 365 ns->dev->name, ns->irq); 369 366 break; … … 372 369 ns->io_addr = res->res.io_range.address; 373 370 if (res->res.io_range.size < REG_COUNT) { 374 ddf_msg(LVL_ERROR, "I/O range assigned to"375 " device %s is too small.", ns->dev->name);371 printf(NAME ": i/o range assigned to the device " 372 "%s is too small.\n", ns->dev->name); 376 373 ret = ELIMIT; 377 374 goto failed; 378 375 } 379 376 ioport = true; 380 ddf_msg(LVL_NOTE, "Device %s was asigned I/Oaddress = "381 "0x%x. ", ns->dev->name, ns->io_addr);382 377 printf(NAME ": the %s device was asigned i/o address = " 378 "0x%x.\n", ns->dev->name, ns->io_addr); 379 break; 383 380 384 381 default: … … 388 385 389 386 if (!irq || !ioport) { 390 ddf_msg(LVL_ERROR, "Missing HW resource(s) for device %s.",387 printf(NAME ": missing hw resource(s) for the device %s.\n", 391 388 ns->dev->name); 392 389 ret = ENOENT; … … 473 470 474 471 if (baud_rate < 50 || MAX_BAUD_RATE % baud_rate != 0) { 475 ddf_msg(LVL_ERROR, "Invalid baud rate %d requested.",476 baud_rate);472 printf(NAME ": error - somebody tried to set invalid baud rate " 473 "%d\n", baud_rate); 477 474 return EINVAL; 478 475 } … … 657 654 if (ns->client_connected) { 658 655 if (!buf_push_back(&ns->input_buffer, val)) { 659 ddf_msg(LVL_WARN, "Buffer overflow on "660 "%s. ", ns->dev->name);656 printf(NAME ": buffer overflow on " 657 "%s.\n", ns->dev->name); 661 658 } else { 662 ddf_msg(LVL_DEBUG2, "Character %c saved "663 "to the buffer of %s. ",659 printf(NAME ": the character %c saved " 660 "to the buffer of %s.\n", 664 661 val, ns->dev->name); 665 662 } … … 717 714 int rc; 718 715 719 ddf_msg(LVL_DEBUG, "ns8250_add_device %s (handle = %d)",716 printf(NAME ": ns8250_add_device %s (handle = %d)\n", 720 717 dev->name, (int) dev->handle); 721 718 … … 752 749 /* Register interrupt handler. */ 753 750 if (ns8250_register_interrupt_handler(ns) != EOK) { 754 ddf_msg(LVL_ERROR, "Failed to register interrupt handler.");751 printf(NAME ": failed to register interrupt handler.\n"); 755 752 rc = EADDRNOTAVAIL; 756 753 goto fail; … … 760 757 rc = ns8250_interrupt_enable(ns); 761 758 if (rc != EOK) { 762 ddf_msg(LVL_ERROR, "Failed to enable the interrupt. Error code = "763 "%d. ", rc);759 printf(NAME ": failed to enable the interrupt. Error code = " 760 "%d.\n", rc); 764 761 goto fail; 765 762 } … … 767 764 fun = ddf_fun_create(dev, fun_exposed, "a"); 768 765 if (fun == NULL) { 769 ddf_msg(LVL_ERROR, "Failed creating function.");766 printf(NAME ": error creating function.\n"); 770 767 goto fail; 771 768 } … … 775 772 rc = ddf_fun_bind(fun); 776 773 if (rc != EOK) { 777 ddf_msg(LVL_ERROR, "Failed binding function.");774 printf(NAME ": error binding function.\n"); 778 775 goto fail; 779 776 } … … 783 780 ddf_fun_add_to_class(fun, "serial"); 784 781 785 ddf_msg(LVL_NOTE, "Device %s successfully initialized.",782 printf(NAME ": the %s device has been successfully initialized.\n", 786 783 dev->name); 787 784 … … 865 862 fibril_mutex_unlock(&data->mutex); 866 863 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,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, 869 866 *stop_bits); 870 867 } … … 882 879 unsigned int parity, unsigned int word_length, unsigned int stop_bits) 883 880 { 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,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, 886 883 stop_bits); 887 884 … … 943 940 static void ns8250_init(void) 944 941 { 945 ddf_log_init(NAME, LVL_ERROR);946 947 942 ns8250_dev_ops.open = &ns8250_open; 948 943 ns8250_dev_ops.close = &ns8250_close; -
uspace/drv/ohci/root_hub.c
r0053fa38 rd773285 40 40 #include "root_hub.h" 41 41 #include "usb/classes/classes.h" 42 #include "usb/devdrv.h"43 42 #include <usb/request.h> 44 43 #include <usb/classes/hub.h> … … 62 61 /// \TODO these values migt be different 63 62 .str_serial_number = 0, 64 .usb_spec_version = 0 x110,63 .usb_spec_version = 0, 65 64 }; 66 65 … … 111 110 }; 112 111 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 126 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 } 171 113 172 /** 114 173 * Create hub descriptor used in hub-driver <-> hub communication 115 * 174 * 116 175 * This means creating byt array from data in root hub registers. For more 117 176 * info see usb hub specification. … … 138 197 result[2] = instance->port_count; 139 198 uint32_t hub_desc_reg = instance->registers->rh_desc_a; 140 result[3] = 199 result[3] = 141 200 ((hub_desc_reg >> 8) %2) + 142 201 (((hub_desc_reg >> 9) %2) << 1) + … … 160 219 (*out_size) = size; 161 220 } 162 163 164 /** initialize hub descriptors165 *166 * Initialized are device and full configuration descriptor. These need to167 * be initialized only once per hub.168 * @instance root hub instance169 */170 static void rh_init_descriptors(rh_t *instance){171 memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor,172 sizeof(ohci_rh_device_descriptor)173 );174 usb_standard_configuration_descriptor_t descriptor;175 memcpy(&descriptor,&ohci_rh_conf_descriptor,176 sizeof(ohci_rh_conf_descriptor));177 uint8_t * hub_descriptor;178 size_t hub_desc_size;179 usb_create_serialized_hub_descriptor(instance, &hub_descriptor,180 &hub_desc_size);181 182 descriptor.total_length =183 sizeof(usb_standard_configuration_descriptor_t)+184 sizeof(usb_standard_endpoint_descriptor_t)+185 sizeof(usb_standard_interface_descriptor_t)+186 hub_desc_size;187 188 uint8_t * full_config_descriptor =189 (uint8_t*) malloc(descriptor.total_length);190 memcpy(full_config_descriptor, &descriptor, sizeof(descriptor));191 memcpy(full_config_descriptor + sizeof(descriptor),192 &ohci_rh_iface_descriptor, sizeof(ohci_rh_iface_descriptor));193 memcpy(full_config_descriptor + sizeof(descriptor) +194 sizeof(ohci_rh_iface_descriptor),195 &ohci_rh_ep_descriptor, sizeof(ohci_rh_ep_descriptor));196 memcpy(full_config_descriptor + sizeof(descriptor) +197 sizeof(ohci_rh_iface_descriptor) +198 sizeof(ohci_rh_ep_descriptor),199 hub_descriptor, hub_desc_size);200 201 instance->descriptors.configuration = full_config_descriptor;202 instance->descriptors.configuration_size = descriptor.total_length;203 }204 205 /** Root hub initialization206 * @return Error code.207 */208 int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs)209 {210 assert(instance);211 instance->address = -1;212 instance->registers = regs;213 instance->device = dev;214 rh_init_descriptors(instance);215 216 217 usb_log_info("OHCI root hub with %d ports.\n", regs->rh_desc_a & 0xff);218 219 //start generic usb hub driver220 221 /* TODO: implement */222 return EOK;223 }224 /*----------------------------------------------------------------------------*/225 226 /**227 * create answer to port status_request228 *229 * Copy content of corresponding port status register to answer buffer.230 *231 * @param instance root hub instance232 * @param port port number, counted from 1233 * @param request structure containing both request and response information234 * @return error code235 */236 static int process_get_port_status_request(rh_t *instance, uint16_t port,237 usb_transfer_batch_t * request){238 if(port<1 || port>instance->port_count)239 return EINVAL;240 uint32_t * uint32_buffer = (uint32_t*)request->buffer;241 request->transfered_size = 4;242 uint32_buffer[0] = instance->registers->rh_port_status[port -1];243 return EOK;244 }245 246 /**247 * create answer to port status_request248 *249 * Copy content of hub status register to answer buffer.250 *251 * @param instance root hub instance252 * @param request structure containing both request and response information253 * @return error code254 */255 static int process_get_hub_status_request(rh_t *instance,256 usb_transfer_batch_t * request){257 uint32_t * uint32_buffer = (uint32_t*)request->buffer;258 //bits, 0,1,16,17259 request->transfered_size = 4;260 uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17);261 uint32_buffer[0] = mask & instance->registers->rh_status;262 return EOK;263 264 }265 266 221 267 222 … … 329 284 } 330 285 } 331 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 332 310 /** 333 311 * create answer to a descriptor request … … 366 344 case USB_DESCTYPE_CONFIGURATION: { 367 345 usb_log_debug("USB_DESCTYPE_CONFIGURATION\n"); 368 result_descriptor = instance->descriptors.configuration; 369 size = instance->descriptors.configuration_size; 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; 370 352 break; 371 353 } … … 398 380 } 399 381 request->transfered_size = size; 400 memcpy(request->transport_buffer,result_descriptor,size); 401 usb_log_debug("sent desctiptor: %s\n", 402 usb_debug_str_buffer((uint8_t*)request->transport_buffer,size,size)); 382 memcpy(request->buffer,result_descriptor,size); 403 383 if (del) 404 384 free(result_descriptor); -
uspace/drv/ohci/root_hub.h
r0053fa38 rd773285 37 37 38 38 #include <usb/usb.h> 39 #include <usb/devdrv.h>40 39 41 40 #include "ohci_regs.h" … … 54 53 /** hub port count */ 55 54 int port_count; 56 /** hubs descriptors */57 usb_device_descriptors_t descriptors;58 55 } rh_t; 59 56 -
uspace/drv/pciintel/pci.c
r0053fa38 rd773285 48 48 49 49 #include <ddf/driver.h> 50 #include <ddf/log.h>51 50 #include <devman.h> 52 51 #include <ipc/devman.h> … … 326 325 327 326 if (match_id_str == NULL) { 328 ddf_msg(LVL_ERROR, "Out of memory creating match ID.");327 printf(NAME ": out of memory creating match ID.\n"); 329 328 return; 330 329 } … … 332 331 rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 90); 333 332 if (rc != EOK) { 334 ddf_msg(LVL_ERROR, "Failed adding match ID: %s",333 printf(NAME ": error adding match ID: %s\n", 335 334 str_error(rc)); 336 335 } … … 429 428 430 429 if (range_addr != 0) { 431 ddf_msg(LVL_DEBUG, "Function %s : address = %" PRIx64432 ", size = %x", fun->fnode->name, range_addr,433 430 printf(NAME ": function %s : ", fun->fnode->name); 431 printf("address = %" PRIx64, range_addr); 432 printf(", size = %x\n", (unsigned int) range_size); 434 433 } 435 434 … … 456 455 hw_res_list->count++; 457 456 458 ddf_msg(LVL_NOTE, "Function %s uses irq %x.", fun->fnode->name, irq);457 printf(NAME ": function %s uses irq %x.\n", fun->fnode->name, irq); 459 458 } 460 459 … … 512 511 char *fun_name = pci_fun_create_name(fun); 513 512 if (fun_name == NULL) { 514 ddf_msg(LVL_ERROR, "Out of memory.");513 printf(NAME ": out of memory.\n"); 515 514 return; 516 515 } … … 518 517 fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name); 519 518 if (fnode == NULL) { 520 ddf_msg(LVL_ERROR, "Failed creating function.");519 printf(NAME ": error creating function.\n"); 521 520 return; 522 521 } … … 532 531 fnode->driver_data = fun; 533 532 534 ddf_msg(LVL_DEBUG, "Adding new function %s.",533 printf(NAME ": adding new function %s.\n", 535 534 fnode->name); 536 535 … … 549 548 child_bus = pci_conf_read_8(fun, 550 549 PCI_BRIDGE_SEC_BUS_NUM); 551 ddf_msg(LVL_DEBUG, "Device is pci-to-pci " 552 "bridge, secondary bus number = %d.", 553 bus_num); 550 printf(NAME ": device is pci-to-pci bridge, " 551 "secondary bus number = %d.\n", bus_num); 554 552 if (child_bus > bus_num) 555 553 pci_bus_scan(bus, child_bus); … … 573 571 int rc; 574 572 575 ddf_msg(LVL_DEBUG, "pci_add_device");573 printf(NAME ": pci_add_device\n"); 576 574 dnode->parent_phone = -1; 577 575 578 576 bus = pci_bus_new(); 579 577 if (bus == NULL) { 580 ddf_msg(LVL_ERROR, "pci_add_device allocation failed.");578 printf(NAME ": pci_add_device allocation failed.\n"); 581 579 rc = ENOMEM; 582 580 goto fail; … … 588 586 IPC_FLAG_BLOCKING); 589 587 if (dnode->parent_phone < 0) { 590 ddf_msg(LVL_ERROR, "pci_add_device failed to connect to the "591 "parent's driver. ");588 printf(NAME ": pci_add_device failed to connect to the " 589 "parent's driver.\n"); 592 590 rc = dnode->parent_phone; 593 591 goto fail; … … 598 596 rc = hw_res_get_resource_list(dnode->parent_phone, &hw_resources); 599 597 if (rc != EOK) { 600 ddf_msg(LVL_ERROR, "pci_add_device failed to get hw resources"601 " for the device.");598 printf(NAME ": pci_add_device failed to get hw resources for " 599 "the device.\n"); 602 600 goto fail; 603 601 } 604 602 got_res = true; 605 603 606 ddf_msg(LVL_DEBUG, "conf_addr = %" PRIx64 ".",604 printf(NAME ": conf_addr = %" PRIx64 ".\n", 607 605 hw_resources.resources[0].res.io_range.address); 608 606 … … 616 614 if (pio_enable((void *)(uintptr_t)bus->conf_io_addr, 8, 617 615 &bus->conf_addr_port)) { 618 ddf_msg(LVL_ERROR, "Failed to enable configuration ports.");616 printf(NAME ": failed to enable configuration ports.\n"); 619 617 rc = EADDRNOTAVAIL; 620 618 goto fail; … … 623 621 624 622 /* Make the bus device more visible. It has no use yet. */ 625 ddf_msg(LVL_DEBUG, "Adding a 'ctl' function");623 printf(NAME ": adding a 'ctl' function\n"); 626 624 627 625 ctl = ddf_fun_create(bus->dnode, fun_exposed, "ctl"); 628 626 if (ctl == NULL) { 629 ddf_msg(LVL_ERROR, "Failed creating control function.");627 printf(NAME ": error creating control function.\n"); 630 628 rc = ENOMEM; 631 629 goto fail; … … 634 632 rc = ddf_fun_bind(ctl); 635 633 if (rc != EOK) { 636 ddf_msg(LVL_ERROR, "Failed binding control function.");634 printf(NAME ": error binding control function.\n"); 637 635 goto fail; 638 636 } 639 637 640 638 /* Enumerate functions. */ 641 ddf_msg(LVL_DEBUG, "Scanning the bus");639 printf(NAME ": scanning the bus\n"); 642 640 pci_bus_scan(bus, 0); 643 641 … … 661 659 static void pciintel_init(void) 662 660 { 663 ddf_log_init(NAME, LVL_ERROR);664 661 pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops; 665 662 pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops; … … 741 738 int main(int argc, char *argv[]) 742 739 { 743 printf(NAME ": HelenOS PCI bus driver (Intel method 1).\n");740 printf(NAME ": HelenOS pci bus driver (intel method 1).\n"); 744 741 pciintel_init(); 745 742 return ddf_driver_main(&pci_driver); -
uspace/drv/root/root.c
r0053fa38 rd773285 52 52 53 53 #include <ddf/driver.h> 54 #include <ddf/log.h>55 54 #include <devman.h> 56 55 #include <ipc/devman.h> … … 90 89 int rc; 91 90 92 ddf_msg(LVL_DEBUG, "Adding new function for virtual devices. "93 "Function node is `%s' (%d %s)", name,91 printf(NAME ": adding new function for virtual devices.\n"); 92 printf(NAME ": function node is `%s' (%d %s)\n", name, 94 93 VIRTUAL_FUN_MATCH_SCORE, VIRTUAL_FUN_MATCH_ID); 95 94 96 95 fun = ddf_fun_create(dev, fun_inner, name); 97 96 if (fun == NULL) { 98 ddf_msg(LVL_ERROR, "Failed creating function %s", name);97 printf(NAME ": error creating function %s\n", name); 99 98 return ENOMEM; 100 99 } … … 103 102 VIRTUAL_FUN_MATCH_SCORE); 104 103 if (rc != EOK) { 105 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s", 106 name); 104 printf(NAME ": error adding match IDs to function %s\n", name); 107 105 ddf_fun_destroy(fun); 108 106 return rc; … … 111 109 rc = ddf_fun_bind(fun); 112 110 if (rc != EOK) { 113 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,111 printf(NAME ": error binding function %s: %s\n", name, 114 112 str_error(rc)); 115 113 ddf_fun_destroy(fun); … … 138 136 platform = sysinfo_get_data("platform", &platform_size); 139 137 if (platform == NULL) { 140 ddf_msg(LVL_ERROR, "Failed to obtain platform name.");138 printf(NAME ": Failed to obtain platform name.\n"); 141 139 return ENOENT; 142 140 } … … 145 143 platform = realloc(platform, platform_size + 1); 146 144 if (platform == NULL) { 147 ddf_msg(LVL_ERROR, "Memory allocation failed.");145 printf(NAME ": Memory allocation failed.\n"); 148 146 return ENOMEM; 149 147 } … … 153 151 /* Construct match ID. */ 154 152 if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) { 155 ddf_msg(LVL_ERROR, "Memory allocation failed.");153 printf(NAME ": Memory allocation failed.\n"); 156 154 return ENOMEM; 157 155 } 158 156 159 157 /* Add function. */ 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);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); 163 161 164 162 fun = ddf_fun_create(dev, fun_inner, name); 165 163 if (fun == NULL) { 166 ddf_msg(LVL_ERROR, "Error creating function %s", name);164 printf(NAME ": error creating function %s\n", name); 167 165 return ENOMEM; 168 166 } … … 170 168 rc = ddf_fun_add_match_id(fun, match_id, PLATFORM_FUN_MATCH_SCORE); 171 169 if (rc != EOK) { 172 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s", 173 name); 170 printf(NAME ": error adding match IDs to function %s\n", name); 174 171 ddf_fun_destroy(fun); 175 172 return rc; … … 178 175 rc = ddf_fun_bind(fun); 179 176 if (rc != EOK) { 180 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,177 printf(NAME ": error binding function %s: %s\n", name, 181 178 str_error(rc)); 182 179 ddf_fun_destroy(fun); … … 194 191 static int root_add_device(ddf_dev_t *dev) 195 192 { 196 ddf_msg(LVL_DEBUG, "root_add_device, device handle=%" PRIun,193 printf(NAME ": root_add_device, device handle=%" PRIun "\n", 197 194 dev->handle); 198 195 … … 207 204 int res = add_platform_fun(dev); 208 205 if (EOK != res) 209 ddf_msg(LVL_ERROR, "Failed adding child device for platform.");206 printf(NAME ": failed to add child device for platform.\n"); 210 207 211 208 return res; … … 215 212 { 216 213 printf(NAME ": HelenOS root device driver\n"); 217 218 ddf_log_init(NAME, LVL_ERROR);219 214 return ddf_driver_main(&root_driver); 220 215 } -
uspace/drv/rootpc/rootpc.c
r0053fa38 rd773285 47 47 48 48 #include <ddf/driver.h> 49 #include <ddf/log.h>50 49 #include <devman.h> 51 50 #include <ipc/devman.h> … … 120 119 rootpc_fun_t *fun) 121 120 { 122 ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);121 printf(NAME ": adding new function '%s'.\n", name); 123 122 124 123 ddf_fun_t *fnode = NULL; … … 146 145 /* Register function. */ 147 146 if (ddf_fun_bind(fnode) != EOK) { 148 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);147 printf(NAME ": error binding function %s.\n", name); 149 148 goto failure; 150 149 } … … 159 158 ddf_fun_destroy(fnode); 160 159 161 ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);160 printf(NAME ": failed to add function '%s'.\n", name); 162 161 163 162 return false; … … 177 176 static int rootpc_add_device(ddf_dev_t *dev) 178 177 { 179 ddf_msg(LVL_DEBUG, "rootpc_add_device, device handle = %d",178 printf(NAME ": rootpc_add_device, device handle = %d\n", 180 179 (int)dev->handle); 181 180 182 181 /* Register functions. */ 183 182 if (!rootpc_add_functions(dev)) { 184 ddf_msg(LVL_ERROR, "Failed to add functions for PC platform.");183 printf(NAME ": failed to add functions for PC platform.\n"); 185 184 } 186 185 … … 190 189 static void root_pc_init(void) 191 190 { 192 ddf_log_init(NAME, LVL_ERROR);193 191 rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops; 194 192 } -
uspace/drv/rootvirt/rootvirt.c
r0053fa38 rd773285 40 40 #include <str_error.h> 41 41 #include <ddf/driver.h> 42 #include <ddf/log.h>43 42 44 43 #define NAME "rootvirt" … … 84 83 int rc; 85 84 86 ddf_msg(LVL_DEBUG, "Registering function `%s' (match \"%s\")",85 printf(NAME ": registering function `%s' (match \"%s\")\n", 87 86 vfun->name, vfun->match_id); 88 87 89 88 fun = ddf_fun_create(vdev, fun_inner, vfun->name); 90 89 if (fun == NULL) { 91 ddf_msg(LVL_ERROR, "Failed creating function %s", vfun->name);90 printf(NAME ": error creating function %s\n", vfun->name); 92 91 return ENOMEM; 93 92 } … … 95 94 rc = ddf_fun_add_match_id(fun, vfun->match_id, 10); 96 95 if (rc != EOK) { 97 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",96 printf(NAME ": error adding match IDs to function %s\n", 98 97 vfun->name); 99 98 ddf_fun_destroy(fun); … … 103 102 rc = ddf_fun_bind(fun); 104 103 if (rc != EOK) { 105 ddf_msg(LVL_ERROR, "Failed binding function %s: %s",106 vfun->name,str_error(rc));104 printf(NAME ": error binding function %s: %s\n", vfun->name, 105 str_error(rc)); 107 106 ddf_fun_destroy(fun); 108 107 return rc; 109 108 } 110 109 111 ddf_msg(LVL_NOTE, "Registered child device `%s'", vfun->name);110 printf(NAME ": registered child device `%s'\n", vfun->name); 112 111 return EOK; 113 112 } … … 125 124 } 126 125 127 ddf_msg(LVL_DEBUG, "add_device(handle=%d)", (int)dev->handle);126 printf(NAME ": add_device(handle=%d)\n", (int)dev->handle); 128 127 129 128 /* … … 143 142 { 144 143 printf(NAME ": HelenOS virtual devices root driver\n"); 145 146 ddf_log_init(NAME, LVL_ERROR);147 144 return ddf_driver_main(&rootvirt_driver); 148 145 } -
uspace/drv/test1/test1.c
r0053fa38 rd773285 35 35 #include <str_error.h> 36 36 #include <ddf/driver.h> 37 #include <ddf/log.h>38 37 39 38 #include "test1.h" … … 59 58 */ 60 59 static int register_fun_verbose(ddf_dev_t *parent, const char *message, 61 const char *name, const char *match_id, int match_score, 62 int expected_rc) 60 const char *name, const char *match_id, int match_score) 63 61 { 64 ddf_fun_t *fun = NULL;62 ddf_fun_t *fun; 65 63 int rc; 66 64 67 ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message);65 printf(NAME ": registering function `%s': %s.\n", name, message); 68 66 69 67 fun = ddf_fun_create(parent, fun_inner, name); 70 68 if (fun == NULL) { 71 ddf_msg(LVL_ERROR, "Failed creating function %s", name); 72 rc = ENOMEM; 73 goto leave; 69 printf(NAME ": error creating function %s\n", name); 70 return ENOMEM; 74 71 } 75 72 76 rc = ddf_fun_add_match_id(fun, str_dup(match_id), match_score);73 rc = ddf_fun_add_match_id(fun, match_id, match_score); 77 74 if (rc != EOK) { 78 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",79 name);80 goto leave;75 printf(NAME ": error adding match IDs to function %s\n", name); 76 ddf_fun_destroy(fun); 77 return rc; 81 78 } 82 79 83 80 rc = ddf_fun_bind(fun); 84 81 if (rc != EOK) { 85 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,82 printf(NAME ": error binding function %s: %s\n", name, 86 83 str_error(rc)); 87 goto leave; 84 ddf_fun_destroy(fun); 85 return rc; 88 86 } 89 87 90 ddf_msg(LVL_NOTE, "Registered child device `%s'", name); 91 rc = EOK; 92 93 leave: 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; 88 printf(NAME ": registered child device `%s'\n", name); 89 return EOK; 106 90 } 107 91 … … 128 112 int rc; 129 113 130 ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)",114 printf(NAME ": add_device(name=\"%s\", handle=%d)\n", 131 115 dev->name, (int) dev->handle); 132 116 133 117 fun_a = ddf_fun_create(dev, fun_exposed, "a"); 134 118 if (fun_a == NULL) { 135 ddf_msg(LVL_ERROR, "Failed creating function 'a'.");119 printf(NAME ": error creating function 'a'.\n"); 136 120 return ENOMEM; 137 121 } … … 139 123 rc = ddf_fun_bind(fun_a); 140 124 if (rc != EOK) { 141 ddf_msg(LVL_ERROR, "Failed binding function 'a'.");125 printf(NAME ": error binding function 'a'.\n"); 142 126 return rc; 143 127 } … … 149 133 ddf_fun_add_to_class(fun_a, "virt-null"); 150 134 } else if (str_cmp(dev->name, "test1") == 0) { 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); 135 (void) register_fun_verbose(dev, "cloning myself ;-)", "clone", 136 "virtual&test1", 10); 157 137 } else if (str_cmp(dev->name, "clone") == 0) { 158 (void) register_fun_verbose(dev, 159 "run by the same task", "child", 160 "virtual&test1&child", 10, EOK); 138 (void) register_fun_verbose(dev, "run by the same task", "child", 139 "virtual&test1&child", 10); 161 140 } 162 141 163 ddf_msg(LVL_DEBUG, "Device `%s' accepted.", dev->name);142 printf(NAME ": device `%s' accepted.\n", dev->name); 164 143 165 144 return EOK; … … 169 148 { 170 149 printf(NAME ": HelenOS test1 virtual device driver\n"); 171 ddf_log_init(NAME, LVL_ERROR);172 150 return ddf_driver_main(&test1_driver); 173 151 } -
uspace/drv/test2/test2.c
r0053fa38 rd773285 36 36 #include <str_error.h> 37 37 #include <ddf/driver.h> 38 #include <ddf/log.h>39 38 40 39 #define NAME "test2" … … 65 64 int rc; 66 65 67 ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message);66 printf(NAME ": registering function `%s': %s.\n", name, message); 68 67 69 68 fun = ddf_fun_create(parent, fun_inner, name); 70 69 if (fun == NULL) { 71 ddf_msg(LVL_ERROR, "Failed creating function %s", name);70 printf(NAME ": error creating function %s\n", name); 72 71 return ENOMEM; 73 72 } … … 75 74 rc = ddf_fun_add_match_id(fun, match_id, match_score); 76 75 if (rc != EOK) { 77 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s", 78 name); 76 printf(NAME ": error adding match IDs to function %s\n", name); 79 77 ddf_fun_destroy(fun); 80 78 return rc; … … 83 81 rc = ddf_fun_bind(fun); 84 82 if (rc != EOK) { 85 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,83 printf(NAME ": error binding function %s: %s\n", name, 86 84 str_error(rc)); 87 85 ddf_fun_destroy(fun); … … 89 87 } 90 88 91 ddf_msg(LVL_NOTE, "Registered child device `%s'", name);89 printf(NAME ": registered child device `%s'\n", name); 92 90 return EOK; 93 91 } … … 113 111 fun_a = ddf_fun_create(dev, fun_exposed, "a"); 114 112 if (fun_a == NULL) { 115 ddf_msg(LVL_ERROR, "Failed creating function 'a'.");113 printf(NAME ": error creating function 'a'.\n"); 116 114 return ENOMEM; 117 115 } … … 119 117 rc = ddf_fun_bind(fun_a); 120 118 if (rc != EOK) { 121 ddf_msg(LVL_ERROR, "Failed binding function 'a'.");119 printf(NAME ": error binding function 'a'.\n"); 122 120 return rc; 123 121 } … … 130 128 static int test2_add_device(ddf_dev_t *dev) 131 129 { 132 ddf_msg(LVL_DEBUG, "test2_add_device(name=\"%s\", handle=%d)",130 printf(NAME ": test2_add_device(name=\"%s\", handle=%d)\n", 133 131 dev->name, (int) dev->handle); 134 132 … … 136 134 fid_t postpone = fibril_create(postponed_birth, dev); 137 135 if (postpone == 0) { 138 ddf_msg(LVL_ERROR, "fibril_create() failed.");136 printf(NAME ": fibril_create() error\n"); 139 137 return ENOMEM; 140 138 } … … 151 149 { 152 150 printf(NAME ": HelenOS test2 virtual device driver\n"); 153 ddf_log_init(NAME, LVL_ERROR);154 151 return ddf_driver_main(&test2_driver); 155 152 } -
uspace/drv/usbhub/usbhub.c
r0053fa38 rd773285 74 74 75 75 while(errorCode == EOK){ 76 async_usleep(1000 * 1000 * 10 );/// \TODO proper number once77 76 errorCode = usb_hub_check_hub_changes(hub_info); 77 async_usleep(1000 * 1000 );/// \TODO proper number once 78 78 } 79 79 usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode); -
uspace/drv/usbkbd/kbddev.c
r0053fa38 rd773285 56 56 #include <usb/classes/hidreq.h> 57 57 #include <usb/classes/hidreport.h> 58 #include <usb/classes/hid/utled.h>59 58 60 59 #include <usb/devdrv.h> … … 70 69 static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK; 71 70 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; 83 static const uint8_t ERROR_ROLLOVER = 1; 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; 84 82 85 83 /** Default idle rate for keyboards. */ … … 265 263 static void usb_kbd_set_led(usb_kbd_t *kbd_dev) 266 264 { 267 u nsigned 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;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; 283 281 } 284 282 … … 286 284 287 285 usb_log_debug("Creating output report.\n"); 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"); 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)); 296 291 return; 297 292 } 298 293 299 294 usb_log_debug("Output report buffer: %s\n", 300 usb_debug_str_buffer(kbd_dev->output_buffer, kbd_dev->output_size, 301 0)); 295 usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0)); 296 297 assert(kbd_dev->usb_dev != NULL); 302 298 303 299 usbhid_req_set_report(&kbd_dev->usb_dev->ctrl_pipe, 304 300 kbd_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT, 305 kbd_dev->output_buffer, kbd_dev->output_size);301 buffer, BOOTP_BUFFER_OUT_SIZE); 306 302 } 307 303 … … 454 450 * First of all, check if the kbd have reported phantom state. 455 451 * 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. 452 * this must be changed as we don't know which keys are modifiers 453 * and which are regular keys. 460 454 */ 461 455 i = 0; 462 while (i < count && key_codes[i] != ERROR_ROLLOVER) { 456 // all fields should report Error Rollover 457 while (i < count && 458 key_codes[i] == BOOTP_ERROR_ROLLOVER) { 463 459 ++i; 464 460 } 465 if (i != count) {461 if (i == count) { 466 462 usb_log_debug("Phantom state occured.\n"); 467 463 // phantom state, do nothing … … 590 586 */ 591 587 static void usb_kbd_process_data(usb_kbd_t *kbd_dev, 592 uint8_t *buffer, size_t actual_size)588 uint8_t *buffer, size_t actual_size) 593 589 { 594 590 assert(kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED); … … 764 760 usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count); 765 761 766 kbd_dev->keys = (uint8_t *)calloc(kbd_dev->key_count, sizeof(uint8_t)); 762 kbd_dev->keys = (uint8_t *)calloc( 763 kbd_dev->key_count, sizeof(uint8_t)); 767 764 768 765 if (kbd_dev->keys == NULL) { … … 771 768 } 772 769 773 /*774 * Output report775 */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 locks810 */811 770 kbd_dev->modifiers = 0; 812 771 kbd_dev->mods = DEFAULT_ACTIVE_MODS; 813 772 kbd_dev->lock_keys = 0; 814 773 815 /*816 * Autorepeat817 */818 774 kbd_dev->repeat.key_new = 0; 819 775 kbd_dev->repeat.key_repeated = 0; … … 923 879 } 924 880 925 // free the output buffer926 usb_hid_report_output_free((*kbd_dev)->output_buffer);927 928 881 /* TODO: what about the USB device structure?? */ 929 882 -
uspace/drv/usbkbd/kbddev.h
r0053fa38 rd773285 94 94 /** Report descriptor size. */ 95 95 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;106 96 107 97 /** HID Report parser. */ -
uspace/lib/c/Makefile
r0053fa38 rd773285 77 77 generic/io/io.c \ 78 78 generic/io/printf.c \ 79 generic/io/log.c \80 79 generic/io/klog.c \ 81 80 generic/io/snprintf.c \ -
uspace/lib/c/generic/devman.c
r0053fa38 rd773285 147 147 ret = devman_send_match_id(phone, match_id); 148 148 if (ret != EOK) { 149 printf("Driver failed to send match id, error %d\n", 150 ret); 149 151 return ret; 150 152 } … … 193 195 } 194 196 195 int match_ids_rc =devman_send_match_ids(phone, match_ids);197 devman_send_match_ids(phone, match_ids); 196 198 197 199 async_wait_for(req, &retval); … … 199 201 async_serialize_end(); 200 202 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 206 203 if (retval == EOK) 207 204 fun_handle = (int) IPC_GET_ARG1(answer); … … 329 326 } 330 327 331 int 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 376 328 377 329 /** @} -
uspace/lib/c/include/devman.h
r0053fa38 rd773285 53 53 extern int devman_device_get_handle(const char *, devman_handle_t *, 54 54 unsigned int); 55 extern int devman_device_get_handle_by_class(const char *, const char *,56 devman_handle_t *, unsigned int);57 55 58 56 extern int devman_add_device_to_class(devman_handle_t, const char *); -
uspace/lib/c/include/ipc/devman.h
r0053fa38 rd773285 148 148 149 149 typedef enum { 150 DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD, 151 DEVMAN_DEVICE_GET_HANDLE_BY_CLASS 150 DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD 152 151 } client_to_devman_t; 153 152 -
uspace/lib/drv/Makefile
r0053fa38 rd773285 36 36 generic/dev_iface.c \ 37 37 generic/remote_char_dev.c \ 38 generic/log.c \39 38 generic/remote_hw_res.c \ 40 39 generic/remote_usb.c \ -
uspace/lib/drv/generic/driver.c
r0053fa38 rd773285 273 273 274 274 res = driver->driver_ops->add_device(dev); 275 if (res != EOK) 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); 276 281 delete_device(dev); 282 } 277 283 278 284 async_answer_0(iid, res); -
uspace/lib/usb/include/usb/classes/hidparser.h
r0053fa38 rd773285 31 31 */ 32 32 /** @file 33 * USB HID report descriptor and report data parser33 * @brief USB HID parser. 34 34 */ 35 35 #ifndef LIBUSB_HIDPARSER_H_ … … 74 74 #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 4 75 75 76 /** */ 77 typedef struct { 78 /** */ 76 typedef struct { 79 77 int32_t usage_page; 80 /** */81 78 int32_t usage; 82 /** */ 79 83 80 link_t link; 84 81 } usb_hid_report_usage_path_t; 85 82 86 /** */ 87 typedef struct { 88 /** */ 83 typedef struct { 89 84 int depth; 90 91 /** */92 85 link_t link; 93 86 } usb_hid_report_path_t; … … 97 90 */ 98 91 typedef struct { 99 /** */100 92 int32_t id; 101 /** */102 93 int32_t usage_minimum; 103 /** */104 94 int32_t usage_maximum; 105 /** */106 95 int32_t logical_minimum; 107 /** */108 96 int32_t logical_maximum; 109 /** */110 97 int32_t size; 111 /** */112 98 int32_t count; 113 /** */114 99 size_t offset; 115 /** */116 100 int32_t delimiter; 117 /** */ 101 118 102 int32_t unit_exponent; 119 /** */120 103 int32_t unit; 121 104 122 /** */ 105 /* 106 * some not yet used fields 107 */ 123 108 int32_t string_index; 124 /** */125 109 int32_t string_minimum; 126 /** */127 110 int32_t string_maximum; 128 /** */129 111 int32_t designator_index; 130 /** */131 112 int32_t designator_minimum; 132 /** */133 113 int32_t designator_maximum; 134 /** */135 114 int32_t physical_minimum; 136 /** */137 115 int32_t physical_maximum; 138 116 139 /** */140 117 uint8_t item_flags; 141 118 142 /** */143 119 usb_hid_report_path_t *usage_path; 144 /** */145 120 link_t link; 146 121 } usb_hid_report_item_t; … … 149 124 /** HID report parser structure. */ 150 125 typedef struct { 151 /** */152 126 link_t input; 153 /** */154 127 link_t output; 155 /** */156 128 link_t feature; 157 129 } usb_hid_report_parser_t; … … 182 154 } usb_hid_modifiers_t; 183 155 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 = 5191 //} usb_hid_led_t;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; 192 164 193 165 static const usb_hid_modifiers_t … … 218 190 219 191 /* 220 * Descriptor parser functions 221 */ 222 /** */ 192 * modifiers definitions 193 */ 194 195 int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size, 196 const usb_hid_report_in_callbacks_t *callbacks, void *arg); 197 198 int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size); 199 223 200 int usb_hid_parser_init(usb_hid_report_parser_t *parser); 224 225 /** */226 201 int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser, 227 202 const uint8_t *data, size_t size); 228 203 229 /** */230 void usb_hid_free_report_parser(usb_hid_report_parser_t *parser);231 232 /** */233 void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);234 235 /*236 * Boot protocol functions237 */238 /** */239 int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,240 const usb_hid_report_in_callbacks_t *callbacks, void *arg);241 242 /** */243 int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);244 245 246 /*247 * Input report parser functions248 */249 /** */250 204 int usb_hid_parse_report(const usb_hid_report_parser_t *parser, 251 205 const uint8_t *data, size_t size, … … 253 207 const usb_hid_report_in_callbacks_t *callbacks, void *arg); 254 208 255 /** */ 256 size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser, 209 int usb_hid_report_input_length(const usb_hid_report_parser_t *parser, 257 210 usb_hid_report_path_t *path, int flags); 258 211 259 212 260 261 /* 262 * usage path functions 263 */ 264 /* **/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 */ 265 218 usb_hid_report_path_t *usb_hid_report_path(void); 266 267 /** */268 219 void usb_hid_report_path_free(usb_hid_report_path_t *path); 269 270 /** */271 220 int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, int32_t usage_page, int32_t usage); 272 273 /** */274 221 void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path); 275 276 /** */277 222 void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path); 278 279 /** */280 223 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data); 281 282 /** */283 224 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, usb_hid_report_path_t *path, int flags); 284 285 /** */ 286 usb_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*/ 293 uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser, size_t *size); 294 295 /** Frees output report buffer*/ 296 void usb_hid_report_output_free(uint8_t *output); 297 298 /** Returns size of output for given usage path */ 299 size_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 */ 303 int 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); 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 307 233 #endif 308 234 /** -
uspace/lib/usb/src/devdrv.c
r0053fa38 rd773285 251 251 &dev->descriptors.configuration_size); 252 252 if (rc != EOK) { 253 usb_log_error("Failed retrieving configuration descriptor: %s. %s\n",253 usb_log_error("Failed retrieving configuration descriptor: %s.\n", 254 254 dev->ddf_dev->name, str_error(rc)); 255 255 return rc; -
uspace/lib/usb/src/hidparser.c
r0053fa38 rd773285 31 31 */ 32 32 /** @file 33 * HID report descriptor and report dataparser implementation.33 * @brief HID parser implementation. 34 34 */ 35 35 #include <usb/classes/hidparser.h> … … 40 40 #include <usb/debug.h> 41 41 42 /** */43 42 #define USB_HID_NEW_REPORT_ITEM 1 44 45 /** */46 43 #define USB_HID_NO_ACTION 2 47 48 /** */49 44 #define USB_HID_UNKNOWN_TAG -99 50 45 51 /* 52 * Private descriptor parser functions 53 */ 46 #define BAD_HACK_USAGE_PAGE 0x07 47 54 48 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size, 55 49 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path); … … 64 58 int usb_hid_report_reset_local_items(); 65 59 void usb_hid_free_report_list(link_t *head); 66 67 /*68 * Data translation private functions69 */70 60 int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size); 71 61 inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset); 72 62 int usb_hid_translate_data(usb_hid_report_item_t *item, const uint8_t *data, size_t j); 73 int32_t usb_hid_translate_data_reverse(usb_hid_report_item_t *item, int32_t value);74 63 int usb_pow(int a, int b); 75 64 76 // TODO: tohle ma bejt asi jinde 65 77 66 int usb_pow(int a, int b) 78 67 { … … 91 80 92 81 /** 93 * Initialize the report descriptor parser structure 94 * 95 * @param parser Report descriptor parser structure 96 * @return Error code 82 * 97 83 */ 98 84 int usb_hid_parser_init(usb_hid_report_parser_t *parser) 99 85 { 100 101 102 103 104 86 if(parser == NULL) { 87 return EINVAL; 88 } 89 90 list_initialize(&(parser->input)); 105 91 list_initialize(&(parser->output)); 106 92 list_initialize(&(parser->feature)); … … 178 164 // store current usage path 179 165 report_item->usage_path = usage_path; 166 167 // new current usage path 168 tmp_usage_path = usb_hid_report_path(); 180 169 181 // c lonepath to the new one182 tmp_usage_path = usb_hid_report_path_clone(usage_path);170 // copy old path to the new one 171 usb_hid_report_path_clone(tmp_usage_path, usage_path); 183 172 184 173 // swap … … 315 304 316 305 /** 317 * Parse one tag of the report descriptor318 306 * 319 307 * @param Tag to parse … … 403 391 * @return Error code 404 392 */ 393 405 394 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size, 406 395 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) … … 531 520 * Prints content of given list of report items. 532 521 * 533 * @param List of report items (usb_hid_report_item_t)522 * @param List of report items 534 523 * @return void 535 524 */ … … 563 552 path = path->next; 564 553 } 565 554 555 556 // usb_log_debug("\tUSAGE: %X\n", report_item->usage); 557 // usb_log_debug("\tUSAGE PAGE: %X\n", report_item->usage_page); 566 558 usb_log_debug("\tLOGMIN: %X\n", report_item->logical_minimum); 567 559 usb_log_debug("\tLOGMAX: %X\n", report_item->logical_maximum); … … 578 570 } 579 571 /** 580 * Prints content of given reportdescriptor in human readable format.581 * 582 * @param parserParsed descriptor to print572 * Prints content of given descriptor in human readable format. 573 * 574 * @param Parsed descriptor to print 583 575 * @return void 584 576 */ … … 603 595 * Releases whole linked list of report items 604 596 * 605 * @param head Head of list of report descriptor items (usb_hid_report_item_t) 606 * @return void 597 * 607 598 */ 608 599 void usb_hid_free_report_list(link_t *head) … … 636 627 } 637 628 638 /** Free s the HID report descriptorparser structure629 /** Free the HID report parser structure 639 630 * 640 631 * @param parser Opaque HID report parser structure 641 * @return void632 * @return Error code 642 633 */ 643 634 void usb_hid_free_report_parser(usb_hid_report_parser_t *parser) … … 669 660 const usb_hid_report_in_callbacks_t *callbacks, void *arg) 670 661 { 662 /* 663 * 664 * only key codes (usage page 0x07) will be processed 665 * other usages will be ignored 666 */ 671 667 link_t *list_item; 672 668 usb_hid_report_item_t *item; … … 680 676 return EINVAL; 681 677 } 682 683 /* get the size of result array */ 678 679 680 // get the size of result keycodes array 684 681 key_count = usb_hid_report_input_length(parser, path, flags); 685 682 … … 688 685 } 689 686 690 / * read data */687 // read data 691 688 list_item = parser->input.next; 692 689 while(list_item != &(parser->input)) { … … 722 719 } 723 720 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 */ 721 732 722 int usb_hid_translate_data(usb_hid_report_item_t *item, const uint8_t *data, size_t j) 733 723 { … … 806 796 } 807 797 808 /** 809 * 810 * 811 * @param parser 812 * @param path 813 * @param flags 814 * @return 815 */ 816 size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser, 798 int usb_hid_report_input_length(const usb_hid_report_parser_t *parser, 817 799 usb_hid_report_path_t *path, int flags) 818 800 { 819 size_t ret = 0;801 int ret = 0; 820 802 link_t *item; 821 803 usb_hid_report_item_t *report_item; 822 804 823 805 if(parser == NULL) { 824 return 0;825 } 826 827 item = parser->input.next;806 return EINVAL; 807 } 808 809 item = (&parser->input)->next; 828 810 while(&parser->input != item) { 829 811 report_item = list_get_instance(item, usb_hid_report_item_t, link); … … 842 824 /** 843 825 * 844 * @param usage_path845 * @param usage_page846 * @param usage847 * @return848 826 */ 849 827 int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, … … 867 845 /** 868 846 * 869 * @param usage_path870 * @return871 847 */ 872 848 void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path) … … 884 860 /** 885 861 * 886 * @param usage_path887 * @return888 862 */ 889 863 void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path) … … 899 873 /** 900 874 * 901 * @param usage_path902 * @param tag903 * @param data904 * @return905 875 */ 906 876 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data) … … 924 894 925 895 /** 926 * 927 * 928 * @param report_path 929 * @param path 930 * @param flags 931 * @return 896 * 932 897 */ 933 898 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, … … 984 949 break; 985 950 986 /* compare with only the end of path*/951 /* given path must be the end of the report one*/ 987 952 case USB_HID_PATH_COMPARE_END: 988 953 report_link = report_path->link.prev; … … 1027 992 /** 1028 993 * 1029 * @return1030 994 */ 1031 995 usb_hid_report_path_t *usb_hid_report_path(void) … … 1045 1009 /** 1046 1010 * 1047 * @param path1048 * @return void1049 1011 */ 1050 1012 void usb_hid_report_path_free(usb_hid_report_path_t *path) … … 1057 1019 1058 1020 /** 1059 * Clone content of given usage path to the new one 1060 * 1061 * @param usage_path 1062 * @return 1063 */ 1064 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path) 1021 * 1022 */ 1023 int usb_hid_report_path_clone(usb_hid_report_path_t *new_usage_path, usb_hid_report_path_t *usage_path) 1065 1024 { 1066 1025 usb_hid_report_usage_path_t *path_item; 1067 1026 link_t *path_link; 1068 usb_hid_report_path_t *new_usage_path = usb_hid_report_path (); 1069 1070 if(new_usage_path == NULL){ 1071 return NULL; 1072 } 1027 1073 1028 1074 1029 if(list_empty(&usage_path->link)){ 1075 return new_usage_path;1030 return EOK; 1076 1031 } 1077 1032 … … 1084 1039 } 1085 1040 1086 return new_usage_path;1087 }1088 1089 1090 /*** OUTPUT API **/1091 1092 /** Allocates output report buffer1093 *1094 * @param parser1095 * @param size1096 * @return1097 */1098 uint8_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 item1106 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 buffer1128 *1129 * @param output Output report buffer1130 * @return1131 */1132 void 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 path1141 *1142 * @param parser1143 * @param path1144 * @param flags1145 * @return1146 */1147 size_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 data1174 *1175 * @param parser1176 * @param path1177 * @param flags1178 * @param buffer1179 * @param size1180 * @param data1181 * @param data_size1182 * @return1183 */1184 int 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 item1219 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 //bitmap1225 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 bytu1232 if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) {1233 break; // TODO ErrorCode1234 }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 21247 1248 // konec prvniho -- dolni x bitu1249 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 bitu1258 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 1272 1041 return EOK; 1273 1042 } 1274 1043 1275 /**1276 *1277 * @param item1278 * @param value1279 * @return1280 */1281 int32_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 item1293 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 // bitmapa1311 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 1324 1044 1325 1045 /** -
uspace/lib/usb/src/request.c
r0053fa38 rd773285 529 529 return rc; 530 530 } 531 531 532 if (bare_config.descriptor_type != USB_DESCTYPE_CONFIGURATION) { 532 533 return ENOENT; -
uspace/srv/devman/devman.c
r0053fa38 rd773285 34 34 #include <fcntl.h> 35 35 #include <sys/stat.h> 36 #include <io/log.h>37 36 #include <ipc/driver.h> 38 37 #include <ipc/devman.h> … … 147 146 fibril_mutex_unlock(&drivers_list->drivers_mutex); 148 147 149 log_msg(LVL_NOTE, "Driver `%s' was added to the list of available " 150 "drivers.", drv->name); 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"); 151 158 } 152 159 … … 238 245 bool read_match_ids(const char *conf_path, match_id_list_t *ids) 239 246 { 240 log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);247 printf(NAME ": read_match_ids conf_path = %s.\n", conf_path); 241 248 242 249 bool suc = false; … … 248 255 fd = open(conf_path, O_RDONLY); 249 256 if (fd < 0) { 250 log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.", 251 conf_path, str_error(fd)); 257 printf(NAME ": unable to open %s\n", conf_path); 252 258 goto cleanup; 253 259 } … … 257 263 lseek(fd, 0, SEEK_SET); 258 264 if (len == 0) { 259 log_msg(LVL_ERROR, "Configuration file '%s' is empty.", 260 conf_path); 265 printf(NAME ": configuration file '%s' is empty.\n", conf_path); 261 266 goto cleanup; 262 267 } … … 264 269 buf = malloc(len + 1); 265 270 if (buf == NULL) { 266 log_msg(LVL_ERROR, "Memory allocation failed when parsing file "267 "'%s'. ", conf_path);271 printf(NAME ": memory allocation failed when parsing file " 272 "'%s'.\n", conf_path); 268 273 goto cleanup; 269 274 } … … 271 276 ssize_t read_bytes = safe_read(fd, buf, len); 272 277 if (read_bytes <= 0) { 273 log_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);278 printf(NAME ": unable to read file '%s'.\n", conf_path); 274 279 goto cleanup; 275 280 } … … 309 314 bool get_driver_info(const char *base_path, const char *name, driver_t *drv) 310 315 { 311 log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")",316 printf(NAME ": get_driver_info base_path = %s, name = %s.\n", 312 317 base_path, name); 313 318 … … 341 346 struct stat s; 342 347 if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */ 343 log_msg(LVL_ERROR, "Driver not found at path `%s'.", 344 drv->binary_path); 348 printf(NAME ": driver not found at path %s.", drv->binary_path); 345 349 goto cleanup; 346 350 } … … 369 373 int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path) 370 374 { 371 log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path);375 printf(NAME ": lookup_available_drivers, dir = %s \n", dir_path); 372 376 373 377 int drv_cnt = 0; … … 403 407 dev_node_t *dev; 404 408 405 log_msg(LVL_DEBUG, "create_root_nodes()");409 printf(NAME ": create_root_nodes\n"); 406 410 407 411 fibril_rwlock_write_lock(&tree->rwlock); … … 488 492 void attach_driver(dev_node_t *dev, driver_t *drv) 489 493 { 490 log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")",491 d ev->pfun->pathname, drv->name);494 printf(NAME ": attach_driver %s to device %s\n", 495 drv->name, dev->pfun->pathname); 492 496 493 497 fibril_mutex_lock(&drv->driver_mutex); … … 511 515 assert(fibril_mutex_is_locked(&drv->driver_mutex)); 512 516 513 log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);517 printf(NAME ": start_driver '%s'\n", drv->name); 514 518 515 519 rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL); 516 520 if (rc != EOK) { 517 log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",518 drv->name, drv->binary_path,str_error(rc));521 printf(NAME ": error spawning %s (%s)\n", 522 drv->name, str_error(rc)); 519 523 return false; 520 524 } … … 578 582 int phone; 579 583 580 log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")", 581 driver->name); 584 printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name); 582 585 583 586 fibril_mutex_lock(&driver->driver_mutex); … … 646 649 * immediately and possibly started here as well. 647 650 */ 648 log_msg(LVL_DEBUG, "Driver `%s' enters running state.", driver->name);651 printf(NAME ": driver %s goes into running state.\n", driver->name); 649 652 driver->state = DRIVER_RUNNING; 650 653 … … 663 666 void initialize_running_driver(driver_t *driver, dev_tree_t *tree) 664 667 { 665 log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")", 666 driver->name); 668 printf(NAME ": initialize_running_driver (`%s')\n", driver->name); 667 669 668 670 /* … … 754 756 * access any structures that would affect driver_t. 755 757 */ 756 log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")",757 d rv->name, dev->pfun->name);758 printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name, 759 dev->pfun->name); 758 760 759 761 sysarg_t rc; … … 816 818 driver_t *drv = find_best_match_driver(drivers_list, dev); 817 819 if (drv == NULL) { 818 log_msg(LVL_ERROR, "No driver found for device `%s'.",820 printf(NAME ": no driver found for device '%s'.\n", 819 821 dev->pfun->pathname); 820 822 return false; … … 854 856 bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list) 855 857 { 856 log_msg(LVL_DEBUG, "init_device_tree()");858 printf(NAME ": init_device_tree.\n"); 857 859 858 860 tree->current_handle = 0; … … 1033 1035 fun->pathname = (char *) malloc(pathsize); 1034 1036 if (fun->pathname == NULL) { 1035 log_msg(LVL_ERROR, "Failed to allocate device path.");1037 printf(NAME ": failed to allocate device path.\n"); 1036 1038 return false; 1037 1039 } … … 1064 1066 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 1065 1067 1066 log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])",1067 dev, pfun, pfun->pathname);1068 1069 1068 /* Add the node to the handle-to-node map. */ 1070 1069 dev->handle = ++tree->current_handle; … … 1073 1072 1074 1073 /* Add the node to the list of its parent's children. */ 1074 printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun); 1075 1075 dev->pfun = pfun; 1076 1076 pfun->child = dev; … … 1173 1173 } 1174 1174 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 */1184 fun_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. */1205 fun_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 1234 1175 /** Find child function node with a specified name. 1235 1176 * … … 1242 1183 fun_node_t *find_node_child(fun_node_t *pfun, const char *name) 1243 1184 { 1244 return find_fun_node_in_device(pfun->child, name); 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; 1245 1200 } 1246 1201 … … 1404 1359 } 1405 1360 1406 dev_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 1426 1361 void init_class_list(class_list_t *class_list) 1427 1362 { -
uspace/srv/devman/devman.h
r0053fa38 rd773285 338 338 extern fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle); 339 339 extern fun_node_t *find_fun_node_by_path(dev_tree_t *, char *); 340 extern fun_node_t *find_fun_node_in_device(dev_node_t *, const char *);341 extern fun_node_t *find_fun_node_by_class(class_list_t *, const char *, const char *);342 340 343 341 /* Device tree */ … … 361 359 extern dev_class_t *get_dev_class(class_list_t *, char *); 362 360 extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *); 363 extern dev_class_info_t *find_dev_in_class(dev_class_t *, const char *);364 361 extern void add_dev_class_no_lock(class_list_t *, dev_class_t *); 365 362 -
uspace/srv/devman/main.c
r0053fa38 rd773285 43 43 #include <stdio.h> 44 44 #include <errno.h> 45 #include <str_error.h>46 45 #include <bool.h> 47 46 #include <fibril_synch.h> … … 52 51 #include <sys/stat.h> 53 52 #include <ctype.h> 54 #include <io/log.h>55 53 #include <ipc/devman.h> 56 54 #include <ipc/driver.h> … … 73 71 driver_t *driver = NULL; 74 72 75 log_msg(LVL_DEBUG, "devman_driver_register");73 printf(NAME ": devman_driver_register \n"); 76 74 77 75 iid = async_get_call(&icall); … … 90 88 } 91 89 92 log_msg(LVL_DEBUG, "The `%s' driver is trying to register.",90 printf(NAME ": the %s driver is trying to register by the service.\n", 93 91 drv_name); 94 92 … … 97 95 98 96 if (driver == NULL) { 99 log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name);97 printf(NAME ": no driver named %s was found.\n", drv_name); 100 98 free(drv_name); 101 99 drv_name = NULL; … … 108 106 109 107 /* Create connection to the driver. */ 110 log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.", 111 driver->name); 108 printf(NAME ": creating connection to the %s driver.\n", driver->name); 112 109 ipc_call_t call; 113 110 ipc_callid_t callid = async_get_call(&call); … … 121 118 set_driver_phone(driver, IPC_GET_ARG5(call)); 122 119 123 log_msg(LVL_NOTE, 124 "The `%s' driver was successfully registered as running.", 120 printf(NAME ": the %s driver was successfully registered as running.\n", 125 121 driver->name); 126 122 … … 146 142 callid = async_get_call(&call); 147 143 if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) { 148 log_msg(LVL_ERROR,149 " Invalid protocol when trying to receive match id.");144 printf(NAME ": ERROR: devman_receive_match_id - invalid " 145 "protocol.\n"); 150 146 async_answer_0(callid, EINVAL); 151 147 delete_match_id(match_id); … … 154 150 155 151 if (match_id == NULL) { 156 log_msg(LVL_ERROR, "Failed to allocate match id."); 152 printf(NAME ": ERROR: devman_receive_match_id - failed to " 153 "allocate match id.\n"); 157 154 async_answer_0(callid, ENOMEM); 158 155 return ENOMEM; … … 168 165 if (rc != EOK) { 169 166 delete_match_id(match_id); 170 log_msg(LVL_ERROR, "Failed to receive match id string: %s.",171 str_error(rc));167 printf(NAME ": devman_receive_match_id - failed to receive " 168 "match id string.\n"); 172 169 return rc; 173 170 } … … 175 172 list_append(&match_id->link, &match_ids->ids); 176 173 177 log_msg(LVL_DEBUG, "Received match id `%s', score %d.",174 printf(NAME ": received match id '%s', score = %d \n", 178 175 match_id->id, match_id->score); 179 176 return rc; … … 231 228 if (ftype != fun_inner && ftype != fun_exposed) { 232 229 /* Unknown function type */ 233 log_msg(LVL_ERROR, 234 "Unknown function type %d provided by driver.", 235 (int) ftype); 230 printf(NAME ": Error, unknown function type provided by driver!\n"); 236 231 237 232 fibril_rwlock_write_unlock(&tree->rwlock); … … 248 243 } 249 244 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 260 245 fun_node_t *fun = create_fun_node(); 261 246 if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) { … … 280 265 fibril_rwlock_write_unlock(&tree->rwlock); 281 266 282 log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname);267 printf(NAME ": devman_add_function %s\n", fun->pathname); 283 268 284 269 devman_receive_match_ids(match_count, &fun->match_ids); … … 362 347 devmap_register_class_dev(class_info); 363 348 364 log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.",365 fun->pathname, class_name, class_info->dev_name);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); 366 351 367 352 async_answer_0(callid, EOK); … … 378 363 379 364 initialize_running_driver(driver, &device_tree); 380 log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.",365 printf(NAME ": the %s driver was successfully initialized. \n", 381 366 driver->name); 382 367 return 0; … … 400 385 fid_t fid = fibril_create(init_running_drv, driver); 401 386 if (fid == 0) { 402 log_msg(LVL_ERROR, "Failed to create initialization fibril " \403 " for driver `%s'.", driver->name);387 printf(NAME ": Error creating fibril for the initialization of " 388 "the newly registered running driver.\n"); 404 389 return; 405 390 } … … 453 438 } 454 439 455 /** Find handle for the device instance identified by device class name. */456 static 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 489 440 490 441 /** Function for handling connections from a client to the device manager. */ … … 506 457 devman_function_get_handle(callid, &call); 507 458 break; 508 case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:509 devman_function_get_handle_by_class(callid, &call);510 break;511 459 default: 512 460 async_answer_0(callid, ENOENT); … … 536 484 */ 537 485 if (dev == NULL) { 538 log_msg(LVL_ERROR, "IPC forwarding failed - no device or"539 " function with handle %" PRIun " was found.", handle);486 printf(NAME ": devman_forward error - no device or function with " 487 "handle %" PRIun " was found.\n", handle); 540 488 async_answer_0(iid, ENOENT); 541 489 return; … … 543 491 544 492 if (fun == NULL && !drv_to_parent) { 545 log_msg(LVL_ERROR, NAME ": devman_forward error - cannot " 546 "connect to handle %" PRIun ", refers to a device.", 547 handle); 493 printf(NAME ": devman_forward error - cannot connect to " 494 "handle %" PRIun ", refers to a device.\n", handle); 548 495 async_answer_0(iid, ENOENT); 549 496 return; … … 566 513 567 514 if (driver == NULL) { 568 log_msg(LVL_ERROR, "IPC forwarding refused - "\569 " the device %" PRIun "(%s) is not in usable state.",515 printf(NAME ": devman_forward error - the device %" PRIun \ 516 " (%s) is not in usable state.\n", 570 517 handle, dev->pfun->pathname); 571 518 async_answer_0(iid, ENOENT); … … 580 527 581 528 if (driver->phone <= 0) { 582 log_msg(LVL_ERROR,583 "Could not forward to driver `%s' (phone is %d).",584 driver->name, (int)driver->phone);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); 585 532 async_answer_0(iid, EINVAL); 586 533 return; … … 588 535 589 536 if (fun != NULL) { 590 log_msg(LVL_DEBUG, 591 "Forwarding request for `%s' function to driver `%s'.", 592 fun->pathname, driver->name); 537 printf(NAME ": devman_forward: forward connection to function %s to " 538 "driver %s.\n", fun->pathname, driver->name); 593 539 } else { 594 log_msg(LVL_DEBUG, 595 "Forwarding request for `%s' device to driver `%s'.", 596 dev->pfun->pathname, driver->name); 540 printf(NAME ": devman_forward: forward connection to device %s to " 541 "driver %s.\n", dev->pfun->pathname, driver->name); 597 542 } 598 543 … … 626 571 async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0, 627 572 IPC_FF_NONE); 628 log_msg(LVL_DEBUG, 629 "Forwarding devmapper request for `%s' function to driver `%s'.", 630 fun->pathname, dev->drv->name); 573 printf(NAME ": devman_connection_devmapper: forwarded connection to " 574 "device %s to driver %s.\n", fun->pathname, dev->drv->name); 631 575 } 632 576 … … 663 607 static bool devman_init(void) 664 608 { 665 log_msg(LVL_DEBUG, "devman_init - looking for available drivers.");609 printf(NAME ": devman_init - looking for available drivers.\n"); 666 610 667 611 /* Initialize list of available drivers. */ … … 669 613 if (lookup_available_drivers(&drivers_list, 670 614 DRIVER_DEFAULT_STORE) == 0) { 671 log_msg(LVL_FATAL, "No drivers found.");615 printf(NAME " no drivers found."); 672 616 return false; 673 617 } 674 618 675 log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.");619 printf(NAME ": devman_init - list of drivers has been initialized.\n"); 676 620 677 621 /* Create root device node. */ 678 622 if (!init_device_tree(&device_tree, &drivers_list)) { 679 log_msg(LVL_FATAL, "Failed to initialize device tree.");623 printf(NAME " failed to initialize device tree."); 680 624 return false; 681 625 } … … 698 642 printf(NAME ": HelenOS Device Manager\n"); 699 643 700 if (log_init(NAME, LVL_ERROR) != EOK) {701 printf(NAME ": Error initializing logging subsystem.\n");702 return -1;703 }704 705 644 if (!devman_init()) { 706 log_msg(LVL_ERROR, "Error while initializing service.");645 printf(NAME ": Error while initializing service\n"); 707 646 return -1; 708 647 } … … 712 651 713 652 /* Register device manager at naming service. */ 714 if (service_register(SERVICE_DEVMAN) != EOK) { 715 log_msg(LVL_ERROR, "Failed registering as a service."); 653 if (service_register(SERVICE_DEVMAN) != EOK) 716 654 return -1; 717 } 718 719 printf(NAME ": Accepting connections.\n"); 655 656 printf(NAME ": Accepting connections\n"); 720 657 async_manager(); 721 658 -
uspace/srv/devmap/devmap.c
r0053fa38 rd773285 551 551 if (devmap_device_find_name(namespace->name, device->name) != NULL) { 552 552 printf("%s: Device '%s/%s' already registered\n", NAME, 553 namespace->name, device->name);553 device->namespace->name, device->name); 554 554 devmap_namespace_destroy(namespace); 555 555 fibril_mutex_unlock(&devices_list_mutex);
Note:
See TracChangeset
for help on using the changeset viewer.