mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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>,
	<lisa.parratt@imgtec.com>, Qais Yousef <qais.yousef@imgtec.com>
Subject: [PATCH v4 04/19] genirq: Add struct ipi_mapping and its helper functions
Date: Tue, 8 Dec 2015 13:20:15 +0000	[thread overview]
Message-ID: <1449580830-23652-5-git-send-email-qais.yousef@imgtec.com> (raw)
In-Reply-To: <1449580830-23652-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.

The use of this mapping mechanism is optional. Irqchips might have better and
simpler ways to represent the mapping without using this.

Signed-off-by: Qais Yousef <qais.yousef@imgtec.com>
---
 include/linux/irq.h |  43 +++++++++++++++++++++
 kernel/irq/Makefile |   1 +
 kernel/irq/ipi.c    | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 153 insertions(+)
 create mode 100644 kernel/irq/ipi.c

diff --git a/include/linux/irq.h b/include/linux/irq.h
index 3c1c96786248..14f1c036119c 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -128,6 +128,18 @@ struct msi_desc;
 struct irq_domain;
 
 /**
+ * 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 irq_common_data - per irq data shared by all irqchips
  * @state_use_accessors: status information for irq chip functions.
  *			Use accessor functions to deal with it
@@ -135,6 +147,9 @@ struct irq_domain;
  * @handler_data:	per-IRQ data for the irq_chip methods
  * @affinity:		IRQ affinity on SMP
  * @msi_desc:		MSI descriptor
+ * @ipi_mapping:	Contains the hwirq mapping of IPIs.
+ *			The use of this struct is optional and not all irqchips
+ *			will use it.
  */
 struct irq_common_data {
 	unsigned int		state_use_accessors;
@@ -144,6 +159,9 @@ struct irq_common_data {
 	void			*handler_data;
 	struct msi_desc		*msi_desc;
 	cpumask_var_t		affinity;
+#ifdef CONFIG_GENERIC_IRQ_IPI
+	struct ipi_mapping	*ipi_map;
+#endif
 };
 
 /**
@@ -681,6 +699,21 @@ static inline struct cpumask *irq_data_get_affinity_mask(struct irq_data *d)
 	return d->common->affinity;
 }
 
+#ifdef CONFIG_GENERIC_IRQ_IPI
+
+static inline struct ipi_mapping *irq_data_get_ipi_map(struct irq_data *d)
+{
+	return d->common->ipi_map;
+}
+
+static inline void irq_data_set_ipi_map(struct irq_data *d,
+					struct ipi_mapping *map)
+{
+	d->common->ipi_map = map;
+}
+
+#endif
+
 unsigned int arch_dynirq_lower_bound(unsigned int from);
 
 int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
@@ -934,4 +967,14 @@ static inline u32 irq_reg_readl(struct irq_chip_generic *gc,
 		return readl(gc->reg_base + reg_offset);
 }
 
+#define INVALID_HWIRQ	-1
+
+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 irq_ipi_mapping_get_hwirq(struct ipi_mapping *map,
+					  unsigned int cpu);
+
 #endif /* _LINUX_IRQ_H */
diff --git a/kernel/irq/Makefile b/kernel/irq/Makefile
index 2fc9cbdf35b6..2ee42e95a3ce 100644
--- a/kernel/irq/Makefile
+++ b/kernel/irq/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_GENERIC_PENDING_IRQ) += migration.o
 obj-$(CONFIG_GENERIC_IRQ_MIGRATION) += cpuhotplug.o
 obj-$(CONFIG_PM_SLEEP) += pm.o
 obj-$(CONFIG_GENERIC_MSI_IRQ) += msi.o
