Index: uspace/drv/bus/usb/ehci/Makefile
===================================================================
--- uspace/drv/bus/usb/ehci/Makefile	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ehci/Makefile	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -31,4 +31,5 @@
 LIBS = \
 	$(LIBUSBHOST_PREFIX)/libusbhost.a \
+	$(LIBUSBVIRT_PREFIX)/libusbvirt.a \
 	$(LIBUSB_PREFIX)/libusb.a \
 	$(LIBDRV_PREFIX)/libdrv.a
@@ -36,5 +37,7 @@
 EXTRA_CFLAGS += \
 	-I$(LIBUSB_PREFIX)/include \
+	-I$(LIBUSBDEV_PREFIX)/include \
 	-I$(LIBUSBHOST_PREFIX)/include \
+	-I$(LIBUSBVIRT_PREFIX)/include \
 	-I$(LIBDRV_PREFIX)/include
 
@@ -42,4 +45,11 @@
 
 SOURCES = \
+	ehci_batch.c \
+	ehci_endpoint.c \
+	ehci_rh.c \
+	endpoint_list.c \
+	hc.c \
+	hw_struct/queue_head.c \
+	hw_struct/transfer_descriptor.c \
 	main.c \
 	res.c
Index: uspace/drv/bus/usb/ehci/ehci_batch.c
===================================================================
--- uspace/drv/bus/usb/ehci/ehci_batch.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/ehci_batch.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,398 @@
+/*
+ * Copyright (c) 2014 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver USB transaction structure
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <macros.h>
+#include <mem.h>
+#include <stdbool.h>
+
+#include <usb/usb.h>
+#include <usb/debug.h>
+
+#include "ehci_batch.h"
+#include "ehci_endpoint.h"
+#include "utils/malloc32.h"
+
+/* The buffer pointer list in the qTD is long enough to support a maximum
+ * transfer size of 20K bytes. This case occurs when all five buffer pointers
+ * are used and the first offset is zero. A qTD handles a 16Kbyte buffer
+ * with any starting buffer alignment. EHCI specs p. 87 (pdf p. 97) */
+#define EHCI_TD_MAX_TRANSFER   (16 * 1024)
+
+static void (*const batch_setup[])(ehci_transfer_batch_t*, usb_direction_t);
+
+/** Safely destructs ehci_transfer_batch_t structure
+ *
+ * @param[in] ehci_batch Instance to destroy.
+ */
+static void ehci_transfer_batch_dispose(ehci_transfer_batch_t *ehci_batch)
+{
+	if (!ehci_batch)
+		return;
+	if (ehci_batch->tds) {
+		const ehci_endpoint_t *ehci_ep =
+		    ehci_endpoint_get(ehci_batch->usb_batch->ep);
+		assert(ehci_ep);
+		for (size_t i = 0; i < ehci_batch->td_count; ++i) {
+			free32(ehci_batch->tds[i]);
+		}
+		free(ehci_batch->tds);
+	}
+	usb_transfer_batch_destroy(ehci_batch->usb_batch);
+	free32(ehci_batch->device_buffer);
+	free(ehci_batch);
+}
+
+/** Finishes usb_transfer_batch and destroys the structure.
+ *
+ * @param[in] uhci_batch Instance to finish and destroy.
+ */
+void ehci_transfer_batch_finish_dispose(ehci_transfer_batch_t *ehci_batch)
+{
+	assert(ehci_batch);
+	assert(ehci_batch->usb_batch);
+	usb_transfer_batch_finish(ehci_batch->usb_batch,
+	    ehci_batch->device_buffer + ehci_batch->usb_batch->setup_size);
+	ehci_transfer_batch_dispose(ehci_batch);
+}
+
+/** Allocate memory and initialize internal data structure.
+ *
+ * @param[in] usb_batch Pointer to generic USB batch structure.
+ * @return Valid pointer if all structures were successfully created,
+ * NULL otherwise.
+ *
+ * Determines the number of needed transfer descriptors (TDs).
+ * Prepares a transport buffer (that is accessible by the hardware).
+ * Initializes parameters needed for the transfer and callback.
+ */
+ehci_transfer_batch_t * ehci_transfer_batch_get(usb_transfer_batch_t *usb_batch)
+{
+	assert(usb_batch);
+
+	ehci_transfer_batch_t *ehci_batch =
+	    calloc(1, sizeof(ehci_transfer_batch_t));
+	if (!ehci_batch) {
+		usb_log_error("Failed to allocate EHCI batch data.");
+		goto dispose;
+	}
+	link_initialize(&ehci_batch->link);
+	ehci_batch->td_count =
+	    (usb_batch->buffer_size + EHCI_TD_MAX_TRANSFER - 1)
+	    / EHCI_TD_MAX_TRANSFER;
+
+	/* Control transfer need Setup and Status stage */
+	if (usb_batch->ep->transfer_type == USB_TRANSFER_CONTROL) {
+		ehci_batch->td_count += 2;
+	}
+
+	ehci_batch->tds = calloc(ehci_batch->td_count, sizeof(td_t*));
+	if (!ehci_batch->tds) {
+		usb_log_error("Failed to allocate EHCI transfer descriptors.");
+		goto dispose;
+	}
+
+	/* Add TD left over by the previous transfer */
+	ehci_batch->qh = ehci_endpoint_get(usb_batch->ep)->qh;
+
+	for (unsigned i = 0; i < ehci_batch->td_count; ++i) {
+		ehci_batch->tds[i] = malloc32(sizeof(td_t));
+		if (!ehci_batch->tds[i]) {
+			usb_log_error("Failed to allocate TD %d.", i);
+			goto dispose;
+		}
+	}
+
+
+	/* Mix setup stage and data together, we have enough space */
+        if (usb_batch->setup_size + usb_batch->buffer_size > 0) {
+		/* Use one buffer for setup and data stage */
+		ehci_batch->device_buffer =
+		    malloc32(usb_batch->setup_size + usb_batch->buffer_size);
+		if (!ehci_batch->device_buffer) {
+			usb_log_error("Failed to allocate device buffer");
+			goto dispose;
+		}
+		/* Copy setup data */
+                memcpy(ehci_batch->device_buffer, usb_batch->setup_buffer,
+		    usb_batch->setup_size);
+		/* Copy generic data */
+		if (usb_batch->ep->direction != USB_DIRECTION_IN)
+			memcpy(
+			    ehci_batch->device_buffer + usb_batch->setup_size,
+			    usb_batch->buffer, usb_batch->buffer_size);
+        }
+	ehci_batch->usb_batch = usb_batch;
+
+	const usb_direction_t dir = usb_transfer_batch_direction(usb_batch);
+	assert(batch_setup[usb_batch->ep->transfer_type]);
+	batch_setup[usb_batch->ep->transfer_type](ehci_batch, dir);
+
+	return ehci_batch;
+dispose:
+	ehci_transfer_batch_dispose(ehci_batch);
+	return NULL;
+}
+
+/** Check batch TDs' status.
+ *
+ * @param[in] ehci_batch Batch structure to use.
+ * @return False, if there is an active TD, true otherwise.
+ *
+ * Walk all TDs (usually there is just one). Stop with false if there is an
+ * active TD. Stop with true if an error is found. Return true if the walk
+ * completes with the last TD.
+ */
+bool ehci_transfer_batch_is_complete(const ehci_transfer_batch_t *ehci_batch)
+{
+	assert(ehci_batch);
+	assert(ehci_batch->usb_batch);
+
+	usb_log_debug("Batch %p checking %zu td(s) for completion.\n",
+	    ehci_batch->usb_batch, ehci_batch->td_count);
+
+	usb_log_debug2("QH: %08x:%08x:%08x:%08x:%08x:%08x.\n",
+	    ehci_batch->qh->ep_char, ehci_batch->qh->ep_cap,
+	    ehci_batch->qh->status, ehci_batch->qh->current,
+	    ehci_batch->qh->next, ehci_batch->qh->alternate);
+
+	if (!qh_halted(ehci_batch->qh) && (qh_transfer_pending(ehci_batch->qh)
+	    || qh_transfer_active(ehci_batch->qh)))
+		return false;
+
+	/* Now we may be sure that either the ED is inactive because of errors
+	 * or all transfer descriptors completed successfully */
+
+	/* Assume all data got through */
+	ehci_batch->usb_batch->transfered_size =
+	    ehci_batch->usb_batch->buffer_size;
+
+	/* Check all TDs */
+	for (size_t i = 0; i < ehci_batch->td_count; ++i) {
+		assert(ehci_batch->tds[i] != NULL);
+		usb_log_debug("TD %zu: %08x:%08x:%08x.", i,
+		    ehci_batch->tds[i]->status, ehci_batch->tds[i]->next,
+		    ehci_batch->tds[i]->alternate);
+
+		ehci_batch->usb_batch->error = td_error(ehci_batch->tds[i]);
+		if (ehci_batch->usb_batch->error == EOK) {
+			/* If the TD got all its data through, it will report
+			 * 0 bytes remain, the sole exception is INPUT with
+			 * data rounding flag (short), i.e. every INPUT.
+			 * Nice thing is that short packets will correctly
+			 * report remaining data, thus making this computation
+			 * correct (short packets need to be produced by the
+			 * last TD)
+			 * NOTE: This also works for CONTROL transfer as
+			 * the first TD will return 0 remain.
+			 * NOTE: Short packets don't break the assumption that
+			 * we leave the very last(unused) TD behind.
+			 */
+			ehci_batch->usb_batch->transfered_size
+			    -= td_remain_size(ehci_batch->tds[i]);
+		} else {
+			usb_log_debug("Batch %p found error TD(%zu):%08x.\n",
+			    ehci_batch->usb_batch, i,
+			    ehci_batch->tds[i]->status);
+			/* Clear possible ED HALT */
+			qh_clear_halt(ehci_batch->qh);
+			break;
+		}
+	}
+
+	assert(ehci_batch->usb_batch->transfered_size <=
+	    ehci_batch->usb_batch->buffer_size);
+	/* Clear TD pointers */
+	ehci_batch->qh->next = LINK_POINTER_TERM;
+	ehci_batch->qh->current = LINK_POINTER_TERM;
+
+	return true;
+}
+
+/** Starts execution of the TD list
+ *
+ * @param[in] ehci_batch Batch structure to use
+ */
+void ehci_transfer_batch_commit(const ehci_transfer_batch_t *ehci_batch)
+{
+	assert(ehci_batch);
+	qh_set_next_td(ehci_batch->qh, ehci_batch->tds[0]);
+}
+
+/** Prepare generic control transfer
+ *
+ * @param[in] ehci_batch Batch structure to use.
+ * @param[in] dir Communication direction
+ *
+ * Setup stage with toggle 0 and direction BOTH(SETUP_PID)
+ * Data stage with alternating toggle and direction supplied by parameter.
+ * Status stage with toggle 1 and direction supplied by parameter.
+ */
+static void batch_control(ehci_transfer_batch_t *ehci_batch, usb_direction_t dir)
+{
+	assert(ehci_batch);
+	assert(ehci_batch->usb_batch);
+	assert(dir == USB_DIRECTION_IN || dir == USB_DIRECTION_OUT);
+
+	usb_log_debug2("Control QH(%"PRIxn"): %08x:%08x:%08x:%08x:%08x:%08x",
+	    addr_to_phys(ehci_batch->qh),
+	    ehci_batch->qh->ep_char, ehci_batch->qh->ep_cap,
+	    ehci_batch->qh->status, ehci_batch->qh->current,
+	    ehci_batch->qh->next, ehci_batch->qh->alternate);
+	static const usb_direction_t reverse_dir[] = {
+		[USB_DIRECTION_IN]  = USB_DIRECTION_OUT,
+		[USB_DIRECTION_OUT] = USB_DIRECTION_IN,
+	};
+
+	int toggle = 0;
+	const char* buffer = ehci_batch->device_buffer;
+	const usb_direction_t data_dir = dir;
+	const usb_direction_t status_dir = reverse_dir[dir];
+
+	/* Setup stage */
+	td_init(
+	    ehci_batch->tds[0], ehci_batch->tds[1], USB_DIRECTION_BOTH,
+	    buffer, ehci_batch->usb_batch->setup_size, toggle, false);
+	usb_log_debug2("Created CONTROL SETUP TD(%"PRIxn"): %08x:%08x:%08x",
+	    addr_to_phys(ehci_batch->tds[0]),
+	    ehci_batch->tds[0]->status, ehci_batch->tds[0]->next,
+	    ehci_batch->tds[0]->alternate);
+	buffer += ehci_batch->usb_batch->setup_size;
+
+	/* Data stage */
+	size_t td_current = 1;
+	size_t remain_size = ehci_batch->usb_batch->buffer_size;
+	while (remain_size > 0) {
+		const size_t transfer_size =
+		    min(remain_size, EHCI_TD_MAX_TRANSFER);
+		toggle = 1 - toggle;
+
+		td_init(ehci_batch->tds[td_current],
+		    ehci_batch->tds[td_current + 1], data_dir, buffer,
+		    transfer_size, toggle, false);
+		usb_log_debug2("Created CONTROL DATA TD(%"PRIxn"): %08x:%08x:%08x",
+		    addr_to_phys(ehci_batch->tds[td_current]),
+		    ehci_batch->tds[td_current]->status,
+		    ehci_batch->tds[td_current]->next,
+		    ehci_batch->tds[td_current]->alternate);
+
+		buffer += transfer_size;
+		remain_size -= transfer_size;
+		assert(td_current < ehci_batch->td_count - 1);
+		++td_current;
+	}
+
+	/* Status stage */
+	assert(td_current == ehci_batch->td_count - 1);
+	td_init(ehci_batch->tds[td_current], NULL, status_dir, NULL, 0, 1, true);
+	usb_log_debug2("Created CONTROL STATUS TD(%"PRIxn"): %08x:%08x:%08x",
+	    addr_to_phys(ehci_batch->tds[td_current]),
+	    ehci_batch->tds[td_current]->status,
+	    ehci_batch->tds[td_current]->next,
+	    ehci_batch->tds[td_current]->alternate);
+
+	usb_log_debug(
+	    "Batch %p %s %s " USB_TRANSFER_BATCH_FMT " initialized.\n", \
+	    ehci_batch->usb_batch,
+	    usb_str_transfer_type(ehci_batch->usb_batch->ep->transfer_type),
+	    usb_str_direction(dir),
+	    USB_TRANSFER_BATCH_ARGS(*ehci_batch->usb_batch));
+}
+
+/** Prepare generic data transfer
+ *
+ * @param[in] ehci_batch Batch structure to use.
+ * @paramp[in] dir Communication direction.
+ *
+ * Direction is supplied by the associated ep and toggle is maintained by the
+ * EHCI hw in ED.
+ */
+static void batch_data(ehci_transfer_batch_t *ehci_batch, usb_direction_t dir)
+{
+	assert(ehci_batch);
+	assert(ehci_batch->usb_batch);
+	assert(dir == USB_DIRECTION_IN || dir == USB_DIRECTION_OUT);
+
+	usb_log_debug("Control QH(%"PRIxn"): %08x:%08x:%08x:%08x:%08x:%08x",
+	    addr_to_phys(ehci_batch->qh),
+	    ehci_batch->qh->ep_char, ehci_batch->qh->ep_cap,
+	    ehci_batch->qh->status, ehci_batch->qh->current,
+	    ehci_batch->qh->next, ehci_batch->qh->alternate);
+
+	size_t td_current = 0;
+	size_t remain_size = ehci_batch->usb_batch->buffer_size;
+	char *buffer = ehci_batch->device_buffer;
+	while (remain_size > 0) {
+		const size_t transfer_size = remain_size > EHCI_TD_MAX_TRANSFER
+		    ? EHCI_TD_MAX_TRANSFER : remain_size;
+
+		const bool last = (remain_size == transfer_size);
+		td_init(
+		    ehci_batch->tds[td_current],
+		    last ? NULL : ehci_batch->tds[td_current + 1],
+		    dir, buffer, transfer_size, -1, last);
+
+		usb_log_debug2("Created DATA TD(%"PRIxn": %08x:%08x:%08x",
+		    addr_to_phys(ehci_batch->tds[td_current]),
+		    ehci_batch->tds[td_current]->status,
+		    ehci_batch->tds[td_current]->next,
+		    ehci_batch->tds[td_current]->alternate);
+
+		buffer += transfer_size;
+		remain_size -= transfer_size;
+		assert(td_current < ehci_batch->td_count);
+		++td_current;
+	}
+
+	usb_log_debug(
+	    "Batch %p %s %s " USB_TRANSFER_BATCH_FMT " initialized",
+	    ehci_batch->usb_batch,
+	    usb_str_transfer_type(ehci_batch->usb_batch->ep->transfer_type),
+	    usb_str_direction(dir),
+	    USB_TRANSFER_BATCH_ARGS(*ehci_batch->usb_batch));
+}
+
+/** Transfer setup table. */
+static void (*const batch_setup[])(ehci_transfer_batch_t*, usb_direction_t) =
+{
+	[USB_TRANSFER_CONTROL] = batch_control,
+	[USB_TRANSFER_BULK] = batch_data,
+	[USB_TRANSFER_INTERRUPT] = batch_data,
+	[USB_TRANSFER_ISOCHRONOUS] = NULL,
+};
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/ehci_batch.h
===================================================================
--- uspace/drv/bus/usb/ehci/ehci_batch.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/ehci_batch.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2014 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver USB transaction structure
+ */
+#ifndef DRV_EHCI_BATCH_H
+#define DRV_EHCI_BATCH_H
+
+#include <adt/list.h>
+#include <assert.h>
+#include <stdbool.h>
+#include <usb/host/usb_transfer_batch.h>
+
+#include "hw_struct/queue_head.h"
+#include "hw_struct/transfer_descriptor.h"
+
+/** EHCI specific data required for USB transfer */
+typedef struct ehci_transfer_batch {
+	/** Link */
+	link_t link;
+	/** Endpoint descriptor of the target endpoint. */
+	qh_t *qh;
+	/** List of TDs needed for the transfer */
+	td_t **tds;
+	/** Number of TDs used by the transfer */
+	size_t td_count;
+	/** Data buffer, must be accessible by the EHCI hw. */
+	char *device_buffer;
+	/** Generic USB transfer structure */
+	usb_transfer_batch_t *usb_batch;
+} ehci_transfer_batch_t;
+
+ehci_transfer_batch_t * ehci_transfer_batch_get(usb_transfer_batch_t *batch);
+bool ehci_transfer_batch_is_complete(const ehci_transfer_batch_t *batch);
+void ehci_transfer_batch_commit(const ehci_transfer_batch_t *batch);
+void ehci_transfer_batch_finish_dispose(ehci_transfer_batch_t *batch);
+
+static inline ehci_transfer_batch_t *ehci_transfer_batch_from_link(link_t *l)
+{
+	assert(l);
+	return list_get_instance(l, ehci_transfer_batch_t, link);
+}
+#endif
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/ehci_endpoint.c
===================================================================
--- uspace/drv/bus/usb/ehci/ehci_endpoint.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/ehci_endpoint.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2014 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <usb/debug.h>
+
+#include "utils/malloc32.h"
+#include "ehci_endpoint.h"
+#include "hc.h"
+
+/** Callback to set toggle on ED.
+ *
+ * @param[in] hcd_ep hcd endpoint structure
+ * @param[in] toggle new value of toggle bit
+ */
+static void ehci_ep_toggle_set(void *ehci_ep, int toggle)
+{
+	ehci_endpoint_t *instance = ehci_ep;
+	assert(instance);
+	assert(instance->qh);
+	if (qh_toggle_from_td(instance->qh))
+		usb_log_warning("Setting toggle bit for transfer directed EP\n");
+	qh_toggle_set(instance->qh, toggle);
+}
+
+/** Callback to get value of toggle bit.
+ *
+ * @param[in] hcd_ep hcd endpoint structure
+ * @return Current value of toggle bit.
+ */
+static int ehci_ep_toggle_get(void *ehci_ep)
+{
+	ehci_endpoint_t *instance = ehci_ep;
+	assert(instance);
+	assert(instance->qh);
+	if (qh_toggle_from_td(instance->qh))
+		usb_log_warning("Reading useless toggle bit\n");
+	return qh_toggle_get(instance->qh);
+}
+
+/** Creates new hcd endpoint representation.
+ *
+ * @param[in] ep USBD endpoint structure
+ * @return Error code.
+ */
+int ehci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
+{
+	assert(ep);
+	ehci_endpoint_t *ehci_ep = malloc(sizeof(ehci_endpoint_t));
+	if (ehci_ep == NULL)
+		return ENOMEM;
+
+	ehci_ep->qh = malloc32(sizeof(qh_t));
+	if (ehci_ep->qh == NULL) {
+		free(ehci_ep);
+		return ENOMEM;
+	}
+
+	link_initialize(&ehci_ep->link);
+	qh_init(ehci_ep->qh, ep);
+	endpoint_set_hc_data(
+	    ep, ehci_ep, ehci_ep_toggle_get, ehci_ep_toggle_set);
+	hc_enqueue_endpoint(hcd->driver.data, ep);
+	return EOK;
+}
+
+/** Disposes hcd endpoint structure
+ *
+ * @param[in] hcd driver using this instance.
+ * @param[in] ep endpoint structure.
+ */
+void ehci_endpoint_fini(hcd_t *hcd, endpoint_t *ep)
+{
+	assert(hcd);
+	assert(ep);
+	ehci_endpoint_t *instance = ehci_endpoint_get(ep);
+	hc_dequeue_endpoint(hcd->driver.data, ep);
+	endpoint_clear_hc_data(ep);
+	if (instance) {
+		free32(instance->qh);
+		free(instance);
+	}
+}
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/ehci_endpoint.h
===================================================================
--- uspace/drv/bus/usb/ehci/ehci_endpoint.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/ehci_endpoint.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2011 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+#ifndef DRV_EHCI_HCD_ENDPOINT_H
+#define DRV_EHCI_HCD_ENDPOINT_H
+
+#include <assert.h>
+#include <adt/list.h>
+#include <usb/host/endpoint.h>
+#include <usb/host/hcd.h>
+
+#include "hw_struct/queue_head.h"
+#include "hw_struct/transfer_descriptor.h"
+
+/** Connector structure linking ED to to prepared TD. */
+typedef struct ehci_endpoint {
+	/** EHCI endpoint descriptor */
+	qh_t *qh;
+	/** Linked list used by driver software */
+	link_t link;
+} ehci_endpoint_t;
+
+int ehci_endpoint_init(hcd_t *hcd, endpoint_t *ep);
+void ehci_endpoint_fini(hcd_t *hcd, endpoint_t *ep);
+
+/** Get and convert assigned ehci_endpoint_t structure
+ * @param[in] ep USBD endpoint structure.
+ * @return Pointer to assigned hcd endpoint structure
+ */
+static inline ehci_endpoint_t * ehci_endpoint_get(const endpoint_t *ep)
+{
+	assert(ep);
+	return ep->hc_data.data;
+}
+
+static inline ehci_endpoint_t * ehci_endpoint_list_instance(link_t *l)
+{
+	return list_get_instance(l, ehci_endpoint_t, link);
+}
+
+#endif
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/ehci_regs.h
===================================================================
--- uspace/drv/bus/usb/ehci/ehci_regs.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/ehci_regs.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2013 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI host controller register structure
+ */
+#ifndef DRV_EHCI_EHCI_REGS_H
+#define DRV_EHCI_EHCI_REGS_H
+#include <sys/types.h>
+#include <byteorder.h>
+#include <macros.h>
+#include <ddi.h>
+
+#define EHCI_WR(reg, val) pio_write_32(&(reg), host2uint32_t_le(val))
+#define EHCI_RD(reg) uint32_t_le2host(pio_read_32(&(reg)))
+#define EHCI_RD8(reg) pio_read_8(&(reg))
+#define EHCI_SET(reg, val) pio_set_32(&(reg), host2uint32_t_le(val), 10)
+#define EHCI_CLR(reg, val) pio_clear_32(&(reg), host2uint32_t_le(val), 10)
+
+/** EHCI memory mapped capability registers structure */
+typedef struct ehci_cap_regs {
+	const ioport8_t caplength;
+	PADD8;
+	const ioport16_t hciversion;
+	const ioport32_t hcsparams;
+#define EHCI_CAPS_HCS_DEBUG_PORT_MASK   0xf
+#define EHCI_CAPS_HCS_DEBUG_PORT_SHIFT  (1 << 20)
+#define EHCI_CAPS_HCS_INDICATORS_FLAG   (1 << 16)
+#define EHCI_CAPS_HCS_N_CC_MASK         0xf
+#define EHCI_CAPS_HCS_N_CC_SHIFT        12
+#define EHCI_CAPS_HCS_N_PCC_MASK        0xf
+#define EHCI_CAPS_HCS_N_PCC_SHIFT       8
+#define EHCI_CAPS_HCS_ROUTING_FLAG      (1 << 7)
+#define EHCI_CAPS_HCS_PPC_FLAG          (1 << 4)
+#define EHCI_CAPS_HCS_N_PORTS_MASK      0xf
+#define EHCI_CAPS_HCS_N_PORTS_SHIFT     0
+
+	const ioport32_t hccparams;
+#define EHCI_CAPS_HCC_EECP_MASK           0xff
+#define EHCI_CAPS_HCC_EECP_SHIFT          8
+#define EHCI_CAPS_HCC_ISO_THRESHOLD_MASK  0xf
+#define EHCI_CAPS_HCC_ISO_THRESHOLD_SHIFT 4
+#define EHCI_CAPS_HCC_ASYNC_PART_FLAG     (1 << 2)
+#define EHCI_CAPS_HCC_PROG_FRAME_FLAG     (1 << 1)
+#define EHCI_CAPS_HCC_64_FLAG             (1 << 0)
+	ioport8_t hcsp_portoute[8];
+
+} ehci_caps_regs_t;
+
+
+/** EHCI memory mapped operational registers structure */
+typedef struct ehci_regs {
+	ioport32_t usbcmd;
+#define USB_CMD_INT_THRESHOLD_MASK     0xff
+#define USB_CMD_INT_THRESHOLD_SHIFT    16
+#define USB_CMD_PARK_MODE_FLAG         (1 << 11)
+#define USB_CMD_PARK_COUNT_MASK        0x3
+#define USB_CMD_PARK_COUNT_SHIFT       8
+#define USB_CMD_LIGHT_RESET            (1 << 7)
+#define USB_CMD_IRQ_ASYNC_DOORBELL     (1 << 6)
+#define USB_CMD_ASYNC_SCHEDULE_FLAG    (1 << 5)
+#define USB_CMD_PERIODIC_SCHEDULE_FLAG (1 << 4)
+#define USB_CMD_FRAME_LIST_SIZE_MASK   0x3
+#define USB_CMD_FRAME_LIST_SIZE_SHIFT  2
+#define USB_CMD_FRAME_LIST_SIZE_1024   0x0
+#define USB_CMD_FRAME_LIST_SIZE_512    0x1
+#define USB_CMD_FRAME_LIST_SIZE_256    0x2
+#define USB_CMD_HC_RESET_FLAG          (1 << 1)
+#define USB_CMD_RUN_FLAG               (1 << 0)
+
+	ioport32_t usbsts;
+#define USB_STS_ASYNC_SCHED_FLAG         (1 << 15)
+#define USB_STS_PERIODIC_SCHED_FLAG      (1 << 14)
+#define USB_STS_RECLAMATION_FLAG         (1 << 13)
+#define USB_STS_HC_HALTED_FLAG           (1 << 12)
+#define USB_STS_IRQ_ASYNC_ADVANCE_FLAG   (1 <<  5)
+#define USB_STS_HOST_ERROR_FLAG          (1 <<  4)
+#define USB_STS_FRAME_ROLLOVER_FLAG      (1 <<  3)
+#define USB_STS_PORT_CHANGE_FLAG         (1 <<  2)
+#define USB_STS_ERR_IRQ_FLAG             (1 <<  1)
+#define USB_STS_IRQ_FLAG                 (1 <<  0)
+
+	ioport32_t usbintr;
+#define USB_INTR_ASYNC_ADVANCE_FLAG   (1 << 5)
+#define USB_INTR_HOST_ERR_FLAG        (1 << 4)
+#define USB_INTR_FRAME_ROLLOVER_FLAG  (1 << 3)
+#define USB_INTR_PORT_CHANGE_FLAG     (1 << 2)
+#define USB_INTR_ERR_IRQ_FLAG         (1 << 1)
+#define USB_INTR_IRQ_FLAG             (1 << 0)
+
+	ioport32_t frindex;
+#define USB_FRINDEX_MASK   0xfff
+
+	ioport32_t ctrldssegment;
+	ioport32_t periodiclistbase;
+#define USB_PERIODIC_LIST_BASE_MASK   0xfffff000
+
+	ioport32_t asynclistaddr;
+#define USB_ASYNCLIST_MASK   0xfffffff0
+
+	PADD32[9];
+
+	ioport32_t configflag;
+#define USB_CONFIG_FLAG_FLAG   (1 << 0)
+
+	ioport32_t portsc[];
+#define USB_PORTSC_WKOC_E_FLAG       (1 << 22)
+#define USB_PORTSC_WKDSCNNT_E_FLAG   (1 << 21)
+#define USB_PORTSC_WKCNNT_E_FLAG     (1 << 20)
+#define USB_PORTSC_PORT_TEST_MASK    (0xf << 16)
+#define USB_PORTSC_NO_TEST           (0x0 << 16)
+#define USB_PORTSC_TEST_J_STATE      (0x1 << 16)
+#define USB_PORTSC_TEST_K_STATE      (0x2 << 16)
+#define USB_PORTSC_TEST_SE0_NAK      (0x3 << 16)
+#define USB_PORTSC_TEST_PACKET       (0x4 << 16)
+#define USB_PORTSC_TEST_FORCE_ENABLE (0x5 << 16)
+#define USB_PORTSC_INDICATOR_MASK    (0x3 << 14)
+#define USB_PORTSC_INDICATOR_OFF     (0x0 << 14)
+#define USB_PORTSC_INDICATOR_AMBER   (0x1 << 14)
+#define USB_PORTSC_INDICATOR_GREEN   (0x2 << 14)
+#define USB_PORTSC_PORT_OWNER_FLAG   (1 << 13)
+#define USB_PORTSC_PORT_POWER_FLAG   (1 << 12)
+#define USB_PORTSC_LINE_STATUS_MASK  (0x3 << 10)
+#define USB_PORTSC_LINE_STATUS_SE0   (0x0 << 10)
+#define USB_PORTSC_LINE_STATUS_K     (0x1 << 10)
+#define USB_PORTSC_LINE_STATUS_J     (0x2 << 10)
+#define USB_PORTSC_PORT_RESET_FLAG   (1 << 8)
+#define USB_PORTSC_SUSPEND_FLAG      (1 << 7)
+#define USB_PORTSC_RESUME_FLAG       (1 << 6)
+#define USB_PORTSC_OC_CHANGE_FLAG    (1 << 5)
+#define USB_PORTSC_OC_ACTIVE_FLAG    (1 << 4)
+#define USB_PORTSC_EN_CHANGE_FLAG    (1 << 3)
+#define USB_PORTSC_ENABLED_FLAG      (1 << 2)
+#define USB_PORTSC_CONNECT_CH_FLAG   (1 << 1)
+#define USB_PORTSC_CONNECT_FLAG      (1 << 0)
+
+#define USB_PORTSC_WC_MASK \
+    (USB_PORTSC_CONNECT_CH_FLAG | USB_PORTSC_EN_CHANGE_FLAG | USB_PORTSC_OC_CHANGE_FLAG)
+} ehci_regs_t;
+
+#endif
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/ehci_rh.c
===================================================================
--- uspace/drv/bus/usb/ehci/ehci_rh.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/ehci_rh.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,565 @@
+/*
+ * Copyright (c) 2013 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <mem.h>
+#include <sys/types.h>
+
+#include <usb/classes/hub.h>
+#include <usb/debug.h>
+#include <usb/descriptor.h>
+#include <usb/request.h>
+#include <usb/usb.h>
+
+#include <usb/host/endpoint.h>
+#include <usbvirt/device.h>
+
+#include "ehci_rh.h"
+
+enum {
+	HUB_STATUS_CHANGE_PIPE = 1,
+};
+
+static usbvirt_device_ops_t ops;
+
+/** Initialize internal USB HUB class descriptor.
+ * @param instance EHCI root hub.
+ * Use register based info to create accurate descriptor.
+ */
+static void ehci_rh_hub_desc_init(ehci_rh_t *instance, unsigned hcs)
+{
+	assert(instance);
+	const unsigned dsize = sizeof(usb_hub_descriptor_header_t) +
+	    STATUS_BYTES(instance->port_count) * 2;
+	assert(dsize <= sizeof(instance->hub_descriptor));
+
+	instance->hub_descriptor.header.length = dsize;
+	instance->hub_descriptor.header.descriptor_type = USB_DESCTYPE_HUB;
+	instance->hub_descriptor.header.port_count = instance->port_count;
+	/* Bits 0,1 indicate power switching mode
+	 * Bit 2 indicates device type (compound device)
+	 * Bits 3,4 indicate over-current protection mode */
+	instance->hub_descriptor.header.characteristics = 0 |
+	    ((hcs & EHCI_CAPS_HCS_PPC_FLAG) ? 0x09 : 0x12) |
+	    ((hcs & EHCI_CAPS_HCS_INDICATORS_FLAG) ? 0x80 : 0) |
+	    (0x3 << 5); /* Need 32 FS bit times */ // TODO Implement
+	instance->hub_descriptor.header.characteristics_reserved = 0;
+	instance->hub_descriptor.header.power_good_time = 50;
+	/* bHubContrCurrent, root hubs don't need no power. */
+	instance->hub_descriptor.header.max_current = 0;
+
+	/* Device removable and some legacy 1.0 stuff*/
+	instance->hub_descriptor.rempow[0] = 0xff;
+	instance->hub_descriptor.rempow[1] = 0xff;
+	instance->hub_descriptor.rempow[2] = 0xff;
+	instance->hub_descriptor.rempow[3] = 0xff;
+
+}
+/** Initialize EHCI root hub.
+ * @param instance Place to initialize.
+ * @param regs EHCI device registers.
+ * @param name Device name.
+ * return Error code, EOK on success.
+ *
+ * Selects preconfigured port powering mode, sets up descriptor, and
+ * initializes internal virtual hub.
+ */
+int ehci_rh_init(ehci_rh_t *instance, ehci_caps_regs_t *caps, ehci_regs_t *regs,
+const char *name)
+{
+	assert(instance);
+	instance->registers = regs;
+	instance->port_count =
+	    (EHCI_RD(caps->hcsparams) >> EHCI_CAPS_HCS_N_PORTS_SHIFT) &
+	    EHCI_CAPS_HCS_N_PORTS_MASK;
+	usb_log_debug2("hcsparams: %x.\n", EHCI_RD(caps->hcsparams));
+	usb_log_info("%s: Found %u ports.\n", name, instance->port_count);
+
+	if (EHCI_RD(caps->hcsparams) & EHCI_CAPS_HCS_PPC_FLAG) {
+		usb_log_info("%s: Per-port power switching.\n", name);
+	} else {
+		usb_log_info("%s: No power switching.\n", name);
+	}
+
+	for (unsigned i = 0; i < EHCI_MAX_PORTS; ++i) {
+		instance->reset_flag[i] = false;
+		instance->resume_flag[i] = false;
+	}
+
+	ehci_rh_hub_desc_init(instance, EHCI_RD(caps->hcsparams));
+	instance->unfinished_interrupt_transfer = NULL;
+
+	return virthub_base_init(&instance->base, name, &ops, instance,
+	    NULL, &instance->hub_descriptor.header, HUB_STATUS_CHANGE_PIPE);
+}
+
+/** Schedule USB request.
+ * @param instance OCHI root hub instance.
+ * @param batch USB requst batch to schedule.
+ * @return Always EOK.
+ * Most requests complete even before this function returns,
+ * status change requests might be postponed until there is something to report.
+ */
+int ehci_rh_schedule(ehci_rh_t *instance, usb_transfer_batch_t *batch)
+{
+	assert(instance);
+	assert(batch);
+	const usb_target_t target = {{
+		.address = batch->ep->address,
+		.endpoint = batch->ep->endpoint,
+	}};
+	batch->error = virthub_base_request(&instance->base, target,
+	    usb_transfer_batch_direction(batch), (void*)batch->setup_buffer,
+	    batch->buffer, batch->buffer_size, &batch->transfered_size);
+	if (batch->error == ENAK) {
+		/* This is safe because only status change interrupt transfers
+		 * return NAK. The assertion holds true because the batch
+		 * existence prevents communication with that ep */
+		assert(instance->unfinished_interrupt_transfer == NULL);
+		instance->unfinished_interrupt_transfer = batch;
+	} else {
+		usb_transfer_batch_finish(batch, NULL);
+		usb_transfer_batch_destroy(batch);
+	}
+	return EOK;
+}
+
+/** Handle EHCI RHSC interrupt.
+ * @param instance EHCI root hub isntance.
+ * @return Always EOK.
+ *
+ * Interrupt means there is a change of status to report. It may trigger
+ * processing of a postponed request.
+ */
+int ehci_rh_interrupt(ehci_rh_t *instance)
+{
+	//TODO atomic swap needed
+	usb_transfer_batch_t *batch = instance->unfinished_interrupt_transfer;
+	instance->unfinished_interrupt_transfer = NULL;
+	if (batch) {
+		const usb_target_t target = {{
+			.address = batch->ep->address,
+			.endpoint = batch->ep->endpoint,
+		}};
+		batch->error = virthub_base_request(&instance->base, target,
+		    usb_transfer_batch_direction(batch),
+		    (void*)batch->setup_buffer,
+		    batch->buffer, batch->buffer_size, &batch->transfered_size);
+		usb_transfer_batch_finish(batch, NULL);
+		usb_transfer_batch_destroy(batch);
+	}
+	return EOK;
+}
+
+/* HUB ROUTINES IMPLEMENTATION */
+#define TEST_SIZE_INIT(size, port, hub) \
+do { \
+	hub = virthub_get_data(device); \
+	assert(hub);\
+	if (uint16_usb2host(setup_packet->length) != size) \
+		return ESTALL; \
+	port = uint16_usb2host(setup_packet->index) - 1; \
+	if (port > hub->port_count) \
+		return EINVAL; \
+} while (0)
+
+/** Hub status request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_get_status(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ehci_rh_t *hub = virthub_get_data(device);
+	assert(hub);
+	if (uint16_usb2host(setup_packet->length) != 4)
+		return ESTALL;
+	/* ECHI RH does not report global OC, and local power is always good */
+	const uint32_t val = 0;
+	memcpy(data, &val, sizeof(val));
+	*act_size = sizeof(val);
+	return EOK;
+}
+
+/** Hub set feature request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_clear_hub_feature(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ehci_rh_t *hub = virthub_get_data(device);
+	assert(hub);
+
+	/*
+	 * Chapter 11.16.2 specifies that only C_HUB_LOCAL_POWER and
+	 * C_HUB_OVER_CURRENT are supported.
+	 * C_HUB_LOCAL_POWER is not supported because root hubs do not support
+	 * local power status feature.
+	 * EHCI RH does not report global OC condition either
+	 */
+	return ESTALL;
+}
+
+#define BIT_VAL(val, bit)   ((val & bit) ? 1 : 0)
+#define EHCI2USB(val, bit, feat)   (BIT_VAL(val, bit) << feat)
+
+/** Port status request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_get_port_status(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ehci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(4, port, hub);
+	if (setup_packet->value != 0)
+		return EINVAL;
+
+	const uint32_t reg = EHCI_RD(hub->registers->portsc[port]);
+	const uint32_t status = uint32_host2usb(
+	    EHCI2USB(reg, USB_PORTSC_CONNECT_FLAG, USB_HUB_FEATURE_PORT_CONNECTION) |
+	    EHCI2USB(reg, USB_PORTSC_ENABLED_FLAG, USB_HUB_FEATURE_PORT_ENABLE) |
+	    EHCI2USB(reg, USB_PORTSC_SUSPEND_FLAG, USB_HUB_FEATURE_PORT_SUSPEND) |
+	    EHCI2USB(reg, USB_PORTSC_OC_ACTIVE_FLAG, USB_HUB_FEATURE_PORT_OVER_CURRENT) |
+	    EHCI2USB(reg, USB_PORTSC_PORT_RESET_FLAG, USB_HUB_FEATURE_PORT_RESET) |
+	    EHCI2USB(reg, USB_PORTSC_PORT_POWER_FLAG, USB_HUB_FEATURE_PORT_POWER) |
+	    (((reg & USB_PORTSC_LINE_STATUS_MASK) == USB_PORTSC_LINE_STATUS_K) ?
+	        (1 << USB_HUB_FEATURE_PORT_LOW_SPEED) : 0) |
+	    ((reg & USB_PORTSC_PORT_OWNER_FLAG) ? 0 : (1 << USB_HUB_FEATURE_PORT_HIGH_SPEED)) |
+	    EHCI2USB(reg, USB_PORTSC_PORT_TEST_MASK, 11) |
+	    EHCI2USB(reg, USB_PORTSC_INDICATOR_MASK, 12) |
+	    EHCI2USB(reg, USB_PORTSC_CONNECT_CH_FLAG, USB_HUB_FEATURE_C_PORT_CONNECTION) |
+	    EHCI2USB(reg, USB_PORTSC_EN_CHANGE_FLAG, USB_HUB_FEATURE_C_PORT_ENABLE) |
+	    (hub->resume_flag[port] ? (1 << USB_HUB_FEATURE_C_PORT_SUSPEND) : 0) |
+	    EHCI2USB(reg, USB_PORTSC_OC_CHANGE_FLAG, USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
+	    (hub->reset_flag[port] ? (1 << USB_HUB_FEATURE_C_PORT_RESET): 0)
+	);
+	/* Note feature numbers for test and indicator feature do not
+	 * corespond to the port status bit locations */
+	memcpy(data, &status, sizeof(status));
+	*act_size = sizeof(status);
+	return EOK;
+}
+
+typedef struct {
+	ehci_rh_t *hub;
+	unsigned port;
+} ehci_rh_job_t;
+
+static int stop_reset(void *arg)
+{
+	ehci_rh_job_t *job = arg;
+	async_usleep(50000);
+	EHCI_CLR(job->hub->registers->portsc[job->port],
+	    USB_PORTSC_PORT_RESET_FLAG);
+	/* wait for reset to complete */
+	while (EHCI_RD(job->hub->registers->portsc[job->port]) &
+	    USB_PORTSC_PORT_RESET_FLAG) {
+		async_usleep(1);
+	};
+	/* Handle port ownership, if the port is not enabled
+	 * after reset it's a full speed device */
+	if (!(EHCI_RD(job->hub->registers->portsc[job->port]) &
+	    USB_PORTSC_ENABLED_FLAG)) {
+		EHCI_SET(job->hub->registers->portsc[job->port],
+		    USB_PORTSC_PORT_OWNER_FLAG);
+	} else {
+		job->hub->reset_flag[job->port] = true;
+	}
+	ehci_rh_interrupt(job->hub);
+	free(job);
+	return 0;
+}
+
+static int stop_resume(void *arg)
+{
+	ehci_rh_job_t *job = arg;
+	async_usleep(20000);
+	EHCI_CLR(job->hub->registers->portsc[job->port],
+	    USB_PORTSC_RESUME_FLAG);
+	job->hub->resume_flag[job->port] = true;
+	ehci_rh_interrupt(job->hub);
+	free(job);
+	return 0;
+}
+
+static int delayed_job(int (*func)(void*), ehci_rh_t *rh, unsigned port)
+{
+	ehci_rh_job_t *job = malloc(sizeof(*job));
+	if (!job)
+		return ENOMEM;
+	job->hub = rh;
+	job->port = port;
+	fid_t fib = fibril_create(func, job);
+	if (!fib) {
+		free(job);
+		return ENOMEM;
+	}
+	fibril_add_ready(fib);
+	return EOK;
+}
+
+
+/** Port clear feature request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_clear_port_feature(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ehci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(0, port, hub);
+	const unsigned feature = uint16_usb2host(setup_packet->value);
+	/* Enabled features to clear: see page 269 of USB specs */
+	switch (feature)
+	{
+	case USB_HUB_FEATURE_PORT_POWER:          /*8*/
+		EHCI_CLR(hub->registers->portsc[port],
+		    USB_PORTSC_PORT_POWER_FLAG);
+		return EOK;
+
+	case USB_HUB_FEATURE_PORT_ENABLE:         /*1*/
+		EHCI_CLR(hub->registers->portsc[port],
+		    USB_PORTSC_ENABLED_FLAG);
+		return EOK;
+
+	case USB_HUB_FEATURE_PORT_SUSPEND:        /*2*/
+		/* If not in suspend it's noop */
+		if ((EHCI_RD(hub->registers->portsc[port]) &
+		    USB_PORTSC_SUSPEND_FLAG) == 0)
+		    return EOK;
+		/* Host driven resume */
+		EHCI_SET(hub->registers->portsc[port],
+		    USB_PORTSC_RESUME_FLAG);
+		delayed_job(stop_resume, hub, port);
+		return EOK;
+
+	case USB_HUB_FEATURE_C_PORT_CONNECTION:   /*16*/
+		EHCI_SET(hub->registers->portsc[port],
+		    USB_PORTSC_CONNECT_CH_FLAG);
+		return EOK;
+	case USB_HUB_FEATURE_C_PORT_ENABLE:       /*17*/
+		EHCI_SET(hub->registers->portsc[port],
+		    USB_PORTSC_CONNECT_CH_FLAG);
+		return EOK;
+	case USB_HUB_FEATURE_C_PORT_OVER_CURRENT: /*19*/
+		EHCI_SET(hub->registers->portsc[port],
+		    USB_PORTSC_OC_CHANGE_FLAG);
+		return EOK;
+	case USB_HUB_FEATURE_C_PORT_SUSPEND:      /*18*/
+		hub->resume_flag[port] = false;
+		return EOK;
+	case USB_HUB_FEATURE_C_PORT_RESET:        /*20*/
+		hub->reset_flag[port] = false;
+		return EOK;
+
+	default:
+		return ENOTSUP;
+	}
+}
+
+/** Port set feature request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_set_port_feature(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ehci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(0, port, hub);
+	const unsigned feature = uint16_usb2host(setup_packet->value);
+	switch (feature) {
+	case USB_HUB_FEATURE_PORT_ENABLE:  /*1*/
+		EHCI_SET(hub->registers->portsc[port],
+		    USB_PORTSC_ENABLED_FLAG);
+		return EOK;
+	case USB_HUB_FEATURE_PORT_SUSPEND: /*2*/
+		EHCI_SET(hub->registers->portsc[port],
+		    USB_PORTSC_SUSPEND_FLAG);
+		return EOK;
+	case USB_HUB_FEATURE_PORT_RESET:   /*4*/
+		EHCI_SET(hub->registers->portsc[port],
+		    USB_PORTSC_PORT_RESET_FLAG);
+		delayed_job(stop_reset, hub, port);
+		return EOK;
+	case USB_HUB_FEATURE_PORT_POWER:   /*8*/
+		EHCI_SET(hub->registers->portsc[port],
+		    USB_PORTSC_PORT_POWER_FLAG);
+		return EOK;
+	default:
+		return ENOTSUP;
+	}
+}
+
+/** Status change handler.
+ * @param device Virtual hub device
+ * @param endpoint Endpoint number
+ * @param tr_type Transfer type
+ * @param buffer Response destination
+ * @param buffer_size Bytes available in buffer
+ * @param actual_size Size us the used part of the dest buffer.
+ *
+ * Produces status mask. Bit 0 indicates hub status change the other bits
+ * represent port status change. Endian does not matter as UHCI root hubs
+ * only need 1 byte.
+ */
+static int req_status_change_handler(usbvirt_device_t *device,
+    usb_endpoint_t endpoint, usb_transfer_type_t tr_type,
+    void *buffer, size_t buffer_size, size_t *actual_size)
+{
+	ehci_rh_t *hub = virthub_get_data(device);
+	assert(hub);
+
+	if (buffer_size < STATUS_BYTES(hub->port_count))
+		return ESTALL;
+
+	uint16_t mask = 0;
+	for (unsigned port = 0; port < hub->port_count; ++port) {
+		/* Write-clean bits are those that indicate change */
+		uint32_t status = EHCI_RD(hub->registers->portsc[port]);
+		if ((status & USB_PORTSC_WC_MASK)
+		    || hub->reset_flag[port] || hub->reset_flag[port]) {
+			/* Ignore new LS device */
+			if ((status & USB_PORTSC_CONNECT_CH_FLAG) &&
+			    (status & USB_PORTSC_LINE_STATUS_MASK) ==
+			        USB_PORTSC_LINE_STATUS_K)
+				EHCI_SET(hub->registers->portsc[port],
+				    USB_PORTSC_PORT_OWNER_FLAG);
+			else
+				mask |= (2 << port);
+		}
+	}
+
+	usb_log_debug2("EHCI root hub interrupt mask: %hx.\n", mask);
+
+	if (mask == 0)
+		return ENAK;
+	mask = uint16_host2usb(mask);
+	memcpy(buffer, &mask, STATUS_BYTES(hub->port_count));
+	*actual_size = STATUS_BYTES(hub->port_count);
+	return EOK;
+}
+
+/** EHCI root hub request handlers */
+static const usbvirt_control_request_handler_t control_transfer_handlers[] = {
+	{
+		STD_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		.name = "GetDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		.name = "GetDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_DESCRIPTOR),
+		.name = "GetHubDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetPortStatus",
+		.callback = req_get_port_status,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_CLEAR_FEATURE),
+		.name = "ClearHubFeature",
+		.callback = req_clear_hub_feature,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_CLEAR_FEATURE),
+		.name = "ClearPortFeature",
+		.callback = req_clear_port_feature,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetHubStatus",
+		.callback = req_get_status,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetPortStatus",
+		.callback = req_get_port_status,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_SET_FEATURE),
+		.name = "SetHubFeature",
+		.callback = req_nop,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_SET_FEATURE),
+		.name = "SetPortFeature",
+		.callback = req_set_port_feature,
+	},
+	{
+		.callback = NULL
+	}
+};
+
+/** Virtual EHCI root hub ops */
+static usbvirt_device_ops_t ops = {
+        .control = control_transfer_handlers,
+        .data_in[HUB_STATUS_CHANGE_PIPE] = req_status_change_handler,
+};
Index: uspace/drv/bus/usb/ehci/ehci_rh.h
===================================================================
--- uspace/drv/bus/usb/ehci/ehci_rh.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/ehci_rh.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2013 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+#ifndef DRV_EHCI_EHCI_RH_H
+#define DRV_EHCI_EHCI_RH_H
+
+#include <assert.h>
+#include <sys/types.h>
+
+#include <usb/usb.h>
+#include <usb/classes/hub.h>
+#include <usb/host/usb_transfer_batch.h>
+#include <usbvirt/virthub_base.h>
+
+#include "ehci_regs.h"
+
+enum {
+	EHCI_MAX_PORTS = 15,
+};
+
+typedef struct {
+	/** Virtual hub instance */
+	virthub_base_t base;
+	/** EHCI device registers */
+	ehci_regs_t *registers;
+	/** Number of downstream ports, EHCI limits this to 15 */
+	unsigned port_count;
+	/** USB hub descriptor describing the EHCI root hub */
+	struct {
+		usb_hub_descriptor_header_t header;
+		uint8_t rempow[STATUS_BYTES(EHCI_MAX_PORTS) * 2];
+	} __attribute__((packed)) hub_descriptor;
+	/** interrupt transfer waiting for an actual interrupt to occur */
+	usb_transfer_batch_t *unfinished_interrupt_transfer;
+	bool reset_flag[EHCI_MAX_PORTS];
+	bool resume_flag[EHCI_MAX_PORTS];
+} ehci_rh_t;
+
+int ehci_rh_init(ehci_rh_t *instance, ehci_caps_regs_t *caps, ehci_regs_t *regs,
+    const char *name);
+int ehci_rh_schedule(ehci_rh_t *instance, usb_transfer_batch_t *batch);
+int ehci_rh_interrupt(ehci_rh_t *instance);
+
+/** Get EHCI rh address.
+ *
+ * @param instance UHCI rh instance.
+ * @return USB address assigned to the hub.
+ * Wrapper for virtual hub address
+ */
+static inline usb_address_t ehci_rh_get_address(ehci_rh_t *instance)
+{
+	assert(instance);
+	return virthub_base_get_address(&instance->base);
+}
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/ehci/endpoint_list.c
===================================================================
--- uspace/drv/bus/usb/ehci/endpoint_list.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/endpoint_list.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2014 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver transfer list implementation
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <libarch/barrier.h>
+
+#include <usb/debug.h>
+
+#include "utils/malloc32.h"
+#include "endpoint_list.h"
+
+/** Initialize transfer list structures.
+ *
+ * @param[in] instance Memory place to use.
+ * @param[in] name Name of the new list.
+ * @return Error code
+ *
+ * Allocates memory for internal ed_t structure.
+ */
+int endpoint_list_init(endpoint_list_t *instance, const char *name)
+{
+	assert(instance);
+	instance->name = name;
+	instance->list_head = malloc32(sizeof(qh_t));
+	if (!instance->list_head) {
+		usb_log_error("Failed to allocate list head.\n");
+		return ENOMEM;
+	}
+	instance->list_head_pa = addr_to_phys(instance->list_head);
+	usb_log_debug2("Transfer list %s setup with ED: %p(0x%0" PRIx32 ")).\n",
+	    name, instance->list_head, instance->list_head_pa);
+
+	qh_init(instance->list_head, NULL);
+	list_initialize(&instance->endpoint_list);
+	fibril_mutex_initialize(&instance->guard);
+	return EOK;
+}
+
+void endpoint_list_chain(endpoint_list_t *instance, const endpoint_list_t *next)
+{
+	assert(instance);
+	assert(next);
+	assert(instance->list_head);
+	assert(next->list_head);
+
+	instance->list_head->horizontal = LINK_POINTER_QH(next->list_head_pa);
+}
+
+/** Add endpoint to the end of the list and queue.
+ *
+ * @param[in] instance List to use.
+ * @param[in] endpoint Endpoint to add.
+ *
+ * The endpoint is added to the end of the list and queue.
+ */
+void endpoint_list_append_ep(endpoint_list_t *instance, ehci_endpoint_t *ep)
+{
+	assert(instance);
+	assert(ep);
+	assert(ep->qh);
+	usb_log_debug2("Queue %s: Append endpoint(%p).\n", instance->name, ep);
+
+	fibril_mutex_lock(&instance->guard);
+
+	qh_t *last_qh = NULL;
+	/* Add to the hardware queue. */
+	if (list_empty(&instance->endpoint_list)) {
+		/* There are no active EDs */
+		last_qh = instance->list_head;
+	} else {
+		/* There are active EDs, get the last one */
+		ehci_endpoint_t *last = ehci_endpoint_list_instance(
+		    list_last(&instance->endpoint_list));
+		last_qh = last->qh;
+	}
+	assert(last_qh);
+	/* Keep link */
+	ep->qh->horizontal = last_qh->horizontal;
+	/* Make sure QH update is written to the memory */
+	write_barrier();
+
+	/* Add QH to the hw queue */
+	qh_append_qh(last_qh, ep->qh);
+	/* Make sure QH is updated */
+	write_barrier();
+	/* Add to the sw list */
+	list_append(&ep->link, &instance->endpoint_list);
+
+	ehci_endpoint_t *first = ehci_endpoint_list_instance(
+	    list_first(&instance->endpoint_list));
+	usb_log_debug("HCD EP(%p) added to list %s, first is %p(%p).\n",
+		ep, instance->name, first, first->qh);
+	if (last_qh == instance->list_head) {
+		usb_log_debug2("%s head ED(%p-0x%0" PRIx32 "): %x:%x.\n",
+		    instance->name, last_qh, instance->list_head_pa,
+		    last_qh->status, last_qh->horizontal);
+	}
+	fibril_mutex_unlock(&instance->guard);
+}
+
+/** Remove endpoint from the list and queue.
+ *
+ * @param[in] instance List to use.
+ * @param[in] endpoint Endpoint to remove.
+ */
+void endpoint_list_remove_ep(endpoint_list_t *instance, ehci_endpoint_t *ep)
+{
+	assert(instance);
+	assert(instance->list_head);
+	assert(ep);
+	assert(ep->qh);
+
+	fibril_mutex_lock(&instance->guard);
+
+	usb_log_debug2("Queue %s: removing endpoint(%p).\n", instance->name, ep);
+
+	const char *qpos = NULL;
+	qh_t *prev_qh;
+	/* Remove from the hardware queue */
+	if (list_first(&instance->endpoint_list) == &ep->link) {
+		/* I'm the first one here */
+		prev_qh = instance->list_head;
+		qpos = "FIRST";
+	} else {
+		ehci_endpoint_t *prev =
+		    list_get_instance(ep->link.prev, ehci_endpoint_t, link);
+		prev_qh = prev->qh;
+		qpos = "NOT FIRST";
+	}
+	assert(qh_next(prev_qh) == addr_to_phys(ep->qh));
+	prev_qh->horizontal = ep->qh->horizontal;
+	/* Make sure ED is updated */
+	write_barrier();
+
+	usb_log_debug("HCD EP(%p) removed (%s) from %s, horizontal %x.\n",
+	    ep, qpos, instance->name, ep->qh->horizontal);
+
+	/* Remove from the endpoint list */
+	list_remove(&ep->link);
+	fibril_mutex_unlock(&instance->guard);
+}
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/endpoint_list.h
===================================================================
--- uspace/drv/bus/usb/ehci/endpoint_list.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/endpoint_list.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2014 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver transfer list structure
+ */
+#ifndef DRV_EHCI_ENDPOINT_LIST_H
+#define DRV_EHCI_ENDPOINT_LIST_H
+
+#include <adt/list.h>
+#include <assert.h>
+#include <fibril_synch.h>
+#include <sys/types.h>
+
+#include "ehci_endpoint.h"
+#include "hw_struct/queue_head.h"
+#include "utils/malloc32.h"
+
+/** Structure maintains both EHCI queue and software list of active endpoints.*/
+typedef struct endpoint_list {
+	/** Guard against add/remove races */
+	fibril_mutex_t guard;
+	/** EHCI hw structure at the beginning of the queue */
+	qh_t *list_head;
+	/** Physical address of the first(dummy) ED */
+	uint32_t list_head_pa;
+	/** Assigned name, provides nicer debug output */
+	const char *name;
+	/** Sw list of all active EDs */
+	list_t endpoint_list;
+} endpoint_list_t;
+
+/** Dispose transfer list structures.
+ *
+ * @param[in] instance Memory place to use.
+ *
+ * Frees memory of the internal ed_t structure.
+ */
+static inline void endpoint_list_fini(endpoint_list_t *instance)
+{
+	assert(instance);
+	free32(instance->list_head);
+	instance->list_head = NULL;
+	instance->list_head_pa = 0;
+}
+
+int endpoint_list_init(endpoint_list_t *instance, const char *name);
+void endpoint_list_chain(endpoint_list_t *instance, const endpoint_list_t *next);
+void endpoint_list_append_ep(endpoint_list_t *instance, ehci_endpoint_t *ep);
+void endpoint_list_remove_ep(endpoint_list_t *instance, ehci_endpoint_t *ep);
+#endif
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/hc.c
===================================================================
--- uspace/drv/bus/usb/ehci/hc.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/hc.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,454 @@
+/*
+ * Copyright (c) 2011 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 drvusbehcihc
+ * @{
+ */
+/** @file
+ * @brief EHCI Host controller driver routines
+ */
+
+#include <assert.h>
+#include <async.h>
+#include <errno.h>
+#include <macros.h>
+#include <mem.h>
+#include <stdlib.h>
+#include <str_error.h>
+#include <sys/types.h>
+
+#include <usb/debug.h>
+#include <usb/usb.h>
+
+//#include "ehci_endpoint.h"
+#include "ehci_batch.h"
+#include "utils/malloc32.h"
+
+#include "hc.h"
+
+#define EHCI_USED_INTERRUPTS \
+    (USB_INTR_IRQ_FLAG | USB_INTR_ERR_IRQ_FLAG | USB_INTR_PORT_CHANGE_FLAG | \
+    USB_INTR_ASYNC_ADVANCE_FLAG | USB_INTR_HOST_ERR_FLAG)
+
+static const irq_pio_range_t ehci_pio_ranges[] = {
+	{
+		.base = 0,
+		.size = sizeof(ehci_regs_t)
+	}
+};
+
+static const irq_cmd_t ehci_irq_commands[] = {
+	{
+		.cmd = CMD_PIO_READ_32,
+		.dstarg = 1,
+		.addr = NULL
+	},
+	{
+		.cmd = CMD_AND,
+		.srcarg = 1,
+		.dstarg = 2,
+		.value = 0
+	},
+	{
+		.cmd = CMD_PREDICATE,
+		.srcarg = 2,
+		.value = 2
+	},
+	{
+		.cmd = CMD_PIO_WRITE_A_32,
+		.srcarg = 1,
+		.addr = NULL
+	},
+	{
+		.cmd = CMD_ACCEPT
+	}
+};
+
+static void hc_start(hc_t *instance);
+static int hc_init_memory(hc_t *instance);
+
+/** Generate IRQ code.
+ * @param[out] ranges PIO ranges buffer.
+ * @param[in] hw_res Device's resources.
+ *
+ * @return Error code.
+ */
+int ehci_hc_gen_irq_code(irq_code_t *code, const hw_res_list_parsed_t *hw_res)
+{
+	assert(code);
+	assert(hw_res);
+
+	if (hw_res->irqs.count != 1 || hw_res->mem_ranges.count != 1)
+		return EINVAL;
+
+	addr_range_t regs = hw_res->mem_ranges.ranges[0];
+
+	if (RNGSZ(regs) < sizeof(ehci_regs_t))
+		return EOVERFLOW;
+
+	code->ranges = malloc(sizeof(ehci_pio_ranges));
+	if (code->ranges == NULL)
+		return ENOMEM;
+
+	code->cmds = malloc(sizeof(ehci_irq_commands));
+	if (code->cmds == NULL) {
+		free(code->ranges);
+		return ENOMEM;
+	}
+
+	code->rangecount = ARRAY_SIZE(ehci_pio_ranges);
+	code->cmdcount = ARRAY_SIZE(ehci_irq_commands);
+
+	memcpy(code->ranges, ehci_pio_ranges, sizeof(ehci_pio_ranges));
+	code->ranges[0].base = RNGABS(regs);
+
+	memcpy(code->cmds, ehci_irq_commands, sizeof(ehci_irq_commands));
+	ehci_caps_regs_t *caps = NULL;
+	int ret = pio_enable_range(&regs, (void**)&caps);
+	if (ret != EOK) {
+		return ret;
+	}
+	ehci_regs_t *registers =
+	    (ehci_regs_t *)(RNGABSPTR(regs) + EHCI_RD8(caps->caplength));
+	code->cmds[0].addr = (void *) &registers->usbsts;
+	code->cmds[3].addr = (void *) &registers->usbsts;
+	EHCI_WR(code->cmds[1].value, EHCI_USED_INTERRUPTS);
+
+	usb_log_debug("Memory mapped regs at %p (size %zu), IRQ %d.\n",
+	    RNGABSPTR(regs), RNGSZ(regs), hw_res->irqs.irqs[0]);
+
+	return hw_res->irqs.irqs[0];
+}
+
+/** Initialize EHCI hc driver structure
+ *
+ * @param[in] instance Memory place for the structure.
+ * @param[in] regs Device's I/O registers range.
+ * @param[in] interrupts True if w interrupts should be used
+ * @return Error code
+ */
+int hc_init(hc_t *instance, const hw_res_list_parsed_t *hw_res, bool interrupts)
+{
+	assert(instance);
+	assert(hw_res);
+	if (hw_res->mem_ranges.count != 1 ||
+	    hw_res->mem_ranges.ranges[0].size <
+	        (sizeof(ehci_caps_regs_t) + sizeof(ehci_regs_t)))
+	    return EINVAL;
+
+	int ret = pio_enable_range(&hw_res->mem_ranges.ranges[0],
+	    (void **)&instance->caps);
+	if (ret != EOK) {
+		usb_log_error("Failed to gain access to device registers: %s.\n",
+		    str_error(ret));
+		return ret;
+	}
+	usb_log_info("Device registers at %" PRIx64 " (%zuB) accessible.\n",
+	    hw_res->mem_ranges.ranges[0].address.absolute,
+	    hw_res->mem_ranges.ranges[0].size);
+	instance->registers =
+	    (void*)instance->caps + EHCI_RD8(instance->caps->caplength);
+	usb_log_info("Device control registers at %" PRIx64 "\n",
+	    hw_res->mem_ranges.ranges[0].address.absolute
+	    + EHCI_RD8(instance->caps->caplength));
+
+	list_initialize(&instance->pending_batches);
+	fibril_mutex_initialize(&instance->guard);
+	fibril_condvar_initialize(&instance->async_doorbell);
+
+	ret = hc_init_memory(instance);
+	if (ret != EOK) {
+		usb_log_error("Failed to create EHCI memory structures: %s.\n",
+		    str_error(ret));
+		return ret;
+	}
+
+	ehci_rh_init(
+	    &instance->rh, instance->caps, instance->registers, "ehci rh");
+	hc_start(instance);
+
+	return EOK;
+}
+
+/** Safely dispose host controller internal structures
+ *
+ * @param[in] instance Host controller structure to use.
+ */
+void hc_fini(hc_t *instance)
+{
+	assert(instance);
+	//TODO: stop the hw
+#if 0
+	endpoint_list_fini(&instance->async_list);
+	endpoint_list_fini(&instance->int_list);
+	return_page(instance->periodic_list_base);
+#endif
+};
+
+void hc_enqueue_endpoint(hc_t *instance, const endpoint_t *ep)
+{
+	assert(instance);
+	assert(ep);
+	ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep);
+	switch (ep->transfer_type)
+	{
+	case USB_TRANSFER_CONTROL:
+	case USB_TRANSFER_BULK:
+		endpoint_list_append_ep(&instance->async_list, ehci_ep);
+		break;
+	case USB_TRANSFER_INTERRUPT:
+		endpoint_list_append_ep(&instance->int_list, ehci_ep);
+		break;
+	case USB_TRANSFER_ISOCHRONOUS:
+		/* NOT SUPPORTED */
+		break;
+	}
+}
+
+void hc_dequeue_endpoint(hc_t *instance, const endpoint_t *ep)
+{
+	assert(instance);
+	assert(ep);
+	ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep);
+	switch (ep->transfer_type)
+	{
+	case USB_TRANSFER_INTERRUPT:
+		endpoint_list_remove_ep(&instance->int_list, ehci_ep);
+		/* Fall through */
+	case USB_TRANSFER_ISOCHRONOUS:
+		/* NOT SUPPORTED */
+		return;
+	case USB_TRANSFER_CONTROL:
+	case USB_TRANSFER_BULK:
+		endpoint_list_remove_ep(&instance->async_list, ehci_ep);
+		break;
+	}
+	fibril_mutex_lock(&instance->guard);
+	EHCI_SET(instance->registers->usbcmd, USB_CMD_IRQ_ASYNC_DOORBELL);
+	fibril_condvar_wait(&instance->async_doorbell, &instance->guard);
+	fibril_mutex_unlock(&instance->guard);
+}
+
+int ehci_hc_status(hcd_t *hcd, uint32_t *status)
+{
+	assert(hcd);
+	hc_t *instance = hcd->driver.data;
+	assert(instance);
+	assert(status);
+	*status = 0;
+	if (instance->registers) {
+		*status = EHCI_RD(instance->registers->usbsts);
+		EHCI_WR(instance->registers->usbsts, *status);
+	}
+	return EOK;
+}
+
+/** Add USB transfer to the schedule.
+ *
+ * @param[in] hcd HCD driver structure.
+ * @param[in] batch Batch representing the transfer.
+ * @return Error code.
+ */
+int ehci_hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
+{
+	assert(hcd);
+	hc_t *instance = hcd->driver.data;
+	assert(instance);
+
+	/* Check for root hub communication */
+	if (batch->ep->address == ehci_rh_get_address(&instance->rh)) {
+		return ehci_rh_schedule(&instance->rh, batch);
+	}
+	ehci_transfer_batch_t *ehci_batch = ehci_transfer_batch_get(batch);
+	if (!ehci_batch)
+		return ENOMEM;
+
+	fibril_mutex_lock(&instance->guard);
+	list_append(&ehci_batch->link, &instance->pending_batches);
+	ehci_transfer_batch_commit(ehci_batch);
+
+	fibril_mutex_unlock(&instance->guard);
+	return EOK;
+}
+
+/** Interrupt handling routine
+ *
+ * @param[in] hcd HCD driver structure.
+ * @param[in] status Value of the status register at the time of interrupt.
+ */
+void ehci_hc_interrupt(hcd_t *hcd, uint32_t status)
+{
+	assert(hcd);
+	hc_t *instance = hcd->driver.data;
+	status = EHCI_RD(status);
+	assert(instance);
+
+	if (status & USB_STS_PORT_CHANGE_FLAG) {
+		ehci_rh_interrupt(&instance->rh);
+	}
+
+	if (status & USB_STS_IRQ_ASYNC_ADVANCE_FLAG) {
+		fibril_mutex_lock(&instance->guard);
+		fibril_condvar_broadcast(&instance->async_doorbell);
+		fibril_mutex_unlock(&instance->guard);
+	}
+
+	if (status & (USB_STS_IRQ_FLAG | USB_STS_ERR_IRQ_FLAG)) {
+		fibril_mutex_lock(&instance->guard);
+
+		link_t *current = list_first(&instance->pending_batches);
+		while (current && current != &instance->pending_batches.head) {
+			link_t *next = current->next;
+			ehci_transfer_batch_t *batch =
+			    ehci_transfer_batch_from_link(current);
+
+			if (ehci_transfer_batch_is_complete(batch)) {
+				list_remove(current);
+				ehci_transfer_batch_finish_dispose(batch);
+			}
+			current = next;
+		}
+		fibril_mutex_unlock(&instance->guard);
+	}
+
+	if (status & USB_STS_HOST_ERROR_FLAG) {
+		usb_log_fatal("HOST CONTROLLER SYSTEM ERROR!\n");
+		//TODO do something here
+	}
+}
+
+/** EHCI hw initialization routine.
+ *
+ * @param[in] instance EHCI hc driver structure.
+ */
+void hc_start(hc_t *instance)
+{
+	assert(instance);
+	/* Turn off the HC if it's running, Reseting a running device is
+	 * undefined */
+	if (!(EHCI_RD(instance->registers->usbsts) & USB_STS_HC_HALTED_FLAG)) {
+		/* disable all interrupts */
+		EHCI_WR(instance->registers->usbintr, 0);
+		/* ack all interrupts */
+		EHCI_WR(instance->registers->usbsts, 0x3f);
+		/* Stop HC hw */
+		EHCI_WR(instance->registers->usbcmd, 0);
+		/* Wait until hc is halted */
+		while ((EHCI_RD(instance->registers->usbsts) & USB_STS_HC_HALTED_FLAG) == 0) {
+			async_usleep(1);
+		}
+		usb_log_info("EHCI turned off.\n");
+	} else {
+		usb_log_info("EHCI was not running.\n");
+	}
+
+	/* Hw initialization sequence, see page 53 (pdf 63) */
+	EHCI_SET(instance->registers->usbcmd, USB_CMD_HC_RESET_FLAG);
+	while (EHCI_RD(instance->registers->usbcmd) & USB_CMD_HC_RESET_FLAG) {
+		async_usleep(1);
+	}
+	/* Enable interrupts */
+	EHCI_WR(instance->registers->usbintr, EHCI_USED_INTERRUPTS);
+	/* Use the lowest 4G segment */
+	EHCI_WR(instance->registers->ctrldssegment, 0);
+
+	/* Enable periodic list */
+	assert(instance->periodic_list_base);
+	const uintptr_t phys_base =
+	    addr_to_phys((void*)instance->periodic_list_base);
+	assert((phys_base & USB_PERIODIC_LIST_BASE_MASK) == phys_base);
+	EHCI_WR(instance->registers->periodiclistbase, phys_base);
+	EHCI_SET(instance->registers->usbcmd, USB_CMD_PERIODIC_SCHEDULE_FLAG);
+
+
+	/* Enable Async schedule */
+	assert((instance->async_list.list_head_pa & USB_ASYNCLIST_MASK) ==
+	    instance->async_list.list_head_pa);
+	EHCI_WR(instance->registers->asynclistaddr,
+	    instance->async_list.list_head_pa);
+	EHCI_SET(instance->registers->usbcmd, USB_CMD_ASYNC_SCHEDULE_FLAG);
+
+	/* Start hc and get all ports */
+	EHCI_SET(instance->registers->usbcmd, USB_CMD_RUN_FLAG);
+	EHCI_SET(instance->registers->configflag, USB_CONFIG_FLAG_FLAG);
+
+	usb_log_debug("Registers: \n"
+	    "\t USBCMD(%p): %x(0x00080000 = at least 1ms between interrupts)\n"
+	    "\t USBSTS(%p): %x(0x00001000 = HC halted)\n"
+	    "\t USBINT(%p): %x(0x0 = no interrupts).\n"
+	    "\t CONFIG(%p): %x(0x0 = ports controlled by companion hc).\n",
+	    &instance->registers->usbcmd, EHCI_RD(instance->registers->usbcmd),
+	    &instance->registers->usbsts, EHCI_RD(instance->registers->usbsts),
+	    &instance->registers->usbintr, EHCI_RD(instance->registers->usbintr),
+	    &instance->registers->configflag, EHCI_RD(instance->registers->configflag));
+}
+
+/** Initialize memory structures used by the EHCI hcd.
+ *
+ * @param[in] instance EHCI hc driver structure.
+ * @return Error code.
+ */
+int hc_init_memory(hc_t *instance)
+{
+	assert(instance);
+	int ret = endpoint_list_init(&instance->async_list, "ASYNC");
+	if (ret != EOK) {
+		usb_log_error("Failed to setup ASYNC list: %s", str_error(ret));
+		return ret;
+	}
+
+	ret = endpoint_list_init(&instance->int_list, "INT");
+	if (ret != EOK) {
+		usb_log_error("Failed to setup INT list: %s", str_error(ret));
+		endpoint_list_fini(&instance->async_list);
+		return ret;
+	}
+	/* Loop async list */
+	endpoint_list_chain(&instance->async_list, &instance->async_list);
+
+	/* Take 1024 periodic list heads, we ignore low mem options */
+	instance->periodic_list_base = get_page();
+	if (!instance->periodic_list_base) {
+		usb_log_error("Failed to get ISO schedule page.");
+		endpoint_list_fini(&instance->async_list);
+		endpoint_list_fini(&instance->int_list);
+		return ENOMEM;
+	}
+	for (unsigned i = 0;
+	    i < PAGE_SIZE/sizeof(instance->periodic_list_base[0]); ++i)
+	{
+		/* Disable everything for now */
+		instance->periodic_list_base[i] =
+		    LINK_POINTER_QH(instance->int_list.list_head_pa);
+	}
+	return EOK;
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/ehci/hc.h
===================================================================
--- uspace/drv/bus/usb/ehci/hc.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/hc.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2011 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI host controller driver structure
+ */
+#ifndef DRV_EHCI_HC_H
+#define DRV_EHCI_HC_H
+
+#include <adt/list.h>
+#include <ddi.h>
+#include <ddf/driver.h>
+#include <device/hw_res_parsed.h>
+#include <fibril.h>
+#include <fibril_synch.h>
+#include <stdbool.h>
+#include <sys/types.h>
+
+#include <usb/host/hcd.h>
+#include <usb/host/endpoint.h>
+#include <usb/host/usb_transfer_batch.h>
+
+#include "ehci_regs.h"
+#include "ehci_rh.h"
+#include "hw_struct/link_pointer.h"
+#include "endpoint_list.h"
+
+/** Main EHCI driver structure */
+typedef struct hc {
+	/** Memory mapped CAPS register area */
+	ehci_caps_regs_t *caps;
+	/** Memory mapped I/O registers area */
+	ehci_regs_t *registers;
+
+	/** Iso transfer list */
+	link_pointer_t *periodic_list_base;
+
+	/** CONTROL and BULK schedules */
+	endpoint_list_t async_list;
+
+	/** INT schedule */
+	endpoint_list_t int_list;
+
+	/** List of active transfers */
+	list_t pending_batches;
+
+	/** Guards schedule and endpoint manipulation */
+	fibril_mutex_t guard;
+
+	/** Wait for hc to restart async chedule */
+	fibril_condvar_t async_doorbell;
+
+	/** USB hub emulation structure */
+	ehci_rh_t rh;
+} hc_t;
+
+int hc_init(hc_t *instance, const hw_res_list_parsed_t *hw_res, bool interrupts);
+void hc_fini(hc_t *instance);
+
+void hc_enqueue_endpoint(hc_t *instance, const endpoint_t *ep);
+void hc_dequeue_endpoint(hc_t *instance, const endpoint_t *ep);
+
+int ehci_hc_gen_irq_code(irq_code_t *code, const hw_res_list_parsed_t *hw_res);
+
+void ehci_hc_interrupt(hcd_t *hcd, uint32_t status);
+int ehci_hc_status(hcd_t *hcd, uint32_t *status);
+int ehci_hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/ehci/hw_struct/fstn.h
===================================================================
--- uspace/drv/bus/usb/ehci/hw_struct/fstn.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/hw_struct/fstn.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+#ifndef DRV_EHCI_HW_STRUCT_FSTN_H
+#define DRV_EHCI_HW_STRUCT_FSTN_H
+
+#include "link_pointer.h"
+
+typedef struct fstn {
+	link_pointer_t normal_path;
+	link_pointer_t back_path;
+} fstn_t;
+
+#endif
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/hw_struct/iso_transfer_descriptor.h
===================================================================
--- uspace/drv/bus/usb/ehci/hw_struct/iso_transfer_descriptor.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/hw_struct/iso_transfer_descriptor.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2013 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+#ifndef DRV_EHCI_HW_STRUCT_ISO_TRANSFER_DESCRIPTOR_H
+#define DRV_EHCI_HW_STRUCT_ISO_TRANSFER_DESCRIPTOR_H
+
+#include <sys/types.h>
+#include "link_pointer.h"
+
+/** Isochronous transfer descriptor (HS only) */
+typedef struct itd {
+	link_pointer_t next;
+
+	volatile uint32_t transaction[8];
+#define ITD_TRANSACTION_STATUS_ACTIVE_FLAG  (1 << 31)
+#define ITD_TRANSACTION_STATUS_BUFFER_ERROR_FLAG  (1 << 30)
+#define ITD_TRANSACTION_STATUS_BABBLE_FLAG   (1 << 29)
+#define ITD_TRANSACTION_STATUS_TRANS_ERROR_FLAG  (1 << 28)
+#define ITD_TRANSACTION_LENGHT_MASK    0xfff
+#define ITD_TRANSACTION_LENGHT_SHIFT   16
+#define ITD_TRANSACTION_IOC_FLAG       (1 << 15)
+#define ITD_TRANSACTION_PG_MASK        0x3
+#define ITD_TRANSACTION_PG_SHIFT       12
+#define ITD_TRANSACTION_OFFSET_MASK    0xfff
+#define ITD_TRANSACTION_OFFSET_SHIFT   0
+
+	volatile uint32_t buffer_pointer[7];
+#define ITD_BUFFER_POINTER_MASK      0xfffff000
+/* First buffer pointer */
+#define ITD_BUFFER_POINTER_EP_MASK      0xf
+#define ITD_BUFFER_POINTER_EP_SHIFT     8
+#define ITD_BUFFER_POINTER_ADDR_MASK    0x3f
+#define ITD_BUFFER_POINTER_ADDR_SHIFT   0
+/* Second buffer pointer */
+#define ITD_BUFFER_POINTER_IN_FLAG            (1 << 11)
+#define ITD_BUFFER_POINTER_MAX_PACKET_MASK    0x3ff
+#define ITD_BUFFER_POINTER_MAX_PACKET_SHIFT   0
+/* Third buffer pointer */
+#define ITD_BUFFER_POINTER_MULTI_MASK    0x3
+#define ITD_BUFFER_POINTER_MULTI_SHIFT   0
+
+	/* 64 bit struct only */
+	volatile uint32_t extended_bp[7];
+} itd_t;
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/ehci/hw_struct/link_pointer.h
===================================================================
--- uspace/drv/bus/usb/ehci/hw_struct/link_pointer.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/hw_struct/link_pointer.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+#ifndef DRV_EHCI_HW_STRUCT_LINK_POINTER_H
+#define DRV_EHCI_HW_STRUCT_LINK_POINTER_H
+
+#include <sys/types.h>
+
+/** EHCI link pointer, used by many data structures */
+typedef volatile uint32_t link_pointer_t;
+
+#define LINK_POINTER_ADDRESS_MASK   0xfffffff0 /* upper 28 bits */
+
+#define LINK_POINTER_TERMINATE_FLAG   (1 << 0)
+
+enum {
+	LINK_POINTER_TYPE_iTD  = 0x0 << 1,
+	LINK_POINTER_TYPE_QH   = 0x1 << 1,
+	LINK_POINTER_TYPE_siTD = 0x2 << 1,
+	LINK_POINTER_TYPE_FSTN = 0x3 << 1,
+	LINK_POINTER_TYPE_MASK = 0x3 << 1,
+};
+
+#define LINK_POINTER_QH(address) \
+	((address & LINK_POINTER_ADDRESS_MASK) | LINK_POINTER_TYPE_QH)
+
+#define LINK_POINTER_TD(address) \
+	(address & LINK_POINTER_ADDRESS_MASK)
+
+#define LINK_POINTER_TERM \
+	((link_pointer_t)LINK_POINTER_TERMINATE_FLAG)
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/ehci/hw_struct/mem_access.h
===================================================================
--- uspace/drv/bus/usb/ehci/hw_struct/mem_access.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/hw_struct/mem_access.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2013 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 drvusbohci
+ * @{
+ */
+/** @file
+ * @brief OHCI driver
+ */
+#ifndef DRV_EHCI_HW_MEM_ACCESS_H
+#define DRV_EHCI_HW_MEM_ACCESS_H
+
+#include <byteorder.h>
+
+#define EHCI_MEM32_WR(reg, val) reg = host2uint32_t_le(val)
+#define EHCI_MEM32_RD(reg) uint32_t_le2host(reg)
+#define EHCI_MEM32_SET(reg, val) reg |= host2uint32_t_le(val)
+#define EHCI_MEM32_CLR(reg, val) reg &= host2uint32_t_le(~val)
+
+#endif
+
+/*
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/hw_struct/queue_head.c
===================================================================
--- uspace/drv/bus/usb/ehci/hw_struct/queue_head.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/hw_struct/queue_head.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2013 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+
+#include <assert.h>
+#include <usb/usb.h>
+#include <mem.h>
+#include <macros.h>
+
+#include "mem_access.h"
+
+#include "queue_head.h"
+
+const uint32_t speed[] = {
+	[USB_SPEED_LOW] = QH_EP_CHAR_EPS_LS,
+	[USB_SPEED_FULL] = QH_EP_CHAR_EPS_FS,
+	[USB_SPEED_HIGH] = QH_EP_CHAR_EPS_HS,
+};
+
+void qh_init(qh_t *instance, const endpoint_t *ep)
+{
+	assert(instance);
+	memset(instance, 0, sizeof(*instance));
+
+	EHCI_MEM32_WR(instance->horizontal, LINK_POINTER_TERM);
+	EHCI_MEM32_WR(instance->current, LINK_POINTER_TERM);
+	EHCI_MEM32_WR(instance->next, LINK_POINTER_TERM);
+	EHCI_MEM32_WR(instance->alternate, LINK_POINTER_TERM);
+	if (ep == NULL) {
+		/* Mark as halted and list head, used by endpoint lists
+		 * as dummy */
+		EHCI_MEM32_WR(instance->ep_char, QH_EP_CHAR_H_FLAG);
+		EHCI_MEM32_WR(instance->status, QH_STATUS_HALTED_FLAG);
+		return;
+	}
+	assert(ep->speed < ARRAY_SIZE(speed));
+	EHCI_MEM32_WR(instance->ep_char,
+	    QH_EP_CHAR_ADDR_SET(ep->address) |
+	    QH_EP_CHAR_EP_SET(ep->endpoint) |
+	    speed[ep->speed] |
+	    QH_EP_CHAR_MAX_LENGTH_SET(ep->max_packet_size)
+	);
+	if (ep->transfer_type == USB_TRANSFER_CONTROL) {
+		if (ep->speed != USB_SPEED_HIGH)
+			EHCI_MEM32_SET(instance->ep_char, QH_EP_CHAR_C_FLAG);
+		/* Let BULK and INT use queue head managed toggle,
+		 * CONTROL needs special toggle handling anyway */
+		EHCI_MEM32_SET(instance->ep_char, QH_EP_CHAR_DTC_FLAG);
+	}
+
+	// TODO Figure out how to correctly use CMASK and SMASK for LS/FS
+	// INT transfers. Current values are just guesses
+	/* Setting TT stuff on HS endpoints is OK, the fields are ignored,
+	 * and so is setting multi on async (should be 1 anyway)*/
+	EHCI_MEM32_WR(instance->ep_cap,
+	    QH_EP_CAP_MULTI_SET(ep->packets) |
+	    QH_EP_CAP_TT_PORT_SET(ep->tt.port) |
+	    QH_EP_CAP_TT_ADDR_SET(ep->tt.address) |
+	    QH_EP_CAP_C_MASK_SET(3 << 2)
+	);
+
+	if (ep->transfer_type == USB_TRANSFER_INTERRUPT) {
+		EHCI_MEM32_SET(instance->ep_cap, QH_EP_CAP_S_MASK_SET(3));
+	}
+	/* The rest of the fields are transfer working area, it should be ok to
+	 * leave it NULL */
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/ehci/hw_struct/queue_head.h
===================================================================
--- uspace/drv/bus/usb/ehci/hw_struct/queue_head.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/hw_struct/queue_head.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,219 @@
+/*
+ * Copyright (c) 2013 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+#ifndef DRV_EHCI_HW_STRUCT_QH_H
+#define DRV_EHCI_HW_STRUCT_QH_H
+
+#include <assert.h>
+#include <sys/types.h>
+#include <usb/host/endpoint.h>
+
+#include "../utils/malloc32.h"
+#include "link_pointer.h"
+#include "transfer_descriptor.h"
+#include "mem_access.h"
+
+/** This structure is defined in EHCI design guide p. 46 */
+typedef struct queue_head {
+	link_pointer_t horizontal;
+
+	volatile uint32_t ep_char;
+#define QH_EP_CHAR_RL_MASK    0xf
+#define QH_EP_CHAR_RL_SHIFT   28
+#define QH_EP_CHAR_C_FLAG     (1 << 27)
+#define QH_EP_CHAR_MAX_LENGTH_MASK   0x7ff
+#define QH_EP_CHAR_MAX_LENGTH_SHIFT  16
+#define QH_EP_CHAR_MAX_LENGTH_SET(len) \
+    (((len) & QH_EP_CHAR_MAX_LENGTH_MASK) << QH_EP_CHAR_MAX_LENGTH_SHIFT)
+#define QH_EP_CHAR_MAX_LENGTH_GET(val) \
+    (((val) >> QH_EP_CHAR_MAX_LENGTH_SHIFT) & QH_EP_CHAR_MAX_LENGTH_MASK)
+#define QH_EP_CHAR_H_FLAG     (1 << 15)
+#define QH_EP_CHAR_DTC_FLAG   (1 << 14)
+#define QH_EP_CHAR_EPS_FS     (0x0 << 12)
+#define QH_EP_CHAR_EPS_LS     (0x1 << 12)
+#define QH_EP_CHAR_EPS_HS     (0x2 << 12)
+#define QH_EP_CHAR_EPS_MASK   (0x3 << 12)
+#define QH_EP_CHAR_EP_MASK    0xf
+#define QH_EP_CHAR_EP_SHIFT   8
+#define QH_EP_CHAR_EP_SET(num) \
+    (((num) & QH_EP_CHAR_EP_MASK) << QH_EP_CHAR_EP_SHIFT)
+#define QH_EP_CHAR_ADDR_GET(val) \
+    (((val) >> QH_EP_CHAR_ADDR_SHIFT) & QH_EP_CHAR_ADDR_MASK)
+#define QH_EP_CHAR_INACT_FLAG (1 << 7)
+#define QH_EP_CHAR_ADDR_MASK  0x3f
+#define QH_EP_CHAR_ADDR_SHIFT 0
+#define QH_EP_CHAR_ADDR_SET(addr) \
+    (((addr) & QH_EP_CHAR_ADDR_MASK) << QH_EP_CHAR_ADDR_SHIFT)
+#define QH_EP_CHAR_ADDR_GET(val) \
+    (((val) >> QH_EP_CHAR_ADDR_SHIFT) & QH_EP_CHAR_ADDR_MASK)
+
+	volatile uint32_t ep_cap;
+#define QH_EP_CAP_MULTI_MASK   0x3
+#define QH_EP_CAP_MULTI_SHIFT  30
+#define QH_EP_CAP_MULTI_SET(count) \
+	(((count) & QH_EP_CAP_MULTI_MASK) << QH_EP_CAP_MULTI_SHIFT)
+#define QH_EP_CAP_PORT_MASK    0x7f
+#define QH_EP_CAP_PORT_SHIFT   23
+#define QH_EP_CAP_TT_PORT_SET(addr) \
+	(((addr) & QH_EP_CAP_HUB_MASK) << QH_EP_CAP_HUB_SHIFT)
+#define QH_EP_CAP_HUB_MASK     0x7f
+#define QH_EP_CAP_HUB_SHIFT    16
+#define QH_EP_CAP_TT_ADDR_SET(addr) \
+	(((addr) & QH_EP_CAP_HUB_MASK) << QH_EP_CAP_HUB_SHIFT)
+#define QH_EP_CAP_C_MASK_MASK  0xff
+#define QH_EP_CAP_C_MASK_SHIFT 8
+#define QH_EP_CAP_C_MASK_SET(val) \
+	(((val) & QH_EP_CAP_C_MASK_MASK) << QH_EP_CAP_C_MASK_SHIFT)
+#define QH_EP_CAP_S_MASK_MASK  0xff
+#define QH_EP_CAP_S_MASK_SHIFT 0
+#define QH_EP_CAP_S_MASK_SET(val) \
+	(((val) & QH_EP_CAP_S_MASK_MASK) << QH_EP_CAP_S_MASK_SHIFT)
+
+	link_pointer_t current;
+/* Transfer overlay starts here */
+	link_pointer_t next;
+	link_pointer_t alternate;
+#define QH_ALTERNATE_NACK_CNT_MASK   0x7
+#define QH_ALTERNATE_NACK_CNT_SHIFT  1
+
+	volatile uint32_t status;
+#define QH_STATUS_TOGGLE_FLAG   (1 << 31)
+#define QH_STATUS_TOTAL_MASK    0x7fff
+#define QH_STATUS_TOTAL_SHIFT   16
+#define QH_STATUS_IOC_FLAG      (1 << 15)
+#define QH_STATUS_C_PAGE_MASK   0x7
+#define QH_STATUS_C_PAGE_SHIFT  12
+#define QH_STATUS_CERR_MASK     0x3
+#define QH_STATUS_CERR_SHIFT    10
+#define QH_STATUS_PID_MASK      0x3
+#define QH_STATUS_PID_SHIFT     8
+#define QH_STATUS_ACTIVE_FLAG   (1 << 7)
+#define QH_STATUS_HALTED_FLAG   (1 << 6)
+#define QH_STATUS_BUFF_ERROR_FLAG  (1 << 5)
+#define QH_STATUS_BABBLE_FLAG   (1 << 4)
+#define QH_STATUS_TRANS_ERR_FLAG   (1 << 3)
+#define QH_STATUS_MISSED_FLAG   (1 << 2)
+#define QH_STATUS_SPLIT_FLAG    (1 << 1)
+#define QH_STATUS_PING_FLAG     (1 << 0)
+
+	volatile uint32_t buffer_pointer[5];
+#define QH_BUFFER_POINTER_MASK   0xfffff000
+/* Only the first buffer pointer */
+#define QH_BUFFER_POINTER_OFFSET_MASK   0xfff
+#define QH_BUFFER_POINTER_OFFSET_SHIFT  0
+/* Only the second buffer pointer */
+#define QH_BUFFER_POINTER_C_MASK_MASK   0xff
+#define QH_BUFFER_POINTER_C_MASK_SHIFFT 0
+/* Only the third buffer pointer */
+#define QH_BUFFER_POINTER_S_MASK      0x7f
+#define QH_BUFFER_POINTER_S_SHIFT     5
+#define QH_BUFFER_POINTER_FTAG_MASK   0x1f
+#define QH_BUFFER_POINTER_FTAG_SHIFT  0
+
+	/* 64 bit struct only */
+	volatile uint32_t extended_bp[5];
+} qh_t;
+
+static inline void qh_append_qh(qh_t *qh, const qh_t *next)
+{
+	assert(qh);
+	assert(next);
+	const uint32_t pa = addr_to_phys(next);
+	assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
+	EHCI_MEM32_WR(qh->horizontal, LINK_POINTER_QH(pa));
+}
+
+static inline uintptr_t qh_next(const qh_t *qh)
+{
+	assert(qh);
+	return (EHCI_MEM32_RD(qh->horizontal) & LINK_POINTER_ADDRESS_MASK);
+}
+
+static inline bool qh_toggle_from_td(const qh_t *qh)
+{
+	assert(qh);
+	return (EHCI_MEM32_RD(qh->ep_cap) & QH_EP_CHAR_DTC_FLAG);
+}
+
+static inline void qh_toggle_set(qh_t *qh, int toggle)
+{
+	assert(qh);
+	if (toggle)
+		EHCI_MEM32_SET(qh->status, QH_STATUS_TOGGLE_FLAG);
+	else
+		EHCI_MEM32_CLR(qh->status, QH_STATUS_TOGGLE_FLAG);
+}
+
+static inline int qh_toggle_get(const qh_t *qh)
+{
+	assert(qh);
+	return (EHCI_MEM32_RD(qh->status) & QH_STATUS_TOGGLE_FLAG) ? 1 : 0;
+}
+
+static inline bool qh_halted(const qh_t *qh)
+{
+	assert(qh);
+	return (EHCI_MEM32_RD(qh->status) & QH_STATUS_HALTED_FLAG);
+}
+
+static inline void qh_clear_halt(qh_t *qh)
+{
+	assert(qh);
+	EHCI_MEM32_CLR(qh->status, QH_STATUS_HALTED_FLAG);
+}
+
+static inline void qh_set_next_td(qh_t *qh, td_t *td)
+{
+	assert(qh);
+	assert(td);
+	EHCI_MEM32_WR(qh->next, LINK_POINTER_TD(addr_to_phys(td)));
+}
+
+static inline bool qh_transfer_active(const qh_t *qh)
+{
+	assert(qh);
+	return (EHCI_MEM32_RD(qh->status) & QH_STATUS_ACTIVE_FLAG);
+}
+
+static inline bool qh_transfer_pending(const qh_t *qh)
+{
+	assert(qh);
+	return !(EHCI_MEM32_RD(qh->next) & LINK_POINTER_TERMINATE_FLAG);
+}
+
+
+void qh_init(qh_t *instance, const endpoint_t *ep);
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/ehci/hw_struct/split_iso_transfer_descriptor.h
===================================================================
--- uspace/drv/bus/usb/ehci/hw_struct/split_iso_transfer_descriptor.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/hw_struct/split_iso_transfer_descriptor.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2013 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+#ifndef DRV_EHCI_HW_STRUCT_SPLIT_ISO_TRANSFER_DESCRIPTOR_H
+#define DRV_EHCI_HW_STRUCT_SPLIT_ISO_TRANSFER_DESCRIPTOR_H
+
+#include <sys/types.h>
+#include "link_pointer.h"
+
+/** Isochronous transfer descriptor (split only) */
+typedef struct sitd {
+	link_pointer_t next;
+
+	volatile uint32_t ep;
+#define SITD_EP_IN_FLAG         (1 << 31)
+#define SITD_EP_PORT_MASK       0x3f
+#define SITD_EP_PORT_SHIFT      24
+#define SITD_EP_HUB_ADDR_MASK   0x3f
+#define SITD_EP_HUB_ADDR_SHIFT  16
+#define SITD_EP_EP_MASK         0xf
+#define SITD_EP_EP_SHIFT        8
+#define SITD_EP_ADDR_MASK       0x3f
+#define SITD_EP_ADDR_SHIFT      0
+
+	volatile uint32_t uframe;
+#define SITD_uFRAME_CMASK_MASK    0xff
+#define SITD_uFRAME_CMASK_SHIFT   8
+#define SITD_uFRAME_SMASK_MASK    0xff
+#define SITD_uFRAME_SMASK_SHIFT   0
+
+	volatile uint32_t status;
+#define SITD_STATUS_IOC_FLAG            (1 << 31)
+#define SITD_STATUS_PAGE_FLAG           (1 << 30)
+#define SITD_STATUS_TOTAL_MASK          0x3ff
+#define SITD_STATUS_TOTAL_SHIFT         16
+#define SITD_STATUS_uFRAME_CMASK_MASK   0xff
+#define SITD_STATUS_uFRAME_CMAKS_SHIFT  8
+#define SITD_STATUS_ACTIVE_FLAG         (1 << 7)
+#define SITD_STATUS_ERR_FLAG            (1 << 6)
+#define SITD_STATUS_DATA_ERROR_FLAG     (1 << 5)
+#define SITD_STATUS_BABBLE_FLAG         (1 << 4)
+#define SITD_STATUS_TRANS_ERROR_FLAG    (1 << 3)
+#define SITD_STATUS_MISSED_uFRAME_FLAG  (1 << 2)
+#define SITD_STATUS_SPLIT_COMPLETE_FLAG (1 << 1)
+
+	volatile uint32_t buffer_pointer[2];
+#define SITD_BUFFER_POINTER_MASK   0xfffff000
+/* Only the first page pointer */
+#define SITD_BUFFER_POINTER_CURRENT_MASK    0xfff
+#define SITD_BUFFER_POINTER_CURRENT_SHIFT   0
+/* Only the second page pointer */
+#define SITD_BUFFER_POINTER_TP_MASK       0x3
+#define SITD_BUFFER_POINTER_TP_SHIFT      3
+#define SITD_BUFFER_POINTER_COUNT_MASK    0x7
+#define SITD_BUFFER_POINTER_COUNT_SHIFT   0
+
+	link_pointer_t back;
+
+	/* 64 bit struct only */
+	volatile uint32_t extended_bp[2];
+} sitd_t;
+#endif
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/hw_struct/transfer_descriptor.c
===================================================================
--- uspace/drv/bus/usb/ehci/hw_struct/transfer_descriptor.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/hw_struct/transfer_descriptor.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2014 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <macros.h>
+#include <mem.h>
+
+#include <usb/usb.h>
+
+#include "../utils/malloc32.h"
+#include "mem_access.h"
+#include "transfer_descriptor.h"
+
+
+int td_error(const td_t *td)
+{
+	assert(td);
+	const uint32_t status = EHCI_MEM32_RD(td->status);
+	if (status & TD_STATUS_HALTED_FLAG) {
+		if (status & TD_STATUS_TRANS_ERR_FLAG)
+			return EIO;
+		if (status & TD_STATUS_BABBLE_FLAG)
+			return EIO;
+		if (status & TD_STATUS_BUFF_ERROR_FLAG)
+			return EOVERFLOW;
+		return ESTALL;
+	}
+	if (status & TD_STATUS_ACTIVE_FLAG)
+		return EINPROGRESS;
+	return EOK;
+}
+
+/** USB direction to EHCI TD values translation table */
+static const uint32_t dir[] = {
+	[USB_DIRECTION_IN] = TD_STATUS_PID_IN,
+	[USB_DIRECTION_OUT] = TD_STATUS_PID_OUT,
+	[USB_DIRECTION_BOTH] = TD_STATUS_PID_SETUP,
+};
+
+/**
+ * Initialize EHCI TD.
+ * @param instance TD structure to initialize.
+ * @param next Next TD in ED list.
+ * @param direction Used to determine PID, BOTH means setup PID.
+ * @param buffer Pointer to the first byte of transferred data.
+ * @param size Size of the buffer.
+ * @param toggle Toggle bit value, use 0/1 to set explicitly,
+ *        any other value means that ED toggle will be used.
+ */
+void td_init(td_t *instance, const td_t *next,
+    usb_direction_t direction, const void *buffer, size_t size, int toggle,
+    bool ioc)
+{
+	assert(instance);
+	memset(instance, 0, sizeof(td_t));
+	/* Set PID and Total size */
+	assert((size & TD_STATUS_TOTAL_MASK) == size);
+	EHCI_MEM32_WR(instance->status,
+	    ((dir[direction] & TD_STATUS_PID_MASK) << TD_STATUS_PID_SHIFT) |
+	    ((size & TD_STATUS_TOTAL_MASK) << TD_STATUS_TOTAL_SHIFT) |
+	    (ioc ? TD_STATUS_IOC_FLAG : 0) );
+
+	if (toggle == 0 || toggle == 1) {
+		EHCI_MEM32_SET(instance->status,
+		    toggle ? TD_STATUS_TOGGLE_FLAG : 0);
+	}
+
+	if (buffer != NULL) {
+		assert(size != 0);
+		for (unsigned i = 0; (i < ARRAY_SIZE(instance->buffer_pointer))
+		    && size; ++i) {
+			const uintptr_t page =
+			    (addr_to_phys(buffer) & TD_BUFFER_POINTER_MASK);
+			const size_t offset =
+			    ((uintptr_t)buffer & TD_BUFFER_POINTER_OFFSET_MASK);
+			assert(offset == 0 || i == 0);
+			size -= min((4096 - offset), size);
+			buffer += min((4096 - offset), size);
+			EHCI_MEM32_WR(instance->buffer_pointer[i],
+			    page | offset);
+		}
+	}
+
+	EHCI_MEM32_WR(instance->next, next ?
+	    LINK_POINTER_TD(addr_to_phys(next)) : LINK_POINTER_TERM);
+
+	EHCI_MEM32_WR(instance->alternate, LINK_POINTER_TERM);
+	EHCI_MEM32_SET(instance->status, TD_STATUS_ACTIVE_FLAG);
+}
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/ehci/hw_struct/transfer_descriptor.h
===================================================================
--- uspace/drv/bus/usb/ehci/hw_struct/transfer_descriptor.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/hw_struct/transfer_descriptor.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2013 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+#ifndef DRV_EHCI_HW_STRUCT_TRANSFER_DESCRIPTOR_H
+#define DRV_EHCI_HW_STRUCT_TRANSFER_DESCRIPTOR_H
+
+#include <sys/types.h>
+#include "link_pointer.h"
+#include "mem_access.h"
+
+/** Transfer descriptor (non-ISO) */
+typedef struct td {
+	link_pointer_t next;
+	link_pointer_t alternate;
+
+	volatile uint32_t status;
+#define TD_STATUS_TOGGLE_FLAG   (1 << 31)
+#define TD_STATUS_TOTAL_MASK    0x7fff
+#define TD_STATUS_TOTAL_SHIFT   16
+#define TD_STATUS_IOC_FLAG      (1 << 15)
+#define TD_STATUS_C_PAGE_MASK   0x7
+#define TD_STATUS_C_PAGE_SHIFT  12
+#define TD_STATUS_CERR_MASK     0x3
+#define TD_STATUS_CERR_SHIFT    10
+#define TD_STATUS_PID_MASK      0x3
+#define TD_STATUS_PID_SHIFT     8
+#define TD_STATUS_PID_OUT       0x0
+#define TD_STATUS_PID_IN        0x1
+#define TD_STATUS_PID_SETUP     0x2
+#define TD_STATUS_ACTIVE_FLAG   (1 << 7)
+#define TD_STATUS_HALTED_FLAG   (1 << 6)
+#define TD_STATUS_BUFF_ERROR_FLAG  (1 << 5)
+#define TD_STATUS_BABBLE_FLAG   (1 << 4)
+#define TD_STATUS_TRANS_ERR_FLAG   (1 << 3)
+#define TD_STATUS_MISSED_FLAG   (1 << 2)
+#define TD_STATUS_SPLIT_FLAG    (1 << 1)
+#define TD_STATUS_PING_FLAG     (1 << 0)
+
+	volatile uint32_t buffer_pointer[5];
+#define TD_BUFFER_POINTER_MASK   0xfffff000
+/* Only the first page pointer */
+#define TD_BUFFER_POINTER_OFFSET_MASK    0xfff
+
+	/* 64 bit struct only */
+	volatile uint32_t extended_bp[5];
+} td_t;
+
+static inline bool td_active(const td_t *td)
+{
+	assert(td);
+	return (EHCI_MEM32_RD(td->status) & TD_STATUS_HALTED_FLAG) != 0;
+}
+
+static inline size_t td_remain_size(const td_t *td)
+{
+	assert(td);
+	return (EHCI_MEM32_RD(td->status) >> TD_STATUS_TOTAL_SHIFT) &
+	    TD_STATUS_TOTAL_MASK;
+}
+
+int td_error(const td_t *td);
+
+void td_init(td_t *td, const td_t *next, usb_direction_t dir, const void * buf,
+    size_t buf_size, int toggle, bool ioc);
+
+#endif
+/**
+ * @}
+ */
+
Index: uspace/drv/bus/usb/ehci/main.c
===================================================================
--- uspace/drv/bus/usb/ehci/main.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ehci/main.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -33,33 +33,56 @@
  * Main routines of EHCI driver.
  */
-
 #include <ddf/driver.h>
 #include <ddf/interrupt.h>
 #include <device/hw_res.h>
 #include <errno.h>
-#include <stdbool.h>
 #include <str_error.h>
 
 #include <usb_iface.h>
-#include <usb/ddfiface.h>
 #include <usb/debug.h>
-#include <usb/host/hcd.h>
+#include <usb/host/ddf_helpers.h>
 
 #include "res.h"
+#include "hc.h"
+#include "ehci_endpoint.h"
 
 #define NAME "ehci"
 
+static int ehci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
+{
+	assert(hcd);
+	assert(hcd->driver.data == NULL);
+
+	hc_t *instance = malloc(sizeof(hc_t));
+	if (!instance)
+		return ENOMEM;
+
+	const int ret = hc_init(instance, res, irq);
+	if (ret == EOK)
+		hcd_set_implementation(hcd, instance, ehci_hc_schedule,
+		    ehci_endpoint_init, ehci_endpoint_fini, ehci_hc_interrupt,
+		    ehci_hc_status);
+	return ret;
+}
+
+static void ehci_driver_fini(hcd_t *hcd)
+{
+	assert(hcd);
+	if (hcd->driver.data)
+		hc_fini(hcd->driver.data);
+
+	free(hcd->driver.data);
+	hcd_set_implementation(hcd, NULL, NULL, NULL, NULL, NULL, NULL);
+}
+
 static int ehci_dev_add(ddf_dev_t *device);
 
-static driver_ops_t ehci_driver_ops = {
+static const driver_ops_t ehci_driver_ops = {
 	.dev_add = ehci_dev_add,
 };
 
-static driver_t ehci_driver = {
+static const driver_t ehci_driver = {
 	.name = NAME,
 	.driver_ops = &ehci_driver_ops
-};
-static ddf_dev_ops_t hc_ops = {
-	.interfaces[USBHC_DEV_IFACE] = &hcd_iface,
 };
 
@@ -72,73 +95,27 @@
 static int ehci_dev_add(ddf_dev_t *device)
 {
-	ddf_fun_t *hc_fun = NULL;
-	bool fun_bound = false;
-
+	usb_log_debug("ehci_dev_add() called\n");
 	assert(device);
 
-	addr_range_t reg_range;
-	int irq = 0;
-
-	int rc = get_my_registers(device, &reg_range, &irq);
-	if (rc != EOK) {
-		usb_log_error("Failed to get memory addresses for %" PRIun
-		    ": %s.\n", ddf_dev_get_handle(device), str_error(rc));
-		goto error;
+	int ret = disable_legacy(device);
+	if (ret != EOK) {
+		usb_log_error("Failed to disable EHCI legacy support: %s\n",
+		    str_error(ret));
+		return ret;
 	}
 
-	usb_log_info("Memory mapped regs at %p (size %zu), IRQ %d.\n",
-	    RNGABSPTR(reg_range), RNGSZ(reg_range), irq);
-
-	rc = disable_legacy(device, &reg_range);
-	if (rc != EOK) {
-		usb_log_error("Failed to disable legacy USB: %s.\n",
-		    str_error(rc));
-		goto error;
+	ret = ddf_hcd_device_setup_all(device, USB_SPEED_HIGH,
+	    BANDWIDTH_AVAILABLE_USB20, bandwidth_count_usb11,
+	    ddf_hcd_gen_irq_handler, ehci_hc_gen_irq_code,
+	    ehci_driver_init, ehci_driver_fini);
+	if (ret != EOK) {
+		usb_log_error("Failed to initialize EHCI driver: %s.\n",
+		    str_error(ret));
+		return ret;
 	}
-
-	hc_fun = ddf_fun_create(device, fun_exposed, "ehci_hc");
-	if (hc_fun == NULL) {
-		usb_log_error("Failed to create EHCI function.\n");
-		rc = ENOMEM;
-		goto error;
-	}
-
-	hcd_t *ehci_hc = ddf_fun_data_alloc(hc_fun, sizeof(hcd_t));
-	if (ehci_hc == NULL) {
-		usb_log_error("Failed to alloc generic HC driver.\n");
-		rc = ENOMEM;
-		goto error;
-	}
-
-	/* High Speed, no bandwidth */
-	hcd_init(ehci_hc, USB_SPEED_HIGH, 0, NULL);
-	ddf_fun_set_ops(hc_fun,  &hc_ops);
-
-	rc = ddf_fun_bind(hc_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to bind EHCI function: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	fun_bound = true;
-
-	rc = ddf_fun_add_to_category(hc_fun, USB_HC_CATEGORY);
-	if (rc != EOK) {
-		usb_log_error("Failed to add EHCI to HC class: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	usb_log_info("Controlling new EHCI device `%s' (handle %" PRIun ").\n",
-	    ddf_dev_get_name(device), ddf_dev_get_handle(device));
+	usb_log_info("Controlling new EHCI device '%s'.\n",
+	    ddf_dev_get_name(device));
 
 	return EOK;
-error:
-	if (fun_bound)
-		ddf_fun_unbind(hc_fun);
-	if (hc_fun != NULL)
-		ddf_fun_destroy(hc_fun);
-	return rc;
 }
 
Index: uspace/drv/bus/usb/ehci/res.c
===================================================================
--- uspace/drv/bus/usb/ehci/res.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ehci/res.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -46,16 +46,5 @@
 
 #include "res.h"
-
-#define HCC_PARAMS_OFFSET 0x8
-#define HCC_PARAMS_EECP_MASK 0xff
-#define HCC_PARAMS_EECP_OFFSET 8
-
-#define CMD_OFFSET 0x0
-#define STS_OFFSET 0x4
-#define INT_OFFSET 0x8
-#define CFG_OFFSET 0x40
-
-#define USBCMD_RUN 1
-#define USBSTS_HALTED (1 << 12)
+#include "ehci_regs.h"
 
 #define USBLEGSUP_OFFSET 0
@@ -67,62 +56,4 @@
 #define WAIT_STEP 10
 
-
-/** Get address of registers and IRQ for given device.
- *
- * @param[in] dev Device asking for the addresses.
- * @param[out] mem_regs_p Pointer to the register range.
- * @param[out] irq_no IRQ assigned to the device.
- * @return Error code.
- */
-int get_my_registers(ddf_dev_t *dev,
-    addr_range_t *mem_regs_p, int *irq_no)
-{
-	assert(dev);
-	
-	async_sess_t *parent_sess = devman_parent_device_connect(
-	    EXCHANGE_SERIALIZE, ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);
-	if (!parent_sess)
-		return ENOMEM;
-	
-	hw_res_list_parsed_t hw_res;
-	hw_res_list_parsed_init(&hw_res);
-	const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
-	async_hangup(parent_sess);
-	if (ret != EOK) {
-		return ret;
-	}
-
-	if (hw_res.irqs.count != 1 || hw_res.mem_ranges.count != 1) {
-		hw_res_list_parsed_clean(&hw_res);
-		return ENOENT;
-	}
-
-	if (mem_regs_p)
-		*mem_regs_p = hw_res.mem_ranges.ranges[0];
-	if (irq_no)
-		*irq_no = hw_res.irqs.irqs[0];
-
-	hw_res_list_parsed_clean(&hw_res);
-	return EOK;
-}
-
-/** Calls the PCI driver with a request to enable interrupts
- *
- * @param[in] device Device asking for interrupts
- * @return Error code.
- */
-int enable_interrupts(ddf_dev_t *device)
-{
-	async_sess_t *parent_sess = devman_parent_device_connect(
-	    EXCHANGE_SERIALIZE, ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
-	if (!parent_sess)
-		return ENOMEM;
-	
-	const bool enabled = hw_res_enable_interrupt(parent_sess);
-	async_hangup(parent_sess);
-	
-	return enabled ? EOK : EIO;
-}
-
 /** Implements BIOS hands-off routine as described in EHCI spec
  *
@@ -131,5 +62,5 @@
  * @return Error code.
  */
-static int disable_extended_caps(ddf_dev_t *device, unsigned eecp)
+static int disable_extended_caps(async_sess_t *parent_sess, unsigned eecp)
 {
 	/* nothing to do */
@@ -137,19 +68,12 @@
 		return EOK;
 
-	async_sess_t *parent_sess = devman_parent_device_connect(
-	    EXCHANGE_SERIALIZE, ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
-	if (!parent_sess)
-		return ENOMEM;
-
 	/* Read the first EEC. i.e. Legacy Support register */
 	uint32_t usblegsup;
-	int rc = pci_config_space_read_32(parent_sess,
+	int ret = pci_config_space_read_32(parent_sess,
 	    eecp + USBLEGSUP_OFFSET, &usblegsup);
-	if (rc != EOK) {
-		usb_log_error("Failed to read USBLEGSUP: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
+	if (ret != EOK) {
+		usb_log_error("Failed to read USBLEGSUP: %s.\n", str_error(ret));
+		return ret;
+	}
 	usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup);
 
@@ -157,31 +81,21 @@
 	 * byte. (OS Control semaphore)*/
 	usb_log_debug("Requesting OS control.\n");
-	rc = pci_config_space_write_8(parent_sess,
+	ret = pci_config_space_write_8(parent_sess,
 	    eecp + USBLEGSUP_OFFSET + 3, 1);
-	if (rc != EOK) {
+	if (ret != EOK) {
 		usb_log_error("Failed to request OS EHCI control: %s.\n",
-		    str_error(rc));
-		goto error;
+		    str_error(ret));
+		return ret;
 	}
 
 	size_t wait = 0;
 	/* Wait for BIOS to release control. */
-	rc = pci_config_space_read_32(
+	ret = pci_config_space_read_32(
 	    parent_sess, eecp + USBLEGSUP_OFFSET, &usblegsup);
-	if (rc != EOK) {
-		usb_log_error("Failed reading PCI config space: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	while ((wait < DEFAULT_WAIT) && (usblegsup & USBLEGSUP_BIOS_CONTROL)) {
+	while ((ret == EOK) && (wait < DEFAULT_WAIT)
+	    && (usblegsup & USBLEGSUP_BIOS_CONTROL)) {
 		async_usleep(WAIT_STEP);
-		rc = pci_config_space_read_32(parent_sess,
+		ret = pci_config_space_read_32(parent_sess,
 		    eecp + USBLEGSUP_OFFSET, &usblegsup);
-		if (rc != EOK) {
-			usb_log_error("Failed reading PCI config space: %s.\n",
-			    str_error(rc));
-			goto error;
-		}
 		wait += WAIT_STEP;
 	}
@@ -189,5 +103,4 @@
 	if ((usblegsup & USBLEGSUP_BIOS_CONTROL) == 0) {
 		usb_log_info("BIOS released control after %zu usec.\n", wait);
-		async_hangup(parent_sess);
 		return EOK;
 	}
@@ -196,10 +109,10 @@
 	usb_log_warning( "BIOS failed to release control after "
 	    "%zu usecs, force it.\n", wait);
-	rc = pci_config_space_write_32(parent_sess,
+	ret = pci_config_space_write_32(parent_sess,
 	    eecp + USBLEGSUP_OFFSET, USBLEGSUP_OS_CONTROL);
-	if (rc != EOK) {
-		usb_log_error("Failed to force OS control: "
-		    "%s.\n", str_error(rc));
-		goto error;
+	if (ret != EOK) {
+		usb_log_error("Failed to force OS control: %s.\n",
+		    str_error(ret));
+		return ret;
 	}
 
@@ -213,12 +126,11 @@
 		/* Read the second EEC Legacy Support and Control register */
 		uint32_t usblegctlsts;
-		rc = pci_config_space_read_32(parent_sess,
+		ret = pci_config_space_read_32(parent_sess,
 		    eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);
-		if (rc != EOK) {
+		if (ret != EOK) {
 			usb_log_error("Failed to get USBLEGCTLSTS: %s.\n",
-			    str_error(rc));
-			goto error;
+			    str_error(ret));
+			return ret;
 		}
-
 		usb_log_debug("USBLEGCTLSTS: %" PRIx32 ".\n", usblegctlsts);
 		/*
@@ -227,20 +139,21 @@
 		 * interfering. NOTE: Three upper bits are WC
 		 */
-		rc = pci_config_space_write_32(parent_sess,
+		ret = pci_config_space_write_32(parent_sess,
 		    eecp + USBLEGCTLSTS_OFFSET, 0xe0000000);
-		if (rc != EOK) {
-			usb_log_error("Failed(%d) zero USBLEGCTLSTS.\n", rc);
-			goto error;
+		if (ret != EOK) {
+			usb_log_error("Failed to zero USBLEGCTLSTS: %s\n",
+			    str_error(ret));
+			return ret;
 		}
 
 		udelay(10);
-		rc = pci_config_space_read_32(parent_sess,
+		/* read again to amke sure it's zeroed */
+		ret = pci_config_space_read_32(parent_sess,
 		    eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);
-		if (rc != EOK) {
+		if (ret != EOK) {
 			usb_log_error("Failed to get USBLEGCTLSTS 2: %s.\n",
-			    str_error(rc));
-			goto error;
+			    str_error(ret));
+			return ret;
 		}
-
 		usb_log_debug("Zeroed USBLEGCTLSTS: %" PRIx32 ".\n",
 		    usblegctlsts);
@@ -248,38 +161,56 @@
 
 	/* Read again Legacy Support register */
-	rc = pci_config_space_read_32(parent_sess,
+	ret = pci_config_space_read_32(parent_sess,
 	    eecp + USBLEGSUP_OFFSET, &usblegsup);
-	if (rc != EOK) {
+	if (ret != EOK) {
 		usb_log_error("Failed to read USBLEGSUP: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
+		    str_error(ret));
+		return ret;
+	}
 	usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup);
-	async_hangup(parent_sess);
-	return EOK;
-error:
-	async_hangup(parent_sess);
-	return rc;
+	return ret;
 }
 
-int disable_legacy(ddf_dev_t *device, addr_range_t *reg_range)
+int disable_legacy(ddf_dev_t *device)
 {
 	assert(device);
+
+	async_sess_t *parent_sess = devman_parent_device_connect(
+	    EXCHANGE_SERIALIZE, ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
+	if (!parent_sess)
+		return ENOMEM;
+
 	usb_log_debug("Disabling EHCI legacy support.\n");
+
+	hw_res_list_parsed_t res;
+	hw_res_list_parsed_init(&res);
+	int ret = hw_res_get_list_parsed(parent_sess, &res, 0);
+	if (ret != EOK) {
+		usb_log_error("Failed to get resource list: %s\n",
+		    str_error(ret));
+		goto clean;
+	}
+
+	if (res.mem_ranges.count < 1) {
+		usb_log_error("Incorrect mem range count: %zu",
+		    res.mem_ranges.count);
+		ret = EINVAL;
+		goto clean;
+	}
 
 	/* Map EHCI registers */
 	void *regs = NULL;
-	int rc = pio_enable_range(reg_range, &regs);
-	if (rc != EOK) {
+	ret = pio_enable_range(&res.mem_ranges.ranges[0], &regs);
+	if (ret != EOK) {
 		usb_log_error("Failed to map registers %p: %s.\n",
-		    RNGABSPTR(*reg_range), str_error(rc));
-		return rc;
+		    RNGABSPTR(res.mem_ranges.ranges[0]), str_error(ret));
+		goto clean;
 	}
 
 	usb_log_debug2("Registers mapped at: %p.\n", regs);
 
-	const uint32_t hcc_params =
-	    *(uint32_t*)(regs + HCC_PARAMS_OFFSET);
+	ehci_caps_regs_t *ehci_caps = regs;
+
+	const uint32_t hcc_params = EHCI_RD(ehci_caps->hccparams);
 	usb_log_debug("Value of hcc params register: %x.\n", hcc_params);
 
@@ -287,52 +218,18 @@
 	 * position of EEC registers (points to PCI config space) */
 	const uint32_t eecp =
-	    (hcc_params >> HCC_PARAMS_EECP_OFFSET) & HCC_PARAMS_EECP_MASK;
+	    (hcc_params >> EHCI_CAPS_HCC_EECP_SHIFT) & EHCI_CAPS_HCC_EECP_MASK;
 	usb_log_debug("Value of EECP: %x.\n", eecp);
 
-	rc = disable_extended_caps(device, eecp);
-	if (rc != EOK) {
+	ret = disable_extended_caps(parent_sess, eecp);
+	if (ret != EOK) {
 		usb_log_error("Failed to disable extended capabilities: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-
-	/*
-	 * TURN OFF EHCI FOR NOW, DRIVER WILL REINITIALIZE IT IF NEEDED
-	 */
-
-	/* Get size of capability registers in memory space. */
-	const unsigned operation_offset = *(uint8_t*)regs;
-	usb_log_debug("USBCMD offset: %d.\n", operation_offset);
-
-	/* Zero USBCMD register. */
-	volatile uint32_t *usbcmd =
-	    (uint32_t*)((uint8_t*)regs + operation_offset + CMD_OFFSET);
-	volatile uint32_t *usbsts =
-	    (uint32_t*)((uint8_t*)regs + operation_offset + STS_OFFSET);
-	volatile uint32_t *usbconf =
-	    (uint32_t*)((uint8_t*)regs + operation_offset + CFG_OFFSET);
-	volatile uint32_t *usbint =
-	    (uint32_t*)((uint8_t*)regs + operation_offset + INT_OFFSET);
-	usb_log_debug("USBCMD value: %x.\n", *usbcmd);
-	if (*usbcmd & USBCMD_RUN) {
-		*usbsts = 0x3f; /* ack all interrupts */
-		*usbint = 0; /* disable all interrupts */
-		*usbconf = 0; /* release control of RH ports */
-
-		*usbcmd = 0;
-		/* Wait until hc is halted */
-		while ((*usbsts & USBSTS_HALTED) == 0);
-		usb_log_info("EHCI turned off.\n");
-	} else {
-		usb_log_info("EHCI was not running.\n");
-	}
-	usb_log_debug("Registers: \n"
-	    "\t USBCMD(%p): %x(0x00080000 = at least 1ms between interrupts)\n"
-	    "\t USBSTS(%p): %x(0x00001000 = HC halted)\n"
-	    "\t USBINT(%p): %x(0x0 = no interrupts).\n"
-	    "\t CONFIG(%p): %x(0x0 = ports controlled by companion hc).\n",
-	    usbcmd, *usbcmd, usbsts, *usbsts, usbint, *usbint, usbconf,*usbconf);
-
-	return rc;
+		    str_error(ret));
+		    goto clean;
+	}
+clean:
+	//TODO unmap registers
+	hw_res_list_parsed_clean(&res);
+	async_hangup(parent_sess);
+	return ret;
 }
 
Index: uspace/drv/bus/usb/ehci/res.h
===================================================================
--- uspace/drv/bus/usb/ehci/res.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ehci/res.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -39,7 +39,5 @@
 #include <device/hw_res_parsed.h>
 
-int get_my_registers(ddf_dev_t *, addr_range_t *, int *);
-int enable_interrupts(ddf_dev_t *);
-int disable_legacy(ddf_dev_t *, addr_range_t *);
+int disable_legacy(ddf_dev_t *);
 
 #endif
Index: uspace/drv/bus/usb/ehci/utils/malloc32.h
===================================================================
--- uspace/drv/bus/usb/ehci/utils/malloc32.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ehci/utils/malloc32.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2013 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 drvusbehci
+ * @{
+ */
+/** @file
+ * @brief EHCI driver
+ */
+#ifndef DRV_EHCI_UTILS_MALLOC32_H
+#define DRV_EHCI_UTILS_MALLOC32_H
+
+#include <as.h>
+#include <ddi.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/types.h>
+
+/* Generic TDs and EDs require 16byte alignment,
+ * Isochronous TD require 32byte alignment,
+ * buffers do not have to be aligned.
+ */
+#define EHCI_ALIGN   32
+
+#define EHCI_REQUIRED_PAGE_SIZE   4096
+
+/** Get physical address translation
+ *
+ * @param[in] addr Virtual address to translate
+ * @return Physical address if exists, NULL otherwise.
+ */
+static inline uintptr_t addr_to_phys(const void *addr)
+{
+	uintptr_t result;
+	int ret = as_get_physical_mapping(addr, &result);
+	
+	if (ret != EOK)
+		return 0;
+	
+	return result;
+}
+
+/** Physical mallocator simulator
+ *
+ * @param[in] size Size of the required memory space
+ * @return Address of the aligned and big enough memory place, NULL on failure.
+ */
+static inline void * malloc32(size_t size)
+	{ return memalign(EHCI_ALIGN, size); }
+
+/** Physical mallocator simulator
+ *
+ * @param[in] addr Address of the place allocated by malloc32
+ */
+static inline void free32(void *addr)
+	{ free(addr); }
+
+/** Create 4KB page mapping
+ *
+ * @return Address of the mapped page, NULL on failure.
+ */
+static inline void *get_page(void)
+{
+	uintptr_t phys;
+	void *address = AS_AREA_ANY;
+
+	const int ret = dmamem_map_anonymous(EHCI_REQUIRED_PAGE_SIZE,
+	    DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
+	    &address);
+
+	return ((ret == EOK) ? address : NULL);
+}
+
+static inline void return_page(void *page)
+{
+	dmamem_unmap_anonymous(page);
+}
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/ohci/Makefile
===================================================================
--- uspace/drv/bus/usb/ohci/Makefile	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/Makefile	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -31,5 +31,5 @@
 LIBS = \
 	$(LIBUSBHOST_PREFIX)/libusbhost.a \
-	$(LIBUSBDEV_PREFIX)/libusbdev.a \
+	$(LIBUSBVIRT_PREFIX)/libusbvirt.a \
 	$(LIBUSB_PREFIX)/libusb.a \
 	$(LIBDRV_PREFIX)/libdrv.a
@@ -39,4 +39,5 @@
 	-I$(LIBUSBDEV_PREFIX)/include \
 	-I$(LIBUSBHOST_PREFIX)/include \
+	-I$(LIBUSBVIRT_PREFIX)/include \
 	-I$(LIBDRV_PREFIX)/include
 
@@ -47,9 +48,7 @@
 	hc.c \
 	main.c \
-	ohci.c \
 	ohci_batch.c \
 	ohci_endpoint.c \
-	res.c \
-	root_hub.c \
+	ohci_rh.c \
 	hw_struct/endpoint_descriptor.c \
 	hw_struct/transfer_descriptor.c
Index: uspace/drv/bus/usb/ohci/endpoint_list.c
===================================================================
--- uspace/drv/bus/usb/ohci/endpoint_list.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/endpoint_list.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -34,7 +34,11 @@
  */
 
+#include <assert.h>
 #include <errno.h>
+#include <libarch/barrier.h>
+
 #include <usb/debug.h>
-#include <libarch/barrier.h>
+
+#include "utils/malloc32.h"
 #include "endpoint_list.h"
 
Index: uspace/drv/bus/usb/ohci/endpoint_list.h
===================================================================
--- uspace/drv/bus/usb/ohci/endpoint_list.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/endpoint_list.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -35,5 +35,8 @@
 #define DRV_OHCI_ENDPOINT_LIST_H
 
+#include <adt/list.h>
+#include <assert.h>
 #include <fibril_synch.h>
+#include <sys/types.h>
 
 #include "ohci_endpoint.h"
@@ -65,4 +68,5 @@
 	assert(instance);
 	free32(instance->list_head);
+	instance->list_head = NULL;
 }
 
Index: uspace/drv/bus/usb/ohci/hc.c
===================================================================
--- uspace/drv/bus/usb/ohci/hc.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/hc.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -34,16 +34,21 @@
  */
 
+#include <assert.h>
+#include <async.h>
 #include <errno.h>
-#include <stdbool.h>
+#include <macros.h>
+#include <mem.h>
+#include <stdlib.h>
 #include <str_error.h>
-#include <adt/list.h>
-#include <libarch/ddi.h>
+#include <sys/types.h>
 
 #include <usb/debug.h>
 #include <usb/usb.h>
-#include <usb/ddfiface.h>
+
+#include "ohci_endpoint.h"
+#include "ohci_batch.h"
+#include "utils/malloc32.h"
 
 #include "hc.h"
-#include "ohci_endpoint.h"
 
 #define OHCI_USED_INTERRUPTS \
@@ -84,20 +89,8 @@
 };
 
-enum {
-	/** Number of PIO ranges used in IRQ code */
-	hc_irq_pio_range_count = 
-	    sizeof(ohci_pio_ranges) / sizeof(irq_pio_range_t),
-
-	/** Number of commands used in IRQ code */
-	hc_irq_cmd_count =
-	    sizeof(ohci_irq_commands) / sizeof(irq_cmd_t)
-};
-
 static void hc_gain_control(hc_t *instance);
 static void hc_start(hc_t *instance);
 static int hc_init_transfer_lists(hc_t *instance);
 static int hc_init_memory(hc_t *instance);
-static int interrupt_emulator(hc_t *instance);
-static int hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
 
 /** Generate IRQ code.
@@ -106,150 +99,47 @@
  * @param[out] cmds Commands buffer.
  * @param[in] cmds_size Size of the commands buffer (bytes).
- * @param[in] regs Device's register range.
+ * @param[in] hw_res Device's resources.
  *
  * @return Error code.
  */
-int
-hc_get_irq_code(irq_pio_range_t ranges[], size_t ranges_size, irq_cmd_t cmds[],
-    size_t cmds_size, addr_range_t *regs)
-{
-	if ((ranges_size < sizeof(ohci_pio_ranges)) ||
-	    (cmds_size < sizeof(ohci_irq_commands)) ||
-	    (RNGSZ(*regs) < sizeof(ohci_regs_t)))
+int ohci_hc_gen_irq_code(irq_code_t *code, const hw_res_list_parsed_t *hw_res)
+{
+	assert(code);
+	assert(hw_res);
+
+	if (hw_res->irqs.count != 1 || hw_res->mem_ranges.count != 1)
+		return EINVAL;
+
+	const addr_range_t regs = hw_res->mem_ranges.ranges[0];
+
+	if (RNGSZ(regs) < sizeof(ohci_regs_t))
 		return EOVERFLOW;
 
-	memcpy(ranges, ohci_pio_ranges, sizeof(ohci_pio_ranges));
-	ranges[0].base = RNGABS(*regs);
-
-	memcpy(cmds, ohci_irq_commands, sizeof(ohci_irq_commands));
-	ohci_regs_t *registers = (ohci_regs_t *) RNGABSPTR(*regs);
-	cmds[0].addr = (void *) &registers->interrupt_status;
-	cmds[3].addr = (void *) &registers->interrupt_status;
-	OHCI_WR(cmds[1].value, OHCI_USED_INTERRUPTS);
-
-	return EOK;
-}
-
-/** Register interrupt handler.
- *
- * @param[in] device Host controller DDF device
- * @param[in] regs Register range
- * @param[in] irq Interrupt number
- * @paran[in] handler Interrupt handler
- *
- * @return EOK on success or negative error code
- */
-int hc_register_irq_handler(ddf_dev_t *device, addr_range_t *regs, int irq,
-    interrupt_handler_t handler)
-{
-	int rc;
-
-	irq_pio_range_t irq_ranges[hc_irq_pio_range_count];
-	irq_cmd_t irq_cmds[hc_irq_cmd_count];
-
-	irq_code_t irq_code = {
-		.rangecount = hc_irq_pio_range_count,
-		.ranges = irq_ranges,
-		.cmdcount = hc_irq_cmd_count,
-		.cmds = irq_cmds
-	};
-
-	rc = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
-	    sizeof(irq_cmds), regs);
-	if (rc != EOK) {
-		usb_log_error("Failed to generate IRQ code: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-
-	/* Register handler to avoid interrupt lockup */
-	rc = register_interrupt_handler(device, irq, handler, &irq_code);
-	if (rc != EOK) {
-		usb_log_error("Failed to register interrupt handler: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-
-	return EOK;
-}
-
-/** Announce OHCI root hub to the DDF
- *
- * @param[in] instance OHCI driver intance
- * @param[in] hub_fun DDF fuction representing OHCI root hub
- * @return Error code
- */
-int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun)
-{
-	bool addr_reqd = false;
-	bool ep_added = false;
-	bool fun_bound = false;
-	int rc;
-
-	assert(instance);
-	assert(hub_fun);
-
-	/* Try to get address 1 for root hub. */
-	instance->rh.address = 1;
-	rc = usb_device_manager_request_address(
-	    &instance->generic->dev_manager, &instance->rh.address, false,
-	    USB_SPEED_FULL);
-	if (rc != EOK) {
-		usb_log_error("Failed to get OHCI root hub address: %s\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	addr_reqd = true;
-
-	rc = usb_endpoint_manager_add_ep(
-	    &instance->generic->ep_manager, instance->rh.address, 0,
-	    USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL, USB_SPEED_FULL, 64,
-	    0, NULL, NULL);
-	if (rc != EOK) {
-    	        usb_log_error("Failed to register root hub control endpoint: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	ep_added = true;
-
-	rc = ddf_fun_add_match_id(hub_fun, "usb&class=hub", 100);
-	if (rc != EOK) {
-		usb_log_error("Failed to add root hub match-id: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	rc = ddf_fun_bind(hub_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to bind root hub function: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	fun_bound = true;
-
-	rc = usb_device_manager_bind_address(&instance->generic->dev_manager,
-	    instance->rh.address, ddf_fun_get_handle(hub_fun));
-	if (rc != EOK) {
-		usb_log_warning("Failed to bind root hub address: %s.\n",
-		    str_error(rc));
-	}
-
-	return EOK;
-error:
-	if (fun_bound)
-		ddf_fun_unbind(hub_fun);
-	if (ep_added) {
-		usb_endpoint_manager_remove_ep(
-		    &instance->generic->ep_manager, instance->rh.address, 0,
-		    USB_DIRECTION_BOTH, NULL, NULL);
-	}
-	if (addr_reqd) {
-		usb_device_manager_release_address(
-		    &instance->generic->dev_manager, instance->rh.address);
-	}
-	return rc;
+	code->ranges = malloc(sizeof(ohci_pio_ranges));
+	if (code->ranges == NULL)
+		return ENOMEM;
+
+	code->cmds = malloc(sizeof(ohci_irq_commands));
+	if (code->cmds == NULL) {
+		free(code->ranges);
+		return ENOMEM;
+	}
+
+	code->rangecount = ARRAY_SIZE(ohci_pio_ranges);
+	code->cmdcount = ARRAY_SIZE(ohci_irq_commands);
+
+	memcpy(code->ranges, ohci_pio_ranges, sizeof(ohci_pio_ranges));
+	code->ranges[0].base = RNGABS(regs);
+
+	memcpy(code->cmds, ohci_irq_commands, sizeof(ohci_irq_commands));
+	ohci_regs_t *registers = (ohci_regs_t *) RNGABSPTR(regs);
+	code->cmds[0].addr = (void *) &registers->interrupt_status;
+	code->cmds[3].addr = (void *) &registers->interrupt_status;
+	OHCI_WR(code->cmds[1].value, OHCI_USED_INTERRUPTS);
+
+	usb_log_debug("Memory mapped regs at %p (size %zu), IRQ %d.\n",
+	    RNGABSPTR(regs), RNGSZ(regs), hw_res->irqs.irqs[0]);
+
+	return hw_res->irqs.irqs[0];
 }
 
@@ -257,57 +147,55 @@
  *
  * @param[in] instance Memory place for the structure.
- * @param[in] HC function node
- * @param[in] regs Device's I/O registers range.
+ * @param[in] regs Device's resources
  * @param[in] interrupts True if w interrupts should be used
  * @return Error code
  */
-int hc_init(hc_t *instance, ddf_fun_t *fun, addr_range_t *regs, bool interrupts)
-{
-	assert(instance);
-
-	int rc = pio_enable_range(regs, (void **) &instance->registers);
-	if (rc != EOK) {
-		usb_log_error("Failed to gain access to device registers: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
+int hc_init(hc_t *instance, const hw_res_list_parsed_t *hw_res, bool interrupts)
+{
+	assert(instance);
+	assert(hw_res);
+	if (hw_res->mem_ranges.count != 1 ||
+	    hw_res->mem_ranges.ranges[0].size < sizeof(ohci_regs_t))
+	    return EINVAL;
+
+	int ret = pio_enable_range(&hw_res->mem_ranges.ranges[0],
+	    (void **) &instance->registers);
+	if (ret != EOK) {
+		usb_log_error("Failed to gain access to registers: %s.\n",
+		    str_error(ret));
+		return ret;
+	}
+	usb_log_debug("Device registers at %" PRIx64 " (%zuB) accessible.\n",
+	    hw_res->mem_ranges.ranges[0].address.absolute,
+	    hw_res->mem_ranges.ranges[0].size);
 
 	list_initialize(&instance->pending_batches);
-
-	instance->generic = ddf_fun_data_alloc(fun, sizeof(hcd_t));
-	if (instance->generic == NULL) {
-		usb_log_error("Out of memory.\n");
-		return ENOMEM;
-	}
-
-	hcd_init(instance->generic, USB_SPEED_FULL,
-	    BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
-	instance->generic->private_data = instance;
-	instance->generic->schedule = hc_schedule;
-	instance->generic->ep_add_hook = ohci_endpoint_init;
-	instance->generic->ep_remove_hook = ohci_endpoint_fini;
-
-	rc = hc_init_memory(instance);
-	if (rc != EOK) {
+	fibril_mutex_initialize(&instance->guard);
+	instance->hw_interrupts = interrupts;
+
+	ret = hc_init_memory(instance);
+	if (ret != EOK) {
 		usb_log_error("Failed to create OHCI memory structures: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-
-	fibril_mutex_initialize(&instance->guard);
+		    str_error(ret));
+		return ret;
+	}
 
 	hc_gain_control(instance);
 
-	if (!interrupts) {
-		instance->interrupt_emulator =
-		    fibril_create((int(*)(void*))interrupt_emulator, instance);
-		fibril_add_ready(instance->interrupt_emulator);
-	}
-
-	rh_init(&instance->rh, instance->registers);
+	ohci_rh_init(&instance->rh, instance->registers, "ohci rh");
 	hc_start(instance);
 
 	return EOK;
 }
+
+/** Safely dispose host controller internal structures
+ *
+ * @param[in] instance Host controller structure to use.
+ */
+void hc_fini(hc_t *instance)
+{
+	assert(instance);
+	/* TODO: implement*/
+};
 
 void hc_enqueue_endpoint(hc_t *instance, const endpoint_t *ep)
@@ -379,21 +267,34 @@
 }
 
+int ohci_hc_status(hcd_t *hcd, uint32_t *status)
+{
+	assert(hcd);
+	assert(status);
+	hc_t *instance = hcd->driver.data;
+	assert(instance);
+
+	if (instance->registers){
+		*status = OHCI_RD(instance->registers->interrupt_status);
+		OHCI_WR(instance->registers->interrupt_status, *status);
+	}
+	return EOK;
+}
+
 /** Add USB transfer to the schedule.
  *
- * @param[in] instance OHCI hc driver structure.
+ * @param[in] hcd HCD driver structure.
  * @param[in] batch Batch representing the transfer.
  * @return Error code.
  */
-int hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
+int ohci_hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
 {
 	assert(hcd);
-	hc_t *instance = hcd->private_data;
+	hc_t *instance = hcd->driver.data;
 	assert(instance);
 
 	/* Check for root hub communication */
-	if (batch->ep->address == instance->rh.address) {
+	if (batch->ep->address == ohci_rh_get_address(&instance->rh)) {
 		usb_log_debug("OHCI root hub request.\n");
-		rh_request(&instance->rh, batch);
-		return EOK;
+		return ohci_rh_schedule(&instance->rh, batch);
 	}
 	ohci_transfer_batch_t *ohci_batch = ohci_transfer_batch_get(batch);
@@ -423,9 +324,11 @@
 /** Interrupt handling routine
  *
- * @param[in] instance OHCI hc driver structure.
+ * @param[in] hcd HCD driver structure.
  * @param[in] status Value of the status register at the time of interrupt.
  */
-void hc_interrupt(hc_t *instance, uint32_t status)
-{
+void ohci_hc_interrupt(hcd_t *hcd, uint32_t status)
+{
+	assert(hcd);
+	hc_t *instance = hcd->driver.data;
 	status = OHCI_RD(status);
 	assert(instance);
@@ -434,5 +337,5 @@
 	usb_log_debug2("OHCI(%p) interrupt: %x.\n", instance, status);
 	if (status & I_RHSC)
-		rh_interrupt(&instance->rh);
+		ohci_rh_interrupt(&instance->rh);
 
 	if (status & I_WDH) {
@@ -465,22 +368,4 @@
 	}
 
-}
-
-/** Check status register regularly
- *
- * @param[in] instance OHCI hc driver structure.
- * @return Error code
- */
-int interrupt_emulator(hc_t *instance)
-{
-	assert(instance);
-	usb_log_info("Started interrupt emulator.\n");
-	while (1) {
-		const uint32_t status = instance->registers->interrupt_status;
-		instance->registers->interrupt_status = status;
-		hc_interrupt(instance, status);
-		async_usleep(10000);
-	}
-	return EOK;
 }
 
@@ -519,5 +404,5 @@
 		OHCI_SET(instance->registers->command_status, CS_OCR);
 		/* Hope that SMM actually knows its stuff or we can hang here */
-		while (OHCI_RD(instance->registers->control & C_IR)) {
+		while (OHCI_RD(instance->registers->control) & C_IR) {
 			async_usleep(1000);
 		}
@@ -603,8 +488,11 @@
 
 	/* Enable interrupts */
-	OHCI_WR(instance->registers->interrupt_enable, OHCI_USED_INTERRUPTS);
-	usb_log_debug("Enabled interrupts: %x.\n",
-	    OHCI_RD(instance->registers->interrupt_enable));
-	OHCI_WR(instance->registers->interrupt_enable, I_MI);
+	if (instance->hw_interrupts) {
+		OHCI_WR(instance->registers->interrupt_enable,
+		    OHCI_USED_INTERRUPTS);
+		usb_log_debug("Enabled interrupts: %x.\n",
+		    OHCI_RD(instance->registers->interrupt_enable));
+		OHCI_WR(instance->registers->interrupt_enable, I_MI);
+	}
 
 	/* Set periodic start to 90% */
@@ -632,5 +520,5 @@
 do { \
 	const char *name = usb_str_transfer_type(type); \
-	int ret = endpoint_list_init(&instance->lists[type], name); \
+	const int ret = endpoint_list_init(&instance->lists[type], name); \
 	if (ret != EOK) { \
 		usb_log_error("Failed to setup %s endpoint list: %s.\n", \
Index: uspace/drv/bus/usb/ohci/hc.h
===================================================================
--- uspace/drv/bus/usb/ohci/hc.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/hc.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -35,17 +35,19 @@
 #define DRV_OHCI_HC_H
 
+#include <adt/list.h>
+#include <ddi.h>
 #include <ddf/driver.h>
-#include <ddf/interrupt.h>
+#include <device/hw_res_parsed.h>
 #include <fibril.h>
 #include <fibril_synch.h>
-#include <adt/list.h>
-#include <ddi.h>
+#include <stdbool.h>
+#include <sys/types.h>
 
-#include <usb/usb.h>
 #include <usb/host/hcd.h>
+#include <usb/host/endpoint.h>
+#include <usb/host/usb_transfer_batch.h>
 
-#include "ohci_batch.h"
 #include "ohci_regs.h"
-#include "root_hub.h"
+#include "ohci_rh.h"
 #include "endpoint_list.h"
 #include "hw_struct/hcca.h"
@@ -53,7 +55,4 @@
 /** Main OHCI driver structure */
 typedef struct hc {
-	/** Generic USB hc driver */
-	hcd_t *generic;
-
 	/** Memory mapped I/O registers area */
 	ohci_regs_t *registers;
@@ -72,25 +71,22 @@
 	fibril_mutex_t guard;
 
+	/** interrupts available */
+	bool hw_interrupts;
+
 	/** USB hub emulation structure */
-	rh_t rh;
+	ohci_rh_t rh;
 } hc_t;
 
-int hc_get_irq_code(irq_pio_range_t [], size_t, irq_cmd_t [], size_t,
-    addr_range_t *);
-int hc_register_irq_handler(ddf_dev_t *, addr_range_t *, int,
-    interrupt_handler_t);
-int hc_register_hub(hc_t *, ddf_fun_t *);
-int hc_init(hc_t *, ddf_fun_t *, addr_range_t *, bool);
-
-/** Safely dispose host controller internal structures
- *
- * @param[in] instance Host controller structure to use.
- */
-static inline void hc_fini(hc_t *instance) { /* TODO: implement*/ };
+int hc_init(hc_t *instance, const hw_res_list_parsed_t *hw_res, bool interrupts);
+void hc_fini(hc_t *instance);
 
 void hc_enqueue_endpoint(hc_t *instance, const endpoint_t *ep);
 void hc_dequeue_endpoint(hc_t *instance, const endpoint_t *ep);
 
-void hc_interrupt(hc_t *instance, uint32_t status);
+int ohci_hc_gen_irq_code(irq_code_t *code, const hw_res_list_parsed_t *hw_res);
+
+void ohci_hc_interrupt(hcd_t *hcd, uint32_t status);
+int ohci_hc_status(hcd_t *hcd, uint32_t *status);
+int ohci_hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
 #endif
 /**
Index: uspace/drv/bus/usb/ohci/hw_struct/completion_codes.h
===================================================================
--- uspace/drv/bus/usb/ohci/hw_struct/completion_codes.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/hw_struct/completion_codes.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -37,20 +37,22 @@
 #include <errno.h>
 
-#define CC_NOERROR (0x0)
-#define CC_CRC (0x1)
-#define CC_BITSTUFF (0x2)
-#define CC_TOGGLE (0x3)
-#define CC_STALL (0x4)
-#define CC_NORESPONSE (0x5)
-#define CC_PIDFAIL (0x6)
-#define CC_PIDUNEXPECTED (0x7)
-#define CC_DATAOVERRRUN (0x8)
-#define CC_DATAUNDERRRUN (0x9)
-#define CC_BUFFEROVERRRUN (0xc)
-#define CC_BUFFERUNDERRUN (0xd)
-#define CC_NOACCESS1 (0xe)
-#define CC_NOACCESS2 (0xf)
+enum {
+	CC_NOERROR = 0x0,
+	CC_CRC = 0x1,
+	CC_BITSTUFF = 0x2,
+	CC_TOGGLE = 0x3,
+	CC_STALL = 0x4,
+	CC_NORESPONSE = 0x5,
+	CC_PIDFAIL = 0x6,
+	CC_PIDUNEXPECTED = 0x7,
+	CC_DATAOVERRRUN = 0x8,
+	CC_DATAUNDERRRUN = 0x9,
+	CC_BUFFEROVERRRUN = 0xc,
+	CC_BUFFERUNDERRUN = 0xd,
+	CC_NOACCESS1 = 0xe,
+	CC_NOACCESS2 = 0xf,
+};
 
-inline static int cc_to_rc(int cc)
+inline static unsigned cc_to_rc(unsigned cc)
 {
 	switch (cc) {
Index: uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.c
===================================================================
--- uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -32,4 +32,14 @@
  * @brief OHCI driver
  */
+
+#include <assert.h>
+#include <macros.h>
+#include <mem.h>
+
+#include <usb/usb.h>
+
+#include "../utils/malloc32.h"
+#include "mem_access.h"
+
 #include "endpoint_descriptor.h"
 
@@ -48,10 +58,10 @@
  * @param td TD to put in the list.
  *
- * If @param ep is NULL, dummy ED is initalized with only skip flag set.
+ * If @param ep is NULL, dummy ED is initialized with only skip flag set.
  */
 void ed_init(ed_t *instance, const endpoint_t *ep, const td_t *td)
 {
 	assert(instance);
-	memset(instance, 0, sizeof(ed_t));
+	memset(instance, 0, sizeof(*instance));
 
 	if (ep == NULL) {
@@ -61,6 +71,8 @@
 		return;
 	}
-	/* Non-dummy ED must have TD assigned */
+	/* Non-dummy ED must have corresponding EP and TD assigned */
 	assert(td);
+	assert(ep);
+	assert(ep->direction < ARRAY_SIZE(dir));
 
 	/* Status: address, endpoint nr, direction mask and max packet size. */
@@ -77,4 +89,5 @@
 
 	/* Isochronous format flag */
+	// TODO: We need iTD instead of TD for iso transfers
 	if (ep->transfer_type == USB_TRANSFER_ISOCHRONOUS)
 		OHCI_MEM32_SET(instance->status, ED_STATUS_F_FLAG);
Index: uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.h
===================================================================
--- uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -36,5 +36,6 @@
 
 #include <assert.h>
-#include <stdint.h>
+#include <stdbool.h>
+#include <sys/types.h>
 
 #include <usb/host/endpoint.h>
Index: uspace/drv/bus/usb/ohci/hw_struct/hcca.h
===================================================================
--- uspace/drv/bus/usb/ohci/hw_struct/hcca.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/hw_struct/hcca.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -35,6 +35,7 @@
 #define DRV_OHCI_HW_STRUCT_HCCA_H
 
-#include <stdint.h>
 #include <malloc.h>
+#include <sys/types.h>
+#include <macros.h>
 
 #include "mem_access.h"
@@ -50,10 +51,12 @@
 	/** Frame number. */
 	uint16_t frame_number;
-	uint16_t pad1;
+	PADD16;
 	/** Pointer to the last completed TD. (useless) */
 	uint32_t done_head;
 	/** Padding to make the size 256B */
-	uint32_t reserved[30];
+	PADD32[30];
 } hcca_t;
+
+STATIC_ASSERT(sizeof(hcca_t) == 256);
 
 /** Allocate properly aligned structure.
@@ -65,6 +68,5 @@
 static inline hcca_t * hcca_get(void)
 {
-	assert(sizeof(hcca_t) == 256);
-	hcca_t *hcca = memalign(256, sizeof(hcca_t));
+	hcca_t *hcca = memalign(sizeof(hcca_t), sizeof(hcca_t));
 	if (hcca)
 		memset(hcca, 0, sizeof(hcca_t));
@@ -80,7 +82,6 @@
 {
 	assert(hcca);
-	assert(index < HCCA_INT_EP_COUNT);
+	assert(index < ARRAY_SIZE(hcca->int_ep));
 	OHCI_MEM32_WR(hcca->int_ep[index], pa);
-
 }
 #endif
Index: uspace/drv/bus/usb/ohci/hw_struct/iso_transfer_descriptor.h
===================================================================
--- uspace/drv/bus/usb/ohci/hw_struct/iso_transfer_descriptor.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/hw_struct/iso_transfer_descriptor.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -35,5 +35,5 @@
 #define DRV_OHCI_HW_STRUCT_ISO_TRANSFER_DESCRIPTOR_H
 
-#include <stdint.h>
+#include <sys/types.h>
 
 #include "completion_codes.h"
Index: uspace/drv/bus/usb/ohci/hw_struct/mem_access.h
===================================================================
--- uspace/drv/bus/usb/ohci/hw_struct/mem_access.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/hw_struct/mem_access.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -47,3 +47,2 @@
  * @}
  */
-
Index: uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.c
===================================================================
--- uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -32,7 +32,13 @@
  * @brief OHCI driver
  */
+
+#include <assert.h>
+#include <mem.h>
+
 #include <usb/usb.h>
-#include <mem.h>
+
 #include "../utils/malloc32.h"
+#include "completion_codes.h"
+#include "mem_access.h"
 #include "transfer_descriptor.h"
 
@@ -70,5 +76,5 @@
 	}
 
-	/* Alow less data on input. */
+	/* Allow less data on input. */
 	if (dir == USB_DIRECTION_IN) {
 		OHCI_MEM32_SET(instance->status, TD_STATUS_ROUND_FLAG);
Index: uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.h
===================================================================
--- uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -35,4 +35,5 @@
 #define DRV_OHCI_HW_STRUCT_TRANSFER_DESCRIPTOR_H
 
+#include <assert.h>
 #include <stdbool.h>
 #include <stdint.h>
Index: uspace/drv/bus/usb/ohci/main.c
===================================================================
--- uspace/drv/bus/usb/ohci/main.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/main.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -33,13 +33,44 @@
  * Main routines of OHCI driver.
  */
+
+#include <assert.h>
 #include <ddf/driver.h>
 #include <errno.h>
+#include <io/log.h>
 #include <str_error.h>
 
 #include <usb/debug.h>
+#include <usb/host/ddf_helpers.h>
 
-#include "ohci.h"
+#include "hc.h"
 
 #define NAME "ohci"
+
+static int ohci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
+{
+	assert(hcd);
+	assert(hcd->driver.data == NULL);
+
+	hc_t *instance = malloc(sizeof(hc_t));
+	if (!instance)
+		return ENOMEM;
+
+	const int ret =  hc_init(instance, res, irq);
+	if (ret == EOK)
+		hcd_set_implementation(hcd, instance, ohci_hc_schedule,
+		    ohci_endpoint_init, ohci_endpoint_fini, ohci_hc_interrupt,
+		    ohci_hc_status);
+	return ret;
+}
+
+static void ohci_driver_fini(hcd_t *hcd)
+{
+	assert(hcd);
+	if (hcd->driver.data)
+		hc_fini(hcd->driver.data);
+
+	free(hcd->driver.data);
+	hcd_set_implementation(hcd, NULL, NULL, NULL, NULL, NULL, NULL);
+}
 
 /** Initializes a new ddf driver instance of OHCI hcd.
@@ -53,20 +84,23 @@
 	assert(device);
 
-	int ret = device_setup_ohci(device);
+	const int ret = ddf_hcd_device_setup_all(device, USB_SPEED_FULL,
+	    BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11,
+	    ddf_hcd_gen_irq_handler, ohci_hc_gen_irq_code,
+	    ohci_driver_init, ohci_driver_fini);
 	if (ret != EOK) {
 		usb_log_error("Failed to initialize OHCI driver: %s.\n",
 		    str_error(ret));
-		return ret;
 	}
-	usb_log_info("Controlling new OHCI device '%s'.\n", ddf_dev_get_name(device));
+	usb_log_info("Controlling new OHCI device '%s'.\n",
+	    ddf_dev_get_name(device));
 
-	return EOK;
+	return ret;
 }
 
-static driver_ops_t ohci_driver_ops = {
+static const driver_ops_t ohci_driver_ops = {
 	.dev_add = ohci_dev_add,
 };
 
-static driver_t ohci_driver = {
+static const driver_t ohci_driver = {
 	.name = NAME,
 	.driver_ops = &ohci_driver_ops
Index: uspace/drv/bus/usb/ohci/ohci.c
===================================================================
--- uspace/drv/bus/usb/ohci/ohci.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,258 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbohci
- * @{
- */
-/** @file
- * @brief OHCI driver
- */
-
-#include <errno.h>
-#include <str_error.h>
-#include <ddf/interrupt.h>
-#include <usb_iface.h>
-#include <usb/usb.h>
-#include <usb/ddfiface.h>
-#include <usb/debug.h>
-
-#include "ohci.h"
-#include "res.h"
-#include "hc.h"
-
-typedef struct ohci {
-	ddf_fun_t *hc_fun;
-	ddf_fun_t *rh_fun;
-
-	hc_t hc;
-} ohci_t;
-
-static inline ohci_t *dev_to_ohci(ddf_dev_t *dev)
-{
-	return ddf_dev_data_get(dev);
-}
-/** IRQ handling callback, identifies device
- *
- * @param[in] iid (Unused).
- * @param[in] call Pointer to the call that represents interrupt.
- * @param[in] dev DDF instance of the device to use.
- *
- */
-static void irq_handler(ipc_callid_t iid, ipc_call_t *call, ddf_dev_t *dev)
-{
-	assert(dev);
-	
-	ohci_t *ohci = dev_to_ohci(dev);
-	if (!ohci) {
-		usb_log_warning("Interrupt on device that is not ready.\n");
-		return;
-	}
-	
-	const uint16_t status = IPC_GET_ARG1(*call);
-	hc_interrupt(&ohci->hc, status);
-}
-
-/** Get USB address assigned to root hub.
- *
- * @param[in] fun Root hub function.
- * @param[out] address Store the address here.
- * @return Error code.
- */
-static int rh_get_my_address(ddf_fun_t *fun, usb_address_t *address)
-{
-	assert(fun);
-
-	if (address != NULL) {
-		*address = dev_to_ohci(ddf_fun_get_dev(fun))->hc.rh.address;
-	}
-
-	return EOK;
-}
-
-/** Gets handle of the respective hc (this device, hc function).
- *
- * @param[in] root_hub_fun Root hub function seeking hc handle.
- * @param[out] handle Place to write the handle.
- * @return Error code.
- */
-static int rh_get_hc_handle(
-    ddf_fun_t *fun, devman_handle_t *handle)
-{
-	assert(fun);
-	ddf_fun_t *hc_fun = dev_to_ohci(ddf_fun_get_dev(fun))->hc_fun;
-	assert(hc_fun);
-
-	if (handle != NULL)
-		*handle = ddf_fun_get_handle(hc_fun);
-	return EOK;
-}
-
-/** Root hub USB interface */
-static usb_iface_t usb_iface = {
-	.get_hc_handle = rh_get_hc_handle,
-	.get_my_address = rh_get_my_address,
-};
-
-/** Standard USB HC options (HC interface) */
-static ddf_dev_ops_t hc_ops = {
-	.interfaces[USBHC_DEV_IFACE] = &hcd_iface,
-};
-
-/** Standard USB RH options (RH interface) */
-static ddf_dev_ops_t rh_ops = {
-	.interfaces[USB_DEV_IFACE] = &usb_iface,
-};
-
-/** Initialize hc and rh ddf structures and their respective drivers.
- *
- * @param[in] device DDF instance of the device to use.
- * @param[in] instance OHCI structure to use.
- *
- * This function does all the preparatory work for hc and rh drivers:
- *  - gets device hw resources
- *  - disables OHCI legacy support
- *  - asks for interrupt
- *  - registers interrupt handler
- */
-int device_setup_ohci(ddf_dev_t *device)
-{
-	bool ih_registered = false;
-	bool hc_inited = false;
-	int rc;
-
-	if (device == NULL)
-		return EBADMEM;
-
-	ohci_t *instance = ddf_dev_data_alloc(device,sizeof(ohci_t));
-	if (instance == NULL) {
-		usb_log_error("Failed to allocate OHCI driver.\n");
-		return ENOMEM;
-	}
-
-	instance->hc_fun = ddf_fun_create(device, fun_exposed, "ohci_hc");
-	if (instance->hc_fun == NULL) {
-		usb_log_error("Failed to create OHCI HC function: %s.\n",
-		    str_error(ENOMEM));
-		rc = ENOMEM;
-		goto error;
-	}
-
-	ddf_fun_set_ops(instance->hc_fun, &hc_ops);
-
-	instance->rh_fun = ddf_fun_create(device, fun_inner, "ohci_rh");
-	if (instance->rh_fun == NULL) {
-		usb_log_error("Failed to create OHCI RH function: %s.\n",
-		    str_error(ENOMEM));
-		rc = ENOMEM;
-		goto error;
-	}
-
-	ddf_fun_set_ops(instance->rh_fun, &rh_ops);
-
-	addr_range_t regs;
-	int irq = 0;
-
-	rc = get_my_registers(device, &regs, &irq);
-	if (rc != EOK) {
-		usb_log_error("Failed to get register memory addresses "
-		    "for %" PRIun ": %s.\n", ddf_dev_get_handle(device),
-		    str_error(rc));
-		goto error;
-	}
-
-	usb_log_debug("Memory mapped regs at %p (size %zu), IRQ %d.\n",
-	    RNGABSPTR(regs), RNGSZ(regs), irq);
-
-	rc = hc_register_irq_handler(device, &regs, irq, irq_handler);
-	if (rc != EOK) {
-		usb_log_error("Failed to register interrupt handler: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	ih_registered = true;
-
-	/* Try to enable interrupts */
-	bool interrupts = false;
-	rc = enable_interrupts(device);
-	if (rc != EOK) {
-		usb_log_warning("Failed to enable interrupts: %s."
-		    " Falling back to polling\n", str_error(rc));
-		/* We don't need that handler */
-		unregister_interrupt_handler(device, irq);
-		ih_registered = false;
-	} else {
-		usb_log_debug("Hw interrupts enabled.\n");
-		interrupts = true;
-	}
-
-	rc = hc_init(&instance->hc, instance->hc_fun, &regs, interrupts);
-	if (rc != EOK) {
-		usb_log_error("Failed to init ohci_hcd: %s.\n", str_error(rc));
-		goto error;
-	}
-
-	hc_inited = true;
-
-	rc = ddf_fun_bind(instance->hc_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to bind OHCI device function: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	rc = ddf_fun_add_to_category(instance->hc_fun, USB_HC_CATEGORY);
-	if (rc != EOK) {
-		usb_log_error("Failed to add OHCI to HC category: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	rc = hc_register_hub(&instance->hc, instance->rh_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to register OHCI root hub: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	return EOK;
-
-error:
-	if (hc_inited)
-		hc_fini(&instance->hc);
-	if (ih_registered)
-		unregister_interrupt_handler(device, irq);
-	if (instance->hc_fun != NULL)
-		ddf_fun_destroy(instance->hc_fun);
-	if (instance->rh_fun != NULL)
-		ddf_fun_destroy(instance->rh_fun);
-	return rc;
-}
-/**
- * @}
- */
Index: uspace/drv/bus/usb/ohci/ohci.h
===================================================================
--- uspace/drv/bus/usb/ohci/ohci.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,44 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbohci
- * @{
- */
-/** @file
- * @brief OHCI driver main structure for both host controller and root-hub.
- */
-#ifndef DRV_OHCI_OHCI_H
-#define DRV_OHCI_OHCI_H
-#include <ddi.h>
-#include <ddf/driver.h>
-
-int device_setup_ohci(ddf_dev_t *device);
-
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/ohci/ohci_batch.c
===================================================================
--- uspace/drv/bus/usb/ohci/ohci_batch.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/ohci_batch.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -32,7 +32,10 @@
  * @brief OHCI driver USB transaction structure
  */
+
+#include <assert.h>
 #include <errno.h>
-#include <str_error.h>
 #include <macros.h>
+#include <mem.h>
+#include <stdbool.h>
 
 #include <usb/usb.h>
@@ -94,15 +97,11 @@
 {
 	assert(usb_batch);
-#define CHECK_NULL_DISPOSE_RET(ptr, message...) \
-if (ptr == NULL) { \
-	usb_log_error(message); \
-	ohci_transfer_batch_dispose(ohci_batch); \
-	return NULL; \
-} else (void)0
 
 	ohci_transfer_batch_t *ohci_batch =
 	    calloc(1, sizeof(ohci_transfer_batch_t));
-	CHECK_NULL_DISPOSE_RET(ohci_batch,
-	    "Failed to allocate OHCI batch data.\n");
+	if (!ohci_batch) {
+		usb_log_error("Failed to allocate OHCI batch data.");
+		goto dispose;
+	}
 	link_initialize(&ohci_batch->link);
 	ohci_batch->td_count =
@@ -116,6 +115,8 @@
 	/* We need an extra place for TD that was left at ED */
 	ohci_batch->tds = calloc(ohci_batch->td_count + 1, sizeof(td_t*));
-	CHECK_NULL_DISPOSE_RET(ohci_batch->tds,
-	    "Failed to allocate OHCI transfer descriptors.\n");
+	if (!ohci_batch->tds) {
+		usb_log_error("Failed to allocate OHCI transfer descriptors.");
+		goto dispose;
+	}
 
 	/* Add TD left over by the previous transfer */
@@ -125,6 +126,8 @@
 	for (unsigned i = 1; i <= ohci_batch->td_count; ++i) {
 		ohci_batch->tds[i] = malloc32(sizeof(td_t));
-		CHECK_NULL_DISPOSE_RET(ohci_batch->tds[i],
-		    "Failed to allocate TD %d.\n", i );
+		if (!ohci_batch->tds[i]) {
+			usb_log_error("Failed to allocate TD %d.", i);
+			goto dispose;
+		}
 	}
 
@@ -138,6 +141,8 @@
 		ohci_batch->device_buffer =
 		    malloc32(usb_batch->setup_size + usb_batch->buffer_size);
-                CHECK_NULL_DISPOSE_RET(ohci_batch->device_buffer,
-                    "Failed to allocate device accessible buffer.\n");
+		if (!ohci_batch->device_buffer) {
+			usb_log_error("Failed to allocate device buffer");
+			goto dispose;
+		}
 		/* Copy setup data */
                 memcpy(ohci_batch->device_buffer, usb_batch->setup_buffer,
@@ -156,5 +161,7 @@
 
 	return ohci_batch;
-#undef CHECK_NULL_DISPOSE_RET
+dispose:
+	ohci_transfer_batch_dispose(ohci_batch);
+	return NULL;
 }
 
Index: uspace/drv/bus/usb/ohci/ohci_batch.h
===================================================================
--- uspace/drv/bus/usb/ohci/ohci_batch.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/ohci_batch.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -36,6 +36,6 @@
 
 #include <adt/list.h>
-#include <usbhc_iface.h>
-#include <usb/usb.h>
+#include <assert.h>
+#include <stdbool.h>
 #include <usb/host/usb_transfer_batch.h>
 
Index: uspace/drv/bus/usb/ohci/ohci_endpoint.c
===================================================================
--- uspace/drv/bus/usb/ohci/ohci_endpoint.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/ohci_endpoint.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -32,4 +32,8 @@
  * @brief OHCI driver
  */
+
+#include <assert.h>
+#include <stdlib.h>
+
 #include "utils/malloc32.h"
 #include "ohci_endpoint.h"
@@ -87,8 +91,9 @@
 	}
 
+	link_initialize(&ohci_ep->link);
 	ed_init(ohci_ep->ed, ep, ohci_ep->td);
 	endpoint_set_hc_data(
 	    ep, ohci_ep, ohci_ep_toggle_get, ohci_ep_toggle_set);
-	hc_enqueue_endpoint(hcd->private_data, ep);
+	hc_enqueue_endpoint(hcd->driver.data, ep);
 	return EOK;
 }
@@ -104,5 +109,5 @@
 	assert(ep);
 	ohci_endpoint_t *instance = ohci_endpoint_get(ep);
-	hc_dequeue_endpoint(hcd->private_data, ep);
+	hc_dequeue_endpoint(hcd->driver.data, ep);
 	if (instance) {
 		free32(instance->ed);
Index: uspace/drv/bus/usb/ohci/ohci_regs.h
===================================================================
--- uspace/drv/bus/usb/ohci/ohci_regs.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/ohci_regs.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -34,12 +34,12 @@
 #ifndef DRV_OHCI_OHCI_REGS_H
 #define DRV_OHCI_OHCI_REGS_H
+#include <ddi.h>
 #include <sys/types.h>
 #include <byteorder.h>
 
-#define OHCI_WR(reg, val) reg = host2uint32_t_le(val)
-#define OHCI_RD(reg) uint32_t_le2host(reg)
-#define OHCI_SET(reg, val) reg |= host2uint32_t_le(val)
-#define OHCI_CLR(reg, val) reg &= host2uint32_t_le(~val)
-
+#define OHCI_WR(reg, val) pio_write_32(&(reg), host2uint32_t_le(val))
+#define OHCI_RD(reg) uint32_t_le2host(pio_read_32(&(reg)))
+#define OHCI_SET(reg, val) pio_set_32(&(reg), host2uint32_t_le(val), 1)
+#define OHCI_CLR(reg, val) pio_clear_32(&(reg), host2uint32_t_le(val), 1)
 
 #define LEGACY_REGS_OFFSET 0x100
@@ -215,14 +215,14 @@
 	/** Root hub per port status */
 	ioport32_t rh_port_status[];
-#define RHPS_CCS_FLAG (1 << 0) /* r: current connect status,
+#define RHPS_CCS_FLAG (1 << 0)                /* r: current connect status,
                                                * w: 1-clear port enable, 0-N/S*/
 #define RHPS_CLEAR_PORT_ENABLE RHPS_CCS_FLAG
-#define RHPS_PES_FLAG (1 << 1) /* r: port enable status
+#define RHPS_PES_FLAG (1 << 1)               /* r: port enable status
                                               * w: 1-set port enable, 0-N/S */
 #define RHPS_SET_PORT_ENABLE RHPS_PES_FLAG
-#define RHPS_PSS_FLAG (1 << 2) /* r: port suspend status
+#define RHPS_PSS_FLAG (1 << 2)                /* r: port suspend status
                                                * w: 1-set port suspend, 0-N/S */
 #define RHPS_SET_PORT_SUSPEND RHPS_PSS_FLAG
-#define RHPS_POCI_FLAG (1 << 3) /* r: port over-current
+#define RHPS_POCI_FLAG (1 << 3)                /* r: port over-current
                                                 * (if reports are per-port
                                                 * w: 1-clear port suspend
@@ -230,11 +230,11 @@
                                                 *    0-nothing */
 #define RHPS_CLEAR_PORT_SUSPEND RHPS_POCI_FLAG
-#define RHPS_PRS_FLAG (1 << 4) /* r: port reset status
+#define RHPS_PRS_FLAG (1 << 4)                /* r: port reset status
                                                * w: 1-set port reset, 0-N/S */
 #define RHPS_SET_PORT_RESET RHPS_PRS_FLAG
-#define RHPS_PPS_FLAG (1 << 8) /* r: port power status
+#define RHPS_PPS_FLAG (1 << 8)               /* r: port power status
                                               * w: 1-set port power, 0-N/S */
 #define RHPS_SET_PORT_POWER RHPS_PPS_FLAG
-#define RHPS_LSDA_FLAG (1 << 9) /* r: low speed device attached
+#define RHPS_LSDA_FLAG (1 << 9)                /* r: low speed device attached
                                                 * w: 1-clear port power, 0-N/S*/
 #define RHPS_CLEAR_PORT_POWER RHPS_LSDA_FLAG
Index: uspace/drv/bus/usb/ohci/ohci_rh.c
===================================================================
--- uspace/drv/bus/usb/ohci/ohci_rh.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ohci/ohci_rh.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,530 @@
+/*
+ * Copyright (c) 2013 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 drvusbohci
+ * @{
+ */
+/** @file
+ * @brief OHCI driver
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <mem.h>
+#include <sys/types.h>
+
+#include <usb/classes/hub.h>
+#include <usb/debug.h>
+#include <usb/descriptor.h>
+#include <usb/request.h>
+#include <usb/usb.h>
+
+#include <usb/host/endpoint.h>
+#include <usbvirt/device.h>
+
+#include "ohci_rh.h"
+
+enum {
+	HUB_STATUS_CHANGE_PIPE = 1,
+};
+
+static usbvirt_device_ops_t ops;
+
+/** Initialize internal USB HUB class descriptor.
+ * @param instance OHCI root hub.
+ * Use register based info to create accurate descriptor.
+ */
+static void ohci_rh_hub_desc_init(ohci_rh_t *instance)
+{
+	assert(instance);
+	const unsigned dsize = sizeof(usb_hub_descriptor_header_t) +
+	    STATUS_BYTES(instance->port_count) * 2;
+	assert(dsize <= sizeof(instance->hub_descriptor));
+	const uint32_t hub_desc = OHCI_RD(instance->registers->rh_desc_a);
+	const uint32_t port_desc = OHCI_RD(instance->registers->rh_desc_b);
+
+	instance->hub_descriptor.header.length = dsize;
+	instance->hub_descriptor.header.descriptor_type = USB_DESCTYPE_HUB;
+	instance->hub_descriptor.header.port_count = instance->port_count;
+	instance->hub_descriptor.header.characteristics = 0 |
+	    /* Bits 0,1 indicate power switching mode */
+	    ((hub_desc & RHDA_PSM_FLAG)  ? 0x01 : 0) |
+	    ((hub_desc & RHDA_NPS_FLAG)  ? 0x02 : 0) |
+	    /* Bit 2 indicates device type (compound device) */
+	    ((hub_desc & RHDA_DT_FLAG)   ? 0x04 : 0) |
+	    /* Bits 3,4 indicate over-current protection mode */
+	    ((hub_desc & RHDA_OCPM_FLAG) ? 0x08 : 0) |
+	    ((hub_desc & RHDA_NOCP_FLAG) ? 0x10 : 0);
+	instance->hub_descriptor.header.power_good_time =
+	    hub_desc >> RHDA_POTPGT_SHIFT;
+	/* bHubContrCurrent, root hubs don't need no power. */
+	instance->hub_descriptor.header.max_current = 0;
+
+	/* Device Removable and some legacy 1.0 stuff*/
+	instance->hub_descriptor.rempow[0] =
+	    (port_desc >> RHDB_DR_SHIFT) & 0xff;
+	if (STATUS_BYTES(instance->port_count) == 1) {
+		instance->hub_descriptor.rempow[1] = 0xff;
+	} else {
+		instance->hub_descriptor.rempow[1] =
+		     ((port_desc >> RHDB_DR_SHIFT) >> 8) & 0xff;
+	}
+
+	instance->hub_descriptor.rempow[2] = 0xff;
+	instance->hub_descriptor.rempow[3] = 0xff;
+
+}
+/** Initialize OHCI root hub.
+ * @param instance Place to initialize.
+ * @param regs OHCI device registers.
+ * @param name Device name.
+ * return Error code, EOK on success.
+ *
+ * Selects preconfigured port powering mode, sets up descriptor, and
+ * initializes internal virtual hub.
+ */
+int ohci_rh_init(ohci_rh_t *instance, ohci_regs_t *regs, const char *name)
+{
+	assert(instance);
+	instance->registers = regs;
+	instance->port_count = OHCI_RD(regs->rh_desc_a) & RHDA_NDS_MASK;
+	usb_log_debug2("rh_desc_a: %x.\n", OHCI_RD(regs->rh_desc_a));
+	if (instance->port_count > OHCI_MAX_PORTS) {
+		usb_log_warning("OHCI specification does not allow %d ports. "
+		    "Max %d ports will be used.\n", instance->port_count,
+		    OHCI_MAX_PORTS);
+		instance->port_count = OHCI_MAX_PORTS;
+	}
+	usb_log_info("%s: Found %u ports.\n", name, instance->port_count);
+
+#if defined OHCI_POWER_SWITCH_no
+	usb_log_info("%s: Set power mode to no power switching.\n", name);
+	/* Set port power mode to no power-switching. (always on) */
+	OHCI_SET(regs->rh_desc_a, RHDA_NPS_FLAG);
+
+	/* Set to no over-current reporting */
+	OHCI_SET(regs->rh_desc_a, RHDA_NOCP_FLAG);
+
+#elif defined OHCI_POWER_SWITCH_ganged
+	usb_log_info("%s: Set power mode to ganged power switching.\n", name);
+	/* Set port power mode to ganged power-switching. */
+	OHCI_CLR(regs->rh_desc_a, RHDA_NPS_FLAG);
+	OHCI_CLR(regs->rh_desc_a, RHDA_PSM_FLAG);
+
+	/* Turn off power (hub driver will turn this back on)*/
+	OHCI_WR(regs->rh_status, RHS_CLEAR_GLOBAL_POWER);
+
+	/* Set to global over-current */
+	OHCI_CLR(regs->rh_desc_a, RHDA_NOCP_FLAG);
+	OHCI_CLR(regs->rh_desc_a, RHDA_OCPM_FLAG);
+#else
+	usb_log_info("%s: Set power mode to per-port power switching.\n", name);
+	/* Set port power mode to per port power-switching. */
+	OHCI_CLR(regs->rh_desc_a, RHDA_NPS_FLAG);
+	OHCI_SET(regs->rh_desc_a, RHDA_PSM_FLAG);
+
+	/* Control all ports by global switch and turn them off */
+	OHCI_CLR(regs->rh_desc_b, RHDB_PCC_MASK << RHDB_PCC_SHIFT);
+	OHCI_WR(regs->rh_status, RHS_CLEAR_GLOBAL_POWER);
+
+	/* Return control to per port state */
+	OHCI_SET(regs->rh_desc_b, RHDB_PCC_MASK << RHDB_PCC_SHIFT);
+
+	/* Set per port over-current */
+	OHCI_CLR(regs->rh_desc_a, RHDA_NOCP_FLAG);
+	OHCI_SET(regs->rh_desc_a, RHDA_OCPM_FLAG);
+#endif
+
+	ohci_rh_hub_desc_init(instance);
+	instance->unfinished_interrupt_transfer = NULL;
+	return virthub_base_init(&instance->base, name, &ops, instance,
+	    NULL, &instance->hub_descriptor.header, HUB_STATUS_CHANGE_PIPE);
+}
+
+/** Schedule USB request.
+ * @param instance OCHI root hub instance.
+ * @param batch USB requst batch to schedule.
+ * @return Always EOK.
+ * Most requests complete even before this function returns,
+ * status change requests might be postponed until there is something to report.
+ */
+int ohci_rh_schedule(ohci_rh_t *instance, usb_transfer_batch_t *batch)
+{
+	assert(instance);
+	assert(batch);
+	const usb_target_t target = {{
+		.address = batch->ep->address,
+		.endpoint = batch->ep->endpoint,
+	}};
+	batch->error = virthub_base_request(&instance->base, target,
+	    usb_transfer_batch_direction(batch), (void*)batch->setup_buffer,
+	    batch->buffer, batch->buffer_size, &batch->transfered_size);
+	if (batch->error == ENAK) {
+		/* This is safe because only status change interrupt transfers
+		 * return NAK. The assertion holds true because the batch
+		 * existence prevents communication with that ep */
+		assert(instance->unfinished_interrupt_transfer == NULL);
+		instance->unfinished_interrupt_transfer = batch;
+	} else {
+		usb_transfer_batch_finish(batch, NULL);
+		usb_transfer_batch_destroy(batch);
+	}
+	return EOK;
+}
+
+/** Handle OHCI RHSC interrupt.
+ * @param instance OHCI root hub isntance.
+ * @return Always EOK.
+ *
+ * Interrupt means there is a change of status to report. It may trigger
+ * processing of a postponed request.
+ */
+int ohci_rh_interrupt(ohci_rh_t *instance)
+{
+	//TODO atomic swap needed
+	usb_transfer_batch_t *batch = instance->unfinished_interrupt_transfer;
+	instance->unfinished_interrupt_transfer = NULL;
+	if (batch) {
+		const usb_target_t target = {{
+			.address = batch->ep->address,
+			.endpoint = batch->ep->endpoint,
+		}};
+		batch->error = virthub_base_request(&instance->base, target,
+		    usb_transfer_batch_direction(batch),
+		    (void*)batch->setup_buffer,
+		    batch->buffer, batch->buffer_size, &batch->transfered_size);
+		usb_transfer_batch_finish(batch, NULL);
+		usb_transfer_batch_destroy(batch);
+	}
+	return EOK;
+}
+
+/* HUB ROUTINES IMPLEMENTATION */
+#define TEST_SIZE_INIT(size, port, hub) \
+do { \
+	hub = virthub_get_data(device); \
+	assert(hub);\
+	if (uint16_usb2host(setup_packet->length) != size) \
+		return ESTALL; \
+	port = uint16_usb2host(setup_packet->index) - 1; \
+	if (port > hub->port_count) \
+		return EINVAL; \
+} while (0)
+
+/** Hub status request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_get_status(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ohci_rh_t *hub = virthub_get_data(device);
+	assert(hub);
+	if (uint16_usb2host(setup_packet->length) != 4)
+		return ESTALL;
+	const uint32_t val = OHCI_RD(hub->registers->rh_status) &
+	    (RHS_LPS_FLAG | RHS_LPSC_FLAG | RHS_OCI_FLAG | RHS_OCIC_FLAG);
+	memcpy(data, &val, sizeof(val));
+	*act_size = sizeof(val);
+	return EOK;
+}
+
+/** Hub set feature request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_clear_hub_feature(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ohci_rh_t *hub = virthub_get_data(device);
+	assert(hub);
+
+	/*
+	 * Chapter 11.16.2 specifies that only C_HUB_LOCAL_POWER and
+	 * C_HUB_OVER_CURRENT are supported.
+	 * C_HUB_LOCAL_POWER is not supported
+	 * because root hubs do not support local power status feature.
+	 * C_HUB_OVER_CURRENT is represented by OHCI RHS_OCIC_FLAG.
+	 * (OHCI pg. 127)
+	 */
+	const unsigned feature = uint16_usb2host(setup_packet->value);
+	if (feature == USB_HUB_FEATURE_C_HUB_OVER_CURRENT) {
+		OHCI_WR(hub->registers->rh_status, RHS_OCIC_FLAG);
+	}
+	return EOK;
+}
+
+/** Port status request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_get_port_status(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ohci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(4, port, hub);
+	if (setup_packet->value != 0)
+		return EINVAL;
+
+	const uint32_t status = OHCI_RD(hub->registers->rh_port_status[port]);
+	memcpy(data, &status, sizeof(status));
+	*act_size = sizeof(status);
+	return EOK;
+}
+
+/** Port clear feature request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_clear_port_feature(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ohci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(0, port, hub);
+	const unsigned feature = uint16_usb2host(setup_packet->value);
+	/* Enabled features to clear: see page 269 of USB specs */
+	switch (feature)
+	{
+	case USB_HUB_FEATURE_PORT_POWER:          /*8*/
+		{
+			const uint32_t rhda =
+			    OHCI_RD(hub->registers->rh_desc_a);
+			/* No power switching */
+			if (rhda & RHDA_NPS_FLAG)
+				return ENOTSUP;
+			/* Ganged power switching, one port powers all */
+			if (!(rhda & RHDA_PSM_FLAG)) {
+				OHCI_WR(hub->registers->rh_status,
+				    RHS_CLEAR_GLOBAL_POWER);
+				return EOK;
+			}
+			OHCI_WR(hub->registers->rh_port_status[port],
+			    RHPS_CLEAR_PORT_POWER);
+			return EOK;
+		}
+
+	case USB_HUB_FEATURE_PORT_ENABLE:         /*1*/
+		OHCI_WR(hub->registers->rh_port_status[port],
+		    RHPS_CLEAR_PORT_ENABLE);
+		return EOK;
+
+	case USB_HUB_FEATURE_PORT_SUSPEND:        /*2*/
+		OHCI_WR(hub->registers->rh_port_status[port],
+		    RHPS_CLEAR_PORT_SUSPEND);
+		return EOK;
+
+	case USB_HUB_FEATURE_C_PORT_CONNECTION:   /*16*/
+	case USB_HUB_FEATURE_C_PORT_ENABLE:       /*17*/
+	case USB_HUB_FEATURE_C_PORT_SUSPEND:      /*18*/
+	case USB_HUB_FEATURE_C_PORT_OVER_CURRENT: /*19*/
+	case USB_HUB_FEATURE_C_PORT_RESET:        /*20*/
+		usb_log_debug2("Clearing port C_CONNECTION, C_ENABLE, "
+		    "C_SUSPEND, C_OC or C_RESET on port %"PRIu16".\n", port);
+		/* Bit offsets correspond to the feature number */
+		OHCI_WR(hub->registers->rh_port_status[port],
+		    1 << feature);
+		return EOK;
+
+	default:
+		return ENOTSUP;
+	}
+}
+
+/** Port set feature request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_set_port_feature(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ohci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(0, port, hub);
+	const unsigned feature = uint16_usb2host(setup_packet->value);
+	switch (feature) {
+	case USB_HUB_FEATURE_PORT_POWER:   /*8*/
+	{
+		const uint32_t rhda = OHCI_RD(hub->registers->rh_desc_a);
+		/* No power switching */
+		if (rhda & RHDA_NPS_FLAG)
+			return EOK;
+		/* Ganged power switching, one port powers all */
+		if (!(rhda & RHDA_PSM_FLAG)) {
+			OHCI_WR(hub->registers->rh_status,RHS_SET_GLOBAL_POWER);
+			return EOK;
+		}
+	}
+	/* Fall through, for per port power */
+	case USB_HUB_FEATURE_PORT_ENABLE:  /*1*/
+	case USB_HUB_FEATURE_PORT_SUSPEND: /*2*/
+	case USB_HUB_FEATURE_PORT_RESET:   /*4*/
+		usb_log_debug2("Setting port POWER, ENABLE, SUSPEND or RESET "
+		    "on port %"PRIu16".\n", port);
+		/* Bit offsets correspond to the feature number */
+		OHCI_WR(hub->registers->rh_port_status[port], 1 << feature);
+		return EOK;
+	default:
+		return ENOTSUP;
+	}
+}
+
+/** Status change handler.
+ * @param device Virtual hub device
+ * @param endpoint Endpoint number
+ * @param tr_type Transfer type
+ * @param buffer Response destination
+ * @param buffer_size Bytes available in buffer
+ * @param actual_size Size us the used part of the dest buffer.
+ *
+ * Produces status mask. Bit 0 indicates hub status change the other bits
+ * represent port status change. Endian does not matter as UHCI root hubs
+ * only need 1 byte.
+ */
+static int req_status_change_handler(usbvirt_device_t *device,
+    usb_endpoint_t endpoint, usb_transfer_type_t tr_type,
+    void *buffer, size_t buffer_size, size_t *actual_size)
+{
+	ohci_rh_t *hub = virthub_get_data(device);
+	assert(hub);
+
+	if (buffer_size < STATUS_BYTES(hub->port_count))
+		return ESTALL;
+
+	uint16_t mask = 0;
+
+	/* Only local power source change and over-current change can happen */
+	if (OHCI_RD(hub->registers->rh_status) & (RHS_LPSC_FLAG | RHS_OCIC_FLAG)) {
+		mask |= 1;
+	}
+
+	for (unsigned port = 1; port <= hub->port_count; ++port) {
+		/* Write-clean bits are those that indicate change */
+		if (OHCI_RD(hub->registers->rh_port_status[port - 1])
+		    & RHPS_CHANGE_WC_MASK) {
+			mask |= (1 << port);
+		}
+	}
+
+	usb_log_debug2("OHCI root hub interrupt mask: %hx.\n", mask);
+
+	if (mask == 0)
+		return ENAK;
+	mask = uint16_host2usb(mask);
+	memcpy(buffer, &mask, STATUS_BYTES(hub->port_count));
+	*actual_size = STATUS_BYTES(hub->port_count);
+	return EOK;
+}
+
+/** OHCI root hub request handlers */
+static const usbvirt_control_request_handler_t control_transfer_handlers[] = {
+	{
+		STD_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		.name = "GetDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		.name = "GetDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_DESCRIPTOR),
+		.name = "GetHubDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetPortStatus",
+		.callback = req_get_port_status,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_CLEAR_FEATURE),
+		.name = "ClearHubFeature",
+		.callback = req_clear_hub_feature,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_CLEAR_FEATURE),
+		.name = "ClearPortFeature",
+		.callback = req_clear_port_feature,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetHubStatus",
+		.callback = req_get_status,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetPortStatus",
+		.callback = req_get_port_status,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_SET_FEATURE),
+		.name = "SetHubFeature",
+		.callback = req_nop,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_SET_FEATURE),
+		.name = "SetPortFeature",
+		.callback = req_set_port_feature,
+	},
+	{
+		.callback = NULL
+	}
+};
+
+/** Virtual OHCI root hub ops */
+static usbvirt_device_ops_t ops = {
+        .control = control_transfer_handlers,
+        .data_in[HUB_STATUS_CHANGE_PIPE] = req_status_change_handler,
+};
Index: uspace/drv/bus/usb/ohci/ohci_rh.h
===================================================================
--- uspace/drv/bus/usb/ohci/ohci_rh.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/ohci/ohci_rh.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2013 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 drvusbohci
+ * @{
+ */
+/** @file
+ * @brief OHCI driver
+ */
+#ifndef DRV_OHCI_OHCI_RH_H
+#define DRV_OHCI_OHCI_RH_H
+
+#include <assert.h>
+#include <sys/types.h>
+
+#include <usb/usb.h>
+#include <usb/classes/hub.h>
+#include <usb/host/usb_transfer_batch.h>
+#include <usbvirt/virthub_base.h>
+
+#include "ohci_regs.h"
+
+enum {
+	OHCI_MAX_PORTS = 15,
+};
+
+typedef struct {
+	/** Virtual hub instance */
+	virthub_base_t base;
+	/** OHCI device registers */
+	ohci_regs_t *registers;
+	/** Number of downstream ports, OHCI limits this to 15 */
+	unsigned port_count;
+	/** USB hub descriptor describing the OHCI root hub */
+	struct {
+		usb_hub_descriptor_header_t header;
+		uint8_t rempow[STATUS_BYTES(OHCI_MAX_PORTS) * 2];
+	} __attribute__((packed)) hub_descriptor;
+	/** interrupt transfer waiting for an actual interrupt to occur */
+	usb_transfer_batch_t *unfinished_interrupt_transfer;
+} ohci_rh_t;
+
+int ohci_rh_init(ohci_rh_t *instance, ohci_regs_t *regs, const char *name);
+int ohci_rh_schedule(ohci_rh_t *instance, usb_transfer_batch_t *batch);
+int ohci_rh_interrupt(ohci_rh_t *instance);
+
+/** Get OHCI rh address.
+ *
+ * @param instance UHCI rh instance.
+ * @return USB address assigned to the hub.
+ * Wrapper for virtual hub address
+ */
+static inline usb_address_t ohci_rh_get_address(ohci_rh_t *instance)
+{
+	assert(instance);
+	return virthub_base_get_address(&instance->base);
+}
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/ohci/res.c
===================================================================
--- uspace/drv/bus/usb/ohci/res.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,108 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbohci
- * @{
- */
-/**
- * @file
- * PCI related functions needed by the OHCI driver.
- */
-
-#include <errno.h>
-#include <assert.h>
-#include <devman.h>
-#include <device/hw_res_parsed.h>
-
-#include <usb/debug.h>
-
-#include "res.h"
-
-/** Get address of registers and IRQ for given device.
- *
- * @param[in] dev Device asking for the addresses.
- * @param[out] p_regs Pointer to register range.
- * @param[out] irq_no IRQ assigned to the device.
- * @return Error code.
- */
-int get_my_registers(ddf_dev_t *dev, addr_range_t *p_regs, int *irq_no)
-{
-	assert(dev);
-
-	async_sess_t *parent_sess =
-	    devman_parent_device_connect(EXCHANGE_SERIALIZE,
-	    ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);
-	if (!parent_sess)
-		return ENOMEM;
-
-	hw_res_list_parsed_t hw_res;
-	hw_res_list_parsed_init(&hw_res);
-	const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
-	async_hangup(parent_sess);
-	if (ret != EOK) {
-		return ret;
-	}
-
-	/* We want one irq and one mem range. */
-	if (hw_res.irqs.count != 1 || hw_res.mem_ranges.count != 1) {
-		hw_res_list_parsed_clean(&hw_res);
-		return EINVAL;
-	}
-
-	if (p_regs)
-		*p_regs = hw_res.mem_ranges.ranges[0];
-	if (irq_no)
-		*irq_no = hw_res.irqs.irqs[0];
-
-	hw_res_list_parsed_clean(&hw_res);
-	return EOK;
-}
-
-/** Call the PCI driver with a request to enable interrupts
- *
- * @param[in] device Device asking for interrupts
- * @return Error code.
- */
-int enable_interrupts(ddf_dev_t *device)
-{
-	async_sess_t *parent_sess =
-	    devman_parent_device_connect(EXCHANGE_SERIALIZE,
-	    ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
-	if (!parent_sess)
-		return ENOMEM;
-	
-	const bool enabled = hw_res_enable_interrupt(parent_sess);
-	async_hangup(parent_sess);
-	
-	return enabled ? EOK : EIO;
-}
-
-/**
- * @}
- */
Index: uspace/drv/bus/usb/ohci/res.h
===================================================================
--- uspace/drv/bus/usb/ohci/res.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,47 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbohci
- * @{
- */
-/** @file
- * PCI related functions needed by OHCI driver.
- */
-#ifndef DRV_OHCI_RES_H
-#define DRV_OHCI_RES_H
-
-#include <ddf/driver.h>
-#include <device/hw_res_parsed.h>
-
-int get_my_registers(ddf_dev_t *, addr_range_t *, int *);
-int enable_interrupts(ddf_dev_t *);
-
-#endif
-/**
- * @}
- */
-
Index: uspace/drv/bus/usb/ohci/root_hub.c
===================================================================
--- uspace/drv/bus/usb/ohci/root_hub.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,843 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbohci
- * @{
- */
-/** @file
- * @brief OHCI driver
- */
-#include <assert.h>
-#include <byteorder.h>
-#include <errno.h>
-#include <str_error.h>
-#include <fibril_synch.h>
-
-#include <usb/usb.h>
-#include <usb/debug.h>
-#include <usb/dev/request.h>
-#include <usb/classes/hub.h>
-
-#include <usb/classes/classes.h>
-#include <usb/classes/hub.h>
-#include <usb/dev/driver.h>
-#include "ohci_regs.h"
-#include "root_hub.h"
-
-/**
- * standart device descriptor for ohci root hub
- */
-static const usb_standard_device_descriptor_t ohci_rh_device_descriptor = {
-	.configuration_count = 1,
-	.descriptor_type = USB_DESCTYPE_DEVICE,
-	.device_class = USB_CLASS_HUB,
-	.device_protocol = 0,
-	.device_subclass = 0,
-	.device_version = 0,
-	.length = sizeof(usb_standard_device_descriptor_t),
-	.max_packet_size = 64,
-	.vendor_id = 0x16db, /* HelenOS does not have USB vendor ID assigned.*/
-	.product_id = 0x0001,
-	.str_serial_number = 0,
-	.usb_spec_version = 0x110,
-};
-
-/**
- * standart configuration descriptor with filled common values
- * for ohci root hubs
- */
-static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor = {
-	.attributes = 1 << 7,
-	.configuration_number = 1,
-	.descriptor_type = USB_DESCTYPE_CONFIGURATION,
-	.interface_count = 1,
-	.length = sizeof(usb_standard_configuration_descriptor_t),
-	.max_power = 0, /* root hubs don't need no power */
-	.str_configuration = 0,
-};
-
-/**
- * standart ohci root hub interface descriptor
- */
-static const usb_standard_interface_descriptor_t ohci_rh_iface_descriptor = {
-	.alternate_setting = 0,
-	.descriptor_type = USB_DESCTYPE_INTERFACE,
-	.endpoint_count = 1,
-	.interface_class = USB_CLASS_HUB,
-	.interface_number = 1,
-	.interface_protocol = 0,
-	.interface_subclass = 0,
-	.length = sizeof(usb_standard_interface_descriptor_t),
-	.str_interface = 0,
-};
-
-/**
- * standart ohci root hub endpoint descriptor
- */
-static const usb_standard_endpoint_descriptor_t ohci_rh_ep_descriptor = {
-	.attributes = USB_TRANSFER_INTERRUPT,
-	.descriptor_type = USB_DESCTYPE_ENDPOINT,
-	.endpoint_address = 1 | (1 << 7),
-	.length = sizeof(usb_standard_endpoint_descriptor_t),
-	.max_packet_size = 2,
-	.poll_interval = 255,
-};
-
-static void create_serialized_hub_descriptor(rh_t *instance);
-static void rh_init_descriptors(rh_t *instance);
-static uint16_t create_interrupt_mask(const rh_t *instance);
-static void get_status(const rh_t *instance, usb_transfer_batch_t *request);
-static void get_descriptor(const rh_t *instance, usb_transfer_batch_t *request);
-static void set_feature(const rh_t *instance, usb_transfer_batch_t *request);
-static void clear_feature(const rh_t *instance, usb_transfer_batch_t *request);
-static int set_feature_port(
-    const rh_t *instance, uint16_t feature, uint16_t port);
-static int clear_feature_port(
-    const rh_t *instance, uint16_t feature, uint16_t port);
-static void control_request(rh_t *instance, usb_transfer_batch_t *request);
-static inline void interrupt_request(
-    usb_transfer_batch_t *request, uint16_t mask, size_t size)
-{
-	assert(request);
-	usb_log_debug("Sending interrupt vector(%zu) %hhx:%hhx.\n",
-	    size, ((uint8_t*)&mask)[0], ((uint8_t*)&mask)[1]);
-	usb_transfer_batch_finish_error(request, &mask, size, EOK);
-	usb_transfer_batch_destroy(request);
-}
-
-#define TRANSFER_END_DATA(request, data, bytes) \
-do { \
-	usb_transfer_batch_finish_error(request, data, bytes, EOK); \
-	usb_transfer_batch_destroy(request); \
-	return; \
-} while (0)
-
-#define TRANSFER_END(request, error) \
-do { \
-	usb_transfer_batch_finish_error(request, NULL, 0, error); \
-	usb_transfer_batch_destroy(request); \
-	return; \
-} while (0)
-
-/** Root Hub driver structure initialization.
- *
- * Reads info registers and prepares descriptors. Sets power mode.
- */
-void rh_init(rh_t *instance, ohci_regs_t *regs)
-{
-	assert(instance);
-	assert(regs);
-
-	instance->registers = regs;
-	instance->port_count = OHCI_RD(regs->rh_desc_a) & RHDA_NDS_MASK;
-	usb_log_debug2("rh_desc_a: %x.\n", OHCI_RD(regs->rh_desc_a));
-	if (instance->port_count > 15) {
-		usb_log_warning("OHCI specification does not allow more than 15"
-		    " ports. Max 15 ports will be used");
-		instance->port_count = 15;
-	}
-
-	/* Don't forget the hub status bit and round up */
-	instance->interrupt_mask_size = 1 + (instance->port_count / 8);
-	instance->unfinished_interrupt_transfer = NULL;
-
-#if defined OHCI_POWER_SWITCH_no
-	usb_log_debug("OHCI rh: Set power mode to no power switching.\n");
-	/* Set port power mode to no power-switching. (always on) */
-	OHCI_SET(regs->rh_desc_a, RHDA_NPS_FLAG);
-
-	/* Set to no over-current reporting */
-	OHCI_SET(regs->rh_desc_a, RHDA_NOCP_FLAG);
-
-#elif defined OHCI_POWER_SWITCH_ganged
-	usb_log_debug("OHCI rh: Set power mode to ganged power switching.\n");
-	/* Set port power mode to ganged power-switching. */
-	OHCI_CLR(regs->rh_desc_a, RHDA_NPS_FLAG);
-	OHCI_CLR(regs->rh_desc_a, RHDA_PSM_FLAG);
-
-	/* Turn off power (hub driver will turn this back on)*/
-	OHCI_WR(regs->rh_status, RHS_CLEAR_GLOBAL_POWER);
-
-	/* Set to global over-current */
-	OHCI_CLR(regs->rh_desc_a, RHDA_NOCP_FLAG);
-	OHCI_CLR(regs->rh_desc_a, RHDA_OCPM_FLAG);
-#else
-	usb_log_debug("OHCI rh: Set power mode to per-port power switching.\n");
-	/* Set port power mode to per port power-switching. */
-	OHCI_CLR(regs->rh_desc_a, RHDA_NPS_FLAG);
-	OHCI_SET(regs->rh_desc_a, RHDA_PSM_FLAG);
-
-	/* Control all ports by global switch and turn them off */
-	OHCI_CLR(regs->rh_desc_b, RHDB_PCC_MASK << RHDB_PCC_SHIFT);
-	OHCI_WR(regs->rh_status, RHS_CLEAR_GLOBAL_POWER);
-
-	/* Return control to per port state */
-	OHCI_SET(regs->rh_desc_b, RHDB_PCC_MASK << RHDB_PCC_SHIFT);
-
-	/* Set per port over-current */
-	OHCI_CLR(regs->rh_desc_a, RHDA_NOCP_FLAG);
-	OHCI_SET(regs->rh_desc_a, RHDA_OCPM_FLAG);
-#endif
-
-	fibril_mutex_initialize(&instance->guard);
-	rh_init_descriptors(instance);
-
-	usb_log_info("Root hub (%zu ports) initialized.\n",
-	    instance->port_count);
-}
-
-/**
- * Process root hub request.
- *
- * @param instance Root hub instance
- * @param request Structure containing both request and response information
- * @return Error code
- */
-void rh_request(rh_t *instance, usb_transfer_batch_t *request)
-{
-	assert(instance);
-	assert(request);
-
-	switch (request->ep->transfer_type)
-	{
-	case USB_TRANSFER_CONTROL:
-		usb_log_debug("Root hub got CONTROL packet\n");
-		control_request(instance, request);
-		break;
-
-	case USB_TRANSFER_INTERRUPT:
-		usb_log_debug("Root hub got INTERRUPT packet\n");
-		fibril_mutex_lock(&instance->guard);
-		assert(instance->unfinished_interrupt_transfer == NULL);
-		const uint16_t mask = create_interrupt_mask(instance);
-		if (mask == 0) {
-			usb_log_debug("No changes(%hx)...\n", mask);
-			instance->unfinished_interrupt_transfer = request;
-		} else {
-			usb_log_debug("Processing changes...\n");
-			interrupt_request(
-			    request, mask, instance->interrupt_mask_size);
-		}
-		fibril_mutex_unlock(&instance->guard);
-		break;
-
-	default:
-		usb_log_error("Root hub got unsupported request.\n");
-		TRANSFER_END(request, ENOTSUP);
-	}
-}
-
-/**
- * Process interrupt on a hub device.
- *
- * If there is no pending interrupt transfer, nothing happens.
- * @param instance
- */
-void rh_interrupt(rh_t *instance)
-{
-	assert(instance);
-
-	fibril_mutex_lock(&instance->guard);
-	if (instance->unfinished_interrupt_transfer) {
-		usb_log_debug("Finalizing interrupt transfer\n");
-		const uint16_t mask = create_interrupt_mask(instance);
-		interrupt_request(instance->unfinished_interrupt_transfer,
-		    mask, instance->interrupt_mask_size);
-		instance->unfinished_interrupt_transfer = NULL;
-	}
-	fibril_mutex_unlock(&instance->guard);
-}
-
-/**
- * Create hub descriptor.
- *
- * For descriptor format see USB hub specification (chapter 11.15.2.1, pg. 263)
- *
- * @param instance Root hub instance
- * @return Error code
- */
-void create_serialized_hub_descriptor(rh_t *instance)
-{
-	assert(instance);
-
-	/* 7 bytes + 2 port bit fields (port count + global bit) */
-	size_t size = 7 + (instance->interrupt_mask_size * 2);
-	assert(size <= HUB_DESCRIPTOR_MAX_SIZE);
-	instance->hub_descriptor_size = size;
-
-	const uint32_t hub_desc = OHCI_RD(instance->registers->rh_desc_a);
-	const uint32_t port_desc = OHCI_RD(instance->registers->rh_desc_b);
-
-	/* bDescLength */
-	instance->descriptors.hub[0] = size;
-	/* bDescriptorType */
-	instance->descriptors.hub[1] = USB_DESCTYPE_HUB;
-	/* bNmbrPorts */
-	instance->descriptors.hub[2] = instance->port_count;
-	/* wHubCharacteristics */
-	instance->descriptors.hub[3] = 0 |
-	    /* The lowest 2 bits indicate power switching mode */
-	    (((hub_desc & RHDA_PSM_FLAG)  ? 1 : 0) << 0) |
-	    (((hub_desc & RHDA_NPS_FLAG)  ? 1 : 0) << 1) |
-	    /* Bit 3 indicates device type (compound device) */
-	    (((hub_desc & RHDA_DT_FLAG)   ? 1 : 0) << 2) |
-	    /* Bits 4,5 indicate over-current protection mode */
-	    (((hub_desc & RHDA_OCPM_FLAG) ? 1 : 0) << 3) |
-	    (((hub_desc & RHDA_NOCP_FLAG) ? 1 : 0) << 4);
-
-	/* Reserved */
-	instance->descriptors.hub[4] = 0;
-	/* bPwrOn2PwrGood */
-	instance->descriptors.hub[5] = hub_desc >> RHDA_POTPGT_SHIFT;
-	/* bHubContrCurrent, root hubs don't need no power. */
-	instance->descriptors.hub[6] = 0;
-
-	/* Device Removable and some legacy 1.0 stuff*/
-	instance->descriptors.hub[7] = (port_desc >> RHDB_DR_SHIFT) & 0xff;
-	instance->descriptors.hub[8] = 0xff;
-	if (instance->interrupt_mask_size == 2) {
-		instance->descriptors.hub[8] =
-		    (port_desc >> RHDB_DR_SHIFT) >> 8;
-		instance->descriptors.hub[9]  = 0xff;
-		instance->descriptors.hub[10] = 0xff;
-	}
-}
-
-/** Initialize hub descriptors.
- *
- * A full configuration descriptor is assembled. The configuration and endpoint
- * descriptors have local modifications.
- * @param instance Root hub instance
- * @return Error code
- */
-void rh_init_descriptors(rh_t *instance)
-{
-	assert(instance);
-
-	instance->descriptors.configuration = ohci_rh_conf_descriptor;
-	instance->descriptors.interface = ohci_rh_iface_descriptor;
-	instance->descriptors.endpoint = ohci_rh_ep_descriptor;
-	create_serialized_hub_descriptor(instance);
-
-	instance->descriptors.endpoint.max_packet_size =
-	    instance->interrupt_mask_size;
-
-	instance->descriptors.configuration.total_length = uint16_host2usb(
-	    sizeof(usb_standard_configuration_descriptor_t) +
-	    sizeof(usb_standard_endpoint_descriptor_t) +
-	    sizeof(usb_standard_interface_descriptor_t) +
-	    instance->hub_descriptor_size);
-}
-
-/**
- * Create bitmap of changes to answer status interrupt.
- *
- * Result contains bitmap where bit 0 indicates change on hub and
- * bit i indicates change on i`th port (i>0). For more info see
- * Hub and Port status bitmap specification in USB specification
- * (chapter 11.13.4).
- * @param instance root hub instance
- * @return Mask of changes.
- */
-uint16_t create_interrupt_mask(const rh_t *instance)
-{
-	assert(instance);
-	uint16_t mask = 0;
-
-	/* Only local power source change and over-current change can happen */
-	if (OHCI_RD(instance->registers->rh_status)
-	    & (RHS_LPSC_FLAG | RHS_OCIC_FLAG)) {
-		mask |= 1;
-	}
-	for (size_t port = 1; port <= instance->port_count; ++port) {
-		/* Write-clean bits are those that indicate change */
-		if (OHCI_RD(instance->registers->rh_port_status[port - 1])
-		    & RHPS_CHANGE_WC_MASK) {
-			mask |= (1 << port);
-		}
-	}
-	usb_log_debug2("OHCI root hub interrupt mask: %hx.\n", mask);
-	return uint16_host2usb(mask);
-}
-
-/**
- * Create answer to status request.
- *
- * This might be either hub status or port status request. If neither,
- * ENOTSUP is returned.
- * @param instance root hub instance
- * @param request structure containing both request and response information
- * @return error code
- */
-void get_status(const rh_t *instance, usb_transfer_batch_t *request)
-{
-	assert(instance);
-	assert(request);
-
-
-	usb_device_request_setup_packet_t *request_packet =
-	    (usb_device_request_setup_packet_t*)request->setup_buffer;
-
-	const uint16_t index = uint16_usb2host(request_packet->index);
-
-	switch (request_packet->request_type)
-	{
-	case USB_HUB_REQ_TYPE_GET_HUB_STATUS:
-	/* Hub status: just filter relevant info from rh_status reg */
-		if (request->buffer_size < 4) {
-			usb_log_error("Buffer(%zu) too small for hub get "
-			    "status request.\n", request->buffer_size);
-			TRANSFER_END(request, EOVERFLOW);
-		} else {
-			const uint32_t data =
-			    OHCI_RD(instance->registers->rh_status) &
-			        (RHS_LPS_FLAG | RHS_LPSC_FLAG
-			            | RHS_OCI_FLAG | RHS_OCIC_FLAG);
-			TRANSFER_END_DATA(request, &data, sizeof(data));
-		}
-
-	/* Copy appropriate rh_port_status register, OHCI designers were
-	 * kind enough to make those bit values match USB specification */
-	case USB_HUB_REQ_TYPE_GET_PORT_STATUS:
-		if (request->buffer_size < 4) {
-			usb_log_error("Buffer(%zu) too small for hub get "
-			    "status request.\n", request->buffer_size);
-			TRANSFER_END(request, EOVERFLOW);
-		} else {
-			const unsigned port = index;
-			if (port < 1 || port > instance->port_count)
-				TRANSFER_END(request, EINVAL);
-			/* Register format matches the format of port status
-			 * field */
-			const uint32_t data = uint32_host2usb(OHCI_RD(
-			    instance->registers->rh_port_status[port - 1]));
-			TRANSFER_END_DATA(request, &data, sizeof(data));
-		}
-	case SETUP_REQUEST_TO_HOST(USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE):
-		if (request->buffer_size < 2) {
-			usb_log_error("Buffer(%zu) too small for hub generic "
-			    "get status request.\n", request->buffer_size);
-			TRANSFER_END(request, EOVERFLOW);
-		} else {
-			const uint16_t data =
-			    uint16_host2usb(USB_DEVICE_STATUS_SELF_POWERED);
-			TRANSFER_END_DATA(request, &data, sizeof(data));
-		}
-
-	case SETUP_REQUEST_TO_HOST(USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE):
-		/* Hubs are allowed to have only one interface */
-		if (index != 0)
-			TRANSFER_END(request, EINVAL);
-		/* Fall through, as the answer will be the same: 0x0000 */
-	case SETUP_REQUEST_TO_HOST(USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_ENDPOINT):
-		/* Endpoint 0 (default control) and 1 (interrupt) */
-		if (index >= 2)
-			TRANSFER_END(request, EINVAL);
-
-		if (request->buffer_size < 2) {
-			usb_log_error("Buffer(%zu) too small for hub generic "
-			    "get status request.\n", request->buffer_size);
-			TRANSFER_END(request, EOVERFLOW);
-		} else {
-			/* Endpoints are OK. (We don't halt) */
-			const uint16_t data = 0;
-			TRANSFER_END_DATA(request, &data, sizeof(data));
-		}
-
-	default:
-		usb_log_error("Unsupported GET_STATUS request.\n");
-		TRANSFER_END(request, ENOTSUP);
-	}
-
-}
-
-/**
- * Create answer to a descriptor request.
- *
- * This might be a request for standard (configuration, device, endpoint or
- * interface) or device specific (hub) descriptor.
- * @param instance Root hub instance
- * @param request Structure containing both request and response information
- * @return Error code
- */
-void get_descriptor(const rh_t *instance, usb_transfer_batch_t *request)
-{
-	assert(instance);
-	assert(request);
-
-	usb_device_request_setup_packet_t *setup_request =
-	    (usb_device_request_setup_packet_t *) request->setup_buffer;
-	/* "The wValue field specifies the descriptor type in the high byte
-	 * and the descriptor index in the low byte (refer to Table 9-5)." */
-	const int desc_type = uint16_usb2host(setup_request->value) >> 8;
-	switch (desc_type)
-	{
-	case USB_DESCTYPE_HUB:
-		usb_log_debug2("USB_DESCTYPE_HUB\n");
-		/* Hub descriptor was generated locally.
-		 * Class specific request. */
-		TRANSFER_END_DATA(request, instance->descriptors.hub,
-		    instance->hub_descriptor_size);
-
-	case USB_DESCTYPE_DEVICE:
-		usb_log_debug2("USB_DESCTYPE_DEVICE\n");
-		/* Device descriptor is shared
-		 * (No one should ask for it, as the device is already setup)
-		 * Standard USB device request. */
-		TRANSFER_END_DATA(request, &ohci_rh_device_descriptor,
-		    sizeof(ohci_rh_device_descriptor));
-
-	case USB_DESCTYPE_CONFIGURATION:
-		usb_log_debug2("USB_DESCTYPE_CONFIGURATION\n");
-		/* Start with configuration and add others depending on
-		 * request size. Standard USB request. */
-		TRANSFER_END_DATA(request, &instance->descriptors,
-		    instance->descriptors.configuration.total_length);
-
-	case USB_DESCTYPE_INTERFACE:
-		usb_log_debug2("USB_DESCTYPE_INTERFACE\n");
-		/* Use local interface descriptor. There is one and it
-		 * might be modified. Hub driver should not ask or this
-		 * descriptor as it is not part of standard requests set. */
-		TRANSFER_END_DATA(request, &instance->descriptors.interface,
-		    sizeof(instance->descriptors.interface));
-
-	case USB_DESCTYPE_ENDPOINT:
-		/* Use local endpoint descriptor. There is one
-		 * it might have max_packet_size field modified. Hub driver
-		 * should not ask for this descriptor as it is not part
-		 * of standard requests set. */
-		usb_log_debug2("USB_DESCTYPE_ENDPOINT\n");
-		TRANSFER_END_DATA(request, &instance->descriptors.endpoint,
-		    sizeof(instance->descriptors.endpoint));
-
-	default:
-		usb_log_debug2("USB_DESCTYPE_EINVAL %d \n"
-		    "\ttype %d\n\trequest %d\n\tvalue "
-		    "%d\n\tindex %d\n\tlen %d\n ",
-		    setup_request->value,
-		    setup_request->request_type, setup_request->request,
-		    desc_type, setup_request->index,
-		    setup_request->length);
-		TRANSFER_END(request, EINVAL);
-	}
-
-	TRANSFER_END(request, ENOTSUP);
-}
-
-/**
- * process feature-enabling request on hub
- *
- * @param instance root hub instance
- * @param feature feature selector
- * @param port port number, counted from 1
- * @param enable enable or disable the specified feature
- * @return error code
- */
-int set_feature_port(const rh_t *instance, uint16_t feature, uint16_t port)
-{
-	assert(instance);
-
-	if (port < 1 || port > instance->port_count)
-		return EINVAL;
-
-	switch (feature) {
-	case USB_HUB_FEATURE_PORT_POWER:   /*8*/
-		{
-			const uint32_t rhda =
-			    OHCI_RD(instance->registers->rh_desc_a);
-			/* No power switching */
-			if (rhda & RHDA_NPS_FLAG)
-				return EOK;
-			/* Ganged power switching, one port powers all */
-			if (!(rhda & RHDA_PSM_FLAG)) {
-				OHCI_WR(instance->registers->rh_status,
-				    RHS_SET_GLOBAL_POWER);
-				return EOK;
-			}
-		}
-			/* Fall through */
-	case USB_HUB_FEATURE_PORT_ENABLE:  /*1*/
-	case USB_HUB_FEATURE_PORT_SUSPEND: /*2*/
-	case USB_HUB_FEATURE_PORT_RESET:   /*4*/
-		usb_log_debug2("Setting port POWER, ENABLE, SUSPEND or RESET "
-		    "on port %"PRIu16".\n", port);
-		OHCI_WR(instance->registers->rh_port_status[port - 1],
-		    1 << feature);
-		return EOK;
-	default:
-		return ENOTSUP;
-	}
-}
-
-/**
- * Process feature clear request.
- *
- * @param instance root hub instance
- * @param feature feature selector
- * @param port port number, counted from 1
- * @param enable enable or disable the specified feature
- * @return error code
- */
-int clear_feature_port(const rh_t *instance, uint16_t feature, uint16_t port)
-{
-	assert(instance);
-
-	if (port < 1 || port > instance->port_count)
-		return EINVAL;
-
-	/* Enabled features to clear: see page 269 of USB specs */
-	switch (feature)
-	{
-	case USB_HUB_FEATURE_PORT_POWER:          /*8*/
-		{
-			const uint32_t rhda =
-			    OHCI_RD(instance->registers->rh_desc_a);
-			/* No power switching */
-			if (rhda & RHDA_NPS_FLAG)
-				return ENOTSUP;
-			/* Ganged power switching, one port powers all */
-			if (!(rhda & RHDA_PSM_FLAG)) {
-				OHCI_WR(instance->registers->rh_status,
-				    RHS_CLEAR_GLOBAL_POWER);
-				return EOK;
-			}
-			OHCI_WR(instance->registers->rh_port_status[port - 1],
-			    RHPS_CLEAR_PORT_POWER);
-			return EOK;
-		}
-
-	case USB_HUB_FEATURE_PORT_ENABLE:         /*1*/
-		OHCI_WR(instance->registers->rh_port_status[port - 1],
-		    RHPS_CLEAR_PORT_ENABLE);
-		return EOK;
-
-	case USB_HUB_FEATURE_PORT_SUSPEND:        /*2*/
-		OHCI_WR(instance->registers->rh_port_status[port - 1],
-		    RHPS_CLEAR_PORT_SUSPEND);
-		return EOK;
-
-	case USB_HUB_FEATURE_C_PORT_CONNECTION:   /*16*/
-	case USB_HUB_FEATURE_C_PORT_ENABLE:       /*17*/
-	case USB_HUB_FEATURE_C_PORT_SUSPEND:      /*18*/
-	case USB_HUB_FEATURE_C_PORT_OVER_CURRENT: /*19*/
-	case USB_HUB_FEATURE_C_PORT_RESET:        /*20*/
-		usb_log_debug2("Clearing port C_CONNECTION, C_ENABLE, "
-		    "C_SUSPEND, C_OC or C_RESET on port %"PRIu16".\n", port);
-		/* Bit offsets correspond to the feature number */
-		OHCI_WR(instance->registers->rh_port_status[port - 1],
-		    1 << feature);
-		return EOK;
-
-	default:
-		return ENOTSUP;
-	}
-}
-
-/**
- * process one of requests that do not request nor carry additional data
- *
- * Request can be one of USB_DEVREQ_CLEAR_FEATURE, USB_DEVREQ_SET_FEATURE or
- * USB_DEVREQ_SET_ADDRESS.
- * @param instance root hub instance
- * @param request structure containing both request and response information
- * @return error code
- */
-void set_feature(const rh_t *instance, usb_transfer_batch_t *request)
-{
-	assert(instance);
-	assert(request);
-
-	usb_device_request_setup_packet_t *setup_request =
-	    (usb_device_request_setup_packet_t *) request->setup_buffer;
-	switch (setup_request->request_type)
-	{
-	case USB_HUB_REQ_TYPE_SET_PORT_FEATURE:
-		usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
-		const int ret = set_feature_port(instance,
-		    setup_request->value, setup_request->index);
-		TRANSFER_END(request, ret);
-
-	case USB_HUB_REQ_TYPE_SET_HUB_FEATURE:
-		/* Chapter 11.16.2 specifies that hub can be recipient
-		 * only for C_HUB_LOCAL_POWER and C_HUB_OVER_CURRENT
-		 * features. It makes no sense to SET either. */
-		usb_log_error("Invalid HUB set feature request.\n");
-		TRANSFER_END(request, ENOTSUP);
-	//TODO: Consider standard USB requests: REMOTE WAKEUP, ENDPOINT STALL
-	default:
-		usb_log_error("Invalid set feature request type: %d\n",
-		    setup_request->request_type);
-		TRANSFER_END(request, ENOTSUP);
-	}
-}
-
-/**
- * process one of requests that do not request nor carry additional data
- *
- * Request can be one of USB_DEVREQ_CLEAR_FEATURE, USB_DEVREQ_SET_FEATURE or
- * USB_DEVREQ_SET_ADDRESS.
- * @param instance root hub instance
- * @param request structure containing both request and response information
- * @return error code
- */
-void clear_feature(const rh_t *instance, usb_transfer_batch_t *request)
-{
-	assert(instance);
-	assert(request);
-
-	usb_device_request_setup_packet_t *setup_request =
-	    (usb_device_request_setup_packet_t *) request->setup_buffer;
-
-	switch (setup_request->request_type)
-	{
-	case USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE:
-		usb_log_debug("USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE\n");
-		const int ret = clear_feature_port(instance,
-		    setup_request->value, setup_request->index);
-		TRANSFER_END(request, ret);
-
-	case USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE:
-		usb_log_debug("USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE\n");
-		/*
-		 * Chapter 11.16.2 specifies that only C_HUB_LOCAL_POWER and
-		 * C_HUB_OVER_CURRENT are supported.
-		 * C_HUB_OVER_CURRENT is represented by OHCI RHS_OCIC_FLAG.
-		 * C_HUB_LOCAL_POWER is not supported
-		 * as root hubs do not support local power status feature.
-		 * (OHCI pg. 127) */
-		if (uint16_usb2host(setup_request->value)
-		    == USB_HUB_FEATURE_C_HUB_OVER_CURRENT) {
-			OHCI_WR(instance->registers->rh_status, RHS_OCIC_FLAG);
-			TRANSFER_END(request, EOK);
-		}
-	//TODO: Consider standard USB requests: REMOTE WAKEUP, ENDPOINT STALL
-	default:
-		usb_log_error("Invalid clear feature request type: %d\n",
-		    setup_request->request_type);
-		TRANSFER_END(request, ENOTSUP);
-	}
-}
-
-/**
- * Process hub control request.
- *
- * If needed, writes answer into the request structure.
- * Request can be one of
- * USB_DEVREQ_GET_STATUS,
- * USB_DEVREQ_GET_DESCRIPTOR,
- * USB_DEVREQ_GET_CONFIGURATION,
- * USB_DEVREQ_CLEAR_FEATURE,
- * USB_DEVREQ_SET_FEATURE,
- * USB_DEVREQ_SET_ADDRESS,
- * USB_DEVREQ_SET_DESCRIPTOR or
- * USB_DEVREQ_SET_CONFIGURATION.
- *
- * @param instance root hub instance
- * @param request structure containing both request and response information
- * @return error code
- */
-void control_request(rh_t *instance, usb_transfer_batch_t *request)
-{
-	assert(instance);
-	assert(request);
-
-	if (!request->setup_buffer) {
-		usb_log_error("Root hub received empty transaction!");
-		TRANSFER_END(request, EBADMEM);
-	}
-
-	if (sizeof(usb_device_request_setup_packet_t) > request->setup_size) {
-		usb_log_error("Setup packet too small\n");
-		TRANSFER_END(request, EOVERFLOW);
-	}
-
-	usb_log_debug2("CTRL packet: %s.\n",
-	    usb_debug_str_buffer((uint8_t *) request->setup_buffer, 8, 8));
-	usb_device_request_setup_packet_t *setup_request =
-	    (usb_device_request_setup_packet_t *) request->setup_buffer;
-	switch (setup_request->request)
-	{
-	case USB_DEVREQ_GET_STATUS:
-		usb_log_debug("USB_DEVREQ_GET_STATUS\n");
-		get_status(instance, request);
-		break;
-
-	case USB_DEVREQ_GET_DESCRIPTOR:
-		usb_log_debug("USB_DEVREQ_GET_DESCRIPTOR\n");
-		get_descriptor(instance, request);
-		break;
-
-	case USB_DEVREQ_GET_CONFIGURATION:
-		usb_log_debug("USB_DEVREQ_GET_CONFIGURATION\n");
-		if (request->buffer_size == 0)
-			TRANSFER_END(request, EOVERFLOW);
-		const uint8_t config = 1;
-		TRANSFER_END_DATA(request, &config, sizeof(config));
-
-	case USB_DEVREQ_CLEAR_FEATURE:
-		usb_log_debug2("USB_DEVREQ_CLEAR_FEATURE\n");
-		clear_feature(instance, request);
-		break;
-
-	case USB_DEVREQ_SET_FEATURE:
-		usb_log_debug2("USB_DEVREQ_SET_FEATURE\n");
-		set_feature(instance, request);
-		break;
-
-	case USB_DEVREQ_SET_ADDRESS:
-		usb_log_debug("USB_DEVREQ_SET_ADDRESS: %u\n",
-		    setup_request->value);
-		if (uint16_usb2host(setup_request->value) > 127)
-			TRANSFER_END(request, EINVAL);
-
-		instance->address = uint16_usb2host(setup_request->value);
-		TRANSFER_END(request, EOK);
-
-	case USB_DEVREQ_SET_CONFIGURATION:
-		usb_log_debug("USB_DEVREQ_SET_CONFIGURATION: %u\n",
-		    uint16_usb2host(setup_request->value));
-		/* We have only one configuration, it's number is 1 */
-		if (uint16_usb2host(setup_request->value) != 1)
-			TRANSFER_END(request, EINVAL);
-		TRANSFER_END(request, EOK);
-
-	/* Both class specific and std is optional for hubs */
-	case USB_DEVREQ_SET_DESCRIPTOR:
-	/* Hubs have only one interface GET/SET is not supported */
-	case USB_DEVREQ_GET_INTERFACE:
-	case USB_DEVREQ_SET_INTERFACE:
-	default:
-		/* Hub class GET_STATE(2) falls in here too. */
-		usb_log_error("Received unsupported request: %d.\n",
-		    setup_request->request);
-		TRANSFER_END(request, ENOTSUP);
-	}
-}
-/**
- * @}
- */
Index: uspace/drv/bus/usb/ohci/root_hub.h
===================================================================
--- uspace/drv/bus/usb/ohci/root_hub.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,79 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbohci
- * @{
- */
-/** @file
- * @brief OHCI driver
- */
-#ifndef DRV_OHCI_ROOT_HUB_H
-#define DRV_OHCI_ROOT_HUB_H
-
-#include <usb/usb.h>
-#include <usb/dev/driver.h>
-#include <usb/host/usb_transfer_batch.h>
-
-#include "ohci_regs.h"
-
-#define HUB_DESCRIPTOR_MAX_SIZE (7 + 2 + 2)
-
-/**
- * ohci root hub representation
- */
-typedef struct rh {
-	fibril_mutex_t guard;
-	/** pointer to ohci driver registers */
-	ohci_regs_t *registers;
-	/** usb address of the root hub */
-	usb_address_t address;
-	/** hub port count */
-	size_t port_count;
-	/** interrupt transfer waiting for an actual interrupt to occur */
-	usb_transfer_batch_t *unfinished_interrupt_transfer;
-	/** size of interrupt buffer */
-	size_t interrupt_mask_size;
-	/** Descriptors */
-	struct {
-		usb_standard_configuration_descriptor_t configuration;
-		usb_standard_interface_descriptor_t interface;
-		usb_standard_endpoint_descriptor_t endpoint;
-		uint8_t hub[HUB_DESCRIPTOR_MAX_SIZE];
-	} __attribute__ ((packed)) descriptors;
-	/** size of hub descriptor */
-	size_t hub_descriptor_size;
-} rh_t;
-
-void rh_init(rh_t *instance, ohci_regs_t *regs);
-
-void rh_request(rh_t *instance, usb_transfer_batch_t *request);
-
-void rh_interrupt(rh_t *instance);
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/ohci/utils/malloc32.h
===================================================================
--- uspace/drv/bus/usb/ohci/utils/malloc32.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/ohci/utils/malloc32.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -35,10 +35,8 @@
 #define DRV_OHCI_UTILS_MALLOC32_H
 
-#include <assert.h>
-#include <malloc.h>
-#include <unistd.h>
+#include <as.h>
 #include <errno.h>
-#include <mem.h>
-#include <as.h>
+#include <stdlib.h>
+#include <sys/types.h>
 
 /* Generic TDs and EDs require 16byte alignment,
Index: uspace/drv/bus/usb/uhci/Makefile
===================================================================
--- uspace/drv/bus/usb/uhci/Makefile	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/uhci/Makefile	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -31,4 +31,5 @@
 LIBS = \
 	$(LIBUSBHOST_PREFIX)/libusbhost.a \
+	$(LIBUSBVIRT_PREFIX)/libusbvirt.a \
 	$(LIBUSB_PREFIX)/libusb.a \
 	$(LIBDRV_PREFIX)/libdrv.a
@@ -36,5 +37,7 @@
 EXTRA_CFLAGS += \
 	-I$(LIBUSB_PREFIX)/include \
+	-I$(LIBUSBDEV_PREFIX)/include \
 	-I$(LIBUSBHOST_PREFIX)/include \
+	-I$(LIBUSBVIRT_PREFIX)/include \
 	-I$(LIBDRV_PREFIX)/include
 
@@ -44,9 +47,7 @@
 	hc.c \
 	main.c \
-	res.c \
-	root_hub.c \
 	transfer_list.c \
-	uhci.c \
 	uhci_batch.c \
+	uhci_rh.c \
 	hw_struct/transfer_descriptor.c
 
Index: uspace/drv/bus/usb/uhci/hc.c
===================================================================
--- uspace/drv/bus/usb/uhci/hc.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/uhci/hc.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -32,14 +32,24 @@
  * @brief UHCI Host controller driver routines
  */
+
+#include <adt/list.h>
+#include <assert.h>
+#include <async.h>
+#include <ddi.h>
+#include <device/hw_res_parsed.h>
+#include <fibril.h>
 #include <errno.h>
+#include <macros.h>
+#include <mem.h>
+#include <stdlib.h>
 #include <str_error.h>
-#include <adt/list.h>
-#include <ddi.h>
+#include <sys/types.h>
 
 #include <usb/debug.h>
 #include <usb/usb.h>
 
+#include "uhci_batch.h"
+#include "utils/malloc32.h"
 #include "hc.h"
-#include "uhci_batch.h"
 
 #define UHCI_INTR_ALLOW_INTERRUPTS \
@@ -85,92 +95,56 @@
 static int hc_init_mem_structures(hc_t *instance);
 static int hc_init_transfer_lists(hc_t *instance);
-static int hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
-
-static int hc_interrupt_emulator(void *arg);
+
 static int hc_debug_checker(void *arg);
 
-enum {
-	/** Number of PIO ranges used in IRQ code */
-	hc_irq_pio_range_count =
-	    sizeof(uhci_irq_pio_ranges) / sizeof(irq_pio_range_t),
-
-	/* Number of commands used in IRQ code */
-	hc_irq_cmd_count =
-	    sizeof(uhci_irq_commands) / sizeof(irq_cmd_t)
-};
 
 /** Generate IRQ code.
- * @param[out] ranges PIO ranges buffer.
- * @param[in] ranges_size Size of the ranges buffer (bytes).
- * @param[out] cmds Commands buffer.
- * @param[in] cmds_size Size of the commands buffer (bytes).
- * @param[in] regs Device's register range.
+ * @param[out] code IRQ code structure.
+ * @param[in] hw_res Device's resources.
  *
  * @return Error code.
  */
-int
-hc_get_irq_code(irq_pio_range_t ranges[], size_t ranges_size, irq_cmd_t cmds[],
-    size_t cmds_size, addr_range_t *regs)
-{
-	if ((ranges_size < sizeof(uhci_irq_pio_ranges)) ||
-	    (cmds_size < sizeof(uhci_irq_commands)) ||
-	    (RNGSZ(*regs) < sizeof(uhci_regs_t)))
+int uhci_hc_gen_irq_code(irq_code_t *code, const hw_res_list_parsed_t *hw_res)
+{
+	assert(code);
+	assert(hw_res);
+
+	if (hw_res->irqs.count != 1 || hw_res->io_ranges.count != 1)
+		return EINVAL;
+	const addr_range_t regs = hw_res->io_ranges.ranges[0];
+
+	if (RNGSZ(regs) < sizeof(uhci_regs_t))
 		return EOVERFLOW;
 
-	memcpy(ranges, uhci_irq_pio_ranges, sizeof(uhci_irq_pio_ranges));
-	ranges[0].base = RNGABS(*regs);
-
-	memcpy(cmds, uhci_irq_commands, sizeof(uhci_irq_commands));
-	uhci_regs_t *registers = (uhci_regs_t *) RNGABSPTR(*regs);
-	cmds[0].addr = (void *) &registers->usbsts;
-	cmds[3].addr = (void *) &registers->usbsts;
-
-	return EOK;
-}
-
-/** Register interrupt handler.
- *
- * @param[in] device Host controller DDF device
- * @param[in] regs Register range
- * @param[in] irq Interrupt number
- * @paran[in] handler Interrupt handler
- *
- * @return EOK on success or negative error code
- */
-int hc_register_irq_handler(ddf_dev_t *device, addr_range_t *regs, int irq,
-    interrupt_handler_t handler)
-{
-	int rc;
-	irq_pio_range_t irq_ranges[hc_irq_pio_range_count];
-	irq_cmd_t irq_cmds[hc_irq_cmd_count];
-	rc = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
-	    sizeof(irq_cmds), regs);
-	if (rc != EOK) {
-		usb_log_error("Failed to generate IRQ commands: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-	
-	irq_code_t irq_code = {
-		.rangecount = hc_irq_pio_range_count,
-		.ranges = irq_ranges,
-		.cmdcount = hc_irq_cmd_count,
-		.cmds = irq_cmds
-	};
-	
-	/* Register handler to avoid interrupt lockup */
-	rc = register_interrupt_handler(device, irq, handler, &irq_code);
-	if (rc != EOK) {
-		usb_log_error("Failed to register interrupt handler: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-	
-	return EOK;
+	code->ranges = malloc(sizeof(uhci_irq_pio_ranges));
+	if (code->ranges == NULL)
+		return ENOMEM;
+
+	code->cmds = malloc(sizeof(uhci_irq_commands));
+	if (code->cmds == NULL) {
+		free(code->ranges);
+		return ENOMEM;
+	}
+
+	code->rangecount = ARRAY_SIZE(uhci_irq_pio_ranges);
+	code->cmdcount = ARRAY_SIZE(uhci_irq_commands);
+
+	memcpy(code->ranges, uhci_irq_pio_ranges, sizeof(uhci_irq_pio_ranges));
+	code->ranges[0].base = RNGABS(regs);
+
+	memcpy(code->cmds, uhci_irq_commands, sizeof(uhci_irq_commands));
+	uhci_regs_t *registers = (uhci_regs_t *) RNGABSPTR(regs);
+	code->cmds[0].addr = (void*)&registers->usbsts;
+	code->cmds[3].addr = (void*)&registers->usbsts;
+
+	usb_log_debug("I/O regs at %p (size %zu), IRQ %d.\n",
+	    RNGABSPTR(regs), RNGSZ(regs), hw_res->irqs.irqs[0]);
+
+	return hw_res->irqs.irqs[0];
 }
 
 /** Take action based on the interrupt cause.
  *
- * @param[in] instance UHCI structure to use.
+ * @param[in] hcd HCD structure to use.
  * @param[in] status Value of the status register at the time of interrupt.
  *
@@ -180,6 +154,8 @@
  * - resume from suspend state (not implemented)
  */
-void hc_interrupt(hc_t *instance, uint16_t status)
-{
+void uhci_hc_interrupt(hcd_t *hcd, uint32_t status)
+{
+	assert(hcd);
+	hc_t *instance = hcd->driver.data;
 	assert(instance);
 	/* Lower 2 bits are transaction error and transaction complete */
@@ -195,9 +171,8 @@
 		    &instance->transfers_bulk_full, &done);
 
-		while (!list_empty(&done)) {
-			link_t *item = list_first(&done);
-			list_remove(item);
+		list_foreach_safe(done, current, next) {
+			list_remove(current);
 			uhci_transfer_batch_t *batch =
-			    uhci_transfer_batch_from_link(item);
+			    uhci_transfer_batch_from_link(current);
 			uhci_transfer_batch_finish_dispose(batch);
 		}
@@ -230,5 +205,4 @@
  *
  * @param[in] instance Memory place to initialize.
- * @param[in] HC function node
  * @param[in] regs Range of device's I/O control registers.
  * @param[in] interrupts True if hw interrupts should be used.
@@ -239,8 +213,11 @@
  * interrupt fibrils.
  */
-int hc_init(hc_t *instance, ddf_fun_t *fun, addr_range_t *regs, bool interrupts)
-{
-	assert(regs->size >= sizeof(uhci_regs_t));
-	int rc;
+int hc_init(hc_t *instance, const hw_res_list_parsed_t *hw_res, bool interrupts)
+{
+	assert(instance);
+	assert(hw_res);
+	if (hw_res->io_ranges.count != 1 ||
+	    hw_res->io_ranges.ranges[0].size < sizeof(uhci_regs_t))
+	    return EINVAL;
 
 	instance->hw_interrupts = interrupts;
@@ -248,45 +225,40 @@
 
 	/* allow access to hc control registers */
-	uhci_regs_t *io;
-	rc = pio_enable_range(regs, (void **) &io);
-	if (rc != EOK) {
-		usb_log_error("Failed to gain access to registers at %p: %s.\n",
-		    io, str_error(rc));
-		return rc;
-	}
-
-	instance->registers = io;
-	usb_log_debug(
-	    "Device registers at %p (%zuB) accessible.\n", io, regs->size);
-
-	rc = hc_init_mem_structures(instance);
-	if (rc != EOK) {
-		usb_log_error("Failed to initialize UHCI memory structures: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-
-	instance->generic = ddf_fun_data_alloc(fun, sizeof(hcd_t));
-	if (instance->generic == NULL) {
-		usb_log_error("Out of memory.\n");
-		return ENOMEM;
-	}
-
-	hcd_init(instance->generic, USB_SPEED_FULL,
-	    BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
-
-	instance->generic->private_data = instance;
-	instance->generic->schedule = hc_schedule;
-	instance->generic->ep_add_hook = NULL;
+	int ret = pio_enable_range(&hw_res->io_ranges.ranges[0],
+	    (void **) &instance->registers);
+	if (ret != EOK) {
+		usb_log_error("Failed to gain access to registers: %s.\n",
+	            str_error(ret));
+		return ret;
+	}
+
+	usb_log_debug("Device registers at %" PRIx64 " (%zuB) accessible.\n",
+	    hw_res->io_ranges.ranges[0].address.absolute,
+	    hw_res->io_ranges.ranges[0].size);
+
+	ret = hc_init_mem_structures(instance);
+	if (ret != EOK) {
+		usb_log_error("Failed to init UHCI memory structures: %s.\n",
+		    str_error(ret));
+		// TODO: we should disable pio here
+		return ret;
+	}
 
 	hc_init_hw(instance);
-	if (!interrupts) {
-		instance->interrupt_emulator =
-		    fibril_create(hc_interrupt_emulator, instance);
-		fibril_add_ready(instance->interrupt_emulator);
-	}
 	(void)hc_debug_checker;
 
+	uhci_rh_init(&instance->rh, instance->registers->ports, "uhci");
+
 	return EOK;
+}
+
+/** Safely dispose host controller internal structures
+ *
+ * @param[in] instance Host controller structure to use.
+ */
+void hc_fini(hc_t *instance)
+{
+	assert(instance);
+	//TODO Implement
 }
 
@@ -432,7 +404,21 @@
 	instance->transfers[USB_SPEED_FULL][USB_TRANSFER_BULK] =
 	  &instance->transfers_bulk_full;
-	instance->transfers[USB_SPEED_LOW][USB_TRANSFER_BULK] =
-	  &instance->transfers_bulk_full;
-
+
+	return EOK;
+}
+
+int uhci_hc_status(hcd_t *hcd, uint32_t *status)
+{
+	assert(hcd);
+	assert(status);
+	hc_t *instance = hcd->driver.data;
+	assert(instance);
+
+	*status = 0;
+	if (instance->registers) {
+		uint16_t s = pio_read_16(&instance->registers->usbsts);
+		pio_write_16(&instance->registers->usbsts, s);
+		*status = s;
+	}
 	return EOK;
 }
@@ -446,10 +432,14 @@
  * Checks for bandwidth availability and appends the batch to the proper queue.
  */
-int hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
+int uhci_hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
 {
 	assert(hcd);
-	hc_t *instance = hcd->private_data;
+	hc_t *instance = hcd->driver.data;
 	assert(instance);
 	assert(batch);
+
+	if (batch->ep->address == uhci_rh_get_address(&instance->rh))
+		return uhci_rh_schedule(&instance->rh, batch);
+
 	uhci_transfer_batch_t *uhci_batch = uhci_transfer_batch_get(batch);
 	if (!uhci_batch) {
@@ -463,27 +453,4 @@
 	transfer_list_add_batch(list, uhci_batch);
 
-	return EOK;
-}
-
-/** Polling function, emulates interrupts.
- *
- * @param[in] arg UHCI hc structure to use.
- * @return EOK (should never return)
- */
-int hc_interrupt_emulator(void* arg)
-{
-	usb_log_debug("Started interrupt emulator.\n");
-	hc_t *instance = arg;
-	assert(instance);
-
-	while (1) {
-		/* Read and clear status register */
-		uint16_t status = pio_read_16(&instance->registers->usbsts);
-		pio_write_16(&instance->registers->usbsts, status);
-		if (status != 0)
-			usb_log_debug2("UHCI status: %x.\n", status);
-		hc_interrupt(instance, status);
-		async_usleep(UHCI_INT_EMULATOR_TIMEOUT);
-	}
 	return EOK;
 }
Index: uspace/drv/bus/usb/uhci/hc.h
===================================================================
--- uspace/drv/bus/usb/uhci/hc.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/uhci/hc.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -36,11 +36,15 @@
 #define DRV_UHCI_HC_H
 
-#include <ddf/driver.h>
-#include <ddf/interrupt.h>
 #include <device/hw_res_parsed.h>
 #include <fibril.h>
+#include <macros.h>
+#include <stdbool.h>
+#include <sys/types.h>
 #include <usb/host/hcd.h>
+#include <usb/host/usb_transfer_batch.h>
 
+#include "uhci_rh.h"
 #include "transfer_list.h"
+#include "hw_struct/link_pointer.h"
 
 /** UHCI I/O registers layout */
@@ -83,17 +87,16 @@
 	/** SOF modification to match external timers */
 	ioport8_t sofmod;
+
+	PADD8[3];
+	ioport16_t ports[];
 } uhci_regs_t;
 
 #define UHCI_FRAME_LIST_COUNT 1024
-#define UHCI_INT_EMULATOR_TIMEOUT 10000
 #define UHCI_DEBUGER_TIMEOUT 5000000
 #define UHCI_ALLOWED_HW_FAIL 5
-#define UHCI_NEEDED_IRQ_COMMANDS 5
 
 /** Main UHCI driver structure */
 typedef struct hc {
-	/** Generic HCD driver structure */
-	hcd_t *generic;
-
+	uhci_rh_t rh;
 	/** Addresses of I/O registers */
 	uhci_regs_t *registers;
@@ -113,6 +116,4 @@
 	/** Pointer table to the above lists, helps during scheduling */
 	transfer_list_t *transfers[2][4];
-	/** Fibril periodically checking status register*/
-	fid_t interrupt_emulator;
 	/** Indicator of hw interrupts availability */
 	bool hw_interrupts;
@@ -122,16 +123,13 @@
 } hc_t;
 
-int hc_register_irq_handler(ddf_dev_t *, addr_range_t *, int,
-    interrupt_handler_t);
-int hc_get_irq_code(irq_pio_range_t [], size_t, irq_cmd_t [], size_t,
-    addr_range_t *);
-void hc_interrupt(hc_t *instance, uint16_t status);
-int hc_init(hc_t *, ddf_fun_t *, addr_range_t *, bool);
+int hc_init(hc_t *instance, const hw_res_list_parsed_t *hw_res, bool interupts);
+void hc_fini(hc_t *instance);
 
-/** Safely dispose host controller internal structures
- *
- * @param[in] instance Host controller structure to use.
- */
-static inline void hc_fini(hc_t *instance) {} /* TODO: implement*/
+int uhci_hc_gen_irq_code(irq_code_t *code, const hw_res_list_parsed_t *hw_res);
+
+void uhci_hc_interrupt(hcd_t *hcd, uint32_t status);
+int uhci_hc_status(hcd_t *hcd, uint32_t *status);
+int uhci_hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
+
 #endif
 
Index: uspace/drv/bus/usb/uhci/hw_struct/link_pointer.h
===================================================================
--- uspace/drv/bus/usb/uhci/hw_struct/link_pointer.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/uhci/hw_struct/link_pointer.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -35,4 +35,6 @@
 #define DRV_UHCI_HW_STRUCT_LINK_POINTER_H
 
+#include <sys/types.h>
+
 /** UHCI link pointer, used by many data structures */
 typedef uint32_t link_pointer_t;
Index: uspace/drv/bus/usb/uhci/hw_struct/queue_head.h
===================================================================
--- uspace/drv/bus/usb/uhci/hw_struct/queue_head.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/uhci/hw_struct/queue_head.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -34,5 +34,7 @@
 #ifndef DRV_UHCI_HW_STRUCT_QH_H
 #define DRV_UHCI_HW_STRUCT_QH_H
+
 #include <assert.h>
+#include <sys/types.h>
 
 #include "link_pointer.h"
Index: uspace/drv/bus/usb/uhci/hw_struct/transfer_descriptor.c
===================================================================
--- uspace/drv/bus/usb/uhci/hw_struct/transfer_descriptor.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/uhci/hw_struct/transfer_descriptor.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -32,7 +32,12 @@
  * @brief UHCI driver
  */
+
+#include <assert.h>
 #include <errno.h>
+
 #include <usb/debug.h>
+#include <usb/usb.h>
 
+#include "link_pointer.h"
 #include "transfer_descriptor.h"
 #include "../utils/malloc32.h"
Index: uspace/drv/bus/usb/uhci/hw_struct/transfer_descriptor.h
===================================================================
--- uspace/drv/bus/usb/uhci/hw_struct/transfer_descriptor.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/uhci/hw_struct/transfer_descriptor.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -35,6 +35,8 @@
 #define DRV_UHCI_HW_STRUCT_TRANSFER_DESCRIPTOR_H
 
-#include <mem.h>
+#include <assert.h>
 #include <usb/usb.h>
+#include <stdbool.h>
+#include <sys/types.h>
 
 #include "link_pointer.h"
Index: uspace/drv/bus/usb/uhci/main.c
===================================================================
--- uspace/drv/bus/usb/uhci/main.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/uhci/main.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -26,5 +26,5 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-/** @addtogroup drvusbuhcihc
+/** @addtogroup drvusbuhci
  * @{
  */
@@ -32,25 +32,78 @@
  * @brief UHCI driver initialization
  */
+
+#include <assert.h>
 #include <ddf/driver.h>
+#include <devman.h>
 #include <errno.h>
+#include <io/log.h>
+#include <pci_dev_iface.h>
+#include <stdio.h>
 #include <str_error.h>
+#include <usb/debug.h>
+#include <usb/host/ddf_helpers.h>
 
-#include <usb/ddfiface.h>
-#include <usb/debug.h>
-
-#include "uhci.h"
+#include "hc.h"
 
 #define NAME "uhci"
 
+static int uhci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
+{
+	assert(hcd);
+	assert(hcd->driver.data == NULL);
+
+	hc_t *instance = malloc(sizeof(hc_t));
+	if (!instance)
+		return ENOMEM;
+
+	const int ret =  hc_init(instance, res, irq);
+	if (ret == EOK)
+		hcd_set_implementation(hcd, instance, uhci_hc_schedule, NULL,
+		    NULL, uhci_hc_interrupt, uhci_hc_status);
+	return ret;
+}
+
+static void uhci_driver_fini(hcd_t *hcd)
+{
+	assert(hcd);
+	if (hcd->driver.data)
+		hc_fini(hcd->driver.data);
+
+	free(hcd->driver.data);
+	hcd_set_implementation(hcd, NULL, NULL, NULL, NULL, NULL, NULL);
+}
+
 static int uhci_dev_add(ddf_dev_t *device);
 
-static driver_ops_t uhci_driver_ops = {
+static const driver_ops_t uhci_driver_ops = {
 	.dev_add = uhci_dev_add,
 };
 
-static driver_t uhci_driver = {
+static const driver_t uhci_driver = {
 	.name = NAME,
 	.driver_ops = &uhci_driver_ops
 };
+
+/** Call the PCI driver with a request to clear legacy support register
+ *
+ * @param[in] device Device asking to disable interrupts
+ * @return Error code.
+ */
+static int disable_legacy(ddf_dev_t *device)
+{
+	assert(device);
+
+	async_sess_t *parent_sess = devman_parent_device_connect(
+	    EXCHANGE_SERIALIZE, ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
+	if (!parent_sess)
+		return ENOMEM;
+
+	/* See UHCI design guide page 45 for these values.
+	 * Write all WC bits in USB legacy register */
+	const int rc = pci_config_space_write_16(parent_sess, 0xc0, 0xaf00);
+
+	async_hangup(parent_sess);
+	return rc;
+}
 
 /** Initialize a new ddf driver instance for uhci hc and hub.
@@ -64,5 +117,16 @@
 	assert(device);
 
-	const int ret = device_setup_uhci(device);
+	int ret = disable_legacy(device);
+	if (ret != EOK) {
+		usb_log_error("Failed to disable legacy USB: %s.\n",
+		    str_error(ret));
+		return ret;
+	}
+
+
+	ret = ddf_hcd_device_setup_all(device, USB_SPEED_FULL,
+	    BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11,
+	    ddf_hcd_gen_irq_handler, uhci_hc_gen_irq_code,
+	    uhci_driver_init, uhci_driver_fini);
 	if (ret != EOK) {
 		usb_log_error("Failed to initialize UHCI driver: %s.\n",
Index: uspace/drv/bus/usb/uhci/res.c
===================================================================
--- uspace/drv/bus/usb/uhci/res.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,128 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbuhcihc
- * @{
- */
-/**
- * @file
- * PCI related functions needed by the UHCI driver.
- */
-
-#include <errno.h>
-#include <assert.h>
-#include <devman.h>
-#include <device/hw_res_parsed.h>
-#include <pci_dev_iface.h>
-
-#include "res.h"
-
-/** Get I/O address of registers and IRQ for given device.
- *
- * @param[in] dev Device asking for the addresses.
- * @param[out] io_regs_p Pointer to register I/O range.
- * @param[out] irq_no IRQ assigned to the device.
- * @return Error code.
- */
-int get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs_p, int *irq_no)
-{
-	assert(dev);
-
-	async_sess_t *parent_sess =
-	    devman_parent_device_connect(EXCHANGE_SERIALIZE,
-	    ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);
-	if (!parent_sess)
-		return ENOMEM;
-
-	hw_res_list_parsed_t hw_res;
-	hw_res_list_parsed_init(&hw_res);
-	const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
-	async_hangup(parent_sess);
-	if (ret != EOK) {
-		return ret;
-	}
-
-	/* We want one irq and one io range. */
-	if (hw_res.irqs.count != 1 || hw_res.io_ranges.count != 1) {
-		hw_res_list_parsed_clean(&hw_res);
-		return EINVAL;
-	}
-
-	if (io_regs_p)
-		*io_regs_p = hw_res.io_ranges.ranges[0];
-	if (irq_no)
-		*irq_no = hw_res.irqs.irqs[0];
-
-	hw_res_list_parsed_clean(&hw_res);
-	return EOK;
-}
-
-/** Call the PCI driver with a request to enable interrupts
- *
- * @param[in] device Device asking for interrupts
- * @return Error code.
- */
-int enable_interrupts(ddf_dev_t *device)
-{
-	async_sess_t *parent_sess =
-	    devman_parent_device_connect(EXCHANGE_SERIALIZE,
-	    ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
-	if (!parent_sess)
-		return ENOMEM;
-
-	const bool enabled = hw_res_enable_interrupt(parent_sess);
-	async_hangup(parent_sess);
-
-	return enabled ? EOK : EIO;
-}
-
-/** Call the PCI driver with a request to clear legacy support register
- *
- * @param[in] device Device asking to disable interrupts
- * @return Error code.
- */
-int disable_legacy(ddf_dev_t *device)
-{
-	assert(device);
-
-	async_sess_t *parent_sess = devman_parent_device_connect(
-	    EXCHANGE_SERIALIZE, ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
-	if (!parent_sess)
-		return ENOMEM;
-
-	/* See UHCI design guide page 45 for these values.
-	 * Write all WC bits in USB legacy register */
-	const int rc = pci_config_space_write_16(parent_sess, 0xc0, 0xaf00);
-
-	async_hangup(parent_sess);
-	return rc;
-}
-
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhci/res.h
===================================================================
--- uspace/drv/bus/usb/uhci/res.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,49 +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.
- */
-
-/** @addtogroup drvusbuhcihc
- * @{
- */
-/** @file
- * @brief UHCI driver PCI helper functions
- */
-#ifndef DRV_UHCI_PCI_H
-#define DRV_UHCI_PCI_H
-
-#include <ddf/driver.h>
-#include <device/hw_res_parsed.h>
-
-int get_my_registers(ddf_dev_t *, addr_range_t *, int *);
-int enable_interrupts(ddf_dev_t *);
-int disable_legacy(ddf_dev_t *);
-
-#endif
-/**
- * @}
- */
-
Index: uspace/drv/bus/usb/uhci/root_hub.c
===================================================================
--- uspace/drv/bus/usb/uhci/root_hub.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,83 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbuhci
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#include <assert.h>
-#include <errno.h>
-#include <str_error.h>
-#include <stdio.h>
-#include <device/hw_res_parsed.h>
-
-#include <usb/debug.h>
-
-#include "root_hub.h"
-
-/** Root hub initialization
- * @param[in] instance RH structure to initialize
- * @param[in] fun DDF function representing UHCI root hub
- * @param[in] reg_addr Address of root hub status and control registers.
- * @param[in] reg_size Size of accessible address space.
- * @return Error code.
- */
-int
-rh_init(rh_t *instance, ddf_fun_t *fun, addr_range_t *regs, uintptr_t reg_addr,
-    size_t reg_size)
-{
-	assert(instance);
-	assert(fun);
-
-	/* Crop the PIO window to the absolute address range of UHCI I/O. */
-	instance->pio_window.mem.base = 0;
-	instance->pio_window.mem.size = 0;
-	instance->pio_window.io.base = RNGABS(*regs);
-	instance->pio_window.io.size = RNGSZ(*regs);
-
-	/* Initialize resource structure */
-	instance->resource_list.count = 1;
-	instance->resource_list.resources = &instance->io_regs;
-
-	instance->io_regs.type = IO_RANGE;
-	instance->io_regs.res.io_range.address = reg_addr;
-	instance->io_regs.res.io_range.size = reg_size;
-	instance->io_regs.res.io_range.relative = true;
-	instance->io_regs.res.io_range.endianness = LITTLE_ENDIAN;
-
-	const int ret = ddf_fun_add_match_id(fun, "usb&uhci&root-hub", 100);
-	if (ret != EOK) {
-		usb_log_error("Failed to add root hub match id: %s\n",
-		    str_error(ret));
-	}
-	return ret;
-}
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhci/root_hub.h
===================================================================
--- uspace/drv/bus/usb/uhci/root_hub.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,57 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbuhci
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#ifndef DRV_UHCI_RH_H
-#define DRV_UHCI_RH_H
-
-#include <ddf/driver.h>
-#include <ops/hw_res.h>
-#include <ops/pio_window.h>
-
-/** DDF support structure for uhci_rhd driver, provides I/O resources */
-typedef struct rh {
-	/** List of resources available to the root hub. */
-	hw_resource_list_t resource_list;
-	/** The only resource in the RH resource list */
-	hw_resource_t io_regs;
-	/** PIO window in which the RH will operate. */
-	pio_window_t pio_window;	
-} rh_t;
-
-extern int rh_init(rh_t *, ddf_fun_t *, addr_range_t *, uintptr_t, size_t);
-
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhci/transfer_list.c
===================================================================
--- uspace/drv/bus/usb/uhci/transfer_list.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/uhci/transfer_list.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -34,8 +34,13 @@
  */
 
+#include <assert.h>
 #include <errno.h>
+#include <libarch/barrier.h>
+#include <sys/types.h>
 #include <usb/debug.h>
-#include <libarch/barrier.h>
-
+#include <usb/host/usb_transfer_batch.h>
+
+#include "utils/malloc32.h"
+#include "hw_struct/link_pointer.h"
 #include "transfer_list.h"
 
Index: uspace/drv/bus/usb/uhci/transfer_list.h
===================================================================
--- uspace/drv/bus/usb/uhci/transfer_list.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/uhci/transfer_list.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -35,4 +35,5 @@
 #define DRV_UHCI_TRANSFER_LIST_H
 
+#include <adt/list.h>
 #include <fibril_synch.h>
 
Index: uspace/drv/bus/usb/uhci/uhci.c
===================================================================
--- uspace/drv/bus/usb/uhci/uhci.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,293 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbuhci
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-
-#include <errno.h>
-#include <stdbool.h>
-#include <str_error.h>
-#include <ddf/interrupt.h>
-#include <usb_iface.h>
-#include <usb/ddfiface.h>
-#include <usb/debug.h>
-
-#include "uhci.h"
-
-#include "res.h"
-#include "hc.h"
-#include "root_hub.h"
-
-/** Structure representing both functions of UHCI hc, USB host controller
- * and USB root hub */
-typedef struct uhci {
-	/** Pointer to DDF representation of UHCI host controller */
-	ddf_fun_t *hc_fun;
-	/** Pointer to DDF representation of UHCI root hub */
-	ddf_fun_t *rh_fun;
-
-	/** Internal driver's representation of UHCI host controller */
-	hc_t hc;
-	/** Internal driver's representation of UHCI root hub */
-	rh_t *rh;
-} uhci_t;
-
-static inline uhci_t *dev_to_uhci(ddf_dev_t *dev)
-{
-	return ddf_dev_data_get(dev);
-}
-
-/** IRQ handling callback, forward status from call to diver structure.
- *
- * @param[in] iid (Unused).
- * @param[in] call Pointer to the call from kernel.
- * @param[in] dev DDF instance of the device to use.
- *
- */
-static void irq_handler(ipc_callid_t iid, ipc_call_t *call, ddf_dev_t *dev)
-{
-	assert(dev);
-	
-	uhci_t *uhci = dev_to_uhci(dev);
-	if (!uhci) {
-		usb_log_error("Interrupt on not yet initialized device.\n");
-		return;
-	}
-	
-	const uint16_t status = IPC_GET_ARG1(*call);
-	hc_interrupt(&uhci->hc, status);
-}
-
-/** Operations supported by the HC driver */
-static ddf_dev_ops_t hc_ops = {
-	.interfaces[USBHC_DEV_IFACE] = &hcd_iface, /* see iface.h/c */
-};
-
-/** Gets handle of the respective hc.
- *
- * @param[in] fun DDF function of uhci device.
- * @param[out] handle Host cotnroller handle.
- * @return Error code.
- */
-static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
-{
-	ddf_fun_t *hc_fun = dev_to_uhci(ddf_fun_get_dev(fun))->hc_fun;
-	assert(hc_fun);
-
-	if (handle != NULL)
-		*handle = ddf_fun_get_handle(hc_fun);
-	return EOK;
-}
-
-/** USB interface implementation used by RH */
-static usb_iface_t usb_iface = {
-	.get_hc_handle = usb_iface_get_hc_handle,
-};
-
-/** Get root hub hw resources (I/O registers).
- *
- * @param[in] fun Root hub function.
- * @return Pointer to the resource list used by the root hub.
- */
-static hw_resource_list_t *get_resource_list(ddf_fun_t *fun)
-{
-	rh_t *rh = ddf_fun_data_get(fun);
-	assert(rh);
-	return &rh->resource_list;
-}
-
-/** Interface to provide the root hub driver with hw info */
-static hw_res_ops_t hw_res_iface = {
-	.get_resource_list = get_resource_list,
-	.enable_interrupt = NULL,
-};
-
-static pio_window_t *get_pio_window(ddf_fun_t *fun)
-{
-	rh_t *rh = ddf_fun_data_get(fun);
-	
-	if (rh == NULL)
-		return NULL;
-	return &rh->pio_window;
-}
-
-static pio_window_ops_t pio_window_iface = {
-	.get_pio_window = get_pio_window
-};
-
-/** RH function support for uhci_rhd */
-static ddf_dev_ops_t rh_ops = {
-	.interfaces[USB_DEV_IFACE] = &usb_iface,
-	.interfaces[HW_RES_DEV_IFACE] = &hw_res_iface,
-	.interfaces[PIO_WINDOW_DEV_IFACE] = &pio_window_iface
-};
-
-/** Initialize hc and rh DDF structures and their respective drivers.
- *
- * @param[in] device DDF instance of the device to use.
- *
- * This function does all the preparatory work for hc and rh drivers:
- *  - gets device's hw resources
- *  - disables UHCI legacy support (PCI config space)
- *  - attempts to enable interrupts
- *  - registers interrupt handler
- */
-int device_setup_uhci(ddf_dev_t *device)
-{
-	bool ih_registered = false;
-	bool hc_inited = false;
-	bool fun_bound = false;
-	int rc;
-
-	if (!device)
-		return EBADMEM;
-
-	uhci_t *instance = ddf_dev_data_alloc(device, sizeof(uhci_t));
-	if (instance == NULL) {
-		usb_log_error("Failed to allocate OHCI driver.\n");
-		return ENOMEM;
-	}
-
-	instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci_hc");
-	if (instance->hc_fun == NULL) {
-		usb_log_error("Failed to create UHCI HC function.\n");
-		rc = ENOMEM;
-		goto error;
-	}
-
-	ddf_fun_set_ops(instance->hc_fun, &hc_ops);
-
-	instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci_rh");
-	if (instance->rh_fun == NULL) {
-		usb_log_error("Failed to create UHCI RH function.\n");
-		rc = ENOMEM;
-		goto error;
-	}
-
-	ddf_fun_set_ops(instance->rh_fun, &rh_ops);
-	instance->rh = ddf_fun_data_alloc(instance->rh_fun, sizeof(rh_t));
-
-	addr_range_t regs;
-	int irq = 0;
-
-	rc = get_my_registers(device, &regs, &irq);
-	if (rc != EOK) {
-		usb_log_error("Failed to get I/O addresses for %" PRIun ": %s.\n",
-		    ddf_dev_get_handle(device), str_error(rc));
-		goto error;
-	}
-	usb_log_debug("I/O regs at %p (size %zu), IRQ %d.\n",
-	    RNGABSPTR(regs), RNGSZ(regs), irq);
-
-	rc = disable_legacy(device);
-	if (rc != EOK) {
-		usb_log_error("Failed to disable legacy USB: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	rc = hc_register_irq_handler(device, &regs, irq, irq_handler);
-	if (rc != EOK) {
-		usb_log_error("Failed to register interrupt handler: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	ih_registered = true;
-
-	bool interrupts = false;
-	rc = enable_interrupts(device);
-	if (rc != EOK) {
-		usb_log_warning("Failed to enable interrupts: %s."
-		    " Falling back to polling.\n", str_error(rc));
-	} else {
-		usb_log_debug("Hw interrupts enabled.\n");
-		interrupts = true;
-	}
-
-	rc = hc_init(&instance->hc, instance->hc_fun, &regs, interrupts);
-	if (rc != EOK) {
-		usb_log_error("Failed to init uhci_hcd: %s.\n", str_error(rc));
-		goto error;
-	}
-
-	hc_inited = true;
-
-	rc = ddf_fun_bind(instance->hc_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to bind UHCI device function: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	fun_bound = true;
-
-	rc = ddf_fun_add_to_category(instance->hc_fun, USB_HC_CATEGORY);
-	if (rc != EOK) {
-		usb_log_error("Failed to add UHCI to HC class: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	rc = rh_init(instance->rh, instance->rh_fun, &regs, 0x10, 4);
-	if (rc != EOK) {
-		usb_log_error("Failed to setup UHCI root hub: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	rc = ddf_fun_bind(instance->rh_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to register UHCI root hub: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	return EOK;
-
-error:
-	if (fun_bound)
-		ddf_fun_unbind(instance->hc_fun);
-	if (hc_inited)
-		hc_fini(&instance->hc);
-	if (ih_registered)
-		unregister_interrupt_handler(device, irq);
-	if (instance->hc_fun != NULL)
-		ddf_fun_destroy(instance->hc_fun);
-	if (instance->rh_fun != NULL) {
-		ddf_fun_destroy(instance->rh_fun);
-	}
-	return rc;
-}
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhci/uhci.h
===================================================================
--- uspace/drv/bus/usb/uhci/uhci.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,43 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbuhci
- * @{
- */
-/** @file
- * @brief UHCI driver main structure for both host controller and root-hub.
- */
-#ifndef DRV_UHCI_UHCI_H
-#define DRV_UHCI_UHCI_H
-#include <ddf/driver.h>
-
-int device_setup_uhci(ddf_dev_t *device);
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhci/uhci_batch.c
===================================================================
--- uspace/drv/bus/usb/uhci/uhci_batch.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/uhci/uhci_batch.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -32,13 +32,16 @@
  * @brief UHCI driver USB transfer structure
  */
+
+#include <assert.h>
 #include <errno.h>
-#include <str_error.h>
 #include <macros.h>
+#include <mem.h>
+#include <stdlib.h>
 
 #include <usb/usb.h>
 #include <usb/debug.h>
+#include <usb/host/endpoint.h>
 
 #include "uhci_batch.h"
-#include "transfer_list.h"
 #include "hw_struct/transfer_descriptor.h"
 #include "utils/malloc32.h"
@@ -67,4 +70,5 @@
 	assert(uhci_batch);
 	assert(uhci_batch->usb_batch);
+	assert(!link_in_use(&uhci_batch->link));
 	usb_transfer_batch_finish(uhci_batch->usb_batch,
 	    uhci_transfer_batch_data_buffer(uhci_batch));
Index: uspace/drv/bus/usb/uhci/uhci_batch.h
===================================================================
--- uspace/drv/bus/usb/uhci/uhci_batch.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/uhci/uhci_batch.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -35,6 +35,10 @@
 #define DRV_UHCI_BATCH_H
 
+#include <adt/list.h>
+#include <assert.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <sys/types.h>
 #include <usb/host/usb_transfer_batch.h>
-#include <adt/list.h>
 
 #include "hw_struct/queue_head.h"
Index: uspace/drv/bus/usb/uhci/uhci_rh.c
===================================================================
--- uspace/drv/bus/usb/uhci/uhci_rh.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/uhci/uhci_rh.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,495 @@
+/*
+ * Copyright (c) 2013 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 <ddi.h>
+#include <errno.h>
+#include <macros.h>
+#include <mem.h>
+#include <sys/time.h>
+
+#include <usb/debug.h>
+#include <usb/descriptor.h>
+#include <usb/classes/hub.h>
+#include <usb/request.h>
+#include <usb/usb.h>
+
+#include "uhci_rh.h"
+
+enum {
+	UHCI_RH_PORT_COUNT = 2,
+	UHCI_PORT_BYTES = STATUS_BYTES(UHCI_RH_PORT_COUNT),
+};
+
+/** Hub descriptor. */
+static const struct {
+	/** Common hub descriptor header */
+	usb_hub_descriptor_header_t header;
+	/** Port removable status bits */
+	uint8_t removable[UHCI_PORT_BYTES];
+	/** Port powered status bits */
+	uint8_t powered[UHCI_PORT_BYTES];
+} __attribute__((packed)) hub_descriptor = {
+	.header = {
+		.length = sizeof(hub_descriptor),
+		.descriptor_type = USB_DESCTYPE_HUB,
+		.port_count = UHCI_RH_PORT_COUNT,
+		.characteristics =
+		    HUB_CHAR_NO_POWER_SWITCH_FLAG | HUB_CHAR_NO_OC_FLAG,
+		.power_good_time = 50,
+		.max_current = 0,
+	},
+	.removable = { 0 },
+	.powered = { 0xFF },
+};
+
+static usbvirt_device_ops_t ops;
+
+/** Initialize uhci rh structure.
+ * @param instance Memory place to initialize.
+ * @param ports Pointer to TWO UHCI RH port registers.
+ * @param name device name, passed to virthub init
+ * @return Error code, EOK on success.
+ */
+int uhci_rh_init(uhci_rh_t *instance, ioport16_t *ports, const char *name)
+{
+	assert(instance);
+	instance->ports[0] = ports;
+	instance->ports[1] = ports + 1;
+	instance->reset_changed[0] = false;
+	instance->reset_changed[1] = false;
+	return virthub_base_init(&instance->base, name, &ops, instance,
+	    NULL, &hub_descriptor.header, HUB_STATUS_CHANGE_PIPE);
+}
+
+/** Schedule USB batch for the root hub.
+ *
+ * @param instance UHCI rh instance
+ * @param batch USB communication batch
+ * @return EOK.
+ *
+ * The result of scheduling is always EOK. The result of communication does
+ * not have to be.
+ */
+int uhci_rh_schedule(uhci_rh_t *instance, usb_transfer_batch_t *batch)
+{
+	assert(instance);
+	assert(batch);
+
+	const usb_target_t target = {{
+		.address = batch->ep->address,
+		.endpoint = batch->ep->endpoint
+	}};
+	batch->error = virthub_base_request(&instance->base, target,
+	    usb_transfer_batch_direction(batch), (void*)batch->setup_buffer,
+	    batch->buffer, batch->buffer_size, &batch->transfered_size);
+	usb_transfer_batch_finish(batch, NULL);
+	usb_transfer_batch_destroy(batch);
+	return EOK;
+}
+
+/** UHCI port register bits */
+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),
+
+	STATUS_CHANGE_BITS = STATUS_CONNECTED_CHANGED | STATUS_ENABLED_CHANGED,
+	STATUS_WC_BITS = STATUS_CHANGE_BITS,
+};
+
+/* HUB ROUTINES IMPLEMENTATION */
+
+static void uhci_port_reset_enable(ioport16_t *port)
+{
+	assert(port);
+	uint16_t port_status = pio_read_16(port);
+	/* We don't wan to remove changes, that's hub drivers work */
+	port_status &= ~STATUS_WC_BITS;
+	port_status |= STATUS_IN_RESET;
+	pio_write_16(port, port_status);
+	async_usleep(50000);
+	port_status = pio_read_16(port);
+	port_status &= ~STATUS_IN_RESET;
+	pio_write_16(port, port_status);
+	while ((port_status = pio_read_16(port)) & STATUS_IN_RESET);
+	/* PIO delay, should not be longer than 3ms as the device might
+	 * enter suspend state. */
+	udelay(10);
+	/* Drop ConnectionChange as some UHCI hw
+	 * sets this bit after reset, that is incorrect */
+	port_status &= ~STATUS_WC_BITS;
+	pio_write_16(port, port_status | STATUS_ENABLED | STATUS_CONNECTED_CHANGED);
+}
+#define TEST_SIZE_INIT(size, port, hub) \
+do { \
+	if (uint16_usb2host(setup_packet->length) != size) \
+		return ESTALL; \
+	port = uint16_usb2host(setup_packet->index) - 1; \
+	if (port != 0 && port != 1) \
+		return EINVAL; \
+	hub = virthub_get_data(device); \
+	assert(hub);\
+} while (0)
+
+#define RH_DEBUG(d, port, msg, ...) \
+	if ((int)port >= 0) \
+		usb_log_debug("%s: rh-%d: " msg, d->name, port, ##__VA_ARGS__); \
+	else \
+		usb_log_debug("%s: rh: " msg, d->name, ##__VA_ARGS__) \
+
+/** USB HUB port state request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ *
+ * Do not confuse with port status. Port state reports data line states,
+ * it is usefull for debuging purposes only.
+ */
+static int req_get_port_state(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	uhci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(1, port, hub);
+	if (setup_packet->value != 0)
+		return EINVAL;
+
+	const uint16_t value = pio_read_16(hub->ports[port]);
+	data[0] = ((value & STATUS_LINE_D_MINUS) ? 1 : 0)
+	    | ((value & STATUS_LINE_D_PLUS) ? 2 : 0);
+	RH_DEBUG(device, port, "Bus state %" PRIx8 "(source %" PRIx16")\n",
+	    data[0], value);
+	*act_size = 1;
+	return EOK;
+}
+
+#define BIT_VAL(val, bit) \
+	((val & bit) ? 1 : 0)
+#define UHCI2USB(val, bit, feat) \
+	(BIT_VAL(val, bit) << feat)
+
+/** Port status request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ *
+ * Converts status reported via ioport to USB format.
+ * @note: reset change status needs to be handled in sw.
+ */
+static int req_get_port_status(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	uhci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(4, port, hub);
+	if (setup_packet->value != 0)
+		return EINVAL;
+
+	const uint16_t val = pio_read_16(hub->ports[port]);
+	const uint32_t status = uint32_host2usb(
+	    UHCI2USB(val, STATUS_CONNECTED, USB_HUB_FEATURE_PORT_CONNECTION) |
+	    UHCI2USB(val, STATUS_ENABLED, USB_HUB_FEATURE_PORT_ENABLE) |
+	    UHCI2USB(val, STATUS_SUSPEND, USB_HUB_FEATURE_PORT_SUSPEND) |
+	    UHCI2USB(val, STATUS_IN_RESET, USB_HUB_FEATURE_PORT_RESET) |
+	    UHCI2USB(val, STATUS_ALWAYS_ONE, USB_HUB_FEATURE_PORT_POWER) |
+	    UHCI2USB(val, STATUS_LOW_SPEED, USB_HUB_FEATURE_PORT_LOW_SPEED) |
+	    UHCI2USB(val, STATUS_CONNECTED_CHANGED, USB_HUB_FEATURE_C_PORT_CONNECTION) |
+	    UHCI2USB(val, STATUS_ENABLED_CHANGED, USB_HUB_FEATURE_C_PORT_ENABLE) |
+//	    UHCI2USB(val, STATUS_SUSPEND, USB_HUB_FEATURE_C_PORT_SUSPEND) |
+	    ((hub->reset_changed[port] ? 1 : 0) << USB_HUB_FEATURE_C_PORT_RESET)
+	);
+	RH_DEBUG(device, port, "Port status %" PRIx32 " (source %" PRIx16
+	    "%s)\n", uint32_usb2host(status), val,
+	    hub->reset_changed[port] ? "-reset" : "");
+	memcpy(data, &status, sizeof(status));
+	*act_size = sizeof(status);;
+	return EOK;
+}
+
+/** Port clear feature request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_clear_port_feature(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	uhci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(0, port, hub);
+	const unsigned feature = uint16_usb2host(setup_packet->value);
+	const uint16_t status = pio_read_16(hub->ports[port]);
+	const uint16_t val = status & (~STATUS_WC_BITS);
+	switch (feature) {
+	case USB_HUB_FEATURE_PORT_ENABLE:
+		RH_DEBUG(device, port, "Clear port enable (status %"
+		    PRIx16 ")\n", status);
+		pio_write_16(hub->ports[port], val & ~STATUS_ENABLED);
+		break;
+	case USB_HUB_FEATURE_PORT_SUSPEND:
+		RH_DEBUG(device, port, "Clear port suspend (status %"
+		    PRIx16 ")\n", status);
+		pio_write_16(hub->ports[port], val & ~STATUS_SUSPEND);
+		// TODO we should do resume magic
+		usb_log_warning("Resume is not implemented on port %u\n", port);
+		break;
+	case USB_HUB_FEATURE_PORT_POWER:
+		RH_DEBUG(device, port, "Clear port power (status %" PRIx16 ")\n",
+		    status);
+		/* We are always powered */
+		usb_log_warning("Tried to power off port %u\n", port);
+		break;
+	case USB_HUB_FEATURE_C_PORT_CONNECTION:
+		RH_DEBUG(device, port, "Clear port conn change (status %"
+		    PRIx16 ")\n", status);
+		pio_write_16(hub->ports[port], val | STATUS_CONNECTED_CHANGED);
+		break;
+	case USB_HUB_FEATURE_C_PORT_RESET:
+		RH_DEBUG(device, port, "Clear port reset change (status %"
+		    PRIx16 ")\n", status);
+		hub->reset_changed[port] = false;
+		break;
+	case USB_HUB_FEATURE_C_PORT_ENABLE:
+		RH_DEBUG(device, port, "Clear port enable change (status %"
+		    PRIx16 ")\n", status);
+		pio_write_16(hub->ports[port], status | STATUS_ENABLED_CHANGED);
+		break;
+	case USB_HUB_FEATURE_C_PORT_SUSPEND:
+		RH_DEBUG(device, port, "Clear port suspend change (status %"
+		    PRIx16 ")\n", status);
+		//TODO
+		return ENOTSUP;
+	case USB_HUB_FEATURE_C_PORT_OVER_CURRENT:
+		RH_DEBUG(device, port, "Clear port OC change (status %"
+		    PRIx16 ")\n", status);
+		/* UHCI Does not report over current */
+		//TODO: newer chips do, but some have broken wiring 
+		break;
+	default:
+		RH_DEBUG(device, port, "Clear unknown feature %d (status %"
+		    PRIx16 ")\n", feature, status);
+		usb_log_warning("Clearing feature %d is unsupported\n",
+		    feature);
+		return ESTALL;
+	}
+	return EOK;
+}
+
+/** Port set feature request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_set_port_feature(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	uhci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(0, port, hub);
+	const unsigned feature = uint16_usb2host(setup_packet->value);
+	const uint16_t status = pio_read_16(hub->ports[port]);
+	switch (feature) {
+	case USB_HUB_FEATURE_PORT_RESET:
+		RH_DEBUG(device, port, "Set port reset before (status %" PRIx16
+		    ")\n", status);
+		uhci_port_reset_enable(hub->ports[port]);
+		hub->reset_changed[port] = true;
+		RH_DEBUG(device, port, "Set port reset after (status %" PRIx16
+		    ")\n", pio_read_16(hub->ports[port]));
+		break;
+	case USB_HUB_FEATURE_PORT_SUSPEND:
+		RH_DEBUG(device, port, "Set port suspend (status %" PRIx16
+		    ")\n", status);
+		pio_write_16(hub->ports[port],
+		    (status & ~STATUS_WC_BITS) | STATUS_SUSPEND);
+		usb_log_warning("Suspend is not implemented on port %u\n", port);
+		break;
+	case USB_HUB_FEATURE_PORT_POWER:
+		RH_DEBUG(device, port, "Set port power (status %" PRIx16
+		    ")\n", status);
+		/* We are always powered */
+		usb_log_warning("Tried to power port %u\n", port);
+		break;
+	case USB_HUB_FEATURE_C_PORT_CONNECTION:
+	case USB_HUB_FEATURE_C_PORT_ENABLE:
+	case USB_HUB_FEATURE_C_PORT_SUSPEND:
+	case USB_HUB_FEATURE_C_PORT_OVER_CURRENT:
+		RH_DEBUG(device, port, "Set port change flag (status %" PRIx16
+		    ")\n", status);
+		/* These are voluntary and don't have to be set
+		 * there is no way we could do it on UHCI anyway */
+		break;
+	default:
+		RH_DEBUG(device, port, "Set unknown feature %d (status %" PRIx16
+		    ")\n", feature, status);
+		usb_log_warning("Setting feature %d is unsupported\n",
+		    feature);
+		return ESTALL;
+	}
+	return EOK;
+}
+
+/** Status change handler.
+ * @param device Virtual hub device
+ * @param endpoint Endpoint number
+ * @param tr_type Transfer type
+ * @param buffer Response destination
+ * @param buffer_size Bytes available in buffer
+ * @param actual_size Size us the used part of the dest buffer.
+ *
+ * Produces status mask. Bit 0 indicates hub status change the other bits
+ * represent port status change. Endian does not matter as UHCI root hubs
+ * only need 1 byte.
+ */
+static int req_status_change_handler(usbvirt_device_t *device,
+    usb_endpoint_t endpoint, usb_transfer_type_t tr_type,
+    void *buffer, size_t buffer_size, size_t *actual_size)
+{
+	uhci_rh_t *hub = virthub_get_data(device);
+	assert(hub);
+
+	if (buffer_size < 1)
+		return ESTALL;
+
+	const uint16_t status_a = pio_read_16(hub->ports[0]);
+	const uint16_t status_b = pio_read_16(hub->ports[1]);
+	const uint8_t status =
+	    ((((status_a & STATUS_CHANGE_BITS) != 0) || hub->reset_changed[0]) ?
+	        0x2 : 0) |
+	    ((((status_b & STATUS_CHANGE_BITS) != 0) || hub->reset_changed[1]) ?
+	        0x4 : 0);
+
+	RH_DEBUG(device, -1, "Event mask %" PRIx8
+	    " (status_a %" PRIx16 "%s),"
+	    " (status_b %" PRIx16 "%s)\n", status,
+	    status_a, hub->reset_changed[0] ? "-reset" : "",
+	    status_b, hub->reset_changed[1] ? "-reset" : "" );
+	((uint8_t *)buffer)[0] = status;
+	*actual_size = 1;
+	return EOK;
+}
+
+/** UHCI root hub request handlers */
+static const usbvirt_control_request_handler_t control_transfer_handlers[] = {
+	{
+		STD_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		.name = "GetDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		.name = "GetDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_DESCRIPTOR),
+		.name = "GetHubDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATE),
+		.name = "GetBusState",
+		.callback = req_get_port_state,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetPortStatus",
+		.callback = req_get_port_status
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_CLEAR_FEATURE),
+		.name = "ClearHubFeature",
+		/* Hub features are overcurrent and supply good,
+		 * this request may only clear changes that we never report*/
+		.callback = req_nop,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_CLEAR_FEATURE),
+		.name = "ClearPortFeature",
+		.callback = req_clear_port_feature
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetHubStatus",
+		/* UHCI can't report OC condition or,
+		 * lose power source */
+		.callback = virthub_base_get_null_status,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetPortStatus",
+		.callback = req_get_port_status
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_SET_FEATURE),
+		.name = "SetHubFeature",
+		/* Hub features are overcurrent and supply good,
+		 * this request may only set changes that we never report*/
+		.callback = req_nop,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_SET_FEATURE),
+		.name = "SetPortFeature",
+		.callback = req_set_port_feature
+	},
+	{
+		.callback = NULL
+	}
+};
+
+static usbvirt_device_ops_t ops = {
+        .control = control_transfer_handlers,
+        .data_in[HUB_STATUS_CHANGE_PIPE] = req_status_change_handler,
+};
Index: uspace/drv/bus/usb/uhci/uhci_rh.h
===================================================================
--- uspace/drv/bus/usb/uhci/uhci_rh.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
+++ uspace/drv/bus/usb/uhci/uhci_rh.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2013 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 drvusbuhci
+ * @{
+ */
+/** @file
+ * @brief UHCI host controller driver structure
+ */
+#ifndef DRV_UHCI_UHCI_RH_H
+#define DRV_UHCI_UHCI_RH_H
+
+#include <usbvirt/virthub_base.h>
+#include <usb/host/usb_transfer_batch.h>
+#include <usb/usb.h>
+
+#include <stdbool.h>
+#include <sys/types.h>
+
+/** Endpoint number for status change pipe. */
+#define HUB_STATUS_CHANGE_PIPE   1
+
+/** Virtual to UHCI hub connector */
+typedef struct {
+	/** Virtual hub software implementation */
+	virthub_base_t base;
+	/** UHCI root hub port io registers */
+	ioport16_t *ports[2];
+	/** Reset change indicator, it is not reported by regs */
+	bool reset_changed[2];
+} uhci_rh_t;
+
+int uhci_rh_init(uhci_rh_t *instance, ioport16_t *ports, const char *name);
+int uhci_rh_schedule(uhci_rh_t *instance, usb_transfer_batch_t *batch);
+
+/** Get UHCI rh address.
+ *
+ * @param instance UHCI rh instance.
+ * @return USB address assigned to the hub.
+ * Wrapper for virtual hub address
+ */
+static inline usb_address_t uhci_rh_get_address(uhci_rh_t *instance)
+{
+	return virthub_base_get_address(&instance->base);
+}
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/uhci/utils/malloc32.h
===================================================================
--- uspace/drv/bus/usb/uhci/utils/malloc32.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/uhci/utils/malloc32.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -36,12 +36,10 @@
 
 #include <as.h>
-#include <assert.h>
 #include <ddi.h>
 #include <errno.h>
 #include <malloc.h>
-#include <mem.h>
-#include <unistd.h>
+#include <sys/types.h>
 
-#define UHCI_STRCUTURES_ALIGNMENT 16
+#define UHCI_STRUCTURES_ALIGNMENT 16
 #define UHCI_REQUIRED_PAGE_SIZE 4096
 
@@ -56,10 +54,10 @@
 	if (addr == NULL)
 		return 0;
-	
+
 	uintptr_t result;
 	const int ret = as_get_physical_mapping(addr, &result);
 	if (ret != EOK)
 		return 0;
-	
+
 	return result;
 }
@@ -81,5 +79,5 @@
 	/* Calculate alignment to make sure the block won't cross page
 	 * boundary */
-	size_t alignment = UHCI_STRCUTURES_ALIGNMENT;
+	size_t alignment = UHCI_STRUCTURES_ALIGNMENT;
 	while (alignment < size)
 		alignment *= 2;
@@ -104,9 +102,9 @@
 	uintptr_t phys;
 	void *address = AS_AREA_ANY;
-	
+
 	const int ret = dmamem_map_anonymous(UHCI_REQUIRED_PAGE_SIZE,
 	    DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
 	    &address);
-	
+
 	return ((ret == EOK) ? address : NULL);
 }
Index: uspace/drv/bus/usb/uhcirh/Makefile
===================================================================
--- uspace/drv/bus/usb/uhcirh/Makefile	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,48 +1,0 @@
-#
-# 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.
-#
-
-USPACE_PREFIX = ../../../..
-
-LIBS = \
-	$(LIBUSBDEV_PREFIX)/libusbdev.a \
-	$(LIBUSB_PREFIX)/libusb.a \
-	$(LIBDRV_PREFIX)/libdrv.a
-
-EXTRA_CFLAGS += \
-	-I$(LIBUSB_PREFIX)/include \
-	-I$(LIBUSBDEV_PREFIX)/include \
-	-I$(LIBDRV_PREFIX)/include
-
-BINARY = uhcirh
-
-SOURCES = \
-	main.c \
-	port.c \
-	root_hub.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: uspace/drv/bus/usb/uhcirh/main.c
===================================================================
--- uspace/drv/bus/usb/uhcirh/main.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,160 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbuhcirh
- * @{
- */
-/** @file
- * @brief UHCI root hub initialization routines
- */
-
-#include <ddf/driver.h>
-#include <devman.h>
-#include <device/hw_res_parsed.h>
-#include <errno.h>
-#include <str_error.h>
-
-#include <usb_iface.h>
-#include <usb/ddfiface.h>
-#include <usb/debug.h>
-
-#include "root_hub.h"
-
-#define NAME "uhcirh"
-
-static int hc_get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs);
-
-static int uhci_rh_dev_add(ddf_dev_t *device);
-
-static driver_ops_t uhci_rh_driver_ops = {
-	.dev_add = uhci_rh_dev_add,
-};
-
-static driver_t uhci_rh_driver = {
-	.name = NAME,
-	.driver_ops = &uhci_rh_driver_ops
-};
-
-/** Initialize global driver structures (NONE).
- *
- * @param[in] argc Nmber of arguments in argv vector (ignored).
- * @param[in] argv Cmdline argument vector (ignored).
- * @return Error code.
- *
- * Driver debug level is set here.
- */
-int main(int argc, char *argv[])
-{
-	printf(NAME ": HelenOS UHCI root hub driver.\n");
-	log_init(NAME);
-	return ddf_driver_main(&uhci_rh_driver);
-}
-
-/** Initialize a new ddf driver instance of UHCI root hub.
- *
- * @param[in] device DDF instance of the device to initialize.
- * @return Error code.
- */
-static int uhci_rh_dev_add(ddf_dev_t *device)
-{
-	if (!device)
-		return EINVAL;
-
-	usb_log_debug2("uhci_rh_dev_add(handle=%" PRIun ")\n",
-	    ddf_dev_get_handle(device));
-
-	addr_range_t regs;
-	uhci_root_hub_t *rh = NULL;
-	int rc;
-
-	rc = hc_get_my_registers(device, &regs);
-	if (rc != EOK) {
-		usb_log_error( "Failed to get registers from HC: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-
-	usb_log_debug("I/O regs at %p (size %zuB).\n",
-	    RNGABSPTR(regs), RNGSZ(regs));
-
-	rh = ddf_dev_data_alloc(device, sizeof(uhci_root_hub_t));
-	if (rh == NULL) {
-		usb_log_error("Failed to allocate rh driver instance.\n");
-		return ENOMEM;
-	}
-
-	rc = uhci_root_hub_init(rh, &regs, device);
-	if (rc != EOK) {
-		usb_log_error("Failed(%d) to initialize rh driver instance: "
-		    "%s.\n", rc, str_error(rc));
-		return rc;
-	}
-
-	usb_log_info("Controlling root hub '%s' (%" PRIun ").\n",
-	    ddf_dev_get_name(device), ddf_dev_get_handle(device));
-
-	return EOK;
-}
-
-/** Get address of I/O registers.
- *
- * @param[in] dev Device asking for the addresses.
- * @param[out] io_regs_p Pointer to the device's register range.
- * @return Error code.
- */
-int hc_get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs_p)
-{
-	async_sess_t *parent_sess =
-	    devman_parent_device_connect(EXCHANGE_SERIALIZE,
-	    ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);
-	if (!parent_sess)
-		return ENOMEM;
-
-	hw_res_list_parsed_t hw_res;
-	hw_res_list_parsed_init(&hw_res);
-	const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
-	async_hangup(parent_sess);
-	if (ret != EOK) {
-		return ret;
-	}
-
-	if (hw_res.io_ranges.count != 1) {
-		hw_res_list_parsed_clean(&hw_res);
-		return EINVAL;
-	}
-
-	if (io_regs_p != NULL)
-		*io_regs_p = hw_res.io_ranges.ranges[0];
-
-	hw_res_list_parsed_clean(&hw_res);
-	return EOK;
-}
-
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhcirh/port.c
===================================================================
--- uspace/drv/bus/usb/uhcirh/port.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,406 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbuhcirh
- * @{
- */
-/** @file
- * @brief UHCI root hub port routines
- */
-#include <ddi.h>
-#include <fibril_synch.h> /* async_usleep */
-#include <errno.h>
-#include <str_error.h>
-#include <async.h>
-
-#include <usb/usb.h>    /* usb_address_t */
-#include <usb/debug.h>
-
-#include "port.h"
-
-#define MAX_ERROR_COUNT 5
-
-static int uhci_port_check(void *port);
-static int uhci_port_reset_enable(void *arg);
-static int uhci_port_new_device(uhci_port_t *port, usb_speed_t speed);
-static int uhci_port_remove_device(uhci_port_t *port);
-static int uhci_port_set_enabled(uhci_port_t *port, bool enabled);
-static void uhci_port_print_status(
-    uhci_port_t *port, const port_status_t value);
-
-/** Register reading helper function.
- *
- * @param[in] port Structure to use.
- * @return Error code. (Always EOK)
- */
-static inline port_status_t uhci_port_read_status(uhci_port_t *port)
-{
-	assert(port);
-	return pio_read_16(port->address);
-}
-
-/** Register writing helper function.
- *
- * @param[in] port Structure to use.
- * @param[in] val New register value.
- * @return Error code. (Always EOK)
- */
-static inline void uhci_port_write_status(uhci_port_t *port, port_status_t val)
-{
-	assert(port);
-	pio_write_16(port->address, val);
-}
-
-/** Initialize UHCI root hub port instance.
- *
- * @param[in] port Memory structure to use.
- * @param[in] address Address of I/O register.
- * @param[in] number Port number.
- * @param[in] usec Polling interval.
- * @param[in] rh Pointer to ddf instance of the root hub driver.
- * @return Error code.
- *
- * Creates and starts the polling fibril.
- */
-int uhci_port_init(uhci_port_t *port,
-    port_status_t *address, unsigned number, unsigned usec, ddf_dev_t *rh)
-{
-	assert(port);
-	char *id_string;
-	asprintf(&id_string, "Port (%p - %u)", port, number);
-	if (id_string == NULL) {
-		return ENOMEM;
-	}
-
-	port->id_string = id_string;
-	port->address = address;
-	port->number = number;
-	port->wait_period_usec = usec;
-	port->attached_device.fun = NULL;
-	port->attached_device.address = -1;
-	port->rh = rh;
-
-	int ret =
-	    usb_hc_connection_initialize_from_device(&port->hc_connection, rh);
-	if (ret != EOK) {
-		usb_log_error("%s: failed to initialize connection to HC.",
-		    port->id_string);
-		free(id_string);
-		return ret;
-	}
-
-	port->checker = fibril_create(uhci_port_check, port);
-	if (port->checker == 0) {
-		usb_log_error("%s: failed to create polling fibril.",
-		    port->id_string);
-		free(id_string);
-		return ENOMEM;
-	}
-
-	fibril_add_ready(port->checker);
-	usb_log_debug("%s: Started polling fibril (%" PRIun ").\n",
-	    port->id_string, port->checker);
-	return EOK;
-}
-
-/** Cleanup UHCI root hub port instance.
- *
- * @param[in] port Memory structure to use.
- *
- * Stops the polling fibril.
- */
-void uhci_port_fini(uhci_port_t *port)
-{
-	assert(port);
-	free(port->id_string);
-	// TODO: Kill fibril here
-	return;
-}
-
-/** Periodically checks port status and reports new devices.
- *
- * @param[in] port Port structure to use.
- * @return Error code.
- */
-int uhci_port_check(void *port)
-{
-	uhci_port_t *instance = port;
-	int rc;
-	assert(instance);
-
-	unsigned allowed_failures = MAX_ERROR_COUNT;
-
-	while (1) {
-		async_usleep(instance->wait_period_usec);
-
-		/* Read register value */
-		const port_status_t port_status =
-		    uhci_port_read_status(instance);
-
-		/* Print the value if it's interesting */
-		if (port_status & ~STATUS_ALWAYS_ONE)
-			uhci_port_print_status(instance, port_status);
-
-		if ((port_status & STATUS_CONNECTED_CHANGED) == 0)
-			continue;
-
-		usb_log_debug("%s: Connected change detected: %x.\n",
-		    instance->id_string, port_status);
-
-		rc = usb_hc_connection_open(&instance->hc_connection);
-		if (rc != EOK) {
-			usb_log_error("%s: Failed to connect to HC %s.\n",
-			    instance->id_string, str_error(rc));
-			if (!(allowed_failures-- > 0))
-				goto fatal_error;
-			continue;
-		}
-
-		/* Remove any old device */
-		if (instance->attached_device.fun) {
-			uhci_port_remove_device(instance);
-		}
-
-		if ((port_status & STATUS_CONNECTED) != 0) {
-			/* New device, this will take care of WC bits */
-			const usb_speed_t speed =
-			    ((port_status & STATUS_LOW_SPEED) != 0) ?
-			    USB_SPEED_LOW : USB_SPEED_FULL;
-			uhci_port_new_device(instance, speed);
-		} else {
-			/* Write one to WC bits, to ack changes */
-			uhci_port_write_status(instance, port_status);
-			usb_log_debug("%s: status change ACK.\n",
-			    instance->id_string);
-		}
-
-		rc = usb_hc_connection_close(&instance->hc_connection);
-		if (rc != EOK) {
-			usb_log_error("%s: Failed to disconnect from HC %s.\n",
-			    instance->id_string, str_error(rc));
-			if (!(allowed_failures-- > 0))
-				goto fatal_error;
-			continue;
-		}
-	}
-
-	return EOK;
-
-fatal_error:
-	usb_log_fatal("Maximum number of failures reached, bailing out.\n");
-	return rc;
-}
-
-/** Callback for enabling port during adding a new device.
- *
- * @param portno Port number (unused).
- * @param arg Pointer to uhci_port_t of port with the new device.
- * @return Error code.
- *
- * Resets and enables the ub port.
- */
-int uhci_port_reset_enable(void *arg)
-{
-	uhci_port_t *port = arg;
-	assert(port);
-
-	usb_log_debug2("%s: new_device_enable_port.\n", port->id_string);
-
-	/*
-	 * Resets from root ports should be nominally 50ms (USB spec 7.1.7.3)
-	 */
-	{
-		usb_log_debug("%s: Reset Signal start.\n", port->id_string);
-		port_status_t port_status = uhci_port_read_status(port);
-		port_status |= STATUS_IN_RESET;
-		uhci_port_write_status(port, port_status);
-		async_usleep(50000);
-		port_status = uhci_port_read_status(port);
-		port_status &= ~STATUS_IN_RESET;
-		uhci_port_write_status(port, port_status);
-		while (uhci_port_read_status(port) & STATUS_IN_RESET);
-	}
-	/* PIO delay, should not be longer than 3ms as the device might
-	 * enter suspend state. */
-	udelay(10);
-	/* Enable the port. */
-	uhci_port_set_enabled(port, true);
-	return EOK;
-}
-
-/** Initialize and report connected device.
- *
- * @param[in] port Port structure to use.
- * @param[in] speed Detected speed.
- * @return Error code.
- *
- * Uses libUSB function to do the actual work.
- */
-int uhci_port_new_device(uhci_port_t *port, usb_speed_t speed)
-{
-	assert(port);
-
-	usb_log_debug("%s: Detected new device.\n", port->id_string);
-
-	int ret, count = MAX_ERROR_COUNT;
-	do {
-		port->attached_device.fun = ddf_fun_create(port->rh, fun_inner,
-		    NULL);
-		if (port->attached_device.fun == NULL) {
-			ret = ENOMEM;
-			continue;
-		}
-
-		ret = usb_hc_new_device_wrapper(port->rh,
-		    port->attached_device.fun,
-		    &port->hc_connection,
-		    speed, uhci_port_reset_enable, port,
-		    &port->attached_device.address, NULL);
-
-		if (ret != EOK) {
-			ddf_fun_destroy(port->attached_device.fun);
-			port->attached_device.fun = NULL;
-		}
-
-	} while (ret != EOK && count-- > 0);
-
-	if (ret != EOK) {
-		usb_log_error("%s: Failed(%d) to add device: %s.\n",
-		    port->id_string, ret, str_error(ret));
-		uhci_port_set_enabled(port, false);
-		return ret;
-	}
-
-	usb_log_info("%s: New device, address %d (handle %" PRIun ").\n",
-	    port->id_string, port->attached_device.address,
-	    ddf_fun_get_handle(port->attached_device.fun));
-	return EOK;
-}
-
-/** Remove device.
- *
- * @param[in] port Port instance to use.
- * @return Error code.
- */
-int uhci_port_remove_device(uhci_port_t *port)
-{
-	assert(port);
-	/* There is nothing to remove. */
-	if (port->attached_device.fun == NULL) {
-		usb_log_warning("%s: Removed a ghost device.\n",
-		    port->id_string);
-		assert(port->attached_device.address == -1);
-		return EOK;
-	}
-
-	usb_log_debug("%s: Removing device.\n", port->id_string);
-
-	/* Stop driver first */
-	int ret = ddf_fun_unbind(port->attached_device.fun);
-	if (ret != EOK) {
-		usb_log_error("%s: Failed to remove child function: %s.\n",
-		   port->id_string, str_error(ret));
-		return ret;
-	}
-	ddf_fun_destroy(port->attached_device.fun);
-	port->attached_device.fun = NULL;
-
-	/* Driver stopped, free used address */
-	ret = usb_hub_unregister_device(&port->hc_connection,
-	    &port->attached_device);
-	if (ret != EOK) {
-		usb_log_error("%s: Failed to unregister address of removed "
-		    "device: %s.\n", port->id_string, str_error(ret));
-		return ret;
-	}
-	port->attached_device.address = -1;
-
-	usb_log_info("%s: Removed attached device.\n", port->id_string);
-	return EOK;
-}
-
-/** Enable or disable root hub port.
- *
- * @param[in] port Port structure to use.
- * @param[in] enabled Port status to set.
- * @return Error code. (Always EOK)
- */
-int uhci_port_set_enabled(uhci_port_t *port, bool enabled)
-{
-	assert(port);
-
-	/* Read register value */
-	port_status_t port_status = uhci_port_read_status(port);
-
-	/* Set enabled bit */
-	if (enabled) {
-		port_status |= STATUS_ENABLED;
-	} else {
-		port_status &= ~STATUS_ENABLED;
-	}
-
-	/* Write new value. */
-	uhci_port_write_status(port, port_status);
-
-	/* Wait for port to become enabled */
-	do {
-		port_status = uhci_port_read_status(port);
-	} while ((port_status & STATUS_CONNECTED) &&
-	    !(port_status & STATUS_ENABLED));
-
-	usb_log_debug("%s: %sabled port.\n",
-		port->id_string, enabled ? "En" : "Dis");
-	return EOK;
-}
-
-/** Print the port status value in a human friendly way
- *
- * @param[in] port Port structure to use.
- * @param[in] value Port register value to print.
- * @return Error code. (Always EOK)
- */
-void uhci_port_print_status(uhci_port_t *port, const port_status_t value)
-{
-	assert(port);
-	usb_log_debug2("%s Port status(%#x):%s%s%s%s%s%s%s%s%s%s%s.\n",
-	    port->id_string, value,
-	    (value & STATUS_SUSPEND) ? " SUSPENDED," : "",
-	    (value & STATUS_RESUME) ? " IN RESUME," : "",
-	    (value & STATUS_IN_RESET) ? " IN RESET," : "",
-	    (value & STATUS_LINE_D_MINUS) ? " VD-," : "",
-	    (value & STATUS_LINE_D_PLUS) ? " VD+," : "",
-	    (value & STATUS_LOW_SPEED) ? " LOWSPEED," : "",
-	    (value & STATUS_ENABLED_CHANGED) ? " ENABLED-CHANGE," : "",
-	    (value & STATUS_ENABLED) ? " ENABLED," : "",
-	    (value & STATUS_CONNECTED_CHANGED) ? " CONNECTED-CHANGE," : "",
-	    (value & STATUS_CONNECTED) ? " CONNECTED," : "",
-	    (value & STATUS_ALWAYS_ONE) ? " ALWAYS ONE" : " ERR: NO ALWAYS ONE"
-	);
-}
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhcirh/port.h
===================================================================
--- uspace/drv/bus/usb/uhcirh/port.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,78 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbuhcirh
- * @{
- */
-/** @file
- * @brief UHCI root hub port routines
- */
-#ifndef DRV_UHCI_PORT_H
-#define DRV_UHCI_PORT_H
-
-#include <stdint.h>
-#include <fibril.h>
-#include <ddf/driver.h>
-#include <usb/hc.h> /* usb_hc_connection_t */
-#include <usb/dev/hub.h>
-
-typedef uint16_t port_status_t;
-#define STATUS_CONNECTED         (1 << 0)
-#define STATUS_CONNECTED_CHANGED (1 << 1)
-#define STATUS_ENABLED           (1 << 2)
-#define STATUS_ENABLED_CHANGED   (1 << 3)
-#define STATUS_LINE_D_PLUS       (1 << 4)
-#define STATUS_LINE_D_MINUS      (1 << 5)
-#define STATUS_RESUME            (1 << 6)
-#define STATUS_ALWAYS_ONE        (1 << 7)
-
-#define STATUS_LOW_SPEED (1 <<  8)
-#define STATUS_IN_RESET  (1 <<  9)
-#define STATUS_SUSPEND   (1 << 12)
-
-/** UHCI port structure */
-typedef struct uhci_port {
-	const char *id_string;
-	port_status_t *address;
-	unsigned number;
-	unsigned wait_period_usec;
-	usb_hc_connection_t hc_connection;
-	ddf_dev_t *rh;
-	usb_hub_attached_device_t attached_device;
-	fid_t checker;
-} uhci_port_t;
-
-int uhci_port_init(
-    uhci_port_t *port, port_status_t *address, unsigned number,
-    unsigned usec, ddf_dev_t *rh);
-
-void uhci_port_fini(uhci_port_t *port);
-
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhcirh/root_hub.c
===================================================================
--- uspace/drv/bus/usb/uhcirh/root_hub.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,99 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbuhcirh
- * @{
- */
-/** @file
- * @brief UHCI root hub driver
- */
-#include <errno.h>
-#include <str_error.h>
-#include <ddi.h>
-#include <usb/debug.h>
-#include <device/hw_res_parsed.h>
-
-#include "root_hub.h"
-
-/** Initialize UHCI root hub instance.
- *
- * @param[in] instance Driver memory structure to use.
- * @param[in] io_regs Range of I/O registers.
- * @param[in] rh Pointer to DDF instance of the root hub driver.
- * @return Error code.
- */
-int uhci_root_hub_init(uhci_root_hub_t *instance, addr_range_t *io_regs,
-    ddf_dev_t *rh)
-{
-	port_status_t *regs;
-
-	assert(instance);
-	assert(rh);
-
-	/* Allow access to root hub port registers */
-	assert(sizeof(*regs) * UHCI_ROOT_HUB_PORT_COUNT <= io_regs->size);
-
-	int ret = pio_enable_range(io_regs, (void **) &regs);
-	if (ret < 0) {
-		usb_log_error(
-		    "Failed(%d) to gain access to port registers at %p: %s.\n",
-		    ret, RNGABSPTR(*io_regs), str_error(ret));
-		return ret;
-	}
-
-	/* Initialize root hub ports */
-	unsigned i = 0;
-	for (; i < UHCI_ROOT_HUB_PORT_COUNT; ++i) {
-		ret = uhci_port_init(
-		    &instance->ports[i], &regs[i], i, ROOT_HUB_WAIT_USEC, rh);
-		if (ret != EOK) {
-			unsigned j = 0;
-			for (;j < i; ++j)
-				uhci_port_fini(&instance->ports[j]);
-			return ret;
-		}
-	}
-
-	return EOK;
-}
-
-/** Cleanup UHCI root hub instance.
- *
- * @param[in] instance Root hub structure to use.
- */
-void uhci_root_hub_fini(uhci_root_hub_t* instance)
-{
-	assert(instance);
-	unsigned i = 0;
-	for (; i < UHCI_ROOT_HUB_PORT_COUNT; ++i) {
-		uhci_port_fini(&instance->ports[i]);
-	}
-}
-
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhcirh/root_hub.h
===================================================================
--- uspace/drv/bus/usb/uhcirh/root_hub.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,58 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbuhcirh
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#ifndef DRV_UHCI_ROOT_HUB_H
-#define DRV_UHCI_ROOT_HUB_H
-
-#include <ddf/driver.h>
-#include <device/hw_res_parsed.h>
-
-#include "port.h"
-
-#define UHCI_ROOT_HUB_PORT_COUNT 2
-#define ROOT_HUB_WAIT_USEC 250000 /* 250 miliseconds */
-
-/** UHCI root hub drvier structure */
-typedef struct root_hub {
-	/** Ports provided by the hub */
-	uhci_port_t ports[UHCI_ROOT_HUB_PORT_COUNT];
-} uhci_root_hub_t;
-
-int uhci_root_hub_init(uhci_root_hub_t *instance, addr_range_t *regs,
-    ddf_dev_t *rh);
-
-void uhci_root_hub_fini(uhci_root_hub_t *instance);
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhcirh/uhcirh.ma
===================================================================
--- uspace/drv/bus/usb/uhcirh/uhcirh.ma	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,1 +1,0 @@
-10 usb&uhci&root-hub
Index: uspace/drv/bus/usb/usbflbk/main.c
===================================================================
--- uspace/drv/bus/usb/usbflbk/main.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbflbk/main.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -48,27 +48,7 @@
 static int usbfallback_device_add(usb_device_t *dev)
 {
-	int rc;
-	const char *fun_name = "ctl";
-
-	ddf_fun_t *ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed,
-	    fun_name);
-	if (ctl_fun == NULL) {
-		usb_log_error("Failed to create control function.\n");
-		return ENOMEM;
-	}
-	rc = ddf_fun_bind(ctl_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to bind control function: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-
-	dev->driver_data = ctl_fun;
-
-	usb_log_info("Pretending to control %s `%s'" \
-	    " (node `%s', handle %" PRIun ").\n",
-	    dev->interface_no < 0 ? "device" : "interface",
-	    ddf_dev_get_name(dev->ddf_dev), fun_name, ddf_dev_get_handle(dev->ddf_dev));
-
+	usb_log_info("Pretending to control %s `%s'.\n",
+	    usb_device_get_iface_number(dev) < 0 ? "device" : "interface",
+	    usb_device_get_name(dev));
 	return EOK;
 }
@@ -82,13 +62,4 @@
 {
 	assert(dev);
-	ddf_fun_t *ctl_fun = dev->driver_data;
-	const int ret = ddf_fun_unbind(ctl_fun);
-	if (ret != EOK) {
-		usb_log_error("Failed to unbind %s.\n", ddf_fun_get_name(ctl_fun));
-		return ret;
-	}
-	ddf_fun_destroy(ctl_fun);
-	dev->driver_data = NULL;
-
 	return EOK;
 }
Index: uspace/drv/bus/usb/usbhid/blink1/blink1.c
===================================================================
--- uspace/drv/bus/usb/usbhid/blink1/blink1.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhid/blink1/blink1.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -35,4 +35,5 @@
  */
 
+#include <errno.h>
 #include <str_error.h>
 #include <usb/debug.h>
@@ -78,7 +79,8 @@
 	report.arg5 = 0;
 	
-	return usbhid_req_set_report(&blink1_dev->hid_dev->usb_dev->ctrl_pipe,
-	    blink1_dev->hid_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_FEATURE,
-	    (uint8_t *) &report, sizeof(report));
+	return usbhid_req_set_report(
+	    usb_device_get_default_pipe(blink1_dev->hid_dev->usb_dev),
+	    usb_device_get_iface_number(blink1_dev->hid_dev->usb_dev),
+	    USB_HID_REPORT_TYPE_FEATURE, (uint8_t *) &report, sizeof(report));
 }
 
@@ -100,6 +102,6 @@
 	
 	/* Create the exposed function. */
-	ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
-	    HID_BLINK1_FUN_NAME);
+	ddf_fun_t *fun = usb_device_ddf_fun_create(hid_dev->usb_dev,
+	    fun_exposed, HID_BLINK1_FUN_NAME);
 	if (fun == NULL) {
 		usb_log_error("Could not create DDF function node `%s'.\n",
Index: uspace/drv/bus/usb/usbhid/generic/hiddev.c
===================================================================
--- uspace/drv/bus/usb/usbhid/generic/hiddev.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhid/generic/hiddev.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -190,6 +190,6 @@
 	/* Create the exposed function. */
 	usb_log_debug("Creating DDF function %s...\n", HID_GENERIC_FUN_NAME);
-	ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 
-	    HID_GENERIC_FUN_NAME);
+	ddf_fun_t *fun = usb_device_ddf_fun_create(hid_dev->usb_dev,
+	    fun_exposed, HID_GENERIC_FUN_NAME);
 	if (fun == NULL) {
 		usb_log_error("Could not create DDF function node.\n");
Index: uspace/drv/bus/usb/usbhid/kbd/kbddev.c
===================================================================
--- uspace/drv/bus/usb/usbhid/kbd/kbddev.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhid/kbd/kbddev.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -100,5 +100,5 @@
 
 const char *HID_KBD_FUN_NAME = "keyboard";
-const char *HID_KBD_CATEGORY = "keyboard";
+const char *HID_KBD_CATEGORY_NAME = "keyboard";
 
 static void usb_kbd_set_led(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev);
@@ -261,6 +261,6 @@
 
 	if (rc != EOK) {
-		usb_log_warning("Error translating LED output to output report"
-		    ".\n");
+		usb_log_warning("Could not translate LED output to output"
+		    "report.\n");
 		return;
 	}
@@ -270,6 +270,8 @@
 	        0));
 
-	rc = usbhid_req_set_report(&hid_dev->usb_dev->ctrl_pipe,
-	    hid_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT,
+	rc = usbhid_req_set_report(
+	    usb_device_get_default_pipe(hid_dev->usb_dev),
+	    usb_device_get_iface_number(hid_dev->usb_dev),
+	    USB_HID_REPORT_TYPE_OUTPUT,
 	    kbd_dev->output_buffer, kbd_dev->output_size);
 	if (rc != EOK) {
@@ -476,66 +478,10 @@
 }
 
-/* API functions                                                              */
-
-/**
- * Initialization of the USB/HID keyboard structure.
- *
- * This functions initializes required structures from the device's descriptors.
- *
- * During initialization, the keyboard is switched into boot protocol, the idle
- * rate is set to 0 (infinity), resulting in the keyboard only reporting event
- * when a key is pressed or released. Finally, the LED lights are turned on 
- * according to the default setup of lock keys.
- *
- * @note By default, the keyboards is initialized with Num Lock turned on and 
- *       other locks turned off.
- *
- * @param kbd_dev Keyboard device structure to be initialized.
- * @param dev DDF device structure of the keyboard.
- *
- * @retval EOK if successful.
- * @retval EINVAL if some parameter is not given.
- * @return Other value inherited from function usbhid_dev_init().
- */
-int usb_kbd_init(usb_hid_dev_t *hid_dev, void **data)
-{
-	ddf_fun_t *fun = NULL;
-	usb_kbd_t *kbd_dev = NULL;
-	usb_hid_report_path_t *path = NULL;
-	bool bound = false;
-	fid_t fid = 0;
-	int rc;
-
-	usb_log_debug("Initializing HID/KBD structure...\n");
-
-	if (hid_dev == NULL) {
-		usb_log_error(
-		    "Failed to init keyboard structure: no structure given.\n");
-		rc = EINVAL;
-		goto error;
-	}
-
-	/* Create the exposed function. */
-	usb_log_debug("Creating DDF function %s...\n", HID_KBD_FUN_NAME);
-	fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
-	    HID_KBD_FUN_NAME);
-	if (fun == NULL) {
-		usb_log_error("Could not create DDF function node.\n");
-		rc = ENOMEM;
-		goto error;
-	}
-
-	/* Store the initialized HID device and HID ops
-	 * to the DDF function. */
-	ddf_fun_set_ops(fun, &kbdops);
-
-	kbd_dev = ddf_fun_data_alloc(fun, sizeof(usb_kbd_t));
-	if (kbd_dev == NULL) {
-		usb_log_error("Failed to allocate KBD device structure.\n");
-		rc = ENOMEM;
-		goto error;
-	}
-
-	kbd_dev->fun = fun;
+/* HID/KBD structure manipulation                                             */
+
+static int kbd_dev_init(usb_kbd_t *kbd_dev, usb_hid_dev_t *hid_dev)
+{
+	assert(kbd_dev);
+	assert(hid_dev);
 
 	/* Default values */
@@ -554,15 +500,18 @@
 
 	// TODO: make more general
-	path = usb_hid_report_path();
+	usb_hid_report_path_t *path = usb_hid_report_path();
 	if (path == NULL) {
 		usb_log_error("Failed to create kbd report path.\n");
-		rc = ENOMEM;
-		goto error;
-	}
-
-	rc = usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
-	if (rc != EOK) {
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
+
+	int ret =
+	    usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
+	if (ret != EOK) {
 		usb_log_error("Failed to append item to kbd report path.\n");
-		goto error;
+		usb_hid_report_path_free(path);
+		usb_kbd_destroy(kbd_dev);
+		return ret;
 	}
 
@@ -573,5 +522,4 @@
 
 	usb_hid_report_path_free(path);
-	path = NULL;
 
 	usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
@@ -580,6 +528,6 @@
 	if (kbd_dev->keys == NULL) {
 		usb_log_error("Failed to allocate key buffer.\n");
-		rc = ENOMEM;
-		goto error;
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
 	}
 
@@ -587,6 +535,6 @@
 	if (kbd_dev->keys_old == NULL) {
 		usb_log_error("Failed to allocate old_key buffer.\n");
-		rc = ENOMEM;
-		goto error;
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
 	}
 
@@ -597,6 +545,6 @@
 	if (kbd_dev->output_buffer == NULL) {
 		usb_log_error("Error creating output report buffer.\n");
-		rc = ENOMEM;
-		goto error;
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
 	}
 
@@ -606,13 +554,14 @@
 	if (kbd_dev->led_path == NULL) {
 		usb_log_error("Failed to create kbd led report path.\n");
-		rc = ENOMEM;
-		goto error;
-	}
-
-	rc = usb_hid_report_path_append_item(
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
+
+	ret = usb_hid_report_path_append_item(
 	    kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
-	if (rc != EOK) {
+	if (ret != EOK) {
 		usb_log_error("Failed to append to kbd/led report path.\n");
-		goto error;
+		usb_kbd_destroy(kbd_dev);
+		return ret;
 	}
 
@@ -626,6 +575,6 @@
 	if (kbd_dev->led_data == NULL) {
 		usb_log_error("Error creating buffer for LED output report.\n");
-		rc = ENOMEM;
-		goto error;
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
 	}
 
@@ -634,65 +583,117 @@
 	usb_kbd_set_led(hid_dev, kbd_dev);
 
-	usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
-	    hid_dev->usb_dev->interface_no, IDLE_RATE);
+	usbhid_req_set_idle(usb_device_get_default_pipe(hid_dev->usb_dev),
+	    usb_device_get_iface_number(hid_dev->usb_dev), IDLE_RATE);
+
+
+	kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED;
+	usb_log_debug("HID/KBD device structure initialized.\n");
+
+	return EOK;
+}
+
+
+/* API functions                                                              */
+
+/**
+ * Initialization of the USB/HID keyboard structure.
+ *
+ * This functions initializes required structures from the device's descriptors.
+ *
+ * During initialization, the keyboard is switched into boot protocol, the idle
+ * rate is set to 0 (infinity), resulting in the keyboard only reporting event
+ * when a key is pressed or released. Finally, the LED lights are turned on
+ * according to the default setup of lock keys.
+ *
+ * @note By default, the keyboards is initialized with Num Lock turned on and
+ *       other locks turned off.
+ *
+ * @param kbd_dev Keyboard device structure to be initialized.
+ * @param dev DDF device structure of the keyboard.
+ *
+ * @retval EOK if successful.
+ * @retval EINVAL if some parameter is not given.
+ * @return Other value inherited from function usbhid_dev_init().
+ */
+int usb_kbd_init(usb_hid_dev_t *hid_dev, void **data)
+{
+	usb_log_debug("Initializing HID/KBD structure...\n");
+
+	if (hid_dev == NULL) {
+		usb_log_error(
+		    "Failed to init keyboard structure: no structure given.\n");
+		return EINVAL;
+	}
+
+	/* Create the exposed function. */
+	usb_log_debug("Creating DDF function %s...\n", HID_KBD_FUN_NAME);
+	ddf_fun_t *fun = usb_device_ddf_fun_create(hid_dev->usb_dev,
+	    fun_exposed, HID_KBD_FUN_NAME);
+	if (fun == NULL) {
+		usb_log_error("Could not create DDF function node.\n");
+		return ENOMEM;
+	}
+
+	usb_kbd_t *kbd_dev = ddf_fun_data_alloc(fun, sizeof(usb_kbd_t));
+	if (kbd_dev == NULL) {
+		usb_log_error("Failed to allocate KBD device structure.\n");
+		ddf_fun_destroy(fun);
+		return ENOMEM;
+	}
+
+	int ret = kbd_dev_init(kbd_dev, hid_dev);
+	if (ret != EOK) {
+		usb_log_error("Failed to initialize KBD device  structure.\n");
+		ddf_fun_destroy(fun);
+		return ret;
+	}
+
+	/* Store the initialized HID device and HID ops
+	 * to the DDF function. */
+	ddf_fun_set_ops(fun, &kbdops);
+
+	ret = ddf_fun_bind(fun);
+	if (ret != EOK) {
+		usb_log_error("Could not bind DDF function: %s.\n",
+		    str_error(ret));
+		usb_kbd_destroy(kbd_dev);
+		ddf_fun_destroy(fun);
+		return ret;
+	}
+
+	usb_log_debug("%s function created. Handle: %" PRIun "\n",
+	    HID_KBD_FUN_NAME, ddf_fun_get_handle(fun));
+
+	usb_log_debug("Adding DDF function to category %s...\n",
+	    HID_KBD_CATEGORY_NAME);
+	ret = ddf_fun_add_to_category(fun, HID_KBD_CATEGORY_NAME);
+	if (ret != EOK) {
+		usb_log_error(
+		    "Could not add DDF function to category %s: %s.\n",
+		    HID_KBD_CATEGORY_NAME, str_error(ret));
+		usb_kbd_destroy(kbd_dev);
+		if (ddf_fun_unbind(fun) == EOK) {
+			ddf_fun_destroy(fun);
+		} else {
+			usb_log_error(
+			    "Failed to unbind `%s', will not destroy.\n",
+			    ddf_fun_get_name(fun));
+		}
+		return ret;
+	}
 
 	/* Create new fibril for auto-repeat. */
-	fid = fibril_create(usb_kbd_repeat_fibril, kbd_dev);
+	fid_t fid = fibril_create(usb_kbd_repeat_fibril, kbd_dev);
 	if (fid == 0) {
 		usb_log_error("Failed to start fibril for KBD auto-repeat");
-		rc = ENOMEM;
-		goto error;
-	}
-
-	kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED;
-	usb_log_debug("HID/KBD device structure initialized.\n");
-
-	rc = ddf_fun_bind(fun);
-	if (rc != EOK) {
-		usb_log_error("Could not bind DDF function: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	bound = true;
-
-	usb_log_debug("%s function created. Handle: %" PRIun "\n",
-	    HID_KBD_FUN_NAME, ddf_fun_get_handle(fun));
-
-	usb_log_debug("Adding DDF function to category %s...\n",
-	    HID_KBD_CATEGORY);
-	rc = ddf_fun_add_to_category(fun, HID_KBD_CATEGORY);
-	if (rc != EOK) {
-		usb_log_error(
-		    "Could not add DDF function to category %s: %s.\n",
-		    HID_KBD_CATEGORY, str_error(rc));
-		goto error;
-	}
-
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
 	fibril_add_ready(fid);
-
+	kbd_dev->fun = fun;
 	/* Save the KBD device structure into the HID device structure. */
 	*data = kbd_dev;
 
 	return EOK;
-error:
-	if (bound)
-		ddf_fun_unbind(fun);
-	if (fid != 0)
-		fibril_destroy(fid);
-	if (kbd_dev != NULL) {
-		free(kbd_dev->led_data);
-		if (kbd_dev->led_path != NULL)
-			usb_hid_report_path_free(kbd_dev->led_path);
-		if (kbd_dev->output_buffer != NULL)
-			usb_hid_report_output_free(kbd_dev->output_buffer);
-		free(kbd_dev->keys_old);
-		free(kbd_dev->keys);
-	}
-	if (path != NULL)
-		usb_hid_report_path_free(path);
-	if (fun != NULL)
-		ddf_fun_destroy(fun);
-	return rc;
 }
 
@@ -749,6 +750,14 @@
 	usb_hid_report_output_free(kbd_dev->output_buffer);
 
-	ddf_fun_unbind(kbd_dev->fun);
-	ddf_fun_destroy(kbd_dev->fun);
+	if (kbd_dev->fun) {
+		if (ddf_fun_unbind(kbd_dev->fun) != EOK) {
+			usb_log_warning("Failed to unbind %s.\n",
+			    ddf_fun_get_name(kbd_dev->fun));
+		} else {
+			usb_log_debug2("%s unbound.\n",
+			    ddf_fun_get_name(kbd_dev->fun));
+			ddf_fun_destroy(kbd_dev->fun);
+		}
+	}
 }
 
@@ -779,6 +788,8 @@
 	}
 
-	rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe,
-	    hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
+	rc = usbhid_req_set_protocol(
+	    usb_device_get_default_pipe(hid_dev->usb_dev),
+	    usb_device_get_iface_number(hid_dev->usb_dev),
+	    USB_HID_PROTOCOL_BOOT);
 
 	if (rc != EOK) {
Index: uspace/drv/bus/usb/usbhid/main.c
===================================================================
--- uspace/drv/bus/usb/usbhid/main.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhid/main.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -65,5 +65,5 @@
 	}
 
-	if (dev->interface_no < 0) {
+	if (usb_device_get_iface_number(dev) < 0) {
 		usb_log_error("Failed to add HID device: endpoints not found."
 		    "\n");
@@ -89,11 +89,13 @@
 	 * This will create a separate fibril that will query the device
 	 * for the data continuously. */
-       rc = usb_device_auto_poll(dev,
+	rc = usb_device_auto_poll_desc(dev,
 	   /* Index of the polling pipe. */
-	   hid_dev->poll_pipe_index,
+	   hid_dev->poll_pipe_mapping->description,
 	   /* Callback when data arrives. */
 	   usb_hid_polling_callback,
 	   /* How much data to request. */
-	   dev->pipes[hid_dev->poll_pipe_index].pipe.max_packet_size,
+	   hid_dev->poll_pipe_mapping->pipe.max_packet_size,
+	   /* Delay */
+	   -1,
 	   /* Callback when the polling ends. */
 	   usb_hid_polling_ended_callback,
@@ -103,5 +105,5 @@
 	if (rc != EOK) {
 		usb_log_error("Failed to start polling fibril for `%s'.\n",
-		    ddf_dev_get_name(dev->ddf_dev));
+		    usb_device_get_name(dev));
 		usb_hid_deinit(hid_dev);
 		return rc;
@@ -109,6 +111,5 @@
 	hid_dev->running = true;
 
-	usb_log_info("HID device `%s' ready to use.\n",
-	    ddf_dev_get_name(dev->ddf_dev));
+	usb_log_info("HID device `%s' ready.\n", usb_device_get_name(dev));
 
 	return EOK;
@@ -137,6 +138,6 @@
 {
 	assert(dev);
-	assert(dev->driver_data);
-	usb_hid_dev_t *hid_dev = dev->driver_data;
+	usb_hid_dev_t *hid_dev = usb_device_data_get(dev);
+	assert(hid_dev);
 	unsigned tries = 100;
 	/* Wait for fail. */
@@ -150,5 +151,5 @@
 
 	usb_hid_deinit(hid_dev);
-	usb_log_debug2("%s destruction complete.\n", ddf_dev_get_name(dev->ddf_dev));
+	usb_log_debug2("%s destruction complete.\n", usb_device_get_name(dev));
 	return EOK;
 }
Index: uspace/drv/bus/usb/usbhid/mouse/mousedev.c
===================================================================
--- uspace/drv/bus/usb/usbhid/mouse/mousedev.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhid/mouse/mousedev.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -246,4 +246,14 @@
 }
 
+#define FUN_UNBIND_DESTROY(fun) \
+if (fun) { \
+	if (ddf_fun_unbind((fun)) == EOK) { \
+		ddf_fun_destroy((fun)); \
+	} else { \
+		usb_log_error("Could not unbind function `%s', it " \
+		    "will not be destroyed.\n", ddf_fun_get_name(fun)); \
+	} \
+} else (void)0
+
 /** Get highest index of a button mentioned in given report.
  *
@@ -286,41 +296,6 @@
 }
 
-int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data)
-{
-	ddf_fun_t *fun = NULL;
-	usb_mouse_t *mouse_dev = NULL;
-	bool bound = false;
-	int rc;
-
-	usb_log_debug("Initializing HID/Mouse structure...\n");
-
-	if (hid_dev == NULL) {
-		usb_log_error("Failed to init mouse structure: no structure"
-		    " given.\n");
-		rc = EINVAL;
-		goto error;
-	}
-
-	/* Create the exposed function. */
-	usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
-	fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
-	    HID_MOUSE_FUN_NAME);
-	if (fun == NULL) {
-		usb_log_error("Could not create DDF function node `%s'.\n",
-		    HID_MOUSE_FUN_NAME);
-		rc = ENOMEM;
-		goto error;
-	}
-
-	ddf_fun_set_ops(fun, &ops);
-
-	mouse_dev = ddf_fun_data_alloc(fun, sizeof(usb_mouse_t));
-	if (mouse_dev == NULL) {
-		usb_log_error("Error while creating USB/HID Mouse device "
-		    "structure.\n");
-		rc = ENOMEM;
-		goto error;
-	}
-
+static int mouse_dev_init(usb_mouse_t *mouse_dev, usb_hid_dev_t *hid_dev)
+{
 	// FIXME: This may not be optimal since stupid hardware vendor may
 	// use buttons 1, 2, 3 and 6000 and we would allocate array of
@@ -335,43 +310,73 @@
 	if (mouse_dev->buttons == NULL) {
 		usb_log_error(NAME ": out of memory, giving up on device!\n");
-		rc = ENOMEM;
-		goto error;
+		free(mouse_dev);
+		return ENOMEM;
 	}
 
 	// TODO: how to know if the device supports the request???
-	usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
-	    hid_dev->usb_dev->interface_no, IDLE_RATE);
-
-	rc = ddf_fun_bind(fun);
-	if (rc != EOK) {
+	usbhid_req_set_idle(usb_device_get_default_pipe(hid_dev->usb_dev),
+	    usb_device_get_iface_number(hid_dev->usb_dev), IDLE_RATE);
+	return EOK;
+}
+
+int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data)
+{
+	usb_log_debug("Initializing HID/Mouse structure...\n");
+
+	if (hid_dev == NULL) {
+		usb_log_error("Failed to init keyboard structure: no structure"
+		    " given.\n");
+		return EINVAL;
+	}
+
+	/* Create the exposed function. */
+	usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
+	ddf_fun_t *fun = usb_device_ddf_fun_create(hid_dev->usb_dev,
+	    fun_exposed, HID_MOUSE_FUN_NAME);
+	if (fun == NULL) {
+		usb_log_error("Could not create DDF function node `%s'.\n",
+		    HID_MOUSE_FUN_NAME);
+		return ENOMEM;
+	}
+
+	usb_mouse_t *mouse_dev = ddf_fun_data_alloc(fun, sizeof(usb_mouse_t));
+	if (mouse_dev == NULL) {
+		usb_log_error("Failed to alloc HID mouse device structure.\n");
+		ddf_fun_destroy(fun);
+		return ENOMEM;
+	}
+
+	int ret = mouse_dev_init(mouse_dev, hid_dev);
+	if (ret != EOK) {
+		usb_log_error("Failed to init HID mouse device structure.\n");
+		return ret;
+	}
+
+	ddf_fun_set_ops(fun, &ops);
+
+	ret = ddf_fun_bind(fun);
+	if (ret != EOK) {
 		usb_log_error("Could not bind DDF function `%s': %s.\n",
-		    ddf_fun_get_name(fun), str_error(rc));
-		goto error;
-	}
-
-	bound = true;
+		    ddf_fun_get_name(fun), str_error(ret));
+		ddf_fun_destroy(fun);
+		return ret;
+	}
 
 	usb_log_debug("Adding DDF function `%s' to category %s...\n",
 	    ddf_fun_get_name(fun), HID_MOUSE_CATEGORY);
-	rc = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY);
-	if (rc != EOK) {
-		usb_log_error("Could not add DDF function to category %s: "
-		    "%s.\n", HID_MOUSE_CATEGORY, str_error(rc));
-		goto error;
-	}
-
+	ret = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY);
+	if (ret != EOK) {
+		usb_log_error(
+		    "Could not add DDF function to category %s: %s.\n",
+		    HID_MOUSE_CATEGORY, str_error(ret));
+		FUN_UNBIND_DESTROY(fun);
+		return ret;
+	}
 	mouse_dev->mouse_fun = fun;
 
 	/* Save the Mouse device structure into the HID device structure. */
 	*data = mouse_dev;
+
 	return EOK;
-error:
-	if (bound)
-		ddf_fun_unbind(fun);
-	if (mouse_dev != NULL)
-		free(mouse_dev->buttons);
-	if (fun != NULL)
-		ddf_fun_destroy(fun);
-	return rc;
 }
 
@@ -404,7 +409,6 @@
 	}
 
-	ddf_fun_unbind(mouse_dev->mouse_fun);
 	free(mouse_dev->buttons);
-	ddf_fun_destroy(mouse_dev->mouse_fun);
+	FUN_UNBIND_DESTROY(mouse_dev->mouse_fun);
 }
 
@@ -421,6 +425,8 @@
 	}
 
-	rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe,
-	    hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
+	rc = usbhid_req_set_protocol(
+	    usb_device_get_default_pipe(hid_dev->usb_dev),
+	    usb_device_get_iface_number(hid_dev->usb_dev),
+	    USB_HID_PROTOCOL_BOOT);
 
 	if (rc != EOK) {
Index: uspace/drv/bus/usb/usbhid/multimedia/multimedia.c
===================================================================
--- uspace/drv/bus/usb/usbhid/multimedia/multimedia.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhid/multimedia/multimedia.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -162,6 +162,6 @@
 
 	/* Create the exposed function. */
-	ddf_fun_t *fun = ddf_fun_create(
-	    hid_dev->usb_dev->ddf_dev, fun_exposed, NAME);
+	ddf_fun_t *fun = usb_device_ddf_fun_create(
+	    hid_dev->usb_dev, fun_exposed, NAME);
 	if (fun == NULL) {
 		usb_log_error("Could not create DDF function node.\n");
Index: uspace/drv/bus/usb/usbhid/usbhid.c
===================================================================
--- uspace/drv/bus/usb/usbhid/usbhid.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhid/usbhid.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -41,5 +41,7 @@
 #include <usb/hid/hidreport.h>
 #include <usb/hid/request.h>
+
 #include <errno.h>
+#include <macros.h>
 #include <str_error.h>
 
@@ -114,11 +116,12 @@
     const usb_hid_subdriver_mapping_t *mapping)
 {
-	assert(hid_dev != NULL);
-	assert(hid_dev->usb_dev != NULL);
-
-	return (hid_dev->usb_dev->descriptors.device.vendor_id
-	    == mapping->vendor_id
-	    && hid_dev->usb_dev->descriptors.device.product_id
-	    == mapping->product_id);
+	assert(hid_dev);
+	assert(hid_dev->usb_dev);
+	assert(mapping);
+	const usb_standard_device_descriptor_t *d =
+	    &usb_device_descriptors(hid_dev->usb_dev)->device;
+
+	return (d->vendor_id == mapping->vendor_id)
+	    && (d->product_id == mapping->product_id);
 }
 
@@ -264,5 +267,5 @@
 }
 
-static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, const usb_device_t *dev)
+static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)
 {
 	assert(hid_dev);
@@ -270,19 +273,18 @@
 
 	static const struct {
-		unsigned ep_number;
+		const usb_endpoint_description_t *desc;
 		const char* description;
 	} endpoints[] = {
-		{USB_HID_KBD_POLL_EP_NO, "Keyboard endpoint"},
-		{USB_HID_MOUSE_POLL_EP_NO, "Mouse endpoint"},
-		{USB_HID_GENERIC_POLL_EP_NO, "Generic HID endpoint"},
+		{&usb_hid_kbd_poll_endpoint_description, "Keyboard endpoint"},
+		{&usb_hid_mouse_poll_endpoint_description, "Mouse endpoint"},
+		{&usb_hid_generic_poll_endpoint_description, "Generic HID endpoint"},
 	};
 
-	for (unsigned i = 0; i < sizeof(endpoints)/sizeof(endpoints[0]); ++i) {
-		if (endpoints[i].ep_number >= dev->pipes_count) {
-			return EINVAL;
-		}
-		if (dev->pipes[endpoints[i].ep_number].present) {
+	for (unsigned i = 0; i < ARRAY_SIZE(endpoints); ++i) {
+		usb_endpoint_mapping_t *epm =
+		    usb_device_get_mapped_ep_desc(dev, endpoints[i].desc);
+		if (epm && epm->present) {
 			usb_log_debug("Found: %s.\n", endpoints[i].description);
-			hid_dev->poll_pipe_index = endpoints[i].ep_number;
+			hid_dev->poll_pipe_mapping = epm;
 			return EOK;
 		}
@@ -351,5 +353,5 @@
 	/* The USB device should already be initialized, save it in structure */
 	hid_dev->usb_dev = dev;
-	hid_dev->poll_pipe_index = -1;
+	hid_dev->poll_pipe_mapping = NULL;
 
 	int rc = usb_hid_check_pipes(hid_dev, dev);
@@ -381,6 +383,6 @@
 		    "boot protocol.\n");
 
-		switch (hid_dev->poll_pipe_index) {
-		case USB_HID_KBD_POLL_EP_NO:
+		switch (hid_dev->poll_pipe_mapping->interface->interface_protocol) {
+		case USB_HID_PROTOCOL_KEYBOARD:
 			usb_log_info("Falling back to kbd boot protocol.\n");
 			rc = usb_kbd_set_boot_protocol(hid_dev);
@@ -389,5 +391,5 @@
 			}
 			break;
-		case USB_HID_MOUSE_POLL_EP_NO:
+		case USB_HID_PROTOCOL_MOUSE:
 			usb_log_info("Falling back to mouse boot protocol.\n");
 			rc = usb_mouse_set_boot_protocol(hid_dev);
@@ -397,6 +399,4 @@
 			break;
 		default:
-			assert(hid_dev->poll_pipe_index
-			    == USB_HID_GENERIC_POLL_EP_NO);
 			usb_log_info("Falling back to generic HID driver.\n");
 			usb_hid_set_generic_hid_subdriver(hid_dev);
@@ -476,5 +476,5 @@
 	    &hid_dev->report, buffer, buffer_size, &hid_dev->report_id);
 	if (rc != EOK) {
-		usb_log_warning("Error in usb_hid_parse_report():"
+		usb_log_warning("Failure in usb_hid_parse_report():"
 		    "%s\n", str_error(rc));
 	}
Index: uspace/drv/bus/usb/usbhid/usbhid.h
===================================================================
--- uspace/drv/bus/usb/usbhid/usbhid.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhid/usbhid.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -103,6 +103,6 @@
 	usb_device_t *usb_dev;
 
-	/** Index of the polling pipe in usb_hid_endpoints array. */
-	unsigned poll_pipe_index;
+	/** Endpont mapping of the polling pipe. */
+	usb_endpoint_mapping_t *poll_pipe_mapping;
 
 	/** Subdrivers. */
@@ -132,16 +132,5 @@
 };
 
-
-
-enum {
-	USB_HID_KBD_POLL_EP_NO = 0,
-	USB_HID_MOUSE_POLL_EP_NO = 1,
-	USB_HID_GENERIC_POLL_EP_NO = 2,
-	USB_HID_POLL_EP_COUNT = 3
-};
-
 extern const usb_endpoint_description_t *usb_hid_endpoints[];
-
-
 
 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev);
Index: uspace/drv/bus/usb/usbhub/main.c
===================================================================
--- uspace/drv/bus/usb/usbhub/main.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhub/main.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -43,17 +43,4 @@
 #include "usbhub.h"
 
-/** Hub status-change endpoint description.
- *
- * For more information see section 11.15.1 of USB 1.1 specification.
- */
-static const usb_endpoint_description_t hub_status_change_endpoint_description =
-{
-	.transfer_type = USB_TRANSFER_INTERRUPT,
-	.direction = USB_DIRECTION_IN,
-	.interface_class = USB_CLASS_HUB,
-	.interface_subclass = 0,
-	.interface_protocol = 0,
-	.flags = 0
-};
 
 /** USB hub driver operations. */
Index: uspace/drv/bus/usb/usbhub/port.c
===================================================================
--- uspace/drv/bus/usb/usbhub/port.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhub/port.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -41,5 +41,4 @@
 
 #include <usb/debug.h>
-#include <usb/dev/hub.h>
 
 #include "port.h"
@@ -58,5 +57,4 @@
     usb_port_status_t status);
 static int get_port_status(usb_hub_port_t *port, usb_port_status_t *status);
-static int enable_port_callback(void *arg);
 static int add_device_phase1_worker_fibril(void *arg);
 static int create_add_device_fibril(usb_hub_port_t *port, usb_hub_dev_t *hub,
@@ -66,5 +64,5 @@
 {
 	assert(port);
-	if (port->attached_device.fun)
+	if (port->device_attached)
 		return usb_hub_port_device_gone(port, hub);
 	return EOK;
@@ -141,10 +139,10 @@
 	assert(port);
 	assert(hub);
-	usb_log_debug("Interrupt at port %zu\n", port->port_number);
+	usb_log_debug("Interrupt at port %u\n", port->port_number);
 
 	usb_port_status_t status = 0;
 	const int opResult = get_port_status(port, &status);
 	if (opResult != EOK) {
-		usb_log_error("Failed to get port %zu status: %s.\n",
+		usb_log_error("Failed to get port %u status: %s.\n",
 		    port->port_number, str_error(opResult));
 		return;
@@ -155,5 +153,5 @@
 		const bool connected =
 		    (status & USB_HUB_PORT_STATUS_CONNECTION) != 0;
-		usb_log_debug("Connection change on port %zu: device %s.\n",
+		usb_log_debug("Connection change on port %u: device %s.\n",
 		    port->port_number, connected ? "attached" : "removed");
 
@@ -171,5 +169,5 @@
 			if (opResult != EOK) {
 				usb_log_error(
-				    "Cannot handle change on port %zu: %s.\n",
+				    "Cannot handle change on port %u: %s.\n",
 				    port->port_number, str_error(opResult));
 			}
@@ -185,5 +183,5 @@
 	/* Enable change, ports are automatically disabled on errors. */
 	if (status & USB_HUB_PORT_C_STATUS_ENABLED) {
-		usb_log_info("Port %zu, disabled because of errors.\n",
+		usb_log_info("Port %u, disabled because of errors.\n",
 		   port->port_number);
 		usb_hub_port_device_gone(port, hub);
@@ -192,5 +190,5 @@
 		if (rc != EOK) {
 			usb_log_error(
-			    "Failed to clear port %zu enable change feature: "
+			    "Failed to clear port %u enable change feature: "
 			    "%s.\n", port->port_number, str_error(rc));
 		}
@@ -200,5 +198,5 @@
 	/* Suspend change */
 	if (status & USB_HUB_PORT_C_STATUS_SUSPEND) {
-		usb_log_error("Port %zu went to suspend state, this should"
+		usb_log_error("Port %u went to suspend state, this should"
 		    "NOT happen as we do not support suspend state!",
 		    port->port_number);
@@ -207,5 +205,5 @@
 		if (rc != EOK) {
 			usb_log_error(
-			    "Failed to clear port %zu suspend change feature: "
+			    "Failed to clear port %u suspend change feature: "
 			    "%s.\n", port->port_number, str_error(rc));
 		}
@@ -223,5 +221,5 @@
 		if (rc != EOK) {
 			usb_log_error(
-			    "Failed to clear port %zu OC change feature: %s.\n",
+			    "Failed to clear port %u OC change feature: %s.\n",
 			    port->port_number, str_error(rc));
 		}
@@ -231,5 +229,5 @@
 			if (rc != EOK) {
 				usb_log_error(
-				    "Failed to set port %zu power after OC:"
+				    "Failed to set port %u power after OC:"
 				    " %s.\n", port->port_number, str_error(rc));
 			}
@@ -242,5 +240,5 @@
 	}
 
-	usb_log_debug("Port %zu status 0x%08" PRIx32 "\n",
+	usb_log_debug("Port %u status %#08" PRIx32 "\n",
 	    port->port_number, status);
 }
@@ -259,43 +257,13 @@
 	assert(port);
 	assert(hub);
-	if (port->attached_device.address < 0) {
-		usb_log_warning(
-		    "Device on port %zu removed before being registered.\n",
-		    port->port_number);
-
-		/*
-		 * Device was removed before port reset completed.
-		 * We will announce a failed port reset to unblock the
-		 * port reset callback from new device wrapper.
-		 */
-		usb_hub_port_reset_fail(port);
-		return EOK;
-	}
-
-	fibril_mutex_lock(&port->mutex);
-	assert(port->attached_device.fun);
-	usb_log_debug("Removing device on port %zu.\n", port->port_number);
-	int ret = ddf_fun_unbind(port->attached_device.fun);
-	if (ret != EOK) {
-		usb_log_error("Failed to unbind child function on port"
-		    " %zu: %s.\n", port->port_number, str_error(ret));
-		fibril_mutex_unlock(&port->mutex);
-		return ret;
-	}
-
-	ddf_fun_destroy(port->attached_device.fun);
-	port->attached_device.fun = NULL;
-
-	ret = usb_hub_unregister_device(&hub->usb_device->hc_conn,
-	    &port->attached_device);
-	if (ret != EOK) {
-		usb_log_warning("Failed to unregister address of the "
-		    "removed device: %s.\n", str_error(ret));
-	}
-
-	port->attached_device.address = -1;
-	fibril_mutex_unlock(&port->mutex);
-	usb_log_info("Removed device on port %zu.\n", port->port_number);
-	return EOK;
+	async_exch_t *exch = usb_device_bus_exchange_begin(hub->usb_device);
+	if (!exch)
+		return ENOMEM;
+	const int rc = usb_device_remove(exch, port->port_number);
+	usb_device_bus_exchange_end(exch);
+	if (rc == EOK)
+		port->device_attached = false;
+	return rc;
+
 }
 
@@ -318,8 +286,8 @@
 
 	if (port->reset_okay) {
-		usb_log_debug("Port %zu reset complete.\n", port->port_number);
+		usb_log_debug("Port %u reset complete.\n", port->port_number);
 	} else {
 		usb_log_warning(
-		    "Port %zu reset complete but port not enabled.\n",
+		    "Port %u reset complete but port not enabled.\n",
 		    port->port_number);
 	}
@@ -331,5 +299,5 @@
 	if (rc != EOK) {
 		usb_log_error(
-		    "Failed to clear port %zu reset change feature: %s.\n",
+		    "Failed to clear port %u reset change feature: %s.\n",
 		    port->port_number, str_error(rc));
 	}
@@ -376,34 +344,26 @@
 }
 
-/** Callback for enabling a specific port.
- *
- * We wait on a CV until port is reseted.
- * That is announced via change on interrupt pipe.
- *
- * @param port_no Port number (starting at 1).
- * @param arg Custom argument, points to @c usb_hub_dev_t.
- * @return Error code.
- */
-static int enable_port_callback(void *arg)
-{
-	usb_hub_port_t *port = arg;
-	assert(port);
-	const int rc =
-	    usb_hub_port_set_feature(port, USB_HUB_FEATURE_PORT_RESET);
-	if (rc != EOK) {
-		usb_log_warning("Port reset failed: %s.\n", str_error(rc));
-		return rc;
-	}
-
-	/*
-	 * Wait until reset completes.
-	 */
-	fibril_mutex_lock(&port->mutex);
-	while (!port->reset_completed) {
-		fibril_condvar_wait(&port->reset_cv, &port->mutex);
-	}
-	fibril_mutex_unlock(&port->mutex);
-
-	return port->reset_okay ? EOK : ESTALL;
+static int port_enable(usb_hub_port_t *port, bool enable)
+{
+	if (enable) {
+		const int rc =
+		    usb_hub_port_set_feature(port, USB_HUB_FEATURE_PORT_RESET);
+		if (rc != EOK) {
+			usb_log_error("Port reset failed: %s.\n",
+			    str_error(rc));
+		} else {
+			/* Wait until reset completes. */
+			fibril_mutex_lock(&port->mutex);
+			while (!port->reset_completed) {
+				fibril_condvar_wait(&port->reset_cv,
+				    &port->mutex);
+			}
+			fibril_mutex_unlock(&port->mutex);
+		}
+		return port->reset_okay ? EOK : ESTALL;
+	} else {
+		return usb_hub_port_clear_feature(port,
+				USB_HUB_FEATURE_PORT_ENABLE);
+	}
 }
 
@@ -418,46 +378,70 @@
 int add_device_phase1_worker_fibril(void *arg)
 {
-	struct add_device_phase1 *data = arg;
-	assert(data);
-
-	usb_address_t new_address;
-	ddf_fun_t *child_fun;
-
-	child_fun = ddf_fun_create(data->hub->usb_device->ddf_dev,
-	    fun_inner, NULL);
-	if (child_fun == NULL)
-		return ENOMEM;
-
-	const int rc = usb_hc_new_device_wrapper(data->hub->usb_device->ddf_dev,
-	    child_fun, &data->hub->usb_device->hc_conn, data->speed,
-	    enable_port_callback, data->port, &new_address, NULL);
-
-	if (rc == EOK) {
-		fibril_mutex_lock(&data->port->mutex);
-		data->port->attached_device.fun = child_fun;
-		data->port->attached_device.address = new_address;
-		fibril_mutex_unlock(&data->port->mutex);
-
-		usb_log_info("Detected new device on `%s' (port %zu), "
-		    "address %d (handle %" PRIun ").\n",
-		    ddf_dev_get_name(data->hub->usb_device->ddf_dev),
-		    data->port->port_number, new_address,
-		    ddf_fun_get_handle(child_fun));
+	struct add_device_phase1 *params = arg;
+	assert(params);
+
+	int ret = EOK;
+	usb_hub_dev_t *hub = params->hub;
+	usb_hub_port_t *port = params->port;
+	const usb_speed_t speed = params->speed;
+	free(arg);
+
+	async_exch_t *exch = usb_device_bus_exchange_begin(hub->usb_device);
+	if (!exch) {
+		usb_log_error("Failed to begin bus exchange\n");
+		ret = ENOMEM;
+		goto out;
+	}
+
+	/* Reserve default address */
+	while ((ret = usb_reserve_default_address(exch, speed)) == ENOENT) {
+		async_usleep(1000000);
+	}
+	if (ret != EOK) {
+		usb_log_error("Failed to reserve default address: %s\n",
+		    str_error(ret));
+		goto out;
+	}
+
+	/* Reset port */
+	port_enable(port, true);
+	if (!port->reset_completed || !port->reset_okay) {
+		usb_log_error("Failed to reset port %u\n", port->port_number);
+		if (usb_release_default_address(exch) != EOK)
+			usb_log_warning("Failed to release default address\n");
+		ret = EIO;
+		goto out;
+	}
+
+	ret = usb_device_enumerate(exch, port->port_number);
+	if (ret != EOK) {
+		usb_log_error("Failed to enumerate device on port %u: %s",
+		    port->port_number, str_error(ret));
+		const int ret = port_enable(port, false);
+		if (ret != EOK) {
+			usb_log_warning("Failed to disable port %u (%s), NOT "
+			    "releasing default address.", port->port_number,
+			    str_error(ret));
+		} else {
+			const int ret = usb_release_default_address(exch);
+			if (ret != EOK)
+				usb_log_warning("Failed to release default "
+				    "address: %s", str_error(ret));
+		}
 	} else {
-		ddf_fun_destroy(child_fun);
-		usb_log_error("Failed registering device on port %zu: %s.\n",
-		    data->port->port_number, str_error(rc));
-	}
-
-
-	fibril_mutex_lock(&data->hub->pending_ops_mutex);
-	assert(data->hub->pending_ops_count > 0);
-	--data->hub->pending_ops_count;
-	fibril_condvar_signal(&data->hub->pending_ops_cv);
-	fibril_mutex_unlock(&data->hub->pending_ops_mutex);
-
-	free(arg);
-
-	return rc;
+		port->device_attached = true;
+		if (usb_release_default_address(exch) != EOK)
+			usb_log_warning("Failed to release default address\n");
+	}
+out:
+	usb_device_bus_exchange_end(exch);
+
+	fibril_mutex_lock(&hub->pending_ops_mutex);
+	assert(hub->pending_ops_count > 0);
+	--hub->pending_ops_count;
+	fibril_condvar_signal(&hub->pending_ops_cv);
+	fibril_mutex_unlock(&hub->pending_ops_mutex);
+
+	return ret;
 }
 
Index: uspace/drv/bus/usb/usbhub/port.h
===================================================================
--- uspace/drv/bus/usb/usbhub/port.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhub/port.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -37,6 +37,6 @@
 
 #include <usb/dev/driver.h>
-#include <usb/dev/hub.h>
 #include <usb/classes/hub.h>
+#include <usb_iface.h>
 
 typedef struct usb_hub_dev usb_hub_dev_t;
@@ -44,6 +44,6 @@
 /** Information about single port on a hub. */
 typedef struct {
-	/* Port number as reported in descriptors. */
-	size_t port_number;
+	/** Port number as reported in descriptors. */
+	unsigned port_number;
 	/** Device communication pipe. */
 	usb_pipe_t *control_pipe;
@@ -58,7 +58,6 @@
 	/** Whether to announce the port reset as successful. */
 	bool reset_okay;
-
-	/** Information about attached device. */
-	usb_hub_attached_device_t attached_device;
+	/** Device reported to USB bus driver */
+	bool device_attached;
 } usb_hub_port_t;
 
@@ -67,12 +66,13 @@
  * @param port Port to be initialized.
  */
-static inline void usb_hub_port_init(usb_hub_port_t *port, size_t port_number,
+static inline void usb_hub_port_init(usb_hub_port_t *port, unsigned port_number,
     usb_pipe_t *control_pipe)
 {
 	assert(port);
-	port->attached_device.address = -1;
-	port->attached_device.fun = NULL;
 	port->port_number = port_number;
 	port->control_pipe = control_pipe;
+	port->reset_completed = false;
+	port->reset_okay = false;
+	port->device_attached = false;
 	fibril_mutex_initialize(&port->mutex);
 	fibril_condvar_initialize(&port->reset_cv);
Index: uspace/drv/bus/usb/usbhub/status.h
===================================================================
--- uspace/drv/bus/usb/usbhub/status.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhub/status.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -64,4 +64,8 @@
 #define USB_HUB_PORT_STATUS_HIGH_SPEED \
     (uint32_usb2host(1 << 10))
+#define USB_HUB_PORT_STATUS_TEST_MODE \
+    (uint32_usb2host(1 << 11))
+#define USB_HUB_PORT_INDICATOR_CONTROL \
+    (uint32_usb2host(1 << 12))
 
 #define USB_HUB_PORT_C_STATUS_CONNECTION \
Index: uspace/drv/bus/usb/usbhub/usbhub.c
===================================================================
--- uspace/drv/bus/usb/usbhub/usbhub.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhub/usbhub.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -45,5 +45,4 @@
 #include <usb/dev/pipes.h>
 #include <usb/classes/classes.h>
-#include <usb/ddfiface.h>
 #include <usb/descriptor.h>
 #include <usb/dev/recognise.h>
@@ -57,4 +56,17 @@
 
 #define HUB_FNC_NAME "hub"
+/** Hub status-change endpoint description.
+ *
+ * For more information see section 11.15.1 of USB 1.1 specification.
+ */
+const usb_endpoint_description_t hub_status_change_endpoint_description =
+{
+	.transfer_type = USB_TRANSFER_INTERRUPT,
+	.direction = USB_DIRECTION_IN,
+	.interface_class = USB_CLASS_HUB,
+	.interface_subclass = 0,
+	.interface_protocol = 0,
+	.flags = 0
+};
 
 /** Standard get hub global status request */
@@ -99,16 +111,7 @@
 	fibril_condvar_initialize(&hub_dev->pending_ops_cv);
 
-
-	int opResult = usb_pipe_start_long_transfer(&usb_dev->ctrl_pipe);
-	if (opResult != EOK) {
-		usb_log_error("Failed to start long ctrl pipe transfer: %s\n",
-		    str_error(opResult));
-		return opResult;
-	}
-
 	/* Set hub's first configuration. (There should be only one) */
-	opResult = usb_set_first_configuration(usb_dev);
-	if (opResult != EOK) {
-		usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
+	int opResult = usb_set_first_configuration(usb_dev);
+	if (opResult != EOK) {
 		usb_log_error("Could not set hub configuration: %s\n",
 		    str_error(opResult));
@@ -119,5 +122,4 @@
 	opResult = usb_hub_process_hub_specific_info(hub_dev);
 	if (opResult != EOK) {
-		usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
 		usb_log_error("Could process hub specific info, %s\n",
 		    str_error(opResult));
@@ -127,8 +129,7 @@
 	/* Create hub control function. */
 	usb_log_debug("Creating DDF function '" HUB_FNC_NAME "'.\n");
-	hub_dev->hub_fun = ddf_fun_create(hub_dev->usb_device->ddf_dev,
+	hub_dev->hub_fun = usb_device_ddf_fun_create(hub_dev->usb_device,
 	    fun_exposed, HUB_FNC_NAME);
 	if (hub_dev->hub_fun == NULL) {
-		usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
 		usb_log_error("Failed to create hub function.\n");
 		return ENOMEM;
@@ -138,5 +139,4 @@
 	opResult = ddf_fun_bind(hub_dev->hub_fun);
 	if (opResult != EOK) {
-		usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
 		usb_log_error("Failed to bind hub function: %s.\n",
 		   str_error(opResult));
@@ -146,9 +146,9 @@
 
 	/* Start hub operation. */
-	opResult = usb_device_auto_poll(hub_dev->usb_device, 0,
-	    hub_port_changes_callback, ((hub_dev->port_count + 1 + 8) / 8),
-	    usb_hub_polling_terminated_callback, hub_dev);
-	if (opResult != EOK) {
-		usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
+	opResult = usb_device_auto_poll_desc(hub_dev->usb_device,
+	    &hub_status_change_endpoint_description,
+	    hub_port_changes_callback, ((hub_dev->port_count + 1 + 7) / 8),
+	    -1, usb_hub_polling_terminated_callback, hub_dev);
+	if (opResult != EOK) {
 		/* Function is already bound */
 		ddf_fun_unbind(hub_dev->hub_fun);
@@ -160,7 +160,6 @@
 	hub_dev->running = true;
 	usb_log_info("Controlling hub '%s' (%zu ports).\n",
-	    ddf_dev_get_name(hub_dev->usb_device->ddf_dev), hub_dev->port_count);
-
-	usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
+	    usb_device_get_name(hub_dev->usb_device), hub_dev->port_count);
+
 	return EOK;
 }
@@ -185,5 +184,5 @@
 {
 	assert(usb_dev);
-	usb_hub_dev_t *hub = usb_dev->driver_data;
+	usb_hub_dev_t *hub = usb_device_data_get(usb_dev);
 	assert(hub);
 	unsigned tries = 10;
@@ -199,10 +198,7 @@
 
 	for (size_t port = 0; port < hub->port_count; ++port) {
-		if (hub->ports[port].attached_device.fun) {
-			const int ret =
-			    usb_hub_port_fini(&hub->ports[port], hub);
-			if (ret != EOK)
-				return ret;
-		}
+		const int ret = usb_hub_port_fini(&hub->ports[port], hub);
+		if (ret != EOK)
+			return ret;
 	}
 	free(hub->ports);
@@ -247,5 +243,5 @@
 
 	/* N + 1 bit indicates change on port N */
-	for (size_t port = 0; port < hub->port_count + 1; port++) {
+	for (size_t port = 0; port < hub->port_count; ++port) {
 		const size_t bit = port + 1;
 		const bool change = (change_bitmap[bit / 8] >> (bit % 8)) & 1;
@@ -273,5 +269,6 @@
 	/* Get hub descriptor. */
 	usb_log_debug("Retrieving descriptor\n");
-	usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe;
+	usb_pipe_t *control_pipe =
+	    usb_device_get_default_pipe(hub_dev->usb_device);
 
 	usb_hub_descriptor_header_t descriptor;
@@ -311,5 +308,6 @@
 	}
 
-	usb_log_info("Hub port power switching enabled.\n");
+	usb_log_info("Hub port power switching enabled (%s).\n",
+	    hub_dev->per_port_power ? "per port" : "ganged");
 
 	for (size_t port = 0; port < hub_dev->port_count; ++port) {
@@ -319,5 +317,5 @@
 
 		if (ret != EOK) {
-			usb_log_error("Cannot power on port %zu: %s.\n",
+			usb_log_error("Cannot power on port %u: %s.\n",
 			    hub_dev->ports[port].port_number, str_error(ret));
 		} else {
@@ -345,5 +343,5 @@
 	/* Get number of possible configurations from device descriptor */
 	const size_t configuration_count =
-	    usb_device->descriptors.device.configuration_count;
+	    usb_device_descriptors(usb_device)->device.configuration_count;
 	usb_log_debug("Hub has %zu configurations.\n", configuration_count);
 
@@ -353,6 +351,11 @@
 	}
 
-	if (usb_device->descriptors.configuration_size
-	    < sizeof(usb_standard_configuration_descriptor_t)) {
+	// TODO: Make sure that the cast is correct
+	const size_t config_size =
+	    usb_device_descriptors(usb_device)->full_config_size;
+	const usb_standard_configuration_descriptor_t *config_descriptor =
+	    usb_device_descriptors(usb_device)->full_config;
+
+	if (config_size < sizeof(usb_standard_configuration_descriptor_t)) {
 	    usb_log_error("Configuration descriptor is not big enough"
 	        " to fit standard configuration descriptor.\n");
@@ -360,13 +363,9 @@
 	}
 
-	// TODO: Make sure that the cast is correct
-	usb_standard_configuration_descriptor_t *config_descriptor
-	    = (usb_standard_configuration_descriptor_t *)
-	    usb_device->descriptors.configuration;
-
 	/* Set configuration. Use the configuration that was in
 	 * usb_device->descriptors.configuration i.e. The first one. */
 	const int opResult = usb_request_set_configuration(
-	    &usb_device->ctrl_pipe, config_descriptor->configuration_number);
+	    usb_device_get_default_pipe(usb_device),
+	    config_descriptor->configuration_number);
 	if (opResult != EOK) {
 		usb_log_error("Failed to set hub configuration: %s.\n",
@@ -407,5 +406,5 @@
 		if (ret != EOK) {
 			usb_log_warning("HUB OVER-CURRENT GONE: Cannot power on"
-			    " port %zu: %s\n", hub_dev->ports[port].port_number,
+			    " port %u: %s\n", hub_dev->ports[port].port_number,
 			    str_error(ret));
 		} else {
@@ -428,5 +427,6 @@
 	assert(hub_dev->usb_device);
 	usb_log_debug("Global interrupt on a hub\n");
-	usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe;
+	usb_pipe_t *control_pipe =
+	    usb_device_get_default_pipe(hub_dev->usb_device);
 
 	usb_hub_status_t status;
@@ -452,5 +452,5 @@
 		/* Ack change in hub OC flag */
 		const int ret = usb_request_clear_feature(
-		    &hub_dev->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS,
+		    control_pipe, USB_REQUEST_TYPE_CLASS,
 		    USB_REQUEST_RECIPIENT_DEVICE,
 		    USB_HUB_FEATURE_C_HUB_OVER_CURRENT, 0);
Index: uspace/drv/bus/usb/usbhub/usbhub.h
===================================================================
--- uspace/drv/bus/usb/usbhub/usbhub.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbhub/usbhub.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -39,5 +39,4 @@
 #include <ddf/driver.h>
 
-#include <usb/dev/hub.h>
 #include <usb/classes/hub.h>
 
@@ -81,4 +80,6 @@
 };
 
+extern const usb_endpoint_description_t hub_status_change_endpoint_description;
+
 int usb_hub_device_add(usb_device_t *usb_dev);
 int usb_hub_device_remove(usb_device_t *usb_dev);
Index: uspace/drv/bus/usb/usbmast/bo_trans.c
===================================================================
--- uspace/drv/bus/usb/usbmast/bo_trans.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbmast/bo_trans.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -65,22 +65,19 @@
 {
 	int rc;
-	int retval = EOK;
-	size_t act_size;
-	usb_pipe_t *bulk_in_pipe = &mfun->mdev->usb_dev->pipes[BULK_IN_EP].pipe;
-	usb_pipe_t *bulk_out_pipe = &mfun->mdev->usb_dev->pipes[BULK_OUT_EP].pipe;
-	usb_direction_t ddir;
-	void *dbuf;
-	size_t dbuf_size;
-
-	if (cmd->data_out != NULL && cmd->data_in == NULL) {
-		ddir = USB_DIRECTION_OUT;
-		dbuf = (void *)cmd->data_out;
-		dbuf_size = cmd->data_out_size;
-	} else if (cmd->data_out == NULL && cmd->data_in != NULL) {
+
+	if (cmd->data_in && cmd->data_out)
+		return EINVAL;
+
+	usb_pipe_t *bulk_in_pipe = mfun->mdev->bulk_in_pipe;
+	usb_pipe_t *bulk_out_pipe = mfun->mdev->bulk_out_pipe;
+
+	usb_pipe_t *dpipe = bulk_out_pipe;
+	usb_direction_t ddir = USB_DIRECTION_OUT;
+	size_t dbuf_size = cmd->data_out_size;
+
+	if (cmd->data_in) {
 		ddir = USB_DIRECTION_IN;
-		dbuf = cmd->data_in;
 		dbuf_size = cmd->data_in_size;
-	} else {
-		assert(false);
+		dpipe = bulk_in_pipe;
 	}
 
@@ -100,15 +97,18 @@
 
 	MASTLOG("Transferring data.\n");
-	if (ddir == USB_DIRECTION_IN) {
+	if (cmd->data_in) {
+		size_t act_size;
 		/* Recieve data from the device. */
-		rc = usb_pipe_read(bulk_in_pipe, dbuf, dbuf_size, &act_size);
+		rc = usb_pipe_read(dpipe, cmd->data_in, cmd->data_in_size,
+		    &act_size);
 		MASTLOG("Received %zu bytes (%s): %s.\n", act_size,
-		    usb_debug_str_buffer((uint8_t *) dbuf, act_size, 0),
+		    usb_debug_str_buffer(cmd->data_in, act_size, 0),
 		    str_error(rc));
-	} else {
+	}
+	if (cmd->data_out) {
 		/* Send data to the device. */
-		rc = usb_pipe_write(bulk_out_pipe, dbuf, dbuf_size);
-		MASTLOG("Sent %zu bytes (%s): %s.\n", act_size,
-		    usb_debug_str_buffer((uint8_t *) dbuf, act_size, 0),
+		rc = usb_pipe_write(dpipe, cmd->data_out, cmd->data_out_size);
+		MASTLOG("Sent %zu bytes (%s): %s.\n", cmd->data_out_size,
+		    usb_debug_str_buffer(cmd->data_out, cmd->data_out_size, 0),
 		    str_error(rc));
 	}
@@ -116,11 +116,6 @@
 	if (rc == ESTALL) {
 		/* Clear stall condition and continue below to read CSW. */
-		if (ddir == USB_DIRECTION_IN) {
-			usb_pipe_clear_halt(&mfun->mdev->usb_dev->ctrl_pipe,
-			    &mfun->mdev->usb_dev->pipes[BULK_IN_EP].pipe);
-		} else {
-			usb_pipe_clear_halt(&mfun->mdev->usb_dev->ctrl_pipe,
-			    &mfun->mdev->usb_dev->pipes[BULK_OUT_EP].pipe);
-		}
+		usb_pipe_clear_halt(
+		    usb_device_get_default_pipe(mfun->mdev->usb_dev), dpipe);
         } else if (rc != EOK) {
 		return EIO;
@@ -163,12 +158,12 @@
 	case cbs_phase_error:
 		MASTLOG("Phase error\n");
-		retval = EIO;
+		rc = EIO;
 		break;
 	default:
-		retval = EIO;
-		break;
-	}
-
-	size_t residue = (size_t) uint32_usb2host(csw.dCSWDataResidue);
+		rc = EIO;
+		break;
+	}
+
+	const size_t residue = uint32_usb2host(csw.dCSWDataResidue);
 	if (residue > dbuf_size) {
 		MASTLOG("residue > dbuf_size\n");
@@ -184,8 +179,8 @@
 	 */
 
-	if (ddir == USB_DIRECTION_IN)
+	if (cmd->data_in)
 		cmd->rcvd_size = dbuf_size - residue;
 
-	return retval;
+	return rc;
 }
 
@@ -197,7 +192,8 @@
 int usb_massstor_reset(usbmast_dev_t *mdev)
 {
-	return usb_control_request_set(&mdev->usb_dev->ctrl_pipe,
+	return usb_control_request_set(
+	    usb_device_get_default_pipe(mdev->usb_dev),
 	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
-	    0xFF, 0, mdev->usb_dev->interface_no, NULL, 0);
+	    0xFF, 0, usb_device_get_iface_number(mdev->usb_dev), NULL, 0);
 }
 
@@ -215,8 +211,8 @@
 	 */
 	usb_massstor_reset(mdev);
-	usb_pipe_clear_halt(&mdev->usb_dev->ctrl_pipe,
-	    &mdev->usb_dev->pipes[BULK_IN_EP].pipe);
-	usb_pipe_clear_halt(&mdev->usb_dev->ctrl_pipe,
-	    &mdev->usb_dev->pipes[BULK_OUT_EP].pipe);
+	usb_pipe_clear_halt(usb_device_get_default_pipe(mdev->usb_dev),
+	    mdev->bulk_in_pipe);
+	usb_pipe_clear_halt(usb_device_get_default_pipe(mdev->usb_dev),
+	    mdev->bulk_out_pipe);
 }
 
@@ -236,7 +232,9 @@
 	uint8_t max_lun;
 	size_t data_recv_len;
-	int rc = usb_control_request_get(&mdev->usb_dev->ctrl_pipe,
+	int rc = usb_control_request_get(
+	    usb_device_get_default_pipe(mdev->usb_dev),
 	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
-	    0xFE, 0, mdev->usb_dev->interface_no, &max_lun, 1, &data_recv_len);
+	    0xFE, 0, usb_device_get_iface_number(mdev->usb_dev), &max_lun, 1,
+	    &data_recv_len);
 	if (rc != EOK) {
 		return rc;
Index: uspace/drv/bus/usb/usbmast/bo_trans.h
===================================================================
--- uspace/drv/bus/usb/usbmast/bo_trans.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbmast/bo_trans.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -44,7 +44,4 @@
 #include "usbmast.h"
 
-#define BULK_IN_EP 0
-#define BULK_OUT_EP 1
-
 typedef enum cmd_status {
 	CMDS_GOOD,
@@ -63,5 +60,5 @@
 
 	/** Command Descriptor Block */
-	void *cdb;
+	const void *cdb;
 	/** CDB size in bytes */
 	size_t cdb_size;
Index: uspace/drv/bus/usb/usbmast/main.c
===================================================================
--- uspace/drv/bus/usb/usbmast/main.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbmast/main.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -52,7 +52,4 @@
 #define NAME "usbmast"
 
-#define GET_BULK_IN(dev) ((dev)->pipes[BULK_IN_EP].pipe)
-#define GET_BULK_OUT(dev) ((dev)->pipes[BULK_OUT_EP].pipe)
-
 static const usb_endpoint_description_t bulk_in_ep = {
 	.transfer_type = USB_TRANSFER_BULK,
@@ -112,5 +109,5 @@
 static int usbmast_device_gone(usb_device_t *dev)
 {
-	usbmast_dev_t *mdev = dev->driver_data;
+	usbmast_dev_t *mdev = usb_device_data_get(dev);
 	assert(mdev);
 
@@ -152,4 +149,13 @@
 	unsigned i;
 
+	usb_endpoint_mapping_t *epm_in =
+	    usb_device_get_mapped_ep_desc(dev, &bulk_in_ep);
+	usb_endpoint_mapping_t *epm_out =
+	    usb_device_get_mapped_ep_desc(dev, &bulk_out_ep);
+	if (!epm_in || !epm_out || !epm_in->present || !epm_out->present) {
+		usb_log_error("Required EPs were not mapped.\n");
+		return ENOENT;
+	}
+
 	/* Allocate softstate */
 	mdev = usb_device_data_alloc(dev, sizeof(usbmast_dev_t));
@@ -159,14 +165,12 @@
 	}
 
-	mdev->ddf_dev = dev->ddf_dev;
 	mdev->usb_dev = dev;
 
-	usb_log_info("Initializing mass storage `%s'.\n", ddf_dev_get_name(dev->ddf_dev));
+	usb_log_info("Initializing mass storage `%s'.\n",
+	    usb_device_get_name(dev));
 	usb_log_debug("Bulk in endpoint: %d [%zuB].\n",
-	    dev->pipes[BULK_IN_EP].pipe.endpoint_no,
-	    dev->pipes[BULK_IN_EP].pipe.max_packet_size);
+	    epm_in->pipe.endpoint_no, epm_in->pipe.max_packet_size);
 	usb_log_debug("Bulk out endpoint: %d [%zuB].\n",
-	    dev->pipes[BULK_OUT_EP].pipe.endpoint_no,
-	    dev->pipes[BULK_OUT_EP].pipe.max_packet_size);
+	    epm_out->pipe.endpoint_no, epm_out->pipe.max_packet_size);
 
 	usb_log_debug("Get LUN count...\n");
@@ -179,4 +183,6 @@
 	}
 
+	mdev->bulk_in_pipe = &epm_in->pipe;
+	mdev->bulk_out_pipe = &epm_out->pipe;
 	for (i = 0; i < mdev->lun_count; i++) {
 		rc = usbmast_fun_create(mdev, i);
@@ -223,5 +229,5 @@
 	}
 
-	fun = ddf_fun_create(mdev->ddf_dev, fun_exposed, fun_name);
+	fun = usb_device_ddf_fun_create(mdev->usb_dev, fun_exposed, fun_name);
 	if (fun == NULL) {
 		usb_log_error("Failed to create DDF function %s.\n", fun_name);
@@ -254,5 +260,5 @@
 	if (rc != EOK) {
 		usb_log_warning("Failed to inquire device `%s': %s.\n",
-		    ddf_dev_get_name(mdev->ddf_dev), str_error(rc));
+		    usb_device_get_name(mdev->usb_dev), str_error(rc));
 		rc = EIO;
 		goto error;
@@ -261,5 +267,5 @@
 	usb_log_info("Mass storage `%s' LUN %u: " \
 	    "%s by %s rev. %s is %s (%s).\n",
-	    ddf_dev_get_name(mdev->ddf_dev),
+	    usb_device_get_name(mdev->usb_dev),
 	    lun,
 	    inquiry.product,
@@ -274,5 +280,5 @@
 	if (rc != EOK) {
 		usb_log_warning("Failed to read capacity, device `%s': %s.\n",
-		    ddf_dev_get_name(mdev->ddf_dev), str_error(rc));
+		    usb_device_get_name(mdev->usb_dev), str_error(rc));
 		rc = EIO;
 		goto error;
Index: uspace/drv/bus/usb/usbmast/scsi_ms.c
===================================================================
--- uspace/drv/bus/usb/usbmast/scsi_ms.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbmast/scsi_ms.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -88,5 +88,5 @@
 		if (rc != EOK) {
 			usb_log_error("Inquiry transport failed, device %s: %s.\n",
-			   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
+			   usb_device_get_name(mfun->mdev->usb_dev), str_error(rc));
 			return rc;
 		}
@@ -96,5 +96,5 @@
 
 		usb_log_error("SCSI command failed, device %s.\n",
-		    ddf_dev_get_name(mfun->mdev->ddf_dev));
+		    usb_device_get_name(mfun->mdev->usb_dev));
 
 		rc = usbmast_request_sense(mfun, &sense_buf, sizeof(sense_buf));
@@ -147,5 +147,5 @@
 	if (rc != EOK) {
 		usb_log_error("Inquiry transport failed, device %s: %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
+		   usb_device_get_name(mfun->mdev->usb_dev), str_error(rc));
 		return rc;
 	}
@@ -153,5 +153,5 @@
 	if (cmd.status != CMDS_GOOD) {
 		usb_log_error("Inquiry command failed, device %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev));
+		   usb_device_get_name(mfun->mdev->usb_dev));
 		return EIO;
 	}
@@ -215,5 +215,5 @@
         if (rc != EOK || cmd.status != CMDS_GOOD) {
 		usb_log_error("Request Sense failed, device %s: %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
+		   usb_device_get_name(mfun->mdev->usb_dev), str_error(rc));
 		return rc;
 	}
@@ -257,5 +257,5 @@
         if (rc != EOK) {
 		usb_log_error("Read Capacity (10) transport failed, device %s: %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
+		   usb_device_get_name(mfun->mdev->usb_dev), str_error(rc));
 		return rc;
 	}
@@ -263,5 +263,5 @@
 	if (cmd.status != CMDS_GOOD) {
 		usb_log_error("Read Capacity (10) command failed, device %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev));
+		   usb_device_get_name(mfun->mdev->usb_dev));
 		return EIO;
 	}
@@ -314,5 +314,5 @@
         if (rc != EOK) {
 		usb_log_error("Read (10) transport failed, device %s: %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
+		   usb_device_get_name(mfun->mdev->usb_dev), str_error(rc));
 		return rc;
 	}
@@ -320,5 +320,5 @@
 	if (cmd.status != CMDS_GOOD) {
 		usb_log_error("Read (10) command failed, device %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev));
+		   usb_device_get_name(mfun->mdev->usb_dev));
 		return EIO;
 	}
@@ -370,5 +370,5 @@
         if (rc != EOK) {
 		usb_log_error("Write (10) transport failed, device %s: %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
+		   usb_device_get_name(mfun->mdev->usb_dev), str_error(rc));
 		return rc;
 	}
@@ -376,5 +376,5 @@
 	if (cmd.status != CMDS_GOOD) {
 		usb_log_error("Write (10) command failed, device %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev));
+		   usb_device_get_name(mfun->mdev->usb_dev));
 		return EIO;
 	}
@@ -394,8 +394,4 @@
 int usbmast_sync_cache(usbmast_fun_t *mfun, uint64_t ba, size_t nblocks)
 {
-	scsi_cmd_t cmd;
-	scsi_cdb_sync_cache_10_t cdb;
-	int rc;
-
 	if (ba > UINT32_MAX)
 		return ELIMIT;
@@ -404,18 +400,20 @@
 		return ELIMIT;
 
-	memset(&cdb, 0, sizeof(cdb));
-	cdb.op_code = SCSI_CMD_SYNC_CACHE_10;
-	cdb.lba = host2uint32_t_be(ba);
-	cdb.numlb = host2uint16_t_be(nblocks);
-
-	memset(&cmd, 0, sizeof(cmd));
-	cmd.cdb = &cdb;
-	cmd.cdb_size = sizeof(cdb);
-
-	rc = usbmast_run_cmd(mfun, &cmd);
+	const scsi_cdb_sync_cache_10_t cdb = {
+		.op_code = SCSI_CMD_SYNC_CACHE_10,
+		.lba = host2uint32_t_be(ba),
+		.numlb = host2uint16_t_be(nblocks),
+	};
+
+	scsi_cmd_t cmd = {
+		.cdb = &cdb,
+		.cdb_size = sizeof(cdb),
+	};
+
+	const int rc = usbmast_run_cmd(mfun, &cmd);
 
         if (rc != EOK) {
 		usb_log_error("Synchronize Cache (10) transport failed, device %s: %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
+		   usb_device_get_name(mfun->mdev->usb_dev), str_error(rc));
 		return rc;
 	}
@@ -423,5 +421,5 @@
 	if (cmd.status != CMDS_GOOD) {
 		usb_log_error("Synchronize Cache (10) command failed, device %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev));
+		   usb_device_get_name(mfun->mdev->usb_dev));
 		return EIO;
 	}
Index: uspace/drv/bus/usb/usbmast/usbmast.h
===================================================================
--- uspace/drv/bus/usb/usbmast/usbmast.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbmast/usbmast.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -43,6 +43,4 @@
 /** Mass storage device. */
 typedef struct usbmast_dev {
-	/** DDF device */
-	ddf_dev_t *ddf_dev;
 	/** USB device */
 	usb_device_t *usb_dev;
@@ -51,4 +49,8 @@
 	/** LUN functions */
 	ddf_fun_t **luns;
+	/** Data read pipe */
+	usb_pipe_t *bulk_in_pipe;
+	/** Data write pipe */
+	usb_pipe_t *bulk_out_pipe;
 } usbmast_dev_t;
 
Index: uspace/drv/bus/usb/usbmid/explore.c
===================================================================
--- uspace/drv/bus/usb/usbmid/explore.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbmid/explore.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -34,5 +34,4 @@
  * Exploration of available interfaces in the USB device.
  */
-#include <ddf/driver.h>
 #include <errno.h>
 #include <str_error.h>
@@ -41,11 +40,5 @@
 #include <usb/dev/request.h>
 #include <usb/dev/dp.h>
-#include <usb/ddfiface.h>
 #include "usbmid.h"
-
-/** Operations of the device itself. */
-static ddf_dev_ops_t mid_device_ops = {
-	.interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl
-};
 
 /** Tell whether given interface is already in the list.
@@ -57,5 +50,5 @@
 static bool interface_in_list(const list_t *list, int interface_no)
 {
-	list_foreach(*list, link, usbmid_interface_t, iface) {
+	list_foreach(*list, link, const usbmid_interface_t, iface) {
 		if (iface->interface_no == interface_no) {
 			return true;
@@ -71,9 +64,11 @@
  * @param config_descriptor_size Size of configuration descriptor in bytes.
  * @param list List where to add the interfaces.
- * @return EOK on success, ENOMEM if out of memory.
  */
-static int create_interfaces(usb_mid_t *mid, const uint8_t *config_descriptor,
-    size_t config_descriptor_size)
+static int create_interfaces(const uint8_t *config_descriptor,
+    size_t config_descriptor_size, list_t *list, usb_device_t *usb_dev)
 {
+	assert(config_descriptor);
+	assert(usb_dev);
+
 	const usb_dp_parser_data_t data = {
 		.data = config_descriptor,
@@ -91,5 +86,5 @@
 	/* Walk all descriptors nested in the current configuration decriptor;
 	 * i.e. all interface descriptors. */
-	for (;interface_ptr != NULL;
+	for (; interface_ptr != NULL;
 	    interface_ptr = usb_dp_get_sibling_descriptor(
 	        &parser, &data, config_descriptor, interface_ptr))
@@ -103,6 +98,5 @@
 
 		/* Skip alternate interfaces. */
-		if (interface_in_list(&mid->interface_list,
-		    interface->interface_number)) {
+		if (interface_in_list(list, interface->interface_number)) {
 			/* TODO: add the alternatives and create match ids
 			 * for them. */
@@ -110,33 +104,23 @@
 		}
 
-		/* Create the function */
-		ddf_fun_t *fun = ddf_fun_create(mid->dev, fun_inner, NULL);
-		if (fun == NULL)
-			goto error;
 
-		usbmid_interface_t *iface = ddf_fun_data_alloc(fun,
-		    sizeof(usbmid_interface_t));
-		if (iface == NULL)
-			goto error;
+		usb_log_info("Creating child for interface %d (%s).\n",
+		    interface->interface_number,
+		    usb_str_class(interface->interface_class));
 
-		link_initialize(&iface->link);
-		iface->fun = fun;
-		iface->interface_no = interface->interface_number;
-		iface->interface = interface;
-
-		list_append(&iface->link, &mid->interface_list);
+		usbmid_interface_t *iface = NULL;
+		const int rc = usbmid_spawn_interface_child(usb_dev, &iface,
+			&usb_device_descriptors(usb_dev)->device, interface);
+		if (rc != EOK) {
+			//TODO: Do something about that failure.
+			usb_log_error("Failed to create interface child for "
+			    "%d (%s): %s.\n", interface->interface_number,
+			    usb_str_class(interface->interface_class),
+			    str_error(rc));
+		} else {
+			list_append(&iface->link, list);
+		}
 	}
-
 	return EOK;
-error:
-	while (!list_empty(&mid->interface_list)) {
-		link_t *link = list_first(&mid->interface_list);
-		usbmid_interface_t *iface = list_get_instance(link,
-		    usbmid_interface_t, link);
-
-		ddf_fun_destroy(iface->fun);
-	}
-
-	return ENOMEM;
 }
 
@@ -149,9 +133,9 @@
  * @return Whether to accept this device from devman.
  */
-bool usbmid_explore_device(usb_device_t *dev)
+int usbmid_explore_device(usb_device_t *dev)
 {
-	int rc;
-
-	unsigned dev_class = dev->descriptors.device.device_class;
+	assert(dev);
+	const unsigned dev_class =
+	    usb_device_descriptors(dev)->device.device_class;
 	if (dev_class != USB_CLASS_USE_INTERFACE) {
 		usb_log_warning(
@@ -159,39 +143,38 @@
 		    dev_class, usb_str_class(dev_class),
 		    USB_CLASS_USE_INTERFACE);
-		usb_log_error("Not multi interface device, refusing.\n");
-		return false;
+		usb_log_error("Not a multi-interface device, refusing.\n");
+		return ENOTSUP;
 	}
 
-	/* Shortcuts to save on typing ;-). */
-	const void *config_descriptor_raw = dev->descriptors.configuration;
-	size_t config_descriptor_size = dev->descriptors.configuration_size;
+	/* Get coonfiguration descriptor. */
+	const size_t config_descriptor_size =
+	    usb_device_descriptors(dev)->full_config_size;
+	const void *config_descriptor_raw =
+	    usb_device_descriptors(dev)->full_config;
 	const usb_standard_configuration_descriptor_t *config_descriptor =
 	    config_descriptor_raw;
 
 	/* Select the first configuration */
-	rc = usb_request_set_configuration(&dev->ctrl_pipe,
+	int rc = usb_request_set_configuration(usb_device_get_default_pipe(dev),
 	    config_descriptor->configuration_number);
 	if (rc != EOK) {
 		usb_log_error("Failed to set device configuration: %s.\n",
 		    str_error(rc));
-		return false;
+		return rc;
 	}
-
+	
 	/* Create driver soft-state. */
 	usb_mid_t *usb_mid = usb_device_data_alloc(dev, sizeof(usb_mid_t));
 	if (!usb_mid) {
 		usb_log_error("Failed to create USB MID structure.\n");
-		return false;
+		return ENOMEM;
 	}
 
-	usb_mid->dev = dev->ddf_dev;
-
 	/* Create control function. */
-	usb_mid->ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl");
+	usb_mid->ctl_fun = usb_device_ddf_fun_create(dev, fun_exposed, "ctl");
 	if (usb_mid->ctl_fun == NULL) {
 		usb_log_error("Failed to create control function.\n");
-		return false;
+		return ENOMEM;
 	}
-	ddf_fun_set_ops(usb_mid->ctl_fun, &mid_device_ops);
 
 	/* Bind control function. */
@@ -201,26 +184,13 @@
 		    str_error(rc));
 		ddf_fun_destroy(usb_mid->ctl_fun);
-		return false;
+		return rc;
 	}
 
 	/* Create interface children. */
 	list_initialize(&usb_mid->interface_list);
-	create_interfaces(usb_mid, config_descriptor_raw, config_descriptor_size);
+	create_interfaces(config_descriptor_raw, config_descriptor_size,
+	    &usb_mid->interface_list, dev);
 
-	/* Start child function for every interface. */
-	list_foreach(usb_mid->interface_list, link, usbmid_interface_t, iface) {
-		usb_log_info("Creating child for interface %d (%s).\n",
-		    iface->interface_no,
-		    usb_str_class(iface->interface->interface_class));
-
-		rc = usbmid_spawn_interface_child(dev, iface,
-		    &dev->descriptors.device, iface->interface);
-		if (rc != EOK) {
-			usb_log_error("Failed to create interface child: %s.\n",
-			    str_error(rc));
-		}
-	}
-
-	return true;
+	return EOK;
 }
 
Index: uspace/drv/bus/usb/usbmid/main.c
===================================================================
--- uspace/drv/bus/usb/usbmid/main.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbmid/main.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -51,13 +51,7 @@
 static int usbmid_device_add(usb_device_t *dev)
 {
-	usb_log_info("Taking care of new MID `%s'.\n", ddf_dev_get_name(dev->ddf_dev));
+	usb_log_info("Taking care of new MID `%s'.\n", usb_device_get_name(dev));
 
-	const bool accept = usbmid_explore_device(dev);
-
-	if (!accept) {
-		return ENOTSUP;
-	}
-
-	return EOK;
+	return usbmid_explore_device(dev);
 }
 
@@ -70,5 +64,5 @@
 {
 	assert(dev);
-	usb_mid_t *usb_mid = dev->driver_data;
+	usb_mid_t *usb_mid = usb_device_data_get(dev);
 	assert(usb_mid);
 
@@ -89,15 +83,12 @@
 		usbmid_interface_t *iface = usbmid_interface_from_link(item);
 
-		usb_log_info("Removing child for interface %d (%s).\n",
-		    iface->interface_no,
-		    usb_str_class(iface->interface->interface_class));
+		usb_log_info("Removing child `%s'.\n",
+		    ddf_fun_get_name(iface->fun));
 
 		/* Tell the child to go off-line. */
 		int pret = ddf_fun_offline(iface->fun);
 		if (pret != EOK) {
-			usb_log_warning("Failed to turn off child for interface"
-			    " %d (%s): %s\n", iface->interface_no,
-			    usb_str_class(iface->interface->interface_class),
-			    str_error(pret));
+			usb_log_warning("Failed to turn off child `%s': %s\n",
+			    ddf_fun_get_name(iface->fun), str_error(pret));
 			ret = pret;
 		}
@@ -106,8 +97,6 @@
 		pret = usbmid_interface_destroy(iface);
 		if (pret != EOK) {
-			usb_log_error("Failed to destroy child for interface "
-			    "%d (%s): %s\n", iface->interface_no,
-			    usb_str_class(iface->interface->interface_class),
-			    str_error(pret));
+			usb_log_error("Failed to destroy child `%s': %s\n",
+			    ddf_fun_get_name(iface->fun), str_error(pret));
 			ret = pret;
 		}
@@ -124,8 +113,8 @@
 {
 	assert(dev);
-	usb_mid_t *usb_mid = dev->driver_data;
+	usb_mid_t *usb_mid = usb_device_data_get(dev);
 	assert(usb_mid);
 
-	usb_log_info("USB MID gone: `%s'.\n", ddf_dev_get_name(dev->ddf_dev));
+	usb_log_info("USB MID gone: `%s'.\n", usb_device_get_name(dev));
 
 	/* Remove ctl function */
@@ -145,15 +134,11 @@
 		usbmid_interface_t *iface = usbmid_interface_from_link(item);
 
-		usb_log_info("Child for interface %d (%s) gone.\n",
-		    iface->interface_no,
-		    usb_str_class(iface->interface->interface_class));
+		usb_log_info("Child `%s' is gone.\n",
+		    ddf_fun_get_name(iface->fun));
 
 		const int pret = usbmid_interface_destroy(iface);
 		if (pret != EOK) {
-			usb_log_error("Failed to remove child for interface "
-			    "%d (%s): %s\n",
-			    iface->interface_no,
-			    usb_str_class(iface->interface->interface_class),
-			    str_error(pret));
+			usb_log_error("Failed to remove child `%s': %s\n",
+			    ddf_fun_get_name(iface->fun), str_error(pret));
 			ret = pret;
 		}
Index: uspace/drv/bus/usb/usbmid/usbmid.c
===================================================================
--- uspace/drv/bus/usb/usbmid/usbmid.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbmid/usbmid.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -39,5 +39,4 @@
 #include <stdlib.h>
 #include <usb_iface.h>
-#include <usb/ddfiface.h>
 #include <usb/dev/pipes.h>
 #include <usb/classes/classes.h>
@@ -45,22 +44,35 @@
 #include "usbmid.h"
 
-/** Callback for DDF USB interface. */
-static int usb_iface_get_interface_impl(ddf_fun_t *fun, int *iface_no)
+/** Get USB device handle by calling the parent usb_device_t.
+ *
+ * @param[in] fun Device function the operation is running on.
+ * @param[out] handle Device handle.
+ * @return Error code.
+ */
+static int usb_iface_device_handle(ddf_fun_t *fun, devman_handle_t *handle)
+{
+	assert(fun);
+	assert(handle);
+	usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun));
+	*handle = usb_device_get_devman_handle(usb_dev);
+	return EOK;
+}
+
+/** Callback for DDF USB get interface. */
+static int usb_iface_iface_no(ddf_fun_t *fun, int *iface_no)
 {
 	usbmid_interface_t *iface = ddf_fun_data_get(fun);
 	assert(iface);
 
-	if (iface_no != NULL) {
+	if (iface_no)
 		*iface_no = iface->interface_no;
-	}
 
 	return EOK;
 }
 
-/** DDF interface of the child - interface function. */
+/** DDF interface of the child - USB functions. */
 static usb_iface_t child_usb_iface = {
-	.get_hc_handle = usb_iface_get_hc_handle_device_impl,
-	.get_my_address = usb_iface_get_my_address_forward_impl,
-	.get_my_interface = usb_iface_get_interface_impl,
+	.get_my_device_handle = usb_iface_device_handle,
+	.get_my_interface = usb_iface_iface_no,
 };
 
@@ -78,9 +90,5 @@
 		return ret;
 	}
-	/* NOTE: usbmid->interface points somewhere, but we did not
-	 * allocate that space, so don't touch */
 	ddf_fun_destroy(mid_iface->fun);
-	/* NOTE: mid_iface is invalid at this point, it was assigned to
-	 * mid_iface->fun->driver_data and freed in ddf_fun_destroy */
 	return EOK;
 }
@@ -95,8 +103,9 @@
  */
 int usbmid_spawn_interface_child(usb_device_t *parent,
-    usbmid_interface_t *iface,
+    usbmid_interface_t **iface_ret,
     const usb_standard_device_descriptor_t *device_descriptor,
     const usb_standard_interface_descriptor_t *interface_descriptor)
 {
+	ddf_fun_t *child = NULL;
 	char *child_name = NULL;
 	int rc;
@@ -110,11 +119,14 @@
 	    usb_str_class(interface_descriptor->interface_class),
 	    interface_descriptor->interface_number);
-	if (rc < 0)
+	if (rc < 0) {
 		return ENOMEM;
+	}
 
-	rc = ddf_fun_set_name(iface->fun, child_name);
+	/* Create the device. */
+	child = usb_device_ddf_fun_create(parent, fun_inner, child_name);
 	free(child_name);
-	if (rc != EOK)
+	if (child == NULL) {
 		return ENOMEM;
+	}
 
 	match_id_list_t match_ids;
@@ -123,21 +135,33 @@
 	rc = usb_device_create_match_ids_from_interface(device_descriptor,
 	    interface_descriptor, &match_ids);
-	if (rc != EOK)
+	if (rc != EOK) {
+		ddf_fun_destroy(child);
 		return rc;
+	}
 
 	list_foreach(match_ids.ids, link, match_id_t, match_id) {
-		rc = ddf_fun_add_match_id(iface->fun, match_id->id, match_id->score);
+		rc = ddf_fun_add_match_id(child, match_id->id, match_id->score);
 		if (rc != EOK) {
 			clean_match_ids(&match_ids);
+			ddf_fun_destroy(child);
 			return rc;
 		}
 	}
 	clean_match_ids(&match_ids);
+	ddf_fun_set_ops(child, &child_device_ops);
 
-	ddf_fun_set_ops(iface->fun, &child_device_ops);
+	usbmid_interface_t *iface = ddf_fun_data_alloc(child, sizeof(*iface));
 
-	rc = ddf_fun_bind(iface->fun);
-	if (rc != EOK)
+	iface->fun = child;
+	iface->interface_no = interface_descriptor->interface_number;
+	link_initialize(&iface->link);
+
+	rc = ddf_fun_bind(child);
+	if (rc != EOK) {
+		/* This takes care of match_id deallocation as well. */
+		ddf_fun_destroy(child);
 		return rc;
+	}
+	*iface_ret = iface;
 
 	return EOK;
Index: uspace/drv/bus/usb/usbmid/usbmid.h
===================================================================
--- uspace/drv/bus/usb/usbmid/usbmid.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbmid/usbmid.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -50,6 +50,4 @@
 	/** Function container. */
 	ddf_fun_t *fun;
-	/** Interface descriptor. */
-	const usb_standard_interface_descriptor_t *interface;
 	/** Interface number. */
 	int interface_no;
@@ -60,11 +58,10 @@
 /** Container to hold all the function pointers */
 typedef struct usb_mid {
-	ddf_dev_t *dev;
 	ddf_fun_t *ctl_fun;
 	list_t interface_list;
 } usb_mid_t;
 
-bool usbmid_explore_device(usb_device_t *);
-int usbmid_spawn_interface_child(usb_device_t *, usbmid_interface_t *,
+int usbmid_explore_device(usb_device_t *);
+int usbmid_spawn_interface_child(usb_device_t *, usbmid_interface_t **,
     const usb_standard_device_descriptor_t *,
     const usb_standard_interface_descriptor_t *);
Index: uspace/drv/bus/usb/usbmid/usbmid.ma
===================================================================
--- uspace/drv/bus/usb/usbmid/usbmid.ma	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/usbmid/usbmid.ma	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -1,1 +1,2 @@
+100 usb&class=use-interface
 100 usb&mid
Index: uspace/drv/bus/usb/vhc/Makefile
===================================================================
--- uspace/drv/bus/usb/vhc/Makefile	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/vhc/Makefile	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -49,7 +49,5 @@
 	hub/virthubops.c \
 	conndev.c \
-	connhost.c \
 	devconn.c \
-	hub.c \
 	main.c \
 	transfer.c
Index: uspace/drv/bus/usb/vhc/conn.h
===================================================================
--- uspace/drv/bus/usb/vhc/conn.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,54 +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.
- */
-
-/** @addtogroup drvusbvhc
- * @{
- */
-/** @file
- * @brief Connection handling of incoming calls.
- */
-#ifndef VHCD_CONN_H_
-#define VHCD_CONN_H_
-
-#include <usb/usb.h>
-#include <usbhc_iface.h>
-#include <usb_iface.h>
-#include "vhcd.h"
-
-extern usbhc_iface_t vhc_iface;
-extern usb_iface_t vhc_usb_iface;
-extern usb_iface_t rh_usb_iface;
-
-void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
-void on_client_close(ddf_fun_t *);
-
-
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/vhc/conndev.c
===================================================================
--- uspace/drv/bus/usb/vhc/conndev.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/vhc/conndev.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -38,6 +38,8 @@
 #include <ddf/driver.h>
 #include <usbvirt/ipc.h>
+#include <usb/debug.h>
 #include <async.h>
-#include "conn.h"
+
+#include "vhcd.h"
 
 static fibril_local uintptr_t plugged_device_handle = 0;
@@ -94,5 +96,5 @@
     ipc_call_t *icall)
 {
-	vhc_data_t *vhc = ddf_dev_data_get(ddf_fun_get_dev(fun));
+	vhc_data_t *vhc = ddf_fun_data_get(fun);
 	
 	async_sess_t *callback =
@@ -125,5 +127,5 @@
 void on_client_close(ddf_fun_t *fun)
 {
-	vhc_data_t *vhc = ddf_dev_data_get(ddf_fun_get_dev(fun));
+	vhc_data_t *vhc = ddf_fun_data_get(fun);
 
 	if (plugged_device_handle != 0) {
Index: uspace/drv/bus/usb/vhc/connhost.c
===================================================================
--- uspace/drv/bus/usb/vhc/connhost.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,533 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbvhc
- * @{
- */
-/** @file
- * Host controller interface implementation.
- */
-#include <assert.h>
-#include <errno.h>
-#include <usb/usb.h>
-#include <usb/ddfiface.h>
-#include <usb/debug.h>
-#include <usbhc_iface.h>
-#include "vhcd.h"
-
-#define GET_VHC_DATA(fun) \
-	((vhc_data_t *)ddf_dev_data_get(ddf_fun_get_dev(fun)))
-#define VHC_DATA(vhc, fun) \
-	vhc_data_t *vhc = GET_VHC_DATA(fun); assert(vhc->magic == 0xdeadbeef)
-
-#define UNSUPPORTED(methodname) \
-	usb_log_warning("Unsupported interface method `%s()' in %s:%d.\n", \
-	    methodname, __FILE__, __LINE__)
-
-/** Found free USB address.
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] speed Speed of the device that will get this address.
- * @param[out] address Non-null pointer where to store the free address.
- * @return Error code.
- */
-static int request_address(ddf_fun_t *fun, usb_address_t *address, bool strict,
-    usb_speed_t speed)
-{
-	VHC_DATA(vhc, fun);
-
-	assert(address);
-	return usb_device_manager_request_address(
-	    &vhc->dev_manager, address, strict, speed);
-}
-
-/** Bind USB address with device devman handle.
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] address USB address of the device.
- * @param[in] handle Devman handle of the device.
- * @return Error code.
- */
-static int bind_address(ddf_fun_t *fun,
-    usb_address_t address, devman_handle_t handle)
-{
-	VHC_DATA(vhc, fun);
-	usb_log_debug("Binding handle %" PRIun " to address %d.\n",
-	    handle, address);
-	usb_device_manager_bind_address(&vhc->dev_manager, address, handle);
-
-	return EOK;
-}
-
-/** Find device handle by address interface function.
- *
- * @param[in] fun DDF function that was called.
- * @param[in] address Address in question.
- * @param[out] handle Where to store device handle if found.
- * @return Error code.
- */
-static int find_by_address(ddf_fun_t *fun, usb_address_t address,
-    devman_handle_t *handle)
-{
-	VHC_DATA(vhc, fun);
-	return usb_device_manager_get_info_by_address(
-	    &vhc->dev_manager, address, handle, NULL);
-}
-
-/** Release previously requested address.
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] address USB address to be released.
- * @return Error code.
- */
-static int release_address(ddf_fun_t *fun, usb_address_t address)
-{
-	VHC_DATA(vhc, fun);
-	usb_log_debug("Releasing address %d...\n", address);
-	usb_device_manager_release_address(&vhc->dev_manager, address);
-
-	return ENOTSUP;
-}
-
-/** Register endpoint for bandwidth reservation.
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] address USB address of the device.
- * @param[in] speed Endpoint speed (invalid means to use device one).
- * @param[in] endpoint Endpoint number.
- * @param[in] transfer_type USB transfer type.
- * @param[in] direction Endpoint data direction.
- * @param[in] max_packet_size Max packet size of the endpoint.
- * @param[in] interval Polling interval.
- * @return Error code.
- */
-static int register_endpoint(ddf_fun_t *fun,
-    usb_address_t address, usb_endpoint_t endpoint,
-    usb_transfer_type_t transfer_type, usb_direction_t direction,
-    size_t max_packet_size, unsigned int interval)
-{
-	VHC_DATA(vhc, fun);
-
-	return usb_endpoint_manager_add_ep(&vhc->ep_manager,
-	    address, endpoint, direction, transfer_type, USB_SPEED_FULL, 1, 0,
-	    NULL, NULL);
-
-}
-
-/** Unregister endpoint (free some bandwidth reservation).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] address USB address of the device.
- * @param[in] endpoint Endpoint number.
- * @param[in] direction Endpoint data direction.
- * @return Error code.
- */
-static int unregister_endpoint(ddf_fun_t *fun, usb_address_t address,
-    usb_endpoint_t endpoint, usb_direction_t direction)
-{
-	VHC_DATA(vhc, fun);
-
-	int rc = usb_endpoint_manager_remove_ep(&vhc->ep_manager,
-	    address, endpoint, direction, NULL, NULL);
-
-	return rc;
-}
-#if 0
-/** Schedule interrupt out transfer.
- *
- * The callback is supposed to be called once the transfer (on the wire) is
- * complete regardless of the outcome.
- * However, the callback could be called only when this function returns
- * with success status (i.e. returns EOK).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] target Target pipe (address and endpoint number) specification.
- * @param[in] data Data to be sent (in USB endianess, allocated and deallocated
- *	by the caller).
- * @param[in] size Size of the @p data buffer in bytes.
- * @param[in] callback Callback to be issued once the transfer is complete.
- * @param[in] arg Pass-through argument to the callback.
- * @return Error code.
- */
-static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	VHC_DATA(vhc, fun);
-
-	vhc_transfer_t *transfer = vhc_transfer_create(target.address,
-	    target.endpoint, USB_DIRECTION_OUT, USB_TRANSFER_INTERRUPT,
-	    fun, arg);
-	if (transfer == NULL) {
-		return ENOMEM;
-	}
-
-	transfer->data_buffer = data;
-	transfer->data_buffer_size = size;
-	transfer->callback_out = callback;
-
-	int rc = vhc_virtdev_add_transfer(vhc, transfer);
-	if (rc != EOK) {
-		free(transfer);
-		return rc;
-	}
-
-	return EOK;
-}
-
-/** Schedule interrupt in transfer.
- *
- * The callback is supposed to be called once the transfer (on the wire) is
- * complete regardless of the outcome.
- * However, the callback could be called only when this function returns
- * with success status (i.e. returns EOK).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] target Target pipe (address and endpoint number) specification.
- * @param[in] data Buffer where to store the data (in USB endianess,
- *	allocated and deallocated by the caller).
- * @param[in] size Size of the @p data buffer in bytes.
- * @param[in] callback Callback to be issued once the transfer is complete.
- * @param[in] arg Pass-through argument to the callback.
- * @return Error code.
- */
-static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_in_callback_t callback, void *arg)
-{
-	VHC_DATA(vhc, fun);
-
-	vhc_transfer_t *transfer = vhc_transfer_create(target.address,
-	    target.endpoint, USB_DIRECTION_IN, USB_TRANSFER_INTERRUPT,
-	    fun, arg);
-	if (transfer == NULL) {
-		return ENOMEM;
-	}
-
-	transfer->data_buffer = data;
-	transfer->data_buffer_size = size;
-	transfer->callback_in = callback;
-
-	int rc = vhc_virtdev_add_transfer(vhc, transfer);
-	if (rc != EOK) {
-		free(transfer);
-		return rc;
-	}
-
-	return EOK;
-}
-
-/** Schedule bulk out transfer.
- *
- * The callback is supposed to be called once the transfer (on the wire) is
- * complete regardless of the outcome.
- * However, the callback could be called only when this function returns
- * with success status (i.e. returns EOK).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] target Target pipe (address and endpoint number) specification.
- * @param[in] data Data to be sent (in USB endianess, allocated and deallocated
- *	by the caller).
- * @param[in] size Size of the @p data buffer in bytes.
- * @param[in] callback Callback to be issued once the transfer is complete.
- * @param[in] arg Pass-through argument to the callback.
- * @return Error code.
- */
-static int bulk_out(ddf_fun_t *fun, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	UNSUPPORTED("bulk_out");
-
-	return ENOTSUP;
-}
-
-/** Schedule bulk in transfer.
- *
- * The callback is supposed to be called once the transfer (on the wire) is
- * complete regardless of the outcome.
- * However, the callback could be called only when this function returns
- * with success status (i.e. returns EOK).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] target Target pipe (address and endpoint number) specification.
- * @param[in] data Buffer where to store the data (in USB endianess,
- *	allocated and deallocated by the caller).
- * @param[in] size Size of the @p data buffer in bytes.
- * @param[in] callback Callback to be issued once the transfer is complete.
- * @param[in] arg Pass-through argument to the callback.
- * @return Error code.
- */
-static int bulk_in(ddf_fun_t *fun, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_in_callback_t callback, void *arg)
-{
-	UNSUPPORTED("bulk_in");
-
-	return ENOTSUP;
-}
-
-/** Schedule control write transfer.
- *
- * The callback is supposed to be called once the transfer (on the wire) is
- * complete regardless of the outcome.
- * However, the callback could be called only when this function returns
- * with success status (i.e. returns EOK).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] target Target pipe (address and endpoint number) specification.
- * @param[in] setup_packet Setup packet buffer (in USB endianess, allocated
- *	and deallocated by the caller).
- * @param[in] setup_packet_size Size of @p setup_packet buffer in bytes.
- * @param[in] data_buffer Data buffer (in USB endianess, allocated and
- *	deallocated by the caller).
- * @param[in] data_buffer_size Size of @p data_buffer buffer in bytes.
- * @param[in] callback Callback to be issued once the transfer is complete.
- * @param[in] arg Pass-through argument to the callback.
- * @return Error code.
- */
-static int control_write(ddf_fun_t *fun, usb_target_t target,
-    void *setup_packet, size_t setup_packet_size,
-    void *data_buffer, size_t data_buffer_size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	VHC_DATA(vhc, fun);
-
-	vhc_transfer_t *transfer = vhc_transfer_create(target.address,
-	    target.endpoint, USB_DIRECTION_OUT, USB_TRANSFER_CONTROL,
-	    fun, arg);
-	if (transfer == NULL) {
-		return ENOMEM;
-	}
-
-	transfer->setup_buffer = setup_packet;
-	transfer->setup_buffer_size = setup_packet_size;
-	transfer->data_buffer = data_buffer;
-	transfer->data_buffer_size = data_buffer_size;
-	transfer->callback_out = callback;
-
-	int rc = vhc_virtdev_add_transfer(vhc, transfer);
-	if (rc != EOK) {
-		free(transfer);
-		return rc;
-	}
-
-	return EOK;
-}
-
-/** Schedule control read transfer.
- *
- * The callback is supposed to be called once the transfer (on the wire) is
- * complete regardless of the outcome.
- * However, the callback could be called only when this function returns
- * with success status (i.e. returns EOK).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] target Target pipe (address and endpoint number) specification.
- * @param[in] setup_packet Setup packet buffer (in USB endianess, allocated
- *	and deallocated by the caller).
- * @param[in] setup_packet_size Size of @p setup_packet buffer in bytes.
- * @param[in] data_buffer Buffer where to store the data (in USB endianess,
- *	allocated and deallocated by the caller).
- * @param[in] data_buffer_size Size of @p data_buffer buffer in bytes.
- * @param[in] callback Callback to be issued once the transfer is complete.
- * @param[in] arg Pass-through argument to the callback.
- * @return Error code.
- */
-static int control_read(ddf_fun_t *fun, usb_target_t target,
-    void *setup_packet, size_t setup_packet_size,
-    void *data_buffer, size_t data_buffer_size,
-    usbhc_iface_transfer_in_callback_t callback, void *arg)
-{
-	VHC_DATA(vhc, fun);
-
-	vhc_transfer_t *transfer = vhc_transfer_create(target.address,
-	    target.endpoint, USB_DIRECTION_IN, USB_TRANSFER_CONTROL,
-	    fun, arg);
-	if (transfer == NULL) {
-		return ENOMEM;
-	}
-
-	transfer->setup_buffer = setup_packet;
-	transfer->setup_buffer_size = setup_packet_size;
-	transfer->data_buffer = data_buffer;
-	transfer->data_buffer_size = data_buffer_size;
-	transfer->callback_in = callback;
-
-	int rc = vhc_virtdev_add_transfer(vhc, transfer);
-	if (rc != EOK) {
-		free(transfer);
-		return rc;
-	}
-
-	return EOK;
-}
-#endif
-static int usb_read(ddf_fun_t *fun, usb_target_t target, uint64_t setup_buffer,
-    uint8_t *data_buffer, size_t data_buffer_size,
-    usbhc_iface_transfer_in_callback_t callback, void *arg)
-{
-	VHC_DATA(vhc, fun);
-
-	endpoint_t *ep = usb_endpoint_manager_find_ep(&vhc->ep_manager,
-	    target.address, target.endpoint, USB_DIRECTION_IN);
-	if (ep == NULL) {
-		return ENOENT;
-	}
-	const usb_transfer_type_t transfer_type = ep->transfer_type;
-
-
-	vhc_transfer_t *transfer = vhc_transfer_create(target.address,
-	    target.endpoint, USB_DIRECTION_IN, transfer_type,
-	    fun, arg);
-	if (transfer == NULL) {
-		return ENOMEM;
-	}
-	if (transfer_type == USB_TRANSFER_CONTROL) {
-		transfer->setup_buffer = malloc(sizeof(uint64_t));
-		assert(transfer->setup_buffer);
-		memcpy(transfer->setup_buffer, &setup_buffer, sizeof(uint64_t));
-		transfer->setup_buffer_size = sizeof(uint64_t);
-	}
-	transfer->data_buffer = data_buffer;
-	transfer->data_buffer_size = data_buffer_size;
-	transfer->callback_in = callback;
-
-	int rc = vhc_virtdev_add_transfer(vhc, transfer);
-	if (rc != EOK) {
-		if (transfer->setup_buffer != NULL) {
-			free(transfer->setup_buffer);
-		}
-		free(transfer);
-		return rc;
-	}
-
-	return EOK;
-}
-
-static int usb_write(ddf_fun_t *fun, usb_target_t target, uint64_t setup_buffer,
-    const uint8_t *data_buffer, size_t data_buffer_size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	VHC_DATA(vhc, fun);
-
-	endpoint_t *ep = usb_endpoint_manager_find_ep(&vhc->ep_manager,
-	    target.address, target.endpoint, USB_DIRECTION_OUT);
-	if (ep == NULL) {
-		return ENOENT;
-	}
-	const usb_transfer_type_t transfer_type = ep->transfer_type;
-
-
-	vhc_transfer_t *transfer = vhc_transfer_create(target.address,
-	    target.endpoint, USB_DIRECTION_OUT, transfer_type,
-	    fun, arg);
-	if (transfer == NULL) {
-		return ENOMEM;
-	}
-	if (transfer_type == USB_TRANSFER_CONTROL) {
-		transfer->setup_buffer = malloc(sizeof(uint64_t));
-		assert(transfer->setup_buffer);
-		memcpy(transfer->setup_buffer, &setup_buffer, sizeof(uint64_t));
-		transfer->setup_buffer_size = sizeof(uint64_t);
-	}
-	transfer->data_buffer = (void*)data_buffer;
-	transfer->data_buffer_size = data_buffer_size;
-	transfer->callback_out = callback;
-
-	int rc = vhc_virtdev_add_transfer(vhc, transfer);
-	if (rc != EOK) {
-		free(transfer->setup_buffer);
-		free(transfer);
-		return rc;
-	}
-
-	return EOK;
-}
-
-static int tell_address(ddf_fun_t *fun, usb_address_t *address)
-{
-	UNSUPPORTED("tell_address");
-
-	return ENOTSUP;
-}
-
-static int usb_iface_get_hc_handle_rh_impl(ddf_fun_t *root_hub_fun,
-    devman_handle_t *handle)
-{
-	VHC_DATA(vhc, root_hub_fun);
-
-	*handle = ddf_fun_get_handle(vhc->hc_fun);
-
-	return EOK;
-}
-
-static int tell_address_rh(ddf_fun_t *root_hub_fun, usb_address_t *address)
-{
-	VHC_DATA(vhc, root_hub_fun);
-
-	devman_handle_t handle = ddf_fun_get_handle(root_hub_fun);
-
-	usb_log_debug("tell_address_rh(handle=%" PRIun ")\n", handle);
-	const usb_address_t addr =
-	    usb_device_manager_find_address(&vhc->dev_manager, handle);
-	if (addr < 0) {
-		return addr;
-	} else {
-		*address = addr;
-		return EOK;
-	}
-}
-
-usbhc_iface_t vhc_iface = {
-	.request_address = request_address,
-	.bind_address = bind_address,
-	.get_handle = find_by_address,
-	.release_address = release_address,
-
-	.register_endpoint = register_endpoint,
-	.unregister_endpoint = unregister_endpoint,
-
-	.write = usb_write,
-	.read = usb_read,
-};
-
-usb_iface_t vhc_usb_iface = {
-	.get_hc_handle = usb_iface_get_hc_handle_hc_impl,
-	.get_my_address = tell_address
-};
-
-usb_iface_t rh_usb_iface = {
-	.get_hc_handle = usb_iface_get_hc_handle_rh_impl,
-	.get_my_address = tell_address_rh
-};
-
-
-/**
- * @}
- */
Index: uspace/drv/bus/usb/vhc/devconn.c
===================================================================
--- uspace/drv/bus/usb/vhc/devconn.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/vhc/devconn.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -51,5 +51,5 @@
 static int vhc_virtdev_plug_generic(vhc_data_t *vhc,
     async_sess_t *sess, usbvirt_device_t *virtdev,
-    uintptr_t *handle, bool connect)
+    uintptr_t *handle, bool connect, usb_address_t address)
 {
 	vhc_virtdev_t *dev = vhc_virtdev_create();
@@ -60,4 +60,5 @@
 	dev->dev_sess = sess;
 	dev->dev_local = virtdev;
+	dev->address = address;
 
 	fibril_mutex_lock(&vhc->guard);
@@ -78,5 +79,5 @@
 	if (connect) {
 		// FIXME: check status
-		(void) virthub_connect_device(vhc->hub, dev);
+		(void) virthub_connect_device(&vhc->hub, dev);
 	}
 
@@ -86,15 +87,15 @@
 int vhc_virtdev_plug(vhc_data_t *vhc, async_sess_t *sess, uintptr_t *handle)
 {
-	return vhc_virtdev_plug_generic(vhc, sess, NULL, handle, true);
+	return vhc_virtdev_plug_generic(vhc, sess, NULL, handle, true, 0);
 }
 
 int vhc_virtdev_plug_local(vhc_data_t *vhc, usbvirt_device_t *dev, uintptr_t *handle)
 {
-	return vhc_virtdev_plug_generic(vhc, NULL, dev, handle, true);
+	return vhc_virtdev_plug_generic(vhc, NULL, dev, handle, true, 0);
 }
 
-int vhc_virtdev_plug_hub(vhc_data_t *vhc, usbvirt_device_t *dev, uintptr_t *handle)
+int vhc_virtdev_plug_hub(vhc_data_t *vhc, usbvirt_device_t *dev, uintptr_t *handle, usb_address_t address)
 {
-	return vhc_virtdev_plug_generic(vhc, NULL, dev, handle, false);
+	return vhc_virtdev_plug_generic(vhc, NULL, dev, handle, false, address);
 }
 
@@ -104,5 +105,5 @@
 
 	// FIXME: check status
-	(void) virthub_disconnect_device(vhc->hub, dev);
+	(void) virthub_disconnect_device(&vhc->hub, dev);
 
 	fibril_mutex_lock(&vhc->guard);
Index: uspace/drv/bus/usb/vhc/hub.c
===================================================================
--- uspace/drv/bus/usb/vhc/hub.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,132 +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.
- */
-
-/** @addtogroup drvusbvhc
- * @{
- */
-/** @file
- * @brief Virtual USB hub.
- */
-
-#include <usb/classes/classes.h>
-#include <usbvirt/device.h>
-#include <errno.h>
-#include <async.h>
-#include <str_error.h>
-#include <stdlib.h>
-#include <ddf/driver.h>
-#include <devman.h>
-#include <usb/dev/hub.h>
-#include <usb/dev/recognise.h>
-
-#include "hub.h"
-#include "vhcd.h"
-#include "conn.h"
-
-usbvirt_device_t virtual_hub_device = {
-	.name = "root hub",
-	.ops = &hub_ops,
-	.address = 0
-};
-
-static ddf_dev_ops_t rh_ops = {
-	.interfaces[USB_DEV_IFACE] = &rh_usb_iface,
-};
-
-static int hub_register_in_devman_fibril(void *arg);
-
-void virtual_hub_device_init(ddf_fun_t *hc_dev)
-{
-	virthub_init(&virtual_hub_device);
-
-	/*
-	 * We need to register the root hub.
-	 * This must be done in separate fibril because the device
-	 * we are connecting to are ourselves and we cannot connect
-	 * before leaving the add_device() function.
-	 */
-	fid_t root_hub_registration
-	    = fibril_create(hub_register_in_devman_fibril, hc_dev);
-	if (root_hub_registration == 0) {
-		usb_log_fatal("Failed to create hub registration fibril.\n");
-		return;
-	}
-
-	fibril_add_ready(root_hub_registration);
-}
-
-static int pretend_port_rest(void *unused2)
-{
-	return EOK;
-}
-
-/** Register root hub in devman.
- *
- * @param arg Host controller device (type <code>device_t *</code>).
- * @return Error code.
- */
-int hub_register_in_devman_fibril(void *arg)
-{
-	ddf_fun_t *hc_dev = (ddf_fun_t *) arg;
-	int rc;
-
-	usb_hc_connection_t hc_conn;
-	usb_hc_connection_initialize(&hc_conn, ddf_fun_get_handle(hc_dev));
-
-	rc = usb_hc_connection_open(&hc_conn);
-	assert(rc == EOK);
-
-	ddf_fun_t *hub_dev;
-
-	hub_dev = ddf_fun_create(ddf_fun_get_dev(hc_dev), fun_inner, NULL);
-	if (hub_dev == NULL) {
-		rc = ENOMEM;
-		usb_log_fatal("Failed to create root hub: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-
-	rc = usb_hc_new_device_wrapper(ddf_fun_get_dev(hc_dev), hub_dev,
-	    &hc_conn, USB_SPEED_FULL, pretend_port_rest, NULL, NULL, &rh_ops);
-	if (rc != EOK) {
-		usb_log_fatal("Failed to create root hub: %s.\n",
-		    str_error(rc));
-		ddf_fun_destroy(hub_dev);
-	}
-
-	usb_hc_connection_close(&hc_conn);
-
-	usb_log_info("Created root hub function (handle %zu).\n",
-	    (size_t) ddf_fun_get_handle(hub_dev));
-
-	return 0;
-}
-
-/**
- * @}
- */
Index: uspace/drv/bus/usb/vhc/hub.h
===================================================================
--- uspace/drv/bus/usb/vhc/hub.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ 	(revision )
@@ -1,52 +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.
- */
-
-/** @addtogroup drvusbvhc
- * @{
- */
-/** @file
- * @brief Virtual USB hub.
- */
-
-#ifndef VHCD_HUB_H_
-#define VHCD_HUB_H_
-
-#include <usbvirt/device.h>
-#include <ddf/driver.h>
-
-#include "hub/hub.h"
-#include "hub/virthub.h"
-
-extern usbvirt_device_t virtual_hub_device;
-
-void virtual_hub_device_init(ddf_fun_t *);
-
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/vhc/hub/virthub.c
===================================================================
--- uspace/drv/bus/usb/vhc/hub/virthub.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/vhc/hub/virthub.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -34,8 +34,10 @@
  */
 #include <usb/classes/classes.h>
+#include <usb/classes/hub.h>
 #include <usbvirt/device.h>
 #include <assert.h>
 #include <errno.h>
 #include <str_error.h>
+#include <stdio.h>
 #include <assert.h>
 #include <stdlib.h>
@@ -76,5 +78,5 @@
 	.type = USB_DESCTYPE_HUB,
 	.port_count = HUB_PORT_COUNT,
-	.characteristics = 0, 
+	.characteristics = HUB_CHAR_NO_POWER_SWITCH_FLAG | HUB_CHAR_NO_OC_FLAG,
 	.power_on_warm_up = 50, /* Huh? */
 	.max_current = 100, /* Huh again. */
@@ -97,5 +99,5 @@
 	.length = sizeof(usb_standard_configuration_descriptor_t),
 	.descriptor_type = USB_DESCTYPE_CONFIGURATION,
-	.total_length = 
+	.total_length =
 		sizeof(usb_standard_configuration_descriptor_t)
 		+ sizeof(std_interface_descriptor)
@@ -145,5 +147,5 @@
  * @return Error code.
  */
-int virthub_init(usbvirt_device_t *dev)
+int virthub_init(usbvirt_device_t *dev, const char* name)
 {
 	if (dev == NULL) {
@@ -152,7 +154,12 @@
 	dev->ops = &hub_ops;
 	dev->descriptors = &descriptors;
+	dev->address = 0;
+	dev->name = str_dup(name);
+	if (!dev->name)
+		return ENOMEM;
 
 	hub_t *hub = malloc(sizeof(hub_t));
 	if (hub == NULL) {
+		free(dev->name);
 		return ENOMEM;
 	}
Index: uspace/drv/bus/usb/vhc/hub/virthub.h
===================================================================
--- uspace/drv/bus/usb/vhc/hub/virthub.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/vhc/hub/virthub.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -79,5 +79,5 @@
 extern hub_descriptor_t hub_descriptor;
 
-int virthub_init(usbvirt_device_t *);
+int virthub_init(usbvirt_device_t *, const char *name);
 int virthub_connect_device(usbvirt_device_t *, vhc_virtdev_t *);
 int virthub_disconnect_device(usbvirt_device_t *, vhc_virtdev_t *);
Index: uspace/drv/bus/usb/vhc/hub/virthubops.c
===================================================================
--- uspace/drv/bus/usb/vhc/hub/virthubops.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/vhc/hub/virthubops.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -340,12 +340,4 @@
 
 
-/** IN class request. */
-#define CLASS_REQ_IN(recipient) \
-	USBVIRT_MAKE_CONTROL_REQUEST_TYPE(USB_DIRECTION_IN, \
-	USBVIRT_REQUEST_TYPE_CLASS, recipient)
-/** OUT class request. */
-#define CLASS_REQ_OUT(recipient) \
-	USBVIRT_MAKE_CONTROL_REQUEST_TYPE(USB_DIRECTION_OUT, \
-	USBVIRT_REQUEST_TYPE_CLASS, recipient)
 
 /** Recipient: other. */
@@ -353,88 +345,60 @@
 /** Recipient: device. */
 #define REC_DEVICE USB_REQUEST_RECIPIENT_DEVICE
-/** Direction: in. */
-#define DIR_IN USB_DIRECTION_IN
-/** Direction: out. */
-#define DIR_OUT USB_DIRECTION_OUT
-
-
-/** Create a class request.
- *
- * @param direction Request direction.
- * @param recipient Request recipient.
- * @param req Request code.
- */
-#define CLASS_REQ(direction, recipient, req) \
-	.req_direction = direction, \
-	.req_recipient = recipient, \
-	.req_type = USB_REQUEST_TYPE_CLASS, \
-	.request = req
-
-/** Create a standard request.
- *
- * @param direction Request direction.
- * @param recipient Request recipient.
- * @param req Request code.
- */
-#define STD_REQ(direction, recipient, req) \
-	.req_direction = direction, \
-	.req_recipient = recipient, \
-	.req_type = USB_REQUEST_TYPE_STANDARD, \
-	.request = req
+
 
 /** Hub operations on control endpoint zero. */
 static usbvirt_control_request_handler_t endpoint_zero_handlers[] = {
 	{
-		STD_REQ(DIR_IN, REC_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		STD_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
 		.name = "GetDescriptor",
 		.callback = req_get_descriptor
 	},
 	{
-		CLASS_REQ(DIR_IN, REC_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		CLASS_REQ_IN(REC_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
 		.name = "GetDescriptor",
 		.callback = req_get_descriptor
 	},
 	{
-		CLASS_REQ(DIR_IN, REC_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		CLASS_REQ_IN(REC_OTHER, USB_HUB_REQUEST_GET_STATUS),
 		.name = "GetPortStatus",
 		.callback = req_get_port_status
 	},
 	{
-		CLASS_REQ(DIR_OUT, REC_DEVICE, USB_HUB_REQUEST_CLEAR_FEATURE),
+		CLASS_REQ_OUT(REC_DEVICE, USB_HUB_REQUEST_CLEAR_FEATURE),
 		.name = "ClearHubFeature",
 		.callback = req_clear_hub_feature
 	},
 	{
-		CLASS_REQ(DIR_OUT, REC_OTHER, USB_HUB_REQUEST_CLEAR_FEATURE),
+		CLASS_REQ_OUT(REC_OTHER, USB_HUB_REQUEST_CLEAR_FEATURE),
 		.name = "ClearPortFeature",
 		.callback = req_clear_port_feature
 	},
 	{
-		CLASS_REQ(DIR_IN, REC_OTHER, USB_HUB_REQUEST_GET_STATE),
+		CLASS_REQ_IN(REC_OTHER, USB_HUB_REQUEST_GET_STATE),
 		.name = "GetBusState",
 		.callback = req_get_bus_state
 	},
 	{
-		CLASS_REQ(DIR_IN, REC_DEVICE, USB_HUB_REQUEST_GET_DESCRIPTOR),
+		CLASS_REQ_IN(REC_DEVICE, USB_HUB_REQUEST_GET_DESCRIPTOR),
 		.name = "GetHubDescriptor",
 		.callback = req_get_descriptor
 	},
 	{
-		CLASS_REQ(DIR_IN, REC_DEVICE, USB_HUB_REQUEST_GET_STATUS),
+		CLASS_REQ_IN(REC_DEVICE, USB_HUB_REQUEST_GET_STATUS),
 		.name = "GetHubStatus",
 		.callback = req_get_hub_status
 	},
 	{
-		CLASS_REQ(DIR_IN, REC_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		CLASS_REQ_IN(REC_OTHER, USB_HUB_REQUEST_GET_STATUS),
 		.name = "GetPortStatus",
 		.callback = req_get_port_status
 	},
 	{
-		CLASS_REQ(DIR_OUT, REC_DEVICE, USB_HUB_REQUEST_SET_FEATURE),
+		CLASS_REQ_OUT(REC_DEVICE, USB_HUB_REQUEST_SET_FEATURE),
 		.name = "SetHubFeature",
 		.callback = req_set_hub_feature
 	},
 	{
-		CLASS_REQ(DIR_OUT, REC_OTHER, USB_HUB_REQUEST_SET_FEATURE),
+		CLASS_REQ_OUT(REC_OTHER, USB_HUB_REQUEST_SET_FEATURE),
 		.name = "SetPortFeature",
 		.callback = req_set_port_feature
Index: uspace/drv/bus/usb/vhc/main.c
===================================================================
--- uspace/drv/bus/usb/vhc/main.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/vhc/main.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -34,9 +34,4 @@
  */
 
-#include <loc.h>
-#include <async.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sysinfo.h>
 #include <stdio.h>
 #include <errno.h>
@@ -44,84 +39,82 @@
 #include <ddf/driver.h>
 
-#include <usb/usb.h>
-#include <usb/ddfiface.h>
-#include <usb_iface.h>
+#include <usb/host/ddf_helpers.h>
+
+#include <usb/debug.h>
 #include "vhcd.h"
-#include "hub.h"
-#include "conn.h"
+
 
 static ddf_dev_ops_t vhc_ops = {
-	.interfaces[USBHC_DEV_IFACE] = &vhc_iface,
-	.interfaces[USB_DEV_IFACE] = &vhc_usb_iface,
 	.close = on_client_close,
 	.default_handler = default_connection_handler
 };
 
+static int vhc_control_node(ddf_dev_t *dev, ddf_fun_t **fun)
+{
+	assert(dev);
+	assert(fun);
+
+	*fun = ddf_fun_create(dev, fun_exposed, "ctl");
+	if (!*fun)
+		return ENOMEM;
+
+	vhc_data_t *vhc = ddf_fun_data_alloc(*fun, sizeof(vhc_data_t));
+	if (!vhc) {
+		ddf_fun_destroy(*fun);
+	}
+	ddf_fun_set_ops(*fun, &vhc_ops);
+	const int ret = ddf_fun_bind(*fun);
+	if (ret != EOK) {
+		ddf_fun_destroy(*fun);
+		*fun = NULL;
+		return ret;
+	}
+	vhc_init(vhc);
+	return EOK;
+}
+
 static int vhc_dev_add(ddf_dev_t *dev)
 {
-	static int vhc_count = 0;
-	int rc;
+	/* Initialize virtual structure */
+	ddf_fun_t *ctl_fun = NULL;
+	int ret = vhc_control_node(dev, &ctl_fun);
+	if (ret != EOK) {
+		usb_log_error("Failed to setup control node.\n");
+		return ret;
+	}
+	vhc_data_t *data = ddf_fun_data_get(ctl_fun);
 
-	if (vhc_count > 0) {
-		return ELIMIT;
+	/* Initialize generic structures */
+	ret = hcd_ddf_setup_hc(dev, USB_SPEED_FULL,
+	    BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
+	if (ret != EOK) {
+		usb_log_error("Failed to init HCD structures: %s.\n",
+		   str_error(ret));
+		ddf_fun_destroy(ctl_fun);
+		return ret;
 	}
 
-	vhc_data_t *data = ddf_dev_data_alloc(dev, sizeof(vhc_data_t));
-	if (data == NULL) {
-		usb_log_fatal("Failed to allocate memory.\n");
-		return ENOMEM;
-	}
-	data->magic = 0xDEADBEEF;
-	rc = usb_endpoint_manager_init(&data->ep_manager, (size_t) -1,
-	    bandwidth_count_usb11);
-	if (rc != EOK) {
-		usb_log_fatal("Failed to initialize endpoint manager.\n");
-		free(data);
-		return rc;
-	}
-	usb_device_manager_init(&data->dev_manager, USB_SPEED_MAX);
+	hcd_set_implementation(dev_to_hcd(dev), data, vhc_schedule, NULL, NULL, NULL, NULL);
 
-	ddf_fun_t *hc = ddf_fun_create(dev, fun_exposed, "hc");
-	if (hc == NULL) {
-		usb_log_fatal("Failed to create device function.\n");
-		free(data);
-		return ENOMEM;
+	/* Add virtual hub device */
+	ret = vhc_virtdev_plug_hub(data, &data->hub, NULL, 0);
+	if (ret != EOK) {
+		usb_log_error("Failed to plug root hub: %s.\n", str_error(ret));
+		ddf_fun_destroy(ctl_fun);
+		return ret;
 	}
 
-	ddf_fun_set_ops(hc, &vhc_ops);
-	list_initialize(&data->devices);
-	fibril_mutex_initialize(&data->guard);
-	data->hub = &virtual_hub_device;
-	data->hc_fun = hc;
-
-	rc = ddf_fun_bind(hc);
-	if (rc != EOK) {
-		usb_log_fatal("Failed to bind HC function: %s.\n",
-		    str_error(rc));
-		free(data);
-		return rc;
+	/*
+	 * Creating root hub registers a new USB device so HC
+	 * needs to be ready at this time.
+	 */
+	ret = hcd_ddf_setup_root_hub(dev);
+	if (ret != EOK) {
+		usb_log_error("Failed to init VHC root hub: %s\n",
+			str_error(ret));
+		// TODO do something here...
 	}
 
-	rc = ddf_fun_add_to_category(hc, USB_HC_CATEGORY);
-	if (rc != EOK) {
-		usb_log_fatal("Failed to add function to HC class: %s.\n",
-		    str_error(rc));
-		free(data);
-		return rc;
-	}
-
-	virtual_hub_device_init(hc);
-
-	usb_log_info("Virtual USB host controller ready (dev %zu, hc %zu).\n",
-	    (size_t) ddf_dev_get_handle(dev), (size_t) ddf_fun_get_handle(hc));
-
-	rc = vhc_virtdev_plug_hub(data, data->hub, NULL);
-	if (rc != EOK) {
-		usb_log_fatal("Failed to plug root hub: %s.\n", str_error(rc));
-		free(data);
-		return rc;
-	}
-
-	return EOK;
+	return ret;
 }
 
@@ -135,9 +128,7 @@
 };
 
-
 int main(int argc, char * argv[])
-{	
+{
 	log_init(NAME);
-
 	printf(NAME ": virtual USB host controller driver.\n");
 
@@ -145,5 +136,4 @@
 }
 
-
 /**
  * @}
Index: uspace/drv/bus/usb/vhc/transfer.c
===================================================================
--- uspace/drv/bus/usb/vhc/transfer.c	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/vhc/transfer.c	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -29,52 +29,23 @@
 #include <errno.h>
 #include <str_error.h>
+#include <usb/debug.h>
 #include <usbvirt/device.h>
 #include <usbvirt/ipc.h>
 #include "vhcd.h"
-
-vhc_transfer_t *vhc_transfer_create(usb_address_t address, usb_endpoint_t ep,
-    usb_direction_t dir, usb_transfer_type_t tr_type,
-    ddf_fun_t *fun, void *callback_arg)
-{
-	vhc_transfer_t *result = malloc(sizeof(vhc_transfer_t));
-	if (result == NULL) {
-		return NULL;
-	}
-	link_initialize(&result->link);
-	result->address = address;
-	result->endpoint = ep;
-	result->direction = dir;
-	result->transfer_type = tr_type;
-	result->setup_buffer = NULL;
-	result->setup_buffer_size = 0;
-	result->data_buffer = NULL;
-	result->data_buffer_size = 0;
-	result->ddf_fun = fun;
-	result->callback_arg = callback_arg;
-	result->callback_in = NULL;
-	result->callback_out = NULL;
-
-	usb_log_debug2("Created transfer %p (%d.%d %s %s)\n", result,
-	    address, ep, usb_str_transfer_type_short(tr_type),
-	    dir == USB_DIRECTION_IN ? "in" : "out");
-
-	return result;
-}
+#include "hub/virthub.h"
 
 static bool is_set_address_transfer(vhc_transfer_t *transfer)
 {
-	if (transfer->endpoint != 0) {
-		return false;
-	}
-	if (transfer->transfer_type != USB_TRANSFER_CONTROL) {
-		return false;
-	}
-	if (transfer->direction != USB_DIRECTION_OUT) {
-		return false;
-	}
-	if (transfer->setup_buffer_size != sizeof(usb_device_request_setup_packet_t)) {
-		return false;
-	}
-	usb_device_request_setup_packet_t *setup = transfer->setup_buffer;
+	if (transfer->batch->ep->endpoint != 0) {
+		return false;
+	}
+	if (transfer->batch->ep->transfer_type != USB_TRANSFER_CONTROL) {
+		return false;
+	}
+	if (usb_transfer_batch_direction(transfer->batch) != USB_DIRECTION_OUT) {
+		return false;
+	}
+	const usb_device_request_setup_packet_t *setup =
+	    (void*)transfer->batch->setup_buffer;
 	if (setup->request_type != 0) {
 		return false;
@@ -87,94 +58,70 @@
 }
 
-int vhc_virtdev_add_transfer(vhc_data_t *vhc, vhc_transfer_t *transfer)
-{
-	fibril_mutex_lock(&vhc->guard);
-
-	bool target_found = false;
-	list_foreach(vhc->devices, link, vhc_virtdev_t, dev) {
-		fibril_mutex_lock(&dev->guard);
-		if (dev->address == transfer->address) {
-			if (target_found) {
-				usb_log_warning("Transfer would be accepted by more devices!\n");
-				goto next;
-			}
-			target_found = true;
-			list_append(&transfer->link, &dev->transfer_queue);
-		}
-next:
-		fibril_mutex_unlock(&dev->guard);
-	}
-
-	fibril_mutex_unlock(&vhc->guard);
-
-	if (target_found) {
-		return EOK;
+static int process_transfer_local(usb_transfer_batch_t *batch,
+    usbvirt_device_t *dev, size_t *actual_data_size)
+{
+	int rc;
+	
+	const usb_direction_t dir = usb_transfer_batch_direction(batch);
+
+	if (batch->ep->transfer_type == USB_TRANSFER_CONTROL) {
+		if (dir == USB_DIRECTION_IN) {
+			rc = usbvirt_control_read(dev,
+			    batch->setup_buffer, batch->setup_size,
+			    batch->buffer, batch->buffer_size,
+			    actual_data_size);
+		} else {
+			assert(dir == USB_DIRECTION_OUT);
+			rc = usbvirt_control_write(dev,
+			    batch->setup_buffer, batch->setup_size,
+			    batch->buffer, batch->buffer_size);
+		}
 	} else {
-		return ENOENT;
-	}
-}
-
-static int process_transfer_local(vhc_transfer_t *transfer,
-    usbvirt_device_t *dev, size_t *actual_data_size)
+		if (dir == USB_DIRECTION_IN) {
+			rc = usbvirt_data_in(dev, batch->ep->transfer_type,
+			    batch->ep->endpoint,
+			    batch->buffer, batch->buffer_size,
+			    actual_data_size);
+		} else {
+			assert(dir == USB_DIRECTION_OUT);
+			rc = usbvirt_data_out(dev, batch->ep->transfer_type,
+			    batch->ep->endpoint,
+			    batch->buffer, batch->buffer_size);
+		}
+	}
+
+	return rc;
+}
+
+static int process_transfer_remote(usb_transfer_batch_t *batch,
+    async_sess_t *sess, size_t *actual_data_size)
 {
 	int rc;
 
-	if (transfer->transfer_type == USB_TRANSFER_CONTROL) {
-		if (transfer->direction == USB_DIRECTION_IN) {
-			rc = usbvirt_control_read(dev,
-			    transfer->setup_buffer, transfer->setup_buffer_size,
-			    transfer->data_buffer, transfer->data_buffer_size,
-			    actual_data_size);
-		} else {
-			assert(transfer->direction == USB_DIRECTION_OUT);
-			rc = usbvirt_control_write(dev,
-			    transfer->setup_buffer, transfer->setup_buffer_size,
-			    transfer->data_buffer, transfer->data_buffer_size);
+	const usb_direction_t dir = usb_transfer_batch_direction(batch);
+
+	if (batch->ep->transfer_type == USB_TRANSFER_CONTROL) {
+		if (dir == USB_DIRECTION_IN) {
+			rc = usbvirt_ipc_send_control_read(sess,
+			    batch->setup_buffer, batch->setup_size,
+			    batch->buffer, batch->buffer_size,
+			    actual_data_size);
+		} else {
+			assert(dir == USB_DIRECTION_OUT);
+			rc = usbvirt_ipc_send_control_write(sess,
+			    batch->setup_buffer, batch->setup_size,
+			    batch->buffer, batch->buffer_size);
 		}
 	} else {
-		if (transfer->direction == USB_DIRECTION_IN) {
-			rc = usbvirt_data_in(dev, transfer->transfer_type,
-			    transfer->endpoint,
-			    transfer->data_buffer, transfer->data_buffer_size,
-			    actual_data_size);
-		} else {
-			assert(transfer->direction == USB_DIRECTION_OUT);
-			rc = usbvirt_data_out(dev, transfer->transfer_type,
-			    transfer->endpoint,
-			    transfer->data_buffer, transfer->data_buffer_size);
-		}
-	}
-
-	return rc;
-}
-
-static int process_transfer_remote(vhc_transfer_t *transfer,
-    async_sess_t *sess, size_t *actual_data_size)
-{
-	int rc;
-
-	if (transfer->transfer_type == USB_TRANSFER_CONTROL) {
-		if (transfer->direction == USB_DIRECTION_IN) {
-			rc = usbvirt_ipc_send_control_read(sess,
-			    transfer->setup_buffer, transfer->setup_buffer_size,
-			    transfer->data_buffer, transfer->data_buffer_size,
-			    actual_data_size);
-		} else {
-			assert(transfer->direction == USB_DIRECTION_OUT);
-			rc = usbvirt_ipc_send_control_write(sess,
-			    transfer->setup_buffer, transfer->setup_buffer_size,
-			    transfer->data_buffer, transfer->data_buffer_size);
-		}
-	} else {
-		if (transfer->direction == USB_DIRECTION_IN) {
-			rc = usbvirt_ipc_send_data_in(sess, transfer->endpoint,
-			    transfer->transfer_type,
-			    transfer->data_buffer, transfer->data_buffer_size,
-			    actual_data_size);
-		} else {
-			assert(transfer->direction == USB_DIRECTION_OUT);
-			rc = usbvirt_ipc_send_data_out(sess, transfer->endpoint,
-			    transfer->transfer_type,
-			    transfer->data_buffer, transfer->data_buffer_size);
+		if (dir == USB_DIRECTION_IN) {
+			rc = usbvirt_ipc_send_data_in(sess, batch->ep->endpoint,
+			    batch->ep->transfer_type,
+			    batch->buffer, batch->buffer_size,
+			    actual_data_size);
+		} else {
+			assert(dir == USB_DIRECTION_OUT);
+			rc = usbvirt_ipc_send_data_out(sess, batch->ep->endpoint,
+			    batch->ep->transfer_type,
+			    batch->buffer, batch->buffer_size);
 		}
 	}
@@ -195,23 +142,59 @@
 }
 
-
 static void execute_transfer_callback_and_free(vhc_transfer_t *transfer,
     size_t data_transfer_size, int outcome)
 {
 	assert(outcome != ENAK);
-
-	usb_log_debug2("Transfer %p ended: %s.\n",
-	    transfer, str_error(outcome));
-
-	if (transfer->direction == USB_DIRECTION_IN) {
-		transfer->callback_in(transfer->ddf_fun, outcome,
-		    data_transfer_size, transfer->callback_arg);
-	} else {
-		assert(transfer->direction == USB_DIRECTION_OUT);
-		transfer->callback_out(transfer->ddf_fun, outcome,
-		    transfer->callback_arg);
-	}
-
+	assert(transfer);
+	assert(transfer->batch);
+	usb_transfer_batch_finish_error(transfer->batch, NULL,
+	    data_transfer_size, outcome);
+	usb_transfer_batch_destroy(transfer->batch);
 	free(transfer);
+}
+
+int vhc_init(vhc_data_t *instance)
+{
+	assert(instance);
+	list_initialize(&instance->devices);
+	fibril_mutex_initialize(&instance->guard);
+	instance->magic = 0xDEADBEEF;
+	return virthub_init(&instance->hub, "root hub");
+}
+
+int vhc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
+{
+	assert(hcd);
+	assert(batch);
+	vhc_data_t *vhc = hcd->driver.data;
+	assert(vhc);
+
+	vhc_transfer_t *transfer = malloc(sizeof(vhc_transfer_t));
+	if (!transfer)
+		return ENOMEM;
+	link_initialize(&transfer->link);
+	transfer->batch = batch;
+
+	fibril_mutex_lock(&vhc->guard);
+
+	int targets = 0;
+
+	list_foreach(vhc->devices, link, vhc_virtdev_t, dev) {
+		fibril_mutex_lock(&dev->guard);
+		if (dev->address == transfer->batch->ep->address) {
+			if (!targets) {
+				list_append(&transfer->link, &dev->transfer_queue);
+			}
+			++targets;
+		}
+		fibril_mutex_unlock(&dev->guard);
+	}
+
+	fibril_mutex_unlock(&vhc->guard);
+	
+	if (targets > 1)
+		usb_log_warning("Transfer would be accepted by more devices!\n");
+
+	return targets ? EOK : ENOENT;
 }
 
@@ -234,9 +217,9 @@
 		size_t data_transfer_size = 0;
 		if (dev->dev_sess) {
-			rc = process_transfer_remote(transfer, dev->dev_sess,
-			    &data_transfer_size);
+			rc = process_transfer_remote(transfer->batch,
+			    dev->dev_sess, &data_transfer_size);
 		} else if (dev->dev_local != NULL) {
-			rc = process_transfer_local(transfer, dev->dev_local,
-			    &data_transfer_size);
+			rc = process_transfer_local(transfer->batch,
+			    dev->dev_local, &data_transfer_size);
 		} else {
 			usb_log_warning("Device has no remote phone nor local node.\n");
@@ -251,5 +234,5 @@
 			if (is_set_address_transfer(transfer)) {
 				usb_device_request_setup_packet_t *setup
-				    = transfer->setup_buffer;
+				    = (void*)transfer->batch->setup_buffer;
 				dev->address = setup->value;
 				usb_log_debug2("Address changed to %d\n",
@@ -284,3 +267,2 @@
 	return EOK;
 }
-
Index: uspace/drv/bus/usb/vhc/vhcd.h
===================================================================
--- uspace/drv/bus/usb/vhc/vhcd.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/drv/bus/usb/vhc/vhcd.h	(revision 6eb957dc03c2cd2c6e13a28a9aa5ec04955bd913)
@@ -36,10 +36,10 @@
 #define VHCD_VHCD_H_
 
-#include <usb/debug.h>
 #include <usbvirt/device.h>
-#include <usb/host/usb_endpoint_manager.h>
-#include <usb/host/usb_device_manager.h>
 #include <usbhc_iface.h>
 #include <async.h>
+
+#include <usb/host/hcd.h>
+
 
 #define NAME "vhc"
@@ -59,36 +59,25 @@
 	list_t devices;
 	fibril_mutex_t guard;
-	usb_endpoint_manager_t ep_manager;
-	usb_device_manager_t dev_manager;
-	usbvirt_device_t *hub;
-	ddf_fun_t *hc_fun;
+	usbvirt_device_t hub;
 } vhc_data_t;
 
 typedef struct {
 	link_t link;
-	usb_address_t address;
-	usb_endpoint_t endpoint;
-	usb_direction_t direction;
-	usb_transfer_type_t transfer_type;
-	void *setup_buffer;
-	size_t setup_buffer_size;
-	void *data_buffer;
-	size_t data_buffer_size;
-	ddf_fun_t *ddf_fun;
-	void *callback_arg;
-	usbhc_iface_transfer_in_callback_t callback_in;
-	usbhc_iface_transfer_out_callback_t callback_out;
+	usb_transfer_batch_t *batch;
 } vhc_transfer_t;
 
-vhc_transfer_t *vhc_transfer_create(usb_address_t, usb_endpoint_t,
-    usb_direction_t, usb_transfer_type_t, ddf_fun_t *, void *);
+
+void on_client_close(ddf_fun_t *fun);
+void default_connection_handler(ddf_fun_t *fun, ipc_callid_t icallid,
+    ipc_call_t *icall);
+
 int vhc_virtdev_plug(vhc_data_t *, async_sess_t *, uintptr_t *);
 int vhc_virtdev_plug_local(vhc_data_t *, usbvirt_device_t *, uintptr_t *);
-int vhc_virtdev_plug_hub(vhc_data_t *, usbvirt_device_t *, uintptr_t *);
+int vhc_virtdev_plug_hub(vhc_data_t *, usbvirt_device_t *, uintptr_t *, usb_address_t address);
 void vhc_virtdev_unplug(vhc_data_t *, uintptr_t);
-int vhc_virtdev_add_transfer(vhc_data_t *, vhc_transfer_t *);
 
+int vhc_init(vhc_data_t *instance);
+int vhc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
 int vhc_transfer_queue_processor(void *arg);
-
 
 #endif
