Index: uspace/drv/bus/usb/ehci/main.c
===================================================================
--- uspace/drv/bus/usb/ehci/main.c	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/ehci/main.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -40,7 +40,6 @@
 
 #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"
@@ -57,7 +56,4 @@
 	.name = NAME,
 	.driver_ops = &ehci_driver_ops
-};
-static ddf_dev_ops_t hc_ops = {
-	.interfaces[USBHC_DEV_IFACE] = &hcd_iface,
 };
 
@@ -92,26 +88,8 @@
 	    "Failed to disable legacy USB: %s.\n", str_error(ret));
 
-	ddf_fun_t *hc_fun = ddf_fun_create(device, fun_exposed, "ehci_hc");
-	if (hc_fun == NULL) {
-		usb_log_error("Failed to create EHCI function.\n");
-		return ENOMEM;
-	}
-	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");
-		return ENOMEM;
-	}
 	/* High Speed, no bandwidth */
-	hcd_init(ehci_hc, USB_SPEED_HIGH, 0, NULL);
-	ddf_fun_set_ops(hc_fun,  &hc_ops);
-
-	ret = ddf_fun_bind(hc_fun);
+	ret = hcd_ddf_setup_device(device, NULL, USB_SPEED_HIGH, 0, NULL);	
 	CHECK_RET_RETURN(ret,
-	    "Failed to bind EHCI function: %s.\n",
-	    str_error(ret));
-	ret = ddf_fun_add_to_category(hc_fun, USB_HC_CATEGORY);
-	CHECK_RET_RETURN(ret,
-	    "Failed to add EHCI to HC class: %s.\n",
-	    str_error(ret));
+	    "Failed to init generci hcd driver: %s\n", str_error(ret));
 
 	usb_log_info("Controlling new EHCI device `%s' (handle %" PRIun ").\n",
Index: uspace/drv/bus/usb/ohci/Makefile
===================================================================
--- uspace/drv/bus/usb/ohci/Makefile	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/ohci/Makefile	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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
 
@@ -50,6 +51,6 @@
 	ohci_batch.c \
 	ohci_endpoint.c \
+	ohci_rh.c \
 	res.c \
-	root_hub.c \
 	hw_struct/endpoint_descriptor.c \
 	hw_struct/transfer_descriptor.c
Index: uspace/drv/bus/usb/ohci/hc.c
===================================================================
--- uspace/drv/bus/usb/ohci/hc.c	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/ohci/hc.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -41,5 +41,4 @@
 #include <usb/debug.h>
 #include <usb/usb.h>
-#include <usb/ddfiface.h>
 
 #include "hc.h"
@@ -88,5 +87,4 @@
 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);
 
 /** Get number of PIO ranges used in IRQ code.
@@ -137,63 +135,4 @@
 }
 
-/** 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)
-{
-	assert(instance);
-	assert(hub_fun);
-
-	/* Try to get address 1 for root hub. */
-	instance->rh.address = 1;
-	int ret = usb_device_manager_request_address(
-	    &instance->generic.dev_manager, &instance->rh.address, false,
-	    USB_SPEED_FULL);
-	if (ret != EOK) {
-		usb_log_error("Failed to get OHCI root hub address: %s\n",
-		    str_error(ret));
-		return ret;
-	}
-
-#define CHECK_RET_UNREG_RETURN(ret, message...) \
-if (ret != EOK) { \
-	usb_log_error(message); \
-	usb_endpoint_manager_remove_ep( \
-	    &instance->generic.ep_manager, instance->rh.address, 0, \
-	    USB_DIRECTION_BOTH, NULL, NULL); \
-	usb_device_manager_release_address( \
-	    &instance->generic.dev_manager, instance->rh.address); \
-	return ret; \
-} else (void)0
-
-	ret = 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);
-	CHECK_RET_UNREG_RETURN(ret,
-	    "Failed to register root hub control endpoint: %s.\n",
-	    str_error(ret));
-
-	ret = ddf_fun_add_match_id(hub_fun, "usb&class=hub", 100);
-	CHECK_RET_UNREG_RETURN(ret,
-	    "Failed to add root hub match-id: %s.\n", str_error(ret));
-
-	ret = ddf_fun_bind(hub_fun);
-	CHECK_RET_UNREG_RETURN(ret,
-	    "Failed to bind root hub function: %s.\n", str_error(ret));
-
-	ret = usb_device_manager_bind_address(&instance->generic.dev_manager,
-	    instance->rh.address, ddf_fun_get_handle(hub_fun));
-	if (ret != EOK)
-		usb_log_warning("Failed to bind root hub address: %s.\n",
-		    str_error(ret));
-
-	return EOK;
-#undef CHECK_RET_RELEASE
-}
-
 /** Initialize OHCI hc driver structure
  *
@@ -221,11 +160,4 @@
 	list_initialize(&instance->pending_batches);
 
-	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;
-
 	ret = hc_init_memory(instance);
 	CHECK_RET_RETURN(ret, "Failed to create OHCI memory structures: %s.\n",
@@ -243,5 +175,5 @@
 	}
 
-	rh_init(&instance->rh, instance->registers);
+	ohci_rh_init(&instance->rh, instance->registers, "ohci rh");
 	hc_start(instance);
 
@@ -330,8 +262,7 @@
 
 	/* 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);
@@ -372,5 +303,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) {
Index: uspace/drv/bus/usb/ohci/hc.h
===================================================================
--- uspace/drv/bus/usb/ohci/hc.h	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/ohci/hc.h	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -45,5 +45,5 @@
 #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"
@@ -51,7 +51,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;
@@ -71,5 +68,5 @@
 
 	/** USB hub emulation structure */
-	rh_t rh;
+	ohci_rh_t rh;
 } hc_t;
 
@@ -89,4 +86,5 @@
 void hc_enqueue_endpoint(hc_t *instance, const endpoint_t *ep);
 void hc_dequeue_endpoint(hc_t *instance, const endpoint_t *ep);
+int hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
 
 void hc_interrupt(hc_t *instance, uint32_t status);
Index: uspace/drv/bus/usb/ohci/ohci.c
===================================================================
--- uspace/drv/bus/usb/ohci/ohci.c	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/ohci/ohci.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -34,14 +34,11 @@
  */
 
-/* XXX Fix this */
-#define _DDF_DATA_IMPLANT
-
 #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 <usb/host/ddf_helpers.h>
 
 #include "ohci.h"
@@ -49,15 +46,6 @@
 #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
  *
