Skip to content

Commit 7ad4263

Browse files
Lorenzo Pieralisirafaeljw
Lorenzo Pieralisi
authored andcommitted
ACPI: Make acpi_dma_configure() DMA regions aware
Current ACPI DMA configuration set-up device DMA capabilities through kernel defaults that do not take into account platform specific DMA configurations reported by firmware. By leveraging the ACPI acpi_dev_get_dma_resources() API, add code in acpi_dma_configure() to retrieve the DMA regions to correctly set-up PCI devices DMA parameters. Rework the ACPI IORT kernel API to make sure they can accommodate the DMA set-up required by firmware. By making PCI devices DMA set-up ACPI IORT specific, the kernel is shielded from unwanted regressions that could be triggered by parsing DMA resources on arches that were previously ignoring them (ie x86/ia64), leaving kernel behaviour unchanged on those arches. Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Acked-by: Will Deacon <will.deacon@arm.com> Tested-by: Nate Watterson <nwatters@codeaurora.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent c04ac67 commit 7ad4263

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

drivers/acpi/arm64/iort.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,12 +681,17 @@ static const struct iommu_ops *iort_iommu_xlate(struct device *dev,
681681
}
682682

683683
/**
684-
* iort_set_dma_mask - Set-up dma mask for a device.
684+
* iort_dma_setup() - Set-up device DMA parameters.
685685
*
686686
* @dev: device to configure
687+
* @dma_addr: device DMA address result pointer
688+
* @size: DMA range size result pointer
687689
*/
688-
void iort_set_dma_mask(struct device *dev)
690+
void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
689691
{
692+
u64 mask, dmaaddr = 0, size = 0, offset = 0;
693+
int ret, msb;
694+
690695
/*
691696
* Set default coherent_dma_mask to 32 bit. Drivers are expected to
692697
* setup the correct supported mask.
@@ -700,6 +705,34 @@ void iort_set_dma_mask(struct device *dev)
700705
*/
701706
if (!dev->dma_mask)
702707
dev->dma_mask = &dev->coherent_dma_mask;
708+
709+
size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1);
710+
711+
if (dev_is_pci(dev)) {
712+
ret = acpi_dma_get_range(dev, &dmaaddr, &offset, &size);
713+
if (!ret) {
714+
msb = fls64(dmaaddr + size - 1);
715+
/*
716+
* Round-up to the power-of-two mask or set
717+
* the mask to the whole 64-bit address space
718+
* in case the DMA region covers the full
719+
* memory window.
720+
*/
721+
mask = msb == 64 ? U64_MAX : (1ULL << msb) - 1;
722+
/*
723+
* Limit coherent and dma mask based on size
724+
* retrieved from firmware.
725+
*/
726+
dev->coherent_dma_mask = mask;
727+
*dev->dma_mask = mask;
728+
}
729+
}
730+
731+
*dma_addr = dmaaddr;
732+
*dma_size = size;
733+
734+
dev->dma_pfn_offset = PFN_DOWN(offset);
735+
dev_dbg(dev, "dma_pfn_offset(%#08llx)\n", offset);
703736
}
704737

705738
/**

drivers/acpi/scan.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,20 +1446,16 @@ int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
14461446
int acpi_dma_configure(struct device *dev, enum dev_dma_attr attr)
14471447
{
14481448
const struct iommu_ops *iommu;
1449-
u64 size;
1449+
u64 dma_addr = 0, size = 0;
14501450

1451-
iort_set_dma_mask(dev);
1451+
iort_dma_setup(dev, &dma_addr, &size);
14521452

14531453
iommu = iort_iommu_configure(dev);
14541454
if (IS_ERR(iommu) && PTR_ERR(iommu) == -EPROBE_DEFER)
14551455
return -EPROBE_DEFER;
14561456

1457-
size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1);
1458-
/*
1459-
* Assume dma valid range starts at 0 and covers the whole
1460-
* coherent_dma_mask.
1461-
*/
1462-
arch_setup_dma_ops(dev, 0, size, iommu, attr == DEV_DMA_COHERENT);
1457+
arch_setup_dma_ops(dev, dma_addr, size,
1458+
iommu, attr == DEV_DMA_COHERENT);
14631459

14641460
return 0;
14651461
}

include/linux/acpi_iort.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct irq_domain *iort_get_device_domain(struct device *dev, u32 req_id);
3636
void acpi_configure_pmsi_domain(struct device *dev);
3737
int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id);
3838
/* IOMMU interface */
39-
void iort_set_dma_mask(struct device *dev);
39+
void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *size);
4040
const struct iommu_ops *iort_iommu_configure(struct device *dev);
4141
#else
4242
static inline void acpi_iort_init(void) { }
@@ -47,7 +47,8 @@ static inline struct irq_domain *iort_get_device_domain(struct device *dev,
4747
{ return NULL; }
4848
static inline void acpi_configure_pmsi_domain(struct device *dev) { }
4949
/* IOMMU interface */
50-
static inline void iort_set_dma_mask(struct device *dev) { }
50+
static inline void iort_dma_setup(struct device *dev, u64 *dma_addr,
51+
u64 *size) { }
5152
static inline
5253
const struct iommu_ops *iort_iommu_configure(struct device *dev)
5354
{ return NULL; }

0 commit comments

Comments
 (0)