2008-10-02 10:18:21 -07:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* SGI UV IRQ functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Silicon Graphics, Inc. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
2009-09-30 09:02:59 -07:00
|
|
|
#include <linux/rbtree.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 01:04:11 -07:00
|
|
|
#include <linux/slab.h>
|
2008-10-02 10:18:21 -07:00
|
|
|
#include <linux/irq.h>
|
2008-10-03 02:38:37 -07:00
|
|
|
|
|
|
|
#include <asm/apic.h>
|
2008-10-02 10:18:21 -07:00
|
|
|
#include <asm/uv/uv_irq.h>
|
2009-09-30 09:02:59 -07:00
|
|
|
#include <asm/uv/uv_hub.h>
|
|
|
|
|
|
|
|
/* MMR offset and pnode of hub sourcing interrupts for a given irq */
|
|
|
|
struct uv_irq_2_mmr_pnode{
|
2009-10-13 13:32:36 -07:00
|
|
|
struct rb_node list;
|
|
|
|
unsigned long offset;
|
|
|
|
int pnode;
|
|
|
|
int irq;
|
2009-09-30 09:02:59 -07:00
|
|
|
};
|
2009-10-13 13:32:36 -07:00
|
|
|
|
|
|
|
static spinlock_t uv_irq_lock;
|
|
|
|
static struct rb_root uv_irq_root;
|
|
|
|
|
|
|
|
static int uv_set_irq_affinity(unsigned int, const struct cpumask *);
|
2008-10-02 10:18:21 -07:00
|
|
|
|
|
|
|
static void uv_noop(unsigned int irq)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int uv_noop_ret(unsigned int irq)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uv_ack_apic(unsigned int irq)
|
|
|
|
{
|
|
|
|
ack_APIC_irq();
|
|
|
|
}
|
|
|
|
|
2010-04-16 17:51:42 -07:00
|
|
|
static struct irq_chip uv_irq_chip = {
|
2008-10-02 10:18:21 -07:00
|
|
|
.name = "UV-CORE",
|
|
|
|
.startup = uv_noop_ret,
|
|
|
|
.shutdown = uv_noop,
|
|
|
|
.enable = uv_noop,
|
|
|
|
.disable = uv_noop,
|
|
|
|
.ack = uv_noop,
|
|
|
|
.mask = uv_noop,
|
|
|
|
.unmask = uv_noop,
|
|
|
|
.eoi = uv_ack_apic,
|
|
|
|
.end = uv_noop,
|
2009-09-30 09:02:59 -07:00
|
|
|
.set_affinity = uv_set_irq_affinity,
|
2008-10-02 10:18:21 -07:00
|
|
|
};
|
|
|
|
|
2009-09-30 09:02:59 -07:00
|
|
|
/*
|
|
|
|
* Add offset and pnode information of the hub sourcing interrupts to the
|
|
|
|
* rb tree for a specific irq.
|
|
|
|
*/
|
|
|
|
static int uv_set_irq_2_mmr_info(int irq, unsigned long offset, unsigned blade)
|
|
|
|
{
|
|
|
|
struct rb_node **link = &uv_irq_root.rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct uv_irq_2_mmr_pnode *n;
|
|
|
|
struct uv_irq_2_mmr_pnode *e;
|
|
|
|
unsigned long irqflags;
|
|
|
|
|
|
|
|
n = kmalloc_node(sizeof(struct uv_irq_2_mmr_pnode), GFP_KERNEL,
|
|
|
|
uv_blade_to_memory_nid(blade));
|
|
|
|
if (!n)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
n->irq = irq;
|
|
|
|
n->offset = offset;
|
|
|
|
n->pnode = uv_blade_to_pnode(blade);
|
|
|
|
spin_lock_irqsave(&uv_irq_lock, irqflags);
|
|
|
|
/* Find the right place in the rbtree: */
|
|
|
|
while (*link) {
|
|
|
|
parent = *link;
|
|
|
|
e = rb_entry(parent, struct uv_irq_2_mmr_pnode, list);
|
|
|
|
|
|
|
|
if (unlikely(irq == e->irq)) {
|
|
|
|
/* irq entry exists */
|
|
|
|
e->pnode = uv_blade_to_pnode(blade);
|
|
|
|
e->offset = offset;
|
|
|
|
spin_unlock_irqrestore(&uv_irq_lock, irqflags);
|
|
|
|
kfree(n);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (irq < e->irq)
|
|
|
|
link = &(*link)->rb_left;
|
|
|
|
else
|
|
|
|
link = &(*link)->rb_right;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert the node into the rbtree. */
|
|
|
|
rb_link_node(&n->list, parent, link);
|
|
|
|
rb_insert_color(&n->list, &uv_irq_root);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&uv_irq_lock, irqflags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve offset and pnode information from the rb tree for a specific irq */
|
|
|
|
int uv_irq_2_mmr_info(int irq, unsigned long *offset, int *pnode)
|
|
|
|
{
|
|
|
|
struct uv_irq_2_mmr_pnode *e;
|
|
|
|
struct rb_node *n;
|
|
|
|
unsigned long irqflags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&uv_irq_lock, irqflags);
|
|
|
|
n = uv_irq_root.rb_node;
|
|
|
|
while (n) {
|
|
|
|
e = rb_entry(n, struct uv_irq_2_mmr_pnode, list);
|
|
|
|
|
|
|
|
if (e->irq == irq) {
|
|
|
|
*offset = e->offset;
|
|
|
|
*pnode = e->pnode;
|
|
|
|
spin_unlock_irqrestore(&uv_irq_lock, irqflags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (irq < e->irq)
|
|
|
|
n = n->rb_left;
|
|
|
|
else
|
|
|
|
n = n->rb_right;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&uv_irq_lock, irqflags);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-10-13 13:32:36 -07:00
|
|
|
/*
|
|
|
|
* Re-target the irq to the specified CPU and enable the specified MMR located
|
|
|
|
* on the specified blade to allow the sending of MSIs to the specified CPU.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
arch_enable_uv_irq(char *irq_name, unsigned int irq, int cpu, int mmr_blade,
|
2010-04-16 17:51:42 -07:00
|
|
|
unsigned long mmr_offset, int limit)
|
2009-10-13 13:32:36 -07:00
|
|
|
{
|
|
|
|
const struct cpumask *eligible_cpu = cpumask_of(cpu);
|
|
|
|
struct irq_desc *desc = irq_to_desc(irq);
|
|
|
|
struct irq_cfg *cfg;
|
|
|
|
int mmr_pnode;
|
|
|
|
unsigned long mmr_value;
|
|
|
|
struct uv_IO_APIC_route_entry *entry;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(sizeof(struct uv_IO_APIC_route_entry) !=
|
|
|
|
sizeof(unsigned long));
|
|
|
|
|
|
|
|
cfg = irq_cfg(irq);
|
|
|
|
|
|
|
|
err = assign_irq_vector(irq, cfg, eligible_cpu);
|
|
|
|
if (err != 0)
|
|
|
|
return err;
|
|
|
|
|
2010-04-16 17:51:42 -07:00
|
|
|
if (limit == UV_AFFINITY_CPU)
|
2009-10-13 13:32:36 -07:00
|
|
|
desc->status |= IRQ_NO_BALANCING;
|
|
|
|
else
|
|
|
|
desc->status |= IRQ_MOVE_PCNTXT;
|
|
|
|
|
|
|
|
set_irq_chip_and_handler_name(irq, &uv_irq_chip, handle_percpu_irq,
|
|
|
|
irq_name);
|
|
|
|
|
|
|
|
mmr_value = 0;
|
|
|
|
entry = (struct uv_IO_APIC_route_entry *)&mmr_value;
|
|
|
|
entry->vector = cfg->vector;
|
|
|
|
entry->delivery_mode = apic->irq_delivery_mode;
|
|
|
|
entry->dest_mode = apic->irq_dest_mode;
|
|
|
|
entry->polarity = 0;
|
|
|
|
entry->trigger = 0;
|
|
|
|
entry->mask = 0;
|
|
|
|
entry->dest = apic->cpu_mask_to_apicid(eligible_cpu);
|
|
|
|
|
|
|
|
mmr_pnode = uv_blade_to_pnode(mmr_blade);
|
|
|
|
uv_write_global_mmr64(mmr_pnode, mmr_offset, mmr_value);
|
|
|
|
|
|
|
|
if (cfg->move_in_progress)
|
|
|
|
send_cleanup_vector(cfg);
|
|
|
|
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable the specified MMR located on the specified blade so that MSIs are
|
|
|
|
* longer allowed to be sent.
|
|
|
|
*/
|
|
|
|
static void arch_disable_uv_irq(int mmr_pnode, unsigned long mmr_offset)
|
|
|
|
{
|
|
|
|
unsigned long mmr_value;
|
|
|
|
struct uv_IO_APIC_route_entry *entry;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(sizeof(struct uv_IO_APIC_route_entry) !=
|
|
|
|
sizeof(unsigned long));
|
|
|
|
|
|
|
|
mmr_value = 0;
|
|
|
|
entry = (struct uv_IO_APIC_route_entry *)&mmr_value;
|
|
|
|
entry->mask = 1;
|
|
|
|
|
|
|
|
uv_write_global_mmr64(mmr_pnode, mmr_offset, mmr_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int uv_set_irq_affinity(unsigned int irq, const struct cpumask *mask)
|
|
|
|
{
|
|
|
|
struct irq_desc *desc = irq_to_desc(irq);
|
|
|
|
struct irq_cfg *cfg = desc->chip_data;
|
|
|
|
unsigned int dest;
|
|
|
|
unsigned long mmr_value;
|
|
|
|
struct uv_IO_APIC_route_entry *entry;
|
|
|
|
unsigned long mmr_offset;
|
2010-04-16 17:51:42 -07:00
|
|
|
int mmr_pnode;
|
2009-10-13 13:32:36 -07:00
|
|
|
|
2009-12-17 19:29:46 -07:00
|
|
|
if (set_desc_affinity(desc, mask, &dest))
|
2009-10-13 13:32:36 -07:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
mmr_value = 0;
|
|
|
|
entry = (struct uv_IO_APIC_route_entry *)&mmr_value;
|
|
|
|
|
|
|
|
entry->vector = cfg->vector;
|
|
|
|
entry->delivery_mode = apic->irq_delivery_mode;
|
|
|
|
entry->dest_mode = apic->irq_dest_mode;
|
|
|
|
entry->polarity = 0;
|
|
|
|
entry->trigger = 0;
|
|
|
|
entry->mask = 0;
|
|
|
|
entry->dest = dest;
|
|
|
|
|
|
|
|
/* Get previously stored MMR and pnode of hub sourcing interrupts */
|
|
|
|
if (uv_irq_2_mmr_info(irq, &mmr_offset, &mmr_pnode))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
uv_write_global_mmr64(mmr_pnode, mmr_offset, mmr_value);
|
|
|
|
|
|
|
|
if (cfg->move_in_progress)
|
|
|
|
send_cleanup_vector(cfg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-02 10:18:21 -07:00
|
|
|
/*
|
|
|
|
* Set up a mapping of an available irq and vector, and enable the specified
|
|
|
|
* MMR that defines the MSI that is to be sent to the specified CPU when an
|
|
|
|
* interrupt is raised.
|
|
|
|
*/
|
|
|
|
int uv_setup_irq(char *irq_name, int cpu, int mmr_blade,
|
2010-04-16 17:51:42 -07:00
|
|
|
unsigned long mmr_offset, int limit)
|
2008-10-02 10:18:21 -07:00
|
|
|
{
|
2009-09-30 09:02:59 -07:00
|
|
|
int irq, ret;
|
|
|
|
|
|
|
|
irq = create_irq_nr(NR_IRQS_LEGACY, uv_blade_to_memory_nid(mmr_blade));
|
2008-10-02 10:18:21 -07:00
|
|
|
|
|
|
|
if (irq <= 0)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2009-09-30 09:02:59 -07:00
|
|
|
ret = arch_enable_uv_irq(irq_name, irq, cpu, mmr_blade, mmr_offset,
|
2010-04-16 17:51:42 -07:00
|
|
|
limit);
|
2009-09-30 09:02:59 -07:00
|
|
|
if (ret == irq)
|
|
|
|
uv_set_irq_2_mmr_info(irq, mmr_offset, mmr_blade);
|
|
|
|
else
|
2008-10-02 10:18:21 -07:00
|
|
|
destroy_irq(irq);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(uv_setup_irq);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tear down a mapping of an irq and vector, and disable the specified MMR that
|
|
|
|
* defined the MSI that was to be sent to the specified CPU when an interrupt
|
|
|
|
* was raised.
|
|
|
|
*
|
|
|
|
* Set mmr_blade and mmr_offset to what was passed in on uv_setup_irq().
|
|
|
|
*/
|
2009-09-30 09:02:59 -07:00
|
|
|
void uv_teardown_irq(unsigned int irq)
|
2008-10-02 10:18:21 -07:00
|
|
|
{
|
2009-09-30 09:02:59 -07:00
|
|
|
struct uv_irq_2_mmr_pnode *e;
|
|
|
|
struct rb_node *n;
|
|
|
|
unsigned long irqflags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&uv_irq_lock, irqflags);
|
|
|
|
n = uv_irq_root.rb_node;
|
|
|
|
while (n) {
|
|
|
|
e = rb_entry(n, struct uv_irq_2_mmr_pnode, list);
|
|
|
|
if (e->irq == irq) {
|
|
|
|
arch_disable_uv_irq(e->pnode, e->offset);
|
|
|
|
rb_erase(n, &uv_irq_root);
|
|
|
|
kfree(e);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (irq < e->irq)
|
|
|
|
n = n->rb_left;
|
|
|
|
else
|
|
|
|
n = n->rb_right;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&uv_irq_lock, irqflags);
|
2008-10-02 10:18:21 -07:00
|
|
|
destroy_irq(irq);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(uv_teardown_irq);
|