~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to arch/powerpc/sysdev/mpic.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 *  with various broken implementations of this HW.
7
7
 *
8
8
 *  Copyright (C) 2004 Benjamin Herrenschmidt, IBM Corp.
 
9
 *  Copyright 2010-2011 Freescale Semiconductor, Inc.
9
10
 *
10
11
 *  This file is subject to the terms and conditions of the GNU General Public
11
12
 *  License.  See the file COPYING in the main directory of this archive
27
28
#include <linux/spinlock.h>
28
29
#include <linux/pci.h>
29
30
#include <linux/slab.h>
 
31
#include <linux/syscore_ops.h>
 
32
#include <linux/ratelimit.h>
30
33
 
31
34
#include <asm/ptrace.h>
32
35
#include <asm/signal.h>
147
150
 
148
151
#endif /* CONFIG_MPIC_WEIRD */
149
152
 
 
153
static inline unsigned int mpic_processor_id(struct mpic *mpic)
 
154
{
 
155
        unsigned int cpu = 0;
 
156
 
 
157
        if (mpic->flags & MPIC_PRIMARY)
 
158
                cpu = hard_smp_processor_id();
 
159
 
 
160
        return cpu;
 
161
}
 
162
 
150
163
/*
151
164
 * Register accessor functions
152
165
 */
208
221
        _mpic_write(mpic->reg_type, &mpic->gregs, offset, value);
209
222
}
210
223
 
 
224
static inline u32 _mpic_tm_read(struct mpic *mpic, unsigned int tm)
 
225
{
 
226
        unsigned int offset = MPIC_INFO(TIMER_VECTOR_PRI) +
 
227
                              ((tm & 3) * MPIC_INFO(TIMER_STRIDE));
 
228
 
 
229
        if (tm >= 4)
 
230
                offset += 0x1000 / 4;
 
231
 
 
232
        return _mpic_read(mpic->reg_type, &mpic->tmregs, offset);
 
233
}
 
234
 
 
235
static inline void _mpic_tm_write(struct mpic *mpic, unsigned int tm, u32 value)
 
236
{
 
237
        unsigned int offset = MPIC_INFO(TIMER_VECTOR_PRI) +
 
238
                              ((tm & 3) * MPIC_INFO(TIMER_STRIDE));
 
239
 
 
240
        if (tm >= 4)
 
241
                offset += 0x1000 / 4;
 
242
 
 
243
        _mpic_write(mpic->reg_type, &mpic->tmregs, offset, value);
 
244
}
 
245
 
211
246
static inline u32 _mpic_cpu_read(struct mpic *mpic, unsigned int reg)
212
247
{
213
 
        unsigned int cpu = 0;
 
248
        unsigned int cpu = mpic_processor_id(mpic);
214
249
 
215
 
        if (mpic->flags & MPIC_PRIMARY)
216
 
                cpu = hard_smp_processor_id();
217
250
        return _mpic_read(mpic->reg_type, &mpic->cpuregs[cpu], reg);
218
251
}
219
252
 
220
253
static inline void _mpic_cpu_write(struct mpic *mpic, unsigned int reg, u32 value)
221
254
{
222
 
        unsigned int cpu = 0;
223
 
 
224
 
        if (mpic->flags & MPIC_PRIMARY)
225
 
                cpu = hard_smp_processor_id();
 
255
        unsigned int cpu = mpic_processor_id(mpic);
226
256
 
227
257
        _mpic_write(mpic->reg_type, &mpic->cpuregs[cpu], reg, value);
228
258
}
263
293
#define mpic_write(b,r,v)       _mpic_write(mpic->reg_type,&(b),(r),(v))
264
294
#define mpic_ipi_read(i)        _mpic_ipi_read(mpic,(i))
265
295
#define mpic_ipi_write(i,v)     _mpic_ipi_write(mpic,(i),(v))
 
296
#define mpic_tm_read(i)         _mpic_tm_read(mpic,(i))
 
297
#define mpic_tm_write(i,v)      _mpic_tm_write(mpic,(i),(v))
266
298
#define mpic_cpu_read(i)        _mpic_cpu_read(mpic,(i))
267
299
#define mpic_cpu_write(i,v)     _mpic_cpu_write(mpic,(i),(v))
268
300
#define mpic_irq_read(s,r)      _mpic_irq_read(mpic,(s),(r))
356
388
}
357
389
 
358
390
static void mpic_startup_ht_interrupt(struct mpic *mpic, unsigned int source,
359
 
                                      unsigned int irqflags)
 
391
                                      bool level)
360
392
{
361
393
        struct mpic_irq_fixup *fixup = &mpic->fixups[source];
362
394
        unsigned long flags;
365
397
        if (fixup->base == NULL)
366
398
                return;
367
399
 
368
 
        DBG("startup_ht_interrupt(0x%x, 0x%x) index: %d\n",
369
 
            source, irqflags, fixup->index);
 
400
        DBG("startup_ht_interrupt(0x%x) index: %d\n",
 
401
            source, fixup->index);
370
402
        raw_spin_lock_irqsave(&mpic->fixup_lock, flags);
371
403
        /* Enable and configure */
372
404
        writeb(0x10 + 2 * fixup->index, fixup->base + 2);
373
405
        tmp = readl(fixup->base + 4);
374
406
        tmp &= ~(0x23U);
375
 
        if (irqflags & IRQ_LEVEL)
 
407
        if (level)
376
408
                tmp |= 0x22;
377
409
        writel(tmp, fixup->base + 4);
378
410
        raw_spin_unlock_irqrestore(&mpic->fixup_lock, flags);
384
416
#endif
385
417
}
386
418
 
387
 
