From: Yinghai Lu <yinghai@kernel.org>
To: Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@elte.hu>,
"H. Peter Anvin" <hpa@zytor.com>, Tony Luck <tony.luck@intel.com>,
Bjorn Helgaas <bhelgaas@google.com>,
"Rafael J. Wysocki" <rjw@sisk.pl>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-acpi@vger.kernel.org, Yinghai Lu <yinghai@kernel.org>,
Joerg Roedel <joro@8bytes.org>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Sebastian Andrzej Siewior <sebastian@breakpoint.cc>,
Grant Likely <grant.likely@linaro.org>,
Paul Gortmaker <paul.gortmaker@windriver.com>,
Andy Lutomirski <luto@amacapital.net>,
iommu@lists.linux-foundation.org
Subject: [PATCH v4 19/28] x86, irq: Add for_each_ioapic helper
Date: Sat, 10 Aug 2013 19:48:05 -0700 [thread overview]
Message-ID: <1376189294-32022-20-git-send-email-yinghai@kernel.org> (raw)
In-Reply-To: <1376189294-32022-1-git-send-email-yinghai@kernel.org>
For hotadd and hotremove ioapic controller, we leave blank
slots in ioapics array.
So we can not use for (i=...) to loop them any more.
Introdue ioapics_mask bitmap to track used ioapics, and use
for_each_ioapic to loop them.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: iommu@lists.linux-foundation.org
---
arch/x86/include/asm/io_apic.h | 6 ++++
arch/x86/kernel/apic/io_apic.c | 64 ++++++++++++++++++++-----------------
arch/x86/kernel/devicetree.c | 2 +-
drivers/iommu/amd_iommu_init.c | 2 +-
drivers/iommu/intel_irq_remapping.c | 2 +-
5 files changed, 43 insertions(+), 33 deletions(-)
diff --git a/arch/x86/include/asm/io_apic.h b/arch/x86/include/asm/io_apic.h
index 02ac411..a25dcf1 100644
--- a/arch/x86/include/asm/io_apic.h
+++ b/arch/x86/include/asm/io_apic.h
@@ -105,6 +105,12 @@ struct IR_IO_APIC_route_entry {
* # of IO-APICs and # of IRQ routing registers
*/
extern int nr_ioapics;
+extern DECLARE_BITMAP(ioapics_mask, MAX_IO_APICS);
+
+#define for_each_ioapic(i) \
+ for ((i) = -1; \
+ (i) = find_next_bit(ioapics_mask, MAX_IO_APICS, (i)+1), \
+ (i) < MAX_IO_APICS;)
extern int mpc_ioapic_id(int ioapic);
extern unsigned int mpc_ioapic_addr(int ioapic);
diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
index 8d087f1..b026cc7 100644
--- a/arch/x86/kernel/apic/io_apic.c
+++ b/arch/x86/kernel/apic/io_apic.c
@@ -93,6 +93,8 @@ static struct ioapic {
DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
} ioapics[MAX_IO_APICS];
+DECLARE_BITMAP(ioapics_mask, MAX_IO_APICS);
+
#define mpc_ioapic_ver(ioapic_idx) ioapics[ioapic_idx].mp_config.apicver
int mpc_ioapic_id(int ioapic_idx)
@@ -344,10 +346,10 @@ int __init arch_early_irq_init(void)
if (!legacy_pic->nr_legacy_irqs)
io_apic_irqs = ~0UL;
- for (i = 0; i < nr_ioapics; i++)
+ for_each_ioapic(i)
alloc_ioapic_saved_registers(i);
- for (i = 0; i < nr_ioapics; i++)
+ for_each_ioapic(i)
reserve_ioapic_gsi_irq_base(i);
reserve_ioapic_gsi_irq_extra();
@@ -715,7 +717,7 @@ static void clear_IO_APIC (void)
{
int apic, pin;
- for (apic = 0; apic < nr_ioapics; apic++)
+ for_each_ioapic(apic)
for (pin = 0; pin < ioapics[apic].nr_registers; pin++)
clear_IO_APIC_pin(apic, pin);
}
@@ -766,7 +768,7 @@ int save_ioapic_entries(void)
int apic, pin;
int err = 0;
- for (apic = 0; apic < nr_ioapics; apic++) {
+ for_each_ioapic(apic) {
if (!ioapics[apic].saved_registers) {
err = -ENOMEM;
continue;
@@ -787,7 +789,7 @@ void mask_ioapic_entries(void)
{
int apic, pin;
- for (apic = 0; apic < nr_ioapics; apic++) {
+ for_each_ioapic(apic) {
if (!ioapics[apic].saved_registers)
continue;
@@ -810,7 +812,7 @@ int restore_ioapic_entries(void)
{
int apic, pin;
- for (apic = 0; apic < nr_ioapics; apic++) {
+ for_each_ioapic(apic) {
if (!ioapics[apic].saved_registers)
continue;
@@ -873,7 +875,7 @@ static int __init find_isa_irq_apic(int irq, int type)
if (i < mp_irq_entries) {
int ioapic_idx;
- for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++)
+ for_each_ioapic(ioapic_idx)
if (mpc_ioapic_id(ioapic_idx) == mp_irqs[i].dstapic)
return ioapic_idx;
}
@@ -1095,7 +1097,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
for (i = 0; i < mp_irq_entries; i++) {
int lbus = mp_irqs[i].srcbus;
- for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++)
+ for_each_ioapic(ioapic_idx)
if (mpc_ioapic_id(ioapic_idx) == mp_irqs[i].dstapic ||
mp_irqs[i].dstapic == MP_APIC_ALL)
break;
@@ -1316,7 +1318,7 @@ static inline int IO_APIC_irq_trigger(int irq)
{
int apic, idx, pin;
- for (apic = 0; apic < nr_ioapics; apic++) {
+ for_each_ioapic(apic) {
for (pin = 0; pin < ioapics[apic].nr_registers; pin++) {
idx = find_irq_entry(apic, pin, mp_INT);
if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin)))
@@ -1472,7 +1474,7 @@ static void __init setup_IO_APIC_irqs(void)
apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
- for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++)
+ for_each_ioapic(ioapic_idx)
__io_apic_setup_irqs(ioapic_idx);
}
@@ -1694,7 +1696,7 @@ __apicdebuginit(void) print_IO_APICs(void)
struct irq_chip *chip;
printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
- for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++)
+ for_each_ioapic(ioapic_idx)
printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
mpc_ioapic_id(ioapic_idx),
ioapics[ioapic_idx].nr_registers);
@@ -1705,7 +1707,7 @@ __apicdebuginit(void) print_IO_APICs(void)
*/
printk(KERN_INFO "testing the IO APIC.......................\n");
- for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++)
+ for_each_ioapic(ioapic_idx)
print_IO_APIC(ioapic_idx);
printk(KERN_DEBUG "IRQ to pin mappings:\n");
@@ -1940,7 +1942,7 @@ void __init enable_IO_APIC(void)
if (!legacy_pic->nr_legacy_irqs)
return;
- for(apic = 0; apic < nr_ioapics; apic++) {
+ for_each_ioapic(apic) {
int pin;
/* See if any of the pins is in ExtINT mode */
for (pin = 0; pin < ioapics[apic].nr_registers; pin++) {
@@ -2057,7 +2059,7 @@ void __init setup_ioapic_ids_from_mpc_nocheck(void)
/*
* Set the IOAPIC ID to the value stored in the MPC table.
*/
- for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++) {
+ for_each_ioapic(ioapic_idx) {
/* Read the register 0 value */
raw_spin_lock_irqsave(&ioapic_lock, flags);
reg_00.raw = io_apic_read(ioapic_idx, 0);
@@ -2987,7 +2989,8 @@ static void ioapic_resume(void)
{
int ioapic_idx;
- for (ioapic_idx = nr_ioapics - 1; ioapic_idx >= 0; ioapic_idx--)
+ /* really do that in reverse order ? */
+ for_each_ioapic(ioapic_idx)
resume_ioapic_id(ioapic_idx);
restore_ioapic_entries();
@@ -3635,9 +3638,9 @@ static u8 __init io_apic_unique_id(u8 id)
DECLARE_BITMAP(used, 256);
bitmap_zero(used, 256);
- for (i = 0; i < nr_ioapics; i++) {
+ for_each_ioapic(i)
__set_bit(mpc_ioapic_id(i), used);
- }
+
if (!test_bit(id, used))
return id;
return find_first_zero_bit(used, 256);
@@ -3695,7 +3698,7 @@ void __init setup_ioapic_dest(void)
if (skip_ioapic_setup == 1)
return;
- for (ioapic = 0; ioapic < nr_ioapics; ioapic++)
+ for_each_ioapic(ioapic)
for (pin = 0; pin < ioapics[ioapic].nr_registers; pin++) {
irq_entry = find_irq_entry(ioapic, pin, mp_INT);
if (irq_entry == -1)
@@ -3743,7 +3746,7 @@ static struct resource * __init ioapic_setup_resources(int nr_ioapics)
mem += sizeof(struct resource) * nr_ioapics;
- for (i = 0; i < nr_ioapics; i++) {
+ for_each_ioapic(i) {
res[i].name = mem;
res[i].flags = IORESOURCE_MEM | IORESOURCE_BUSY;
snprintf(mem, IOAPIC_RESOURCE_NAME_SIZE, "IOAPIC %u", i);
@@ -3762,7 +3765,7 @@ void __init native_io_apic_init_mappings(void)
int i;
ioapic_res = ioapic_setup_resources(nr_ioapics);
- for (i = 0; i < nr_ioapics; i++) {
+ for_each_ioapic(i) {
if (smp_found_config) {
ioapic_phys = mpc_ioapic_addr(i);
#ifdef CONFIG_X86_32
@@ -3809,7 +3812,7 @@ void __init ioapic_insert_resources(void)
return;
}
- for (i = 0; i < nr_ioapics; i++) {
+ for_each_ioapic(i) {
insert_resource(&iomem_resource, r);
r++;
}
@@ -3823,7 +3826,7 @@ int mp_find_ioapic(u32 gsi)
return -1;
/* Find the IOAPIC that manages this GSI. */
- for (i = 0; i < nr_ioapics; i++) {
+ for_each_ioapic(i) {
struct mp_ioapic_gsi *gsi_cfg = mp_ioapic_gsi_routing(i);
if ((gsi >= gsi_cfg->gsi_base)
&& (gsi <= gsi_cfg->gsi_end))
@@ -3850,11 +3853,6 @@ int mp_find_ioapic_pin(int ioapic, u32 gsi)
static __init int bad_ioapic(unsigned long address)
{
- if (nr_ioapics >= MAX_IO_APICS) {
- pr_warn("WARNING: Max # of I/O APICs (%d) exceeded (found %d), skipping\n",
- MAX_IO_APICS, nr_ioapics);
- return 1;
- }
if (!address) {
pr_warn("WARNING: Bogus (zero) I/O APIC address found in table, skipping!\n");
return 1;
@@ -3883,14 +3881,19 @@ static __init int bad_ioapic_register(int idx)
void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
{
- int idx = 0;
+ int idx;
int entries;
struct mp_ioapic_gsi *gsi_cfg;
if (bad_ioapic(address))
return;
- idx = nr_ioapics;
+ idx = find_first_zero_bit(ioapics_mask, MAX_IO_APICS);
+ if (idx >= MAX_IO_APICS) {
+ pr_warn("WARNING: Max # of I/O APICs (%d) exceeded, skipping\n",
+ MAX_IO_APICS);
+ return;
+ }
ioapics[idx].mp_config.type = MP_IOAPIC;
ioapics[idx].mp_config.flags = MPC_APIC_USABLE;
@@ -3928,7 +3931,8 @@ void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
mpc_ioapic_ver(idx), mpc_ioapic_addr(idx),
gsi_cfg->gsi_base, gsi_cfg->gsi_end);
- nr_ioapics++;
+ set_bit(idx, ioapics_mask);
+ nr_ioapics = bitmap_weight(ioapics_mask, MAX_IO_APICS);
}
/* Enable IOAPIC early just for system timer */
diff --git a/arch/x86/kernel/devicetree.c b/arch/x86/kernel/devicetree.c
index 69eb2fa..c811e2f 100644
--- a/arch/x86/kernel/devicetree.c
+++ b/arch/x86/kernel/devicetree.c
@@ -393,7 +393,7 @@ static void __init ioapic_add_ofnode(struct device_node *np)
return;
}
- for (i = 0; i < nr_ioapics; i++) {
+ for_each_ioapic(i) {
if (r.start == mpc_ioapic_addr(i)) {
dt_add_ioapic_domain(i, np);
return;
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 7acbf35..7bbe9d2 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -1743,7 +1743,7 @@ static bool __init check_ioapic_information(void)
if (cmdline_maps)
fw_bug = "";
- for (idx = 0; idx < nr_ioapics; idx++) {
+ for_each_ioapic(idx) {
int devid, id = mpc_ioapic_id(idx);
devid = get_ioapic_devid(id);
diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c
index f71673d..84a6807 100644
--- a/drivers/iommu/intel_irq_remapping.c
+++ b/drivers/iommu/intel_irq_remapping.c
@@ -793,7 +793,7 @@ int __init parse_ioapics_under_ir(void)
if (!ir_supported)
return 0;
- for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++) {
+ for_each_ioapic(ioapic_idx) {
int ioapic_id = mpc_ioapic_id(ioapic_idx);
if (!map_ioapic_to_ir(ioapic_id)) {
pr_err(FW_BUG "ioapic %d has no mapping iommu, "
--
1.8.1.4
next prev parent reply other threads:[~2013-08-11 2:48 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-11 2:47 [PATCH v4 00/28] x86, irq: Support ioapic controller hotplug Yinghai Lu
2013-08-11 2:47 ` [PATCH v4 01/28] genirq: Split __irq_reserve_irqs from irq_alloc_descs Yinghai Lu
2013-08-11 2:47 ` [PATCH v4 02/28] genirq: Add irq_alloc_reserved_desc() Yinghai Lu
2013-08-11 2:47 ` [PATCH v4 03/28] genirq: Do not free unallocated irq descriptors Yinghai Lu
2013-08-11 2:47 ` [PATCH v4 04/28] x86, irq: Change irq_remap_modify_chip_defaults() to static Yinghai Lu
2013-08-11 2:47 ` [PATCH v4 05/28] x86, irq: Modify irq chip once for irq remapping Yinghai Lu
2013-08-11 2:47 ` [PATCH v4 06/28] x86, irq: Show MSI-X clearly in debug message Yinghai Lu
2013-08-11 2:47 ` [PATCH v4 07/28] x86, irq: Show MSI-X in /proc/interrupt Yinghai Lu
2013-08-11 2:47 ` [PATCH v4 08/28] x86, irq: Make dmar_msi/hpet_msi irq_chip name consistent Yinghai Lu
2013-08-11 2:47 ` [PATCH v4 09/28] ia64, irq: Add dummy create_irq_nr() Yinghai Lu
2013-08-11 2:47 ` Yinghai Lu
2013-08-11 2:47 ` [PATCH v4 10/28] iommu, irq: Allocate irq_desc for dmar_msi with local node Yinghai Lu
2013-08-11 2:47 ` [PATCH v4 11/28] x86, irq: Kill create_irq() Yinghai Lu
2013-08-11 2:47 ` [PATCH v4 12/28] x86, irq: Convert irq_2_pin list to generic list Yinghai Lu
2013-08-11 2:47 ` [PATCH v4 13/28] x86, irq: Add alloc_reserved_irq_and_cfg_at() Yinghai Lu
2013-08-11 2:48 ` [PATCH v4 14/28] x86, irq: Move down arch_early_irq_init() Yinghai Lu
2013-08-11 2:48 ` [PATCH v4 15/28] x86, irq: Split out alloc_ioapic_save_registers() Yinghai Lu
2013-08-11 2:48 ` [PATCH v4 16/28] xen, irq: Call irq_alloc_reserved_desc_at() at first Yinghai Lu
2013-08-11 2:48 ` Yinghai Lu
2013-08-11 2:48 ` [PATCH v4 17/28] x86, irq: Reserve irq range and alloc_reserved for booting path Yinghai Lu
2013-08-11 2:48 ` [PATCH v4 18/28] x86, irq: Add ioapic_gsi_to_irq Yinghai Lu
2013-08-11 2:48 ` Yinghai Lu [this message]
2013-08-11 2:48 ` [PATCH v4 20/28] x86, irq: More strict checking about registering ioapic Yinghai Lu
2013-08-19 7:47 ` Lan Tianyu
2013-10-21 10:54 ` Yijing Wang
2013-10-21 10:54 ` Yijing Wang
2013-08-11 2:48 ` [PATCH v4 21/28] x86, irq: Make mp_register_ioapic handle hot-added ioapic Yinghai Lu
2013-08-11 2:48 ` [PATCH v4 22/28] x86, irq: Add mp_unregister_ioapic to handle hot-remove ioapic Yinghai Lu
2013-08-11 2:48 ` [PATCH v4 23/28] x86, ioapic: Find usable ioapic id for 64bit Yinghai Lu
2013-08-11 2:48 ` [PATCH v4 24/28] x86: Move declaration for mp_register_ioapic() Yinghai Lu
2013-08-11 2:48 ` [PATCH v4 25/28] PCI, x86: Make ioapic hotplug support built-in Yinghai Lu
2013-10-01 16:00 ` Bjorn Helgaas
2013-10-01 17:42 ` Yinghai Lu
2013-08-11 2:48 ` [PATCH v4 26/28] PCI, x86, ACPI: Link acpi ioapic register to ioapic Yinghai Lu
2013-08-24 0:51 ` rui wang
2013-08-27 0:40 ` Yinghai Lu
2013-08-27 6:44 ` rui wang
2013-08-27 6:53 ` Yinghai Lu
2013-08-27 10:08 ` rui wang
2013-08-28 6:17 ` Yinghai Lu
2013-08-11 2:48 ` [PATCH v4 27/28] PCI, x86, ACPI: Enable ioapic hotplug support with acpi host bridge Yinghai Lu
2013-08-27 10:25 ` rui wang
2013-08-28 1:10 ` rui wang
2013-08-28 6:22 ` Yinghai Lu
2013-08-28 8:25 ` rui wang
2013-10-21 12:30 ` Yijing Wang
2013-10-21 12:30 ` Yijing Wang
2013-08-11 2:48 ` [PATCH v4 28/28] PCI, x86, ACPI: get ioapic address from acpi device Yinghai Lu
2013-08-22 13:29 ` rui wang
2013-08-23 10:41 ` rui wang
2013-08-23 15:34 ` Lan Tianyu
2013-08-23 18:38 ` Yinghai Lu
2013-08-23 19:04 ` Yinghai Lu
2013-08-23 19:38 ` Yinghai Lu
2013-08-26 15:46 ` Lan Tianyu
2013-08-27 1:03 ` Yinghai Lu
2013-08-27 14:56 ` Lan Tianyu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1376189294-32022-20-git-send-email-yinghai@kernel.org \
--to=yinghai@kernel.org \
--cc=bhelgaas@google.com \
--cc=grant.likely@linaro.org \
--cc=hpa@zytor.com \
--cc=iommu@lists.linux-foundation.org \
--cc=joro@8bytes.org \
--cc=konrad.wilk@oracle.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@elte.hu \
--cc=paul.gortmaker@windriver.com \
--cc=rjw@sisk.pl \
--cc=sebastian@breakpoint.cc \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.