Index: uspace/drv/isa/isa.c
===================================================================
--- uspace/drv/isa/isa.c	(revision 8b1e15ac9100f7b9da56e372d2f441ba44db6fcc)
+++ uspace/drv/isa/isa.c	(revision 68414f4a1f1b548a47a6b4525bd18dfbed67df1d)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2010 Lenka Trochtova
+ * Copyright (c) 2011 Jiri Svoboda
  * All rights reserved.
  *
@@ -60,22 +61,23 @@
 #define CHILD_FUN_CONF_PATH "/drv/isa/isa.dev"
 
+/** Obtain soft-state pointer from function node pointer */
+#define ISA_FUN(fnode) ((isa_fun_t *) ((fnode)->driver_data))
+
 #define ISA_MAX_HW_RES 4
 
-typedef struct isa_fun_data {
+typedef struct isa_fun {
+	function_t *fnode;
 	hw_resource_list_t hw_resources;
-} isa_fun_data_t;
-
-static hw_resource_list_t *isa_get_fun_resources(function_t *fun)
-{
-	isa_fun_data_t *fun_data;
-
-	fun_data = (isa_fun_data_t *)fun->driver_data;
-	if (fun_data == NULL)
-		return NULL;
-
-	return &fun_data->hw_resources;
-}
-
-static bool isa_enable_fun_interrupt(function_t *fun)
+} isa_fun_t;
+
+static hw_resource_list_t *isa_get_fun_resources(function_t *fnode)
+{
+	isa_fun_t *fun = ISA_FUN(fnode);
+	assert(fun != NULL);
+
+	return &fun->hw_resources;
+}
+
+static bool isa_enable_fun_interrupt(function_t *fnode)
 {
 	// TODO
@@ -89,5 +91,5 @@
 };
 
-static device_ops_t isa_fun_dev_ops;
+static device_ops_t isa_fun_ops;
 
 static int isa_add_device(device_t *dev);
@@ -104,33 +106,22 @@
 };
 
-
-static isa_fun_data_t *create_isa_fun_data() 
-{
-	isa_fun_data_t *data;
-
-	data = (isa_fun_data_t *) malloc(sizeof(isa_fun_data_t));
-	if (data != NULL)
-		memset(data, 0, sizeof(isa_fun_data_t));
-
-	return data;
-}
-
-static function_t *create_isa_fun()
-{
-	function_t *fun = create_function();
+static isa_fun_t *isa_fun_create()
+{
+	isa_fun_t *fun = calloc(1, sizeof(isa_fun_t));
 	if (fun == NULL)
 		return NULL;
 
-	isa_fun_data_t *data = create_isa_fun_data();
-	if (data == NULL) {
-		delete_function(fun);
+	function_t *fnode = create_function();
+	if (fnode == NULL) {
+		free(fun);
 		return NULL;
 	}
 
-	fun->driver_data = data;
+	fun->fnode = fnode;
+	fnode->driver_data = fun;
 	return fun;
 }
 
-static char *read_fun_conf(const char *conf_path)
+static char *fun_conf_read(const char *conf_path)
 {
 	bool suc = false;
@@ -151,5 +142,5 @@
 	lseek(fd, 0, SEEK_SET);	
 	if (len == 0) {
-		printf(NAME ": read_fun_conf error: configuration file '%s' "
+		printf(NAME ": fun_conf_read error: configuration file '%s' "
 		    "is empty.\n", conf_path);
 		goto cleanup;
@@ -158,10 +149,10 @@
 	buf = malloc(len + 1);
 	if (buf == NULL) {
-		printf(NAME ": read_fun_conf error: memory allocation failed.\n");
+		printf(NAME ": fun_conf_read error: memory allocation failed.\n");
 		goto cleanup;
 	}
 
 	if (0 >= read(fd, buf, len)) {
-		printf(NAME ": read_fun_conf error: unable to read file '%s'.\n",
+		printf(NAME ": fun_conf_read error: unable to read file '%s'.\n",
 		    conf_path);
 		goto cleanup;
@@ -249,10 +240,8 @@
 }
 
-static void isa_fun_set_irq(function_t *fun, int irq)
-{
-	isa_fun_data_t *data = (isa_fun_data_t *)fun->driver_data;
-
-	size_t count = data->hw_resources.count;
-	hw_resource_t *resources = data->hw_resources.resources;
+static void isa_fun_set_irq(isa_fun_t *fun, int irq)
+{
+	size_t count = fun->hw_resources.count;
+	hw_resource_t *resources = fun->hw_resources.resources;
 
 	if (count < ISA_MAX_HW_RES) {
@@ -260,16 +249,15 @@
 		resources[count].res.interrupt.irq = irq;
 
-		data->hw_resources.count++;
-
-		printf(NAME ": added irq 0x%x to function %s\n", irq, fun->name);
-	}
-}
-
-static void isa_fun_set_io_range(function_t *fun, size_t addr, size_t len)
-{
-	isa_fun_data_t *data = (isa_fun_data_t *)fun->driver_data;
-
-	size_t count = data->hw_resources.count;
-	hw_resource_t *resources = data->hw_resources.resources;
+		fun->hw_resources.count++;
+
+		printf(NAME ": added irq 0x%x to function %s\n", irq,
+		    fun->fnode->name);
+	}
+}
+
+static void isa_fun_set_io_range(isa_fun_t *fun, size_t addr, size_t len)
+{
+	size_t count = fun->hw_resources.count;
+	hw_resource_t *resources = fun->hw_resources.resources;
 
 	if (count < ISA_MAX_HW_RES) {
@@ -279,13 +267,13 @@
 		resources[count].res.io_range.endianness = LITTLE_ENDIAN;
 
-		data->hw_resources.count++;
+		fun->hw_resources.count++;
 
 		printf(NAME ": added io range (addr=0x%x, size=0x%x) to "
 		    "function %s\n", (unsigned int) addr, (unsigned int) len,
-		    fun->name);
-	}
-}
-
-static void get_dev_irq(function_t *fun, char *val)
+		    fun->fnode->name);
+	}
+}
+
+static void fun_parse_irq(isa_fun_t *fun, char *val)
 {
 	int irq = 0;
@@ -299,5 +287,5 @@
 }
 
-static void get_dev_io_range(function_t *fun, char *val)
+static void fun_parse_io_range(isa_fun_t *fun, char *val)
 {
 	size_t addr, len;
@@ -331,5 +319,5 @@
 }
 
-static void get_fun_match_id(function_t *fun, char *val)
+static void fun_parse_match_id(isa_fun_t *fun, char *val)
 {
 	char *id = NULL;
@@ -337,10 +325,10 @@
 	char *end = NULL;
 
-	val = skip_spaces(val);	
+	val = skip_spaces(val);
 
 	score = (int)strtol(val, &end, 10);
 	if (val == end) {
 		printf(NAME " : error - could not read match score for "
-		    "function %s.\n", fun->name);
+		    "function %s.\n", fun->fnode->name);
 		return;
 	}
@@ -349,5 +337,5 @@
 	if (match_id == NULL) {
 		printf(NAME " : failed to allocate match id for function %s.\n",
-		    fun->name);
+		    fun->fnode->name);
 		return;
 	}
@@ -357,5 +345,5 @@
 	if (id == NULL) {
 		printf(NAME " : error - could not read match id for "
-		    "function %s.\n", fun->name);
+		    "function %s.\n", fun->fnode->name);
 		delete_match_id(match_id);
 		return;
@@ -366,10 +354,10 @@
 
 	printf(NAME ": adding match id '%s' with score %d to function %s\n", id,
-	    score, fun->name);
-	add_match_id(&fun->match_ids, match_id);
-}
-
-static bool read_fun_prop(function_t *fun, char *line, const char *prop,
-    void (*read_fn)(function_t *, char *))
+	    score, fun->fnode->name);
+	add_match_id(&fun->fnode->match_ids, match_id);
+}
+
+static bool prop_parse(isa_fun_t *fun, char *line, const char *prop,
+    void (*read_fn)(isa_fun_t *, char *))
 {
 	size_t proplen = str_size(prop);
@@ -386,12 +374,12 @@
 }
 