@@ -69,64 +57,13 @@
 {
 	assert(dev);
-
-	ohci_t *ohci = dev_to_ohci(dev);
-	if (!ohci) {
+	hcd_t *hcd = dev_to_hcd(dev);
+	if (!hcd || !hcd->private_data) {
 		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);
+	hc_interrupt(hcd->private_data, 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.
@@ -143,37 +80,9 @@
 int device_setup_ohci(ddf_dev_t *device)
 {
-	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;
-	}
-
-#define CHECK_RET_DEST_FREE_RETURN(ret, message...) \
+#define CHECK_RET_RETURN(ret, message...) \
 if (ret != EOK) { \
-	if (instance->hc_fun) { \
-		ddf_fun_destroy(instance->hc_fun); \
-	} \
-	if (instance->rh_fun) { \
-		ddf_fun_destroy(instance->rh_fun); \
-	} \
 	usb_log_error(message); \
 	return ret; \
-} else (void)0
-
-	instance->hc_fun = ddf_fun_create(device, fun_exposed, "ohci_hc");
-	int ret = instance->hc_fun ? EOK : ENOMEM;
-	CHECK_RET_DEST_FREE_RETURN(ret,
-	    "Failed to create OHCI HC function: %s.\n", str_error(ret));
-	ddf_fun_set_ops(instance->hc_fun, &hc_ops);
-	ddf_fun_data_implant(instance->hc_fun, &instance->hc);
-
-	instance->rh_fun = ddf_fun_create(device, fun_inner, "ohci_rh");
-	ret = instance->rh_fun ? EOK : ENOMEM;
-	CHECK_RET_DEST_FREE_RETURN(ret,
-	    "Failed to create OHCI RH function: %s.\n", str_error(ret));
-	ddf_fun_set_ops(instance->rh_fun, &rh_ops);
+}
 
 	uintptr_t reg_base = 0;
@@ -181,8 +90,8 @@
 	int irq = 0;
 
-	ret = get_my_registers(device, &reg_base, &reg_size, &irq);
-	CHECK_RET_DEST_FREE_RETURN(ret,
-	    "Failed to get register memory addresses for %" PRIun ": %s.\n",
-	    ddf_dev_get_handle(device), str_error(ret));
+	int ret = get_my_registers(device, &reg_base, &reg_size, &irq);
+	CHECK_RET_RETURN(ret, "Failed to get register memory addresses for %"
+	    PRIun ": %s.\n", ddf_dev_get_handle(device), str_error(ret));
+
 	usb_log_debug("Memory mapped regs at %p (size %zu), IRQ %d.\n",
 	    (void *) reg_base, reg_size, irq);
@@ -201,12 +110,10 @@
 	ret = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
 	    sizeof(irq_cmds), reg_base, reg_size);
-	CHECK_RET_DEST_FREE_RETURN(ret,
-	    "Failed to generate IRQ code: %s.\n", str_error(ret));
-
+	CHECK_RET_RETURN(ret, "Failed to gen IRQ code: %s.\n", str_error(ret));
 
 	/* Register handler to avoid interrupt lockup */
 	ret = register_interrupt_handler(device, irq, irq_handler, &irq_code);
-	CHECK_RET_DEST_FREE_RETURN(ret,
-	    "Failed to register interrupt handler: %s.\n", str_error(ret));
+	CHECK_RET_RETURN(ret,
+	    "Failed to register irq handler: %s.\n", str_error(ret));
 
 	/* Try to enable interrupts */
@@ -223,30 +130,37 @@
 	}
 
-	ret = hc_init(&instance->hc, reg_base, reg_size, interrupts);
-	CHECK_RET_DEST_FREE_RETURN(ret,
-	    "Failed to init ohci_hcd: %s.\n", str_error(ret));
+	/* Initialize generic HCD driver */
+	ret = hcd_ddf_setup_device(device, NULL, USB_SPEED_FULL,
+	    BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
+	if (ret != EOK) {
+		unregister_interrupt_handler(device, irq);
+		return ret;
+	}
 
-#define CHECK_RET_FINI_RETURN(ret, message...) \
+// TODO: Undo hcd_setup_device
+#define CHECK_RET_CLEAN_RETURN(ret, message...) \
 if (ret != EOK) { \
-	hc_fini(&instance->hc); \
 	unregister_interrupt_handler(device, irq); \
-	CHECK_RET_DEST_FREE_RETURN(ret, message); \
+	CHECK_RET_RETURN(ret, message); \
 } else (void)0
 
+	hc_t *hc_impl = malloc(sizeof(hc_t));
+	ret = hc_impl ? EOK : ENOMEM;
+	CHECK_RET_CLEAN_RETURN(ret, "Failed to allocate driver structure.\n");
 
-	ret = ddf_fun_bind(instance->hc_fun);
-	CHECK_RET_FINI_RETURN(ret,
-	    "Failed to bind OHCI device function: %s.\n", str_error(ret));
+	/* Initialize OHCI HC */
+	ret = hc_init(hc_impl, reg_base, reg_size, interrupts);
+	CHECK_RET_CLEAN_RETURN(ret, "Failed to init hc: %s.\n", str_error(ret));
 
-	ret = ddf_fun_add_to_category(instance->hc_fun, USB_HC_CATEGORY);
-	CHECK_RET_FINI_RETURN(ret,
-	    "Failed to add OHCI to HC class: %s.\n", str_error(ret));
+	/* Connect OHCI to generic HCD */
+	hcd_set_implementation(dev_to_hcd(device), hc_impl,
+	    hc_schedule, ohci_endpoint_init, ohci_endpoint_fini);
 
-	ret = hc_register_hub(&instance->hc, instance->rh_fun);
-	CHECK_RET_FINI_RETURN(ret,
+	/* HC should be running OK. We can add root hub */
+	ret = hcd_ddf_setup_root_hub(device, USB_SPEED_FULL);
+	CHECK_RET_CLEAN_RETURN(ret,
 	    "Failed to register OHCI root hub: %s.\n", str_error(ret));
+
 	return ret;
-
-#undef CHECK_RET_FINI_RETURN
 }
 /**
Index: uspace/drv/bus/usb/ohci/ohci.h
===================================================================
--- uspace/drv/bus/usb/ohci/ohci.h	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/ohci/ohci.h	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -34,5 +34,4 @@
 #ifndef DRV_OHCI_OHCI_H
 #define DRV_OHCI_OHCI_H
-#include <ddi.h>
 #include <ddf/driver.h>
 
Index: uspace/drv/bus/usb/ohci/ohci_regs.h
===================================================================
--- uspace/drv/bus/usb/ohci/ohci_regs.h	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/ohci/ohci_regs.h	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
+++ uspace/drv/bus/usb/ohci/ohci_rh.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -0,0 +1,518 @@
+/*
+ * 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 <usb/debug.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);
+	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 tru 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 db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
+++ uspace/drv/bus/usb/ohci/ohci_rh.h	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -0,0 +1,82 @@
+/*
+ * 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 <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/root_hub.c
===================================================================
--- uspace/drv/bus/usb/ohci/root_hub.c	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(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/uhci/Makefile
===================================================================
--- uspace/drv/bus/usb/uhci/Makefile	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/uhci/Makefile	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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
 
@@ -45,8 +48,8 @@
 	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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/uhci/hc.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -85,5 +85,4 @@
 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);
@@ -131,6 +130,6 @@
 	memcpy(cmds, uhci_irq_commands, sizeof(uhci_irq_commands));
 	uhci_regs_t *registers = (uhci_regs_t *) regs;
-	cmds[0].addr = &registers->usbsts;
-	cmds[3].addr = &registers->usbsts;
+	cmds[0].addr = (void*)&registers->usbsts;
+	cmds[3].addr = (void*)&registers->usbsts;
 
 	return EOK;
@@ -236,11 +235,4 @@
 #undef CHECK_RET_RETURN
 
-	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;
-
 	hc_init_hw(instance);
 	if (!interrupts) {
@@ -250,4 +242,6 @@
 	}
 	(void)hc_debug_checker;
+
+	uhci_rh_init(&instance->rh, instance->registers->ports, "uhci");
 
 	return EOK;
@@ -414,4 +408,8 @@
 	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) {
Index: uspace/drv/bus/usb/uhci/hc.h
===================================================================
--- uspace/drv/bus/usb/uhci/hc.h	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/uhci/hc.h	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -37,5 +37,7 @@
 
 #include <fibril.h>
+#include <macros.h>
 #include <usb/host/hcd.h>
+#include "uhci_rh.h"
 
 #include "transfer_list.h"
@@ -44,5 +46,5 @@
 typedef struct uhci_regs {
 	/** Command register, controls HC behaviour */
-	uint16_t usbcmd;
+	ioport16_t usbcmd;
 #define UHCI_CMD_MAX_PACKET (1 << 7)
 #define UHCI_CMD_CONFIGURE  (1 << 6)
@@ -55,5 +57,5 @@
 
 	/** Status register, 1 means interrupt is asserted (if enabled) */
-	uint16_t usbsts;
+	ioport16_t usbsts;
 #define UHCI_STATUS_HALTED (1 << 5)
 #define UHCI_STATUS_PROCESS_ERROR (1 << 4)
@@ -66,5 +68,5 @@
 
 	/** Interrupt enabled registers */
-	uint16_t usbintr;
+	ioport16_t usbintr;
 #define UHCI_INTR_SHORT_PACKET (1 << 3)
 #define UHCI_INTR_COMPLETE (1 << 2)
@@ -73,11 +75,14 @@
 
 	/** Register stores frame number used in SOF packet */
-	uint16_t frnum;
+	ioport16_t frnum;
 
 	/** Pointer(physical) to the Frame List */
-	uint32_t flbaseadd;
+	ioport32_t flbaseadd;
 
 	/** SOF modification to match external timers */
-	uint8_t sofmod;
+	ioport8_t sofmod;
+
+	PADD8[3];
+	ioport16_t ports[];
 } uhci_regs_t;
 
