Changeset 5dab9ef0 in mainline
- Timestamp:
- 2018-01-17T11:37:34Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 61e27e80
- Parents:
- 0f803831
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/streams.c
r0f803831 r5dab9ef0 70 70 } 71 71 72 static int initialize_primary_structures(xhci_endpoint_t *xhci_ep, unsigned count) 73 { 74 usb_log_debug2("Allocating primary stream context array of size %u for endpoint " XHCI_EP_FMT, 75 count, XHCI_EP_ARGS(*xhci_ep)); 76 77 if ((dma_buffer_alloc(&xhci_ep->primary_stream_ctx_dma, count * sizeof(xhci_stream_ctx_t)))) { 78 return ENOMEM; 79 } 80 81 xhci_ep->primary_stream_ctx_array = xhci_ep->primary_stream_ctx_dma.virt; 82 xhci_ep->primary_stream_data_array = calloc(count, sizeof(xhci_stream_data_t)); 83 if (!xhci_ep->primary_stream_data_array) { 84 dma_buffer_free(&xhci_ep->primary_stream_ctx_dma); 85 return ENOMEM; 86 } 87 88 xhci_ep->primary_stream_data_size = count; 89 90 return EOK; 91 } 92 93 static void clear_primary_structures(xhci_endpoint_t *xhci_ep) 94 { 95 usb_log_debug2("Deallocating primary stream structures for endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep)); 96 97 dma_buffer_free(&xhci_ep->primary_stream_ctx_dma); 98 free(xhci_ep->primary_stream_data_array); 99 } 100 101 static void clear_secondary_streams(xhci_endpoint_t *xhci_ep, unsigned index) 102 { 103 xhci_stream_data_t *data = &xhci_ep->primary_stream_data_array[index]; 104 if (!data->secondary_size) { 105 xhci_trb_ring_fini(&data->ring); 106 return; 107 } 108 109 for (size_t i = 0; i < data->secondary_size; ++i) { 110 xhci_trb_ring_fini(&data->secondary_data[i].ring); 111 } 112 113 dma_buffer_free(&data->secondary_stream_ctx_dma); 114 free(data->secondary_data); 115 } 116 72 117 void xhci_stream_free_ds(xhci_endpoint_t *xhci_ep) 73 118 { … … 75 120 76 121 for (size_t index = 0; index < xhci_ep->primary_stream_data_size; ++index) { 77 xhci_stream_data_t *primary_data = xhci_ep->primary_stream_data_array + index; 78 if (primary_data->secondary_size > 0) { 79 for (size_t index2 = 0; index2 < primary_data->secondary_size; ++index2) { 80 xhci_stream_data_t *secondary_data = primary_data->secondary_data + index2; 81 xhci_trb_ring_fini(&secondary_data->ring); 82 } 83 dma_buffer_free(&primary_data->secondary_stream_ctx_dma); 84 } 85 else { 86 xhci_trb_ring_fini(&primary_data->ring); 87 } 88 } 89 dma_buffer_free(&xhci_ep->primary_stream_ctx_dma); 90 } 91 92 /** Initialize secondary streams of XHCI bulk endpoint. 122 clear_secondary_streams(xhci_ep, index); 123 } 124 clear_primary_structures(xhci_ep); 125 } 126 127 /** Initialize primary stream structure with given index. 93 128 * @param[in] hc Host controller of the endpoint. 94 129 * @param[in] xhci_epi XHCI bulk endpoint to use. 95 * @param[in] index Index to primary stream array130 * @param[in] index index of the initialized stream structure. 96 131 */ 97 132 static int initialize_primary_stream(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep, unsigned index) { … … 116 151 /** Initialize primary streams of XHCI bulk endpoint. 117 152 * @param[in] hc Host controller of the endpoint. 118 * @param[in] xhci_ep iXHCI bulk endpoint to use.153 * @param[in] xhci_ep XHCI bulk endpoint to use. 119 154 */ 120 155 static int initialize_primary_streams(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep) 121 156 { 122 157 int err = EOK; 123 for (size_t index = 0; index < xhci_ep->primary_stream_data_size; ++index) { 158 size_t index; 159 for (index = 0; index < xhci_ep->primary_stream_data_size; ++index) { 124 160 err = initialize_primary_stream(hc, xhci_ep, index); 125 161 if (err) { 126 return err;162 goto err_clean; 127 163 } 128 164 } 129 165 130 // TODO: deinitialize if we got stuck in the middle 131 132 return EOK; 166 return EOK; 167 168 err_clean: 169 for (size_t i = 0; i < index; ++i) { 170 xhci_trb_ring_fini(&xhci_ep->primary_stream_data_array[i].ring); 171 } 172 return err; 133 173 } 134 174 … … 136 176 * @param[in] hc Host controller of the endpoint. 137 177 * @param[in] xhci_epi XHCI bulk endpoint to use. 138 * @param[in] i ndex Index to primary stream array178 * @param[in] idx Index to primary stream array 139 179 * @param[in] count Number of secondary streams to initialize. 140 180 */ 141 static int initialize_secondary_streams(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep, unsigned i ndex, unsigned count)181 static int initialize_secondary_streams(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep, unsigned idx, unsigned count) 142 182 { 143 183 if (count == 0) { 144 return initialize_primary_stream(hc, xhci_ep, i ndex);184 return initialize_primary_stream(hc, xhci_ep, idx); 145 185 } 146 186 … … 150 190 } 151 191 152 xhci_stream_ctx_t *ctx = &xhci_ep->primary_stream_ctx_array[i ndex];153 xhci_stream_data_t *data = &xhci_ep->primary_stream_data_array[i ndex];192 xhci_stream_ctx_t *ctx = &xhci_ep->primary_stream_ctx_array[idx]; 193 xhci_stream_data_t *data = &xhci_ep->primary_stream_data_array[idx]; 154 194 memset(data, 0, sizeof(xhci_stream_data_t)); 155 195 … … 161 201 162 202 if ((dma_buffer_alloc(&data->secondary_stream_ctx_dma, count * sizeof(xhci_stream_ctx_t)))) { 203 free(data->secondary_data); 163 204 return ENOMEM; 164 205 } … … 169 210 170 211 int err = EOK; 171 172 for ( size_t i = 0; i < count; ++i) {173 xhci_stream_ctx_t *secondary_ctx = &data->secondary_stream_ctx_array[i ];174 xhci_stream_data_t *secondary_data = &data->secondary_data[i ];212 size_t index; 213 for (index = 0; index < count; ++index) { 214 xhci_stream_ctx_t *secondary_ctx = &data->secondary_stream_ctx_array[index]; 215 xhci_stream_data_t *secondary_data = &data->secondary_data[index]; 175 216 /* Init and register TRB ring for every secondary stream */ 176 217 if ((err = xhci_trb_ring_init(&secondary_data->ring))) { 177 return err;218 goto err_init; 178 219 } 179 220 180 221 XHCI_STREAM_DEQ_PTR_SET(*secondary_ctx, secondary_data->ring.dequeue); 181 182 /* Set to linear stream array */ 222 /* Set to secondary stream array */ 183 223 XHCI_STREAM_SCT_SET(*secondary_ctx, 0); 184 224 } 185 225 186 // TODO: deinitialize if we got stuck in the middle 187 188 return EOK; 226 return EOK; 227 228 err_init: 229 for (size_t i = 0; i < index; ++i) { 230 xhci_trb_ring_fini(&data->secondary_data[i].ring); 231 } 232 return err; 189 233 } 190 234 … … 246 290 } 247 291 248 static int initialize_primary_structures(xhci_endpoint_t *xhci_ep, unsigned count)249 {250 usb_log_debug2("Allocating primary stream context array of size %u for endpoint " XHCI_EP_FMT,251 count, XHCI_EP_ARGS(*xhci_ep));252 253 if ((dma_buffer_alloc(&xhci_ep->primary_stream_ctx_dma, count * sizeof(xhci_stream_ctx_t)))) {254 return ENOMEM;255 }256 257 xhci_ep->primary_stream_ctx_array = xhci_ep->primary_stream_ctx_dma.virt;258 xhci_ep->primary_stream_data_array = calloc(count, sizeof(xhci_stream_data_t));259 if (!xhci_ep->primary_stream_data_array) {260 dma_buffer_free(&xhci_ep->primary_stream_ctx_dma);261 return ENOMEM;262 }263 264 xhci_ep->primary_stream_data_size = count;265 266 return EOK;267 }268 269 292 /** Initialize primary streams 270 293 */ … … 283 306 284 307 memset(xhci_ep->primary_stream_ctx_array, 0, count * sizeof(xhci_stream_ctx_t)); 285 initialize_primary_streams(hc, xhci_ep); 308 err = initialize_primary_streams(hc, xhci_ep); 309 if (err) { 310 clear_primary_structures(xhci_ep); 311 return err; 312 } 286 313 287 314 xhci_ep_ctx_t ep_ctx; … … 340 367 341 368 memset(xhci_ep->primary_stream_ctx_array, 0, count * sizeof(xhci_stream_ctx_t)); 342 for (size_t index = 0; index < count; ++index) { 343 initialize_secondary_streams(hc, xhci_ep, index, *(sizes + index)); 369 size_t index; 370 for (index = 0; index < count; ++index) { 371 err = initialize_secondary_streams(hc, xhci_ep, index, *(sizes + index)); 372 if (err) { 373 goto err_init; 374 } 344 375 } 345 376 … … 350 381 // FIXME: do we add endpoint? do we need to destroy previous configuration? 351 382 return hc_add_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep), &ep_ctx); 352 } 383 384 err_init: 385 for (size_t i = 0; i < index; ++i) { 386 clear_secondary_streams(xhci_ep, i); 387 } 388 clear_primary_structures(xhci_ep); 389 return err; 390 }
Note:
See TracChangeset
for help on using the changeset viewer.