Changeset 89cefe78 in mainline
- Timestamp:
- 2017-10-22T21:47:55Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 82fe063
- Parents:
- ee794529
- Location:
- uspace/drv/bus/usb/xhci
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/endpoint.c
ree794529 r89cefe78 54 54 endpoint_init(ep, bus); 55 55 56 return xhci_trb_ring_init(&xhci_ep->ring);56 return EOK; 57 57 } 58 58 … … 61 61 assert(xhci_ep); 62 62 63 /* FIXME: Tear down TR's? */ 64 xhci_trb_ring_fini(&xhci_ep->ring); 63 // TODO: Something missed? 64 } 65 66 int xhci_endpoint_alloc_transfer_ds(xhci_endpoint_t *xhci_ep) 67 { 68 int err; 69 70 if (xhci_ep->max_streams > 0) { 71 // Set up primary stream context array if needed. 72 xhci_ep->primary_stream_ctx_array = malloc32(xhci_ep->max_streams * sizeof(xhci_stream_ctx_t)); 73 if (!xhci_ep->primary_stream_ctx_array) { 74 return ENOMEM; 75 } 76 memset(xhci_ep->primary_stream_ctx_array, 0, xhci_ep->max_streams * sizeof(xhci_stream_ctx_t)); 77 } else { 78 xhci_ep->primary_stream_ctx_array = NULL; 79 if ((err = xhci_trb_ring_init(&xhci_ep->ring))) { 80 return err; 81 } 82 } 83 84 return EOK; 85 } 86 87 int xhci_endpoint_free_transfer_ds(xhci_endpoint_t *xhci_ep) 88 { 89 int err; 90 91 if (xhci_ep->max_streams > 0) { 92 // TODO: What about secondaries? 93 free32(xhci_ep->primary_stream_ctx_array); 94 } else { 95 if ((err = xhci_trb_ring_fini(&xhci_ep->ring))) { 96 return err; 97 } 98 } 99 100 return EOK; 65 101 } 66 102 … … 113 149 } 114 150 115 static void setup_control_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx, 116 xhci_trb_ring_t *ring) 151 static void setup_control_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx) 117 152 { 118 153 // EP0 is configured elsewhere. … … 122 157 XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size); 123 158 XHCI_EP_ERROR_COUNT_SET(*ctx, 3); 124 XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue);159 XHCI_EP_TR_DPTR_SET(*ctx, ep->ring.dequeue); 125 160 XHCI_EP_DCS_SET(*ctx, 1); 126 161 } 127 162 128 static void setup_bulk_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx, 129 xhci_trb_ring_t *ring, usb_superspeed_endpoint_companion_descriptor_t *ss_desc) 163 static void setup_bulk_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx) 130 164 { 131 165 XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(ep)); 132 166 XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size); 133 167 XHCI_EP_MAX_BURST_SIZE_SET(*ctx, 134 xhci_device_get(ep->base.device)->usb3 ? ss_desc->max_burst : 0);168 xhci_device_get(ep->base.device)->usb3 ? ep->max_burst : 0); 135 169 XHCI_EP_ERROR_COUNT_SET(*ctx, 3); 136 170 137 // FIXME: Get maxStreams and other things from ss_desc 138 const uint8_t maxStreams = 0; 139 if (maxStreams > 0) { 140 // TODO: allocate and clear primary stream array 141 // TODO: XHCI_EP_MAX_P_STREAMS_SET(ctx, psa_size); 142 // TODO: XHCI_EP_TR_DPTR_SET(ctx, psa_start_phys_addr); 171 if (ep->max_streams > 0) { 172 XHCI_EP_MAX_P_STREAMS_SET(*ctx, ep->max_streams); 173 XHCI_EP_TR_DPTR_SET(*ctx, addr_to_phys(ep->primary_stream_ctx_array)); 143 174 // TODO: set HID 144 175 // TODO: set LSA 145 176 } else { 146 177 XHCI_EP_MAX_P_STREAMS_SET(*ctx, 0); 147 XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue);178 XHCI_EP_TR_DPTR_SET(*ctx, ep->ring.dequeue); 148 179 XHCI_EP_DCS_SET(*ctx, 1); 149 180 } 150 181 } 151 182 152 static void setup_isoch_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx, 153 xhci_trb_ring_t *ring, usb_superspeed_endpoint_companion_descriptor_t *ss_desc) 183 static void setup_isoch_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx) 154 184 { 155 185 XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(ep)); 156 186 XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size & 0x07FF); 157 XHCI_EP_MAX_BURST_SIZE_SET(*ctx, ss_desc->max_burst); 158 // FIXME: get Mult field from SS companion descriptor somehow 159 XHCI_EP_MULT_SET(*ctx, 0); 187 XHCI_EP_MAX_BURST_SIZE_SET(*ctx, ep->max_burst); 188 XHCI_EP_MULT_SET(*ctx, ep->mult); 160 189 XHCI_EP_ERROR_COUNT_SET(*ctx, 0); 161 XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue);190 XHCI_EP_TR_DPTR_SET(*ctx, ep->ring.dequeue); 162 191 XHCI_EP_DCS_SET(*ctx, 1); 163 192 // TODO: max ESIT payload 164 193 } 165 194 166 static void setup_interrupt_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx, 167 xhci_trb_ring_t *ring, usb_superspeed_endpoint_companion_descriptor_t *ss_desc) 195 static void setup_interrupt_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx) 168 196 { 169 197 XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(ep)); 170 198 XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size & 0x07FF); 171 XHCI_EP_MAX_BURST_SIZE_SET(*ctx, ss_desc->max_burst);199 XHCI_EP_MAX_BURST_SIZE_SET(*ctx, ep->max_burst); 172 200 XHCI_EP_MULT_SET(*ctx, 0); 173 201 XHCI_EP_ERROR_COUNT_SET(*ctx, 3); 174 XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue);202 XHCI_EP_TR_DPTR_SET(*ctx, ep->ring.dequeue); 175 203 XHCI_EP_DCS_SET(*ctx, 1); 176 204 // TODO: max ESIT payload 177 205 } 206 207 typedef void (*setup_ep_ctx_helper)(xhci_endpoint_t *, xhci_ep_ctx_t *); 208 209 static const setup_ep_ctx_helper setup_ep_ctx_helpers[] = { 210 [USB_TRANSFER_CONTROL] = setup_control_ep_ctx, 211 [USB_TRANSFER_ISOCHRONOUS] = setup_isoch_ep_ctx, 212 [USB_TRANSFER_BULK] = setup_bulk_ep_ctx, 213 [USB_TRANSFER_INTERRUPT] = setup_interrupt_ep_ctx, 214 }; 178 215 179 216 int xhci_device_add_endpoint(xhci_device_t *dev, xhci_endpoint_t *ep) … … 202 239 return EOK; 203 240 204 // FIXME: Retrieve this from somewhere, if applicable. 205 usb_superspeed_endpoint_companion_descriptor_t ss_desc; 206 memset(&ss_desc, 0, sizeof(ss_desc)); 241 // FIXME: Set these from usb_superspeed_endpoint_companion_descriptor_t: 242 ep->max_streams = 0; 243 ep->max_burst = 0; 244 ep->mult = 0; 245 246 xhci_endpoint_alloc_transfer_ds(ep); 207 247 208 248 // Prepare input context. … … 222 262 XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */ 223 263 224 xhci_trb_ring_t *ep_ring = &ep->ring;225 264 xhci_ep_ctx_t *ep_ctx = &ictx->endpoint_ctx[ep_idx]; 226 227 // TODO: Convert to table 228 switch (ep->base.transfer_type) { 229 case USB_TRANSFER_CONTROL: 230 setup_control_ep_ctx(ep, ep_ctx, ep_ring); 231 break; 232 233 case USB_TRANSFER_BULK: 234 setup_bulk_ep_ctx(ep, ep_ctx, ep_ring, &ss_desc); 235 break; 236 237 case USB_TRANSFER_ISOCHRONOUS: 238 setup_isoch_ep_ctx(ep, ep_ctx, ep_ring, &ss_desc); 239 break; 240 241 case USB_TRANSFER_INTERRUPT: 242 setup_interrupt_ep_ctx(ep, ep_ctx, ep_ring, &ss_desc); 243 break; 244 } 265 setup_ep_ctx_helpers[ep->base.transfer_type](ep, ep_ctx); 245 266 246 267 // Issue configure endpoint command (sec 4.3.5). … … 274 295 // TODO: Issue configure endpoint command to drop this endpoint. 275 296 297 // FIXME: Ignoring return code. 298 xhci_endpoint_free_transfer_ds(ep); 299 276 300 dev->endpoints[ep->base.target.endpoint] = NULL; 277 301 --dev->active_endpoint_count; -
uspace/drv/bus/usb/xhci/endpoint.h
ree794529 r89cefe78 65 65 endpoint_t base; /**< Inheritance. Keep this first. */ 66 66 67 /** Main TRB ring */67 /** Main TRB ring (or NULL if endpoint uses streams) */ 68 68 xhci_trb_ring_t ring; 69 69 … … 72 72 * endpoint_t */ 73 73 xhci_transfer_t active_transfer; 74 75 /** Primary stream context array (or NULL if endpoint doesn't use streams) */ 76 xhci_stream_ctx_t *primary_stream_ctx_array; 77 78 /** Maximum number of streams, also a valid range of PSCA above */ 79 uint16_t max_streams; 80 81 /* FIXME: Figure out type for these two fields. */ 82 uint8_t max_burst; 83 uint8_t mult; 74 84 } xhci_endpoint_t; 75 85 … … 101 111 int xhci_endpoint_init(xhci_endpoint_t *, xhci_bus_t *); 102 112 void xhci_endpoint_fini(xhci_endpoint_t *); 113 int xhci_endpoint_alloc_transfer_ds(xhci_endpoint_t *); 114 int xhci_endpoint_free_transfer_ds(xhci_endpoint_t *); 103 115 104 116 uint8_t xhci_endpoint_dci(xhci_endpoint_t *); -
uspace/drv/bus/usb/xhci/rh.c
ree794529 r89cefe78 129 129 goto err_ictx; 130 130 xhci_endpoint_t *ep0 = xhci_endpoint_get(ep0_base); 131 132 /* Control endpoints don't use streams. */ 133 /* FIXME: Sync this with xhci_device_add_endpoint. */ 134 ep0->max_streams = 0; 135 ep0->max_burst = 0; 136 ep0->mult = 0; 137 if ((err = xhci_endpoint_alloc_transfer_ds(ep0))) 138 goto err_ictx; 139 131 140 setup_control_ep0_ctx(&ictx->endpoint_ctx[0], &ep0->ring, speed); 132 141
Note:
See TracChangeset
for help on using the changeset viewer.