2015-11-25 12:07:30

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 00/19] Implement generic IPI support mechanism

This series adds support for a generic IPI mechanism that can be used by both
arch and drivers to send IPIs to other CPUs.

v2 introduces a big change over v1 and should have addressed all review comments.

List of changes:
- We now have 2 IPI flags to distinguish per cpu IPIs from single ones.
- IPI functions are in ipi.c
- Added offset to ipi_mask to cater for masks starting at non-zero.
- New API for sending IPIs.
- Added device hierarchy to mips-gic.
- Added a new patch to reserve mips-gic IPIs from DT.
- Dropped the Docs help for now till API stabilises.

It's hard to detail every change done but these are the headlines.
It would be good to look at all patches again. Hopefully I broke them down in
an away that is easy to review.

I hope this is close enough to how it should be done and I didn't stray off.

I tested this on Malta platform which effectively doesn't have DT support.
Unfortunately I don't have access to a platform with DT support that can run on
latest kernel. The recent changes in irq/core makes backporting the patches non
trivial.

Thanks in advance.

Qais

Qais Yousef (19):
genirq: Add new IRQ_DOMAIN_FLAGS_IPI
genirq: Add DOMAIN_BUS_IPI
genirq: Add GENERIC_IRQ_IPI Kconfig symbol
genirq: Add new struct ipi_mask and helper functions
genirq: Add struct ipi_mask to irq_data
genirq: Add struct ipi_mapping and its helper functions
genirq: Make irq_domain_alloc_descs() non static
genirq: Add a new generic IPI reservation code to irq core
genirq: Add a new function to get IPI reverse mapping
genirq: Add a new irq_send_ipi() to irq_chip
genirq: Implement ipi_send_{mask, single}()
irqchip/mips-gic: Add a IPI hierarchy domain
irqchip/mips-gic: Add device hierarchy domain
irqchip/mips-gic: Use gic_vpes instead of NR_CPUS
irqchip/mips-gic: Clear percpu_masks correctly when mapping
MIPS: Add generic SMP IPI support
MIPS: Make smp CMP, CPS and MT use the new generic IPI functions
MIPS: Delete smp-gic.c
irqchip/mips-gic: Add new DT property to reserve IPIs

.../bindings/interrupt-controller/mips-gic.txt | 7 +
arch/mips/Kconfig | 6 -
arch/mips/include/asm/smp-ops.h | 5 +-
arch/mips/kernel/Makefile | 1 -
arch/mips/kernel/smp-cmp.c | 4 +-
arch/mips/kernel/smp-cps.c | 4 +-
arch/mips/kernel/smp-gic.c | 64 ---
arch/mips/kernel/smp-mt.c | 2 +-
arch/mips/kernel/smp.c | 139 ++++++
drivers/irqchip/Kconfig | 2 +
drivers/irqchip/irq-mips-gic.c | 354 +++++++++++----
include/linux/irq.h | 152 +++++++
include/linux/irqchip/mips-gic.h | 3 -
include/linux/irqdomain.h | 46 ++
kernel/irq/Kconfig | 4 +
kernel/irq/Makefile | 1 +
kernel/irq/ipi.c | 478 +++++++++++++++++++++
kernel/irq/irqdomain.c | 6 +-
18 files changed, 1102 insertions(+), 176 deletions(-)
delete mode 100644 arch/mips/kernel/smp-gic.c
create mode 100644 kernel/irq/ipi.c

--
2.1.0


2015-11-25 12:07:43

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 01/19] genirq: Add new IRQ_DOMAIN_FLAGS_IPI

This flag will be used to identify an IPI domain.

We have two types:

- PER_CPU: indicating a virq for each IPI
- SINGLE: indicating a single virq for all IPIs

Signed-off-by: Qais Yousef <[email protected]>
---
include/linux/irqdomain.h | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)

diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index d5e5c5bef28c..c1a59f37674d 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -171,6 +171,12 @@ enum {
/* Core calls alloc/free recursive through the domain hierarchy. */
IRQ_DOMAIN_FLAG_AUTO_RECURSIVE = (1 << 1),

+ /* Irq domain is an IPI domain with virq per cpu */
+ IRQ_DOMAIN_FLAG_IPI_PER_CPU = (1 << 2),
+
+ /* Irq domain is an IPI domain with single virq */
+ IRQ_DOMAIN_FLAG_IPI_SINGLE = (1 << 3),
+
/*
* Flags starting from IRQ_DOMAIN_FLAG_NONCORE are reserved
* for implementation specific purposes and ignored by the
@@ -391,6 +397,22 @@ static inline bool irq_domain_is_hierarchy(struct irq_domain *domain)
{
return domain->flags & IRQ_DOMAIN_FLAG_HIERARCHY;
}
+
+static inline bool irq_domain_is_ipi(struct irq_domain *domain)
+{
+ return domain->flags &
+ (IRQ_DOMAIN_FLAG_IPI_PER_CPU | IRQ_DOMAIN_FLAG_IPI_SINGLE);
+}
+
+static inline bool irq_domain_is_ipi_per_cpu(struct irq_domain *domain)
+{
+ return domain->flags & IRQ_DOMAIN_FLAG_IPI_PER_CPU;
+}
+
+static inline bool irq_domain_is_ipi_single(struct irq_domain *domain)
+{
+ return domain->flags & IRQ_DOMAIN_FLAG_IPI_SINGLE;
+}
#else /* CONFIG_IRQ_DOMAIN_HIERARCHY */
static inline void irq_domain_activate_irq(struct irq_data *data) { }
static inline void irq_domain_deactivate_irq(struct irq_data *data) { }
@@ -404,6 +426,21 @@ static inline bool irq_domain_is_hierarchy(struct irq_domain *domain)
{
return false;
}
+
+static inline bool irq_domain_is_ipi(struct irq_domain *domain)
+{
+ return false;
+}
+
+static inline bool irq_domain_is_ipi_per_cpu(struct irq_domain *domain)
+{
+ return false;
+}
+
+static inline bool irq_domain_is_ipi_single(struct irq_domain *domain)
+{
+ return false;
+}
#endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */

#else /* CONFIG_IRQ_DOMAIN */
--
2.1.0

2015-11-25 12:07:50

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 02/19] genirq: Add DOMAIN_BUS_IPI

We need a way to search and match IPI domains.

Using the new enum we can use irq_find_matching_host() to do that.

Signed-off-by: Qais Yousef <[email protected]>
---
include/linux/irqdomain.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index c1a59f37674d..f717796a4d5e 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -73,6 +73,7 @@ enum irq_domain_bus_token {
DOMAIN_BUS_PCI_MSI,
DOMAIN_BUS_PLATFORM_MSI,
DOMAIN_BUS_NEXUS,
+ DOMAIN_BUS_IPI,
};

/**
--
2.1.0

2015-11-25 12:07:54

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 03/19] genirq: Add GENERIC_IRQ_IPI Kconfig symbol

irqchip should select this config to denote it supports generic IPI.

This will aid generic arch code to know when it can use generic IPI layer.

Signed-off-by: Qais Yousef <[email protected]>
---
kernel/irq/Kconfig | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/kernel/irq/Kconfig b/kernel/irq/Kconfig
index 3b48dab80164..3bbfd6a9c475 100644
--- a/kernel/irq/Kconfig
+++ b/kernel/irq/Kconfig
@@ -64,6 +64,10 @@ config IRQ_DOMAIN_HIERARCHY
bool
select IRQ_DOMAIN

+# Generic IRQ IPI support
+config GENERIC_IRQ_IPI
+ bool
+
# Generic MSI interrupt support
config GENERIC_MSI_IRQ
bool
--
2.1.0

2015-11-25 12:07:57

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 04/19] genirq: Add new struct ipi_mask and helper functions

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 <[email protected]>
---
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

2015-11-25 12:15:14

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 05/19] genirq: Add struct ipi_mask to irq_data

It has a similar role to affinity mask, but tracks the IPI affinity instead.

Signed-off-by: Qais Yousef <[email protected]>
---
include/linux/irq.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index 7d8c3d88f16f..fcdcb9394e75 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -168,6 +168,9 @@ struct irq_common_data {
void *handler_data;
struct msi_desc *msi_desc;
cpumask_var_t affinity;
+#ifdef CONFIG_GENERIC_IRQ_IPI
+ struct ipi_mask *ipi_mask;
+#endif
};

/**
@@ -705,6 +708,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_mask *irq_data_get_ipi_mask(struct irq_data *d)
+{
+ return d->common->ipi_mask;
+}
+
+static inline void irq_data_set_ipi_mask(struct irq_data *d,
+ struct ipi_mask *ipimask)
+{
+ d->common->ipi_mask = ipimask;
+}
+
+#endif
+
unsigned int arch_dynirq_lower_bound(unsigned int from);

int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
--
2.1.0

2015-11-25 12:08:00

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 06/19] genirq: Add struct ipi_mapping and its helper functions

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 <[email protected]>
---
include/linux/irq.h | 34 +++++++++++++++++
kernel/irq/Makefile | 1 +
kernel/irq/ipi.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 141 insertions(+)
create mode 100644 kernel/irq/ipi.c

diff --git a/include/linux/irq.h b/include/linux/irq.h
index fcdcb9394e75..2fb5d255313e 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -152,6 +152,18 @@ struct ipi_mask {
};

/**
+ * 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
@@ -170,6 +182,7 @@ struct irq_common_data {
cpumask_var_t affinity;
#ifdef CONFIG_GENERIC_IRQ_IPI
struct ipi_mask *ipi_mask;
+ struct ipi_mapping *ipi_map;
#endif
};

@@ -721,6 +734,17 @@ static inline void irq_data_set_ipi_mask(struct irq_data *d,
d->common->ipi_mask = ipimask;
}

+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);
@@ -1036,4 +1060,14 @@ static inline void ipi_mask_set_offset(struct ipi_mask *ipimask,
(mask)->nbits, (cpu)+1), \
(cpu) < (mask)->nbits;)

+#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..d07325498707
--- /dev/null
+++ b/kernel/irq/ipi.c
@@ -0,0 +1,106 @@
+/*
+ * linux/kernel/irq/ipi.c
+ *
+ * Copyright (C) 2015 Imagination Technologies Ltd
+ * Author: Qais Yousef <[email protected]>
+ *
+ * This file contains driver APIs to the IPI subsystem.
+ */
+
+#include <linux/irq.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;
+
+ 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
+ *
+ * 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

2015-11-25 12:08:04

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 07/19] genirq: Make irq_domain_alloc_descs() non static

We will need to use this function to implement irq_reserve_ipi() later. So make
it non static and move the prototype to irqdomain.h to allow using it outside
irqdomain.c

Signed-off-by: Qais Yousef <[email protected]>
---
include/linux/irqdomain.h | 2 ++
kernel/irq/irqdomain.c | 6 ++----
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index f717796a4d5e..fcafae8e3aaf 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -212,6 +212,8 @@ struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
extern struct irq_domain *irq_find_matching_fwnode(struct fwnode_handle *fwnode,
enum irq_domain_bus_token bus_token);
extern void irq_set_default_host(struct irq_domain *host);
+extern int irq_domain_alloc_descs(int virq, unsigned int nr_irqs,
+ irq_hw_number_t hwirq, int node);

