Changeset 0206d35 in mainline for uspace/drv/bus/usb/xhci/hc.c
- Timestamp:
- 2017-10-25T00:03:57Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c3d926f3
- Parents:
- 56db65d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/hc.c
r56db65d r0206d35 43 43 #include "rh.h" 44 44 #include "hw_struct/trb.h" 45 #include "hw_struct/context.h" 46 #include "endpoint.h" 45 47 #include "commands.h" 46 48 #include "transfers.h" … … 449 451 { 450 452 assert(batch); 453 assert(batch->ep); 451 454 452 455 usb_log_debug2("Endpoint(%d:%d) started %s transfer of size %lu.", … … 632 635 } 633 636 634 int hc_address_device(xhci_hc_t *hc, uint32_t slot_id, xhci_input_ctx_t *ictx)635 {636 assert(hc);637 638 int err;639 xhci_cmd_t cmd;640 xhci_cmd_init(&cmd);641 642 cmd.slot_id = slot_id;643 644 if ((err = xhci_send_address_device_command(hc, &cmd, ictx)) != EOK)645 return err;646 647 if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT)) != EOK)648 return err;649 650 xhci_cmd_fini(&cmd);651 return EOK;652 }653 654 637 static int create_valid_input_ctx(xhci_input_ctx_t **out_ictx) 655 638 { … … 674 657 } 675 658 676 int hc_address_rh_device(xhci_hc_t *hc, uint32_t slot_id, uint8_t port, xhci_ep_ctx_t *ep_ctx) 659 // TODO: This currently assumes the device is attached to rh directly 660 // -> calculate route string 661 int hc_address_device(xhci_hc_t *hc, xhci_device_t *dev, xhci_endpoint_t *ep0) 662 { 663 int err = ENOMEM; 664 665 /* Setup and register device context */ 666 dev->dev_ctx = malloc32(sizeof(xhci_device_ctx_t)); 667 if (!dev->dev_ctx) 668 goto err; 669 memset(dev->dev_ctx, 0, sizeof(xhci_device_ctx_t)); 670 671 hc->dcbaa[dev->slot_id] = addr_to_phys(dev->dev_ctx); 672 673 /* Issue configure endpoint command (sec 4.3.5). */ 674 xhci_input_ctx_t *ictx; 675 if ((err = create_valid_input_ctx(&ictx))) { 676 goto err_dev_ctx; 677 } 678 679 /* Initialize slot_ctx according to section 4.3.3 point 3. */ 680 XHCI_SLOT_ROOT_HUB_PORT_SET(ictx->slot_ctx, dev->base.port); // FIXME: This should be port at RH 681 XHCI_SLOT_CTX_ENTRIES_SET(ictx->slot_ctx, 1); 682 683 /* Attaching to root hub port, root string equals to 0. */ 684 XHCI_SLOT_ROUTE_STRING_SET(ictx->slot_ctx, 0); // FIXME: This is apparently valid in limited cases 685 686 /* Copy endpoint 0 context and set A1 flag. */ 687 XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 1); 688 xhci_setup_endpoint_context(ep0, &ictx->endpoint_ctx[0]); 689 690 xhci_cmd_t cmd; 691 xhci_cmd_init(&cmd); 692 693 cmd.slot_id = dev->slot_id; 694 695 if ((err = xhci_send_address_device_command(hc, &cmd, ictx)) != EOK) 696 goto err_cmd; 697 698 if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT)) != EOK) 699 goto err_cmd; 700 701 dev->base.address = XHCI_SLOT_DEVICE_ADDRESS(dev->dev_ctx->slot_ctx); 702 usb_log_debug2("Obtained USB address: %d.\n", dev->base.address); 703 704 /* From now on, the device is officially online, yay! */ 705 fibril_mutex_lock(&dev->base.guard); 706 dev->online = true; 707 fibril_mutex_unlock(&dev->base.guard); 708 709 xhci_cmd_fini(&cmd); 710 free32(ictx); 711 return EOK; 712 713 err_cmd: 714 xhci_cmd_fini(&cmd); 715 free32(ictx); 716 err_dev_ctx: 717 free32(dev->dev_ctx); 718 hc->dcbaa[dev->slot_id] = 0; 719 err: 720 return err; 721 } 722 723 int hc_configure_device(xhci_hc_t *hc, uint32_t slot_id) 677 724 { 678 725 int err; … … 684 731 } 685 732 686 /* Initialize slot_ctx according to section 4.3.3 point 3. */ 687 XHCI_SLOT_ROOT_HUB_PORT_SET(ictx->slot_ctx, port); 688 XHCI_SLOT_CTX_ENTRIES_SET(ictx->slot_ctx, 1); 689 690 /* Attaching to root hub port, root string equals to 0. */ 691 XHCI_SLOT_ROUTE_STRING_SET(ictx->slot_ctx, 0); 692 693 /* Copy endpoint 0 context and set A1 flag. */ 694 memcpy(&ictx->endpoint_ctx[0], ep_ctx, sizeof(xhci_ep_ctx_t)); 695 XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 1); 696 697 if ((err = hc_address_device(hc, slot_id, ictx))) { 733 // TODO: Set slot context and other flags. (probably forgot a lot of 'em) 734 735 xhci_cmd_t cmd; 736 xhci_cmd_init(&cmd); 737 738 cmd.slot_id = slot_id; 739 740 if ((err = xhci_send_configure_endpoint_command(hc, &cmd, ictx))) { 698 741 goto err_cmd; 699 742 } 743 744 if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) { 745 goto err_cmd; 746 } 747 748 xhci_cmd_fini(&cmd); 700 749 701 750 free32(ictx); … … 708 757 } 709 758 710 int hc_configure_device(xhci_hc_t *hc, uint32_t slot_id) 759 int hc_deconfigure_device(xhci_hc_t *hc, uint32_t slot_id) 760 { 761 int err; 762 763 /* Issue configure endpoint command (sec 4.3.5) with the DC flag. */ 764 xhci_cmd_t cmd; 765 xhci_cmd_init(&cmd); 766 767 cmd.slot_id = slot_id; 768 cmd.deconfigure = true; 769 770 if ((err = xhci_send_configure_endpoint_command(hc, &cmd, NULL))) { 771 return err; 772 } 773 774 if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) { 775 return err; 776 } 777 778 xhci_cmd_fini(&cmd); 779 780 return EOK; 781 } 782 783 int hc_add_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx, xhci_ep_ctx_t *ep_ctx) 711 784 { 712 785 int err; … … 718 791 } 719 792 793 XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */ 794 memcpy(&ictx->endpoint_ctx[ep_idx], ep_ctx, sizeof(xhci_ep_ctx_t)); 795 720 796 // TODO: Set slot context and other flags. (probably forgot a lot of 'em) 721 797 … … 744 820 } 745 821 746 int hc_deconfigure_device(xhci_hc_t *hc, uint32_t slot_id) 747 { 748 int err; 749 750 /* Issue configure endpoint command (sec 4.3.5) with the DC flag. */ 751 xhci_cmd_t cmd; 752 xhci_cmd_init(&cmd); 753 754 cmd.slot_id = slot_id; 755 cmd.deconfigure = true; 756 757 if ((err = xhci_send_configure_endpoint_command(hc, &cmd, NULL))) { 758 return err; 759 } 760 761 if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) { 762 return err; 763 } 764 765 xhci_cmd_fini(&cmd); 766 767 return EOK; 768 } 769 770 int hc_add_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx, xhci_ep_ctx_t *ep_ctx) 822 int hc_drop_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx) 771 823 { 772 824 int err; … … 778 830 } 779 831 780 XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */ 781 memcpy(&ictx->endpoint_ctx[ep_idx], ep_ctx, sizeof(xhci_ep_ctx_t)); 832 XHCI_INPUT_CTRL_CTX_DROP_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */ 782 833 783 834 // TODO: Set slot context and other flags. (probably forgot a lot of 'em) … … 807 858 } 808 859 809 int hc_drop_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx)810 {811 int err;812 813 /* Issue configure endpoint command (sec 4.3.5). */814 xhci_input_ctx_t *ictx;815 if ((err = create_valid_input_ctx(&ictx))) {816 goto err;817 }818 819 XHCI_INPUT_CTRL_CTX_DROP_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */820 821 // TODO: Set slot context and other flags. (probably forgot a lot of 'em)822 823 xhci_cmd_t cmd;824 xhci_cmd_init(&cmd);825 826 cmd.slot_id = slot_id;827 828 if ((err = xhci_send_configure_endpoint_command(hc, &cmd, ictx))) {829 goto err_cmd;830 }831 832 if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) {833 goto err_cmd;834 }835 836 xhci_cmd_fini(&cmd);837 838 free32(ictx);839 return EOK;840 841 err_cmd:842 free32(ictx);843 err:844 return err;845 }846 847 860 /** 848 861 * @}
Note:
See TracChangeset
for help on using the changeset viewer.