Changeset f8e8738 in mainline for uspace/drv
- Timestamp:
- 2011-04-07T20:22:40Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fee6381
- Parents:
- 61257f4 (diff), a82889e (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:
-
- 4 added
- 36 edited
- 3 moved
-
isa/isa.c (modified) (13 diffs)
-
ns8250/ns8250.c (modified) (21 diffs)
-
ohci/batch.c (modified) (1 diff)
-
ohci/hc.c (modified) (7 diffs)
-
ohci/hc.h (modified) (3 diffs)
-
ohci/hw_struct/completion_codes.h (moved) (moved from kernel/arch/arm32/include/memstr.h ) (2 diffs)
-
ohci/hw_struct/endpoint_descriptor.h (added)
-
ohci/hw_struct/hcca.h (moved) (moved from kernel/arch/abs32le/include/memstr.h ) (2 diffs)
-
ohci/hw_struct/iso_transfer_descriptor.h (added)
-
ohci/hw_struct/transfer_descriptor.h (added)
-
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) (18 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/batch.c (modified) (8 diffs)
-
uhci-hcd/batch.h (modified) (2 diffs)
-
uhci-hcd/hc.c (modified) (8 diffs)
-
uhci-hcd/hc.h (modified) (2 diffs)
-
uhci-hcd/hw_struct/queue_head.h (modified) (1 diff)
-
uhci-hcd/iface.c (modified) (12 diffs)
-
uhci-hcd/transfer_list.h (modified) (1 diff)
-
uhci-hcd/utils/malloc32.h (modified) (1 diff)
-
uhci-rhd/main.c (modified) (5 diffs)
-
uhci-rhd/port.c (modified) (5 diffs)
-
uhci-rhd/root_hub.c (modified) (3 diffs)
-
uhci-rhd/root_hub.h (modified) (1 diff)
-
usbhub/Makefile (modified) (1 diff)
-
usbhub/port_status.h (modified) (1 diff)
-
usbhub/ports.c (added)
-
usbhub/ports.h (moved) (moved from uspace/drv/usbhub/usblist.c ) (2 diffs)
-
usbhub/usbhub.c (modified) (10 diffs)
-
usbhub/usbhub.h (modified) (2 diffs)
-
usbhub/usbhub_private.h (modified) (1 diff)
-
usbmid/explore.c (modified) (6 diffs)
-
usbmid/usbmid.c (modified) (5 diffs)
-
usbmid/usbmid.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/isa/isa.c
r61257f4 rf8e8738 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
r61257f4 rf8e8738 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/batch.c
r61257f4 rf8e8738 73 73 CHECK_NULL_DISPOSE_RETURN(instance, 74 74 "Failed to allocate batch instance.\n"); 75 usb_transfer_batch_init(instance, target, transfer_type, speed, max_packet_size,76 buffer, NULL, buffer_size, NULL, setup_size, func_in,77 func_ out, arg, fun, NULL);75 usb_transfer_batch_init(instance, target, transfer_type, speed, 76 max_packet_size, buffer, NULL, buffer_size, NULL, setup_size, 77 func_in, func_out, arg, fun, NULL, NULL); 78 78 79 79 if (buffer_size > 0) { -
uspace/drv/ohci/hc.c
r61257f4 rf8e8738 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 = usb_endpoint_manager_init(&instance->ep_manager, 95 BANDWIDTH_AVAILABLE_USB11); 96 CHECK_RET_RETURN(ret, "Failed to initialize endpoint manager: %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 /* turn off legacy emulation */ 187 volatile uint32_t *ohci_emulation_reg = 188 (uint32_t*)((char*)instance->registers + 0x100); 189 usb_log_info("OHCI legacy register status %p: %x.\n", 190 ohci_emulation_reg, *ohci_emulation_reg); 191 *ohci_emulation_reg = 0; 192 193 } 194 /*----------------------------------------------------------------------------*/ 195 void hc_init_hw(hc_t *instance) 196 { 197 assert(instance); 198 const uint32_t fm_interval = instance->registers->fm_interval; 199 instance->registers->command_status = CS_HCR; 200 async_usleep(10); 201 instance->registers->fm_interval = fm_interval; 202 assert((instance->registers->command_status & CS_HCR) == 0); 203 /* hc is now in suspend state */ 204 /* TODO: init HCCA block */ 205 /* TODO: init queues */ 206 /* TODO: enable queues */ 207 /* TODO: enable interrupts */ 208 /* TODO: set periodic start to 90% */ 209 210 instance->registers->control &= (C_HCFS_OPERATIONAL << C_HCFS_SHIFT); 211 usb_log_info("OHCI HC up and running.\n"); 212 } 135 213 /** 136 214 * @} -
uspace/drv/ohci/hc.h
r61257f4 rf8e8738 42 42 #include <usb/usb.h> 43 43 #include <usb/host/device_keeper.h> 44 #include <usb/host/usb_endpoint_manager.h> 44 45 #include <usbhc_iface.h> 45 46 … … 47 48 #include "ohci_regs.h" 48 49 #include "root_hub.h" 50 #include "hw_struct/hcca.h" 49 51 50 52 typedef struct hc { … … 54 56 ddf_fun_t *ddf_instance; 55 57 usb_device_keeper_t manager; 58 usb_endpoint_manager_t ep_manager; 56 59 fid_t interrupt_emulator; 57 60 } hc_t; -
uspace/drv/ohci/hw_struct/completion_codes.h
r61257f4 rf8e8738 1 1 /* 2 * Copyright (c) 20 05 Sergey Bondari2 * Copyright (c) 2011 Jan Vesely 3 3 * All rights reserved. 4 4 * … … 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 29 /** @addtogroup arm32 28 /** @addtogroup drvusbohci 30 29 * @{ 31 30 */ 32 31 /** @file 33 * @brief Memory manipulating functions declarations.32 * @brief OHCI driver 34 33 */ 34 #ifndef DRV_OHCI_HW_STRUCT_COMPLETION_CODES_H 35 #define DRV_OHCI_HW_STRUCT_COMPLETION_CODES_H 35 36 36 #ifndef KERN_arm32_MEMSTR_H_ 37 #define KERN_arm32_MEMSTR_H_ 38 39 #define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt)) 40 41 extern void memsetw(void *, size_t, uint16_t); 42 extern void memsetb(void *, size_t, uint8_t); 37 #define CC_NOERROR (0x0) 38 #define CC_CRC (0x1) 39 #define CC_BITSTUFF (0x2) 40 #define CC_TOGGLE (0x3) 41 #define CC_STALL (0x4) 42 #define CC_NORESPONSE (0x5) 43 #define CC_PIDFAIL (0x6) 44 #define CC_PIDUNEXPECTED (0x7) 45 #define CC_DATAOVERRRUN (0x8) 46 #define CC_DATAUNDERRRUN (0x9) 47 #define CC_BUFFEROVERRRUN (0xc) 48 #define CC_BUFFERUNDERRUN (0xd) 49 #define CC_NOACCESS1 (0xe) 50 #define CC_NOACCESS2 (0xf) 43 51 44 52 #endif 45 46 /** @}53 /** 54 * @} 47 55 */ -
uspace/drv/ohci/hw_struct/hcca.h
r61257f4 rf8e8738 1 1 /* 2 * Copyright (c) 201 0 Martin Decky2 * Copyright (c) 2011 Jan Vesely 3 3 * All rights reserved. 4 4 * … … 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 29 /** @addtogroup abs32le 28 /** @addtogroup drvusbohci 30 29 * @{ 31 30 */ 32 31 /** @file 32 * @brief OHCI driver 33 */ 34 #ifndef DRV_OHCI_HW_STRUCT_HCCA_H 35 #define DRV_OHCI_HW_STRUCT_HCCA_H 36 37 #include <stdint.h> 38 39 typedef struct hcca { 40 uint32_t int_ep[32]; 41 uint16_t frame_number; 42 uint16_t pad1; 43 uint32_t done_head; 44 uint32_t reserved[29]; 45 } __attribute__((packed)) hcca_t; 46 47 #endif 48 /** 49 * @} 33 50 */ 34 51 35 #ifndef KERN_abs32le_MEMSTR_H_36 #define KERN_abs32le_MEMSTR_H_37 38 #define memcpy(dst, src, cnt) _memcpy((dst), (src), (cnt))39 #define memsetb(dst, cnt, val) _memsetb((dst), (cnt), (val))40 #define memsetw(dst, cnt, val) _memsetw((dst), (cnt), (val))41 42 #endif43 44 /** @}45 */ -
uspace/drv/ohci/iface.c
r61257f4 rf8e8738 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 // TODO use real endpoint here! 165 return usb_endpoint_manager_register_ep(&hc->ep_manager,NULL, 0); 156 166 } 157 167 /*----------------------------------------------------------------------------*/ … … 168 178 usb_endpoint_t endpoint, usb_direction_t direction) 169 179 { 170 UNSUPPORTED("unregister_endpoint"); 171 172 return ENOTSUP; 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 usb_endpoint_manager_unregister_ep(&hc->ep_manager, address, 186 endpoint, direction); 173 187 } 174 188 /*----------------------------------------------------------------------------*/ -
uspace/drv/ohci/ohci.c
r61257f4 rf8e8738 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
r61257f4 rf8e8738 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
r61257f4 rf8e8738 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
r61257f4 rf8e8738 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
r61257f4 rf8e8738 48 48 49 49 #include <ddf/driver.h> 50 #include <ddf/log.h> 50 51 #include <devman.h> 51 52 #include <ipc/devman.h> … … 106 107 } 107 108 108 size_t i; 109 for (i = 0; i < dev_data->hw_resources.count; i++) { 110 if (dev_data->hw_resources.resources[i].type == INTERRUPT) { 111 int irq = dev_data->hw_resources.resources[i].res.interrupt.irq; 112 int rc = async_req_1_0(irc_phone, IRC_ENABLE_INTERRUPT, irq); 109 size_t i = 0; 110 hw_resource_list_t *res = &dev_data->hw_resources; 111 for (; i < res->count; i++) { 112 if (res->resources[i].type == INTERRUPT) { 113 const int irq = res->resources[i].res.interrupt.irq; 114 const int rc = 115 async_req_1_0(irc_phone, IRC_ENABLE_INTERRUPT, irq); 113 116 if (rc != EOK) { 114 117 async_hangup(irc_phone); … … 325 328 326 329 if (match_id_str == NULL) { 327 printf(NAME ": out of memory creating match ID.\n");330 ddf_msg(LVL_ERROR, "Out of memory creating match ID."); 328 331 return; 329 332 } … … 331 334 rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 90); 332 335 if (rc != EOK) { 333 printf(NAME ": error adding match ID: %s\n",336 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", 334 337 str_error(rc)); 335 338 } … … 428 431 429 432 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);433 ddf_msg(LVL_DEBUG, "Function %s : address = %" PRIx64 434 ", size = %x", fun->fnode->name, range_addr, 435 (unsigned int) range_size); 433 436 } 434 437 … … 455 458 hw_res_list->count++; 456 459 457 printf(NAME ": function %s uses irq %x.\n", fun->fnode->name, irq);460 ddf_msg(LVL_NOTE, "Function %s uses irq %x.", fun->fnode->name, irq); 458 461 } 459 462 … … 511 514 char *fun_name = pci_fun_create_name(fun); 512 515 if (fun_name == NULL) { 513 printf(NAME ": out of memory.\n");516 ddf_msg(LVL_ERROR, "Out of memory."); 514 517 return; 515 518 } … … 517 520 fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name); 518 521 if (fnode == NULL) { 519 printf(NAME ": error creating function.\n");522 ddf_msg(LVL_ERROR, "Failed creating function."); 520 523 return; 521 524 } … … 531 534 fnode->driver_data = fun; 532 535 533 printf(NAME ": adding new function %s.\n",536 ddf_msg(LVL_DEBUG, "Adding new function %s.", 534 537 fnode->name); 535 538 … … 548 551 child_bus = pci_conf_read_8(fun, 549 552 PCI_BRIDGE_SEC_BUS_NUM); 550 printf(NAME ": device is pci-to-pci bridge, " 551 "secondary bus number = %d.\n", bus_num); 553 ddf_msg(LVL_DEBUG, "Device is pci-to-pci " 554 "bridge, secondary bus number = %d.", 555 bus_num); 552 556 if (child_bus > bus_num) 553 557 pci_bus_scan(bus, child_bus); … … 571 575 int rc; 572 576 573 printf(NAME ": pci_add_device\n");577 ddf_msg(LVL_DEBUG, "pci_add_device"); 574 578 dnode->parent_phone = -1; 575 579 576 580 bus = pci_bus_new(); 577 581 if (bus == NULL) { 578 printf(NAME ": pci_add_device allocation failed.\n");582 ddf_msg(LVL_ERROR, "pci_add_device allocation failed."); 579 583 rc = ENOMEM; 580 584 goto fail; … … 586 590 IPC_FLAG_BLOCKING); 587 591 if (dnode->parent_phone < 0) { 588 printf(NAME ":pci_add_device failed to connect to the "589 "parent's driver. \n");592 ddf_msg(LVL_ERROR, "pci_add_device failed to connect to the " 593 "parent's driver."); 590 594 rc = dnode->parent_phone; 591 595 goto fail; … … 596 600 rc = hw_res_get_resource_list(dnode->parent_phone, &hw_resources); 597 601 if (rc != EOK) { 598 printf(NAME ": pci_add_device failed to get hw resources for"599 " the device.\n");602 ddf_msg(LVL_ERROR, "pci_add_device failed to get hw resources " 603 "for the device."); 600 604 goto fail; 601 605 } 602 606 got_res = true; 603 607 604 printf(NAME ": conf_addr = %" PRIx64 ".\n",608 ddf_msg(LVL_DEBUG, "conf_addr = %" PRIx64 ".", 605 609 hw_resources.resources[0].res.io_range.address); 606 610 … … 614 618 if (pio_enable((void *)(uintptr_t)bus->conf_io_addr, 8, 615 619 &bus->conf_addr_port)) { 616 printf(NAME ": failed to enable configuration ports.\n");620 ddf_msg(LVL_ERROR, "Failed to enable configuration ports."); 617 621 rc = EADDRNOTAVAIL; 618 622 goto fail; … … 621 625 622 626 /* Make the bus device more visible. It has no use yet. */ 623 printf(NAME ": adding a 'ctl' function\n");627 ddf_msg(LVL_DEBUG, "Adding a 'ctl' function"); 624 628 625 629 ctl = ddf_fun_create(bus->dnode, fun_exposed, "ctl"); 626 630 if (ctl == NULL) { 627 printf(NAME ": error creating control function.\n");631 ddf_msg(LVL_ERROR, "Failed creating control function."); 628 632 rc = ENOMEM; 629 633 goto fail; … … 632 636 rc = ddf_fun_bind(ctl); 633 637 if (rc != EOK) { 634 printf(NAME ": error binding control function.\n");638 ddf_msg(LVL_ERROR, "Failed binding control function."); 635 639 goto fail; 636 640 } 637 641 638 642 /* Enumerate functions. */ 639 printf(NAME ": scanning the bus\n");643 ddf_msg(LVL_DEBUG, "Scanning the bus"); 640 644 pci_bus_scan(bus, 0); 641 645 … … 659 663 static void pciintel_init(void) 660 664 { 665 ddf_log_init(NAME, LVL_ERROR); 661 666 pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops; 662 667 pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops; … … 738 743 int main(int argc, char *argv[]) 739 744 { 740 printf(NAME ": HelenOS pci bus driver (intel method 1).\n");745 printf(NAME ": HelenOS PCI bus driver (Intel method 1).\n"); 741 746 pciintel_init(); 742 747 return ddf_driver_main(&pci_driver); -
uspace/drv/root/root.c
r61257f4 rf8e8738 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
r61257f4 rf8e8738 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
r61257f4 rf8e8738 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
r61257f4 rf8e8738 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
r61257f4 rf8e8738 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/batch.c
r61257f4 rf8e8738 49 49 td_t *tds; 50 50 size_t transfers; 51 usb_device_keeper_t *manager;52 51 } uhci_batch_t; 53 52 … … 73 72 * @param[in] func_out function to call on outbound transaction completion 74 73 * @param[in] arg additional parameter to func_in or func_out 75 * @param[in] manager Pointer totoggle management structure.74 * @param[in] ep Pointer to endpoint toggle management structure. 76 75 * @return Valid pointer if all substructures were successfully created, 77 76 * NULL otherwise. … … 86 85 char* setup_buffer, size_t setup_size, 87 86 usbhc_iface_transfer_in_callback_t func_in, 88 usbhc_iface_transfer_out_callback_t func_out, void *arg, 89 usb_device_keeper_t *manager 87 usbhc_iface_transfer_out_callback_t func_out, void *arg, endpoint_t *ep 90 88 ) 91 89 { … … 105 103 CHECK_NULL_DISPOSE_RETURN(instance, 106 104 "Failed to allocate batch instance.\n"); 107 usb_transfer_batch_init(instance, target, transfer_type, speed, max_packet_size, 105 usb_transfer_batch_init(instance, target, 106 transfer_type, speed, max_packet_size, 108 107 buffer, NULL, buffer_size, NULL, setup_size, func_in, 109 func_out, arg, fun, NULL);108 func_out, arg, fun, ep, NULL); 110 109 111 110 … … 114 113 "Failed to allocate batch instance.\n"); 115 114 bzero(data, sizeof(uhci_batch_t)); 116 data->manager = manager;117 115 instance->private_data = data; 118 116 … … 180 178 instance, i, data->tds[i].status); 181 179 td_print_status(&data->tds[i]); 182 183 usb_device_keeper_set_toggle(data->manager, 184 instance->target, instance->direction, 185 td_toggle(&data->tds[i])); 180 if (instance->ep != NULL) 181 endpoint_toggle_set(instance->ep, 182 td_toggle(&data->tds[i])); 186 183 if (i > 0) 187 184 goto substract_ret; … … 310 307 311 308 const bool low_speed = instance->speed == USB_SPEED_LOW; 312 int toggle = usb_device_keeper_get_toggle( 313 data->manager, instance->target, instance->direction); 309 int toggle = endpoint_toggle_get(instance->ep); 314 310 assert(toggle == 0 || toggle == 1); 315 311 … … 342 338 } 343 339 td_set_ioc(&data->tds[transfer - 1]); 344 usb_device_keeper_set_toggle(data->manager, instance->target, 345 instance->direction, toggle); 340 endpoint_toggle_set(instance->ep, toggle); 346 341 } 347 342 /*----------------------------------------------------------------------------*/ -
uspace/drv/uhci-hcd/batch.h
r61257f4 rf8e8738 35 35 #define DRV_UHCI_BATCH_H 36 36 37 #include <adt/list.h>38 39 37 #include <usbhc_iface.h> 40 38 #include <usb/usb.h> 41 39 #include <usb/host/device_keeper.h> 40 #include <usb/host/endpoint.h> 42 41 #include <usb/host/batch.h> 43 42 … … 57 56 usbhc_iface_transfer_out_callback_t func_out, 58 57 void *arg, 59 usb_device_keeper_t *manager58 endpoint_t *ep 60 59 ); 61 60 -
uspace/drv/uhci-hcd/hc.c
r61257f4 rf8e8738 66 66 static int hc_interrupt_emulator(void *arg); 67 67 static int hc_debug_checker(void *arg); 68 68 #if 0 69 69 static bool usb_is_allowed( 70 70 bool low_speed, usb_transfer_type_t transfer, size_t size); 71 #endif 71 72 /*----------------------------------------------------------------------------*/ 72 73 /** Initialize UHCI hcd driver structure … … 238 239 usb_device_keeper_init(&instance->manager); 239 240 usb_log_debug("Initialized device manager.\n"); 241 242 ret = 243 usb_endpoint_manager_init(&instance->ep_manager, 244 BANDWIDTH_AVAILABLE_USB11); 245 assert(ret == EOK); 240 246 241 247 return EOK; … … 322 328 assert(instance); 323 329 assert(batch); 324 const int low_speed = (batch->speed == USB_SPEED_LOW);325 if (!usb_is_allowed(326 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,330 batch->max_packet_size);331 return ENOTSUP;332 }333 /* TODO: check available bandwidth here */334 330 335 331 transfer_list_t *list = … … 338 334 if (batch->transfer_type == USB_TRANSFER_CONTROL) { 339 335 usb_device_keeper_use_control( 340 &instance->manager, batch->target .address);336 &instance->manager, batch->target); 341 337 } 342 338 transfer_list_add_batch(list, batch); … … 358 354 { 359 355 assert(instance); 356 // status |= 1; //Uncomment to work around qemu hang 360 357 /* TODO: Resume interrupts are not supported */ 361 358 /* Lower 2 bits are transaction error and transaction complete */ … … 376 373 usb_transfer_batch_t *batch = 377 374 list_get_instance(item, usb_transfer_batch_t, link); 378 if (batch->transfer_type == USB_TRANSFER_CONTROL) { 375 switch (batch->transfer_type) 376 { 377 case USB_TRANSFER_CONTROL: 379 378 usb_device_keeper_release_control( 380 &instance->manager, batch->target.address); 379 &instance->manager, batch->target); 380 break; 381 case USB_TRANSFER_INTERRUPT: 382 case USB_TRANSFER_ISOCHRONOUS: { 383 /* 384 int ret = bandwidth_free(&instance->bandwidth, 385 batch->target.address, 386 batch->target.endpoint, 387 batch->direction); 388 if (ret != EOK) 389 usb_log_warning("Failed(%d) to free " 390 "reserved bw: %s.\n", ret, 391 str_error(ret)); 392 */ 393 } 394 default: 395 break; 381 396 } 382 397 batch->next_step(batch); … … 499 514 * @return True if transaction is allowed by USB specs, false otherwise 500 515 */ 516 #if 0 501 517 bool usb_is_allowed( 502 518 bool low_speed, usb_transfer_type_t transfer, size_t size) … … 516 532 return false; 517 533 } 534 #endif 518 535 /** 519 536 * @} -
uspace/drv/uhci-hcd/hc.h
r61257f4 rf8e8738 43 43 #include <usbhc_iface.h> 44 44 #include <usb/host/device_keeper.h> 45 #include <usb/host/usb_endpoint_manager.h> 45 46 46 47 #include "batch.h" … … 84 85 typedef struct hc { 85 86 usb_device_keeper_t manager; 87 usb_endpoint_manager_t ep_manager; 86 88 87 89 regs_t *registers; -
uspace/drv/uhci-hcd/hw_struct/queue_head.h
r61257f4 rf8e8738 39 39 40 40 #include "link_pointer.h" 41 #include "utils/malloc32.h"42 41 43 42 typedef struct queue_head { -
uspace/drv/uhci-hcd/iface.c
r61257f4 rf8e8738 36 36 37 37 #include <usb/debug.h> 38 #include <usb/host/endpoint.h> 38 39 39 40 #include "iface.h" … … 54 55 usb_device_keeper_reserve_default_address(&hc->manager, speed); 55 56 return EOK; 57 #if 0 58 endpoint_t *ep = malloc(sizeof(endpoint_t)); 59 if (ep == NULL) 60 return ENOMEM; 61 const size_t max_packet_size = speed == USB_SPEED_LOW ? 8 : 64; 62 endpoint_init(ep, USB_TRANSFER_CONTROL, speed, max_packet_size); 63 int ret; 64 try_retgister: 65 ret = usb_endpoint_manager_register_ep(&hc->ep_manager, 66 USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH, ep, endpoint_destroy, 0); 67 if (ret == EEXISTS) { 68 async_usleep(1000); 69 goto try_retgister; 70 } 71 if (ret != EOK) { 72 endpoint_destroy(ep); 73 } 74 return ret; 75 #endif 56 76 } 57 77 /*----------------------------------------------------------------------------*/ … … 67 87 assert(hc); 68 88 usb_log_debug("Default address release.\n"); 89 // return usb_endpoint_manager_unregister_ep(&hc->ep_manager, 90 // USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH); 69 91 usb_device_keeper_release_default_address(&hc->manager); 70 92 return EOK; … … 128 150 } 129 151 /*----------------------------------------------------------------------------*/ 152 static int register_endpoint( 153 ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint, 154 usb_transfer_type_t transfer_type, usb_direction_t direction, 155 size_t max_packet_size, unsigned int interval) 156 { 157 hc_t *hc = fun_to_hc(fun); 158 assert(hc); 159 const usb_speed_t speed = 160 usb_device_keeper_get_speed(&hc->manager, address); 161 const size_t size = 162 (transfer_type == USB_TRANSFER_INTERRUPT 163 || transfer_type == USB_TRANSFER_ISOCHRONOUS) ? 164 max_packet_size : 0; 165 int ret; 166 167 endpoint_t *ep = malloc(sizeof(endpoint_t)); 168 if (ep == NULL) 169 return ENOMEM; 170 ret = endpoint_init(ep, address, endpoint, direction, 171 transfer_type, speed, max_packet_size); 172 if (ret != EOK) { 173 free(ep); 174 return ret; 175 } 176 177 usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n", 178 address, endpoint, usb_str_transfer_type(transfer_type), 179 usb_str_speed(speed), direction, size, max_packet_size, interval); 180 181 ret = usb_endpoint_manager_register_ep(&hc->ep_manager, ep, size); 182 if (ret != EOK) { 183 endpoint_destroy(ep); 184 } else { 185 usb_device_keeper_add_ep(&hc->manager, address, ep); 186 } 187 return ret; 188 } 189 /*----------------------------------------------------------------------------*/ 190 static int unregister_endpoint( 191 ddf_fun_t *fun, usb_address_t address, 192 usb_endpoint_t endpoint, usb_direction_t direction) 193 { 194 hc_t *hc = fun_to_hc(fun); 195 assert(hc); 196 usb_log_debug("Unregister endpoint %d:%d %d.\n", 197 address, endpoint, direction); 198 return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address, 199 endpoint, direction); 200 } 201 /*----------------------------------------------------------------------------*/ 130 202 /** Interrupt out transaction interface function 131 203 * … … 146 218 hc_t *hc = fun_to_hc(fun); 147 219 assert(hc); 148 usb_speed_t speed =149 usb_device_keeper_get_speed(&hc->manager, target.address);150 220 151 221 usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n", 152 222 target.address, target.endpoint, size, max_packet_size); 153 223 224 size_t res_bw; 225 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 226 target.address, target.endpoint, USB_DIRECTION_OUT, &res_bw); 227 if (ep == NULL) { 228 usb_log_error("Endpoint(%d:%d) not registered for INT OUT.\n", 229 target.address, target.endpoint); 230 return ENOENT; 231 } 232 const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type, 233 size, ep->max_packet_size); 234 if (res_bw < bw) 235 { 236 usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw " 237 "but only %zu is reserved.\n", 238 target.address, target.endpoint, bw, res_bw); 239 return ENOENT; 240 } 241 assert(ep->speed == 242 usb_device_keeper_get_speed(&hc->manager, target.address)); 243 assert(ep->max_packet_size == max_packet_size); 244 assert(ep->transfer_type == USB_TRANSFER_INTERRUPT); 245 154 246 usb_transfer_batch_t *batch = 155 batch_get(fun, target, USB_TRANSFER_INTERRUPT,max_packet_size,156 speed, data, size, NULL, 0, NULL, callback, arg, &hc->manager);247 batch_get(fun, target, ep->transfer_type, ep->max_packet_size, 248 ep->speed, data, size, NULL, 0, NULL, callback, arg, ep); 157 249 if (!batch) 158 250 return ENOMEM; … … 183 275 hc_t *hc = fun_to_hc(fun); 184 276 assert(hc); 185 usb_speed_t speed = 186 usb_device_keeper_get_speed(&hc->manager, target.address); 277 187 278 usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n", 188 279 target.address, target.endpoint, size, max_packet_size); 189 280 281 size_t res_bw; 282 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 283 target.address, target.endpoint, USB_DIRECTION_IN, &res_bw); 284 if (ep == NULL) { 285 usb_log_error("Endpoint(%d:%d) not registered for INT IN.\n", 286 target.address, target.endpoint); 287 return ENOENT; 288 } 289 const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type, 290 size, ep->max_packet_size); 291 if (res_bw < bw) 292 { 293 usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw " 294 "but only %zu bw is reserved.\n", 295 target.address, target.endpoint, bw, res_bw); 296 return ENOENT; 297 } 298 299 assert(ep->speed == 300 usb_device_keeper_get_speed(&hc->manager, target.address)); 301 assert(ep->max_packet_size == max_packet_size); 302 assert(ep->transfer_type == USB_TRANSFER_INTERRUPT); 303 190 304 usb_transfer_batch_t *batch = 191 batch_get(fun, target, USB_TRANSFER_INTERRUPT,max_packet_size,192 speed, data, size, NULL, 0, callback, NULL, arg, &hc->manager);305 batch_get(fun, target, ep->transfer_type, ep->max_packet_size, 306 ep->speed, data, size, NULL, 0, callback, NULL, arg, ep); 193 307 if (!batch) 194 308 return ENOMEM; … … 219 333 hc_t *hc = fun_to_hc(fun); 220 334 assert(hc); 221 usb_speed_t speed =222 usb_device_keeper_get_speed(&hc->manager, target.address);223 335 224 336 usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n", 225 337 target.address, target.endpoint, size, max_packet_size); 226 338 339 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 340 target.address, target.endpoint, USB_DIRECTION_OUT, NULL); 341 if (ep == NULL) { 342 usb_log_error("Endpoint(%d:%d) not registered for BULK OUT.\n", 343 target.address, target.endpoint); 344 return ENOENT; 345 } 346 assert(ep->speed == 347 usb_device_keeper_get_speed(&hc->manager, target.address)); 348 assert(ep->max_packet_size == max_packet_size); 349 assert(ep->transfer_type == USB_TRANSFER_BULK); 350 227 351 usb_transfer_batch_t *batch = 228 batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,229 data, size, NULL, 0, NULL, callback, arg, &hc->manager);352 batch_get(fun, target, ep->transfer_type, ep->max_packet_size, 353 ep->speed, data, size, NULL, 0, NULL, callback, arg, ep); 230 354 if (!batch) 231 355 return ENOMEM; … … 256 380 hc_t *hc = fun_to_hc(fun); 257 381 assert(hc); 258 usb_speed_t speed =259 usb_device_keeper_get_speed(&hc->manager, target.address);260 382 usb_log_debug("Bulk IN %d:%d %zu(%zu).\n", 261 383 target.address, target.endpoint, size, max_packet_size); 262 384 385 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 386 target.address, target.endpoint, USB_DIRECTION_IN, NULL); 387 if (ep == NULL) { 388 usb_log_error("Endpoint(%d:%d) not registered for BULK IN.\n", 389 target.address, target.endpoint); 390 return ENOENT; 391 } 392 assert(ep->speed == 393 usb_device_keeper_get_speed(&hc->manager, target.address)); 394 assert(ep->max_packet_size == max_packet_size); 395 assert(ep->transfer_type == USB_TRANSFER_BULK); 396 263 397 usb_transfer_batch_t *batch = 264 batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,265 data, size, NULL, 0, callback, NULL, arg, &hc->manager);398 batch_get(fun, target, ep->transfer_type, ep->max_packet_size, 399 ep->speed, data, size, NULL, 0, callback, NULL, arg, ep); 266 400 if (!batch) 267 401 return ENOMEM; … … 299 433 usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n", 300 434 speed, target.address, target.endpoint, size, max_packet_size); 435 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 436 target.address, target.endpoint, USB_DIRECTION_BOTH, NULL); 437 if (ep == NULL) { 438 usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n", 439 target.address, target.endpoint); 440 } 301 441 302 442 if (setup_size != 8) … … 305 445 usb_transfer_batch_t *batch = 306 446 batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed, 307 data, size, setup_data, setup_size, NULL, callback, arg, 308 &hc->manager); 447 data, size, setup_data, setup_size, NULL, callback, arg, ep); 309 448 if (!batch) 310 449 return ENOMEM; … … 344 483 usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n", 345 484 speed, target.address, target.endpoint, size, max_packet_size); 485 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 486 target.address, target.endpoint, USB_DIRECTION_BOTH, NULL); 487 if (ep == NULL) { 488 usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n", 489 target.address, target.endpoint); 490 } 346 491 usb_transfer_batch_t *batch = 347 492 batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed, 348 data, size, setup_data, setup_size, callback, NULL, arg, 349 &hc->manager); 493 data, size, setup_data, setup_size, callback, NULL, arg, ep); 350 494 if (!batch) 351 495 return ENOMEM; … … 365 509 .release_address = release_address, 366 510 511 .register_endpoint = register_endpoint, 512 .unregister_endpoint = unregister_endpoint, 513 367 514 .interrupt_out = interrupt_out, 368 515 .interrupt_in = interrupt_in, -
uspace/drv/uhci-hcd/transfer_list.h
r61257f4 rf8e8738 39 39 #include "batch.h" 40 40 #include "hw_struct/queue_head.h" 41 #include "utils/malloc32.h" 41 42 42 43 typedef struct transfer_list -
uspace/drv/uhci-hcd/utils/malloc32.h
r61257f4 rf8e8738 36 36 37 37 #include <assert.h> 38 #include <errno.h> 38 39 #include <malloc.h> 39 40 #include <mem.h> -
uspace/drv/uhci-rhd/main.c
r61257f4 rf8e8738 44 44 45 45 #define NAME "uhci-rhd" 46 46 47 static int hc_get_my_registers(ddf_dev_t *dev, 47 48 uintptr_t *io_reg_address, size_t *io_reg_size); 48 #if 049 49 /*----------------------------------------------------------------------------*/ 50 static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle) 51 { 52 assert(fun); 53 assert(fun->driver_data); 54 assert(handle); 55 56 *handle = ((uhci_root_hub_t*)fun->driver_data)->hc_handle; 57 58 return EOK; 59 } 60 /*----------------------------------------------------------------------------*/ 61 static usb_iface_t uhci_rh_usb_iface = { 62 .get_hc_handle = usb_iface_get_hc_handle, 63 .get_address = usb_iface_get_address_hub_impl 64 }; 65 /*----------------------------------------------------------------------------*/ 66 static ddf_dev_ops_t uhci_rh_ops = { 67 .interfaces[USB_DEV_IFACE] = &uhci_rh_usb_iface, 68 }; 69 #endif 70 /*----------------------------------------------------------------------------*/ 71 /** Initialize a new ddf driver instance of UHCI root hub. 72 * 73 * @param[in] device DDF instance of the device to initialize. 74 * @return Error code. 75 */ 76 static int uhci_rh_add_device(ddf_dev_t *device) 77 { 78 if (!device) 79 return ENOTSUP; 80 81 usb_log_debug2("%s called device %d\n", __FUNCTION__, device->handle); 82 83 //device->ops = &uhci_rh_ops; 84 uintptr_t io_regs = 0; 85 size_t io_size = 0; 86 87 int ret = hc_get_my_registers(device, &io_regs, &io_size); 88 if (ret != EOK) { 89 usb_log_error("Failed to get registers from parent HC: %s.\n", 90 str_error(ret)); 91 } 92 usb_log_debug("I/O regs at %#X (size %zu).\n", io_regs, io_size); 93 94 uhci_root_hub_t *rh = malloc(sizeof(uhci_root_hub_t)); 95 if (!rh) { 96 usb_log_error("Failed to allocate driver instance.\n"); 97 return ENOMEM; 98 } 99 100 ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device); 101 if (ret != EOK) { 102 usb_log_error("Failed to initialize driver instance: %s.\n", 103 str_error(ret)); 104 free(rh); 105 return ret; 106 } 107 108 device->driver_data = rh; 109 usb_log_info("Controlling root hub `%s' (%llu).\n", 110 device->name, device->handle); 111 return EOK; 112 } 50 static int uhci_rh_add_device(ddf_dev_t *device); 113 51 /*----------------------------------------------------------------------------*/ 114 52 static driver_ops_t uhci_rh_driver_ops = { … … 132 70 { 133 71 printf(NAME ": HelenOS UHCI root hub driver.\n"); 72 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 73 return ddf_driver_main(&uhci_rh_driver); 74 } 75 /*----------------------------------------------------------------------------*/ 76 /** Initialize a new ddf driver instance of UHCI root hub. 77 * 78 * @param[in] device DDF instance of the device to initialize. 79 * @return Error code. 80 */ 81 static int uhci_rh_add_device(ddf_dev_t *device) 82 { 83 if (!device) 84 return EINVAL; 134 85 135 usb_log_ enable(USB_LOG_LEVEL_DEFAULT, NAME);86 usb_log_debug2("%s called device %d\n", __FUNCTION__, device->handle); 136 87 137 return ddf_driver_main(&uhci_rh_driver); 88 uintptr_t io_regs = 0; 89 size_t io_size = 0; 90 uhci_root_hub_t *rh = NULL; 91 int ret = EOK; 92 93 #define CHECK_RET_FREE_RH_RETURN(ret, message...) \ 94 if (ret != EOK) { \ 95 usb_log_error(message); \ 96 if (rh) \ 97 free(rh); \ 98 return ret; \ 99 } else (void)0 100 101 ret = hc_get_my_registers(device, &io_regs, &io_size); 102 CHECK_RET_FREE_RH_RETURN(ret, 103 "Failed(%d) to get registers from HC: %s.\n", ret, str_error(ret)); 104 usb_log_debug("I/O regs at %#x (size %zu).\n", io_regs, io_size); 105 106 rh = malloc(sizeof(uhci_root_hub_t)); 107 ret = (rh == NULL) ? ENOMEM : EOK; 108 CHECK_RET_FREE_RH_RETURN(ret, 109 "Failed to allocate rh driver instance.\n"); 110 111 ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device); 112 CHECK_RET_FREE_RH_RETURN(ret, 113 "Failed(%d) to initialize rh driver instance: %s.\n", 114 ret, str_error(ret)); 115 116 device->driver_data = rh; 117 usb_log_info("Controlling root hub '%s' (%llu).\n", 118 device->name, device->handle); 119 return EOK; 138 120 } 139 121 /*----------------------------------------------------------------------------*/ … … 156 138 } 157 139 158 int rc;159 160 140 hw_resource_list_t hw_resources; 161 rc = hw_res_get_resource_list(parent_phone, &hw_resources); 162 if (rc != EOK) { 163 goto leave; 141 int ret = hw_res_get_resource_list(parent_phone, &hw_resources); 142 if (ret != EOK) { 143 async_hangup(parent_phone); 144 return ret; 164 145 } 165 146 … … 168 149 bool io_found = false; 169 150 170 size_t i ;171 for ( i = 0; i < hw_resources.count; i++) {151 size_t i = 0; 152 for (; i < hw_resources.count; i++) { 172 153 hw_resource_t *res = &hw_resources.resources[i]; 173 switch (res->type) 174 { 175 case IO_RANGE: 176 io_address = (uintptr_t) res->res.io_range.address; 154 if (res->type == IO_RANGE) { 155 io_address = res->res.io_range.address; 177 156 io_size = res->res.io_range.size; 178 157 io_found = true; 179 180 default:181 break;182 158 } 183 159 } 160 async_hangup(parent_phone); 184 161 185 162 if (!io_found) { 186 rc = ENOENT; 187 goto leave; 163 return ENOENT; 188 164 } 189 190 165 if (io_reg_address != NULL) { 191 166 *io_reg_address = io_address; … … 194 169 *io_reg_size = io_size; 195 170 } 196 rc = EOK; 197 198 leave: 199 async_hangup(parent_phone); 200 return rc; 171 return EOK; 201 172 } 202 173 /** -
uspace/drv/uhci-rhd/port.c
r61257f4 rf8e8738 43 43 #include "port.h" 44 44 45 static int uhci_port_check(void *port); 46 static int uhci_port_reset_enable(int portno, void *arg); 45 47 static int uhci_port_new_device(uhci_port_t *port, usb_speed_t speed); 46 48 static int uhci_port_remove_device(uhci_port_t *port); 47 49 static int uhci_port_set_enabled(uhci_port_t *port, bool enabled); 48 static int uhci_port_check(void *port);49 static int uhci_port_reset_enable(int portno, void *arg);50 50 static void uhci_port_print_status( 51 51 uhci_port_t *port, const port_status_t value); … … 74 74 pio_write_16(port->address, value); 75 75 } 76 77 76 /*----------------------------------------------------------------------------*/ 78 77 /** Initialize UHCI root hub port instance. … … 259 258 260 259 usb_address_t dev_addr; 261 int r c= usb_hc_new_device_wrapper(port->rh, &port->hc_connection,260 int ret = usb_hc_new_device_wrapper(port->rh, &port->hc_connection, 262 261 speed, uhci_port_reset_enable, port->number, port, 263 262 &dev_addr, &port->attached_device, NULL, NULL, NULL); 264 263 265 if (r c!= EOK) {264 if (ret != EOK) { 266 265 usb_log_error("%s: Failed(%d) to add device: %s.\n", 267 port->id_string, r c, str_error(rc));266 port->id_string, ret, str_error(ret)); 268 267 uhci_port_set_enabled(port, false); 269 return r c;268 return ret; 270 269 } 271 270 … … 287 286 int uhci_port_remove_device(uhci_port_t *port) 288 287 { 289 usb_log_error("%s: Don't know how to remove device % d.\n",290 port->id_string, (unsigned int)port->attached_device);291 return E OK;288 usb_log_error("%s: Don't know how to remove device %llu.\n", 289 port->id_string, port->attached_device); 290 return ENOTSUP; 292 291 } 293 292 /*----------------------------------------------------------------------------*/ … … 341 340 (value & STATUS_CONNECTED_CHANGED) ? " CONNECTED-CHANGE," : "", 342 341 (value & STATUS_CONNECTED) ? " CONNECTED," : "", 343 (value & STATUS_ALWAYS_ONE) ? " ALWAYS ONE" : " ERR OR: NO ALWAYS ONE"342 (value & STATUS_ALWAYS_ONE) ? " ALWAYS ONE" : " ERR: NO ALWAYS ONE" 344 343 ); 345 344 } -
uspace/drv/uhci-rhd/root_hub.c
r61257f4 rf8e8738 51 51 assert(instance); 52 52 assert(rh); 53 int ret;54 53 55 54 /* Allow access to root hub port registers */ 56 55 assert(sizeof(port_status_t) * UHCI_ROOT_HUB_PORT_COUNT <= size); 57 56 port_status_t *regs; 58 ret = pio_enable(addr, size, (void**)®s);57 int ret = pio_enable(addr, size, (void**)®s); 59 58 if (ret < 0) { 60 59 usb_log_error( … … 84 83 * 85 84 * @param[in] instance Root hub structure to use. 86 * @return Error code.87 85 */ 88 intuhci_root_hub_fini(uhci_root_hub_t* instance)86 void uhci_root_hub_fini(uhci_root_hub_t* instance) 89 87 { 90 88 assert(instance); … … 93 91 uhci_port_fini(&instance->ports[i]); 94 92 } 95 return EOK;96 93 } 97 94 /*----------------------------------------------------------------------------*/ -
uspace/drv/uhci-rhd/root_hub.h
r61257f4 rf8e8738 50 50 uhci_root_hub_t *instance, void *addr, size_t size, ddf_dev_t *rh); 51 51 52 intuhci_root_hub_fini(uhci_root_hub_t *instance);52 void uhci_root_hub_fini(uhci_root_hub_t *instance); 53 53 #endif 54 54 /** -
uspace/drv/usbhub/Makefile
r61257f4 rf8e8738 34 34 SOURCES = \ 35 35 main.c \ 36 ports.c \ 36 37 utils.c \ 37 usbhub.c \ 38 usblist.c 38 usbhub.c 39 39 40 40 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/usbhub/port_status.h
r61257f4 rf8e8738 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/ports.h
r61257f4 rf8e8738 1 1 /* 2 * Copyright (c) 201 0 Matus Dekanek2 * Copyright (c) 2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 /** @addtogroup drvusbhub 29 30 * @{ 30 31 */ 31 32 /** @file 32 * @brief usblist implementation33 * Hub ports related functions. 33 34 */ 34 #include <sys/types.h> 35 #ifndef DRV_USBHUB_PORTS_H 36 #define DRV_USBHUB_PORTS_H 35 37 36 #include "usbhub_private.h" 38 #include <ipc/devman.h> 39 #include <usb/usb.h> 40 #include <ddf/driver.h> 41 #include <fibril_synch.h> 42 43 #include <usb/hub.h> 44 45 #include <usb/pipes.h> 46 #include <usb/devdrv.h> 47 48 /** Information about single port on a hub. */ 49 typedef struct { 50 /** Mutex needed by CV for checking port reset. */ 51 fibril_mutex_t reset_mutex; 52 /** CV for waiting to port reset completion. */ 53 fibril_condvar_t reset_cv; 54 /** Whether port reset is completed. 55 * Guarded by @c reset_mutex. 56 */ 57 bool reset_completed; 58 59 /** Information about attached device. */ 60 usb_hc_attached_device_t attached_device; 61 } usb_hub_port_t; 62 63 /** Initialize hub port information. 64 * 65 * @param port Port to be initialized. 66 */ 67 static inline void usb_hub_port_init(usb_hub_port_t *port) { 68 port->attached_device.address = -1; 69 port->attached_device.handle = 0; 70 fibril_mutex_initialize(&port->reset_mutex); 71 fibril_condvar_initialize(&port->reset_cv); 72 } 73 74 bool hub_port_changes_callback(usb_device_t *, uint8_t *, size_t, void *); 37 75 38 76 39 usb_general_list_t * usb_lst_create(void) { 40 usb_general_list_t* result = usb_new(usb_general_list_t); 41 usb_lst_init(result); 42 return result; 43 } 44 45 void usb_lst_init(usb_general_list_t * lst) { 46 lst->prev = lst; 47 lst->next = lst; 48 lst->data = NULL; 49 } 50 51 void usb_lst_prepend(usb_general_list_t* item, void* data) { 52 usb_general_list_t* appended = usb_new(usb_general_list_t); 53 appended->data = data; 54 appended->next = item; 55 appended->prev = item->prev; 56 item->prev->next = appended; 57 item->prev = appended; 58 } 59 60 void usb_lst_append(usb_general_list_t* item, void* data) { 61 usb_general_list_t* appended = usb_new(usb_general_list_t); 62 appended->data = data; 63 appended->next = item->next; 64 appended->prev = item; 65 item->next->prev = appended; 66 item->next = appended; 67 } 68 69 void usb_lst_remove(usb_general_list_t* item) { 70 item->next->prev = item->prev; 71 item->prev->next = item->next; 72 } 73 74 75 77 #endif 76 78 /** 77 79 * @} 78 80 */ 79 80 -
uspace/drv/usbhub/usbhub.c
r61257f4 rf8e8738 53 53 #include "usb/classes/classes.h" 54 54 55 56 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,57 usb_speed_t speed);58 59 55 static int usb_hub_trigger_connecting_non_removable_devices( 60 56 usb_hub_info_t * hub, usb_hub_descriptor_t * descriptor); 61 62 /**63 * control loop running in hub`s fibril64 *65 * Hub`s fibril periodically asks for changes on hub and if needded calls66 * change handling routine.67 * @warning currently hub driver asks for changes once a second68 * @param hub_info_param hub representation pointer69 * @return zero70 */71 int usb_hub_control_loop(void * hub_info_param){72 usb_hub_info_t * hub_info = (usb_hub_info_t*)hub_info_param;73 int errorCode = EOK;74 75 while(errorCode == EOK){76 errorCode = usb_hub_check_hub_changes(hub_info);77 async_usleep(1000 * 1000 );/// \TODO proper number once78 }79 usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode);80 81 return 0;82 }83 57 84 58 … … 152 126 usb_log_debug("setting port count to %d\n",descriptor->ports_count); 153 127 hub_info->port_count = descriptor->ports_count; 154 hub_info->attached_devs = (usb_hc_attached_device_t*) 155 malloc((hub_info->port_count+1) * sizeof(usb_hc_attached_device_t)); 156 int i; 157 for(i=0;i<hub_info->port_count+1;++i){ 158 hub_info->attached_devs[i].handle=0; 159 hub_info->attached_devs[i].address=0; 128 hub_info->ports = malloc(sizeof(usb_hub_port_t) * (hub_info->port_count+1)); 129 size_t port; 130 for (port = 0; port < hub_info->port_count + 1; port++) { 131 usb_hub_port_init(&hub_info->ports[port]); 160 132 } 161 133 //handle non-removable devices … … 259 231 assert(rc == EOK); 260 232 261 //create fibril for the hub control loop 262 fid_t fid = fibril_create(usb_hub_control_loop, hub_info); 263 if (fid == 0) { 264 usb_log_error("failed to start monitoring fibril for new hub.\n"); 265 return ENOMEM; 266 } 267 fibril_add_ready(fid); 268 usb_log_debug("Hub fibril created.\n"); 233 /* 234 * The processing will require opened control pipe and connection 235 * to the host controller. 236 * It is waste of resources but let's hope there will be less 237 * hubs than the phone limit. 238 * FIXME: with some proper locking over pipes and session 239 * auto destruction, this could work better. 240 */ 241 rc = usb_pipe_start_session(&usb_dev->ctrl_pipe); 242 if (rc != EOK) { 243 usb_log_error("Failed to start session on control pipe: %s.\n", 244 str_error(rc)); 245 goto leave; 246 } 247 rc = usb_hc_connection_open(&hub_info->connection); 248 if (rc != EOK) { 249 usb_pipe_end_session(&usb_dev->ctrl_pipe); 250 usb_log_error("Failed to open connection to HC: %s.\n", 251 str_error(rc)); 252 goto leave; 253 } 254 255 rc = usb_device_auto_poll(hub_info->usb_device, 0, 256 hub_port_changes_callback, ((hub_info->port_count+1) / 8) + 1, 257 NULL, hub_info); 258 if (rc != EOK) { 259 usb_log_error("Failed to create polling fibril: %s.\n", 260 str_error(rc)); 261 free(hub_info); 262 return rc; 263 } 269 264 270 265 usb_log_info("Controlling hub `%s' (%d ports).\n", 271 266 hub_info->usb_device->ddf_dev->name, hub_info->port_count); 272 267 return EOK; 268 269 leave: 270 free(hub_info); 271 272 return rc; 273 273 } 274 274 … … 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 } … … 352 397 hub->is_default_address_used = false; 353 398 return EOK; 354 }355 356 /**357 * Reset the port with new device and reserve the default address.358 * @param hub hub representation359 * @param port port number, starting from 1360 * @param speed transfer speed of attached device, one of low, full or high361 */362 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,363 usb_speed_t speed) {364 //if this hub already uses default address, it cannot request it once more365 if(hub->is_default_address_used) return;366 usb_log_debug("some connection changed\n");367 assert(hub->control_pipe->hc_phone);368 int opResult = usb_hub_clear_port_feature(hub->control_pipe,369 port, USB_HUB_FEATURE_C_PORT_CONNECTION);370 if(opResult != EOK){371 usb_log_warning("could not clear port-change-connection flag\n");372 }373 usb_device_request_setup_packet_t request;374 375 //get default address376 opResult = usb_hc_reserve_default_address(&hub->connection, speed);377 378 if (opResult != EOK) {379 usb_log_warning("cannot assign default address, it is probably used %d\n",380 opResult);381 return;382 }383 hub->is_default_address_used = true;384 //reset port385 usb_hub_set_reset_port_request(&request, port);386 opResult = usb_pipe_control_write(387 hub->control_pipe,388 &request,sizeof(usb_device_request_setup_packet_t),389 NULL, 0390 );391 if (opResult != EOK) {392 usb_log_error("something went wrong when reseting a port %d\n",opResult);393 usb_hub_release_default_address(hub);394 }395 return;396 }397 398 /**399 * Finalize adding new device after port reset400 *401 * Set device`s address and start it`s driver.402 * @param hub hub representation403 * @param port port number, starting from 1404 * @param speed transfer speed of attached device, one of low, full or high405 */406 static void usb_hub_finalize_add_device( usb_hub_info_t * hub,407 uint16_t port, usb_speed_t speed) {408 409 int opResult;410 usb_log_debug("finalizing add device\n");411 opResult = usb_hub_clear_port_feature(hub->control_pipe,412 port, USB_HUB_FEATURE_C_PORT_RESET);413 414 if (opResult != EOK) {415 usb_log_error("failed to clear port reset feature\n");416 usb_hub_release_default_address(hub);417 return;418 }419 //create connection to device420 usb_pipe_t new_device_pipe;421 usb_device_connection_t new_device_connection;422 usb_device_connection_initialize_on_default_address(423 &new_device_connection,424 &hub->connection425 );426 usb_pipe_initialize_default_control(427 &new_device_pipe,428 &new_device_connection);429 usb_pipe_probe_default_control(&new_device_pipe);430 431 /* Request address from host controller. */432 usb_address_t new_device_address = usb_hc_request_address(433 &hub->connection,434 speed435 );436 if (new_device_address < 0) {437 usb_log_error("failed to get free USB address\n");438 opResult = new_device_address;439 usb_hub_release_default_address(hub);440 return;441 }442 usb_log_debug("setting new address %d\n",new_device_address);443 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,444 // new_device_address);445 usb_pipe_start_session(&new_device_pipe);446 opResult = usb_request_set_address(&new_device_pipe,new_device_address);447 usb_pipe_end_session(&new_device_pipe);448 if (opResult != EOK) {449 usb_log_error("could not set address for new device %d\n",opResult);450 usb_hub_release_default_address(hub);451 return;452 }453 454 //opResult = usb_hub_release_default_address(hc);455 opResult = usb_hub_release_default_address(hub);456 if(opResult!=EOK){457 return;458 }459 460 devman_handle_t child_handle;461 //??462 opResult = usb_device_register_child_in_devman(new_device_address,463 hub->connection.hc_handle, hub->usb_device->ddf_dev, &child_handle,464 NULL, NULL, NULL);465 466 if (opResult != EOK) {467 usb_log_error("could not start driver for new device %d\n",opResult);468 return;469 }470 hub->attached_devs[port].handle = child_handle;471 hub->attached_devs[port].address = new_device_address;472 473 //opResult = usb_drv_bind_address(hc, new_device_address, child_handle);474 opResult = usb_hc_register_device(475 &hub->connection,476 &hub->attached_devs[port]);477 if (opResult != EOK) {478 usb_log_error("could not assign address of device in hcd %d\n",opResult);479 return;480 }481 usb_log_info("Detected new device on `%s' (port %d), " \482 "address %d (handle %llu).\n",483 hub->usb_device->ddf_dev->name, (int) port,484 new_device_address, child_handle);485 399 } 486 400 … … 494 408 * @param port port number, starting from 1 495 409 */ 496 staticvoid usb_hub_removed_device(410 void usb_hub_removed_device( 497 411 usb_hub_info_t * hub,uint16_t port) { 498 412 … … 507 421 508 422 //close address 509 if(hub-> attached_devs[port].address!=0){423 if(hub->ports[port].attached_device.address >= 0){ 510 424 /*uncomment this code to use it when DDF allows device removal 511 425 opResult = usb_hc_unregister_device( … … 534 448 * @param port port number, starting from 1 535 449 */ 536 staticvoid usb_hub_over_current( usb_hub_info_t * hub,450 void usb_hub_over_current( usb_hub_info_t * hub, 537 451 uint16_t port){ 538 452 int opResult; … … 545 459 } 546 460 547 /**548 * Process interrupts on given hub port549 *550 * Accepts connection, over current and port reset change.551 * @param hub hub representation552 * @param port port number, starting from 1553 */554 static void usb_hub_process_interrupt(usb_hub_info_t * hub,555 uint16_t port) {556 usb_log_debug("interrupt at port %d\n", port);557 //determine type of change558 usb_pipe_t *pipe = hub->control_pipe;559 560 int opResult;561 562 usb_port_status_t status;563 size_t rcvd_size;564 usb_device_request_setup_packet_t request;565 //int opResult;566 usb_hub_set_port_status_request(&request, port);567 //endpoint 0568 569 opResult = usb_pipe_control_read(570 pipe,571 &request, sizeof(usb_device_request_setup_packet_t),572 &status, 4, &rcvd_size573 );574 if (opResult != EOK) {575 usb_log_error("could not get port status\n");576 return;577 }578 if (rcvd_size != sizeof (usb_port_status_t)) {579 usb_log_error("received status has incorrect size\n");580 return;581 }582 //something connected/disconnected583 if (usb_port_connect_change(&status)) {584 if (usb_port_dev_connected(&status)) {585 usb_log_debug("some connection changed\n");586 usb_hub_init_add_device(hub, port, usb_port_speed(&status));587 } else {588 usb_hub_removed_device(hub, port);589 }590 }591 //over current592 if (usb_port_overcurrent_change(&status)) {593 //check if it was not auto-resolved594 if(usb_port_over_current(&status)){595 usb_hub_over_current(hub,port);596 }else{597 usb_log_debug("over current condition was auto-resolved on port %d\n",598 port);599 }600 }601 //port reset602 if (usb_port_reset_completed(&status)) {603 usb_log_debug("port reset complete\n");604 if (usb_port_enabled(&status)) {605 usb_hub_finalize_add_device(hub, port, usb_port_speed(&status));606 } else {607 usb_log_warning("port reset, but port still not enabled\n");608 }609 }610 611 usb_port_set_connect_change(&status, false);612 usb_port_set_reset(&status, false);613 usb_port_set_reset_completed(&status, false);614 usb_port_set_dev_connected(&status, false);615 if (status>>16) {616 usb_log_info("there was some unsupported change on port %d: %X\n",617 port,status);618 619 }620 }621 622 /**623 * check changes on hub624 *625 * Handles changes on each port with a status change.626 * @param hub_info hub representation627 * @return error code628 */629 int usb_hub_check_hub_changes(usb_hub_info_t * hub_info){630 int opResult;631 opResult = usb_pipe_start_session(632 hub_info->status_change_pipe);633 if(opResult != EOK){634 usb_log_error("could not initialize communication for hub; %d\n",635 opResult);636 return opResult;637 }638 639 size_t port_count = hub_info->port_count;640 641 /// FIXME: count properly642 size_t byte_length = ((port_count+1) / 8) + 1;643 void *change_bitmap = malloc(byte_length);644 size_t actual_size;645 646 /*647 * Send the request.648 */649 opResult = usb_pipe_read(650 hub_info->status_change_pipe,651 change_bitmap, byte_length, &actual_size652 );653 654 if (opResult != EOK) {655 free(change_bitmap);656 usb_log_warning("something went wrong while getting status of hub\n");657 usb_pipe_end_session(hub_info->status_change_pipe);658 return opResult;659 }660 unsigned int port;661 opResult = usb_pipe_start_session(hub_info->control_pipe);662 if(opResult!=EOK){663 usb_log_error("could not start control pipe session %d\n", opResult);664 usb_pipe_end_session(hub_info->status_change_pipe);665 return opResult;666 }667 opResult = usb_hc_connection_open(&hub_info->connection);668 if(opResult!=EOK){669 usb_log_error("could not start host controller session %d\n",670 opResult);671 usb_pipe_end_session(hub_info->control_pipe);672 usb_pipe_end_session(hub_info->status_change_pipe);673 return opResult;674 }675 676 ///todo, opresult check, pre obe konekce677 for (port = 1; port < port_count+1; ++port) {678 bool interrupt =679 (((uint8_t*) change_bitmap)[port / 8] >> (port % 8)) % 2;680 if (interrupt) {681 usb_hub_process_interrupt(682 hub_info, port);683 }684 }685 usb_hc_connection_close(&hub_info->connection);686 usb_pipe_end_session(hub_info->control_pipe);687 usb_pipe_end_session(hub_info->status_change_pipe);688 free(change_bitmap);689 return EOK;690 }691 692 693 461 694 462 /** -
uspace/drv/usbhub/usbhub.h
r61257f4 rf8e8738 47 47 #include <usb/devdrv.h> 48 48 49 #include "ports.h" 50 51 49 52 50 53 /** Information about attached hub. */ 51 54 typedef struct { 52 55 /** Number of ports. */ 53 int port_count;56 size_t port_count; 54 57 55 /** attached device handles, for each port one*/56 usb_h c_attached_device_t * attached_devs;58 /** Ports. */ 59 usb_hub_port_t *ports; 57 60 58 61 /** connection to hcd */ … … 100 103 int usb_hub_check_hub_changes(usb_hub_info_t * hub_info_param); 101 104 105 void usb_hub_removed_device(usb_hub_info_t *, uint16_t); 106 void usb_hub_over_current(usb_hub_info_t *, uint16_t); 102 107 103 108 int usb_hub_add_device(usb_device_t * usb_dev); -
uspace/drv/usbhub/usbhub_private.h
r61257f4 rf8e8738 38 38 39 39 #include "usbhub.h" 40 #include "usblist.h"41 40 42 41 #include <adt/list.h> -
uspace/drv/usbmid/explore.c
r61257f4 rf8e8738 48 48 }; 49 49 50 /** Find starting indexes of all interface descriptors in a configuration. 51 * 52 * @param config_descriptor Full configuration descriptor. 53 * @param config_descriptor_size Size of @p config_descriptor in bytes. 54 * @param interface_positions Array where to store indexes of interfaces. 55 * @param interface_count Size of @p interface_positions array. 56 * @return Number of found interfaces. 57 * @retval (size_t)-1 Error occured. 58 */ 59 static size_t find_interface_descriptors(uint8_t *config_descriptor, 60 size_t config_descriptor_size, 61 size_t *interface_positions, size_t interface_count) 50 /** Tell whether given interface is already in the list. 51 * 52 * @param list List of usbmid_interface_t members to be searched. 53 * @param interface_no Interface number caller is looking for. 54 * @return Interface @p interface_no is already present in the list. 55 */ 56 static bool interface_in_list(link_t *list, int interface_no) 62 57 { 63 if (interface_count == 0) { 64 return (size_t) -1; 65 } 66 58 link_t *l; 59 for (l = list->next; l != list; l = l->next) { 60 usbmid_interface_t *iface 61 = list_get_instance(l, usbmid_interface_t, link); 62 if (iface->interface_no == interface_no) { 63 return true; 64 } 65 } 66 67 return false; 68 } 69 70 /** Create list of interfaces from configuration descriptor. 71 * 72 * @param config_descriptor Configuration descriptor. 73 * @param config_descriptor_size Size of configuration descriptor in bytes. 74 * @param list List where to add the interfaces. 75 */ 76 static void create_interfaces(uint8_t *config_descriptor, 77 size_t config_descriptor_size, link_t *list) 78 { 67 79 usb_dp_parser_data_t data = { 68 80 .data = config_descriptor, … … 75 87 }; 76 88 77 uint8_t *interface = usb_dp_get_nested_descriptor(&parser, &data,89 uint8_t *interface_ptr = usb_dp_get_nested_descriptor(&parser, &data, 78 90 data.data); 79 if (interface == NULL) { 80 return (size_t) -1; 81 } 82 if (interface[1] != USB_DESCTYPE_INTERFACE) { 83 return (size_t) -1; 84 } 85 86 size_t found_interfaces = 0; 87 interface_positions[found_interfaces] = interface - config_descriptor; 88 found_interfaces++; 89 90 while (interface != NULL) { 91 interface = usb_dp_get_sibling_descriptor(&parser, &data, 92 data.data, interface); 93 if ((interface != NULL) 94 && (found_interfaces < interface_count) 95 && (interface[1] == USB_DESCTYPE_INTERFACE)) { 96 interface_positions[found_interfaces] 97 = interface - config_descriptor; 98 found_interfaces++; 99 } 100 } 101 102 return found_interfaces; 91 if (interface_ptr == NULL) { 92 return; 93 } 94 95 do { 96 if (interface_ptr[1] != USB_DESCTYPE_INTERFACE) { 97 goto next_descriptor; 98 } 99 100 usb_standard_interface_descriptor_t *interface 101 = (usb_standard_interface_descriptor_t *) interface_ptr; 102 103 /* Skip alternate interfaces. */ 104 if (!interface_in_list(list, interface->interface_number)) { 105 usbmid_interface_t *iface 106 = malloc(sizeof(usbmid_interface_t)); 107 if (iface == NULL) { 108 break; 109 } 110 link_initialize(&iface->link); 111 iface->fun = NULL; 112 iface->interface_no = interface->interface_number; 113 iface->interface = interface; 114 115 list_append(&iface->link, list); 116 } 117 118 /* TODO: add the alternatives and create match ids from them 119 * as well. 120 */ 121 122 next_descriptor: 123 interface_ptr = usb_dp_get_sibling_descriptor(&parser, &data, 124 data.data, interface_ptr); 125 126 } while (interface_ptr != NULL); 127 103 128 } 104 129 … … 130 155 (usb_standard_configuration_descriptor_t *) config_descriptor_raw; 131 156 132 size_t *interface_descriptors133 = malloc(sizeof(size_t) * config_descriptor->interface_count);134 if (interface_descriptors == NULL) {135 usb_log_error("Out of memory (wanted %zuB).\n",136 sizeof(size_t) * config_descriptor->interface_count);137 free(config_descriptor_raw);138 return false;139 }140 size_t interface_descriptors_count141 = find_interface_descriptors(142 config_descriptor_raw, config_descriptor_size,143 interface_descriptors, config_descriptor->interface_count);144 145 if (interface_descriptors_count == (size_t) -1) {146 usb_log_error("Problem parsing configuration descriptor.\n");147 free(interface_descriptors);148 return false;149 }150 151 157 /* Select the first configuration */ 152 158 rc = usb_request_set_configuration(&dev->ctrl_pipe, … … 155 161 usb_log_error("Failed to set device configuration: %s.\n", 156 162 str_error(rc)); 157 free(interface_descriptors); 158 return false; 159 } 160 163 return false; 164 } 161 165 162 166 /* Create control function */ … … 164 168 if (ctl_fun == NULL) { 165 169 usb_log_error("Failed to create control function.\n"); 166 free(interface_descriptors);167 170 return false; 168 171 } … … 174 177 usb_log_error("Failed to bind control function: %s.\n", 175 178 str_error(rc)); 176 free(interface_descriptors); 177 return false; 178 } 179 180 /* Spawn interface children */ 181 size_t i; 182 for (i = 0; i < interface_descriptors_count; i++) { 183 usb_standard_interface_descriptor_t *interface 184 = (usb_standard_interface_descriptor_t *) 185 (config_descriptor_raw + interface_descriptors[i]); 186 usb_log_debug2("Interface descriptor at index %zu (type %d).\n", 187 interface_descriptors[i], (int) interface->descriptor_type); 179 return false; 180 } 181 182 /* Create interface children. */ 183 link_t interface_list; 184 list_initialize(&interface_list); 185 create_interfaces(config_descriptor_raw, config_descriptor_size, 186 &interface_list); 187 188 link_t *link; 189 for (link = interface_list.next; link != &interface_list; 190 link = link->next) { 191 usbmid_interface_t *iface = list_get_instance(link, 192 usbmid_interface_t, link); 193 188 194 usb_log_info("Creating child for interface %d (%s).\n", 189 (int) interface->interface_number, 190 usb_str_class(interface->interface_class)); 191 rc = usbmid_spawn_interface_child(dev, &dev->descriptors.device, 192 interface); 195 (int) iface->interface_no, 196 usb_str_class(iface->interface->interface_class)); 197 198 rc = usbmid_spawn_interface_child(dev, iface, 199 &dev->descriptors.device, iface->interface); 193 200 if (rc != EOK) { 194 201 usb_log_error("Failed to create interface child: %s.\n", -
uspace/drv/usbmid/usbmid.c
r61257f4 rf8e8738 79 79 }; 80 80 81 /** Create new interface for USB MID device.82 *83 * @param fun Backing generic DDF device function (representing interface).84 * @param iface_no Interface number.85 * @return New interface.86 * @retval NULL Error occured.87 */88 usbmid_interface_t *usbmid_interface_create(ddf_fun_t *fun, int iface_no)89 {90 usbmid_interface_t *iface = malloc(sizeof(usbmid_interface_t));91 if (iface == NULL) {92 usb_log_error("Out of memory (wanted %zuB).\n",93 sizeof(usbmid_interface_t));94 return NULL;95 }96 97 iface->fun = fun;98 iface->interface_no = iface_no;99 100 return iface;101 }102 103 81 104 82 /** Spawn new child device from one interface. 105 83 * 106 84 * @param parent Parent MID device. 85 * @param iface Interface information. 107 86 * @param device_descriptor Device descriptor. 108 87 * @param interface_descriptor Interface descriptor. … … 110 89 */ 111 90 int usbmid_spawn_interface_child(usb_device_t *parent, 91 usbmid_interface_t *iface, 112 92 const usb_standard_device_descriptor_t *device_descriptor, 113 93 const usb_standard_interface_descriptor_t *interface_descriptor) … … 115 95 ddf_fun_t *child = NULL; 116 96 char *child_name = NULL; 117 usbmid_interface_t *child_as_interface = NULL;118 97 int rc; 119 98 … … 137 116 } 138 117 118 iface->fun = child; 139 119 140 141 child_as_interface = usbmid_interface_create(child, 142 (int) interface_descriptor->interface_number); 143 if (child_as_interface == NULL) { 144 rc = ENOMEM; 145 goto error_leave; 146 } 147 148 child->driver_data = child_as_interface; 120 child->driver_data = iface; 149 121 child->ops = &child_device_ops; 150 122 … … 172 144 free(child_name); 173 145 } 174 if (child_as_interface != NULL) {175 free(child_as_interface);176 }177 146 178 147 return rc; -
uspace/drv/usbmid/usbmid.h
r61257f4 rf8e8738 37 37 #define USBMID_H_ 38 38 39 #include <adt/list.h> 39 40 #include <ddf/driver.h> 40 41 #include <usb/usb.h> … … 49 50 /** Function container. */ 50 51 ddf_fun_t *fun; 51 52 /** Interface descriptor. */ 53 usb_standard_interface_descriptor_t *interface; 52 54 /** Interface number. */ 53 55 int interface_no; 56 /** List link. */ 57 link_t link; 54 58 } usbmid_interface_t; 55 59 56 usbmid_interface_t *usbmid_interface_create(ddf_fun_t *, int);57 60 bool usbmid_explore_device(usb_device_t *); 58 int usbmid_spawn_interface_child(usb_device_t *, 61 int usbmid_spawn_interface_child(usb_device_t *, usbmid_interface_t *, 59 62 const usb_standard_device_descriptor_t *, 60 63 const usb_standard_interface_descriptor_t *);
Note:
See TracChangeset
for help on using the changeset viewer.
