]> err.no Git - linux-2.6/blobdiff - arch/sparc64/kernel/irq.c
[ARM] 4652/1: pxa: fix a typo of pxa27x usb host clk definition
[linux-2.6] / arch / sparc64 / kernel / irq.c
index 5a92851296c03fd4ef0414e7c19462a2b60b9346..30431bd24e1efbe7ea2153043d2d06605433febe 100644 (file)
@@ -42,6 +42,7 @@
 #include <asm/auxio.h>
 #include <asm/head.h>
 #include <asm/hypervisor.h>
+#include <asm/cacheflush.h>
 
 /* UPA nodes send interrupt packet to UltraSparc with first data reg
  * value low 5 (7 on Starfire) bits holding the IRQ identifier being
  * of the vectored interrupt trap handler(s) in entry.S and sun4v_ivec.S
  */
 struct ino_bucket {
-/*0x00*/unsigned long irq_chain_pa;
+/*0x00*/unsigned long __irq_chain_pa;
 
        /* Virtual interrupt number assigned to this INO.  */
-/*0x08*/unsigned int virt_irq;
+/*0x08*/unsigned int __virt_irq;
 /*0x0c*/unsigned int __pad;
 };
 
@@ -67,21 +68,71 @@ struct ino_bucket {
 struct ino_bucket *ivector_table;
 unsigned long ivector_table_pa;
 
-#define __irq_ino(irq) \
-        (((struct ino_bucket *)(irq)) - &ivector_table[0])
-#define __bucket(irq) ((struct ino_bucket *)(irq))
-#define __irq(bucket) ((unsigned long)(bucket))
+/* On several sun4u processors, it is illegal to mix bypass and
+ * non-bypass accesses.  Therefore we access all INO buckets
+ * using bypass accesses only.
+ */
+static unsigned long bucket_get_chain_pa(unsigned long bucket_pa)
+{
+       unsigned long ret;
+
+       __asm__ __volatile__("ldxa      [%1] %2, %0"
+                            : "=&r" (ret)
+                            : "r" (bucket_pa +
+                                   offsetof(struct ino_bucket,
+                                            __irq_chain_pa)),
+                              "i" (ASI_PHYS_USE_EC));
+
+       return ret;
+}
+
+static void bucket_clear_chain_pa(unsigned long bucket_pa)
+{
+       __asm__ __volatile__("stxa      %%g0, [%0] %1"
+                            : /* no outputs */
+                            : "r" (bucket_pa +
+                                   offsetof(struct ino_bucket,
+                                            __irq_chain_pa)),
+                              "i" (ASI_PHYS_USE_EC));
+}
+
+static unsigned int bucket_get_virt_irq(unsigned long bucket_pa)
+{
+       unsigned int ret;
+
+       __asm__ __volatile__("lduwa     [%1] %2, %0"
+                            : "=&r" (ret)
+                            : "r" (bucket_pa +
+                                   offsetof(struct ino_bucket,
+                                            __virt_irq)),
+                              "i" (ASI_PHYS_USE_EC));
+
+       return ret;
+}
+
+static void bucket_set_virt_irq(unsigned long bucket_pa,
+                               unsigned int virt_irq)
+{
+       __asm__ __volatile__("stwa      %0, [%1] %2"
+                            : /* no outputs */
+                            : "r" (virt_irq),
+                              "r" (bucket_pa +
+                                   offsetof(struct ino_bucket,
+                                            __virt_irq)),
+                              "i" (ASI_PHYS_USE_EC));
+}
 
 #define irq_work_pa(__cpu)     &(trap_block[(__cpu)].irq_worklist_pa)
 
 static struct {
-       unsigned long irq;
        unsigned int dev_handle;
        unsigned int dev_ino;
-} virt_to_real_irq_table[NR_IRQS];
+       unsigned int in_use;
+} virt_irq_table[NR_IRQS];
 static DEFINE_SPINLOCK(virt_irq_alloc_lock);
 
