Index: uspace/drv/bus/pci/pciintel/pci.c
===================================================================
--- uspace/drv/bus/pci/pciintel/pci.c	(revision 690d2e7fd4c0881f308821afad3098e8d891212a)
+++ uspace/drv/bus/pci/pciintel/pci.c	(revision beb93360b4fa19e27b1668938b25de12f07de3f6)
@@ -50,6 +50,4 @@
 #include <ddf/driver.h>
 #include <ddf/log.h>
-#include <devman.h>
-#include <ipc/devman.h>
 #include <ipc/dev_iface.h>
 #include <ipc/irc.h>
@@ -71,11 +69,22 @@
 
 /** Obtain PCI function soft-state from DDF function node */
-#define PCI_FUN(fnode) ((pci_fun_t *) (fnode)->driver_data)
+static pci_fun_t *pci_fun(ddf_fun_t *fnode)
+{
+	return ddf_fun_data_get(fnode);
+}
 
 /** Obtain PCI bus soft-state from DDF device node */
-#define PCI_BUS(dnode) ((pci_bus_t *) (dnode)->driver_data)
+#if 0
+static pci_bus_t *pci_bus(ddf_dev_t *dnode)
+{
+	return ddf_dev_data_get(dnode);
+}
+#endif
 
 /** Obtain PCI bus soft-state from function soft-state */
-#define PCI_BUS_FROM_FUN(fun) ((fun)->busptr)
+static pci_bus_t *pci_bus_from_fun(pci_fun_t *fun)
+{
+	return fun->busptr;
+}
 
 /** Max is 47, align to something nice. */
@@ -84,5 +93,5 @@
 static hw_resource_list_t *pciintel_get_resources(ddf_fun_t *fnode)
 {
-	pci_fun_t *fun = PCI_FUN(fnode);
+	pci_fun_t *fun = pci_fun(fnode);
 	
 	if (fun == NULL)
@@ -95,5 +104,5 @@
 	/* This is an old ugly way */
 	assert(fnode);
-	pci_fun_t *dev_data = (pci_fun_t *) fnode->driver_data;
+	pci_fun_t *dev_data = pci_fun(fnode);
 	
 	sysarg_t apic;
@@ -138,5 +147,5 @@
 	if (address > 252)
 		return EINVAL;
-	pci_conf_write_32(PCI_FUN(fun), address, data);
+	pci_conf_write_32(pci_fun(fun), address, data);
 	return EOK;
 }
@@ -147,5 +156,5 @@
 	if (address > 254)
 		return EINVAL;
-	pci_conf_write_16(PCI_FUN(fun), address, data);
+	pci_conf_write_16(pci_fun(fun), address, data);
 	return EOK;
 }
@@ -156,5 +165,5 @@
 	if (address > 255)
 		return EINVAL;
-	pci_conf_write_8(PCI_FUN(fun), address, data);
+	pci_conf_write_8(pci_fun(fun), address, data);
 	return EOK;
 }
@@ -165,5 +174,5 @@
 	if (address > 252)
 		return EINVAL;
-	*data = pci_conf_read_32(PCI_FUN(fun), address);
+	*data = pci_conf_read_32(pci_fun(fun), address);
 	return EOK;
 }
@@ -174,5 +183,5 @@
 	if (address > 254)
 		return EINVAL;
-	*data = pci_conf_read_16(PCI_FUN(fun), address);
+	*data = pci_conf_read_16(pci_fun(fun), address);
 	return EOK;
 }
@@ -183,5 +192,5 @@
 	if (address > 255)
 		return EINVAL;
-	*data = pci_conf_read_8(PCI_FUN(fun), address);
+	*data = pci_conf_read_8(pci_fun(fun), address);
 	return EOK;
 }
@@ -225,5 +234,5 @@
 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);
+	pci_bus_t *bus = pci_bus_from_fun(fun);
 	
 	fibril_mutex_lock(&bus->conf_mutex);
@@ -252,5 +261,5 @@
 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);
+	pci_bus_t *bus = pci_bus_from_fun(fun);
 	
 	fibril_mutex_lock(&bus->conf_mutex);
@@ -480,5 +489,5 @@
 	if (range_addr != 0) {
 		ddf_msg(LVL_DEBUG, "Function %s : address = %" PRIx64
-		    ", size = %x", fun->fnode->name, range_addr,
+		    ", size = %x", ddf_fun_get_name(fun->fnode), range_addr,
 		    (unsigned int) range_size);
 	}
@@ -506,5 +515,5 @@
 	hw_res_list->count++;
 	
-	ddf_msg(LVL_NOTE, "Function %s uses irq %x.", fun->fnode->name, irq);
+	ddf_msg(LVL_NOTE, "Function %s uses irq %x.", ddf_fun_get_name(fun->fnode), irq);
 }
 