static void mpic_shutdown_ht_interrupt(struct mpic *mpic, unsigned int source,
388
 
                                       unsigned int irqflags)
 
419
static void mpic_shutdown_ht_interrupt(struct mpic *mpic, unsigned int source)
389
420
{
390
421
        struct mpic_irq_fixup *fixup = &mpic->fixups[source];
391
422
        unsigned long flags;
394
425
        if (fixup->base == NULL)
395
426
                return;
396
427
 
397
 
        DBG("shutdown_ht_interrupt(0x%x, 0x%x)\n", source, irqflags);
 
428
        DBG("shutdown_ht_interrupt(0x%x)\n", source);
398
429
 
399
430
        /* Disable */
400
431
        raw_spin_lock_irqsave(&mpic->fixup_lock, flags);
603
634
}
604
635
#endif
605
636
 
606
 
#define mpic_irq_to_hw(virq)    ((unsigned int)irq_map[virq].hwirq)
607
 
 
608
637
/* Find an mpic associated with a given linux interrupt */
609
638
static struct mpic *mpic_find(unsigned int irq)
610
639
{
611
640
        if (irq < NUM_ISA_INTERRUPTS)
612
641
                return NULL;
613
642
 
614
 
        return irq_to_desc(irq)->chip_data;
 
643
        return irq_get_chip_data(irq);
615
644
}
616
645
 
617
646
/* Determine if the linux irq is an IPI */
618
647
static unsigned int mpic_is_ipi(struct mpic *mpic, unsigned int irq)
619
648
{
620
 
        unsigned int src = mpic_irq_to_hw(irq);
 
649
        unsigned int src = virq_to_hw(irq);
621
650
 
622
651
        return (src >= mpic->ipi_vecs[0] && src <= mpic->ipi_vecs[3]);
623
652
}
624
653
 
 
654
/* Determine if the linux irq is a timer */
 
655
static unsigned int mpic_is_tm(struct mpic *mpic, unsigned int irq)
 
656
{
 
657
        unsigned int src = virq_to_hw(irq);
 
658
 
 
659
        return (src >= mpic->timer_vecs[0] && src <= mpic->timer_vecs[7]);
 
660
}
625
661
 
626
662
/* Convert a cpu mask from logical to physical cpu numbers. */
627
663
static inline u32 mpic_physmask(u32 cpumask)
629
665
        int i;
630
666
        u32 mask = 0;
631
667
 
632
 
        for (i = 0; i < NR_CPUS; ++i, cpumask >>= 1)
 
668
        for (i = 0; i < min(32, NR_CPUS); ++i, cpumask >>= 1)
633
669
                mask |= (cpumask & 1) << get_hard_smp_processor_id(i);
634
670
        return mask;
635
671
}
636
672
 
637
673
#ifdef CONFIG_SMP
638
674
/* Get the mpic structure from the IPI number */
639
 
static inline struct mpic * mpic_from_ipi(unsigned int ipi)
 
675
static inline struct mpic * mpic_from_ipi(struct irq_data *d)
640
676
{
641
 
        return irq_to_desc(ipi)->chip_data;
 
677
        return irq_data_get_irq_chip_data(d);
642
678
}
643
679
#endif
644
680
 
645
681
/* Get the mpic structure from the irq number */
646
682
static inline struct mpic * mpic_from_irq(unsigned int irq)
647
683
{
648
 
        return irq_to_desc(irq)->chip_data;
 
684
        return irq_get_chip_data(irq);
 
685
}
 
686
 
 
687
/* Get the mpic structure from the irq data */
 
688
static inline struct mpic * mpic_from_irq_data(struct irq_data *d)
 
689
{
 
690
        return irq_data_get_irq_chip_data(d);
649
691
}
650
692
 
651
693
/* Send an EOI */
660
702
 */
661
703
 
662
704
 
663
 
void mpic_unmask_irq(unsigned int irq)
 
705
void mpic_unmask_irq(struct irq_data *d)
664
706
{
665
707
        unsigned int loops = 100000;
666
 
        struct mpic *mpic = mpic_from_irq(irq);
667
 
        unsigned int src = mpic_irq_to_hw(irq);
 
708
        struct mpic *mpic = mpic_from_irq_data(d);
 
709
        unsigned int src = irqd_to_hwirq(d);
668
710
 
669
 
        DBG("%p: %s: enable_irq: %d (src %d)\n", mpic, mpic->name, irq, src);
 
711
        DBG("%p: %s: enable_irq: %d (src %d)\n", mpic, mpic->name, d->irq, src);
670
712
 
671
713
        mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI),
672
714
                       mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) &
681
723
        } while(mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) & MPIC_VECPRI_MASK);
682
724
}
683
725
 
684
 
void mpic_mask_irq(unsigned int irq)
 
726
void mpic_mask_irq(struct irq_data *d)
685
727
{
686
728
        unsigned int loops = 100000;
687
 
        struct mpic *mpic = mpic_from_irq(irq);
688
 
        unsigned int src = mpic_irq_to_hw(irq);
 
729
        struct mpic *mpic = mpic_from_irq_data(d);
 
730
        unsigned int src = irqd_to_hwirq(d);
689
731
 
690
 
        DBG("%s: disable_irq: %d (src %d)\n", mpic->name, irq, src);
 
732
        DBG("%s: disable_irq: %d (src %d)\n", mpic->name, d->irq, src);
691
733
 
692
734
        mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI),
693
735
                       mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) |
703
745
        } while(!(mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) & MPIC_VECPRI_MASK));
704
746
}
705
747
 
706
 
void mpic_end_irq(unsigned int irq)
 