@@ -90,7 +95,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;
@@ -125,4 +128,5 @@
 void hc_interrupt(hc_t *instance, uint16_t status);
 int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interupts);
+int hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
 
 /** Safely dispose host controller internal structures
Index: uspace/drv/bus/usb/uhci/main.c
===================================================================
--- uspace/drv/bus/usb/uhci/main.c	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/uhci/main.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -36,5 +36,4 @@
 #include <str_error.h>
 
-#include <usb/ddfiface.h>
 #include <usb/debug.h>
 
Index: uspace/drv/bus/usb/uhci/root_hub.c
===================================================================
--- uspace/drv/bus/usb/uhci/root_hub.c	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(revision )
@@ -1,73 +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 <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, uintptr_t reg_addr, size_t reg_size)
-{
-	assert(instance);
-	assert(fun);
-
-	/* 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.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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(revision )
@@ -1,55 +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>
-
-/** 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;
-} rh_t;
-
-int rh_init(
-    rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size);
-
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhci/uhci.c
===================================================================
--- uspace/drv/bus/usb/uhci/uhci.c	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/uhci/uhci.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -40,7 +40,7 @@
 #include <str_error.h>
 #include <ddf/interrupt.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 "uhci.h"
@@ -48,24 +48,5 @@
 #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.
@@ -78,62 +59,12 @@
 {
 	assert(dev);
-	uhci_t *uhci = dev_to_uhci(dev);
-	if (!uhci) {
+	hcd_t *hcd = dev_to_hcd(dev);
+	if (!hcd || !hcd->private_data) {
 		usb_log_error("Interrupt on not yet initialized device.\n");
 		return;
 	}
 	const uint16_t status = IPC_GET_ARG1(*call);
-	hc_interrupt(&uhci->hc, status);
+	hc_interrupt(hcd->private_data, 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,
-};
-
-/** 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
-};
 
 /** Initialize hc and rh DDF structures and their respective drivers.
@@ -152,33 +83,9 @@
 		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;
-	}
-
-#define CHECK_RET_DEST_FREE_RETURN(ret, message...) \
+#define CHECK_RET_RETURN(ret, message...) \
 if (ret != EOK) { \
-	if (instance->hc_fun) \
-		ddf_fun_destroy(instance->hc_fun); \
-	if (instance->rh_fun) {\
-		ddf_fun_destroy(instance->rh_fun); \
-	} \
 	usb_log_error(message); \
 	return ret; \
 } else (void)0
-
-	instance->rh_fun = NULL;
-	instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci_hc");
-	int ret = (instance->hc_fun == NULL) ? ENOMEM : EOK;
-	CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create UHCI HC function.\n");
-	ddf_fun_set_ops(instance->hc_fun, &hc_ops);
-	ddf_fun_data_implant(instance->hc_fun, &instance->hc.generic);
-
-	instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci_rh");
-	ret = (instance->rh_fun == NULL) ? ENOMEM : EOK;
-	CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create UHCI RH function.\n");
-	ddf_fun_set_ops(instance->rh_fun, &rh_ops);
-	ddf_fun_data_implant(instance->rh_fun, &instance->rh);
 
 	uintptr_t reg_base = 0;
@@ -186,14 +93,9 @@
 	int irq = 0;
 
-	ret = get_my_registers(device, &reg_base, &reg_size, &irq);
-	CHECK_RET_DEST_FREE_RETURN(ret,
-	    "Failed to get I/O addresses for %" PRIun ": %s.\n",
+	int ret = get_my_registers(device, &reg_base, &reg_size, &irq);
+	CHECK_RET_RETURN(ret, "Failed to get I/O region for %" PRIun ": %s.\n",
 	    ddf_dev_get_handle(device), str_error(ret));
 	usb_log_debug("I/O regs at 0x%p (size %zu), IRQ %d.\n",
 	    (void *) reg_base, reg_size, irq);
-
-	ret = disable_legacy(device);
-	CHECK_RET_DEST_FREE_RETURN(ret,
-	    "Failed to disable legacy USB: %s.\n", str_error(ret));
 
 	const size_t ranges_count = hc_irq_pio_range_count();
@@ -203,6 +105,6 @@
 	ret = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
 	    sizeof(irq_cmds), reg_base, reg_size);
-	CHECK_RET_DEST_FREE_RETURN(ret,
-	    "Failed to generate IRQ commands: %s.\n", str_error(ret));
+	CHECK_RET_RETURN(ret, "Failed to generate IRQ commands: %s.\n",
+	    str_error(ret));
 
 	irq_code_t irq_code = {
@@ -215,6 +117,10 @@
         /* Register handler to avoid interrupt lockup */
         ret = register_interrupt_handler(device, irq, irq_handler, &irq_code);
-        CHECK_RET_DEST_FREE_RETURN(ret,
-            "Failed to register interrupt handler: %s.\n", str_error(ret));
+        CHECK_RET_RETURN(ret, "Failed to register interrupt handler: %s.\n",
+	    str_error(ret));
+	
+	ret = disable_legacy(device);
+	CHECK_RET_RETURN(ret, "Failed to disable legacy USB: %s.\n",
+	    str_error(ret));
 
 	bool interrupts = false;
@@ -228,31 +134,30 @@
 	}
 
