e7ac8109b6e70a9e43aee29760c82f249df349a1
[pandora-kernel.git] / include / asm-powerpc / mpic.h
1 #ifndef _ASM_POWERPC_MPIC_H
2 #define _ASM_POWERPC_MPIC_H
3 #ifdef __KERNEL__
4
5 #include <linux/irq.h>
6 #include <linux/sysdev.h>
7 #include <asm/dcr.h>
8
9 /*
10  * Global registers
11  */
12
13 #define MPIC_GREG_BASE                  0x01000
14
15 #define MPIC_GREG_FEATURE_0             0x00000
16 #define         MPIC_GREG_FEATURE_LAST_SRC_MASK         0x07ff0000
17 #define         MPIC_GREG_FEATURE_LAST_SRC_SHIFT        16
18 #define         MPIC_GREG_FEATURE_LAST_CPU_MASK         0x00001f00
19 #define         MPIC_GREG_FEATURE_LAST_CPU_SHIFT        8
20 #define         MPIC_GREG_FEATURE_VERSION_MASK          0xff
21 #define MPIC_GREG_FEATURE_1             0x00010
22 #define MPIC_GREG_GLOBAL_CONF_0         0x00020
23 #define         MPIC_GREG_GCONF_RESET                   0x80000000
24 #define         MPIC_GREG_GCONF_8259_PTHROU_DIS         0x20000000
25 #define         MPIC_GREG_GCONF_BASE_MASK               0x000fffff
26 #define         MPIC_GREG_GCONF_MCK                     0x08000000
27 #define MPIC_GREG_GLOBAL_CONF_1         0x00030
28 #define         MPIC_GREG_GLOBAL_CONF_1_SIE             0x08000000
29 #define         MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO_MASK  0x70000000
30 #define         MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO(r)    \
31                         (((r) << 28) & MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO_MASK)
32 #define MPIC_GREG_VENDOR_0              0x00040
33 #define MPIC_GREG_VENDOR_1              0x00050
34 #define MPIC_GREG_VENDOR_2              0x00060
35 #define MPIC_GREG_VENDOR_3              0x00070
36 #define MPIC_GREG_VENDOR_ID             0x00080
37 #define         MPIC_GREG_VENDOR_ID_STEPPING_MASK       0x00ff0000
38 #define         MPIC_GREG_VENDOR_ID_STEPPING_SHIFT      16
39 #define         MPIC_GREG_VENDOR_ID_DEVICE_ID_MASK      0x0000ff00
40 #define         MPIC_GREG_VENDOR_ID_DEVICE_ID_SHIFT     8
41 #define         MPIC_GREG_VENDOR_ID_VENDOR_ID_MASK      0x000000ff
42 #define MPIC_GREG_PROCESSOR_INIT        0x00090
43 #define MPIC_GREG_IPI_VECTOR_PRI_0      0x000a0
44 #define MPIC_GREG_IPI_VECTOR_PRI_1      0x000b0
45 #define MPIC_GREG_IPI_VECTOR_PRI_2      0x000c0
46 #define MPIC_GREG_IPI_VECTOR_PRI_3      0x000d0
47 #define MPIC_GREG_IPI_STRIDE            0x10
48 #define MPIC_GREG_SPURIOUS              0x000e0
49 #define MPIC_GREG_TIMER_FREQ            0x000f0
50
51 /*
52  *
53  * Timer registers
54  */
55 #define MPIC_TIMER_BASE                 0x01100
56 #define MPIC_TIMER_STRIDE               0x40
57
58 #define MPIC_TIMER_CURRENT_CNT          0x00000
59 #define MPIC_TIMER_BASE_CNT             0x00010
60 #define MPIC_TIMER_VECTOR_PRI           0x00020
61 #define MPIC_TIMER_DESTINATION          0x00030
62
63 /*
64  * Per-Processor registers
65  */
66
67 #define MPIC_CPU_THISBASE               0x00000
68 #define MPIC_CPU_BASE                   0x20000
69 #define MPIC_CPU_STRIDE                 0x01000
70
71 #define MPIC_CPU_IPI_DISPATCH_0         0x00040
72 #define MPIC_CPU_IPI_DISPATCH_1         0x00050
73 #define MPIC_CPU_IPI_DISPATCH_2         0x00060
74 #define MPIC_CPU_IPI_DISPATCH_3         0x00070
75 #define MPIC_CPU_IPI_DISPATCH_STRIDE    0x00010
76 #define MPIC_CPU_CURRENT_TASK_PRI       0x00080
77 #define         MPIC_CPU_TASKPRI_MASK                   0x0000000f
78 #define MPIC_CPU_WHOAMI                 0x00090
79 #define         MPIC_CPU_WHOAMI_MASK                    0x0000001f
80 #define MPIC_CPU_INTACK                 0x000a0
81 #define MPIC_CPU_EOI                    0x000b0
82 #define MPIC_CPU_MCACK                  0x000c0
83
84 /*
85  * Per-source registers
86  */
87
88 #define MPIC_IRQ_BASE                   0x10000
89 #define MPIC_IRQ_STRIDE                 0x00020
90 #define MPIC_IRQ_VECTOR_PRI             0x00000
91 #define         MPIC_VECPRI_MASK                        0x80000000
92 #define         MPIC_VECPRI_ACTIVITY                    0x40000000      /* Read Only */
93 #define         MPIC_VECPRI_PRIORITY_MASK               0x000f0000
94 #define         MPIC_VECPRI_PRIORITY_SHIFT              16
95 #define         MPIC_VECPRI_VECTOR_MASK                 0x000007ff
96 #define         MPIC_VECPRI_POLARITY_POSITIVE           0x00800000
97 #define         MPIC_VECPRI_POLARITY_NEGATIVE           0x00000000
98 #define         MPIC_VECPRI_POLARITY_MASK               0x00800000
99 #define         MPIC_VECPRI_SENSE_LEVEL                 0x00400000
100 #define         MPIC_VECPRI_SENSE_EDGE                  0x00000000
101 #define         MPIC_VECPRI_SENSE_MASK                  0x00400000
102 #define MPIC_IRQ_DESTINATION            0x00010
103
104 #define MPIC_MAX_IRQ_SOURCES    2048
105 #define MPIC_MAX_CPUS           32
106 #define MPIC_MAX_ISU            32
107
108 /*
109  * Tsi108 implementation of MPIC has many differences from the original one
110  */
111
112 /*
113  * Global registers
114  */
115
116 #define TSI108_GREG_BASE                0x00000
117 #define TSI108_GREG_FEATURE_0           0x00000
118 #define TSI108_GREG_GLOBAL_CONF_0       0x00004
119 #define TSI108_GREG_VENDOR_ID           0x0000c
120 #define TSI108_GREG_IPI_VECTOR_PRI_0    0x00204         /* Doorbell 0 */
121 #define TSI108_GREG_IPI_STRIDE          0x0c
122 #define TSI108_GREG_SPURIOUS            0x00010
123 #define TSI108_GREG_TIMER_FREQ          0x00014
124
125 /*
126  * Timer registers
127  */
128 #define TSI108_TIMER_BASE               0x0030
129 #define TSI108_TIMER_STRIDE             0x10
130 #define TSI108_TIMER_CURRENT_CNT        0x00000
131 #define TSI108_TIMER_BASE_CNT           0x00004
132 #define TSI108_TIMER_VECTOR_PRI         0x00008
133 #define TSI108_TIMER_DESTINATION        0x0000c
134
135 /*
136  * Per-Processor registers
137  */
138 #define TSI108_CPU_BASE                 0x00300
139 #define TSI108_CPU_STRIDE               0x00040
140 #define TSI108_CPU_IPI_DISPATCH_0       0x00200
141 #define TSI108_CPU_IPI_DISPATCH_STRIDE  0x00000
142 #define TSI108_CPU_CURRENT_TASK_PRI     0x00000
143 #define TSI108_CPU_WHOAMI               0xffffffff
144 #define TSI108_CPU_INTACK               0x00004
145 #define TSI108_CPU_EOI                  0x00008
146 #define TSI108_CPU_MCACK                0x00004 /* Doesn't really exist here */
147
148 /*
149  * Per-source registers
150  */
151 #define TSI108_IRQ_BASE                 0x00100
152 #define TSI108_IRQ_STRIDE               0x00008
153 #define TSI108_IRQ_VECTOR_PRI           0x00000
154 #define TSI108_VECPRI_VECTOR_MASK       0x000000ff
155 #define TSI108_VECPRI_POLARITY_POSITIVE 0x01000000
156 #define TSI108_VECPRI_POLARITY_NEGATIVE 0x00000000
157 #define TSI108_VECPRI_SENSE_LEVEL       0x02000000
158 #define TSI108_VECPRI_SENSE_EDGE        0x00000000
159 #define TSI108_VECPRI_POLARITY_MASK     0x01000000
160 #define TSI108_VECPRI_SENSE_MASK        0x02000000
161 #define TSI108_IRQ_DESTINATION          0x00004
162
163 /* weird mpic register indices and mask bits in the HW info array */
164 enum {
165         MPIC_IDX_GREG_BASE = 0,
166         MPIC_IDX_GREG_FEATURE_0,
167         MPIC_IDX_GREG_GLOBAL_CONF_0,
168         MPIC_IDX_GREG_VENDOR_ID,
169         MPIC_IDX_GREG_IPI_VECTOR_PRI_0,
170         MPIC_IDX_GREG_IPI_STRIDE,
171         MPIC_IDX_GREG_SPURIOUS,
172         MPIC_IDX_GREG_TIMER_FREQ,
173
174         MPIC_IDX_TIMER_BASE,
175         MPIC_IDX_TIMER_STRIDE,
176         MPIC_IDX_TIMER_CURRENT_CNT,
177         MPIC_IDX_TIMER_BASE_CNT,
178         MPIC_IDX_TIMER_VECTOR_PRI,
179         MPIC_IDX_TIMER_DESTINATION,
180
181         MPIC_IDX_CPU_BASE,
182         MPIC_IDX_CPU_STRIDE,
183         MPIC_IDX_CPU_IPI_DISPATCH_0,
184         MPIC_IDX_CPU_IPI_DISPATCH_STRIDE,
185         MPIC_IDX_CPU_CURRENT_TASK_PRI,
186         MPIC_IDX_CPU_WHOAMI,
187         MPIC_IDX_CPU_INTACK,
188         MPIC_IDX_CPU_EOI,
189         MPIC_IDX_CPU_MCACK,
190
191         MPIC_IDX_IRQ_BASE,
192         MPIC_IDX_IRQ_STRIDE,
193         MPIC_IDX_IRQ_VECTOR_PRI,
194
195         MPIC_IDX_VECPRI_VECTOR_MASK,
196         MPIC_IDX_VECPRI_POLARITY_POSITIVE,
197         MPIC_IDX_VECPRI_POLARITY_NEGATIVE,
198         MPIC_IDX_VECPRI_SENSE_LEVEL,
199         MPIC_IDX_VECPRI_SENSE_EDGE,
200         MPIC_IDX_VECPRI_POLARITY_MASK,
201         MPIC_IDX_VECPRI_SENSE_MASK,
202         MPIC_IDX_IRQ_DESTINATION,
203         MPIC_IDX_END
204 };
205
206
207 #ifdef CONFIG_MPIC_U3_HT_IRQS
208 /* Fixup table entry */
209 struct mpic_irq_fixup
210 {
211         u8 __iomem      *base;
212         u8 __iomem      *applebase;
213         u32             data;
214         unsigned int    index;
215 };
216 #endif /* CONFIG_MPIC_U3_HT_IRQS */
217
218
219 enum mpic_reg_type {
220         mpic_access_mmio_le,
221         mpic_access_mmio_be,
222 #ifdef CONFIG_PPC_DCR
223         mpic_access_dcr
224 #endif
225 };
226
227 struct mpic_reg_bank {
228         u32 __iomem     *base;
229 #ifdef CONFIG_PPC_DCR
230         dcr_host_t      dhost;
231 #endif /* CONFIG_PPC_DCR */
232 };
233
234 struct mpic_irq_save {
235         u32             vecprio,
236                         dest;
237 #ifdef CONFIG_MPIC_U3_HT_IRQS
238         u32             fixup_data;
239 #endif
240 };
241
242 /* The instance data of a given MPIC */
243 struct mpic
244 {
245         /* The remapper for this MPIC */
246         struct irq_host         *irqhost;
247
248         /* The "linux" controller struct */
249         struct irq_chip         hc_irq;
250 #ifdef CONFIG_MPIC_U3_HT_IRQS
251         struct irq_chip         hc_ht_irq;
252 #endif
253 #ifdef CONFIG_SMP
254         struct irq_chip         hc_ipi;
255 #endif
256         const char              *name;
257         /* Flags */
258         unsigned int            flags;
259         /* How many irq sources in a given ISU */
260         unsigned int            isu_size;
261         unsigned int            isu_shift;
262         unsigned int            isu_mask;
263         unsigned int            irq_count;
264         /* Number of sources */
265         unsigned int            num_sources;
266         /* Number of CPUs */
267         unsigned int            num_cpus;
268         /* default senses array */
269         unsigned char           *senses;
270         unsigned int            senses_count;
271
272         /* vector numbers used for internal sources (ipi/timers) */
273         unsigned int            ipi_vecs[4];
274         unsigned int            timer_vecs[4];
275
276         /* Spurious vector to program into unused sources */
277         unsigned int            spurious_vec;
278
279 #ifdef CONFIG_MPIC_U3_HT_IRQS
280         /* The fixup table */
281         struct mpic_irq_fixup   *fixups;
282         spinlock_t              fixup_lock;
283 #endif
284
285         /* Register access method */
286         enum mpic_reg_type      reg_type;
287
288         /* The various ioremap'ed bases */
289         struct mpic_reg_bank    gregs;
290         struct mpic_reg_bank    tmregs;
291         struct mpic_reg_bank    cpuregs[MPIC_MAX_CPUS];
292         struct mpic_reg_bank    isus[MPIC_MAX_ISU];
293
294         /* Protected sources */
295         unsigned long           *protected;
296
297 #ifdef CONFIG_MPIC_WEIRD
298         /* Pointer to HW info array */
299         u32                     *hw_set;
300 #endif
301
302 #ifdef CONFIG_PCI_MSI
303         spinlock_t              bitmap_lock;
304         unsigned long           *hwirq_bitmap;
305 #endif
306
307 #ifdef CONFIG_MPIC_BROKEN_REGREAD
308         u32                     isu_reg0_shadow[MPIC_MAX_IRQ_SOURCES];
309 #endif
310
311         /* link */
312         struct mpic             *next;
313
314         struct sys_device       sysdev;
315
316 #ifdef CONFIG_PM
317         struct mpic_irq_save    *save_data;
318 #endif
319 };
320
321 /*
322  * MPIC flags (passed to mpic_alloc)
323  *
324  * The top 4 bits contain an MPIC bhw id that is used to index the
325  * register offsets and some masks when CONFIG_MPIC_WEIRD is set.
326  * Note setting any ID (leaving those bits to 0) means standard MPIC
327  */
328
329 /* This is the primary controller, only that one has IPIs and
330  * has afinity control. A non-primary MPIC always uses CPU0
331  * registers only
332  */
333 #define MPIC_PRIMARY                    0x00000001
334
335 /* Set this for a big-endian MPIC */
336 #define MPIC_BIG_ENDIAN                 0x00000002
337 /* Broken U3 MPIC */
338 #define MPIC_U3_HT_IRQS                 0x00000004
339 /* Broken IPI registers (autodetected) */
340 #define MPIC_BROKEN_IPI                 0x00000008
341 /* MPIC wants a reset */
342 #define MPIC_WANTS_RESET                0x00000010
343 /* Spurious vector requires EOI */
344 #define MPIC_SPV_EOI                    0x00000020
345 /* No passthrough disable */
346 #define MPIC_NO_PTHROU_DIS              0x00000040
347 /* DCR based MPIC */
348 #define MPIC_USES_DCR                   0x00000080
349 /* MPIC has 11-bit vector fields (or larger) */
350 #define MPIC_LARGE_VECTORS              0x00000100
351 /* Enable delivery of prio 15 interrupts as MCK instead of EE */
352 #define MPIC_ENABLE_MCK                 0x00000200
353
354 /* MPIC HW modification ID */
355 #define MPIC_REGSET_MASK                0xf0000000
356 #define MPIC_REGSET(val)                (((val) & 0xf ) << 28)
357 #define MPIC_GET_REGSET(flags)          (((flags) >> 28) & 0xf)
358
359 #define MPIC_REGSET_STANDARD            MPIC_REGSET(0)  /* Original MPIC */
360 #define MPIC_REGSET_TSI108              MPIC_REGSET(1)  /* Tsi108/109 PIC */
361
362 /* Allocate the controller structure and setup the linux irq descs
363  * for the range if interrupts passed in. No HW initialization is
364  * actually performed.
365  * 
366  * @phys_addr:  physial base address of the MPIC
367  * @flags:      flags, see constants above
368  * @isu_size:   number of interrupts in an ISU. Use 0 to use a
369  *              standard ISU-less setup (aka powermac)
370  * @irq_offset: first irq number to assign to this mpic
371  * @irq_count:  number of irqs to use with this mpic IRQ sources. Pass 0
372  *              to match the number of sources
373  * @ipi_offset: first irq number to assign to this mpic IPI sources,
374  *              used only on primary mpic
375  * @senses:     array of sense values
376  * @senses_num: number of entries in the array
377  *
378  * Note about the sense array. If none is passed, all interrupts are
379  * setup to be level negative unless MPIC_U3_HT_IRQS is set in which
380  * case they are edge positive (and the array is ignored anyway).
381  * The values in the array start at the first source of the MPIC,
382  * that is senses[0] correspond to linux irq "irq_offset".
383  */
384 extern struct mpic *mpic_alloc(struct device_node *node,
385                                phys_addr_t phys_addr,
386                                unsigned int flags,
387                                unsigned int isu_size,
388                                unsigned int irq_count,
389                                const char *name);
390
391 /* Assign ISUs, to call before mpic_init()
392  *
393  * @mpic:       controller structure as returned by mpic_alloc()
394  * @isu_num:    ISU number
395  * @phys_addr:  physical address of the ISU
396  */
397 extern void mpic_assign_isu(struct mpic *mpic, unsigned int isu_num,
398                             phys_addr_t phys_addr);
399
400 /* Set default sense codes
401  *
402  * @mpic:       controller
403  * @senses:     array of sense codes
404  * @count:      size of above array
405  *
406  * Optionally provide an array (indexed on hardware interrupt numbers
407  * for this MPIC) of default sense codes for the chip. Those are linux
408  * sense codes IRQ_TYPE_*
409  *
410  * The driver gets ownership of the pointer, don't dispose of it or
411  * anything like that. __init only.
412  */
413 extern void mpic_set_default_senses(struct mpic *mpic, u8 *senses, int count);
414
415
416 /* Initialize the controller. After this has been called, none of the above
417  * should be called again for this mpic
418  */
419 extern void mpic_init(struct mpic *mpic);
420
421 /*
422  * All of the following functions must only be used after the
423  * ISUs have been assigned and the controller fully initialized
424  * with mpic_init()
425  */
426
427
428 /* Change/Read the priority of an interrupt. Default is 8 for irqs and
429  * 10 for IPIs. You can call this on both IPIs and IRQ numbers, but the
430  * IPI number is then the offset'ed (linux irq number mapped to the IPI)
431  */
432 extern void mpic_irq_set_priority(unsigned int irq, unsigned int pri);
433 extern unsigned int mpic_irq_get_priority(unsigned int irq);
434
435 /* Setup a non-boot CPU */
436 extern void mpic_setup_this_cpu(void);
437
438 /* Clean up for kexec (or cpu offline or ...) */
439 extern void mpic_teardown_this_cpu(int secondary);
440
441 /* Get the current cpu priority for this cpu (0..15) */
442 extern int mpic_cpu_get_priority(void);
443
444 /* Set the current cpu priority for this cpu */
445 extern void mpic_cpu_set_priority(int prio);
446
447 /* Request IPIs on primary mpic */
448 extern void mpic_request_ipis(void);
449
450 /* Send an IPI (non offseted number 0..3) */
451 extern void mpic_send_ipi(unsigned int ipi_no, unsigned int cpu_mask);
452
453 /* Send a message (IPI) to a given target (cpu number or MSG_*) */
454 void smp_mpic_message_pass(int target, int msg);
455
456 /* Unmask a specific virq */
457 extern void mpic_unmask_irq(unsigned int irq);
458 /* Mask a specific virq */
459 extern void mpic_mask_irq(unsigned int irq);
460 /* EOI a specific virq */
461 extern void mpic_end_irq(unsigned int irq);
462
463 /* Fetch interrupt from a given mpic */
464 extern unsigned int mpic_get_one_irq(struct mpic *mpic);
465 /* This one gets from the primary mpic */
466 extern unsigned int mpic_get_irq(void);
467 /* Fetch Machine Check interrupt from primary mpic */
468 extern unsigned int mpic_get_mcirq(void);
469
470 /* Set the EPIC clock ratio */
471 void mpic_set_clk_ratio(struct mpic *mpic, u32 clock_ratio);
472
473 /* Enable/Disable EPIC serial interrupt mode */
474 void mpic_set_serial_int(struct mpic *mpic, int enable);
475
476 #endif /* __KERNEL__ */
477 #endif  /* _ASM_POWERPC_MPIC_H */