-unsigned char virt_irq_alloc(unsigned long real_irq)
+unsigned char virt_irq_alloc(unsigned int dev_handle,
+                            unsigned int dev_ino)
 {
        unsigned long flags;
        unsigned char ent;
@@ -91,14 +142,16 @@ unsigned char virt_irq_alloc(unsigned long real_irq)
        spin_lock_irqsave(&virt_irq_alloc_lock, flags);
 
        for (ent = 1; ent < NR_IRQS; ent++) {
-               if (!virt_to_real_irq_table[ent].irq)
+               if (!virt_irq_table[ent].in_use)
                        break;
        }
        if (ent >= NR_IRQS) {
                printk(KERN_ERR "IRQ: Out of virtual IRQs.\n");
                ent = 0;
        } else {
-               virt_to_real_irq_table[ent].irq = real_irq;
+               virt_irq_table[ent].dev_handle = dev_handle;
+               virt_irq_table[ent].dev_ino = dev_ino;
+               virt_irq_table[ent].in_use = 1;
        }
 
        spin_unlock_irqrestore(&virt_irq_alloc_lock, flags);
@@ -116,17 +169,12 @@ void virt_irq_free(unsigned int virt_irq)
 
        spin_lock_irqsave(&virt_irq_alloc_lock, flags);
 
-       virt_to_real_irq_table[virt_irq].irq = 0;
+       virt_irq_table[virt_irq].in_use = 0;
 
        spin_unlock_irqrestore(&virt_irq_alloc_lock, flags);
 }
 #endif
 
-static unsigned long virt_to_real_irq(unsigned char virt_irq)
-{
-       return virt_to_real_irq_table[virt_irq].irq;
-}
-
 /*
  * /proc/interrupts printing:
  */
@@ -209,21 +257,10 @@ struct irq_handler_data {
        unsigned long   imap;
 
        void            (*pre_handler)(unsigned int, void *, void *);
-       void            *pre_handler_arg1;
-       void            *pre_handler_arg2;
+       void            *arg1;
+       void            *arg2;
 };
 
-static inline struct ino_bucket *virt_irq_to_bucket(unsigned int virt_irq)
-{
-       unsigned long real_irq = virt_to_real_irq(virt_irq);
-       struct ino_bucket *bucket = NULL;
-
-       if (likely(real_irq))
-               bucket = __bucket(real_irq);
-
-       return bucket;
-}
-
 #ifdef CONFIG_SMP
 static int irq_choose_cpu(unsigned int virt_irq)
 {
@@ -309,7 +346,7 @@ static void sun4u_irq_disable(unsigned int virt_irq)
        }
 }
 
-static void sun4u_irq_end(unsigned int virt_irq)
+static void sun4u_irq_eoi(unsigned int virt_irq)
 {
        struct irq_handler_data *data = get_irq_chip_data(virt_irq);
        struct irq_desc *desc = irq_desc + virt_irq;
@@ -323,206 +360,149 @@ static void sun4u_irq_end(unsigned int virt_irq)
 
 static void sun4v_irq_enable(unsigned int virt_irq)
 {
-       struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
-       unsigned int ino = bucket - &ivector_table[0];
-
-       if (likely(bucket)) {
-               unsigned long cpuid;
-               int err;
+       unsigned int ino = virt_irq_table[virt_irq].dev_ino;
+       unsigned long cpuid = irq_choose_cpu(virt_irq);
+       int err;
 
-               cpuid = irq_choose_cpu(virt_irq);
-
-               err = sun4v_intr_settarget(ino, cpuid);
-               if (err != HV_EOK)
-                       printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): "
-                              "err(%d)\n", ino, cpuid, err);
-               err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
-               if (err != HV_EOK)
-                       printk(KERN_ERR "sun4v_intr_setstate(%x): "
-                              "err(%d)\n", ino, err);
-               err = sun4v_intr_setenabled(ino, HV_INTR_ENABLED);
-               if (err != HV_EOK)
-                       printk(KERN_ERR "sun4v_intr_setenabled(%x): err(%d)\n",
-                              ino, err);
-       }
+       err = sun4v_intr_settarget(ino, cpuid);
+       if (err != HV_EOK)
+               printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): "
+                      "err(%d)\n", ino, cpuid, err);
+       err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
+       if (err != HV_EOK)
+               printk(KERN_ERR "sun4v_intr_setstate(%x): "
+                      "err(%d)\n", ino, err);
+       err = sun4v_intr_setenabled(ino, HV_INTR_ENABLED);
+       if (err != HV_EOK)
+               printk(KERN_ERR "sun4v_intr_setenabled(%x): err(%d)\n",
+                      ino, err);
 }
 
 static void sun4v_set_affinity(unsigned int virt_irq, cpumask_t mask)
 {
-       struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
-       unsigned int ino = bucket - &ivector_table[0];
+       unsigned int ino = virt_irq_table[virt_irq].dev_ino;
+       unsigned long cpuid = irq_choose_cpu(virt_irq);
+       int err;
 
-       if (likely(bucket)) {
-               unsigned long cpuid;
-               int err;
-
-               cpuid = irq_choose_cpu(virt_irq);
-
-               err = sun4v_intr_settarget(ino, cpuid);
-               if (err != HV_EOK)
-                       printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): "
-                              "err(%d)\n", ino, cpuid, err);
-       }
+       err = sun4v_intr_settarget(ino, cpuid);
+       if (err != HV_EOK)
+               printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): "
+                      "err(%d)\n", ino, cpuid, err);
 }
 
 static void sun4v_irq_disable(unsigned int virt_irq)
 {
-       struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
-       unsigned int ino = bucket - &ivector_table[0];
-
-       if (likely(bucket)) {
-               int err;
+       unsigned int ino = virt_irq_table[virt_irq].dev_ino;
+       int err;
 
-               err = sun4v_intr_setenabled(ino, HV_INTR_DISABLED);
-               if (err != HV_EOK)
-                       printk(KERN_ERR "sun4v_intr_setenabled(%x): "
-                              "err(%d)\n", ino, err);
-       }
+       err = sun4v_intr_setenabled(ino, HV_INTR_DISABLED);
+       if (err != HV_EOK)
+               printk(KERN_ERR "sun4v_intr_setenabled(%x): "
+                      "err(%d)\n", ino, err);
 }
 