748
void mpic_end_irq(struct irq_data *d)
707
749
{
708
 
        struct mpic *mpic = mpic_from_irq(irq);
 
750
        struct mpic *mpic = mpic_from_irq_data(d);
709
751
 
710
752
#ifdef DEBUG_IRQ
711
 
        DBG("%s: end_irq: %d\n", mpic->name, irq);
 
753
        DBG("%s: end_irq: %d\n", mpic->name, d->irq);
712
754
#endif
713
755
        /* We always EOI on end_irq() even for edge interrupts since that
714
756
         * should only lower the priority, the MPIC should have properly
720
762
 
721
763
#ifdef CONFIG_MPIC_U3_HT_IRQS
722
764
 
723
 
static void mpic_unmask_ht_irq(unsigned int irq)
 
765
static void mpic_unmask_ht_irq(struct irq_data *d)
724
766
{
725
 
        struct mpic *mpic = mpic_from_irq(irq);
726
 
        unsigned int src = mpic_irq_to_hw(irq);
727
 
 
728
 
        mpic_unmask_irq(irq);
729
 
 
730
 
        if (irq_to_desc(irq)->status & IRQ_LEVEL)
 
767
        struct mpic *mpic = mpic_from_irq_data(d);
 
768
        unsigned int src = irqd_to_hwirq(d);
 
769
 
 
770
        mpic_unmask_irq(d);
 
771
 
 
772
        if (irqd_is_level_type(d))
731
773
                mpic_ht_end_irq(mpic, src);
732
774
}
733
775
 
734
 
static unsigned int mpic_startup_ht_irq(unsigned int irq)
 
776
static unsigned int mpic_startup_ht_irq(struct irq_data *d)
735
777
{
736
 
        struct mpic *mpic = mpic_from_irq(irq);
737
 
        unsigned int src = mpic_irq_to_hw(irq);
 
778
        struct mpic *mpic = mpic_from_irq_data(d);
 
779
        unsigned int src = irqd_to_hwirq(d);
738
780
 
739
 
        mpic_unmask_irq(irq);
740
 
        mpic_startup_ht_interrupt(mpic, src, irq_to_desc(irq)->status);
 
781
        mpic_unmask_irq(d);
 
782
        mpic_startup_ht_interrupt(mpic, src, irqd_is_level_type(d));
741
783
 
742
784
        return 0;
743
785
}
744
786
 
745
 
static void mpic_shutdown_ht_irq(unsigned int irq)
 
787
static void mpic_shutdown_ht_irq(struct irq_data *d)
746
788
{
747
 
        struct mpic *mpic = mpic_from_irq(irq);
748
 
        unsigned int src = mpic_irq_to_hw(irq);
 
789
        struct mpic *mpic = mpic_from_irq_data(d);
 
790
        unsigned int src = irqd_to_hwirq(d);
749
791
 
750
 
        mpic_shutdown_ht_interrupt(mpic, src, irq_to_desc(irq)->status);
751
 
        mpic_mask_irq(irq);
 
792
        mpic_shutdown_ht_interrupt(mpic, src);
 
793
        mpic_mask_irq(d);
752
794
}
753
795
 
754
 
static void mpic_end_ht_irq(unsigned int irq)
 
796
static void mpic_end_ht_irq(struct irq_data *d)
755
797
{
756
 
        struct mpic *mpic = mpic_from_irq(irq);
757
 
        unsigned int src = mpic_irq_to_hw(irq);
 
798
        struct mpic *mpic = mpic_from_irq_data(d);
 
799
        unsigned int src = irqd_to_hwirq(d);
758
800
 
759
801
#ifdef DEBUG_IRQ
760
 
        DBG("%s: end_irq: %d\n", mpic->name, irq);
 
802
        DBG("%s: end_irq: %d\n", mpic->name, d->irq);
761
803
#endif
762
804
        /* We always EOI on end_irq() even for edge interrupts since that
763
805
         * should only lower the priority, the MPIC should have properly
764
806
         * latched another edge interrupt coming in anyway
765
807
         */
766
808
 
767
 
        if (irq_to_desc(irq)->status & IRQ_LEVEL)
 
809
        if (irqd_is_level_type(d))
768
810
                mpic_ht_end_irq(mpic, src);
769
811
        mpic_eoi(mpic);
770
812
}
772
814
 
773
815
#ifdef CONFIG_SMP
774
816
 
775
 
static void mpic_unmask_ipi(unsigned int irq)
 
817
static void mpic_unmask_ipi(struct irq_data *d)
776
818
{
777
 
        struct mpic *mpic = mpic_from_ipi(irq);
778
 
        unsigned int src = mpic_irq_to_hw(irq) - mpic->ipi_vecs[0];
 
819
        struct mpic *mpic = mpic_from_ipi(d);
 
820
        unsigned int src = virq_to_hw(d->irq) - mpic->ipi_vecs[0];
779
821
 
780
 
        DBG("%s: enable_ipi: %d (ipi %d)\n", mpic->name, irq, src);
 
822
        DBG("%s: enable_ipi: %d (ipi %d)\n", mpic->name, d->irq, src);
781
823
        mpic_ipi_write(src, mpic_ipi_read(src) & ~MPIC_VECPRI_MASK);
782
824
}
783
825
 
784
 
static void mpic_mask_ipi(unsigned int irq)
 
826
static void mpic_mask_ipi(struct irq_data *d)
785
827
{
786
828
        /* NEVER disable an IPI... that's just plain wrong! */
787
829
}
788
830
 
789
 
static void mpic_end_ipi(unsigned int irq)
 
