Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1261411 > unrolled thread

[PATCH 06/14] genirq: Add struct ipi_mapping and its helper functions

Started byQais Yousef <qais.yousef@imgtec.com>
First post2015-11-03 12:20 +0100
Last post2015-11-09 11:10 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 06/14] genirq: Add struct ipi_mapping and its helper functions Qais Yousef <qais.yousef@imgtec.com> - 2015-11-03 12:20 +0100
    Re: [PATCH 06/14] genirq: Add struct ipi_mapping and its helper  functions Thomas Gleixner <tglx@linutronix.de> - 2015-11-07 13:20 +0100
      Re: [PATCH 06/14] genirq: Add struct ipi_mapping and its helper  functions Qais Yousef <qais.yousef@imgtec.com> - 2015-11-09 11:10 +0100

#1261411 — [PATCH 06/14] genirq: Add struct ipi_mapping and its helper functions

FromQais Yousef <qais.yousef@imgtec.com>
Date2015-11-03 12:20 +0100
Subject[PATCH 06/14] genirq: Add struct ipi_mapping and its helper functions
Message-ID<qqHN8-1ZB-25@gated-at.bofh.it>
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1264826 — Re: [PATCH 06/14] genirq: Add struct ipi_mapping and its helper functions

FromThomas Gleixner <tglx@linutronix.de>
Date2015-11-07 13:20 +0100
SubjectRe: [PATCH 06/14] genirq: Add struct ipi_mapping and its helper functions
Message-ID<qsaDn-29u-9@gated-at.bofh.it>
In reply to#1261411
On Tue, 3 Nov 2015, Qais Yousef wrote:

> struct ipi_mapping will provide a mechanism for irqchip code to fill out the
> mapping at reservation and to look it up when sending.

I'm fine with the code, but can you please move it to w new file,
i.e. kernel/irq/ipi.c and make the compilation depend on GENERIC_IPI?

Thanks,

	tglx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1265500 — Re: [PATCH 06/14] genirq: Add struct ipi_mapping and its helper functions

FromQais Yousef <qais.yousef@imgtec.com>
Date2015-11-09 11:10 +0100
SubjectRe: [PATCH 06/14] genirq: Add struct ipi_mapping and its helper functions
Message-ID<qsRyF-50w-1@gated-at.bofh.it>
In reply to#1264826
On 11/07/2015 12:09 PM, Thomas Gleixner wrote:
> On Tue, 3 Nov 2015, Qais Yousef wrote:
>
>> struct ipi_mapping will provide a mechanism for irqchip code to fill out the
>> mapping at reservation and to look it up when sending.
> I'm fine with the code, but can you please move it to w new file,
> i.e. kernel/irq/ipi.c and make the compilation depend on GENERIC_IPI?

I originally had ipi.c then removed it. I'll move all functionality there.

Thanks,
Qais
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web