2 * linux/kernel/irq/ipi.c
4 * Copyright (C) 2015 Imagination Technologies Ltd
5 * Author: Qais Yousef <qais.yousef@imgtec.com>
7 * This file contains driver APIs to the IPI subsystem.
10 #define pr_fmt(fmt) "genirq/ipi: " fmt
12 #include <linux/irqdomain.h>
13 #include <linux/irq.h>
16 * irq_reserve_ipi() - Setup an IPI to destination cpumask
18 * @dest: cpumask of cpus which can receive the IPI
20 * Allocate a virq that can be used to send IPI to any CPU in dest mask.
22 * On success it'll return linux irq number and 0 on failure
24 unsigned int irq_reserve_ipi(struct irq_domain
*domain
,
25 const struct cpumask
*dest
)
27 unsigned int nr_irqs
, offset
;
28 struct irq_data
*data
;
31 if (!domain
||!irq_domain_is_ipi(domain
)) {
32 pr_warn("Reservation on a non IPI domain\n");
36 if (!cpumask_subset(dest
, cpu_possible_mask
)) {
37 pr_warn("Reservation is not in possible_cpu_mask\n");
41 nr_irqs
= cpumask_weight(dest
);
43 pr_warn("Reservation for empty destination mask\n");
47 if (irq_domain_is_ipi_single(domain
)) {
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.
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
65 offset
= cpumask_first(dest
);
67 * Find a hole and if found look for another set bit after the
68 * hole. For now we don't support this scenario.
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");
79 virq
= irq_domain_alloc_descs(-1, nr_irqs
, 0, NUMA_NO_NODE
);
81 pr_warn("Can't reserve IPI, failed to alloc descs\n");
85 virq
= __irq_domain_alloc_irqs(domain
, virq
, nr_irqs
, NUMA_NO_NODE
,
89 pr_warn("Can't reserve IPI, failed to alloc hw irqs\n");
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
;
101 irq_free_descs(virq
, nr_irqs
);
106 * irq_destroy_ipi() - unreserve an IPI that was previously allocated
107 * @irq: linux irq number to be destroyed
109 * Return the IPIs allocated with irq_reserve_ipi() to the system destroying
110 * all virqs associated with them.
112 void irq_destroy_ipi(unsigned int irq
)
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
;
119 if (!irq
|| !data
|| !ipimask
)
122 domain
= data
->domain
;
123 if (WARN_ON(domain
== NULL
))
126 if (!irq_domain_is_ipi(domain
)) {
127 pr_warn("Trying to destroy a non IPI domain!\n");
131 if (irq_domain_is_ipi_per_cpu(domain
))
132 nr_irqs
= cpumask_weight(ipimask
);
136 irq_domain_free_irqs(irq
, nr_irqs
);
This page took 0.032809 seconds and 5 git commands to generate.