831
static void mpic_end_ipi(struct irq_data *d)
790
832
{
791
 
        struct mpic *mpic = mpic_from_ipi(irq);
 
833
        struct mpic *mpic = mpic_from_ipi(d);
792
834
 
793
835
        /*
794
836
         * IPIs are marked IRQ_PER_CPU. This has the side effect of
802
844
 
803
845
#endif /* CONFIG_SMP */
804
846
 
805
 
int mpic_set_affinity(unsigned int irq, const struct cpumask *cpumask)
806
 
{
807
 
        struct mpic *mpic = mpic_from_irq(irq);
808
 
        unsigned int src = mpic_irq_to_hw(irq);
 
847
static void mpic_unmask_tm(struct irq_data *d)
 
848
{
 
849
        struct mpic *mpic = mpic_from_irq_data(d);
 
850
        unsigned int src = virq_to_hw(d->irq) - mpic->timer_vecs[0];
 
851
 
 
852
        DBG("%s: enable_tm: %d (tm %d)\n", mpic->name, irq, src);
 
853
        mpic_tm_write(src, mpic_tm_read(src) & ~MPIC_VECPRI_MASK);
 
854
        mpic_tm_read(src);
 
855
}
 
856
 
 
857
static void mpic_mask_tm(struct irq_data *d)
 
858
{
 
859
        struct mpic *mpic = mpic_from_irq_data(d);
 
860
        unsigned int src = virq_to_hw(d->irq) - mpic->timer_vecs[0];
 
861
 
 
862
        mpic_tm_write(src, mpic_tm_read(src) | MPIC_VECPRI_MASK);
 
863
        mpic_tm_read(src);
 
864
}
 
865
 
 
866
int mpic_set_affinity(struct irq_data *d, const struct cpumask *cpumask,
 
867
                      bool force)
 
868
{
 
869
        struct mpic *mpic = mpic_from_irq_data(d);
 
870
        unsigned int src = irqd_to_hwirq(d);
809
871
 
810
872
        if (mpic->flags & MPIC_SINGLE_DEST_CPU) {
811
873
                int cpuid = irq_choose_cpu(cpumask);
812
874
 
813
875
                mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION), 1 << cpuid);
814
876
        } else {
815
 
                cpumask_var_t tmp;
816
 
 
817
 
                alloc_cpumask_var(&tmp, GFP_KERNEL);
818
 
 
819
 
                cpumask_and(tmp, cpumask, cpu_online_mask);
 
877
                u32 mask = cpumask_bits(cpumask)[0];
 
878
 
 
879
                mask &= cpumask_bits(cpu_online_mask)[0];
820
880
 
821
881
                mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION),
822
 
                               mpic_physmask(cpumask_bits(tmp)[0]));
823
 
 
824
 
                free_cpumask_var(tmp);
 
882
                               mpic_physmask(mask));
825
883
        }
826
884
 
827
885
        return 0;
848
906
        }
849
907
}
850
908
 
851
 
int mpic_set_irq_type(unsigned int virq, unsigned int flow_type)
 
909
int mpic_set_irq_type(struct irq_data *d, unsigned int flow_type)
852
910
{
853
 
        struct mpic *mpic = mpic_from_irq(virq);
854
 
        unsigned int src = mpic_irq_to_hw(virq);
855
 
        struct irq_desc *desc = irq_to_desc(virq);
 
911
        struct mpic *mpic = mpic_from_irq_data(d);
 
912
        unsigned int src = irqd_to_hwirq(d);
856
913
        unsigned int vecpri, vold, vnew;
857
914
 
858
915
        DBG("mpic: set_irq_type(mpic:@%p,virq:%d,src:0x%x,type:0x%x)\n",
859
 
            mpic, virq, src, flow_type);
 
916
            mpic, d->irq, src, flow_type);
860
917
 
861
918
        if (src >= mpic->irq_count)
862
919
                return -EINVAL;
867
924
        if (flow_type == IRQ_TYPE_NONE)
868
925
                flow_type = IRQ_TYPE_LEVEL_LOW;
869
926
 
870
 
        desc->status &= ~(IRQ_TYPE_SENSE_MASK | IRQ_LEVEL);
871
 
        desc->status |= flow_type & IRQ_TYPE_SENSE_MASK;
872
 
        if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW))
873
 
                desc->status |= IRQ_LEVEL;
 
927
        irqd_set_trigger_type(d, flow_type);
874
928
 
875
929
        if (mpic_is_ht_interrupt(mpic, src))
876
930
                vecpri = MPIC_VECPRI_POLARITY_POSITIVE |
885
939
        if (vold != vnew)
886
940
                mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), vnew);
887
941
 
888
 
        return 0;
 
942
        return IRQ_SET_MASK_OK_NOCOPY;;
889
943
}
890
944
 
891
945
void mpic_set_vector(unsigned int virq, unsigned int vector)
892
946
{
893
947
        struct mpic *mpic = mpic_from_irq(virq);
894
 
        unsigned int src = mpic_irq_to_hw(virq);
 
948
        unsigned int src = virq_to_hw(virq);
895
949
        unsigned int vecpri;
896
950
 
897
951
        DBG("mpic: set_vector(mpic:@%p,virq:%d,src:%d,vector:0x%x)\n",
906
960
        mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), vecpri);
907
961
}
908
962
 
 
963
void mpic_set_destination(unsigned int virq, unsigned int cpuid)
 
964
{
 
965
        struct mpic *mpic = mpic_from_irq(virq);
 
966
        unsigned int src = virq_to_hw(virq);
 
967
 
 
968
        DBG("mpic: set_destination(mpic:@%p,virq:%d,src:%d,cpuid:0x%x)\n",
 
969
            mpic, virq, src, cpuid);
 
970
 
 
971
        if (src >= mpic->irq_count)
 
972
                return;
 
973
 
 
974
        mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION), 1 << cpuid);
 
