Index: uspace/srv/devman/devman.c
===================================================================
--- uspace/srv/devman/devman.c	(revision 5159ae9cfe175971e2b16fd2a8cf120ffefe7cf2)
+++ uspace/srv/devman/devman.c	(revision ce89036b64f8d563964217c344f139b41be8d6cf)
@@ -831,5 +831,5 @@
 {
 	dev_class_t *cl;
-	fibril_mutex_lock(&class_list->classes_mutex);	
+	fibril_rwlock_write_lock(&class_list->rwlock);	
 	cl = find_dev_class_no_lock(class_list, class_name);
 	if (NULL == cl) {
@@ -841,5 +841,5 @@
 		}		
 	}	
-	fibril_mutex_unlock(&class_list->classes_mutex);
+	fibril_rwlock_write_unlock(&class_list->rwlock);
 	return cl;
 }
@@ -859,4 +859,49 @@
 }
 
+void init_class_list(class_list_t *class_list)
+{
+	list_initialize(&class_list->classes);
+	fibril_rwlock_initialize(&class_list->rwlock);
+	hash_table_create(&class_list->devmap_devices, DEVICE_BUCKETS, 1, &devmap_devices_ops);	
+}
+
+
+// devmap devices
+
+node_t *find_devmap_tree_device(dev_tree_t *tree, dev_handle_t devmap_handle)
+{
+	node_t *dev = NULL;
+	link_t *link;
+	unsigned long key = (unsigned long)devmap_handle;
+	
+	fibril_rwlock_read_lock(&tree->rwlock);
+	link = hash_table_find(&tree->devmap_devices, &key);	
+	if (NULL != link) {
+		dev = hash_table_get_instance(link, node_t, devmap_link);
+	}
+	fibril_rwlock_read_unlock(&tree->rwlock);
+	
+	return dev;
+}
+
+node_t *find_devmap_class_device(class_list_t *classes, dev_handle_t devmap_handle)
+{
+	node_t *dev = NULL;
+	dev_class_info_t *cli;
+	link_t *link;
+	unsigned long key = (unsigned long)devmap_handle;
+	
+	fibril_rwlock_read_lock(&classes->rwlock);
+	link = hash_table_find(&classes->devmap_devices, &key);	
+	if (NULL != link) {
+		cli = hash_table_get_instance(link, dev_class_info_t, devmap_link);
+		dev = cli->dev;
+	}
+	fibril_rwlock_read_unlock(&classes->rwlock);
+	
+	return dev;	
+}
+
+
 /** @}
  */
Index: uspace/srv/devman/devman.h
===================================================================
--- uspace/srv/devman/devman.h	(revision 5159ae9cfe175971e2b16fd2a8cf120ffefe7cf2)
+++ uspace/srv/devman/devman.h	(revision ce89036b64f8d563964217c344f139b41be8d6cf)
@@ -52,4 +52,8 @@
 #define MATCH_EXT ".ma"
 #define DEVICE_BUCKETS 256
+
+#define DEVMAP_CLASS_NAMESPACE "class"
+#define DEVMAP_DEVICE_NAMESPACE "devices"
+#define DEVMAP_SEPARATOR "\\"
 
 struct node;
@@ -149,5 +153,4 @@
 	/** Hash table of devices registered by devmapper, indexed by devmap handles.*/
 	hash_table_t devmap_devices;
-	
 } dev_tree_t;
 
@@ -183,4 +186,6 @@
 	/** The handle of the device by device mapper in the class namespace.*/
 	dev_handle_t devmap_handle;
+	/** Link in the hash table of devices registered by the devmapper using their class names.*/
+	link_t devmap_link;
 } dev_class_info_t;
 
@@ -189,6 +194,8 @@
 	/** List of classes */
 	link_t classes;
+	/** Hash table of devices registered by devmapper using their class name, indexed by devmap handles.*/
+	hash_table_t devmap_devices;
 	/** Fibril mutex for list of classes. */
-	fibril_mutex_t classes_mutex;	
+	fibril_rwlock_t rwlock;	
 } class_list_t;
 
@@ -404,9 +411,5 @@
 dev_class_info_t * add_device_to_class(node_t *dev, dev_class_t *cl, const char *base_dev_name);
 
-static inline void init_class_list(class_list_t *class_list)
-{
-	list_initialize(&class_list->classes);
-	fibril_mutex_initialize(&class_list->classes_mutex);
-}
+void init_class_list(class_list_t *class_list);
 
 dev_class_t * get_dev_class(class_list_t *class_list, char *class_name);
@@ -418,4 +421,10 @@
 }
 
+
+// devmap devices
+
+node_t *find_devmap_tree_device(dev_tree_t *tree, dev_handle_t devmap_handle);
+node_t *find_devmap_class_device(class_list_t *classes, dev_handle_t devmap_handle);
+
 #endif
 