-	ret = hc_init(&instance->hc, (void*)reg_base, reg_size, interrupts);
-	CHECK_RET_DEST_FREE_RETURN(ret,
+	ddf_fun_t *hc_fun = NULL;
+	ret = hcd_ddf_setup_device(device, &hc_fun, USB_SPEED_FULL,
+	    BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
+	CHECK_RET_RETURN(ret, "Failed to setup UHCI HCD.\n");
+	
+	hc_t *hc = malloc(sizeof(hc_t));
+	ret = hc ? EOK : ENOMEM;
+	CHECK_RET_RETURN(ret, "Failed to allocate UHCI HC structure.\n");
+
+	ret = hc_init(hc, (void*)reg_base, reg_size, interrupts);
+	CHECK_RET_RETURN(ret,
 	    "Failed to init uhci_hcd: %s.\n", str_error(ret));
 
+	hcd_set_implementation(dev_to_hcd(device), hc, hc_schedule, NULL, NULL);
+
+// TODO: Undo hcd_setup_device
 #define CHECK_RET_FINI_RETURN(ret, message...) \
 if (ret != EOK) { \
-	hc_fini(&instance->hc); \
-	CHECK_RET_DEST_FREE_RETURN(ret, message); \
+	hc_fini(hc); \
+	CHECK_RET_RETURN(ret, message); \
 	return ret; \
 } else (void)0
 
-	ret = ddf_fun_bind(instance->hc_fun);
-	CHECK_RET_FINI_RETURN(ret, "Failed to bind UHCI device function: %s.\n",
-	    str_error(ret));
-
-	ret = ddf_fun_add_to_category(instance->hc_fun, USB_HC_CATEGORY);
-	CHECK_RET_FINI_RETURN(ret,
-	    "Failed to add UHCI to HC class: %s.\n", str_error(ret));
-
-	ret = rh_init(&instance->rh, instance->rh_fun,
-	    (uintptr_t)instance->hc.registers + 0x10, 4);
+	ret = hcd_ddf_setup_root_hub(device, USB_SPEED_FULL);
 	CHECK_RET_FINI_RETURN(ret,
 	    "Failed to setup UHCI root hub: %s.\n", str_error(ret));
-
-	ret = ddf_fun_bind(instance->rh_fun);
-	CHECK_RET_FINI_RETURN(ret,
-	    "Failed to register UHCI root hub: %s.\n", str_error(ret));
 
 	return EOK;
Index: uspace/drv/bus/usb/uhci/uhci_rh.c
===================================================================
--- uspace/drv/bus/usb/uhci/uhci_rh.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
+++ uspace/drv/bus/usb/uhci/uhci_rh.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -0,0 +1,487 @@
+/*
+ * 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 <macros.h>
+#include <usb/debug.h>
+#include <usb/classes/hub.h>
+#include <ddi.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 db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
+++ uspace/drv/bus/usb/uhci/uhci_rh.h	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -0,0 +1,72 @@
+/*
+ * 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>
+
+/** 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)
+{
+	assert(instance);
+	return virthub_base_get_address(&instance->base);
+}
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/uhcirh/Makefile
===================================================================
--- uspace/drv/bus/usb/uhcirh/Makefile	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(revision )
@@ -1,165 +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,
-    uintptr_t *io_reg_address, size_t *io_reg_size);
-
-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));
-
-	uintptr_t io_regs = 0;
-	size_t io_size = 0;
-	uhci_root_hub_t *rh = NULL;
-	int ret = EOK;
-
-#define CHECK_RET_FREE_RH_RETURN(ret, message...) \
-if (ret != EOK) { \
-	usb_log_error(message); \
-	return ret; \
-} else (void)0
-
-	ret = hc_get_my_registers(device, &io_regs, &io_size);
-	CHECK_RET_FREE_RH_RETURN(ret,
-	    "Failed to get registers from HC: %s.\n", str_error(ret));
-	usb_log_debug("I/O regs at %p (size %zuB).\n",
-	    (void *) io_regs, io_size);
-
-	rh = ddf_dev_data_alloc(device, sizeof(uhci_root_hub_t));
-	ret = (rh == NULL) ? ENOMEM : EOK;
-	CHECK_RET_FREE_RH_RETURN(ret,
-	    "Failed to allocate rh driver instance.\n");
-
-	ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
-	CHECK_RET_FREE_RH_RETURN(ret,
-	    "Failed(%d) to initialize rh driver instance: %s.\n",
-	    ret, str_error(ret));
-
-	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_reg_address Base address of the memory range.
- * @param[out] io_reg_size Size of the memory range.
- * @return Error code.
- */
-int hc_get_my_registers(
-    ddf_dev_t *dev, uintptr_t *io_reg_address, size_t *io_reg_size)
-{
-	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_reg_address != NULL)
-		*io_reg_address = hw_res.io_ranges.ranges[0].address;
-
-	if (io_reg_size != NULL)
-		*io_reg_size = hw_res.io_ranges.ranges[0].size;
-
-	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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(revision )
@@ -1,387 +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;
-	assert(instance);
-
-	unsigned allowed_failures = MAX_ERROR_COUNT;
-#define CHECK_RET_FAIL(ret, msg...) \
-	if (ret != EOK) { \
-		usb_log_error(msg); \
-		if (!(allowed_failures-- > 0)) { \
-			usb_log_fatal( \
-			   "Maximum number of failures reached, " \
-			   "bailing out.\n"); \
-			return ret; \
-		} \
-		continue; \
-	} else (void)0
-
-	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);
-
-		int ret = usb_hc_connection_open(&instance->hc_connection);
-		CHECK_RET_FAIL(ret, "%s: Failed to connect to HC %s.\n",
-		    instance->id_string, str_error(ret));
-
-		/* 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);
-		}
-
-		ret = usb_hc_connection_close(&instance->hc_connection);
-		CHECK_RET_FAIL(ret, "%s: Failed to disconnect from hc: %s.\n",
-		    instance->id_string, str_error(ret));
-	}
-	return EOK;
-}
-
-/** 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 {
-		ret = usb_hc_new_device_wrapper(port->rh, &port->hc_connection,
-		    speed, uhci_port_reset_enable, port,
-		    &port->attached_device.address, NULL, NULL,
-		    &port->attached_device.fun);
-	} 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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(revision )
@@ -1,97 +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 "root_hub.h"
-
-/** Initialize UHCI root hub instance.
- *
- * @param[in] instance Driver memory structure to use.
- * @param[in] addr Address of I/O registers.
- * @param[in] size Size of available I/O space.
- * @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, void *addr, size_t size, ddf_dev_t *rh)
-{
-	assert(instance);
-	assert(rh);
-
-	/* Allow access to root hub port registers */
-	assert(sizeof(port_status_t) * UHCI_ROOT_HUB_PORT_COUNT <= size);
-	port_status_t *regs;
-	int ret = pio_enable(addr, size, (void**)&regs);
-	if (ret < 0) {
-		usb_log_error(
-		    "Failed(%d) to gain access to port registers at %p: %s.\n",
-		    ret, 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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(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 drvusbuhcirh
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#ifndef DRV_UHCI_ROOT_HUB_H
-#define DRV_UHCI_ROOT_HUB_H
-
-#include <ddf/driver.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, void *addr, size_t size, 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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbflbk/main.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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/generic/hiddev.c
===================================================================
--- uspace/drv/bus/usb/usbhid/generic/hiddev.c	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbhid/generic/hiddev.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -195,6 +195,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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbhid/kbd/kbddev.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -34,7 +34,4 @@
  * USB HID keyboard device structure and API.
  */
-
-/* XXX Fix this */
-#define _DDF_DATA_IMPLANT
 
 #include <errno.h>
@@ -264,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;
 	}
@@ -273,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) {
@@ -481,13 +480,153 @@
 /* HID/KBD structure manipulation                                             */
 
-static int usb_kbd_create_function(usb_kbd_t *kbd_dev)
-{
-	assert(kbd_dev != NULL);
-	assert(kbd_dev->hid_dev != NULL);
-	assert(kbd_dev->hid_dev->usb_dev != NULL);
+static int kbd_dev_init(usb_kbd_t *kbd_dev, usb_hid_dev_t *hid_dev)
+{
+	assert(kbd_dev);
+	assert(hid_dev);
+
+	/* Default values */
+	fibril_mutex_initialize(&kbd_dev->repeat_mtx);
+	kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED;
+
+	/* Store link to HID device */
+	kbd_dev->hid_dev = hid_dev;
+
+	/* Modifiers and locks */
+	kbd_dev->mods = DEFAULT_ACTIVE_MODS;
+
+	/* Autorepeat */
+	kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT;
+	kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY;
+
+	// TODO: make more general
+	usb_hid_report_path_t *path = usb_hid_report_path();
+	if (path == NULL) {
+		usb_log_error("Failed to create kbd report path.\n");
+		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");
+		usb_hid_report_path_free(path);
+		usb_kbd_destroy(kbd_dev);
+		return ret;
+	}
+
+	usb_hid_report_path_set_report_id(path, 0);
+
+	kbd_dev->key_count =
+	    usb_hid_report_size(&hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
+
+	usb_hid_report_path_free(path);
+
+	usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
+
+	kbd_dev->keys = calloc(kbd_dev->key_count, sizeof(int32_t));
+	if (kbd_dev->keys == NULL) {
+		usb_log_error("Failed to allocate key buffer.\n");
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
+
+	kbd_dev->keys_old = calloc(kbd_dev->key_count, sizeof(int32_t));
+	if (kbd_dev->keys_old == NULL) {
+		usb_log_error("Failed to allocate old_key buffer.\n");
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
+
+	/* Output report */
+	kbd_dev->output_size = 0;
+	kbd_dev->output_buffer = usb_hid_report_output(&hid_dev->report,
+	    &kbd_dev->output_size, 0);
+	if (kbd_dev->output_buffer == NULL) {
+		usb_log_error("Error creating output report buffer.\n");
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
+
+	usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size);
+
+	kbd_dev->led_path = usb_hid_report_path();
+	if (kbd_dev->led_path == NULL) {
+		usb_log_error("Failed to create kbd led report path.\n");
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
+
+	ret = usb_hid_report_path_append_item(
+	    kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
+	if (ret != EOK) {
+		usb_log_error("Failed to append to kbd/led report path.\n");
+		usb_kbd_destroy(kbd_dev);
+		return ret;
+	}
+
+	kbd_dev->led_output_size = usb_hid_report_size(
+	    &hid_dev->report, 0, USB_HID_REPORT_TYPE_OUTPUT);
+
+	usb_log_debug("Output report size (in items): %zu\n",
+	    kbd_dev->led_output_size);
+
+	kbd_dev->led_data = calloc(kbd_dev->led_output_size, sizeof(int32_t));
+	if (kbd_dev->led_data == NULL) {
+		usb_log_error("Error creating buffer for LED output report.\n");
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
+
+	/* Set LEDs according to initial setup.
+	 * Set Idle rate */
+	usb_kbd_set_led(hid_dev, kbd_dev);
+
+	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 = ddf_fun_create(kbd_dev->hid_dev->usb_dev->ddf_dev,
+	ddf_fun_t *fun = usb_device_ddf_fun_create(hid_dev->usb_dev,
 	    fun_exposed, HID_KBD_FUN_NAME);
 	if (fun == NULL) {
@@ -496,15 +635,29 @@
 	}
 
+	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);
-	ddf_fun_data_implant(fun, kbd_dev);
-
-	int rc = ddf_fun_bind(fun);
-	if (rc != EOK) {
+
+	ret = ddf_fun_bind(fun);
+	if (ret != EOK) {
 		usb_log_error("Could not bind DDF function: %s.\n",
-		    str_error(rc));
+		    str_error(ret));
+		usb_kbd_destroy(kbd_dev);
 		ddf_fun_destroy(fun);
-		return rc;
+		return ret;
 	}
 
@@ -514,9 +667,10 @@
 	usb_log_debug("Adding DDF function to category %s...\n",
 	    HID_KBD_CLASS_NAME);
-	rc = ddf_fun_add_to_category(fun, HID_KBD_CATEGORY_NAME);
-	if (rc != EOK) {
+	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_CLASS_NAME, str_error(rc));
+		    HID_KBD_CLASS_NAME, str_error(ret));
+		usb_kbd_destroy(kbd_dev);
 		if (ddf_fun_unbind(fun) == EOK) {
 			ddf_fun_destroy(fun);
@@ -526,160 +680,4 @@
 			    ddf_fun_get_name(fun));
 		}
-		return rc;
-	}
-	kbd_dev->fun = fun;
-
-	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;
-	}
-
-	usb_kbd_t *kbd_dev = calloc(1, sizeof(usb_kbd_t));
-	if (kbd_dev == NULL) {
-		usb_log_error("Failed to allocate KBD device structure.\n");
-		return ENOMEM;
-	}
-	/* Default values */
-	fibril_mutex_initialize(&kbd_dev->repeat_mtx);
-	kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED;
-
-	/* Store link to HID device */
-	kbd_dev->hid_dev = hid_dev;
-
-	/* Modifiers and locks */
-	kbd_dev->mods = DEFAULT_ACTIVE_MODS;
-
-	/* Autorepeat */
-	kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT;
-	kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY;
-
-
-	// TODO: make more general
-	usb_hid_report_path_t *path = usb_hid_report_path();
-	if (path == NULL) {
-		usb_log_error("Failed to create kbd report path.\n");
-		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");
-		usb_hid_report_path_free(path);
-		usb_kbd_destroy(kbd_dev);
-		return ret;
-	}
-
-	usb_hid_report_path_set_report_id(path, 0);
-
-	kbd_dev->key_count =
-	    usb_hid_report_size(&hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
-
-	usb_hid_report_path_free(path);
-
-	usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
-
-	kbd_dev->keys = calloc(kbd_dev->key_count, sizeof(int32_t));
-	if (kbd_dev->keys == NULL) {
-		usb_log_error("Failed to allocate key buffer.\n");
-		usb_kbd_destroy(kbd_dev);
-		return ENOMEM;
-	}
-
-	kbd_dev->keys_old = calloc(kbd_dev->key_count, sizeof(int32_t));
-	if (kbd_dev->keys_old == NULL) {
-		usb_log_error("Failed to allocate old_key buffer.\n");
-		usb_kbd_destroy(kbd_dev);
-		return ENOMEM;
-	}
-
-	/* Output report */
-	kbd_dev->output_size = 0;
-	kbd_dev->output_buffer = usb_hid_report_output(&hid_dev->report,
-	    &kbd_dev->output_size, 0);
-	if (kbd_dev->output_buffer == NULL) {
-		usb_log_error("Error creating output report buffer.\n");
-		usb_kbd_destroy(kbd_dev);
-		return ENOMEM;
-	}
-
-	usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size);
-
-	kbd_dev->led_path = usb_hid_report_path();
-	if (kbd_dev->led_path == NULL) {
-		usb_log_error("Failed to create kbd led report path.\n");
-		usb_kbd_destroy(kbd_dev);
-		return ENOMEM;
-	}
-
-	ret = usb_hid_report_path_append_item(
-	    kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
-	if (ret != EOK) {
-		usb_log_error("Failed to append to kbd/led report path.\n");
-		usb_kbd_destroy(kbd_dev);
-		return ret;
-	}
-
-	kbd_dev->led_output_size = usb_hid_report_size(
-	    &hid_dev->report, 0, USB_HID_REPORT_TYPE_OUTPUT);
-
-	usb_log_debug("Output report size (in items): %zu\n",
-	    kbd_dev->led_output_size);
-
-	kbd_dev->led_data = calloc(kbd_dev->led_output_size, sizeof(int32_t));
-	if (kbd_dev->led_data == NULL) {
-		usb_log_error("Error creating buffer for LED output report.\n");
-		usb_kbd_destroy(kbd_dev);
-		return ENOMEM;
-	}
-
-	/* Set LEDs according to initial setup.
-	 * Set Idle rate */
-	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);
-
-	/* Save the KBD device structure into the HID device structure. */
-	*data = kbd_dev;
-
-	kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED;
-	usb_log_debug("HID/KBD device structure initialized.\n");
-
-	usb_log_debug("Creating KBD function...\n");
-	ret = usb_kbd_create_function(kbd_dev);
-	if (ret != EOK) {
-		usb_kbd_destroy(kbd_dev);
 		return ret;
 	}
@@ -693,4 +691,7 @@
 	}
 	fibril_add_ready(fid);
+	kbd_dev->fun = fun;
+	/* Save the KBD device structure into the HID device structure. */
+	*data = kbd_dev;
 
 	return EOK;
@@ -787,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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbhid/main.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbhid/mouse/mousedev.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -34,7 +34,4 @@
  * USB Mouse driver API.
  */
-
-/* XXX Fix this */
-#define _DDF_DATA_IMPLANT
 
 #include <usb/debug.h>
@@ -259,44 +256,4 @@
 } else (void)0
 
-static int usb_mouse_create_function(usb_hid_dev_t *hid_dev, usb_mouse_t *mouse)
-{
-	assert(hid_dev != NULL);
-	assert(mouse != NULL);
-
-	/* Create the exposed function. */
-	usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
-	ddf_fun_t *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);
-		return ENOMEM;
-	}
-
-	ddf_fun_set_ops(fun, &ops);
-	ddf_fun_data_implant(fun, mouse);
-
-	int rc = ddf_fun_bind(fun);
-	if (rc != EOK) {
-		usb_log_error("Could not bind DDF function `%s': %s.\n",
-		    ddf_fun_get_name(fun), str_error(rc));
-		ddf_fun_destroy(fun);
-		return rc;
-	}
-
-	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));
-		FUN_UNBIND_DESTROY(fun);
-		return rc;
-	}
-	mouse->mouse_fun = fun;
-	return EOK;
-}
-
 /** Get highest index of a button mentioned in given report.
  *
@@ -339,21 +296,6 @@
 }
 
-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;
-	}
-
-	usb_mouse_t *mouse_dev = calloc(1, sizeof(usb_mouse_t));
-	if (mouse_dev == NULL) {
-		usb_log_error("Error while creating USB/HID Mouse device "
-		    "structure.\n");
-		return ENOMEM;
-	}
-
+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
@@ -373,13 +315,63 @@
 
 	// 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);
-
-	int rc = usb_mouse_create_function(hid_dev, mouse_dev);
-	if (rc != EOK) {
-		free(mouse_dev->buttons);
-		free(mouse_dev);
-		return rc;
-	}
+	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(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);
+	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. */
@@ -417,7 +409,6 @@
 	}
 
