Index: kernel/generic/src/ipc/ipc.c
===================================================================
--- kernel/generic/src/ipc/ipc.c	(revision 06e1e95342d7b9a9c85c7492529a309d51a3fb6c)
+++ kernel/generic/src/ipc/ipc.c	(revision 5f9b4d9af46404a0fa7382a0a6d74b1fbf1e2334)
@@ -441,12 +441,8 @@
 
 
-/** Initilize ipc subsystem */
+/** Initilize IPC subsystem */
 void ipc_init(void)
 {
-	ipc_call_slab = slab_cache_create("ipc_call",
-					  sizeof(call_t),
-					  0,
-					  NULL, NULL, 0);
-	ipc_irq_make_table(IRQ_COUNT);
+	ipc_call_slab = slab_cache_create("ipc_call", sizeof(call_t), 0, NULL, NULL, 0);
 }
 
Index: kernel/generic/src/ipc/irq.c
===================================================================
--- kernel/generic/src/ipc/irq.c	(revision 06e1e95342d7b9a9c85c7492529a309d51a3fb6c)
+++ kernel/generic/src/ipc/irq.c	(revision 5f9b4d9af46404a0fa7382a0a6d74b1fbf1e2334)
@@ -1,4 +1,5 @@
 /*
  * Copyright (C) 2006 Ondrej Palkovsky
+ * Copyright (C) 2006 Jakub Jermar
  * All rights reserved.
  *
@@ -40,8 +41,8 @@
  *
  * The structure of a notification message is as follows:
- * - METHOD: interrupt number
+ * - METHOD: method as registered by the SYS_IPC_REGISTER_IRQ syscall
  * - ARG1: payload modified by a 'top-half' handler
- * - ARG2: payload
- * - ARG3: payload
+ * - ARG2: payload modified by a 'top-half' handler
+ * - ARG3: payload modified by a 'top-half' handler
  * - in_phone_hash: interrupt counter (may be needed to assure correct order
  *         in multithreaded drivers)
@@ -51,24 +52,16 @@
 #include <mm/slab.h>
 #include <errno.h>
+#include <ddi/irq.h>
 #include <ipc/ipc.h>
 #include <ipc/irq.h>
-#include <atomic.h>
 #include <syscall/copy.h>
 #include <console/console.h>
 #include <print.h>
 
-typedef struct {
-	SPINLOCK_DECLARE(lock);
-	answerbox_t *box;
-	irq_code_t *code;
-	atomic_t counter;
-} ipc_irq_t;
-
-
-static ipc_irq_t *irq_conns = NULL;
-static int irq_conns_size;
-
-
-/* Execute code associated with IRQ notification */
+/** Execute code associated with IRQ notification.
+ *
+ * @param call Notification call.
+ * @param code Top-half pseudocode.
+ */
 static void code_execute(call_t *call, irq_code_t *code)
 {
@@ -169,30 +162,46 @@
 }
 
-/** Unregister task from irq */
-void ipc_irq_unregister(answerbox_t *box, int irq)
+/** Unregister task from IRQ notification.
+ *
+ * @param box Answerbox associated with the notification.
+ * @param inr IRQ numbe.
+ * @param devno Device number.
+ */
+void ipc_irq_unregister(answerbox_t *box, inr_t inr, devno_t devno)
 {
 	ipl_t ipl;
-	int mq = irq + IPC_IRQ_RESERVED_VIRTUAL;
+	irq_t *irq;
 
 	ipl = interrupts_disable();
-	spinlock_lock(&irq_conns[mq].lock);
-	if (irq_conns[mq].box == box) {
-		irq_conns[mq].box = NULL;
-		code_free(irq_conns[mq].code);
-		irq_conns[mq].code = NULL;
-	}
-
-	spinlock_unlock(&irq_conns[mq].lock);
+	irq = irq_find_and_lock(inr, devno);
+	if (irq) {
+		if (irq->notif_cfg.answerbox == box) {
+			code_free(irq->notif_cfg.code);
+			irq->notif_cfg.code = NULL;
+			irq->notif_cfg.answerbox = NULL;
+			irq->notif_cfg.method = 0;
+			irq->notif_cfg.counter = 0;
+			spinlock_unlock(&irq->lock);
+		}
+	}
 	interrupts_restore(ipl);
 }
 
