Changeset a4e7e6e1 in mainline
- Timestamp:
- 2018-01-19T15:25:20Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 861b5d6
- Parents:
- c7d5189
- Location:
- uspace/drv/bus/usb/xhci
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/bus.c
rc7d5189 ra4e7e6e1 87 87 88 88 /* Address device */ 89 if ((err = hc_address_device( bus->hc,dev, ep0)))89 if ((err = hc_address_device(dev, ep0))) 90 90 goto err_added; 91 91 … … 128 128 xhci_setup_endpoint_context(ep0, &ep_ctx); 129 129 130 if ((err = hc_update_endpoint( hc, dev->slot_id, 0, &ep_ctx)))130 if ((err = hc_update_endpoint(dev, 0, &ep_ctx))) 131 131 return err; 132 132 … … 238 238 239 239 /* Transition the device from the Addressed to the Configured state. */ 240 if ((err = hc_configure_device( bus->hc, dev->slot_id))) {240 if ((err = hc_configure_device(dev))) { 241 241 usb_log_warning("Failed to configure device " XHCI_DEV_FMT ".", XHCI_DEV_ARGS(*dev)); 242 242 return err; … … 263 263 264 264 /* Issue one HC command to simultaneously drop all endpoints except zero. */ 265 if ((err = hc_deconfigure_device( bus->hc, dev->slot_id))) {265 if ((err = hc_deconfigure_device(dev))) { 266 266 usb_log_warning("Failed to deconfigure device " XHCI_DEV_FMT ".", 267 267 XHCI_DEV_ARGS(*dev)); … … 312 312 { 313 313 int err; 314 xhci_bus_t *bus = bus_to_xhci_bus(endpoint_get_bus(ep_base));315 314 xhci_endpoint_t *ep = xhci_endpoint_get(ep_base); 316 315 xhci_device_t *dev = xhci_device_get(ep_base->device); … … 319 318 xhci_setup_endpoint_context(ep, &ep_ctx); 320 319 321 if ((err = hc_add_endpoint( bus->hc, dev->slot_id, xhci_endpoint_index(ep), &ep_ctx)))320 if ((err = hc_add_endpoint(dev, xhci_endpoint_index(ep), &ep_ctx))) 322 321 return err; 323 322 … … 330 329 static int endpoint_abort(endpoint_t *ep) 331 330 { 332 xhci_bus_t *bus = bus_to_xhci_bus(endpoint_get_bus(ep));333 331 xhci_device_t *dev = xhci_device_get(ep->device); 334 332 … … 337 335 if (ep->active_batch) { 338 336 if (dev->slot_id) { 339 const int err = hc_stop_endpoint( bus->hc, dev->slot_id, xhci_endpoint_dci(xhci_endpoint_get(ep)));337 const int err = hc_stop_endpoint(dev, xhci_endpoint_dci(xhci_endpoint_get(ep))); 340 338 if (err) { 341 339 usb_log_warning("Failed to stop endpoint %u of device " XHCI_DEV_FMT ": %s", … … 370 368 { 371 369 int err; 372 xhci_bus_t *bus = bus_to_xhci_bus(endpoint_get_bus(ep_base));373 370 xhci_endpoint_t *ep = xhci_endpoint_get(ep_base); 374 371 xhci_device_t *dev = xhci_device_get(ep_base->device); … … 379 376 if (dev->slot_id) { 380 377 381 if ((err = hc_drop_endpoint( bus->hc, dev->slot_id, xhci_endpoint_index(ep)))) {378 if ((err = hc_drop_endpoint(dev, xhci_endpoint_index(ep)))) { 382 379 usb_log_error("Failed to drop endpoint " XHCI_EP_FMT ": %s", XHCI_EP_ARGS(*ep), str_error(err)); 383 380 } -
uspace/drv/bus/usb/xhci/endpoint.c
rc7d5189 ra4e7e6e1 346 346 const unsigned dci = xhci_endpoint_dci(ep); 347 347 348 if ((err = hc_reset_endpoint( hc, slot_id, dci)))348 if ((err = hc_reset_endpoint(dev, dci))) 349 349 return err; 350 350 -
uspace/drv/bus/usb/xhci/hc.c
rc7d5189 ra4e7e6e1 764 764 765 765 /** 766 * Fill a slot context that is part of an Input Context with appropriate 767 * values. 768 * 769 * @param ctx Slot context, zeroed out. 770 */ 771 static void xhci_setup_slot_context(xhci_device_t *dev, xhci_slot_ctx_t *ctx) 772 { 773 /* Initialize slot_ctx according to section 4.3.3 point 3. */ 774 XHCI_SLOT_ROOT_HUB_PORT_SET(*ctx, dev->rh_port); 775 XHCI_SLOT_CTX_ENTRIES_SET(*ctx, 1); 776 XHCI_SLOT_ROUTE_STRING_SET(*ctx, dev->route_str); 777 XHCI_SLOT_SPEED_SET(*ctx, usb_speed_to_psiv[dev->base.speed]); 778 779 /* Setup Transaction Translation. TODO: Test this with HS hub. */ 780 if (dev->base.tt.dev != NULL) { 781 xhci_device_t *hub = xhci_device_get(dev->base.tt.dev); 782 XHCI_SLOT_TT_HUB_SLOT_ID_SET(*ctx, hub->slot_id); 783 XHCI_SLOT_TT_HUB_PORT_SET(*ctx, dev->base.tt.port); 784 } 785 786 // As we always allocate space for whole input context, we can set this to maximum 787 XHCI_SLOT_CTX_ENTRIES_SET(*ctx, 31); 788 } 789 790 /** 766 791 * Prepare an empty Endpoint Input Context inside a dma buffer. 767 792 */ 768 static int create_configure_ep_input_ctx( dma_buffer_t *dma_buf)793 static int create_configure_ep_input_ctx(xhci_device_t *dev, dma_buffer_t *dma_buf) 769 794 { 770 795 const int err = dma_buffer_alloc(dma_buf, sizeof(xhci_input_ctx_t)); … … 777 802 // Quoting sec. 4.6.5 and 4.6.6: A1, D0, D1 are down (already zeroed), A0 is up. 778 803 XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 0); 779 780 // As we always allocate space for whole input context, we can set this to maximum 781 XHCI_SLOT_CTX_ENTRIES_SET(ictx->slot_ctx, 31); 804 xhci_setup_slot_context(dev, &ictx->slot_ctx); 782 805 783 806 return EOK; … … 790 813 * @param ep0 EP0 of device TODO remove, can be fetched from dev 791 814 */ 792 int hc_address_device(xhci_ hc_t *hc, xhci_device_t *dev, xhci_endpoint_t *ep0)815 int hc_address_device(xhci_device_t *dev, xhci_endpoint_t *ep0) 793 816 { 794 817 int err = ENOMEM; 818 xhci_hc_t * const hc = bus_to_hc(dev->base.bus); 795 819 796 820 /* Although we have the precise PSIV value on devices of tier 1, … … 810 834 /* Issue configure endpoint command (sec 4.3.5). */ 811 835 dma_buffer_t ictx_dma_buf; 812 if ((err = create_configure_ep_input_ctx( &ictx_dma_buf))) {836 if ((err = create_configure_ep_input_ctx(dev, &ictx_dma_buf))) { 813 837 goto err_dev_ctx; 814 838 } 815 839 xhci_input_ctx_t *ictx = ictx_dma_buf.virt; 816 817 /* Initialize slot_ctx according to section 4.3.3 point 3. */818 XHCI_SLOT_ROOT_HUB_PORT_SET(ictx->slot_ctx, dev->rh_port);819 XHCI_SLOT_CTX_ENTRIES_SET(ictx->slot_ctx, 1);820 XHCI_SLOT_ROUTE_STRING_SET(ictx->slot_ctx, dev->route_str);821 XHCI_SLOT_SPEED_SET(ictx->slot_ctx, usb_speed_to_psiv[dev->base.speed]);822 823 /* Setup Transaction Translation. TODO: Test this with HS hub. */824 if (dev->base.tt.dev != NULL) {825 xhci_device_t *hub = xhci_device_get(dev->base.tt.dev);826 XHCI_SLOT_TT_HUB_SLOT_ID_SET(ictx->slot_ctx, hub->slot_id);827 XHCI_SLOT_TT_HUB_PORT_SET(ictx->slot_ctx, dev->base.tt.port);828 XHCI_SLOT_MTT_SET(ictx->slot_ctx, 0); // MTT not supported yet829 }830 840 831 841 /* Copy endpoint 0 context and set A1 flag. */ … … 856 866 * @param slot_id Slot ID assigned to the device. 857 867 */ 858 int hc_configure_device(xhci_hc_t *hc, uint32_t slot_id) 859 { 868 int hc_configure_device(xhci_device_t *dev) 869 { 870 xhci_hc_t * const hc = bus_to_hc(dev->base.bus); 871 860 872 /* Issue configure endpoint command (sec 4.3.5). */ 861 873 dma_buffer_t ictx_dma_buf; 862 const int err = create_configure_ep_input_ctx( &ictx_dma_buf);874 const int err = create_configure_ep_input_ctx(dev, &ictx_dma_buf); 863 875 if (err) 864 876 return err; 865 877 866 // TODO: Set slot context and other flags. (probably forgot a lot of 'em) 867 868 return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = slot_id, .input_ctx = ictx_dma_buf); 878 return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf); 869 879 } 870 880 … … 872 882 * Issue a Deconfigure Device command for a device in slot. 873 883 * 874 * @param slot_id Slot ID assigned to the device. 875 */ 876 int hc_deconfigure_device(xhci_hc_t *hc, uint32_t slot_id) 877 { 884 * @param dev The owner of the device 885 */ 886 int hc_deconfigure_device(xhci_device_t *dev) 887 { 888 xhci_hc_t * const hc = bus_to_hc(dev->base.bus); 889 878 890 /* Issue configure endpoint command (sec 4.3.5) with the DC flag. */ 879 return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = slot_id, .deconfigure = true);891 return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .deconfigure = true); 880 892 } 881 893 … … 883 895 * Instruct xHC to add an endpoint with supplied endpoint context. 884 896 * 885 * @param slot_id Slot ID assigned to the device.886 * @param ep_idx Endpoint index (number + direction)in question897 * @param dev The owner of the device 898 * @param ep_idx Endpoint DCI in question 887 899 * @param ep_ctx Endpoint context of the endpoint 888 900 */ 889 int hc_add_endpoint(xhci_ hc_t *hc, uint32_t slot_id, uint8_t ep_idx, xhci_ep_ctx_t *ep_ctx)901 int hc_add_endpoint(xhci_device_t *dev, uint8_t ep_idx, xhci_ep_ctx_t *ep_ctx) 890 902 { 891 903 /* Issue configure endpoint command (sec 4.3.5). */ 892 904 dma_buffer_t ictx_dma_buf; 893 const int err = create_configure_ep_input_ctx( &ictx_dma_buf);905 const int err = create_configure_ep_input_ctx(dev, &ictx_dma_buf); 894 906 if (err) 895 907 return err; … … 899 911 memcpy(&ictx->endpoint_ctx[ep_idx], ep_ctx, sizeof(xhci_ep_ctx_t)); 900 912 901 // TODO: Set slot context and other flags. (probably forgot a lot of 'em) 902 903 return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = slot_id, .input_ctx = ictx_dma_buf); 913 xhci_hc_t * const hc = bus_to_hc(dev->base.bus); 914 return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf); 904 915 } 905 916 … … 907 918 * Instruct xHC to drop an endpoint. 908 919 * 909 * @param slot_id Slot ID assigned to the device.910 * @param ep_idx Endpoint index (number + direction)in question911 */ 912 int hc_drop_endpoint(xhci_ hc_t *hc, uint32_t slot_id, uint8_t ep_idx)920 * @param dev The owner of the endpoint 921 * @param ep_idx Endpoint DCI in question 922 */ 923 int hc_drop_endpoint(xhci_device_t *dev, uint8_t ep_idx) 913 924 { 914 925 /* Issue configure endpoint command (sec 4.3.5). */ 915 926 dma_buffer_t ictx_dma_buf; 916 const int err = create_configure_ep_input_ctx( &ictx_dma_buf);927 const int err = create_configure_ep_input_ctx(dev, &ictx_dma_buf); 917 928 if (err) 918 929 return err; … … 920 931 xhci_input_ctx_t *ictx = ictx_dma_buf.virt; 921 932 XHCI_INPUT_CTRL_CTX_DROP_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */ 922 // TODO: Set slot context and other flags. (probably forgot a lot of 'em) 923 924 return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = slot_id, .input_ctx = ictx_dma_buf);933 934 xhci_hc_t * const hc = bus_to_hc(dev->base.bus); 935 return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf); 925 936 } 926 937 … … 929 940 * endpoint context. 930 941 * 931 * @param slot_id Slot ID assigned to the device.932 * @param ep_idx Endpoint index (number + direction)in question942 * @param dev The owner of the endpoint 943 * @param ep_idx Endpoint DCI in question 933 944 * @param ep_ctx Endpoint context of the endpoint 934 945 */ 935 int hc_update_endpoint(xhci_ hc_t *hc, uint32_t slot_id, uint8_t ep_idx, xhci_ep_ctx_t *ep_ctx)946 int hc_update_endpoint(xhci_device_t *dev, uint8_t ep_idx, xhci_ep_ctx_t *ep_ctx) 936 947 { 937 948 dma_buffer_t ictx_dma_buf; … … 946 957 memcpy(&ictx->endpoint_ctx[ep_idx], ep_ctx, sizeof(xhci_ep_ctx_t)); 947 958 948 return xhci_cmd_sync_inline(hc, EVALUATE_CONTEXT, .slot_id = slot_id, .input_ctx = ictx_dma_buf); 959 xhci_hc_t * const hc = bus_to_hc(dev->base.bus); 960 return xhci_cmd_sync_inline(hc, EVALUATE_CONTEXT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf); 949 961 } 950 962 … … 952 964 * Instruct xHC to stop running a transfer ring on an endpoint. 953 965 * 954 * @param slot_id Slot ID assigned to the device. 955 * @param ep_idx Endpoint index (number + direction) in question 956 */ 957 int hc_stop_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx) 958 { 959 return xhci_cmd_sync_inline(hc, STOP_ENDPOINT, .slot_id = slot_id, .endpoint_id = ep_idx); 966 * @param dev The owner of the endpoint 967 * @param ep_idx Endpoint DCI in question 968 */ 969 int hc_stop_endpoint(xhci_device_t *dev, uint8_t ep_idx) 970 { 971 xhci_hc_t * const hc = bus_to_hc(dev->base.bus); 972 return xhci_cmd_sync_inline(hc, STOP_ENDPOINT, .slot_id = dev->slot_id, .endpoint_id = ep_idx); 960 973 } 961 974 … … 963 976 * Instruct xHC to reset halted endpoint. 964 977 * 965 * @param slot_id Slot ID assigned to the device. 966 * @param ep_idx Endpoint index (number + direction) in question 967 */ 968 int hc_reset_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx) 969 { 970 return xhci_cmd_sync_inline(hc, RESET_ENDPOINT, .slot_id = slot_id, .endpoint_id = ep_idx); 978 * @param dev The owner of the endpoint 979 * @param ep_idx Endpoint DCI in question 980 */ 981 int hc_reset_endpoint(xhci_device_t *dev, uint8_t ep_idx) 982 { 983 xhci_hc_t * const hc = bus_to_hc(dev->base.bus); 984 return xhci_cmd_sync_inline(hc, RESET_ENDPOINT, .slot_id = dev->slot_id, .endpoint_id = ep_idx); 971 985 } 972 986 -
uspace/drv/bus/usb/xhci/hc.h
rc7d5189 ra4e7e6e1 120 120 void hc_fini(xhci_hc_t *); 121 121 void hc_ring_doorbell(xhci_hc_t *, unsigned, unsigned); 122 122 123 int hc_enable_slot(xhci_hc_t *, uint32_t *); 123 124 int hc_disable_slot(xhci_hc_t *, xhci_device_t *); 124 int hc_address_device(xhci_ hc_t *, xhci_device_t *, xhci_endpoint_t *);125 int hc_configure_device(xhci_ hc_t *, uint32_t);126 int hc_deconfigure_device(xhci_ hc_t *, uint32_t);127 int hc_add_endpoint(xhci_ hc_t *, uint32_t, uint8_t, xhci_ep_ctx_t *);128 int hc_drop_endpoint(xhci_ hc_t *, uint32_t, uint8_t);129 int hc_update_endpoint(xhci_ hc_t *, uint32_t, uint8_t, xhci_ep_ctx_t *);130 int hc_stop_endpoint(xhci_ hc_t *, uint32_t, uint8_t);131 int hc_reset_endpoint(xhci_ hc_t *, uint32_t, uint8_t);125 int hc_address_device(xhci_device_t *, xhci_endpoint_t *); 126 int hc_configure_device(xhci_device_t *); 127 int hc_deconfigure_device(xhci_device_t *); 128 int hc_add_endpoint(xhci_device_t *, uint8_t, xhci_ep_ctx_t *); 129 int hc_drop_endpoint(xhci_device_t *, uint8_t); 130 int hc_update_endpoint(xhci_device_t *, uint8_t, xhci_ep_ctx_t *); 131 int hc_stop_endpoint(xhci_device_t *, uint8_t); 132 int hc_reset_endpoint(xhci_device_t *, uint8_t); 132 133 133 134 int hc_status(bus_t *, uint32_t *); -
uspace/drv/bus/usb/xhci/streams.c
rc7d5189 ra4e7e6e1 327 327 } 328 328 329 hc_stop_endpoint( hc, dev->slot_id, xhci_endpoint_index(xhci_ep));329 hc_stop_endpoint(dev, xhci_endpoint_index(xhci_ep)); 330 330 xhci_endpoint_free_transfer_ds(xhci_ep); 331 331 … … 340 340 memset(&ep_ctx, 0, sizeof(ep_ctx)); 341 341 xhci_setup_endpoint_context(xhci_ep, &ep_ctx); 342 return hc_update_endpoint( hc, dev->slot_id, xhci_endpoint_index(xhci_ep), &ep_ctx);342 return hc_update_endpoint(dev, xhci_endpoint_index(xhci_ep), &ep_ctx); 343 343 } 344 344 … … 361 361 * Stop the endpoint, destroy the ring, and transition to streams. 362 362 */ 363 hc_stop_endpoint( hc, dev->slot_id, xhci_endpoint_index(xhci_ep));363 hc_stop_endpoint(dev, xhci_endpoint_index(xhci_ep)); 364 364 xhci_endpoint_free_transfer_ds(xhci_ep); 365 365 … … 381 381 setup_stream_context(xhci_ep, &ep_ctx, pstreams, 1); 382 382 383 return hc_update_endpoint( hc, dev->slot_id, xhci_endpoint_index(xhci_ep), &ep_ctx);383 return hc_update_endpoint(dev, xhci_endpoint_index(xhci_ep), &ep_ctx); 384 384 } 385 385 … … 434 434 * Stop the endpoint, destroy the ring, and transition to streams. 435 435 */ 436 hc_stop_endpoint( hc, dev->slot_id, xhci_endpoint_index(xhci_ep));436 hc_stop_endpoint(dev, xhci_endpoint_index(xhci_ep)); 437 437 xhci_endpoint_free_transfer_ds(xhci_ep); 438 438 … … 455 455 setup_stream_context(xhci_ep, &ep_ctx, pstreams, 0); 456 456 457 return hc_update_endpoint( hc, dev->slot_id, xhci_endpoint_index(xhci_ep), &ep_ctx);457 return hc_update_endpoint(dev, xhci_endpoint_index(xhci_ep), &ep_ctx); 458 458 459 459 err_init: -
uspace/drv/bus/usb/xhci/transfers.c
rc7d5189 ra4e7e6e1 197 197 // Issue a Configure Endpoint command, if needed. 198 198 if (configure_endpoint_needed(setup)) { 199 const int err = hc_configure_device( hc, xhci_ep_to_dev(xhci_ep)->slot_id);199 const int err = hc_configure_device(xhci_ep_to_dev(xhci_ep)); 200 200 if (err) 201 201 return err;
Note:
See TracChangeset
for help on using the changeset viewer.