Skip to content

Commit 10d8ab2

Browse files
Lorenzo Pieralisirafaeljw
Lorenzo Pieralisi
authored andcommitted
ACPI/IORT: Add IORT named component memory address limits
IORT named components provide firmware configuration describing how many address bits a given device is capable of generating to address memory. Add code to the kernel to retrieve memory address limits configuration for IORT named components and configure DMA masks accordingly. 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 7ad4263 commit 10d8ab2

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

drivers/acpi/arm64/iort.c

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,24 @@ static const struct iommu_ops *iort_iommu_xlate(struct device *dev,
680680
return ret ? NULL : ops;
681681
}
682682

683+
static int nc_dma_get_range(struct device *dev, u64 *size)
684+
{
685+
struct acpi_iort_node *node;
686+
struct acpi_iort_named_component *ncomp;
687+
688+
node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT,
689+
iort_match_node_callback, dev);
690+
if (!node)
691+
return -ENODEV;
692+
693+
ncomp = (struct acpi_iort_named_component *)node->node_data;
694+
695+
*size = ncomp->memory_address_limit >= 64 ? U64_MAX :
696+
1ULL<<ncomp->memory_address_limit;
697+
698+
return 0;
699+
}
700+
683701
/**
684702
* iort_dma_setup() - Set-up device DMA parameters.
685703
*
@@ -708,24 +726,26 @@ void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
708726

709727
size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1);
710728

711-
if (dev_is_pci(dev)) {
729+
if (dev_is_pci(dev))
712730
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-
}
731+
else
732+
ret = nc_dma_get_range(dev, &size);
733+
734+
if (!ret) {
735+
msb = fls64(dmaaddr + size - 1);
736+
/*
737+
* Round-up to the power-of-two mask or set
738+
* the mask to the whole 64-bit address space
739+
* in case the DMA region covers the full
740+
* memory window.
741+
*/
742+
mask = msb == 64 ? U64_MAX : (1ULL << msb) - 1;
743+
/*
744+
* Limit coherent and dma mask based on size
745+
* retrieved from firmware.
746+
*/
747+
dev->coherent_dma_mask = mask;
748+
*dev->dma_mask = mask;
729749
}
730750

731751
*dma_addr = dmaaddr;

0 commit comments

Comments
 (0)