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

TOMOYO Linux Cross Reference
Linux/arch/arm/xen/mm.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 /arch/arm/xen/mm.c (Version linux-6.12-rc7) and /arch/ppc/xen/mm.c (Version policy-sample)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 
  2 #include <linux/cpu.h>                            
  3 #include <linux/dma-direct.h>                     
  4 #include <linux/dma-map-ops.h>                    
  5 #include <linux/gfp.h>                            
  6 #include <linux/highmem.h>                        
  7 #include <linux/export.h>                         
  8 #include <linux/memblock.h>                       
  9 #include <linux/of_address.h>                     
 10 #include <linux/slab.h>                           
 11 #include <linux/types.h>                          
 12 #include <linux/vmalloc.h>                        
 13 #include <linux/swiotlb.h>                        
 14                                                   
 15 #include <xen/xen.h>                              
 16 #include <xen/interface/grant_table.h>            
 17 #include <xen/interface/memory.h>                 
 18 #include <xen/page.h>                             
 19 #include <xen/xen-ops.h>                          
 20 #include <xen/swiotlb-xen.h>                      
 21                                                   
 22 #include <asm/cacheflush.h>                       
 23 #include <asm/xen/hypercall.h>                    
 24 #include <asm/xen/interface.h>                    
 25                                                   
 26 static gfp_t xen_swiotlb_gfp(void)                
 27 {                                                 
 28         phys_addr_t base;                         
 29         u64 i;                                    
 30                                                   
 31         for_each_mem_range(i, &base, NULL) {      
 32                 if (base < (phys_addr_t)0xffff    
 33                         if (IS_ENABLED(CONFIG_    
 34                                 return __GFP_D    
 35                         return __GFP_DMA;         
 36                 }                                 
 37         }                                         
 38                                                   
 39         return GFP_KERNEL;                        
 40 }                                                 
 41                                                   
 42 static bool hypercall_cflush = false;             
 43                                                   
 44 /* buffers in highmem or foreign pages cannot     
 45 static void dma_cache_maint(struct device *dev    
 46                             size_t size, u32 o    
 47 {                                                 
 48         struct gnttab_cache_flush cflush;         
 49                                                   
 50         cflush.offset = xen_offset_in_page(han    
 51         cflush.op = op;                           
 52         handle &= XEN_PAGE_MASK;                  
 53                                                   
 54         do {                                      
 55                 cflush.a.dev_bus_addr = dma_to    
 56                                                   
 57                 if (size + cflush.offset > XEN    
 58                         cflush.length = XEN_PA    
 59                 else                              
 60                         cflush.length = size;     
 61                                                   
 62                 HYPERVISOR_grant_table_op(GNTT    
 63                                                   
 64                 cflush.offset = 0;                
 65                 handle += cflush.length;          
 66                 size -= cflush.length;            
 67         } while (size);                           
 68 }                                                 
 69                                                   
 70 /*                                                
 71  * Dom0 is mapped 1:1, and while the Linux pag    
 72  * pages, it is not possible for it to contain    
 73  * pages.  Calling pfn_valid on a foreign mfn     
 74  * pfn_valid returns true the pages is local a    
 75  * dma-direct functions, otherwise we call the    
 76  */                                               
 77 void xen_dma_sync_for_cpu(struct device *dev,     
 78                           size_t size, enum dm    
 79 {                                                 
 80         if (dir != DMA_TO_DEVICE)                 
 81                 dma_cache_maint(dev, handle, s    
 82 }                                                 
 83                                                   
 84 void xen_dma_sync_for_device(struct device *de    
 85                              size_t size, enum    
 86 {                                                 
 87         if (dir == DMA_FROM_DEVICE)               
 88                 dma_cache_maint(dev, handle, s    
 89         else                                      
 90                 dma_cache_maint(dev, handle, s    
 91 }                                                 
 92                                                   
 93 bool xen_arch_need_swiotlb(struct device *dev,    
 94                            phys_addr_t phys,      
 95                            dma_addr_t dev_addr    
 96 {                                                 
 97         unsigned int xen_pfn = XEN_PFN_DOWN(ph    
 98         unsigned int bfn = XEN_PFN_DOWN(dma_to    
 99                                                   
100         /*                                        
101          * The swiotlb buffer should be used i    
102          *      - Xen doesn't have the cache f    
103          *      - The Linux page refers to for    
104          *      - The device doesn't support c    
105          *                                        
106          * The Linux page may be spanned acrro    
107          * it's not possible to have a mix of     
108          * Furthermore, range_straddles_page_b    
109          * if buffer is physically contiguous     
110          *                                        
111          * Therefore we only need to check the    
112          * require a bounce buffer because the    
113          * memory and we are not able to flush    
114          */                                       
115         return (!hypercall_cflush && (xen_pfn     
116                 !dev_is_dma_coherent(dev));       
117 }                                                 
118                                                   
119 static int __init xen_mm_init(void)               
120 {                                                 
121         struct gnttab_cache_flush cflush;         
122         int rc;                                   
123                                                   
124         if (!xen_swiotlb_detect())                
125                 return 0;                         
126                                                   
127         /* we can work with the default swiotl    
128         rc = swiotlb_init_late(swiotlb_size_or    
129                                xen_swiotlb_gfp    
130         if (rc < 0)                               
131                 return rc;                        
132                                                   
133         cflush.op = 0;                            
134         cflush.a.dev_bus_addr = 0;                
135         cflush.offset = 0;                        
136         cflush.length = 0;                        
137         if (HYPERVISOR_grant_table_op(GNTTABOP    
138                 hypercall_cflush = true;          
139         return 0;                                 
140 }                                                 
141 arch_initcall(xen_mm_init);                       
142                                                   

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