Index: uspace/app/bdsh/cmds/modules/cat/cat.c
===================================================================
--- uspace/app/bdsh/cmds/modules/cat/cat.c	(revision a523af42844746625eb330a7a2ea4015969a83fd)
+++ uspace/app/bdsh/cmds/modules/cat/cat.c	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 a523af42844746625eb330a7a2ea4015969a83fd)
+++ uspace/app/bdsh/cmds/modules/rm/rm.c	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 a523af42844746625eb330a7a2ea4015969a83fd)
+++ uspace/drv/rootvirt/devices.def	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 a523af42844746625eb330a7a2ea4015969a83fd)
+++ uspace/drv/uhci/Makefile	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -29,10 +29,16 @@
 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
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/drv/uhci/debug.h
===================================================================
--- uspace/drv/uhci/debug.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/debug.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/iface.c	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/iface.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/link_ptr.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 a523af42844746625eb330a7a2ea4015969a83fd)
+++ uspace/drv/uhci/main.c	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/name.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/qh.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/root_hub/port.c	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -0,0 +1,247 @@
+
+#include <atomic.h>
+#include <errno.h>
+#include <usb/devreq.h>
+#include <usb/usb.h>
+
+#include "debug.h"
+#include "uhci.h"
+#include "port.h"
+#include "port_status.h"
+#include "utils/hc_synchronizer.h"
+
+struct usb_match {
+	int id_score;
+	const char *id_string;
+};
+
+static int uhci_port_new_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 );
+static int report_new_device(
+  device_t *hc, usb_address_t address, int hub_port, devman_handle_t *handle);
+
+/*----------------------------------------------------------------------------*/
+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);
+//		port_status.raw_value = pio_read_16(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) {
+				/* assign address and report new device */
+				uhci_port_new_device(port_instance);
+			} else {
+				/* TODO */
+				/* remove device here */
+				uhci_print_error(
+				  "Don't know how to remove device %#x.\n",
+				  port_instance->attached_device);
+				uhci_port_set_enabled(port_instance, false);
+			}
+		}
+		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);
+
+	/* release default address */
+	usb_address_keeping_release_default(&uhci_instance->address_manager);
+
+	if (address <= 0) { /* address assigning went wrong */
+		uhci_port_set_enabled(port, false);
+		uhci_print_error("Failed to assign address to the device.\n");
+		return ENOMEM;
+	}
+
+	/* report to devman */
+	assert( port->attached_device == 0 );
+	report_new_device(port->hc, address, port->number,
+		&port->attached_device);
+
+	/* bind address */
+	usb_address_keeping_devman_bind(&uhci_instance->address_manager,
+	  address, port->attached_device);
+
+	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 );
+
+/*
+	port_status.status.enabled = enabled;
+	pio_write_16( port->address, port_status.raw_value );
+*/
+
+	uhci_print_info( "%s port %d.\n",
+	  enabled ? "Enabled" : "Disabled", port->number );
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+static int report_new_device(
+  device_t *hc, usb_address_t address, int hub_port, devman_handle_t *handle)
+{
+	assert( hc );
+	assert( address > 0 );
+	assert( address <= USB11_ADDRESS_MAX );
+
+	device_t *child = create_device();
+	if (child == NULL)
+		{ return ENOMEM; }
+
+	char *name;
+	int ret;
+
+	ret = asprintf( &name, "usbdevice on hc%p/%d/%#x", hc, hub_port, address );
+	if (ret < 0) {
+		uhci_print_error( "Failed to create device name.\n" );
+		delete_device( child );
+		return ret;
+	}
+	child->name = name;
+
+	/* TODO get and parse device descriptor */
+	const int vendor = 1;
+	const int product = 1;
+	const char* release = "unknown";
+	const char* class = "unknown";
+
+	/* create match ids TODO fix class printf*/
+	static const struct usb_match usb_matches[] = {
+	  { 100, "usb&vendor=%d&product=%d&release=%s" },
+	  {  90, "usb&vendor=%d&product=%d" },
+	  {  50, "usb&class=%d" },
+	  {   1, "usb&fallback" }
+	};
+
+	unsigned i = 0;
+	for (;i < sizeof( usb_matches )/ sizeof( struct usb_match ); ++i ) {
+		char *match_str;
+		const int ret = asprintf(
+		  &match_str, usb_matches[i].id_string, vendor, product, release, class );
+		if (ret < 0 ) {
+			uhci_print_error( "Failed to create matchid string.\n" );
+			delete_device( child );
+			return ret;
+		}
+		uhci_print_verbose( "Adding match id rule:%s\n", match_str );
+
+		match_id_t *id = create_match_id();
+		if (id == NULL) {
+			uhci_print_error( "Failed to create matchid.\n" );
+			delete_device( child );
+			free( match_str );
+			return ENOMEM;
+		}
+		id->id = match_str;
+		id->score = usb_matches[i].id_score;
+		add_match_id( &child->match_ids, id );
+
+		uhci_print_info( "Added match id, score: %d, string %s\n",
+		  id->score, id->id );
+	}
+
+	ret = child_device_register( child, hc );
+	if (ret < 0) {
+		uhci_print_error( "Failed to create device name.\n" );
+		delete_device( child );
+		return ret;
+	}
+
+	if (handle != NULL)
+		{ *handle = child->handle; }
+
+	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 value;
+	sync_init(&value);
+
+	uhci_setup(
+	  hc, new_device, USB_TRANSFER_CONTROL, &data, sizeof(data),
+		sync_out_callback, (void*)&value);
+	uhci_print_verbose("address assignment sent, waiting to complete.\n");
+
+	sync_wait_for(&value);
+	if (value.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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/root_hub/port.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/root_hub/port_status.c	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 ? "ON" : "OFF");
+	}
+}
Index: uspace/drv/uhci/root_hub/port_status.h
===================================================================
--- uspace/drv/uhci/root_hub/port_status.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/root_hub/port_status.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/root_hub/root_hub.c	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/root_hub/root_hub.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/td_ptr.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/transfer.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 a523af42844746625eb330a7a2ea4015969a83fd)
+++ 	(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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/uhci.c	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 a523af42844746625eb330a7a2ea4015969a83fd)
+++ uspace/drv/uhci/uhci.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/utils/fibril_semaphore.c	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/utils/fibril_semaphore.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/utils/hc_synchronizer.c	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -0,0 +1,32 @@
+#include "hc_synchronizer.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);
+}
Index: uspace/drv/uhci/utils/hc_synchronizer.h
===================================================================
--- uspace/drv/uhci/utils/hc_synchronizer.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/drv/uhci/utils/hc_synchronizer.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -0,0 +1,64 @@
+/*
+ * 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);
+#endif
+/**
+ * @}
+ */
Index: uspace/lib/usb/include/usb/addrkeep.h
===================================================================
--- uspace/lib/usb/include/usb/addrkeep.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
+++ uspace/lib/usb/include/usb/addrkeep.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 a523af42844746625eb330a7a2ea4015969a83fd)
+++ uspace/lib/usb/include/usb/devreq.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 a523af42844746625eb330a7a2ea4015969a83fd)
+++ uspace/lib/usb/include/usb/hcd.h	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -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 a523af42844746625eb330a7a2ea4015969a83fd)
+++ uspace/lib/usb/src/addrkeep.c	(revision 93fb170c39691e453743ec966fe97197a7ddbfd1)
@@ -33,5 +33,5 @@
  * @brief Address keeping.
  */
-#include <usb/hcd.h>
+#include <usb/addrkeep.h>
 #include <errno.h>
 #include <assert.h>