static inline struct fwnode_handle *of_node_to_fwnode(struct device_node *node)
{
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 22aa9612ef7c..c31ab8f67f06 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -23,8 +23,6 @@ static DEFINE_MUTEX(irq_domain_mutex);
static DEFINE_MUTEX(revmap_trees_mutex);
static struct irq_domain *irq_default_domain;

-static int irq_domain_alloc_descs(int virq, unsigned int nr_irqs,
- irq_hw_number_t hwirq, int node);
static void irq_domain_check_hierarchy(struct irq_domain *domain);

struct irqchip_fwid {
@@ -833,8 +831,8 @@ const struct irq_domain_ops irq_domain_simple_ops = {
};
EXPORT_SYMBOL_GPL(irq_domain_simple_ops);

-static int irq_domain_alloc_descs(int virq, unsigned int cnt,
- irq_hw_number_t hwirq, int node)
+int irq_domain_alloc_descs(int virq, unsigned int cnt,
+ irq_hw_number_t hwirq, int node)
{
unsigned int hint;

--
2.1.0

2015-11-25 12:14:27

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 08/19] genirq: Add a new generic IPI reservation code to irq core

Add a generic mechanism to dynamically allocate an IPI.

With this change the user can call irq_reserve_ipi() to dynamically allocate an
IPI and use the associated virq to send one to 1 or more cpus.

Signed-off-by: Qais Yousef <[email protected]>
---
include/linux/irqdomain.h | 6 ++
kernel/irq/ipi.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 149 insertions(+)

diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index fcafae8e3aaf..d2eb6c266522 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -39,6 +39,7 @@ struct irq_domain;
struct of_device_id;
struct irq_chip;
struct irq_data;
+struct ipi_mask;

/* Number of irqs reserved for a legacy isa controller */
#define NUM_ISA_INTERRUPTS 16
@@ -338,6 +339,11 @@ int irq_domain_xlate_onetwocell(struct irq_domain *d, struct device_node *ctrlr,
const u32 *intspec, unsigned int intsize,
irq_hw_number_t *out_hwirq, unsigned int *out_type);

+/* IPI functions */
+unsigned int irq_reserve_ipi(struct irq_domain *domain,
+ const struct ipi_mask *dest);
+void irq_destroy_ipi(unsigned int irq);
+
/* V2 interfaces to support hierarchy IRQ domains. */
extern struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
unsigned int virq);
diff --git a/kernel/irq/ipi.c b/kernel/irq/ipi.c
index d07325498707..f2dc8c73965c 100644
--- a/kernel/irq/ipi.c
+++ b/kernel/irq/ipi.c
@@ -8,6 +8,7 @@
*/

#include <linux/irq.h>
+#include <linux/irqdomain.h>

/**
* irq_alloc_ipi_mapping - allocate memory for struct ipi_mapping
@@ -104,3 +105,145 @@ irq_hw_number_t irq_ipi_mapping_get_hwirq(struct ipi_mapping *map,

return map->cpumap[cpu];
}
+
+/**
+ * irq_reserve_ipi() - setup an IPI to destination cpumask
+ * @domain: IPI domain
+ * @dest: cpumask of cpus to receive the IPI
+ *
+ * Allocate a virq that can be used to send IPI to any CPU in dest mask.
+ *
+ * On success it'll return linux irq number and 0 on failure
+ */
+unsigned int irq_reserve_ipi(struct irq_domain *domain,
+ const struct ipi_mask *dest)
+{
+ struct ipi_mask *ipimask;
+ struct irq_data *data;
+ unsigned int nr_irqs, offset = 0;
+ int prev_cpu = -1, cpu;
+ int virq, i;
+
+ if (domain == NULL) {
+ pr_warn("Must provide a valid IPI domain!\n");
+ return 0;
+ }
+
+ if (!irq_domain_is_ipi(domain)) {
+ pr_warn("Not an IPI domain!\n");
+ return 0;
+ }
+
+ if (irq_domain_is_ipi_per_cpu(domain))
+ nr_irqs = ipi_mask_weight(dest);
+ else
+ nr_irqs = 1;
+
+ /*
+ * Disallow holes in the ipi_mask.
+ * Holes makes it difficult to manage code in generic way. So we always
+ * assume a consecutive ipi_mask. It's easy for the user to split
+ * an ipi_mask with a hole into 2 consecutive ipi_masks and manage
+ * which virq to use locally than adding generic support that would
+ * complicate the generic code.
+ */
+ ipi_mask_for_each_cpu(cpu, dest) {
+ if (prev_cpu == -1) {
+ /* while at it save the offset */
+ offset = cpu;
+ prev_cpu = cpu;
+ continue;
+ }
+
+ if (prev_cpu - cpu > 1) {
+ pr_err("Can't allocate IPIs using non consecutive ipi_mask\n");
+ return 0;
+ }
+
+ prev_cpu = cpu;
+ }
+
+ virq = irq_domain_alloc_descs(-1, nr_irqs, 0, NUMA_NO_NODE);
+ if (virq <= 0) {
+ pr_warn("Can't reserve IPI, failed to alloc descs\n");
+ return 0;
+ }
+
+ virq = __irq_domain_alloc_irqs(domain, virq, nr_irqs, NUMA_NO_NODE,
+ (void *) dest, true);
+ if (virq <= 0) {
+ pr_warn("Can't reserve IPI, failed to alloc irqs\n");
+ goto free_descs;
+ }
+
+ /* The generic code will only need the ipi_mask in the base virq.
+ * We can save memory by storing it once only there.
+ *
+ * Do we need to keep the per virq ipi_mask for the irqchip? */
+ for (i = 0; i < nr_irqs; i++) {
+ data = irq_get_irq_data(virq + i);
+ ipimask = ipi_mask_alloc(dest->nbits);
+ if (!ipimask)
+ goto free_ipi_mask;
+ ipi_mask_copy(ipimask, dest);
+ ipi_mask_set_offset(ipimask, offset);
+ irq_data_set_ipi_mask(data, ipimask);
+ }
+
+ return virq;
+
+free_ipi_mask:
+ for (i = 0; i < nr_irqs; i++) {
+ data = irq_get_irq_data(virq + i);
+ ipimask = irq_data_get_ipi_mask(data);
+ ipi_mask_free(ipimask);
+ irq_data_set_ipi_mask(data, NULL);
+ }
+free_descs:
+ irq_free_descs(virq, nr_irqs);
+ return 0;
+}
+
+/**
+ * irq_destroy_ipi() - unreserve an IPI that was previously allocated
+ * @irq: linux irq number to be destroyed
+ *
+ * Return the IPIs allocated with irq_reserve_ipi() to the system destroying all
+ * virqs associated with them.
+ */
+void irq_destroy_ipi(unsigned int irq)
+{
+ struct irq_data *data = irq_get_irq_data(irq);
+ struct ipi_mask *ipimask = data ? irq_data_get_ipi_mask(data) : NULL;
+ struct irq_domain *domain;
+ unsigned int nr_irqs, i;
+
+ if (!irq || !data || !ipimask)
+ return;
+
+ domain = data->domain;
+ if (WARN_ON(domain == NULL))
+ return;
+
+ if (!irq_domain_is_ipi(domain)) {
+ pr_warn("Not an IPI domain!\n");
+ return;
+ }
+
+ if (irq_domain_is_ipi_per_cpu(domain))
+ nr_irqs = ipi_mask_weight(ipimask);
+ else
+ nr_irqs = 1;
+
+ ipi_mask_free(ipimask);
+ irq_data_set_ipi_mask(data, NULL);
+
+ for (i = 1; i < nr_irqs; i++) {
+ data = irq_get_irq_data(irq + i);
+ ipimask = irq_data_get_ipi_mask(data);
+ ipi_mask_free(ipimask);
+ irq_data_set_ipi_mask(data, NULL);
+ }
+
+ irq_domain_free_irqs(irq, nr_irqs);
+}
--
2.1.0

2015-11-25 12:08:06

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 09/19] genirq: Add a new function to get IPI reverse mapping

When dealing with coprocessors we need to find out the actual hwirqs values to
pass on to the firmware so that it knows what it needs to use to received and
send IPIs from and to us.

Signed-off-by: Qais Yousef <[email protected]>
---
include/linux/irq.h | 2 ++
kernel/irq/ipi.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index 2fb5d255313e..9a5d1e11a08f 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -1070,4 +1070,6 @@ 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);

+irq_hw_number_t ipi_get_hwirq(unsigned int irq, unsigned int cpu);
+
#endif /* _LINUX_IRQ_H */
diff --git a/kernel/irq/ipi.c b/kernel/irq/ipi.c
index f2dc8c73965c..d6faa0e768b8 100644
--- a/kernel/irq/ipi.c
+++ b/kernel/irq/ipi.c
@@ -247,3 +247,40 @@ void irq_destroy_ipi(unsigned int irq)

irq_domain_free_irqs(irq, nr_irqs);
}
+
+/**
+ * ipi_get_hwirq - get the hwirq associated with an IPI to a cpu
+ * @irq: linux irq number
+ * @cpu: the cpu to find the revmap for
+ *
+ * When dealing with coprocessors IPI, we need to inform it of the hwirq it
+ * needs to use to receive and send IPIs. This function provides the revmap
+ * to get this info to pass on to coprocessor firmware.
+ *
+ * Returns hwirq value on success and INVALID_HWIRQ on failure.
+ */
+irq_hw_number_t ipi_get_hwirq(unsigned int irq, unsigned int cpu)
+{
+ struct irq_data *data = irq_get_irq_data(irq);
+ struct ipi_mask *ipimask = data ? irq_data_get_ipi_mask(data) : NULL;
+ irq_hw_number_t hwirq;
+
+ if (!data || !ipimask)
+ return INVALID_HWIRQ;
+
+ if (cpu > ipimask->nbits)
+ return INVALID_HWIRQ;
+
+ if (!test_bit(cpu, ipimask->cpu_bitmap))
+ return INVALID_HWIRQ;
+
+ if (irq_domain_is_ipi_per_cpu(data->domain)) {
+ data = irq_get_irq_data(irq + cpu - ipimask->offset);
+ hwirq = data ? irqd_to_hwirq(data) : INVALID_HWIRQ;
+ } else {
+ hwirq = irqd_to_hwirq(data) + cpu - ipimask->offset;
+ }
+
+ return hwirq;
+}
+EXPORT_SYMBOL_GPL(ipi_get_hwirq);
--
2.1.0

2015-11-25 12:13:58

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 10/19] genirq: Add a new irq_send_ipi() to irq_chip

Introduce the new functions to allow generic IPI send mechanism to be
used from arch and drivers code.

