Index: uspace/app/bdsh/cmds/modules/cat/cat.c
===================================================================
--- uspace/app/bdsh/cmds/modules/cat/cat.c	(revision 6610565b4f069eca9d1d17e21f317196b1a98756)
+++ uspace/app/bdsh/cmds/modules/cat/cat.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -144,14 +144,14 @@
 			return CMD_SUCCESS;
 		case 'H':
-			printf(cat_oops);
+			printf("%s", cat_oops);
 			return CMD_FAILURE;
 		case 't':
-			printf(cat_oops);
+			printf("%s", cat_oops);
 			return CMD_FAILURE;
 		case 'b':
-			printf(cat_oops);
+			printf("%s", cat_oops);
 			break;
 		case 'm':
-			printf(cat_oops);
+			printf("%s", cat_oops);
 			return CMD_FAILURE;
 		}
Index: uspace/app/bdsh/cmds/modules/rm/rm.c
===================================================================
--- uspace/app/bdsh/cmds/modules/rm/rm.c	(revision 6610565b4f069eca9d1d17e21f317196b1a98756)
+++ uspace/app/bdsh/cmds/modules/rm/rm.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -227,5 +227,5 @@
 		}
 		memset(buff, 0, sizeof(buff));
-		snprintf(buff, len, argv[i]);
+		snprintf(buff, len, "%s", argv[i]);
 
 		scope = rm_scope(buff);
Index: uspace/drv/rootvirt/devices.def
===================================================================
--- uspace/drv/rootvirt/devices.def	(revision 6610565b4f069eca9d1d17e21f317196b1a98756)
+++ uspace/drv/rootvirt/devices.def	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -23,6 +23,8 @@
 #endif
 /* Virtual USB host controller. */
+/*
 {
 	.name = "usbhc",
 	.match_id = "usb&hc=vhc"
 },
+*/
Index: uspace/drv/uhci/Makefile
===================================================================
--- uspace/drv/uhci/Makefile	(revision 6610565b4f069eca9d1d17e21f317196b1a98756)
+++ uspace/drv/uhci/Makefile	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -29,10 +29,17 @@
 USPACE_PREFIX = ../..
 LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
-EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include
+EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
 BINARY = uhci
 
 SOURCES = \
+	iface.c \
 	main.c \
