aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/DMA-API.txt79
1 files changed, 38 insertions, 41 deletions
diff --git a/Documentation/DMA-API.txt b/Documentation/DMA-API.txt
index 805db4b2cba6..cc7a8c39fb6f 100644
--- a/Documentation/DMA-API.txt
+++ b/Documentation/DMA-API.txt
@@ -26,7 +26,7 @@ Part Ia - Using large dma-coherent buffers
26 26
27void * 27void *
28dma_alloc_coherent(struct device *dev, size_t size, 28dma_alloc_coherent(struct device *dev, size_t size,
29 dma_addr_t *dma_handle, int flag) 29 dma_addr_t *dma_handle, gfp_t flag)
30void * 30void *
31pci_alloc_consistent(struct pci_dev *dev, size_t size, 31pci_alloc_consistent(struct pci_dev *dev, size_t size,
32 dma_addr_t *dma_handle) 32 dma_addr_t *dma_handle)
@@ -38,7 +38,7 @@ to make sure to flush the processor's write buffers before telling
38devices to read that memory.) 38devices to read that memory.)
39 39
40This routine allocates a region of <size> bytes of consistent memory. 40This routine allocates a region of <size> bytes of consistent memory.
41it also returns a <dma_handle> which may be cast to an unsigned 41It also returns a <dma_handle> which may be cast to an unsigned
42integer the same width as the bus and used as the physical address 42integer the same width as the bus and used as the physical address
43base of the region. 43base of the region.
44 44
@@ -52,21 +52,21 @@ The simplest way to do that is to use the dma_pool calls (see below).
52 52
53The flag parameter (dma_alloc_coherent only) allows the caller to 53The flag parameter (dma_alloc_coherent only) allows the caller to
54specify the GFP_ flags (see kmalloc) for the allocation (the 54specify the GFP_ flags (see kmalloc) for the allocation (the
55implementation may chose to ignore flags that affect the location of 55implementation may choose to ignore flags that affect the location of
56the returned memory, like GFP_DMA). For pci_alloc_consistent, you 56the returned memory, like GFP_DMA). For pci_alloc_consistent, you
57must assume GFP_ATOMIC behaviour. 57must assume GFP_ATOMIC behaviour.
58 58
59void 59void
60dma_free_coherent(struct device *dev, size_t size, void *cpu_addr 60dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
61 dma_addr_t dma_handle) 61 dma_addr_t dma_handle)
62void 62void
63pci_free_consistent(struct pci_dev *dev, size_t size, void *cpu_addr 63pci_free_consistent(struct pci_dev *dev, size_t size, void *cpu_addr,
64 dma_addr_t dma_handle) 64 dma_addr_t dma_handle)
65 65
66Free the region of consistent memory you previously allocated. dev, 66Free the region of consistent memory you previously allocated. dev,
67size and dma_handle must all be the same as those passed into the 67size and dma_handle must all be the same as those passed into the
68consistent allocate. cpu_addr must be the virtual address returned by 68consistent allocate. cpu_addr must be the virtual address returned by
69the consistent allocate 69the consistent allocate.
70 70
71 71
72Part Ib - Using small dma-coherent buffers 72Part Ib - Using small dma-coherent buffers
@@ -77,9 +77,9 @@ To get this part of the dma_ API, you must #include <linux/dmapool.h>
77Many drivers need lots of small dma-coherent memory regions for DMA 77Many drivers need lots of small dma-coherent memory regions for DMA
78descriptors or I/O buffers. Rather than allocating in units of a page 78descriptors or I/O buffers. Rather than allocating in units of a page
79or more using dma_alloc_coherent(), you can use DMA pools. These work 79or more using dma_alloc_coherent(), you can use DMA pools. These work
80much like a struct kmem_cache, except that they use the dma-coherent allocator 80much like a struct kmem_cache, except that they use the dma-coherent allocator,
81not __get_free_pages(). Also, they understand common hardware constraints 81not __get_free_pages(). Also, they understand common hardware constraints
82for alignment, like queue heads needing to be aligned on N byte boundaries. 82for alignment, like queue heads needing to be aligned on N-byte boundaries.
83 83
84 84
85 struct dma_pool * 85 struct dma_pool *
@@ -102,15 +102,15 @@ crossing restrictions, pass 0 for alloc; passing 4096 says memory allocated
102from this pool must not cross 4KByte boundaries. 102from this pool must not cross 4KByte boundaries.
103 103
104 104
105 void *dma_pool_alloc(struct dma_pool *pool, int gfp_flags, 105 void *dma_pool_alloc(struct dma_pool *pool, gfp_t gfp_flags,
106 dma_addr_t *dma_handle); 106 dma_addr_t *dma_handle);
107 107
108 void *pci_pool_alloc(struct pci_pool *pool, int gfp_flags, 108 void *pci_pool_alloc(struct pci_pool *pool, gfp_t gfp_flags,
109 dma_addr_t *dma_handle); 109 dma_addr_t *dma_handle);
110 110
111This allocates memory from the pool; the returned memory will meet the size 111This allocates memory from the pool; the returned memory will meet the size
112and alignment requirements specified at creation time. Pass GFP_ATOMIC to 112and alignment requirements specified at creation time. Pass GFP_ATOMIC to
113prevent blocking, or if it's permitted (not in_interrupt, not holding SMP locks) 113prevent blocking, or if it's permitted (not in_interrupt, not holding SMP locks),
114pass GFP_KERNEL to allow blocking. Like dma_alloc_coherent(), this returns 114pass GFP_KERNEL to allow blocking. Like dma_alloc_coherent(), this returns
115two values: an address usable by the cpu, and the dma address usable by the 115two values: an address usable by the cpu, and the dma address usable by the
116pool's device. 116pool's device.
@@ -123,7 +123,7 @@ pool's device.
123 dma_addr_t addr); 123 dma_addr_t addr);
124 124
125This puts memory back into the pool. The pool is what was passed to 125This puts memory back into the pool. The pool is what was passed to
126the pool allocation routine; the cpu and dma addresses are what 126the pool allocation routine; the cpu (vaddr) and dma addresses are what
127were returned when that routine allocated the memory being freed. 127were returned when that routine allocated the memory being freed.
128 128
129 129
@@ -209,18 +209,18 @@ Notes: Not all memory regions in a machine can be mapped by this
209API. Further, regions that appear to be physically contiguous in 209API. Further, regions that appear to be physically contiguous in
210kernel virtual space may not be contiguous as physical memory. Since 210kernel virtual space may not be contiguous as physical memory. Since
211this API does not provide any scatter/gather capability, it will fail 211this API does not provide any scatter/gather capability, it will fail
212if the user tries to map a non physically contiguous piece of memory. 212if the user tries to map a non-physically contiguous piece of memory.
213For this reason, it is recommended that memory mapped by this API be 213For this reason, it is recommended that memory mapped by this API be
214obtained only from sources which guarantee to be physically contiguous 214obtained only from sources which guarantee it to be physically contiguous
215(like kmalloc). 215(like kmalloc).
216 216
217Further, the physical address of the memory must be within the 217Further, the physical address of the memory must be within the
218dma_mask of the device (the dma_mask represents a bit mask of the 218dma_mask of the device (the dma_mask represents a bit mask of the
219addressable region for the device. i.e. if the physical address of 219addressable region for the device. I.e., if the physical address of
220the memory anded with the dma_mask is still equal to the physical 220the memory anded with the dma_mask is still equal to the physical
221address, then the device can perform DMA to the memory). In order to 221address, then the device can perform DMA to the memory). In order to
222ensure that the memory allocated by kmalloc is within the dma_mask, 222ensure that the memory allocated by kmalloc is within the dma_mask,
223the driver may specify various platform dependent flags to restrict 223the driver may specify various platform-dependent flags to restrict
224the physical memory range of the allocation (e.g. on x86, GFP_DMA 224the physical memory range of the allocation (e.g. on x86, GFP_DMA
225guarantees to be within the first 16Mb of available physical memory, 225guarantees to be within the first 16Mb of available physical memory,
226as required by ISA devices). 226as required by ISA devices).
@@ -244,14 +244,14 @@ are guaranteed also to be cache line boundaries).
244 244
245DMA_TO_DEVICE synchronisation must be done after the last modification 245DMA_TO_DEVICE synchronisation must be done after the last modification
246of the memory region by the software and before it is handed off to 246of the memory region by the software and before it is handed off to
247the driver. Once this primitive is used. Memory covered by this 247the driver. Once this primitive is used, memory covered by this
248primitive should be treated as read only by the device. If the device 248primitive should be treated as read-only by the device. If the device
249may write to it at any point, it should be DMA_BIDIRECTIONAL (see 249may write to it at any point, it should be DMA_BIDIRECTIONAL (see
250below). 250below).
251 251
252DMA_FROM_DEVICE synchronisation must be done before the driver 252DMA_FROM_DEVICE synchronisation must be done before the driver
253accesses data that may be changed by the device. This memory should 253accesses data that may be changed by the device. This memory should
254be treated as read only by the driver. If the driver needs to write 254be treated as read-only by the driver. If the driver needs to write
255to it at any point, it should be DMA_BIDIRECTIONAL (see below). 255to it at any point, it should be DMA_BIDIRECTIONAL (see below).
256 256
257DMA_BIDIRECTIONAL requires special handling: it means that the driver 257DMA_BIDIRECTIONAL requires special handling: it means that the driver
@@ -261,7 +261,7 @@ you must always sync bidirectional memory twice: once before the
261memory is handed off to the device (to make sure all memory changes 261memory is handed off to the device (to make sure all memory changes
262are flushed from the processor) and once before the data may be 262are flushed from the processor) and once before the data may be
263accessed after being used by the device (to make sure any processor 263accessed after being used by the device (to make sure any processor
264cache lines are updated with data that the device may have changed. 264cache lines are updated with data that the device may have changed).
265 265
266void 266void
267dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, 267dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
@@ -302,8 +302,8 @@ pci_dma_mapping_error(dma_addr_t dma_addr)
302 302
303In some circumstances dma_map_single and dma_map_page will fail to create 303In some circumstances dma_map_single and dma_map_page will fail to create
304a mapping. A driver can check for these errors by testing the returned 304a mapping. A driver can check for these errors by testing the returned
305dma address with dma_mapping_error(). A non zero return value means the mapping 305dma address with dma_mapping_error(). A non-zero return value means the mapping
306could not be created and the driver should take appropriate action (eg 306could not be created and the driver should take appropriate action (e.g.
307reduce current DMA mapping usage or delay and try again later). 307reduce current DMA mapping usage or delay and try again later).
308 308
309 int 309 int
@@ -315,7 +315,7 @@ reduce current DMA mapping usage or delay and try again later).
315 315
316Maps a scatter gather list from the block layer. 316Maps a scatter gather list from the block layer.
317 317
318Returns: the number of physical segments mapped (this may be shorted 318Returns: the number of physical segments mapped (this may be shorter
319than <nents> passed in if the block layer determines that some 319than <nents> passed in if the block layer determines that some
320elements of the scatter/gather list are physically adjacent and thus 320elements of the scatter/gather list are physically adjacent and thus
321may be mapped with a single entry). 321may be mapped with a single entry).
@@ -357,7 +357,7 @@ accessed sg->address and sg->length as shown above.
357 pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg, 357 pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
358 int nents, int direction) 358 int nents, int direction)
359 359
360unmap the previously mapped scatter/gather list. All the parameters 360Unmap the previously mapped scatter/gather list. All the parameters
361must be the same as those and passed in to the scatter/gather mapping 361must be the same as those and passed in to the scatter/gather mapping
362API. 362API.
363 363
@@ -377,7 +377,7 @@ void
377pci_dma_sync_sg(struct pci_dev *hwdev, struct scatterlist *sg, 377pci_dma_sync_sg(struct pci_dev *hwdev, struct scatterlist *sg,
378 int nelems, int direction) 378 int nelems, int direction)
379 379
380synchronise a single contiguous or scatter/gather mapping. All the 380Synchronise a single contiguous or scatter/gather mapping. All the
381parameters must be the same as those passed into the single mapping 381parameters must be the same as those passed into the single mapping
382API. 382API.
383 383
@@ -406,7 +406,7 @@ API at all.
406 406
407void * 407void *
408dma_alloc_noncoherent(struct device *dev, size_t size, 408dma_alloc_noncoherent(struct device *dev, size_t size,
409 dma_addr_t *dma_handle, int flag) 409 dma_addr_t *dma_handle, gfp_t flag)
410 410
411Identical to dma_alloc_coherent() except that the platform will 411Identical to dma_alloc_coherent() except that the platform will
412choose to return either consistent or non-consistent memory as it sees 412choose to return either consistent or non-consistent memory as it sees
@@ -426,34 +426,34 @@ void
426dma_free_noncoherent(struct device *dev, size_t size, void *cpu_addr, 426dma_free_noncoherent(struct device *dev, size_t size, void *cpu_addr,
427 dma_addr_t dma_handle) 427 dma_addr_t dma_handle)
428 428
429free memory allocated by the nonconsistent API. All parameters must 429Free memory allocated by the nonconsistent API. All parameters must
430be identical to those passed in (and returned by 430be identical to those passed in (and returned by
431dma_alloc_noncoherent()). 431dma_alloc_noncoherent()).
432 432
433int 433int
434dma_is_consistent(struct device *dev, dma_addr_t dma_handle) 434dma_is_consistent(struct device *dev, dma_addr_t dma_handle)
435 435
436returns true if the device dev is performing consistent DMA on the memory 436Returns true if the device dev is performing consistent DMA on the memory
437area pointed to by the dma_handle. 437area pointed to by the dma_handle.
438 438
439int 439int
440dma_get_cache_alignment(void) 440dma_get_cache_alignment(void)
441 441
442returns the processor cache alignment. This is the absolute minimum 442Returns the processor cache alignment. This is the absolute minimum
443alignment *and* width that you must observe when either mapping 443alignment *and* width that you must observe when either mapping
444memory or doing partial flushes. 444memory or doing partial flushes.
445 445
446Notes: This API may return a number *larger* than the actual cache 446Notes: This API may return a number *larger* than the actual cache
447line, but it will guarantee that one or more cache lines fit exactly 447line, but it will guarantee that one or more cache lines fit exactly
448into the width returned by this call. It will also always be a power 448into the width returned by this call. It will also always be a power
449of two for easy alignment 449of two for easy alignment.
450 450
451void 451void
452dma_sync_single_range(struct device *dev, dma_addr_t dma_handle, 452dma_sync_single_range(struct device *dev, dma_addr_t dma_handle,
453 unsigned long offset, size_t size, 453 unsigned long offset, size_t size,
454 enum dma_data_direction direction) 454 enum dma_data_direction direction)
455 455
456does a partial sync. starting at offset and continuing for size. You 456Does a partial sync, starting at offset and continuing for size. You
457must be careful to observe the cache alignment and width when doing 457must be careful to observe the cache alignment and width when doing
458anything like this. You must also be extra careful about accessing 458anything like this. You must also be extra careful about accessing
459memory you intend to sync partially. 459memory you intend to sync partially.
@@ -472,21 +472,20 @@ dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
472 dma_addr_t device_addr, size_t size, int 472 dma_addr_t device_addr, size_t size, int
473 flags) 473 flags)
474 474
475
476Declare region of memory to be handed out by dma_alloc_coherent when 475Declare region of memory to be handed out by dma_alloc_coherent when
477it's asked for coherent memory for this device. 476it's asked for coherent memory for this device.
478 477
479bus_addr is the physical address to which the memory is currently 478bus_addr is the physical address to which the memory is currently
480assigned in the bus responding region (this will be used by the 479assigned in the bus responding region (this will be used by the
481platform to perform the mapping) 480platform to perform the mapping).
482 481
483device_addr is the physical address the device needs to be programmed 482device_addr is the physical address the device needs to be programmed
484with actually to address this memory (this will be handed out as the 483with actually to address this memory (this will be handed out as the
485dma_addr_t in dma_alloc_coherent()) 484dma_addr_t in dma_alloc_coherent()).
486 485
487size is the size of the area (must be multiples of PAGE_SIZE). 486size is the size of the area (must be multiples of PAGE_SIZE).
488 487
489flags can be or'd together and are 488flags can be or'd together and are:
490 489
491DMA_MEMORY_MAP - request that the memory returned from 490DMA_MEMORY_MAP - request that the memory returned from
492dma_alloc_coherent() be directly writable. 491dma_alloc_coherent() be directly writable.
@@ -494,7 +493,7 @@ dma_alloc_coherent() be directly writable.
494DMA_MEMORY_IO - request that the memory returned from 493DMA_MEMORY_IO - request that the memory returned from
495dma_alloc_coherent() be addressable using read/write/memcpy_toio etc. 494dma_alloc_coherent() be addressable using read/write/memcpy_toio etc.
496 495
497One or both of these flags must be present 496One or both of these flags must be present.
498 497
499DMA_MEMORY_INCLUDES_CHILDREN - make the declared memory be allocated by 498DMA_MEMORY_INCLUDES_CHILDREN - make the declared memory be allocated by
500dma_alloc_coherent of any child devices of this one (for memory residing 499dma_alloc_coherent of any child devices of this one (for memory residing
@@ -528,7 +527,7 @@ dma_release_declared_memory(struct device *dev)
528Remove the memory region previously declared from the system. This 527Remove the memory region previously declared from the system. This
529API performs *no* in-use checking for this region and will return 528API performs *no* in-use checking for this region and will return
530unconditionally having removed all the required structures. It is the 529unconditionally having removed all the required structures. It is the
531drivers job to ensure that no parts of this memory region are 530driver's job to ensure that no parts of this memory region are
532currently in use. 531currently in use.
533 532
534void * 533void *
@@ -538,12 +537,10 @@ dma_mark_declared_memory_occupied(struct device *dev,
538This is used to occupy specific regions of the declared space 537This is used to occupy specific regions of the declared space
539(dma_alloc_coherent() will hand out the first free region it finds). 538(dma_alloc_coherent() will hand out the first free region it finds).
540 539
541device_addr is the *device* address of the region requested 540device_addr is the *device* address of the region requested.
542 541
543size is the size (and should be a page sized multiple). 542size is the size (and should be a page-sized multiple).
544 543
545The return value will be either a pointer to the processor virtual 544The return value will be either a pointer to the processor virtual
546address of the memory, or an error (via PTR_ERR()) if any part of the 545address of the memory, or an error (via PTR_ERR()) if any part of the
547region is occupied. 546region is occupied.
548
549