Signed-off-by: Qais Yousef <[email protected]>
---
include/linux/irq.h | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index 9a5d1e11a08f..ee01e89c2140 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -381,6 +381,10 @@ static inline irq_hw_number_t irqd_to_hwirq(struct irq_data *d)
* @irq_get_irqchip_state: return the internal state of an interrupt
* @irq_set_irqchip_state: set the internal state of a interrupt
* @irq_set_vcpu_affinity: optional to target a vCPU in a virtual machine
+ * @ipi_send_single: send a single IPI to destination cpus
+ * @ipi_send_mask: send an IPI to destination cpus in cpumask
+ * @ipi_send_coproc_single: send a single IPI to destination coprocessor
+ * @ipi_send_coproc_mask: send an IPI to destination corocessors in ipi_mask
* @flags: chip specific flags
*/
struct irq_chip {
@@ -425,6 +429,11 @@ struct irq_chip {

int (*irq_set_vcpu_affinity)(struct irq_data *data, void *vcpu_info);

+ void (*ipi_send_single)(struct irq_data *data, unsigned int cpu);
+ void (*ipi_send_mask)(struct irq_data *data, const struct cpumask *dest);
+ void (*ipi_send_coproc_single)(struct irq_data *data, unsigned int cpu);
+ void (*ipi_send_coproc_mask)(struct irq_data *data, const struct ipi_mask *dest);
+
unsigned long flags;
};

--
2.1.0

2015-11-25 12:08:10

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 11/19] genirq: Implement ipi_send_{mask, single}()

Add APIs to send single or mask IPI. We have 2 variants, one that uses cpumask
and to be used by arch code to send regular SMP IPIs. And another that uses
ipi_mask to be used by drivers to send IPIs to coprocessors.

