Index: uspace/srv/hid/input/generic/input.c
===================================================================
--- uspace/srv/hid/input/generic/input.c	(revision 99ac5cf97460b67d1cf745618acf386fef0e193e)
+++ uspace/srv/hid/input/generic/input.c	(revision 333c2331d250e6a8fe1890db1774bc13b66cb23b)
@@ -38,5 +38,4 @@
 
 #include <adt/list.h>
-#include <bool.h>
 #include <ipc/services.h>
 #include <ipc/input.h>
@@ -54,5 +53,5 @@
 #include <io/console.h>
 #include <io/keycode.h>
-#include <loc.h>
+#include <devmap.h>
 #include <input.h>
 #include <kbd.h>
@@ -64,5 +63,8 @@
 
 // FIXME: remove this header
-#include <abi/ipc/methods.h>
+#include <kernel/ipc/ipc_methods.h>
+
+/* In microseconds */
+#define DISCOVERY_POLL_INTERVAL  (10 * 1000 * 1000)
 
 #define NUM_LAYOUTS  3
@@ -273,5 +275,5 @@
 	kdev->port_ops = port;
 	kdev->ctl_ops = ctl;
-	kdev->svc_id = 0;
+	kdev->dev_path = NULL;
 	
 	/* Initialize port driver. */
@@ -301,5 +303,5 @@
 	mdev->port_ops = port;
 	mdev->proto_ops = proto;
-	mdev->svc_id = 0;
+	mdev->dev_path = NULL;
 	
 	/* Initialize port driver. */
@@ -322,8 +324,8 @@
 /** Add new kbdev device.
  *
- * @param service_id	Service ID of the keyboard device
+ * @param dev_path Filesystem path to the device (/dev/class/...)
  *
  */