975
}
 
976
 
909
977
static struct irq_chip mpic_irq_chip = {
910
 
        .mask           = mpic_mask_irq,
911
 
        .unmask         = mpic_unmask_irq,
912
 
        .eoi            = mpic_end_irq,
913
 
        .set_type       = mpic_set_irq_type,
 
978
        .irq_mask       = mpic_mask_irq,
 
979
        .irq_unmask     = mpic_unmask_irq,
 
980
        .irq_eoi        = mpic_end_irq,
 
981
        .irq_set_type   = mpic_set_irq_type,
914
982
};
915
983
 
916
984
#ifdef CONFIG_SMP
917
985
static struct irq_chip mpic_ipi_chip = {
918
 
        .mask           = mpic_mask_ipi,
919
 
        .unmask         = mpic_unmask_ipi,
920
 
        .eoi            = mpic_end_ipi,
 
986
        .irq_mask       = mpic_mask_ipi,
 
987
        .irq_unmask     = mpic_unmask_ipi,
 
988
        .irq_eoi        = mpic_end_ipi,
921
989
};
922
990
#endif /* CONFIG_SMP */
923
991
 
 
992
static struct irq_chip mpic_tm_chip = {
 
993
        .irq_mask       = mpic_mask_tm,
 
994
        .irq_unmask     = mpic_unmask_tm,
 
995
        .irq_eoi        = mpic_end_irq,
 
996
};
 
997
 
924
998
#ifdef CONFIG_MPIC_U3_HT_IRQS
925
999
static struct irq_chip mpic_irq_ht_chip = {
926
 
        .startup        = mpic_startup_ht_irq,
927
 
        .shutdown       = mpic_shutdown_ht_irq,
928
 
        .mask           = mpic_mask_irq,
929
 
        .unmask         = mpic_unmask_ht_irq,
930
 
        .eoi            = mpic_end_ht_irq,
931
 
        .set_type       = mpic_set_irq_type,
 
1000
        .irq_startup    = mpic_startup_ht_irq,
 
1001
        .irq_shutdown   = mpic_shutdown_ht_irq,
 
1002
        .irq_mask       = mpic_mask_irq,
 
1003
        .irq_unmask     = mpic_unmask_ht_irq,
 
1004
        .irq_eoi        = mpic_end_ht_irq,
 
1005
        .irq_set_type   = mpic_set_irq_type,
932
1006
};
933
1007
#endif /* CONFIG_MPIC_U3_HT_IRQS */
934
1008
 
957
1031
                WARN_ON(!(mpic->flags & MPIC_PRIMARY));
958
1032
 
959
1033
                DBG("mpic: mapping as IPI\n");
960
 
                set_irq_chip_data(virq, mpic);
961
 
                set_irq_chip_and_handler(virq, &mpic->hc_ipi,
 
1034
                irq_set_chip_data(virq, mpic);
 
1035
                irq_set_chip_and_handler(virq, &mpic->hc_ipi,
962
1036
                                         handle_percpu_irq);
963
1037
                return 0;
964
1038
        }
965
1039
#endif /* CONFIG_SMP */
966
1040
 
 
1041
        if (hw >= mpic->timer_vecs[0] && hw <= mpic->timer_vecs[7]) {
 
1042
                WARN_ON(!(mpic->flags & MPIC_PRIMARY));
 
1043
 
 
1044
                DBG("mpic: mapping as timer\n");
 
1045
                irq_set_chip_data(virq, mpic);
 
1046
                irq_set_chip_and_handler(virq, &mpic->hc_tm,
 
1047
                                         handle_fasteoi_irq);
 
1048
                return 0;
 
1049
        }
 
1050
 
967
1051
        if (hw >= mpic->irq_count)
968
1052
                return -EINVAL;
969
1053
 
980
1064
 
981
1065
        DBG("mpic: mapping to irq chip @%p\n", chip);
982
1066
 
983
 
        set_irq_chip_data(virq, mpic);
984
 
        set_irq_chip_and_handler(virq, chip, handle_fasteoi_irq);
 
1067
        irq_set_chip_data(virq, mpic);
 
1068
        irq_set_chip_and_handler(virq, chip, handle_fasteoi_irq);
985
1069
 
986
1070
        /* Set default irq type */
987
 
        set_irq_type(virq, IRQ_TYPE_NONE);
 
1071
        irq_set_irq_type(virq, IRQ_TYPE_NONE);
 
1072
 
 
1073
        /* If the MPIC was reset, then all vectors have already been
 
1074
         * initialized.  Otherwise, a per source lazy initialization
 
1075
         * is done here.
 
1076
         */
 
1077
        if (!mpic_is_ipi(mpic, hw) && (mpic->flags & MPIC_NO_RESET)) {
 
1078
                mpic_set_vector(virq, hw);
 
1079
                mpic_set_destination(virq, mpic_processor_id(mpic));
 
1080
                mpic_irq_set_priority(virq, 8);
 
1081
        }
988
1082
 
989
1083
        return 0;
990
1084
}
994
1088
                           irq_hw_number_t *out_hwirq, unsigned int *out_flags)
995
1089
 