+	free(mouse_dev->buttons);
 	FUN_UNBIND_DESTROY(mouse_dev->mouse_fun);
-
-	free(mouse_dev->buttons);
 }
 
@@ -434,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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbhid/multimedia/multimedia.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -161,6 +161,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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbhid/usbhid.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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);
@@ -485,5 +485,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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbhid/usbhid.h	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbhub/main.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbhub/port.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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->attached_handle != USB_DEVICE_HANDLE_INVALID)
 		return usb_hub_port_device_gone(port, hub);
 	return EOK;
@@ -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->attached_handle);
+	usb_device_bus_exchange_end(exch);
+	if (rc == EOK)
+		port->attached_handle = -1;
+	return 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,40 +378,65 @@
 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;
-
-	const int rc = usb_hc_new_device_wrapper(data->hub->usb_device->ddf_dev,
-	    &data->hub->usb_device->hc_conn, data->speed, enable_port_callback,
-	    data->port, &new_address, NULL, NULL, &child_fun);
-
-	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 %zu\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->attached_handle);
+	if (ret != EOK) {
+		usb_log_error("Failed to reset port %zu\n", port->port_number);
+		if (port_enable(port, false) != EOK) {
+			usb_log_warning("Failed to disable port %zu, NOT "
+			    "releasing default address.\n", port->port_number);
+		} else {
+			if (usb_release_default_address(exch) != EOK)
+				usb_log_warning(
+				    "Failed to release default address\n");
+		}
 	} else {
-		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;
+		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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbhub/port.h	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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;
@@ -59,6 +59,6 @@
 	bool reset_okay;
 
-	/** Information about attached device. */
-	usb_hub_attached_device_t attached_device;
+	usb_device_handle_t attached_handle;
+
 } usb_hub_port_t;
 
