2008-08-05 23:10:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2006-2008, Michael Ellerman, IBM Corporation.
|
|
|
|
*
|
|
|
|
* 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; version 2 of the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2008-08-05 23:10:01 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/bitmap.h>
|
2015-09-16 19:26:14 +00:00
|
|
|
#include <linux/bootmem.h>
|
2008-08-05 23:10:01 +00:00
|
|
|
#include <asm/msi_bitmap.h>
|
2012-03-28 17:30:02 +00:00
|
|
|
#include <asm/setup.h>
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int offset, order = get_count_order(num);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&bmp->lock, flags);
|
2014-10-08 08:54:53 +00:00
|
|
|
|
|
|
|
offset = bitmap_find_next_zero_area(bmp->bitmap, bmp->irq_count, 0,
|
|
|
|
num, (1 << order) - 1);
|
|
|
|
if (offset > bmp->irq_count)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
bitmap_set(bmp->bitmap, offset, num);
|
2008-08-05 23:10:01 +00:00
|
|
|
spin_unlock_irqrestore(&bmp->lock, flags);
|
|
|
|
|
2014-10-08 08:54:53 +00:00
|
|
|
pr_debug("msi_bitmap: allocated 0x%x at offset 0x%x\n", num, offset);
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
return offset;
|
2014-10-08 08:54:53 +00:00
|
|
|
err:
|
|
|
|
spin_unlock_irqrestore(&bmp->lock, flags);
|
|
|
|
return -ENOMEM;
|
2008-08-05 23:10:01 +00:00
|
|
|
}
|
2014-10-08 08:54:53 +00:00
|
|
|
EXPORT_SYMBOL(msi_bitmap_alloc_hwirqs);
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
void msi_bitmap_free_hwirqs(struct msi_bitmap *bmp, unsigned int offset,
|
|
|
|
unsigned int num)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2014-10-08 08:54:53 +00:00
|
|
|
pr_debug("msi_bitmap: freeing 0x%x at offset 0x%x\n",
|
|
|
|
num, offset);
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&bmp->lock, flags);
|
2014-10-08 08:54:53 +00:00
|
|
|
bitmap_clear(bmp->bitmap, offset, num);
|
2008-08-05 23:10:01 +00:00
|
|
|
spin_unlock_irqrestore(&bmp->lock, flags);
|
|
|
|
}
|
2014-10-08 08:54:53 +00:00
|
|
|
EXPORT_SYMBOL(msi_bitmap_free_hwirqs);
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
void msi_bitmap_reserve_hwirq(struct msi_bitmap *bmp, unsigned int hwirq)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
pr_debug("msi_bitmap: reserving hwirq 0x%x\n", hwirq);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&bmp->lock, flags);
|
|
|
|
bitmap_allocate_region(bmp->bitmap, hwirq, 0);
|
|
|
|
spin_unlock_irqrestore(&bmp->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* msi_bitmap_reserve_dt_hwirqs - Reserve irqs specified in the device tree.
|
|
|
|
* @bmp: pointer to the MSI bitmap.
|
|
|
|
*
|
|
|
|
* Looks in the device tree to see if there is a property specifying which
|
|
|
|
* irqs can be used for MSI. If found those irqs reserved in the device tree
|
|
|
|
* are reserved in the bitmap.
|
|
|
|
*
|
|
|
|
* Returns 0 for success, < 0 if there was an error, and > 0 if no property
|
|
|
|
* was found in the device tree.
|
|
|
|
**/
|
|
|
|
int msi_bitmap_reserve_dt_hwirqs(struct msi_bitmap *bmp)
|
|
|
|
{
|
|
|
|
int i, j, len;
|
|
|
|
const u32 *p;
|
|
|
|
|
|
|
|
if (!bmp->of_node)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
p = of_get_property(bmp->of_node, "msi-available-ranges", &len);
|
|
|
|
if (!p) {
|
|
|
|
pr_debug("msi_bitmap: no msi-available-ranges property " \
|
|
|
|
"found on %s\n", bmp->of_node->full_name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len % (2 * sizeof(u32)) != 0) {
|
|
|
|
printk(KERN_WARNING "msi_bitmap: Malformed msi-available-ranges"
|
|
|
|
" property on %s\n", bmp->of_node->full_name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bitmap_allocate_region(bmp->bitmap, 0, get_count_order(bmp->irq_count));
|
|
|
|
|
|
|
|
spin_lock(&bmp->lock);
|
|
|
|
|
|
|
|
/* Format is: (<u32 start> <u32 count>)+ */
|
|
|
|
len /= 2 * sizeof(u32);
|
|
|
|
for (i = 0; i < len; i++, p += 2) {
|
|
|
|
for (j = 0; j < *(p + 1); j++)
|
|
|
|
bitmap_release_region(bmp->bitmap, *p + j, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&bmp->lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-21 11:29:13 +00:00
|
|
|
int __init_refok msi_bitmap_alloc(struct msi_bitmap *bmp, unsigned int irq_count,
|
2008-08-05 23:10:01 +00:00
|
|
|
struct device_node *of_node)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (!irq_count)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
size = BITS_TO_LONGS(irq_count) * sizeof(long);
|
|
|
|
pr_debug("msi_bitmap: allocator bitmap size is 0x%x bytes\n", size);
|
|
|
|
|
2015-09-16 19:26:14 +00:00
|
|
|
bmp->bitmap_from_slab = slab_is_available();
|
|
|
|
if (bmp->bitmap_from_slab)
|
|
|
|
bmp->bitmap = kzalloc(size, GFP_KERNEL);
|
|
|
|
else {
|
|
|
|
bmp->bitmap = memblock_virt_alloc(size, 0);
|
|
|
|
/* the bitmap won't be freed from memblock allocator */
|
|
|
|
kmemleak_not_leak(bmp->bitmap);
|
|
|
|
}
|
|
|
|
|
2008-08-05 23:10:01 +00:00
|
|
|
if (!bmp->bitmap) {
|
|
|
|
pr_debug("msi_bitmap: ENOMEM allocating allocator bitmap!\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We zalloc'ed the bitmap, so all irqs are free by default */
|
|
|
|
spin_lock_init(&bmp->lock);
|
|
|
|
bmp->of_node = of_node_get(of_node);
|
|
|
|
bmp->irq_count = irq_count;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void msi_bitmap_free(struct msi_bitmap *bmp)
|
|
|
|
{
|
2015-09-16 19:26:14 +00:00
|
|
|
if (bmp->bitmap_from_slab)
|
|
|
|
kfree(bmp->bitmap);
|
2008-08-05 23:10:01 +00:00
|
|
|
of_node_put(bmp->of_node);
|
|
|
|
bmp->bitmap = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_MSI_BITMAP_SELFTEST
|
|
|
|
|
2014-08-19 22:55:18 +00:00
|
|
|
static void __init test_basics(void)
|
2008-08-05 23:10:01 +00:00
|
|
|
{
|
|
|
|
struct msi_bitmap bmp;
|
2014-10-10 08:04:24 +00:00
|
|
|
int rc, i, size = 512;
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
/* Can't allocate a bitmap of 0 irqs */
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(msi_bitmap_alloc(&bmp, 0, NULL) == 0);
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
/* of_node may be NULL */
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(msi_bitmap_alloc(&bmp, size, NULL));
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
/* Should all be free by default */
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(bitmap_find_free_region(bmp.bitmap, size, get_count_order(size)));
|
2008-08-05 23:10:01 +00:00
|
|
|
bitmap_release_region(bmp.bitmap, 0, get_count_order(size));
|
|
|
|
|
|
|
|
/* With no node, there's no msi-available-ranges, so expect > 0 */
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp) <= 0);
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
/* Should all still be free */
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(bitmap_find_free_region(bmp.bitmap, size, get_count_order(size)));
|
2008-08-05 23:10:01 +00:00
|
|
|
bitmap_release_region(bmp.bitmap, 0, get_count_order(size));
|
|
|
|
|
|
|
|
/* Check we can fill it up and then no more */
|
|
|
|
for (i = 0; i < size; i++)
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(msi_bitmap_alloc_hwirqs(&bmp, 1) < 0);
|
2008-08-05 23:10:01 +00:00
|
|
|
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(msi_bitmap_alloc_hwirqs(&bmp, 1) >= 0);
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
/* Should all be allocated */
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(bitmap_find_free_region(bmp.bitmap, size, 0) >= 0);
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
/* And if we free one we can then allocate another */
|
|
|
|
msi_bitmap_free_hwirqs(&bmp, size / 2, 1);
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(msi_bitmap_alloc_hwirqs(&bmp, 1) != size / 2);
|
2008-08-05 23:10:01 +00:00
|
|
|
|
2014-10-10 08:04:24 +00:00
|
|
|
/* Free most of them for the alignment tests */
|
|
|
|
msi_bitmap_free_hwirqs(&bmp, 3, size - 3);
|
|
|
|
|
2014-10-08 08:54:53 +00:00
|
|
|
/* Check we get a naturally aligned offset */
|
2014-10-10 08:04:24 +00:00
|
|
|
rc = msi_bitmap_alloc_hwirqs(&bmp, 2);
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(rc < 0 && rc % 2 != 0);
|
2014-10-10 08:04:24 +00:00
|
|
|
rc = msi_bitmap_alloc_hwirqs(&bmp, 4);
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(rc < 0 && rc % 4 != 0);
|
2014-10-10 08:04:24 +00:00
|
|
|
rc = msi_bitmap_alloc_hwirqs(&bmp, 8);
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(rc < 0 && rc % 8 != 0);
|
2014-10-10 08:04:24 +00:00
|
|
|
rc = msi_bitmap_alloc_hwirqs(&bmp, 9);
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(rc < 0 && rc % 16 != 0);
|
2014-10-10 08:04:24 +00:00
|
|
|
rc = msi_bitmap_alloc_hwirqs(&bmp, 3);
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(rc < 0 && rc % 4 != 0);
|
2014-10-10 08:04:24 +00:00
|
|
|
rc = msi_bitmap_alloc_hwirqs(&bmp, 7);
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(rc < 0 && rc % 8 != 0);
|
2014-10-10 08:04:24 +00:00
|
|
|
rc = msi_bitmap_alloc_hwirqs(&bmp, 121);
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(rc < 0 && rc % 128 != 0);
|
2014-10-08 08:54:53 +00:00
|
|
|
|
2008-08-05 23:10:01 +00:00
|
|
|
msi_bitmap_free(&bmp);
|
|
|
|
|
2014-10-10 08:04:25 +00:00
|
|
|
/* Clients may WARN_ON bitmap == NULL for "not-allocated" */
|
|
|
|
WARN_ON(bmp.bitmap != NULL);
|
2008-08-05 23:10:01 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 22:55:18 +00:00
|
|
|
static void __init test_of_node(void)
|
2008-08-05 23:10:01 +00:00
|
|
|
{
|
|
|
|
u32 prop_data[] = { 10, 10, 25, 3, 40, 1, 100, 100, 200, 20 };
|
|
|
|
const char *expected_str = "0-9,20-24,28-39,41-99,220-255";
|
|
|
|
char *prop_name = "msi-available-ranges";
|
|
|
|
char *node_name = "/fakenode";
|
|
|
|
struct device_node of_node;
|
|
|
|
struct property prop;
|
|
|
|
struct msi_bitmap bmp;
|
|
|
|
int size = 256;
|
|
|
|
DECLARE_BITMAP(expected, size);
|
|
|
|
|
|
|
|
/* There should really be a struct device_node allocator */
|
|
|
|
memset(&of_node, 0, sizeof(of_node));
|
2014-04-03 06:58:20 +00:00
|
|
|
of_node_init(&of_node);
|
2008-08-05 23:10:01 +00:00
|
|
|
of_node.full_name = node_name;
|
|
|
|
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(msi_bitmap_alloc(&bmp, size, &of_node));
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
/* No msi-available-ranges, so expect > 0 */
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp) <= 0);
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
/* Should all still be free */
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(bitmap_find_free_region(bmp.bitmap, size, get_count_order(size)));
|
2008-08-05 23:10:01 +00:00
|
|
|
bitmap_release_region(bmp.bitmap, 0, get_count_order(size));
|
|
|
|
|
|
|
|
/* Now create a fake msi-available-ranges property */
|
|
|
|
|
|
|
|
/* There should really .. oh whatever */
|
|
|
|
memset(&prop, 0, sizeof(prop));
|
|
|
|
prop.name = prop_name;
|
|
|
|
prop.value = &prop_data;
|
|
|
|
prop.length = sizeof(prop_data);
|
|
|
|
|
|
|
|
of_node.properties = ∝
|
|
|
|
|
|
|
|
/* msi-available-ranges, so expect == 0 */
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp));
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
/* Check we got the expected result */
|
2014-10-10 08:04:25 +00:00
|
|
|
WARN_ON(bitmap_parselist(expected_str, expected, size));
|
|
|
|
WARN_ON(!bitmap_equal(expected, bmp.bitmap, size));
|
2008-08-05 23:10:01 +00:00
|
|
|
|
|
|
|
msi_bitmap_free(&bmp);
|
|
|
|
kfree(bmp.bitmap);
|
|
|
|
}
|
|
|
|
|
2014-08-19 22:55:18 +00:00
|
|
|
static int __init msi_bitmap_selftest(void)
|
2008-08-05 23:10:01 +00:00
|
|
|
{
|
|
|
|
printk(KERN_DEBUG "Running MSI bitmap self-tests ...\n");
|
|
|
|
|
|
|
|
test_basics();
|
|
|
|
test_of_node();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
late_initcall(msi_bitmap_selftest);
|
|
|
|
#endif /* CONFIG_MSI_BITMAP_SELFTEST */
|