-static void get_fun_prop(function_t *fun, char *line)
+static void fun_prop_parse(isa_fun_t *fun, char *line)
 {
 	/* Skip leading spaces. */
 	line = skip_spaces(line);
 
-	if (!read_fun_prop(fun, line, "io_range", &get_dev_io_range) &&
-	    !read_fun_prop(fun, line, "irq", &get_dev_irq) &&
-	    !read_fun_prop(fun, line, "match", &get_fun_match_id))
+	if (!prop_parse(fun, line, "io_range", &fun_parse_io_range) &&
+	    !prop_parse(fun, line, "irq", &fun_parse_irq) &&
+	    !prop_parse(fun, line, "match", &fun_parse_match_id))
 	{
 	    printf(NAME " error undefined device property at line '%s'\n",
@@ -400,12 +388,11 @@
 }
 
-static void child_alloc_hw_res(function_t *fun)
-{
-	isa_fun_data_t *data = (isa_fun_data_t *)fun->driver_data;
-	data->hw_resources.resources = 
+static void fun_hw_res_alloc(isa_fun_t *fun)
+{
+	fun->hw_resources.resources = 
 	    (hw_resource_t *)malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES);
 }
 
-static char *read_isa_fun_info(char *fun_conf, device_t *dev)
+static char *isa_fun_read_info(char *fun_conf, device_t *dev)
 {
 	char *line;
@@ -430,5 +417,5 @@
 		return NULL;
 
-	function_t *fun = create_isa_fun();
+	isa_fun_t *fun = isa_fun_create();
 	if (fun == NULL) {
 		free(fun_name);
@@ -436,9 +423,10 @@
 	}
 
-	fun->name = fun_name;
-	fun->ftype = fun_inner;
+	function_t *fnode = fun->fnode;
+	fnode->name = fun_name;
+	fnode->ftype = fun_inner;
 
 	/* Allocate buffer for the list of hardware resources of the device. */
-	child_alloc_hw_res(fun);
+	fun_hw_res_alloc(fun);
 
 	/* Get properties of the device (match ids, irq and io range). */
@@ -455,34 +443,31 @@
 		 * and store it in the device structure.
 		 */
-		get_fun_prop(fun, line);
-
-		//printf(NAME ": next line ='%s'\n", fun_conf);
-		//printf(NAME ": current line ='%s'\n", line);
+		fun_prop_parse(fun, line);
 	}
 
 	/* Set device operations to the device. */
-	fun->ops = &isa_fun_dev_ops;
+	fnode->ops = &isa_fun_ops;
 
 	printf(NAME ": register_function(fun, dev); function is %s.\n",
-	    fun->name);
-	register_function(fun, dev);
+	    fnode->name);
+	register_function(fnode, dev);
 
 	return fun_conf;
 }
 
-static void parse_fun_conf(char *conf, device_t *dev)
+static void fun_conf_parse(char *conf, device_t *dev)
 {
 	while (conf != NULL && *conf != '\0') {
-		conf = read_isa_fun_info(conf, dev);
-	}
-}
-
-static void add_legacy_children(device_t *dev)
+		conf = isa_fun_read_info(conf, dev);
+	}
+}
+
+static void isa_functions_add(device_t *dev)
 {
 	char *fun_conf;
 
-	fun_conf = read_fun_conf(CHILD_FUN_CONF_PATH);
+	fun_conf = fun_conf_read(CHILD_FUN_CONF_PATH);
 	if (fun_conf != NULL) {
-		parse_fun_conf(fun_conf, dev);
+		fun_conf_parse(fun_conf, dev);
 		free(fun_conf);
 	}
@@ -502,7 +487,7 @@
 	register_function(ctl, dev);
 
-	/* Add child devices. */
-	add_legacy_children(dev);
-	printf(NAME ": finished the enumeration of legacy devices\n");
+	/* Add functions as specified in the configuration file. */
+	isa_functions_add(dev);
+	printf(NAME ": finished the enumeration of legacy functions\n");
 
 	return EOK;
@@ -511,5 +496,5 @@
 static void isa_init() 
 {
-	isa_fun_dev_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops;
+	isa_fun_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops;
 }
 
@@ -524,3 +509,2 @@
  * @}
  */
