~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/kernel/irq/ipi-mux.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /kernel/irq/ipi-mux.c (Version linux-6.12-rc7) and /kernel/irq/ipi-mux.c (Version linux-4.17.19)


  1 // SPDX-License-Identifier: GPL-2.0-or-later        1 
  2 /*                                                
  3  * Multiplex several virtual IPIs over a singl    
  4  *                                                
  5  * Copyright The Asahi Linux Contributors         
  6  * Copyright (c) 2022 Ventana Micro Systems In    
  7  */                                               
  8                                                   
  9 #define pr_fmt(fmt) "ipi-mux: " fmt               
 10 #include <linux/cpu.h>                            
 11 #include <linux/init.h>                           
 12 #include <linux/irq.h>                            
 13 #include <linux/irqchip.h>                        
 14 #include <linux/irqchip/chained_irq.h>            
 15 #include <linux/irqdomain.h>                      
 16 #include <linux/jump_label.h>                     
 17 #include <linux/percpu.h>                         
 18 #include <linux/smp.h>                            
 19                                                   
 20 struct ipi_mux_cpu {                              
 21         atomic_t                        enable    
 22         atomic_t                        bits;     
 23 };                                                
 24                                                   
 25 static struct ipi_mux_cpu __percpu *ipi_mux_pc    
 26 static struct irq_domain *ipi_mux_domain;         
 27 static void (*ipi_mux_send)(unsigned int cpu);    
 28                                                   
 29 static void ipi_mux_mask(struct irq_data *d)      
 30 {                                                 
 31         struct ipi_mux_cpu *icpu = this_cpu_pt    
 32                                                   
 33         atomic_andnot(BIT(irqd_to_hwirq(d)), &    
 34 }                                                 
 35                                                   
 36 static void ipi_mux_unmask(struct irq_data *d)    
 37 {                                                 
 38         struct ipi_mux_cpu *icpu = this_cpu_pt    
 39         u32 ibit = BIT(irqd_to_hwirq(d));         
 40                                                   
 41         atomic_or(ibit, &icpu->enable);           
 42                                                   
 43         /*                                        
 44          * The atomic_or() above must complete    
 45          * below to avoid racing ipi_mux_send_    
 46          */                                       
 47         smp_mb__after_atomic();                   
 48                                                   
 49         /* If a pending IPI was unmasked, rais    
 50         if (atomic_read(&icpu->bits) & ibit)      
 51                 ipi_mux_send(smp_processor_id(    
 52 }                                                 
 53                                                   
 54 static void ipi_mux_send_mask(struct irq_data     
 55 {                                                 
 56         struct ipi_mux_cpu *icpu = this_cpu_pt    
 57         u32 ibit = BIT(irqd_to_hwirq(d));         
 58         unsigned long pending;                    
 59         int cpu;                                  
 60                                                   
 61         for_each_cpu(cpu, mask) {                 
 62                 icpu = per_cpu_ptr(ipi_mux_pcp    
 63                                                   
 64                 /*                                
 65                  * This sequence is the mirror    
 66                  * see the comment there. Addi    
 67                  * ensure that the vIPI flag s    
 68                  * memory accesses that preced    
 69                  * with the atomic_fetch_andno    
 70                  */                               
 71                 pending = atomic_fetch_or_rele    
 72                                                   
 73                 /*                                
 74                  * The atomic_fetch_or_release    
 75                  * before the atomic_read() be    
 76                  * ipi_mux_unmask().              
 77                  */                               
 78                 smp_mb__after_atomic();           
 79                                                   
 80                 /*                                
 81                  * The flag writes must comple    
 82                  * issued to another CPU. This    
 83                  * dependency on the result of    
 84                  * itself already ordered afte    
 85                  */                               
 86                 if (!(pending & ibit) && (atom    
 87                         ipi_mux_send(cpu);        
 88         }                                         
 89 }                                                 
 90                                                   
 91 static const struct irq_chip ipi_mux_chip = {     
 92         .name           = "IPI Mux",              
 93         .irq_mask       = ipi_mux_mask,           
 94         .irq_unmask     = ipi_mux_unmask,         
 95         .ipi_send_mask  = ipi_mux_send_mask,      
 96 };                                                
 97                                                   
 98 static int ipi_mux_domain_alloc(struct irq_dom    
 99                                 unsigned int n    
100 {                                                 
101         int i;                                    
102                                                   
103         for (i = 0; i < nr_irqs; i++) {           
104                 irq_set_percpu_devid(virq + i)    
105                 irq_domain_set_info(d, virq +     
106                                     handle_per    
107         }                                         
108                                                   
109         return 0;                                 
110 }                                                 
111                                                   
112 static const struct irq_domain_ops ipi_mux_dom    
113         .alloc          = ipi_mux_domain_alloc    
114         .free           = irq_domain_free_irqs    
115 };                                                
116                                                   
117 /**                                               
118  * ipi_mux_process - Process multiplexed virtu    
119  */                                               
120 void ipi_mux_process(void)                        
121 {                                                 
122         struct ipi_mux_cpu *icpu = this_cpu_pt    
123         irq_hw_number_t hwirq;                    
124         unsigned long ipis;                       
125         unsigned int en;                          
126                                                   
127         /*                                        
128          * Reading enable mask does not need t    
129          * this function is called from interr    
130          * the CPU itself can change it's own     
131          */                                       
132         en = atomic_read(&icpu->enable);          
133                                                   
134         /*                                        
135          * Clear the IPIs we are about to hand    
136          * atomic_fetch_or_release() in ipi_mu    
137          */                                       
138         ipis = atomic_fetch_andnot(en, &icpu->    
139                                                   
140         for_each_set_bit(hwirq, &ipis, BITS_PE    
141                 generic_handle_domain_irq(ipi_    
142 }                                                 
143                                                   
144 /**                                               
145  * ipi_mux_create - Create virtual IPIs multip    
146  * parent IPI.                                    
147  * @nr_ipi:             number of virtual IPIs    
148  *                      be <= BITS_PER_TYPE(in    
149  * @mux_send:           callback to trigger pa    
150  *                                                
151  * Returns first virq of the newly created vir    
152  * or <=0 upon failure                            
153  */                                               
154 int ipi_mux_create(unsigned int nr_ipi, void (    
155 {                                                 
156         struct fwnode_handle *fwnode;             
157         struct irq_domain *domain;                
158         int rc;                                   
159                                                   
160         if (ipi_mux_domain)                       
161                 return -EEXIST;                   
162                                                   
163         if (BITS_PER_TYPE(int) < nr_ipi || !mu    
164                 return -EINVAL;                   
165                                                   
166         ipi_mux_pcpu = alloc_percpu(typeof(*ip    
167         if (!ipi_mux_pcpu)                        
168                 return -ENOMEM;                   
169                                                   
170         fwnode = irq_domain_alloc_named_fwnode    
171         if (!fwnode) {                            
172                 pr_err("unable to create IPI M    
173                 rc = -ENOMEM;                     
174                 goto fail_free_cpu;               
175         }                                         
176                                                   
177         domain = irq_domain_create_linear(fwno    
178                                           &ipi    
179         if (!domain) {                            
180                 pr_err("unable to add IPI Mux     
181                 rc = -ENOMEM;                     
182                 goto fail_free_fwnode;            
183         }                                         
184                                                   
185         domain->flags |= IRQ_DOMAIN_FLAG_IPI_S    
186         irq_domain_update_bus_token(domain, DO    
187                                                   
188         rc = irq_domain_alloc_irqs(domain, nr_    
189         if (rc <= 0) {                            
190                 pr_err("unable to alloc IRQs f    
191                 goto fail_free_domain;            
192         }                                         
193                                                   
194         ipi_mux_domain = domain;                  
195         ipi_mux_send = mux_send;                  
196                                                   
197         return rc;                                
198                                                   
199 fail_free_domain:                                 
200         irq_domain_remove(domain);                
201 fail_free_fwnode:                                 
202         irq_domain_free_fwnode(fwnode);           
203 fail_free_cpu:                                    
204         free_percpu(ipi_mux_pcpu);                
205         return rc;                                
206 }                                                 
207                                                   

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php