2015-05-15 12:06:37 +08:00
|
|
|
/*
|
|
|
|
* This file implements an irqchip for OPAL events. Whenever there is
|
|
|
|
* an interrupt that is handled by OPAL we get passed a list of events
|
|
|
|
* that Linux needs to do something about. These basically look like
|
|
|
|
* interrupts to Linux so we implement an irqchip to handle them.
|
|
|
|
*
|
|
|
|
* Copyright Alistair Popple, IBM Corporation 2014.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*/
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/irqchip.h>
|
|
|
|
#include <linux/irqdomain.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/kthread.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/irq_work.h>
|
|
|
|
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/opal.h>
|
|
|
|
|
|
|
|
#include "powernv.h"
|
|
|
|
|
|
|
|
/* Maximum number of events supported by OPAL firmware */
|
|
|
|
#define MAX_NUM_EVENTS 64
|
|
|
|
|
|
|
|
struct opal_event_irqchip {
|
|
|
|
struct irq_chip irqchip;
|
|
|
|
struct irq_domain *domain;
|
|
|
|
unsigned long mask;
|
|
|
|
};
|
|
|
|
static struct opal_event_irqchip opal_event_irqchip;
|
|
|
|
|
|
|
|
static unsigned int opal_irq_count;
|
|
|
|
static unsigned int *opal_irqs;
|
|
|
|
|
|
|
|
static void opal_handle_irq_work(struct irq_work *work);
|
2015-12-07 08:28:28 +08:00
|
|
|
static u64 last_outstanding_events;
|
2015-05-15 12:06:37 +08:00
|
|
|
static struct irq_work opal_event_irq_work = {
|
|
|
|
.func = opal_handle_irq_work,
|
|
|
|
};
|
|
|
|
|
2015-12-07 08:28:28 +08:00
|
|
|
void opal_handle_events(uint64_t events)
|
|
|
|
{
|
|
|
|
int virq, hwirq = 0;
|
|
|
|
u64 mask = opal_event_irqchip.mask;
|
|
|
|
|
|
|
|
if (!in_irq() && (events & mask)) {
|
|
|
|
last_outstanding_events = events;
|
|
|
|
irq_work_queue(&opal_event_irq_work);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (events & mask) {
|
|
|
|
hwirq = fls64(events) - 1;
|
|
|
|
if (BIT_ULL(hwirq) & mask) {
|
|
|
|
virq = irq_find_mapping(opal_event_irqchip.domain,
|
|
|
|
hwirq);
|
|
|
|
if (virq)
|
|
|
|
generic_handle_irq(virq);
|
|
|
|
}
|
|
|
|
events &= ~BIT_ULL(hwirq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-15 12:06:37 +08:00
|
|
|
static void opal_event_mask(struct irq_data *d)
|
|
|
|
{
|
|
|
|
clear_bit(d->hwirq, &opal_event_irqchip.mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void opal_event_unmask(struct irq_data *d)
|
|
|
|
{
|
2015-12-07 08:28:28 +08:00
|
|
|
__be64 events;
|
|
|
|
|
2015-05-15 12:06:37 +08:00
|
|
|
set_bit(d->hwirq, &opal_event_irqchip.mask);
|
|
|
|
|
2015-12-07 08:28:28 +08:00
|
|
|
opal_poll_events(&events);
|
powerpc/opal-irqchip: Fix deadlock introduced by "Fix double endian conversion"
Commit 25642e1459ac ("powerpc/opal-irqchip: Fix double endian
conversion") fixed an endian bug by calling opal_handle_events() in
opal_event_unmask().
However this introduced a deadlock if we find an event is active
during unmasking and call opal_handle_events() again. The bad call
sequence is:
opal_interrupt()
-> opal_handle_events()
-> generic_handle_irq()
-> handle_level_irq()
-> raw_spin_lock(&desc->lock)
handle_irq_event(desc)
unmask_irq(desc)
-> opal_event_unmask()
-> opal_handle_events()
-> generic_handle_irq()
-> handle_level_irq()
-> raw_spin_lock(&desc->lock) (BOOM)
When generating multiple opal events in quick succession this would lead
to the following stall warnings:
EEH: Fenced PHB#0 detected, location: U78C9.001.WZS09XA-P1-C32
INFO: rcu_sched detected stalls on CPUs/tasks:
12-...: (1 GPs behind) idle=68f/140000000000001/0 softirq=860/861 fqs=2065
15-...: (1 GPs behind) idle=be5/140000000000001/0 softirq=1142/1143 fqs=2065
(detected by 13, t=2102 jiffies, g=1325, c=1324, q=602)
NMI watchdog: BUG: soft lockup - CPU#18 stuck for 22s! [irqbalance:2696]
INFO: rcu_sched detected stalls on CPUs/tasks:
12-...: (1 GPs behind) idle=68f/140000000000001/0 softirq=860/861 fqs=8371
15-...: (1 GPs behind) idle=be5/140000000000001/0 softirq=1142/1143 fqs=8371
(detected by 20, t=8407 jiffies, g=1325, c=1324, q=1290)
This patch corrects the problem by queuing the work if an event is
active during unmasking, which is similar to the pre-endian fix
behaviour.
Fixes: 25642e1459ac ("powerpc/opal-irqchip: Fix double endian conversion")
Signed-off-by: Alistair Popple <alistair@popple.id.au>
Reported-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2015-12-18 14:16:17 +08:00
|
|
|
last_outstanding_events = be64_to_cpu(events);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can't just handle the events now with opal_handle_events().
|
|
|
|
* If we did we would deadlock when opal_event_unmask() is called from
|
|
|
|
* handle_level_irq() with the irq descriptor lock held, because
|
|
|
|
* calling opal_handle_events() would call generic_handle_irq() and
|
|
|
|
* then handle_level_irq() which would try to take the descriptor lock
|
|
|
|
* again. Instead queue the events for later.
|
|
|
|
*/
|
|
|
|
if (last_outstanding_events & opal_event_irqchip.mask)
|
|
|
|
/* Need to retrigger the interrupt */
|
|
|
|
irq_work_queue(&opal_event_irq_work);
|
2015-05-15 12:06:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int opal_event_set_type(struct irq_data *d, unsigned int flow_type)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* For now we only support level triggered events. The irq
|
|
|
|
* handler will be called continuously until the event has
|
|
|
|
* been cleared in OPAL.
|
|
|
|
*/
|
|
|
|
if (flow_type != IRQ_TYPE_LEVEL_HIGH)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct opal_event_irqchip opal_event_irqchip = {
|
|
|
|
.irqchip = {
|
|
|
|
.name = "OPAL EVT",
|
|
|
|
.irq_mask = opal_event_mask,
|
|
|
|
.irq_unmask = opal_event_unmask,
|
|
|
|
.irq_set_type = opal_event_set_type,
|
|
|
|
},
|
|
|
|
.mask = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int opal_event_map(struct irq_domain *d, unsigned int irq,
|
|
|
|
irq_hw_number_t hwirq)
|
|
|
|
{
|
|
|
|
irq_set_chip_data(irq, &opal_event_irqchip);
|
|
|
|
irq_set_chip_and_handler(irq, &opal_event_irqchip.irqchip,
|
|
|
|
handle_level_irq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t opal_interrupt(int irq, void *data)
|
|
|
|
{
|
|
|
|
__be64 events;
|
|
|
|
|
|
|
|
opal_handle_interrupt(virq_to_hw(irq), &events);
|
|
|
|
opal_handle_events(be64_to_cpu(events));
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void opal_handle_irq_work(struct irq_work *work)
|
|
|
|
{
|
2015-12-07 08:28:28 +08:00
|
|
|
opal_handle_events(last_outstanding_events);
|
2015-05-15 12:06:37 +08:00
|
|
|
}
|
|
|
|
|
genirq/irqdomain: Allow irq domain aliasing
It is not uncommon (at least with the ARM stuff) to have a piece
of hardware that implements different flavours of "interrupts".
A typical example of this is the GICv3 ITS, which implements
standard PCI/MSI support, but also some form of "generic MSI".
So far, the PCI/MSI domain is registered using the ITS device_node,
so that irq_find_host can return it. On the contrary, the raw MSI
domain is not registered with an device_node, making it impossible
to be looked up by another subsystem (obviously, using the same
device_node twice would only result in confusion, as it is not
defined which one irq_find_host would return).
A solution to this is to "type" domains that may be aliasing, and
to be able to lookup an device_node that matches a given type.
For this, we introduce irq_find_matching_host() as a superset
of irq_find_host:
struct irq_domain *irq_find_matching_host(struct device_node *node,
enum irq_domain_bus_token bus_token);
where bus_token is the "type" we want to match the domain against
(so far, only DOMAIN_BUS_ANY is defined). This result in some
moderately invasive changes on the PPC side (which is the only
user of the .match method).
This has otherwise no functionnal change.
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Cc: <linux-arm-kernel@lists.infradead.org>
Cc: Yijing Wang <wangyijing@huawei.com>
Cc: Ma Jun <majun258@huawei.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Duc Dang <dhdang@apm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Jiang Liu <jiang.liu@linux.intel.com>
Cc: Jason Cooper <jason@lakedaemon.net>
Link: http://lkml.kernel.org/r/1438091186-10244-2-git-send-email-marc.zyngier@arm.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2015-07-28 21:46:08 +08:00
|
|
|
static int opal_event_match(struct irq_domain *h, struct device_node *node,
|
|
|
|
enum irq_domain_bus_token bus_token)
|
2015-05-15 12:06:37 +08:00
|
|
|
{
|
2015-10-13 19:51:29 +08:00
|
|
|
return irq_domain_get_of_node(h) == node;
|
2015-05-15 12:06:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int opal_event_xlate(struct irq_domain *h, struct device_node *np,
|
|
|
|
const u32 *intspec, unsigned int intsize,
|
|
|
|
irq_hw_number_t *out_hwirq, unsigned int *out_flags)
|
|
|
|
{
|
|
|
|
*out_hwirq = intspec[0];
|
|
|
|
*out_flags = IRQ_TYPE_LEVEL_HIGH;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct irq_domain_ops opal_event_domain_ops = {
|
|
|
|
.match = opal_event_match,
|
|
|
|
.map = opal_event_map,
|
|
|
|
.xlate = opal_event_xlate,
|
|
|
|
};
|
|
|
|
|
|
|
|
void opal_event_shutdown(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* First free interrupts, which will also mask them */
|
|
|
|
for (i = 0; i < opal_irq_count; i++) {
|
|
|
|
if (opal_irqs[i])
|
|
|
|
free_irq(opal_irqs[i], NULL);
|
|
|
|
opal_irqs[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int __init opal_event_init(void)
|
|
|
|
{
|
|
|
|
struct device_node *dn, *opal_node;
|
2017-02-06 13:07:36 +08:00
|
|
|
const char **names;
|
|
|
|
u32 *irqs;
|
|
|
|
int i, rc;
|
2015-05-15 12:06:37 +08:00
|
|
|
|
|
|
|
opal_node = of_find_node_by_path("/ibm,opal");
|
|
|
|
if (!opal_node) {
|
|
|
|
pr_warn("opal: Node not found\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If dn is NULL it means the domain won't be linked to a DT
|
|
|
|
* node so therefore irq_of_parse_and_map(...) wont work. But
|
|
|
|
* that shouldn't be problem because if we're running a
|
|
|
|
* version of skiboot that doesn't have the dn then the
|
|
|
|
* devices won't have the correct properties and will have to
|
|
|
|
* fall back to the legacy method (opal_event_request(...))
|
|
|
|
* anyway. */
|
|
|
|
dn = of_find_compatible_node(NULL, NULL, "ibm,opal-event");
|
|
|
|
opal_event_irqchip.domain = irq_domain_add_linear(dn, MAX_NUM_EVENTS,
|
|
|
|
&opal_event_domain_ops, &opal_event_irqchip);
|
|
|
|
of_node_put(dn);
|
|
|
|
if (!opal_event_irqchip.domain) {
|
|
|
|
pr_warn("opal: Unable to create irq domain\n");
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-06 13:07:36 +08:00
|
|
|
/* Get opal-interrupts property and names if present */
|
|
|
|
rc = of_property_count_u32_elems(opal_node, "opal-interrupts");
|
|
|
|
if (rc < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
opal_irq_count = rc;
|
2015-05-15 12:06:37 +08:00
|
|
|
pr_debug("Found %d interrupts reserved for OPAL\n", opal_irq_count);
|
|
|
|
|
2017-02-06 13:07:36 +08:00
|
|
|
irqs = kcalloc(opal_irq_count, sizeof(*irqs), GFP_KERNEL);
|
|
|
|
names = kcalloc(opal_irq_count, sizeof(*names), GFP_KERNEL);
|
2015-05-15 12:06:37 +08:00
|
|
|
opal_irqs = kcalloc(opal_irq_count, sizeof(*opal_irqs), GFP_KERNEL);
|
2017-02-06 13:07:36 +08:00
|
|
|
|
|
|
|
if (WARN_ON(!irqs || !names || !opal_irqs))
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
rc = of_property_read_u32_array(opal_node, "opal-interrupts",
|
|
|
|
irqs, opal_irq_count);
|
|
|
|
if (rc < 0) {
|
|
|
|
pr_err("Error %d reading opal-interrupts array\n", rc);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* It's not an error for the names to be missing */
|
|
|
|
of_property_read_string_array(opal_node, "opal-interrupts-names",
|
|
|
|
names, opal_irq_count);
|
|
|
|
|
|
|
|
/* Install interrupt handlers */
|
|
|
|
for (i = 0; i < opal_irq_count; i++) {
|
|
|
|
unsigned int virq;
|
|
|
|
char *name;
|
2015-05-15 12:06:37 +08:00
|
|
|
|
|
|
|
/* Get hardware and virtual IRQ */
|
2017-02-06 13:07:36 +08:00
|
|
|
virq = irq_create_mapping(NULL, irqs[i]);
|
2016-09-06 19:53:24 +08:00
|
|
|
if (!virq) {
|
2017-02-06 13:07:36 +08:00
|
|
|
pr_warn("Failed to map irq 0x%x\n", irqs[i]);
|
2015-05-15 12:06:37 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-02-06 13:07:36 +08:00
|
|
|
if (names[i] && strlen(names[i]))
|
|
|
|
name = kasprintf(GFP_KERNEL, "opal-%s", names[i]);
|
|
|
|
else
|
|
|
|
name = kasprintf(GFP_KERNEL, "opal");
|
|
|
|
|
2015-05-15 12:06:37 +08:00
|
|
|
/* Install interrupt handler */
|
2016-08-02 10:39:43 +08:00
|
|
|
rc = request_irq(virq, opal_interrupt, IRQF_TRIGGER_LOW,
|
2017-02-06 13:07:36 +08:00
|
|
|
name, NULL);
|
2015-05-15 12:06:37 +08:00
|
|
|
if (rc) {
|
|
|
|
irq_dispose_mapping(virq);
|
|
|
|
pr_warn("Error %d requesting irq %d (0x%x)\n",
|
2017-02-06 13:07:36 +08:00
|
|
|
rc, virq, irqs[i]);
|
2015-05-15 12:06:37 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cache IRQ */
|
|
|
|
opal_irqs[i] = virq;
|
|
|
|
}
|
|
|
|
|
2017-02-06 13:07:36 +08:00
|
|
|
out_free:
|
|
|
|
kfree(irqs);
|
|
|
|
kfree(names);
|
2015-05-15 12:06:37 +08:00
|
|
|
out:
|
|
|
|
of_node_put(opal_node);
|
|
|
|
return rc;
|
|
|
|
}
|
2015-06-17 09:36:57 +08:00
|
|
|
machine_arch_initcall(powernv, opal_event_init);
|
2015-05-15 12:06:37 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* opal_event_request(unsigned int opal_event_nr) - Request an event
|
|
|
|
* @opal_event_nr: the opal event number to request
|
|
|
|
*
|
|
|
|
* This routine can be used to find the linux virq number which can
|
|
|
|
* then be passed to request_irq to assign a handler for a particular
|
|
|
|
* opal event. This should only be used by legacy devices which don't
|
|
|
|
* have proper device tree bindings. Most devices should use
|
|
|
|
* irq_of_parse_and_map() instead.
|
|
|
|
*/
|
|
|
|
int opal_event_request(unsigned int opal_event_nr)
|
|
|
|
{
|
2015-06-17 09:36:57 +08:00
|
|
|
if (WARN_ON_ONCE(!opal_event_irqchip.domain))
|
2016-09-06 19:53:24 +08:00
|
|
|
return 0;
|
2015-06-17 09:36:57 +08:00
|
|
|
|
2015-05-15 12:06:37 +08:00
|
|
|
return irq_create_mapping(opal_event_irqchip.domain, opal_event_nr);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(opal_event_request);
|