996
1090
{
 
1091
        struct mpic *mpic = h->host_data;
997
1092
        static unsigned char map_mpic_senses[4] = {
998
1093
                IRQ_TYPE_EDGE_RISING,
999
1094
                IRQ_TYPE_LEVEL_LOW,
1002
1097
        };
1003
1098
 
1004
1099
        *out_hwirq = intspec[0];
1005
 
        if (intsize > 1) {
 
1100
        if (intsize >= 4 && (mpic->flags & MPIC_FSL)) {
 
1101
                /*
 
1102
                 * Freescale MPIC with extended intspec:
 
1103
                 * First two cells are as usual.  Third specifies
 
1104
                 * an "interrupt type".  Fourth is type-specific data.
 
1105
                 *
 
1106
                 * See Documentation/devicetree/bindings/powerpc/fsl/mpic.txt
 
1107
                 */
 
1108
                switch (intspec[2]) {
 
1109
                case 0:
 
1110
                case 1: /* no EISR/EIMR support for now, treat as shared IRQ */
 
1111
                        break;
 
1112
                case 2:
 
1113
                        if (intspec[0] >= ARRAY_SIZE(mpic->ipi_vecs))
 
1114
                                return -EINVAL;
 
1115
 
 
1116
                        *out_hwirq = mpic->ipi_vecs[intspec[0]];
 
1117
                        break;
 
1118
                case 3:
 
1119
                        if (intspec[0] >= ARRAY_SIZE(mpic->timer_vecs))
 
1120
                                return -EINVAL;
 
1121
 
 
1122
                        *out_hwirq = mpic->timer_vecs[intspec[0]];
 
1123
                        break;
 
1124
                default:
 
1125
                        pr_debug("%s: unknown irq type %u\n",
 
1126
                                 __func__, intspec[2]);
 
1127
                        return -EINVAL;
 
1128
                }
 
1129
 
 
1130
                *out_flags = map_mpic_senses[intspec[1] & 3];
 
1131
        } else if (intsize > 1) {
1006
1132
                u32 mask = 0x3;
1007
1133
 
1008
1134
                /* Apple invented a new race of encoding on machines with
1033
1159
        .xlate = mpic_host_xlate,
1034
1160
};
1035
1161
 
 
1162
static int mpic_reset_prohibited(struct device_node *node)
 
1163
{
 
1164
        return node && of_get_property(node, "pic-no-reset", NULL);
 
1165
}
 
1166
 
1036
1167
/*
1037
1168
 * Exported functions
1038
1169
 */
1060
1191
        mpic->hc_irq = mpic_irq_chip;
1061
1192
        mpic->hc_irq.name = name;
1062
1193
        if (flags & MPIC_PRIMARY)
1063
 
                mpic->hc_irq.set_affinity = mpic_set_affinity;
 
1194
                mpic->hc_irq.irq_set_affinity = mpic_set_affinity;
1064
1195
#ifdef CONFIG_MPIC_U3_HT_IRQS
1065
1196
        mpic->hc_ht_irq = mpic_irq_ht_chip;
1066
1197
        mpic->hc_ht_irq.name = name;
1067
1198
        if (flags & MPIC_PRIMARY)
1068
 
                mpic->hc_ht_irq.set_affinity = mpic_set_affinity;
 
1199
                mpic->hc_ht_irq.irq_set_affinity = mpic_set_affinity;
1069
1200
#endif /* CONFIG_MPIC_U3_HT_IRQS */
1070
1201
 
1071
1202
#ifdef CONFIG_SMP
1073
1204
        mpic->hc_ipi.name = name;
1074
1205
#endif /* CONFIG_SMP */
1075
1206
 
 
1207
        mpic->hc_tm = mpic_tm_chip;
 
1208
        mpic->hc_tm.name = name;
 
1209
 
1076
1210
        mpic->flags = flags;
1077
1211
        mpic->isu_size = isu_size;
1078
1212
        mpic->irq_count = irq_count;
1083
1217
        else
1084
1218
                intvec_top = 255;
1085
1219
 
1086
 
        mpic->timer_vecs[0] = intvec_top - 8;
1087
 
        mpic->timer_vecs[1] = intvec_top - 7;
1088
 
        mpic->timer_vecs[2] = intvec_top - 6;
1089
 
        mpic->timer_vecs[3] = intvec_top - 5;
 
1220
        mpic->timer_vecs[0] = intvec_top - 12;
 
1221
        mpic->timer_vecs[1] = intvec_top - 11;
 
1222
        mpic->timer_vecs[2] = intvec_top - 10;
 
1223
        mpic->timer_vecs[3] = intvec_top - 9;
 
1224
        mpic->timer_vecs[4] = intvec_top - 8;
 
1225
        mpic->timer_vecs[5] = intvec_top - 7;
 
1226
        mpic->timer_vecs[6] = intvec_top - 6;
 
1227
        mpic->timer_vecs[7] = intvec_top - 5;
1090
1228
        mpic->ipi_vecs[0]   = intvec_top - 4;
1091
1229
        mpic->ipi_vecs[1]   = intvec_top - 3;
1092
1230
        mpic->ipi_vecs[2]   = intvec_top - 2;
1096
1234
        /* Check for "big-endian" in device-tree */
1097
1235
        if (node && of_get_property(node, "big-endian", NULL) != NULL)
1098
1236
                mpic->flags |= MPIC_BIG_ENDIAN;
 
1237
        if (node && of_device_is_compatible(node, "fsl,mpic"))
 
1238
                mpic->flags |= MPIC_FSL;
1099
1239
 
1100
1240
        /* Look for protected sources */
1101
1241
        if (node) {
1153
1293
        mpic_map(mpic, node, paddr, &mpic->tmregs, MPIC_INFO(TIMER_BASE), 0x1000);
1154
1294
 
1155
1295
        /* Reset */
1156
 
        if (flags & MPIC_WANTS_RESET) {
 
1296
 
 
1297
        /* When using a device-node, reset requests are only honored if the MPIC
 
1298
         * is allowed to reset.
 
1299
         */
 
1300
        if (mpic_reset_prohibited(node))
 
1301
                mpic->flags |= MPIC_NO_RESET;
 
1302
 
 
1303
        if ((flags & MPIC_WANTS_RESET) && !(mpic->flags & MPIC_NO_RESET)) {
 
1304
                printk(KERN_DEBUG "mpic: Resetting\n");
1157
1305
                mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
1158
1306
                           mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
1159
1307
                           | MPIC_GREG_GCONF_RESET);
1279
1427
        /* Set current processor priority to max */
1280
1428
        mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0xf);
1281
1429
 
1282
 
        /* Initialize timers: just disable them all */
 
1430
        /* Initialize timers to our reserved vectors and mask them for now */
1283
1431
        for (i = 0; i < 4; i++) {
1284
1432
                mpic_write(mpic->tmregs,
1285
1433
                           i * MPIC_INFO(TIMER_STRIDE) +
1286
 
                           MPIC_INFO(TIMER_DESTINATION), 0);
 
1434
                           MPIC_INFO(TIMER_DESTINATION),
 
1435
                           1 << hard_smp_processor_id());
1287
1436
                mpic_write(mpic->tmregs,
1288
1437
                           i * MPIC_INFO(TIMER_STRIDE) +
1289
1438
                           MPIC_INFO(TIMER_VECTOR_PRI),
1290
1439
                           MPIC_VECPRI_MASK |
 
1440
                           (9 << MPIC_VECPRI_PRIORITY_SHIFT) |
1291
1441
                           (mpic->timer_vecs[0] + i));
1292
1442
        }
1293
1443
 
1313
1463
 
1314
1464
        mpic_pasemi_msi_init(mpic);
1315
1465
 
1316
 
        if (mpic->flags & MPIC_PRIMARY)
1317
 
                cpu = hard_smp_processor_id();
1318
 
        else
1319
 
                cpu = 0;
 
1466
        cpu = mpic_processor_id(mpic);
1320
1467
 
1321
 
        for (i = 0; i < mpic->num_sources; i++) {
1322
 
                /* start with vector = source number, and masked */
1323
 
                u32 vecpri = MPIC_VECPRI_MASK | i |
1324
 
                        (8 << MPIC_VECPRI_PRIORITY_SHIFT);
 
1468
        if (!(mpic->flags & MPIC_NO_RESET)) {
 
1469
                for (i = 0; i < mpic->num_sources; i++) {
 
1470
                        /* start with vector = source number, and masked */
 
1471
                        u32 vecpri = MPIC_VECPRI_MASK | i |
 
1472
                                (8 << MPIC_VECPRI_PRIORITY_SHIFT);
1325
1473
                
1326
 
                /* check if protected */
1327
 
                if (mpic->protected && test_bit(i, mpic->protected))
1328
 
                        continue;
1329
 
                /* init hw */
1330
 
                mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI), vecpri);
1331
 
                mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION), 1 << cpu);
 
1474
                        /* check if protected */
 
1475
                        if (mpic->protected && test_bit(i, mpic->protected))
 
1476
                                continue;
 
1477
                        /* init hw */
 
1478
                        mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI), vecpri);
 