Index: uspace/srv/devman/main.c
===================================================================
--- uspace/srv/devman/main.c	(revision 5159ae9cfe175971e2b16fd2a8cf120ffefe7cf2)
+++ uspace/srv/devman/main.c	(revision ce89036b64f8d563964217c344f139b41be8d6cf)
@@ -53,4 +53,5 @@
 #include <ipc/driver.h>
 #include <thread.h>
+#include <devmap.h>
 
 #include "devman.h"
@@ -61,5 +62,4 @@
 static dev_tree_t device_tree;
 static class_list_t class_list;
-
 
 /**
@@ -239,10 +239,25 @@
 	ipc_answer_1(callid, EOK, node->handle);
 	
-	// try to find suitable driver and assign it to the device	
+	// try to find suitable driver and assign it to the device
 	assign_driver(node, &drivers_list);	
 }
 
+static void devmap_register_class_dev(dev_class_info_t *cli)
+{
+	// create devmap path and name for the device
+	char *devmap_pathname = NULL;
+	asprintf(&devmap_pathname, "%s/%s%s%s", DEVMAP_CLASS_NAMESPACE, cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name);
+	if (NULL == devmap_pathname) {
+		return;
+	}
+	
+	// register the device by the device mapper and remember its devmap handle
+	devmap_device_register(devmap_pathname, &cli->devmap_handle);	
+	
+	free(devmap_pathname);	
+}
+
 static void devman_add_device_to_class(ipc_callid_t callid, ipc_call_t *call)
-{		
+{
 	device_handle_t handle = IPC_GET_ARG1(*call);
 	
@@ -262,8 +277,9 @@
 	
 	dev_class_t *cl = get_dev_class(&class_list, class_name);
-	
+		
 	dev_class_info_t *class_info = add_device_to_class(dev, cl, NULL);
 	
-	// TODO register the device's class alias by devmapper
+	// register the device's class alias by devmapper
+	devmap_register_class_dev(class_info);
 	
 	printf(NAME ": device '%s' added to class '%s', class name '%s' was asigned to it\n", dev->pathname, class_name, class_info->dev_name);
@@ -424,8 +440,35 @@
 		printf(NAME ": devman_forward: cound not forward to driver %s ", driver->name);
 		printf("the driver's phone is %x).\n", driver->phone);
-		return;
-	}
-	printf(NAME ": devman_forward: forward connection to device %s to driver %s.\n", dev->pathname, driver->name);
+		ipc_answer_0(iid, EINVAL);
+		return;
+	}
+	printf(NAME ": devman_forward: forward connection to device %s to driver %s.\n", 
+		dev->pathname, driver->name);
 	ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);	
+}
+
+/** Function for handling connections from a client forwarded by the device mapper to the device manager.
+ */
+static void devman_connection_devmapper(ipc_callid_t iid, ipc_call_t *icall)
+{
+	dev_handle_t devmap_handle = IPC_GET_METHOD(*icall);
+	node_t *dev = find_devmap_tree_device(&device_tree, devmap_handle);
+	if (NULL == dev) {
+		dev = find_devmap_class_device(&class_list, devmap_handle);
+	}
+	
+	if (NULL == dev || NULL == dev->drv) {
+		ipc_answer_0(iid, ENOENT);
+		return;
+	}
+	
+	if (DEVICE_USABLE != dev->state || dev->drv->phone <= 0) {
+		ipc_answer_0(iid, EINVAL);
+		return;
+	}
+	
+	printf(NAME ": devman_connection_devmapper: forward connection to device %s to driver %s.\n", 
+		dev->pathname, dev->drv->name);
+	ipc_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, dev->handle, 0, IPC_FF_NONE);	
 }
 
@@ -434,5 +477,18 @@
  */
 static void devman_connection(ipc_callid_t iid, ipc_call_t *icall)
-{
+{	
+	// Silly hack to enable the device manager to register as a driver by the device mapper. 
+	// If the ipc method is not IPC_M_CONNECT_ME_TO, this is not the forwarded connection from naming service,
+	// so it must be a connection from the devmapper which thinks this is a devmapper-style driver. 
+	// So pretend this is a devmapper-style driver. 
+	// (This does not work for device with handle == IPC_M_CONNECT_ME_TO, 
+	// because devmapper passes device handle to the driver as an ipc method.)
+	if (IPC_M_CONNECT_ME_TO != IPC_GET_METHOD(*icall)) {
+		devman_connection_devmapper(iid, icall);
+	}
+
+	// ipc method is IPC_M_CONNECT_ME_TO, so this is forwarded connection from naming service
+	// by which we registered as device manager, so be device manager
+	
 	// Select interface 
 	switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) {
@@ -479,4 +535,9 @@
 	init_class_list(&class_list);
 	
+	// !!! devman_connection ... as the device manager is not a real devmap driver 
+	// (it uses a completely different ipc protocol than an ordinary devmap driver)
+	// forwarding a connection from client to the devman by devmapper would not work
+	devmap_driver_register(NAME, devman_connection);	
+	
 	return true;
 }
