From: Qais Yousef <qais.yousef@imgtec.com>
To: <linux-kernel@vger.kernel.org>
Cc: <tglx@linutronix.de>, <jason@lakedaemon.net>,
<marc.zyngier@arm.com>, <jiang.liu@linux.intel.com>,
<ralf@linux-mips.org>, <linux-mips@linux-mips.org>,
Qais Yousef <qais.yousef@imgtec.com>
Subject: [PATCH v2 08/19] genirq: Add a new generic IPI reservation code to irq core
Date: Wed, 25 Nov 2015 12:06:46 +0000 [thread overview]
Message-ID: <1448453217-3874-9-git-send-email-qais.yousef@imgtec.com> (raw)
In-Reply-To: <1448453217-3874-1-git-send-email-qais.yousef@imgtec.com>
Add a generic mechanism to dynamically allocate an IPI.
With this change the user can call irq_reserve_ipi() to dynamically allocate an
IPI and use the associated virq to send one to 1 or more cpus.
Signed-off-by: Qais Yousef <qais.yousef@imgtec.com>
---
include/linux/irqdomain.h | 6 ++
kernel/irq/ipi.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 149 insertions(+)
diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index fcafae8e3aaf..d2eb6c266522 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -39,6 +39,7 @@ struct irq_domain;
struct of_device_id;
struct irq_chip;
struct irq_data;
+struct ipi_mask;
/* Number of irqs reserved for a legacy isa controller */
#define NUM_ISA_INTERRUPTS 16
@@ -338,6 +339,11 @@ int irq_domain_xlate_onetwocell(struct irq_domain *d, struct device_node *ctrlr,
const u32 *intspec, unsigned int intsize,
irq_hw_number_t *out_hwirq, unsigned int *out_type);
+/* IPI functions */
+unsigned int irq_reserve_ipi(struct irq_domain *domain,
+ const struct ipi_mask *dest);
+void irq_destroy_ipi(unsigned int irq);
+
/* V2 interfaces to support hierarchy IRQ domains. */
extern struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
unsigned int virq);
diff --git a/kernel/irq/ipi.c b/kernel/irq/ipi.c
index d07325498707..f2dc8c73965c 100644
--- a/kernel/irq/ipi.c
+++ b/kernel/irq/ipi.c
@@ -8,6 +8,7 @@
*/
#include <linux/irq.h>
+#include <linux/irqdomain.h>
/**
* irq_alloc_ipi_mapping - allocate memory for struct ipi_mapping
@@ -104,3 +105,145 @@ irq_hw_number_t irq_ipi_mapping_get_hwirq(struct ipi_mapping *map,
return map->cpumap[cpu];
}
+
+/**
+ * irq_reserve_ipi() - setup an IPI to destination cpumask
+ * @domain: IPI domain
+ * @dest: cpumask of cpus to receive the IPI
+ *
+ * Allocate a virq that can be used to send IPI to any CPU in dest mask.
+ *
+ * On success it'll return linux irq number and 0 on failure
+ */
+unsigned int irq_reserve_ipi(struct irq_domain *domain,
+ const struct ipi_mask *dest)
+{
+ struct ipi_mask *ipimask;
+ struct irq_data *data;
+ unsigned int nr_irqs, offset = 0;
+ int prev_cpu = -1, cpu;
+ int virq, i;
+
+ if (domain == NULL) {
+ pr_warn("Must provide a valid IPI domain!\n");
+ return 0;
+ }
+
+ if (!irq_domain_is_ipi(domain)) {
+ pr_warn("Not an IPI domain!\n");
+ return 0;
+ }
+
+ if (irq_domain_is_ipi_per_cpu(domain))
+ nr_irqs = ipi_mask_weight(dest);
+ else
+ nr_irqs = 1;
+
+ /*
+ * Disallow holes in the ipi_mask.
+ * Holes makes it difficult to manage code in generic way. So we always
+ * assume a consecutive ipi_mask. It's easy for the user to split
+ * an ipi_mask with a hole into 2 consecutive ipi_masks and manage
+ * which virq to use locally than adding generic support that would
+ * complicate the generic code.
+ */
+ ipi_mask_for_each_cpu(cpu, dest) {
+ if (prev_cpu == -1) {
+ /* while at it save the offset */
+ offset = cpu;
+ prev_cpu = cpu;
+ continue;
+ }
+
+ if (prev_cpu - cpu > 1) {
+ pr_err("Can't allocate IPIs using non consecutive ipi_mask\n");
+ return 0;
+ }
+
+ prev_cpu = cpu;
+ }
+
+ virq = irq_domain_alloc_descs(-1, nr_irqs, 0, NUMA_NO_NODE);
+ if (virq <= 0) {
+ pr_warn("Can't reserve IPI, failed to alloc descs\n");
+ return 0;
+ }
+
+ virq = __irq_domain_alloc_irqs(domain, virq, nr_irqs, NUMA_NO_NODE,
+ (void *) dest, true);
+ if (virq <= 0) {
+ pr_warn("Can't reserve IPI, failed to alloc irqs\n");
+ goto free_descs;
+ }
+
+ /* The generic code will only need the ipi_mask in the base virq.
+ * We can save memory by storing it once only there.
+ *
+ * Do we need to keep the per virq ipi_mask for the irqchip? */
+ for (i = 0; i < nr_irqs; i++) {
+ data = irq_get_irq_data(virq + i);
+ ipimask = ipi_mask_alloc(dest->nbits);
+ if (!ipimask)
+ goto free_ipi_mask;
+ ipi_mask_copy(ipimask, dest);
+ ipi_mask_set_offset(ipimask, offset);
+ irq_data_set_ipi_mask(data, ipimask);
+ }
+
+ return virq;
+
+free_ipi_mask:
+ for (i = 0; i < nr_irqs; i++) {
+ data = irq_get_irq_data(virq + i);
+ ipimask = irq_data_get_ipi_mask(data);
+ ipi_mask_free(ipimask);
+ irq_data_set_ipi_mask(data, NULL);
+ }
+free_descs:
+ irq_free_descs(virq, nr_irqs);
+ return 0;
+}
+
+/**
+ * irq_destroy_ipi() - unreserve an IPI that was previously allocated
+ * @irq: linux irq number to be destroyed
+ *
+ * Return the IPIs allocated with irq_reserve_ipi() to the system destroying all
+ * virqs associated with them.
+ */
+void irq_destroy_ipi(unsigned int irq)
+{
+ struct irq_data *data = irq_get_irq_data(irq);
+ struct ipi_mask *ipimask = data ? irq_data_get_ipi_mask(data) : NULL;
+ struct irq_domain *domain;
+ unsigned int nr_irqs, i;
+
+ if (!irq || !data || !ipimask)
+ return;
+
+ domain = data->domain;
+ if (WARN_ON(domain == NULL))
+ return;
+
+ if (!irq_domain_is_ipi(domain)) {
+ pr_warn("Not an IPI domain!\n");
+ return;
+ }
+
+ if (irq_domain_is_ipi_per_cpu(domain))
+ nr_irqs = ipi_mask_weight(ipimask);
+ else
+ nr_irqs = 1;
+
+ ipi_mask_free(ipimask);
+ irq_data_set_ipi_mask(data, NULL);
+
+ for (i = 1; i < nr_irqs; i++) {
+ data = irq_get_irq_data(irq + i);
+ ipimask = irq_data_get_ipi_mask(data);
+ ipi_mask_free(ipimask);
+ irq_data_set_ipi_mask(data, NULL);
+ }
+
+ irq_domain_free_irqs(irq, nr_irqs);
+}
--
2.1.0
next prev parent reply other threads:[~2015-11-25 12:14 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-25 12:06 [PATCH v2 00/19] Implement generic IPI support mechanism Qais Yousef
2015-11-25 12:06 ` [PATCH v2 01/19] genirq: Add new IRQ_DOMAIN_FLAGS_IPI Qais Yousef
2015-11-25 12:06 ` [PATCH v2 02/19] genirq: Add DOMAIN_BUS_IPI Qais Yousef
2015-11-25 12:06 ` [PATCH v2 03/19] genirq: Add GENERIC_IRQ_IPI Kconfig symbol Qais Yousef
2015-11-25 12:06 ` [PATCH v2 04/19] genirq: Add new struct ipi_mask and helper functions Qais Yousef
2015-11-30 11:20 ` Thomas Gleixner
2015-11-30 11:48 ` Qais Yousef
2015-11-30 13:11 ` Thomas Gleixner
2015-11-30 13:57 ` Qais Yousef
2015-11-25 12:06 ` [PATCH v2 05/19] genirq: Add struct ipi_mask to irq_data Qais Yousef
2015-11-25 12:06 ` [PATCH v2 06/19] genirq: Add struct ipi_mapping and its helper functions Qais Yousef
2015-11-25 12:06 ` [PATCH v2 07/19] genirq: Make irq_domain_alloc_descs() non static Qais Yousef
2015-11-25 12:06 ` Qais Yousef [this message]
2015-11-25 12:06 ` [PATCH v2 09/19] genirq: Add a new function to get IPI reverse mapping Qais Yousef
2015-11-27 11:46 ` Qais Yousef
2015-11-30 10:40 ` Thomas Gleixner
2015-11-30 10:53 ` Qais Yousef
2015-11-30 11:22 ` Thomas Gleixner
2015-11-30 11:59 ` Qais Yousef
2015-12-01 10:47 ` Qais Yousef
2015-11-25 12:06 ` [PATCH v2 10/19] genirq: Add a new irq_send_ipi() to irq_chip Qais Yousef
2015-11-25 12:06 ` [PATCH v2 11/19] genirq: Implement ipi_send_{mask, single}() Qais Yousef
2015-11-25 12:06 ` [PATCH v2 12/19] irqchip/mips-gic: Add a IPI hierarchy domain Qais Yousef
2015-11-25 12:06 ` [PATCH v2 13/19] irqchip/mips-gic: Add device " Qais Yousef
2015-11-25 12:06 ` [PATCH v2 14/19] irqchip/mips-gic: Use gic_vpes instead of NR_CPUS Qais Yousef
2015-11-25 12:06 ` [PATCH v2 15/19] irqchip/mips-gic: Clear percpu_masks correctly when mapping Qais Yousef
2015-11-25 12:06 ` [PATCH v2 16/19] MIPS: Add generic SMP IPI support Qais Yousef
2015-11-25 12:06 ` [PATCH v2 17/19] MIPS: Make smp CMP, CPS and MT use the new generic IPI functions Qais Yousef
2015-11-25 12:06 ` [PATCH v2 18/19] MIPS: Delete smp-gic.c Qais Yousef
2015-11-25 12:06 ` [PATCH v2 19/19] irqchip/mips-gic: Add new DT property to reserve IPIs Qais Yousef
2015-11-25 16:09 ` Rob Herring
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=1448453217-3874-9-git-send-email-qais.yousef@imgtec.com \
--to=qais.yousef@imgtec.com \
--cc=jason@lakedaemon.net \
--cc=jiang.liu@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=marc.zyngier@arm.com \
--cc=ralf@linux-mips.org \
--cc=tglx@linutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®