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

TOMOYO Linux Cross Reference
Linux/arch/s390/include/asm/idals.h

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 /arch/s390/include/asm/idals.h (Architecture alpha) and /arch/sparc64/include/asm-sparc64/idals.h (Architecture sparc64)


  1 /* SPDX-License-Identifier: GPL-2.0 */              1 
  2 /*                                                
  3  * Author(s)......: Holger Smolinski <Holger.S    
  4  *                  Martin Schwidefsky <schwid    
  5  * Bugreports.to..: <Linux390@de.ibm.com>         
  6  * Copyright IBM Corp. 2000                       
  7  *                                                
  8  * History of changes                             
  9  * 07/24/00 new file                              
 10  * 05/04/02 code restructuring.                   
 11  */                                               
 12                                                   
 13 #ifndef _S390_IDALS_H                             
 14 #define _S390_IDALS_H                             
 15                                                   
 16 #include <linux/errno.h>                          
 17 #include <linux/err.h>                            
 18 #include <linux/types.h>                          
 19 #include <linux/slab.h>                           
 20 #include <linux/uaccess.h>                        
 21 #include <asm/dma-types.h>                        
 22 #include <asm/cio.h>                              
 23                                                   
 24 #define IDA_SIZE_SHIFT          12                
 25 #define IDA_BLOCK_SIZE          (1UL << IDA_SI    
 26                                                   
 27 #define IDA_2K_SIZE_SHIFT       11                
 28 #define IDA_2K_BLOCK_SIZE       (1UL << IDA_2K    
 29                                                   
 30 /*                                                
 31  * Test if an address/length pair needs an ida    
 32  */                                               
 33 static inline bool idal_is_needed(void *vaddr,    
 34 {                                                 
 35         dma64_t paddr = virt_to_dma64(vaddr);     
 36                                                   
 37         return (((__force unsigned long)(paddr    
 38 }                                                 
 39                                                   
 40 /*                                                
 41  * Return the number of idal words needed for     
 42  */                                               
 43 static inline unsigned int idal_nr_words(void     
 44 {                                                 
 45         unsigned int cidaw;                       
 46                                                   
 47         cidaw = (unsigned long)vaddr & (IDA_BL    
 48         cidaw += length + IDA_BLOCK_SIZE - 1;     
 49         cidaw >>= IDA_SIZE_SHIFT;                 
 50         return cidaw;                             
 51 }                                                 
 52                                                   
 53 /*                                                
 54  * Return the number of 2K IDA words needed fo    
 55  */                                               
 56 static inline unsigned int idal_2k_nr_words(vo    
 57 {                                                 
 58         unsigned int cidaw;                       
 59                                                   
 60         cidaw = (unsigned long)vaddr & (IDA_2K    
 61         cidaw += length + IDA_2K_BLOCK_SIZE -     
 62         cidaw >>= IDA_2K_SIZE_SHIFT;              
 63         return cidaw;                             
 64 }                                                 
 65                                                   
 66 /*                                                
 67  * Create the list of idal words for an addres    
 68  */                                               
 69 static inline dma64_t *idal_create_words(dma64    
 70 {                                                 
 71         dma64_t paddr = virt_to_dma64(vaddr);     
 72         unsigned int cidaw;                       
 73                                                   
 74         *idaws++ = paddr;                         
 75         cidaw = idal_nr_words(vaddr, length);     
 76         paddr = dma64_and(paddr, -IDA_BLOCK_SI    
 77         while (--cidaw > 0) {                     
 78                 paddr = dma64_add(paddr, IDA_B    
 79                 *idaws++ = paddr;                 
 80         }                                         
 81         return idaws;                             
 82 }                                                 
 83                                                   
 84 /*                                                
 85  * Sets the address of the data in CCW.           
 86  * If necessary it allocates an IDAL and sets     
 87  */                                               
 88 static inline int set_normalized_cda(struct cc    
 89 {                                                 
 90         unsigned int nridaws;                     
 91         dma64_t *idal;                            
 92                                                   
 93         if (ccw->flags & CCW_FLAG_IDA)            
 94                 return -EINVAL;                   
 95         nridaws = idal_nr_words(vaddr, ccw->co    
 96         if (nridaws > 0) {                        
 97                 idal = kcalloc(nridaws, sizeof    
 98                 if (!idal)                        
 99                         return -ENOMEM;           
100                 idal_create_words(idal, vaddr,    
101                 ccw->flags |= CCW_FLAG_IDA;       
102                 vaddr = idal;                     
103         }                                         
104         ccw->cda = virt_to_dma32(vaddr);          
105         return 0;                                 
106 }                                                 
107                                                   
108 /*                                                
109  * Releases any allocated IDAL related to the     
110  */                                               
111 static inline void clear_normalized_cda(struct    
112 {                                                 
113         if (ccw->flags & CCW_FLAG_IDA) {          
114                 kfree(dma32_to_virt(ccw->cda))    
115                 ccw->flags &= ~CCW_FLAG_IDA;      
116         }                                         
117         ccw->cda = 0;                             
118 }                                                 
119                                                   
120 /*                                                
121  * Idal buffer extension                          
122  */                                               
123 struct idal_buffer {                              
124         size_t size;                              
125         size_t page_order;                        
126         dma64_t data[];                           
127 };                                                
128                                                   
129 /*                                                
130  * Allocate an idal buffer                        
131  */                                               
132 static inline struct idal_buffer *idal_buffer_    
133 {                                                 
134         int nr_chunks, nr_ptrs, i;                
135         struct idal_buffer *ib;                   
136         void *vaddr;                              
137                                                   
138         nr_ptrs = (size + IDA_BLOCK_SIZE - 1)     
139         nr_chunks = (PAGE_SIZE << page_order)     
140         ib = kmalloc(struct_size(ib, data, nr_    
141         if (!ib)                                  
142                 return ERR_PTR(-ENOMEM);          
143         ib->size = size;                          
144         ib->page_order = page_order;              
145         for (i = 0; i < nr_ptrs; i++) {           
146                 if (i & (nr_chunks - 1)) {        
147                         ib->data[i] = dma64_ad    
148                         continue;                 
149                 }                                 
150                 vaddr = (void *)__get_free_pag    
151                 if (!vaddr)                       
152                         goto error;               
153                 ib->data[i] = virt_to_dma64(va    
154         }                                         
155         return ib;                                
156 error:                                            
157         while (i >= nr_chunks) {                  
158                 i -= nr_chunks;                   
159                 vaddr = dma64_to_virt(ib->data    
160                 free_pages((unsigned long)vadd    
161         }                                         
162         kfree(ib);                                
163         return ERR_PTR(-ENOMEM);                  
164 }                                                 
165                                                   
166 /*                                                
167  * Free an idal buffer.                           
168  */                                               
169 static inline void idal_buffer_free(struct ida    
170 {                                                 
171         int nr_chunks, nr_ptrs, i;                
172         void *vaddr;                              
173                                                   
174         nr_ptrs = (ib->size + IDA_BLOCK_SIZE -    
175         nr_chunks = (PAGE_SIZE << ib->page_ord    
176         for (i = 0; i < nr_ptrs; i += nr_chunk    
177                 vaddr = dma64_to_virt(ib->data    
178                 free_pages((unsigned long)vadd    
179         }                                         
180         kfree(ib);                                
181 }                                                 
182                                                   
183 /*                                                
184  * Test if a idal list is really needed.          
185  */                                               
186 static inline bool __idal_buffer_is_needed(str    
187 {                                                 
188         if (ib->size > (PAGE_SIZE << ib->page_    
189                 return true;                      
190         return idal_is_needed(dma64_to_virt(ib    
191 }                                                 
192                                                   
193 /*                                                
194  * Set channel data address to idal buffer.       
195  */                                               
196 static inline void idal_buffer_set_cda(struct     
197 {                                                 
198         void *vaddr;                              
199                                                   
200         if (__idal_buffer_is_needed(ib)) {        
201                 /* Setup idals */                 
202                 ccw->cda = virt_to_dma32(ib->d    
203                 ccw->flags |= CCW_FLAG_IDA;       
204         } else {                                  
205                 /*                                
206                  * No idals needed - use direc    
207                  * dma64_t to virt and then to    
208                  * checking. The physical addr    
209                  */                               
210                 vaddr = dma64_to_virt(ib->data    
211                 ccw->cda = virt_to_dma32(vaddr    
212         }                                         
213         ccw->count = ib->size;                    
214 }                                                 
215                                                   
216 /*                                                
217  * Copy count bytes from an idal buffer to use    
218  */                                               
219 static inline size_t idal_buffer_to_user(struc    
220 {                                                 
221         size_t left;                              
222         void *vaddr;                              
223         int i;                                    
224                                                   
225         BUG_ON(count > ib->size);                 
226         for (i = 0; count > IDA_BLOCK_SIZE; i+    
227                 vaddr = dma64_to_virt(ib->data    
228                 left = copy_to_user(to, vaddr,    
229                 if (left)                         
230                         return left + count -     
231                 to = (void __user *)to + IDA_B    
232                 count -= IDA_BLOCK_SIZE;          
233         }                                         
234         vaddr = dma64_to_virt(ib->data[i]);       
235         return copy_to_user(to, vaddr, count);    
236 }                                                 
237                                                   
238 /*                                                
239  * Copy count bytes from user memory to an ida    
240  */                                               
241 static inline size_t idal_buffer_from_user(str    
242 {                                                 
243         size_t left;                              
244         void *vaddr;                              
245         int i;                                    
246                                                   
247         BUG_ON(count > ib->size);                 
248         for (i = 0; count > IDA_BLOCK_SIZE; i+    
249                 vaddr = dma64_to_virt(ib->data    
250                 left = copy_from_user(vaddr, f    
251                 if (left)                         
252                         return left + count -     
253                 from = (void __user *)from + I    
254                 count -= IDA_BLOCK_SIZE;          
255         }                                         
256         vaddr = dma64_to_virt(ib->data[i]);       
257         return copy_from_user(vaddr, from, cou    
258 }                                                 
259                                                   
260 #endif                                            
261                                                   

~ [ 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