Revision b90600ee dma.h
b/dma.h | ||
---|---|---|
11 | 11 |
#define DMA_H |
12 | 12 |
|
13 | 13 |
#include <stdio.h> |
14 |
#include "memory.h" |
|
14 | 15 |
#include "hw/hw.h" |
15 | 16 |
#include "block.h" |
16 | 17 |
#include "kvm.h" |
... | ... | |
61 | 62 |
dma_addr_t access_len); |
62 | 63 |
|
63 | 64 |
struct DMAContext { |
65 |
AddressSpace *as; |
|
64 | 66 |
DMATranslateFunc *translate; |
65 | 67 |
DMAMapFunc *map; |
66 | 68 |
DMAUnmapFunc *unmap; |
... | ... | |
93 | 95 |
|
94 | 96 |
static inline bool dma_has_iommu(DMAContext *dma) |
95 | 97 |
{ |
96 |
return !!dma;
|
|
98 |
return dma && dma->translate;
|
|
97 | 99 |
} |
98 | 100 |
|
99 | 101 |
/* Checks that the given range of addresses is valid for DMA. This is |
... | ... | |
120 | 122 |
{ |
121 | 123 |
if (!dma_has_iommu(dma)) { |
122 | 124 |
/* Fast-path for no IOMMU */ |
123 |
cpu_physical_memory_rw(addr, buf, len, |
|
124 |
dir == DMA_DIRECTION_FROM_DEVICE); |
|
125 |
address_space_rw(dma->as, addr, buf, len, dir == DMA_DIRECTION_FROM_DEVICE); |
|
125 | 126 |
return 0; |
126 | 127 |
} else { |
127 | 128 |
return iommu_dma_memory_rw(dma, addr, buf, len, dir); |
... | ... | |
179 | 180 |
target_phys_addr_t xlen = *len; |
180 | 181 |
void *p; |
181 | 182 |
|
182 |
p = cpu_physical_memory_map(addr, &xlen, |
|
183 |
dir == DMA_DIRECTION_FROM_DEVICE); |
|
183 |
p = address_space_map(dma->as, addr, &xlen, dir == DMA_DIRECTION_FROM_DEVICE); |
|
184 | 184 |
*len = xlen; |
185 | 185 |
return p; |
186 | 186 |
} else { |
... | ... | |
196 | 196 |
DMADirection dir, dma_addr_t access_len) |
197 | 197 |
{ |
198 | 198 |
if (!dma_has_iommu(dma)) { |
199 |
cpu_physical_memory_unmap(buffer, (target_phys_addr_t)len, |
|
200 |
dir == DMA_DIRECTION_FROM_DEVICE, |
|
201 |
access_len); |
|
199 |
address_space_unmap(dma->as, buffer, (target_phys_addr_t)len, |
|
200 |
dir == DMA_DIRECTION_FROM_DEVICE, access_len); |
|
202 | 201 |
} else { |
203 | 202 |
iommu_dma_memory_unmap(dma, buffer, len, dir, access_len); |
204 | 203 |
} |
... | ... | |
242 | 241 |
|
243 | 242 |
#undef DEFINE_LDST_DMA |
244 | 243 |
|
245 |
void dma_context_init(DMAContext *dma, DMATranslateFunc translate, |
|
244 |
void dma_context_init(DMAContext *dma, AddressSpace *as, DMATranslateFunc translate,
|
|
246 | 245 |
DMAMapFunc map, DMAUnmapFunc unmap); |
247 | 246 |
|
248 | 247 |
struct ScatterGatherEntry { |
Also available in: Unified diff