Index: uspace/app/bdsh/cmds/modules/cat/cat.c
===================================================================
--- uspace/app/bdsh/cmds/modules/cat/cat.c	(revision 6265a2b2cf4693bc7c801083a14366ba3ee2fb15)
+++ uspace/app/bdsh/cmds/modules/cat/cat.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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 6265a2b2cf4693bc7c801083a14366ba3ee2fb15)
+++ uspace/app/bdsh/cmds/modules/rm/rm.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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 6265a2b2cf4693bc7c801083a14366ba3ee2fb15)
+++ uspace/drv/rootvirt/devices.def	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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 6265a2b2cf4693bc7c801083a14366ba3ee2fb15)
+++ uspace/drv/uhci/Makefile	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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 = \
+	callback.c \
+	iface.c \
 	main.c \
-	transfers.c
+	root_hub/port.c \
+	root_hub/port_status.c \
+	root_hub/root_hub.c \
+	transfer_list.c \
+	uhci.c 
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/drv/uhci/callback.c
===================================================================
--- uspace/drv/uhci/callback.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/callback.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -0,0 +1,27 @@
+#include <errno.h>
+
+#include "callback.h"
+
+
+int callback_init(callback_t *instance, device_t *dev,
+  void *buffer, size_t size, usbhc_iface_transfer_in_callback_t func_in,
+  usbhc_iface_transfer_out_callback_t func_out, void *arg)
+{
+	assert(instance);
+	assert(func_in == NULL || func_out == NULL);
+	instance->new_buffer = trans_malloc(size);
+	if (!instance->new_buffer) {
+		uhci_print_error("Failed to allocate device acessible buffer.\n");
+		return ENOMEM;
+	}
+
+	if (func_out)
+		memcpy(instance->new_buffer, buffer, size);
+
+	instance->callback_out = func_out;
+	instance->callback_in = func_in;
+	instance->old_buffer = buffer;
+	instance->buffer_size = size;
+	instance->dev = dev;
+	return EOK;
+}
Index: uspace/drv/uhci/callback.h
===================================================================
--- uspace/drv/uhci/callback.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/callback.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -0,0 +1,74 @@
+/*
+ * 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_CALLBACK_H
+#define DRV_UHCI_CALLBACK_H
+
+#include <mem.h>
+#include <usbhc_iface.h>
+
+#include "debug.h"
+#include "translating_malloc.h"
+
+typedef struct callback
+{
+	usbhc_iface_transfer_in_callback_t callback_in;
+	usbhc_iface_transfer_out_callback_t callback_out;
+	void *old_buffer;
+	void *new_buffer;
+	void *arg;
+	size_t buffer_size;
+	device_t *dev;
+} callback_t;
+
+
+int callback_init(callback_t *instance, device_t *dev,
+  void *buffer, size_t size, usbhc_iface_transfer_in_callback_t func_in,
+  usbhc_iface_transfer_out_callback_t func_out, void *arg);
+
+#define callback_in_init(instance, dev, buffer, size, func, arg) \
+	callback_init(instance, dev, buffer, size, func, NULL, arg)
+
+#define callback_out_init(instance, dev, buffer, size, func, arg) \
+	callback_init(instance, dev, buffer, size, func, NULL, arg)
+
+static inline void callback_fini(callback_t *instance)
+{
+	assert(instance);
+	if (instance->new_buffer)
+		trans_free(instance->new_buffer);
+}
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/debug.h
===================================================================
--- uspace/drv/uhci/debug.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/debug.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/iface.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/iface.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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/main.c
===================================================================
--- uspace/drv/uhci/main.c	(revision 6265a2b2cf4693bc7c801083a14366ba3ee2fb15)
+++ uspace/drv/uhci/main.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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");
+	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);
+	// TODO: get this value out of pci driver
+	uhci_init(device, (void*)0xc020);
 
 	return EOK;
@@ -80,5 +79,5 @@
 	 */
 	sleep(5);