1479
                        mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION), 1 << cpu);
 
1480
                }
1332
1481
        }
1333
1482
        
1334
1483
        /* Init spurious vector */
1384
1533
void mpic_irq_set_priority(unsigned int irq, unsigned int pri)
1385
1534
{
1386
1535
        struct mpic *mpic = mpic_find(irq);
1387
 
        unsigned int src = mpic_irq_to_hw(irq);
 
1536
        unsigned int src = virq_to_hw(irq);
1388
1537
        unsigned long flags;
1389
1538
        u32 reg;
1390
1539
 
1397
1546
                        ~MPIC_VECPRI_PRIORITY_MASK;
1398
1547
                mpic_ipi_write(src - mpic->ipi_vecs[0],
1399
1548
                               reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
 
1549
        } else if (mpic_is_tm(mpic, irq)) {
 
1550
                reg = mpic_tm_read(src - mpic->timer_vecs[0]) &
 
1551
                        ~MPIC_VECPRI_PRIORITY_MASK;
 
1552
                mpic_tm_write(src - mpic->timer_vecs[0],
 
1553
                              reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
1400
1554
        } else {
1401
1555
                reg = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI))
1402
1556
                        & ~MPIC_VECPRI_PRIORITY_MASK;
1495
1649
                return NO_IRQ;
1496
1650
        }
1497
1651
        if (unlikely(mpic->protected && test_bit(src, mpic->protected))) {
1498
 
                if (printk_ratelimit())
1499
 
                        printk(KERN_WARNING "%s: Got protected source %d !\n",
1500
 
                               mpic->name, (int)src);
 
1652
                printk_ratelimited(KERN_WARNING "%s: Got protected source %d !\n",
 
1653
                                   mpic->name, (int)src);
1501
1654
                mpic_eoi(mpic);
1502
1655
                return NO_IRQ;
1503
1656
        }
1535
1688
                return NO_IRQ;
1536
1689
        }
1537
1690
        if (unlikely(mpic->protected && test_bit(src, mpic->protected))) {
1538
 
                if (printk_ratelimit())
1539
 
                        printk(KERN_WARNING "%s: Got protected source %d !\n",
1540
 
                               mpic->name, (int)src);
 
1691
                printk_ratelimited(KERN_WARNING "%s: Got protected source %d !\n",
 
1692
                                   mpic->name, (int)src);
1541
1693
                return NO_IRQ;
1542
1694
        }
1543
1695
 
1576
1728
        }
1577
1729
}
1578
1730
 
1579
 
static void mpic_send_ipi(unsigned int ipi_no, const struct cpumask *cpu_mask)
 