@@ -523,6 +532,6 @@
 void pci_bus_scan(pci_bus_t *bus, int bus_num) 
 {
-	ddf_fun_t *fnode;
 	pci_fun_t *fun;
+	int rc;
 	
 	int child_bus = 0;
@@ -531,11 +540,12 @@
 	uint8_t header_type;
 	
-	fun = pci_fun_new(bus);
-	
 	for (dnum = 0; dnum < 32; dnum++) {
 		multi = true;
 		for (fnum = 0; multi && fnum < 8; fnum++) {
+			fun = pci_fun_new(bus);
+			
 			pci_fun_init(fun, bus_num, dnum, fnum);
 			if (fun->vendor_id == 0xffff) {
+				pci_fun_delete(fun);
 				/*
 				 * The device is not present, go on scanning the
@@ -559,15 +569,15 @@
 			if (fun_name == NULL) {
 				ddf_msg(LVL_ERROR, "Out of memory.");
+				pci_fun_delete(fun);
 				return;
 			}
 			
-			fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name);
+			rc = ddf_fun_set_name(fun->fnode, fun_name);
 			free(fun_name);
-			if (fnode == NULL) {
-				ddf_msg(LVL_ERROR, "Failed creating function.");
+			if (rc != EOK) {
+				ddf_msg(LVL_ERROR, "Failed setting function name.");
+				pci_fun_delete(fun);
 				return;
 			}
-			
-			fun->fnode = fnode;
 			
 			pci_alloc_resource_list(fun);
@@ -575,17 +585,14 @@
 			pci_read_interrupt(fun);
 			
-			fnode->ops = &pci_fun_ops;
-			fnode->driver_data = fun;
+			ddf_fun_set_ops(fun->fnode, &pci_fun_ops);
 			
 			ddf_msg(LVL_DEBUG, "Adding new function %s.",
-			    fnode->name);
+			    ddf_fun_get_name(fun->fnode));
 			
 			pci_fun_create_match_ids(fun);
 			
-			if (ddf_fun_bind(fnode) != EOK) {
+			if (ddf_fun_bind(fun->fnode) != EOK) {
 				pci_clean_resource_list(fun);
-				clean_match_ids(&fnode->match_ids);
-				free((char *) fnode->name);
-				fnode->name = NULL;
+				pci_fun_delete(fun);
 				continue;
 			}
@@ -601,12 +608,5 @@
 					pci_bus_scan(bus, child_bus);
 			}
-			
-			fun = pci_fun_new(bus);
 		}
-	}
-	
-	if (fun->vendor_id == 0xffff) {
-		/* Free the auxiliary function structure. */
-		pci_fun_delete(fun);
 	}
 }
@@ -617,8 +617,8 @@
 	ddf_fun_t *ctl = NULL;
 	bool got_res = false;
+	async_sess_t *sess;
 	int rc;
 	
 	ddf_msg(LVL_DEBUG, "pci_dev_add");
-	dnode->parent_sess = NULL;
 	
 	bus = ddf_dev_data_alloc(dnode, sizeof(pci_bus_t));
@@ -631,9 +631,7 @@
 
 	bus->dnode = dnode;
-	dnode->driver_data = bus;
-	
-	dnode->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE,
-	    dnode->handle, IPC_FLAG_BLOCKING);
-	if (!dnode->parent_sess) {
+	
+	sess = ddf_dev_parent_sess_create(dnode, EXCHANGE_SERIALIZE);
+	if (sess == NULL) {
 		ddf_msg(LVL_ERROR, "pci_dev_add failed to connect to the "
 		    "parent driver.");
@@ -644,5 +642,5 @@
 	hw_resource_list_t hw_resources;
 	
-	rc = hw_res_get_resource_list(dnode->parent_sess, &hw_resources);
+	rc = hw_res_get_resource_list(sess, &hw_resources);
 	if (rc != EOK) {
 		ddf_msg(LVL_ERROR, "pci_dev_add failed to get hw resources "
@@ -708,7 +706,4 @@
 	
 fail:
-	if (dnode->parent_sess)
-		async_hangup(dnode->parent_sess);
-	
 	if (got_res)
 		hw_res_clean_resource_list(&hw_resources);
@@ -742,10 +737,16 @@
 {
 	pci_fun_t *fun;
-	
-	fun = (pci_fun_t *) calloc(1, sizeof(pci_fun_t));
+	ddf_fun_t *fnode;
+	
+	fnode = ddf_fun_create(bus->dnode, fun_inner, NULL);
+	if (fnode == NULL)
+		return NULL;
+
+	fun = ddf_fun_data_alloc(fnode, sizeof(pci_fun_t));
 	if (fun == NULL)
 		return NULL;
 
 	fun->busptr = bus;
+	fun->fnode = fnode;
 	return fun;
 }
@@ -766,7 +767,7 @@
 void pci_fun_delete(pci_fun_t *fun)
 {
-	assert(fun != NULL);
 	hw_res_clean_resource_list(&fun->hw_resources);
-	free(fun);
+	if (fun->fnode != NULL)
+		ddf_fun_destroy(fun->fnode);
 }
 
