Changeset 9a6fde4 in mainline
- Timestamp:
- 2011-04-13T13:56:51Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7013b14
- Parents:
- 592369ae
- Location:
- uspace/drv/ohci
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/batch.c
r592369ae r9a6fde4 39 39 40 40 #include "batch.h" 41 #include "hcd_endpoint.h" 41 42 #include "utils/malloc32.h" 42 43 #include "hw_struct/endpoint_descriptor.h" … … 45 46 typedef struct ohci_transfer_batch { 46 47 ed_t *ed; 47 td_t * tds;48 td_t **tds; 48 49 size_t td_count; 50 size_t leave_td; 51 char *device_buffer; 49 52 } ohci_transfer_batch_t; 50 53 51 54 static void ohci_transfer_batch_dispose(void *ohci_batch) 52 55 { 53 //TODO: add buffer disposal54 56 ohci_transfer_batch_t *instance = ohci_batch; 55 assert(instance); 56 free32(instance->ed); 57 free32(instance->tds); 58 } 59 57 if (!instance) 58 return; 59 free32(instance->device_buffer); 60 unsigned i = 0; 61 if (instance->tds) { 62 for (; i< instance->td_count; ++i) { 63 if (i != instance->leave_td) 64 free32(instance->tds[i]); 65 } 66 free(instance->tds); 67 } 68 free(instance); 69 } 70 /*----------------------------------------------------------------------------*/ 60 71 static void batch_control(usb_transfer_batch_t *instance, 61 72 usb_direction_t data_dir, usb_direction_t status_dir); 62 73 static void batch_data(usb_transfer_batch_t *instance); 63 64 #define DEFAULT_ERROR_COUNT 3 74 /*----------------------------------------------------------------------------*/ 65 75 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep, 66 76 char *buffer, size_t buffer_size, char* setup_buffer, size_t setup_size, … … 84 94 ohci_transfer_batch_dispose); 85 95 86 ohci_transfer_batch_t *data = malloc(sizeof(ohci_transfer_batch_t)); 96 hcd_endpoint_t *hcd_ep = hcd_endpoint_get(ep); 97 assert(hcd_ep); 98 99 ohci_transfer_batch_t *data = calloc(sizeof(ohci_transfer_batch_t), 1); 87 100 CHECK_NULL_DISPOSE_RETURN(data, "Failed to allocate batch data.\n"); 88 bzero(data, sizeof(ohci_transfer_batch_t));89 101 instance->private_data = data; 90 102 91 /* we needs + 1 transfer descriptor as the last one won't be executed */ 92 data->td_count = 1 + 103 data->td_count = 93 104 ((buffer_size + OHCI_TD_MAX_TRANSFER - 1) / OHCI_TD_MAX_TRANSFER); 94 105 if (ep->transfer_type == USB_TRANSFER_CONTROL) { … … 96 107 } 97 108 98 data->tds = malloc32(sizeof(td_t) * data->td_count); 109 /* we need one extra place for td that is currently assigned to hcd_ep*/ 110 data->tds = calloc(sizeof(td_t*), data->td_count + 1); 99 111 CHECK_NULL_DISPOSE_RETURN(data->tds, 100 112 "Failed to allocate transfer descriptors.\n"); 101 bzero(data->tds, sizeof(td_t) * data->td_count); 102 103 data->ed = malloc32(sizeof(ed_t)); 104 CHECK_NULL_DISPOSE_RETURN(data->ed, 105 "Failed to allocate endpoint descriptor.\n"); 106 107 if (buffer_size > 0) { 108 instance->data_buffer = malloc32(buffer_size); 109 CHECK_NULL_DISPOSE_RETURN(instance->data_buffer, 113 114 data->tds[0] = hcd_ep->td; 115 data->leave_td = 0; 116 unsigned i = 1; 117 for (; i <= data->td_count; ++i) { 118 data->tds[i] = malloc32(sizeof(td_t)); 119 CHECK_NULL_DISPOSE_RETURN(data->tds[i], 120 "Failed to allocate TD %d.\n", i ); 121 } 122 123 data->ed = hcd_ep->ed; 124 125 if (setup_size + buffer_size > 0) { 126 data->device_buffer = malloc32(setup_size + buffer_size); 127 CHECK_NULL_DISPOSE_RETURN(data->device_buffer, 110 128 "Failed to allocate device accessible buffer.\n"); 111 } 112 113 if (setup_size > 0) { 114 instance->setup_buffer = malloc32(setup_size); 115 CHECK_NULL_DISPOSE_RETURN(instance->setup_buffer, 116 "Failed to allocate device accessible setup buffer.\n"); 129 instance->setup_buffer = data->device_buffer; 130 instance->data_buffer = data->device_buffer + setup_size; 117 131 memcpy(instance->setup_buffer, setup_buffer, setup_size); 118 132 } … … 126 140 ohci_transfer_batch_t *data = instance->private_data; 127 141 assert(data); 128 size_t tds = data->td_count - 1;142 size_t tds = data->td_count; 129 143 usb_log_debug("Batch(%p) checking %d td(s) for completion.\n", 130 144 instance, tds); … … 134 148 size_t i = 0; 135 149 for (; i < tds; ++i) { 150 assert(data->tds[i] != NULL); 136 151 usb_log_debug("TD %d: %x:%x:%x:%x.\n", i, 137 data->tds[i] .status, data->tds[i].cbp, data->tds[i].next,138 data->tds[i] .be);139 if (!td_is_finished( &data->tds[i])) {152 data->tds[i]->status, data->tds[i]->cbp, data->tds[i]->next, 153 data->tds[i]->be); 154 if (!td_is_finished(data->tds[i])) { 140 155 return false; 141 156 } 142 instance->error = td_error( &data->tds[i]);157 instance->error = td_error(data->tds[i]); 143 158 /* FIXME: calculate real transfered size */ 144 159 instance->transfered_size = instance->buffer_size; 145 160 if (instance->error != EOK) { 146 161 usb_log_debug("Batch(%p) found error TD(%d):%x.\n", 147 instance, i, data->tds[i].status); 148 return true; 149 // endpoint_toggle_set(instance->ep, 162 instance, i, data->tds[i]->status); 163 break; 150 164 } 151 165 } 166 data->leave_td = ++i; 167 assert(data->leave_td <= data->td_count); 152 168 return true; 153 169 } … … 220 236 assert(data); 221 237 ed_init(data->ed, instance->ep); 222 ed_add_tds(data->ed, &data->tds[0], &data->tds[data->td_count - 1]);238 // ed_add_tds(data->ed, &data->tds[0], &data->tds[data->td_count - 1]); 223 239 usb_log_debug("Created ED(%p): %x:%x:%x:%x.\n", data->ed, 224 240 data->ed->status, data->ed->td_tail, data->ed->td_head, … … 226 242 int toggle = 0; 227 243 /* setup stage */ 228 td_init( &data->tds[0], USB_DIRECTION_BOTH, instance->setup_buffer,244 td_init(data->tds[0], USB_DIRECTION_BOTH, instance->setup_buffer, 229 245 instance->setup_size, toggle); 230 td_set_next( &data->tds[0], &data->tds[1]);231 usb_log_debug("Created SETUP TD: %x:%x:%x:%x.\n", data->tds[0] .status,232 data->tds[0] .cbp, data->tds[0].next, data->tds[0].be);246 td_set_next(data->tds[0], data->tds[1]); 247 usb_log_debug("Created SETUP TD: %x:%x:%x:%x.\n", data->tds[0]->status, 248 data->tds[0]->cbp, data->tds[0]->next, data->tds[0]->be); 233 249 234 250 /* data stage */ … … 241 257 toggle = 1 - toggle; 242 258 243 td_init( &data->tds[td_current], data_dir, buffer,259 td_init(data->tds[td_current], data_dir, buffer, 244 260 transfer_size, toggle); 245 td_set_next( &data->tds[td_current], &data->tds[td_current + 1]);261 td_set_next(data->tds[td_current], data->tds[td_current + 1]); 246 262 usb_log_debug("Created DATA TD: %x:%x:%x:%x.\n", 247 data->tds[td_current] .status, data->tds[td_current].cbp,248 data->tds[td_current] .next, data->tds[td_current].be);263 data->tds[td_current]->status, data->tds[td_current]->cbp, 264 data->tds[td_current]->next, data->tds[td_current]->be); 249 265 250 266 buffer += transfer_size; 251 267 remain_size -= transfer_size; 252 assert(td_current < data->td_count - 2);268 assert(td_current < data->td_count - 1); 253 269 ++td_current; 254 270 } 255 271 256 272 /* status stage */ 257 assert(td_current == data->td_count - 2); 258 td_init(&data->tds[td_current], status_dir, NULL, 0, 1); 273 assert(td_current == data->td_count - 1); 274 td_init(data->tds[td_current], status_dir, NULL, 0, 1); 275 td_set_next(data->tds[td_current], data->tds[td_current + 1]); 259 276 usb_log_debug("Created STATUS TD: %x:%x:%x:%x.\n", 260 data->tds[td_current] .status, data->tds[td_current].cbp,261 data->tds[td_current] .next, data->tds[td_current].be);277 data->tds[td_current]->status, data->tds[td_current]->cbp, 278 data->tds[td_current]->next, data->tds[td_current]->be); 262 279 } 263 280 /*----------------------------------------------------------------------------*/ … … 268 285 assert(data); 269 286 ed_init(data->ed, instance->ep); 270 ed_add_tds(data->ed, &data->tds[0], &data->tds[data->td_count - 1]);287 // ed_add_tds(data->ed, &data->tds[0], &data->tds[data->td_count - 1]); 271 288 usb_log_debug("Created ED(%p): %x:%x:%x:%x.\n", data->ed, 272 289 data->ed->status, data->ed->td_tail, data->ed->td_head, … … 281 298 OHCI_TD_MAX_TRANSFER : remain_size; 282 299 283 td_init( &data->tds[td_current], instance->ep->direction,300 td_init(data->tds[td_current], instance->ep->direction, 284 301 buffer, transfer_size, -1); 285 td_set_next( &data->tds[td_current], &data->tds[td_current + 1]);302 td_set_next(data->tds[td_current], data->tds[td_current + 1]); 286 303 usb_log_debug("Created DATA TD: %x:%x:%x:%x.\n", 287 data->tds[td_current] .status, data->tds[td_current].cbp,288 data->tds[td_current] .next, data->tds[td_current].be);304 data->tds[td_current]->status, data->tds[td_current]->cbp, 305 data->tds[td_current]->next, data->tds[td_current]->be); 289 306 290 307 buffer += transfer_size; -
uspace/drv/ohci/hc.c
r592369ae r9a6fde4 68 68 &instance->manager, hub_address, hub_fun->handle); 69 69 70 ret = usb_endpoint_manager_add_ep(&instance->ep_manager, 71 hub_address, 0, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL, 72 USB_SPEED_FULL, 64, 0); 70 ret = hc_add_endpoint(instance, hub_address, 0, USB_SPEED_FULL, 71 USB_TRANSFER_CONTROL, USB_DIRECTION_BOTH, 64, 0, 0); 73 72 if (ret != EOK) { 74 73 usb_log_error("Failed to add OHCI rh endpoint 0.\n"); -
uspace/drv/ohci/hcd_endpoint.c
r592369ae r9a6fde4 56 56 57 57 ed_init(hcd_ep->ed, ep); 58 ed_ add_tds(hcd_ep->ed, hcd_ep->td, hcd_ep->td);58 ed_set_td(hcd_ep->ed, hcd_ep->td); 59 59 endpoint_set_hc_data(ep, hcd_ep, NULL, NULL); 60 60 -
uspace/drv/ohci/hw_struct/endpoint_descriptor.h
r592369ae r9a6fde4 81 81 void ed_init(ed_t *instance, endpoint_t *ep); 82 82 83 static inline void ed_ add_tds(ed_t *instance, td_t *head, td_t *tail)83 static inline void ed_set_td(ed_t *instance, td_t *td) 84 84 { 85 85 assert(instance); 86 uintptr_t pa = addr_to_phys(td); 86 87 instance->td_head = 87 (( addr_to_phys(head)& ED_TDHEAD_PTR_MASK)88 ((pa & ED_TDHEAD_PTR_MASK) 88 89 | (instance->td_head & ~ED_TDHEAD_PTR_MASK)); 89 instance->td_tail = addr_to_phys(tail) & ED_TDTAIL_PTR_MASK; 90 instance->td_tail = pa & ED_TDTAIL_PTR_MASK; 91 } 92 93 static inline void ed_set_end_td(ed_t *instance, td_t *td) 94 { 95 assert(instance); 96 uintptr_t pa = addr_to_phys(td); 97 instance->td_tail = pa & ED_TDTAIL_PTR_MASK; 90 98 } 91 99
Note:
See TracChangeset
for help on using the changeset viewer.