/drivers/base/power/

_2019' selected='selected'>update_litmus_2019 Unnamed repository; edit this file 'description' to name the repository.Zelin Tong
summaryrefslogblamecommitdiffstats
path: root/Documentation/DMA-API-HOWTO.txt
blob: a0b6250add79c9c144fd1185fa91314febaa4241 (plain) (tree)
1
2
3
4
5
6
7
8
9

                                              




                                                   

                                                                    


















                                                                          




                                                                      


                                  
                              

























                                                                      








                                                                      










                                                                      

                                                                     

                                                                    












                                                                      


                                                                  
                                                    
 
                                                       
 
                                                               
                        
 
                                                                
 







                                                                      
 
                                                                  














                                                                        
                                                                   
 
                                                  




                                                              






                                                                      





                                                                    
                                                   
                              
                                                          











                                                                    
                                                   

                                         

                                                             

                                         
                                                             





                                                              

                                                                
                                                                 
                                                    
 
                                                         
                                    
 
                                                  




                                                                        

                                                                     







                                                                   
                                                            



                                                   
                                                        
                                                        

                                   
                           

           
                                                        


                                           
                                                                                      

                                   
                                                      


                                         
                                                                                    



















                                                                       

                                                                      

























                                                                      




                                                                            


                                                                     













                                                                   

                                                                     


                                                                    







                                                                   
                                                                   
 

                                                                  





                                                                       










                                                                      











                                                                      
                                                           
 

                                                                  


                                                                  


                                                                  


                                                               
                            
 
                              
 
                                                              
 
                                                                    




                                                                      
                                            
 
                                          
 
                                                            

                                                                    
                                                                    

                                                 
                                                         
 
                                                  
 

                                                                 

                                   
                              
 
                               
 
                                                              








                                                                



                  


                                                          

                                                      






                                                                
                                                           



                                                               
                                                        








                                                                      
                                                                     



                                                                
                  
 


                                                             

                                                                  
                                                        
                                                                  
                                             









                                                                  
                                          



                                  
                                                                


                
                                                           
 
                                                                        



                                                                    
                                                               


                                                               
                                          




                                              
                                                                      


           
                                                         




                                                                     
                                                                 

                               
                                           



















                                                                          
                                                    


                                                   

                                                                   
                                                                      
                              
 
                                                                    









                                                                           
                                                                     

                     
                                                                  


   
                                                           






                                                                
                                                                     


   
                                                              



                                                              

                                                                           


                                                                   
                                   




                                                                               
                                                                                






















                                                                             


                                                                     



                                                                   

                                                                                  


                                                                 





                                                                        
                                   








                                                                          

                                                                       


                                                                          

                                                                    


                                                                      





























                                                                      

                                                        
                                                             







                                                                      
                                                              











                                    

                                               

          
                                                    






                             

                                                
 
                                                   

                   

                                                         


         



                                                        












                                                                



                                                                      
 
                    




                                                                      
                                                             


                                                                    
                                                            


                                                                     
 









                                                                      

                                  
                                                              










                                                                    
                                          
                                                
		     Dynamic DMA mapping Guide
		     =========================

		 David S. Miller <davem@redhat.com>
		 Richard Henderson <rth@cygnus.com>
		  Jakub Jelinek <jakub@redhat.com>

This is a guide to device driver writers on how to use the DMA API
with example pseudo-code.  For a concise description of the API, see
DMA-API.txt.

Most of the 64bit platforms have special hardware that translates bus
addresses (DMA addresses) into physical addresses.  This is similar to
how page tables and/or a TLB translates virtual addresses to physical
addresses on a CPU.  This is needed so that e.g. PCI devices can
access with a Single Address Cycle (32bit DMA address) any page in the
64bit physical address space.  Previously in Linux those 64bit
platforms had to set artificial limits on the maximum RAM size in the
system, so that the virt_to_bus() static scheme works (the DMA address
translation tables were simply filled on bootup to map each bus
address to the physical page __pa(bus_to_virt())).

So that Linux can use the dynamic DMA mapping, it needs some help from the
drivers, namely it has to take into account that DMA addresses should be
mapped only for the time they are actually used and unmapped after the DMA
transfer.

The following API will work of course even on platforms where no such
hardware exists.

Note that the DMA API works with any bus independent of the underlying
microprocessor architecture. You should use the DMA API rather than
the bus specific DMA API (e.g. pci_dma_*).

First of all, you should make sure

#include <linux/dma-mapping.h>

is in your driver. This file will obtain for you the definition of the
dma_addr_t (which can hold any valid DMA address for the platform)
type which should be used everywhere you hold a DMA (bus) address
returned from the DMA mapping functions.

			 What memory is DMA'able?

The first piece of information you must know is what kernel memory can
be used with the DMA mapping facilities.  There has been an unwritten
set of rules regarding this, and this text is an attempt to finally
write them down.

If you acquired your memory via the page allocator
(i.e. __get_free_page*()) or the generic memory allocators
(i.e. kmalloc() or kmem_cache_alloc()) then you may DMA to/from
that memory using the addresses returned from those routines.

This means specifically that you may _not_ use the memory/addresses
returned from vmalloc() for DMA.  It is possible to DMA to the
_underlying_ memory mapped into a vmalloc() area, but this requires
walking page tables to get the physical addresses, and then
translating each of those pages back to a kernel address using
something like __va().  [ EDIT: Update this when we integrate
Gerd Knorr's generic code which does this. ]