@@ -71,8 +71,7 @@
 {
 	assert(port);
-	port->attached_device.address = -1;
-	port->attached_device.fun = NULL;
 	port->port_number = port_number;
 	port->control_pipe = control_pipe;
+	port->attached_handle = USB_DEVICE_HANDLE_INVALID;
 	fibril_mutex_initialize(&port->mutex);
 	fibril_condvar_initialize(&port->reset_cv);
Index: uspace/drv/bus/usb/usbhub/usbhub.c
===================================================================
--- uspace/drv/bus/usb/usbhub/usbhub.c	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbhub/usbhub.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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,6 +111,7 @@
 	fibril_condvar_initialize(&hub_dev->pending_ops_cv);
 
-
-	int opResult = usb_pipe_start_long_transfer(&usb_dev->ctrl_pipe);
+	usb_pipe_t *control_pipe = usb_device_get_default_pipe(usb_dev);
+
+	int opResult = usb_pipe_start_long_transfer(control_pipe);
 	if (opResult != EOK) {
 		usb_log_error("Failed to start long ctrl pipe transfer: %s\n",
@@ -110,5 +123,5 @@
 	opResult = usb_set_first_configuration(usb_dev);
 	if (opResult != EOK) {
-		usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
+		usb_pipe_end_long_transfer(control_pipe);
 		usb_log_error("Could not set hub configuration: %s\n",
 		    str_error(opResult));
@@ -119,5 +132,5 @@
 	opResult = usb_hub_process_hub_specific_info(hub_dev);
 	if (opResult != EOK) {
-		usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
+		usb_pipe_end_long_transfer(control_pipe);
 		usb_log_error("Could process hub specific info, %s\n",
 		    str_error(opResult));
@@ -127,8 +140,8 @@
 	/* 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_pipe_end_long_transfer(control_pipe);
 		usb_log_error("Failed to create hub function.\n");
 		return ENOMEM;
@@ -138,5 +151,5 @@
 	opResult = ddf_fun_bind(hub_dev->hub_fun);
 	if (opResult != EOK) {
-		usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
+		usb_pipe_end_long_transfer(control_pipe);
 		usb_log_error("Failed to bind hub function: %s.\n",
 		   str_error(opResult));
@@ -146,9 +159,10 @@
 
 	/* 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) {
+		usb_pipe_end_long_transfer(control_pipe);
 		/* Function is already bound */
 		ddf_fun_unbind(hub_dev->hub_fun);
@@ -160,7 +174,7 @@
 	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);
+
+	usb_pipe_end_long_transfer(control_pipe);
 	return EOK;
 }
@@ -185,5 +199,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 +213,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 +258,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 +284,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 +323,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) {
@@ -345,5 +358,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 +366,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 +378,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",
@@ -428,5 +442,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 +467,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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbhub/usbhub.h	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbmast/bo_trans.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -67,6 +67,6 @@
 	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_pipe_t *bulk_in_pipe = mfun->mdev->bulk_in_pipe;
+	usb_pipe_t *bulk_out_pipe = mfun->mdev->bulk_out_pipe;
 	usb_direction_t ddir;
 	void *dbuf;
@@ -117,9 +117,11 @@
 		/* 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);
+			usb_pipe_clear_halt(
+			    usb_device_get_default_pipe(mfun->mdev->usb_dev),
+			    bulk_in_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),
+			    bulk_out_pipe);
 		}
         } else if (rc != EOK) {
@@ -197,7 +199,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 +218,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 +239,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/main.c
===================================================================
--- uspace/drv/bus/usb/usbmast/main.c	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbmast/main.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -110,5 +110,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);
 
@@ -150,4 +150,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));
@@ -157,14 +166,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");
@@ -182,4 +189,6 @@
 			goto error;
 	}
+	mdev->bulk_in_pipe = &epm_in->pipe;
+	mdev->bulk_out_pipe = &epm_out->pipe;
 
 	return EOK;
@@ -221,5 +230,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);
@@ -252,5 +261,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;
@@ -259,5 +268,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,
@@ -272,5 +281,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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbmast/scsi_ms.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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;
 	}
Index: uspace/drv/bus/usb/usbmast/usbmast.h
===================================================================
--- uspace/drv/bus/usb/usbmast/usbmast.h	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbmast/usbmast.h	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbmid/explore.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -40,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 +51,5 @@
 {
 	list_foreach(*list, l) {
-		usbmid_interface_t *iface = usbmid_interface_from_link(l);
+		const usbmid_interface_t *iface = usbmid_interface_from_link(l);
 		if (iface->interface_no == interface_no) {
 			return true;
@@ -72,7 +66,10 @@
  * @param list List where to add the interfaces.
  */
-static void create_interfaces(const uint8_t *config_descriptor,
-    size_t config_descriptor_size, list_t *list)
+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,
@@ -90,5 +87,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))
@@ -107,17 +104,24 @@
 			continue;
 		}
