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 06/14] genirq: Add struct ipi_mapping and its helper functions
Date: Tue, 3 Nov 2015 11:12:53 +0000 [thread overview]
Message-ID: <1446549181-31788-7-git-send-email-qais.yousef@imgtec.com> (raw)
In-Reply-To: <1446549181-31788-1-git-send-email-qais.yousef@imgtec.com>
struct ipi_mapping will provide a mechanism for irqchip code to fill out the
mapping at reservation and to look it up when sending.
Signed-off-by: Qais Yousef <qais.yousef@imgtec.com>
---
include/linux/irq.h | 21 +++++++++++++
kernel/irq/manage.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 107 insertions(+)
diff --git a/include/linux/irq.h b/include/linux/irq.h
index 2d3ff30c0cee..ccd53143cc1e 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -1008,4 +1008,25 @@ static inline void ipi_mask_set_cpumask(struct ipi_mask *ipimask,
cpumask_copy(&ipimask->cpumask, cpumask);
}
+#define INVALID_HWIRQ -1
+
+/**
+ * struct ipi_mapping - IPI mapping information object
+ * @nr_hwirqs: number of hwirqs mapped
+ * @nr_cpus: number of cpus the controller can talk to
+ * @cpumap: per cpu hwirq mapping table
+ */
+struct ipi_mapping {
+ unsigned int nr_hwirqs;
+ unsigned int nr_cpus;
+ unsigned int cpumap[];
+};
+
+struct ipi_mapping *irq_alloc_ipi_mapping(unsigned int nr_cpus);
+void irq_free_ipi_mapping(struct ipi_mapping *map);
+int irq_map_ipi(struct ipi_mapping *map,
+ unsigned int cpu, irq_hw_number_t hwirq);
+int irq_unmap_ipi(struct ipi_mapping *map,
+ unsigned int cpu, irq_hw_number_t *hwirq);
+
#endif /* _LINUX_IRQ_H */
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index a71175ff98d5..67a71667a359 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -2001,3 +2001,89 @@ int irq_set_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
return err;
}
EXPORT_SYMBOL_GPL(irq_set_irqchip_state);
+
+/**
+ * irq_alloc_ipi_mapping - allocate memory for struct ipi_mapping
+ * @nr_cpus: number of CPUs the mapping will have
+ *
+ * Will allocate and setup ipi_mapping structure.
+ *
+ * Returns a valid ipi_mapping pointer on success and NULL on error.
+ */
+struct ipi_mapping *irq_alloc_ipi_mapping(unsigned int nr_cpus)
+{
+ struct ipi_mapping *map;
+ int i;
+
+ map = kzalloc(sizeof(struct ipi_mapping) +
+ BITS_TO_LONGS(nr_cpus), GFP_KERNEL);
+ if (!map)
+ return NULL;
+
+ map->nr_cpus = nr_cpus;
+
+ memset(map->cpumap, INVALID_HWIRQ, nr_cpus);
+
+ return map;
+}
+
+/**
+ * irq_free_ipi_mapping - release mempry associated with ipi_mapping struct
+ * @map: pointer to struct ipi_mapping to be freed
+ *
+ * Release the memory allocated for sturct ipi_mapping to the system.
+ */
+void irq_free_ipi_mapping(struct ipi_mapping *map)
+{
+ kfree(map);
+}
+
+/**
+ * irq_map_ipi - create a CPU to HWIRQ mapping for an IPI
+ * @map: pointer to the mapping structure
+ * @cpu: the CPU to map
+ * @hwirq: the HWIRQ to associate with @cpu
+ *
+ * Returns zero on success and negative error number on failure.
+ */
+int irq_map_ipi(struct ipi_mapping *map,
+ unsigned int cpu, irq_hw_number_t hwirq)
+{
+ if (cpu >= map->nr_cpus)
+ return -EINVAL;
+
+ map->cpumap[cpu] = hwirq;
+ map->nr_hwirqs++;
+
+ return 0;
+}
+
+/**
+ * irq_unmap_ipi - remove the CPU mapping of an IPI
+ * @map: pointer to the mapping structure
+ * @cpu: the CPU to be unmapped
+ * @hwirq: pointer to HWIRQ to be filled with old value before unampping
+ *
+ * Mark the IPI mapping of a CPU to INVALID_HWIRQ setting @hwirq to the
+ * old value before unamapping. This old value might be required by the
+ * caller to return it to the pool of IPIs in a dynamic system.
+ *
+ * Returns zero on success and negative error number on failure.
+ */
+int irq_unmap_ipi(struct ipi_mapping *map,
+ unsigned int cpu, irq_hw_number_t *hwirq)
+{
+ if (cpu >= map->nr_cpus)
+ return -EINVAL;
+
+ if (map->cpumap[cpu] == INVALID_HWIRQ)
+ return -EINVAL;
+
+ if (hwirq)
+ *hwirq = map->cpumap[cpu];
+
+ map->cpumap[cpu] = INVALID_HWIRQ;
+ map->nr_hwirqs--;
+
+ return 0;
+}
--
2.1.0
next prev parent reply other threads:[~2015-11-03 11:16 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-03 11:12 [PATCH 00/14] Implement generic IPI support mechanism Qais Yousef
2015-11-03 11:12 ` [PATCH 01/14] genirq: Add new IRQ_DOMAIN_FLAGS_IPI Qais Yousef
2015-11-03 11:12 ` [PATCH 02/14] genirq: Add DOMAIN_BUS_IPI Qais Yousef
2015-11-03 11:12 ` [PATCH 03/14] genirq: Add GENERIC_IRQ_IPI Kconfig symbol Qais Yousef
2015-11-03 11:12 ` [PATCH 04/14] genirq: Add new struct ipi_mask and helper functions Qais Yousef
2015-11-07 12:05 ` Thomas Gleixner
2015-11-03 11:12 ` [PATCH 05/14] genirq: Add struct ipi_mask to irq_data Qais Yousef
2015-11-03 11:12 ` Qais Yousef [this message]
2015-11-07 12:09 ` [PATCH 06/14] genirq: Add struct ipi_mapping and its helper functions Thomas Gleixner
2015-11-09 10:05 ` Qais Yousef
2015-11-03 11:12 ` [PATCH 07/14] genirq: Add a new generic IPI reservation code to irq core Qais Yousef
2015-11-03 12:06 ` kbuild test robot
2015-11-07 12:11 ` Thomas Gleixner
2015-11-07 13:31 ` Thomas Gleixner
2015-11-09 10:07 ` Qais Yousef
2015-11-16 15:09 ` Thomas Gleixner
2015-11-03 11:12 ` [PATCH 08/14] genirq: Add a new irq_send_ipi() to irq_chip Qais Yousef
2015-11-03 11:12 ` [PATCH 09/14] genirq: Implement irq_send_ipi() to be used by drivers Qais Yousef
2015-11-03 12:09 ` kbuild test robot
2015-11-07 12:14 ` Thomas Gleixner
2015-11-03 11:12 ` [PATCH 10/14] irqchip/mips-gic: Add a IPI hierarchy domain Qais Yousef
2015-11-07 14:51 ` Thomas Gleixner
2015-11-09 11:10 ` Qais Yousef
2015-11-16 17:17 ` Thomas Gleixner
2015-11-17 10:08 ` Qais Yousef
2015-11-17 10:11 ` Thomas Gleixner
2015-11-17 10:30 ` Qais Yousef
2015-11-20 10:48 ` Qais Yousef
2015-11-20 20:39 ` [PATCH 10/14] irqchip/mips-gic: Add a IPI hierarchy domaind Thomas Gleixner
2015-11-23 16:55 ` Qais Yousef
2015-11-12 15:12 ` [PATCH 10/14] irqchip/mips-gic: Add a IPI hierarchy domain Qais Yousef
2015-11-16 17:24 ` Thomas Gleixner
2015-11-17 10:24 ` Qais Yousef
2015-11-17 10:30 ` Thomas Gleixner
2015-11-03 11:12 ` [PATCH 11/14] MIPS: Add generic SMP IPI support Qais Yousef
2015-11-03 11:12 ` [PATCH 12/14] MIPS: Make smp CMP, CPS and MT use the new generic IPI functions Qais Yousef
2015-11-03 11:13 ` [PATCH 13/14] MIPS: Delete smp-gic.c Qais Yousef
2015-11-03 11:13 ` [PATCH 14/14] Docs: IRQ: Add new IRQ-ipi.txt Qais Yousef
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=1446549181-31788-7-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;
as well as URLs for NNTP newsgroup(s).