Changeset b80c1ab in mainline for uspace/drv/bus/usb/xhci/scratchpad.c
- Timestamp:
- 2017-11-14T23:17:54Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e76c0ea
- Parents:
- cfe4852
- git-author:
- Aearsis <Hlavaty.Ondrej@…> (2017-11-14 23:15:24)
- git-committer:
- Aearsis <Hlavaty.Ondrej@…> (2017-11-14 23:17:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/scratchpad.c
rcfe4852 rb80c1ab 36 36 #include <errno.h> 37 37 #include <usb/debug.h> 38 #include <usb/host/utils/malloc32.h>39 38 #include "hc.h" 40 39 #include "hw_struct/regs.h" … … 53 52 int xhci_scratchpad_alloc(xhci_hc_t *hc) 54 53 { 55 unsigned num_bufs, allocated; 56 xhci_scratchpad_t *bufs; 57 58 num_bufs = xhci_scratchpad_count(hc); 54 const unsigned num_bufs = xhci_scratchpad_count(hc); 59 55 60 56 if (!num_bufs) 61 57 return EOK; 62 58 63 bufs = malloc32(sizeof(xhci_scratchpad_t)); 64 if (!bufs) 59 if (dma_buffer_alloc(&hc->scratchpad_array, num_bufs * sizeof(uint64_t))) 65 60 return ENOMEM; 61 uint64_t *phys_array = hc->scratchpad_array.virt; 66 62 67 allocated = 0;63 hc->dcbaa[0] = host2xhci(64, hc->scratchpad_array.phys); 68 64 69 uint64_t *phys_array = malloc32(num_bufs * sizeof(uint64_t)); 70 if (phys_array == NULL) 71 goto err_phys_array; 72 73 uint64_t *virt_array = malloc32(num_bufs * sizeof(uint64_t)); 74 if (virt_array == NULL) 75 goto err_virt_array; 65 hc->scratchpad_buffers = calloc(num_bufs, sizeof(dma_buffer_t)); 66 if (!hc->scratchpad_buffers) 67 goto err_dma; 76 68 77 69 for (unsigned i = 0; i < num_bufs; ++i) { 78 void *buf = malloc32(PAGE_SIZE);79 phys_array[i] = host2xhci(64, (uint64_t) addr_to_phys(buf));80 virt_array[i] = (uint64_t) buf;70 dma_buffer_t *cur = &hc->scratchpad_buffers[i]; 71 if (dma_buffer_alloc(cur, PAGE_SIZE)) 72 goto err_buffers; 81 73 82 if (buf != NULL) 83 ++allocated; 84 else 85 goto err_page_alloc; 86 87 memset(buf, 0, PAGE_SIZE); 74 memset(cur->virt, 0, PAGE_SIZE); 75 phys_array[i] = host2xhci(64, cur->phys); 88 76 } 89 77 90 bufs->phys_ptr = host2xhci(64, (uint64_t) addr_to_phys(phys_array));91 bufs->virt_ptr = (uint64_t) virt_array;92 bufs->phys_bck = (uint64_t) phys_array;93 94 hc->dcbaa[0] = bufs->phys_ptr;95 hc->scratchpad = bufs;96 78 97 79 usb_log_debug2("Allocated %d scratchpad buffers.", num_bufs); … … 99 81 return EOK; 100 82 101 err_page_alloc: 102 for (unsigned i = 0; i < allocated; ++i) 103 free32((void *) virt_array[i]); 104 free32(virt_array); 105 106 err_virt_array: 107 free32(phys_array); 108 109 err_phys_array: 110 free32(bufs); 111 83 err_buffers: 84 for (unsigned i = 0; i < num_bufs; ++i) 85 dma_buffer_free(&hc->scratchpad_buffers[i]); 86 free(hc->scratchpad_buffers); 87 err_dma: 88 hc->dcbaa[0] = 0; 89 dma_buffer_free(&hc->scratchpad_array); 112 90 return ENOMEM; 113 91 } … … 115 93 void xhci_scratchpad_free(xhci_hc_t *hc) 116 94 { 117 unsigned num_bufs; 118 xhci_scratchpad_t *scratchpad; 119 uint64_t *virt_array; 95 const unsigned num_bufs = xhci_scratchpad_count(hc); 120 96 121 num_bufs = xhci_scratchpad_count(hc);122 97 if (!num_bufs) 123 98 return; 124 99 125 scratchpad = hc->scratchpad; 126 virt_array = (uint64_t *) scratchpad->virt_ptr; 127 100 hc->dcbaa[0] = 0; 101 dma_buffer_free(&hc->scratchpad_array); 128 102 for (unsigned i = 0; i < num_bufs; ++i) 129 free32((void *) virt_array[i]); 130 free32((void *) scratchpad->virt_ptr); 131 free32((void *) scratchpad->phys_bck); 132 133 hc->dcbaa[0] = 0; 134 103 dma_buffer_free(&hc->scratchpad_buffers[i]); 104 free(hc->scratchpad_buffers); 135 105 return; 136 106 }
Note:
See TracChangeset
for help on using the changeset viewer.