Skip to content

Commit 18ed580

Browse files
rleonkawasaki
authored andcommitted
PCI/P2PDMA: Simplify bus address mapping API
Update the pci_p2pdma_bus_addr_map() function to take a direct pointer to the p2pdma_provider structure instead of the pci_p2pdma_map_state. This simplifies the API by removing the need for callers to extract the provider from the state structure. The change updates all callers across the kernel (block layer, IOMMU, DMA direct, and HMM) to pass the provider pointer directly, making the code more explicit and reducing unnecessary indirection. This also removes the runtime warning check since callers now have direct control over which provider they use. Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 35d8ba2 commit 18ed580

5 files changed

Lines changed: 9 additions & 10 deletions

File tree

block/blk-mq-dma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static inline bool blk_can_dma_map_iova(struct request *req,
7979

8080
static bool blk_dma_map_bus(struct blk_dma_iter *iter, struct phys_vec *vec)
8181
{
82-
iter->addr = pci_p2pdma_bus_addr_map(&iter->p2pdma, vec->paddr);
82+
iter->addr = pci_p2pdma_bus_addr_map(iter->p2pdma.mem, vec->paddr);
8383
iter->len = vec->len;
8484
return true;
8585
}

drivers/iommu/dma-iommu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,8 +1429,8 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
14291429
* as a bus address, __finalise_sg() will copy the dma
14301430
* address into the output segment.
14311431
*/
1432-
s->dma_address = pci_p2pdma_bus_addr_map(&p2pdma_state,
1433-
sg_phys(s));
1432+
s->dma_address = pci_p2pdma_bus_addr_map(
1433+
p2pdma_state.mem, sg_phys(s));
14341434
sg_dma_len(s) = sg->length;
14351435
sg_dma_mark_bus_address(s);
14361436
continue;

include/linux/pci-p2pdma.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,15 @@ pci_p2pdma_state(struct pci_p2pdma_map_state *state, struct device *dev,
186186
/**
187187
* pci_p2pdma_bus_addr_map - Translate a physical address to a bus address
188188
* for a PCI_P2PDMA_MAP_BUS_ADDR transfer.
189-
* @state: P2P state structure
189+
* @provider: P2P provider structure
190190
* @paddr: physical address to map
191191
*
192192
* Map a physically contiguous PCI_P2PDMA_MAP_BUS_ADDR transfer.
193193
*/
194194
static inline dma_addr_t
195-
pci_p2pdma_bus_addr_map(struct pci_p2pdma_map_state *state, phys_addr_t paddr)
195+
pci_p2pdma_bus_addr_map(struct p2pdma_provider *provider, phys_addr_t paddr)
196196
{
197-
WARN_ON_ONCE(state->map != PCI_P2PDMA_MAP_BUS_ADDR);
198-
return paddr + state->mem->bus_offset;
197+
return paddr + provider->bus_offset;
199198
}
200199

201200
#endif /* _LINUX_PCI_P2P_H */

kernel/dma/direct.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
484484
}
485485
break;
486486
case PCI_P2PDMA_MAP_BUS_ADDR:
487-
sg->dma_address = pci_p2pdma_bus_addr_map(&p2pdma_state,
488-
sg_phys(sg));
487+
sg->dma_address = pci_p2pdma_bus_addr_map(
488+
p2pdma_state.mem, sg_phys(sg));
489489
sg_dma_mark_bus_address(sg);
490490
continue;
491491
default:

mm/hmm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ dma_addr_t hmm_dma_map_pfn(struct device *dev, struct hmm_dma_map *map,
751751
break;
752752
case PCI_P2PDMA_MAP_BUS_ADDR:
753753
pfns[idx] |= HMM_PFN_P2PDMA_BUS | HMM_PFN_DMA_MAPPED;
754-
return pci_p2pdma_bus_addr_map(p2pdma_state, paddr);
754+
return pci_p2pdma_bus_addr_map(p2pdma_state->mem, paddr);
755755
default:
756756
return DMA_MAPPING_ERROR;
757757
}

0 commit comments

Comments
 (0)