lkml.org 
[lkml]   [2015]   [Nov]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 04/19] genirq: Add new struct ipi_mask and helper functions
Date
cpumask is limited to NR_CPUS. Introduce ipi_mask which allows us to address
cpu range that is higher than NR_CPUS which is required for drivers to send
IPIs for coprocessor that are outside Linux CPU range.

Signed-off-by: Qais Yousef <qais.yousef@imgtec.com>
---
include/linux/irq.h | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 84 insertions(+)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index 3c1c96786248..7d8c3d88f16f 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -19,6 +19,7 @@
#include <linux/irqreturn.h>
#include <linux/irqnr.h>
#include <linux/errno.h>
+#include <linux/slab.h>
#include <linux/topology.h>
#include <linux/wait.h>
#include <linux/io.h>
@@ -128,6 +129,29 @@ struct msi_desc;
struct irq_domain;

/**
+ * struct ipi_mask - IPI mask information
+ * @nbits: number of bits in cpumask
+ * @offset: the starting position at which the first cpu is set in the mask
+ * this is only required by generic code to manage per_cpu IPIs.
+ * @global: whether the mask is SMP IPI ie: subset of cpu_possible_mask or not
+ * @cpumask: cpumask to be used when the ipi_mask is global
+ * @cpu_bitmap: the cpu bitmap to use when the ipi_mask is not global
+ *
+ * ipi_mask is similar to cpumask, but it provides nbits that's configurable
+ * rather than fixed to NR_CPUS. We need that to describe IPI masks to
+ * coprocessors that are outside the NR_CPUS range.
+ */
+struct ipi_mask {
+ unsigned int nbits;
+ unsigned int offset;
+ bool global;
+ union {
+ struct cpumask cpumask;
+ unsigned long cpu_bitmap[0];
+ };
+};
+
+/**
* 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
@@ -934,4 +958,64 @@ static inline u32 irq_reg_readl(struct irq_chip_generic *gc,
return readl(gc->reg_base + reg_offset);
}

+static inline const unsigned long *ipi_mask_bits(const struct ipi_mask *ipimask)
+{
+ if (ipimask->global)
+ return cpumask_bits(&ipimask->cpumask);
+ else
+ return ipimask->cpu_bitmap;
+}
+
+static inline unsigned int ipi_mask_weight(const struct ipi_mask *ipimask)
+{
+ if (ipimask->global)
+ return cpumask_weight(&ipimask->cpumask);
+ else
+ return bitmap_weight(ipimask->cpu_bitmap, ipimask->nbits);
+}
+
+static inline void ipi_mask_copy(struct ipi_mask *dst,
+ const struct ipi_mask *src)
+{
+ dst->nbits = src->nbits;
+ dst->global = src->global;
+
+ if (src->global)
+ return cpumask_copy(&dst->cpumask, &src->cpumask);
+ else
+ return bitmap_copy(dst->cpu_bitmap,
+ src->cpu_bitmap, src->nbits);
+}
+
+static inline struct ipi_mask *ipi_mask_alloc(unsigned int nbits)
+{
+ size_t size = sizeof(struct ipi_mask) + BITS_TO_LONGS(nbits);
+ return kzalloc(size, GFP_KERNEL);
+}
+
+static inline void ipi_mask_free(struct ipi_mask *ipimask)
+{
+ kfree(ipimask);
+}
+
+static inline void ipi_mask_set_cpumask(struct ipi_mask *ipimask,
+ const struct cpumask *cpumask)
+{
+ ipimask->nbits = nr_cpu_ids;
+ ipimask->global = true;
+ cpumask_copy(&ipimask->cpumask, cpumask);
+}
+
+static inline void ipi_mask_set_offset(struct ipi_mask *ipimask,
+ unsigned int offset)
+{
+ ipimask->offset = offset;
+}
+
+#define ipi_mask_for_each_cpu(cpu, mask) \
+ for ((cpu) = -1; \
+ (cpu) = find_next_bit(ipi_mask_bits(mask), \
+ (mask)->nbits, (cpu)+1), \
+ (cpu) < (mask)->nbits;)
+
#endif /* _LINUX_IRQ_H */
--
2.1.0


\
 
 \ /
  Last update: 2015-11-25 13:21    [W:0.149 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site