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> 224b16f8e2SPaul Gortmaker #include <linux/export.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) 3383bb643dSGeert Uytterhoeven #define DBG udbg_printf 342832a81dSGeoff Levand #else 3583bb643dSGeert 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 * 47b595076aSUwe Kleine-König * The HV maintains 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. 6346ca0d15SStephen Rothwell * 6446ca0d15SStephen Rothwell * The mask is declared as unsigned long so we can use set/clear_bit on it. 65861be32cSGeoff Levand */ 66861be32cSGeoff Levand 6757715765SGeoff Levand #define PS3_BMP_MINALIGN 64 6857715765SGeoff Levand 69861be32cSGeoff Levand struct ps3_bmp { 70861be32cSGeoff Levand struct { 71861be32cSGeoff Levand u64 status; 72861be32cSGeoff Levand u64 unused_1[3]; 7346ca0d15SStephen Rothwell unsigned long mask; 74861be32cSGeoff Levand u64 unused_2[3]; 75861be32cSGeoff Levand }; 76861be32cSGeoff Levand u64 ipi_debug_brk_mask; 77861be32cSGeoff Levand spinlock_t lock; 78861be32cSGeoff Levand }; 79861be32cSGeoff Levand 80861be32cSGeoff Levand /** 81861be32cSGeoff Levand * struct ps3_private - a per cpu data structure 82861be32cSGeoff Levand * @bmp: ps3_bmp structure 83aab83500SGeoff Levand * @ppe_id: HV logical_ppe_id 84aab83500SGeoff Levand * @thread_id: HV thread_id 85861be32cSGeoff Levand */ 86861be32cSGeoff Levand 87861be32cSGeoff Levand struct ps3_private { 8857715765SGeoff Levand struct ps3_bmp bmp __attribute__ ((aligned (PS3_BMP_MINALIGN))); 89aab83500SGeoff Levand u64 ppe_id; 90aab83500SGeoff Levand u64 thread_id; 91*72f3bea0SGeoff Levand unsigned long ipi_mask; 92861be32cSGeoff Levand }; 93861be32cSGeoff Levand 94861be32cSGeoff Levand static DEFINE_PER_CPU(struct ps3_private, ps3_private); 95861be32cSGeoff Levand 96dc4f60c2SGeoff Levand /** 97743c1bb0SGeoff Levand * ps3_chip_mask - Set an interrupt mask bit in ps3_bmp. 98743c1bb0SGeoff Levand * @virq: The assigned Linux virq. 99743c1bb0SGeoff Levand * 100743c1bb0SGeoff Levand * Sets ps3_bmp.mask and calls lv1_did_update_interrupt_mask(). 101743c1bb0SGeoff Levand */ 102743c1bb0SGeoff Levand 1038126708aSLennert Buytenhek static void ps3_chip_mask(struct irq_data *d) 104743c1bb0SGeoff Levand { 1058126708aSLennert Buytenhek struct ps3_private *pd = irq_data_get_irq_chip_data(d); 106743c1bb0SGeoff Levand unsigned long flags; 107743c1bb0SGeoff Levand 1085c949070SStephen Rothwell pr_debug("%s:%d: thread_id %llu, virq %d\n", __func__, __LINE__, 1098126708aSLennert Buytenhek pd->thread_id, d->irq); 110743c1bb0SGeoff Levand 111743c1bb0SGeoff Levand local_irq_save(flags); 1128126708aSLennert Buytenhek clear_bit(63 - d->irq, &pd->bmp.mask); 113aab83500SGeoff Levand lv1_did_update_interrupt_mask(pd->ppe_id, pd->thread_id); 114743c1bb0SGeoff Levand local_irq_restore(flags); 115743c1bb0SGeoff Levand } 116743c1bb0SGeoff Levand 117743c1bb0SGeoff Levand /** 118743c1bb0SGeoff Levand * ps3_chip_unmask - Clear an interrupt mask bit in ps3_bmp. 119743c1bb0SGeoff Levand * @virq: The assigned Linux virq. 120743c1bb0SGeoff Levand * 121743c1bb0SGeoff Levand * Clears ps3_bmp.mask and calls lv1_did_update_interrupt_mask(). 122743c1bb0SGeoff Levand */ 123743c1bb0SGeoff Levand 1248126708aSLennert Buytenhek static void ps3_chip_unmask(struct irq_data *d) 125743c1bb0SGeoff Levand { 1268126708aSLennert Buytenhek struct ps3_private *pd = irq_data_get_irq_chip_data(d); 127743c1bb0SGeoff Levand unsigned long flags; 128743c1bb0SGeoff Levand 1295c949070SStephen Rothwell pr_debug("%s:%d: thread_id %llu, virq %d\n", __func__, __LINE__, 1308126708aSLennert Buytenhek pd->thread_id, d->irq); 131743c1bb0SGeoff Levand 132743c1bb0SGeoff Levand local_irq_save(flags); 1338126708aSLennert Buytenhek set_bit(63 - d->irq, &pd->bmp.mask); 134aab83500SGeoff Levand lv1_did_update_interrupt_mask(pd->ppe_id, pd->thread_id); 135743c1bb0SGeoff Levand local_irq_restore(flags); 136743c1bb0SGeoff Levand } 137743c1bb0SGeoff Levand 138743c1bb0SGeoff Levand /** 139743c1bb0SGeoff Levand * ps3_chip_eoi - HV end-of-interrupt. 140743c1bb0SGeoff Levand * @virq: The assigned Linux virq. 141743c1bb0SGeoff Levand * 142743c1bb0SGeoff Levand * Calls lv1_end_of_interrupt_ext(). 143743c1bb0SGeoff Levand */ 144743c1bb0SGeoff Levand 1458126708aSLennert Buytenhek static void ps3_chip_eoi(struct irq_data *d) 146743c1bb0SGeoff Levand { 1478126708aSLennert Buytenhek const struct ps3_private *pd = irq_data_get_irq_chip_data(d); 148*72f3bea0SGeoff Levand 149*72f3bea0SGeoff Levand /* non-IPIs are EOIed here. */ 150*72f3bea0SGeoff Levand 151*72f3bea0SGeoff Levand if (!test_bit(63 - d->irq, &pd->ipi_mask)) 1528126708aSLennert Buytenhek lv1_end_of_interrupt_ext(pd->ppe_id, pd->thread_id, d->irq); 153743c1bb0SGeoff Levand } 154743c1bb0SGeoff Levand 155743c1bb0SGeoff Levand /** 156743c1bb0SGeoff Levand * ps3_irq_chip - Represents the ps3_bmp as a Linux struct irq_chip. 157743c1bb0SGeoff Levand */ 158743c1bb0SGeoff Levand 159743c1bb0SGeoff Levand static struct irq_chip ps3_irq_chip = { 160b27df672SThomas Gleixner .name = "ps3", 1618126708aSLennert Buytenhek .irq_mask = ps3_chip_mask, 1628126708aSLennert Buytenhek .irq_unmask = ps3_chip_unmask, 1638126708aSLennert Buytenhek .irq_eoi = ps3_chip_eoi, 164743c1bb0SGeoff Levand }; 165743c1bb0SGeoff Levand 166743c1bb0SGeoff Levand /** 167dc4f60c2SGeoff Levand * ps3_virq_setup - virq related setup. 168dc4f60c2SGeoff Levand * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be 169dc4f60c2SGeoff Levand * serviced on. 170dc4f60c2SGeoff Levand * @outlet: The HV outlet from the various create outlet routines. 171dc4f60c2SGeoff Levand * @virq: The assigned Linux virq. 172dc4f60c2SGeoff Levand * 173dc4f60c2SGeoff Levand * Calls irq_create_mapping() to get a virq and sets the chip data to 174dc4f60c2SGeoff Levand * ps3_private data. 175dc4f60c2SGeoff Levand */ 176dc4f60c2SGeoff Levand 177fdedb4caSGeert Uytterhoeven static int ps3_virq_setup(enum ps3_cpu_binding cpu, unsigned long outlet, 178861be32cSGeoff Levand unsigned int *virq) 179861be32cSGeoff Levand { 180861be32cSGeoff Levand int result; 181861be32cSGeoff Levand struct ps3_private *pd; 182861be32cSGeoff Levand 183861be32cSGeoff Levand /* This defines the default interrupt distribution policy. */ 184861be32cSGeoff Levand 185861be32cSGeoff Levand if (cpu == PS3_BINDING_CPU_ANY) 186861be32cSGeoff Levand cpu = 0; 187861be32cSGeoff Levand 188861be32cSGeoff Levand pd = &per_cpu(ps3_private, cpu); 189861be32cSGeoff Levand 190861be32cSGeoff Levand *virq = irq_create_mapping(NULL, outlet); 191861be32cSGeoff Levand 192861be32cSGeoff Levand if (*virq == NO_IRQ) { 193861be32cSGeoff Levand pr_debug("%s:%d: irq_create_mapping failed: outlet %lu\n", 194861be32cSGeoff Levand __func__, __LINE__, outlet); 195861be32cSGeoff Levand result = -ENOMEM; 196861be32cSGeoff Levand goto fail_create; 197861be32cSGeoff Levand } 198861be32cSGeoff Levand 199861be32cSGeoff Levand pr_debug("%s:%d: outlet %lu => cpu %u, virq %u\n", __func__, __LINE__, 200861be32cSGeoff Levand outlet, cpu, *virq); 201861be32cSGeoff Levand 202ec775d0eSThomas Gleixner result = irq_set_chip_data(*virq, pd); 203861be32cSGeoff Levand 204861be32cSGeoff Levand if (result) { 205b618d2f0SGeert Uytterhoeven pr_debug("%s:%d: irq_set_chip_data failed\n", 206861be32cSGeoff Levand __func__, __LINE__); 207861be32cSGeoff Levand goto fail_set; 208861be32cSGeoff Levand } 209861be32cSGeoff Levand 2108126708aSLennert Buytenhek ps3_chip_mask(irq_get_irq_data(*virq)); 2119263e85aSGeoff Levand 212861be32cSGeoff Levand return result; 213861be32cSGeoff Levand 214861be32cSGeoff Levand fail_set: 215861be32cSGeoff Levand irq_dispose_mapping(*virq); 216861be32cSGeoff Levand fail_create: 217861be32cSGeoff Levand return result; 218861be32cSGeoff Levand } 219861be32cSGeoff Levand 220dc4f60c2SGeoff Levand /** 221dc4f60c2SGeoff Levand * ps3_virq_destroy - virq related teardown. 222dc4f60c2SGeoff Levand * @virq: The assigned Linux virq. 223dc4f60c2SGeoff Levand * 224dc4f60c2SGeoff Levand * Clears chip data and calls irq_dispose_mapping() for the virq. 225dc4f60c2SGeoff Levand */ 226dc4f60c2SGeoff Levand 227fdedb4caSGeert Uytterhoeven static int ps3_virq_destroy(unsigned int virq) 228dc4f60c2SGeoff Levand { 229ec775d0eSThomas Gleixner const struct ps3_private *pd = irq_get_chip_data(virq); 230dc4f60c2SGeoff Levand 2315c949070SStephen Rothwell pr_debug("%s:%d: ppe_id %llu, thread_id %llu, virq %u\n", __func__, 232aab83500SGeoff Levand __LINE__, pd->ppe_id, pd->thread_id, virq); 233dc4f60c2SGeoff Levand 234ec775d0eSThomas Gleixner irq_set_chip_data(virq, NULL); 235dc4f60c2SGeoff Levand irq_dispose_mapping(virq); 236dc4f60c2SGeoff Levand 237dc4f60c2SGeoff Levand pr_debug("%s:%d <-\n", __func__, __LINE__); 238dc4f60c2SGeoff Levand return 0; 239dc4f60c2SGeoff Levand } 240dc4f60c2SGeoff Levand 241dc4f60c2SGeoff Levand /** 242dc4f60c2SGeoff Levand * ps3_irq_plug_setup - Generic outlet and virq related setup. 243dc4f60c2SGeoff Levand * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be 244dc4f60c2SGeoff Levand * serviced on. 245dc4f60c2SGeoff Levand * @outlet: The HV outlet from the various create outlet routines. 246dc4f60c2SGeoff Levand * @virq: The assigned Linux virq. 247dc4f60c2SGeoff Levand * 248dc4f60c2SGeoff Levand * Sets up virq and connects the irq plug. 249dc4f60c2SGeoff Levand */ 250dc4f60c2SGeoff Levand 251dc4f60c2SGeoff Levand int ps3_irq_plug_setup(enum ps3_cpu_binding cpu, unsigned long outlet, 252dc4f60c2SGeoff Levand unsigned int *virq) 253dc4f60c2SGeoff Levand { 254dc4f60c2SGeoff Levand int result; 255dc4f60c2SGeoff Levand struct ps3_private *pd; 256dc4f60c2SGeoff Levand 257dc4f60c2SGeoff Levand result = ps3_virq_setup(cpu, outlet, virq); 258dc4f60c2SGeoff Levand 259dc4f60c2SGeoff Levand if (result) { 260dc4f60c2SGeoff Levand pr_debug("%s:%d: ps3_virq_setup failed\n", __func__, __LINE__); 261dc4f60c2SGeoff Levand goto fail_setup; 262dc4f60c2SGeoff Levand } 263dc4f60c2SGeoff Levand 264ec775d0eSThomas Gleixner pd = irq_get_chip_data(*virq); 265dc4f60c2SGeoff Levand 266dc4f60c2SGeoff Levand /* Binds outlet to cpu + virq. */ 267dc4f60c2SGeoff Levand 268aab83500SGeoff Levand result = lv1_connect_irq_plug_ext(pd->ppe_id, pd->thread_id, *virq, 269aab83500SGeoff Levand outlet, 0); 270dc4f60c2SGeoff Levand 271dc4f60c2SGeoff Levand if (result) { 272dc4f60c2SGeoff Levand pr_info("%s:%d: lv1_connect_irq_plug_ext failed: %s\n", 273dc4f60c2SGeoff Levand __func__, __LINE__, ps3_result(result)); 274dc4f60c2SGeoff Levand result = -EPERM; 275dc4f60c2SGeoff Levand goto fail_connect; 276dc4f60c2SGeoff Levand } 277dc4f60c2SGeoff Levand 278dc4f60c2SGeoff Levand return result; 279dc4f60c2SGeoff Levand 280dc4f60c2SGeoff Levand fail_connect: 281dc4f60c2SGeoff Levand ps3_virq_destroy(*virq); 282dc4f60c2SGeoff Levand fail_setup: 283dc4f60c2SGeoff Levand return result; 284dc4f60c2SGeoff Levand } 285dc4f60c2SGeoff Levand EXPORT_SYMBOL_GPL(ps3_irq_plug_setup); 286dc4f60c2SGeoff Levand 287dc4f60c2SGeoff Levand /** 288dc4f60c2SGeoff Levand * ps3_irq_plug_destroy - Generic outlet and virq related teardown. 289dc4f60c2SGeoff Levand * @virq: The assigned Linux virq. 290dc4f60c2SGeoff Levand * 291dc4f60c2SGeoff Levand * Disconnects the irq plug and tears down virq. 292dc4f60c2SGeoff Levand * Do not call for system bus event interrupts setup with 293dc4f60c2SGeoff Levand * ps3_sb_event_receive_port_setup(). 294dc4f60c2SGeoff Levand */ 295dc4f60c2SGeoff Levand 296dc4f60c2SGeoff Levand int ps3_irq_plug_destroy(unsigned int virq) 297861be32cSGeoff Levand { 298861be32cSGeoff Levand int result; 299ec775d0eSThomas Gleixner const struct ps3_private *pd = irq_get_chip_data(virq); 300861be32cSGeoff Levand 3015c949070SStephen Rothwell pr_debug("%s:%d: ppe_id %llu, thread_id %llu, virq %u\n", __func__, 302aab83500SGeoff Levand __LINE__, pd->ppe_id, pd->thread_id, virq); 303861be32cSGeoff Levand 3048126708aSLennert Buytenhek ps3_chip_mask(irq_get_irq_data(virq)); 3059263e85aSGeoff Levand 306aab83500SGeoff Levand result = lv1_disconnect_irq_plug_ext(pd->ppe_id, pd->thread_id, virq); 307861be32cSGeoff Levand 308861be32cSGeoff Levand if (result) 309861be32cSGeoff Levand pr_info("%s:%d: lv1_disconnect_irq_plug_ext failed: %s\n", 310861be32cSGeoff Levand __func__, __LINE__, ps3_result(result)); 311861be32cSGeoff Levand 312dc4f60c2SGeoff Levand ps3_virq_destroy(virq); 313dc4f60c2SGeoff Levand 314b1eeb38eSGeert Uytterhoeven return result; 315861be32cSGeoff Levand } 316dc4f60c2SGeoff Levand EXPORT_SYMBOL_GPL(ps3_irq_plug_destroy); 317861be32cSGeoff Levand 318861be32cSGeoff Levand /** 319dc4f60c2SGeoff Levand * ps3_event_receive_port_setup - Setup an event receive port. 320861be32cSGeoff Levand * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be 321861be32cSGeoff Levand * serviced on. 3222832a81dSGeoff Levand * @virq: The assigned Linux virq. 3232832a81dSGeoff Levand * 3242832a81dSGeoff Levand * The virq can be used with lv1_connect_interrupt_event_receive_port() to 325dc4f60c2SGeoff Levand * arrange to receive interrupts from system-bus devices, or with 326dc4f60c2SGeoff Levand * ps3_send_event_locally() to signal events. 3272832a81dSGeoff Levand */ 3282832a81dSGeoff Levand 329dc4f60c2SGeoff Levand int ps3_event_receive_port_setup(enum ps3_cpu_binding cpu, unsigned int *virq) 3302832a81dSGeoff Levand { 3312832a81dSGeoff Levand int result; 332b17b3df1SStephen Rothwell u64 outlet; 3332832a81dSGeoff Levand 3342832a81dSGeoff Levand result = lv1_construct_event_receive_port(&outlet); 3352832a81dSGeoff Levand 3362832a81dSGeoff Levand if (result) { 3372832a81dSGeoff Levand pr_debug("%s:%d: lv1_construct_event_receive_port failed: %s\n", 3382832a81dSGeoff Levand __func__, __LINE__, ps3_result(result)); 3392832a81dSGeoff Levand *virq = NO_IRQ; 3402832a81dSGeoff Levand return result; 3412832a81dSGeoff Levand } 3422832a81dSGeoff Levand 343dc4f60c2SGeoff Levand result = ps3_irq_plug_setup(cpu, outlet, virq); 344861be32cSGeoff Levand BUG_ON(result); 3452832a81dSGeoff Levand 346861be32cSGeoff Levand return result; 3472832a81dSGeoff Levand } 348dc4f60c2SGeoff Levand EXPORT_SYMBOL_GPL(ps3_event_receive_port_setup); 3492832a81dSGeoff Levand 350dc4f60c2SGeoff Levand /** 351dc4f60c2SGeoff Levand * ps3_event_receive_port_destroy - Destroy an event receive port. 352dc4f60c2SGeoff Levand * @virq: The assigned Linux virq. 353dc4f60c2SGeoff Levand * 354dc4f60c2SGeoff Levand * Since ps3_event_receive_port_destroy destroys the receive port outlet, 355dc4f60c2SGeoff Levand * SB devices need to call disconnect_interrupt_event_receive_port() before 356dc4f60c2SGeoff Levand * this. 357dc4f60c2SGeoff Levand */ 358dc4f60c2SGeoff Levand 359dc4f60c2SGeoff Levand int ps3_event_receive_port_destroy(unsigned int virq) 3602832a81dSGeoff Levand { 3612832a81dSGeoff Levand int result; 3622832a81dSGeoff Levand 3639263e85aSGeoff Levand pr_debug(" -> %s:%d virq %u\n", __func__, __LINE__, virq); 3649263e85aSGeoff Levand 3658126708aSLennert Buytenhek ps3_chip_mask(irq_get_irq_data(virq)); 3662832a81dSGeoff Levand 3672832a81dSGeoff Levand result = lv1_destruct_event_receive_port(virq_to_hw(virq)); 3682832a81dSGeoff Levand 3692832a81dSGeoff Levand if (result) 3702832a81dSGeoff Levand pr_debug("%s:%d: lv1_destruct_event_receive_port failed: %s\n", 3712832a81dSGeoff Levand __func__, __LINE__, ps3_result(result)); 3722832a81dSGeoff Levand 3739263e85aSGeoff Levand /* 3749263e85aSGeoff Levand * Don't call ps3_virq_destroy() here since ps3_smp_cleanup_cpu() 3759263e85aSGeoff Levand * calls from interrupt context (smp_call_function) when kexecing. 376dc4f60c2SGeoff Levand */ 377dc4f60c2SGeoff Levand 3782832a81dSGeoff Levand pr_debug(" <- %s:%d\n", __func__, __LINE__); 3792832a81dSGeoff Levand return result; 3802832a81dSGeoff Levand } 3812832a81dSGeoff Levand 3822832a81dSGeoff Levand int ps3_send_event_locally(unsigned int virq) 3832832a81dSGeoff Levand { 3842832a81dSGeoff Levand return lv1_send_event_locally(virq_to_hw(virq)); 3852832a81dSGeoff Levand } 3862832a81dSGeoff Levand 3872832a81dSGeoff Levand /** 388dc4f60c2SGeoff Levand * ps3_sb_event_receive_port_setup - Setup a system bus event receive port. 389861be32cSGeoff Levand * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be 390861be32cSGeoff Levand * serviced on. 3916bb5cf10SGeoff Levand * @dev: The system bus device instance. 3922832a81dSGeoff Levand * @virq: The assigned Linux virq. 3932832a81dSGeoff Levand * 3942832a81dSGeoff Levand * An event irq represents a virtual device interrupt. The interrupt_id 3952832a81dSGeoff Levand * coresponds to the software interrupt number. 3962832a81dSGeoff Levand */ 3972832a81dSGeoff Levand 3986bb5cf10SGeoff Levand int ps3_sb_event_receive_port_setup(struct ps3_system_bus_device *dev, 3996bb5cf10SGeoff Levand enum ps3_cpu_binding cpu, unsigned int *virq) 4002832a81dSGeoff Levand { 401dc4f60c2SGeoff Levand /* this should go in system-bus.c */ 402dc4f60c2SGeoff Levand 4032832a81dSGeoff Levand int result; 4042832a81dSGeoff Levand 405dc4f60c2SGeoff Levand result = ps3_event_receive_port_setup(cpu, virq); 4062832a81dSGeoff Levand 4072832a81dSGeoff Levand if (result) 4082832a81dSGeoff Levand return result; 4092832a81dSGeoff Levand 4106bb5cf10SGeoff Levand result = lv1_connect_interrupt_event_receive_port(dev->bus_id, 4116bb5cf10SGeoff Levand dev->dev_id, virq_to_hw(*virq), dev->interrupt_id); 4122832a81dSGeoff Levand 4132832a81dSGeoff Levand if (result) { 4142832a81dSGeoff Levand pr_debug("%s:%d: lv1_connect_interrupt_event_receive_port" 4152832a81dSGeoff Levand " failed: %s\n", __func__, __LINE__, 4162832a81dSGeoff Levand ps3_result(result)); 417dc4f60c2SGeoff Levand ps3_event_receive_port_destroy(*virq); 4182832a81dSGeoff Levand *virq = NO_IRQ; 4192832a81dSGeoff Levand return result; 4202832a81dSGeoff Levand } 4212832a81dSGeoff Levand 4222832a81dSGeoff Levand pr_debug("%s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__, 4236bb5cf10SGeoff Levand dev->interrupt_id, *virq); 4242832a81dSGeoff Levand 4252832a81dSGeoff Levand return 0; 4262832a81dSGeoff Levand } 427dc4f60c2SGeoff Levand EXPORT_SYMBOL(ps3_sb_event_receive_port_setup); 4282832a81dSGeoff Levand 4296bb5cf10SGeoff Levand int ps3_sb_event_receive_port_destroy(struct ps3_system_bus_device *dev, 4306bb5cf10SGeoff Levand unsigned int virq) 4312832a81dSGeoff Levand { 432dc4f60c2SGeoff Levand /* this should go in system-bus.c */ 433dc4f60c2SGeoff Levand 4342832a81dSGeoff Levand int result; 4352832a81dSGeoff Levand 4362832a81dSGeoff Levand pr_debug(" -> %s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__, 4376bb5cf10SGeoff Levand dev->interrupt_id, virq); 4382832a81dSGeoff Levand 4396bb5cf10SGeoff Levand result = lv1_disconnect_interrupt_event_receive_port(dev->bus_id, 4406bb5cf10SGeoff Levand dev->dev_id, virq_to_hw(virq), dev->interrupt_id); 4412832a81dSGeoff Levand 4422832a81dSGeoff Levand if (result) 4432832a81dSGeoff Levand pr_debug("%s:%d: lv1_disconnect_interrupt_event_receive_port" 4442832a81dSGeoff Levand " failed: %s\n", __func__, __LINE__, 4452832a81dSGeoff Levand ps3_result(result)); 4462832a81dSGeoff Levand 447dc4f60c2SGeoff Levand result = ps3_event_receive_port_destroy(virq); 448dc4f60c2SGeoff Levand BUG_ON(result); 4492832a81dSGeoff Levand 4509263e85aSGeoff Levand /* 4519263e85aSGeoff Levand * ps3_event_receive_port_destroy() destroys the IRQ plug, 4529263e85aSGeoff Levand * so don't call ps3_irq_plug_destroy() here. 4539263e85aSGeoff Levand */ 4549263e85aSGeoff Levand 4559263e85aSGeoff Levand result = ps3_virq_destroy(virq); 4569263e85aSGeoff Levand BUG_ON(result); 4579263e85aSGeoff Levand 4582832a81dSGeoff Levand pr_debug(" <- %s:%d\n", __func__, __LINE__); 4592832a81dSGeoff Levand return result; 4602832a81dSGeoff Levand } 461dc4f60c2SGeoff Levand EXPORT_SYMBOL(ps3_sb_event_receive_port_destroy); 4622832a81dSGeoff Levand 4632832a81dSGeoff Levand /** 464dc4f60c2SGeoff Levand * ps3_io_irq_setup - Setup a system bus io irq. 465dc4f60c2SGeoff Levand * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be 466dc4f60c2SGeoff Levand * serviced on. 467dc4f60c2SGeoff Levand * @interrupt_id: The device interrupt id read from the system repository. 468dc4f60c2SGeoff Levand * @virq: The assigned Linux virq. 469dc4f60c2SGeoff Levand * 470dc4f60c2SGeoff Levand * An io irq represents a non-virtualized device interrupt. interrupt_id 471dc4f60c2SGeoff Levand * coresponds to the interrupt number of the interrupt controller. 472dc4f60c2SGeoff Levand */ 473dc4f60c2SGeoff Levand 474dc4f60c2SGeoff Levand int ps3_io_irq_setup(enum ps3_cpu_binding cpu, unsigned int interrupt_id, 475dc4f60c2SGeoff Levand unsigned int *virq) 476dc4f60c2SGeoff Levand { 477dc4f60c2SGeoff Levand int result; 478b17b3df1SStephen Rothwell u64 outlet; 479dc4f60c2SGeoff Levand 480dc4f60c2SGeoff Levand result = lv1_construct_io_irq_outlet(interrupt_id, &outlet); 481dc4f60c2SGeoff Levand 482dc4f60c2SGeoff Levand if (result) { 483dc4f60c2SGeoff Levand pr_debug("%s:%d: lv1_construct_io_irq_outlet failed: %s\n", 484dc4f60c2SGeoff Levand __func__, __LINE__, ps3_result(result)); 485dc4f60c2SGeoff Levand return result; 486dc4f60c2SGeoff Levand } 487dc4f60c2SGeoff Levand 488dc4f60c2SGeoff Levand result = ps3_irq_plug_setup(cpu, outlet, virq); 489dc4f60c2SGeoff Levand BUG_ON(result); 490dc4f60c2SGeoff Levand 491dc4f60c2SGeoff Levand return result; 492dc4f60c2SGeoff Levand } 493dc4f60c2SGeoff Levand EXPORT_SYMBOL_GPL(ps3_io_irq_setup); 494dc4f60c2SGeoff Levand 495dc4f60c2SGeoff Levand int ps3_io_irq_destroy(unsigned int virq) 496dc4f60c2SGeoff Levand { 497dc4f60c2SGeoff Levand int result; 4989263e85aSGeoff Levand unsigned long outlet = virq_to_hw(virq); 499dc4f60c2SGeoff Levand 5008126708aSLennert Buytenhek ps3_chip_mask(irq_get_irq_data(virq)); 5019263e85aSGeoff Levand 5029263e85aSGeoff Levand /* 5039263e85aSGeoff Levand * lv1_destruct_io_irq_outlet() will destroy the IRQ plug, 5049263e85aSGeoff Levand * so call ps3_irq_plug_destroy() first. 5059263e85aSGeoff Levand */ 5069263e85aSGeoff Levand 5079263e85aSGeoff Levand result = ps3_irq_plug_destroy(virq); 5089263e85aSGeoff Levand BUG_ON(result); 5099263e85aSGeoff Levand 5109263e85aSGeoff Levand result = lv1_destruct_io_irq_outlet(outlet); 511dc4f60c2SGeoff Levand 512dc4f60c2SGeoff Levand if (result) 513dc4f60c2SGeoff Levand pr_debug("%s:%d: lv1_destruct_io_irq_outlet failed: %s\n", 514dc4f60c2SGeoff Levand __func__, __LINE__, ps3_result(result)); 515dc4f60c2SGeoff Levand 516dc4f60c2SGeoff Levand return result; 517dc4f60c2SGeoff Levand } 518dc4f60c2SGeoff Levand EXPORT_SYMBOL_GPL(ps3_io_irq_destroy); 519dc4f60c2SGeoff Levand 520dc4f60c2SGeoff Levand /** 521dc4f60c2SGeoff Levand * ps3_vuart_irq_setup - Setup the system virtual uart virq. 522861be32cSGeoff Levand * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be 523861be32cSGeoff Levand * serviced on. 5242832a81dSGeoff Levand * @virt_addr_bmp: The caller supplied virtual uart interrupt bitmap. 5252832a81dSGeoff Levand * @virq: The assigned Linux virq. 5262832a81dSGeoff Levand * 5272832a81dSGeoff Levand * The system supports only a single virtual uart, so multiple calls without 5282832a81dSGeoff Levand * freeing the interrupt will return a wrong state error. 5292832a81dSGeoff Levand */ 5302832a81dSGeoff Levand 531dc4f60c2SGeoff Levand int ps3_vuart_irq_setup(enum ps3_cpu_binding cpu, void* virt_addr_bmp, 532861be32cSGeoff Levand unsigned int *virq) 5332832a81dSGeoff Levand { 5342832a81dSGeoff Levand int result; 535b17b3df1SStephen Rothwell u64 outlet; 536861be32cSGeoff Levand u64 lpar_addr; 5372832a81dSGeoff Levand 538861be32cSGeoff Levand BUG_ON(!is_kernel_addr((u64)virt_addr_bmp)); 5392832a81dSGeoff Levand 5402832a81dSGeoff Levand lpar_addr = ps3_mm_phys_to_lpar(__pa(virt_addr_bmp)); 5412832a81dSGeoff Levand 5422832a81dSGeoff Levand result = lv1_configure_virtual_uart_irq(lpar_addr, &outlet); 5432832a81dSGeoff Levand 5442832a81dSGeoff Levand if (result) { 5452832a81dSGeoff Levand pr_debug("%s:%d: lv1_configure_virtual_uart_irq failed: %s\n", 5462832a81dSGeoff Levand __func__, __LINE__, ps3_result(result)); 5472832a81dSGeoff Levand return result; 5482832a81dSGeoff Levand } 5492832a81dSGeoff Levand 550dc4f60c2SGeoff Levand result = ps3_irq_plug_setup(cpu, outlet, virq); 551861be32cSGeoff Levand BUG_ON(result); 5522832a81dSGeoff Levand 553861be32cSGeoff Levand return result; 5542832a81dSGeoff Levand } 5557626e78dSGeoff Levand EXPORT_SYMBOL_GPL(ps3_vuart_irq_setup); 5562832a81dSGeoff Levand 557dc4f60c2SGeoff Levand int ps3_vuart_irq_destroy(unsigned int virq) 5582832a81dSGeoff Levand { 5592832a81dSGeoff Levand int result; 5602832a81dSGeoff Levand 5618126708aSLennert Buytenhek ps3_chip_mask(irq_get_irq_data(virq)); 5622832a81dSGeoff Levand result = lv1_deconfigure_virtual_uart_irq(); 5632832a81dSGeoff Levand 5642832a81dSGeoff Levand if (result) { 5652832a81dSGeoff Levand pr_debug("%s:%d: lv1_configure_virtual_uart_irq failed: %s\n", 5662832a81dSGeoff Levand __func__, __LINE__, ps3_result(result)); 5672832a81dSGeoff Levand return result; 5682832a81dSGeoff Levand } 5692832a81dSGeoff Levand 570dc4f60c2SGeoff Levand result = ps3_irq_plug_destroy(virq); 571dc4f60c2SGeoff Levand BUG_ON(result); 5722832a81dSGeoff Levand 5732832a81dSGeoff Levand return result; 5742832a81dSGeoff Levand } 5757626e78dSGeoff Levand EXPORT_SYMBOL_GPL(ps3_vuart_irq_destroy); 5762832a81dSGeoff Levand 5772832a81dSGeoff Levand /** 578dc4f60c2SGeoff Levand * ps3_spe_irq_setup - Setup an spe virq. 579861be32cSGeoff Levand * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be 580861be32cSGeoff Levand * serviced on. 5812832a81dSGeoff Levand * @spe_id: The spe_id returned from lv1_construct_logical_spe(). 5822832a81dSGeoff Levand * @class: The spe interrupt class {0,1,2}. 5832832a81dSGeoff Levand * @virq: The assigned Linux virq. 5842832a81dSGeoff Levand * 5852832a81dSGeoff Levand */ 5862832a81dSGeoff Levand 587dc4f60c2SGeoff Levand int ps3_spe_irq_setup(enum ps3_cpu_binding cpu, unsigned long spe_id, 588861be32cSGeoff Levand unsigned int class, unsigned int *virq) 5892832a81dSGeoff Levand { 5902832a81dSGeoff Levand int result; 591b17b3df1SStephen Rothwell u64 outlet; 5922832a81dSGeoff Levand 5932832a81dSGeoff Levand BUG_ON(class > 2); 5942832a81dSGeoff Levand 5952832a81dSGeoff Levand result = lv1_get_spe_irq_outlet(spe_id, class, &outlet); 5962832a81dSGeoff Levand 5972832a81dSGeoff Levand if (result) { 5982832a81dSGeoff Levand pr_debug("%s:%d: lv1_get_spe_irq_outlet failed: %s\n", 5992832a81dSGeoff Levand __func__, __LINE__, ps3_result(result)); 6002832a81dSGeoff Levand return result; 6012832a81dSGeoff Levand } 6022832a81dSGeoff Levand 603dc4f60c2SGeoff Levand result = ps3_irq_plug_setup(cpu, outlet, virq); 604861be32cSGeoff Levand BUG_ON(result); 6052832a81dSGeoff Levand 606861be32cSGeoff Levand return result; 6072832a81dSGeoff Levand } 6082832a81dSGeoff Levand 609dc4f60c2SGeoff Levand int ps3_spe_irq_destroy(unsigned int virq) 6102832a81dSGeoff Levand { 6119263e85aSGeoff Levand int result; 6129263e85aSGeoff Levand 6138126708aSLennert Buytenhek ps3_chip_mask(irq_get_irq_data(virq)); 6149263e85aSGeoff Levand 6159263e85aSGeoff Levand result = ps3_irq_plug_destroy(virq); 616dc4f60c2SGeoff Levand BUG_ON(result); 6179263e85aSGeoff Levand 6189263e85aSGeoff Levand return result; 6192832a81dSGeoff Levand } 6202832a81dSGeoff Levand 621b1eeb38eSGeert Uytterhoeven 6222832a81dSGeoff Levand #define PS3_INVALID_OUTLET ((irq_hw_number_t)-1) 6232832a81dSGeoff Levand #define PS3_PLUG_MAX 63 6242832a81dSGeoff Levand 6252832a81dSGeoff Levand #if defined(DEBUG) 626861be32cSGeoff Levand static void _dump_64_bmp(const char *header, const u64 *p, unsigned cpu, 6272832a81dSGeoff Levand const char* func, int line) 6282832a81dSGeoff Levand { 6292832a81dSGeoff Levand pr_debug("%s:%d: %s %u {%04lx_%04lx_%04lx_%04lx}\n", 6302832a81dSGeoff Levand func, line, header, cpu, 6312832a81dSGeoff Levand *p >> 48, (*p >> 32) & 0xffff, (*p >> 16) & 0xffff, 6322832a81dSGeoff Levand *p & 0xffff); 6332832a81dSGeoff Levand } 6342832a81dSGeoff Levand 635848cfdc5SGeoff Levand static void __maybe_unused _dump_256_bmp(const char *header, 636861be32cSGeoff Levand const u64 *p, unsigned cpu, const char* func, int line) 6372832a81dSGeoff Levand { 6382832a81dSGeoff Levand pr_debug("%s:%d: %s %u {%016lx:%016lx:%016lx:%016lx}\n", 6392832a81dSGeoff Levand func, line, header, cpu, p[0], p[1], p[2], p[3]); 6402832a81dSGeoff Levand } 6412832a81dSGeoff Levand 6422832a81dSGeoff Levand #define dump_bmp(_x) _dump_bmp(_x, __func__, __LINE__) 6439633ac8dSGeoff Levand static void _dump_bmp(struct ps3_private* pd, const char* func, int line) 6442832a81dSGeoff Levand { 6452832a81dSGeoff Levand unsigned long flags; 6462832a81dSGeoff Levand 6472832a81dSGeoff Levand spin_lock_irqsave(&pd->bmp.lock, flags); 648aab83500SGeoff Levand _dump_64_bmp("stat", &pd->bmp.status, pd->thread_id, func, line); 649aab83500SGeoff Levand _dump_64_bmp("mask", &pd->bmp.mask, pd->thread_id, func, line); 6502832a81dSGeoff Levand spin_unlock_irqrestore(&pd->bmp.lock, flags); 6512832a81dSGeoff Levand } 6522832a81dSGeoff Levand 6532832a81dSGeoff Levand #define dump_mask(_x) _dump_mask(_x, __func__, __LINE__) 654848cfdc5SGeoff Levand static void __maybe_unused _dump_mask(struct ps3_private *pd, 6552832a81dSGeoff Levand const char* func, int line) 6562832a81dSGeoff Levand { 6572832a81dSGeoff Levand unsigned long flags; 6582832a81dSGeoff Levand 6592832a81dSGeoff Levand spin_lock_irqsave(&pd->bmp.lock, flags); 660aab83500SGeoff Levand _dump_64_bmp("mask", &pd->bmp.mask, pd->thread_id, func, line); 6612832a81dSGeoff Levand spin_unlock_irqrestore(&pd->bmp.lock, flags); 6622832a81dSGeoff Levand } 6632832a81dSGeoff Levand #else 6649633ac8dSGeoff Levand static void dump_bmp(struct ps3_private* pd) {}; 6652832a81dSGeoff Levand #endif /* defined(DEBUG) */ 6662832a81dSGeoff Levand 6679633ac8dSGeoff Levand static int ps3_host_map(struct irq_host *h, unsigned int virq, 6682832a81dSGeoff Levand irq_hw_number_t hwirq) 6692832a81dSGeoff Levand { 670861be32cSGeoff Levand pr_debug("%s:%d: hwirq %lu, virq %u\n", __func__, __LINE__, hwirq, 671861be32cSGeoff Levand virq); 6722832a81dSGeoff Levand 673ec775d0eSThomas Gleixner irq_set_chip_and_handler(virq, &ps3_irq_chip, handle_fasteoi_irq); 6742832a81dSGeoff Levand 675861be32cSGeoff Levand return 0; 6762832a81dSGeoff Levand } 6772832a81dSGeoff Levand 6788528ab84SMichael Ellerman static int ps3_host_match(struct irq_host *h, struct device_node *np) 6798528ab84SMichael Ellerman { 6808528ab84SMichael Ellerman /* Match all */ 6818528ab84SMichael Ellerman return 1; 6828528ab84SMichael Ellerman } 6838528ab84SMichael Ellerman 6849633ac8dSGeoff Levand static struct irq_host_ops ps3_host_ops = { 6859633ac8dSGeoff Levand .map = ps3_host_map, 6868528ab84SMichael Ellerman .match = ps3_host_match, 6872832a81dSGeoff Levand }; 6882832a81dSGeoff Levand 6892832a81dSGeoff Levand void __init ps3_register_ipi_debug_brk(unsigned int cpu, unsigned int virq) 6902832a81dSGeoff Levand { 6919633ac8dSGeoff Levand struct ps3_private *pd = &per_cpu(ps3_private, cpu); 6922832a81dSGeoff Levand 6932832a81dSGeoff Levand pd->bmp.ipi_debug_brk_mask = 0x8000000000000000UL >> virq; 6942832a81dSGeoff Levand 6955c949070SStephen Rothwell pr_debug("%s:%d: cpu %u, virq %u, mask %llxh\n", __func__, __LINE__, 6962832a81dSGeoff Levand cpu, virq, pd->bmp.ipi_debug_brk_mask); 6972832a81dSGeoff Levand } 6982832a81dSGeoff Levand 699*72f3bea0SGeoff Levand void __init ps3_register_ipi_irq(unsigned int cpu, unsigned int virq) 700*72f3bea0SGeoff Levand { 701*72f3bea0SGeoff Levand struct ps3_private *pd = &per_cpu(ps3_private, cpu); 702*72f3bea0SGeoff Levand 703*72f3bea0SGeoff Levand set_bit(63 - virq, &pd->ipi_mask); 704*72f3bea0SGeoff Levand 705*72f3bea0SGeoff Levand DBG("%s:%d: cpu %u, virq %u, ipi_mask %lxh\n", __func__, __LINE__, 706*72f3bea0SGeoff Levand cpu, virq, pd->ipi_mask); 707*72f3bea0SGeoff Levand } 708*72f3bea0SGeoff Levand 7099263e85aSGeoff Levand static unsigned int ps3_get_irq(void) 7102832a81dSGeoff Levand { 7119cf9e196SBenjamin Herrenschmidt struct ps3_private *pd = &__get_cpu_var(ps3_private); 712861be32cSGeoff Levand u64 x = (pd->bmp.status & pd->bmp.mask); 7139cf9e196SBenjamin Herrenschmidt unsigned int plug; 7142832a81dSGeoff Levand 7152832a81dSGeoff Levand /* check for ipi break first to stop this cpu ASAP */ 7162832a81dSGeoff Levand 7179cf9e196SBenjamin Herrenschmidt if (x & pd->bmp.ipi_debug_brk_mask) 7189cf9e196SBenjamin Herrenschmidt x &= pd->bmp.ipi_debug_brk_mask; 7192832a81dSGeoff Levand 7209cf9e196SBenjamin Herrenschmidt asm volatile("cntlzd %0,%1" : "=r" (plug) : "r" (x)); 7219cf9e196SBenjamin Herrenschmidt plug &= 0x3f; 7222832a81dSGeoff Levand 723ad18c3dbSRoel Kluin if (unlikely(plug == NO_IRQ)) { 7245c949070SStephen Rothwell pr_debug("%s:%d: no plug found: thread_id %llu\n", __func__, 725aab83500SGeoff Levand __LINE__, pd->thread_id); 7269633ac8dSGeoff Levand dump_bmp(&per_cpu(ps3_private, 0)); 7279633ac8dSGeoff Levand dump_bmp(&per_cpu(ps3_private, 1)); 7282832a81dSGeoff Levand return NO_IRQ; 7292832a81dSGeoff Levand } 7302832a81dSGeoff Levand 7312832a81dSGeoff Levand #if defined(DEBUG) 7329cf9e196SBenjamin Herrenschmidt if (unlikely(plug < NUM_ISA_INTERRUPTS || plug > PS3_PLUG_MAX)) { 7339633ac8dSGeoff Levand dump_bmp(&per_cpu(ps3_private, 0)); 7349633ac8dSGeoff Levand dump_bmp(&per_cpu(ps3_private, 1)); 7352832a81dSGeoff Levand BUG(); 7362832a81dSGeoff Levand } 7372832a81dSGeoff Levand #endif 738*72f3bea0SGeoff Levand 739*72f3bea0SGeoff Levand /* IPIs are EOIed here. */ 740*72f3bea0SGeoff Levand 741*72f3bea0SGeoff Levand if (test_bit(63 - plug, &pd->ipi_mask)) 742*72f3bea0SGeoff Levand lv1_end_of_interrupt_ext(pd->ppe_id, pd->thread_id, plug); 743*72f3bea0SGeoff Levand 7442832a81dSGeoff Levand return plug; 7452832a81dSGeoff Levand } 7462832a81dSGeoff Levand 7472832a81dSGeoff Levand void __init ps3_init_IRQ(void) 7482832a81dSGeoff Levand { 7492832a81dSGeoff Levand int result; 7502832a81dSGeoff Levand unsigned cpu; 7512832a81dSGeoff Levand struct irq_host *host; 7522832a81dSGeoff Levand 75352964f87SMichael Ellerman host = irq_alloc_host(NULL, IRQ_HOST_MAP_NOMAP, 0, &ps3_host_ops, 7542832a81dSGeoff Levand PS3_INVALID_OUTLET); 7552832a81dSGeoff Levand irq_set_default_host(host); 7562832a81dSGeoff Levand irq_set_virq_count(PS3_PLUG_MAX + 1); 7572832a81dSGeoff Levand 7582832a81dSGeoff Levand for_each_possible_cpu(cpu) { 7599633ac8dSGeoff Levand struct ps3_private *pd = &per_cpu(ps3_private, cpu); 7602832a81dSGeoff Levand 761aab83500SGeoff Levand lv1_get_logical_ppe_id(&pd->ppe_id); 762aab83500SGeoff Levand pd->thread_id = get_hard_smp_processor_id(cpu); 7632832a81dSGeoff Levand spin_lock_init(&pd->bmp.lock); 7642832a81dSGeoff Levand 7655c949070SStephen Rothwell pr_debug("%s:%d: ppe_id %llu, thread_id %llu, bmp %lxh\n", 766aab83500SGeoff Levand __func__, __LINE__, pd->ppe_id, pd->thread_id, 767407e24a0SGeoff Levand ps3_mm_phys_to_lpar(__pa(&pd->bmp))); 768407e24a0SGeoff Levand 769aab83500SGeoff Levand result = lv1_configure_irq_state_bitmap(pd->ppe_id, 770aab83500SGeoff Levand pd->thread_id, ps3_mm_phys_to_lpar(__pa(&pd->bmp))); 7712832a81dSGeoff Levand 7722832a81dSGeoff Levand if (result) 7732832a81dSGeoff Levand pr_debug("%s:%d: lv1_configure_irq_state_bitmap failed:" 7742832a81dSGeoff Levand " %s\n", __func__, __LINE__, 7752832a81dSGeoff Levand ps3_result(result)); 7762832a81dSGeoff Levand } 7772832a81dSGeoff Levand 7782832a81dSGeoff Levand ppc_md.get_irq = ps3_get_irq; 7792832a81dSGeoff Levand } 7809263e85aSGeoff Levand 7819263e85aSGeoff Levand void ps3_shutdown_IRQ(int cpu) 7829263e85aSGeoff Levand { 7839263e85aSGeoff Levand int result; 7849263e85aSGeoff Levand u64 ppe_id; 7859263e85aSGeoff Levand u64 thread_id = get_hard_smp_processor_id(cpu); 7869263e85aSGeoff Levand 7879263e85aSGeoff Levand lv1_get_logical_ppe_id(&ppe_id); 7889263e85aSGeoff Levand result = lv1_configure_irq_state_bitmap(ppe_id, thread_id, 0); 7899263e85aSGeoff Levand 7905c949070SStephen Rothwell DBG("%s:%d: lv1_configure_irq_state_bitmap (%llu:%llu/%d) %s\n", __func__, 7919263e85aSGeoff Levand __LINE__, ppe_id, thread_id, cpu, ps3_result(result)); 7929263e85aSGeoff Levand } 793