Path: blob/master/arch/powerpc/platforms/iseries/irq.c
10820 views
/*1* This module supports the iSeries PCI bus interrupt handling2* Copyright (C) 20yy <Robert L Holtorf> <IBM Corp>3* Copyright (C) 2004-2005 IBM Corporation4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the:17* Free Software Foundation, Inc.,18* 59 Temple Place, Suite 330,19* Boston, MA 02111-1307 USA20*21* Change Activity:22* Created, December 13, 2000 by Wayne Holm23* End Change Activity24*/25#include <linux/pci.h>26#include <linux/init.h>27#include <linux/threads.h>28#include <linux/smp.h>29#include <linux/param.h>30#include <linux/string.h>31#include <linux/bootmem.h>32#include <linux/irq.h>33#include <linux/spinlock.h>3435#include <asm/paca.h>36#include <asm/iseries/hv_types.h>37#include <asm/iseries/hv_lp_event.h>38#include <asm/iseries/hv_call_xm.h>39#include <asm/iseries/it_lp_queue.h>4041#include "irq.h"42#include "pci.h"43#include "call_pci.h"4445#ifdef CONFIG_PCI4647enum pci_event_type {48pe_bus_created = 0, /* PHB has been created */49pe_bus_error = 1, /* PHB has failed */50pe_bus_failed = 2, /* Msg to Secondary, Primary failed bus */51pe_node_failed = 4, /* Multi-adapter bridge has failed */52pe_node_recovered = 5, /* Multi-adapter bridge has recovered */53pe_bus_recovered = 12, /* PHB has been recovered */54pe_unquiese_bus = 18, /* Secondary bus unqiescing */55pe_bridge_error = 21, /* Bridge Error */56pe_slot_interrupt = 22 /* Slot interrupt */57};5859struct pci_event {60struct HvLpEvent event;61union {62u64 __align; /* Align on an 8-byte boundary */63struct {64u32 fisr;65HvBusNumber bus_number;66HvSubBusNumber sub_bus_number;67HvAgentId dev_id;68} slot;69struct {70HvBusNumber bus_number;71HvSubBusNumber sub_bus_number;72} bus;73struct {74HvBusNumber bus_number;75HvSubBusNumber sub_bus_number;76HvAgentId dev_id;77} node;78} data;79};8081static DEFINE_SPINLOCK(pending_irqs_lock);82static int num_pending_irqs;83static int pending_irqs[NR_IRQS];8485static void int_received(struct pci_event *event)86{87int irq;8889switch (event->event.xSubtype) {90case pe_slot_interrupt:91irq = event->event.xCorrelationToken;92if (irq < NR_IRQS) {93spin_lock(&pending_irqs_lock);94pending_irqs[irq]++;95num_pending_irqs++;96spin_unlock(&pending_irqs_lock);97} else {98printk(KERN_WARNING "int_received: bad irq number %d\n",99irq);100HvCallPci_eoi(event->data.slot.bus_number,101event->data.slot.sub_bus_number,102event->data.slot.dev_id);103}104break;105/* Ignore error recovery events for now */106case pe_bus_created:107printk(KERN_INFO "int_received: system bus %d created\n",108event->data.bus.bus_number);109break;110case pe_bus_error:111case pe_bus_failed:112printk(KERN_INFO "int_received: system bus %d failed\n",113event->data.bus.bus_number);114break;115case pe_bus_recovered:116case pe_unquiese_bus:117printk(KERN_INFO "int_received: system bus %d recovered\n",118event->data.bus.bus_number);119break;120case pe_node_failed:121case pe_bridge_error:122printk(KERN_INFO123"int_received: multi-adapter bridge %d/%d/%d failed\n",124event->data.node.bus_number,125event->data.node.sub_bus_number,126event->data.node.dev_id);127break;128case pe_node_recovered:129printk(KERN_INFO130"int_received: multi-adapter bridge %d/%d/%d recovered\n",131event->data.node.bus_number,132event->data.node.sub_bus_number,133event->data.node.dev_id);134break;135default:136printk(KERN_ERR137"int_received: unrecognized event subtype 0x%x\n",138event->event.xSubtype);139break;140}141}142143static void pci_event_handler(struct HvLpEvent *event)144{145if (event && (event->xType == HvLpEvent_Type_PciIo)) {146if (hvlpevent_is_int(event))147int_received((struct pci_event *)event);148else149printk(KERN_ERR150"pci_event_handler: unexpected ack received\n");151} else if (event)152printk(KERN_ERR153"pci_event_handler: Unrecognized PCI event type 0x%x\n",154(int)event->xType);155else156printk(KERN_ERR "pci_event_handler: NULL event received\n");157}158159#define REAL_IRQ_TO_SUBBUS(irq) (((irq) >> 14) & 0xff)160#define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1)161#define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1)162#define REAL_IRQ_TO_FUNC(irq) ((irq) & 7)163164/*165* This will be called by device drivers (via enable_IRQ)166* to enable INTA in the bridge interrupt status register.167*/168static void iseries_enable_IRQ(struct irq_data *d)169{170u32 bus, dev_id, function, mask;171const u32 sub_bus = 0;172unsigned int rirq = (unsigned int)irqd_to_hwirq(d);173174/* The IRQ has already been locked by the caller */175bus = REAL_IRQ_TO_BUS(rirq);176function = REAL_IRQ_TO_FUNC(rirq);177dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;178179/* Unmask secondary INTA */180mask = 0x80000000;181HvCallPci_unmaskInterrupts(bus, sub_bus, dev_id, mask);182}183184/* This is called by iseries_activate_IRQs */185static unsigned int iseries_startup_IRQ(struct irq_data *d)186{187u32 bus, dev_id, function, mask;188const u32 sub_bus = 0;189unsigned int rirq = (unsigned int)irqd_to_hwirq(d);190191bus = REAL_IRQ_TO_BUS(rirq);192function = REAL_IRQ_TO_FUNC(rirq);193dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;194195/* Link the IRQ number to the bridge */196HvCallXm_connectBusUnit(bus, sub_bus, dev_id, d->irq);197198/* Unmask bridge interrupts in the FISR */199mask = 0x01010000 << function;200HvCallPci_unmaskFisr(bus, sub_bus, dev_id, mask);201iseries_enable_IRQ(d);202return 0;203}204205/*206* This is called out of iSeries_fixup to activate interrupt207* generation for usable slots208*/209void __init iSeries_activate_IRQs()210{211int irq;212unsigned long flags;213214for_each_irq (irq) {215struct irq_desc *desc = irq_to_desc(irq);216struct irq_chip *chip;217218if (!desc)219continue;220221chip = irq_desc_get_chip(desc);222if (chip && chip->irq_startup) {223raw_spin_lock_irqsave(&desc->lock, flags);224chip->irq_startup(&desc->irq_data);225raw_spin_unlock_irqrestore(&desc->lock, flags);226}227}228}229230/* this is not called anywhere currently */231static void iseries_shutdown_IRQ(struct irq_data *d)232{233u32 bus, dev_id, function, mask;234const u32 sub_bus = 0;235unsigned int rirq = (unsigned int)irqd_to_hwirq(d);236237/* irq should be locked by the caller */238bus = REAL_IRQ_TO_BUS(rirq);239function = REAL_IRQ_TO_FUNC(rirq);240dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;241242/* Invalidate the IRQ number in the bridge */243HvCallXm_connectBusUnit(bus, sub_bus, dev_id, 0);244245/* Mask bridge interrupts in the FISR */246mask = 0x01010000 << function;247HvCallPci_maskFisr(bus, sub_bus, dev_id, mask);248}249250/*251* This will be called by device drivers (via disable_IRQ)252* to disable INTA in the bridge interrupt status register.253*/254static void iseries_disable_IRQ(struct irq_data *d)255{256u32 bus, dev_id, function, mask;257const u32 sub_bus = 0;258unsigned int rirq = (unsigned int)irqd_to_hwirq(d);259260/* The IRQ has already been locked by the caller */261bus = REAL_IRQ_TO_BUS(rirq);262function = REAL_IRQ_TO_FUNC(rirq);263dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;264265/* Mask secondary INTA */266mask = 0x80000000;267HvCallPci_maskInterrupts(bus, sub_bus, dev_id, mask);268}269270static void iseries_end_IRQ(struct irq_data *d)271{272unsigned int rirq = (unsigned int)irqd_to_hwirq(d);273274HvCallPci_eoi(REAL_IRQ_TO_BUS(rirq), REAL_IRQ_TO_SUBBUS(rirq),275(REAL_IRQ_TO_IDSEL(rirq) << 4) + REAL_IRQ_TO_FUNC(rirq));276}277278static struct irq_chip iseries_pic = {279.name = "iSeries",280.irq_startup = iseries_startup_IRQ,281.irq_shutdown = iseries_shutdown_IRQ,282.irq_unmask = iseries_enable_IRQ,283.irq_mask = iseries_disable_IRQ,284.irq_eoi = iseries_end_IRQ285};286287/*288* This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot289* It calculates the irq value for the slot.290* Note that sub_bus is always 0 (at the moment at least).291*/292int __init iSeries_allocate_IRQ(HvBusNumber bus,293HvSubBusNumber sub_bus, u32 bsubbus)294{295unsigned int realirq;296u8 idsel = ISERIES_GET_DEVICE_FROM_SUBBUS(bsubbus);297u8 function = ISERIES_GET_FUNCTION_FROM_SUBBUS(bsubbus);298299realirq = (((((sub_bus << 8) + (bus - 1)) << 3) + (idsel - 1)) << 3)300+ function;301302return irq_create_mapping(NULL, realirq);303}304305#endif /* CONFIG_PCI */306307/*308* Get the next pending IRQ.309*/310unsigned int iSeries_get_irq(void)311{312int irq = NO_IRQ_IGNORE;313314#ifdef CONFIG_SMP315if (get_lppaca()->int_dword.fields.ipi_cnt) {316get_lppaca()->int_dword.fields.ipi_cnt = 0;317smp_ipi_demux();318}319#endif /* CONFIG_SMP */320if (hvlpevent_is_pending())321process_hvlpevents();322323#ifdef CONFIG_PCI324if (num_pending_irqs) {325spin_lock(&pending_irqs_lock);326for (irq = 0; irq < NR_IRQS; irq++) {327if (pending_irqs[irq]) {328pending_irqs[irq]--;329num_pending_irqs--;330break;331}332}333spin_unlock(&pending_irqs_lock);334if (irq >= NR_IRQS)335irq = NO_IRQ_IGNORE;336}337#endif338339return irq;340}341342#ifdef CONFIG_PCI343344static int iseries_irq_host_map(struct irq_host *h, unsigned int virq,345irq_hw_number_t hw)346{347irq_set_chip_and_handler(virq, &iseries_pic, handle_fasteoi_irq);348349return 0;350}351352static int iseries_irq_host_match(struct irq_host *h, struct device_node *np)353{354/* Match all */355return 1;356}357358static struct irq_host_ops iseries_irq_host_ops = {359.map = iseries_irq_host_map,360.match = iseries_irq_host_match,361};362363/*364* This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c365* It must be called before the bus walk.366*/367void __init iSeries_init_IRQ(void)368{369/* Register PCI event handler and open an event path */370struct irq_host *host;371int ret;372373/*374* The Hypervisor only allows us up to 256 interrupt375* sources (the irq number is passed in a u8).376*/377irq_set_virq_count(256);378379/* Create irq host. No need for a revmap since HV will give us380* back our virtual irq number381*/382host = irq_alloc_host(NULL, IRQ_HOST_MAP_NOMAP, 0,383&iseries_irq_host_ops, 0);384BUG_ON(host == NULL);385irq_set_default_host(host);386387ret = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,388&pci_event_handler);389if (ret == 0) {390ret = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);391if (ret != 0)392printk(KERN_ERR "iseries_init_IRQ: open event path "393"failed with rc 0x%x\n", ret);394} else395printk(KERN_ERR "iseries_init_IRQ: register handler "396"failed with rc 0x%x\n", ret);397}398399#endif /* CONFIG_PCI */400401402