Changeset 7fc092a in mainline for uspace/drv
- Timestamp:
- 2011-01-27T22:09:29Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- db7ed07
- Parents:
- 9ee87f6 (diff), 6265a2b (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. - Location:
- uspace/drv
- Files:
-
- 3 added
- 28 edited
- 1 moved
-
ns8250/ns8250.c (modified) (1 diff)
-
usbhub/main.c (modified) (4 diffs)
-
usbhub/port_status.h (modified) (2 diffs)
-
usbhub/usbhub.c (modified) (35 diffs)
-
usbhub/usbhub.h (modified) (1 diff)
-
usbhub/usbhub_private.h (modified) (6 diffs)
-
usbhub/usblist.c (modified) (1 diff)
-
usbhub/usblist.h (modified) (3 diffs)
-
usbhub/utils.c (modified) (1 diff)
-
usbkbd/Makefile (modified) (1 diff)
-
usbkbd/descdump.c (added)
-
usbkbd/descdump.h (added)
-
usbkbd/descparser.c (added)
-
usbkbd/descparser.h (moved) (moved from uspace/srv/net/il/ip/ip_module.h ) (2 diffs)
-
usbkbd/main.c (modified) (10 diffs)
-
vhc/conn.h (modified) (2 diffs)
-
vhc/conndev.c (modified) (4 diffs)
-
vhc/connhost.c (modified) (1 diff)
-
vhc/debug.c (modified) (1 diff)
-
vhc/devices.c (modified) (8 diffs)
-
vhc/devices.h (modified) (2 diffs)
-
vhc/hc.c (modified) (3 diffs)
-
vhc/hc.h (modified) (2 diffs)
-
vhc/hcd.c (modified) (3 diffs)
-
vhc/hub.c (modified) (1 diff)
-
vhc/hub.h (modified) (1 diff)
-
vhc/hub/hub.c (modified) (3 diffs)
-
vhc/hub/hub.h (modified) (2 diffs)
-
vhc/hub/virthub.c (modified) (2 diffs)
-
vhc/hub/virthub.h (modified) (1 diff)
-
vhc/hub/virthubops.c (modified) (1 diff)
-
vhc/vhcd.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ns8250/ns8250.c
r9ee87f6 r7fc092a 431 431 { 432 432 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data; 433 int res;434 435 /* Enable interrupt globally. */436 res = interrupt_enable(data->irq);437 if (res != EOK)438 return res;439 433 440 434 /* Enable interrupt on the serial port. */ -
uspace/drv/usbhub/main.c
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup drvusbhub 30 * @{ 31 */ 32 29 33 #include <driver.h> 30 34 #include <errno.h> … … 52 56 while(true){ 53 57 usb_hub_check_hub_changes(); 54 async_usleep(1000 * 1000 );58 async_usleep(1000 * 1000 );/// \TODO proper number once 55 59 } 56 60 return 0; … … 60 64 int main(int argc, char *argv[]) 61 65 { 62 usb_dprintf_enable(NAME,1); 66 usb_dprintf_enable(NAME, 0); 67 63 68 futex_initialize(&usb_hub_list_lock, 0); 64 69 usb_lst_init(&usb_hub_list); 65 70 futex_up(&usb_hub_list_lock); 71 66 72 fid_t fid = fibril_create(usb_hub_control_loop, NULL); 67 73 if (fid == 0) { 68 dprintf(1, "failed to start fibril for HUB devices");69 //printf("%s: failed to start fibril for HUB devices\n", NAME);74 fprintf(stderr, NAME ": failed to start monitoring fibril," \ 75 " driver aborting.\n"); 70 76 return ENOMEM; 71 77 } … … 74 80 return driver_main(&hub_driver); 75 81 } 82 83 /** 84 * @} 85 */ 86 -
uspace/drv/usbhub/port_status.h
r9ee87f6 r7fc092a 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 /** @addtogroup drvusbhub 29 * @{ 30 */ 28 31 29 32 #ifndef PORT_STATUS_H … … 302 305 #endif /* PORT_STATUS_H */ 303 306 307 /** 308 * @} 309 */ -
uspace/drv/usbhub/usbhub.c
r9ee87f6 r7fc092a 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 /** @addtogroup usb hub driver28 /** @addtogroup drvusbhub 29 29 * @{ 30 30 */ … … 46 46 #include "usbhub_private.h" 47 47 #include "port_status.h" 48 #include "usb/usb.h" 48 49 49 50 static usb_iface_t hub_usb_iface = { … … 75 76 //get some hub info 76 77 usb_address_t addr = usb_drv_get_my_address(hc, device); 77 dprintf(1, "[usb_hub]address of newly created hub = %d", addr);78 dprintf(1, "address of newly created hub = %d", addr); 78 79 /*if(addr<0){ 79 80 //return result; … … 85 86 86 87 // get hub descriptor 87 usb_target_t target;88 target.address = addr;89 target.endpoint = 0;90 usb_device_request_setup_packet_t request;91 //printf("[usb_hub] creating descriptor request\n");92 usb_hub_set_descriptor_request(&request);93 88 94 89 //printf("[usb_hub] creating serialized descriptor\n"); … … 98 93 int opResult; 99 94 //printf("[usb_hub] starting control transaction\n"); 100 opResult = usb_drv_sync_control_read( 101 hc, target, &request, serialized_descriptor, 95 96 opResult = usb_drv_req_get_descriptor(hc, addr, 97 USB_REQUEST_TYPE_CLASS, 98 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 102 99 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 103 if (opResult != EOK) { 104 dprintf(1,"[usb_hub] failed when receiving hub descriptor, badcode = %d",opResult); 100 101 if (opResult != EOK) { 102 dprintf(1, "failed when receiving hub descriptor, badcode = %d",opResult); 105 103 free(serialized_descriptor); 106 104 return result; … … 109 107 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor); 110 108 if(descriptor==NULL){ 111 dprintf(1, "[usb_hub]could not deserialize descriptor ");109 dprintf(1, "could not deserialize descriptor "); 112 110 result->port_count = 1;///\TODO this code is only for debug!!! 113 111 return result; … … 129 127 //finish 130 128 131 dprintf(1, "[usb_hub]hub info created");129 dprintf(1, "hub info created"); 132 130 133 131 return result; … … 136 134 int usb_add_hub_device(device_t *dev) { 137 135 dprintf(1, "add_hub_device(handle=%d)", (int) dev->handle); 138 dprintf(1, "[usb_hub]hub device");136 dprintf(1, "hub device"); 139 137 140 138 /* … … 155 153 int port; 156 154 int opResult; 157 usb_device_request_setup_packet_t request;158 155 usb_target_t target; 159 156 target.address = hub_info->usb_device->address; … … 165 162 usb_standard_device_descriptor_t std_descriptor; 166 163 opResult = usb_drv_req_get_device_descriptor(hc, target.address, 167 &std_descriptor);164 &std_descriptor); 168 165 if(opResult!=EOK){ 169 dprintf(1, "[usb_hub]could not get device descriptor, %d",opResult);166 dprintf(1, "could not get device descriptor, %d",opResult); 170 167 return opResult; 171 168 } 172 dprintf(1, "[usb_hub]hub has %d configurations",std_descriptor.configuration_count);169 dprintf(1, "hub has %d configurations",std_descriptor.configuration_count); 173 170 if(std_descriptor.configuration_count<1){ 174 dprintf(1,"[usb_hub] THERE ARE NO CONFIGURATIONS AVAILABLE"); 171 dprintf(1, "THERE ARE NO CONFIGURATIONS AVAILABLE"); 172 //shouldn`t I return? 175 173 } 176 174 /// \TODO check other configurations … … 180 178 &config_descriptor); 181 179 if(opResult!=EOK){ 182 dprintf(1, "[usb_hub]could not get configuration descriptor, %d",opResult);180 dprintf(1, "could not get configuration descriptor, %d",opResult); 183 181 return opResult; 184 182 } 185 183 //set configuration 186 request.request_type = 0; 187 request.request = USB_DEVREQ_SET_CONFIGURATION; 188 request.index=0; 189 request.length=0; 190 request.value_high=0; 191 request.value_low = config_descriptor.configuration_number; 192 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 193 if (opResult != EOK) { 194 dprintf(1,"[usb_hub]something went wrong when setting hub`s configuration, %d", opResult); 195 } 196 184 opResult = usb_drv_req_set_configuration(hc, target.address, 185 config_descriptor.configuration_number); 186 187 if (opResult != EOK) { 188 dprintf(1, "something went wrong when setting hub`s configuration, %d", opResult); 189 } 190 191 usb_device_request_setup_packet_t request; 197 192 for (port = 1; port < hub_info->port_count+1; ++port) { 198 193 usb_hub_set_power_port_request(&request, port); 199 194 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 200 dprintf(1, "[usb_hub]powering port %d",port);195 dprintf(1, "powering port %d",port); 201 196 if (opResult != EOK) { 202 dprintf(1, "[usb_hub]something went wrong when setting hub`s %dth port", port);197 dprintf(1, "something went wrong when setting hub`s %dth port", port); 203 198 } 204 199 } … … 212 207 futex_up(&usb_hub_list_lock); 213 208 214 dprintf(1, "[usb_hub]hub info added to list");209 dprintf(1, "hub info added to list"); 215 210 //(void)hub_info; 216 211 usb_hub_check_hub_changes(); … … 218 213 219 214 220 dprintf(1, "[usb_hub]hub dev added");221 dprintf(1, "\taddress %d, has %d ports ",215 dprintf(1, "hub dev added"); 216 dprintf(1, "\taddress %d, has %d ports ", 222 217 hub_info->usb_device->address, 223 218 hub_info->port_count); 224 dprintf(1, "\tused configuration %d",config_descriptor.configuration_number);219 dprintf(1, "\tused configuration %d",config_descriptor.configuration_number); 225 220 226 221 return EOK; 227 222 //return ENOTSUP; 228 223 } 229 230 224 231 225 … … 237 231 238 232 /** 239 * convenience function for releasing default address and writing debug info240 * (these few lines are used too often to be written again and again) 233 * Convenience function for releasing default address and writing debug info 234 * (these few lines are used too often to be written again and again). 241 235 * @param hc 242 236 * @return … … 244 238 inline static int usb_hub_release_default_address(int hc){ 245 239 int opResult; 246 dprintf(1, "[usb_hub]releasing default address");240 dprintf(1, "releasing default address"); 247 241 opResult = usb_drv_release_default_address(hc); 248 242 if (opResult != EOK) { 249 dprintf(1, "[usb_hub]failed to release default address");243 dprintf(1, "failed to release default address"); 250 244 } 251 245 return opResult; … … 253 247 254 248 /** 255 * reset the port with new device and reserve the default address249 * Reset the port with new device and reserve the default address. 256 250 * @param hc 257 251 * @param port … … 261 255 usb_device_request_setup_packet_t request; 262 256 int opResult; 263 dprintf(1, "[usb_hub]some connection changed");257 dprintf(1, "some connection changed"); 264 258 //get default address 265 259 opResult = usb_drv_reserve_default_address(hc); 266 260 if (opResult != EOK) { 267 dprintf(1, "[usb_hub]cannot assign default address, it is probably used");261 dprintf(1, "cannot assign default address, it is probably used"); 268 262 return; 269 263 } … … 276 270 ); 277 271 if (opResult != EOK) { 278 dprintf(1, "[usb_hub]something went wrong when reseting a port");272 dprintf(1, "something went wrong when reseting a port"); 279 273 usb_hub_release_default_address(hc); 280 274 } … … 282 276 283 277 /** 284 * finalize adding new device after port reset278 * Finalize adding new device after port reset 285 279 * @param hc 286 280 * @param port … … 291 285 292 286 int opResult; 293 dprintf(1, "[usb_hub]finalizing add device");287 dprintf(1, "finalizing add device"); 294 288 opResult = usb_hub_clear_port_feature(hc, target.address, 295 289 port, USB_HUB_FEATURE_C_PORT_RESET); 296 290 if (opResult != EOK) { 297 dprintf(1, "[usb_hub]failed to clear port reset feature");291 dprintf(1, "failed to clear port reset feature"); 298 292 usb_hub_release_default_address(hc); 299 293 return; … … 303 297 usb_address_t new_device_address = usb_drv_request_address(hc); 304 298 if (new_device_address < 0) { 305 dprintf(1, "[usb_hub]failed to get free USB address");299 dprintf(1, "failed to get free USB address"); 306 300 opResult = new_device_address; 307 301 usb_hub_release_default_address(hc); 308 302 return; 309 303 } 310 dprintf(1, "[usb_hub]setting new address");304 dprintf(1, "setting new address"); 311 305 opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 312 306 new_device_address); 313 307 314 308 if (opResult != EOK) { 315 dprintf(1, "[usb_hub]could not set address for new device");309 dprintf(1, "could not set address for new device"); 316 310 usb_hub_release_default_address(hc); 317 311 return; … … 328 322 new_device_address, &child_handle); 329 323 if (opResult != EOK) { 330 dprintf(1, "[usb_hub]could not start driver for new device");324 dprintf(1, "could not start driver for new device"); 331 325 return; 332 326 } … … 336 330 opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 337 331 if (opResult != EOK) { 338 dprintf(1, "[usb_hub]could not assign address of device in hcd");339 return; 340 } 341 dprintf(1, "[usb_hub]new device address %d, handle %zu",332 dprintf(1, "could not assign address of device in hcd"); 333 return; 334 } 335 dprintf(1, "new device address %d, handle %zu", 342 336 new_device_address, child_handle); 343 337 … … 345 339 346 340 /** 347 * unregister device address in hc341 * Unregister device address in hc 348 342 * @param hc 349 343 * @param port … … 355 349 int opResult; 356 350 357 /// \TODO remove device 351 /** \TODO remove device from device manager - not yet implemented in 352 * devide manager 353 */ 358 354 359 355 hub->attached_devs[port].devman_handle=0; … … 362 358 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 363 359 if(opResult != EOK) { 364 dprintf(1, 365 "[usb_hub] could not release address of removed device: %d" 366 ,opResult); 360 dprintf(1, "could not release address of " \ 361 "removed device: %d", opResult); 367 362 } 368 363 hub->attached_devs[port].address = 0; 369 364 }else{ 370 dprintf(1, 371 "[usb_hub] this is strange, disconnected device had no address"); 365 dprintf(1, "this is strange, disconnected device had no address"); 372 366 //device was disconnected before it`s port was reset - return default address 373 367 usb_drv_release_default_address(hc); … … 376 370 377 371 /** 378 * process interrupts on given hub port372 * Process interrupts on given hub port 379 373 * @param hc 380 374 * @param port … … 383 377 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc, 384 378 uint16_t port, usb_address_t address) { 385 dprintf(1, "[usb_hub]interrupt at port %d", port);379 dprintf(1, "interrupt at port %d", port); 386 380 //determine type of change 387 381 usb_target_t target; … … 401 395 ); 402 396 if (opResult != EOK) { 403 dprintf(1, "[usb_hub]ERROR: could not get port status");397 dprintf(1, "ERROR: could not get port status"); 404 398 return; 405 399 } 406 400 if (rcvd_size != sizeof (usb_port_status_t)) { 407 dprintf(1, "[usb_hub]ERROR: received status has incorrect size");401 dprintf(1, "ERROR: received status has incorrect size"); 408 402 return; 409 403 } … … 414 408 // TODO: check opResult 415 409 if (usb_port_dev_connected(&status)) { 416 dprintf(1, "[usb_hub]some connection changed");410 dprintf(1, "some connection changed"); 417 411 usb_hub_init_add_device(hc, port, target); 418 412 } else { … … 422 416 //port reset 423 417 if (usb_port_reset_completed(&status)) { 424 dprintf(1, "[usb_hub]port reset complete");418 dprintf(1, "port reset complete"); 425 419 if (usb_port_enabled(&status)) { 426 420 usb_hub_finalize_add_device(hub, hc, port, target); 427 421 } else { 428 dprintf(1, "[usb_hub]ERROR: port reset, but port still not enabled");422 dprintf(1, "ERROR: port reset, but port still not enabled"); 429 423 } 430 424 } … … 434 428 usb_port_set_reset_completed(&status, false); 435 429 usb_port_set_dev_connected(&status, false); 436 if (status) { 437 dprintf(1,"[usb_hub]there was some unsupported change on port %d",port); 430 if (status>>16) { 431 dprintf(1, "there was some unsupported change on port %d: %X",port,status); 432 438 433 } 439 434 /// \TODO handle other changes … … 442 437 } 443 438 444 /* Check changes on all known hubs. 439 /** 440 * Check changes on all known hubs. 445 441 */ 446 442 void usb_hub_check_hub_changes(void) { … … 462 458 target.address = hub_info->usb_device->address; 463 459 target.endpoint = 1;/// \TODO get from endpoint descriptor 464 dprintf(1, "[usb_hub]checking changes for hub at addr %d",460 dprintf(1, "checking changes for hub at addr %d", 465 461 target.address); 466 462 … … 492 488 493 489 if (opResult != EOK) { 494 dprintf(1, "[usb_hub]something went wrong while getting status of hub");490 dprintf(1, "something went wrong while getting status of hub"); 495 491 continue; 496 492 } -
uspace/drv/usbhub/usbhub.h
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbhub 30 30 * @{ 31 31 */ -
uspace/drv/usbhub/usbhub_private.h
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbhub 30 30 * @{ 31 31 */ 32 32 /** @file 33 * @brief Hub driver .33 * @brief Hub driver private definitions 34 34 */ 35 35 … … 68 68 69 69 /** 70 * create hub structure instance70 * Create hub structure instance 71 71 * 72 72 * Set the address and port count information most importantly. … … 78 78 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc); 79 79 80 /** list of hubs maanged by this driver */80 /** List of hubs maanged by this driver */ 81 81 extern usb_general_list_t usb_hub_list; 82 82 83 /** lock for hub list*/83 /** Lock for hub list*/ 84 84 extern futex_t usb_hub_list_lock; 85 85 86 86 87 87 /** 88 * perform complete control read transaction88 * Perform complete control read transaction 89 89 * 90 * manages all three steps of transaction: setup, read and finalize90 * Manages all three steps of transaction: setup, read and finalize 91 91 * @param phone 92 92 * @param target 93 * @param request request for data94 * @param rcvd_buffer received data93 * @param request Request packet 94 * @param rcvd_buffer Received data 95 95 * @param rcvd_size 96 * @param actual_size actual size of received data96 * @param actual_size Actual size of received data 97 97 * @return error code 98 98 */ … … 104 104 105 105 /** 106 * perform complete control write transaction106 * Perform complete control write transaction 107 107 * 108 * manages all three steps of transaction: setup, write and finalize108 * Manages all three steps of transaction: setup, write and finalize 109 109 * @param phone 110 110 * @param target 111 * @param request request to send data111 * @param request Request packet to send data 112 112 * @param sent_buffer 113 113 * @param sent_size … … 121 121 122 122 /** 123 * set the device request to be a get hub descriptor request.123 * Set the device request to be a get hub descriptor request. 124 124 * @warning the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE 125 125 * @param request … … 137 137 } 138 138 139 /** 140 * Clear feature on hub port. 141 * 142 * @param hc Host controller telephone 143 * @param address Hub address 144 * @param port_index Port 145 * @param feature Feature selector 146 * @return Operation result 147 */ 139 148 static inline int usb_hub_clear_port_feature(int hc, usb_address_t address, 140 149 int port_index, -
uspace/drv/usbhub/usblist.c
r9ee87f6 r7fc092a 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 /** @addtogroup usb hub driver28 /** @addtogroup drvusbhub 29 29 * @{ 30 30 */ -
uspace/drv/usbhub/usblist.h
r9ee87f6 r7fc092a 27 27 */ 28 28 29 30 #ifndef USBLIST_H 31 #define USBLIST_H 32 /** @addtogroup usb hub driver 29 /** @addtogroup drvusbhub 33 30 * @{ 34 31 */ … … 40 37 * much simpler and more straight-forward semantics. 41 38 */ 39 #ifndef USBLIST_H 40 #define USBLIST_H 42 41 43 42 /** … … 78 77 } 79 78 80 79 #endif /* USBLIST_H */ 81 80 /** 82 81 * @} 83 82 */ 84 85 86 87 #endif /* USBLIST_H */88 -
uspace/drv/usbhub/utils.c
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup libusb usb29 /** @addtogroup drvusbhub 30 30 * @{ 31 31 */ -
uspace/drv/usbkbd/Makefile
r9ee87f6 r7fc092a 33 33 34 34 SOURCES = \ 35 main.c 35 main.c \ 36 descparser.c \ 37 descdump.c 36 38 37 39 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/usbkbd/descparser.h
r9ee87f6 r7fc092a 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2010 Lubos Slovak 3 3 * All rights reserved. 4 4 * … … 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 29 /** @addtogroup ip 28 /** @addtogroup drvusbhid 30 29 * @{ 31 30 */ 32 31 33 /** @file 34 * IP module functions. 35 * The functions are used as IP module entry points. 36 */ 32 #ifndef USBHID_DESCPARSER_H_ 33 #define USBHID_DESCPARSER_H_ 37 34 38 #ifndef NET_IP_MODULE_H_ 39 #define NET_IP_MODULE_H_ 35 #include <usb/classes/hid.h> 40 36 41 #include <ipc/ipc.h> 37 int usbkbd_parse_descriptors(const uint8_t *data, size_t size, 38 usb_hid_configuration_t *config); 42 39 43 extern int ip_initialize(async_client_conn_t); 44 extern int ip_message_standalone(ipc_callid_t, ipc_call_t *, ipc_call_t *, 45 size_t *); 40 void usbkbd_print_config(const usb_hid_configuration_t *config); 46 41 47 42 #endif 48 43 49 /** @} 44 /** 45 * @} 50 46 */ -
uspace/drv/usbkbd/main.c
r9ee87f6 r7fc092a 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 /** @addtogroup drvusbhid 29 * @{ 30 */ 28 31 #include <usb/usbdrv.h> 29 32 #include <driver.h> … … 38 41 #include <usb/devreq.h> 39 42 #include <usb/descriptor.h> 43 #include "descparser.h" 44 #include "descdump.h" 40 45 41 46 #define BUFFER_SIZE 32 … … 88 93 * Callbacks for parser 89 94 */ 90 static void usbkbd_process_keycodes(const uint16_t *key_codes, size_t count, 91 void *arg) 92 { 93 95 static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count, 96 uint8_t modifiers, void *arg) 97 { 98 printf("Got keys: "); 99 unsigned i; 100 for (i = 0; i < count; ++i) { 101 printf("%d ", key_codes[i]); 102 } 103 printf("\n"); 94 104 } 95 105 … … 97 107 * Kbd functions 98 108 */ 99 static int usbkbd_parse_descriptors(usb_hid_dev_kbd_t *kbd_dev, 100 const uint8_t *data, size_t size) 101 { 102 // const uint8_t *pos = data; 103 104 // // get the configuration descriptor (should be first) 105 // if (*pos != sizeof(usb_standard_configuration_descriptor_t) 106 // || *(pos + 1) != USB_DESCTYPE_CONFIGURATION) { 107 // fprintf(stderr, "Wrong format of configuration descriptor"); 108 // return EINVAL; 109 // } 110 111 // usb_standard_configuration_descriptor_t config_descriptor; 112 // memcpy(&config_descriptor, pos, 113 // sizeof(usb_standard_configuration_descriptor_t)); 114 // pos += sizeof(usb_standard_configuration_descriptor_t); 115 116 // // parse other descriptors 117 // while (pos - data < size) { 118 // //uint8_t desc_size = *pos; 119 // uint8_t desc_type = *(pos + 1); 120 // switch (desc_type) { 121 // case USB_DESCTYPE_INTERFACE: 122 // break; 123 // case USB_DESCTYPE_ENDPOINT: 124 // break; 125 // case USB_DESCTYPE_HID: 126 // break; 127 // case USB_DESCTYPE_HID_REPORT: 128 // break; 129 // case USB_DESCTYPE_HID_PHYSICAL: 130 // break; 131 // } 132 // } 133 109 static int usbkbd_get_report_descriptor(usb_hid_dev_kbd_t *kbd_dev) 110 { 111 // iterate over all configurations and interfaces 112 // TODO: more configurations!! 113 unsigned i; 114 for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) { 115 // TODO: endianness 116 uint16_t length = 117 kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length; 118 size_t actual_size = 0; 119 120 // allocate space for the report descriptor 121 kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length); 122 123 // get the descriptor from the device 124 int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone, 125 kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT, 126 0, i, kbd_dev->conf->interfaces[i].report_desc, length, 127 &actual_size); 128 129 if (rc != EOK) { 130 return rc; 131 } 132 133 assert(actual_size == length); 134 135 //dump_hid_class_descriptor(0, USB_DESCTYPE_HID_REPORT, 136 // kbd_dev->conf->interfaces[i].report_desc, length); 137 } 138 134 139 return EOK; 135 140 } 136 141 137 static int usbkbd_ get_descriptors(usb_hid_dev_kbd_t *kbd_dev)138 { 139 // get the first configuration descriptor (TODO: or some other??)142 static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev) 143 { 144 // get the first configuration descriptor (TODO: parse also other!) 140 145 usb_standard_configuration_descriptor_t config_desc; 141 146 … … 166 171 } 167 172 168 rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred); 173 kbd_dev->conf = (usb_hid_configuration_t *)calloc(1, 174 sizeof(usb_hid_configuration_t)); 175 if (kbd_dev->conf == NULL) { 176 free(descriptors); 177 return ENOMEM; 178 } 179 180 rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf); 169 181 free(descriptors); 170 171 return rc; 182 if (rc != EOK) { 183 printf("Problem with parsing standard descriptors.\n"); 184 return rc; 185 } 186 187 // get and report descriptors 188 rc = usbkbd_get_report_descriptor(kbd_dev); 189 if (rc != EOK) { 190 printf("Problem with parsing HID REPORT descriptor.\n"); 191 return rc; 192 } 193 194 //usbkbd_print_config(kbd_dev->conf); 195 196 /* 197 * TODO: 198 * 1) select one configuration (lets say the first) 199 * 2) how many interfaces?? how to select one?? 200 * ("The default setting for an interface is always alternate setting zero.") 201 * 3) find endpoint which is IN and INTERRUPT (parse), save its number 202 * as the endpoint for polling 203 */ 204 205 return EOK; 172 206 } 173 207 174 208 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev) 175 209 { 176 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *) malloc(177 sizeof(usb_hid_dev_kbd_t));210 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1, 211 sizeof(usb_hid_dev_kbd_t)); 178 212 179 213 if (kbd_dev == NULL) { … … 186 220 // get phone to my HC and save it as my parent's phone 187 221 // TODO: maybe not a good idea if DDF will use parent_phone 188 kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0); 189 190 kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, 191 dev); 222 int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0); 223 if (rc < 0) { 224 printf("Problem setting phone to HC.\n"); 225 free(kbd_dev); 226 return NULL; 227 } 228 229 rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev); 230 if (rc < 0) { 231 printf("Problem getting address of the device.\n"); 232 free(kbd_dev); 233 return NULL; 234 } 192 235 193 236 // doesn't matter now that we have no address … … 208 251 */ 209 252 210 // TODO: get descriptors 211 usbkbd_get_descriptors(kbd_dev); 212 // TODO: parse descriptors and save endpoints 253 // TODO: get descriptors, parse descriptors and save endpoints 254 usbkbd_process_descriptors(kbd_dev); 213 255 214 256 return kbd_dev; … … 218 260 uint8_t *buffer, size_t actual_size) 219 261 { 220 /*221 * here, the parser will be called, probably with some callbacks222 * now only take last 6 bytes and process, i.e. send to kbd223 */224 225 262 usb_hid_report_in_callbacks_t *callbacks = 226 263 (usb_hid_report_in_callbacks_t *)malloc( … … 228 265 callbacks->keyboard = usbkbd_process_keycodes; 229 266 230 usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 231 NULL); 267 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 268 // NULL); 269 printf("Calling usb_hid_boot_keyboard_input_report()...\n)"); 270 usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL); 232 271 } 233 272 234 273 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 235 274 { 275 return; 276 236 277 int rc; 237 278 usb_handle_t handle; … … 356 397 return driver_main(&kbd_driver); 357 398 } 399 400 /** 401 * @} 402 */ -
uspace/drv/vhc/conn.h
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ … … 51 51 52 52 void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *); 53 void on_client_close(device_t *); 53 54 54 55 -
uspace/drv/vhc/conndev.c
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ … … 88 88 int callback = IPC_GET_ARG5(*icall); 89 89 virtdev_connection_t *dev 90 = virtdev_add_device(callback );90 = virtdev_add_device(callback, (sysarg_t)fibril_get_id()); 91 91 if (!dev) { 92 92 ipc_answer_0(icallid, EEXISTS); … … 99 99 int rc = get_device_name(callback, devname, DEVICE_NAME_MAXLENGTH); 100 100 101 dprintf(0, "virtual device connected (name: %s)", 102 rc == EOK ? devname : "<unknown>"); 103 104 /* FIXME: destroy the device when the client disconnects. */ 101 dprintf(0, "virtual device connected (name: %s, id: %x)", 102 rc == EOK ? devname : "<unknown>", dev->id); 105 103 106 104 return; … … 110 108 } 111 109 110 /** Callback for DDF when client disconnects. 111 * 112 * @param d Device the client was connected to. 113 */ 114 void on_client_close(device_t *d) 115 { 116 /* 117 * Maybe a virtual device is being unplugged. 118 */ 119 virtdev_connection_t *dev = virtdev_find((sysarg_t)fibril_get_id()); 120 if (dev == NULL) { 121 return; 122 } 123 124 dprintf(0, "virtual device disconnected (id: %x)", dev->id); 125 virtdev_destroy_device(dev); 126 } 127 112 128 113 129 /** -
uspace/drv/vhc/connhost.c
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ -
uspace/drv/vhc/debug.c
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ -
uspace/drv/vhc/devices.c
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ … … 58 58 /** Create virtual device. 59 59 * 60 * @param address USB address.61 60 * @param phone Callback phone. 61 * @param id Device id. 62 62 * @return New device. 63 * @retval NULL Out of memory or address already occupied.64 */ 65 virtdev_connection_t *virtdev_add_device(int phone )63 * @retval NULL Out of memory. 64 */ 65 virtdev_connection_t *virtdev_add_device(int phone, sysarg_t id) 66 66 { 67 67 virtdev_connection_t *dev = (virtdev_connection_t *) 68 68 malloc(sizeof(virtdev_connection_t)); 69 if (dev == NULL) { 70 return NULL; 71 } 72 69 73 dev->phone = phone; 74 dev->id = id; 70 75 list_append(&dev->link, &devices); 71 76 … … 73 78 74 79 return dev; 80 } 81 82 /** Find virtual device by id. 83 * 84 * @param id Device id. 85 * @return Device with given id. 86 * @retval NULL No such device. 87 */ 88 virtdev_connection_t *virtdev_find(sysarg_t id) 89 { 90 link_t *pos; 91 list_foreach(pos, &devices) { 92 virtdev_connection_t *dev 93 = list_get_instance(pos, virtdev_connection_t, link); 94 if (dev->id == id) { 95 return dev; 96 } 97 } 98 99 return NULL; 75 100 } 76 101 … … 90 115 usb_transaction_outcome_t virtdev_send_to_all(transaction_t *transaction) 91 116 { 117 /* For easier debugging. */ 118 switch (transaction->type) { 119 case USBVIRT_TRANSACTION_SETUP: 120 case USBVIRT_TRANSACTION_OUT: 121 transaction->actual_len = transaction->len; 122 break; 123 case USBVIRT_TRANSACTION_IN: 124 transaction->actual_len = 0; 125 break; 126 default: 127 assert(false && "unreachable branch in switch()"); 128 } 129 usb_transaction_outcome_t outcome = USB_OUTCOME_BABBLE; 130 92 131 link_t *pos; 93 132 list_foreach(pos, &devices) { … … 138 177 } else { 139 178 async_wait_for(req, &answer_rc); 179 transaction->actual_len = IPC_GET_ARG1(answer_data); 140 180 rc = (int)answer_rc; 181 } 182 183 /* 184 * If at least one device was able to accept this 185 * transaction and process it, we can announce success. 186 */ 187 if (rc == EOK) { 188 outcome = USB_OUTCOME_OK; 141 189 } 142 190 } … … 164 212 transaction->buffer, transaction->len, 165 213 &tmp); 166 if (tmp < transaction->len) { 167 transaction->len = tmp; 168 } 214 transaction->actual_len = tmp; 169 215 break; 170 216 … … 177 223 } 178 224 dprintf(4, "transaction on hub processed..."); 225 outcome = USB_OUTCOME_OK; 179 226 } 180 227 … … 183 230 * real-life image. 184 231 */ 185 return USB_OUTCOME_OK;232 return outcome; 186 233 } 187 234 -
uspace/drv/vhc/devices.h
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ … … 45 45 /** Phone used when sending data to device. */ 46 46 int phone; 47 /** Unique identification. */ 48 sysarg_t id; 47 49 /** Linked-list handle. */ 48 50 link_t link; 49 51 } virtdev_connection_t; 50 52 51 virtdev_connection_t *virtdev_add_device(int );52 virtdev_connection_t *virtdev_ get_mine(void);53 virtdev_connection_t *virtdev_add_device(int, sysarg_t); 54 virtdev_connection_t *virtdev_find(sysarg_t); 53 55 void virtdev_destroy_device(virtdev_connection_t *); 54 56 usb_transaction_outcome_t virtdev_send_to_all(transaction_t *); -
uspace/drv/vhc/hc.c
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ … … 96 96 usb_str_transaction_outcome(outcome)); 97 97 98 transaction->callback(transaction->buffer, transaction-> len, outcome,99 transaction->callback_arg);98 transaction->callback(transaction->buffer, transaction->actual_len, 99 outcome, transaction->callback_arg); 100 100 } 101 101 … … 169 169 transaction->buffer = buffer; 170 170 transaction->len = len; 171 transaction->actual_len = len; 171 172 transaction->callback = callback; 172 173 transaction->callback_arg = arg; -
uspace/drv/vhc/hc.h
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ … … 65 65 /** Transaction data length. */ 66 66 size_t len; 67 /** Data length actually transfered. */ 68 size_t actual_len; 67 69 /** Callback after transaction is done. */ 68 70 hc_transaction_done_callback_t callback; -
uspace/drv/vhc/hcd.c
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ … … 69 69 .interfaces[USBHC_DEV_IFACE] = &vhc_iface, 70 70 .interfaces[USB_DEV_IFACE] = &hc_usb_iface, 71 .close = on_client_close, 71 72 .default_handler = default_connection_handler 72 73 }; … … 116 117 sleep(5); 117 118 118 usb_dprintf_enable(NAME, 0);119 usb_dprintf_enable(NAME, -1); 119 120 120 121 printf(NAME ": virtual USB host controller driver.\n"); -
uspace/drv/vhc/hub.c
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ -
uspace/drv/vhc/hub.h
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ -
uspace/drv/vhc/hub/hub.c
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ … … 155 155 } 156 156 157 /** Disconnects a device from a hub. 158 * 159 * @param hub Hub the device was connected to. 160 * @param device Device to be disconnected. 161 * @return Error code. 162 */ 163 int hub_disconnect_device(hub_t *hub, void *device) 164 { 165 size_t index = hub_find_device(hub, device); 166 if (index == (size_t) -1) { 167 return ENOENT; 168 } 169 170 hub_port_t *port = &hub->ports[index]; 171 172 port->connected_device = NULL; 173 port->state = HUB_PORT_STATE_DISCONNECTED; 174 set_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION); 175 176 return EOK; 177 } 178 157 179 /** Find port device is connected to. 158 180 * … … 173 195 } 174 196 175 return 0;197 return -1; 176 198 } 177 199 -
uspace/drv/vhc/hub/hub.h
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ … … 94 94 void hub_init(hub_t *); 95 95 size_t hub_connect_device(hub_t *, void *); 96 int hub_disconnect_device(hub_t *, void *); 96 97 size_t hub_find_device(hub_t *, void *); 97 98 void hub_acquire(hub_t *); -
uspace/drv/vhc/hub/virthub.c
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ … … 203 203 204 204 hub_acquire(hub); 205 /* TODO: implement. */205 hub_disconnect_device(hub, conn); 206 206 hub_release(hub); 207 207 -
uspace/drv/vhc/hub/virthub.h
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ -
uspace/drv/vhc/hub/virthubops.c
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ -
uspace/drv/vhc/vhcd.h
r9ee87f6 r7fc092a 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */
Note:
See TracChangeset
for help on using the changeset viewer.