-static void sun4v_irq_end(unsigned int virt_irq)
+static void sun4v_irq_eoi(unsigned int virt_irq)
 {
-       struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
-       unsigned int ino = bucket - &ivector_table[0];
+       unsigned int ino = virt_irq_table[virt_irq].dev_ino;
        struct irq_desc *desc = irq_desc + virt_irq;
+       int err;
 
        if (unlikely(desc->status & (IRQ_DISABLED|IRQ_INPROGRESS)))
                return;
 
-       if (likely(bucket)) {
-               int err;
-
-               err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
-               if (err != HV_EOK)
-                       printk(KERN_ERR "sun4v_intr_setstate(%x): "
-                              "err(%d)\n", ino, err);
-       }
+       err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
+       if (err != HV_EOK)
+               printk(KERN_ERR "sun4v_intr_setstate(%x): "
+                      "err(%d)\n", ino, err);
 }
 
 static void sun4v_virq_enable(unsigned int virt_irq)
 {
-       struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
-
-       if (likely(bucket)) {
-               unsigned long cpuid, dev_handle, dev_ino;
-               int err;
-
-               cpuid = irq_choose_cpu(virt_irq);
-
-               dev_handle = virt_to_real_irq_table[virt_irq].dev_handle;
-               dev_ino = virt_to_real_irq_table[virt_irq].dev_ino;
-
-               err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid);
-               if (err != HV_EOK)
-                       printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): "
-                              "err(%d)\n",
-                              dev_handle, dev_ino, cpuid, err);
-               err = sun4v_vintr_set_state(dev_handle, dev_ino,
-                                           HV_INTR_STATE_IDLE);
-               if (err != HV_EOK)
-                       printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
-                               "HV_INTR_STATE_IDLE): err(%d)\n",
-                              dev_handle, dev_ino, err);
-               err = sun4v_vintr_set_valid(dev_handle, dev_ino,
-                                           HV_INTR_ENABLED);
-               if (err != HV_EOK)
-                       printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
-                              "HV_INTR_ENABLED): err(%d)\n",
-                              dev_handle, dev_ino, err);
-       }
+       unsigned long cpuid, dev_handle, dev_ino;
+       int err;
+
+       cpuid = irq_choose_cpu(virt_irq);
+
+       dev_handle = virt_irq_table[virt_irq].dev_handle;
+       dev_ino = virt_irq_table[virt_irq].dev_ino;
+
+       err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid);
+       if (err != HV_EOK)
+               printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): "
+                      "err(%d)\n",
+                      dev_handle, dev_ino, cpuid, err);
+       err = sun4v_vintr_set_state(dev_handle, dev_ino,
+                                   HV_INTR_STATE_IDLE);
+       if (err != HV_EOK)
+               printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
+                      "HV_INTR_STATE_IDLE): err(%d)\n",
+                      dev_handle, dev_ino, err);
+       err = sun4v_vintr_set_valid(dev_handle, dev_ino,
+                                   HV_INTR_ENABLED);
+       if (err != HV_EOK)
+               printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
+                      "HV_INTR_ENABLED): err(%d)\n",
+                      dev_handle, dev_ino, err);
 }
 
 static void sun4v_virt_set_affinity(unsigned int virt_irq, cpumask_t mask)
 {
-       struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
+       unsigned long cpuid, dev_handle, dev_ino;
+       int err;
 
-       if (likely(bucket)) {
-               unsigned long cpuid, dev_handle, dev_ino;
-               int err;
+       cpuid = irq_choose_cpu(virt_irq);
 
-               cpuid = irq_choose_cpu(virt_irq);
+       dev_handle = virt_irq_table[virt_irq].dev_handle;
+       dev_ino = virt_irq_table[virt_irq].dev_ino;
 
-               dev_handle = virt_to_real_irq_table[virt_irq].dev_handle;
-               dev_ino = virt_to_real_irq_table[virt_irq].dev_ino;
-
-               err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid);
-               if (err != HV_EOK)
-                       printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): "
-                              "err(%d)\n",
-                              dev_handle, dev_ino, cpuid, err);
-       }
+       err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid);
+       if (err != HV_EOK)
+               printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): "
+                      "err(%d)\n",
+                      dev_handle, dev_ino, cpuid, err);
 }
 
 static void sun4v_virq_disable(unsigned int virt_irq)
 {
-       struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
+       unsigned long dev_handle, dev_ino;
+       int err;
 
-       if (likely(bucket)) {
-               unsigned long dev_handle, dev_ino;
-               int err;
+       dev_handle = virt_irq_table[virt_irq].dev_handle;
+       dev_ino = virt_irq_table[virt_irq].dev_ino;
 
-               dev_handle = virt_to_real_irq_table[virt_irq].dev_handle;
-               dev_ino = virt_to_real_irq_table[virt_irq].dev_ino;
-
-               err = sun4v_vintr_set_valid(dev_handle, dev_ino,
-                                           HV_INTR_DISABLED);
-               if (err != HV_EOK)
-                       printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
-                              "HV_INTR_DISABLED): err(%d)\n",
-                              dev_handle, dev_ino, err);
-       }
+       err = sun4v_vintr_set_valid(dev_handle, dev_ino,
+                                   HV_INTR_DISABLED);
+       if (err != HV_EOK)
+               printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
+                      "HV_INTR_DISABLED): err(%d)\n",
+                      dev_handle, dev_ino, err);
 }
 