Signed-off-by: Qais Yousef <[email protected]>
---
include/linux/irq.h | 5 ++
kernel/irq/ipi.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 197 insertions(+)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index ee01e89c2140..eee522a04a7c 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -1081,4 +1081,9 @@ irq_hw_number_t irq_ipi_mapping_get_hwirq(struct ipi_mapping *map,

irq_hw_number_t ipi_get_hwirq(unsigned int irq, unsigned int cpu);

+int ipi_send_single(struct irq_desc *desc, unsigned int cpu);
+int ipi_send_mask(struct irq_desc *desc, const struct cpumask *dest);
+int ipi_send_coproc_single(unsigned int virq, unsigned int cpu);
+int ipi_send_coproc_mask(unsigned int virq, const struct ipi_mask *dest);
+
#endif /* _LINUX_IRQ_H */
diff --git a/kernel/irq/ipi.c b/kernel/irq/ipi.c
index d6faa0e768b8..e07642d0e59a 100644
--- a/kernel/irq/ipi.c
+++ b/kernel/irq/ipi.c
@@ -284,3 +284,195 @@ irq_hw_number_t ipi_get_hwirq(unsigned int irq, unsigned int cpu)
return hwirq;
}
EXPORT_SYMBOL_GPL(ipi_get_hwirq);
+
+/**
+ * ipi_send_single - send an IPI to a target Linux SMP CPU
+ * @desc: pointer to irq_desc of the IRQ
+ * @cpu: dest CPU, must be the same or a subset of the mask passed to
+ * irq_reserve_ipi()
+ *
+ * Sends an IPI to a single smp cpu
+ * This function is meant to be used from arch code to send single SMP IPI.
+ *
+ * Returns zero on success and negative error number on failure.
+ */
+int ipi_send_single(struct irq_desc *desc, unsigned int cpu)
+{
+ struct irq_data *data = desc ? irq_desc_get_irq_data(desc) : NULL;
+ struct irq_chip *chip = data ? irq_data_get_irq_chip(data) : NULL;
+ struct ipi_mask *ipimask = data ? irq_data_get_ipi_mask(data) : NULL;
+ const struct cpumask *dest = cpumask_of(cpu);
+
+ /* do we want to make the checks below optional to reduce the overhead
+ * since the only user of this function is arch code? */
+ if (!chip || !ipimask)
+ return -EINVAL;
+
+ if (!chip->ipi_send_single && !chip->ipi_send_mask)
+ return -EINVAL;
+
+ if (!ipimask->global || cpu > nr_cpu_ids)
+ return -EINVAL;
+
+ if (!cpumask_subset(dest, &ipimask->cpumask))
+ return -EINVAL;
+
+ if (chip->ipi_send_single)
+ chip->ipi_send_single(data, cpu);
+ else
+ chip->ipi_send_mask(data, dest);
+ return 0;
+}
+
+/**
+ * ipi_send_mask - send an IPI to target Linux SMP CPU(s)
+ * @desc: pointer to irq_desc of the IRQ
+ * @dest: dest CPU(s), must be the same or a subset of the mask passed to
+ * irq_reserve_ipi()
+ *
+ * Sends an IPI to all smp cpus in dest mask.
+ * This function is meant to be used from arch code to send SMP IPIs.
+ *
+ * Returns zero on success and negative error number on failure.
+ */
+int ipi_send_mask(struct irq_desc *desc, const struct cpumask *dest)
+{
+ struct irq_data *data = desc ? irq_desc_get_irq_data(desc) : NULL;
+ struct irq_chip *chip = data ? irq_data_get_irq_chip(data) : NULL;
+ struct ipi_mask *ipimask = data ? irq_data_get_ipi_mask(data) : NULL;
+ unsigned int cpu;
+
+ /* do we want to make the checks below optional to reduce the overhead
+ * since the only user of this function is arch code? */
+ if (!chip || !ipimask)
+ return -EINVAL;
+
+ if (!chip->ipi_send_single && !chip->ipi_send_mask)
+ return -EINVAL;
+
+ if (!ipimask->global)
+ return -EINVAL;
+
+ if (!cpumask_subset(dest, &ipimask->cpumask))
+ return -EINVAL;
+
+ if (chip->ipi_send_mask) {
+ chip->ipi_send_mask(data, dest);
+ return 0;
+ }
+
+ if (irq_domain_is_ipi_per_cpu(data->domain)) {
+ unsigned int base_virq = data->irq;
+ for_each_cpu(cpu, dest) {
+ data = irq_get_irq_data(base_virq + cpu - ipimask->offset);
+ chip->ipi_send_single(data, cpu);
+ }
+ } else {
+ for_each_cpu(cpu, dest)
+ chip->ipi_send_single(data, cpu);
+ }
+
+ return 0;
+}
+
+/**
+ * ipi_send_coproc_single - send an IPI to a single coprocessor
+ * @virq: linux irq number from irq_reserve_ipi()
+ * @cpu: cpu value of coprocessor.
+ * Must be a subset of the mask passed to irq_reserve_ipi()
+ *
+ * Sends an IPI to single coprcessor
+ *
+ * Returns zero on success and negative error number on failure.
+ */
+int ipi_send_coproc_single(unsigned int virq, unsigned int cpu)
+{
+ struct irq_desc *desc = irq_to_desc(virq);
+ struct irq_data *data = desc ? irq_desc_get_irq_data(desc) : NULL;
+ struct irq_chip *chip = data ? irq_data_get_irq_chip(data) : NULL;
+ struct ipi_mask *ipimask = data ? irq_data_get_ipi_mask(data) : NULL;
+
+ if (!chip || !ipimask)
+ return -EINVAL;
+
+ if (!chip->ipi_send_coproc_single && !chip->ipi_send_coproc_mask)
+ return -EINVAL;
+
+ if (cpu > ipimask->nbits)
+ return -EINVAL;
+
+ if (ipimask->global)
+ return -EINVAL;
+
+ if (!test_bit(cpu, ipimask->cpu_bitmap))
+ return -EINVAL;
+
+ if (chip->ipi_send_single) {
+ chip->ipi_send_coproc_single(data, cpu);
+ } else {
+ struct ipi_mask *dest = ipi_mask_alloc(cpu);
+ if (!dest)
+ return -ENOMEM;
+ set_bit(cpu, dest->cpu_bitmap);
+ chip->ipi_send_coproc_mask(data, dest);
+ ipi_mask_free(dest);
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ipi_send_coproc_single);
+
+/**
+ * ipi_send_coproc_mask - send an IPI to target coprocessor(s)
+ * @virq: linux irq number from irq_reserve_ipi()
+ * @dest: dest CPU(s), must be the same or a subset of the mask passed to
+ * irq_reserve_ipi()
+ *
+ * Sends an IPI to all coprcessors in dest mask.
+ *
+ * Returns zero on success and negative error number on failure.
+ */
+int ipi_send_coproc_mask(unsigned int virq, const struct ipi_mask *dest)
+{
+ struct irq_desc *desc = irq_to_desc(virq);
+ struct irq_data *data = desc ? irq_desc_get_irq_data(desc) : NULL;
+ struct irq_chip *chip = data ? irq_data_get_irq_chip(data) : NULL;
+ struct ipi_mask *ipimask = data ? irq_data_get_ipi_mask(data) : NULL;
+ unsigned int cpu;
+
+ if (!chip || !ipimask)
+ return -EINVAL;
+
+ if (!chip->ipi_send_coproc_single && !chip->ipi_send_coproc_mask)
+ return -EINVAL;
+
+ if (dest->nbits > ipimask->nbits)
+ return -EINVAL;
+
+ if (ipimask->global || dest->global)
+ return -EINVAL;
+
+ if (!bitmap_subset(dest->cpu_bitmap,
+ ipimask->cpu_bitmap,
+ dest->nbits))
+ return -EINVAL;
+
+ if (chip->ipi_send_mask) {
+ chip->ipi_send_coproc_mask(data, dest);
+ return 0;
+ }
+
+ if (irq_domain_is_ipi_per_cpu(data->domain)) {
+ unsigned int base_virq = data->irq;
+ ipi_mask_for_each_cpu(cpu, dest) {
+ data = irq_get_irq_data(base_virq + cpu - ipimask->offset);
+ chip->ipi_send_coproc_single(data, cpu);
+ }
+ } else {
+ ipi_mask_for_each_cpu(cpu, dest)
+ chip->ipi_send_coproc_single(data, cpu);
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ipi_send_coproc_mask);
--
2.1.0

2015-11-25 12:12:38

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 12/19] irqchip/mips-gic: Add a IPI hierarchy domain

Add a new ipi domain on top of the normal domain.

MIPS GIC now supports dynamic allocation of an IPI.

Signed-off-by: Qais Yousef <[email protected]>
---
drivers/irqchip/Kconfig | 1 +
drivers/irqchip/irq-mips-gic.c | 183 +++++++++++++++++++++++++++++++++++++++--
2 files changed, 179 insertions(+), 5 deletions(-)

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 4d7294e5d982..e1dcfdffd2c7 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -168,6 +168,7 @@ config KEYSTONE_IRQ

config MIPS_GIC
bool
+ select IRQ_DOMAIN_HIERARCHY
select MIPS_CM

config INGENIC_IRQ
diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
index aeaa061f0dbf..8cc77336d927 100644
--- a/drivers/irqchip/irq-mips-gic.c
+++ b/drivers/irqchip/irq-mips-gic.c
@@ -29,15 +29,29 @@ struct gic_pcpu_mask {
DECLARE_BITMAP(pcpu_mask, GIC_MAX_INTRS);
};

+struct gic_irq_spec {
+ enum {
+ GIC_DEVICE,
+ GIC_IPI
+ } type;
+
+ union {
+ struct ipi_mask *ipimask;
+ unsigned int hwirq;
+ };
+};
+
static void __iomem *gic_base;
static struct gic_pcpu_mask pcpu_masks[NR_CPUS];
static DEFINE_SPINLOCK(gic_lock);
static struct irq_domain *gic_irq_domain;
+static struct irq_domain *gic_ipi_domain;
static int gic_shared_intrs;
static int gic_vpes;
static unsigned int gic_cpu_pin;
static unsigned int timer_cpu_pin;
static struct irq_chip gic_level_irq_controller, gic_edge_irq_controller;
+DECLARE_BITMAP(ipi_resrv, GIC_MAX_INTRS);

static void __gic_irq_dispatch(void);

@@ -741,7 +755,7 @@ static int gic_local_irq_domain_map(struct irq_domain *d, unsigned int virq,
}

static int gic_shared_irq_domain_map(struct irq_domain *d, unsigned int virq,
- irq_hw_number_t hw)
+ irq_hw_number_t hw, unsigned int vpe)
{
int intr = GIC_HWIRQ_TO_SHARED(hw);
unsigned long flags;
@@ -751,9 +765,8 @@ static int gic_shared_irq_domain_map(struct irq_domain *d, unsigned int virq,

spin_lock_irqsave(&gic_lock, flags);
gic_map_to_pin(intr, gic_cpu_pin);
- /* Map to VPE 0 by default */
- gic_map_to_vpe(intr, 0);
- set_bit(intr, pcpu_masks[0].pcpu_mask);
+ gic_map_to_vpe(intr, vpe);
+ set_bit(intr, pcpu_masks[vpe].pcpu_mask);
spin_unlock_irqrestore(&gic_lock, flags);

return 0;
@@ -764,7 +777,7 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq,
{
if (GIC_HWIRQ_TO_LOCAL(hw) < GIC_NUM_LOCAL_INTRS)
return gic_local_irq_domain_map(d, virq, hw);
- return gic_shared_irq_domain_map(d, virq, hw);
+ return gic_shared_irq_domain_map(d, virq, hw, 0);
}

static int gic_irq_domain_xlate(struct irq_domain *d, struct device_node *ctrlr,
@@ -786,9 +799,157 @@ static int gic_irq_domain_xlate(struct irq_domain *d, struct device_node *ctrlr,
return 0;
}

+static int gic_irq_domain_alloc(struct irq_domain *d, unsigned int virq,
+ unsigned int nr_irqs, void *arg)
+{
+ struct gic_irq_spec *spec = arg;
+ irq_hw_number_t hwirq, base_hwirq;
+ int cpu, ret, i;
+
+ if (spec->type == GIC_DEVICE) {
+ /* verify that it doesn't conflict with an IPI irq */
+ if (test_bit(spec->hwirq, ipi_resrv))
+ return -EBUSY;
+ } else {
+ base_hwirq = find_first_bit(ipi_resrv, gic_shared_intrs);
+ if (base_hwirq == gic_shared_intrs) {
+ return -ENOMEM;
+ }
+
+ /* check that we have enough space */
+ for (i = base_hwirq; i < nr_irqs; i++) {
+ if (!test_bit(i, ipi_resrv))
+ return -EBUSY;
+ }
+ bitmap_clear(ipi_resrv, base_hwirq, nr_irqs);
+
+ /* map the hwirq for each cpu consecutively */
+ i = 0;
+ ipi_mask_for_each_cpu(cpu, spec->ipimask) {
+ hwirq = GIC_SHARED_TO_HWIRQ(base_hwirq + i);
+
+ ret = irq_domain_set_hwirq_and_chip(d, virq + i, hwirq,
+ &gic_edge_irq_controller,
+ NULL);
+ if (ret)
+ goto error;
+
+ ret = gic_shared_irq_domain_map(d, virq + i, hwirq, cpu);
+ if (ret)
+ goto error;
+
+ i++;
+ }
+
+ /*
+ * tell the parent about the base hwirq we allocated so it can
+ * set its own domain data
+ */
+ spec->hwirq = base_hwirq;
+ }
+
+ return 0;
+error:
+ bitmap_set(ipi_resrv, base_hwirq, nr_irqs);
+ return ret;
+}
+
+void gic_irq_domain_free(struct irq_domain *d, unsigned int virq,
+ unsigned int nr_irqs)
+{
+ irq_hw_number_t base_hwirq;
+ struct irq_data *data;
+
+ data = irq_get_irq_data(virq);
+ if (!data)
+ return;
+
+ base_hwirq = irqd_to_hwirq(data);
+ bitmap_set(ipi_resrv, base_hwirq, nr_irqs);
+}
+
static const struct irq_domain_ops gic_irq_domain_ops = {
.map = gic_irq_domain_map,
.xlate = gic_irq_domain_xlate,
+ .alloc = gic_irq_domain_alloc,
+ .free = gic_irq_domain_free,
+};
+
+static int gic_ipi_domain_xlate(struct irq_domain *d, struct device_node *ctrlr,
+ const u32 *intspec, unsigned int intsize,
+ irq_hw_number_t *out_hwirq,
+ unsigned int *out_type)
+{
+ /*
+ * There's nothing to translate here. hwirq is dynamically allocated and
+ * the irq type is always edge triggered.
+ * */
+ *out_hwirq = 0;
+ *out_type = IRQ_TYPE_EDGE_RISING;
+
+ return 0;
+}
+
+static int gic_ipi_domain_alloc(struct irq_domain *d, unsigned int virq,
+ unsigned int nr_irqs, void *arg)
+{
+ struct ipi_mask *ipimask = arg;
+ struct gic_irq_spec spec = {
+ .type = GIC_IPI,
+ .ipimask = ipimask
+ };
+ int ret, i;
+
+ ret = irq_domain_alloc_irqs_parent(d, virq, nr_irqs, &spec);
+ if (ret)
+ return ret;
+
+ /* the parent should have set spec.hwirq to the base_hwirq it allocated */
+ for (i = 0; i < nr_irqs; i++) {
+ ret = irq_domain_set_hwirq_and_chip(d, virq + i,
+ GIC_SHARED_TO_HWIRQ(spec.hwirq + i),
+ &gic_edge_irq_controller,
+ NULL);
+ if (ret)
+ goto error;
+
+ ret = irq_set_irq_type(virq + i, IRQ_TYPE_EDGE_RISING);
+ if (ret)
+ goto error;
+ }
+
+ return 0;
+error:
+ irq_domain_free_irqs_parent(d, virq, nr_irqs);
+ return ret;
+}
+
+void gic_ipi_domain_free(struct irq_domain *d, unsigned int virq,
+ unsigned int nr_irqs)
+{
+ irq_domain_free_irqs_parent(d, virq, nr_irqs);
+}
+
+int gic_ipi_domain_match(struct irq_domain *d, struct device_node *node,
+ enum irq_domain_bus_token bus_token)
+{
+ bool is_ipi;
+
+ switch (bus_token) {
+ case DOMAIN_BUS_IPI:
+ is_ipi = d->bus_token == bus_token;
+ return to_of_node(d->fwnode) == node && is_ipi;
+ break;
+ default:
+ return 0;
+ }
+}
+
+static struct irq_domain_ops gic_ipi_domain_ops = {
+ .xlate = gic_ipi_domain_xlate,
+ .alloc = gic_ipi_domain_alloc,
+ .free = gic_ipi_domain_free,
+ .match = gic_ipi_domain_match,
};

static void __init __gic_init(unsigned long gic_base_addr,
@@ -850,6 +1011,18 @@ static void __init __gic_init(unsigned long gic_base_addr,
if (!gic_irq_domain)
panic("Failed to add GIC IRQ domain");

+ gic_ipi_domain = irq_domain_add_hierarchy(gic_irq_domain,
+ IRQ_DOMAIN_FLAG_IPI_PER_CPU,
+ GIC_NUM_LOCAL_INTRS + gic_shared_intrs,
+ node, &gic_ipi_domain_ops, NULL);
+ if (!gic_ipi_domain)
+ panic("Failed to add GIC IPI domain");
+
+ gic_ipi_domain->bus_token = DOMAIN_BUS_IPI;
+
+ /* Make the last 2 * NR_CPUS available for IPIs */
+ bitmap_set(ipi_resrv, gic_shared_intrs - 2 * NR_CPUS, 2 * NR_CPUS);
+
gic_basic_init();

gic_ipi_init();
--
2.1.0

2015-11-25 12:12:15

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 13/19] irqchip/mips-gic: Add device hierarchy domain

Now the root gic_irq_domain is split into device and IPI domains.

This form provides a better representation of how the root domain is split into
2. One for devices and one for IPIs.

Signed-off-by: Qais Yousef <[email protected]>
---
drivers/irqchip/irq-mips-gic.c | 103 +++++++++++++++++++++++++++++++++--------
1 file changed, 83 insertions(+), 20 deletions(-)

diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
index 8cc77336d927..8ce5731bd40d 100644
--- a/drivers/irqchip/irq-mips-gic.c
+++ b/drivers/irqchip/irq-mips-gic.c
@@ -45,6 +45,7 @@ static void __iomem *gic_base;
static struct gic_pcpu_mask pcpu_masks[NR_CPUS];
static DEFINE_SPINLOCK(gic_lock);
static struct irq_domain *gic_irq_domain;
+static struct irq_domain *gic_dev_domain;
static struct irq_domain *gic_ipi_domain;
static int gic_shared_intrs;
static int gic_vpes;
@@ -780,25 +781,6 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq,
return gic_shared_irq_domain_map(d, virq, hw, 0);
}

-static int gic_irq_domain_xlate(struct irq_domain *d, struct device_node *ctrlr,
- const u32 *intspec, unsigned int intsize,
- irq_hw_number_t *out_hwirq,
- unsigned int *out_type)
-{
- if (intsize != 3)
- return -EINVAL;
-
- if (intspec[0] == GIC_SHARED)
- *out_hwirq = GIC_SHARED_TO_HWIRQ(intspec[1]);
- else if (intspec[0] == GIC_LOCAL)
- *out_hwirq = GIC_LOCAL_TO_HWIRQ(intspec[1]);
- else
- return -EINVAL;
- *out_type = intspec[2] & IRQ_TYPE_SENSE_MASK;
-
- return 0;
-}
-
static int gic_irq_domain_alloc(struct irq_domain *d, unsigned int virq,
unsigned int nr_irqs, void *arg)
{
@@ -868,11 +850,86 @@ void gic_irq_domain_free(struct irq_domain *d, unsigned int virq,
bitmap_set(ipi_resrv, base_hwirq, nr_irqs);
}

+int gic_irq_domain_match(struct irq_domain *d, struct device_node *node,
+ enum irq_domain_bus_token bus_token)
+{
+ /* this domain should'nt be accessed directly */
+ return 0;
+}
+
static const struct irq_domain_ops gic_irq_domain_ops = {
.map = gic_irq_domain_map,
- .xlate = gic_irq_domain_xlate,
.alloc = gic_irq_domain_alloc,
.free = gic_irq_domain_free,
+ .match = gic_irq_domain_match,
+};
+
+static int gic_dev_domain_xlate(struct irq_domain *d, struct device_node *ctrlr,
+ const u32 *intspec, unsigned int intsize,
+ irq_hw_number_t *out_hwirq,
+ unsigned int *out_type)
+{
+ if (intsize != 3)
+ return -EINVAL;
+
+ if (intspec[0] == GIC_SHARED)
+ *out_hwirq = GIC_SHARED_TO_HWIRQ(intspec[1]);
+ else if (intspec[0] == GIC_LOCAL)
+ *out_hwirq = GIC_LOCAL_TO_HWIRQ(intspec[1]);
+ else
+ return -EINVAL;
+ *out_type = intspec[2] & IRQ_TYPE_SENSE_MASK;
+
+ return 0;
+}
+
+static int gic_dev_domain_alloc(struct irq_domain *d, unsigned int virq,
+ unsigned int nr_irqs, void *arg)
+{
+ struct irq_fwspec *fwspec = arg;
+ struct gic_irq_spec spec = {
+ .type = GIC_DEVICE,
+ .hwirq = fwspec->param[1],
+ };
+ int i, ret;
+ bool is_shared = fwspec->param[0] == GIC_SHARED;
+
+ if (is_shared) {
+ ret = irq_domain_alloc_irqs_parent(d, virq, nr_irqs, &spec);
+ if (ret)
+ return ret;
+ }
+
+ for (i = 0; i < nr_irqs; i++) {
+ irq_hw_number_t hwirq;
+
+ if (is_shared)
+ hwirq = GIC_SHARED_TO_HWIRQ(spec.hwirq + i);
+ else
+ hwirq = GIC_LOCAL_TO_HWIRQ(spec.hwirq + i);
+
+ ret = irq_domain_set_hwirq_and_chip(d, virq + i,
+ hwirq,
+ &gic_level_irq_controller,
+ NULL);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+void gic_dev_domain_free(struct irq_domain *d, unsigned int virq,
+ unsigned int nr_irqs)
+{
+ /* no real allocation is done for dev irqs, so no need to free anything */
+ return;
+}
+
+static struct irq_domain_ops gic_dev_domain_ops = {
+ .xlate = gic_dev_domain_xlate,
+ .alloc = gic_dev_domain_alloc,
+ .free = gic_dev_domain_free,
};

static int gic_ipi_domain_xlate(struct irq_domain *d, struct device_node *ctrlr,
@@ -1011,6 +1068,12 @@ static void __init __gic_init(unsigned long gic_base_addr,
if (!gic_irq_domain)
panic("Failed to add GIC IRQ domain");

+ gic_dev_domain = irq_domain_add_hierarchy(gic_irq_domain, 0,
+ GIC_NUM_LOCAL_INTRS + gic_shared_intrs,
+ node, &gic_dev_domain_ops, NULL);
+ if (!gic_dev_domain)
+ panic("Failed to add GIC DEV domain");
+
gic_ipi_domain = irq_domain_add_hierarchy(gic_irq_domain,
IRQ_DOMAIN_FLAG_IPI_PER_CPU,
GIC_NUM_LOCAL_INTRS + gic_shared_intrs,
--
2.1.0

2015-11-25 12:08:13

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 14/19] irqchip/mips-gic: Use gic_vpes instead of NR_CPUS

NR_CPUS is set by Kconfig and could be much higher than what actually is in the
system.

gic_vpes should be a true representitives of the number of cpus in the system,
so use it instead.

Signed-off-by: Qais Yousef <[email protected]>
---
drivers/irqchip/irq-mips-gic.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
index 8ce5731bd40d..00d197c24e16 100644
--- a/drivers/irqchip/irq-mips-gic.c
+++ b/drivers/irqchip/irq-mips-gic.c
@@ -452,7 +452,7 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *cpumask,
gic_map_to_vpe(irq, mips_cm_vp_id(cpumask_first(&tmp)));

/* Update the pcpu_masks */
- for (i = 0; i < NR_CPUS; i++)
+ for (i = 0; i < gic_vpes; i++)
clear_bit(irq, pcpu_masks[i].pcpu_mask);
set_bit(irq, pcpu_masks[cpumask_first(&tmp)].pcpu_mask);

@@ -1084,7 +1084,7 @@ static void __init __gic_init(unsigned long gic_base_addr,
gic_ipi_domain->bus_token = DOMAIN_BUS_IPI;

/* Make the last 2 * NR_CPUS available for IPIs */
- bitmap_set(ipi_resrv, gic_shared_intrs - 2 * NR_CPUS, 2 * NR_CPUS);
+ bitmap_set(ipi_resrv, gic_shared_intrs - 2 * gic_vpes, 2 * gic_vpes);

gic_basic_init();

--
2.1.0

2015-11-25 12:10:59

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 15/19] irqchip/mips-gic: Clear percpu_masks correctly when mapping

When setting the mapping for a hwirq, make sure we clear percpu_masks for
all other cpus in case it was set previously.

Signed-off-by: Qais Yousef <[email protected]>
---
drivers/irqchip/irq-mips-gic.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
index 00d197c24e16..723135dcacb3 100644
--- a/drivers/irqchip/irq-mips-gic.c
+++ b/drivers/irqchip/irq-mips-gic.c
@@ -760,6 +760,7 @@ static int gic_shared_irq_domain_map(struct irq_domain *d, unsigned int virq,
{
int intr = GIC_HWIRQ_TO_SHARED(hw);
unsigned long flags;
+ int i;

irq_set_chip_and_handler(virq, &gic_level_irq_controller,
handle_level_irq);
@@ -767,6 +768,8 @@ static int gic_shared_irq_domain_map(struct irq_domain *d, unsigned int virq,
spin_lock_irqsave(&gic_lock, flags);
gic_map_to_pin(intr, gic_cpu_pin);
gic_map_to_vpe(intr, vpe);
+ for (i = 0; i < gic_vpes; i++)
+ clear_bit(intr, pcpu_masks[i].pcpu_mask);
set_bit(intr, pcpu_masks[vpe].pcpu_mask);
spin_unlock_irqrestore(&gic_lock, flags);

--
2.1.0

2015-11-25 12:08:17

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 16/19] MIPS: Add generic SMP IPI support

Use the new generic IPI layer to provide generic SMP IPI support if the irqchip
supports it.

Signed-off-by: Qais Yousef <[email protected]>
---
arch/mips/kernel/smp.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 139 insertions(+)

diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c
index bd4385a8e6e8..7d0a440a2b02 100644
--- a/arch/mips/kernel/smp.c
+++ b/arch/mips/kernel/smp.c
@@ -33,12 +33,16 @@
#include <linux/cpu.h>
#include <linux/err.h>
#include <linux/ftrace.h>
+#include <linux/irqdomain.h>
+#include <linux/of.h>
+#include <linux/of_irq.h>

#include <linux/atomic.h>
#include <asm/cpu.h>
#include <asm/processor.h>
#include <asm/idle.h>
#include <asm/r4k-timer.h>
+#include <asm/mips-cpc.h>
#include <asm/mmu_context.h>
#include <asm/time.h>
#include <asm/setup.h>
@@ -79,6 +83,11 @@ static cpumask_t cpu_core_setup_map;

cpumask_t cpu_coherent_mask;

+#ifdef CONFIG_GENERIC_IRQ_IPI
+static struct irq_desc *call_desc;
+static struct irq_desc *sched_desc;
+#endif
+
static inline void set_cpu_sibling_map(int cpu)
{
int i;
@@ -145,6 +154,136 @@ void register_smp_ops(struct plat_smp_ops *ops)
mp_ops = ops;
}

+#ifdef CONFIG_GENERIC_IRQ_IPI
+void mips_smp_send_ipi_single(int cpu, unsigned int action)
+{
+ mips_smp_send_ipi_mask(cpumask_of(cpu), action);
+}
+
+void mips_smp_send_ipi_mask(const struct cpumask *mask, unsigned int action)
+{
+ unsigned long flags;
+ unsigned int core;
+ int cpu;
+
+ local_irq_save(flags);
+
+ switch (action) {
+ case SMP_CALL_FUNCTION:
+ ipi_send_mask(call_desc, mask);
+ break;
+
+ case SMP_RESCHEDULE_YOURSELF:
+ ipi_send_mask(sched_desc, mask);
+ break;
+
+ default:
+ BUG();
+ }
+
+ if (mips_cpc_present()) {
+ for_each_cpu(cpu, mask) {
+ core = cpu_data[cpu].core;
+
+ if (core == current_cpu_data.core)
+ continue;
+
+ while (!cpumask_test_cpu(cpu, &cpu_coherent_mask)) {
+ mips_cpc_lock_other(core);
+ write_cpc_co_cmd(CPC_Cx_CMD_PWRUP);
+ mips_cpc_unlock_other();
+ }
+ }
+ }
+
+ local_irq_restore(flags);
+}
+
+
+static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id)
+{
+ scheduler_ipi();
+
+ return IRQ_HANDLED;
+}
+
+static irqreturn_t ipi_call_interrupt(int irq, void *dev_id)
+{
+ generic_smp_call_function_interrupt();
+
+ return IRQ_HANDLED;
+}
+
+static struct irqaction irq_resched = {
+ .handler = ipi_resched_interrupt,
+ .flags = IRQF_PERCPU,
+ .name = "IPI resched"
+};
+
+static struct irqaction irq_call = {
+ .handler = ipi_call_interrupt,
+ .flags = IRQF_PERCPU,
+ .name = "IPI call"
+};
+
+static __init void smp_ipi_init_one(unsigned int virq,
+ struct irqaction *action)
+{
+ int ret;
+
+ irq_set_handler(virq, handle_percpu_irq);
+ ret = setup_irq(virq, action);
+ BUG_ON(ret);
+}
+
+static int __init mips_smp_ipi_init(void)
+{
+ unsigned int call_virq, sched_virq;
+ struct irq_domain *ipidomain;
+ struct device_node *node;
+ struct ipi_mask ipimask;
+
+ node = of_irq_find_parent(of_root);
+ ipidomain = irq_find_matching_host(node, DOMAIN_BUS_IPI);
+
+ /*
+ * Some platforms have half DT setup. So if we found irq node but
+ * didn't find an ipidomain, try to search for one that is not in the
+ * DT.
+ */
+ if (node && !ipidomain)
+ ipidomain = irq_find_matching_host(NULL, DOMAIN_BUS_IPI);
+
+ BUG_ON(!ipidomain);
+
+ ipi_mask_set_cpumask(&ipimask, cpu_possible_mask);
+
+ call_virq = irq_reserve_ipi(ipidomain, &ipimask);
+ BUG_ON(!call_virq);
+
+ sched_virq = irq_reserve_ipi(ipidomain, &ipimask);
+ BUG_ON(!sched_virq);
+
+ if (irq_domain_is_ipi_per_cpu(ipidomain)) {
+ int cpu;
+
+ for_each_cpu(cpu, cpu_possible_mask) {
+ smp_ipi_init_one(call_virq + cpu, &irq_call);
+ smp_ipi_init_one(sched_virq + cpu, &irq_resched);
+ }
+ } else {
+ smp_ipi_init_one(call_virq, &irq_call);
+ smp_ipi_init_one(sched_virq, &irq_resched);
+ }
+
+ call_desc = irq_to_desc(call_virq);
+ sched_desc = irq_to_desc(sched_virq);
+
+ return 0;
+}
+early_initcall(mips_smp_ipi_init);
+#endif
+
/*
* First C code run on the secondary CPUs after being started up by
* the master.
--
2.1.0

2015-11-25 12:10:08

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 17/19] MIPS: Make smp CMP, CPS and MT use the new generic IPI functions

This commit does several things to avoid breaking bisectability.

1- Remove IPI init code from irqchip/mips-gic
2- Implement the new irqchip->send_ipi() in irqchip/mips-gic
3- Select GENERIC_IRQ_IPI Kconfig symbol for MIPS_GIC
4- Change MIPS SMP to use the generic IPI implementation

Only the SMP variants that use GIC were converted as it's the only irqchip that
will have the support for generic IPI for now.

Signed-off-by: Qais Yousef <[email protected]>
---
arch/mips/include/asm/smp-ops.h | 5 ++-
arch/mips/kernel/smp-cmp.c | 4 +-
arch/mips/kernel/smp-cps.c | 4 +-
arch/mips/kernel/smp-mt.c | 2 +-
drivers/irqchip/Kconfig | 1 +
drivers/irqchip/irq-mips-gic.c | 87 +++-------------------------------------
include/linux/irqchip/mips-gic.h | 3 --
7 files changed, 15 insertions(+), 91 deletions(-)

diff --git a/arch/mips/include/asm/smp-ops.h b/arch/mips/include/asm/smp-ops.h
index 6ba1fb8b11e2..db7c322f057f 100644
--- a/arch/mips/include/asm/smp-ops.h
+++ b/arch/mips/include/asm/smp-ops.h
@@ -44,8 +44,9 @@ static inline void plat_smp_setup(void)
mp_ops->smp_setup();
}

-extern void gic_send_ipi_single(int cpu, unsigned int action);
-extern void gic_send_ipi_mask(const struct cpumask *mask, unsigned int action);
+extern void mips_smp_send_ipi_single(int cpu, unsigned int action);
+extern void mips_smp_send_ipi_mask(const struct cpumask *mask,
+ unsigned int action);

#else /* !CONFIG_SMP */

diff --git a/arch/mips/kernel/smp-cmp.c b/arch/mips/kernel/smp-cmp.c
index d5e0f949dc48..76923349b4fe 100644
--- a/arch/mips/kernel/smp-cmp.c
+++ b/arch/mips/kernel/smp-cmp.c
@@ -149,8 +149,8 @@ void __init cmp_prepare_cpus(unsigned int max_cpus)
}

struct plat_smp_ops cmp_smp_ops = {
- .send_ipi_single = gic_send_ipi_single,
- .send_ipi_mask = gic_send_ipi_mask,
+ .send_ipi_single = mips_smp_send_ipi_single,
+ .send_ipi_mask = mips_smp_send_ipi_mask,
.init_secondary = cmp_init_secondary,
.smp_finish = cmp_smp_finish,
.boot_secondary = cmp_boot_secondary,
diff --git a/arch/mips/kernel/smp-cps.c b/arch/mips/kernel/smp-cps.c
index c88937745b4e..69d811e72f2b 100644
--- a/arch/mips/kernel/smp-cps.c
+++ b/arch/mips/kernel/smp-cps.c
@@ -444,8 +444,8 @@ static struct plat_smp_ops cps_smp_ops = {
.boot_secondary = cps_boot_secondary,
.init_secondary = cps_init_secondary,
.smp_finish = cps_smp_finish,
- .send_ipi_single = gic_send_ipi_single,
- .send_ipi_mask = gic_send_ipi_mask,
+ .send_ipi_single = mips_smp_send_ipi_single,
+ .send_ipi_mask = mips_smp_send_ipi_mask,
#ifdef CONFIG_HOTPLUG_CPU
.cpu_disable = cps_cpu_disable,
.cpu_die = cps_cpu_die,
diff --git a/arch/mips/kernel/smp-mt.c b/arch/mips/kernel/smp-mt.c
index 86311a164ef1..4f9570a57e8d 100644
--- a/arch/mips/kernel/smp-mt.c
+++ b/arch/mips/kernel/smp-mt.c
@@ -121,7 +121,7 @@ static void vsmp_send_ipi_single(int cpu, unsigned int action)

#ifdef CONFIG_MIPS_GIC
if (gic_present) {
- gic_send_ipi_single(cpu, action);
+ mips_smp_send_ipi_single(cpu, action);
return;
}
#endif
diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index e1dcfdffd2c7..590bc55f28da 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -168,6 +168,7 @@ config KEYSTONE_IRQ

config MIPS_GIC
bool
+ select GENERIC_IRQ_IPI
select IRQ_DOMAIN_HIERARCHY
select MIPS_CM

diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
index 723135dcacb3..c7043a15253b 100644
--- a/drivers/irqchip/irq-mips-gic.c
+++ b/drivers/irqchip/irq-mips-gic.c
@@ -278,9 +278,11 @@ static void gic_bind_eic_interrupt(int irq, int set)
GIC_VPE_EIC_SS(irq), set);
}

-void gic_send_ipi(unsigned int intr)
+static void gic_send_ipi(struct irq_data *d, unsigned int cpu)
{
- gic_write(GIC_REG(SHARED, GIC_SH_WEDGE), GIC_SH_WEDGE_SET(intr));
+ irq_hw_number_t hwirq = GIC_HWIRQ_TO_SHARED(irqd_to_hwirq(d));
+
+ gic_write(GIC_REG(SHARED, GIC_SH_WEDGE), GIC_SH_WEDGE_SET(hwirq));
}

int gic_get_c0_compare_int(void)
@@ -482,6 +484,8 @@ static struct irq_chip gic_edge_irq_controller = {
#ifdef CONFIG_SMP
.irq_set_affinity = gic_set_affinity,
#endif
+ .ipi_send_single = gic_send_ipi,
+ .ipi_send_coproc_single = gic_send_ipi,
};

static void gic_handle_local_int(bool chained)
@@ -575,83 +579,6 @@ static void gic_irq_dispatch(struct irq_desc *desc)
gic_handle_shared_int(true);
}

-#ifdef CONFIG_MIPS_GIC_IPI
-static int gic_resched_int_base;
-static int gic_call_int_base;
-
-unsigned int plat_ipi_resched_int_xlate(unsigned int cpu)
-{
- return gic_resched_int_base + cpu;
-}
-
-unsigned int plat_ipi_call_int_xlate(unsigned int cpu)
-{
- return gic_call_int_base + cpu;
-}
-
-static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id)
-{
- scheduler_ipi();
-
- return IRQ_HANDLED;
-}
-
-static irqreturn_t ipi_call_interrupt(int irq, void *dev_id)
-{
- generic_smp_call_function_interrupt();
-
- return IRQ_HANDLED;
-}
-
-static struct irqaction irq_resched = {
- .handler = ipi_resched_interrupt,
- .flags = IRQF_PERCPU,
- .name = "IPI resched"
-};
-
-static struct irqaction irq_call = {
- .handler = ipi_call_interrupt,
- .flags = IRQF_PERCPU,
- .name = "IPI call"
-};
-
-static __init void gic_ipi_init_one(unsigned int intr, int cpu,
- struct irqaction *action)
-{
- int virq = irq_create_mapping(gic_irq_domain,
- GIC_SHARED_TO_HWIRQ(intr));
- int i;
-
- gic_map_to_vpe(intr, mips_cm_vp_id(cpu));
- for (i = 0; i < NR_CPUS; i++)
- clear_bit(intr, pcpu_masks[i].pcpu_mask);
- set_bit(intr, pcpu_masks[cpu].pcpu_mask);
-
- irq_set_irq_type(virq, IRQ_TYPE_EDGE_RISING);
-
- irq_set_handler(virq, handle_percpu_irq);
- setup_irq(virq, action);
-}
-
-static __init void gic_ipi_init(void)
-{
- int i;
-
- /* Use last 2 * NR_CPUS interrupts as IPIs */
- gic_resched_int_base = gic_shared_intrs - nr_cpu_ids;
- gic_call_int_base = gic_resched_int_base - nr_cpu_ids;
-
- for (i = 0; i < nr_cpu_ids; i++) {
- gic_ipi_init_one(gic_call_int_base + i, i, &irq_call);
- gic_ipi_init_one(gic_resched_int_base + i, i, &irq_resched);
- }
-}
-#else
-static inline void gic_ipi_init(void)
-{
-}
-#endif
-
static void __init gic_basic_init(void)
{
unsigned int i;
@@ -1090,8 +1017,6 @@ static void __init __gic_init(unsigned long gic_base_addr,
bitmap_set(ipi_resrv, gic_shared_intrs - 2 * gic_vpes, 2 * gic_vpes);

gic_basic_init();
-
- gic_ipi_init();
}

void __init gic_init(unsigned long gic_base_addr,
diff --git a/include/linux/irqchip/mips-gic.h b/include/linux/irqchip/mips-gic.h
index 4e6861605050..321278767506 100644
--- a/include/linux/irqchip/mips-gic.h
+++ b/include/linux/irqchip/mips-gic.h
@@ -258,9 +258,6 @@ extern void gic_write_compare(cycle_t cnt);
extern void gic_write_cpu_compare(cycle_t cnt, int cpu);
extern void gic_start_count(void);
extern void gic_stop_count(void);
-extern void gic_send_ipi(unsigned int intr);
-extern unsigned int plat_ipi_call_int_xlate(unsigned int);
-extern unsigned int plat_ipi_resched_int_xlate(unsigned int);
extern int gic_get_c0_compare_int(void);
extern int gic_get_c0_perfcount_int(void);
extern int gic_get_c0_fdc_int(void);
--
2.1.0

2015-11-25 12:08:21

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 18/19] MIPS: Delete smp-gic.c

We now have a generic IPI layer that will use GIC automatically
if it's compiled in.

Signed-off-by: Qais Yousef <[email protected]>
---
arch/mips/Kconfig | 6 -----
arch/mips/kernel/Makefile | 1 -
arch/mips/kernel/smp-gic.c | 64 ----------------------------------------------
3 files changed, 71 deletions(-)
delete mode 100644 arch/mips/kernel/smp-gic.c

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index e3aa5b0b4ef1..5a73c1217af7 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2123,7 +2123,6 @@ config MIPS_MT_SMP
select CPU_MIPSR2_IRQ_VI
select CPU_MIPSR2_IRQ_EI
select SYNC_R4K
- select MIPS_GIC_IPI
select MIPS_MT
select SMP
select SMP_UP
@@ -2221,7 +2220,6 @@ config MIPS_VPE_APSP_API_MT
config MIPS_CMP
bool "MIPS CMP framework support (DEPRECATED)"
depends on SYS_SUPPORTS_MIPS_CMP && !CPU_MIPSR6
- select MIPS_GIC_IPI
select SMP
select SYNC_R4K
select SYS_SUPPORTS_SMP
@@ -2241,7 +2239,6 @@ config MIPS_CPS
select MIPS_CM
select MIPS_CPC
select MIPS_CPS_PM if HOTPLUG_CPU
- select MIPS_GIC_IPI
select SMP
select SYNC_R4K if (CEVT_R4K || CSRC_R4K)
select SYS_SUPPORTS_HOTPLUG_CPU
@@ -2259,9 +2256,6 @@ config MIPS_CPS_PM
select MIPS_CPC
bool

-config MIPS_GIC_IPI
- bool
-
config MIPS_CM
bool

diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
index d982be1ea1c3..a4bfc41d46b5 100644
--- a/arch/mips/kernel/Makefile
+++ b/arch/mips/kernel/Makefile
@@ -51,7 +51,6 @@ obj-$(CONFIG_MIPS_MT_FPAFF) += mips-mt-fpaff.o
obj-$(CONFIG_MIPS_MT_SMP) += smp-mt.o
obj-$(CONFIG_MIPS_CMP) += smp-cmp.o
obj-$(CONFIG_MIPS_CPS) += smp-cps.o cps-vec.o
-obj-$(CONFIG_MIPS_GIC_IPI) += smp-gic.o
obj-$(CONFIG_MIPS_SPRAM) += spram.o

obj-$(CONFIG_MIPS_VPE_LOADER) += vpe.o
diff --git a/arch/mips/kernel/smp-gic.c b/arch/mips/kernel/smp-gic.c
deleted file mode 100644
index 5f0ab5bcd01e..000000000000
--- a/arch/mips/kernel/smp-gic.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2013 Imagination Technologies
- * Author: Paul Burton <[email protected]>
- *
- * Based on smp-cmp.c:
- * Copyright (C) 2007 MIPS Technologies, Inc.
- * Author: Chris Dearman ([email protected])
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- */
-
-#include <linux/irqchip/mips-gic.h>
-#include <linux/printk.h>
-
-#include <asm/mips-cpc.h>
-#include <asm/smp-ops.h>
-
-void gic_send_ipi_single(int cpu, unsigned int action)
-{
- unsigned long flags;
- unsigned int intr;
- unsigned int core = cpu_data[cpu].core;
-
- pr_debug("CPU%d: %s cpu %d action %u status %08x\n",
- smp_processor_id(), __func__, cpu, action, read_c0_status());
-
- local_irq_save(flags);
-
- switch (action) {
- case SMP_CALL_FUNCTION:
- intr = plat_ipi_call_int_xlate(cpu);
- break;
-
- case SMP_RESCHEDULE_YOURSELF:
- intr = plat_ipi_resched_int_xlate(cpu);
- break;
-
- default:
- BUG();
- }
-
- gic_send_ipi(intr);
-
- if (mips_cpc_present() && (core != current_cpu_data.core)) {
- while (!cpumask_test_cpu(cpu, &cpu_coherent_mask)) {
- mips_cpc_lock_other(core);
- write_cpc_co_cmd(CPC_Cx_CMD_PWRUP);
- mips_cpc_unlock_other();
- }
- }
-
- local_irq_restore(flags);
-}
-
-void gic_send_ipi_mask(const struct cpumask *mask, unsigned int action)
-{
- unsigned int i;
-
- for_each_cpu(i, mask)
- gic_send_ipi_single(i, action);
-}
--
2.1.0

2015-11-25 12:08:30

by Qais Yousef

[permalink] [raw]
Subject: [PATCH v2 19/19] irqchip/mips-gic: Add new DT property to reserve IPIs

The new property will allow to specify the range of GIC hwirqs to use for IPIs.

This is an optinal property. We preserve the previous behaviour of allocating
the last 2 * gic_vpes if it's not specified or DT is not supported.

Signed-off-by: Qais Yousef <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Pawel Moll <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Kumar Gala <[email protected]>
Cc: [email protected]

---
.../devicetree/bindings/interrupt-controller/mips-gic.txt | 7 +++++++
drivers/irqchip/irq-mips-gic.c | 12 ++++++++++--
2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/interrupt-controller/mips-gic.txt b/Documentation/devicetree/bindings/interrupt-controller/mips-gic.txt
index aae4c384ee1f..173595305e26 100644
--- a/Documentation/devicetree/bindings/interrupt-controller/mips-gic.txt
+++ b/Documentation/devicetree/bindings/interrupt-controller/mips-gic.txt
@@ -23,6 +23,12 @@ Optional properties:
- mti,reserved-cpu-vectors : Specifies the list of CPU interrupt vectors
to which the GIC may not route interrupts. Valid values are 2 - 7.
This property is ignored if the CPU is started in EIC mode.
+- mti,reserved-ipi-vectors : Specifies the range of GIC interrupts that are
+ reserved for IPIs.
+ It accepts 2 values, the 1st is the starting interrupt and the 2nd is the size
+ of the reserved range.
+ If not specified, the driver will allocate the last 2 * number of VPEs in the
+ system.

Required properties for timer sub-node:
- compatible : Should be "mti,gic-timer".
@@ -44,6 +50,7 @@ Example:
#interrupt-cells = <3>;

mti,reserved-cpu-vectors = <7>;
+ mti,reserved-ipi-vectors = <40 8>;

timer {
compatible = "mti,gic-timer";
diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
index c7043a15253b..659fe734d1b7 100644
--- a/drivers/irqchip/irq-mips-gic.c
+++ b/drivers/irqchip/irq-mips-gic.c
@@ -945,6 +945,7 @@ static void __init __gic_init(unsigned long gic_base_addr,
struct device_node *node)
{
unsigned int gicconfig;
+ unsigned int v[2];

gic_base = ioremap_nocache(gic_base_addr, gic_addrspace_size);

@@ -1013,8 +1014,15 @@ static void __init __gic_init(unsigned long gic_base_addr,

gic_ipi_domain->bus_token = DOMAIN_BUS_IPI;

- /* Make the last 2 * NR_CPUS available for IPIs */
- bitmap_set(ipi_resrv, gic_shared_intrs - 2 * gic_vpes, 2 * gic_vpes);
+ if (node &&
+ !of_property_read_u32_array(node, "mti,reserved-ipi-vectors", &v, 2)) {
+ bitmap_set(ipi_resrv, v[0], v[1]);
+ } else {
+ /* Make the last 2 * gic_vpes available for IPIs */
+ bitmap_set(ipi_resrv,
+ gic_shared_intrs - 2 * gic_vpes,
+ 2 * gic_vpes);
+ }

gic_basic_init();
}
--
2.1.0

2015-11-25 16:09:29

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH v2 19/19] irqchip/mips-gic: Add new DT property to reserve IPIs

On Wed, Nov 25, 2015 at 12:06:57PM +0000, Qais Yousef wrote:
> The new property will allow to specify the range of GIC hwirqs to use for IPIs.
>
> This is an optinal property. We preserve the previous behaviour of allocating
> the last 2 * gic_vpes if it's not specified or DT is not supported.
>
> Signed-off-by: Qais Yousef <[email protected]>
> Cc: Rob Herring <[email protected]>
> Cc: Pawel Moll <[email protected]>
> Cc: Mark Rutland <[email protected]>
> Cc: Ian Campbell <[email protected]>
> Cc: Kumar Gala <[email protected]>
> Cc: [email protected]

Acked-by: Rob Herring <[email protected]>

>
> ---
> .../devicetree/bindings/interrupt-controller/mips-gic.txt | 7 +++++++
> drivers/irqchip/irq-mips-gic.c | 12 ++++++++++--
> 2 files changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/interrupt-controller/mips-gic.txt b/Documentation/devicetree/bindings/interrupt-controller/mips-gic.txt
> index aae4c384ee1f..173595305e26 100644
> --- a/Documentation/devicetree/bindings/interrupt-controller/mips-gic.txt
> +++ b/Documentation/devicetree/bindings/interrupt-controller/mips-gic.txt
> @@ -23,6 +23,12 @@ Optional properties:
> - mti,reserved-cpu-vectors : Specifies the list of CPU interrupt vectors
> to which the GIC may not route interrupts. Valid values are 2 - 7.
> This property is ignored if the CPU is started in EIC mode.
> +- mti,reserved-ipi-vectors : Specifies the range of GIC interrupts that are
> + reserved for IPIs.
> + It accepts 2 values, the 1st is the starting interrupt and the 2nd is the size
> + of the reserved range.
> + If not specified, the driver will allocate the last 2 * number of VPEs in the
> + system.
>
> Required properties for timer sub-node:
> - compatible : Should be "mti,gic-timer".
> @@ -44,6 +50,7 @@ Example:
> #interrupt-cells = <3>;
>
> mti,reserved-cpu-vectors = <7>;
> + mti,reserved-ipi-vectors = <40 8>;
>
> timer {
> compatible = "mti,gic-timer";
> diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
> index c7043a15253b..659fe734d1b7 100644
> --- a/drivers/irqchip/irq-mips-gic.c
> +++ b/drivers/irqchip/irq-mips-gic.c
> @@ -945,6 +945,7 @@ static void __init __gic_init(unsigned long gic_base_addr,
> struct device_node *node)
> {
> unsigned int gicconfig;
> + unsigned int v[2];
>
> gic_base = ioremap_nocache(gic_base_addr, gic_addrspace_size);
>
> @@ -1013,8 +1014,15 @@ static void __init __gic_init(unsigned long gic_base_addr,
>
> gic_ipi_domain->bus_token = DOMAIN_BUS_IPI;
>
> - /* Make the last 2 * NR_CPUS available for IPIs */
> - bitmap_set(ipi_resrv, gic_shared_intrs - 2 * gic_vpes, 2 * gic_vpes);
> + if (node &&
> + !of_property_read_u32_array(node, "mti,reserved-ipi-vectors", &v, 2)) {
> + bitmap_set(ipi_resrv, v[0], v[1]);
> + } else {
> + /* Make the last 2 * gic_vpes available for IPIs */
> + bitmap_set(ipi_resrv,
> + gic_shared_intrs - 2 * gic_vpes,
> + 2 * gic_vpes);
> + }
>
> gic_basic_init();
> }
> --
> 2.1.0
>

2015-11-27 11:46:43

by Qais Yousef

[permalink] [raw]
Subject: Re: [PATCH v2 09/19] genirq: Add a new function to get IPI reverse mapping

On 11/25/2015 12:06 PM, Qais Yousef wrote:
> +
> +/**
> + * ipi_get_hwirq - get the hwirq associated with an IPI to a cpu
> + * @irq: linux irq number
> + * @cpu: the cpu to find the revmap for
> + *
> + * When dealing with coprocessors IPI, we need to inform it of the hwirq it
> + * needs to use to receive and send IPIs. This function provides the revmap
> + * to get this info to pass on to coprocessor firmware.
> + *
> + * Returns hwirq value on success and INVALID_HWIRQ on failure.
> + */
> +irq_hw_number_t ipi_get_hwirq(unsigned int irq, unsigned int cpu)
> +{
> + struct irq_data *data = irq_get_irq_data(irq);
> + struct ipi_mask *ipimask = data ? irq_data_get_ipi_mask(data) : NULL;
> + irq_hw_number_t hwirq;
> +
> + if (!data || !ipimask)
> + return INVALID_HWIRQ;
> +
> + if (cpu > ipimask->nbits)
> + return INVALID_HWIRQ;
> +
> + if (!test_bit(cpu, ipimask->cpu_bitmap))
> + return INVALID_HWIRQ;
> +
> + if (irq_domain_is_ipi_per_cpu(data->domain)) {
> + data = irq_get_irq_data(irq + cpu - ipimask->offset);
> + hwirq = data ? irqd_to_hwirq(data) : INVALID_HWIRQ;
> + } else {
> + hwirq = irqd_to_hwirq(data) + cpu - ipimask->offset;
> + }
> +
> + return hwirq;
> +}
> +EXPORT_SYMBOL_GPL(ipi_get_hwirq);


While trying to get my remoteproc driver work with this I uncovered a
problem with this approach.

mips-gic doesn't store the actual hwirq in the irq_data. It uses
GIC_SHARED_TO_HWIRQ() and GIC_HWIRQ_TO_SHARED() to add and remove an offset.

I'll add a new chip function irq_get_raw_hwirq(struct irq_data *d) that
will return the real hardware value of hwirq. If not defined, I'll
revert back to using the irqd_to_hwirq().

Objections?

Thanks,
Qais

2015-11-30 10:41:33

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH v2 09/19] genirq: Add a new function to get IPI reverse mapping

On Fri, 27 Nov 2015, Qais Yousef wrote:
>
> While trying to get my remoteproc driver work with this I uncovered a problem
> with this approach.
>
> mips-gic doesn't store the actual hwirq in the irq_data. It uses
> GIC_SHARED_TO_HWIRQ() and GIC_HWIRQ_TO_SHARED() to add and remove an offset.

Why can't MIPS store the real hwirq number in irq_data?

Thanks,

tglx

2015-11-30 10:53:52

by Qais Yousef

[permalink] [raw]
Subject: Re: [PATCH v2 09/19] genirq: Add a new function to get IPI reverse mapping

On 11/30/2015 10:40 AM, Thomas Gleixner wrote:
> On Fri, 27 Nov 2015, Qais Yousef wrote:
>> While trying to get my remoteproc driver work with this I uncovered a problem
>> with this approach.
>>
>> mips-gic doesn't store the actual hwirq in the irq_data. It uses
>> GIC_SHARED_TO_HWIRQ() and GIC_HWIRQ_TO_SHARED() to add and remove an offset.
> Why can't MIPS store the real hwirq number in irq_data?


I'm wary of ending up in inconsistency hell where some functions need to
deal with raw hwirq and others with translated ones.

I will give this a go first and see if it gets really ugly.

Thanks,
Qais

2015-11-30 11:21:00

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH v2 04/19] genirq: Add new struct ipi_mask and helper functions

On Wed, 25 Nov 2015, Qais Yousef wrote:
> 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.

I have second thoughts on this.

cpumask is indeed limited to NR_CPUS or in case of CPUMASK_ON_STACK
limited to nr_cpu_ids.

But, that's not an issue for that coprocessor case. Let's assume you
have 16 Linux CPUs and 4 coprocessors. So you set the number of
possible cpus (NR_CPUS) to 20. That makes the cpumask sizeof 20.

The boot-process sets the number of available cpus to 16. So the
Linux side will never try to access anything beyond cpu15.

But you can spare that extra mask magic and simply use cpumask. Sorry
that I did not think about that earlier.

Thanks,

tglx

2015-11-30 11:23:02

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH v2 09/19] genirq: Add a new function to get IPI reverse mapping

On Mon, 30 Nov 2015, Qais Yousef wrote:
> On 11/30/2015 10:40 AM, Thomas Gleixner wrote:
> > On Fri, 27 Nov 2015, Qais Yousef wrote:
> > > While trying to get my remoteproc driver work with this I uncovered a
> > > problem
> > > with this approach.
> > >
> > > mips-gic doesn't store the actual hwirq in the irq_data. It uses
> > > GIC_SHARED_TO_HWIRQ() and GIC_HWIRQ_TO_SHARED() to add and remove an
> > > offset.
> > Why can't MIPS store the real hwirq number in irq_data?
>
>
> I'm wary of ending up in inconsistency hell where some functions need to deal
> with raw hwirq and others with translated ones.
>
> I will give this a go first and see if it gets really ugly.

Well, the question is why can't those functions not all use the raw
hardware irq. We have it in irq_data exactly to avoid calculations in
the hot path functions.

Thanks,

tglx

2015-11-30 11:48:06

by Qais Yousef

[permalink] [raw]
Subject: Re: [PATCH v2 04/19] genirq: Add new struct ipi_mask and helper functions

On 11/30/2015 11:20 AM, Thomas Gleixner wrote:
> On Wed, 25 Nov 2015, Qais Yousef wrote:
>> 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.
> I have second thoughts on this.
>
> cpumask is indeed limited to NR_CPUS or in case of CPUMASK_ON_STACK
> limited to nr_cpu_ids.
>
> But, that's not an issue for that coprocessor case. Let's assume you
> have 16 Linux CPUs and 4 coprocessors. So you set the number of
> possible cpus (NR_CPUS) to 20. That makes the cpumask sizeof 20.
>
> The boot-process sets the number of available cpus to 16. So the
> Linux side will never try to access anything beyond cpu15.
>
> But you can spare that extra mask magic and simply use cpumask. Sorry
> that I did not think about that earlier.
>
>


Yes it would be much better to reuse it but wouldn't the runtime checks
against nr_cpu_ids create problems especially when CPUMASK_ON_STACK is
defined?

Thanks,
Qais

2015-11-30 11:59:19

by Qais Yousef

[permalink] [raw]
Subject: Re: [PATCH v2 09/19] genirq: Add a new function to get IPI reverse mapping

On 11/30/2015 11:22 AM, Thomas Gleixner wrote:
> On Mon, 30 Nov 2015, Qais Yousef wrote:
>> On 11/30/2015 10:40 AM, Thomas Gleixner wrote:
>>> On Fri, 27 Nov 2015, Qais Yousef wrote:
>>>> While trying to get my remoteproc driver work with this I uncovered a
>>>> problem
>>>> with this approach.
>>>>
>>>> mips-gic doesn't store the actual hwirq in the irq_data. It uses
>>>> GIC_SHARED_TO_HWIRQ() and GIC_HWIRQ_TO_SHARED() to add and remove an
>>>> offset.
>>> Why can't MIPS store the real hwirq number in irq_data?
>>
>> I'm wary of ending up in inconsistency hell where some functions need to deal
>> with raw hwirq and others with translated ones.
>>
>> I will give this a go first and see if it gets really ugly.
> Well, the question is why can't those functions not all use the raw
> hardware irq. We have it in irq_data exactly to avoid calculations in
> the hot path functions.
>


I'll see what I can do as part of this series. I think I can fix the new
IPI and device domains, but can't promise about the root gic domain. It
might be too big of a change for this series.

Thanks,
Qais

2015-11-30 13:11:51

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH v2 04/19] genirq: Add new struct ipi_mask and helper functions

On Mon, 30 Nov 2015, Qais Yousef wrote:
> On 11/30/2015 11:20 AM, Thomas Gleixner wrote:
> > On Wed, 25 Nov 2015, Qais Yousef wrote:
> > > 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.
> > I have second thoughts on this.
> >
> > cpumask is indeed limited to NR_CPUS or in case of CPUMASK_ON_STACK
> > limited to nr_cpu_ids.
> >
> > But, that's not an issue for that coprocessor case. Let's assume you
> > have 16 Linux CPUs and 4 coprocessors. So you set the number of
> > possible cpus (NR_CPUS) to 20. That makes the cpumask sizeof 20.
> >
> > The boot-process sets the number of available cpus to 16. So the
> > Linux side will never try to access anything beyond cpu15.
> >
> > But you can spare that extra mask magic and simply use cpumask. Sorry
> > that I did not think about that earlier.
> >
> >
> Yes it would be much better to reuse it but wouldn't the runtime checks
> against nr_cpu_ids create problems especially when CPUMASK_ON_STACK is
> defined?

nr_cpu_ids == find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1;

Thanks,

tglx

2015-11-30 13:57:39

by Qais Yousef

[permalink] [raw]
Subject: Re: [PATCH v2 04/19] genirq: Add new struct ipi_mask and helper functions

On 11/30/2015 01:11 PM, Thomas Gleixner wrote:
> On Mon, 30 Nov 2015, Qais Yousef wrote:
>>
>> Yes it would be much better to reuse it but wouldn't the runtime checks
>> against nr_cpu_ids create problems especially when CPUMASK_ON_STACK is
>> defined?
> nr_cpu_ids == find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1;
>
>


OK. I can partially see your point. I can't see how the extra
coprocessor bits will be set in cpu_possible_mask and whether this will
affect normal linux operation (ie: will it think it can bring that cpu
up or migrate irqs to it?).

Since you don't see an issue with it, it must be just a missing gap in
my knowledge that I'll fill while doing this work.

Thanks,
Qais

2015-12-01 10:47:10

by Qais Yousef

[permalink] [raw]
Subject: Re: [PATCH v2 09/19] genirq: Add a new function to get IPI reverse mapping

On 11/30/2015 11:59 AM, Qais Yousef wrote:
> On 11/30/2015 11:22 AM, Thomas Gleixner wrote:
>> Well, the question is why can't those functions not all use the raw
>> hardware irq. We have it in irq_data exactly to avoid calculations in
>> the hot path functions.
>>
>
>
> I'll see what I can do as part of this series. I think I can fix the
> new IPI and device domains, but can't promise about the root gic
> domain. It might be too big of a change for this series.


Unfortunately this is more work than I can afford putting into it right
now. Can we have this fix coming in later? It shouldn't affect anything
in this series.

The major issue here is that I need to split the root domain into shared
and local so that each will have its linear hwirq space therefore get
rid of the conversion macros.

BUT, the DT binding will break if I do this. I can't think of a simple
way to keep the existing binding and do the split. Not without hackery
and more magic at least which I don't think would be a better alternative.

Thanks,
Qais