-	transfers.c
+	root_hub/port.c \
+	root_hub/port_status.c \
+	root_hub/root_hub.c \
+	uhci.c \
+	utils/fibril_semaphore.c \
+	utils/hc_synchronizer.c \
+	utils/usb_device.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/drv/uhci/debug.h
===================================================================
--- uspace/drv/uhci/debug.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/debug.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_DEBUG_H
+#define DRV_UHCI_DEBUG_H
+
+#include <usb/debug.h>
+
+#include "name.h"
+
+enum debug_levels {
+	DEBUG_LEVEL_FATAL_ERROR = 1,
+	DEBUG_LEVEL_ERROR = 2,
+	DEBUG_LEVEL_WARNING = 3,
+	DEBUG_LEVEL_INFO = 4,
+	DEBUG_LEVEL_VERBOSE = 5,
+	DEBUG_LEVEL_MAX = DEBUG_LEVEL_VERBOSE
+};
+
+#define uhci_printf( level, fmt, args...) \
+	usb_dprintf( NAME, level, fmt, ##args )
+
+#define uhci_print_error( fmt, args... ) \
+	usb_dprintf( NAME, DEBUG_LEVEL_ERROR, fmt, ##args )
+
+#define uhci_print_info( fmt, args... ) \
+	usb_dprintf( NAME, DEBUG_LEVEL_INFO, fmt, ##args )
+
+#define uhci_print_verbose( fmt, args... ) \
+	usb_dprintf( NAME, DEBUG_LEVEL_VERBOSE, fmt, ##args )
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/iface.c
===================================================================
--- uspace/drv/uhci/iface.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/iface.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <usb/hcdhubd.h>
+#include <errno.h>
+
+#include "iface.h"
+#include "uhci.h"
+/*
+static int enqueue_transfer_out(device_t *dev,
+    usb_target_t target, usb_transfer_type_t transfer_type,
+    void *buffer, size_t size,
+    usbhc_iface_transfer_out_callback_t callback, void *arg)
+{
+	printf(NAME ": transfer OUT [%d.%d (%s); %zu]\n",
+	    target.address, target.endpoint,
+	    usb_str_transfer_type(transfer_type),
+	    size);
+
+	return ENOTSUP;
+}
+
+static int enqueue_transfer_setup(device_t *dev,
+    usb_target_t target, usb_transfer_type_t transfer_type,
+    void *buffer, size_t size,
+    usbhc_iface_transfer_out_callback_t callback, void *arg)
+{
+	printf(NAME ": transfer SETUP [%d.%d (%s); %zu]\n",
+	    target.address, target.endpoint,
+	    usb_str_transfer_type(transfer_type),
+	    size);
+
+	return ENOTSUP;
+}
+
+static int enqueue_transfer_in(device_t *dev,
+    usb_target_t target, usb_transfer_type_t transfer_type,
+    void *buffer, size_t size,
+    usbhc_iface_transfer_in_callback_t callback, void *arg)
+{
+	printf(NAME ": transfer IN [%d.%d (%s); %zu]\n",
+	    target.address, target.endpoint,
+	    usb_str_transfer_type(transfer_type),
+	    size);
+
+	return ENOTSUP;
+}
+*/
+
+static int get_address(device_t *dev, devman_handle_t handle,
+    usb_address_t *address)
+{
+	return ENOTSUP;
+}
+/*----------------------------------------------------------------------------*/
+static int interrupt_out(device_t *dev, usb_target_t target,
+    void *data, size_t size,
+    usbhc_iface_transfer_out_callback_t callback, void *arg)
+{
+	return uhci_out(dev, target, USB_TRANSFER_INTERRUPT,
+	    data, size, callback, arg);
+}
+/*----------------------------------------------------------------------------*/
+static int interrupt_in(device_t *dev, usb_target_t target,
+    void *data, size_t size,
+    usbhc_iface_transfer_in_callback_t callback, void *arg)
+{
+	return uhci_in(dev, target, USB_TRANSFER_INTERRUPT,
+	    data, size, callback, arg);
+}
+/*----------------------------------------------------------------------------*/
+static int control_write_setup(device_t *dev, usb_target_t target,
+    void *data, size_t size,
+    usbhc_iface_transfer_out_callback_t callback, void *arg)
+{
+	return uhci_setup(dev, target, USB_TRANSFER_CONTROL,
+	    data, size, callback, arg);
+}
+/*----------------------------------------------------------------------------*/
+static int control_write_data(device_t *dev, usb_target_t target,
+    void *data, size_t size,
+    usbhc_iface_transfer_out_callback_t callback, void *arg)
+{
+	return uhci_out(dev, target, USB_TRANSFER_CONTROL,
+	    data, size, callback, arg);
+}
+/*----------------------------------------------------------------------------*/
+static int control_write_status(device_t *dev, usb_target_t target,
+    usbhc_iface_transfer_in_callback_t callback, void *arg)
+{
+	return uhci_in(dev, target, USB_TRANSFER_CONTROL,
+	    NULL, 0, callback, arg);
+}
+/*----------------------------------------------------------------------------*/
+static int control_read_setup(device_t *dev, usb_target_t target,
+    void *data, size_t size,
+    usbhc_iface_transfer_out_callback_t callback, void *arg)
+{
+	return uhci_setup(dev, target, USB_TRANSFER_CONTROL,
+	    data, size, callback, arg);
+}
+/*----------------------------------------------------------------------------*/
+static int control_read_data(device_t *dev, usb_target_t target,
+    void *data, size_t size,
+    usbhc_iface_transfer_in_callback_t callback, void *arg)
+{
+	return uhci_in(dev, target, USB_TRANSFER_CONTROL,
+	    data, size, callback, arg);
+}
+/*----------------------------------------------------------------------------*/
+static int control_read_status(device_t *dev, usb_target_t target,
+    usbhc_iface_transfer_out_callback_t callback, void *arg)
+{
+	return uhci_out(dev, target, USB_TRANSFER_CONTROL,
+	    NULL, 0, callback, arg);
+}
+
+
+usbhc_iface_t uhci_iface = {
+	.tell_address = get_address,
+
+	.reserve_default_address = NULL,
+	.release_default_address = NULL,
+	.request_address = NULL,
+	.bind_address = NULL,
+	.release_address = NULL,
+
+	.interrupt_out = interrupt_out,
+	.interrupt_in = interrupt_in,
+
+	.control_write_setup = control_write_setup,
+	.control_write_data = control_write_data,
+	.control_write_status = control_write_status,
+
+	.control_read_setup = control_read_setup,
+	.control_read_data = control_read_data,
+	.control_read_status = control_read_status
+};
Index: uspace/drv/uhci/iface.h
===================================================================
--- uspace/drv/uhci/iface.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/iface.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_IFACE_H
+#define DRV_UHCI_IFACE_H
+
+#include <usbhc_iface.h>
+
+usbhc_iface_t uhci_iface;
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/link_ptr.h
===================================================================
--- uspace/drv/uhci/link_ptr.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/link_ptr.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_LINK_PTR_H
+#define DRV_UHCI_LINK_PTR_H
+
+#include "td_ptr.h"
+
+/** Links in Frame List */
+typedef td_ptr_t link_ptr_t;
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/main.c
===================================================================
--- uspace/drv/uhci/main.c	(revision 6610565b4f069eca9d1d17e21f317196b1a98756)
+++ uspace/drv/uhci/main.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2010 Vojtech Horky
+ * Copyright (c) 2010 Vojtech Horky, Jan Vesely
  * All rights reserved.
  *
@@ -28,7 +28,9 @@
 #include <usb/hcdhubd.h>
 #include <usb_iface.h>
-#include <usb/debug.h>
 #include <errno.h>
-#include <driver.h>
+
+#include "debug.h"
+#include "iface.h"
+#include "name.h"
 #include "uhci.h"
 
@@ -53,12 +55,9 @@
 static int uhci_add_device(device_t *device)
 {
-	usb_dprintf(NAME, 1, "uhci_add_device() called\n");
+//	usb_dprintf(NAME, DEBUG, "uhci_add_device() called\n");
+	uhci_print_info( "uhci_add_device() called\n" );
 	device->ops = &uhci_ops;
 
-	/*
-	 * We need to announce the presence of our root hub.
-	 */
-	usb_dprintf(NAME, 2, "adding root hub\n");
-	usb_hcd_add_root_hub(device);
+	uhci_init( device, (void*)0xc020 );
 
 	return EOK;
@@ -79,6 +78,6 @@
 	 * Do some global initializations.
 	 */
-	sleep(5);
-	usb_dprintf_enable(NAME, 5);
+	sleep( 5 );
+	usb_dprintf_enable(NAME, DEBUG_LEVEL_MAX);
 
 	return driver_main(&uhci_driver);
Index: uspace/drv/uhci/name.h
===================================================================
--- uspace/drv/uhci/name.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/name.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_TD_NAME_H
+#define DRV_UHCI_TD_NAME_H
+
+#define NAME "uhci"
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/qh.h
===================================================================
--- uspace/drv/uhci/qh.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/qh.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,47 @@
+
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_QH_H
+#define DRV_UHCI_QH_H
+
+#include "link_ptr.h"
+
+typedef struct qh {
+	link_ptr_t
+} __attribute__(("packed")) link_ptr_t;
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/root_hub/port.c
===================================================================
--- uspace/drv/uhci/root_hub/port.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/root_hub/port.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,180 @@
+
+#include <errno.h>
+#include <usb/devreq.h> /* for usb_device_request_setup_packet_t */
+#include <usb/usb.h>
+
+#include "debug.h"
+#include "uhci.h"
+#include "port.h"
+#include "port_status.h"
+#include "utils/hc_synchronizer.h"
+#include "utils/usb_device.h"
+
+static int uhci_port_new_device(uhci_port_t *port);
+static int uhci_port_remove_device(uhci_port_t *port);
+static int uhci_port_set_enabled(uhci_port_t *port, bool enabled);
+static usb_address_t assign_address_to_zero_device(device_t *hc);
+
+/*----------------------------------------------------------------------------*/
+int uhci_port_check(void *port)
+{
+	uhci_port_t *port_instance = port;
+	assert(port_instance);
+
+	while (1) {
+		uhci_print_info("Port(%d) status address %p:\n",
+		  port_instance->number, port_instance->address);
+
+		/* read register value */
+		port_status_t port_status =
+			port_status_read(port_instance->address);
+
+		/* debug print */
+		uhci_print_info("Port(%d) status %#.4x:\n",
+		  port_instance->number, port_status);
+		print_port_status( port_status );
+
+		if (port_status & STATUS_CONNECTED_CHANGED) {
+			if (port_status & STATUS_CONNECTED) {
+				uhci_port_new_device(port_instance);
+			} else {
+				uhci_port_remove_device(port_instance);
+			}
+		}
+		async_usleep(port_instance->wait_period_usec);
+	}
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+static int uhci_port_new_device(uhci_port_t *port)
+{
+	assert(port);
+	assert(port->hc);
+
+	uhci_print_info("Adding new device on port %d.\n", port->number);
+
+	uhci_t *uhci_instance = (uhci_t*)(port->hc->driver_data);
+
+	/* get default address */
+	usb_address_keeping_reserve_default(&uhci_instance->address_manager);
+
+	/* enable port */
+	uhci_port_set_enabled( port, true );
+
+	/* assign address to device */
+	usb_address_t address = assign_address_to_zero_device(port->hc);
+
+
+	if (address <= 0) { /* address assigning went wrong */
+		uhci_print_error("Failed to assign address to the device.\n");
+		uhci_port_set_enabled(port, false);
+		usb_address_keeping_release_default(&uhci_instance->address_manager);
+		return ENOMEM;
+	}
+
+	/* release default address */
+	usb_address_keeping_release_default(&uhci_instance->address_manager);
+
+	/* communicate and possibly report to devman */
+	assert(port->attached_device == 0);
+
+#define CHECK_RET_DELETE_CHILD_RETURN(ret, child, message, args...)\
+	if (ret < 0) { \
+		uhci_print_error("Failed(%d) to "message, ret, ##args); \
+		if (child) { \
+			delete_device(child); \
+		} \
+		uhci_port_set_enabled(port, false); \
+		usb_address_keeping_release(&uhci_instance->address_manager, address); \
+		return ret; \
+	} else (void)0
+
+	device_t *child = create_device();
+
+	int ret = child ? EOK : ENOMEM;
+	CHECK_RET_DELETE_CHILD_RETURN(ret, child, "create device.\n" );
+
+	ret = usb_device_init(child, port->hc, address, port->number );
+	CHECK_RET_DELETE_CHILD_RETURN(ret, child, "init usb device.\n" );
+
+	ret = child_device_register(child, port->hc);
+	CHECK_RET_DELETE_CHILD_RETURN(ret, child, "register usb device.\n" );
+
+	/* store device and bind address, can not fail */
+	port->attached_device = child->handle;
+	usb_address_keeping_devman_bind(&uhci_instance->address_manager,
+	  address, port->attached_device);
+
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+static int uhci_port_remove_device(uhci_port_t *port)
+{
+	uhci_print_error(	"Don't know how to remove device %#x.\n",
+		port->attached_device);
+	uhci_port_set_enabled(port, false);
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+static int uhci_port_set_enabled(uhci_port_t *port, bool enabled)
+{
+	assert(port);
+
+	/* read register value */
+	port_status_t port_status
+		= port_status_read(port->address);
+
+	/* enable port: register write */
+	if (enabled) {
+		port_status |= STATUS_ENABLED;
+	} else {
+		port_status &= ~STATUS_ENABLED;
+	}
+	port_status_write( port->address, port_status );
+
+	uhci_print_info( "%s port %d.\n",
+	  enabled ? "Enabled" : "Disabled", port->number );
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+static usb_address_t assign_address_to_zero_device( device_t *hc )
+{
+	assert( hc );
+	assert( hc->driver_data );
+
+	uhci_t *uhci_instance = (uhci_t*)hc->driver_data;
+
+	/* get new address */
+	const usb_address_t usb_address =
+	  usb_address_keeping_request(&uhci_instance->address_manager);
+
+	if (usb_address <= 0) {
+		return usb_address;
+	}
+
+	/* assign new address */
+	usb_target_t new_device = { USB_ADDRESS_DEFAULT, 0 };
+	usb_device_request_setup_packet_t data =
+	{
+		.request_type = 0,
+		.request = USB_DEVREQ_SET_ADDRESS,
+		{ .value = usb_address },
+		.index = 0,
+		.length = 0
+	};
+
+	sync_value_t sync;
+	uhci_setup_sync(hc, new_device,
+	  USB_TRANSFER_CONTROL, &data, sizeof(data), &sync);
+
+	if (sync.result != USB_OUTCOME_OK) {
+		uhci_print_error(
+		  "Failed to assign address to the connected device.\n");
+		usb_address_keeping_release(&uhci_instance->address_manager,
+		  usb_address);
+		return -1;
+	}
+
+	uhci_print_info("Assigned address %#x.\n", usb_address);
+	return usb_address;
+}
Index: uspace/drv/uhci/root_hub/port.h
===================================================================
--- uspace/drv/uhci/root_hub/port.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/root_hub/port.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI port driver
+ */
+#ifndef DRV_UHCI_PORT_H
+#define DRV_UHCI_PORT_H
+
+#include <assert.h>
+#include <driver.h>
+#include <stdint.h>
+
+#include "port_status.h"
+
+typedef struct uhci_port
+{
+	port_status_t *address;
+	device_t *hc;
+	unsigned number;
+	unsigned wait_period_usec;
+	devman_handle_t attached_device;
+} uhci_port_t;
+
+static inline void uhci_port_init(
+  uhci_port_t *port, port_status_t *address, device_t *hc, unsigned number,
+  unsigned usec)
+{
+	assert( port );
+	port->address = address;
+	port->hc = hc;
+	port->number = number;
+	port->wait_period_usec = usec;
+	port->attached_device = 0;
+}
+
+int uhci_port_check(void *port);
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/root_hub/port_status.c
===================================================================
--- uspace/drv/uhci/root_hub/port_status.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/root_hub/port_status.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,35 @@
+#include <assert.h>
+#include <stdio.h>
+
+#include "debug.h"
+#include "port_status.h"
+
+struct flag_name
+{
+	unsigned flag;
+	const char *name;
+};
+
+static const struct flag_name flags[] =
+{
+	{ STATUS_SUSPEND, "suspended" },
+	{ STATUS_IN_RESET, "in reset" },
+	{ STATUS_LOW_SPEED, "low speed device" },
+	{ STATUS_ALWAYS_ONE, "always 1 bit" },
+	{ STATUS_RESUME, "resume" },
+	{ STATUS_LINE_D_MINUS, "line D- value" },
+	{ STATUS_LINE_D_PLUS, "line D+ value" },
+	{ STATUS_ENABLED_CHANGED, "enabled changed" },
+	{ STATUS_ENABLED, "enabled" },
+	{ STATUS_CONNECTED_CHANGED, "connected changed" },
+	{ STATUS_CONNECTED, "connected" }
+};
+
+void print_port_status(port_status_t value)
+{
+	unsigned i = 0;
+	for (;i < sizeof(flags)/sizeof(struct flag_name); ++i) {
+		uhci_print_verbose("\t%s status: %s.\n", flags[i].name,
+		  value & flags[i].flag ? "YES" : "NO");
+	}
+}
Index: uspace/drv/uhci/root_hub/port_status.h
===================================================================
--- uspace/drv/uhci/root_hub/port_status.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/root_hub/port_status.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_TD_PORT_STATUS_H
+#define DRV_UHCI_TD_PORT_STATUS_H
+
+#include <libarch/ddi.h>
+#include <stdint.h>
+
+typedef uint16_t port_status_t;
+
+enum {
+	STATUS_CONNECTED         = 1 << 0,
+	STATUS_CONNECTED_CHANGED = 1 << 1,
+	STATUS_ENABLED           = 1 << 2,
+	STATUS_ENABLED_CHANGED   = 1 << 3,
+	STATUS_LINE_D_PLUS       = 1 << 4,
+	STATUS_LINE_D_MINUS      = 1 << 5,
+	STATUS_RESUME            = 1 << 6,
+	STATUS_ALWAYS_ONE        = 1 << 7,
+
+	STATUS_LOW_SPEED = 1 <<  8,
+	STATUS_IN_RESET  = 1 <<  9,
+	STATUS_SUSPEND   = 1 << 12,
+};
+
+static inline port_status_t port_status_read(port_status_t * address)
+	{ return pio_read_16(address); }
+
+static inline void port_status_write(
+  port_status_t * address, port_status_t value)
+	{ pio_write_16(address, value); }
+
+void print_port_status(const port_status_t status);
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/root_hub/root_hub.c
===================================================================
--- uspace/drv/uhci/root_hub/root_hub.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/root_hub/root_hub.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,53 @@
+#include <async.h>
+#include <ddi.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#include "debug.h"
+#include "root_hub.h"
+
+#define ROOT_HUB_WAIT_USEC 10000000 /* 10 second */
+
+int uhci_root_hub_init( uhci_root_hub_t *hub, device_t *hc, void *addr )
+{
+	assert( hub );
+
+	/* allow access to root hub registers */
+	port_status_t *regs;
+	const int ret = pio_enable(
+	  addr, sizeof(port_status_t) * UHCI_ROOT_HUB_PORT_COUNT, (void**)&regs);
+
+	if (ret < 0) {
+		uhci_print_error(": Failed to gain access to port registers at %p\n", regs);
+		return ret;
+	}
+
+	/* add fibrils for periodic port checks */
+	unsigned i = 0;
+	for (; i < UHCI_ROOT_HUB_PORT_COUNT; ++i) {
+		/* mind pointer arithmetics */
+		uhci_port_init(
+		  &hub->ports[i], regs + i, hc, i, ROOT_HUB_WAIT_USEC);
+
+		hub->checker[i] = fibril_create(uhci_port_check, &hub->ports[i]);
+		if (hub->checker[i] == 0) {
+			uhci_print_error(": failed to launch root hub fibril.");
+			return ENOMEM;
+		}
+		fibril_add_ready(hub->checker[i]);
+		uhci_print_verbose(" added fibril for port %d: %p.\n", i, hub->checker[i]);
+	}
+
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+int uhci_root_hub_fini( uhci_root_hub_t* instance )
+{
+	assert( instance );
+	// TODO:
+	//destroy fibril here
+	//disable access to registers
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
Index: uspace/drv/uhci/root_hub/root_hub.h
===================================================================
--- uspace/drv/uhci/root_hub/root_hub.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/root_hub/root_hub.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_ROOT_HUB_H
+#define DRV_UHCI_ROOT_HUB_H
+
+#include <fibril.h>
+#include <driver.h>
+
+#include "port.h"
+
+#define UHCI_ROOT_HUB_PORT_COUNT 2
+#define UHCI_ROOT_HUB_PORT_REGISTERS_OFFSET 0x10
+
+typedef struct root_hub {
+	uhci_port_t ports[UHCI_ROOT_HUB_PORT_COUNT];
+	fid_t checker[UHCI_ROOT_HUB_PORT_COUNT];
+} uhci_root_hub_t;
+
+int uhci_root_hub_init(
+  uhci_root_hub_t *instance, device_t *device, void *addr);
+
+int uhci_root_hub_fini(uhci_root_hub_t* instance);
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/td_ptr.h
===================================================================
--- uspace/drv/uhci/td_ptr.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/td_ptr.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_TD_PTR_H
+#define DRV_UHCI_TD_PTR_H
+
+/** UHCI Transfer Descriptor pointer */
+typedef struct td_ptr {
+	uint32_t fpl:28;
+	char :2;
+	uint8_t qh:1;
+	uint8_t terminate:1;
+} __attribute__(("packed")) td_ptr_t;
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/transfer.h
===================================================================
--- uspace/drv/uhci/transfer.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/transfer.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_TRANSFER_H
+#define DRV_UHCI_TRANSFER_H
+
+/** Status field in UHCI Transfer Descriptor (TD) */
+typedef struct status {
+	uint8_t active:1;
+	uint8_t stalled:1;
+	uint8_t data_buffer_error:1;
+	uint8_t babble:1;
+	uint8_t nak:1;
+	uint8_t crc:1;
+	uint8_t bitstuff:1;
+	uint8_t :1; /* reserved */
+} status_t
+
+/** UHCI Transfer Descriptor */
+typedef struct td {
+	uint32_t fpl:28;
+	char :1; /* reserved */
+	uint8_t depth:1;
+	uint8_t qh:1;
+	uint8_t terminate:1;
+
+	char :2; /* reserved */
+	uint8_t spd:1;
+	uint8_t error_count:2;
+	uint8_t low_speed:1;
+	uint8_t isochronous:1;
+	uint8_t ioc:1;
+	status_t status;
+	char :5; /* reserved */
+	uint16_t act_len:10;
+
+	uint16_t maxlen:11;
+	char :1; /* reserved */
+	uint8_t toggle:1;
+	uint8_t end_point:4;
+	uint8_t address:7;
+	uint8_t pid;
+
+	uint32_t buffer_ptr;
+} __attribute__(("packed")) td_t;
+
+
+#endif
+/**
+ * @}
+ */
Index: pace/drv/uhci/transfers.c
===================================================================
--- uspace/drv/uhci/transfers.c	(revision 6610565b4f069eca9d1d17e21f317196b1a98756)
+++ 	(revision )
@@ -1,160 +1,0 @@
-/*
- * Copyright (c) 2010 Vojtech Horky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include <usb/hcdhubd.h>
-#include <errno.h>
-
-#include "uhci.h"
-
-static int enqueue_transfer_out(device_t *dev,
-    usb_target_t target, usb_transfer_type_t transfer_type,
-    void *buffer, size_t size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	printf(NAME ": transfer OUT [%d.%d (%s); %zu]\n",
-	    target.address, target.endpoint,
-	    usb_str_transfer_type(transfer_type),
-	    size);
-
-	return ENOTSUP;
-}
-
-static int enqueue_transfer_setup(device_t *dev,
-    usb_target_t target, usb_transfer_type_t transfer_type,
-    void *buffer, size_t size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	printf(NAME ": transfer SETUP [%d.%d (%s); %zu]\n",
-	    target.address, target.endpoint,
-	    usb_str_transfer_type(transfer_type),
-	    size);
-
-	return ENOTSUP;
-}
-
-static int enqueue_transfer_in(device_t *dev,
-    usb_target_t target, usb_transfer_type_t transfer_type,
-    void *buffer, size_t size,
-    usbhc_iface_transfer_in_callback_t callback, void *arg)
-{
-	printf(NAME ": transfer IN [%d.%d (%s); %zu]\n",
-	    target.address, target.endpoint,
-	    usb_str_transfer_type(transfer_type),
-	    size);
-
-	return ENOTSUP;
-}
-
-
-static int get_address(device_t *dev, devman_handle_t handle,
-    usb_address_t *address)
-{
-	return ENOTSUP;
-}
-
-static int interrupt_out(device_t *dev, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	return enqueue_transfer_out(dev, target, USB_TRANSFER_INTERRUPT,
-	    data, size,
-	    callback, arg);
-}
-
-static int interrupt_in(device_t *dev, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_in_callback_t callback, void *arg)
-{
-	return enqueue_transfer_in(dev, target, USB_TRANSFER_INTERRUPT,
-	    data, size,
-	    callback, arg);
-}
-
-static int control_write_setup(device_t *dev, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL,
-	    data, size,
-	    callback, arg);
-}
-
-static int control_write_data(device_t *dev, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL,
-	    data, size,
-	    callback, arg);
-}
-
-static int control_write_status(device_t *dev, usb_target_t target,
-    usbhc_iface_transfer_in_callback_t callback, void *arg)
-{
-	return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL,
-	    NULL, 0,
-	    callback, arg);
-}
-
-static int control_read_setup(device_t *dev, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL,
-	    data, size,
-	    callback, arg);
-}
-
-static int control_read_data(device_t *dev, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_in_callback_t callback, void *arg)
-{
-	return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL,
-	    data, size,
-	    callback, arg);
-}
-
-static int control_read_status(device_t *dev, usb_target_t target,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL,
-	    NULL, 0,
-	    callback, arg);
-}
-
-
-usbhc_iface_t uhci_iface = {
-	.tell_address = get_address,
-	.interrupt_out = interrupt_out,
-	.interrupt_in = interrupt_in,
-	.control_write_setup = control_write_setup,
-	.control_write_data = control_write_data,
-	.control_write_status = control_write_status,
-	.control_read_setup = control_read_setup,
-	.control_read_data = control_read_data,
-	.control_read_status = control_read_status
-};
Index: uspace/drv/uhci/uhci.c
===================================================================
--- uspace/drv/uhci/uhci.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/uhci.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,95 @@
+#include <errno.h>
+#include <usb/debug.h>
+#include <usb/usb.h>
+
+#include "debug.h"
+#include "name.h"
+#include "uhci.h"
+
+
+int uhci_init(device_t *device, void *regs)
+{
+	assert( device );
+	uhci_print_info( "Initializing device at address %p\n", device);
+
+	/* create instance */
+	uhci_t *instance = malloc( sizeof(uhci_t) );
+	if (!instance)
+		{ return ENOMEM; }
+	memset( instance, 0, sizeof(uhci_t) );
+
+	/* init address keeper(libusb) */
+	usb_address_keeping_init( &instance->address_manager, USB11_ADDRESS_MAX );
+
+	/* allow access to hc control registers */
+	regs_t *io;
+	int ret = pio_enable( regs, sizeof(regs_t), (void**)&io);
+	if (ret < 0) {
+		free( instance );
+		printf(NAME": Failed to gain access to registers at %p\n", io);
+		return ret;
+	}
+	instance->registers = io;
+
+	/* init root hub */
+	ret = uhci_root_hub_init( &instance->root_hub, device,
+	  (char*)regs + UHCI_ROOT_HUB_PORT_REGISTERS_OFFSET );
+	if (ret < 0) {
+		free( instance );
+		printf(NAME": Failed to initialize root hub driver.\n");
+		return ret;
+	}
+
+	device->driver_data = instance;
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+int uhci_in(
+  device_t *dev,
+	usb_target_t target,
+	usb_transfer_type_t transfer_type,
+	void *buffer, size_t size,
+	usbhc_iface_transfer_in_callback_t callback, void *arg
+	)
+{
+	uhci_print_info( "transfer IN [%d.%d (%s); %zu]\n",
+	    target.address, target.endpoint,
+	    usb_str_transfer_type(transfer_type),
+	    size);
+
+	return ENOTSUP;
+}
+/*----------------------------------------------------------------------------*/
+int uhci_out(
+  device_t *dev,
+  usb_target_t target,
+  usb_transfer_type_t transfer_type,
+  void *buffer, size_t size,
+	usbhc_iface_transfer_out_callback_t callback, void *arg
+  )
+{
+	uhci_print_info( "transfer OUT [%d.%d (%s); %zu]\n",
+	    target.address, target.endpoint,
+	    usb_str_transfer_type(transfer_type),
+	    size);
+
+	return ENOTSUP;
+}
+/*----------------------------------------------------------------------------*/
+int uhci_setup(
+  device_t *dev,
+  usb_target_t target,
+  usb_transfer_type_t transfer_type,
+  void *buffer, size_t size,
+  usbhc_iface_transfer_out_callback_t callback, void *arg
+  )
+{
+	uhci_print_info( "transfer SETUP [%d.%d (%s); %zu]\n",
+	    target.address, target.endpoint,
+	    usb_str_transfer_type(transfer_type),
+	    size);
+	callback( dev, USB_OUTCOME_OK, arg );
+
+	return ENOTSUP;
+}
+/*----------------------------------------------------------------------------*/
Index: uspace/drv/uhci/uhci.h
===================================================================
--- uspace/drv/uhci/uhci.h	(revision 6610565b4f069eca9d1d17e21f317196b1a98756)
+++ uspace/drv/uhci/uhci.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2010 Vojtech Horky
+ * Copyright (c) 2010 Jan Vesely
  * All rights reserved.
  *
@@ -26,5 +26,4 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
 /** @addtogroup usb
  * @{
@@ -36,9 +35,55 @@
 #define DRV_UHCI_UHCI_H
 
+#include <fibril.h>
+
+#include <usb/addrkeep.h>
+#include <usb/hcdhubd.h>
 #include <usbhc_iface.h>
 
-#define NAME "uhci"
+#include "root_hub/root_hub.h"
 
-usbhc_iface_t uhci_iface;
+typedef struct uhci_regs {
+	uint16_t usbcmd;
+	uint16_t usbsts;
+	uint16_t usbintr;
+	uint16_t frnum;
+	uint32_t flbaseadd;
+	uint8_t sofmod;
+} regs_t;
+
+typedef struct uhci {
+	usb_address_keeping_t address_manager;
+	uhci_root_hub_t root_hub;
+	volatile regs_t* registers;
+} uhci_t ;
+
+/* init uhci specifics in device.driver_data */
+int uhci_init( device_t *device, void *regs );
+
+int uhci_destroy( device_t *device );
+
+int uhci_in(
+  device_t *dev,
+	usb_target_t target,
+	usb_transfer_type_t transfer_type,
+	void *buffer, size_t size,
+	usbhc_iface_transfer_in_callback_t callback, void *arg
+	);
+
+int uhci_out(
+  device_t *dev,
+	usb_target_t target,
+  usb_transfer_type_t transfer_type,
+  void *buffer, size_t size,
+	usbhc_iface_transfer_out_callback_t callback, void *arg
+  );
+
+int uhci_setup(
+  device_t *dev,
+  usb_target_t target,
+  usb_transfer_type_t transfer_type,
+  void *buffer, size_t size,
+  usbhc_iface_transfer_out_callback_t callback, void *arg
+  );
 
 #endif
Index: uspace/drv/uhci/utils/fibril_semaphore.c
===================================================================
--- uspace/drv/uhci/utils/fibril_semaphore.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/utils/fibril_semaphore.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <assert.h>
+#include <async.h>
+#include <async_priv.h>
+#include <futex.h>
+
+#include "fibril_semaphore.h"
+static void optimize_execution_power(void)
+{
+  /*
+   * When waking up a worker fibril previously blocked in fibril
+   * synchronization, chances are that there is an idle manager fibril
+   * waiting for IPC, that could start executing the awakened worker
+   * fibril right away. We try to detect this and bring the manager
+   * fibril back to fruitful work.
+   */
+  if (atomic_get(&threads_in_ipc_wait) > 0)
+    ipc_poke();
+}
+/*----------------------------------------------------------------------------*/
+void fibril_semaphore_initialize(fibril_semaphore_t *fs, int value)
+{
+	assert( fs );
+  fs->oi.owned_by = NULL;
+  fs->counter = 1;
+	fs->value = value;
+  list_initialize(&fs->waiters);
+}
+/*----------------------------------------------------------------------------*/
+void fibril_semaphore_down(fibril_semaphore_t *fs)
+{
+	assert( fs );
+  fibril_t *f = (fibril_t *) fibril_get_id();
+
+  futex_down(&async_futex);
+  if (--fs->value < 0) {
+    awaiter_t wdata;
+    wdata.fid = fibril_get_id();
+    wdata.active = false;
+    wdata.wu_event.inlist = true;
+    link_initialize(&wdata.wu_event.link);
+    list_append(&wdata.wu_event.link, &fs->waiters);
+//    check_for_deadlock(&fm->oi);
+    f->waits_for = &fs->oi;
+		++fs->counter;
+    fibril_switch(FIBRIL_TO_MANAGER);
+  } else {
+    fs->oi.owned_by = f;
+    futex_up(&async_futex);
+  }
+}
+/*----------------------------------------------------------------------------*/
+bool fibril_semaphore_trydown(fibril_semaphore_t *fs)
+{
+  bool locked = false;
+
+  futex_down(&async_futex);
+  if (fs->value > 0) {
+    --fs->value;
+    fs->oi.owned_by = (fibril_t *) fibril_get_id();
+    locked = true;
+  }
+  futex_up(&async_futex);
+
+  return locked;
+}
+/*----------------------------------------------------------------------------*/
+void fibril_semaphore_up(fibril_semaphore_t *fs)
+{
+	assert(fs);
+	futex_down(&async_futex);
+  if (++fs->value <= 0) {
+    link_t *tmp;
+    awaiter_t *wdp;
+    fibril_t *f;
+
+    assert(!list_empty(&fs->waiters));
+
+    tmp = fs->waiters.next;
+    wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
+    wdp->active = true;
+    wdp->wu_event.inlist = false;
+
+    f = (fibril_t *) wdp->fid;
+    fs->oi.owned_by = f;
+    f->waits_for = NULL;
+
+    list_remove(&wdp->wu_event.link);
+    fibril_add_ready(wdp->fid);
+    optimize_execution_power();
+  } else {
+    fs->oi.owned_by = NULL;
+  }
+	futex_up(&async_futex);
+}
Index: uspace/drv/uhci/utils/fibril_semaphore.h
===================================================================
--- uspace/drv/uhci/utils/fibril_semaphore.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/utils/fibril_semaphore.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_UTILS_FIBRIL_SEMAPHORE_H
+#define DRV_UHCI_UTILS_FIBRIL_SEMAPHORE_H
+
+#include <bool.h>
+#include <fibril.h>
+
+typedef struct {
+  fibril_owner_info_t oi;   /* Keep this the first thing. */
+  int counter;
+	int value;
+  link_t waiters;
+} fibril_semaphore_t;
+
+#define FIBRIL_SEMAPHORE_INITIALIZER(name) \
+  { \
+    .oi = { \
+      .owned_by = NULL \
+    }, \
+    .counter = 0, \
+		.value = 0, \
+    .waiters = { \
+      .prev = &name.waiters, \
+      .next = &name.waiters, \
+    } \
+  }
+
+extern void fibril_semaphore_initialize(fibril_semaphore_t *, int value);
+extern void fibril_semaphore_down(fibril_semaphore_t *);
+extern bool fibril_semaphore_trydown(fibril_semaphore_t *);
+extern void fibril_semaphore_up(fibril_semaphore_t *);
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/utils/hc_synchronizer.c
===================================================================
--- uspace/drv/uhci/utils/hc_synchronizer.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/utils/hc_synchronizer.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,60 @@
+#include "debug.h"
+#include "hc_synchronizer.h"
+#include "uhci.h"
+
+void sync_init(sync_value_t *value)
+{
+	assert(value);
+	fibril_semaphore_initialize(&value->done, 0);
+}
+/*----------------------------------------------------------------------------*/
+void sync_wait_for(sync_value_t *value)
+{
+	assert( value );
+	fibril_semaphore_down(&value->done);
+}
+/*----------------------------------------------------------------------------*/
+void sync_in_callback(
+  device_t *device, usb_transaction_outcome_t result, size_t size, void *arg)
+{
+	sync_value_t *value = arg;
+	assert(value);
+	value->size = size;
+	value->result = result;
+	fibril_semaphore_up(&value->done);
+}
+/*----------------------------------------------------------------------------*/
+void sync_out_callback(
+  device_t *device, usb_transaction_outcome_t result, void *arg)
+{
+	sync_value_t *value = arg;
+	assert(value);
+	value->result = result;
+	fibril_semaphore_up(&value->done);
+}
+/*----------------------------------------------------------------------------*/
+int uhci_setup_sync(
+  device_t *hc,
+  usb_target_t target,
+  usb_transfer_type_t type,
+  void *buffer, size_t size,
+  sync_value_t *result
+  )
+{
+	assert(result);
+	sync_init(result);
+
+	int ret =
+	  uhci_setup(hc, target, type, buffer, size,
+		  sync_out_callback, (void*)result);
+
+	if (ret) {
+		uhci_print_error("sync setup transaction failed(%d).\n", ret);
+		return ret;
+	}
+
+	uhci_print_verbose("setup transaction sent, waiting to complete.\n");
+	sync_wait_for(result);
+
+	return ret;
+}
Index: uspace/drv/uhci/utils/hc_synchronizer.h
===================================================================
--- uspace/drv/uhci/utils/hc_synchronizer.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/utils/hc_synchronizer.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_UTIL_SYNCHRONIZER_H
+#define DRV_UHCI_UTIL_SYNCHRONIZER_H
+
+#include <assert.h>
+#include <driver.h>
+#include <usb/usb.h>
+
+#include "debug.h"
+#include "utils/fibril_semaphore.h"
+
+typedef struct value
+{
+	/* TODO Think of better fibril synch to use */
+	usb_transaction_outcome_t result;
+	size_t size;
+	fibril_semaphore_t done;
+} sync_value_t;
+
+void sync_init(sync_value_t *value);
+
+void sync_wait_for(sync_value_t *value);
+
+void sync_in_callback(
+  device_t *device, usb_transaction_outcome_t result, size_t size, void *value);
+
+void sync_out_callback(
+  device_t *device, usb_transaction_outcome_t result, void *value);
+
+int uhci_setup_sync(
+  device_t *hc,
+  usb_target_t target,
+  usb_transfer_type_t type,
+  void *buffer, size_t size,
+  sync_value_t *result
+  );
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/utils/usb_device.c
===================================================================
--- uspace/drv/uhci/utils/usb_device.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/utils/usb_device.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <usb/classes/classes.h>
+#include <usb/descriptor.h>
+#include <usb/usbdrv.h>
+
+#include "debug.h"
+#include "usb_device.h"
+
+/*----------------------------------------------------------------------------*/
+#define CHECK_RET_RETURN(ret, child, message, args...)\
+  if (ret < 0) { \
+    uhci_print_error("Failed(%d) to "message, ret, ##args); \
+    return ret; \
+  } else (void)0
+
+int usb_device_init(device_t *device, device_t *hc, usb_address_t address,
+  int hub_port)
+{
+	assert(device);
+	assert(hc);
+
+	int ret = 0;
+  char *name;
+
+  /* create name */
+  ret = asprintf(&name, "usbdevice on hc%p/root_hub[%d]/%#x",
+	  hc, hub_port, address);
+  CHECK_RET_RETURN(ret, child, "create device name.\n");
+
+  device->name = name;
+
+	/* use descriptors to identify the device */
+  ret = usb_device_identify(device, hc, address);
+  CHECK_RET_RETURN(ret, child, "identify device.\n");
+
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+struct device_descriptor_packet
+{
+	usb_device_request_setup_packet_t request;
+	usb_standard_device_descriptor_t descriptor;
+};
+#define DEVICE_DESCRIPTOR_PACKET_INITIALIZER \
+	{ \
+		.request = { \
+			.request_type = 0, \
+			.request = USB_DEVREQ_GET_DESCRIPTOR, \
+			{ .value = USB_DESCTYPE_DEVICE }, \
+			.index = 0, \
+			.length = sizeof(usb_standard_device_descriptor_t) \
+		} \
+	}
+/*----------------------------------------------------------------------------*/
+struct configuration_descriptor_packet
+{
+	usb_device_request_setup_packet_t request;
+	usb_standard_configuration_descriptor_t descriptor;
+};
+#define CONFIGURATION_DESCRIPTOR_PACKET_INITIALIZER \
+	{ \
+		.request = { \
+			.request_type = 0, \
+			.request = USB_DEVREQ_GET_DESCRIPTOR, \
+			{ .value = USB_DESCTYPE_CONFIGURATION }, \
+			.index = 0, \
+			.length = sizeof(usb_standard_device_descriptor_t); \
+		}; \
+	}
+/*----------------------------------------------------------------------------*/
+int usb_device_identify(device_t *device, device_t *hc, usb_address_t address)
+{
+	assert(device);
+	assert(hc);
+
+	struct device_descriptor_packet packet =
+	  DEVICE_DESCRIPTOR_PACKET_INITIALIZER;
+
+  packet.descriptor.device_class = USB_CLASS_HUB;
+  usb_drv_create_match_ids_from_device_descriptor(
+	  &device->match_ids, &packet.descriptor );
+
+	return 0;
+}
+/*----------------------------------------------------------------------------*/
Index: uspace/drv/uhci/utils/usb_device.h
===================================================================
--- uspace/drv/uhci/utils/usb_device.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/drv/uhci/utils/usb_device.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2010 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup usb
+ * @{
+ */
+/** @file
+ * @brief UHCI driver
+ */
+#ifndef DRV_UHCI_UTILS_IDENTIFY_H
+#define DRV_UHCI_UTILS_IDENTIFY_H
+
+#include <driver.h>
+#include <usb/usb.h>
+
+int usb_device_identify(device_t *device, device_t *hc, usb_address_t address);
+
+int usb_device_init(device_t *device, device_t *hc, usb_address_t address,
+  int port);
+
+#endif
+/**
+ * @}
+ */
Index: uspace/lib/usb/include/usb/addrkeep.h
===================================================================
--- uspace/lib/usb/include/usb/addrkeep.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
+++ uspace/lib/usb/include/usb/addrkeep.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libusb usb
+ * @{
+ */
+/** @file
+ * @brief HC driver.
+ */
+#ifndef LIBUSB_HCD_H_
+#define LIBUSB_HCD_H_
+
+#include <usb/usb.h>
+#include <fibril_synch.h>
+#include <devman.h>
+
+/** Info about used address. */
+typedef struct {
+	/** Linked list member. */
+	link_t link;
+	/** Address. */
+	usb_address_t address;
+	/** Corresponding devman handle. */
+	devman_handle_t devman_handle;
+} usb_address_keeping_used_t;
+
+/** Structure for keeping track of free and used USB addresses. */
+typedef struct {
+	/** Head of list of used addresses. */
+	link_t used_addresses;
+	/** Upper bound for USB addresses. */
+	usb_address_t max_address;
+	/** Mutex protecting used address. */
+	fibril_mutex_t used_addresses_guard;
+	/** Condition variable for used addresses. */
+	fibril_condvar_t used_addresses_condvar;
+
+	/** Condition variable mutex for default address. */
+	fibril_mutex_t default_condvar_guard;
+	/** Condition variable for default address. */
+	fibril_condvar_t default_condvar;
+	/** Whether is default address available. */
+	bool default_available;
+} usb_address_keeping_t;
+
+void usb_address_keeping_init(usb_address_keeping_t *, usb_address_t);
+
+void usb_address_keeping_reserve_default(usb_address_keeping_t *);
+void usb_address_keeping_release_default(usb_address_keeping_t *);
+
+usb_address_t usb_address_keeping_request(usb_address_keeping_t *);
+int usb_address_keeping_release(usb_address_keeping_t *, usb_address_t);
+void usb_address_keeping_devman_bind(usb_address_keeping_t *, usb_address_t,
+    devman_handle_t);
+usb_address_t usb_address_keeping_find(usb_address_keeping_t *,
+    devman_handle_t);
+
+
+#endif
Index: uspace/lib/usb/include/usb/devreq.h
===================================================================
--- uspace/lib/usb/include/usb/devreq.h	(revision 6610565b4f069eca9d1d17e21f317196b1a98756)
+++ uspace/lib/usb/include/usb/devreq.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -70,4 +70,5 @@
 	/** Main parameter to the request. */
 	union {
+		uint16_t value;
 		/* FIXME: add #ifdefs according to host endianess */
 		struct {
@@ -75,5 +76,4 @@
 			uint8_t value_high;
 		};
-		uint16_t value;
 	};
 	/** Auxiliary parameter to the request.
Index: uspace/lib/usb/include/usb/hcd.h
===================================================================
--- uspace/lib/usb/include/usb/hcd.h	(revision 6610565b4f069eca9d1d17e21f317196b1a98756)
+++ uspace/lib/usb/include/usb/hcd.h	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -1,84 +1,1 @@
-/*
- * Copyright (c) 2010 Vojtech Horky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libusb usb
- * @{
- */
-/** @file
- * @brief HC driver.
- */
-#ifndef LIBUSB_HCD_H_
-#define LIBUSB_HCD_H_
-
-#include <usb/usb.h>
-#include <fibril_synch.h>
-#include <devman.h>
-
-/** Info about used address. */
-typedef struct {
-	/** Linked list member. */
-	link_t link;
-	/** Address. */
-	usb_address_t address;
-	/** Corresponding devman handle. */
-	devman_handle_t devman_handle;
-} usb_address_keeping_used_t;
-
-/** Structure for keeping track of free and used USB addresses. */
-typedef struct {
-	/** Head of list of used addresses. */
-	link_t used_addresses;
-	/** Upper bound for USB addresses. */
-	usb_address_t max_address;
-	/** Mutex protecting used address. */
-	fibril_mutex_t used_addresses_guard;
-	/** Condition variable for used addresses. */
-	fibril_condvar_t used_addresses_condvar;
-
-	/** Condition variable mutex for default address. */
-	fibril_mutex_t default_condvar_guard;
-	/** Condition variable for default address. */
-	fibril_condvar_t default_condvar;
-	/** Whether is default address available. */
-	bool default_available;
-} usb_address_keeping_t;
-
-void usb_address_keeping_init(usb_address_keeping_t *, usb_address_t);
-
-void usb_address_keeping_reserve_default(usb_address_keeping_t *);
-void usb_address_keeping_release_default(usb_address_keeping_t *);
-
-usb_address_t usb_address_keeping_request(usb_address_keeping_t *);
-int usb_address_keeping_release(usb_address_keeping_t *, usb_address_t);
-void usb_address_keeping_devman_bind(usb_address_keeping_t *, usb_address_t,
-    devman_handle_t);
-usb_address_t usb_address_keeping_find(usb_address_keeping_t *,
-    devman_handle_t);
-
-
-#endif
+addrkeep.h
Index: uspace/lib/usb/src/addrkeep.c
===================================================================
--- uspace/lib/usb/src/addrkeep.c	(revision 6610565b4f069eca9d1d17e21f317196b1a98756)
+++ uspace/lib/usb/src/addrkeep.c	(revision 977fcea2d1f12932431b92aaae48a7368a2db4d6)
@@ -33,5 +33,5 @@
  * @brief Address keeping.
  */
-#include <usb/hcd.h>
+#include <usb/addrkeep.h>
 #include <errno.h>
 #include <assert.h>