- 
Index: uspace/drv/ns8250/ns8250.c
===================================================================
--- uspace/drv/ns8250/ns8250.c	(revision 8b1e15ac9100f7b9da56e372d2f441ba44db6fcc)
+++ uspace/drv/ns8250/ns8250.c	(revision 68414f4a1f1b548a47a6b4525bd18dfbed67df1d)
@@ -1,4 +1,5 @@
-/*                        
+/*
  * Copyright (c) 2010 Lenka Trochtova
+ * Copyright (c) 2011 Jiri Svoboda
  * All rights reserved.
  *
@@ -68,4 +69,10 @@
 #define DLAB_MASK (1 << 7)
 
+/** Obtain soft-state structure from function node */
+#define NS8250(fnode) ((ns8250_t *) ((fnode)->dev->driver_data))
+
+/** Obtain soft-state structure from device node */
+#define NS8250_FROM_DEV(dnode) ((ns8250_t *) ((dnode)->driver_data))
+
 /** The number of bits of one data unit send by the serial port. */
 typedef enum {
@@ -85,5 +92,9 @@
 
 /** The driver data for the serial port devices. */
-typedef struct ns8250_dev_data {
+typedef struct ns8250 {
+	/** DDF device node */
+	device_t *dev;
+	/** DDF function node */
+	function_t *fun;
 	/** Is there any client conntected to the device? */
 	bool client_connected;
@@ -98,30 +109,29 @@
 	/** The fibril mutex for synchronizing the access to the device. */
 	fibril_mutex_t mutex;
-} ns8250_dev_data_t;
-
-/** Create driver data for a device.
- *
- * @return		The driver data.
- */
-static ns8250_dev_data_t *create_ns8250_dev_data(void)
-{
-	ns8250_dev_data_t *data;
-	
-	data = (ns8250_dev_data_t *) malloc(sizeof(ns8250_dev_data_t));
-	if (NULL != data) {
-		memset(data, 0, sizeof(ns8250_dev_data_t));
-		fibril_mutex_initialize(&data->mutex);
-	}
-	return data;
-}
-
-/** Delete driver data.
- *
- * @param data		The driver data structure.
- */
-static void delete_ns8250_dev_data(ns8250_dev_data_t *data)
-{
-	if (data != NULL)
-		free(data);
+} ns8250_t;
+
+/** Create per-device soft-state structure.
+ *
+ * @return	Pointer to soft-state structure.
+ */
+static ns8250_t *ns8250_new(void)
+{
+	ns8250_t *ns;
+	
+	ns = (ns8250_t *) calloc(1, sizeof(ns8250_t));
+	if (ns == NULL)
+		return NULL;
+	
+	fibril_mutex_initialize(&ns->mutex);
+	return ns;
+}
+
+/** Delete soft-state structure.
+ *
+ * @param ns	The driver data structure.
+ */
+static void ns8250_delete(ns8250_t *ns)
+{
+	free(ns);
 }
 
@@ -171,5 +181,5 @@
 /** Read data from the serial port device.
  *
- * @param dev		The serial port device.
+ * @param fun		The serial port function
  * @param buf		The ouput buffer for read data.
  * @param count		The number of bytes to be read.
@@ -180,13 +190,13 @@
 static int ns8250_read(function_t *fun, char *buf, size_t count)
 {
+	ns8250_t *ns = NS8250(fun);
 	int ret = EOK;
-	ns8250_dev_data_t *data = (ns8250_dev_data_t *) fun->dev->driver_data;
-	
-	fibril_mutex_lock(&data->mutex);
-	while (!buf_is_empty(&data->input_buffer) && (size_t)ret < count) {
-		buf[ret] = (char)buf_pop_front(&data->input_buffer);
+	
+	fibril_mutex_lock(&ns->mutex);
+	while (!buf_is_empty(&ns->input_buffer) && (size_t)ret < count) {
+		buf[ret] = (char)buf_pop_front(&ns->input_buffer);
 		ret++;
 	}
-	fibril_mutex_unlock(&data->mutex);
+	fibril_mutex_unlock(&ns->mutex);
 	
 	return ret;
@@ -195,28 +205,28 @@
 /** Write a character to the serial port.
  *
- * @param data		The serial port device's driver data.
- * @param c		The character to be written.
- */
-static inline void ns8250_putchar(ns8250_dev_data_t *data, uint8_t c)
-{
-	fibril_mutex_lock(&data->mutex);
-	ns8250_write_8(data->port, c);
-	fibril_mutex_unlock(&data->mutex);
+ * @param ns		Serial port device
+ * @param c		The character to be written
+ */
+static inline void ns8250_putchar(ns8250_t *ns, uint8_t c)
+{
+	fibril_mutex_lock(&ns->mutex);
+	ns8250_write_8(ns->port, c);
+	fibril_mutex_unlock(&ns->mutex);
 }
 
 /** Write data to the serial port.
  *
- * @param dev		The serial port device.
- * @param buf		The data to be written.
- * @param count		The number of bytes to be written.
- * @return		Zero on success.
+ * @param fun		The serial port function
+ * @param buf		The data to be written
+ * @param count		The number of bytes to be written
+ * @return		Zero on success
  */
 static int ns8250_write(function_t *fun, char *buf, size_t count)
 {
-	ns8250_dev_data_t *data = (ns8250_dev_data_t *) fun->dev->driver_data;
+	ns8250_t *ns = NS8250(fun);
 	size_t idx;
 	
 	for (idx = 0; idx < count; idx++)
-		ns8250_putchar(data, (uint8_t) buf[idx]);
+		ns8250_putchar(ns, (uint8_t) buf[idx]);
 	
 	return 0;
@@ -244,18 +254,13 @@
 };
 
-/** Clean up the serial port device structure.
- *
- * @param dev		The device structure.
- */
-static void ns8250_dev_cleanup(device_t *dev)
-{
-	if (dev->driver_data != NULL) {
-		delete_ns8250_dev_data((ns8250_dev_data_t*) dev->driver_data);
-		dev->driver_data = NULL;
-	}
-	
-	if (dev->parent_phone > 0) {
-		async_hangup(dev->parent_phone);
-		dev->parent_phone = 0;
+/** Clean up the serial port soft-state
+ *
+ * @param ns		Serial port device
+ */
+static void ns8250_dev_cleanup(ns8250_t *ns)
+{
+	if (ns->dev->parent_phone > 0) {
+		async_hangup(ns->dev->parent_phone);
+		ns->dev->parent_phone = 0;
 	}
 }
@@ -263,18 +268,16 @@
 /** Enable the i/o ports of the device.
  *
- * @param dev		The serial port device.
- * @return		True on success, false otherwise.
- */
-static bool ns8250_pio_enable(device_t *dev)
-{
-	printf(NAME ": ns8250_pio_enable %s\n", dev->name);
-	
-	ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
+ * @param ns		Serial port device
+ * @return		True on success, false otherwise
+ */
+static bool ns8250_pio_enable(ns8250_t *ns)
+{
+	printf(NAME ": ns8250_pio_enable %s\n", ns->dev->name);
 	
 	/* Gain control over port's registers. */
-	if (pio_enable((void *)(uintptr_t) data->io_addr, REG_COUNT,
-	    (void **) &data->port)) {
+	if (pio_enable((void *)(uintptr_t) ns->io_addr, REG_COUNT,
+	    (void **) &ns->port)) {
 		printf(NAME ": error - cannot gain the port %#" PRIx32 " for device "
-		    "%s.\n", data->io_addr, dev->name);
+		    "%s.\n", ns->io_addr, ns->dev->name);
 		return false;
 	}
@@ -285,13 +288,12 @@
 /** Probe the serial port device for its presence.
  *
- * @param dev		The serial port device.
- * @return		True if the device is present, false otherwise.
- */
-static bool ns8250_dev_probe(device_t *dev)
-{
-	printf(NAME ": ns8250_dev_probe %s\n", dev->name);
-	
-	ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data;
-	ioport8_t *port_addr = data->port;
+ * @param ns		Serial port device
+ * @return		True if the device is present, false otherwise
+ */
+static bool ns8250_dev_probe(ns8250_t *ns)
+{
+	printf(NAME ": ns8250_dev_probe %s\n", ns->dev->name);
+	
+	ioport8_t *port_addr = ns->port;
 	bool res = true;
 	uint8_t olddata;
@@ -310,5 +312,5 @@
 	
 	if (!res)
-		printf(NAME ": device %s is not present.\n", dev->name);
+		printf(NAME ": device %s is not present.\n", ns->dev->name);
 	
 	return res;
@@ -317,10 +319,10 @@
 /** Initialize serial port device.
  *
- * @param dev		The serial port device.
- * @return		Zero on success, negative error number otherwise.
- */
-static int ns8250_dev_initialize(device_t *dev)
-{
-	printf(NAME ": ns8250_dev_initialize %s\n", dev->name);
+ * @param ns		Serial port device
+ * @return		Zero on success, negative error number otherwise
+ */
+static int ns8250_dev_initialize(ns8250_t *ns)
+{
+	printf(NAME ": ns8250_dev_initialize %s\n", ns->dev->name);
 	
 	int ret = EOK;
@@ -329,25 +331,19 @@
 	memset(&hw_resources, 0, sizeof(hw_resource_list_t));
 	
-	/* Allocate driver data for the device. */
-	ns8250_dev_data_t *data = create_ns8250_dev_data();
-	if (data == NULL)
-		return ENOMEM;
-	dev->driver_data = data;
-	
 	/* Connect to the parent's driver. */
-	dev->parent_phone = devman_parent_device_connect(dev->handle,
+	ns->dev->parent_phone = devman_parent_device_connect(ns->dev->handle,
 	    IPC_FLAG_BLOCKING);
-	if (dev->parent_phone < 0) {
+	if (ns->dev->parent_phone < 0) {
 		printf(NAME ": failed to connect to the parent driver of the "
-		    "device %s.\n", dev->name);
-		ret = dev->parent_phone;
+		    "device %s.\n", ns->dev->name);
+		ret = ns->dev->parent_phone;
 		goto failed;
 	}
 	
 	/* Get hw resources. */
-	ret = hw_res_get_resource_list(dev->parent_phone, &hw_resources);
+	ret = hw_res_get_resource_list(ns->dev->parent_phone, &hw_resources);
 	if (ret != EOK) {
 		printf(NAME ": failed to get hw resources for the device "
-		    "%s.\n", dev->name);
+		    "%s.\n", ns->dev->name);
 		goto failed;
 	}
@@ -362,15 +358,15 @@
 		switch (res->type) {
 		case INTERRUPT:
-			data->irq = res->res.interrupt.irq;
+			ns->irq = res->res.interrupt.irq;
 			irq = true;
 			printf(NAME ": the %s device was asigned irq = 0x%x.\n",
-			    dev->name, data->irq);
+			    ns->dev->name, ns->irq);
 			break;
 			
 		case IO_RANGE:
-			data->io_addr = res->res.io_range.address;
+			ns->io_addr = res->res.io_range.address;
 			if (res->res.io_range.size < REG_COUNT) {
 				printf(NAME ": i/o range assigned to the device "
-				    "%s is too small.\n", dev->name);
+				    "%s is too small.\n", ns->dev->name);
 				ret = ELIMIT;
 				goto failed;
@@ -378,5 +374,5 @@
 			ioport = true;
 			printf(NAME ": the %s device was asigned i/o address = "
-			    "0x%x.\n", dev->name, data->io_addr);
+			    "0x%x.\n", ns->dev->name, ns->io_addr);
 			break;
 			
@@ -388,5 +384,5 @@
 	if (!irq || !ioport) {
 		printf(NAME ": missing hw resource(s) for the device %s.\n",
-		    dev->name);
+		    ns->dev->name);
 		ret = ENOENT;
 		goto failed;
@@ -397,5 +393,5 @@
 	
 failed:
-	ns8250_dev_cleanup(dev);
+	ns8250_dev_cleanup(ns);
 	hw_res_clean_resource_list(&hw_resources);
 	return ret;
@@ -404,5 +400,5 @@
 /** Enable interrupts on the serial port device.
  *
- * Interrupt when data is received.
+ * Interrupt when data is received
  *
  * @param port		The base address of the serial port device's ports.
@@ -416,5 +412,5 @@
 /** Disable interrupts on the serial port device.
  *
- * @param port		The base address of the serial port device's ports.
+ * @param port		The base address of the serial port device's ports
  */
 static inline void ns8250_port_interrupts_disable(ioport8_t *port)
@@ -425,13 +421,11 @@
 /** Enable interrupts for the serial port device.
  *
- * @param dev		The device.
- * @return		Zero on success, negative error number otherwise.
- */
-static int ns8250_interrupt_enable(device_t *dev)
-{
-	ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data;
-	
+ * @param ns		Serial port device
+ * @return		Zero on success, negative error number otherwise
+ */
+static int ns8250_interrupt_enable(ns8250_t *ns)
+{
 	/* Enable interrupt on the serial port. */
-	ns8250_port_interrupts_enable(data->port);
+	ns8250_port_interrupts_enable(ns->port);
 	
 	return EOK;
@@ -618,10 +612,9 @@
  * Set the default parameters of the serial communication.
  *
- * @param dev		The serial port device.
- */
-static void ns8250_initialize_port(device_t *dev)
-{
-	ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
-	ioport8_t *port = data->port;
+ * @param ns		Serial port device
+ */
+static void ns8250_initialize_port(ns8250_t *ns)
+{
+	ioport8_t *port = ns->port;
 	
 	/* Disable interrupts. */
@@ -643,14 +636,13 @@
  * buffer.
  *
- * @param dev		The serial port device.
- */
-static void ns8250_read_from_device(device_t *dev)
-{
-	ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data;
-	ioport8_t *port = data->port;
+ * @param ns		Serial port device
+ */
+static void ns8250_read_from_device(ns8250_t *ns)
+{
+	ioport8_t *port = ns->port;
 	bool cont = true;
 	
 	while (cont) {
-		fibril_mutex_lock(&data->mutex);
+		fibril_mutex_lock(&ns->mutex);
 		
 		cont = ns8250_received(port);
@@ -658,17 +650,17 @@
 			uint8_t val = ns8250_read_8(port);
 			
-			if (data->client_connected) {
-				if (!buf_push_back(&data->input_buffer, val)) {
+			if (ns->client_connected) {
+				if (!buf_push_back(&ns->input_buffer, val)) {
 					printf(NAME ": buffer overflow on "
-					    "%s.\n", dev->name);
+					    "%s.\n", ns->dev->name);
 				} else {
 					printf(NAME ": the character %c saved "
 					    "to the buffer of %s.\n",
-					    val, dev->name);
+					    val, ns->dev->name);
 				}
 			}
 		}
 		
-		fibril_mutex_unlock(&data->mutex);
+		fibril_mutex_unlock(&ns->mutex);
 		fibril_yield();
 	}
@@ -685,78 +677,87 @@
     ipc_call_t *icall)
 {
-	ns8250_read_from_device(dev);
+	ns8250_read_from_device(NS8250_FROM_DEV(dev));
 }
 
 /** Register the interrupt handler for the device.
  *
+ * @param ns		Serial port device
+ */
+static inline int ns8250_register_interrupt_handler(ns8250_t *ns)
+{
+	return register_interrupt_handler(ns->dev, ns->irq,
+	    ns8250_interrupt_handler, NULL);
+}
+
+/** Unregister the interrupt handler for the device.
+ *
+ * @param ns		Serial port device
+ */
+static inline int ns8250_unregister_interrupt_handler(ns8250_t *ns)
+{
+	return unregister_interrupt_handler(ns->dev, ns->irq);
+}
+
+/** The add_device callback method of the serial port driver.
+ *
+ * Probe and initialize the newly added device.
+ *
  * @param dev		The serial port device.
  */
-static inline int ns8250_register_interrupt_handler(device_t *dev)
-{
-	ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data;
-	
-	return register_interrupt_handler(dev, data->irq,
-	    ns8250_interrupt_handler, NULL);
-}
-
-/** Unregister the interrupt handler for the device.
- *
- * @param dev		The serial port device.
- */
-static inline int ns8250_unregister_interrupt_handler(device_t *dev)
-{
-	ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data;
-	
-	return unregister_interrupt_handler(dev, data->irq);
-}
-
-/** The add_device callback method of the serial port driver.
- *
- * Probe and initialize the newly added device.
- *
- * @param dev		The serial port device.
- */
 static int ns8250_add_device(device_t *dev)
 {
-	function_t *fun;
-
+	ns8250_t *ns = NULL;
+	function_t *fun = NULL;
+	bool need_cleanup = false;
+	int rc;
+	
 	printf(NAME ": ns8250_add_device %s (handle = %d)\n",
 	    dev->name, (int) dev->handle);
 	
-	int res = ns8250_dev_initialize(dev);
-	if (res != EOK)
-		return res;
-	
-	if (!ns8250_pio_enable(dev)) {
-		ns8250_dev_cleanup(dev);
-		return EADDRNOTAVAIL;
+	/* Allocate soft-state for the device */
+	ns = ns8250_new();
+	if (ns == NULL) {
+		rc = ENOMEM;
+		goto fail;
+	}
+	
+	ns->dev = dev;
+	dev->driver_data = ns;
+	
+	rc = ns8250_dev_initialize(ns);
+	if (rc != EOK)
+		goto fail;
+	
+	need_cleanup = true;
+	
+	if (!ns8250_pio_enable(ns)) {
+		rc = EADDRNOTAVAIL;
+		goto fail;
 	}
 	
 	/* Find out whether the device is present. */
-	if (!ns8250_dev_probe(dev)) {
-		ns8250_dev_cleanup(dev);
-		return ENOENT;
+	if (!ns8250_dev_probe(ns)) {
+		rc = ENOENT;
+		goto fail;
 	}
 	
 	/* Serial port initialization (baud rate etc.). */
-	ns8250_initialize_port(dev);
+	ns8250_initialize_port(ns);
 	
 	/* Register interrupt handler. */
-	if (ns8250_register_interrupt_handler(dev) != EOK) {
+	if (ns8250_register_interrupt_handler(ns) != EOK) {
 		printf(NAME ": failed to register interrupt handler.\n");
-		ns8250_dev_cleanup(dev);
-		return res;
+		rc = EADDRNOTAVAIL;
+		goto fail;
 	}
 	
 	/* Enable interrupt. */
-	res = ns8250_interrupt_enable(dev);
-	if (res != EOK) {
+	rc = ns8250_interrupt_enable(ns);
+	if (rc != EOK) {
 		printf(NAME ": failed to enable the interrupt. Error code = "
-		    "%d.\n", res);
-		ns8250_dev_cleanup(dev);
-		ns8250_unregister_interrupt_handler(dev);
-		return res;
-	}
-
+		    "%d.\n", rc);
+		goto fail;
+	}
+	
 	fun = create_function();
 	fun->ftype = fun_exposed;
@@ -766,4 +767,5 @@
 	fun->ops = &ns8250_dev_ops;
 	register_function(fun, dev);
+	ns->fun = fun;
 	
 	add_function_to_class(fun, "serial");
@@ -773,4 +775,10 @@
 	
 	return EOK;
+fail:
+	if (need_cleanup)
+		ns8250_dev_cleanup(ns);
+	if (ns != NULL)
+		ns8250_delete(ns);
+	return rc;
 }
 
@@ -784,5 +792,5 @@
 static int ns8250_open(function_t *fun)
 {
-	ns8250_dev_data_t *data = (ns8250_dev_data_t *) fun->dev->driver_data;
+	ns8250_t *data = (ns8250_t *) fun->dev->driver_data;
 	int res;
 	
@@ -808,5 +816,5 @@
 static void ns8250_close(function_t *fun)
 {
-	ns8250_dev_data_t *data = (ns8250_dev_data_t *) fun->dev->driver_data;
+	ns8250_t *data = (ns8250_t *) fun->dev->driver_data;
 	
 	fibril_mutex_lock(&data->mutex);
@@ -833,5 +841,5 @@
     unsigned int *word_length, unsigned int* stop_bits)
 {
-	ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data;
+	ns8250_t *data = (ns8250_t *) dev->driver_data;
 	ioport8_t *port = data->port;
 	
@@ -864,5 +872,5 @@
 	    stop_bits);
 	
-	ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data;
+	ns8250_t *data = (ns8250_t *) dev->driver_data;
 	ioport8_t *port = data->port;
 	int ret;
Index: uspace/drv/pciintel/pci.c
===================================================================
--- uspace/drv/pciintel/pci.c	(revision 8b1e15ac9100f7b9da56e372d2f441ba44db6fcc)
+++ uspace/drv/pciintel/pci.c	(revision 68414f4a1f1b548a47a6b4525bd18dfbed67df1d)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2010 Lenka Trochtova
+ * Copyright (c) 2011 Jiri Svoboda
  * All rights reserved.
  *
@@ -61,14 +62,23 @@
 	((1 << 31) | (bus << 16) | (dev << 11) | (fn << 8) | (reg & ~3))
 
-static hw_resource_list_t *pciintel_get_child_resources(function_t *fun)
-{
-	pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data;
-	
-	if (fun_data == NULL)
+/** Obtain PCI function soft-state from DDF function node */
+#define PCI_FUN(fnode) ((pci_fun_t *) (fnode)->driver_data)
+
+/** Obtain PCI bus soft-state from DDF device node */
+#define PCI_BUS(dnode) ((pci_bus_t *) (dnode)->driver_data)
+
+/** Obtain PCI bus soft-state from function soft-state */
+#define PCI_BUS_FROM_FUN(fun) (PCI_BUS(fun->fnode->dev))
+
+static hw_resource_list_t *pciintel_get_resources(function_t *fnode)
+{
+	pci_fun_t *fun = PCI_FUN(fnode);
+	
+	if (fun == NULL)
 		return NULL;
-	return &fun_data->hw_resources;
-}
-
-static bool pciintel_enable_child_interrupt(function_t *fun)
+	return &fun->hw_resources;
+}
+
+static bool pciintel_enable_interrupt(function_t *fnode)
 {
 	/* TODO */
@@ -77,19 +87,19 @@
 }
 
-static hw_res_ops_t pciintel_child_hw_res_ops = {
-	&pciintel_get_child_resources,
-	&pciintel_enable_child_interrupt
+static hw_res_ops_t pciintel_hw_res_ops = {
+	&pciintel_get_resources,
+	&pciintel_enable_interrupt
 };
 
-static device_ops_t pci_child_ops;
+static device_ops_t pci_fun_ops;
 
 static int pci_add_device(device_t *);
 
-/** The pci bus driver's standard operations. */
+/** PCI bus driver standard operations */
 static driver_ops_t pci_ops = {
 	.add_device = &pci_add_device
 };
 
-/** The pci bus driver structure. */
+/** PCI bus driver structure */
 static driver_t pci_driver = {
 	.name = NAME,
@@ -97,43 +107,33 @@
 };
 
-typedef struct pciintel_bus_data {
-	uint32_t conf_io_addr;
-	void *conf_data_port;
-	void *conf_addr_port;
-	fibril_mutex_t conf_mutex;
-} pci_bus_data_t;
-
-static pci_bus_data_t *create_pci_bus_data(void)
-{
-	pci_bus_data_t *bus_data;
-	
-	bus_data = (pci_bus_data_t *) malloc(sizeof(pci_bus_data_t));
-	if (bus_data != NULL) {
-		memset(bus_data, 0, sizeof(pci_bus_data_t));
-		fibril_mutex_initialize(&bus_data->conf_mutex);
-	}
-
-	return bus_data;
-}
-
-static void delete_pci_bus_data(pci_bus_data_t *bus_data)
-{
-	free(bus_data);
-}
-
-static void pci_conf_read(function_t *fun, int reg, uint8_t *buf, size_t len)
-{
-	assert(fun->dev != NULL);
-	
-	pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data;
-	pci_bus_data_t *bus_data = (pci_bus_data_t *) fun->dev->driver_data;
-	
-	fibril_mutex_lock(&bus_data->conf_mutex);
+static pci_bus_t *pci_bus_new(void)
+{
+	pci_bus_t *bus;
+	
+	bus = (pci_bus_t *) malloc(sizeof(pci_bus_t));
+	if (bus != NULL) {
+		memset(bus, 0, sizeof(pci_bus_t));
+		fibril_mutex_initialize(&bus->conf_mutex);
+	}
+
+	return bus;
+}
+
+static void pci_bus_delete(pci_bus_t *bus)
+{
+	free(bus);
+}
+
+static void pci_conf_read(pci_fun_t *fun, int reg, uint8_t *buf, size_t len)
+{
+	pci_bus_t *bus = PCI_BUS_FROM_FUN(fun);
+	
+	fibril_mutex_lock(&bus->conf_mutex);
 	
 	uint32_t conf_addr;
-	conf_addr = CONF_ADDR(fun_data->bus, fun_data->dev, fun_data->fn, reg);
-	void *addr = bus_data->conf_data_port + (reg & 3);
-	
-	pio_write_32(bus_data->conf_addr_port, conf_addr);
+	conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
+	void *addr = bus->conf_data_port + (reg & 3);
+	
+	pio_write_32(bus->conf_addr_port, conf_addr);
 	
 	switch (len) {
@@ -149,21 +149,18 @@
 	}
 	
-	fibril_mutex_unlock(&bus_data->conf_mutex);
-}
-
-static void pci_conf_write(function_t *fun, int reg, uint8_t *buf, size_t len)
-{
-	assert(fun->dev != NULL);
-	
-	pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data;
-	pci_bus_data_t *bus_data = (pci_bus_data_t *) fun->dev->driver_data;
-	
-	fibril_mutex_lock(&bus_data->conf_mutex);
+	fibril_mutex_unlock(&bus->conf_mutex);
+}
+
+static void pci_conf_write(pci_fun_t *fun, int reg, uint8_t *buf, size_t len)
+{
+	pci_bus_t *bus = PCI_BUS_FROM_FUN(fun);
+	
+	fibril_mutex_lock(&bus->conf_mutex);
 	
 	uint32_t conf_addr;
-	conf_addr = CONF_ADDR(fun_data->bus, fun_data->dev, fun_data->fn, reg);
-	void *addr = bus_data->conf_data_port + (reg & 3);
-	
-	pio_write_32(bus_data->conf_addr_port, conf_addr);
+	conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
+	void *addr = bus->conf_data_port + (reg & 3);
+	
+	pio_write_32(bus->conf_addr_port, conf_addr);
 	
 	switch (len) {
@@ -179,8 +176,8 @@
 	}
 	
-	fibril_mutex_unlock(&bus_data->conf_mutex);
-}
-
-uint8_t pci_conf_read_8(function_t *fun, int reg)
+	fibril_mutex_unlock(&bus->conf_mutex);
+}
+
+uint8_t pci_conf_read_8(pci_fun_t *fun, int reg)
 {
 	uint8_t res;
@@ -189,5 +186,5 @@
 }
 
-uint16_t pci_conf_read_16(function_t *fun, int reg)
+uint16_t pci_conf_read_16(pci_fun_t *fun, int reg)
 {
 	uint16_t res;
@@ -196,5 +193,5 @@
 }
 
-uint32_t pci_conf_read_32(function_t *fun, int reg)
+uint32_t pci_conf_read_32(pci_fun_t *fun, int reg)
 {
 	uint32_t res;
@@ -203,22 +200,21 @@
 }
 
-void pci_conf_write_8(function_t *fun, int reg, uint8_t val)
+void pci_conf_write_8(pci_fun_t *fun, int reg, uint8_t val)
 {
 	pci_conf_write(fun, reg, (uint8_t *) &val, 1);
 }
 
-void pci_conf_write_16(function_t *fun, int reg, uint16_t val)
+void pci_conf_write_16(pci_fun_t *fun, int reg, uint16_t val)
 {
 	pci_conf_write(fun, reg, (uint8_t *) &val, 2);
 }
 
-void pci_conf_write_32(function_t *fun, int reg, uint32_t val)
+void pci_conf_write_32(pci_fun_t *fun, int reg, uint32_t val)
 {
 	pci_conf_write(fun, reg, (uint8_t *) &val, 4);
 }
 
-void create_pci_match_ids(function_t *fun)
-{
-	pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data;
+void pci_fun_create_match_ids(pci_fun_t *fun)
+{
 	match_id_t *match_id = NULL;
 	char *match_id_str;
@@ -227,8 +223,8 @@
 	if (match_id != NULL) {
 		asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
-		    fun_data->vendor_id, fun_data->device_id);
+		    fun->vendor_id, fun->device_id);
 		match_id->id = match_id_str;
 		match_id->score = 90;
-		add_match_id(&fun->match_ids, match_id);
+		add_match_id(&fun->fnode->match_ids, match_id);
 	}
 
@@ -236,9 +232,8 @@
 }
 
-void
-pci_add_range(function_t *fun, uint64_t range_addr, size_t range_size, bool io)
-{
-	pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data;
-	hw_resource_list_t *hw_res_list = &fun_data->hw_resources;
+void pci_add_range(pci_fun_t *fun, uint64_t range_addr, size_t range_size,
+    bool io)
+{
+	hw_resource_list_t *hw_res_list = &fun->hw_resources;
 	hw_resource_t *hw_resources =  hw_res_list->resources;
 	size_t count = hw_res_list->count;
@@ -265,10 +260,10 @@
  * address add it to the devices hw resource list.
  *
- * @param dev	The pci device.
+ * @param fun	PCI function
  * @param addr	The address of the BAR in the PCI configuration address space of
- *		the device.
- * @return	The addr the address of the BAR which should be read next.
+ *		the device
+ * @return	The addr the address of the BAR which should be read next
  */
-int pci_read_bar(function_t *fun, int addr)
+int pci_read_bar(pci_fun_t *fun, int addr)
 {	
 	/* Value of the BAR */
@@ -322,5 +317,5 @@
 	
 	if (range_addr != 0) {
-		printf(NAME ": function %s : ", fun->name);
+		printf(NAME ": function %s : ", fun->fnode->name);
 		printf("address = %" PRIx64, range_addr);
 		printf(", size = %x\n", (unsigned int) range_size);
@@ -335,8 +330,7 @@
 }
 
-void pci_add_interrupt(function_t *fun, int irq)
-{
-	pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data;
-	hw_resource_list_t *hw_res_list = &fun_data->hw_resources;
+void pci_add_interrupt(pci_fun_t *fun, int irq)
+{
+	hw_resource_list_t *hw_res_list = &fun->hw_resources;
 	hw_resource_t *hw_resources = hw_res_list->resources;
 	size_t count = hw_res_list->count;
@@ -350,8 +344,8 @@
 	hw_res_list->count++;
 	
-	printf(NAME ": function %s uses irq %x.\n", fun->name, irq);
-}
-
-void pci_read_interrupt(function_t *fun)
+	printf(NAME ": function %s uses irq %x.\n", fun->fnode->name, irq);
+}
+
+void pci_read_interrupt(pci_fun_t *fun)
 {
 	uint8_t irq = pci_conf_read_8(fun, PCI_BRIDGE_INT_LINE);
@@ -362,12 +356,12 @@
 /** Enumerate (recursively) and register the devices connected to a pci bus.
  *
- * @param dev		The host-to-pci bridge device.
- * @param bus_num	The bus number.
+ * @param bus		Host-to-PCI bridge
+ * @param bus_num	Bus number
  */
-void pci_bus_scan(device_t *dev, int bus_num) 
-{
-	function_t *fun = create_function();
-	pci_fun_data_t *fun_data = create_pci_fun_data();
-	fun->driver_data = fun_data;
+void pci_bus_scan(pci_bus_t *bus, int bus_num) 
+{
+	function_t *fnode = create_function();
+	pci_fun_t *fun = pci_fun_new();
+	fnode->driver_data = fun;
 	
 	int child_bus = 0;
@@ -377,15 +371,17 @@
 
 	/* We need this early, before registering. */
-	fun->dev = dev;
+	fun->fnode = fnode;
+	fnode->dev = bus->dnode;
+	fnode->driver_data = fun;
 	
 	for (dnum = 0; dnum < 32; dnum++) {
 		multi = true;
 		for (fnum = 0; multi && fnum < 8; fnum++) {
-			init_pci_fun_data(fun_data, bus_num, dnum, fnum);
-			fun_data->vendor_id = pci_conf_read_16(fun,
+			pci_fun_init(fun, bus_num, dnum, fnum);
+			fun->vendor_id = pci_conf_read_16(fun,
 			    PCI_VENDOR_ID);
-			fun_data->device_id = pci_conf_read_16(fun,
+			fun->device_id = pci_conf_read_16(fun,
 			    PCI_DEVICE_ID);
-			if (fun_data->vendor_id == 0xffff) {
+			if (fun->vendor_id == 0xffff) {
 				/*
 				 * The device is not present, go on scanning the
@@ -406,5 +402,5 @@
 			header_type = header_type & 0x7F;
 			
-			create_pci_fun_name(fun);
+			pci_fun_create_name(fun);
 			
 			pci_alloc_resource_list(fun);
@@ -412,17 +408,17 @@
 			pci_read_interrupt(fun);
 			
-			fun->ftype = fun_inner;
-			fun->ops = &pci_child_ops;
+			fnode->ftype = fun_inner;
+			fnode->ops = &pci_fun_ops;
 			
 			printf(NAME ": adding new function %s.\n",
-			    fun->name);
-			
-			create_pci_match_ids(fun);
-			
-			if (register_function(fun, dev) != EOK) {
+			    fnode->name);
+			
+			pci_fun_create_match_ids(fun);
+			
+			if (register_function(fnode, bus->dnode) != EOK) {
 				pci_clean_resource_list(fun);
-				clean_match_ids(&fun->match_ids);
-				free((char *) fun->name);
-				fun->name = NULL;
+				clean_match_ids(&fnode->match_ids);
+				free((char *) fnode->name);
+				fnode->name = NULL;
 				continue;
 			}
@@ -435,54 +431,57 @@
 				    "secondary bus number = %d.\n", bus_num);
 				if (child_bus > bus_num)
-					pci_bus_scan(dev, child_bus);
+					pci_bus_scan(bus, child_bus);
 			}
 			
 			/* Alloc new aux. fun. structure. */
-			fun = create_function();
+			fnode = create_function();
 
 			/* We need this early, before registering. */
-		    	fun->dev = dev;
-
-			fun_data = create_pci_fun_data();
-			fun->driver_data = fun_data;
+		    	fnode->dev = bus->dnode;
+
+			fun = pci_fun_new();
+			fun->fnode = fnode;
+			fnode->driver_data = fun;
 		}
 	}
 	
-	if (fun_data->vendor_id == 0xffff) {
-		delete_function(fun);
+	if (fun->vendor_id == 0xffff) {
+		delete_function(fnode);
 		/* Free the auxiliary function structure. */
-		delete_pci_fun_data(fun_data);
-	}
-}
-
-static int pci_add_device(device_t *dev)
+		pci_fun_delete(fun);
+	}
+}
+
+static int pci_add_device(device_t *dnode)
 {
 	int rc;
-
+	
 	printf(NAME ": pci_add_device\n");
 	
-	pci_bus_data_t *bus_data = create_pci_bus_data();
-	if (bus_data == NULL) {
+	pci_bus_t *bus = pci_bus_new();
+	if (bus == NULL) {
 		printf(NAME ": pci_add_device allocation failed.\n");
 		return ENOMEM;
 	}
-	
-	dev->parent_phone = devman_parent_device_connect(dev->handle,
+	bus->dnode = dnode;
+	dnode->driver_data = bus;
+	
+	dnode->parent_phone = devman_parent_device_connect(dnode->handle,
 	    IPC_FLAG_BLOCKING);
-	if (dev->parent_phone < 0) {
+	if (dnode->parent_phone < 0) {
 		printf(NAME ": pci_add_device failed to connect to the "
 		    "parent's driver.\n");
-		delete_pci_bus_data(bus_data);
-		return dev->parent_phone;
+		pci_bus_delete(bus);
+		return dnode->parent_phone;
 	}
 	
 	hw_resource_list_t hw_resources;
 	
-	rc = hw_res_get_resource_list(dev->parent_phone, &hw_resources);
+	rc = hw_res_get_resource_list(dnode->parent_phone, &hw_resources);
 	if (rc != EOK) {
 		printf(NAME ": pci_add_device failed to get hw resources for "
 		    "the device.\n");
-		delete_pci_bus_data(bus_data);
-		async_hangup(dev->parent_phone);
+		pci_bus_delete(bus);
+		async_hangup(dnode->parent_phone);
 		return rc;
 	}	
@@ -495,30 +494,28 @@
 	assert(hw_resources.resources[0].res.io_range.size == 8);
 	
-	bus_data->conf_io_addr =
+	bus->conf_io_addr =
 	    (uint32_t) hw_resources.resources[0].res.io_range.address;
 	
-	if (pio_enable((void *)(uintptr_t)bus_data->conf_io_addr, 8,
-	    &bus_data->conf_addr_port)) {
+	if (pio_enable((void *)(uintptr_t)bus->conf_io_addr, 8,
+	    &bus->conf_addr_port)) {
 		printf(NAME ": failed to enable configuration ports.\n");
-		delete_pci_bus_data(bus_data);
-		async_hangup(dev->parent_phone);
+		pci_bus_delete(bus);
+		async_hangup(dnode->parent_phone);
 		hw_res_clean_resource_list(&hw_resources);
 		return EADDRNOTAVAIL;
 	}
-	bus_data->conf_data_port = (char *) bus_data->conf_addr_port + 4;
-	
-	dev->driver_data = bus_data;
-	
-	/* Make the bus device more visible. Does not do anything. */
+	bus->conf_data_port = (char *) bus->conf_addr_port + 4;
+	
+	/* Make the bus device more visible. It has no use yet. */
 	printf(NAME ": adding a 'ctl' function\n");
-
+	
 	function_t *ctl = create_function();
 	ctl->ftype = fun_exposed;
 	ctl->name = "ctl";
-	register_function(ctl, dev);
-	
-	/* Enumerate child devices. */
+	register_function(ctl, dnode);
+	
+	/* Enumerate functions. */
 	printf(NAME ": scanning the bus\n");
-	pci_bus_scan(dev, 0);
+	pci_bus_scan(bus, 0);
 	
 	hw_res_clean_resource_list(&hw_resources);
@@ -529,66 +526,61 @@
 static void pciintel_init(void)
 {
-	pci_child_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_child_hw_res_ops;
-}
-
-pci_fun_data_t *create_pci_fun_data(void)
-{
-	pci_fun_data_t *res = (pci_fun_data_t *) malloc(sizeof(pci_fun_data_t));
+	pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops;
+}
+
+pci_fun_t *pci_fun_new(void)
+{
+	pci_fun_t *res = (pci_fun_t *) malloc(sizeof(pci_fun_t));
 	
 	if (res != NULL)
-		memset(res, 0, sizeof(pci_fun_data_t));
+		memset(res, 0, sizeof(pci_fun_t));
 	return res;
 }
 
-void init_pci_fun_data(pci_fun_data_t *fun_data, int bus, int dev, int fn)
-{
-	fun_data->bus = bus;
-	fun_data->dev = dev;
-	fun_data->fn = fn;
-}
-
-void delete_pci_fun_data(pci_fun_data_t *fun_data)
-{
-	if (fun_data != NULL) {
-		hw_res_clean_resource_list(&fun_data->hw_resources);
-		free(fun_data);
-	}
-}
-
-void create_pci_fun_name(function_t *fun)
-{
-	pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data;
+void pci_fun_init(pci_fun_t *fun, int bus, int dev, int fn)
+{
+	fun->bus = bus;
+	fun->dev = dev;
+	fun->fn = fn;
+}
+
+void pci_fun_delete(pci_fun_t *fun)
+{
+	if (fun != NULL) {
+		hw_res_clean_resource_list(&fun->hw_resources);
+		free(fun);
+	}
+}
+
+void pci_fun_create_name(pci_fun_t *fun)
+{
 	char *name = NULL;
 	
-	asprintf(&name, "%02x:%02x.%01x", fun_data->bus, fun_data->dev,
-	    fun_data->fn);
-	fun->name = name;
-}
-
-bool pci_alloc_resource_list(function_t *fun)
-{
-	pci_fun_data_t *fun_data = (pci_fun_data_t *)fun->driver_data;
-	
-	fun_data->hw_resources.resources =
+	asprintf(&name, "%02x:%02x.%01x", fun->bus, fun->dev,
+	    fun->fn);
+	fun->fnode->name = name;
+}
+
+bool pci_alloc_resource_list(pci_fun_t *fun)
+{
+	fun->hw_resources.resources =
 	    (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
-	return fun_data->hw_resources.resources != NULL;
-}
-
-void pci_clean_resource_list(function_t *fun)
-{
-	pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data;
-	
-	if (fun_data->hw_resources.resources != NULL) {
-		free(fun_data->hw_resources.resources);
-		fun_data->hw_resources.resources = NULL;
-	}
-}
-
-/** Read the base address registers (BARs) of the device and adds the addresses
- * to its hw resource list.
+	return fun->hw_resources.resources != NULL;
+}
+
+void pci_clean_resource_list(pci_fun_t *fun)
+{
+	if (fun->hw_resources.resources != NULL) {
+		free(fun->hw_resources.resources);
+		fun->hw_resources.resources = NULL;
+	}
+}
+
+/** Read the base address registers (BARs) of the function and add the addresses
+ * to its HW resource list.
  *
- * @param dev the pci device.
+ * @param fun	PCI function
  */
-void pci_read_bars(function_t *fun)
+void pci_read_bars(pci_fun_t *fun)
 {
 	/*
Index: uspace/drv/pciintel/pci.h
===================================================================
--- uspace/drv/pciintel/pci.h	(revision 8b1e15ac9100f7b9da56e372d2f441ba44db6fcc)
+++ uspace/drv/pciintel/pci.h	(revision 68414f4a1f1b548a47a6b4525bd18dfbed67df1d)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2010 Lenka Trochtova
+ * Copyright (c) 2011 Jiri Svoboda
  * All rights reserved.
  *
@@ -45,4 +46,6 @@
 
 typedef struct pci_fun_data {
+	function_t *fnode;
+
 	int bus;
 	int dev;
@@ -51,31 +54,40 @@
 	int device_id;
 	hw_resource_list_t hw_resources;
-} pci_fun_data_t;
+} pci_fun_t;
 
-extern void create_pci_match_ids(function_t *);
+typedef struct pciintel_bus {
+	/** DDF device node */
+	device_t *dnode;
+	uint32_t conf_io_addr;
+	void *conf_data_port;
+	void *conf_addr_port;
+	fibril_mutex_t conf_mutex;
+} pci_bus_t;
 
-extern uint8_t pci_conf_read_8(function_t *, int);
-extern uint16_t pci_conf_read_16(function_t *, int);
-extern uint32_t pci_conf_read_32(function_t *, int);
-extern void pci_conf_write_8(function_t *, int, uint8_t);
-extern void pci_conf_write_16(function_t *, int, uint16_t);
-extern void pci_conf_write_32(function_t *, int, uint32_t);
+extern void pci_fun_create_match_ids(pci_fun_t *);
 
-extern void pci_add_range(function_t *, uint64_t, size_t, bool);
-extern int pci_read_bar(function_t *, int);
-extern void pci_read_interrupt(function_t *);
-extern void pci_add_interrupt(function_t *, int);
+extern uint8_t pci_conf_read_8(pci_fun_t *, int);
+extern uint16_t pci_conf_read_16(pci_fun_t *, int);
+extern uint32_t pci_conf_read_32(pci_fun_t *, int);
+extern void pci_conf_write_8(pci_fun_t *, int, uint8_t);
+extern void pci_conf_write_16(pci_fun_t *, int, uint16_t);
+extern void pci_conf_write_32(pci_fun_t *, int, uint32_t);
 
-extern void pci_bus_scan(device_t *, int);
+extern void pci_add_range(pci_fun_t *, uint64_t, size_t, bool);
+extern int pci_read_bar(pci_fun_t *, int);
+extern void pci_read_interrupt(pci_fun_t *);
+extern void pci_add_interrupt(pci_fun_t *, int);
 
-extern pci_fun_data_t *create_pci_fun_data(void);
-extern void init_pci_fun_data(pci_fun_data_t *, int, int, int);
-extern void delete_pci_fun_data(pci_fun_data_t *);
-extern void create_pci_fun_name(function_t *);
+extern pci_fun_t *pci_fun_new(void);
+extern void pci_fun_init(pci_fun_t *, int, int, int);
+extern void pci_fun_delete(pci_fun_t *);
+extern void pci_fun_create_name(pci_fun_t *);
 
-extern bool pci_alloc_resource_list(function_t *);
-extern void pci_clean_resource_list(function_t *);
+extern void pci_bus_scan(pci_bus_t *, int);
 
-extern void pci_read_bars(function_t *);
+extern bool pci_alloc_resource_list(pci_fun_t *);
+extern void pci_clean_resource_list(pci_fun_t *);
+
+extern void pci_read_bars(pci_fun_t *);
 extern size_t pci_bar_mask_to_size(uint32_t);
 
Index: uspace/drv/root/root.c
===================================================================
--- uspace/drv/root/root.c	(revision 8b1e15ac9100f7b9da56e372d2f441ba44db6fcc)
+++ uspace/drv/root/root.c	(revision 68414f4a1f1b548a47a6b4525bd18dfbed67df1d)
@@ -2,4 +2,5 @@
  * Copyright (c) 2010 Lenka Trochtova
  * Copyright (c) 2010 Vojtech Horky
+ * Copyright (c) 2011 Jiri Svoboda
  * All rights reserved.
  *
@@ -55,11 +56,11 @@
 #define NAME "root"
 
-#define PLATFORM_DEVICE_NAME "hw"
-#define PLATFORM_DEVICE_MATCH_ID_FMT "platform/%s"
-#define PLATFORM_DEVICE_MATCH_SCORE 100
+#define PLATFORM_FUN_NAME "hw"
+#define PLATFORM_FUN_MATCH_ID_FMT "platform/%s"
+#define PLATFORM_FUN_MATCH_SCORE 100
 
-#define VIRTUAL_DEVICE_NAME "virt"
-#define VIRTUAL_DEVICE_MATCH_ID "rootvirt"
-#define VIRTUAL_DEVICE_MATCH_SCORE 100
+#define VIRTUAL_FUN_NAME "virt"
+#define VIRTUAL_FUN_MATCH_ID "rootvirt"
+#define VIRTUAL_FUN_MATCH_SCORE 100
 
 static int root_add_device(device_t *dev);
@@ -76,27 +77,27 @@
 };
 
-/** Create the device which represents the root of virtual device tree.
+/** Create the function which represents the root of virtual device tree.
  *
- * @param parent Parent of the newly created device.
- * @return Error code.
+ * @param dev	Device
+ * @return	EOK on success or negative error code
  */
-static int add_virtual_root_child(device_t *parent)
+static int add_virtual_root_fun(device_t *dev)
 {
-	printf(NAME ": adding new child for virtual devices.\n");
-	printf(NAME ":   device node is `%s' (%d %s)\n", VIRTUAL_DEVICE_NAME,
-	    VIRTUAL_DEVICE_MATCH_SCORE, VIRTUAL_DEVICE_MATCH_ID);
+	printf(NAME ": adding new function for virtual devices.\n");
+	printf(NAME ":   function node is `%s' (%d %s)\n", VIRTUAL_FUN_NAME,
+	    VIRTUAL_FUN_MATCH_SCORE, VIRTUAL_FUN_MATCH_ID);
 
-	int res = register_function_wrapper(parent, VIRTUAL_DEVICE_NAME,
-	    VIRTUAL_DEVICE_MATCH_ID, VIRTUAL_DEVICE_MATCH_SCORE);
+	int res = register_function_wrapper(dev, VIRTUAL_FUN_NAME,
+	    VIRTUAL_FUN_MATCH_ID, VIRTUAL_FUN_MATCH_SCORE);
 
 	return res;
 }
 
-/** Create the device which represents the root of HW device tree.
+/** Create the function which represents the root of HW device tree.
  *
- * @param parent	Parent of the newly created device.
- * @return 0 on success, negative error number otherwise.
+ * @param dev	Device
+ * @return	EOK on success or negative error code
  */
-static int add_platform_child(device_t *parent)
+static int add_platform_fun(device_t *dev)
 {
 	char *match_id;
@@ -106,5 +107,4 @@
 
 	/* Get platform name from sysinfo. */
-
 	platform = sysinfo_get_data("platform", &platform_size);
 	if (platform == NULL) {
@@ -123,18 +123,16 @@
 
 	/* Construct match ID. */
-
-	if (asprintf(&match_id, PLATFORM_DEVICE_MATCH_ID_FMT, platform) == -1) {
+	if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) {
 		printf(NAME ": Memory allocation failed.\n");
 		return ENOMEM;
 	}
 
-	/* Add child. */
+	/* Add function. */
+	printf(NAME ": adding platform function\n");
+	printf(NAME ":   function node is `%s' (%d %s)\n", PLATFORM_FUN_NAME,
+	    PLATFORM_FUN_MATCH_SCORE, match_id);
 
-	printf(NAME ": adding new child for platform device.\n");
-	printf(NAME ":   device node is `%s' (%d %s)\n", PLATFORM_DEVICE_NAME,
-	    PLATFORM_DEVICE_MATCH_SCORE, match_id);
-
-	res = register_function_wrapper(parent, PLATFORM_DEVICE_NAME,
-	    match_id, PLATFORM_DEVICE_MATCH_SCORE);
+	res = register_function_wrapper(dev, PLATFORM_FUN_NAME,
+	    match_id, PLATFORM_FUN_MATCH_SCORE);
 
 	return res;
@@ -156,8 +154,8 @@
 	 * vital for the system.
 	 */
-	add_virtual_root_child(dev);
+	add_virtual_root_fun(dev);
 
 	/* Register root device's children. */
-	int res = add_platform_child(dev);
+	int res = add_platform_fun(dev);
 	if (EOK != res)
 		printf(NAME ": failed to add child device for platform.\n");
Index: uspace/drv/rootpc/rootpc.c
===================================================================
--- uspace/drv/rootpc/rootpc.c	(revision 8b1e15ac9100f7b9da56e372d2f441ba44db6fcc)
+++ uspace/drv/rootpc/rootpc.c	(revision 68414f4a1f1b548a47a6b4525bd18dfbed67df1d)
@@ -55,7 +55,10 @@
 #define NAME "rootpc"
 
-typedef struct rootpc_fun_data {
+/** Obtain function soft-state from DDF function node */
+#define ROOTPC_FUN(fnode) ((rootpc_fun_t *) (fnode)->driver_data)
+
+typedef struct rootpc_fun {
 	hw_resource_list_t hw_resources;
-} rootpc_fun_data_t;
+} rootpc_fun_t;
 
 static int rootpc_add_device(device_t *dev);
@@ -82,5 +85,5 @@
 };
 
-static rootpc_fun_data_t pci_data = {
+static rootpc_fun_t pci_data = {
 	.hw_resources = {
 		1,
@@ -89,16 +92,13 @@
 };
 
-static hw_resource_list_t *rootpc_get_fun_resources(function_t *fun)
-{
-	rootpc_fun_data_t *data;
-	
-	data = (rootpc_fun_data_t *) fun->driver_data;
-	if (NULL == data)
-		return NULL;
-	
-	return &data->hw_resources;
-}
-
-static bool rootpc_enable_fun_interrupt(function_t *fun)
+static hw_resource_list_t *rootpc_get_resources(function_t *fnode)
+{
+	rootpc_fun_t *fun = ROOTPC_FUN(fnode);
+	
+	assert(fun != NULL);
+	return &fun->hw_resources;
+}
+
+static bool rootpc_enable_interrupt(function_t *fun)
 {
 	/* TODO */
@@ -108,6 +108,6 @@
 
 static hw_res_ops_t fun_hw_res_ops = {
-	&rootpc_get_fun_resources,
-	&rootpc_enable_fun_interrupt
+	&rootpc_get_resources,
+	&rootpc_enable_interrupt
 };
 
@@ -116,47 +116,47 @@
 
 static bool
-rootpc_add_fun(device_t *parent, const char *name, const char *str_match_id,
-    rootpc_fun_data_t *drv_data)
+rootpc_add_fun(device_t *dev, const char *name, const char *str_match_id,
+    rootpc_fun_t *fun)
 {
 	printf(NAME ": adding new function '%s'.\n", name);
 	
-	function_t *fun = NULL;
+	function_t *fnode = NULL;
 	match_id_t *match_id = NULL;
 	
 	/* Create new device. */
-	fun = create_function();
-	if (fun == NULL)
+	fnode = create_function();
+	if (fnode == NULL)
 		goto failure;
 	
-	fun->name = name;
-	fun->driver_data = drv_data;
-	fun->ftype = fun_inner;
+	fnode->name = name;
+	fnode->driver_data = fun;
+	fnode->ftype = fun_inner;
 	
 	/* Initialize match id list */
 	match_id = create_match_id();
-	if (NULL == match_id)
+	if (match_id == NULL)
 		goto failure;
 	
 	match_id->id = str_match_id;
 	match_id->score = 100;
-	add_match_id(&fun->match_ids, match_id);
+	add_match_id(&fnode->match_ids, match_id);
 	
 	/* Set provided operations to the device. */
-	fun->ops = &rootpc_fun_ops;
+	fnode->ops = &rootpc_fun_ops;
 	
 	/* Register function. */
-	if (EOK != register_function(fun, parent))
+	if (register_function(fnode, dev) != EOK)
 		goto failure;
-	printf(NAME ": registered function handle = %u\n", fun->handle);
+	printf(NAME ": registered function handle = %u\n", fnode->handle);
 	
 	return true;
 	
 failure:
-	if (NULL != match_id)
+	if (match_id != NULL)
 		match_id->id = NULL;
 	
-	if (NULL != fun) {
-		fun->name = NULL;
-		delete_function(fun);
+	if (fnode != NULL) {
+		fnode->name = NULL;
+		delete_function(fnode);
 	}
 	
Index: uspace/drv/rootvirt/rootvirt.c
===================================================================
--- uspace/drv/rootvirt/rootvirt.c	(revision 8b1e15ac9100f7b9da56e372d2f441ba44db6fcc)
+++ uspace/drv/rootvirt/rootvirt.c	(revision 68414f4a1f1b548a47a6b4525bd18dfbed67df1d)
@@ -61,8 +61,8 @@
 };
 
-static int add_device(device_t *dev);
+static int rootvirt_add_device(device_t *dev);
 
 static driver_ops_t rootvirt_ops = {
-	.add_device = &add_device
+	.add_device = &rootvirt_add_device
 };
 
@@ -78,5 +78,5 @@
  * @return		EOK on success or negative error code.
  */
-static int add_child(device_t *vdev, virtual_function_t *vfun)
+static int rootvirt_add_fun(device_t *vdev, virtual_function_t *vfun)
 {
 	printf(NAME ": registering function `%s' (match \"%s\")\n",
@@ -97,5 +97,5 @@
 }
 
-static int add_device(device_t *dev)
+static int rootvirt_add_device(device_t *dev)
 {
 	static int instances = 0;
@@ -117,5 +117,5 @@
 	virtual_function_t *vfun = virtual_functions;
 	while (vfun->name != NULL) {
-		(void) add_child(dev, vfun);
+		(void) rootvirt_add_fun(dev, vfun);
 		vfun++;
 	}
