1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_DMA_MAPPING_H 3 #define _LINUX_DMA_MAPPING_H 4 5 #include <linux/sizes.h> 6 #include <linux/string.h> 7 #include <linux/device.h> 8 #include <linux/err.h> 9 #include <linux/dma-direction.h> 10 #include <linux/scatterlist.h> 11 #include <linux/bug.h> 12 #include <linux/mem_encrypt.h> 13 14 /** 15 * List of possible attributes associated with a DMA mapping. The semantics 16 * of each attribute should be defined in Documentation/core-api/dma-attributes.rst. 17 */ 18 19 /* 20 * DMA_ATTR_WEAK_ORDERING: Specifies that reads and writes to the mapping 21 * may be weakly ordered, that is that reads and writes may pass each other. 22 */ 23 #define DMA_ATTR_WEAK_ORDERING (1UL << 1) 24 /* 25 * DMA_ATTR_WRITE_COMBINE: Specifies that writes to the mapping may be 26 * buffered to improve performance. 27 */ 28 #define DMA_ATTR_WRITE_COMBINE (1UL << 2) 29 /* 30 * DMA_ATTR_NO_KERNEL_MAPPING: Lets the platform to avoid creating a kernel 31 * virtual mapping for the allocated buffer. 32 */ 33 #define DMA_ATTR_NO_KERNEL_MAPPING (1UL << 4) 34 /* 35 * DMA_ATTR_SKIP_CPU_SYNC: Allows platform code to skip synchronization of 36 * the CPU cache for the given buffer assuming that it has been already 37 * transferred to 'device' domain. 38 */ 39 #define DMA_ATTR_SKIP_CPU_SYNC (1UL << 5) 40 /* 41 * DMA_ATTR_FORCE_CONTIGUOUS: Forces contiguous allocation of the buffer 42 * in physical memory. 43 */ 44 #define DMA_ATTR_FORCE_CONTIGUOUS (1UL << 6) 45 /* 46 * DMA_ATTR_ALLOC_SINGLE_PAGES: This is a hint to the DMA-mapping subsystem 47 * that it's probably not worth the time to try to allocate memory to in a way 48 * that gives better TLB efficiency. 49 */ 50 #define DMA_ATTR_ALLOC_SINGLE_PAGES (1UL << 7) 51 /* 52 * DMA_ATTR_NO_WARN: This tells the DMA-mapping subsystem to suppress 53 * allocation failure reports (similarly to __GFP_NOWARN). 54 */ 55 #define DMA_ATTR_NO_WARN (1UL << 8) 56 57 /* 58 * DMA_ATTR_PRIVILEGED: used to indicate that the buffer is fully 59 * accessible at an elevated privilege level (and ideally inaccessible or 60 * at least read-only at lesser-privileged levels). 61 */ 62 #define DMA_ATTR_PRIVILEGED (1UL << 9) 63 64 /* 65 * A dma_addr_t can hold any valid DMA or bus address for the platform. It can 66 * be given to a device to use as a DMA source or target. It is specific to a 67 * given device and there may be a translation between the CPU physical address 68 * space and the bus address space. 69 * 70 * DMA_MAPPING_ERROR is the magic error code if a mapping failed. It should not 71 * be used directly in drivers, but checked for using dma_mapping_error() 72 * instead. 73 */ 74 #define DMA_MAPPING_ERROR (~(dma_addr_t)0) 75 76 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1)) 77 78 #ifdef CONFIG_DMA_API_DEBUG 79 void debug_dma_mapping_error(struct device *dev, dma_addr_t dma_addr); 80 void debug_dma_map_single(struct device *dev, const void *addr, 81 unsigned long len); 82 #else 83 static inline void debug_dma_mapping_error(struct device *dev, 84 dma_addr_t dma_addr) 85 { 86 } 87 static inline void debug_dma_map_single(struct device *dev, const void *addr, 88 unsigned long len) 89 { 90 } 91 #endif /* CONFIG_DMA_API_DEBUG */ 92 93 #ifdef CONFIG_HAS_DMA 94 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) 95 { 96 debug_dma_mapping_error(dev, dma_addr); 97 98 if (unlikely(dma_addr == DMA_MAPPING_ERROR)) 99 return -ENOMEM; 100 return 0; 101 } 102 103 dma_addr_t dma_map_page_attrs(struct device *dev, struct page *page, 104 size_t offset, size_t size, enum dma_data_direction dir, 105 unsigned long attrs); 106 void dma_unmap_page_attrs(struct device *dev, dma_addr_t addr, size_t size, 107 enum dma_data_direction dir, unsigned long attrs); 108 int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg, int nents, 109 enum dma_data_direction dir, unsigned long attrs); 110 void dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg, 111 int nents, enum dma_data_direction dir, 112 unsigned long attrs); 113 int dma_map_sgtable(struct device *dev, struct sg_table *sgt, 114 enum dma_data_direction dir, unsigned long attrs); 115 dma_addr_t dma_map_resource(struct device *dev, phys_addr_t phys_addr, 116 size_t size, enum dma_data_direction dir, unsigned long attrs); 117 void dma_unmap_resource(struct device *dev, dma_addr_t addr, size_t size, 118 enum dma_data_direction dir, unsigned long attrs); 119 void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr, size_t size, 120 enum dma_data_direction dir); 121 void dma_sync_single_for_device(struct device *dev, dma_addr_t addr, 122 size_t size, enum dma_data_direction dir); 123 void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, 124 int nelems, enum dma_data_direction dir); 125 void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, 126 int nelems, enum dma_data_direction dir); 127 void *dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle, 128 gfp_t flag, unsigned long attrs); 129 void dma_free_attrs(struct device *dev, size_t size, void *cpu_addr, 130 dma_addr_t dma_handle, unsigned long attrs); 131 void *dmam_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle, 132 gfp_t gfp, unsigned long attrs); 133 void dmam_free_coherent(struct device *dev, size_t size, void *vaddr, 134 dma_addr_t dma_handle); 135 int dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, 136 void *cpu_addr, dma_addr_t dma_addr, size_t size, 137 unsigned long attrs); 138 int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, 139 void *cpu_addr, dma_addr_t dma_addr, size_t size, 140 unsigned long attrs); 141 bool dma_can_mmap(struct device *dev); 142 int dma_supported(struct device *dev, u64 mask); 143 int dma_set_mask(struct device *dev, u64 mask); 144 int dma_set_coherent_mask(struct device *dev, u64 mask); 145 u64 dma_get_required_mask(struct device *dev); 146 size_t dma_max_mapping_size(struct device *dev); 147 bool dma_need_sync(struct device *dev, dma_addr_t dma_addr); 148 unsigned long dma_get_merge_boundary(struct device *dev); 149 struct sg_table *dma_alloc_noncontiguous(struct device *dev, size_t size, 150 enum dma_data_direction dir, gfp_t gfp, unsigned long attrs); 151 void dma_free_noncontiguous(struct device *dev, size_t size, 152 struct sg_table *sgt, enum dma_data_direction dir); 153 void *dma_vmap_noncontiguous(struct device *dev, size_t size, 154 struct sg_table *sgt); 155 void dma_vunmap_noncontiguous(struct device *dev, void *vaddr); 156 int dma_mmap_noncontiguous(struct device *dev, struct vm_area_struct *vma, 157 size_t size, struct sg_table *sgt); 158 #else /* CONFIG_HAS_DMA */ 159 static inline dma_addr_t dma_map_page_attrs(struct device *dev, 160 struct page *page, size_t offset, size_t size, 161 enum dma_data_direction dir, unsigned long attrs) 162 { 163 return DMA_MAPPING_ERROR; 164 } 165 static inline void dma_unmap_page_attrs(struct device *dev, dma_addr_t addr, 166 size_t size, enum dma_data_direction dir, unsigned long attrs) 167 { 168 } 169 static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg, 170 int nents, enum dma_data_direction dir, unsigned long attrs) 171 { 172 return 0; 173 } 174 static inline void dma_unmap_sg_attrs(struct device *dev, 175 struct scatterlist *sg, int nents, enum dma_data_direction dir, 176 unsigned long attrs) 177 { 178 } 179 static inline int dma_map_sgtable(struct device *dev, struct sg_table *sgt, 180 enum dma_data_direction dir, unsigned long attrs) 181 { 182 return -EOPNOTSUPP; 183 } 184 static inline dma_addr_t dma_map_resource(struct device *dev, 185 phys_addr_t phys_addr, size_t size, enum dma_data_direction dir, 186 unsigned long attrs) 187 { 188 return DMA_MAPPING_ERROR; 189 } 190 static inline void dma_unmap_resource(struct device *dev, dma_addr_t addr, 191 size_t size, enum dma_data_direction dir, unsigned long attrs) 192 { 193 } 194 static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr, 195 size_t size, enum dma_data_direction dir) 196 { 197 } 198 static inline void dma_sync_single_for_device(struct device *dev, 199 dma_addr_t addr, size_t size, enum dma_data_direction dir) 200 { 201 } 202 static inline void dma_sync_sg_for_cpu(struct device *dev, 203 struct scatterlist *sg, int nelems, enum dma_data_direction dir) 204 { 205 } 206 static inline void dma_sync_sg_for_device(struct device *dev, 207 struct scatterlist *sg, int nelems, enum dma_data_direction dir) 208 { 209 } 210 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) 211 { 212 return -ENOMEM; 213 } 214 static inline void *dma_alloc_attrs(struct device *dev, size_t size, 215 dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs) 216 { 217 return NULL; 218 } 219 static void dma_free_attrs(struct device *dev, size_t size, void *cpu_addr, 220 dma_addr_t dma_handle, unsigned long attrs) 221 { 222 } 223 static inline void *dmam_alloc_attrs(struct device *dev, size_t size, 224 dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) 225 { 226 return NULL; 227 } 228 static inline void dmam_free_coherent(struct device *dev, size_t size, 229 void *vaddr, dma_addr_t dma_handle) 230 { 231 } 232 static inline int dma_get_sgtable_attrs(struct device *dev, 233 struct sg_table *sgt, void *cpu_addr, dma_addr_t dma_addr, 234 size_t size, unsigned long attrs) 235 { 236 return -ENXIO; 237 } 238 static inline int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, 239 void *cpu_addr, dma_addr_t dma_addr, size_t size, 240 unsigned long attrs) 241 { 242 return -ENXIO; 243 } 244 static inline bool dma_can_mmap(struct device *dev) 245 { 246 return false; 247 } 248 static inline int dma_supported(struct device *dev, u64 mask) 249 { 250 return 0; 251 } 252 static inline int dma_set_mask(struct device *dev, u64 mask) 253 { 254 return -EIO; 255 } 256 static inline int dma_set_coherent_mask(struct device *dev, u64 mask) 257 { 258 return -EIO; 259 } 260 static inline u64 dma_get_required_mask(struct device *dev) 261 { 262 return 0; 263 } 264 static inline size_t dma_max_mapping_size(struct device *dev) 265 { 266 return 0; 267 } 268 static inline bool dma_need_sync(struct device *dev, dma_addr_t dma_addr) 269 { 270 return false; 271 } 272 static inline unsigned long dma_get_merge_boundary(struct device *dev) 273 { 274 return 0; 275 } 276 static inline struct sg_table *dma_alloc_noncontiguous(struct device *dev, 277 size_t size, enum dma_data_direction dir, gfp_t gfp, 278 unsigned long attrs) 279 { 280 return NULL; 281 } 282 static inline void dma_free_noncontiguous(struct device *dev, size_t size, 283 struct sg_table *sgt, enum dma_data_direction dir) 284 { 285 } 286 static inline void *dma_vmap_noncontiguous(struct device *dev, size_t size, 287 struct sg_table *sgt) 288 { 289 return NULL; 290 } 291 static inline void dma_vunmap_noncontiguous(struct device *dev, void *vaddr) 292 { 293 } 294 static inline int dma_mmap_noncontiguous(struct device *dev, 295 struct vm_area_struct *vma, size_t size, struct sg_table *sgt) 296 { 297 return -EINVAL; 298 } 299 #endif /* CONFIG_HAS_DMA */ 300 301 struct page *dma_alloc_pages(struct device *dev, size_t size, 302 dma_addr_t *dma_handle, enum dma_data_direction dir, gfp_t gfp); 303 void dma_free_pages(struct device *dev, size_t size, struct page *page, 304 dma_addr_t dma_handle, enum dma_data_direction dir); 305 int dma_mmap_pages(struct device *dev, struct vm_area_struct *vma, 306 size_t size, struct page *page); 307 308 static inline void *dma_alloc_noncoherent(struct device *dev, size_t size, 309 dma_addr_t *dma_handle, enum dma_data_direction dir, gfp_t gfp) 310 { 311 struct page *page = dma_alloc_pages(dev, size, dma_handle, dir, gfp); 312 return page ? page_address(page) : NULL; 313 } 314 315 static inline void dma_free_noncoherent(struct device *dev, size_t size, 316 void *vaddr, dma_addr_t dma_handle, enum dma_data_direction dir) 317 { 318 dma_free_pages(dev, size, virt_to_page(vaddr), dma_handle, dir); 319 } 320 321 static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr, 322 size_t size, enum dma_data_direction dir, unsigned long attrs) 323 { 324 /* DMA must never operate on areas that might be remapped. */ 325 if (dev_WARN_ONCE(dev, is_vmalloc_addr(ptr), 326 "rejecting DMA map of vmalloc memory\n")) 327 return DMA_MAPPING_ERROR; 328 debug_dma_map_single(dev, ptr, size); 329 return dma_map_page_attrs(dev, virt_to_page(ptr), offset_in_page(ptr), 330 size, dir, attrs); 331 } 332 333 static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t addr, 334 size_t size, enum dma_data_direction dir, unsigned long attrs) 335 { 336 return dma_unmap_page_attrs(dev, addr, size, dir, attrs); 337 } 338 339 static inline void dma_sync_single_range_for_cpu(struct device *dev, 340 dma_addr_t addr, unsigned long offset, size_t size, 341 enum dma_data_direction dir) 342 { 343 return dma_sync_single_for_cpu(dev, addr + offset, size, dir); 344 } 345 346 static inline void dma_sync_single_range_for_device(struct device *dev, 347 dma_addr_t addr, unsigned long offset, size_t size, 348 enum dma_data_direction dir) 349 { 350 return dma_sync_single_for_device(dev, addr + offset, size, dir); 351 } 352 353 /** 354 * dma_unmap_sgtable - Unmap the given buffer for DMA 355 * @dev: The device for which to perform the DMA operation 356 * @sgt: The sg_table object describing the buffer 357 * @dir: DMA direction 358 * @attrs: Optional DMA attributes for the unmap operation 359 * 360 * Unmaps a buffer described by a scatterlist stored in the given sg_table 361 * object for the @dir DMA operation by the @dev device. After this function 362 * the ownership of the buffer is transferred back to the CPU domain. 363 */ 364 static inline void dma_unmap_sgtable(struct device *dev, struct sg_table *sgt, 365 enum dma_data_direction dir, unsigned long attrs) 366 { 367 dma_unmap_sg_attrs(dev, sgt->sgl, sgt->orig_nents, dir, attrs); 368 } 369 370 /** 371 * dma_sync_sgtable_for_cpu - Synchronize the given buffer for CPU access 372 * @dev: The device for which to perform the DMA operation 373 * @sgt: The sg_table object describing the buffer 374 * @dir: DMA direction 375 * 376 * Performs the needed cache synchronization and moves the ownership of the 377 * buffer back to the CPU domain, so it is safe to perform any access to it 378 * by the CPU. Before doing any further DMA operations, one has to transfer 379 * the ownership of the buffer back to the DMA domain by calling the 380 * dma_sync_sgtable_for_device(). 381 */ 382 static inline void dma_sync_sgtable_for_cpu(struct device *dev, 383 struct sg_table *sgt, enum dma_data_direction dir) 384 { 385 dma_sync_sg_for_cpu(dev, sgt->sgl, sgt->orig_nents, dir); 386 } 387 388 /** 389 * dma_sync_sgtable_for_device - Synchronize the given buffer for DMA 390 * @dev: The device for which to perform the DMA operation 391 * @sgt: The sg_table object describing the buffer 392 * @dir: DMA direction 393 * 394 * Performs the needed cache synchronization and moves the ownership of the 395 * buffer back to the DMA domain, so it is safe to perform the DMA operation. 396 * Once finished, one has to call dma_sync_sgtable_for_cpu() or 397 * dma_unmap_sgtable(). 398 */ 399 static inline void dma_sync_sgtable_for_device(struct device *dev, 400 struct sg_table *sgt, enum dma_data_direction dir) 401 { 402 dma_sync_sg_for_device(dev, sgt->sgl, sgt->orig_nents, dir); 403 } 404 405 #define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, 0) 406 #define dma_unmap_single(d, a, s, r) dma_unmap_single_attrs(d, a, s, r, 0) 407 #define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, 0) 408 #define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, 0) 409 #define dma_map_page(d, p, o, s, r) dma_map_page_attrs(d, p, o, s, r, 0) 410 #define dma_unmap_page(d, a, s, r) dma_unmap_page_attrs(d, a, s, r, 0) 411 #define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, 0) 412 #define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, 0) 413 414 static inline void *dma_alloc_coherent(struct device *dev, size_t size, 415 dma_addr_t *dma_handle, gfp_t gfp) 416 { 417 return dma_alloc_attrs(dev, size, dma_handle, gfp, 418 (gfp & __GFP_NOWARN) ? DMA_ATTR_NO_WARN : 0); 419 } 420 421 static inline void dma_free_coherent(struct device *dev, size_t size, 422 void *cpu_addr, dma_addr_t dma_handle) 423 { 424 return dma_free_attrs(dev, size, cpu_addr, dma_handle, 0); 425 } 426 427 428 static inline u64 dma_get_mask(struct device *dev) 429 { 430 if (dev->dma_mask && *dev->dma_mask) 431 return *dev->dma_mask; 432 return DMA_BIT_MASK(32); 433 } 434 435 /* 436 * Set both the DMA mask and the coherent DMA mask to the same thing. 437 * Note that we don't check the return value from dma_set_coherent_mask() 438 * as the DMA API guarantees that the coherent DMA mask can be set to 439 * the same or smaller than the streaming DMA mask. 440 */ 441 static inline int dma_set_mask_and_coherent(struct device *dev, u64 mask) 442 { 443 int rc = dma_set_mask(dev, mask); 444 if (rc == 0) 445 dma_set_coherent_mask(dev, mask); 446 return rc; 447 } 448 449 /* 450 * Similar to the above, except it deals with the case where the device 451 * does not have dev->dma_mask appropriately setup. 452 */ 453 static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask) 454 { 455 dev->dma_mask = &dev->coherent_dma_mask; 456 return dma_set_mask_and_coherent(dev, mask); 457 } 458 459 /** 460 * dma_addressing_limited - return if the device is addressing limited 461 * @dev: device to check 462 * 463 * Return %true if the devices DMA mask is too small to address all memory in 464 * the system, else %false. Lack of addressing bits is the prime reason for 465 * bounce buffering, but might not be the only one. 466 */ 467 static inline bool dma_addressing_limited(struct device *dev) 468 { 469 return min_not_zero(dma_get_mask(dev), dev->bus_dma_limit) < 470 dma_get_required_mask(dev); 471 } 472 473 static inline unsigned int dma_get_max_seg_size(struct device *dev) 474 { 475 if (dev->dma_parms && dev->dma_parms->max_segment_size) 476 return dev->dma_parms->max_segment_size; 477 return SZ_64K; 478 } 479 480 static inline int dma_set_max_seg_size(struct device *dev, unsigned int size) 481 { 482 if (dev->dma_parms) { 483 dev->dma_parms->max_segment_size = size; 484 return 0; 485 } 486 return -EIO; 487 } 488 489 static inline unsigned long dma_get_seg_boundary(struct device *dev) 490 { 491 if (dev->dma_parms && dev->dma_parms->segment_boundary_mask) 492 return dev->dma_parms->segment_boundary_mask; 493 return ULONG_MAX; 494 } 495 496 /** 497 * dma_get_seg_boundary_nr_pages - return the segment boundary in "page" units 498 * @dev: device to guery the boundary for 499 * @page_shift: ilog() of the IOMMU page size 500 * 501 * Return the segment boundary in IOMMU page units (which may be different from 502 * the CPU page size) for the passed in device. 503 * 504 * If @dev is NULL a boundary of U32_MAX is assumed, this case is just for 505 * non-DMA API callers. 506 */ 507 static inline unsigned long dma_get_seg_boundary_nr_pages(struct device *dev, 508 unsigned int page_shift) 509 { 510 if (!dev) 511 return (U32_MAX >> page_shift) + 1; 512 return (dma_get_seg_boundary(dev) >> page_shift) + 1; 513 } 514 515 static inline int dma_set_seg_boundary(struct device *dev, unsigned long mask) 516 { 517 if (dev->dma_parms) { 518 dev->dma_parms->segment_boundary_mask = mask; 519 return 0; 520 } 521 return -EIO; 522 } 523 524 static inline unsigned int dma_get_min_align_mask(struct device *dev) 525 { 526 if (dev->dma_parms) 527 return dev->dma_parms->min_align_mask; 528 return 0; 529 } 530 531 static inline int dma_set_min_align_mask(struct device *dev, 532 unsigned int min_align_mask) 533 { 534 if (WARN_ON_ONCE(!dev->dma_parms)) 535 return -EIO; 536 dev->dma_parms->min_align_mask = min_align_mask; 537 return 0; 538 } 539 540 static inline int dma_get_cache_alignment(void) 541 { 542 #ifdef ARCH_DMA_MINALIGN 543 return ARCH_DMA_MINALIGN; 544 #endif 545 return 1; 546 } 547 548 static inline void *dmam_alloc_coherent(struct device *dev, size_t size, 549 dma_addr_t *dma_handle, gfp_t gfp) 550 { 551 return dmam_alloc_attrs(dev, size, dma_handle, gfp, 552 (gfp & __GFP_NOWARN) ? DMA_ATTR_NO_WARN : 0); 553 } 554 555 static inline void *dma_alloc_wc(struct device *dev, size_t size, 556 dma_addr_t *dma_addr, gfp_t gfp) 557 { 558 unsigned long attrs = DMA_ATTR_WRITE_COMBINE; 559 560 if (gfp & __GFP_NOWARN) 561 attrs |= DMA_ATTR_NO_WARN; 562 563 return dma_alloc_attrs(dev, size, dma_addr, gfp, attrs); 564 } 565 566 static inline void dma_free_wc(struct device *dev, size_t size, 567 void *cpu_addr, dma_addr_t dma_addr) 568 { 569 return dma_free_attrs(dev, size, cpu_addr, dma_addr, 570 DMA_ATTR_WRITE_COMBINE); 571 } 572 573 static inline int dma_mmap_wc(struct device *dev, 574 struct vm_area_struct *vma, 575 void *cpu_addr, dma_addr_t dma_addr, 576 size_t size) 577 { 578 return dma_mmap_attrs(dev, vma, cpu_addr, dma_addr, size, 579 DMA_ATTR_WRITE_COMBINE); 580 } 581 582 #ifdef CONFIG_NEED_DMA_MAP_STATE 583 #define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME) dma_addr_t ADDR_NAME 584 #define DEFINE_DMA_UNMAP_LEN(LEN_NAME) __u32 LEN_NAME 585 #define dma_unmap_addr(PTR, ADDR_NAME) ((PTR)->ADDR_NAME) 586 #define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) (((PTR)->ADDR_NAME) = (VAL)) 587 #define dma_unmap_len(PTR, LEN_NAME) ((PTR)->LEN_NAME) 588 #define dma_unmap_len_set(PTR, LEN_NAME, VAL) (((PTR)->LEN_NAME) = (VAL)) 589 #else 590 #define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME) 591 #define DEFINE_DMA_UNMAP_LEN(LEN_NAME) 592 #define dma_unmap_addr(PTR, ADDR_NAME) (0) 593 #define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0) 594 #define dma_unmap_len(PTR, LEN_NAME) (0) 595 #define dma_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0) 596 #endif 597 598 #endif /* _LINUX_DMA_MAPPING_H */ 599