Changeset c593b21 in mainline for uspace/drv
- Timestamp:
- 2011-04-03T18:06:29Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c4e0b47
- Parents:
- 0b4e7ca (diff), 0cec844d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/drv
- Files:
-
- 22 edited
-
isa/isa.c (modified) (13 diffs)
-
ns8250/ns8250.c (modified) (21 diffs)
-
ohci/hc.c (modified) (7 diffs)
-
ohci/hc.h (modified) (2 diffs)
-
ohci/iface.c (modified) (2 diffs)
-
ohci/ohci.c (modified) (4 diffs)
-
ohci/ohci_regs.h (modified) (2 diffs)
-
ohci/root_hub.c (modified) (12 diffs)
-
ohci/root_hub.h (modified) (2 diffs)
-
pciintel/pci.c (modified) (17 diffs)
-
root/root.c (modified) (12 diffs)
-
rootpc/rootpc.c (modified) (6 diffs)
-
rootvirt/rootvirt.c (modified) (6 diffs)
-
test1/test1.c (modified) (6 diffs)
-
test2/test2.c (modified) (10 diffs)
-
uhci-hcd/hc.c (modified) (5 diffs)
-
uhci-hcd/hc.h (modified) (2 diffs)
-
uhci-hcd/iface.c (modified) (2 diffs)
-
usbhub/port_status.h (modified) (1 diff)
-
usbhub/usbhub.c (modified) (6 diffs)
-
usbkbd/kbddev.c (modified) (9 diffs)
-
usbkbd/kbddev.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/isa/isa.c
r0b4e7ca rc593b21 53 53 54 54 #include <ddf/driver.h> 55 #include <ddf/log.h> 55 56 #include <ops/hw_res.h> 56 57 … … 134 135 fd = open(conf_path, O_RDONLY); 135 136 if (fd < 0) { 136 printf(NAME ": unable to open %s\n", conf_path);137 ddf_msg(LVL_ERROR, "Unable to open %s", conf_path); 137 138 goto cleanup; 138 139 } … … 141 142 142 143 len = lseek(fd, 0, SEEK_END); 143 lseek(fd, 0, SEEK_SET); 144 lseek(fd, 0, SEEK_SET); 144 145 if (len == 0) { 145 printf(NAME ": fun_conf_read error: configuration file '%s' "146 "is empty.\n",conf_path);146 ddf_msg(LVL_ERROR, "Configuration file '%s' is empty.", 147 conf_path); 147 148 goto cleanup; 148 149 } … … 150 151 buf = malloc(len + 1); 151 152 if (buf == NULL) { 152 printf(NAME ": fun_conf_read error: memory allocation failed.\n");153 ddf_msg(LVL_ERROR, "Memory allocation failed."); 153 154 goto cleanup; 154 155 } 155 156 156 157 if (0 >= read(fd, buf, len)) { 157 printf(NAME ": fun_conf_read error: unable to read file '%s'.\n", 158 conf_path); 158 ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path); 159 159 goto cleanup; 160 160 } … … 252 252 fun->hw_resources.count++; 253 253 254 printf(NAME ": added irq 0x%x to function %s\n", irq,254 ddf_msg(LVL_NOTE, "Added irq 0x%x to function %s", irq, 255 255 fun->fnode->name); 256 256 } … … 270 270 fun->hw_resources.count++; 271 271 272 printf(NAME ": added io range (addr=0x%x, size=0x%x) to "273 "function %s \n", (unsigned int) addr, (unsigned int) len,272 ddf_msg(LVL_NOTE, "Added io range (addr=0x%x, size=0x%x) to " 273 "function %s", (unsigned int) addr, (unsigned int) len, 274 274 fun->fnode->name); 275 275 } … … 331 331 score = (int)strtol(val, &end, 10); 332 332 if (val == end) { 333 printf(NAME " : error - could not read match score for"334 " function %s.\n", fun->fnode->name);333 ddf_msg(LVL_ERROR, "Cannot read match score for function " 334 "%s.", fun->fnode->name); 335 335 return; 336 336 } … … 339 339 get_match_id(&id, val); 340 340 if (id == NULL) { 341 printf(NAME " : error - could not read match id for "342 "function %s.\n",fun->fnode->name);341 ddf_msg(LVL_ERROR, "Cannot read match ID for function %s.", 342 fun->fnode->name); 343 343 return; 344 344 } 345 345 346 printf(NAME ": adding match id '%s' with score %d to function %s\n", id,347 score, fun->fnode->name);346 ddf_msg(LVL_DEBUG, "Adding match id '%s' with score %d to " 347 "function %s", id, score, fun->fnode->name); 348 348 349 349 rc = ddf_fun_add_match_id(fun->fnode, id, score); 350 if (rc != EOK) 351 printf(NAME ": error adding match ID: %s\n", str_error(rc)); 350 if (rc != EOK) { 351 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", 352 str_error(rc)); 353 } 352 354 } 353 355 … … 375 377 if (!prop_parse(fun, line, "io_range", &fun_parse_io_range) && 376 378 !prop_parse(fun, line, "irq", &fun_parse_irq) && 377 !prop_parse(fun, line, "match", &fun_parse_match_id)) 378 { 379 printf(NAME " error undefined device property at line '%s'\n",380 line);379 !prop_parse(fun, line, "match", &fun_parse_match_id)) { 380 381 ddf_msg(LVL_ERROR, "Undefined device property at line '%s'", 382 line); 381 383 } 382 384 } … … 439 441 fun->fnode->ops = &isa_fun_ops; 440 442 441 printf(NAME ": Binding function %s.\n", fun->fnode->name);443 ddf_msg(LVL_DEBUG, "Binding function %s.", fun->fnode->name); 442 444 443 445 /* XXX Handle error */ … … 467 469 static int isa_add_device(ddf_dev_t *dev) 468 470 { 469 printf(NAME ": isa_add_device, device handle = %d\n",471 ddf_msg(LVL_DEBUG, "isa_add_device, device handle = %d", 470 472 (int) dev->handle); 471 473 472 474 /* Make the bus device more visible. Does not do anything. */ 473 printf(NAME ": adding a 'ctl' function\n");475 ddf_msg(LVL_DEBUG, "Adding a 'ctl' function"); 474 476 475 477 ddf_fun_t *ctl = ddf_fun_create(dev, fun_exposed, "ctl"); 476 478 if (ctl == NULL) { 477 printf(NAME ": Error creating control function.\n");479 ddf_msg(LVL_ERROR, "Failed creating control function."); 478 480 return EXDEV; 479 481 } 480 482 481 483 if (ddf_fun_bind(ctl) != EOK) { 482 printf(NAME ": Error binding control function.\n");484 ddf_msg(LVL_ERROR, "Failed binding control function."); 483 485 return EXDEV; 484 486 } … … 486 488 /* Add functions as specified in the configuration file. */ 487 489 isa_functions_add(dev); 488 printf(NAME ": finished the enumeration of legacy functions\n");490 ddf_msg(LVL_NOTE, "Finished enumerating legacy functions"); 489 491 490 492 return EOK; … … 493 495 static void isa_init() 494 496 { 497 ddf_log_init(NAME, LVL_ERROR); 495 498 isa_fun_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops; 496 499 } -
uspace/drv/ns8250/ns8250.c
r0b4e7ca rc593b21 55 55 #include <ddf/driver.h> 56 56 #include <ddf/interrupt.h> 57 #include <ddf/log.h> 57 58 #include <ops/char_dev.h> 58 59 … … 275 276 static bool ns8250_pio_enable(ns8250_t *ns) 276 277 { 277 printf(NAME ": ns8250_pio_enable %s\n", ns->dev->name);278 ddf_msg(LVL_DEBUG, "ns8250_pio_enable %s", ns->dev->name); 278 279 279 280 /* Gain control over port's registers. */ 280 281 if (pio_enable((void *)(uintptr_t) ns->io_addr, REG_COUNT, 281 282 (void **) &ns->port)) { 282 printf(NAME ": error - cannot gain the port %#" PRIx32 " for device "283 " %s.\n", ns->io_addr, ns->dev->name);283 ddf_msg(LVL_ERROR, "Cannot map the port %#" PRIx32 284 " for device %s.", ns->io_addr, ns->dev->name); 284 285 return false; 285 286 } … … 295 296 static bool ns8250_dev_probe(ns8250_t *ns) 296 297 { 297 printf(NAME ": ns8250_dev_probe %s\n", ns->dev->name);298 ddf_msg(LVL_DEBUG, "ns8250_dev_probe %s", ns->dev->name); 298 299 299 300 ioport8_t *port_addr = ns->port; … … 313 314 pio_write_8(port_addr + 4, olddata); 314 315 315 if (!res) 316 printf(NAME ": device %s is not present.\n", ns->dev->name); 316 if (!res) { 317 ddf_msg(LVL_DEBUG, "Device %s is not present.", 318 ns->dev->name); 319 } 317 320 318 321 return res; … … 326 329 static int ns8250_dev_initialize(ns8250_t *ns) 327 330 { 328 printf(NAME ": ns8250_dev_initialize %s\n", ns->dev->name);331 ddf_msg(LVL_DEBUG, "ns8250_dev_initialize %s", ns->dev->name); 329 332 330 333 int ret = EOK; … … 337 340 IPC_FLAG_BLOCKING); 338 341 if (ns->dev->parent_phone < 0) { 339 printf(NAME ": failed to connect to the parent driver of the"340 "device %s. \n", ns->dev->name);342 ddf_msg(LVL_ERROR, "Failed to connect to parent driver of " 343 "device %s.", ns->dev->name); 341 344 ret = ns->dev->parent_phone; 342 345 goto failed; … … 346 349 ret = hw_res_get_resource_list(ns->dev->parent_phone, &hw_resources); 347 350 if (ret != EOK) { 348 printf(NAME ": failed to get hw resources for thedevice "349 "%s. \n", ns->dev->name);351 ddf_msg(LVL_ERROR, "Failed to get HW resources for device " 352 "%s.", ns->dev->name); 350 353 goto failed; 351 354 } … … 362 365 ns->irq = res->res.interrupt.irq; 363 366 irq = true; 364 printf(NAME ": the %s device was asigned irq = 0x%x.\n",367 ddf_msg(LVL_NOTE, "Device %s was asigned irq = 0x%x.", 365 368 ns->dev->name, ns->irq); 366 369 break; … … 369 372 ns->io_addr = res->res.io_range.address; 370 373 if (res->res.io_range.size < REG_COUNT) { 371 printf(NAME ": i/o range assigned to the device"372 " %s is too small.\n", ns->dev->name);374 ddf_msg(LVL_ERROR, "I/O range assigned to " 375 "device %s is too small.", ns->dev->name); 373 376 ret = ELIMIT; 374 377 goto failed; 375 378 } 376 379 ioport = true; 377 printf(NAME ": the %s device was asigned i/oaddress = "378 "0x%x. \n", ns->dev->name, ns->io_addr);379 break;380 ddf_msg(LVL_NOTE, "Device %s was asigned I/O address = " 381 "0x%x.", ns->dev->name, ns->io_addr); 382 break; 380 383 381 384 default: … … 385 388 386 389 if (!irq || !ioport) { 387 printf(NAME ": missing hw resource(s) for the device %s.\n",390 ddf_msg(LVL_ERROR, "Missing HW resource(s) for device %s.", 388 391 ns->dev->name); 389 392 ret = ENOENT; … … 470 473 471 474 if (baud_rate < 50 || MAX_BAUD_RATE % baud_rate != 0) { 472 printf(NAME ": error - somebody tried to set invalid baud rate "473 "%d\n",baud_rate);475 ddf_msg(LVL_ERROR, "Invalid baud rate %d requested.", 476 baud_rate); 474 477 return EINVAL; 475 478 } … … 654 657 if (ns->client_connected) { 655 658 if (!buf_push_back(&ns->input_buffer, val)) { 656 printf(NAME ": buffer overflow on "657 "%s. \n", ns->dev->name);659 ddf_msg(LVL_WARN, "Buffer overflow on " 660 "%s.", ns->dev->name); 658 661 } else { 659 printf(NAME ": the character %c saved "660 "to the buffer of %s. \n",662 ddf_msg(LVL_DEBUG2, "Character %c saved " 663 "to the buffer of %s.", 661 664 val, ns->dev->name); 662 665 } … … 714 717 int rc; 715 718 716 printf(NAME ": ns8250_add_device %s (handle = %d)\n",719 ddf_msg(LVL_DEBUG, "ns8250_add_device %s (handle = %d)", 717 720 dev->name, (int) dev->handle); 718 721 … … 749 752 /* Register interrupt handler. */ 750 753 if (ns8250_register_interrupt_handler(ns) != EOK) { 751 printf(NAME ": failed to register interrupt handler.\n");754 ddf_msg(LVL_ERROR, "Failed to register interrupt handler."); 752 755 rc = EADDRNOTAVAIL; 753 756 goto fail; … … 757 760 rc = ns8250_interrupt_enable(ns); 758 761 if (rc != EOK) { 759 printf(NAME ": failed to enable the interrupt. Error code = "760 "%d. \n", rc);762 ddf_msg(LVL_ERROR, "Failed to enable the interrupt. Error code = " 763 "%d.", rc); 761 764 goto fail; 762 765 } … … 764 767 fun = ddf_fun_create(dev, fun_exposed, "a"); 765 768 if (fun == NULL) { 766 printf(NAME ": error creating function.\n");769 ddf_msg(LVL_ERROR, "Failed creating function."); 767 770 goto fail; 768 771 } … … 772 775 rc = ddf_fun_bind(fun); 773 776 if (rc != EOK) { 774 printf(NAME ": error binding function.\n");777 ddf_msg(LVL_ERROR, "Failed binding function."); 775 778 goto fail; 776 779 } … … 780 783 ddf_fun_add_to_class(fun, "serial"); 781 784 782 printf(NAME ": the %s device has been successfully initialized.\n",785 ddf_msg(LVL_NOTE, "Device %s successfully initialized.", 783 786 dev->name); 784 787 … … 862 865 fibril_mutex_unlock(&data->mutex); 863 866 864 printf(NAME ":ns8250_get_props: baud rate %d, parity 0x%x, word "865 "length %d, stop bits %d \n", *baud_rate, *parity, *word_length,867 ddf_msg(LVL_DEBUG, "ns8250_get_props: baud rate %d, parity 0x%x, word " 868 "length %d, stop bits %d", *baud_rate, *parity, *word_length, 866 869 *stop_bits); 867 870 } … … 879 882 unsigned int parity, unsigned int word_length, unsigned int stop_bits) 880 883 { 881 printf(NAME ":ns8250_set_props: baud rate %d, parity 0x%x, word "882 "length %d, stop bits %d \n", baud_rate, parity, word_length,884 ddf_msg(LVL_DEBUG, "ns8250_set_props: baud rate %d, parity 0x%x, word " 885 "length %d, stop bits %d", baud_rate, parity, word_length, 883 886 stop_bits); 884 887 … … 940 943 static void ns8250_init(void) 941 944 { 945 ddf_log_init(NAME, LVL_ERROR); 946 942 947 ns8250_dev_ops.open = &ns8250_open; 943 948 ns8250_dev_ops.close = &ns8250_close; -
uspace/drv/ohci/hc.c
r0b4e7ca rc593b21 45 45 46 46 static int interrupt_emulator(hc_t *instance); 47 static void hc_gain_control(hc_t *instance); 48 static void hc_init_hw(hc_t *instance); 47 49 /*----------------------------------------------------------------------------*/ 48 50 int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun) … … 58 60 59 61 char *match_str = NULL; 60 int ret = asprintf(&match_str, "usb& mid");62 int ret = asprintf(&match_str, "usb&class=hub"); 61 63 ret = (match_str == NULL) ? ret : EOK; 62 64 if (ret < 0) { … … 77 79 assert(instance); 78 80 int ret = EOK; 81 #define CHECK_RET_RETURN(ret, message...) \ 82 if (ret != EOK) { \ 83 usb_log_error(message); \ 84 return ret; \ 85 } else (void)0 79 86 80 87 ret = pio_enable((void*)regs, reg_size, (void**)&instance->registers); 81 if (ret != EOK) {82 usb_log_error("Failed to gain access to device registers.\n");83 return ret;84 } 88 CHECK_RET_RETURN(ret, 89 "Failed(%d) to gain access to device registers: %s.\n", 90 ret, str_error(ret)); 91 85 92 instance->ddf_instance = fun; 86 93 usb_device_keeper_init(&instance->manager); 94 ret = bandwidth_init(&instance->bandwidth, BANDWIDTH_AVAILABLE_USB11, 95 bandwidth_count_usb11); 96 CHECK_RET_RETURN(ret, "Failed to initialize bandwidth allocator: %s.\n", 97 ret, str_error(ret)); 87 98 88 99 if (!interrupts) { … … 92 103 } 93 104 105 hc_gain_control(instance); 106 94 107 rh_init(&instance->rh, dev, instance->registers); 108 109 hc_init_hw(instance); 95 110 96 111 /* TODO: implement */ … … 117 132 rh_interrupt(&instance->rh); 118 133 134 usb_log_info("OHCI interrupt: %x.\n", status); 135 119 136 /* TODO: Check for further interrupt causes */ 120 137 /* TODO: implement */ … … 126 143 usb_log_info("Started interrupt emulator.\n"); 127 144 while (1) { 128 uint32_t status = instance->registers->interrupt_status;145 const uint32_t status = instance->registers->interrupt_status; 129 146 instance->registers->interrupt_status = status; 130 147 hc_interrupt(instance, status); … … 133 150 return EOK; 134 151 } 152 /*----------------------------------------------------------------------------*/ 153 void hc_gain_control(hc_t *instance) 154 { 155 assert(instance); 156 /* Interrupt routing enabled => smm driver is active */ 157 if (instance->registers->control & C_IR) { 158 usb_log_info("Found SMM driver requesting ownership change.\n"); 159 instance->registers->command_status |= CS_OCR; 160 while (instance->registers->control & C_IR) { 161 async_usleep(1000); 162 } 163 usb_log_info("Ownership taken from SMM driver.\n"); 164 return; 165 } 166 167 const unsigned hc_status = 168 (instance->registers->control >> C_HCFS_SHIFT) & C_HCFS_MASK; 169 /* Interrupt routing disabled && status != USB_RESET => BIOS active */ 170 if (hc_status != C_HCFS_RESET) { 171 usb_log_info("Found BIOS driver.\n"); 172 if (hc_status == C_HCFS_OPERATIONAL) { 173 usb_log_info("HC operational(BIOS).\n"); 174 return; 175 } 176 /* HC is suspended assert resume for 20ms */ 177 instance->registers->control &= (C_HCFS_RESUME << C_HCFS_SHIFT); 178 async_usleep(20000); 179 return; 180 } 181 182 /* HC is in reset (hw startup) => no other driver 183 * maintain reset for at least the time specified in USB spec (50 ms)*/ 184 async_usleep(50000); 185 } 186 /*----------------------------------------------------------------------------*/ 187 void hc_init_hw(hc_t *instance) 188 { 189 assert(instance); 190 const uint32_t fm_interval = instance->registers->fm_interval; 191 instance->registers->command_status = CS_HCR; 192 async_usleep(10); 193 instance->registers->fm_interval = fm_interval; 194 assert((instance->registers->command_status & CS_HCR) == 0); 195 /* hc is now in suspend state */ 196 /* TODO: init HCCA block */ 197 /* TODO: init queues */ 198 /* TODO: enable queues */ 199 /* TODO: enable interrupts */ 200 /* TODO: set periodic start to 90% */ 201 202 instance->registers->control &= (C_HCFS_OPERATIONAL << C_HCFS_SHIFT); 203 usb_log_info("OHCI HC up and running.\n"); 204 } 135 205 /** 136 206 * @} -
uspace/drv/ohci/hc.h
r0b4e7ca rc593b21 42 42 #include <usb/usb.h> 43 43 #include <usb/host/device_keeper.h> 44 #include <usb/host/bandwidth.h> 44 45 #include <usbhc_iface.h> 45 46 … … 54 55 ddf_fun_t *ddf_instance; 55 56 usb_device_keeper_t manager; 57 bandwidth_t bandwidth; 56 58 fid_t interrupt_emulator; 57 59 } hc_t; -
uspace/drv/ohci/iface.c
r0b4e7ca rc593b21 151 151 size_t max_packet_size, unsigned int interval) 152 152 { 153 UNSUPPORTED("register_endpoint"); 154 155 return ENOTSUP; 153 assert(fun); 154 hc_t *hc = fun_to_hc(fun); 155 assert(hc); 156 if (address == hc->rh.address) 157 return EOK; 158 const usb_speed_t speed = 159 usb_device_keeper_get_speed(&hc->manager, address); 160 const size_t size = max_packet_size; 161 usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n", 162 address, endpoint, usb_str_transfer_type(transfer_type), 163 usb_str_speed(speed), direction, size, max_packet_size, interval); 164 return bandwidth_reserve(&hc->bandwidth, address, endpoint, direction, 165 speed, transfer_type, max_packet_size, size, interval); 156 166 } 157 167 /*----------------------------------------------------------------------------*/ … … 168 178 usb_endpoint_t endpoint, usb_direction_t direction) 169 179 { 170 UNSUPPORTED("unregister_endpoint"); 180 assert(fun); 181 hc_t *hc = fun_to_hc(fun); 182 assert(hc); 183 usb_log_debug("Unregister endpoint %d:%d %d.\n", 184 address, endpoint, direction); 185 return bandwidth_release(&hc->bandwidth, address, endpoint, direction); 171 186 172 187 return ENOTSUP; -
uspace/drv/ohci/ohci.c
r0b4e7ca rc593b21 31 31 */ 32 32 /** @file 33 * @brief UHCI driver33 * @brief OHCI driver 34 34 */ 35 35 #include <errno.h> … … 117 117 /** Initialize hc and rh ddf structures and their respective drivers. 118 118 * 119 * @param[in] instance UHCI structure to use.119 * @param[in] instance OHCI structure to use. 120 120 * @param[in] device DDF instance of the device to use. 121 121 * 122 122 * This function does all the preparatory work for hc and rh drivers: 123 123 * - gets device hw resources 124 * - disables UHCI legacy support124 * - disables OHCI legacy support 125 125 * - asks for interrupt 126 126 * - registers interrupt handler … … 185 185 ret = ddf_fun_bind(instance->hc_fun); 186 186 CHECK_RET_DEST_FUN_RETURN(ret, 187 "Failed(%d) to bind UHCI device function: %s.\n",187 "Failed(%d) to bind OHCI device function: %s.\n", 188 188 ret, str_error(ret)); 189 189 #undef CHECK_RET_HC_RETURN … … 216 216 ret = ddf_fun_bind(instance->rh_fun); 217 217 CHECK_RET_FINI_RETURN(ret, 218 "Failed(%d) to register UHCI root hub.\n", ret);218 "Failed(%d) to register OHCI root hub.\n", ret); 219 219 220 220 return EOK; -
uspace/drv/ohci/ohci_regs.h
r0b4e7ca rc593b21 39 39 typedef struct ohci_regs 40 40 { 41 volatile uint32_t revision;41 const volatile uint32_t revision; 42 42 volatile uint32_t control; 43 #define C_CSBR_MASK (0x3) 44 #define C_CSBR_SHIFT (0) 45 #define C_PLE (1 << 2) 46 #define C_IE (1 << 3) 47 #define C_CLE (1 << 4) 48 #define C_BLE (1 << 5) 49 50 #define C_HCFS_MASK (0x3) 51 #define C_HCFS_SHIFT (6) 52 #define C_HCFS_RESET (0x0) 53 #define C_HCFS_OPERATIONAL (0x1) 54 #define C_HCFS_RESUME (0x2) 55 #define C_HCFS_SUSPEND (0x3) 56 57 #define C_IR (1 << 8) 58 #define C_RWC (1 << 9) 59 #define C_RWE (1 << 10) 60 43 61 volatile uint32_t command_status; 62 #define CS_HCR (1 << 0) 63 #define CS_CLF (1 << 1) 64 #define CS_BLF (1 << 2) 65 #define CS_OCR (1 << 3) 66 #define CS_SOC_MASK (0x3) 67 #define CS_SOC_SHIFT (16) 68 44 69 volatile uint32_t interrupt_status; 45 70 #define IS_SO (1 << 0) … … 51 76 #define IS_RHSC (1 << 6) 52 77 #define IS_OC (1 << 30) 78 53 79 volatile uint32_t interupt_enable; 54 80 #define IE_SO (1 << 0) -
uspace/drv/ohci/root_hub.c
r0b4e7ca rc593b21 40 40 #include "root_hub.h" 41 41 #include "usb/classes/classes.h" 42 #include "usb/devdrv.h" 42 43 #include <usb/request.h> 43 44 #include <usb/classes/hub.h> … … 61 62 /// \TODO these values migt be different 62 63 .str_serial_number = 0, 63 .usb_spec_version = 0 ,64 .usb_spec_version = 0x110, 64 65 }; 65 66 … … 110 111 }; 111 112 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 113 static const uint32_t hub_clear_feature_valid_mask = 114 (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) + 115 (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT); 116 117 static const uint32_t hub_clear_feature_by_writing_one_mask = 118 1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER; 119 120 static const uint32_t hub_set_feature_valid_mask = 121 (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT); 122 126 123 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 } 124 static const uint32_t hub_set_feature_direct_mask = 125 (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT); 126 127 static const uint32_t port_set_feature_valid_mask = 128 (1 << USB_HUB_FEATURE_PORT_ENABLE) + 129 (1 << USB_HUB_FEATURE_PORT_SUSPEND) + 130 (1 << USB_HUB_FEATURE_PORT_RESET) + 131 (1 << USB_HUB_FEATURE_PORT_POWER); 132 133 static const uint32_t port_clear_feature_valid_mask = 134 (1 << USB_HUB_FEATURE_PORT_CONNECTION) + 135 (1 << USB_HUB_FEATURE_PORT_SUSPEND) + 136 (1 << USB_HUB_FEATURE_PORT_OVER_CURRENT) + 137 (1 << USB_HUB_FEATURE_PORT_POWER) + 138 (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) + 139 (1 << USB_HUB_FEATURE_C_PORT_ENABLE) + 140 (1 << USB_HUB_FEATURE_C_PORT_SUSPEND) + 141 (1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) + 142 (1 << USB_HUB_FEATURE_C_PORT_RESET); 143 //note that USB_HUB_FEATURE_PORT_POWER bit is translated into USB_HUB_FEATURE_PORT_LOW_SPEED 144 145 146 171 147 172 148 /** 173 149 * Create hub descriptor used in hub-driver <-> hub communication 174 * 150 * 175 151 * This means creating byt array from data in root hub registers. For more 176 152 * info see usb hub specification. … … 197 173 result[2] = instance->port_count; 198 174 uint32_t hub_desc_reg = instance->registers->rh_desc_a; 199 result[3] = 175 result[3] = 200 176 ((hub_desc_reg >> 8) %2) + 201 177 (((hub_desc_reg >> 9) %2) << 1) + … … 219 195 (*out_size) = size; 220 196 } 197 198 199 /** initialize hub descriptors 200 * 201 * Initialized are device and full configuration descriptor. These need to 202 * be initialized only once per hub. 203 * @instance root hub instance 204 */ 205 static void rh_init_descriptors(rh_t *instance){ 206 memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor, 207 sizeof(ohci_rh_device_descriptor) 208 ); 209 usb_standard_configuration_descriptor_t descriptor; 210 memcpy(&descriptor,&ohci_rh_conf_descriptor, 211 sizeof(ohci_rh_conf_descriptor)); 212 uint8_t * hub_descriptor; 213 size_t hub_desc_size; 214 usb_create_serialized_hub_descriptor(instance, &hub_descriptor, 215 &hub_desc_size); 216 217 descriptor.total_length = 218 sizeof(usb_standard_configuration_descriptor_t)+ 219 sizeof(usb_standard_endpoint_descriptor_t)+ 220 sizeof(usb_standard_interface_descriptor_t)+ 221 hub_desc_size; 222 223 uint8_t * full_config_descriptor = 224 (uint8_t*) malloc(descriptor.total_length); 225 memcpy(full_config_descriptor, &descriptor, sizeof(descriptor)); 226 memcpy(full_config_descriptor + sizeof(descriptor), 227 &ohci_rh_iface_descriptor, sizeof(ohci_rh_iface_descriptor)); 228 memcpy(full_config_descriptor + sizeof(descriptor) + 229 sizeof(ohci_rh_iface_descriptor), 230 &ohci_rh_ep_descriptor, sizeof(ohci_rh_ep_descriptor)); 231 memcpy(full_config_descriptor + sizeof(descriptor) + 232 sizeof(ohci_rh_iface_descriptor) + 233 sizeof(ohci_rh_ep_descriptor), 234 hub_descriptor, hub_desc_size); 235 236 instance->descriptors.configuration = full_config_descriptor; 237 instance->descriptors.configuration_size = descriptor.total_length; 238 } 239 240 /** Root hub initialization 241 * @return Error code. 242 */ 243 int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs) 244 { 245 assert(instance); 246 instance->address = -1; 247 instance->registers = regs; 248 instance->device = dev; 249 instance->port_count = instance->registers->rh_desc_a & 0xff; 250 rh_init_descriptors(instance); 251 /// \TODO set port power mode 252 253 254 usb_log_info("OHCI root hub with %d ports.\n", instance->port_count); 255 256 //start generic usb hub driver 257 258 /* TODO: implement */ 259 return EOK; 260 } 261 /*----------------------------------------------------------------------------*/ 262 263 /** 264 * create answer to port status_request 265 * 266 * Copy content of corresponding port status register to answer buffer. 267 * 268 * @param instance root hub instance 269 * @param port port number, counted from 1 270 * @param request structure containing both request and response information 271 * @return error code 272 */ 273 static int process_get_port_status_request(rh_t *instance, uint16_t port, 274 usb_transfer_batch_t * request){ 275 if(port<1 || port>instance->port_count) 276 return EINVAL; 277 uint32_t * uint32_buffer = (uint32_t*)request->transport_buffer; 278 request->transfered_size = 4; 279 uint32_buffer[0] = instance->registers->rh_port_status[port -1]; 280 return EOK; 281 } 282 283 /** 284 * create answer to port status_request 285 * 286 * Copy content of hub status register to answer buffer. 287 * 288 * @param instance root hub instance 289 * @param request structure containing both request and response information 290 * @return error code 291 */ 292 static int process_get_hub_status_request(rh_t *instance, 293 usb_transfer_batch_t * request){ 294 uint32_t * uint32_buffer = (uint32_t*)request->transport_buffer; 295 //bits, 0,1,16,17 296 request->transfered_size = 4; 297 uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17); 298 uint32_buffer[0] = mask & instance->registers->rh_status; 299 return EOK; 300 301 } 302 221 303 222 304 … … 284 366 } 285 367 } 286 287 /** 288 * create standart configuration descriptor for the root hub instance 289 * @param instance root hub instance 290 * @return newly allocated descriptor 291 */ 292 static usb_standard_configuration_descriptor_t * 293 usb_ohci_rh_create_standart_configuration_descriptor(rh_t *instance){ 294 usb_standard_configuration_descriptor_t * descriptor = 295 malloc(sizeof(usb_standard_configuration_descriptor_t)); 296 memcpy(descriptor, &ohci_rh_conf_descriptor, 297 sizeof(usb_standard_configuration_descriptor_t)); 298 /// \TODO should this include device descriptor? 299 const size_t hub_descriptor_size = 7 + 300 2* (instance->port_count / 8 + 301 ((instance->port_count % 8 > 0) ? 1 : 0)); 302 descriptor->total_length = 303 sizeof(usb_standard_configuration_descriptor_t)+ 304 sizeof(usb_standard_endpoint_descriptor_t)+ 305 sizeof(usb_standard_interface_descriptor_t)+ 306 hub_descriptor_size; 307 return descriptor; 308 } 309 368 310 369 /** 311 370 * create answer to a descriptor request … … 344 403 case USB_DESCTYPE_CONFIGURATION: { 345 404 usb_log_debug("USB_DESCTYPE_CONFIGURATION\n"); 346 usb_standard_configuration_descriptor_t * descriptor = 347 usb_ohci_rh_create_standart_configuration_descriptor( 348 instance); 349 result_descriptor = descriptor; 350 size = sizeof(usb_standard_configuration_descriptor_t); 351 del = true; 405 result_descriptor = instance->descriptors.configuration; 406 size = instance->descriptors.configuration_size; 352 407 break; 353 408 } … … 380 435 } 381 436 request->transfered_size = size; 382 memcpy(request->buffer,result_descriptor,size); 437 memcpy(request->transport_buffer,result_descriptor,size); 438 usb_log_debug("sent desctiptor: %s\n", 439 usb_debug_str_buffer((uint8_t*)request->transport_buffer,size,size)); 383 440 if (del) 384 441 free(result_descriptor); … … 400 457 if(request->buffer_size != 1) 401 458 return EINVAL; 402 request-> buffer[0] = 1;459 request->transport_buffer[0] = 1; 403 460 request->transfered_size = 1; 404 461 return EOK; … … 406 463 407 464 /** 408 * process feature-enabling /disablingrequest on hub465 * process feature-enabling request on hub 409 466 * 410 467 * @param instance root hub instance 411 468 * @param feature feature selector 412 * @param enable enable or disable specified feature413 469 * @return error code 414 470 */ 415 471 static int process_hub_feature_set_request(rh_t *instance, 416 uint16_t feature , bool enable){417 if( feature > USB_HUB_FEATURE_C_HUB_OVER_CURRENT)472 uint16_t feature){ 473 if(! ((1<<feature) & hub_set_feature_valid_mask)) 418 474 return EINVAL; 419 475 instance->registers->rh_status = 420 enable ?421 476 (instance->registers->rh_status | (1<<feature)) 422 : 423 (instance->registers->rh_status & (~(1<<feature))); 424 /// \TODO any error? 425 return EOK; 426 } 427 428 /** 429 * process feature-enabling/disabling request on hub 477 & (~ hub_clear_feature_by_writing_one_mask); 478 return EOK; 479 } 480 481 /** 482 * process feature-disabling request on hub 483 * 484 * @param instance root hub instance 485 * @param feature feature selector 486 * @return error code 487 */ 488 static int process_hub_feature_clear_request(rh_t *instance, 489 uint16_t feature){ 490 if(! ((1<<feature) & hub_clear_feature_valid_mask)) 491 return EINVAL; 492 //is the feature cleared directly? 493 if ((1<<feature) & hub_set_feature_direct_mask){ 494 instance->registers->rh_status = 495 (instance->registers->rh_status & (~(1<<feature))) 496 & (~ hub_clear_feature_by_writing_one_mask); 497 }else{//the feature is cleared by writing '1' 498 instance->registers->rh_status = 499 (instance->registers->rh_status 500 & (~ hub_clear_feature_by_writing_one_mask)) 501 | (1<<feature); 502 } 503 return EOK; 504 } 505 506 507 508 /** 509 * process feature-enabling request on hub 430 510 * 431 511 * @param instance root hub instance … … 436 516 */ 437 517 static int process_port_feature_set_request(rh_t *instance, 438 uint16_t feature, uint16_t port , bool enable){439 if( feature > USB_HUB_FEATURE_C_PORT_RESET)518 uint16_t feature, uint16_t port){ 519 if(!((1<<feature) & port_set_feature_valid_mask)) 440 520 return EINVAL; 441 521 if(port<1 || port>instance->port_count) 442 522 return EINVAL; 443 523 instance->registers->rh_port_status[port - 1] = 444 enable ?445 524 (instance->registers->rh_port_status[port - 1] | (1<<feature)) 446 : 447 (instance->registers->rh_port_status[port - 1] & (~(1<<feature))); 525 & (~port_clear_feature_valid_mask); 448 526 /// \TODO any error? 449 527 return EOK; 450 528 } 529 530 /** 531 * process feature-disabling request on hub 532 * 533 * @param instance root hub instance 534 * @param feature feature selector 535 * @param port port number, counted from 1 536 * @param enable enable or disable the specified feature 537 * @return error code 538 */ 539 static int process_port_feature_clear_request(rh_t *instance, 540 uint16_t feature, uint16_t port){ 541 if(!((1<<feature) & port_clear_feature_valid_mask)) 542 return EINVAL; 543 if(port<1 || port>instance->port_count) 544 return EINVAL; 545 if(feature == USB_HUB_FEATURE_PORT_POWER) 546 feature = USB_HUB_FEATURE_PORT_LOW_SPEED; 547 if(feature == USB_HUB_FEATURE_PORT_SUSPEND) 548 feature = USB_HUB_FEATURE_PORT_OVER_CURRENT; 549 instance->registers->rh_port_status[port - 1] = 550 (instance->registers->rh_port_status[port - 1] 551 & (~port_clear_feature_valid_mask)) 552 | (1<<feature); 553 /// \TODO any error? 554 return EOK; 555 } 556 451 557 452 558 /** … … 530 636 (usb_device_request_setup_packet_t*)request->setup_buffer; 531 637 request->transfered_size = 0; 532 if(setup_request->request == USB_DEVREQ_CLEAR_FEATURE 533 || setup_request->request == USB_DEVREQ_SET_FEATURE){ 638 if(setup_request->request == USB_DEVREQ_CLEAR_FEATURE){ 534 639 if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){ 535 640 usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n"); 536 return process_hub_feature_ set_request(instance, setup_request->value,537 setup_request-> request == USB_DEVREQ_SET_FEATURE);641 return process_hub_feature_clear_request(instance, 642 setup_request->value); 538 643 } 539 644 if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){ 540 645 usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n"); 541 return process_port_feature_set_request(instance, setup_request->value, 542 setup_request->index, 543 setup_request->request == USB_DEVREQ_SET_FEATURE); 646 return process_port_feature_clear_request(instance, 647 setup_request->value, 648 setup_request->index); 649 } 650 usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n", 651 setup_request->request_type); 652 return EINVAL; 653 } 654 if(setup_request->request == USB_DEVREQ_SET_FEATURE){ 655 if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){ 656 usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n"); 657 return process_hub_feature_set_request(instance, 658 setup_request->value); 659 } 660 if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){ 661 usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n"); 662 return process_port_feature_set_request(instance, 663 setup_request->value, 664 setup_request->index); 544 665 } 545 666 usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",setup_request->request_type); -
uspace/drv/ohci/root_hub.h
r0b4e7ca rc593b21 37 37 38 38 #include <usb/usb.h> 39 #include <usb/devdrv.h> 39 40 40 41 #include "ohci_regs.h" … … 53 54 /** hub port count */ 54 55 int port_count; 56 /** hubs descriptors */ 57 usb_device_descriptors_t descriptors; 55 58 } rh_t; 56 59 -
uspace/drv/pciintel/pci.c
r0b4e7ca rc593b21 48 48 49 49 #include <ddf/driver.h> 50 #include <ddf/log.h> 50 51 #include <devman.h> 51 52 #include <ipc/devman.h> … … 325 326 326 327 if (match_id_str == NULL) { 327 printf(NAME ": out of memory creating match ID.\n");328 ddf_msg(LVL_ERROR, "Out of memory creating match ID."); 328 329 return; 329 330 } … … 331 332 rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 90); 332 333 if (rc != EOK) { 333 printf(NAME ": error adding match ID: %s\n",334 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", 334 335 str_error(rc)); 335 336 } … … 428 429 429 430 if (range_addr != 0) { 430 printf(NAME ": function %s : ", fun->fnode->name);431 printf("address = %" PRIx64, range_addr);432 printf(", size = %x\n",(unsigned int) range_size);431 ddf_msg(LVL_DEBUG, "Function %s : address = %" PRIx64 432 ", size = %x", fun->fnode->name, range_addr, 433 (unsigned int) range_size); 433 434 } 434 435 … … 455 456 hw_res_list->count++; 456 457 457 printf(NAME ": function %s uses irq %x.\n", fun->fnode->name, irq);458 ddf_msg(LVL_NOTE, "Function %s uses irq %x.", fun->fnode->name, irq); 458 459 } 459 460 … … 511 512 char *fun_name = pci_fun_create_name(fun); 512 513 if (fun_name == NULL) { 513 printf(NAME ": out of memory.\n");514 ddf_msg(LVL_ERROR, "Out of memory."); 514 515 return; 515 516 } … … 517 518 fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name); 518 519 if (fnode == NULL) { 519 printf(NAME ": error creating function.\n");520 ddf_msg(LVL_ERROR, "Failed creating function."); 520 521 return; 521 522 } … … 531 532 fnode->driver_data = fun; 532 533 533 printf(NAME ": adding new function %s.\n",534 ddf_msg(LVL_DEBUG, "Adding new function %s.", 534 535 fnode->name); 535 536 … … 548 549 child_bus = pci_conf_read_8(fun, 549 550 PCI_BRIDGE_SEC_BUS_NUM); 550 printf(NAME ": device is pci-to-pci bridge, " 551 "secondary bus number = %d.\n", bus_num); 551 ddf_msg(LVL_DEBUG, "Device is pci-to-pci " 552 "bridge, secondary bus number = %d.", 553 bus_num); 552 554 if (child_bus > bus_num) 553 555 pci_bus_scan(bus, child_bus); … … 571 573 int rc; 572 574 573 printf(NAME ": pci_add_device\n");575 ddf_msg(LVL_DEBUG, "pci_add_device"); 574 576 dnode->parent_phone = -1; 575 577 576 578 bus = pci_bus_new(); 577 579 if (bus == NULL) { 578 printf(NAME ": pci_add_device allocation failed.\n");580 ddf_msg(LVL_ERROR, "pci_add_device allocation failed."); 579 581 rc = ENOMEM; 580 582 goto fail; … … 586 588 IPC_FLAG_BLOCKING); 587 589 if (dnode->parent_phone < 0) { 588 printf(NAME ":pci_add_device failed to connect to the "589 "parent's driver. \n");590 ddf_msg(LVL_ERROR, "pci_add_device failed to connect to the " 591 "parent's driver."); 590 592 rc = dnode->parent_phone; 591 593 goto fail; … … 596 598 rc = hw_res_get_resource_list(dnode->parent_phone, &hw_resources); 597 599 if (rc != EOK) { 598 printf(NAME ": pci_add_device failed to get hw resources for"599 " the device.\n");600 ddf_msg(LVL_ERROR, "pci_add_device failed to get hw resources " 601 "for the device."); 600 602 goto fail; 601 603 } 602 604 got_res = true; 603 605 604 printf(NAME ": conf_addr = %" PRIx64 ".\n",606 ddf_msg(LVL_DEBUG, "conf_addr = %" PRIx64 ".", 605 607 hw_resources.resources[0].res.io_range.address); 606 608 … … 614 616 if (pio_enable((void *)(uintptr_t)bus->conf_io_addr, 8, 615 617 &bus->conf_addr_port)) { 616 printf(NAME ": failed to enable configuration ports.\n");618 ddf_msg(LVL_ERROR, "Failed to enable configuration ports."); 617 619 rc = EADDRNOTAVAIL; 618 620 goto fail; … … 621 623 622 624 /* Make the bus device more visible. It has no use yet. */ 623 printf(NAME ": adding a 'ctl' function\n");625 ddf_msg(LVL_DEBUG, "Adding a 'ctl' function"); 624 626 625 627 ctl = ddf_fun_create(bus->dnode, fun_exposed, "ctl"); 626 628 if (ctl == NULL) { 627 printf(NAME ": error creating control function.\n");629 ddf_msg(LVL_ERROR, "Failed creating control function."); 628 630 rc = ENOMEM; 629 631 goto fail; … … 632 634 rc = ddf_fun_bind(ctl); 633 635 if (rc != EOK) { 634 printf(NAME ": error binding control function.\n");636 ddf_msg(LVL_ERROR, "Failed binding control function."); 635 637 goto fail; 636 638 } 637 639 638 640 /* Enumerate functions. */ 639 printf(NAME ": scanning the bus\n");641 ddf_msg(LVL_DEBUG, "Scanning the bus"); 640 642 pci_bus_scan(bus, 0); 641 643 … … 659 661 static void pciintel_init(void) 660 662 { 663 ddf_log_init(NAME, LVL_ERROR); 661 664 pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops; 662 665 pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops; … … 738 741 int main(int argc, char *argv[]) 739 742 { 740 printf(NAME ": HelenOS pci bus driver (intel method 1).\n");743 printf(NAME ": HelenOS PCI bus driver (Intel method 1).\n"); 741 744 pciintel_init(); 742 745 return ddf_driver_main(&pci_driver); -
uspace/drv/root/root.c
r0b4e7ca rc593b21 52 52 53 53 #include <ddf/driver.h> 54 #include <ddf/log.h> 54 55 #include <devman.h> 55 56 #include <ipc/devman.h> … … 89 90 int rc; 90 91 91 printf(NAME ": adding new function for virtual devices.\n");92 printf(NAME ": function node is `%s' (%d %s)\n", name,92 ddf_msg(LVL_DEBUG, "Adding new function for virtual devices. " 93 "Function node is `%s' (%d %s)", name, 93 94 VIRTUAL_FUN_MATCH_SCORE, VIRTUAL_FUN_MATCH_ID); 94 95 95 96 fun = ddf_fun_create(dev, fun_inner, name); 96 97 if (fun == NULL) { 97 printf(NAME ": error creating function %s\n", name);98 ddf_msg(LVL_ERROR, "Failed creating function %s", name); 98 99 return ENOMEM; 99 100 } … … 102 103 VIRTUAL_FUN_MATCH_SCORE); 103 104 if (rc != EOK) { 104 printf(NAME ": error adding match IDs to function %s\n", name); 105 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s", 106 name); 105 107 ddf_fun_destroy(fun); 106 108 return rc; … … 109 111 rc = ddf_fun_bind(fun); 110 112 if (rc != EOK) { 111 printf(NAME ": error binding function %s: %s\n", name,113 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name, 112 114 str_error(rc)); 113 115 ddf_fun_destroy(fun); … … 136 138 platform = sysinfo_get_data("platform", &platform_size); 137 139 if (platform == NULL) { 138 printf(NAME ": Failed to obtain platform name.\n");140 ddf_msg(LVL_ERROR, "Failed to obtain platform name."); 139 141 return ENOENT; 140 142 } … … 143 145 platform = realloc(platform, platform_size + 1); 144 146 if (platform == NULL) { 145 printf(NAME ": Memory allocation failed.\n");147 ddf_msg(LVL_ERROR, "Memory allocation failed."); 146 148 return ENOMEM; 147 149 } … … 151 153 /* Construct match ID. */ 152 154 if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) { 153 printf(NAME ": Memory allocation failed.\n");155 ddf_msg(LVL_ERROR, "Memory allocation failed."); 154 156 return ENOMEM; 155 157 } 156 158 157 159 /* Add function. */ 158 printf(NAME ": adding platform function\n");159 printf(NAME ": function node is `%s' (%d %s)\n", PLATFORM_FUN_NAME,160 PLATFORM_FUN_MATCH_SCORE,match_id);160 ddf_msg(LVL_DEBUG, "Adding platform function. Function node is `%s' " 161 " (%d %s)", PLATFORM_FUN_NAME, PLATFORM_FUN_MATCH_SCORE, 162 match_id); 161 163 162 164 fun = ddf_fun_create(dev, fun_inner, name); 163 165 if (fun == NULL) { 164 printf(NAME ": error creating function %s\n", name);166 ddf_msg(LVL_ERROR, "Error creating function %s", name); 165 167 return ENOMEM; 166 168 } … … 168 170 rc = ddf_fun_add_match_id(fun, match_id, PLATFORM_FUN_MATCH_SCORE); 169 171 if (rc != EOK) { 170 printf(NAME ": error adding match IDs to function %s\n", name); 172 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s", 173 name); 171 174 ddf_fun_destroy(fun); 172 175 return rc; … … 175 178 rc = ddf_fun_bind(fun); 176 179 if (rc != EOK) { 177 printf(NAME ": error binding function %s: %s\n", name,180 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name, 178 181 str_error(rc)); 179 182 ddf_fun_destroy(fun); … … 191 194 static int root_add_device(ddf_dev_t *dev) 192 195 { 193 printf(NAME ": root_add_device, device handle=%" PRIun "\n",196 ddf_msg(LVL_DEBUG, "root_add_device, device handle=%" PRIun, 194 197 dev->handle); 195 198 … … 204 207 int res = add_platform_fun(dev); 205 208 if (EOK != res) 206 printf(NAME ": failed to add child device for platform.\n");209 ddf_msg(LVL_ERROR, "Failed adding child device for platform."); 207 210 208 211 return res; … … 212 215 { 213 216 printf(NAME ": HelenOS root device driver\n"); 217 218 ddf_log_init(NAME, LVL_ERROR); 214 219 return ddf_driver_main(&root_driver); 215 220 } -
uspace/drv/rootpc/rootpc.c
r0b4e7ca rc593b21 47 47 48 48 #include <ddf/driver.h> 49 #include <ddf/log.h> 49 50 #include <devman.h> 50 51 #include <ipc/devman.h> … … 119 120 rootpc_fun_t *fun) 120 121 { 121 printf(NAME ": adding new function '%s'.\n", name);122 ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name); 122 123 123 124 ddf_fun_t *fnode = NULL; … … 145 146 /* Register function. */ 146 147 if (ddf_fun_bind(fnode) != EOK) { 147 printf(NAME ": error binding function %s.\n", name);148 ddf_msg(LVL_ERROR, "Failed binding function %s.", name); 148 149 goto failure; 149 150 } … … 158 159 ddf_fun_destroy(fnode); 159 160 160 printf(NAME ": failed to add function '%s'.\n", name);161 ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name); 161 162 162 163 return false; … … 176 177 static int rootpc_add_device(ddf_dev_t *dev) 177 178 { 178 printf(NAME ": rootpc_add_device, device handle = %d\n",179 ddf_msg(LVL_DEBUG, "rootpc_add_device, device handle = %d", 179 180 (int)dev->handle); 180 181 181 182 /* Register functions. */ 182 183 if (!rootpc_add_functions(dev)) { 183 printf(NAME ": failed to add functions for PC platform.\n");184 ddf_msg(LVL_ERROR, "Failed to add functions for PC platform."); 184 185 } 185 186 … … 189 190 static void root_pc_init(void) 190 191 { 192 ddf_log_init(NAME, LVL_ERROR); 191 193 rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops; 192 194 } -
uspace/drv/rootvirt/rootvirt.c
r0b4e7ca rc593b21 40 40 #include <str_error.h> 41 41 #include <ddf/driver.h> 42 #include <ddf/log.h> 42 43 43 44 #define NAME "rootvirt" … … 83 84 int rc; 84 85 85 printf(NAME ": registering function `%s' (match \"%s\")\n",86 ddf_msg(LVL_DEBUG, "Registering function `%s' (match \"%s\")", 86 87 vfun->name, vfun->match_id); 87 88 88 89 fun = ddf_fun_create(vdev, fun_inner, vfun->name); 89 90 if (fun == NULL) { 90 printf(NAME ": error creating function %s\n", vfun->name);91 ddf_msg(LVL_ERROR, "Failed creating function %s", vfun->name); 91 92 return ENOMEM; 92 93 } … … 94 95 rc = ddf_fun_add_match_id(fun, vfun->match_id, 10); 95 96 if (rc != EOK) { 96 printf(NAME ": error adding match IDs to function %s\n",97 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s", 97 98 vfun->name); 98 99 ddf_fun_destroy(fun); … … 102 103 rc = ddf_fun_bind(fun); 103 104 if (rc != EOK) { 104 printf(NAME ": error binding function %s: %s\n", vfun->name,105 str_error(rc));105 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", 106 vfun->name, str_error(rc)); 106 107 ddf_fun_destroy(fun); 107 108 return rc; 108 109 } 109 110 110 printf(NAME ": registered child device `%s'\n", vfun->name);111 ddf_msg(LVL_NOTE, "Registered child device `%s'", vfun->name); 111 112 return EOK; 112 113 } … … 124 125 } 125 126 126 printf(NAME ": add_device(handle=%d)\n", (int)dev->handle);127 ddf_msg(LVL_DEBUG, "add_device(handle=%d)", (int)dev->handle); 127 128 128 129 /* … … 142 143 { 143 144 printf(NAME ": HelenOS virtual devices root driver\n"); 145 146 ddf_log_init(NAME, LVL_ERROR); 144 147 return ddf_driver_main(&rootvirt_driver); 145 148 } -
uspace/drv/test1/test1.c
r0b4e7ca rc593b21 35 35 #include <str_error.h> 36 36 #include <ddf/driver.h> 37 #include <ddf/log.h> 37 38 38 39 #include "test1.h" … … 58 59 */ 59 60 static int register_fun_verbose(ddf_dev_t *parent, const char *message, 60 const char *name, const char *match_id, int match_score) 61 const char *name, const char *match_id, int match_score, 62 int expected_rc) 61 63 { 62 ddf_fun_t *fun ;64 ddf_fun_t *fun = NULL; 63 65 int rc; 64 66 65 printf(NAME ": registering function `%s': %s.\n", name, message);67 ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message); 66 68 67 69 fun = ddf_fun_create(parent, fun_inner, name); 68 70 if (fun == NULL) { 69 printf(NAME ": error creating function %s\n", name); 70 return ENOMEM; 71 ddf_msg(LVL_ERROR, "Failed creating function %s", name); 72 rc = ENOMEM; 73 goto leave; 71 74 } 72 75 73 rc = ddf_fun_add_match_id(fun, match_id, match_score);76 rc = ddf_fun_add_match_id(fun, str_dup(match_id), match_score); 74 77 if (rc != EOK) { 75 printf(NAME ": error adding match IDs to function %s\n", name);76 ddf_fun_destroy(fun);77 return rc;78 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s", 79 name); 80 goto leave; 78 81 } 79 82 80 83 rc = ddf_fun_bind(fun); 81 84 if (rc != EOK) { 82 printf(NAME ": error binding function %s: %s\n", name,85 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name, 83 86 str_error(rc)); 84 ddf_fun_destroy(fun); 85 return rc; 87 goto leave; 86 88 } 87 89 88 printf(NAME ": registered child device `%s'\n", name); 89 return EOK; 90 ddf_msg(LVL_NOTE, "Registered child device `%s'", name); 91 rc = EOK; 92 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; 90 106 } 91 107 … … 112 128 int rc; 113 129 114 printf(NAME ": add_device(name=\"%s\", handle=%d)\n",130 ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)", 115 131 dev->name, (int) dev->handle); 116 132 117 133 fun_a = ddf_fun_create(dev, fun_exposed, "a"); 118 134 if (fun_a == NULL) { 119 printf(NAME ": error creating function 'a'.\n");135 ddf_msg(LVL_ERROR, "Failed creating function 'a'."); 120 136 return ENOMEM; 121 137 } … … 123 139 rc = ddf_fun_bind(fun_a); 124 140 if (rc != EOK) { 125 printf(NAME ": error binding function 'a'.\n");141 ddf_msg(LVL_ERROR, "Failed binding function 'a'."); 126 142 return rc; 127 143 } … … 133 149 ddf_fun_add_to_class(fun_a, "virt-null"); 134 150 } else if (str_cmp(dev->name, "test1") == 0) { 135 (void) register_fun_verbose(dev, "cloning myself ;-)", "clone", 136 "virtual&test1", 10); 151 (void) register_fun_verbose(dev, 152 "cloning myself ;-)", "clone", 153 "virtual&test1", 10, EOK); 154 (void) register_fun_verbose(dev, 155 "cloning myself twice ;-)", "clone", 156 "virtual&test1", 10, EEXISTS); 137 157 } else if (str_cmp(dev->name, "clone") == 0) { 138 (void) register_fun_verbose(dev, "run by the same task", "child", 139 "virtual&test1&child", 10); 158 (void) register_fun_verbose(dev, 159 "run by the same task", "child", 160 "virtual&test1&child", 10, EOK); 140 161 } 141 162 142 printf(NAME ": device `%s' accepted.\n", dev->name);163 ddf_msg(LVL_DEBUG, "Device `%s' accepted.", dev->name); 143 164 144 165 return EOK; … … 148 169 { 149 170 printf(NAME ": HelenOS test1 virtual device driver\n"); 171 ddf_log_init(NAME, LVL_ERROR); 150 172 return ddf_driver_main(&test1_driver); 151 173 } -
uspace/drv/test2/test2.c
r0b4e7ca rc593b21 36 36 #include <str_error.h> 37 37 #include <ddf/driver.h> 38 #include <ddf/log.h> 38 39 39 40 #define NAME "test2" … … 64 65 int rc; 65 66 66 printf(NAME ": registering function `%s': %s.\n", name, message);67 ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message); 67 68 68 69 fun = ddf_fun_create(parent, fun_inner, name); 69 70 if (fun == NULL) { 70 printf(NAME ": error creating function %s\n", name);71 ddf_msg(LVL_ERROR, "Failed creating function %s", name); 71 72 return ENOMEM; 72 73 } … … 74 75 rc = ddf_fun_add_match_id(fun, match_id, match_score); 75 76 if (rc != EOK) { 76 printf(NAME ": error adding match IDs to function %s\n", name); 77 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s", 78 name); 77 79 ddf_fun_destroy(fun); 78 80 return rc; … … 81 83 rc = ddf_fun_bind(fun); 82 84 if (rc != EOK) { 83 printf(NAME ": error binding function %s: %s\n", name,85 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name, 84 86 str_error(rc)); 85 87 ddf_fun_destroy(fun); … … 87 89 } 88 90 89 printf(NAME ": registered child device `%s'\n", name);91 ddf_msg(LVL_NOTE, "Registered child device `%s'", name); 90 92 return EOK; 91 93 } … … 111 113 fun_a = ddf_fun_create(dev, fun_exposed, "a"); 112 114 if (fun_a == NULL) { 113 printf(NAME ": error creating function 'a'.\n");115 ddf_msg(LVL_ERROR, "Failed creating function 'a'."); 114 116 return ENOMEM; 115 117 } … … 117 119 rc = ddf_fun_bind(fun_a); 118 120 if (rc != EOK) { 119 printf(NAME ": error binding function 'a'.\n");121 ddf_msg(LVL_ERROR, "Failed binding function 'a'."); 120 122 return rc; 121 123 } … … 128 130 static int test2_add_device(ddf_dev_t *dev) 129 131 { 130 printf(NAME ": test2_add_device(name=\"%s\", handle=%d)\n",132 ddf_msg(LVL_DEBUG, "test2_add_device(name=\"%s\", handle=%d)", 131 133 dev->name, (int) dev->handle); 132 134 … … 134 136 fid_t postpone = fibril_create(postponed_birth, dev); 135 137 if (postpone == 0) { 136 printf(NAME ": fibril_create() error\n");138 ddf_msg(LVL_ERROR, "fibril_create() failed."); 137 139 return ENOMEM; 138 140 } … … 149 151 { 150 152 printf(NAME ": HelenOS test2 virtual device driver\n"); 153 ddf_log_init(NAME, LVL_ERROR); 151 154 return ddf_driver_main(&test2_driver); 152 155 } -
uspace/drv/uhci-hcd/hc.c
r0b4e7ca rc593b21 239 239 usb_log_debug("Initialized device manager.\n"); 240 240 241 ret = bandwidth_init(&instance->bandwidth, BANDWIDTH_AVAILABLE_USB11, 242 bandwidth_count_usb11); 243 assert(ret == EOK); 244 241 245 return EOK; 242 246 #undef CHECK_RET_DEST_CMDS_RETURN … … 325 329 if (!usb_is_allowed( 326 330 low_speed, batch->transfer_type, batch->max_packet_size)) { 327 usb_log_warning( 328 "Invalid USB transfer specified %s SPEED %d %zu.\n", 329 low_speed ? "LOW" : "FULL" , batch->transfer_type, 331 usb_log_error("Invalid USB transfer specified %s %d %zu.\n", 332 usb_str_speed(batch->speed), batch->transfer_type, 330 333 batch->max_packet_size); 331 334 return ENOTSUP; 332 335 } 333 /* TODO: check available bandwidth here */ 336 /* Check available bandwidth */ 337 if (batch->transfer_type == USB_TRANSFER_INTERRUPT || 338 batch->transfer_type == USB_TRANSFER_ISOCHRONOUS) { 339 int ret = 340 bandwidth_use(&instance->bandwidth, batch->target.address, 341 batch->target.endpoint, batch->direction); 342 if (ret != EOK) { 343 usb_log_warning("Failed(%d) to use reserved bw: %s.\n", 344 ret, str_error(ret)); 345 } 346 } 334 347 335 348 transfer_list_t *list = … … 338 351 if (batch->transfer_type == USB_TRANSFER_CONTROL) { 339 352 usb_device_keeper_use_control( 340 &instance->manager, batch->target .address);353 &instance->manager, batch->target); 341 354 } 342 355 transfer_list_add_batch(list, batch); … … 358 371 { 359 372 assert(instance); 373 // status |= 1; //Uncomment to work around qemu hang 360 374 /* TODO: Resume interrupts are not supported */ 361 375 /* Lower 2 bits are transaction error and transaction complete */ … … 376 390 usb_transfer_batch_t *batch = 377 391 list_get_instance(item, usb_transfer_batch_t, link); 378 if (batch->transfer_type == USB_TRANSFER_CONTROL) { 392 switch (batch->transfer_type) 393 { 394 case USB_TRANSFER_CONTROL: 379 395 usb_device_keeper_release_control( 380 &instance->manager, batch->target.address); 396 &instance->manager, batch->target); 397 break; 398 case USB_TRANSFER_INTERRUPT: 399 case USB_TRANSFER_ISOCHRONOUS: { 400 int ret = bandwidth_free(&instance->bandwidth, 401 batch->target.address, 402 batch->target.endpoint, 403 batch->direction); 404 if (ret != EOK) 405 usb_log_warning("Failed(%d) to free " 406 "reserved bw: %s.\n", ret, 407 str_error(ret)); 408 } 409 default: 410 break; 381 411 } 382 412 batch->next_step(batch); -
uspace/drv/uhci-hcd/hc.h
r0b4e7ca rc593b21 43 43 #include <usbhc_iface.h> 44 44 #include <usb/host/device_keeper.h> 45 #include <usb/host/bandwidth.h> 45 46 46 47 #include "batch.h" … … 84 85 typedef struct hc { 85 86 usb_device_keeper_t manager; 87 bandwidth_t bandwidth; 86 88 87 89 regs_t *registers; -
uspace/drv/uhci-hcd/iface.c
r0b4e7ca rc593b21 128 128 } 129 129 /*----------------------------------------------------------------------------*/ 130 static int register_endpoint( 131 ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint, 132 usb_transfer_type_t transfer_type, usb_direction_t direction, 133 size_t max_packet_size, unsigned int interval) 134 { 135 hc_t *hc = fun_to_hc(fun); 136 assert(hc); 137 const usb_speed_t speed = 138 usb_device_keeper_get_speed(&hc->manager, address); 139 size_t size = max_packet_size; 140 141 usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n", 142 address, endpoint, usb_str_transfer_type(transfer_type), 143 usb_str_speed(speed), direction, size, max_packet_size, interval); 144 return bandwidth_reserve(&hc->bandwidth, address, endpoint, direction, 145 speed, transfer_type, max_packet_size, size, interval); 146 } 147 /*----------------------------------------------------------------------------*/ 148 static int unregister_endpoint( 149 ddf_fun_t *fun, usb_address_t address, 150 usb_endpoint_t endpoint, usb_direction_t direction) 151 { 152 hc_t *hc = fun_to_hc(fun); 153 assert(hc); 154 usb_log_debug("Unregister endpoint %d:%d %d.\n", 155 address, endpoint, direction); 156 return bandwidth_release(&hc->bandwidth, address, endpoint, direction); 157 } 158 /*----------------------------------------------------------------------------*/ 130 159 /** Interrupt out transaction interface function 131 160 * … … 365 394 .release_address = release_address, 366 395 396 .register_endpoint = register_endpoint, 397 .unregister_endpoint = unregister_endpoint, 398 367 399 .interrupt_out = interrupt_out, 368 400 .interrupt_in = interrupt_in, -
uspace/drv/usbhub/port_status.h
r0b4e7ca rc593b21 95 95 } 96 96 97 /** 98 * set the device request to be a port feature clear request 99 * @param request 100 * @param port 101 * @param feature_selector 102 */ 103 static inline void usb_hub_set_disable_port_feature_request( 104 usb_device_request_setup_packet_t * request, uint16_t port, 105 uint16_t feature_selector 106 ){ 107 request->index = port; 108 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE; 109 request->request = USB_HUB_REQUEST_CLEAR_FEATURE; 110 request->value = feature_selector; 111 request->length = 0; 112 } 97 113 98 114 /** -
uspace/drv/usbhub/usbhub.c
r0b4e7ca rc593b21 74 74 75 75 while(errorCode == EOK){ 76 async_usleep(1000 * 1000 * 10 );/// \TODO proper number once 76 77 errorCode = usb_hub_check_hub_changes(hub_info); 77 async_usleep(1000 * 1000 );/// \TODO proper number once78 78 } 79 79 usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode); … … 317 317 //set the status change bit, so it will be noticed in driver loop 318 318 if(usb_port_dev_connected(&status)){ 319 usb_hub_set_ enable_port_feature_request(&request, port,320 USB_HUB_FEATURE_ C_PORT_CONNECTION);319 usb_hub_set_disable_port_feature_request(&request, port, 320 USB_HUB_FEATURE_PORT_CONNECTION); 321 321 opResult = usb_pipe_control_read( 322 322 hub->control_pipe, … … 326 326 if (opResult != EOK) { 327 327 usb_log_warning( 328 "could not set port changeon port %d errno:%d\n",328 "could not clear port connection on port %d errno:%d\n", 329 329 port, opResult); 330 330 } 331 usb_log_debug("cleared port connection\n"); 332 usb_hub_set_enable_port_feature_request(&request, port, 333 USB_HUB_FEATURE_PORT_ENABLE); 334 opResult = usb_pipe_control_read( 335 hub->control_pipe, 336 &request, sizeof(usb_device_request_setup_packet_t), 337 &status, 4, &rcvd_size 338 ); 339 if (opResult != EOK) { 340 usb_log_warning( 341 "could not set port enabled on port %d errno:%d\n", 342 port, opResult); 343 } 344 usb_log_debug("port set to enabled - should lead to connection change\n"); 331 345 } 346 } 347 } 348 /// \TODO this is just a debug code 349 for(port=1;port<=descriptor->ports_count;++port){ 350 bool is_non_removable = 351 ((non_removable_dev_bitmap[port/8]) >> (port%8)) %2; 352 if(is_non_removable){ 353 usb_log_debug("port %d is non-removable\n",port); 354 usb_port_status_t status; 355 size_t rcvd_size; 356 usb_device_request_setup_packet_t request; 357 //int opResult; 358 usb_hub_set_port_status_request(&request, port); 359 //endpoint 0 360 opResult = usb_pipe_control_read( 361 hub->control_pipe, 362 &request, sizeof(usb_device_request_setup_packet_t), 363 &status, 4, &rcvd_size 364 ); 365 if (opResult != EOK) { 366 usb_log_error("could not get port status %d\n",opResult); 367 } 368 if (rcvd_size != sizeof (usb_port_status_t)) { 369 usb_log_error("received status has incorrect size\n"); 370 } 371 //something connected/disconnected 372 if (usb_port_connect_change(&status)) { 373 usb_log_debug("some connection changed\n"); 374 } 375 usb_log_debug("status: %s\n",usb_debug_str_buffer( 376 (uint8_t *)&status,4,4)); 332 377 } 333 378 } … … 582 627 //something connected/disconnected 583 628 if (usb_port_connect_change(&status)) { 629 usb_log_debug("connection change on port\n"); 584 630 if (usb_port_dev_connected(&status)) { 585 631 usb_log_debug("some connection changed\n"); … … 592 638 if (usb_port_overcurrent_change(&status)) { 593 639 //check if it was not auto-resolved 640 usb_log_debug("overcurrent change on port\n"); 594 641 if(usb_port_over_current(&status)){ 595 642 usb_hub_over_current(hub,port); … … 608 655 } 609 656 } 657 usb_log_debug("status %x\n ",status); 610 658 611 659 usb_port_set_connect_change(&status, false); -
uspace/drv/usbkbd/kbddev.c
r0b4e7ca rc593b21 56 56 #include <usb/classes/hidreq.h> 57 57 #include <usb/classes/hidreport.h> 58 #include <usb/classes/hid/utled.h> 58 59 59 60 #include <usb/devdrv.h> … … 69 70 static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK; 70 71 71 /** Boot protocol report size (key part). */ 72 static const size_t BOOTP_REPORT_SIZE = 6; 73 74 /** Boot protocol total report size. */ 75 static const size_t BOOTP_BUFFER_SIZE = 8; 76 77 /** Boot protocol output report size. */ 78 static const size_t BOOTP_BUFFER_OUT_SIZE = 1; 79 80 /** Boot protocol error key code. */ 81 static const uint8_t BOOTP_ERROR_ROLLOVER = 1; 72 ///** Boot protocol report size (key part). */ 73 //static const size_t BOOTP_REPORT_SIZE = 6; 74 75 ///** Boot protocol total report size. */ 76 //static const size_t BOOTP_BUFFER_SIZE = 8; 77 78 ///** Boot protocol output report size. */ 79 //static const size_t BOOTP_BUFFER_OUT_SIZE = 1; 80 81 ///** Boot protocol error key code. */ 82 //static const uint8_t BOOTP_ERROR_ROLLOVER = 1; 83 static const uint8_t ERROR_ROLLOVER = 1; 82 84 83 85 /** Default idle rate for keyboards. */ … … 263 265 static void usb_kbd_set_led(usb_kbd_t *kbd_dev) 264 266 { 265 u int8_t buffer[BOOTP_BUFFER_OUT_SIZE];266 int rc= 0;267 268 memset( buffer, 0, BOOTP_BUFFER_OUT_SIZE);269 uint8_t leds = 0;270 271 if (kbd_dev->mods & KM_NUM_LOCK) {272 leds |= USB_HID_LED_NUM_LOCK;273 }274 275 if (kbd_dev->mods & KM_CAPS_LOCK) {276 leds |= USB_HID_LED_CAPS_LOCK;277 }278 279 if (kbd_dev->mods & KM_SCROLL_LOCK) {280 leds |= USB_HID_LED_SCROLL_LOCK;267 unsigned i = 0; 268 269 /* Reset the LED data. */ 270 memset(kbd_dev->led_data, 0, kbd_dev->led_output_size * sizeof(int32_t)); 271 272 if ((kbd_dev->mods & KM_NUM_LOCK) && (i < kbd_dev->led_output_size)) { 273 kbd_dev->led_data[i++] = USB_HID_LED_NUM_LOCK; 274 } 275 276 if ((kbd_dev->mods & KM_CAPS_LOCK) && (i < kbd_dev->led_output_size)) { 277 kbd_dev->led_data[i++] = USB_HID_LED_CAPS_LOCK; 278 } 279 280 if ((kbd_dev->mods & KM_SCROLL_LOCK) 281 && (i < kbd_dev->led_output_size)) { 282 kbd_dev->led_data[i++] = USB_HID_LED_SCROLL_LOCK; 281 283 } 282 284 … … 284 286 285 287 usb_log_debug("Creating output report.\n"); 286 usb_log_debug("Leds: 0x%x\n", leds); 287 if ((rc = usb_hid_boot_keyboard_output_report( 288 leds, buffer, BOOTP_BUFFER_OUT_SIZE)) != EOK) { 289 usb_log_warning("Error composing output report to the keyboard:" 290 "%s.\n", str_error(rc)); 288 289 int rc = usb_hid_report_output_translate(kbd_dev->parser, 290 kbd_dev->led_path, USB_HID_PATH_COMPARE_END, kbd_dev->output_buffer, 291 kbd_dev->output_size, kbd_dev->led_data, kbd_dev->led_output_size); 292 293 if (rc != EOK) { 294 usb_log_warning("Error translating LED output to output report" 295 ".\n"); 291 296 return; 292 297 } 293 298 294 299 usb_log_debug("Output report buffer: %s\n", 295 usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0)); 296 297 assert(kbd_dev->usb_dev != NULL); 300 usb_debug_str_buffer(kbd_dev->output_buffer, kbd_dev->output_size, 301 0)); 298 302 299 303 usbhid_req_set_report(&kbd_dev->usb_dev->ctrl_pipe, 300 304 kbd_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT, 301 buffer, BOOTP_BUFFER_OUT_SIZE);305 kbd_dev->output_buffer, kbd_dev->output_size); 302 306 } 303 307 … … 450 454 * First of all, check if the kbd have reported phantom state. 451 455 * 452 * this must be changed as we don't know which keys are modifiers 453 * and which are regular keys. 456 * As there is no way to distinguish keys from modifiers, we do not have 457 * a way to check that 'all keys report Error Rollover'. We thus check 458 * if there is at least one such error and in such case we ignore the 459 * whole input report. 454 460 */ 455 461 i = 0; 456 // all fields should report Error Rollover 457 while (i < count && 458 key_codes[i] == BOOTP_ERROR_ROLLOVER) { 462 while (i < count && key_codes[i] != ERROR_ROLLOVER) { 459 463 ++i; 460 464 } 461 if (i == count) {465 if (i != count) { 462 466 usb_log_debug("Phantom state occured.\n"); 463 467 // phantom state, do nothing … … 586 590 */ 587 591 static void usb_kbd_process_data(usb_kbd_t *kbd_dev, 588 uint8_t *buffer, size_t actual_size)592 uint8_t *buffer, size_t actual_size) 589 593 { 590 594 assert(kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED); … … 760 764 usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count); 761 765 762 kbd_dev->keys = (uint8_t *)calloc( 763 kbd_dev->key_count, sizeof(uint8_t)); 766 kbd_dev->keys = (uint8_t *)calloc(kbd_dev->key_count, sizeof(uint8_t)); 764 767 765 768 if (kbd_dev->keys == NULL) { … … 768 771 } 769 772 773 /* 774 * Output report 775 */ 776 kbd_dev->output_size = 0; 777 kbd_dev->output_buffer = usb_hid_report_output(kbd_dev->parser, 778 &kbd_dev->output_size); 779 if (kbd_dev->output_buffer == NULL) { 780 usb_log_warning("Error creating output report buffer.\n"); 781 free(kbd_dev->keys); 782 return ENOMEM; /* TODO: other error code */ 783 } 784 785 usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size); 786 787 kbd_dev->led_path = usb_hid_report_path(); 788 usb_hid_report_path_append_item( 789 kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0); 790 791 kbd_dev->led_output_size = usb_hid_report_output_size(kbd_dev->parser, 792 kbd_dev->led_path, USB_HID_PATH_COMPARE_END); 793 794 usb_log_debug("Output report size (in items): %zu\n", 795 kbd_dev->led_output_size); 796 797 kbd_dev->led_data = (int32_t *)calloc( 798 kbd_dev->led_output_size, sizeof(int32_t)); 799 800 if (kbd_dev->led_data == NULL) { 801 usb_log_warning("Error creating buffer for LED output report." 802 "\n"); 803 free(kbd_dev->keys); 804 usb_hid_report_output_free(kbd_dev->output_buffer); 805 return ENOMEM; 806 } 807 808 /* 809 * Modifiers and locks 810 */ 770 811 kbd_dev->modifiers = 0; 771 812 kbd_dev->mods = DEFAULT_ACTIVE_MODS; 772 813 kbd_dev->lock_keys = 0; 773 814 815 /* 816 * Autorepeat 817 */ 774 818 kbd_dev->repeat.key_new = 0; 775 819 kbd_dev->repeat.key_repeated = 0; … … 879 923 } 880 924 925 // free the output buffer 926 usb_hid_report_output_free((*kbd_dev)->output_buffer); 927 881 928 /* TODO: what about the USB device structure?? */ 882 929 -
uspace/drv/usbkbd/kbddev.h
r0b4e7ca rc593b21 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; 96 106 97 107 /** HID Report parser. */
Note:
See TracChangeset
for help on using the changeset viewer.