-	usb_dprintf_enable(NAME, 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 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/name.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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/root_hub/port.c
===================================================================
--- uspace/drv/uhci/root_hub/port.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/root_hub/port.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -0,0 +1,127 @@
+
+#include <errno.h>
+//#include <usb/devreq.h> /* for usb_device_request_setup_packet_t */
+#include <usb/usb.h>
+#include <usb/usbdrv.h>
+
+#include "debug.h"
+#include "uhci.h"
+#include "port.h"
+#include "port_status.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);
+
+/*----------------------------------------------------------------------------*/
+int uhci_port_check(void *port)
+{
+	uhci_port_t *port_instance = port;
+	assert(port_instance);
+	port_instance->hc_phone = devman_device_connect(port_instance->hc->handle, 0);
+
+	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);
+
+	const usb_address_t usb_address =
+	  usb_address_keeping_request(&uhci_instance->address_manager);
+
+	if (usb_address <= 0) {
+		return usb_address;
+	}
+
+	/* enable port */
+	uhci_port_set_enabled(port, true);
+
+	/* assign address to device */
+	int ret = usb_drv_req_set_address(port->hc_phone, 0, usb_address);
+
+
+	if (ret != EOK) { /* address assigning went wrong */
+		uhci_print_error("Failed(%d) to assign address to the device.\n", ret);
+		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);
+
+	ret = usb_drv_register_child_in_devman(port->hc_phone, port->hc, usb_address,
+		&port->attached_device);
+
+	if (ret != EOK) { /* something went wrong */
+		uhci_print_error("Failed(%d) in usb_drv_register_child.\n", ret);
+		uhci_port_set_enabled(port, false);
+		return ENOMEM;
+	}
+
+	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;
+}
+/*----------------------------------------------------------------------------*/
Index: uspace/drv/uhci/root_hub/port.h
===================================================================
--- uspace/drv/uhci/root_hub/port.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/root_hub/port.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -0,0 +1,70 @@
+/*
+ * 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;
+	int hc_phone;
+	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->hc_phone = -1;
+	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 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/root_hub/port_status.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/root_hub/port_status.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/root_hub/root_hub.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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 seconds */
+
+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 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/root_hub/root_hub.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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/transfer_list.c
===================================================================
--- uspace/drv/uhci/transfer_list.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/transfer_list.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -0,0 +1,50 @@
+#include <errno.h>
+
+#include "transfer_list.h"
+
+int transfer_list_init(transfer_list_t *instance, transfer_list_t *next)
+{
+	assert(instance);
+	instance->first = NULL;
+	instance->last = NULL;
+	instance->queue_head = trans_malloc(sizeof(queue_head_t));
+	if (!instance->queue_head) {
+		uhci_print_error("Failed to allocate queue head.\n");
+		return ENOMEM;
+	}
+	instance->queue_head_pa = (uintptr_t)addr_to_phys(instance->queue_head);
+
+	uint32_t next_pa = next ? next->queue_head_pa : 0;
+	queue_head_init(instance->queue_head, next_pa);
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+int transfer_list_append(
+  transfer_list_t *instance, transfer_descriptor_t *transfer)
+{
+	assert(instance);
+	assert(transfer);
+
+	uint32_t pa = (uintptr_t)addr_to_phys(transfer);
+	assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
+
+	/* empty list */
+	if (instance->first == NULL) {
+		assert(instance->last == NULL);
+		instance->first = instance->last = transfer;
+	} else {
+		assert(instance->last);
+		instance->last->next_va = transfer;
+
+		assert(instance->last->next & LINK_POINTER_TERMINATE_FLAG);
+		instance->last->next = (pa & LINK_POINTER_ADDRESS_MASK);
+		instance->last = transfer;
+	}
+
+	assert(instance->queue_head);
+	if (instance->queue_head->element & LINK_POINTER_TERMINATE_FLAG) {
+		instance->queue_head->element = (pa & LINK_POINTER_ADDRESS_MASK);
+	}
+	uhci_print_info("Successfully added transfer to the hc queue.\n");
+	return EOK;
+}
Index: uspace/drv/uhci/transfer_list.h
===================================================================
--- uspace/drv/uhci/transfer_list.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/transfer_list.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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_TRANSFER_LIST_H
+#define DRV_UHCI_TRANSFER_LIST_H
+
+#include "debug.h"
+#include "translating_malloc.h"
+#include "uhci_struct/queue_head.h"
+#include "uhci_struct/transfer_descriptor.h"
+
+typedef struct transfer_list
+{
+	transfer_descriptor_t *first;
+	transfer_descriptor_t *last;
+	queue_head_t *queue_head;
+	uint32_t queue_head_pa;
+} transfer_list_t;
+
+int transfer_list_init(transfer_list_t *instance, transfer_list_t *next);
+
+static inline void transfer_list_fini(transfer_list_t *instance)
+{
+	assert(instance);
+	if (instance->queue_head)
+		trans_free(instance->queue_head);
+}
+
+int transfer_list_append(
+  transfer_list_t *instance, transfer_descriptor_t *transfer);
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/transfers.c
===================================================================
--- uspace/drv/uhci/transfers.c	(revision 6265a2b2cf4693bc7c801083a14366ba3ee2fb15)
+++ 	(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/translating_malloc.h
===================================================================
--- uspace/drv/uhci/translating_malloc.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/translating_malloc.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -0,0 +1,54 @@
+/*
+ * 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_TRANSLATOR_H
+#define DRV_UHCI_TRANSLATOR_H
+
+#include <malloc.h>
+
+static inline void * addr_to_phys( void *addr )
+	{ return addr; }
+
+static inline void * addr_to_virt( void *addr )
+	{ return addr; }
+
+static inline void * trans_malloc( size_t size )
+	{ return malloc( size ); }
+
+static inline void trans_free( void * addr )
+	{ free( addr ); }
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/uhci.c
===================================================================
--- uspace/drv/uhci/uhci.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/uhci.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -0,0 +1,245 @@
+#include <errno.h>
+#include <usb/debug.h>
+#include <usb/usb.h>
+
+#include "translating_malloc.h"
+
+#include "debug.h"
+#include "name.h"
+#include "uhci.h"
+
+static int uhci_init_transfer_lists(transfer_list_t list[]);
+static int uhci_clean_finished(void *arg);
+static inline int uhci_add_transfer(
+  device_t *dev,
+  usb_target_t target,
+  usb_transfer_type_t transfer_type,
+  usb_packet_id pid,
+  void *buffer, size_t size,
+  usbhc_iface_transfer_out_callback_t callback_out,
+  usbhc_iface_transfer_in_callback_t callback_in,
+  void *arg );
+
+int uhci_init(device_t *device, void *regs)
+{
+	assert(device);
+	uhci_print_info("Initializing device at address %p.\n", device);
+
+#define CHECK_RET_FREE_INSTANCE(message...) \
+	if (ret != EOK) { \
+		uhci_print_error(message); \
+		if (instance) { \
+			free(instance); \
+		} \
+		return ret; \
+	} else (void) 0
+
+	/* create instance */
+	uhci_t *instance = malloc( sizeof(uhci_t) );
+	int ret = instance ? EOK : ENOMEM;
+	CHECK_RET_FREE_INSTANCE("Failed to allocate uhci driver instance.\n");
+
+	bzero(instance, 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;
+	ret = pio_enable(regs, sizeof(regs_t), (void**)&io);
+	CHECK_RET_FREE_INSTANCE("Failed to gain access to registers at %p.\n", io);
+	instance->registers = io;
+
+	/* init transfer lists */
+	ret = uhci_init_transfer_lists(instance->transfers);
+	CHECK_RET_FREE_INSTANCE("Failed to initialize transfer lists.\n");
+
+	/* init root hub */
+	ret = uhci_root_hub_init(&instance->root_hub, device,
+	  (char*)regs + UHCI_ROOT_HUB_PORT_REGISTERS_OFFSET);
+	CHECK_RET_FREE_INSTANCE("Failed to initialize root hub driver.\n");
+
+	instance->frame_list =
+	  trans_malloc(sizeof(link_pointer_t) * UHCI_FRAME_LIST_COUNT);
+	if (instance->frame_list == NULL) {
+		uhci_print_error("Failed to allocate frame list pointer.\n");
+		uhci_root_hub_fini(&instance->root_hub);
+		free(instance);
+		return ENOMEM;
+	}
+
+	/* initialize all frames to point to the first queue head */
+	unsigned i = 0;
+	const uint32_t queue =
+	  instance->transfers[USB_TRANSFER_INTERRUPT].queue_head_pa
+	  | LINK_POINTER_QUEUE_HEAD_FLAG;
+	for(; i < UHCI_FRAME_LIST_COUNT; ++i) {
+		instance->frame_list[i] = queue;
+	}
+
+	const uintptr_t pa = (uintptr_t)addr_to_phys(instance->frame_list);
+
+	pio_write_32(&instance->registers->flbaseadd, (uint32_t)pa);
+
+	instance->cleaner = fibril_create(uhci_clean_finished, instance);
+	fibril_add_ready(instance->cleaner);
+
+	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 uhci_add_transfer(
+	  dev, target, transfer_type, USB_PID_IN, buffer, size, NULL, callback, 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
+  )
+{
+	uhci_print_info( "transfer OUT [%d.%d (%s); %zu]\n",
+	    target.address, target.endpoint,
+	    usb_str_transfer_type(transfer_type),
+	    size);
+	return uhci_add_transfer(
+	  dev, target, transfer_type, USB_PID_OUT, buffer, size, callback, NULL, 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
+  )
+{
+	uhci_print_info( "transfer SETUP [%d.%d (%s); %zu]\n",
+	    target.address, target.endpoint,
+	    usb_str_transfer_type(transfer_type),
+	    size);
+	uhci_print_info("Setup packet content: %x %x.\n", ((uint8_t*)buffer)[0],
+	  ((uint8_t*)buffer)[1]);
+	return uhci_add_transfer( dev,
+	  target, transfer_type, USB_PID_SETUP, buffer, size, callback, NULL, arg);
+
+}
+/*----------------------------------------------------------------------------*/
+int uhci_init_transfer_lists(transfer_list_t transfers[])
+{
+	//TODO:refactor
+	transfers[USB_TRANSFER_ISOCHRONOUS].first = NULL;
+	transfers[USB_TRANSFER_ISOCHRONOUS].last = NULL;
+
+	int ret;
+	ret = transfer_list_init(&transfers[USB_TRANSFER_BULK], NULL);
+	if (ret != EOK) {
+		uhci_print_error("Failed to initialize bulk queue.\n");
+		return ret;
+	}
+
+	ret = transfer_list_init(
+	  &transfers[USB_TRANSFER_CONTROL], &transfers[USB_TRANSFER_BULK]);
+	if (ret != EOK) {
+		uhci_print_error("Failed to initialize control queue.\n");
+		transfer_list_fini(&transfers[USB_TRANSFER_BULK]);
+		return ret;
+	}
+
+	ret = transfer_list_init(
+	  &transfers[USB_TRANSFER_INTERRUPT], &transfers[USB_TRANSFER_CONTROL]);
+	if (ret != EOK) {
+		uhci_print_error("Failed to initialize interrupt queue.\n");
+		transfer_list_fini(&transfers[USB_TRANSFER_CONTROL]);
+		transfer_list_fini(&transfers[USB_TRANSFER_BULK]);
+		return ret;
+	}
+
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+static inline int uhci_add_transfer(
+  device_t *dev,
+  usb_target_t target,
+  usb_transfer_type_t transfer_type,
+  usb_packet_id pid,
+  void *buffer, size_t size,
+  usbhc_iface_transfer_out_callback_t callback_out,
+  usbhc_iface_transfer_in_callback_t callback_in,
+  void *arg )
+{
+	// TODO: Add support for isochronous transfers
+	if (transfer_type == USB_TRANSFER_ISOCHRONOUS)
+		return ENOTSUP;
+
+	if (size >= 1024)
+		return ENOTSUP;
+
+	transfer_descriptor_t *td = NULL;
+	callback_t *job = NULL;
+	int ret = EOK;
+
+#define CHECK_RET_TRANS_FREE_JOB_TD(message) \
+	if (ret != EOK) { \
+		uhci_print_error(message); \
+		if (job) { \
+			callback_fini(job); \
+			trans_free(job); \
+		} \
+		if (td) { trans_free(td); } \
+		return ret; \
+	} else (void) 0
+
+
+	job = malloc(sizeof(callback_t));
+	ret= job ? EOK : ENOMEM;
+	CHECK_RET_TRANS_FREE_JOB_TD("Failed to allocate callback structure.\n");
+
+	ret = callback_init(job, dev, buffer, size, callback_in, callback_out, arg);
+	CHECK_RET_TRANS_FREE_JOB_TD("Failed to initialize callback structure.\n");
+
+	td = trans_malloc(sizeof(transfer_descriptor_t));
+	ret = td ? EOK : ENOMEM;
+	CHECK_RET_TRANS_FREE_JOB_TD("Failed to allocate transfer descriptor.\n");
+
+	ret = transfer_descriptor_init(td, 3, size, false, target, pid);
+	CHECK_RET_TRANS_FREE_JOB_TD("Failed to initialize transfer descriptor.\n");
+
+	td->callback = job;
+
+	assert(dev);
+	uhci_t *instance = (uhci_t*)dev->driver_data;
+	assert(instance);
+
+	ret = transfer_list_append(&instance->transfers[transfer_type], td);
+	CHECK_RET_TRANS_FREE_JOB_TD("Failed to append transfer descriptor.\n");
+
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+int uhci_clean_finished(void* arg)
+{
+	uhci_print_verbose("Started cleaning fibril.\n");
+	uhci_t *instance = (uhci_t*)arg;
+	assert(instance);
+	while(1) {
+		uhci_print_verbose("Running cleaning fibril on %p.\n", instance);
+
+		async_usleep(1000000);
+	}
+	return EOK;
+}
Index: uspace/drv/uhci/uhci.h
===================================================================
--- uspace/drv/uhci/uhci.h	(revision 6265a2b2cf4693bc7c801083a14366ba3ee2fb15)
+++ uspace/drv/uhci/uhci.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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,64 @@
 #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"
+#include "transfer_list.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;
+
+#define TRANSFER_QUEUES 4
+#define UHCI_FRAME_LIST_COUNT 1024
+
+typedef struct uhci {
+	usb_address_keeping_t address_manager;
+	uhci_root_hub_t root_hub;
+	volatile regs_t *registers;
+
+	link_pointer_t *frame_list;
+
+	transfer_list_t transfers[TRANSFER_QUEUES];
+	fid_t cleaner;
+} 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/uhci_struct/link_pointer.h
===================================================================
--- uspace/drv/uhci/uhci_struct/link_pointer.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/uhci_struct/link_pointer.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -0,0 +1,52 @@
+/*
+ * 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_POINTER_H
+#define DRV_UHCI_LINK_POINTER_H
+
+/* UHCI link pointer, used by many data structures */
+typedef uint32_t link_pointer_t;
+
+#define LINK_POINTER_TERMINATE_FLAG (1 << 0)
+#define LINK_POINTER_QUEUE_HEAD_FLAG (1 << 1)
+#define LINK_POINTER_ZERO_BIT_FLAG (1 << 2)
+#define LINK_POINTER_VERTICAL_FLAG (1 << 2)
+#define LINK_POINTER_RESERVED_FLAG (1 << 3)
+
+#define LINK_POINTER_ADDRESS_MASK 0xfffffff0 /* upper 28 bits */
+
+#endif
+/**
+ * @}
+ */
+
Index: uspace/drv/uhci/uhci_struct/queue_head.h
===================================================================
--- uspace/drv/uhci/uhci_struct/queue_head.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/uhci_struct/queue_head.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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_QH_H
+#define DRV_UHCI_QH_H
+
+#include <assert.h>
+
+#include "link_pointer.h"
+
+typedef struct queue_head {
+	link_pointer_t next_queue;
+	link_pointer_t element;
+} __attribute__((packed)) queue_head_t;
+
+static inline void queue_head_init(queue_head_t *instance, uint32_t next_queue_pa)
+{
+	assert(instance);
+	assert((next_queue_pa & LINK_POINTER_ADDRESS_MASK) == next_queue_pa);
+
+	instance->element = 0 | LINK_POINTER_TERMINATE_FLAG;
+	if (next_queue_pa) {
+		instance->next_queue = (next_queue_pa & LINK_POINTER_ADDRESS_MASK)
+		  | LINK_POINTER_QUEUE_HEAD_FLAG;
+	} else {
+		instance->next_queue = 0 | LINK_POINTER_TERMINATE_FLAG;
+	}
+}
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/uhci_struct/transfer_descriptor.h
===================================================================
--- uspace/drv/uhci/uhci_struct/transfer_descriptor.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/drv/uhci/uhci_struct/transfer_descriptor.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -0,0 +1,134 @@
+/*
+ * 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_DESCRIPTOR_H
+#define DRV_UHCI_TRANSFER_DESCRIPTOR_H
+
+#include <mem.h>
+#include <usb/usb.h>
+
+#include "translating_malloc.h"
+#include "callback.h"
+#include "link_pointer.h"
+
+/** UHCI Transfer Descriptor */
+typedef struct transfer_descriptor {
+	link_pointer_t next;
+
+	uint32_t status;
+
+#define TD_STATUS_RESERVED_MASK 0xc000f800
+#define TD_STATUS_SPD_FLAG ( 1 << 29 )
+#define TD_STATUS_ERROR_COUNT_POS ( 27 )
+#define TD_STATUS_ERROR_COUNT_MASK ( 0x11 )
+#define TD_STATUS_ERROR_COUNT_DEFAULT 3
+#define TD_STATUS_LOW_SPEED_FLAG ( 1 << 26 )
+#define TD_STATUS_ISOCHRONOUS_FLAG ( 1 << 25 )
+#define TD_STATUS_COMPLETE_INTERRUPT_FLAG ( 1 << 24 )
+
+#define TD_STATUS_ACTIVE ( 1 << 23 )
+#define TD_STATUS_ERROR_STALLED ( 1 << 22 )
+#define TD_STATUS_ERROR_BUFFER ( 1 << 21 )
+#define TD_STATUS_ERROR_BABBLE ( 1 << 20 )
+#define TD_STATUS_ERROR_NAK ( 1 << 19 )
+#define TD_STATUS_ERROR_CRC ( 1 << 18 )
+#define TD_STATUS_ERROR_BIT_STUFF ( 1 << 17 )
+#define TD_STATUS_ERROR_RESERVED ( 1 << 16 )
+#define TD_STATUS_POS 16
+#define TD_STATUS_MASK ( 0xff )
+
+#define TD_STATUS_ACTLEN_POS 0
+#define TD_STATUS_ACTLEN_MASK 0x7ff
+
+	uint32_t device;
+
+#define TD_DEVICE_MAXLEN_POS 21
+#define TD_DEVICE_MAXLEN_MASK ( 0x7ff )
+#define TD_DEVICE_RESERVED_FLAG ( 1 << 20 )
+#define TD_DEVICE_DATA_TOGGLE_ONE_FLAG ( 1 << 19 )
+#define TD_DEVICE_ENDPOINT_POS 15
+#define TD_DEVICE_ENDPOINT_MASK ( 0xf )
+#define TD_DEVICE_ADDRESS_POS 8
+#define TD_DEVICE_ADDRESS_MASK ( 0x7f )
+#define TD_DEVICE_PID_POS 0
+#define TD_DEVICE_PID_MASK ( 0xff )
+
+	uint32_t buffer_ptr;
+
+	/* there is 16 byte of data available here
+	 * those are used to store callback pointer
+	 * and next pointer. Thus there is some free space
+	 * on 32bits systems.
+	 */
+	struct transfer_descriptor *next_va;
+	callback_t *callback;
+} __attribute__((packed)) transfer_descriptor_t;
+
+static inline int transfer_descriptor_init(transfer_descriptor_t *instance,
+  int error_count, size_t size, bool isochronous, usb_target_t target,
+	int pid)
+{
+	assert(instance);
+
+	instance->next =
+	  0 | LINK_POINTER_VERTICAL_FLAG | LINK_POINTER_TERMINATE_FLAG;
+
+	assert(size < 1024);
+	instance->status = 0
+	  | ((error_count & TD_STATUS_ERROR_COUNT_MASK) << TD_STATUS_ERROR_COUNT_POS)
+	  | TD_STATUS_ACTIVE;
+
+	instance->device = 0
+		| ((size & TD_DEVICE_MAXLEN_MASK) << TD_DEVICE_MAXLEN_POS)
+		| ((target.address & TD_DEVICE_ADDRESS_MASK) << TD_DEVICE_ADDRESS_POS)
+		| ((target.endpoint & TD_DEVICE_ENDPOINT_MASK) << TD_DEVICE_ENDPOINT_POS)
+		| ((pid & TD_DEVICE_PID_MASK) << TD_DEVICE_PID_POS);
+
+	instance->next_va = NULL;
+	instance->callback = NULL;
+
+	return EOK;
+}
+
+static inline void transfer_descriptor_append(
+  transfer_descriptor_t *instance, transfer_descriptor_t *item)
+{
+	assert(instance);
+	instance->next_va = item;
+	instance->next = (uintptr_t)addr_to_phys( item ) & LINK_POINTER_ADDRESS_MASK;
+}
+
+#endif
+/**
+ * @}
+ */
Index: uspace/lib/usb/include/usb/addrkeep.h
===================================================================
--- uspace/lib/usb/include/usb/addrkeep.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
+++ uspace/lib/usb/include/usb/addrkeep.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -0,0 +1,1 @@
+hcd.h
Index: uspace/lib/usb/include/usb/devreq.h
===================================================================
--- uspace/lib/usb/include/usb/devreq.h	(revision 6265a2b2cf4693bc7c801083a14366ba3ee2fb15)
+++ uspace/lib/usb/include/usb/devreq.h	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -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/src/addrkeep.c
===================================================================
--- uspace/lib/usb/src/addrkeep.c	(revision 6265a2b2cf4693bc7c801083a14366ba3ee2fb15)
+++ uspace/lib/usb/src/addrkeep.c	(revision 7fc092aa97e8ab15728e29fd3aa1ab61ca8620a3)
@@ -33,5 +33,5 @@
  * @brief Address keeping.
  */
-#include <usb/hcd.h>
+#include <usb/addrkeep.h>
 #include <errno.h>
 #include <assert.h>