-		usbmid_interface_t *iface = malloc(sizeof(usbmid_interface_t));
-		if (iface == NULL) {
+
+
+		usb_log_info("Creating child for interface %d (%s).\n",
+		    interface->interface_number,
+		    usb_str_class(interface->interface_class));
+
+		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.
-			break;
+			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);
 		}
-
-		link_initialize(&iface->link);
-		iface->fun = NULL;
-		iface->interface_no = interface->interface_number;
-		iface->interface = interface;
-
-		list_append(&iface->link, list);
-	}
+	}
+	return EOK;
 }
 
@@ -130,9 +134,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(
@@ -140,37 +144,38 @@
 		    dev_class, usb_str_class(dev_class),
 		    USB_CLASS_USE_INTERFACE);
-		usb_log_error("Not multi interface device, refusing.\n");
-		return false;
-	}
-
-	/* Shortcuts to save on typing ;-). */
-	const void *config_descriptor_raw = dev->descriptors.configuration;
-	size_t config_descriptor_size = dev->descriptors.configuration_size;
+		usb_log_error("Not a multi-interface device, refusing.\n");
+		return ENOTSUP;
+	}
+
+	/* 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;
 	}
 
 	/* 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;
-	}
-	ddf_fun_set_ops(usb_mid->ctl_fun, &mid_device_ops);
+		return ENOMEM;
+	}
 
 	/* Bind control function. */
@@ -180,30 +185,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(config_descriptor_raw, config_descriptor_size,
-	    &usb_mid->interface_list);
-
-	/* Start child function for every interface. */
-	list_foreach(usb_mid->interface_list, link) {
-		usbmid_interface_t *iface = usbmid_interface_from_link(link);
-
-		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;
+	    &usb_mid->interface_list, dev);
+
+	return EOK;
 }
 
Index: uspace/drv/bus/usb/usbmid/main.c
===================================================================
--- uspace/drv/bus/usb/usbmid/main.c	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbmid/main.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbmid/usbmid.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -31,7 +31,4 @@
  */
 
-/* XXX Fix this */
-#define _DDF_DATA_IMPLANT
-
 /**
  * @file
@@ -42,12 +39,43 @@
 #include <stdlib.h>
 #include <usb_iface.h>
-#include <usb/ddfiface.h>
 #include <usb/dev/pipes.h>
 #include <usb/classes/classes.h>
 #include <usb/dev/recognise.h>
 #include "usbmid.h"
+/** Get host controller handle by calling the parent usb_device_t.
+ *
+ * @param[in] fun Device function the operation is running on.
+ * @param[out] handle Storage for the host controller handle.
+ * @return Error code.
+ */
+static int usb_iface_device_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
+{
+	assert(handle);
+	assert(fun);
+	usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun));
+	assert(usb_dev);
+	*handle = usb_device_hc_handle(usb_dev);
+	return EOK;
+}
+
+/** Get USB device address by calling the parent usb_device_t.
+ *
+ * @param[in] fun Device function the operation is running on.
+ * @param[in] handle Devman handle of USB device we want address of.
+ * @param[out] address Storage for USB address of device with handle @p handle.
+ * @return Error code.
+ */
+static int usb_iface_device_address(ddf_fun_t *fun, usb_address_t *address)
+{
+	assert(address);
+	assert(fun);
+	usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun));
+	assert(usb_dev);
+	*address = usb_device_address(usb_dev);
+	return EOK;
+}
 
 /** Callback for DDF USB interface. */
-static int usb_iface_get_interface_impl(ddf_fun_t *fun, int *iface_no)
+static int usb_iface_iface(ddf_fun_t *fun, int *iface_no)
 {
 	usbmid_interface_t *iface = ddf_fun_data_get(fun);
@@ -61,9 +89,37 @@
 }
 
