Changeset c21e6a5 in mainline for uspace/drv/bus/usb/ehci/ehci_batch.c
- Timestamp:
- 2018-02-05T00:54:08Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- af16ebe
- Parents:
- 65c059f
- git-author:
- Ondřej Hlavatý <aearsis@…> (2018-02-05 00:27:40)
- git-committer:
- Ondřej Hlavatý <aearsis@…> (2018-02-05 00:54:08)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ehci/ehci_batch.c
r65c059f rc21e6a5 61 61 { 62 62 assert(ehci_batch); 63 dma_buffer_free(&ehci_batch-> dma_buffer);63 dma_buffer_free(&ehci_batch->ehci_dma_buffer); 64 64 usb_log_debug2("Batch(%p): disposed", ehci_batch); 65 65 free(ehci_batch); … … 116 116 } 117 117 118 assert(ehci_batch->td_count > 0); 119 118 120 const size_t tds_size = ehci_batch->td_count * sizeof(td_t); 119 121 120 /* Mix setup stage, data and TDs together, we have enough space */ 121 if (size + setup_size + tds_size > 0) { 122 if (dma_buffer_alloc(&ehci_batch->dma_buffer, tds_size + setup_size + size)) { 123 usb_log_error("Batch %p: Failed to allocate device " 124 "buffer", ehci_batch); 125 return ENOMEM; 126 } 127 /* Clean TDs */ 128 ehci_batch->tds = ehci_batch->dma_buffer.virt; 129 memset(ehci_batch->tds, 0, tds_size); 130 /* Copy setup data */ 131 ehci_batch->setup_buffer = ehci_batch->dma_buffer.virt + tds_size; 132 memcpy(ehci_batch->setup_buffer, ehci_batch->base.setup.buffer, setup_size); 133 /* Copy generic data */ 134 ehci_batch->data_buffer = ehci_batch->setup_buffer + setup_size; 135 if (ehci_batch->base.dir != USB_DIRECTION_IN) 136 memcpy(ehci_batch->data_buffer, 137 ehci_batch->base.buffer, 138 ehci_batch->base.buffer_size); 139 } 122 /* Mix setup stage and TDs together, we have enough space */ 123 if (dma_buffer_alloc(&ehci_batch->ehci_dma_buffer, tds_size + setup_size)) { 124 usb_log_error("Batch %p: Failed to allocate device buffer", 125 ehci_batch); 126 return ENOMEM; 127 } 128 129 /* Clean TDs */ 130 ehci_batch->tds = ehci_batch->ehci_dma_buffer.virt; 131 memset(ehci_batch->tds, 0, tds_size); 132 133 /* Copy setup data */ 134 ehci_batch->setup_buffer = ehci_batch->ehci_dma_buffer.virt + tds_size; 135 memcpy(ehci_batch->setup_buffer, ehci_batch->base.setup.buffer, setup_size); 136 137 /* Generic data already prepared*/ 138 ehci_batch->data_buffer = ehci_batch->base.dma_buffer.virt; 140 139 141 140 if (!batch_setup[ehci_batch->base.ep->transfer_type]) … … 219 218 assert(ehci_batch->base.transferred_size <= ehci_batch->base.buffer_size); 220 219 221 if (ehci_batch->base.dir == USB_DIRECTION_IN)222 memcpy(ehci_batch->base.buffer,223 ehci_batch->data_buffer,224 ehci_batch->base.transferred_size);225 226 220 /* Clear TD pointers */ 227 221 ehci_batch->qh->next = LINK_POINTER_TERM; … … 240 234 { 241 235 assert(ehci_batch); 242 qh_set_next_td(ehci_batch->qh, dma_buffer_phys(&ehci_batch->dma_buffer, &ehci_batch->tds[0])); 236 qh_set_next_td(ehci_batch->qh, 237 dma_buffer_phys(&ehci_batch->ehci_dma_buffer, &ehci_batch->tds[0])); 243 238 } 244 239 … … 275 270 /* Setup stage */ 276 271 td_init(&ehci_batch->tds[0], 277 dma_buffer_phys(&ehci_batch-> dma_buffer, &ehci_batch->tds[1]),278 dma_buffer_phys(&ehci_batch-> dma_buffer, ehci_batch->setup_buffer),272 dma_buffer_phys(&ehci_batch->ehci_dma_buffer, &ehci_batch->tds[1]), 273 dma_buffer_phys(&ehci_batch->ehci_dma_buffer, ehci_batch->setup_buffer), 279 274 USB_DIRECTION_BOTH, USB_SETUP_PACKET_SIZE, toggle, false); 280 275 usb_log_debug2("Batch %p: Created CONTROL SETUP TD(%"PRIxn"): " 281 276 "%08x:%08x:%08x", ehci_batch, 282 dma_buffer_phys(&ehci_batch-> dma_buffer, &ehci_batch->tds[0]),277 dma_buffer_phys(&ehci_batch->ehci_dma_buffer, &ehci_batch->tds[0]), 283 278 ehci_batch->tds[0].status, ehci_batch->tds[0].next, 284 279 ehci_batch->tds[0].alternate); … … 287 282 unsigned td_current = 1; 288 283 size_t remain_size = ehci_batch->base.buffer_size; 289 uintptr_t buffer = dma_buffer_phys(&ehci_batch->dma_buffer, ehci_batch->data_buffer); 284 uintptr_t buffer = dma_buffer_phys(&ehci_batch->base.dma_buffer, 285 ehci_batch->data_buffer); 290 286 while (remain_size > 0) { 291 287 const size_t transfer_size = min(remain_size, EHCI_TD_MAX_TRANSFER); … … 293 289 294 290 td_init(&ehci_batch->tds[td_current], 295 dma_buffer_phys(&ehci_batch-> dma_buffer, &ehci_batch->tds[td_current + 1]),291 dma_buffer_phys(&ehci_batch->ehci_dma_buffer, &ehci_batch->tds[td_current + 1]), 296 292 buffer, data_dir, transfer_size, toggle, false); 297 293 usb_log_debug2("Batch %p: Created CONTROL DATA TD(%"PRIxn"): " 298 294 "%08x:%08x:%08x", ehci_batch, 299 dma_buffer_phys(&ehci_batch-> dma_buffer, &ehci_batch->tds[td_current]),295 dma_buffer_phys(&ehci_batch->ehci_dma_buffer, &ehci_batch->tds[td_current]), 300 296 ehci_batch->tds[td_current].status, 301 297 ehci_batch->tds[td_current].next, … … 313 309 usb_log_debug2("Batch %p: Created CONTROL STATUS TD %d(%"PRIxn"): " 314 310 "%08x:%08x:%08x", ehci_batch, td_current, 315 dma_buffer_phys(&ehci_batch-> dma_buffer, &ehci_batch->tds[td_current]),311 dma_buffer_phys(&ehci_batch->ehci_dma_buffer, &ehci_batch->tds[td_current]), 316 312 ehci_batch->tds[td_current].status, 317 313 ehci_batch->tds[td_current].next, … … 340 336 size_t td_current = 0; 341 337 size_t remain_size = ehci_batch->base.buffer_size; 342 uintptr_t buffer = dma_buffer_phys(&ehci_batch->dma_buffer, ehci_batch->data_buffer); 338 uintptr_t buffer = dma_buffer_phys(&ehci_batch->base.dma_buffer, 339 ehci_batch->data_buffer); 343 340 while (remain_size > 0) { 344 341 const size_t transfer_size = remain_size > EHCI_TD_MAX_TRANSFER … … 347 344 const bool last = (remain_size == transfer_size); 348 345 td_init(&ehci_batch->tds[td_current], 349 last ? 0 : dma_buffer_phys(&ehci_batch->dma_buffer, &ehci_batch->tds[td_current + 1]), 346 last ? 0 : dma_buffer_phys(&ehci_batch->ehci_dma_buffer, 347 &ehci_batch->tds[td_current + 1]), 350 348 buffer, ehci_batch->base.dir, transfer_size, -1, last); 351 349 352 350 usb_log_debug2("Batch %p: DATA TD(%"PRIxn": %08x:%08x:%08x", 353 351 ehci_batch, 354 dma_buffer_phys(&ehci_batch->dma_buffer, &ehci_batch->tds[td_current]), 352 dma_buffer_phys(&ehci_batch->ehci_dma_buffer, 353 &ehci_batch->tds[td_current]), 355 354 ehci_batch->tds[td_current].status, 356 355 ehci_batch->tds[td_current].next,
Note:
See TracChangeset
for help on using the changeset viewer.