Changeset 5fe0a69 in mainline
- Timestamp:
- 2011-08-24T14:40:26Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3afb758
- Parents:
- df8f3fa
- Location:
- uspace/drv/bus/usb/uhci
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/uhci/batch.c
rdf8f3fa r5fe0a69 45 45 #define DEFAULT_ERROR_COUNT 3 46 46 47 static void batch_setup_control(usb_transfer_batch_t *batch) 48 { 49 // TODO Find a better way to do this 50 if (batch->setup_buffer[0] & (1 << 7)) 51 batch_control_read(batch); 52 else 53 batch_control_write(batch); 54 } 55 56 void (*batch_setup[4][3])(usb_transfer_batch_t*) = 57 { 58 { NULL, NULL, batch_setup_control }, 59 { NULL, NULL, NULL }, 60 { batch_bulk_in, batch_bulk_out, NULL }, 61 { batch_interrupt_in, batch_interrupt_out, NULL }, 62 }; 63 // */ 47 64 /** UHCI specific data required for USB transfer */ 48 65 typedef struct uhci_transfer_batch { … … 68 85 * @param[in] uhci_batch Instance to destroy. 69 86 */ 70 staticvoid uhci_transfer_batch_dispose(void *uhci_batch)87 void uhci_transfer_batch_dispose(void *uhci_batch) 71 88 { 72 89 uhci_transfer_batch_t *instance = uhci_batch; … … 74 91 free32(instance->device_buffer); 75 92 free(instance); 93 } 94 /*----------------------------------------------------------------------------*/ 95 void * uhci_transfer_batch_create(usb_transfer_batch_t *batch) 96 { 97 #define CHECK_NULL_DISPOSE_RETURN(ptr, message...) \ 98 if (ptr == NULL) { \ 99 usb_log_error(message); \ 100 if (uhci_data) { \ 101 uhci_transfer_batch_dispose(uhci_data); \ 102 } \ 103 return NULL; \ 104 } else (void)0 105 106 uhci_transfer_batch_t *uhci_data = 107 calloc(1, sizeof(uhci_transfer_batch_t)); 108 CHECK_NULL_DISPOSE_RETURN(uhci_data, 109 "Failed to allocate UHCI batch.\n"); 110 111 uhci_data->td_count = 112 (batch->buffer_size + batch->ep->max_packet_size - 1) 113 / batch->ep->max_packet_size; 114 if (batch->ep->transfer_type == USB_TRANSFER_CONTROL) { 115 uhci_data->td_count += 2; 116 } 117 118 assert((sizeof(td_t) % 16) == 0); 119 const size_t total_size = (sizeof(td_t) * uhci_data->td_count) 120 + sizeof(qh_t) + batch->setup_size + batch->buffer_size; 121 uhci_data->device_buffer = malloc32(total_size); 122 CHECK_NULL_DISPOSE_RETURN(uhci_data->device_buffer, 123 "Failed to allocate UHCI buffer.\n"); 124 bzero(uhci_data->device_buffer, total_size); 125 126 uhci_data->tds = uhci_data->device_buffer; 127 uhci_data->qh = 128 (uhci_data->device_buffer + (sizeof(td_t) * uhci_data->td_count)); 129 130 qh_init(uhci_data->qh); 131 qh_set_element_td(uhci_data->qh, uhci_data->tds); 132 133 void *setup = 134 uhci_data->device_buffer + (sizeof(td_t) * uhci_data->td_count) 135 + sizeof(qh_t); 136 /* Copy SETUP packet data to device buffer */ 137 memcpy(setup, batch->setup_buffer, batch->setup_size); 138 /* Set generic data buffer pointer */ 139 batch->data_buffer = setup + batch->setup_size; 140 batch->private_data = uhci_data; 141 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT 142 " memory structures ready.\n", batch, 143 USB_TRANSFER_BATCH_ARGS(*batch)); 144 assert(batch_setup[batch->ep->transfer_type][batch->ep->direction]); 145 batch_setup[batch->ep->transfer_type][batch->ep->direction](batch); 146 147 return uhci_data; 76 148 } 77 149 /*----------------------------------------------------------------------------*/ -
uspace/drv/bus/usb/uhci/batch.h
rdf8f3fa r5fe0a69 46 46 void *arg); 47 47 48 void * uhci_transfer_batch_create(usb_transfer_batch_t *batch); 49 void uhci_transfer_batch_dispose(void *uhci_batch); 50 48 51 void batch_dispose(usb_transfer_batch_t *instance); 49 52 -
uspace/drv/bus/usb/uhci/hc.c
rdf8f3fa r5fe0a69 41 41 42 42 #include "hc.h" 43 #include "batch.h" 43 44 44 45 #define UHCI_INTR_ALLOW_INTERRUPTS \ … … 46 47 #define UHCI_STATUS_USED_INTERRUPTS \ 47 48 (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT) 49 50 static int schedule(hcd_t *hcd, usb_transfer_batch_t *batch) 51 { 52 assert(hcd); 53 return hc_schedule(hcd->private_data, batch); 54 } 48 55 49 56 static const irq_cmd_t uhci_irq_commands[] = … … 131 138 usb_log_debug( 132 139 "Device registers at %p (%zuB) accessible.\n", io, reg_size); 140 hcd_init(&instance->generic, BANDWIDTH_AVAILABLE_USB11); 141 instance->generic.private_data = instance; 142 instance->generic.schedule = schedule; 143 instance->generic.batch_private_ctor = uhci_transfer_batch_create; 144 instance->generic.batch_private_dtor = uhci_transfer_batch_dispose; 133 145 134 146 ret = hc_init_mem_structures(instance); -
uspace/drv/bus/usb/uhci/hc.h
rdf8f3fa r5fe0a69 42 42 #include <usb/host/usb_endpoint_manager.h> 43 43 #include <usb/host/batch.h> 44 #include <usb/host/hcd.h> 44 45 45 46 #include "transfer_list.h" … … 94 95 /** Main UHCI driver structure */ 95 96 typedef struct hc { 97 hcd_t generic; 96 98 /** USB bus driver, devices and addresses */ 97 99 usb_device_keeper_t manager; -
uspace/drv/bus/usb/uhci/uhci.c
rdf8f3fa r5fe0a69 87 87 /** Operations supported by the HC driver */ 88 88 static ddf_dev_ops_t hc_ops = { 89 .interfaces[USBHC_DEV_IFACE] = &hc _iface, /* see iface.h/c */89 .interfaces[USBHC_DEV_IFACE] = &hcd_iface, /* see iface.h/c */ 90 90 }; 91 91 /*----------------------------------------------------------------------------*/ … … 100 100 { 101 101 assert(fun); 102 usb_device_keeper_t *manager = &dev_to_uhci(fun->dev)->hc. manager;102 usb_device_keeper_t *manager = &dev_to_uhci(fun->dev)->hc.generic.dev_manager; 103 103 usb_address_t addr = usb_device_keeper_find(manager, handle); 104 104 … … 202 202 CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create UHCI HC function.\n"); 203 203 instance->hc_fun->ops = &hc_ops; 204 instance->hc_fun->driver_data = &instance->hc ;204 instance->hc_fun->driver_data = &instance->hc.generic; 205 205 206 206 instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci_rh");
Note:
See TracChangeset
for help on using the changeset viewer.