xref: /openbmc/linux/arch/powerpc/include/asm/xics.h (revision 0b05ac6e24807f0c26f763b3a546c0bcbf84125f)
1*0b05ac6eSBenjamin Herrenschmidt /*
2*0b05ac6eSBenjamin Herrenschmidt  * Common definitions accross all variants of ICP and ICS interrupt
3*0b05ac6eSBenjamin Herrenschmidt  * controllers.
4*0b05ac6eSBenjamin Herrenschmidt  */
5*0b05ac6eSBenjamin Herrenschmidt 
6*0b05ac6eSBenjamin Herrenschmidt #ifndef _XICS_H
7*0b05ac6eSBenjamin Herrenschmidt #define _XICS_H
8*0b05ac6eSBenjamin Herrenschmidt 
9*0b05ac6eSBenjamin Herrenschmidt #define XICS_IPI		2
10*0b05ac6eSBenjamin Herrenschmidt #define XICS_IRQ_SPURIOUS	0
11*0b05ac6eSBenjamin Herrenschmidt 
12*0b05ac6eSBenjamin Herrenschmidt /* Want a priority other than 0.  Various HW issues require this. */
13*0b05ac6eSBenjamin Herrenschmidt #define	DEFAULT_PRIORITY	5
14*0b05ac6eSBenjamin Herrenschmidt 
15*0b05ac6eSBenjamin Herrenschmidt /*
16*0b05ac6eSBenjamin Herrenschmidt  * Mark IPIs as higher priority so we can take them inside interrupts that
17*0b05ac6eSBenjamin Herrenschmidt  * arent marked IRQF_DISABLED
18*0b05ac6eSBenjamin Herrenschmidt  */
19*0b05ac6eSBenjamin Herrenschmidt #define IPI_PRIORITY		4
20*0b05ac6eSBenjamin Herrenschmidt 
21*0b05ac6eSBenjamin Herrenschmidt /* The least favored priority */
22*0b05ac6eSBenjamin Herrenschmidt #define LOWEST_PRIORITY		0xFF
23*0b05ac6eSBenjamin Herrenschmidt 
24*0b05ac6eSBenjamin Herrenschmidt /* The number of priorities defined above */
25*0b05ac6eSBenjamin Herrenschmidt #define MAX_NUM_PRIORITIES	3
26*0b05ac6eSBenjamin Herrenschmidt 
27*0b05ac6eSBenjamin Herrenschmidt /* Native ICP */
28*0b05ac6eSBenjamin Herrenschmidt extern int icp_native_init(void);
29*0b05ac6eSBenjamin Herrenschmidt 
30*0b05ac6eSBenjamin Herrenschmidt /* PAPR ICP */
31*0b05ac6eSBenjamin Herrenschmidt extern int icp_hv_init(void);
32*0b05ac6eSBenjamin Herrenschmidt 
33*0b05ac6eSBenjamin Herrenschmidt /* ICP ops */
34*0b05ac6eSBenjamin Herrenschmidt struct icp_ops {
35*0b05ac6eSBenjamin Herrenschmidt 	unsigned int (*get_irq)(void);
36*0b05ac6eSBenjamin Herrenschmidt 	void (*eoi)(struct irq_data *d);
37*0b05ac6eSBenjamin Herrenschmidt 	void (*set_priority)(unsigned char prio);
38*0b05ac6eSBenjamin Herrenschmidt 	void (*teardown_cpu)(void);
39*0b05ac6eSBenjamin Herrenschmidt 	void (*flush_ipi)(void);
40*0b05ac6eSBenjamin Herrenschmidt #ifdef CONFIG_SMP
41*0b05ac6eSBenjamin Herrenschmidt 	void (*message_pass)(int target, int msg);
42*0b05ac6eSBenjamin Herrenschmidt 	irq_handler_t ipi_action;
43*0b05ac6eSBenjamin Herrenschmidt #endif
44*0b05ac6eSBenjamin Herrenschmidt };
45*0b05ac6eSBenjamin Herrenschmidt 
46*0b05ac6eSBenjamin Herrenschmidt extern const struct icp_ops *icp_ops;
47*0b05ac6eSBenjamin Herrenschmidt 
48*0b05ac6eSBenjamin Herrenschmidt /* Native ICS */
49*0b05ac6eSBenjamin Herrenschmidt extern int ics_native_init(void);
50*0b05ac6eSBenjamin Herrenschmidt 
51*0b05ac6eSBenjamin Herrenschmidt /* RTAS ICS */
52*0b05ac6eSBenjamin Herrenschmidt extern int ics_rtas_init(void);
53*0b05ac6eSBenjamin Herrenschmidt 
54*0b05ac6eSBenjamin Herrenschmidt /* ICS instance, hooked up to chip_data of an irq */
55*0b05ac6eSBenjamin Herrenschmidt struct ics {
56*0b05ac6eSBenjamin Herrenschmidt 	struct list_head link;
57*0b05ac6eSBenjamin Herrenschmidt 	int (*map)(struct ics *ics, unsigned int virq);
58*0b05ac6eSBenjamin Herrenschmidt 	void (*mask_unknown)(struct ics *ics, unsigned long vec);
59*0b05ac6eSBenjamin Herrenschmidt 	long (*get_server)(struct ics *ics, unsigned long vec);
60*0b05ac6eSBenjamin Herrenschmidt 	char data[];
61*0b05ac6eSBenjamin Herrenschmidt };
62*0b05ac6eSBenjamin Herrenschmidt 
63*0b05ac6eSBenjamin Herrenschmidt /* Commons */
64*0b05ac6eSBenjamin Herrenschmidt extern unsigned int xics_default_server;
65*0b05ac6eSBenjamin Herrenschmidt extern unsigned int xics_default_distrib_server;
66*0b05ac6eSBenjamin Herrenschmidt extern unsigned int xics_interrupt_server_size;
67*0b05ac6eSBenjamin Herrenschmidt extern struct irq_host *xics_host;
68*0b05ac6eSBenjamin Herrenschmidt 
69*0b05ac6eSBenjamin Herrenschmidt struct xics_cppr {
70*0b05ac6eSBenjamin Herrenschmidt 	unsigned char stack[MAX_NUM_PRIORITIES];
71*0b05ac6eSBenjamin Herrenschmidt 	int index;
72*0b05ac6eSBenjamin Herrenschmidt };
73*0b05ac6eSBenjamin Herrenschmidt 
74*0b05ac6eSBenjamin Herrenschmidt DECLARE_PER_CPU(struct xics_cppr, xics_cppr);
75*0b05ac6eSBenjamin Herrenschmidt 
76*0b05ac6eSBenjamin Herrenschmidt static inline void xics_push_cppr(unsigned int vec)
77*0b05ac6eSBenjamin Herrenschmidt {
78*0b05ac6eSBenjamin Herrenschmidt 	struct xics_cppr *os_cppr = &__get_cpu_var(xics_cppr);
79*0b05ac6eSBenjamin Herrenschmidt 
80*0b05ac6eSBenjamin Herrenschmidt 	if (WARN_ON(os_cppr->index >= MAX_NUM_PRIORITIES - 1))
81*0b05ac6eSBenjamin Herrenschmidt 		return;
82*0b05ac6eSBenjamin Herrenschmidt 
83*0b05ac6eSBenjamin Herrenschmidt 	if (vec == XICS_IPI)
84*0b05ac6eSBenjamin Herrenschmidt 		os_cppr->stack[++os_cppr->index] = IPI_PRIORITY;
85*0b05ac6eSBenjamin Herrenschmidt 	else
86*0b05ac6eSBenjamin Herrenschmidt 		os_cppr->stack[++os_cppr->index] = DEFAULT_PRIORITY;
87*0b05ac6eSBenjamin Herrenschmidt }
88*0b05ac6eSBenjamin Herrenschmidt 
89*0b05ac6eSBenjamin Herrenschmidt static inline unsigned char xics_pop_cppr(void)
90*0b05ac6eSBenjamin Herrenschmidt {
91*0b05ac6eSBenjamin Herrenschmidt 	struct xics_cppr *os_cppr = &__get_cpu_var(xics_cppr);
92*0b05ac6eSBenjamin Herrenschmidt 
93*0b05ac6eSBenjamin Herrenschmidt 	if (WARN_ON(os_cppr->index < 1))
94*0b05ac6eSBenjamin Herrenschmidt 		return LOWEST_PRIORITY;
95*0b05ac6eSBenjamin Herrenschmidt 
96*0b05ac6eSBenjamin Herrenschmidt 	return os_cppr->stack[--os_cppr->index];
97*0b05ac6eSBenjamin Herrenschmidt }
98*0b05ac6eSBenjamin Herrenschmidt 
99*0b05ac6eSBenjamin Herrenschmidt static inline void xics_set_base_cppr(unsigned char cppr)
100*0b05ac6eSBenjamin Herrenschmidt {
101*0b05ac6eSBenjamin Herrenschmidt 	struct xics_cppr *os_cppr = &__get_cpu_var(xics_cppr);
102*0b05ac6eSBenjamin Herrenschmidt 
103*0b05ac6eSBenjamin Herrenschmidt 	/* we only really want to set the priority when there's
104*0b05ac6eSBenjamin Herrenschmidt 	 * just one cppr value on the stack
105*0b05ac6eSBenjamin Herrenschmidt 	 */
106*0b05ac6eSBenjamin Herrenschmidt 	WARN_ON(os_cppr->index != 0);
107*0b05ac6eSBenjamin Herrenschmidt 
108*0b05ac6eSBenjamin Herrenschmidt 	os_cppr->stack[0] = cppr;
109*0b05ac6eSBenjamin Herrenschmidt }
110*0b05ac6eSBenjamin Herrenschmidt 
111*0b05ac6eSBenjamin Herrenschmidt static inline unsigned char xics_cppr_top(void)
112*0b05ac6eSBenjamin Herrenschmidt {
113*0b05ac6eSBenjamin Herrenschmidt 	struct xics_cppr *os_cppr = &__get_cpu_var(xics_cppr);
114*0b05ac6eSBenjamin Herrenschmidt 
115*0b05ac6eSBenjamin Herrenschmidt 	return os_cppr->stack[os_cppr->index];
116*0b05ac6eSBenjamin Herrenschmidt }
117*0b05ac6eSBenjamin Herrenschmidt 
118*0b05ac6eSBenjamin Herrenschmidt DECLARE_PER_CPU_SHARED_ALIGNED(unsigned long, xics_ipi_message);
119*0b05ac6eSBenjamin Herrenschmidt 
120*0b05ac6eSBenjamin Herrenschmidt extern void xics_init(void);
121*0b05ac6eSBenjamin Herrenschmidt extern void xics_setup_cpu(void);
122*0b05ac6eSBenjamin Herrenschmidt extern void xics_update_irq_servers(void);
123*0b05ac6eSBenjamin Herrenschmidt extern void xics_set_cpu_giq(unsigned int gserver, unsigned int join);
124*0b05ac6eSBenjamin Herrenschmidt extern void xics_mask_unknown_vec(unsigned int vec);
125*0b05ac6eSBenjamin Herrenschmidt extern irqreturn_t xics_ipi_dispatch(int cpu);
126*0b05ac6eSBenjamin Herrenschmidt extern int xics_smp_probe(void);
127*0b05ac6eSBenjamin Herrenschmidt extern void xics_register_ics(struct ics *ics);
128*0b05ac6eSBenjamin Herrenschmidt extern void xics_teardown_cpu(void);
129*0b05ac6eSBenjamin Herrenschmidt extern void xics_kexec_teardown_cpu(int secondary);
130*0b05ac6eSBenjamin Herrenschmidt extern void xics_migrate_irqs_away(void);
131*0b05ac6eSBenjamin Herrenschmidt #ifdef CONFIG_SMP
132*0b05ac6eSBenjamin Herrenschmidt extern int xics_get_irq_server(unsigned int virq, const struct cpumask *cpumask,
133*0b05ac6eSBenjamin Herrenschmidt 			       unsigned int strict_check);
134*0b05ac6eSBenjamin Herrenschmidt #else
135*0b05ac6eSBenjamin Herrenschmidt #define xics_get_irq_server(virq, cpumask, strict_check) (xics_default_server)
136*0b05ac6eSBenjamin Herrenschmidt #endif
137*0b05ac6eSBenjamin Herrenschmidt 
138*0b05ac6eSBenjamin Herrenschmidt 
139*0b05ac6eSBenjamin Herrenschmidt #endif /* _XICS_H */
140