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


Groups > linux.kernel > #1245542 > unrolled thread

[RFC v2 PATCH 06/14] irq: add struct ipi_mapping and its helper functions

Started byQais Yousef <qais.yousef@imgtec.com>
First post2015-10-13 12:20 +0200
Last post2015-10-13 16:40 +0200
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

  [RFC v2 PATCH 06/14] irq: add struct ipi_mapping and its helper functions Qais Yousef <qais.yousef@imgtec.com> - 2015-10-13 12:20 +0200
    Re: [RFC v2 PATCH 06/14] irq: add struct ipi_mapping and its helper  functions Thomas Gleixner <tglx@linutronix.de> - 2015-10-13 15:40 +0200
      Re: [RFC v2 PATCH 06/14] irq: add struct ipi_mapping and its helper  functions Qais Yousef <qais.yousef@imgtec.com> - 2015-10-13 16:40 +0200

#1245542 — [RFC v2 PATCH 06/14] irq: add struct ipi_mapping and its helper functions

FromQais Yousef <qais.yousef@imgtec.com>
Date2015-10-13 12:20 +0200
Subject[RFC v2 PATCH 06/14] irq: add struct ipi_mapping and its helper functions
Message-ID<qj4QA-3vO-35@gated-at.bofh.it>
struct ipi_mapping will provide a mechanism for irqdomain/architure
code to fill out the mapping for the generic code later to implement
generic IPI reserve and send functions.

Signed-off-by: Qais Yousef <qais.yousef@imgtec.com>
---
 include/linux/irq.h | 21 +++++++++++++++++++
 kernel/irq/manage.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index b000b217ea24..c3d0f26c3eff 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -964,4 +964,25 @@ 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 - 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 f9a59f6cabd2..9a9bc0822c8f 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -1924,3 +1924,62 @@ int irq_set_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
 	return err;
 }
 EXPORT_SYMBOL_GPL(irq_set_irqchip_state);
+
+struct ipi_mapping *irq_alloc_ipi_mapping(unsigned int nr_cpus)
+{
+	struct ipi_mapping *map;
+	int i;
+
+	map = kzalloc(sizeof(struct ipi_mapping), GFP_KERNEL);
+	if (!map)
+		return NULL;
+
+	map->nr_cpus = nr_cpus;
+
+	map->cpumap = kmalloc(sizeof(irq_hw_number_t) * nr_cpus, GFP_KERNEL);
+	if (!map->cpumap) {
+		kfree(map);
+		return NULL;
+	}
+
+	for (i = 0; i < nr_cpus; i++)
+		map->cpumap[i] = INVALID_HWIRQ;
+
+	return map;
+}
+
+void irq_free_ipi_mapping(struct ipi_mapping *map)
+{
+	kfree(map->cpumap);
+	kfree(map);
+}
+
+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;
+}
+
+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]


#1245721 — Re: [RFC v2 PATCH 06/14] irq: add struct ipi_mapping and its helper functions

FromThomas Gleixner <tglx@linutronix.de>
Date2015-10-13 15:40 +0200
SubjectRe: [RFC v2 PATCH 06/14] irq: add struct ipi_mapping and its helper functions
Message-ID<qj7Y6-819-31@gated-at.bofh.it>
In reply to#1245542
On Tue, 13 Oct 2015, Qais Yousef wrote:

> struct ipi_mapping will provide a mechanism for irqdomain/architure
> code to fill out the mapping for the generic code later to implement
> generic IPI reserve and send functions.
> 
> Signed-off-by: Qais Yousef <qais.yousef@imgtec.com>
> ---
>  include/linux/irq.h | 21 +++++++++++++++++++
>  kernel/irq/manage.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 80 insertions(+)
> 
> diff --git a/include/linux/irq.h b/include/linux/irq.h
> index b000b217ea24..c3d0f26c3eff 100644
> --- a/include/linux/irq.h
> +++ b/include/linux/irq.h
> @@ -964,4 +964,25 @@ 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 - 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;
> +};

Again, you can avoid seperate allocations and pointer indirections by
s/*cpumap/cpumap[]/
      
> +struct ipi_mapping *irq_alloc_ipi_mapping(unsigned int nr_cpus)
> +{
> +	struct ipi_mapping *map;
> +	int i;
> +
> +	map = kzalloc(sizeof(struct ipi_mapping), GFP_KERNEL);
> +	if (!map)
> +		return NULL;
> +
> +	map->nr_cpus = nr_cpus;
> +
> +	map->cpumap = kmalloc(sizeof(irq_hw_number_t) * nr_cpus, GFP_KERNEL);
> +	if (!map->cpumap) {
> +		kfree(map);
> +		return NULL;
> +	}
> +	for (i = 0; i < nr_cpus; i++)
> +		map->cpumap[i] = INVALID_HWIRQ;

memset please

> +
> +	return map;
> +}
> +
> +void irq_free_ipi_mapping(struct ipi_mapping *map)
> +{
> +	kfree(map->cpumap);
> +	kfree(map);
> +}
> +
> +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;
> +}
> +
> +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];

Why do we store hwirq in unmap?

All these new functions lack kerneldoc comments.

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]


#1245791 — Re: [RFC v2 PATCH 06/14] irq: add struct ipi_mapping and its helper functions

FromQais Yousef <qais.yousef@imgtec.com>
Date2015-10-13 16:40 +0200
SubjectRe: [RFC v2 PATCH 06/14] irq: add struct ipi_mapping and its helper functions
Message-ID<qj8Ub-Wq-25@gated-at.bofh.it>
In reply to#1245721
On 10/13/2015 02:31 PM, Thomas Gleixner wrote:
> On Tue, 13 Oct 2015, Qais Yousef wrote:
>
> +
> +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];
> Why do we store hwirq in unmap?

So that the irqchip driver can return the hwirq to its available IPI pool.

>
> All these new functions lack kerneldoc comments.

Apologies about the missing docs here and in other places.

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