~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to arch/arm/include/asm/dma-mapping.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno, Martin Michlmayr
  • Date: 2011-04-06 13:53:30 UTC
  • mfrom: (43.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110406135330-wjufxhd0tvn3zx4z
Tags: 2.6.38-3
[ Ben Hutchings ]
* [ppc64] Add to linux-tools package architectures (Closes: #620124)
* [amd64] Save cr4 to mmu_cr4_features at boot time (Closes: #620284)
* appletalk: Fix bugs introduced when removing use of BKL
* ALSA: Fix yet another race in disconnection
* cciss: Fix lost command issue
* ath9k: Fix kernel panic in AR2427
* ses: Avoid kernel panic when lun 0 is not mapped
* PCI/ACPI: Report ASPM support to BIOS if not disabled from command line

[ Aurelien Jarno ]
* rtlwifi: fix build when PCI is not enabled.

[ Martin Michlmayr ]
* rtlwifi: Eliminate udelay calls with too large values (Closes: #620204)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
#include <linux/mm_types.h>
7
7
#include <linux/scatterlist.h>
 
8
#include <linux/dma-debug.h>
8
9
 
9
10
#include <asm-generic/dma-coherent.h>
10
11
#include <asm/memory.h>
11
12
 
 
13
#ifdef __arch_page_to_dma
 
14
#error Please update to __arch_pfn_to_dma
 
15
#endif
 
16
 
12
17
/*
13
 
 * page_to_dma/dma_to_virt/virt_to_dma are architecture private functions
14
 
 * used internally by the DMA-mapping API to provide DMA addresses. They
15
 
 * must not be used by drivers.
 
18
 * dma_to_pfn/pfn_to_dma/dma_to_virt/virt_to_dma are architecture private
 
19
 * functions used internally by the DMA-mapping API to provide DMA
 
20
 * addresses. They must not be used by drivers.
16
21
 */
17
 
#ifndef __arch_page_to_dma
 
22
#ifndef __arch_pfn_to_dma
 
23
static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
 
24
{
 
25
        return (dma_addr_t)__pfn_to_bus(pfn);
 
26
}
18
27
 
19
 
#if !defined(CONFIG_HIGHMEM)
20
 
static inline dma_addr_t page_to_dma(struct device *dev, struct page *page)
21
 
{
22
 
        return (dma_addr_t)__virt_to_bus((unsigned long)page_address(page));
23
 
}
24
 
#elif defined(__pfn_to_bus)
25
 
static inline dma_addr_t page_to_dma(struct device *dev, struct page *page)
26
 
{
27
 
        return (dma_addr_t)__pfn_to_bus(page_to_pfn(page));
28
 
}
29
 
#else
30
 
#error "this machine class needs to define __arch_page_to_dma to use HIGHMEM"
31
 
#endif
 
28
static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
 
29
{
 
30
        return __bus_to_pfn(addr);
 
31
}
32
32
 
33
33
static inline void *dma_to_virt(struct device *dev, dma_addr_t addr)
34
34
{
40
40
        return (dma_addr_t)__virt_to_bus((unsigned long)(addr));
41
41
}
42
42
#else
43
 
static inline dma_addr_t page_to_dma(struct device *dev, struct page *page)
44
 
{
45
 
        return __arch_page_to_dma(dev, page);
 
43
static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
 
44
{
 
45
        return __arch_pfn_to_dma(dev, pfn);
 
46
}
 
47
 
 
48
static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
 
49
{
 
50
        return __arch_dma_to_pfn(dev, addr);
46
51
}
47
52
 
48
53
static inline void *dma_to_virt(struct device *dev, dma_addr_t addr)
57
62
#endif
58
63
 
59
64
/*
60
 
 * DMA-consistent mapping functions.  These allocate/free a region of
61
 
 * uncached, unwrite-buffered mapped memory space for use with DMA
62
 
 * devices.  This is the "generic" version.  The PCI specific version
63
 
 * is in pci.h
64
 
 *
65
 
 * Note: Drivers should NOT use this function directly, as it will break
66
 
 * platforms with CONFIG_DMABOUNCE.
67
 
 * Use the driver DMA support - see dma-mapping.h (dma_sync_*)
 
65
 * The DMA API is built upon the notion of "buffer ownership".  A buffer
 
66
 * is either exclusively owned by the CPU (and therefore may be accessed
 
67
 * by it) or exclusively owned by the DMA device.  These helper functions
 
68
 * represent the transitions between these two ownership states.
 
69
 *
 
70
 * Note, however, that on later ARMs, this notion does not work due to
 
71
 * speculative prefetches.  We model our approach on the assumption that
 
72
 * the CPU does do speculative prefetches, which means we clean caches
 
73
 * before transfers and delay cache invalidation until transfer completion.
 
74
 *
 
75
 * Private support functions: these are not part of the API and are
 
76
 * liable to change.  Drivers must not use these.
68
77
 */
69
 
extern void dma_cache_maint(const void *kaddr, size_t size, int rw);
70
 
extern void dma_cache_maint_page(struct page *page, unsigned long offset,
71
 
                                 size_t size, int rw);
 
78
static inline void __dma_single_cpu_to_dev(const void *kaddr, size_t size,
 
79
        enum dma_data_direction dir)
 
80
{
 
81
        extern void ___dma_single_cpu_to_dev(const void *, size_t,
 
82
                enum dma_data_direction);
 
83
 
 
84
        if (!arch_is_coherent())
 
85
                ___dma_single_cpu_to_dev(kaddr, size, dir);
 
86
}
 
87
 
 
88
static inline void __dma_single_dev_to_cpu(const void *kaddr, size_t size,
 
89
        enum dma_data_direction dir)
 
90
{
 
91
        extern void ___dma_single_dev_to_cpu(const void *, size_t,
 
92
                enum dma_data_direction);
 
93
 
 
94
        if (!arch_is_coherent())
 
95
                ___dma_single_dev_to_cpu(kaddr, size, dir);
 
96
}
 
97
 
 
98
static inline void __dma_page_cpu_to_dev(struct page *page, unsigned long off,
 
99
        size_t size, enum dma_data_direction dir)
 
100
{
 
101
        extern void ___dma_page_cpu_to_dev(struct page *, unsigned long,
 
102
                size_t, enum dma_data_direction);
 
103
 
 
104
        if (!arch_is_coherent())
 
105
                ___dma_page_cpu_to_dev(page, off, size, dir);
 
106
}
 
107
 
 
108
static inline void __dma_page_dev_to_cpu(struct page *page, unsigned long off,
 
109
        size_t size, enum dma_data_direction dir)
 
110
{
 
111
        extern void ___dma_page_dev_to_cpu(struct page *, unsigned long,
 
112
                size_t, enum dma_data_direction);
 
113
 
 
114
        if (!arch_is_coherent())
 
115
                ___dma_page_dev_to_cpu(page, off, size, dir);
 
116
}
72
117
 
73
118
/*
74
119
 * Return whether the given device DMA address mask can be supported
88
133
 
89
134
static inline int dma_set_mask(struct device *dev, u64 dma_mask)
90
135
{
 
136
#ifdef CONFIG_DMABOUNCE
 
137
        if (dev->archdata.dmabounce) {
 
138
                if (dma_mask >= ISA_DMA_THRESHOLD)
 
139
                        return 0;
 
140
                else
 
141
                        return -EIO;
 
142
        }
 
143
#endif
91
144
        if (!dev->dma_mask || !dma_supported(dev, dma_mask))
92
145
                return -EIO;
93
146
 
96
149
        return 0;
97
150
}
98
151
 
99
 
static inline int dma_get_cache_alignment(void)
100
 
{
101
 
        return 32;
102
 
}
103
 
 
104
 
static inline int dma_is_consistent(struct device *dev, dma_addr_t handle)
105
 
{
106
 
        return !!arch_is_coherent();
107
 
}
108
 
 
109
152
/*
110
153
 * DMA errors are defined by all-bits-set in the DMA address.
111
154
 */
255
298
/*
256
299
 * The DMA API, implemented by dmabounce.c.  See below for descriptions.
257
300
 */
258
 
extern dma_addr_t dma_map_single(struct device *, void *, size_t,
259
 
                enum dma_data_direction);
260
 
extern dma_addr_t dma_map_page(struct device *, struct page *,
 
301
extern dma_addr_t __dma_map_single(struct device *, void *, size_t,
 
302
                enum dma_data_direction);
 
303
extern void __dma_unmap_single(struct device *, dma_addr_t, size_t,
 
304
                enum dma_data_direction);
 
305
extern dma_addr_t __dma_map_page(struct device *, struct page *,
261
306
                unsigned long, size_t, enum dma_data_direction);
262
 
extern void dma_unmap_single(struct device *, dma_addr_t, size_t,
 
307
extern void __dma_unmap_page(struct device *, dma_addr_t, size_t,
263
308
                enum dma_data_direction);
264
309
 
265
310
/*
283
328
}
284
329
 
285
330
 
 
331
static inline dma_addr_t __dma_map_single(struct device *dev, void *cpu_addr,
 
332
                size_t size, enum dma_data_direction dir)
 
333
{
 
334
        __dma_single_cpu_to_dev(cpu_addr, size, dir);
 
335
        return virt_to_dma(dev, cpu_addr);
 
336
}
 
337
 
 
338
static inline dma_addr_t __dma_map_page(struct device *dev, struct page *page,
 
339
             unsigned long offset, size_t size, enum dma_data_direction dir)
 
340
{
 
341
        __dma_page_cpu_to_dev(page, offset, size, dir);
 
342
        return pfn_to_dma(dev, page_to_pfn(page)) + offset;
 
343
}
 
344
 
 
345
static inline void __dma_unmap_single(struct device *dev, dma_addr_t handle,
 
346
                size_t size, enum dma_data_direction dir)
 
347
{
 
348
        __dma_single_dev_to_cpu(dma_to_virt(dev, handle), size, dir);
 
349
}
 
350
 
 
351
static inline void __dma_unmap_page(struct device *dev, dma_addr_t handle,
 
352
                size_t size, enum dma_data_direction dir)
 
353
{
 
354
        __dma_page_dev_to_cpu(pfn_to_page(dma_to_pfn(dev, handle)),
 
355
                handle & ~PAGE_MASK, size, dir);
 
356
}
 
357
#endif /* CONFIG_DMABOUNCE */
 
358
 
286
359
/**
287
360
 * dma_map_single - map a single buffer for streaming DMA
288
361
 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
300
373
static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
301
374
                size_t size, enum dma_data_direction dir)
302
375
{
 
376
        dma_addr_t addr;
 
377
 
303
378
        BUG_ON(!valid_dma_direction(dir));
304
379
 
305
 
        if (!arch_is_coherent())
306
 
                dma_cache_maint(cpu_addr, size, dir);
 
380
        addr = __dma_map_single(dev, cpu_addr, size, dir);
 
381
        debug_dma_map_page(dev, virt_to_page(cpu_addr),
 
382
                        (unsigned long)cpu_addr & ~PAGE_MASK, size,
 
383
                        dir, addr, true);
307
384
 
308
 
        return virt_to_dma(dev, cpu_addr);
 
385
        return addr;
309
386
}
310
387
 
311
388
/**
325
402
static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
326
403
             unsigned long offset, size_t size, enum dma_data_direction dir)
327
404
{
 
405
        dma_addr_t addr;
 
406
 
328
407
        BUG_ON(!valid_dma_direction(dir));
329
408
 
330
 
        if (!arch_is_coherent())
331
 
                dma_cache_maint_page(page, offset, size, dir);
 
409
        addr = __dma_map_page(dev, page, offset, size, dir);
 
410
        debug_dma_map_page(dev, page, offset, size, dir, addr, false);
332
411
 
333
 
        return page_to_dma(dev, page) + offset;
 
412
        return addr;
334
413
}
335
414
 
336
415
/**
350
429
static inline void dma_unmap_single(struct device *dev, dma_addr_t handle,
351
430
                size_t size, enum dma_data_direction dir)
352
431
{
353
 
        /* nothing to do */
 
432
        debug_dma_unmap_page(dev, handle, size, dir, true);
 
433
        __dma_unmap_single(dev, handle, size, dir);
354
434
}
355
 
#endif /* CONFIG_DMABOUNCE */
356
435
 
357
436
/**
358
437
 * dma_unmap_page - unmap a buffer previously mapped through dma_map_page()
371
450
static inline void dma_unmap_page(struct device *dev, dma_addr_t handle,
372
451
                size_t size, enum dma_data_direction dir)
373
452
{
374
 
        dma_unmap_single(dev, handle, size, dir);
 
453
        debug_dma_unmap_page(dev, handle, size, dir, false);
 
454
        __dma_unmap_page(dev, handle, size, dir);
375
455
}
376
456
 
377
457
/**
398
478
{
399
479
        BUG_ON(!valid_dma_direction(dir));
400
480
 
401
 
        dmabounce_sync_for_cpu(dev, handle, offset, size, dir);
 
481
        debug_dma_sync_single_for_cpu(dev, handle + offset, size, dir);
 
482
 
 
483
        if (!dmabounce_sync_for_cpu(dev, handle, offset, size, dir))
 
484
                return;
 
485
 
 
486
        __dma_single_dev_to_cpu(dma_to_virt(dev, handle) + offset, size, dir);
402
487
}
403
488
 
404
489
static inline void dma_sync_single_range_for_device(struct device *dev,
407
492
{
408
493
        BUG_ON(!valid_dma_direction(dir));
409
494
 
 
495
        debug_dma_sync_single_for_device(dev, handle + offset, size, dir);
 
496
 
410
497
        if (!dmabounce_sync_for_device(dev, handle, offset, size, dir))
411
498
                return;
412
499
 
413
 
        if (!arch_is_coherent())
414
 
                dma_cache_maint(dma_to_virt(dev, handle) + offset, size, dir);
 
500
        __dma_single_cpu_to_dev(dma_to_virt(dev, handle) + offset, size, dir);
415
501
}
416
502
 
417
503
static inline void dma_sync_single_for_cpu(struct device *dev,