+static int usb_iface_register_endpoint(ddf_fun_t *fun, usb_endpoint_t ep,
+    usb_transfer_type_t type, usb_direction_t dir, size_t mps, unsigned inter)
+{
+	usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun));
+	assert(usb_dev);
+	async_exch_t *exch = usb_device_bus_exchange_begin(usb_dev);
+	if (!exch)
+		return ENOMEM;
+	const int ret = usb_register_endpoint(exch, ep, type, dir, mps, inter);
+	usb_device_bus_exchange_end(exch);
+	return ret;
+}
+
+static int usb_iface_unregister_endpoint(ddf_fun_t *fun, usb_endpoint_t ep,
+    usb_direction_t dir)
+{
+	usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun));
+	assert(usb_dev);
+	async_exch_t *exch = usb_device_bus_exchange_begin(usb_dev);
+	if (!exch)
+		return ENOMEM;
+	const int ret = usb_unregister_endpoint(exch, ep, dir);
+	usb_device_bus_exchange_end(exch);
+	return ret;
+}
+
 /** DDF interface of the child - interface function. */
 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_hc_handle = usb_iface_device_hc_handle,
+	.get_my_address = usb_iface_device_address,
+	.get_my_interface = usb_iface_iface,
+	.register_endpoint = usb_iface_register_endpoint,
+	.unregister_endpoint = usb_iface_unregister_endpoint,
 };
 
@@ -81,9 +137,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;
 }
@@ -98,5 +150,5 @@
  */
 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)
@@ -119,5 +171,5 @@
 
 	/* Create the device. */
-	child = ddf_fun_create(parent->ddf_dev, fun_inner, child_name);
+	child = usb_device_ddf_fun_create(parent, fun_inner, child_name);
 	free(child_name);
 	if (child == NULL) {
@@ -145,4 +197,11 @@
 	}
 	clean_match_ids(&match_ids);
+	ddf_fun_set_ops(child, &child_device_ops);
+
+	usbmid_interface_t *iface = ddf_fun_data_alloc(child, sizeof(*iface));
+
+	iface->fun = child;
+	iface->interface_no = interface_descriptor->interface_number;
+	link_initialize(&iface->link);
 
 	rc = ddf_fun_bind(child);
@@ -152,8 +211,5 @@
 		return rc;
 	}
-
-	iface->fun = child;
-	ddf_fun_data_implant(child, iface);
-	ddf_fun_set_ops(child, &child_device_ops);
+	*iface_ret = iface;
 
 	return EOK;
Index: uspace/drv/bus/usb/usbmid/usbmid.h
===================================================================
--- uspace/drv/bus/usb/usbmid/usbmid.h	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbmid/usbmid.h	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -50,6 +50,4 @@
 	/** Function container. */
 	ddf_fun_t *fun;
-	/** Interface descriptor. */
-	const usb_standard_interface_descriptor_t *interface;
 	/** Interface number. */
 	int interface_no;
@@ -64,6 +62,6 @@
 } 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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/usbmid/usbmid.ma	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/vhc/Makefile	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/vhc/conndev.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/vhc/devconn.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(revision )
@@ -1,133 +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;
-
-	/*
-	 * Wait until parent device is properly initialized.
-	 */
-	async_sess_t *sess;
-	do {
-		sess = devman_device_connect(EXCHANGE_SERIALIZE,
-		    ddf_fun_get_handle(hc_dev), 0);
-	} while (!sess);
-	async_hangup(sess);
-
-	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;
-	rc = usb_hc_new_device_wrapper(ddf_fun_get_dev(hc_dev), &hc_conn, USB_SPEED_FULL,
-	    pretend_port_rest, NULL, NULL, &rh_ops, hc_dev, &hub_dev);
-	if (rc != EOK) {
-		usb_log_fatal("Failed to create root hub: %s.\n",
-		    str_error(rc));
-	}
-
-	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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ 	(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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/vhc/hub/virthub.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/vhc/hub/virthub.h	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/vhc/hub/virthubops.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/vhc/main.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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,78 @@
 #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_device(dev, NULL, 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);
 
-	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;
+	ret = hcd_ddf_setup_root_hub(dev, USB_SPEED_FULL);
+	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 +124,7 @@
 };
 
-
 int main(int argc, char * argv[])
-{	
+{
 	log_init(NAME);
-
 	printf(NAME ": virtual USB host controller driver.\n");
 
@@ -145,5 +132,4 @@
 }
 
-
 /**
  * @}
Index: uspace/drv/bus/usb/vhc/transfer.c
===================================================================
--- uspace/drv/bus/usb/vhc/transfer.c	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/vhc/transfer.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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,132 +58,144 @@
 }
 
-int vhc_virtdev_add_transfer(vhc_data_t *vhc, vhc_transfer_t *transfer)
-{
+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 {
+		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;
+
+	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 (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);
+		}
+	}
+
+	return rc;
+}
+
+static vhc_transfer_t *dequeue_first_transfer(vhc_virtdev_t *dev)
+{
+	assert(fibril_mutex_is_locked(&dev->guard));
+	assert(!list_empty(&dev->transfer_queue));
+
+	vhc_transfer_t *transfer = list_get_instance(
+	    list_first(&dev->transfer_queue), vhc_transfer_t, link);
+	list_remove(&transfer->link);
+
+	return transfer;
+}
+
+static void execute_transfer_callback_and_free(vhc_transfer_t *transfer,
+    size_t data_transfer_size, int outcome)
+{
+	assert(outcome != ENAK);
+	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->private_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);
 
-	bool target_found = false;
+	int targets = 0;
+
 	list_foreach(vhc->devices, pos) {
 		vhc_virtdev_t *dev = list_get_instance(pos, vhc_virtdev_t, link);
 		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;
+		if (dev->address == transfer->batch->ep->address) {
+			if (!targets) {
+				list_append(&transfer->link, &dev->transfer_queue);
 			}
-			target_found = true;
-			list_append(&transfer->link, &dev->transfer_queue);
-		}
-next:
+			++targets;
+		}
 		fibril_mutex_unlock(&dev->guard);
 	}
 
 	fibril_mutex_unlock(&vhc->guard);
-
-	if (target_found) {
-		return EOK;
-	} else {
-		return ENOENT;
-	}
-}
-
-static int process_transfer_local(vhc_transfer_t *transfer,
-    usbvirt_device_t *dev, 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);
-		}
-	} 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);
-		}
-	}
-
-	return rc;
-}
-
-static vhc_transfer_t *dequeue_first_transfer(vhc_virtdev_t *dev)
-{
-	assert(fibril_mutex_is_locked(&dev->guard));
-	assert(!list_empty(&dev->transfer_queue));
-
-	vhc_transfer_t *transfer = list_get_instance(
-	    list_first(&dev->transfer_queue), vhc_transfer_t, link);
-	list_remove(&transfer->link);
-
-	return transfer;
-}
-
-
-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);
-	}
-
-	free(transfer);
+	
+	if (targets > 1)
+		usb_log_warning("Transfer would be accepted by more devices!\n");
+
+	return targets ? EOK : ENOENT;
 }
 
@@ -235,9 +218,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");
@@ -252,5 +235,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",
@@ -285,3 +268,2 @@
 	return EOK;
 }
-
Index: uspace/drv/bus/usb/vhc/vhcd.h
===================================================================
--- uspace/drv/bus/usb/vhc/vhcd.h	(revision cffa14e6a3bd4ce597e7947bdeaf548e0a312d19)
+++ uspace/drv/bus/usb/vhc/vhcd.h	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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