-static int kbd_add_kbdev(service_id_t service_id, kbd_dev_t **kdevp)
+static int kbd_add_kbdev(const char *dev_path)
 {
 	kbd_dev_t *kdev = kbd_dev_new();
@@ -331,13 +333,7 @@
 		return -1;
 	
-	kdev->svc_id = service_id;
+	kdev->dev_path = dev_path;
 	kdev->port_ops = NULL;
 	kdev->ctl_ops = &kbdev_ctl;
-	
-	int rc = loc_service_get_name(service_id, &kdev->svc_name);
-	if (rc != EOK) {
-		kdev->svc_name = NULL;
-		goto fail;
-	}
 	
 	/* Initialize controller driver. */
@@ -347,10 +343,7 @@
 	
 	list_append(&kdev->kbd_devs, &kbd_devs);
-	*kdevp = kdev;
 	return EOK;
 	
 fail:
-	if (kdev->svc_name != NULL)
-		free(kdev->svc_name);
 	free(kdev);
 	return -1;
@@ -359,8 +352,8 @@
 /** Add new mousedev device.
  *
- * @param service_id	Service ID of the mouse device
+ * @param dev_path Filesystem path to the device (/dev/class/...)
  *
  */
-static int mouse_add_mousedev(service_id_t service_id, mouse_dev_t **mdevp)
+static int mouse_add_mousedev(const char *dev_path)
 {
 	mouse_dev_t *mdev = mouse_dev_new();
@@ -368,13 +361,7 @@
 		return -1;
 	
-	mdev->svc_id = service_id;
+	mdev->dev_path = dev_path;
 	mdev->port_ops = NULL;
 	mdev->proto_ops = &mousedev_proto;
-	
-	int rc = loc_service_get_name(service_id, &mdev->svc_name);
-	if (rc != EOK) {
-		mdev->svc_name = NULL;
-		goto fail;
-	}
 	
 	/* Initialize controller driver. */
@@ -384,5 +371,4 @@
 	
 	list_append(&mdev->mouse_devs, &mouse_devs);
-	*mdevp = mdev;
 	return EOK;
 	
@@ -494,143 +480,70 @@
 }
 
-static int dev_check_new_kbdevs(void)
-{
-	category_id_t keyboard_cat;
-	service_id_t *svcs;
-	size_t count, i;
-	bool already_known;
+/** Periodically check for new input devices.
+ *
+ * Looks under /dev/class/keyboard and /dev/class/mouse.
+ *
+ * @param arg Ignored
+ *
+ */
+static int dev_discovery_fibril(void *arg)
+{
+	char *dev_path;
+	size_t kbd_id = 1;
+	size_t mouse_id = 1;
 	int rc;
 	
-	rc = loc_category_get_id("keyboard", &keyboard_cat, IPC_FLAG_BLOCKING);
-	if (rc != EOK) {
-		printf("%s: Failed resolving category 'keyboard'.\n", NAME);
-		return ENOENT;
-	}
-	
-	/*
-	 * Check for new keyboard devices
-	 */
-	rc = loc_category_get_svcs(keyboard_cat, &svcs, &count);
-	if (rc != EOK) {
-		printf("%s: Failed getting list of keyboard devices.\n",
+	while (true) {
+		async_usleep(DISCOVERY_POLL_INTERVAL);
+		
+		/*
+		 * Check for new keyboard device
+		 */
+		rc = asprintf(&dev_path, "/dev/class/keyboard\\%zu", kbd_id);
+		if (rc < 0)
+			continue;
+		
+		if (kbd_add_kbdev(dev_path) == EOK) {
+			printf("%s: Connected keyboard device '%s'\n",
+			    NAME, dev_path);
+			
+			/* XXX Handle device removal */
+			++kbd_id;
+		}
+		
+		free(dev_path);
+		
+		/*
+		 * Check for new mouse device
+		 */
+		rc = asprintf(&dev_path, "/dev/class/mouse\\%zu", mouse_id);
+		if (rc < 0)
+			continue;
+		
+		if (mouse_add_mousedev(dev_path) == EOK) {
+			printf("%s: Connected mouse device '%s'\n",
+			    NAME, dev_path);
+			
+			/* XXX Handle device removal */
+			++mouse_id;
+		}
+		
+		free(dev_path);
+	}
+	
+	return EOK;
+}
+
+/** Start a fibril for discovering new devices. */
+static void input_start_dev_discovery(void)
+{
+	fid_t fid = fibril_create(dev_discovery_fibril, NULL);
+	if (!fid) {
+		printf("%s: Failed to create device discovery fibril.\n",
 		    NAME);
-		return EIO;
-	}
-
-	for (i = 0; i < count; i++) {
-		already_known = false;
-		
-		/* Determine whether we already know this device. */
-		list_foreach(kbd_devs, kdev_link) {
-			kbd_dev_t *kdev = list_get_instance(kdev_link,
-			    kbd_dev_t, kbd_devs);
-			if (kdev->svc_id == svcs[i]) {
-				already_known = true;
-				break;
-			}
-		}
-		
-		if (!already_known) {
-			kbd_dev_t *kdev;
-			if (kbd_add_kbdev(svcs[i], &kdev) == EOK) {
-				printf("%s: Connected keyboard device '%s'\n",
-				    NAME, kdev->svc_name);
-			}
-		}
-	}
-	
-	free(svcs);
-	
-	/* XXX Handle device removal */
-	
-	return EOK;
-}
-
-static int dev_check_new_mousedevs(void)
-{
-	category_id_t mouse_cat;
-	service_id_t *svcs;
-	size_t count, i;
-	bool already_known;
-	int rc;
-	
-	rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING);
-	if (rc != EOK) {
-		printf("%s: Failed resolving category 'mouse'.\n", NAME);
-		return ENOENT;
-	}
-	
-	/*
-	 * Check for new mouse devices
-	 */
-	rc = loc_category_get_svcs(mouse_cat, &svcs, &count);
-	if (rc != EOK) {
-		printf("%s: Failed getting list of mouse devices.\n",
-		    NAME);
-		return EIO;
-	}
-	
-	for (i = 0; i < count; i++) {
-		already_known = false;
-		
-		/* Determine whether we already know this device. */
-		list_foreach(mouse_devs, mdev_link) {
-			mouse_dev_t *mdev = list_get_instance(mdev_link,
-			    mouse_dev_t, mouse_devs);
-			if (mdev->svc_id == svcs[i]) {
-				already_known = true;
-				break;
-			}
-		}
-		
-		if (!already_known) {
-			mouse_dev_t *mdev;
-			if (mouse_add_mousedev(svcs[i], &mdev) == EOK) {
-				printf("%s: Connected mouse device '%s'\n",
-				    NAME, mdev->svc_name);
-			}
-		}
-	}
-	
-	free(svcs);
-	
-	/* XXX Handle device removal */
-	
-	return EOK;
-}
-
-static int dev_check_new(void)
-{
-	int rc;
-	
-	rc = dev_check_new_kbdevs();
-	if (rc != EOK)
-		return rc;
-	
-	rc = dev_check_new_mousedevs();
-	if (rc != EOK)
-		return rc;
-
-	return EOK;
-}
-
-static void cat_change_cb(void)
-{
-	dev_check_new();
-}
-
-/** Start listening for new devices. */
-static int input_start_dev_discovery(void)
-{
-	int rc;
-
-	rc = loc_register_cat_change_cb(cat_change_cb);
-	if (rc != EOK) {
-		printf("%s: Failed registering callback for device discovery. "
-		    "(%d)\n", NAME, rc);
-		return rc;
-	}
-
-	return dev_check_new();
+		return;
+	}
+	
+	fibril_add_ready(fid);
 }
 
@@ -659,16 +572,16 @@
 	
 	/* Register driver */
-	int rc = loc_server_register(NAME, client_connection);
+	int rc = devmap_driver_register(NAME, client_connection);
 	if (rc < 0) {
-		printf("%s: Unable to register server (%d)\n", NAME, rc);
+		printf("%s: Unable to register driver (%d)\n", NAME, rc);
 		return -1;
 	}
 	
-	char kbd[LOC_NAME_MAXLEN + 1];
-	snprintf(kbd, LOC_NAME_MAXLEN, "%s/%s", NAMESPACE, NAME);
-	
-	service_id_t service_id;
-	if (loc_service_register(kbd, &service_id) != EOK) {
-		printf("%s: Unable to register service %s\n", NAME, kbd);
+	char kbd[DEVMAP_NAME_MAXLEN + 1];
+	snprintf(kbd, DEVMAP_NAME_MAXLEN, "%s/%s", NAMESPACE, NAME);
+	
+	devmap_handle_t devmap_handle;
+	if (devmap_device_register(kbd, &devmap_handle) != EOK) {
+		printf("%s: Unable to register device %s\n", NAME, kbd);
 		return -1;
 	}
