Changeset 8033f89 in mainline for uspace/drv/bus/usb/xhci/streams.c
- Timestamp:
- 2018-01-23T12:41:22Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e7e1fd3
- Parents:
- e546142
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/streams.c
re546142 r8033f89 39 39 #include "streams.h" 40 40 41 /** Finds stream data with given stream ID if it exists. 41 /** 42 * Finds stream data with given stream ID if it exists. 42 43 * Note that streams with ID 0, 65534 and 65535 are reserved. 43 44 * Splits the ID into primary and secondary context ID and searches the structures. … … 52 53 53 54 /* See 4.12.2.1 for the calculation of the IDs and dividing the stream_id */ 54 uint32_t primary_stream_id = (uint32_t) (stream_id & (ep->primary_stream_data_size - 1)); 55 uint32_t secondary_stream_id = (uint32_t) ((stream_id / ep->primary_stream_data_size) & 0xFF); 55 uint32_t primary_stream_id = 56 (uint32_t) (stream_id & (ep->primary_stream_data_size - 1)); 57 uint32_t secondary_stream_id = 58 (uint32_t) ((stream_id / ep->primary_stream_data_size) & 0xFF); 56 59 57 60 if (primary_stream_id >= ep->primary_stream_data_size) { … … 59 62 } 60 63 61 xhci_stream_data_t *primary_data = &ep->primary_stream_data_array[primary_stream_id]; 64 xhci_stream_data_t *primary_data = 65 &ep->primary_stream_data_array[primary_stream_id]; 62 66 if (secondary_stream_id != 0 && !primary_data->secondary_size) { 63 67 return NULL; … … 76 80 } 77 81 78 /** Initializes primary stream data structures in endpoint. 82 /** 83 * Initializes primary stream data structures in endpoint. 79 84 * @param[in] xhci_ep Used XHCI bulk endpoint. 80 85 * @param[in] count Amount of primary streams. … … 82 87 static int initialize_primary_structures(xhci_endpoint_t *xhci_ep, unsigned count) 83 88 { 84 usb_log_debug("Allocating primary stream context array of size %u for endpoint " XHCI_EP_FMT, 85 count, XHCI_EP_ARGS(*xhci_ep)); 86 87 if ((dma_buffer_alloc(&xhci_ep->primary_stream_ctx_dma, count * sizeof(xhci_stream_ctx_t)))) { 89 usb_log_debug("Allocating primary stream context array of size %u " 90 "for endpoint " XHCI_EP_FMT, count, XHCI_EP_ARGS(*xhci_ep)); 91 92 if ((dma_buffer_alloc(&xhci_ep->primary_stream_ctx_dma, 93 count * sizeof(xhci_stream_ctx_t)))) { 88 94 return ENOMEM; 89 95 } … … 101 107 } 102 108 103 /**104 *105 */106 109 static void clear_primary_structures(xhci_endpoint_t *xhci_ep) 107 110 { 108 usb_log_debug("Deallocating primary stream structures for endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep)); 111 usb_log_debug("Deallocating primary stream structures for " 112 "endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep)); 109 113 110 114 dma_buffer_free(&xhci_ep->primary_stream_ctx_dma); … … 133 137 void xhci_stream_free_ds(xhci_endpoint_t *xhci_ep) 134 138 { 135 usb_log_debug("Freeing stream rings and context arrays of endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep)); 139 usb_log_debug("Freeing stream rings and context arrays of endpoint " 140 XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep)); 136 141 137 142 for (size_t index = 0; index < xhci_ep->primary_stream_data_size; ++index) { … … 141 146 } 142 147 143 /** Initialize a single primary stream structure with given index. 148 /** 149 * Initialize a single primary stream structure with given index. 144 150 * @param[in] hc Host controller of the endpoint. 145 151 * @param[in] xhci_ep XHCI bulk endpoint to use. 146 152 * @param[in] index index of the initialized stream structure. 147 153 */ 148 static int initialize_primary_stream(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep, unsigned index) { 154 static int initialize_primary_stream(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep, 155 unsigned index) 156 { 149 157 xhci_stream_ctx_t *ctx = &xhci_ep->primary_stream_ctx_array[index]; 150 158 xhci_stream_data_t *data = &xhci_ep->primary_stream_data_array[index]; … … 165 173 } 166 174 167 /** Initialize primary streams of XHCI bulk endpoint. 175 /** 176 * Initialize primary streams of XHCI bulk endpoint. 168 177 * @param[in] hc Host controller of the endpoint. 169 178 * @param[in] xhci_ep XHCI bulk endpoint to use. … … 189 198 } 190 199 191 /** Initialize secondary streams of XHCI bulk endpoint. 200 /** 201 * Initialize secondary streams of XHCI bulk endpoint. 192 202 * @param[in] hc Host controller of the endpoint. 193 203 * @param[in] xhci_epi XHCI bulk endpoint to use. … … 195 205 * @param[in] count Number of secondary streams to initialize. 196 206 */ 197 static int initialize_secondary_streams(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep, unsigned idx, unsigned count) 207 static int initialize_secondary_streams(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep, 208 unsigned idx, unsigned count) 198 209 { 199 210 if (count == 0) { 200 /* The primary stream context can still point to a single ring, not a secondary. */ 211 /* 212 * The primary stream context can still point to a single ring, not 213 * a secondary. 214 */ 201 215 return initialize_primary_stream(hc, xhci_ep, idx); 202 216 } 203 217 204 218 if ((count & (count - 1)) != 0 || count < 8 || count > 256) { 205 usb_log_error("The secondary stream array size must be a power of 2 between 8 and 256."); 219 usb_log_error("The secondary stream array size must be a power of 2 " 220 "between 8 and 256."); 206 221 return EINVAL; 207 222 } … … 217 232 } 218 233 219 if ((dma_buffer_alloc(&data->secondary_stream_ctx_dma, count * sizeof(xhci_stream_ctx_t)))) { 234 if ((dma_buffer_alloc(&data->secondary_stream_ctx_dma, 235 count * sizeof(xhci_stream_ctx_t)))) { 220 236 free(data->secondary_data); 221 237 return ENOMEM; … … 251 267 } 252 268 253 /** Configure XHCI bulk endpoint's stream context. 269 /** 270 * Configure XHCI bulk endpoint's stream context. 254 271 * @param[in] xhci_ep Associated XHCI bulk endpoint. 255 272 * @param[in] ctx Endpoint context to configure. … … 257 274 * @param[in] lsa Specifies if the stream IDs point to primary stream array. 258 275 */ 259 static void setup_stream_context(xhci_endpoint_t *xhci_ep, xhci_ep_ctx_t *ctx, unsigned pstreams, unsigned lsa) 276 static void setup_stream_context(xhci_endpoint_t *xhci_ep, xhci_ep_ctx_t *ctx, 277 unsigned pstreams, unsigned lsa) 260 278 { 261 279 XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(xhci_ep)); … … 269 287 } 270 288 271 /** Verifies if all the common preconditions are satisfied. 289 /** 290 * Verifies if all the common preconditions are satisfied. 272 291 * @param[in] hc Host controller of the endpoint. 273 292 * @param[in] dev Used device. … … 285 304 286 305 if (xhci_ep->max_streams <= 1) { 287 usb_log_error("Streams are not supported by endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep)); 306 usb_log_error("Streams are not supported by endpoint " 307 XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep)); 288 308 return EINVAL; 289 309 } … … 294 314 } 295 315 296 /* The maximum amount of primary streams is 2 ^ (MaxPSA + 1) (See table 26 of XHCI specification) */ 316 /* 317 * The maximum amount of primary streams is 2 ^ (MaxPSA + 1) 318 * See table 26 of XHCI specification. 319 */ 297 320 uint8_t max_psa_size = 1 << (XHCI_REG_RD(hc->cap_regs, XHCI_CAP_MAX_PSA_SIZE) + 1); 298 321 if (count > max_psa_size) { 299 usb_log_error("Host controller only supports %u primary streams.", max_psa_size); 322 usb_log_error("Host controller only supports " 323 "%u primary streams.", max_psa_size); 300 324 return EINVAL; 301 325 } … … 315 339 } 316 340 317 /** Cancels streams and reconfigures endpoint back to single ring no stream endpoint. 341 /** 342 * Cancels streams and reconfigures endpoint back to single ring no stream endpoint. 318 343 * @param[in] hc Host controller of the endpoint. 319 344 * @param[in] dev Used device. 320 345 * @param[in] xhci_ep Associated XHCI bulk endpoint. 321 346 */ 322 int xhci_endpoint_remove_streams(xhci_hc_t *hc, xhci_device_t *dev, xhci_endpoint_t *xhci_ep) 347 int xhci_endpoint_remove_streams(xhci_hc_t *hc, xhci_device_t *dev, 348 xhci_endpoint_t *xhci_ep) 323 349 { 324 350 if (!xhci_ep->primary_stream_data_size) { … … 340 366 } 341 367 342 /** Initialize, setup and register primary streams. 368 /** 369 * Initialize, setup and register primary streams. 343 370 * @param[in] hc Host controller of the endpoint. 344 371 * @param[in] dev Used device. … … 374 401 375 402 xhci_ep_ctx_t ep_ctx; 376 /* Allowed values are 1-15, where 2 ^ pstreams is the actual amount of streams. */ 403 /* 404 * Allowed values are 1-15, where 2 ^ pstreams is the actual amount of 405 * streams. 406 */ 377 407 const size_t pstreams = fnzb32(count) - 1; 378 408 setup_stream_context(xhci_ep, &ep_ctx, pstreams, 1); … … 381 411 } 382 412 383 /** Initialize, setup and register secondary streams. 413 /** 414 * Initialize, setup and register secondary streams. 384 415 * @param[in] hc Host controller of the endpoint. 385 416 * @param[in] dev Used device. 386 417 * @param[in] xhci_ep Associated XHCI bulk endpoint. 387 * @param[in] sizes Amount of secondary streams in each primary stream.388 This array should have exactly count elements.389 If the sizeis 0, then a primary ring is created with that index.418 * @param[in] sizes Amount of secondary streams in each of the primary streams. 419 * This array should have exactly count elements. If the size 420 * is 0, then a primary ring is created with that index. 390 421 * @param[in] count Amount of primary streams requested. 391 422 */
Note:
See TracChangeset
for help on using the changeset viewer.