+obj-$(CONFIG_GENERIC_IRQ_IPI) += ipi.o
diff --git a/kernel/irq/ipi.c b/kernel/irq/ipi.c
new file mode 100644
index 000000000000..8cf76852982f
--- /dev/null
+++ b/kernel/irq/ipi.c
@@ -0,0 +1,109 @@
+/*
+ * linux/kernel/irq/ipi.c
+ *
+ * Copyright (C) 2015 Imagination Technologies Ltd
+ * Author: Qais Yousef <qais.yousef@imgtec.com>
+ *
+ * This file contains driver APIs to the IPI subsystem.
+ */
+
+#include <linux/irq.h>
+#include <linux/slab.h>
+
+/**
+ * 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;
+	size_t size;
+
+	size = sizeof(struct ipi_mapping) + BITS_TO_LONGS(nr_cpus) * sizeof(long);
+
+	map = kzalloc(size, GFP_KERNEL);
+	if (!map)
+		return NULL;
+
+	map->nr_cpus = nr_cpus;
+
+	memset(map->cpumap, INVALID_HWIRQ, size);
+
+	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
+ *
+ * Mark the IPI mapping of a CPU to INVALID_HWIRQ.
+ *
+ * Returns zero on success and negative error number on failure.
+ */
+int irq_unmap_ipi(struct ipi_mapping *map, unsigned int cpu)
+{
+	if (cpu >= map->nr_cpus)
+		return -EINVAL;
+
+	if (map->cpumap[cpu] == INVALID_HWIRQ)
+		return -EINVAL;
+
+	map->cpumap[cpu] = INVALID_HWIRQ;
+	map->nr_hwirqs--;
+
+	return 0;
+}
+
+/**
+ * irq_ipi_mapping_get_hwirq - get the value of hwirq associated with @cpu
+ * @map: pointer to the mapping structure
+ * @cpu: the CPU to get its associated hwirq
+ *
+ * Return the hwiq asocaited with a @cpu
+ *
+ * Returns hwirq value on success and INVALID_HWIRQ on failure.
+ */
+irq_hw_number_t irq_ipi_mapping_get_hwirq(struct ipi_mapping *map,
+					  unsigned int cpu)
+{
+	if (cpu >= map->nr_cpus)
+		return INVALID_HWIRQ;
+
+	return map->cpumap[cpu];
+}
-- 
2.1.0


  parent reply	other threads:[~2015-12-08 13:21 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-08 13:20 [PATCH v4 00/19] Implement generic IPI support mechanism Qais Yousef
2015-12-08 13:20 ` [PATCH v4 01/19] genirq: Add new IRQ_DOMAIN_FLAGS_IPI Qais Yousef
2016-02-25 10:00   ` [tip:irq/core] genirq: Add new IPI irqdomain flags tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 02/19] genirq: Add DOMAIN_BUS_IPI Qais Yousef
2016-02-25 10:00   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 03/19] genirq: Add GENERIC_IRQ_IPI Kconfig symbol Qais Yousef
2016-02-25 10:01   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` Qais Yousef [this message]
2015-12-08 13:20 ` [PATCH v4 05/19] genirq: Add ipi_offset to irq_common_data Qais Yousef
2016-02-25 10:01   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 06/19] genirq: Add an extra comment about the use of affinity in irq_common_data Qais Yousef
2016-02-25 10:01   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 07/19] genirq: Make irq_domain_alloc_descs() non static Qais Yousef
2016-02-25 10:02   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 08/19] genirq: Add a new generic IPI reservation code to irq core Qais Yousef
2016-02-25 10:02   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 09/19] genirq: Add a new function to get IPI reverse mapping Qais Yousef
2016-02-25 10:02   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 10/19] genirq: Add a new irq_send_ipi() to irq_chip Qais Yousef
2016-02-25 10:03   ` [tip:irq/core] genirq: Add send_ipi callbacks " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 11/19] genirq: Implement ipi_send_{mask, single}() Qais Yousef
2016-02-25 10:03   ` [tip:irq/core] genirq: Implement ipi_send_mask/single() tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 12/19] irqchip/mips-gic: Add a IPI hierarchy domain Qais Yousef
2016-02-25 10:03   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 13/19] irqchip/mips-gic: Add device " Qais Yousef
2016-02-25 10:04   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 14/19] irqchip/mips-gic: Use gic_vpes instead of NR_CPUS Qais Yousef
2016-02-25 10:04   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 15/19] irqchip/mips-gic: Clear percpu_masks correctly when mapping Qais Yousef
2016-02-25 10:04   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 16/19] MIPS: Add generic SMP IPI support Qais Yousef
2016-02-25 10:05   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 17/19] MIPS: Make smp CMP, CPS and MT use the new generic IPI functions Qais Yousef
2015-12-09 10:30   ` kbuild test robot
2016-02-25 10:05   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 18/19] MIPS: Delete smp-gic.c Qais Yousef
2016-02-25 10:05   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 13:20 ` [PATCH v4 19/19] irqchip/mips-gic: Add new DT property to reserve IPIs Qais Yousef
2016-02-25 10:06   ` [tip:irq/core] " tip-bot for Qais Yousef
2015-12-08 21:20 ` [PATCH v4 00/19] Implement generic IPI support mechanism Thomas Gleixner

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=1449580830-23652-5-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=lisa.parratt@imgtec.com \
    --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®