Changeset 8c877b2 in mainline for uspace/drv/uhci-hcd/batch.c
- Timestamp:
- 2011-03-04T13:05:35Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d49728c
- Parents:
- dff940f8 (diff), 9a422574 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/batch.c
rdff940f8 r8c877b2 33 33 */ 34 34 #include <errno.h> 35 35 #include <str_error.h> 36 37 #include <usb/usb.h> 36 38 #include <usb/debug.h> 37 39 … … 45 47 static int batch_schedule(batch_t *instance); 46 48 49 static void batch_control( 50 batch_t *instance, int data_stage, int status_stage); 47 51 static void batch_call_in(batch_t *instance); 48 52 static void batch_call_out(batch_t *instance); … … 53 57 batch_t * batch_get(ddf_fun_t *fun, usb_target_t target, 54 58 usb_transfer_type_t transfer_type, size_t max_packet_size, 55 dev_speed_t speed, char *buffer, size_t size,59 usb_speed_t speed, char *buffer, size_t size, 56 60 char* setup_buffer, size_t setup_size, 57 61 usbhc_iface_transfer_in_callback_t func_in, … … 92 96 instance->transport_buffer = 93 97 (size > 0) ? malloc32(transport_size) : NULL; 98 94 99 if ((size > 0) && (instance->transport_buffer == NULL)) { 95 100 usb_log_error("Failed to allocate device accessible buffer.\n"); … … 133 138 134 139 queue_head_element_td(instance->qh, addr_to_phys(instance->tds)); 140 usb_log_debug("Batch(%p) %d:%d memory structures ready.\n", 141 instance, target.address, target.endpoint); 135 142 return instance; 136 143 } … … 139 146 { 140 147 assert(instance); 141 usb_log_debug ("Checking(%p) %d packetfor completion.\n",148 usb_log_debug2("Batch(%p) checking %d packet(s) for completion.\n", 142 149 instance, instance->packets); 143 150 instance->transfered_size = 0; … … 151 158 if (i > 0) 152 159 instance->transfered_size -= instance->setup_size; 160 usb_log_debug("Batch(%p) found error TD(%d):%x.\n", 161 instance, i, instance->tds[i].status); 153 162 return true; 154 163 } … … 156 165 transfer_descriptor_actual_size(&instance->tds[i]); 157 166 } 158 /* This is just an ugly trick to support the old API */159 167 instance->transfered_size -= instance->setup_size; 160 168 return true; … … 164 172 { 165 173 assert(instance); 166 167 174 /* we are data out, we are supposed to provide data */ 168 175 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 169 170 int toggle = 0; 171 /* setup stage */ 172 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 173 instance->setup_size, toggle, false, instance->target, 174 USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]); 175 176 /* data stage */ 177 size_t i = 1; 178 for (;i < instance->packets - 1; ++i) { 179 char *data = 180 instance->transport_buffer + ((i - 1) * instance->max_packet_size); 181 toggle = 1 - toggle; 182 183 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 184 instance->max_packet_size, toggle++, false, instance->target, 185 USB_PID_OUT, data, &instance->tds[i + 1]); 186 } 187 188 /* status stage */ 189 i = instance->packets - 1; 190 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 191 0, 1, false, instance->target, USB_PID_IN, NULL, NULL); 192 193 instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 194 176 batch_control(instance, USB_PID_OUT, USB_PID_IN); 195 177 instance->next_step = batch_call_out_and_dispose; 178 usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance); 196 179 batch_schedule(instance); 197 180 } … … 200 183 { 201 184 assert(instance); 202 203 int toggle = 0; 204 /* setup stage */ 205 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 206 instance->setup_size, toggle, false, instance->target, 207 USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]); 208 209 /* data stage */ 210 size_t i = 1; 211 for (;i < instance->packets - 1; ++i) { 212 char *data = 213 instance->transport_buffer + ((i - 1) * instance->max_packet_size); 214 toggle = 1 - toggle; 215 216 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 217 instance->max_packet_size, toggle, false, instance->target, 218 USB_PID_IN, data, &instance->tds[i + 1]); 219 } 220 221 /* status stage */ 222 i = instance->packets - 1; 223 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 224 0, 1, false, instance->target, USB_PID_OUT, NULL, NULL); 225 226 instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 227 185 batch_control(instance, USB_PID_IN, USB_PID_OUT); 228 186 instance->next_step = batch_call_in_and_dispose; 187 usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance); 229 188 batch_schedule(instance); 230 189 } … … 234 193 assert(instance); 235 194 195 const bool low_speed = instance->speed == USB_SPEED_LOW; 236 196 int toggle = 1; 237 197 size_t i = 0; … … 244 204 245 205 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 246 instance->max_packet_size, toggle, false, instance->target,247 USB_PID_IN, data, next);206 instance->max_packet_size, toggle, false, low_speed, 207 instance->target, USB_PID_IN, data, next); 248 208 } 249 209 … … 251 211 252 212 instance->next_step = batch_call_in_and_dispose; 213 usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance); 253 214 batch_schedule(instance); 254 215 } … … 257 218 { 258 219 assert(instance); 259 260 220 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 261 221 222 const bool low_speed = instance->speed == USB_SPEED_LOW; 262 223 int toggle = 1; 263 224 size_t i = 0; … … 270 231 271 232 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 272 instance->max_packet_size, toggle++, false, instance->target,273 USB_PID_OUT, data, next);233 instance->max_packet_size, toggle++, false, low_speed, 234 instance->target, USB_PID_OUT, data, next); 274 235 } 275 236 … … 277 238 278 239 instance->next_step = batch_call_out_and_dispose; 240 usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance); 279 241 batch_schedule(instance); 280 242 } 281 243 /*----------------------------------------------------------------------------*/ 244 static void batch_control( 245 batch_t *instance, int data_stage, int status_stage) 246 { 247 assert(instance); 248 249 const bool low_speed = instance->speed == USB_SPEED_LOW; 250 int toggle = 0; 251 /* setup stage */ 252 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 253 instance->setup_size, toggle, false, low_speed, instance->target, 254 USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]); 255 256 /* data stage */ 257 size_t packet = 1; 258 size_t remain_size = instance->buffer_size; 259 while (remain_size > 0) { 260 char *data = 261 instance->transport_buffer + instance->buffer_size 262 - remain_size; 263 264 toggle = 1 - toggle; 265 266 const size_t packet_size = 267 (instance->max_packet_size > remain_size) ? 268 remain_size : instance->max_packet_size; 269 270 transfer_descriptor_init(&instance->tds[packet], 271 DEFAULT_ERROR_COUNT, packet_size, toggle, false, low_speed, 272 instance->target, data_stage, data, 273 &instance->tds[packet + 1]); 274 275 ++packet; 276 assert(packet < instance->packets); 277 assert(packet_size <= remain_size); 278 remain_size -= packet_size; 279 } 280 281 /* status stage */ 282 assert(packet == instance->packets - 1); 283 transfer_descriptor_init(&instance->tds[packet], DEFAULT_ERROR_COUNT, 284 0, 1, false, low_speed, instance->target, status_stage, NULL, NULL); 285 286 287 instance->tds[packet].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 288 usb_log_debug2("Control last TD status: %x.\n", 289 instance->tds[packet].status); 290 } 291 /*----------------------------------------------------------------------------*/ 282 292 void batch_call_in(batch_t *instance) 283 293 { … … 288 298 289 299 int err = instance->error; 290 usb_log_info("Callback IN(%d): %d, %zu.\n", instance->transfer_type, 291 err, instance->transfered_size); 300 usb_log_debug("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n", 301 instance, instance->transfer_type, str_error(err), err, 302 instance->transfered_size); 292 303 293 304 instance->callback_in(instance->fun, … … 302 313 303 314 int err = instance->error; 304 usb_log_info("Callback OUT(%d): %d.\n", instance->transfer_type, err); 315 usb_log_debug("Batch(%p) callback OUT(type:%d): %s(%d).\n", 316 instance, instance->transfer_type, str_error(err), err); 305 317 instance->callback_out(instance->fun, 306 318 err, instance->arg); … … 311 323 assert(instance); 312 324 batch_call_in(instance); 313 usb_log_debug(" Disposing batch: %p.\n", instance);325 usb_log_debug("Batch(%p) disposing.\n", instance); 314 326 free32(instance->tds); 315 327 free32(instance->qh); … … 323 335 assert(instance); 324 336 batch_call_out(instance); 325 usb_log_debug(" Disposing batch: %p.\n", instance);337 usb_log_debug("Batch(%p) disposing.\n", instance); 326 338 free32(instance->tds); 327 339 free32(instance->qh); … … 338 350 return uhci_schedule(hc, instance); 339 351 } 340 /*----------------------------------------------------------------------------*/341 /* DEPRECATED FUNCTIONS NEEDED BY THE OLD API */342 void batch_control_setup_old(batch_t *instance)343 {344 assert(instance);345 instance->packets = 1;346 347 /* setup stage */348 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,349 instance->setup_size, 0, false, instance->target,350 USB_PID_SETUP, instance->setup_buffer, NULL);351 352 instance->next_step = batch_call_out_and_dispose;353 batch_schedule(instance);354 }355 /*----------------------------------------------------------------------------*/356 void batch_control_write_data_old(batch_t *instance)357 {358 assert(instance);359 instance->packets -= 2;360 batch_interrupt_out(instance);361 }362 /*----------------------------------------------------------------------------*/363 void batch_control_read_data_old(batch_t *instance)364 {365 assert(instance);366 instance->packets -= 2;367 batch_interrupt_in(instance);368 }369 /*----------------------------------------------------------------------------*/370 void batch_control_write_status_old(batch_t *instance)371 {372 assert(instance);373 instance->packets = 1;374 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,375 0, 1, false, instance->target, USB_PID_IN, NULL, NULL);376 instance->next_step = batch_call_in_and_dispose;377 batch_schedule(instance);378 }379 /*----------------------------------------------------------------------------*/380 void batch_control_read_status_old(batch_t *instance)381 {382 assert(instance);383 instance->packets = 1;384 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,385 0, 1, false, instance->target, USB_PID_OUT, NULL, NULL);386 instance->next_step = batch_call_out_and_dispose;387 batch_schedule(instance);388 }389 352 /** 390 353 * @}
Note:
See TracChangeset
for help on using the changeset viewer.