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.

alpha: Convert mapping routine to rely on physical address

Alpha doesn't need struct *page and can perform mapping based on
physical addresses. So convert it to implement new .map_phys callback.

As part of this change, remove useless BUG_ON() as DMA mapping layer
ensures that right direction is provided.

Tested-by: Magnus Lindholm <linmag7@gmail.com>
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-7-3bbfe3a25cdf@kernel.org

authored by

Leon Romanovsky and committed by
Marek Szyprowski
6aaecdf0 14cb413a

+21 -27
+21 -27
arch/alpha/kernel/pci_iommu.c
··· 224 224 until either pci_unmap_single or pci_dma_sync_single is performed. */ 225 225 226 226 static dma_addr_t 227 - pci_map_single_1(struct pci_dev *pdev, void *cpu_addr, size_t size, 227 + pci_map_single_1(struct pci_dev *pdev, phys_addr_t paddr, size_t size, 228 228 int dac_allowed) 229 229 { 230 230 struct pci_controller *hose = pdev ? pdev->sysdata : pci_isa_hose; 231 231 dma_addr_t max_dma = pdev ? pdev->dma_mask : ISA_DMA_MASK; 232 + unsigned long offset = offset_in_page(paddr); 232 233 struct pci_iommu_arena *arena; 233 234 long npages, dma_ofs, i; 234 - unsigned long paddr; 235 235 dma_addr_t ret; 236 236 unsigned int align = 0; 237 237 struct device *dev = pdev ? &pdev->dev : NULL; 238 - 239 - paddr = __pa(cpu_addr); 240 238 241 239 #if !DEBUG_NODIRECT 242 240 /* First check to see if we can use the direct map window. */ ··· 242 244 && paddr + size <= __direct_map_size) { 243 245 ret = paddr + __direct_map_base; 244 246 245 - DBGA2("pci_map_single: [%p,%zx] -> direct %llx from %ps\n", 246 - cpu_addr, size, ret, __builtin_return_address(0)); 247 + DBGA2("pci_map_single: [%pa,%zx] -> direct %llx from %ps\n", 248 + &paddr, size, ret, __builtin_return_address(0)); 247 249 248 250 return ret; 249 251 } ··· 253 255 if (dac_allowed) { 254 256 ret = paddr + alpha_mv.pci_dac_offset; 255 257 256 - DBGA2("pci_map_single: [%p,%zx] -> DAC %llx from %ps\n", 257 - cpu_addr, size, ret, __builtin_return_address(0)); 258 + DBGA2("pci_map_single: [%pa,%zx] -> DAC %llx from %ps\n", 259 + &paddr, size, ret, __builtin_return_address(0)); 258 260 259 261 return ret; 260 262 } ··· 288 290 arena->ptes[i + dma_ofs] = mk_iommu_pte(paddr); 289 291 290 292 ret = arena->dma_base + dma_ofs * PAGE_SIZE; 291 - ret += (unsigned long)cpu_addr & ~PAGE_MASK; 293 + ret += offset; 292 294 293 - DBGA2("pci_map_single: [%p,%zx] np %ld -> sg %llx from %ps\n", 294 - cpu_addr, size, npages, ret, __builtin_return_address(0)); 295 + DBGA2("pci_map_single: [%pa,%zx] np %ld -> sg %llx from %ps\n", 296 + &paddr, size, npages, ret, __builtin_return_address(0)); 295 297 296 298 return ret; 297 299 } ··· 320 322 return NULL; 321 323 } 322 324 323 - static dma_addr_t alpha_pci_map_page(struct device *dev, struct page *page, 324 - unsigned long offset, size_t size, 325 - enum dma_data_direction dir, 325 + static dma_addr_t alpha_pci_map_phys(struct device *dev, phys_addr_t phys, 326 + size_t size, enum dma_data_direction dir, 326 327 unsigned long attrs) 327 328 { 328 329 struct pci_dev *pdev = alpha_gendev_to_pci(dev); 329 330 int dac_allowed; 330 331 331 - BUG_ON(dir == DMA_NONE); 332 + if (unlikely(attrs & DMA_ATTR_MMIO)) 333 + return DMA_MAPPING_ERROR; 332 334 333 - dac_allowed = pdev ? pci_dac_dma_supported(pdev, pdev->dma_mask) : 0; 334 - return pci_map_single_1(pdev, (char *)page_address(page) + offset, 335 - size, dac_allowed); 335 + dac_allowed = pdev ? pci_dac_dma_supported(pdev, pdev->dma_mask) : 0; 336 + return pci_map_single_1(pdev, phys, size, dac_allowed); 336 337 } 337 338 338 339 /* Unmap a single streaming mode DMA translation. The DMA_ADDR and ··· 340 343 the cpu to the buffer are guaranteed to see whatever the device 341 344 wrote there. */ 342 345 343 - static void alpha_pci_unmap_page(struct device *dev, dma_addr_t dma_addr, 346 + static void alpha_pci_unmap_phys(struct device *dev, dma_addr_t dma_addr, 344 347 size_t size, enum dma_data_direction dir, 345 348 unsigned long attrs) 346 349 { ··· 349 352 struct pci_controller *hose = pdev ? pdev->sysdata : pci_isa_hose; 350 353 struct pci_iommu_arena *arena; 351 354 long dma_ofs, npages; 352 - 353 - BUG_ON(dir == DMA_NONE); 354 355 355 356 if (dma_addr >= __direct_map_base 356 357 && dma_addr < __direct_map_base + __direct_map_size) { ··· 424 429 } 425 430 memset(cpu_addr, 0, size); 426 431 427 - *dma_addrp = pci_map_single_1(pdev, cpu_addr, size, 0); 432 + *dma_addrp = pci_map_single_1(pdev, virt_to_phys(cpu_addr), size, 0); 428 433 if (*dma_addrp == DMA_MAPPING_ERROR) { 429 434 free_pages((unsigned long)cpu_addr, order); 430 435 if (alpha_mv.mv_pci_tbi || (gfp & GFP_DMA)) ··· 638 643 /* Fast path single entry scatterlists. */ 639 644 if (nents == 1) { 640 645 sg->dma_length = sg->length; 641 - sg->dma_address 642 - = pci_map_single_1(pdev, SG_ENT_VIRT_ADDRESS(sg), 643 - sg->length, dac_allowed); 646 + sg->dma_address = pci_map_single_1(pdev, sg_phys(sg), 647 + sg->length, dac_allowed); 644 648 if (sg->dma_address == DMA_MAPPING_ERROR) 645 649 return -EIO; 646 650 return 1; ··· 911 917 const struct dma_map_ops alpha_pci_ops = { 912 918 .alloc = alpha_pci_alloc_coherent, 913 919 .free = alpha_pci_free_coherent, 914 - .map_page = alpha_pci_map_page, 915 - .unmap_page = alpha_pci_unmap_page, 920 + .map_phys = alpha_pci_map_phys, 921 + .unmap_phys = alpha_pci_unmap_phys, 916 922 .map_sg = alpha_pci_map_sg, 917 923 .unmap_sg = alpha_pci_unmap_sg, 918 924 .dma_supported = alpha_pci_supported,