Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ARM: dma-mapping: Switch to physical address mapping callbacks

Combine resource and page mappings routines to one function, which
handles both these flows at the same manner. This conversion allows
us to remove .map_resource/.unmap_resource callbacks completely.

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/20251015-remove-map-page-v5-4-3bbfe3a25cdf@kernel.org

authored by

Leon Romanovsky and committed by
Marek Szyprowski
50b149be 52c9aa1a

+23 -77
+23 -77
arch/arm/mm/dma-mapping.c
··· 732 732 if (attrs & DMA_ATTR_PRIVILEGED) 733 733 prot |= IOMMU_PRIV; 734 734 735 + if (attrs & DMA_ATTR_MMIO) 736 + prot |= IOMMU_MMIO; 737 + 735 738 switch (dir) { 736 739 case DMA_BIDIRECTIONAL: 737 740 return prot | IOMMU_READ | IOMMU_WRITE; ··· 1353 1350 } 1354 1351 1355 1352 /** 1356 - * arm_iommu_map_page 1353 + * arm_iommu_map_phys 1357 1354 * @dev: valid struct device pointer 1358 - * @page: page that buffer resides in 1359 - * @offset: offset into page for start of buffer 1355 + * @phys: physical address that buffer resides in 1360 1356 * @size: size of buffer to map 1361 1357 * @dir: DMA transfer direction 1358 + * @attrs: DMA mapping attributes 1362 1359 * 1363 1360 * IOMMU aware version of arm_dma_map_page() 1364 1361 */ 1365 - static dma_addr_t arm_iommu_map_page(struct device *dev, struct page *page, 1366 - unsigned long offset, size_t size, enum dma_data_direction dir, 1367 - unsigned long attrs) 1362 + static dma_addr_t arm_iommu_map_phys(struct device *dev, phys_addr_t phys, 1363 + size_t size, enum dma_data_direction dir, unsigned long attrs) 1368 1364 { 1369 1365 struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); 1366 + int len = PAGE_ALIGN(size + offset_in_page(phys)); 1367 + phys_addr_t addr = phys & PAGE_MASK; 1370 1368 dma_addr_t dma_addr; 1371 - int ret, prot, len = PAGE_ALIGN(size + offset); 1369 + int ret, prot; 1372 1370 1373 - if (!dev->dma_coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC)) 1374 - arch_sync_dma_for_device(page_to_phys(page), offset, size, dir); 1371 + if (!dev->dma_coherent && 1372 + !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO))) 1373 + arch_sync_dma_for_device(phys, size, dir); 1375 1374 1376 1375 dma_addr = __alloc_iova(mapping, len); 1377 1376 if (dma_addr == DMA_MAPPING_ERROR) ··· 1381 1376 1382 1377 prot = __dma_info_to_prot(dir, attrs); 1383 1378 1384 - ret = iommu_map(mapping->domain, dma_addr, page_to_phys(page), len, 1385 - prot, GFP_KERNEL); 1379 + ret = iommu_map(mapping->domain, dma_addr, addr, len, prot, GFP_KERNEL); 1386 1380 if (ret < 0) 1387 1381 goto fail; 1388 1382 1389 - return dma_addr + offset; 1383 + return dma_addr + offset_in_page(phys); 1390 1384 fail: 1391 1385 __free_iova(mapping, dma_addr, len); 1392 1386 return DMA_MAPPING_ERROR; ··· 1397 1393 * @handle: DMA address of buffer 1398 1394 * @size: size of buffer (same as passed to dma_map_page) 1399 1395 * @dir: DMA transfer direction (same as passed to dma_map_page) 1396 + * @attrs: DMA mapping attributes 1400 1397 * 1401 - * IOMMU aware version of arm_dma_unmap_page() 1398 + * IOMMU aware version of arm_dma_unmap_phys() 1402 1399 */ 1403 - static void arm_iommu_unmap_page(struct device *dev, dma_addr_t handle, 1400 + static void arm_iommu_unmap_phys(struct device *dev, dma_addr_t handle, 1404 1401 size_t size, enum dma_data_direction dir, unsigned long attrs) 1405 1402 { 1406 1403 struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); ··· 1412 1407 if (!iova) 1413 1408 return; 1414 1409 1415 - if (!dev->dma_coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC)) { 1410 + if (!dev->dma_coherent && 1411 + !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO))) { 1416 1412 phys_addr_t phys = iommu_iova_to_phys(mapping->domain, iova); 1417 1413 1418 1414 arch_sync_dma_for_cpu(phys + offset, size, dir); 1419 1415 } 1420 - 1421 - iommu_unmap(mapping->domain, iova, len); 1422 - __free_iova(mapping, iova, len); 1423 - } 1424 - 1425 - /** 1426 - * arm_iommu_map_resource - map a device resource for DMA 1427 - * @dev: valid struct device pointer 1428 - * @phys_addr: physical address of resource 1429 - * @size: size of resource to map 1430 - * @dir: DMA transfer direction 1431 - */ 1432 - static dma_addr_t arm_iommu_map_resource(struct device *dev, 1433 - phys_addr_t phys_addr, size_t size, 1434 - enum dma_data_direction dir, unsigned long attrs) 1435 - { 1436 - struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); 1437 - dma_addr_t dma_addr; 1438 - int ret, prot; 1439 - phys_addr_t addr = phys_addr & PAGE_MASK; 1440 - unsigned int offset = phys_addr & ~PAGE_MASK; 1441 - size_t len = PAGE_ALIGN(size + offset); 1442 - 1443 - dma_addr = __alloc_iova(mapping, len); 1444 - if (dma_addr == DMA_MAPPING_ERROR) 1445 - return dma_addr; 1446 - 1447 - prot = __dma_info_to_prot(dir, attrs) | IOMMU_MMIO; 1448 - 1449 - ret = iommu_map(mapping->domain, dma_addr, addr, len, prot, GFP_KERNEL); 1450 - if (ret < 0) 1451 - goto fail; 1452 - 1453 - return dma_addr + offset; 1454 - fail: 1455 - __free_iova(mapping, dma_addr, len); 1456 - return DMA_MAPPING_ERROR; 1457 - } 1458 - 1459 - /** 1460 - * arm_iommu_unmap_resource - unmap a device DMA resource 1461 - * @dev: valid struct device pointer 1462 - * @dma_handle: DMA address to resource 1463 - * @size: size of resource to map 1464 - * @dir: DMA transfer direction 1465 - */ 1466 - static void arm_iommu_unmap_resource(struct device *dev, dma_addr_t dma_handle, 1467 - size_t size, enum dma_data_direction dir, 1468 - unsigned long attrs) 1469 - { 1470 - struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); 1471 - dma_addr_t iova = dma_handle & PAGE_MASK; 1472 - unsigned int offset = dma_handle & ~PAGE_MASK; 1473 - size_t len = PAGE_ALIGN(size + offset); 1474 - 1475 - if (!iova) 1476 - return; 1477 1416 1478 1417 iommu_unmap(mapping->domain, iova, len); 1479 1418 __free_iova(mapping, iova, len); ··· 1459 1510 .mmap = arm_iommu_mmap_attrs, 1460 1511 .get_sgtable = arm_iommu_get_sgtable, 1461 1512 1462 - .map_page = arm_iommu_map_page, 1463 - .unmap_page = arm_iommu_unmap_page, 1513 + .map_phys = arm_iommu_map_phys, 1514 + .unmap_phys = arm_iommu_unmap_phys, 1464 1515 .sync_single_for_cpu = arm_iommu_sync_single_for_cpu, 1465 1516 .sync_single_for_device = arm_iommu_sync_single_for_device, 1466 1517 ··· 1468 1519 .unmap_sg = arm_iommu_unmap_sg, 1469 1520 .sync_sg_for_cpu = arm_iommu_sync_sg_for_cpu, 1470 1521 .sync_sg_for_device = arm_iommu_sync_sg_for_device, 1471 - 1472 - .map_resource = arm_iommu_map_resource, 1473 - .unmap_resource = arm_iommu_unmap_resource, 1474 1522 }; 1475 1523 1476 1524 /**