diff options
author | Qais Yousef <qais.yousef@imgtec.com> | 2015-12-08 08:20:19 -0500 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2016-02-25 04:56:56 -0500 |
commit | d17bf24e695290d3fe7943aca52ab48098a10653 (patch) | |
tree | 3053c2e487c3b21c4541c3ee4102a8908fedd955 | |
parent | ac0a0cd266d1f21236d5975ca6bced9b377a2a6a (diff) |
genirq: Add a new generic IPI reservation code to irq core
Add a generic mechanism to dynamically allocate an IPI. Depending on the
underlying implementation this creates either a single Linux irq or a
consective range of Linux irqs. The Linux irq is used later to send IPIs to
other CPUs.
[ tglx: Massaged the code and removed the 'consecutive mask' restriction for
the single IRQ case ]
Signed-off-by: Qais Yousef <qais.yousef@imgtec.com>
Cc: <jason@lakedaemon.net>
Cc: <marc.zyngier@arm.com>
Cc: <jiang.liu@linux.intel.com>
Cc: <ralf@linux-mips.org>
Cc: <linux-mips@linux-mips.org>
Cc: <lisa.parratt@imgtec.com>
Cc: Qais Yousef <qsyousef@gmail.com>
Link: http://lkml.kernel.org/r/1449580830-23652-9-git-send-email-qais.yousef@imgtec.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
-rw-r--r-- | include/linux/irq.h | 3 | ||||
-rw-r--r-- | include/linux/irqdomain.h | 5 | ||||
-rw-r--r-- | kernel/irq/Makefile | 1 | ||||
-rw-r--r-- | kernel/irq/ipi.c | 137 |
4 files changed, 146 insertions, 0 deletions
diff --git a/include/linux/irq.h b/include/linux/irq.h index a32b47fbf874..95f4f66f95f3 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h | |||
@@ -940,4 +940,7 @@ static inline u32 irq_reg_readl(struct irq_chip_generic *gc, | |||
940 | return readl(gc->reg_base + reg_offset); | 940 | return readl(gc->reg_base + reg_offset); |
941 | } | 941 | } |
942 | 942 | ||
943 | /* Contrary to Linux irqs, for hardware irqs the irq number 0 is valid */ | ||
944 | #define INVALID_HWIRQ (~0UL) | ||
945 | |||
943 | #endif /* _LINUX_IRQ_H */ | 946 | #endif /* _LINUX_IRQ_H */ |
diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h index c466cc17b8e9..ed48594e96d2 100644 --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h | |||
@@ -344,6 +344,11 @@ int irq_domain_xlate_onetwocell(struct irq_domain *d, struct device_node *ctrlr, | |||
344 | const u32 *intspec, unsigned int intsize, | 344 | const u32 *intspec, unsigned int intsize, |
345 | irq_hw_number_t *out_hwirq, unsigned int *out_type); | 345 | irq_hw_number_t *out_hwirq, unsigned int *out_type); |
346 | 346 | ||
347 | /* IPI functions */ | ||
348 | unsigned int irq_reserve_ipi(struct irq_domain *domain, | ||
349 | const struct cpumask *dest); | ||
350 | void irq_destroy_ipi(unsigned int irq); | ||
351 | |||
347 | /* V2 interfaces to support hierarchy IRQ domains. */ | 352 | /* V2 interfaces to support hierarchy IRQ domains. */ |
348 | extern struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain, | 353 | extern struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain, |
349 | unsigned int virq); | 354 | unsigned int virq); |
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 | |||
8 | obj-$(CONFIG_GENERIC_IRQ_MIGRATION) += cpuhotplug.o | 8 | obj-$(CONFIG_GENERIC_IRQ_MIGRATION) += cpuhotplug.o |
9 | obj-$(CONFIG_PM_SLEEP) += pm.o | 9 | obj-$(CONFIG_PM_SLEEP) += pm.o |
10 | obj-$(CONFIG_GENERIC_MSI_IRQ) += msi.o | 10 | obj-$(CONFIG_GENERIC_MSI_IRQ) += msi.o |
11 | 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..340af273429c --- /dev/null +++ b/kernel/irq/ipi.c | |||
@@ -0,0 +1,137 @@ | |||
1 | /* | ||
2 | * linux/kernel/irq/ipi.c | ||
3 | * | ||
4 | * Copyright (C) 2015 Imagination Technologies Ltd | ||
5 | * Author: Qais Yousef <qais.yousef@imgtec.com> | ||
6 | * | ||
7 | * This file contains driver APIs to the IPI subsystem. | ||
8 | */ | ||
9 | |||
10 | #define pr_fmt(fmt) "genirq/ipi: " fmt | ||
11 | |||
12 | #include <linux/irqdomain.h> | ||
13 | #include <linux/irq.h> | ||
14 | |||
15 | /** | ||
16 | * irq_reserve_ipi() - Setup an IPI to destination cpumask | ||
17 | * @domain: IPI domain | ||
18 | * @dest: cpumask of cpus which can receive the IPI | ||
19 | * | ||
20 | * Allocate a virq that can be used to send IPI to any CPU in dest mask. | ||
21 | * | ||
22 | * On success it'll return linux irq number and 0 on failure | ||
23 | */ | ||
24 | unsigned int irq_reserve_ipi(struct irq_domain *domain, | ||
25 | const struct cpumask *dest) | ||
26 | { | ||
27 | unsigned int nr_irqs, offset; | ||
28 | struct irq_data *data; | ||
29 | int virq, i; | ||
30 | |||
31 | if (!domain ||!irq_domain_is_ipi(domain)) { | ||
32 | pr_warn("Reservation on a non IPI domain\n"); | ||
33 | return 0; | ||
34 | } | ||
35 | |||
36 | if (!cpumask_subset(dest, cpu_possible_mask)) { | ||
37 | pr_warn("Reservation is not in possible_cpu_mask\n"); | ||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | nr_irqs = cpumask_weight(dest); | ||
42 | if (!nr_irqs) { | ||
43 | pr_warn("Reservation for empty destination mask\n"); | ||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | if (irq_domain_is_ipi_single(domain)) { | ||
48 | /* | ||
49 | * If the underlying implementation uses a single HW irq on | ||
50 | * all cpus then we only need a single Linux irq number for | ||
51 | * it. We have no restrictions vs. the destination mask. The | ||
52 | * underlying implementation can deal with holes nicely. | ||
53 | */ | ||
54 | nr_irqs = 1; | ||
55 | offset = 0; | ||
56 | } else { | ||
57 | unsigned int next; | ||
58 | |||
59 | /* | ||
60 | * The IPI requires a seperate HW irq on each CPU. We require | ||
61 | * that the destination mask is consecutive. If an | ||
62 | * implementation needs to support holes, it can reserve | ||
63 | * several IPI ranges. | ||
64 | */ | ||
65 | offset = cpumask_first(dest); | ||
66 | /* | ||
67 | * Find a hole and if found look for another set bit after the | ||
68 | * hole. For now we don't support this scenario. | ||
69 | */ | ||
70 | next = cpumask_next_zero(offset, dest); | ||
71 | if (next < nr_cpu_ids) | ||
72 | next = cpumask_next(next, dest); | ||
73 | if (next < nr_cpu_ids) { | ||
74 | pr_warn("Destination mask has holes\n"); | ||
75 | return 0; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | virq = irq_domain_alloc_descs(-1, nr_irqs, 0, NUMA_NO_NODE); | ||
80 | if (virq <= 0) { | ||
81 | pr_warn("Can't reserve IPI, failed to alloc descs\n"); | ||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | virq = __irq_domain_alloc_irqs(domain, virq, nr_irqs, NUMA_NO_NODE, | ||
86 | (void *) dest, true); | ||
87 | |||
88 | if (virq <= 0) { | ||
89 | pr_warn("Can't reserve IPI, failed to alloc hw irqs\n"); | ||
90 | goto free_descs; | ||
91 | } | ||
92 | |||
93 | for (i = 0; i < nr_irqs; i++) { | ||
94 | data = irq_get_irq_data(virq + i); | ||
95 | cpumask_copy(data->common->affinity, dest); | ||
96 | data->common->ipi_offset = offset; | ||
97 | } | ||
98 | return virq; | ||
99 | |||
100 | free_descs: | ||
101 | irq_free_descs(virq, nr_irqs); | ||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * irq_destroy_ipi() - unreserve an IPI that was previously allocated | ||
107 | * @irq: linux irq number to be destroyed | ||
108 | * | ||
109 | * Return the IPIs allocated with irq_reserve_ipi() to the system destroying | ||
110 | * all virqs associated with them. | ||
111 | */ | ||
112 | void irq_destroy_ipi(unsigned int irq) | ||
113 | { | ||
114 | struct irq_data *data = irq_get_irq_data(irq); | ||
115 | struct cpumask *ipimask = data ? irq_data_get_affinity_mask(data) : NULL; | ||
116 | struct irq_domain *domain; | ||
117 | unsigned int nr_irqs; | ||
118 | |||
119 | if (!irq || !data || !ipimask) | ||
120 | return; | ||
121 | |||
122 | domain = data->domain; | ||
123 | if (WARN_ON(domain == NULL)) | ||
124 | return; | ||
125 | |||
126 | if (!irq_domain_is_ipi(domain)) { | ||
127 | pr_warn("Trying to destroy a non IPI domain!\n"); | ||
128 | return; | ||
129 | } | ||
130 | |||
131 | if (irq_domain_is_ipi_per_cpu(domain)) | ||
132 | nr_irqs = cpumask_weight(ipimask); | ||
133 | else | ||
134 | nr_irqs = 1; | ||
135 | |||
136 | irq_domain_free_irqs(irq, nr_irqs); | ||
137 | } | ||