-static void sun4v_virq_end(unsigned int virt_irq)
+static void sun4v_virq_eoi(unsigned int virt_irq)
 {
-       struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
        struct irq_desc *desc = irq_desc + virt_irq;
+       unsigned long dev_handle, dev_ino;
+       int err;
 
        if (unlikely(desc->status & (IRQ_DISABLED|IRQ_INPROGRESS)))
                return;
 
-       if (likely(bucket)) {
-               unsigned long dev_handle, dev_ino;
-               int err;
-
-               dev_handle = virt_to_real_irq_table[virt_irq].dev_handle;
-               dev_ino = virt_to_real_irq_table[virt_irq].dev_ino;
+       dev_handle = virt_irq_table[virt_irq].dev_handle;
+       dev_ino = virt_irq_table[virt_irq].dev_ino;
 
-               err = sun4v_vintr_set_state(dev_handle, dev_ino,
-                                           HV_INTR_STATE_IDLE);
-               if (err != HV_EOK)
-                       printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
-                               "HV_INTR_STATE_IDLE): err(%d)\n",
-                              dev_handle, dev_ino, err);
-       }
-}
-
-static void run_pre_handler(unsigned int virt_irq)
-{
-       struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
-       struct irq_handler_data *data = get_irq_chip_data(virt_irq);
-
-       if (likely(data->pre_handler)) {
-               data->pre_handler(__irq_ino(__irq(bucket)),
-                                 data->pre_handler_arg1,
-                                 data->pre_handler_arg2);
-       }
+       err = sun4v_vintr_set_state(dev_handle, dev_ino,
+                                   HV_INTR_STATE_IDLE);
+       if (err != HV_EOK)
+               printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
+                      "HV_INTR_STATE_IDLE): err(%d)\n",
+                      dev_handle, dev_ino, err);
 }
 
 static struct irq_chip sun4u_irq = {
        .typename       = "sun4u",
        .enable         = sun4u_irq_enable,
        .disable        = sun4u_irq_disable,
-       .end            = sun4u_irq_end,
-       .set_affinity   = sun4u_set_affinity,
-};
-
-static struct irq_chip sun4u_irq_ack = {
-       .typename       = "sun4u+ack",
-       .enable         = sun4u_irq_enable,
-       .disable        = sun4u_irq_disable,
-       .ack            = run_pre_handler,
-       .end            = sun4u_irq_end,
+       .eoi            = sun4u_irq_eoi,
        .set_affinity   = sun4u_set_affinity,
 };
 
