Changeset a35b458 in mainline for uspace/drv/bus
- Timestamp:
- 2018-03-02T20:10:49Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- Location:
- uspace/drv/bus
- Files:
-
- 13 edited
-
isa/i8237.c (modified) (17 diffs)
-
isa/isa.c (modified) (4 diffs)
-
pci/pciintel/pci.c (modified) (40 diffs)
-
usb/ehci/ehci_bus.h (modified) (1 diff)
-
usb/ohci/hc.h (modified) (1 diff)
-
usb/ohci/ohci_rh.c (modified) (1 diff)
-
usb/usbhub/port.c (modified) (1 diff)
-
usb/usbmid/explore.c (modified) (1 diff)
-
usb/vhc/conndev.c (modified) (4 diffs)
-
usb/vhc/hub/virthubops.c (modified) (2 diffs)
-
usb/vhc/transfer.c (modified) (1 diff)
-
usb/xhci/debug.c (modified) (1 diff)
-
usb/xhci/rh.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/isa/i8237.c
r3061bc1 ra35b458 99 99 uint8_t channel_start3; 100 100 uint8_t channel_count3; 101 101 102 102 uint8_t command_status; 103 103 104 104 /** Memory to memory transfers, NOT implemented on PCs */ 105 105 uint8_t request; … … 107 107 uint8_t mode; 108 108 uint8_t flip_flop; 109 109 110 110 /* 111 111 * Master reset sets Flip-Flop low, clears status, … … 136 136 uint8_t reserved6; 137 137 uint8_t channel_count7; 138 138 139 139 uint8_t command_status; 140 140 uint8_t reserved8; … … 230 230 .flip_flop_address = (uint8_t *) 0x0c, 231 231 }, 232 232 233 233 /* The second chip 16-bit */ 234 234 { /* Channel 4 - Unusable */ … … 265 265 }, 266 266 }, 267 267 268 268 .page_table = NULL, 269 269 .first = NULL, … … 286 286 if (ret != EOK) 287 287 return EIO; 288 288 289 289 ret = pio_enable(DMA_CONTROLLER_FIRST_BASE, 290 290 sizeof(dma_controller_regs_first_t), (void **) &controller->first); 291 291 if (ret != EOK) 292 292 return EIO; 293 293 294 294 ret = pio_enable(DMA_CONTROLLER_SECOND_BASE, 295 295 sizeof(dma_controller_regs_second_t), (void **) &controller->second); 296 296 if (ret != EOK) 297 297 return EIO; 298 298 299 299 controller->initialized = true; 300 300 301 301 /* Reset the controller */ 302 302 pio_write_8(&controller->second->master_reset, 0xff); 303 303 pio_write_8(&controller->first->master_reset, 0xff); 304 304 305 305 return EOK; 306 306 } … … 347 347 if ((channel == 0) || (channel == 4)) 348 348 return ENOTSUP; 349 349 350 350 /* DMA is limited to 24bit addresses. */ 351 351 if (pa >= (1 << 24)) 352 352 return EINVAL; 353 353 354 354 /* 8 bit channels use only 4 bits from the page register. */ 355 355 if (is_dma8(channel) && (pa >= (1 << 20))) … … 359 359 if ((pa & 0xffff0000) != ((pa + size - 1) & 0xffff0000)) 360 360 return EINVAL; 361 361 362 362 fibril_mutex_lock(&guard); 363 363 364 364 if (!controller_8237.initialized) 365 365 dma_controller_init(&controller_8237); 366 366 367 367 if (!controller_8237.initialized) { 368 368 fibril_mutex_unlock(&guard); 369 369 return EIO; 370 370 } 371 371 372 372 /* 16 bit transfers are a bit special */ 373 373 ddf_msg(LVL_DEBUG, "Unspoiled address %#" PRIx32 " (size %" PRIu32 ")", … … 384 384 pa = ((pa & 0xffff) >> 1) | (pa & 0xff0000); 385 385 } 386 386 387 387 const dma_channel_t dma_channel = controller_8237.channels[channel]; 388 388 389 389 ddf_msg(LVL_DEBUG, "Setting channel %u to address %#" PRIx32 " " 390 390 "(size %" PRIu32 "), mode %hhx.", channel, pa, size, mode); 391 391 392 392 /* Mask DMA request */ 393 393 uint8_t value = DMA_SINGLE_MASK_CHAN_TO_REG(channel) | 394 394 DMA_SINGLE_MASK_MASKED_FLAG; 395 395 pio_write_8(dma_channel.single_mask_address, value); 396 396 397 397 /* Set mode */ 398 398 value = DMA_MODE_CHAN_TO_REG(channel) | mode; … … 400 400 dma_channel.mode_address, value); 401 401 pio_write_8(dma_channel.mode_address, value); 402 402 403 403 /* Set address - reset flip-flop */ 404 404 pio_write_8(dma_channel.flip_flop_address, 0); 405 405 406 406 /* Low byte */ 407 407 value = pa & 0xff; … … 409 409 dma_channel.offset_reg_address, value); 410 410 pio_write_8(dma_channel.offset_reg_address, value); 411 411 412 412 /* High byte */ 413 413 value = (pa >> 8) & 0xff; … … 415 415 dma_channel.offset_reg_address, value); 416 416 pio_write_8(dma_channel.offset_reg_address, value); 417 417 418 418 /* Page address - third byte */ 419 419 value = (pa >> 16) & 0xff; … … 421 421 dma_channel.page_reg_address, value); 422 422 pio_write_8(dma_channel.page_reg_address, value); 423 423 424 424 /* Set size - reset flip-flop */ 425 425 pio_write_8(dma_channel.flip_flop_address, 0); 426 426 427 427 /* Low byte */ 428 428 value = (size - 1) & 0xff; … … 430 430 dma_channel.size_reg_address, value); 431 431 pio_write_8(dma_channel.size_reg_address, value); 432 432 433 433 /* High byte */ 434 434 value = ((size - 1) >> 8) & 0xff; … … 436 436 dma_channel.size_reg_address, value); 437 437 pio_write_8(dma_channel.size_reg_address, value); 438 438 439 439 /* Unmask DMA request */ 440 440 value = DMA_SINGLE_MASK_CHAN_TO_REG(channel); 441 441 pio_write_8(dma_channel.single_mask_address, value); 442 442 443 443 fibril_mutex_unlock(&guard); 444 444 445 445 return EOK; 446 446 } … … 459 459 if (!is_dma8(channel) && !is_dma16(channel)) 460 460 return ENOENT; 461 461 462 462 if ((channel == 0) || (channel == 4)) 463 463 return ENOTSUP; 464 464 465 465 fibril_mutex_lock(&guard); 466 466 if (!controller_8237.initialized) { … … 472 472 /* Get size - reset flip-flop */ 473 473 pio_write_8(dma_channel.flip_flop_address, 0); 474 474 475 475 /* Low byte */ 476 476 const uint8_t value_low = pio_read_8(dma_channel.size_reg_address); 477 477 ddf_msg(LVL_DEBUG2, "Read size low byte: %p:%x.", 478 478 dma_channel.size_reg_address, value_low); 479 479 480 480 /* High byte */ 481 481 const uint8_t value_high = pio_read_8(dma_channel.size_reg_address); -
uspace/drv/bus/isa/isa.c
r3061bc1 ra35b458 402 402 size_t count = fun->hw_resources.count; 403 403 hw_resource_t *resources = fun->hw_resources.resources; 404 404 405 405 if (count < ISA_MAX_HW_RES) { 406 406 if ((dma > 0) && (dma < 4)) { 407 407 resources[count].type = DMA_CHANNEL_8; 408 408 resources[count].res.dma_channel.dma8 = dma; 409 409 410 410 fun->hw_resources.count++; 411 411 ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma, 412 412 ddf_fun_get_name(fun->fnode)); 413 413 414 414 return; 415 415 } … … 418 418 resources[count].type = DMA_CHANNEL_16; 419 419 resources[count].res.dma_channel.dma16 = dma; 420 420 421 421 fun->hw_resources.count++; 422 422 ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma, 423 423 ddf_fun_get_name(fun->fnode)); 424 424 425 425 return; 426 426 } 427 427 428 428 ddf_msg(LVL_WARN, "Skipped dma 0x%x for function %s", dma, 429 429 ddf_fun_get_name(fun->fnode)); … … 492 492 { 493 493 char *end = NULL; 494 494 495 495 val = skip_spaces(val); 496 496 const int dma = strtol(val, &end, 10); 497 497 498 498 if (val != end) 499 499 isa_fun_add_dma(fun, dma); … … 733 733 if (rc != EOK) 734 734 return rc; 735 735 736 736 rc = pio_window_get(sess, &isa->pio_win); 737 737 if (rc != EOK) { -
uspace/drv/bus/pci/pciintel/pci.c
r3061bc1 ra35b458 93 93 { 94 94 pci_fun_t *fun = pci_fun(fnode); 95 95 96 96 if (fun == NULL) 97 97 return NULL; … … 103 103 size_t i; 104 104 hw_resource_list_t *res = &fun->hw_resources; 105 105 106 106 for (i = 0; i < res->count; i++) { 107 107 if (res->resources[i].type == INTERRUPT && … … 110 110 } 111 111 } 112 112 113 113 return false; 114 114 } … … 117 117 { 118 118 pci_fun_t *fun = pci_fun(fnode); 119 119 120 120 if (!pciintel_fun_owns_interrupt(fun, irq)) 121 121 return EINVAL; … … 127 127 { 128 128 pci_fun_t *fun = pci_fun(fnode); 129 129 130 130 if (!pciintel_fun_owns_interrupt(fun, irq)) 131 131 return EINVAL; … … 137 137 { 138 138 pci_fun_t *fun = pci_fun(fnode); 139 139 140 140 if (!pciintel_fun_owns_interrupt(fun, irq)) 141 141 return EINVAL; … … 147 147 { 148 148 pci_fun_t *fun = pci_fun(fnode); 149 149 150 150 if (fun == NULL) 151 151 return NULL; … … 256 256 pci_bus_t *bus = pci_bus_from_fun(fun); 257 257 uint32_t val; 258 258 259 259 fibril_mutex_lock(&bus->conf_mutex); 260 260 … … 285 285 break; 286 286 } 287 287 288 288 fibril_mutex_unlock(&bus->conf_mutex); 289 289 } … … 294 294 pci_bus_t *bus = pci_bus_from_fun(fun); 295 295 uint32_t val = 0; 296 296 297 297 fibril_mutex_lock(&bus->conf_mutex); 298 298 … … 317 317 } 318 318 } 319 319 320 320 switch (len) { 321 321 case 1: … … 340 340 host2uint32_t_le(val)); 341 341 } 342 342 343 343 fibril_mutex_unlock(&bus->conf_mutex); 344 344 } … … 458 458 hw_resource_t *hw_resources = hw_res_list->resources; 459 459 size_t count = hw_res_list->count; 460 460 461 461 assert(hw_resources != NULL); 462 462 assert(count < PCI_MAX_HW_RES); 463 463 464 464 if (io) { 465 465 hw_resources[count].type = IO_RANGE; … … 475 475 hw_resources[count].res.mem_range.endianness = LITTLE_ENDIAN; 476 476 } 477 477 478 478 hw_res_list->count++; 479 479 } … … 498 498 /* 64-bit wide address */ 499 499 bool addrw64; 500 500 501 501 /* Size of the io or memory range specified by the BAR */ 502 502 size_t range_size; 503 503 /* Beginning of the io or memory range specified by the BAR */ 504 504 uint64_t range_addr; 505 505 506 506 /* Get the value of the BAR. */ 507 507 val = pci_conf_read_32(fun, addr); … … 509 509 #define IO_MASK (~0x3) 510 510 #define MEM_MASK (~0xf) 511 511 512 512 io = (val & 1) != 0; 513 513 if (io) { … … 528 528 } 529 529 } 530 530 531 531 /* Get the address mask. */ 532 532 pci_conf_write_32(fun, addr, 0xffffffff); … … 544 544 pci_conf_write_32(fun, addr, val); 545 545 val = pci_conf_read_32(fun, addr); 546 546 547 547 range_size = pci_bar_mask_to_size(mask); 548 548 549 549 if (addrw64) { 550 550 range_addr = ((uint64_t)pci_conf_read_32(fun, addr + 4) << 32) | … … 553 553 range_addr = (val & 0xfffffff0); 554 554 } 555 555 556 556 if (range_addr != 0) { 557 557 ddf_msg(LVL_DEBUG, "Function %s : address = %" PRIx64 … … 559 559 (unsigned int) range_size); 560 560 } 561 561 562 562 pci_add_range(fun, range_addr, range_size, io); 563 563 564 564 if (addrw64) 565 565 return addr + 8; 566 566 567 567 return addr + 4; 568 568 } … … 573 573 hw_resource_t *hw_resources = hw_res_list->resources; 574 574 size_t count = hw_res_list->count; 575 575 576 576 assert(NULL != hw_resources); 577 577 assert(count < PCI_MAX_HW_RES); 578 578 579 579 hw_resources[count].type = INTERRUPT; 580 580 hw_resources[count].res.interrupt.irq = irq; 581 581 582 582 hw_res_list->count++; 583 583 584 584 ddf_msg(LVL_NOTE, "Function %s uses irq %x.", ddf_fun_get_name(fun->fnode), irq); 585 585 } … … 603 603 pci_fun_t *fun; 604 604 errno_t rc; 605 605 606 606 int child_bus = 0; 607 607 int dnum, fnum; 608 608 bool multi; 609 609 uint8_t header_type; 610 610 611 611 for (dnum = 0; dnum < 32; dnum++) { 612 612 multi = true; 613 613 for (fnum = 0; multi && fnum < 8; fnum++) { 614 614 fun = pci_fun_new(bus); 615 615 616 616 pci_fun_init(fun, bus_num, dnum, fnum); 617 617 if (fun->vendor_id == 0xffff) { … … 626 626 continue; 627 627 } 628 628 629 629 header_type = pci_conf_read_8(fun, PCI_HEADER_TYPE); 630 630 if (fnum == 0) { … … 634 634 /* Clear the multifunction bit. */ 635 635 header_type = header_type & 0x7F; 636 636 637 637 char *fun_name = pci_fun_create_name(fun); 638 638 if (fun_name == NULL) { … … 641 641 return; 642 642 } 643 643 644 644 rc = ddf_fun_set_name(fun->fnode, fun_name); 645 645 free(fun_name); … … 649 649 return; 650 650 } 651 651 652 652 pci_alloc_resource_list(fun); 653 653 pci_read_bars(fun); … … 656 656 /* Propagate the PIO window to the function. */ 657 657 fun->pio_window = bus->pio_win; 658 658 659 659 ddf_fun_set_ops(fun->fnode, &pci_fun_ops); 660 660 661 661 ddf_msg(LVL_DEBUG, "Adding new function %s.", 662 662 ddf_fun_get_name(fun->fnode)); 663 663 664 664 pci_fun_create_match_ids(fun); 665 665 666 666 if (ddf_fun_bind(fun->fnode) != EOK) { 667 667 pci_clean_resource_list(fun); … … 669 669 continue; 670 670 } 671 671 672 672 if (header_type == PCI_HEADER_TYPE_BRIDGE || 673 673 header_type == PCI_HEADER_TYPE_CARDBUS) { … … 692 692 async_sess_t *sess; 693 693 errno_t rc; 694 694 695 695 ddf_msg(LVL_DEBUG, "pci_dev_add"); 696 696 697 697 bus = ddf_dev_data_alloc(dnode, sizeof(pci_bus_t)); 698 698 if (bus == NULL) { … … 704 704 705 705 bus->dnode = dnode; 706 706 707 707 sess = ddf_dev_parent_sess_get(dnode); 708 708 if (sess == NULL) { … … 719 719 goto fail; 720 720 } 721 721 722 722 rc = hw_res_get_resource_list(sess, &hw_resources); 723 723 if (rc != EOK) { … … 727 727 } 728 728 got_res = true; 729 730 729 730 731 731 assert(hw_resources.count >= 1); 732 732 … … 745 745 goto fail; 746 746 } 747 747 748 748 } else { 749 749 assert(hw_resources.resources[0].type == IO_RANGE); 750 750 assert(hw_resources.resources[0].res.io_range.size >= 4); 751 751 752 752 assert(hw_resources.resources[1].type == IO_RANGE); 753 753 assert(hw_resources.resources[1].res.io_range.size >= 4); 754 754 755 755 ddf_msg(LVL_DEBUG, "conf_addr = %" PRIx64 ".", 756 756 hw_resources.resources[0].res.io_range.address); 757 757 ddf_msg(LVL_DEBUG, "data_addr = %" PRIx64 ".", 758 758 hw_resources.resources[1].res.io_range.address); 759 759 760 760 if (pio_enable_resource(&bus->pio_win, 761 761 &hw_resources.resources[0], … … 775 775 } 776 776 } 777 777 778 778 /* Make the bus device more visible. It has no use yet. */ 779 779 ddf_msg(LVL_DEBUG, "Adding a 'ctl' function"); 780 780 781 781 ctl = ddf_fun_create(bus->dnode, fun_exposed, "ctl"); 782 782 if (ctl == NULL) { … … 785 785 goto fail; 786 786 } 787 787 788 788 rc = ddf_fun_bind(ctl); 789 789 if (rc != EOK) { … … 791 791 goto fail; 792 792 } 793 793 794 794 /* Enumerate functions. */ 795 795 ddf_msg(LVL_DEBUG, "Scanning the bus"); 796 796 pci_bus_scan(bus, 0); 797 797 798 798 hw_res_clean_resource_list(&hw_resources); 799 799 800 800 return EOK; 801 801 802 802 fail: 803 803 if (got_res) 804 804 hw_res_clean_resource_list(&hw_resources); 805 805 806 806 if (ctl != NULL) 807 807 ddf_fun_destroy(ctl); 808 808 809 809 return rc; 810 810 } … … 831 831 pci_fun_t *fun; 832 832 ddf_fun_t *fnode; 833 833 834 834 fnode = ddf_fun_create(bus->dnode, fun_inner, NULL); 835 835 if (fnode == NULL) … … 852 852 fun->vendor_id = pci_conf_read_16(fun, PCI_VENDOR_ID); 853 853 fun->device_id = pci_conf_read_16(fun, PCI_DEVICE_ID); 854 854 855 855 /* Explicitly enable PCI bus mastering */ 856 856 fun->command = pci_conf_read_16(fun, PCI_COMMAND) | 857 857 PCI_COMMAND_MASTER; 858 858 pci_conf_write_16(fun, PCI_COMMAND, fun->command); 859 859 860 860 fun->class_code = pci_conf_read_8(fun, PCI_BASE_CLASS); 861 861 fun->subclass_code = pci_conf_read_8(fun, PCI_SUB_CLASS); … … 874 874 { 875 875 char *name = NULL; 876 876 877 877 asprintf(&name, "%02x:%02x.%01x", fun->bus, fun->dev, 878 878 fun->fn); … … 903 903 */ 904 904 int addr = PCI_BASE_ADDR_0; 905 905 906 906 while (addr <= PCI_BASE_ADDR_5) 907 907 addr = pci_read_bar(fun, addr); -
uspace/drv/bus/usb/ehci/ehci_bus.h
r3061bc1 ra35b458 51 51 /** EHCI endpoint descriptor, backed by dma_buffer */ 52 52 qh_t *qh; 53 53 54 54 dma_buffer_t dma_buffer; 55 55 -
uspace/drv/bus/usb/ohci/hc.h
r3061bc1 ra35b458 64 64 /** Memory mapped I/O registers area */ 65 65 ohci_regs_t *registers; 66 66 67 67 /** Host controller communication area structure */ 68 68 hcca_t *hcca; -
uspace/drv/bus/usb/ohci/ohci_rh.c
r3061bc1 ra35b458 409 409 TEST_SIZE_INIT(0, port, hub); 410 410 const unsigned feature = uint16_usb2host(setup_packet->value); 411 411 412 412 switch (feature) { 413 413 case USB_HUB_FEATURE_PORT_POWER: /*8*/ 414 414 { 415 415 const uint32_t rhda = OHCI_RD(hub->registers->rh_desc_a); 416 416 417 417 /* No power switching */ 418 418 if (rhda & RHDA_NPS_FLAG) 419 419 return EOK; 420 420 421 421 /* Ganged power switching, one port powers all */ 422 422 if (!(rhda & RHDA_PSM_FLAG)) { -
uspace/drv/bus/usb/usbhub/port.c
r3061bc1 ra35b458 87 87 return; 88 88 } 89 89 90 90 const errno_t err = usbhc_device_remove(exch, port->port_number); 91 91 if (err) -
uspace/drv/bus/usb/usbmid/explore.c
r3061bc1 ra35b458 164 164 return rc; 165 165 } 166 166 167 167 /* Create driver soft-state. */ 168 168 usb_mid_t *usb_mid = usb_device_data_alloc(dev, sizeof(usb_mid_t)); -
uspace/drv/bus/usb/vhc/conndev.c
r3061bc1 ra35b458 57 57 { 58 58 async_exch_t *exch = async_exchange_begin(sess); 59 59 60 60 aid_t opening_request = async_send_0(exch, IPC_M_USBVIRT_GET_NAME, NULL); 61 61 if (opening_request == 0) { … … 63 63 return; 64 64 } 65 65 66 66 ipc_call_t data_request_call; 67 67 aid_t data_request = async_data_read(exch, plugged_device_name, 68 68 PLUGGED_DEVICE_NAME_MAXLEN, &data_request_call); 69 69 70 70 async_exchange_end(exch); 71 71 72 72 if (data_request == 0) { 73 73 async_forget(opening_request); 74 74 return; 75 75 } 76 76 77 77 errno_t data_request_rc; 78 78 errno_t opening_request_rc; 79 79 async_wait_for(data_request, &data_request_rc); 80 80 async_wait_for(opening_request, &opening_request_rc); 81 81 82 82 if ((data_request_rc != EOK) || (opening_request_rc != EOK)) 83 83 return; 84 84 85 85 size_t len = IPC_GET_ARG2(data_request_call); 86 86 plugged_device_name[len] = 0; … … 97 97 { 98 98 vhc_data_t *vhc = ddf_fun_data_get(fun); 99 99 100 100 async_sess_t *callback = 101 101 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); 102 102 103 103 if (callback) { 104 104 errno_t rc = vhc_virtdev_plug(vhc, callback, &plugged_device_handle); … … 108 108 return; 109 109 } 110 110 111 111 async_answer_0(icallid, EOK); 112 112 113 113 receive_device_name(callback); 114 114 115 115 usb_log_info("New virtual device `%s' (id: %" PRIxn ").", 116 116 plugged_device_name, plugged_device_handle); -
uspace/drv/bus/usb/vhc/hub/virthubops.c
r3061bc1 ra35b458 73 73 return ESTALL; 74 74 } 75 75 76 76 hub_t *hub = dev->device_data; 77 77 … … 94 94 *actual_size = 0; 95 95 } 96 96 97 97 hub->signal_changes = false; 98 98 -
uspace/drv/bus/usb/vhc/transfer.c
r3061bc1 ra35b458 228 228 229 229 fibril_mutex_unlock(&vhc->guard); 230 230 231 231 if (targets > 1) 232 232 usb_log_warning("Transfer would be accepted by more devices!"); -
uspace/drv/bus/usb/xhci/debug.c
r3061bc1 ra35b458 301 301 static const char speed_exp [] = " KMG"; 302 302 static const char *psi_types [] = { "", " rsvd", " RX", " TX" }; 303 303 304 304 usb_log_debug("Speed %u%s: %5u %cb/s, %s", 305 305 XHCI_REG_RD(psi, XHCI_PSI_PSIV), -
uspace/drv/bus/usb/xhci/rh.c
r3061bc1 ra35b458 273 273 if (status != 0) 274 274 usb_log_debug("RH port %u change not handled: 0x%x", port_id, status); 275 275 276 276 /* Make sure that PSCEG is 0 before exiting the loop. */ 277 277 status = XHCI_REG_RD_FIELD(&port->regs->portsc, 32);
Note:
See TracChangeset
for help on using the changeset viewer.