1731
void smp_mpic_message_pass(int cpu, int msg)
1580
1732
{
1581
1733
        struct mpic *mpic = mpic_primary;
 
1734
        u32 physmask;
1582
1735
 
1583
1736
        BUG_ON(mpic == NULL);
1584
1737
 
1585
 
#ifdef DEBUG_IPI
1586
 
        DBG("%s: send_ipi(ipi_no: %d)\n", mpic->name, ipi_no);
1587
 
#endif
1588
 
 
1589
 
        mpic_cpu_write(MPIC_INFO(CPU_IPI_DISPATCH_0) +
1590
 
                       ipi_no * MPIC_INFO(CPU_IPI_DISPATCH_STRIDE),
1591
 
                       mpic_physmask(cpumask_bits(cpu_mask)[0]));
1592
 
}
1593
 
 
1594
 
void smp_mpic_message_pass(int target, int msg)
1595
 
{
1596
 
        cpumask_var_t tmp;
1597
 
 
1598
1738
        /* make sure we're sending something that translates to an IPI */
1599
1739
        if ((unsigned int)msg > 3) {
1600
1740
                printk("SMP %d: smp_message_pass: unknown msg %d\n",
1601
1741
                       smp_processor_id(), msg);
1602
1742
                return;
1603
1743
        }
1604
 
        switch (target) {
1605
 
        case MSG_ALL:
1606
 
                mpic_send_ipi(msg, cpu_online_mask);
1607
 
                break;
1608
 
        case MSG_ALL_BUT_SELF:
1609
 
                alloc_cpumask_var(&tmp, GFP_NOWAIT);
1610
 
                cpumask_andnot(tmp, cpu_online_mask,
1611
 
                               cpumask_of(smp_processor_id()));
1612
 
                mpic_send_ipi(msg, tmp);
1613
 
                free_cpumask_var(tmp);
1614
 
                break;
1615
 
        default:
1616
 
                mpic_send_ipi(msg, cpumask_of(target));
1617
 
                break;
1618
 
        }
 
1744
 
 
1745
#ifdef DEBUG_IPI
 
1746
        DBG("%s: send_ipi(ipi_no: %d)\n", mpic->name, msg);
 
1747
#endif
 
1748
 
 
1749
        physmask = 1 << get_hard_smp_processor_id(cpu);
 
1750
 
 
1751
        mpic_cpu_write(MPIC_INFO(CPU_IPI_DISPATCH_0) +
 
1752
                       msg * MPIC_INFO(CPU_IPI_DISPATCH_STRIDE), physmask);
1619
1753
}
1620
1754
 
1621
1755
int __init smp_mpic_probe(void)
1659
1793
#endif /* CONFIG_SMP */
1660
1794
 
1661
1795
#ifdef CONFIG_PM
1662
 
static int mpic_suspend(struct sys_device *dev, pm_message_t state)
 
1796
static void mpic_suspend_one(struct mpic *mpic)
1663
1797
{
1664
 
        struct mpic *mpic = container_of(dev, struct mpic, sysdev);
1665
1798
        int i;
1666
1799
 
1667
1800
        for (i = 0; i < mpic->num_sources; i++) {
1670
1803
                mpic->save_data[i].dest =
1671
1804
                        mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION));
1672
1805
        }
 
1806
}
 
1807
 
 
1808
static int mpic_suspend(void)
 
1809
{
 
1810
        struct mpic *mpic = mpics;
 
1811
 
 
1812
        while (mpic) {
 
1813
                mpic_suspend_one(mpic);
 
1814
                mpic = mpic->next;
 
1815
        }
1673
1816
 
1674
1817
        return 0;
1675
1818
}
1676
1819
 
1677
 
static int mpic_resume(struct sys_device *dev)
 
1820
static void mpic_resume_one(struct mpic *mpic)
1678
1821
{
1679
 
        struct mpic *mpic = container_of(dev, struct mpic, sysdev);
1680
1822
        int i;
1681
1823
 
1682
1824
        for (i = 0; i < mpic->num_sources; i++) {
1703
1845
        }
1704
1846
#endif
1705
1847
        } /* end for loop */
1706
 
 
1707
 
        return 0;
1708
 
}
1709
 
#endif
1710
 
 
1711
 
static struct sysdev_class mpic_sysclass = {
1712
 
#ifdef CONFIG_PM
 
1848
}
 
1849
 
 
1850
static void mpic_resume(void)
 
1851
{
 
1852
        struct mpic *mpic = mpics;
 
1853
 
 
1854
        while (mpic) {
 
1855
                mpic_resume_one(mpic);
 
1856
                mpic = mpic->next;
 
1857
        }
 
1858
}
 
1859
 
 
1860
static struct syscore_ops mpic_syscore_ops = {
1713
1861
        .resume = mpic_resume,
1714
1862
        .suspend = mpic_suspend,
1715
 
#endif
1716
 
        .name = "mpic",
1717
1863
};
1718
1864
 
1719
1865
static int mpic_init_sys(void)
1720
1866
{
1721
 
        struct mpic *mpic = mpics;
1722
 
        int error, id = 0;
1723
 
 
1724
 
        error = sysdev_class_register(&mpic_sysclass);
1725
 
 
1726
 
        while (mpic && !error) {
1727
 
                mpic->sysdev.cls = &mpic_sysclass;
1728
 
                mpic->sysdev.id = id++;
1729
 
                error = sysdev_register(&mpic->sysdev);
1730
 
                mpic = mpic->next;
1731
 
        }
1732
 
        return error;
 
1867
        register_syscore_ops(&mpic_syscore_ops);
 
1868
        return 0;
1733
1869
}
1734
1870
 
1735
1871
device_initcall(mpic_init_sys);
 
1872
#endif