@@ -530,7 +510,7 @@ static struct irq_chip sun4v_irq = {
        .typename       = "sun4v",
        .enable         = sun4v_irq_enable,
        .disable        = sun4v_irq_disable,
-       .end            = sun4v_irq_end,
+       .eoi            = sun4v_irq_eoi,
        .set_affinity   = sun4v_set_affinity,
 };
 
@@ -538,49 +518,57 @@ static struct irq_chip sun4v_virq = {
        .typename       = "vsun4v",
        .enable         = sun4v_virq_enable,
        .disable        = sun4v_virq_disable,
-       .end            = sun4v_virq_end,
+       .eoi            = sun4v_virq_eoi,
        .set_affinity   = sun4v_virt_set_affinity,
 };
 
+static void fastcall pre_flow_handler(unsigned int virt_irq,
+                                     struct irq_desc *desc)
+{
+       struct irq_handler_data *data = get_irq_chip_data(virt_irq);
+       unsigned int ino = virt_irq_table[virt_irq].dev_ino;
+
+       data->pre_handler(ino, data->arg1, data->arg2);
+
+       handle_fasteoi_irq(virt_irq, desc);
+}
+
 void irq_install_pre_handler(int virt_irq,
                             void (*func)(unsigned int, void *, void *),
                             void *arg1, void *arg2)
 {
        struct irq_handler_data *data = get_irq_chip_data(virt_irq);
-       struct irq_chip *chip = get_irq_chip(virt_irq);
-
-       if (WARN_ON(chip == &sun4v_irq || chip == &sun4v_virq)) {
-               printk(KERN_ERR "IRQ: Trying to install pre-handler on "
-                      "sun4v irq %u\n", virt_irq);
-               return;
-       }
+       struct irq_desc *desc = irq_desc + virt_irq;
 
        data->pre_handler = func;
-       data->pre_handler_arg1 = arg1;
-       data->pre_handler_arg2 = arg2;
+       data->arg1 = arg1;
+       data->arg2 = arg2;
 
-       if (chip == &sun4u_irq_ack)
-               return;
-
-       set_irq_chip(virt_irq, &sun4u_irq_ack);
+       desc->handle_irq = pre_flow_handler;
 }
 
 unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap)
 {
        struct ino_bucket *bucket;
        struct irq_handler_data *data;
+       unsigned int virt_irq;
        int ino;
 
        BUG_ON(tlb_type == hypervisor);
 
        ino = (upa_readq(imap) & (IMAP_IGN | IMAP_INO)) + inofixup;
        bucket = &ivector_table[ino];
-       if (!bucket->virt_irq) {
-               bucket->virt_irq = virt_irq_alloc(__irq(bucket));
-               set_irq_chip(bucket->virt_irq, &sun4u_irq);
+       virt_irq = bucket_get_virt_irq(__pa(bucket));
+       if (!virt_irq) {
+               virt_irq = virt_irq_alloc(0, ino);
+               bucket_set_virt_irq(__pa(bucket), virt_irq);
+               set_irq_chip_and_handler_name(virt_irq,
+                                             &sun4u_irq,
+                                             handle_fasteoi_irq,
+                                             "IVEC");
        }
 
-       data = get_irq_chip_data(bucket->virt_irq);
+       data = get_irq_chip_data(virt_irq);
        if (unlikely(data))
                goto out;
 
@@ -589,13 +577,13 @@ unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap)
                prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
                prom_halt();
        }
