Changeset 09ace19 in mainline for uspace/drv/bus/usb/ohci/batch.c
- Timestamp:
- 2011-08-25T15:33:41Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f974519
- Parents:
- cc34f5f0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ohci/batch.c
rcc34f5f0 r09ace19 43 43 #include "hw_struct/endpoint_descriptor.h" 44 44 #include "hw_struct/transfer_descriptor.h" 45 /* 45 46 46 static void batch_control_write(usb_transfer_batch_t *instance); 47 47 static void batch_control_read(usb_transfer_batch_t *instance); … … 52 52 static void batch_bulk_in(usb_transfer_batch_t *instance); 53 53 static void batch_bulk_out(usb_transfer_batch_t *instance); 54 */ 54 55 55 static void batch_setup_control(usb_transfer_batch_t *batch) 56 56 { … … 173 173 return EOK; 174 174 #undef CHECK_NULL_DISPOSE_RETURN 175 }176 /*----------------------------------------------------------------------------*/177 /** Allocate memory initialize internal structures178 *179 * @param[in] fun DDF function to pass to callback.180 * @param[in] ep Communication target181 * @param[in] buffer Data source/destination.182 * @param[in] buffer_size Size of the buffer.183 * @param[in] setup_buffer Setup data source (if not NULL)184 * @param[in] setup_size Size of setup_buffer (should be always 8)185 * @param[in] func_in function to call on inbound transfer completion186 * @param[in] func_out function to call on outbound transfer completion187 * @param[in] arg additional parameter to func_in or func_out188 * @return Valid pointer if all structures were successfully created,189 * NULL otherwise.190 *191 * Allocates and initializes structures needed by the OHCI hw for the transfer.192 */193 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep,194 char *buffer, size_t buffer_size,195 const char *setup_buffer, size_t setup_size,196 usbhc_iface_transfer_in_callback_t func_in,197 usbhc_iface_transfer_out_callback_t func_out, void *arg)198 {199 #define CHECK_NULL_DISPOSE_RETURN(ptr, message...) \200 if (ptr == NULL) { \201 usb_log_error(message); \202 if (instance) { \203 usb_transfer_batch_dispose(instance); \204 } \205 return NULL; \206 } else (void)0207 208 usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t));209 CHECK_NULL_DISPOSE_RETURN(instance,210 "Failed to allocate batch instance.\n");211 usb_transfer_batch_init(instance, ep, buffer, NULL, buffer_size,212 NULL, setup_size, func_in, func_out, arg, fun, NULL,213 ohci_batch_dispose);214 215 const ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep);216 assert(ohci_ep);217 218 ohci_transfer_batch_t *data = calloc(sizeof(ohci_transfer_batch_t), 1);219 CHECK_NULL_DISPOSE_RETURN(data, "Failed to allocate batch data.\n");220 instance->private_data = data;221 222 data->td_count =223 ((buffer_size + OHCI_TD_MAX_TRANSFER - 1) / OHCI_TD_MAX_TRANSFER);224 /* Control transfer need Setup and Status stage */225 if (ep->transfer_type == USB_TRANSFER_CONTROL) {226 data->td_count += 2;227 }228 229 /* We need an extra place for TD that is currently assigned to hcd_ep*/230 data->tds = calloc(sizeof(td_t*), data->td_count + 1);231 CHECK_NULL_DISPOSE_RETURN(data->tds,232 "Failed to allocate transfer descriptors.\n");233 234 /* Add TD left over by the previous transfer */235 data->tds[0] = ohci_ep->td;236 data->leave_td = 0;237 unsigned i = 1;238 for (; i <= data->td_count; ++i) {239 data->tds[i] = malloc32(sizeof(td_t));240 CHECK_NULL_DISPOSE_RETURN(data->tds[i],241 "Failed to allocate TD %d.\n", i );242 }243 244 data->ed = ohci_ep->ed;245 246 /* NOTE: OHCI is capable of handling buffer that crosses page boundaries247 * it is, however, not capable of handling buffer that occupies more248 * than two pages (the first page is computed using start pointer, the249 * other using the end pointer) */250 if (setup_size + buffer_size > 0) {251 data->device_buffer = malloc32(setup_size + buffer_size);252 CHECK_NULL_DISPOSE_RETURN(data->device_buffer,253 "Failed to allocate device accessible buffer.\n");254 instance->setup_buffer = data->device_buffer;255 instance->data_buffer = data->device_buffer + setup_size;256 memcpy(instance->setup_buffer, setup_buffer, setup_size);257 }258 259 return instance;260 175 } 261 176 /*----------------------------------------------------------------------------*/
Note:
See TracChangeset
for help on using the changeset viewer.