xref: /openbmc/linux/arch/powerpc/platforms/ps3/interrupt.c (revision 83bb643d0714b0006ab99dbd195ec51b55a97f4e)
12832a81dSGeoff Levand /*
22832a81dSGeoff Levand  *  PS3 interrupt routines.
32832a81dSGeoff Levand  *
42832a81dSGeoff Levand  *  Copyright (C) 2006 Sony Computer Entertainment Inc.
52832a81dSGeoff Levand  *  Copyright 2006 Sony Corp.
62832a81dSGeoff Levand  *
72832a81dSGeoff Levand  *  This program is free software; you can redistribute it and/or modify
82832a81dSGeoff Levand  *  it under the terms of the GNU General Public License as published by
92832a81dSGeoff Levand  *  the Free Software Foundation; version 2 of the License.
102832a81dSGeoff Levand  *
112832a81dSGeoff Levand  *  This program is distributed in the hope that it will be useful,
122832a81dSGeoff Levand  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
132832a81dSGeoff Levand  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
142832a81dSGeoff Levand  *  GNU General Public License for more details.
152832a81dSGeoff Levand  *
162832a81dSGeoff Levand  *  You should have received a copy of the GNU General Public License
172832a81dSGeoff Levand  *  along with this program; if not, write to the Free Software
182832a81dSGeoff Levand  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
192832a81dSGeoff Levand  */
202832a81dSGeoff Levand 
212832a81dSGeoff Levand #include <linux/kernel.h>
222832a81dSGeoff Levand #include <linux/module.h>
232832a81dSGeoff Levand #include <linux/irq.h>
242832a81dSGeoff Levand 
252832a81dSGeoff Levand #include <asm/machdep.h>
262832a81dSGeoff Levand #include <asm/udbg.h>
272832a81dSGeoff Levand #include <asm/lv1call.h>
2842d284bcSStephen Rothwell #include <asm/smp.h>
292832a81dSGeoff Levand 
302832a81dSGeoff Levand #include "platform.h"
312832a81dSGeoff Levand 
322832a81dSGeoff Levand #if defined(DEBUG)
33*83bb643dSGeert Uytterhoeven #define DBG udbg_printf
342832a81dSGeoff Levand #else
35*83bb643dSGeert Uytterhoeven #define DBG pr_debug
362832a81dSGeoff Levand #endif
372832a81dSGeoff Levand 
382832a81dSGeoff Levand /**
39861be32cSGeoff Levand  * struct ps3_bmp - a per cpu irq status and mask bitmap structure
40861be32cSGeoff Levand  * @status: 256 bit status bitmap indexed by plug
41861be32cSGeoff Levand  * @unused_1:
42861be32cSGeoff Levand  * @mask: 256 bit mask bitmap indexed by plug
43861be32cSGeoff Levand  * @unused_2:
44861be32cSGeoff Levand  * @lock:
45861be32cSGeoff Levand  * @ipi_debug_brk_mask:
46861be32cSGeoff Levand  *
47861be32cSGeoff Levand  * The HV mantains per SMT thread mappings of HV outlet to HV plug on
48861be32cSGeoff Levand  * behalf of the guest.  These mappings are implemented as 256 bit guest
49861be32cSGeoff Levand  * supplied bitmaps indexed by plug number.  The addresses of the bitmaps
50861be32cSGeoff Levand  * are registered with the HV through lv1_configure_irq_state_bitmap().
5157715765SGeoff Levand  * The HV requires that the 512 bits of status + mask not cross a page
5257715765SGeoff Levand  * boundary.  PS3_BMP_MINALIGN is used to define this minimal 64 byte
5357715765SGeoff Levand  * alignment.
54861be32cSGeoff Levand  *
55861be32cSGeoff Levand  * The HV supports 256 plugs per thread, assigned as {0..255}, for a total
56861be32cSGeoff Levand  * of 512 plugs supported on a processor.  To simplify the logic this
57861be32cSGeoff Levand  * implementation equates HV plug value to Linux virq value, constrains each
58861be32cSGeoff Levand  * interrupt to have a system wide unique plug number, and limits the range
59861be32cSGeoff Levand  * of the plug values to map into the first dword of the bitmaps.  This
60861be32cSGeoff Levand  * gives a usable range of plug values of  {NUM_ISA_INTERRUPTS..63}.  Note
61861be32cSGeoff Levand  * that there is no constraint on how many in this set an individual thread
62861be32cSGeoff Levand  * can acquire.
63861be32cSGeoff Levand  */
64861be32cSGeoff Levand 
6557715765SGeoff Levand #define PS3_BMP_MINALIGN 64
6657715765SGeoff Levand 
67861be32cSGeoff Levand struct ps3_bmp {
68861be32cSGeoff Levand 	struct {
69861be32cSGeoff Levand 		u64 status;
70861be32cSGeoff Levand 		u64 unused_1[3];
71861be32cSGeoff Levand 		u64 mask;
72861be32cSGeoff Levand 		u64 unused_2[3];
73861be32cSGeoff Levand 	};
74861be32cSGeoff Levand 	u64 ipi_debug_brk_mask;
75861be32cSGeoff Levand 	spinlock_t lock;
76861be32cSGeoff Levand };
77861be32cSGeoff Levand 
78861be32cSGeoff Levand /**
79861be32cSGeoff Levand  * struct ps3_private - a per cpu data structure
80861be32cSGeoff Levand  * @bmp: ps3_bmp structure
81861be32cSGeoff Levand  * @node: HV logical_ppe_id
82861be32cSGeoff Levand  * @cpu: HV thread_id
83861be32cSGeoff Levand  */
84861be32cSGeoff Levand 
85861be32cSGeoff Levand struct ps3_private {
8657715765SGeoff Levand 	struct ps3_bmp bmp __attribute__ ((aligned (PS3_BMP_MINALIGN)));
87861be32cSGeoff Levand 	u64 node;
88861be32cSGeoff Levand 	unsigned int cpu;
89861be32cSGeoff Levand };
90861be32cSGeoff Levand 
91861be32cSGeoff Levand static DEFINE_PER_CPU(struct ps3_private, ps3_private);
92861be32cSGeoff Levand 
93dc4f60c2SGeoff Levand /**
94743c1bb0SGeoff Levand  * ps3_chip_mask - Set an interrupt mask bit in ps3_bmp.
95743c1bb0SGeoff Levand  * @virq: The assigned Linux virq.
96743c1bb0SGeoff Levand  *
97743c1bb0SGeoff Levand  * Sets ps3_bmp.mask and calls lv1_did_update_interrupt_mask().
98743c1bb0SGeoff Levand  */
99743c1bb0SGeoff Levand 
100743c1bb0SGeoff Levand static void ps3_chip_mask(unsigned int virq)
101743c1bb0SGeoff Levand {
102743c1bb0SGeoff Levand 	struct ps3_private *pd = get_irq_chip_data(virq);
103743c1bb0SGeoff Levand 	u64 bit = 0x8000000000000000UL >> virq;
104743c1bb0SGeoff Levand 	u64 *p = &pd->bmp.mask;
105743c1bb0SGeoff Levand 	u64 old;
106743c1bb0SGeoff Levand 	unsigned long flags;
107743c1bb0SGeoff Levand 
108743c1bb0SGeoff Levand 	pr_debug("%s:%d: cpu %u, virq %d\n", __func__, __LINE__, pd->cpu, virq);
109743c1bb0SGeoff Levand 
110743c1bb0SGeoff Levand 	local_irq_save(flags);
111743c1bb0SGeoff Levand 	asm volatile(
112743c1bb0SGeoff Levand 		     "1:	ldarx %0,0,%3\n"
113743c1bb0SGeoff Levand 		     "andc	%0,%0,%2\n"
114743c1bb0SGeoff Levand 		     "stdcx.	%0,0,%3\n"
115743c1bb0SGeoff Levand 		     "bne-	1b"
116743c1bb0SGeoff Levand 		     : "=&r" (old), "+m" (*p)
117743c1bb0SGeoff Levand 		     : "r" (bit), "r" (p)
118743c1bb0SGeoff Levand 		     : "cc" );
119743c1bb0SGeoff Levand 
120743c1bb0SGeoff Levand 	lv1_did_update_interrupt_mask(pd->node, pd->cpu);
121743c1bb0SGeoff Levand 	local_irq_restore(flags);
122743c1bb0SGeoff Levand }
123743c1bb0SGeoff Levand 
124743c1bb0SGeoff Levand /**
125743c1bb0SGeoff Levand  * ps3_chip_unmask - Clear an interrupt mask bit in ps3_bmp.
126743c1bb0SGeoff Levand  * @virq: The assigned Linux virq.
127743c1bb0SGeoff Levand  *
128743c1bb0SGeoff Levand  * Clears ps3_bmp.mask and calls lv1_did_update_interrupt_mask().
129743c1bb0SGeoff Levand  */
130743c1bb0SGeoff Levand 
131743c1bb0SGeoff Levand static void ps3_chip_unmask(unsigned int virq)
132743c1bb0SGeoff Levand {
133743c1bb0SGeoff Levand 	struct ps3_private *pd = get_irq_chip_data(virq);
134743c1bb0SGeoff Levand 	u64 bit = 0x8000000000000000UL >> virq;
135743c1bb0SGeoff Levand 	u64 *p = &pd->bmp.mask;
136743c1bb0SGeoff Levand 	u64 old;
137743c1bb0SGeoff Levand 	unsigned long flags;
138743c1bb0SGeoff Levand 
139743c1bb0SGeoff Levand 	pr_debug("%s:%d: cpu %u, virq %d\n", __func__, __LINE__, pd->cpu, virq);
140743c1bb0SGeoff Levand 
141743c1bb0SGeoff Levand 	local_irq_save(flags);
142743c1bb0SGeoff Levand 	asm volatile(
143743c1bb0SGeoff Levand 		     "1:	ldarx %0,0,%3\n"
144743c1bb0SGeoff Levand 		     "or	%0,%0,%2\n"
145743c1bb0SGeoff Levand 		     "stdcx.	%0,0,%3\n"
146743c1bb0SGeoff Levand 		     "bne-	1b"
147743c1bb0SGeoff Levand 		     : "=&r" (old), "+m" (*p)
148743c1bb0SGeoff Levand 		     : "r" (bit), "r" (p)
149743c1bb0SGeoff Levand 		     : "cc" );
150743c1bb0SGeoff Levand 
151743c1bb0SGeoff Levand 	lv1_did_update_interrupt_mask(pd->node, pd->cpu);
152743c1bb0SGeoff Levand 	local_irq_restore(flags);
153743c1bb0SGeoff Levand }
154743c1bb0SGeoff Levand 
155743c1bb0SGeoff Levand /**
156743c1bb0SGeoff Levand  * ps3_chip_eoi - HV end-of-interrupt.
157743c1bb0SGeoff Levand  * @virq: The assigned Linux virq.
158743c1bb0SGeoff Levand  *
159743c1bb0SGeoff Levand  * Calls lv1_end_of_interrupt_ext().
160743c1bb0SGeoff Levand  */
161743c1bb0SGeoff Levand 
162743c1bb0SGeoff Levand static void ps3_chip_eoi(unsigned int virq)
163743c1bb0SGeoff Levand {
164743c1bb0SGeoff Levand 	const struct ps3_private *pd = get_irq_chip_data(virq);
165743c1bb0SGeoff Levand 	lv1_end_of_interrupt_ext(pd->node, pd->cpu, virq);
166743c1bb0SGeoff Levand }
167743c1bb0SGeoff Levand 
168743c1bb0SGeoff Levand /**
169743c1bb0SGeoff Levand  * ps3_irq_chip - Represents the ps3_bmp as a Linux struct irq_chip.
170743c1bb0SGeoff Levand  */
171743c1bb0SGeoff Levand 
172743c1bb0SGeoff Levand static struct irq_chip ps3_irq_chip = {
173743c1bb0SGeoff Levand 	.typename = "ps3",
174743c1bb0SGeoff Levand 	.mask = ps3_chip_mask,
175743c1bb0SGeoff Levand 	.unmask = ps3_chip_unmask,
176743c1bb0SGeoff Levand 	.eoi = ps3_chip_eoi,
177743c1bb0SGeoff Levand };
178743c1bb0SGeoff Levand 
179743c1bb0SGeoff Levand /**
180dc4f60c2SGeoff Levand  * ps3_virq_setup - virq related setup.
181dc4f60c2SGeoff Levand  * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
182dc4f60c2SGeoff Levand  * serviced on.
183dc4f60c2SGeoff Levand  * @outlet: The HV outlet from the various create outlet routines.
184dc4f60c2SGeoff Levand  * @virq: The assigned Linux virq.
185dc4f60c2SGeoff Levand  *
186dc4f60c2SGeoff Levand  * Calls irq_create_mapping() to get a virq and sets the chip data to
187dc4f60c2SGeoff Levand  * ps3_private data.
188dc4f60c2SGeoff Levand  */
189dc4f60c2SGeoff Levand 
190dc4f60c2SGeoff Levand int ps3_virq_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
191861be32cSGeoff Levand 	unsigned int *virq)
192861be32cSGeoff Levand {
193861be32cSGeoff Levand 	int result;
194861be32cSGeoff Levand 	struct ps3_private *pd;
195861be32cSGeoff Levand 
196861be32cSGeoff Levand 	/* This defines the default interrupt distribution policy. */
197861be32cSGeoff Levand 
198861be32cSGeoff Levand 	if (cpu == PS3_BINDING_CPU_ANY)
199861be32cSGeoff Levand 		cpu = 0;
200861be32cSGeoff Levand 
201861be32cSGeoff Levand 	pd = &per_cpu(ps3_private, cpu);
202861be32cSGeoff Levand 
203861be32cSGeoff Levand 	*virq = irq_create_mapping(NULL, outlet);
204861be32cSGeoff Levand 
205861be32cSGeoff Levand 	if (*virq == NO_IRQ) {
206861be32cSGeoff Levand 		pr_debug("%s:%d: irq_create_mapping failed: outlet %lu\n",
207861be32cSGeoff Levand 			__func__, __LINE__, outlet);
208861be32cSGeoff Levand 		result = -ENOMEM;
209861be32cSGeoff Levand 		goto fail_create;
210861be32cSGeoff Levand 	}
211861be32cSGeoff Levand 
212861be32cSGeoff Levand 	pr_debug("%s:%d: outlet %lu => cpu %u, virq %u\n", __func__, __LINE__,
213861be32cSGeoff Levand 		outlet, cpu, *virq);
214861be32cSGeoff Levand 
215861be32cSGeoff Levand 	result = set_irq_chip_data(*virq, pd);
216861be32cSGeoff Levand 
217861be32cSGeoff Levand 	if (result) {
218861be32cSGeoff Levand 		pr_debug("%s:%d: set_irq_chip_data failed\n",
219861be32cSGeoff Levand 			__func__, __LINE__);
220861be32cSGeoff Levand 		goto fail_set;
221861be32cSGeoff Levand 	}
222861be32cSGeoff Levand 
223861be32cSGeoff Levand 	return result;
224861be32cSGeoff Levand 
225861be32cSGeoff Levand fail_set:
226861be32cSGeoff Levand 	irq_dispose_mapping(*virq);
227861be32cSGeoff Levand fail_create:
228861be32cSGeoff Levand 	return result;
229861be32cSGeoff Levand }
230861be32cSGeoff Levand 
231dc4f60c2SGeoff Levand /**
232dc4f60c2SGeoff Levand  * ps3_virq_destroy - virq related teardown.
233dc4f60c2SGeoff Levand  * @virq: The assigned Linux virq.
234dc4f60c2SGeoff Levand  *
235dc4f60c2SGeoff Levand  * Clears chip data and calls irq_dispose_mapping() for the virq.
236dc4f60c2SGeoff Levand  */
237dc4f60c2SGeoff Levand 
238dc4f60c2SGeoff Levand int ps3_virq_destroy(unsigned int virq)
239dc4f60c2SGeoff Levand {
240dc4f60c2SGeoff Levand 	const struct ps3_private *pd = get_irq_chip_data(virq);
241dc4f60c2SGeoff Levand 
242dc4f60c2SGeoff Levand 	pr_debug("%s:%d: node %lu, cpu %d, virq %u\n", __func__, __LINE__,
243dc4f60c2SGeoff Levand 		pd->node, pd->cpu, virq);
244dc4f60c2SGeoff Levand 
245dc4f60c2SGeoff Levand 	set_irq_chip_data(virq, NULL);
246dc4f60c2SGeoff Levand 	irq_dispose_mapping(virq);
247dc4f60c2SGeoff Levand 
248dc4f60c2SGeoff Levand 	pr_debug("%s:%d <-\n", __func__, __LINE__);
249dc4f60c2SGeoff Levand 	return 0;
250dc4f60c2SGeoff Levand }
251dc4f60c2SGeoff Levand 
252dc4f60c2SGeoff Levand /**
253dc4f60c2SGeoff Levand  * ps3_irq_plug_setup - Generic outlet and virq related setup.
254dc4f60c2SGeoff Levand  * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
255dc4f60c2SGeoff Levand  * serviced on.
256dc4f60c2SGeoff Levand  * @outlet: The HV outlet from the various create outlet routines.
257dc4f60c2SGeoff Levand  * @virq: The assigned Linux virq.
258dc4f60c2SGeoff Levand  *
259dc4f60c2SGeoff Levand  * Sets up virq and connects the irq plug.
260dc4f60c2SGeoff Levand  */
261dc4f60c2SGeoff Levand 
262dc4f60c2SGeoff Levand int ps3_irq_plug_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
263dc4f60c2SGeoff Levand 	unsigned int *virq)
264dc4f60c2SGeoff Levand {
265dc4f60c2SGeoff Levand 	int result;
266dc4f60c2SGeoff Levand 	struct ps3_private *pd;
267dc4f60c2SGeoff Levand 
268dc4f60c2SGeoff Levand 	result = ps3_virq_setup(cpu, outlet, virq);
269dc4f60c2SGeoff Levand 
270dc4f60c2SGeoff Levand 	if (result) {
271dc4f60c2SGeoff Levand 		pr_debug("%s:%d: ps3_virq_setup failed\n", __func__, __LINE__);
272dc4f60c2SGeoff Levand 		goto fail_setup;
273dc4f60c2SGeoff Levand 	}
274dc4f60c2SGeoff Levand 
275dc4f60c2SGeoff Levand 	pd = get_irq_chip_data(*virq);
276dc4f60c2SGeoff Levand 
277dc4f60c2SGeoff Levand 	/* Binds outlet to cpu + virq. */
278dc4f60c2SGeoff Levand 
279dc4f60c2SGeoff Levand 	result = lv1_connect_irq_plug_ext(pd->node, pd->cpu, *virq, outlet, 0);
280dc4f60c2SGeoff Levand 
281dc4f60c2SGeoff Levand 	if (result) {
282dc4f60c2SGeoff Levand 		pr_info("%s:%d: lv1_connect_irq_plug_ext failed: %s\n",
283dc4f60c2SGeoff Levand 		__func__, __LINE__, ps3_result(result));
284dc4f60c2SGeoff Levand 		result = -EPERM;
285dc4f60c2SGeoff Levand 		goto fail_connect;
286dc4f60c2SGeoff Levand 	}
287dc4f60c2SGeoff Levand 
288dc4f60c2SGeoff Levand 	return result;
289dc4f60c2SGeoff Levand 
290dc4f60c2SGeoff Levand fail_connect:
291dc4f60c2SGeoff Levand 	ps3_virq_destroy(*virq);
292dc4f60c2SGeoff Levand fail_setup:
293dc4f60c2SGeoff Levand 	return result;
294dc4f60c2SGeoff Levand }
295dc4f60c2SGeoff Levand EXPORT_SYMBOL_GPL(ps3_irq_plug_setup);
296dc4f60c2SGeoff Levand 
297dc4f60c2SGeoff Levand /**
298dc4f60c2SGeoff Levand  * ps3_irq_plug_destroy - Generic outlet and virq related teardown.
299dc4f60c2SGeoff Levand  * @virq: The assigned Linux virq.
300dc4f60c2SGeoff Levand  *
301dc4f60c2SGeoff Levand  * Disconnects the irq plug and tears down virq.
302dc4f60c2SGeoff Levand  * Do not call for system bus event interrupts setup with
303dc4f60c2SGeoff Levand  * ps3_sb_event_receive_port_setup().
304dc4f60c2SGeoff Levand  */
305dc4f60c2SGeoff Levand 
306dc4f60c2SGeoff Levand int ps3_irq_plug_destroy(unsigned int virq)
307861be32cSGeoff Levand {
308861be32cSGeoff Levand 	int result;
309861be32cSGeoff Levand 	const struct ps3_private *pd = get_irq_chip_data(virq);
310861be32cSGeoff Levand 
311861be32cSGeoff Levand 	pr_debug("%s:%d: node %lu, cpu %d, virq %u\n", __func__, __LINE__,
312861be32cSGeoff Levand 		pd->node, pd->cpu, virq);
313861be32cSGeoff Levand 
314861be32cSGeoff Levand 	result = lv1_disconnect_irq_plug_ext(pd->node, pd->cpu, virq);
315861be32cSGeoff Levand 
316861be32cSGeoff Levand 	if (result)
317861be32cSGeoff Levand 		pr_info("%s:%d: lv1_disconnect_irq_plug_ext failed: %s\n",
318861be32cSGeoff Levand 		__func__, __LINE__, ps3_result(result));
319861be32cSGeoff Levand 
320dc4f60c2SGeoff Levand 	ps3_virq_destroy(virq);
321dc4f60c2SGeoff Levand 
322b1eeb38eSGeert Uytterhoeven 	return result;
323861be32cSGeoff Levand }
324dc4f60c2SGeoff Levand EXPORT_SYMBOL_GPL(ps3_irq_plug_destroy);
325861be32cSGeoff Levand 
326861be32cSGeoff Levand /**
327dc4f60c2SGeoff Levand  * ps3_event_receive_port_setup - Setup an event receive port.
328861be32cSGeoff Levand  * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
329861be32cSGeoff Levand  * serviced on.
3302832a81dSGeoff Levand  * @virq: The assigned Linux virq.
3312832a81dSGeoff Levand  *
3322832a81dSGeoff Levand  * The virq can be used with lv1_connect_interrupt_event_receive_port() to
333dc4f60c2SGeoff Levand  * arrange to receive interrupts from system-bus devices, or with
334dc4f60c2SGeoff Levand  * ps3_send_event_locally() to signal events.
3352832a81dSGeoff Levand  */
3362832a81dSGeoff Levand 
337dc4f60c2SGeoff Levand int ps3_event_receive_port_setup(enum ps3_cpu_binding cpu, unsigned int *virq)
3382832a81dSGeoff Levand {
3392832a81dSGeoff Levand 	int result;
3402832a81dSGeoff Levand 	unsigned long outlet;
3412832a81dSGeoff Levand 
3422832a81dSGeoff Levand 	result = lv1_construct_event_receive_port(&outlet);
3432832a81dSGeoff Levand 
3442832a81dSGeoff Levand 	if (result) {
3452832a81dSGeoff Levand 		pr_debug("%s:%d: lv1_construct_event_receive_port failed: %s\n",
3462832a81dSGeoff Levand 			__func__, __LINE__, ps3_result(result));
3472832a81dSGeoff Levand 		*virq = NO_IRQ;
3482832a81dSGeoff Levand 		return result;
3492832a81dSGeoff Levand 	}
3502832a81dSGeoff Levand 
351dc4f60c2SGeoff Levand 	result = ps3_irq_plug_setup(cpu, outlet, virq);
352861be32cSGeoff Levand 	BUG_ON(result);
3532832a81dSGeoff Levand 
354861be32cSGeoff Levand 	return result;
3552832a81dSGeoff Levand }
356dc4f60c2SGeoff Levand EXPORT_SYMBOL_GPL(ps3_event_receive_port_setup);
3572832a81dSGeoff Levand 
358dc4f60c2SGeoff Levand /**
359dc4f60c2SGeoff Levand  * ps3_event_receive_port_destroy - Destroy an event receive port.
360dc4f60c2SGeoff Levand  * @virq: The assigned Linux virq.
361dc4f60c2SGeoff Levand  *
362dc4f60c2SGeoff Levand  * Since ps3_event_receive_port_destroy destroys the receive port outlet,
363dc4f60c2SGeoff Levand  * SB devices need to call disconnect_interrupt_event_receive_port() before
364dc4f60c2SGeoff Levand  * this.
365dc4f60c2SGeoff Levand  */
366dc4f60c2SGeoff Levand 
367dc4f60c2SGeoff Levand int ps3_event_receive_port_destroy(unsigned int virq)
3682832a81dSGeoff Levand {
3692832a81dSGeoff Levand 	int result;
3702832a81dSGeoff Levand 
371dc4f60c2SGeoff Levand 	pr_debug(" -> %s:%d virq: %u\n", __func__, __LINE__, virq);
3722832a81dSGeoff Levand 
3732832a81dSGeoff Levand 	result = lv1_destruct_event_receive_port(virq_to_hw(virq));
3742832a81dSGeoff Levand 
3752832a81dSGeoff Levand 	if (result)
3762832a81dSGeoff Levand 		pr_debug("%s:%d: lv1_destruct_event_receive_port failed: %s\n",
3772832a81dSGeoff Levand 			__func__, __LINE__, ps3_result(result));
3782832a81dSGeoff Levand 
379dc4f60c2SGeoff Levand 	/* lv1_destruct_event_receive_port() destroys the IRQ plug,
380dc4f60c2SGeoff Levand 	 * so don't call ps3_irq_plug_destroy() here.
381dc4f60c2SGeoff Levand 	 */
382dc4f60c2SGeoff Levand 
383dc4f60c2SGeoff Levand 	result = ps3_virq_destroy(virq);
384dc4f60c2SGeoff Levand 	BUG_ON(result);
3852832a81dSGeoff Levand 
3862832a81dSGeoff Levand 	pr_debug(" <- %s:%d\n", __func__, __LINE__);
3872832a81dSGeoff Levand 	return result;
3882832a81dSGeoff Levand }
389dc4f60c2SGeoff Levand EXPORT_SYMBOL_GPL(ps3_event_receive_port_destroy);
3902832a81dSGeoff Levand 
3912832a81dSGeoff Levand int ps3_send_event_locally(unsigned int virq)
3922832a81dSGeoff Levand {
3932832a81dSGeoff Levand 	return lv1_send_event_locally(virq_to_hw(virq));
3942832a81dSGeoff Levand }
3952832a81dSGeoff Levand 
3962832a81dSGeoff Levand /**
397dc4f60c2SGeoff Levand  * ps3_sb_event_receive_port_setup - Setup a system bus event receive port.
398861be32cSGeoff Levand  * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
399861be32cSGeoff Levand  * serviced on.
4002832a81dSGeoff Levand  * @did: The HV device identifier read from the system repository.
4012832a81dSGeoff Levand  * @interrupt_id: The device interrupt id read from the system repository.
4022832a81dSGeoff Levand  * @virq: The assigned Linux virq.
4032832a81dSGeoff Levand  *
4042832a81dSGeoff Levand  * An event irq represents a virtual device interrupt.  The interrupt_id
4052832a81dSGeoff Levand  * coresponds to the software interrupt number.
4062832a81dSGeoff Levand  */
4072832a81dSGeoff Levand 
408dc4f60c2SGeoff Levand int ps3_sb_event_receive_port_setup(enum ps3_cpu_binding cpu,
409861be32cSGeoff Levand 	const struct ps3_device_id *did, unsigned int interrupt_id,
410861be32cSGeoff Levand 	unsigned int *virq)
4112832a81dSGeoff Levand {
412dc4f60c2SGeoff Levand 	/* this should go in system-bus.c */
413dc4f60c2SGeoff Levand 
4142832a81dSGeoff Levand 	int result;
4152832a81dSGeoff Levand 
416dc4f60c2SGeoff Levand 	result = ps3_event_receive_port_setup(cpu, virq);
4172832a81dSGeoff Levand 
4182832a81dSGeoff Levand 	if (result)
4192832a81dSGeoff Levand 		return result;
4202832a81dSGeoff Levand 
4212832a81dSGeoff Levand 	result = lv1_connect_interrupt_event_receive_port(did->bus_id,
4222832a81dSGeoff Levand 		did->dev_id, virq_to_hw(*virq), interrupt_id);
4232832a81dSGeoff Levand 
4242832a81dSGeoff Levand 	if (result) {
4252832a81dSGeoff Levand 		pr_debug("%s:%d: lv1_connect_interrupt_event_receive_port"
4262832a81dSGeoff Levand 			" failed: %s\n", __func__, __LINE__,
4272832a81dSGeoff Levand 			ps3_result(result));
428dc4f60c2SGeoff Levand 		ps3_event_receive_port_destroy(*virq);
4292832a81dSGeoff Levand 		*virq = NO_IRQ;
4302832a81dSGeoff Levand 		return result;
4312832a81dSGeoff Levand 	}
4322832a81dSGeoff Levand 
4332832a81dSGeoff Levand 	pr_debug("%s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__,
4342832a81dSGeoff Levand 		interrupt_id, *virq);
4352832a81dSGeoff Levand 
4362832a81dSGeoff Levand 	return 0;
4372832a81dSGeoff Levand }
438dc4f60c2SGeoff Levand EXPORT_SYMBOL(ps3_sb_event_receive_port_setup);
4392832a81dSGeoff Levand 
440dc4f60c2SGeoff Levand int ps3_sb_event_receive_port_destroy(const struct ps3_device_id *did,
4412832a81dSGeoff Levand 	unsigned int interrupt_id, unsigned int virq)
4422832a81dSGeoff Levand {
443dc4f60c2SGeoff Levand 	/* this should go in system-bus.c */
444dc4f60c2SGeoff Levand 
4452832a81dSGeoff Levand 	int result;
4462832a81dSGeoff Levand 
4472832a81dSGeoff Levand 	pr_debug(" -> %s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__,
4482832a81dSGeoff Levand 		interrupt_id, virq);
4492832a81dSGeoff Levand 
4502832a81dSGeoff Levand 	result = lv1_disconnect_interrupt_event_receive_port(did->bus_id,
4512832a81dSGeoff Levand 		did->dev_id, virq_to_hw(virq), interrupt_id);
4522832a81dSGeoff Levand 
4532832a81dSGeoff Levand 	if (result)
4542832a81dSGeoff Levand 		pr_debug("%s:%d: lv1_disconnect_interrupt_event_receive_port"
4552832a81dSGeoff Levand 			" failed: %s\n", __func__, __LINE__,
4562832a81dSGeoff Levand 			ps3_result(result));
4572832a81dSGeoff Levand 
458dc4f60c2SGeoff Levand 	result = ps3_event_receive_port_destroy(virq);
459dc4f60c2SGeoff Levand 	BUG_ON(result);
4602832a81dSGeoff Levand 
4612832a81dSGeoff Levand 	pr_debug(" <- %s:%d\n", __func__, __LINE__);
4622832a81dSGeoff Levand 	return result;
4632832a81dSGeoff Levand }
464dc4f60c2SGeoff Levand EXPORT_SYMBOL(ps3_sb_event_receive_port_destroy);
4652832a81dSGeoff Levand 
4662832a81dSGeoff Levand /**
467dc4f60c2SGeoff Levand  * ps3_io_irq_setup - Setup a system bus io irq.
468dc4f60c2SGeoff Levand  * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
469dc4f60c2SGeoff Levand  * serviced on.
470dc4f60c2SGeoff Levand  * @interrupt_id: The device interrupt id read from the system repository.
471dc4f60c2SGeoff Levand  * @virq: The assigned Linux virq.
472dc4f60c2SGeoff Levand  *
473dc4f60c2SGeoff Levand  * An io irq represents a non-virtualized device interrupt.  interrupt_id
474dc4f60c2SGeoff Levand  * coresponds to the interrupt number of the interrupt controller.
475dc4f60c2SGeoff Levand  */
476dc4f60c2SGeoff Levand 
477dc4f60c2SGeoff Levand int ps3_io_irq_setup(enum ps3_cpu_binding cpu, unsigned int interrupt_id,
478dc4f60c2SGeoff Levand 	unsigned int *virq)
479dc4f60c2SGeoff Levand {
480dc4f60c2SGeoff Levand 	int result;
481dc4f60c2SGeoff Levand 	unsigned long outlet;
482dc4f60c2SGeoff Levand 
483dc4f60c2SGeoff Levand 	result = lv1_construct_io_irq_outlet(interrupt_id, &outlet);
484dc4f60c2SGeoff Levand 
485dc4f60c2SGeoff Levand 	if (result) {
486dc4f60c2SGeoff Levand 		pr_debug("%s:%d: lv1_construct_io_irq_outlet failed: %s\n",
487dc4f60c2SGeoff Levand 			__func__, __LINE__, ps3_result(result));
488dc4f60c2SGeoff Levand 		return result;
489dc4f60c2SGeoff Levand 	}
490dc4f60c2SGeoff Levand 
491dc4f60c2SGeoff Levand 	result = ps3_irq_plug_setup(cpu, outlet, virq);
492dc4f60c2SGeoff Levand 	BUG_ON(result);
493dc4f60c2SGeoff Levand 
494dc4f60c2SGeoff Levand 	return result;
495dc4f60c2SGeoff Levand }
496dc4f60c2SGeoff Levand EXPORT_SYMBOL_GPL(ps3_io_irq_setup);
497dc4f60c2SGeoff Levand 
498dc4f60c2SGeoff Levand int ps3_io_irq_destroy(unsigned int virq)
499dc4f60c2SGeoff Levand {
500dc4f60c2SGeoff Levand 	int result;
501dc4f60c2SGeoff Levand 
502dc4f60c2SGeoff Levand 	result = lv1_destruct_io_irq_outlet(virq_to_hw(virq));
503dc4f60c2SGeoff Levand 
504dc4f60c2SGeoff Levand 	if (result)
505dc4f60c2SGeoff Levand 		pr_debug("%s:%d: lv1_destruct_io_irq_outlet failed: %s\n",
506dc4f60c2SGeoff Levand 			__func__, __LINE__, ps3_result(result));
507dc4f60c2SGeoff Levand 
508dc4f60c2SGeoff Levand 	result = ps3_irq_plug_destroy(virq);
509dc4f60c2SGeoff Levand 	BUG_ON(result);
510dc4f60c2SGeoff Levand 
511dc4f60c2SGeoff Levand 	return result;
512dc4f60c2SGeoff Levand }
513dc4f60c2SGeoff Levand EXPORT_SYMBOL_GPL(ps3_io_irq_destroy);
514dc4f60c2SGeoff Levand 
515dc4f60c2SGeoff Levand /**
516dc4f60c2SGeoff Levand  * ps3_vuart_irq_setup - Setup the system virtual uart virq.
517861be32cSGeoff Levand  * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
518861be32cSGeoff Levand  * serviced on.
5192832a81dSGeoff Levand  * @virt_addr_bmp: The caller supplied virtual uart interrupt bitmap.
5202832a81dSGeoff Levand  * @virq: The assigned Linux virq.
5212832a81dSGeoff Levand  *
5222832a81dSGeoff Levand  * The system supports only a single virtual uart, so multiple calls without
5232832a81dSGeoff Levand  * freeing the interrupt will return a wrong state error.
5242832a81dSGeoff Levand  */
5252832a81dSGeoff Levand 
526dc4f60c2SGeoff Levand int ps3_vuart_irq_setup(enum ps3_cpu_binding cpu, void* virt_addr_bmp,
527861be32cSGeoff Levand 	unsigned int *virq)
5282832a81dSGeoff Levand {
5292832a81dSGeoff Levand 	int result;
5302832a81dSGeoff Levand 	unsigned long outlet;
531861be32cSGeoff Levand 	u64 lpar_addr;
5322832a81dSGeoff Levand 
533861be32cSGeoff Levand 	BUG_ON(!is_kernel_addr((u64)virt_addr_bmp));
5342832a81dSGeoff Levand 
5352832a81dSGeoff Levand 	lpar_addr = ps3_mm_phys_to_lpar(__pa(virt_addr_bmp));
5362832a81dSGeoff Levand 
5372832a81dSGeoff Levand 	result = lv1_configure_virtual_uart_irq(lpar_addr, &outlet);
5382832a81dSGeoff Levand 
5392832a81dSGeoff Levand 	if (result) {
5402832a81dSGeoff Levand 		pr_debug("%s:%d: lv1_configure_virtual_uart_irq failed: %s\n",
5412832a81dSGeoff Levand 			__func__, __LINE__, ps3_result(result));
5422832a81dSGeoff Levand 		return result;
5432832a81dSGeoff Levand 	}
5442832a81dSGeoff Levand 
545dc4f60c2SGeoff Levand 	result = ps3_irq_plug_setup(cpu, outlet, virq);
546861be32cSGeoff Levand 	BUG_ON(result);
5472832a81dSGeoff Levand 
548861be32cSGeoff Levand 	return result;
5492832a81dSGeoff Levand }
5502832a81dSGeoff Levand 
551dc4f60c2SGeoff Levand int ps3_vuart_irq_destroy(unsigned int virq)
5522832a81dSGeoff Levand {
5532832a81dSGeoff Levand 	int result;
5542832a81dSGeoff Levand 
5552832a81dSGeoff Levand 	result = lv1_deconfigure_virtual_uart_irq();
5562832a81dSGeoff Levand 
5572832a81dSGeoff Levand 	if (result) {
5582832a81dSGeoff Levand 		pr_debug("%s:%d: lv1_configure_virtual_uart_irq failed: %s\n",
5592832a81dSGeoff Levand 			__func__, __LINE__, ps3_result(result));
5602832a81dSGeoff Levand 		return result;
5612832a81dSGeoff Levand 	}
5622832a81dSGeoff Levand 
563dc4f60c2SGeoff Levand 	result = ps3_irq_plug_destroy(virq);
564dc4f60c2SGeoff Levand 	BUG_ON(result);
5652832a81dSGeoff Levand 
5662832a81dSGeoff Levand 	return result;
5672832a81dSGeoff Levand }
5682832a81dSGeoff Levand 
5692832a81dSGeoff Levand /**
570dc4f60c2SGeoff Levand  * ps3_spe_irq_setup - Setup an spe virq.
571861be32cSGeoff Levand  * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be
572861be32cSGeoff Levand  * serviced on.
5732832a81dSGeoff Levand  * @spe_id: The spe_id returned from lv1_construct_logical_spe().
5742832a81dSGeoff Levand  * @class: The spe interrupt class {0,1,2}.
5752832a81dSGeoff Levand  * @virq: The assigned Linux virq.
5762832a81dSGeoff Levand  *
5772832a81dSGeoff Levand  */
5782832a81dSGeoff Levand 
579dc4f60c2SGeoff Levand int ps3_spe_irq_setup(enum ps3_cpu_binding cpu, unsigned long spe_id,
580861be32cSGeoff Levand 	unsigned int class, unsigned int *virq)
5812832a81dSGeoff Levand {
5822832a81dSGeoff Levand 	int result;
5832832a81dSGeoff Levand 	unsigned long outlet;
5842832a81dSGeoff Levand 
5852832a81dSGeoff Levand 	BUG_ON(class > 2);
5862832a81dSGeoff Levand 
5872832a81dSGeoff Levand 	result = lv1_get_spe_irq_outlet(spe_id, class, &outlet);
5882832a81dSGeoff Levand 
5892832a81dSGeoff Levand 	if (result) {
5902832a81dSGeoff Levand 		pr_debug("%s:%d: lv1_get_spe_irq_outlet failed: %s\n",
5912832a81dSGeoff Levand 			__func__, __LINE__, ps3_result(result));
5922832a81dSGeoff Levand 		return result;
5932832a81dSGeoff Levand 	}
5942832a81dSGeoff Levand 
595dc4f60c2SGeoff Levand 	result = ps3_irq_plug_setup(cpu, outlet, virq);
596861be32cSGeoff Levand 	BUG_ON(result);
5972832a81dSGeoff Levand 
598861be32cSGeoff Levand 	return result;
5992832a81dSGeoff Levand }
6002832a81dSGeoff Levand 
601dc4f60c2SGeoff Levand int ps3_spe_irq_destroy(unsigned int virq)
6022832a81dSGeoff Levand {
603dc4f60c2SGeoff Levand 	int result = ps3_irq_plug_destroy(virq);
604dc4f60c2SGeoff Levand 	BUG_ON(result);
6052832a81dSGeoff Levand 	return 0;
6062832a81dSGeoff Levand }
6072832a81dSGeoff Levand 
608b1eeb38eSGeert Uytterhoeven 
6092832a81dSGeoff Levand #define PS3_INVALID_OUTLET ((irq_hw_number_t)-1)
6102832a81dSGeoff Levand #define PS3_PLUG_MAX 63
6112832a81dSGeoff Levand 
6122832a81dSGeoff Levand #if defined(DEBUG)
613861be32cSGeoff Levand static void _dump_64_bmp(const char *header, const u64 *p, unsigned cpu,
6142832a81dSGeoff Levand 	const char* func, int line)
6152832a81dSGeoff Levand {
6162832a81dSGeoff Levand 	pr_debug("%s:%d: %s %u {%04lx_%04lx_%04lx_%04lx}\n",
6172832a81dSGeoff Levand 		func, line, header, cpu,
6182832a81dSGeoff Levand 		*p >> 48, (*p >> 32) & 0xffff, (*p >> 16) & 0xffff,
6192832a81dSGeoff Levand 		*p & 0xffff);
6202832a81dSGeoff Levand }
6212832a81dSGeoff Levand 
622848cfdc5SGeoff Levand static void __maybe_unused _dump_256_bmp(const char *header,
623861be32cSGeoff Levand 	const u64 *p, unsigned cpu, const char* func, int line)
6242832a81dSGeoff Levand {
6252832a81dSGeoff Levand 	pr_debug("%s:%d: %s %u {%016lx:%016lx:%016lx:%016lx}\n",
6262832a81dSGeoff Levand 		func, line, header, cpu, p[0], p[1], p[2], p[3]);
6272832a81dSGeoff Levand }
6282832a81dSGeoff Levand 
6292832a81dSGeoff Levand #define dump_bmp(_x) _dump_bmp(_x, __func__, __LINE__)
6309633ac8dSGeoff Levand static void _dump_bmp(struct ps3_private* pd, const char* func, int line)
6312832a81dSGeoff Levand {
6322832a81dSGeoff Levand 	unsigned long flags;
6332832a81dSGeoff Levand 
6342832a81dSGeoff Levand 	spin_lock_irqsave(&pd->bmp.lock, flags);
6352832a81dSGeoff Levand 	_dump_64_bmp("stat", &pd->bmp.status, pd->cpu, func, line);
6362832a81dSGeoff Levand 	_dump_64_bmp("mask", &pd->bmp.mask, pd->cpu, func, line);
6372832a81dSGeoff Levand 	spin_unlock_irqrestore(&pd->bmp.lock, flags);
6382832a81dSGeoff Levand }
6392832a81dSGeoff Levand 
6402832a81dSGeoff Levand #define dump_mask(_x) _dump_mask(_x, __func__, __LINE__)
641848cfdc5SGeoff Levand static void __maybe_unused _dump_mask(struct ps3_private *pd,
6422832a81dSGeoff Levand 	const char* func, int line)
6432832a81dSGeoff Levand {
6442832a81dSGeoff Levand 	unsigned long flags;
6452832a81dSGeoff Levand 
6462832a81dSGeoff Levand 	spin_lock_irqsave(&pd->bmp.lock, flags);
6472832a81dSGeoff Levand 	_dump_64_bmp("mask", &pd->bmp.mask, pd->cpu, func, line);
6482832a81dSGeoff Levand 	spin_unlock_irqrestore(&pd->bmp.lock, flags);
6492832a81dSGeoff Levand }
6502832a81dSGeoff Levand #else
6519633ac8dSGeoff Levand static void dump_bmp(struct ps3_private* pd) {};
6522832a81dSGeoff Levand #endif /* defined(DEBUG) */
6532832a81dSGeoff Levand 
6549633ac8dSGeoff Levand static void ps3_host_unmap(struct irq_host *h, unsigned int virq)
6552832a81dSGeoff Levand {
656861be32cSGeoff Levand 	set_irq_chip_data(virq, NULL);
6572832a81dSGeoff Levand }
6582832a81dSGeoff Levand 
6599633ac8dSGeoff Levand static int ps3_host_map(struct irq_host *h, unsigned int virq,
6602832a81dSGeoff Levand 	irq_hw_number_t hwirq)
6612832a81dSGeoff Levand {
662861be32cSGeoff Levand 	pr_debug("%s:%d: hwirq %lu, virq %u\n", __func__, __LINE__, hwirq,
663861be32cSGeoff Levand 		virq);
6642832a81dSGeoff Levand 
6652832a81dSGeoff Levand 	set_irq_chip_and_handler(virq, &irq_chip, handle_fasteoi_irq);
6662832a81dSGeoff Levand 
667861be32cSGeoff Levand 	return 0;
6682832a81dSGeoff Levand }
6692832a81dSGeoff Levand 
6709633ac8dSGeoff Levand static struct irq_host_ops ps3_host_ops = {
6719633ac8dSGeoff Levand 	.map = ps3_host_map,
6729633ac8dSGeoff Levand 	.unmap = ps3_host_unmap,
6732832a81dSGeoff Levand };
6742832a81dSGeoff Levand 
6752832a81dSGeoff Levand void __init ps3_register_ipi_debug_brk(unsigned int cpu, unsigned int virq)
6762832a81dSGeoff Levand {
6779633ac8dSGeoff Levand 	struct ps3_private *pd = &per_cpu(ps3_private, cpu);
6782832a81dSGeoff Levand 
6792832a81dSGeoff Levand 	pd->bmp.ipi_debug_brk_mask = 0x8000000000000000UL >> virq;
6802832a81dSGeoff Levand 
6812832a81dSGeoff Levand 	pr_debug("%s:%d: cpu %u, virq %u, mask %lxh\n", __func__, __LINE__,
6822832a81dSGeoff Levand 		cpu, virq, pd->bmp.ipi_debug_brk_mask);
6832832a81dSGeoff Levand }
6842832a81dSGeoff Levand 
6859cf9e196SBenjamin Herrenschmidt unsigned int ps3_get_irq(void)
6862832a81dSGeoff Levand {
6879cf9e196SBenjamin Herrenschmidt 	struct ps3_private *pd = &__get_cpu_var(ps3_private);
688861be32cSGeoff Levand 	u64 x = (pd->bmp.status & pd->bmp.mask);
6899cf9e196SBenjamin Herrenschmidt 	unsigned int plug;
6902832a81dSGeoff Levand 
6912832a81dSGeoff Levand 	/* check for ipi break first to stop this cpu ASAP */
6922832a81dSGeoff Levand 
6939cf9e196SBenjamin Herrenschmidt 	if (x & pd->bmp.ipi_debug_brk_mask)
6949cf9e196SBenjamin Herrenschmidt 		x &= pd->bmp.ipi_debug_brk_mask;
6952832a81dSGeoff Levand 
6969cf9e196SBenjamin Herrenschmidt 	asm volatile("cntlzd %0,%1" : "=r" (plug) : "r" (x));
6979cf9e196SBenjamin Herrenschmidt 	plug &= 0x3f;
6982832a81dSGeoff Levand 
6999cf9e196SBenjamin Herrenschmidt 	if (unlikely(plug) == NO_IRQ) {
7002832a81dSGeoff Levand 		pr_debug("%s:%d: no plug found: cpu %u\n", __func__, __LINE__,
7012832a81dSGeoff Levand 			pd->cpu);
7029633ac8dSGeoff Levand 		dump_bmp(&per_cpu(ps3_private, 0));
7039633ac8dSGeoff Levand 		dump_bmp(&per_cpu(ps3_private, 1));
7042832a81dSGeoff Levand 		return NO_IRQ;
7052832a81dSGeoff Levand 	}
7062832a81dSGeoff Levand 
7072832a81dSGeoff Levand #if defined(DEBUG)
7089cf9e196SBenjamin Herrenschmidt 	if (unlikely(plug < NUM_ISA_INTERRUPTS || plug > PS3_PLUG_MAX)) {
7099633ac8dSGeoff Levand 		dump_bmp(&per_cpu(ps3_private, 0));
7109633ac8dSGeoff Levand 		dump_bmp(&per_cpu(ps3_private, 1));
7112832a81dSGeoff Levand 		BUG();
7122832a81dSGeoff Levand 	}
7132832a81dSGeoff Levand #endif
7142832a81dSGeoff Levand 	return plug;
7152832a81dSGeoff Levand }
7162832a81dSGeoff Levand 
7172832a81dSGeoff Levand void __init ps3_init_IRQ(void)
7182832a81dSGeoff Levand {
7192832a81dSGeoff Levand 	int result;
7202832a81dSGeoff Levand 	unsigned cpu;
7212832a81dSGeoff Levand 	struct irq_host *host;
7222832a81dSGeoff Levand 
7239633ac8dSGeoff Levand 	host = irq_alloc_host(IRQ_HOST_MAP_NOMAP, 0, &ps3_host_ops,
7242832a81dSGeoff Levand 		PS3_INVALID_OUTLET);
7252832a81dSGeoff Levand 	irq_set_default_host(host);
7262832a81dSGeoff Levand 	irq_set_virq_count(PS3_PLUG_MAX + 1);
7272832a81dSGeoff Levand 
7282832a81dSGeoff Levand 	for_each_possible_cpu(cpu) {
7299633ac8dSGeoff Levand 		struct ps3_private *pd = &per_cpu(ps3_private, cpu);
7302832a81dSGeoff Levand 
731407e24a0SGeoff Levand 		lv1_get_logical_ppe_id(&pd->node);
732407e24a0SGeoff Levand 		pd->cpu = get_hard_smp_processor_id(cpu);
7332832a81dSGeoff Levand 		spin_lock_init(&pd->bmp.lock);
7342832a81dSGeoff Levand 
735407e24a0SGeoff Levand 		pr_debug("%s:%d: node %lu, cpu %d, bmp %lxh\n", __func__,
736407e24a0SGeoff Levand 			__LINE__, pd->node, pd->cpu,
737407e24a0SGeoff Levand 			ps3_mm_phys_to_lpar(__pa(&pd->bmp)));
738407e24a0SGeoff Levand 
739407e24a0SGeoff Levand 		result = lv1_configure_irq_state_bitmap(pd->node, pd->cpu,
740407e24a0SGeoff Levand 			ps3_mm_phys_to_lpar(__pa(&pd->bmp)));
7412832a81dSGeoff Levand 
7422832a81dSGeoff Levand 		if (result)
7432832a81dSGeoff Levand 			pr_debug("%s:%d: lv1_configure_irq_state_bitmap failed:"
7442832a81dSGeoff Levand 				" %s\n", __func__, __LINE__,
7452832a81dSGeoff Levand 				ps3_result(result));
7462832a81dSGeoff Levand 	}
7472832a81dSGeoff Levand 
7482832a81dSGeoff Levand 	ppc_md.get_irq = ps3_get_irq;
7492832a81dSGeoff Levand }
750