-       set_irq_chip_data(bucket->virt_irq, data);
+       set_irq_chip_data(virt_irq, data);
 
        data->imap  = imap;
        data->iclr  = iclr;
 
 out:
-       return bucket->virt_irq;
+       return virt_irq;
 }
 
 static unsigned int sun4v_build_common(unsigned long sysino,
@@ -603,16 +591,21 @@ static unsigned int sun4v_build_common(unsigned long sysino,
 {
        struct ino_bucket *bucket;
        struct irq_handler_data *data;
+       unsigned int virt_irq;
 
        BUG_ON(tlb_type != hypervisor);
 
        bucket = &ivector_table[sysino];
-       if (!bucket->virt_irq) {
-               bucket->virt_irq = virt_irq_alloc(__irq(bucket));
-               set_irq_chip(bucket->virt_irq, chip);
+       virt_irq = bucket_get_virt_irq(__pa(bucket));
+       if (!virt_irq) {
+               virt_irq = virt_irq_alloc(0, sysino);
+               bucket_set_virt_irq(__pa(bucket), virt_irq);
+               set_irq_chip_and_handler_name(virt_irq, chip,
+                                             handle_fasteoi_irq,
+                                             "IVEC");
        }
 
-       data = get_irq_chip_data(bucket->virt_irq);
+       data = get_irq_chip_data(virt_irq);
        if (unlikely(data))
                goto out;
 
@@ -621,7 +614,7 @@ static unsigned int sun4v_build_common(unsigned long sysino,
                prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
                prom_halt();
        }
-       set_irq_chip_data(bucket->virt_irq, data);
+       set_irq_chip_data(virt_irq, data);
 
        /* Catch accidental accesses to these things.  IMAP/ICLR handling
         * is done by hypervisor calls on sun4v platforms, not by direct
@@ -631,7 +624,7 @@ static unsigned int sun4v_build_common(unsigned long sysino,
        data->iclr = ~0UL;
 
 out:
-       return bucket->virt_irq;
+       return virt_irq;
 }
 
 unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino)
@@ -643,36 +636,55 @@ unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino)
 
 unsigned int sun4v_build_virq(u32 devhandle, unsigned int devino)
 {
-       unsigned long sysino, hv_err;
-       unsigned int virq;
+       struct irq_handler_data *data;
+       struct ino_bucket *bucket;
+       unsigned long hv_err, cookie;
+       unsigned int virt_irq;
+
+       bucket = kzalloc(sizeof(struct ino_bucket), GFP_ATOMIC);
+       if (unlikely(!bucket))
+               return 0;
+       __flush_dcache_range((unsigned long) bucket,
+                            ((unsigned long) bucket +
+                             sizeof(struct ino_bucket)));
+
+       virt_irq = virt_irq_alloc(devhandle, devino);
+       bucket_set_virt_irq(__pa(bucket), virt_irq);
 
-       BUG_ON(devhandle & devino);
+       set_irq_chip_and_handler_name(virt_irq, &sun4v_virq,
+                                     handle_fasteoi_irq,
+                                     "IVEC");
+
+       data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
+       if (unlikely(!data))
+               return 0;
 
-       sysino = devhandle | devino;
-       BUG_ON(sysino & ~(IMAP_IGN | IMAP_INO));
+       set_irq_chip_data(virt_irq, data);
 
-       hv_err = sun4v_vintr_set_cookie(devhandle, devino, sysino);
+       /* Catch accidental accesses to these things.  IMAP/ICLR handling
+        * is done by hypervisor calls on sun4v platforms, not by direct
+        * register accesses.
+        */
+       data->imap = ~0UL;
+       data->iclr = ~0UL;
+
+       cookie = ~__pa(bucket);
+       hv_err = sun4v_vintr_set_cookie(devhandle, devino, cookie);
        if (hv_err) {
                prom_printf("IRQ: Fatal, cannot set cookie for [%x:%x] "
                            "err=%lu\n", devhandle, devino, hv_err);
                prom_halt();
        }
 
-       virq = sun4v_build_common(sysino, &sun4v_virq);
-
-       virt_to_real_irq_table[virq].dev_handle = devhandle;
-       virt_to_real_irq_table[virq].dev_ino = devino;
-
-       return virq;
+       return virt_irq;
 }
 
 void ack_bad_irq(unsigned int virt_irq)
 {
-       struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
-       unsigned int ino = 0xdeadbeef;
+       unsigned int ino = virt_irq_table[virt_irq].dev_ino;
 
-       if (bucket)
-               ino = bucket - &ivector_table[0];
+       if (!ino)
+               ino = 0xdeadbeef;
 
        printk(KERN_CRIT "Unexpected IRQ from ino[%x] virt_irq[%u]\n",
               ino, virt_irq);
@@ -700,22 +712,17 @@ void handler_irq(int irq, struct pt_regs *regs)
                             : "memory");
 
        while (bucket_pa) {
+               struct irq_desc *desc;
                unsigned long next_pa;
                unsigned int virt_irq;
 
-               __asm__ __volatile__("ldxa      [%2] %4, %0\n\t"
-                                    "lduwa     [%3] %4, %1\n\t"
-                                    "stxa      %%g0, [%2] %4"
-                                    : "=&r" (next_pa), "=&r" (virt_irq)
-                                    : "r" (bucket_pa +
-                                           offsetof(struct ino_bucket,
-                                                    irq_chain_pa)),
-                                      "r" (bucket_pa +
-                                           offsetof(struct ino_bucket,
-                                                    virt_irq)),
-                                      "i" (ASI_PHYS_USE_EC));
+               next_pa = bucket_get_chain_pa(bucket_pa);
+               virt_irq = bucket_get_virt_irq(bucket_pa);
+               bucket_clear_chain_pa(bucket_pa);
+
+               desc = irq_desc + virt_irq;
 
-               __do_IRQ(virt_irq);
+               desc->handle_irq(virt_irq, desc);
 
                bucket_pa = next_pa;
        }
@@ -861,7 +868,7 @@ void __cpuinit sun4v_register_mondo_queues(int this_cpu)
 static void __init alloc_one_mondo(unsigned long *pa_ptr, unsigned long qmask)
 {
        unsigned long size = PAGE_ALIGN(qmask + 1);
-       void *p = __alloc_bootmem_low(size, size, 0);
+       void *p = __alloc_bootmem(size, size, 0);
        if (!p) {
                prom_printf("SUN4V: Error, cannot allocate mondo queue.\n");
                prom_halt();
@@ -873,7 +880,7 @@ static void __init alloc_one_mondo(unsigned long *pa_ptr, unsigned long qmask)
 static void __init alloc_one_kbuf(unsigned long *pa_ptr, unsigned long qmask)
 {
        unsigned long size = PAGE_ALIGN(qmask + 1);
-       void *p = __alloc_bootmem_low(size, size, 0);
+       void *p = __alloc_bootmem(size, size, 0);
 
        if (!p) {
                prom_printf("SUN4V: Error, cannot allocate kbuf page.\n");
@@ -890,7 +897,7 @@ static void __init init_cpu_send_mondo_info(struct trap_per_cpu *tb)
 
        BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64));
 
-       page = alloc_bootmem_low_pages(PAGE_SIZE);
+       page = alloc_bootmem_pages(PAGE_SIZE);
        if (!page) {
                prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n");
                prom_halt();
@@ -937,11 +944,13 @@ void __init init_IRQ(void)
        kill_prom_timer();
 
        size = sizeof(struct ino_bucket) * NUM_IVECS;
-       ivector_table = alloc_bootmem_low(size);
+       ivector_table = alloc_bootmem(size);
        if (!ivector_table) {
                prom_printf("Fatal error, cannot allocate ivector_table\n");
                prom_halt();
        }
+       __flush_dcache_range((unsigned long) ivector_table,
+                            ((unsigned long) ivector_table) + size);
 
        ivector_table_pa = __pa(ivector_table);