Changeset fd9f4ffe in mainline
- Timestamp:
- 2017-07-12T16:11:22Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 481af21e
- Parents:
- c9c0e41
- Location:
- uspace/drv/bus/usb/xhci
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/hc.c
rc9c0e41 rfd9f4ffe 41 41 #include "hc.h" 42 42 #include "hw_struct/trb.h" 43 #include "scratchpad.h"44 43 #include "commands.h" 45 44 -
uspace/drv/bus/usb/xhci/hc.h
rc9c0e41 rfd9f4ffe 40 40 #include "hw_struct/regs.h" 41 41 #include "hw_struct/context.h" 42 #include "scratchpad.h" 42 43 #include "trb_ring.h" 43 44 … … 66 67 xhci_event_ring_t event_ring; 67 68 xhci_device_ctx_t **dcbaa; 69 xhci_scratchpad_t *scratchpad; 68 70 69 71 /* Cached capabilities */ -
uspace/drv/bus/usb/xhci/scratchpad.c
rc9c0e41 rfd9f4ffe 54 54 { 55 55 unsigned num_bufs, allocated; 56 xhci_scratchpad_t *buf _array;56 xhci_scratchpad_t *bufs; 57 57 58 58 num_bufs = xhci_scratchpad_count(hc); … … 61 61 return EOK; 62 62 63 buf _array = malloc32(num_bufs *sizeof(xhci_scratchpad_t));64 if (!buf _array)63 bufs = malloc32(sizeof(xhci_scratchpad_t)); 64 if (!bufs) 65 65 return ENOMEM; 66 66 67 hc->dcbaa[0] = (xhci_device_ctx_t *) buf_array;67 allocated = 0; 68 68 69 allocated = 0; 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; 76 70 77 for (unsigned i = 0; i < num_bufs; ++i) { 71 buf_array[i].sp_ptr = (uint64_t) malloc32(PAGE_SIZE); 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; 72 81 73 if (buf _array[i].sp_ptr)82 if (buf != NULL) 74 83 ++allocated; 75 84 else 76 85 goto err_page_alloc; 77 86 78 memset( (void *) buf_array[i].sp_ptr, 0, PAGE_SIZE);87 memset(buf, 0, PAGE_SIZE); 79 88 } 89 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] = (xhci_device_ctx_t *) bufs->phys_ptr; 95 hc->scratchpad = bufs; 80 96 81 97 usb_log_debug2("Allocated %d scratchpad buffers.", num_bufs); … … 85 101 err_page_alloc: 86 102 for (unsigned i = 0; i < allocated; ++i) 87 free32((void *) buf_array[i].sp_ptr); 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); 88 111 89 112 return ENOMEM; … … 93 116 { 94 117 unsigned num_bufs; 95 xhci_scratchpad_t *buf_array; 96 118 xhci_scratchpad_t *scratchpad; 119 uint64_t *virt_array; 120 97 121 num_bufs = xhci_scratchpad_count(hc); 98 122 if(!num_bufs) 99 123 return; 100 124 101 buf_array = (xhci_scratchpad_t *) hc->dcbaa[0]; 125 scratchpad = hc->scratchpad; 126 virt_array = (uint64_t *) scratchpad->virt_ptr; 102 127 103 128 for (unsigned i = 0; i < num_bufs; ++i) 104 free32((void *) buf_array[i].sp_ptr); 105 free32(buf_array); 129 free32((void *) virt_array[i]); 130 free32((void *) scratchpad->virt_ptr); 131 free32((void *) scratchpad->phys_bck); 106 132 107 133 hc->dcbaa[0] = NULL; -
uspace/drv/bus/usb/xhci/scratchpad.h
rc9c0e41 rfd9f4ffe 41 41 #define XHCI_SCRATCHPAD_H 42 42 43 typedef struct xhci_hc xhci_hc_t; 44 43 45 typedef struct xhci_scratchpad { 44 uint64_t sp_ptr; 46 /* Pointers to scratchpad buffers used by the xHC. */ 47 uint64_t phys_ptr; 48 /* Pointers to scratchpad buffers used for deallocation. */ 49 uint64_t virt_ptr; 50 /* Pointers to the scratchpad array used for deallocation. */ 51 uint64_t phys_bck; 45 52 } xhci_scratchpad_t; 46 53
Note:
See TracChangeset
for help on using the changeset viewer.