Changeset e2976bb in mainline for uspace/drv/bus/usb/ohci/batch.c
- Timestamp:
- 2011-08-25T11:34:19Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4f0e510
- Parents:
- 27873be
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ohci/batch.c
r27873be re2976bb 66 66 * @param[in] ohci_batch Instance to destroy. 67 67 */ 68 static void ohci_ transfer_batch_dispose(void *ohci_batch)68 static void ohci_batch_dispose(void *ohci_batch) 69 69 { 70 70 ohci_transfer_batch_t *instance = ohci_batch; … … 83 83 } 84 84 /*----------------------------------------------------------------------------*/ 85 int batch_init_ohci(usb_transfer_batch_t *batch) 86 { 87 assert(batch); 88 #define CHECK_NULL_DISPOSE_RETURN(ptr, message...) \ 89 if (ptr == NULL) { \ 90 usb_log_error(message); \ 91 if (data) { \ 92 ohci_batch_dispose(data); \ 93 } \ 94 return ENOMEM; \ 95 } else (void)0 96 97 const hcd_endpoint_t *hcd_ep = hcd_endpoint_get(batch->ep); 98 assert(hcd_ep); 99 100 ohci_transfer_batch_t *data = calloc(sizeof(ohci_transfer_batch_t), 1); 101 CHECK_NULL_DISPOSE_RETURN(data, "Failed to allocate batch data.\n"); 102 103 data->td_count = ((batch->buffer_size + OHCI_TD_MAX_TRANSFER - 1) 104 / OHCI_TD_MAX_TRANSFER); 105 /* Control transfer need Setup and Status stage */ 106 if (batch->ep->transfer_type == USB_TRANSFER_CONTROL) { 107 data->td_count += 2; 108 } 109 110 /* We need an extra place for TD that is currently assigned to hcd_ep*/ 111 data->tds = calloc(sizeof(td_t*), data->td_count + 1); 112 CHECK_NULL_DISPOSE_RETURN(data->tds, 113 "Failed to allocate transfer descriptors.\n"); 114 115 /* Add TD left over by the previous transfer */ 116 data->tds[0] = hcd_ep->td; 117 data->leave_td = 0; 118 unsigned i = 1; 119 for (; i <= data->td_count; ++i) { 120 data->tds[i] = malloc32(sizeof(td_t)); 121 CHECK_NULL_DISPOSE_RETURN(data->tds[i], 122 "Failed to allocate TD %d.\n", i ); 123 } 124 125 data->ed = hcd_ep->ed; 126 batch->private_data = data; 127 batch->private_data_dtor = ohci_batch_dispose; 128 129 /* NOTE: OHCI is capable of handling buffer that crosses page boundaries 130 * it is, however, not capable of handling buffer that occupies more 131 * than two pages (the first page is computed using start pointer, the 132 * other using the end pointer) */ 133 if (batch->setup_size + batch->buffer_size > 0) { 134 data->device_buffer = 135 malloc32(batch->setup_size + batch->buffer_size); 136 CHECK_NULL_DISPOSE_RETURN(data->device_buffer, 137 "Failed to allocate device accessible buffer.\n"); 138 memcpy(data->device_buffer, batch->setup_buffer, 139 batch->setup_size); 140 batch->data_buffer = data->device_buffer + batch->setup_size; 141 } 142 143 return EOK; 144 #undef CHECK_NULL_DISPOSE_RETURN 145 } 146 /*----------------------------------------------------------------------------*/ 85 147 /** Allocate memory initialize internal structures 86 148 * … … 119 181 usb_transfer_batch_init(instance, ep, buffer, NULL, buffer_size, 120 182 NULL, setup_size, func_in, func_out, arg, fun, NULL, 121 ohci_ transfer_batch_dispose);183 ohci_batch_dispose); 122 184 123 185 const hcd_endpoint_t *hcd_ep = hcd_endpoint_get(ep);
Note:
See TracChangeset
for help on using the changeset viewer.