Changes in / [37f7cfe:682b697] in mainline
- Location:
- uspace
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/virtusbkbd/virtusbkbd.c
r37f7cfe r682b697 55 55 #include "stdreq.h" 56 56 57 /** Pause between individual key-presses in seconds. */ 58 #define KEY_PRESS_DELAY 2 57 #define LOOPS 5 59 58 #define NAME "virt-usb-kbd" 60 59 … … 84 83 } 85 84 86 /** Compares current and last status of pressed keys.87 *88 * @warning Has side-efect - changes status_last field.89 *90 * @param status_now Status now.91 * @param status_last Last status.92 * @param len Size of status.93 * @return Whether they are the same.94 */95 static bool keypress_check_with_last_request(uint8_t *status_now,96 uint8_t *status_last, size_t len)97 {98 bool same = true;99 size_t i;100 for (i = 0; i < len; i++) {101 if (status_now[i] != status_last[i]) {102 status_last[i] = status_now[i];103 same = false;104 }105 }106 return same;107 }108 109 85 static int on_request_for_data(struct usbvirt_device *dev, 110 86 usb_endpoint_t endpoint, void *buffer, size_t size, size_t *actual_size) 111 87 { 112 static uint8_t last_data[2 + KB_MAX_KEYS_AT_ONCE];113 114 88 if (size < 2 + KB_MAX_KEYS_AT_ONCE) { 115 89 return EINVAL; … … 127 101 } 128 102 129 if (keypress_check_with_last_request(data, last_data,130 2 + KB_MAX_KEYS_AT_ONCE)) {131 *actual_size = 0;132 return EOK;133 }134 135 103 memcpy(buffer, &data, *actual_size); 136 104 … … 184 152 .ops = &keyboard_ops, 185 153 .descriptors = &descriptors, 186 .lib_debug_level = 3,187 .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL,188 154 .name = "keyboard" 189 155 }; … … 211 177 printf("\n"); 212 178 213 fibril_sleep( KEY_PRESS_DELAY);179 fibril_sleep(1); 214 180 } 215 181 … … 257 223 258 224 printf("%s: Simulating keyboard events...\n", NAME); 259 while (1){225 while(1){ 260 226 kb_process_events(&status, keyboard_events, keyboard_events_count, 261 227 on_keyboard_change); -
uspace/drv/usbhub/main.c
r37f7cfe r682b697 50 50 while(true){ 51 51 usb_hub_check_hub_changes(); 52 async_usleep(1000 * 1000);52 async_usleep(10000000); 53 53 } 54 54 return 0; -
uspace/drv/usbhub/usbhub_private.h
r37f7cfe r682b697 182 182 } 183 183 184 static inline int usb_hub_clear_port_feature(int hc, usb_address_t address,185 int port_index,186 usb_hub_class_feature_t feature) {187 usb_target_t target = {188 .address = address,189 .endpoint = 0190 };191 usb_device_request_setup_packet_t clear_request = {192 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,193 .request = USB_DEVREQ_CLEAR_FEATURE,194 .length = 0,195 .index = port_index196 };197 clear_request.value = feature;198 return usb_drv_psync_control_write(hc, target, &clear_request,199 sizeof(clear_request), NULL, 0);200 }201 202 184 203 185 -
uspace/drv/usbhub/utils.c
r37f7cfe r682b697 506 506 int hc, uint16_t port, usb_target_t target) { 507 507 508 usb_device_request_setup_packet_t request; 508 509 int opResult; 509 510 printf("[usb_hub] finalizing add device\n"); 510 opResult = usb_hub_clear_port_feature(hc, target.address, 511 port, USB_HUB_FEATURE_C_PORT_RESET); 512 if (opResult != EOK) { 513 goto release; 514 } 515 516 /* Request address at from host controller. */ 517 usb_address_t new_device_address = usb_drv_request_address(hc); 518 if (new_device_address < 0) { 519 printf("[usb_hub] failed to get free USB address\n"); 520 opResult = new_device_address; 521 goto release; 522 } 523 printf("[usb_hub] setting new address\n"); 524 opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 525 new_device_address); 526 511 usb_address_t new_device_address = 512 usb_drv_request_address(hc); 513 usb_hub_set_set_address_request 514 (&request, new_device_address); 515 opResult = usb_drv_sync_control_write( 516 hc, target, 517 &request, 518 NULL, 0 519 ); 527 520 if (opResult != EOK) { 528 521 printf("[usb_hub] could not set address for new device\n"); 529 goto release; 530 } 531 532 release: 533 printf("[usb_hub] releasing default address\n"); 522 //will retry later... 523 return; 524 } 525 534 526 usb_drv_release_default_address(hc); 535 if (opResult != EOK) {536 return;537 }538 527 539 528 devman_handle_t child_handle; 540 529 opResult = usb_drv_register_child_in_devman(hc, hub->device, 541 530 new_device_address, &child_handle); 542 531 if (opResult != EOK) { 543 532 printf("[usb_hub] could not start driver for new device \n"); … … 554 543 printf("[usb_hub] new device address %d, handle %d\n", 555 544 new_device_address, child_handle); 545 sleep(60); 556 546 557 547 } … … 630 620 //something connected/disconnected 631 621 if (usb_port_connect_change(&status)) { 632 opResult = usb_hub_clear_port_feature(hc, target.address,633 port, USB_HUB_FEATURE_C_PORT_CONNECTION);634 // TODO: check opResult635 622 if (usb_port_dev_connected(&status)) { 636 623 printf("[usb_hub] some connection changed\n"); … … 642 629 //port reset 643 630 if (usb_port_reset_completed(&status)) { 644 printf("[usb_hub] port reset complete\n");631 printf("[usb_hub] finalizing add device\n"); 645 632 if (usb_port_enabled(&status)) { 646 633 usb_hub_finalize_add_device(hub, hc, port, target); … … 683 670 lst_item != &usb_hub_list; 684 671 lst_item = lst_item->next) { 672 printf("[usb_hub] checking hub changes\n"); 685 673 usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data); 686 674 /* … … 691 679 target.address = hub_info->usb_device->address; 692 680 target.endpoint = 1;/// \TODO get from endpoint descriptor 693 printf("[usb_hub] checking changes for hub at addr %d\n", 694 target.address); 681 printf("checking changes for hub at addr %d \n",target.address); 695 682 696 683 size_t port_count = hub_info->port_count; -
uspace/drv/usbkbd/main.c
r37f7cfe r682b697 39 39 #define NAME "usbkbd" 40 40 41 #define GUESSED_POLL_ENDPOINT 1 41 static const usb_endpoint_t CONTROL_EP = 0; 42 42 43 43 /* … … 155 155 156 156 // default endpoint 157 kbd_dev-> poll_endpoint = GUESSED_POLL_ENDPOINT;157 kbd_dev->default_ep = CONTROL_EP; 158 158 159 159 /* … … 204 204 usb_target_t poll_target = { 205 205 .address = kbd_dev->address, 206 .endpoint = kbd_dev-> poll_endpoint206 .endpoint = kbd_dev->default_ep 207 207 }; 208 208 209 209 while (true) { 210 async_usleep(1000 * 1000);211 210 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 212 211 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); -
uspace/drv/vhc/hc.c
r37f7cfe r682b697 50 50 #include "hub.h" 51 51 52 #define USLEEP_BASE (0 * 5 * 1000)52 #define USLEEP_BASE (0 * 500 * 1000) 53 53 54 #define USLEEP_VAR 50 54 #define USLEEP_VAR 5000 55 55 56 56 #define SHORTENING_VAR 15 … … 89 89 usb_transaction_outcome_t outcome) 90 90 { 91 dprintf(3, " transaction " TRANSACTION_FORMAT " done, outcome: %s",91 dprintf(3, "processing transaction " TRANSACTION_FORMAT ", outcome: %s", 92 92 TRANSACTION_PRINTF(*transaction), 93 93 usb_str_transaction_outcome(outcome)); … … 116 116 char ports[HUB_PORT_COUNT + 2]; 117 117 hub_get_port_statuses(ports, HUB_PORT_COUNT + 1); 118 dprintf( 4, "virtual hub: addr=%d ports=%s",118 dprintf(0, "virtual hub: addr=%d ports=%s", 119 119 virthub_dev.address, ports); 120 120 … … 124 124 list_remove(first_transaction_link); 125 125 126 127 dprintf(0, "about to process " TRANSACTION_FORMAT " (vhub:%s)",128 TRANSACTION_PRINTF(*transaction), ports);129 130 126 dprintf(3, "processing transaction " TRANSACTION_FORMAT "", 131 127 TRANSACTION_PRINTF(*transaction)); -
uspace/drv/vhc/hcd.c
r37f7cfe r682b697 110 110 printf("%s: virtual USB host controller driver.\n", NAME); 111 111 112 usb_dprintf_enable(NAME, 0);112 usb_dprintf_enable(NAME, 2); 113 113 114 114 fid_t fid = fibril_create(hc_manager_fibril, NULL); -
uspace/drv/vhc/hub.c
r37f7cfe r682b697 144 144 .ops = &hub_ops, 145 145 .descriptors = &descriptors, 146 .lib_debug_level = 0,146 .lib_debug_level = 1, 147 147 .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL 148 148 }; … … 181 181 hub_port_t *port = &hub_dev.ports[i]; 182 182 183 port->index = (int) i + 1;183 port->index = (int) i; 184 184 port->device = NULL; 185 185 port->state = HUB_PORT_STATE_NOT_CONFIGURED; 186 186 port->status_change = 0; 187 fibril_mutex_initialize(&port->guard);188 187 } 189 188 … … 226 225 for (i = 0; i < HUB_PORT_COUNT; i++) { 227 226 hub_port_t *port = &hub_dev.ports[i]; 228 fibril_mutex_lock(&port->guard);229 227 230 228 if (port->device != NULL) { 231 fibril_mutex_unlock(&port->guard);232 229 continue; 233 230 } … … 244 241 //if (port->state == HUB_PORT_STATE_DISCONNECTED) { 245 242 port->state = HUB_PORT_STATE_DISABLED; 246 set_port_status_change _nl(port, HUB_STATUS_C_PORT_CONNECTION);243 set_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION); 247 244 //} 248 245 249 fibril_mutex_unlock(&port->guard);250 251 246 return i; 252 247 } -
uspace/drv/vhc/hubintern.h
r37f7cfe r682b697 37 37 38 38 #include "hub.h" 39 #include <fibril_synch.h>40 39 41 40 /** Endpoint number for status change pipe. */ … … 125 124 hub_port_state_t state; 126 125 uint16_t status_change; 127 fibril_mutex_t guard;128 126 } hub_port_t; 129 127 … … 141 139 void clear_port_status_change(hub_port_t *, uint16_t); 142 140 void set_port_status_change(hub_port_t *, uint16_t); 143 void set_port_status_change_nl(hub_port_t *, uint16_t);144 141 145 142 -
uspace/drv/vhc/hubops.c
r37f7cfe r682b697 67 67 void *buffer, size_t size, size_t *actual_size); 68 68 static void set_port_state(hub_port_t *, hub_port_state_t); 69 static void clear_port_status_change_nl(hub_port_t *, uint16_t);70 static void set_port_state_nl(hub_port_t *, hub_port_state_t);71 69 72 70 /** Standard USB requests. */ … … 137 135 async_usleep(change->delay); 138 136 139 fibril_mutex_lock(&change->port->guard);140 137 if (change->port->state == change->old_state) { 141 set_port_state_nl(change->port, change->new_state); 142 } 143 fibril_mutex_unlock(&change->port->guard); 138 set_port_state(change->port, change->new_state); 139 } 144 140 145 141 free(change); … … 170 166 void set_port_state(hub_port_t *port, hub_port_state_t state) 171 167 { 172 fibril_mutex_lock(&port->guard); 173 set_port_state_nl(port, state); 174 fibril_mutex_unlock(&port->guard); 175 } 176 177 void set_port_state_nl(hub_port_t *port, hub_port_state_t state) 178 { 179 180 dprintf(2, "setting port %d state to %d (%c) from %c (change=%u)", 181 port->index, 182 state, hub_port_state_as_char(state), 183 hub_port_state_as_char(port->state), 184 (unsigned int) port->status_change); 168 dprintf(1, "setting port %d state to %d (%c)", port->index, 169 state, hub_port_state_as_char(state)); 185 170 186 171 if (state == HUB_PORT_STATE_POWERED_OFF) { 187 clear_port_status_change _nl(port, HUB_STATUS_C_PORT_CONNECTION);188 clear_port_status_change _nl(port, HUB_STATUS_C_PORT_ENABLE);189 clear_port_status_change _nl(port, HUB_STATUS_C_PORT_RESET);172 clear_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION); 173 clear_port_status_change(port, HUB_STATUS_C_PORT_ENABLE); 174 clear_port_status_change(port, HUB_STATUS_C_PORT_RESET); 190 175 } 191 176 if (state == HUB_PORT_STATE_RESUMING) { … … 199 184 if ((port->state == HUB_PORT_STATE_RESETTING) 200 185 && (state == HUB_PORT_STATE_ENABLED)) { 201 set_port_status_change _nl(port, HUB_STATUS_C_PORT_RESET);186 set_port_status_change(port, HUB_STATUS_C_PORT_RESET); 202 187 } 203 188 … … 227 212 _GET_PORT(port, portindex); 228 213 229 fibril_mutex_lock(&port->guard);230 int rc = ENOTSUP;231 232 214 switch (feature) { 233 215 case USB_HUB_FEATURE_PORT_ENABLE: 234 216 if ((port->state != HUB_PORT_STATE_NOT_CONFIGURED) 235 217 && (port->state != HUB_PORT_STATE_POWERED_OFF)) { 236 set_port_state_nl(port, HUB_PORT_STATE_DISABLED); 237 } 238 rc = EOK; 239 break; 218 set_port_state(port, HUB_PORT_STATE_DISABLED); 219 } 220 return EOK; 240 221 241 222 case USB_HUB_FEATURE_PORT_SUSPEND: 242 223 if (port->state != HUB_PORT_STATE_SUSPENDED) { 243 rc = EOK; 244 break; 245 } 246 set_port_state_nl(port, HUB_PORT_STATE_RESUMING); 247 rc = EOK; 248 break; 224 return EOK; 225 } 226 set_port_state(port, HUB_PORT_STATE_RESUMING); 227 return EOK; 249 228 250 229 case USB_HUB_FEATURE_PORT_POWER: 251 230 if (port->state != HUB_PORT_STATE_NOT_CONFIGURED) { 252 set_port_state_nl(port, HUB_PORT_STATE_POWERED_OFF); 253 } 254 rc = EOK; 255 break; 231 set_port_state(port, HUB_PORT_STATE_POWERED_OFF); 232 } 233 return EOK; 256 234 257 235 case USB_HUB_FEATURE_C_PORT_CONNECTION: 258 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION); 259 rc = EOK; 260 break; 236 clear_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION); 237 return EOK; 261 238 262 239 case USB_HUB_FEATURE_C_PORT_ENABLE: 263 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_ENABLE); 264 rc = EOK; 265 break; 240 clear_port_status_change(port, HUB_STATUS_C_PORT_ENABLE); 241 return EOK; 266 242 267 243 case USB_HUB_FEATURE_C_PORT_SUSPEND: 268 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_SUSPEND); 269 rc = EOK; 270 break; 244 clear_port_status_change(port, HUB_STATUS_C_PORT_SUSPEND); 245 return EOK; 271 246 272 247 case USB_HUB_FEATURE_C_PORT_OVER_CURRENT: 273 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_OVER_CURRENT); 274 rc = EOK; 275 break; 276 277 case USB_HUB_FEATURE_C_PORT_RESET: 278 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET); 279 rc = EOK; 280 break; 281 } 282 283 fibril_mutex_unlock(&port->guard); 284 285 return rc; 248 clear_port_status_change(port, HUB_STATUS_C_PORT_OVER_CURRENT); 249 return EOK; 250 } 251 252 return ENOTSUP; 286 253 } 287 254 … … 318 285 _GET_PORT(port, portindex); 319 286 320 fibril_mutex_lock(&port->guard);321 322 287 uint32_t status; 323 288 status = MAKE_BYTE( … … 347 312 status |= (port->status_change << 16); 348 313 349 fibril_mutex_unlock(&port->guard);350 351 314 dprintf(2, "GetPortStatus(port=%d, status=%u)\n", (int)portindex, 352 315 (unsigned int) status); … … 364 327 _GET_PORT(port, portindex); 365 328 366 fibril_mutex_lock(&port->guard);367 368 int rc = ENOTSUP;369 370 329 switch (feature) { 371 330 case USB_HUB_FEATURE_PORT_RESET: 372 331 if (port->state != HUB_PORT_STATE_POWERED_OFF) { 373 set_port_state_nl(port, HUB_PORT_STATE_RESETTING); 374 } 375 rc = EOK; 376 break; 332 set_port_state(port, HUB_PORT_STATE_RESETTING); 333 } 334 return EOK; 377 335 378 336 case USB_HUB_FEATURE_PORT_SUSPEND: 379 337 if (port->state == HUB_PORT_STATE_ENABLED) { 380 set_port_state_nl(port, HUB_PORT_STATE_SUSPENDED); 381 } 382 rc = EOK; 383 break; 338 set_port_state(port, HUB_PORT_STATE_SUSPENDED); 339 } 340 return EOK; 384 341 385 342 case USB_HUB_FEATURE_PORT_POWER: 386 343 if (port->state == HUB_PORT_STATE_POWERED_OFF) { 387 set_port_state_nl(port, HUB_PORT_STATE_DISCONNECTED); 388 } 389 rc = EOK; 390 break; 391 } 392 393 fibril_mutex_unlock(&port->guard); 394 return rc; 344 set_port_state(port, HUB_PORT_STATE_DISCONNECTED); 345 } 346 return EOK; 347 } 348 return ENOTSUP; 395 349 } 396 350 … … 462 416 } 463 417 464 void clear_port_status_change _nl(hub_port_t *port, uint16_t change)418 void clear_port_status_change(hub_port_t *port, uint16_t change) 465 419 { 466 420 port->status_change &= (~change); 467 dprintf(2, "cleared port %d status change %d (%u)", port->index, 468 (int)change, (unsigned int) port->status_change); 469 } 470 471 void set_port_status_change_nl(hub_port_t *port, uint16_t change) 421 } 422 423 void set_port_status_change(hub_port_t *port, uint16_t change) 472 424 { 473 425 port->status_change |= change; 474 dprintf(2, "set port %d status change %d (%u)", port->index,475 (int)change, (unsigned int) port->status_change);476 477 }478 479 void clear_port_status_change(hub_port_t *port, uint16_t change)480 {481 fibril_mutex_lock(&port->guard);482 clear_port_status_change_nl(port, change);483 fibril_mutex_unlock(&port->guard);484 }485 486 void set_port_status_change(hub_port_t *port, uint16_t change)487 {488 fibril_mutex_lock(&port->guard);489 set_port_status_change_nl(port, change);490 fibril_mutex_unlock(&port->guard);491 426 } 492 427 … … 506 441 hub_port_t *port = &hub_dev.ports[i]; 507 442 508 fibril_mutex_lock(&port->guard);509 443 if (port->status_change != 0) { 510 444 change_map |= (1 << (i + 1)); 511 445 } 512 fibril_mutex_unlock(&port->guard);513 446 } 514 447 -
uspace/lib/usb/include/usb/classes/hid.h
r37f7cfe r682b697 100 100 device_t *device; 101 101 usb_address_t address; 102 usb_endpoint_t poll_endpoint;102 usb_endpoint_t default_ep; 103 103 usb_hid_report_parser_t *parser; 104 104 } usb_hid_dev_kbd_t; -
uspace/lib/usbvirt/callback.c
r37f7cfe r682b697 155 155 * If the request was processed, we will send data back. 156 156 */ 157 if ( (rc == EOK) && (expected_len > 0)) {157 if (rc == EOK) { 158 158 size_t receive_len; 159 159 ipc_callid_t callid;
Note:
See TracChangeset
for help on using the changeset viewer.