-/** Register an answerbox as a receiving end of interrupts notifications */
-int ipc_irq_register(answerbox_t *box, int irq, irq_code_t *ucode)
+/** Register an answerbox as a receiving end for IRQ notifications.
+ *
+ * @param box Receiving answerbox.
+ * @param inr IRQ number.
+ * @param devno Device number.
+ * @param method Method to be associated with the notification.
+ * @param ucode Uspace pointer to top-half pseudocode.
+ *
+ * @return EBADMEM, ENOENT or EEXISTS on failure or 0 on success.
+ */
+int
+ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, unative_t method, irq_code_t *ucode)
 {
 	ipl_t ipl;
 	irq_code_t *code;
-	int mq = irq + IPC_IRQ_RESERVED_VIRTUAL;
-
-	ASSERT(irq_conns);
+	irq_t *irq;
 
 	if (ucode) {
@@ -204,16 +213,23 @@
 
 	ipl = interrupts_disable();
-	spinlock_lock(&irq_conns[mq].lock);
-
-	if (irq_conns[mq].box) {
-		spinlock_unlock(&irq_conns[mq].lock);
+	irq = irq_find_and_lock(inr, devno);
+	if (!irq) {
+		interrupts_restore(ipl);
+		code_free(code);
+		return ENOENT;
+	}
+	
+	if (irq->notif_cfg.answerbox) {
+		spinlock_unlock(&irq->lock);
 		interrupts_restore(ipl);
 		code_free(code);
 		return EEXISTS;
 	}
-	irq_conns[mq].box = box;
-	irq_conns[mq].code = code;
-	atomic_set(&irq_conns[mq].counter, 0);
-	spinlock_unlock(&irq_conns[mq].lock);
+	
+	irq->notif_cfg.answerbox = box;
+	irq->notif_cfg.method = method;
+	irq->notif_cfg.code = code;
+	irq->notif_cfg.counter = 0;
+	spinlock_unlock(&irq->lock);
 	interrupts_restore(ipl);
 
@@ -221,14 +237,16 @@
 }
 
-/** Add call to proper answerbox queue
- *
- * Assume irq_conns[mq].lock is locked */
-static void send_call(int mq, call_t *call)
-{
-	spinlock_lock(&irq_conns[mq].box->irq_lock);
-	list_append(&call->link, &irq_conns[mq].box->irq_notifs);
-	spinlock_unlock(&irq_conns[mq].box->irq_lock);
+/** Add call to proper answerbox queue.
+ *
+ * Assume irq->lock is locked.
+ *
+ */
+static void send_call(irq_t *irq, call_t *call)
+{
+	spinlock_lock(&irq->notif_cfg.answerbox->irq_lock);
+	list_append(&call->link, &irq->notif_cfg.answerbox->irq_notifs);
+	spinlock_unlock(&irq->notif_cfg.answerbox->irq_lock);
 		
-	waitq_wakeup(&irq_conns[mq].box->wq, 0);
+	waitq_wakeup(&irq->notif_cfg.answerbox->wq, WAKEUP_FIRST);
 }
 
@@ -236,101 +254,64 @@
  *
  */
-void ipc_irq_send_msg(int irq, unative_t a1, unative_t a2, unative_t a3)
+void ipc_irq_send_msg(irq_t *irq, unative_t a1, unative_t a2, unative_t a3)
 {
 	call_t *call;
-	int mq = irq + IPC_IRQ_RESERVED_VIRTUAL;
-
-	spinlock_lock(&irq_conns[mq].lock);
-
-	if (irq_conns[mq].box) {
+
+	spinlock_lock(&irq->lock);
+
+	if (irq->notif_cfg.answerbox) {
 		call = ipc_call_alloc(FRAME_ATOMIC);
 		if (!call) {
-			spinlock_unlock(&irq_conns[mq].lock);
+			spinlock_unlock(&irq->lock);
 			return;
 		}
 		call->flags |= IPC_CALL_NOTIF;
-		IPC_SET_METHOD(call->data, irq);
+		IPC_SET_METHOD(call->data, irq->notif_cfg.method);
 		IPC_SET_ARG1(call->data, a1);
 		IPC_SET_ARG2(call->data, a2);
 		IPC_SET_ARG3(call->data, a3);
 		/* Put a counter to the message */
-		call->private = atomic_preinc(&irq_conns[mq].counter);
+		call->private = ++irq->notif_cfg.counter;
 		
-		send_call(mq, call);
-	}
-	spinlock_unlock(&irq_conns[mq].lock);
+		send_call(irq, call);
+	}
+	spinlock_unlock(&irq->lock);
 }
 
 /** Notify task that an irq had occurred.
  *
- * We expect interrupts to be disabled
- */
-void ipc_irq_send_notif(int irq)
+ * We expect interrupts to be disabled and the irq->lock already held.
+ */
+void ipc_irq_send_notif(irq_t *irq)
 {
 	call_t *call;
-	int mq = irq + IPC_IRQ_RESERVED_VIRTUAL;
-
-	ASSERT(irq_conns);
-	spinlock_lock(&irq_conns[mq].lock);
-
-	if (irq_conns[mq].box) {
+
+	ASSERT(irq);
+
+	if (irq->notif_cfg.answerbox) {
 		call = ipc_call_alloc(FRAME_ATOMIC);
 		if (!call) {
-			spinlock_unlock(&irq_conns[mq].lock);
 			return;
 		}
 		call->flags |= IPC_CALL_NOTIF;
 		/* Put a counter to the message */
-		call->private = atomic_preinc(&irq_conns[mq].counter);
+		call->private = ++irq->notif_cfg.counter;
 		/* Set up args */
-		IPC_SET_METHOD(call->data, irq);
+		IPC_SET_METHOD(call->data, irq->notif_cfg.method);
 
 		/* Execute code to handle irq */
-		code_execute(call, irq_conns[mq].code);
+		code_execute(call, irq->notif_cfg.code);
 		
-		send_call(mq, call);
-	}
-		
-	spinlock_unlock(&irq_conns[mq].lock);
-}
-
-
-/** Initialize table of interrupt handlers
- *
- * @param irqcount Count of required hardware IRQs to be supported
- */
-void ipc_irq_make_table(int irqcount)
-{
-	int i;
-
-	irqcount +=  IPC_IRQ_RESERVED_VIRTUAL;
-
-	irq_conns_size = irqcount;
-	irq_conns = malloc(irqcount * (sizeof(*irq_conns)), 0);
-	for (i=0; i < irqcount; i++) {
-		spinlock_initialize(&irq_conns[i].lock, "irq_ipc_lock");
-		irq_conns[i].box = NULL;
-		irq_conns[i].code = NULL;
-	}
-}
-
-/** Disconnect all irq's notifications
- *
- * @todo It may be better to do some linked list, so that
- *       we wouldn't need to go through whole array every cleanup
+		send_call(irq, call);
+	}
+}
+
+/** Disconnect all IRQ notifications from an answerbox.
+ *
+ * @param box Answerbox for which we want to carry out the cleanup.
  */
 void ipc_irq_cleanup(answerbox_t *box)
 {
-	int i;
-	ipl_t ipl;
-	
-	for (i=0; i < irq_conns_size; i++) {
-		ipl = interrupts_disable();
-		spinlock_lock(&irq_conns[i].lock);
-		if (irq_conns[i].box == box)
-			irq_conns[i].box = NULL;
-		spinlock_unlock(&irq_conns[i].lock);
-		interrupts_restore(ipl);
-	}
+	/* TODO */
 }
 
Index: kernel/generic/src/ipc/sysipc.c
===================================================================
--- kernel/generic/src/ipc/sysipc.c	(revision 06e1e95342d7b9a9c85c7492529a309d51a3fb6c)
+++ kernel/generic/src/ipc/sysipc.c	(revision 5f9b4d9af46404a0fa7382a0a6d74b1fbf1e2334)
@@ -566,28 +566,32 @@
 }
 
-/** Connect irq handler to task */
-unative_t sys_ipc_register_irq(int irq, irq_code_t *ucode)
+/** Connect irq handler to task.
+ *
+ * @param inr IRQ number.
+ * @param devno Device number.
+ * @param method Method to be associated with the notification.
+ * @param ucode Uspace pointer to the top-half pseudocode.
+ *
+ * @return EPERM or a return code returned by ipc_irq_register().
+ */
+unative_t sys_ipc_register_irq(inr_t inr, devno_t devno, unative_t method, irq_code_t *ucode)
 {
 	if (!(cap_get(TASK) & CAP_IRQ_REG))
 		return EPERM;
 
-	if (irq >= IRQ_COUNT || irq <= -IPC_IRQ_RESERVED_VIRTUAL)
-		return (unative_t) ELIMIT;
-	
-	irq_ipc_bind_arch(irq);
-
-	return ipc_irq_register(&TASK->answerbox, irq, ucode);
-}
-
-/* Disconnect irq handler from task */
-unative_t sys_ipc_unregister_irq(int irq)
+	return ipc_irq_register(&TASK->answerbox, inr, devno, method, ucode);
+}
+
+/** Disconnect irq handler from task.
+ *
+ * @param inr IRQ number.
+ * @param devno Device number.
+ */
+unative_t sys_ipc_unregister_irq(inr_t inr, devno_t devno)
 {
 	if (!(cap_get(TASK) & CAP_IRQ_REG))
 		return EPERM;
 
-	if (irq >= IRQ_COUNT || irq <= -IPC_IRQ_RESERVED_VIRTUAL)
-		return (unative_t) ELIMIT;
-
-	ipc_irq_unregister(&TASK->answerbox, irq);
+	ipc_irq_unregister(&TASK->answerbox, inr, devno);
 
 	return 0;
