fsldma: Support 40 bit DMA addresses where capable
Subsystems (2)
PATCH 1/1 fsldma: Support 40 bit DMA addresses where capable
On 64-bit QorIQ platforms like T4240, the CPU supports 40-bit addressing and memory configurations > 64GiB. The fsldma driver is limiting itself to only 64GiB in all Elo configurations.
Setup fsldma driver to make use of the full 40-bit addressing space, specifically on the e5500 and e6500 CPUs.
--- drivers/dma/fsldma.c | 2 +- drivers/dma/fsldma.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/dma/fsldma.c +1 -1
@@ -1254,7 +1254,7 @@ static int fsldma_of_probe(struct platform_device *op) fdev->common.directions =BIT (DMA_DEV_TO_MEM ) |BIT (DMA_MEM_TO_DEV ); fdev->common.residue_granularity =DMA_RESIDUE_GRANULARITY_DESCRIPTOR ; -dma_set_mask (&(op->dev),DMA_BIT_MASK (36 )); +dma_set_mask (&(op->dev),DMA_BIT_MASK (ELO_MAX_PHYS_BITS ));platform_set_drvdata (op, fdev);
drivers/dma/fsldma.h +7 -0
@@ -13,6 +13,13 @@#include <linux/dmapool.h> #include <linux/dmaengine.h> +/* Physical addressing capability */ +#if defined(CONFIG_E6500_CPU ) || defined(CONFIG_E5500_CPU ) +#define ELO_MAX_PHYS_BITS 40 +#else +#define ELO_MAX_PHYS_BITS 36 +#endif +/* Define data structures needed by Freescale * MPC8540 and MPC8349 DMA controller. */
Signature · 9 lines
2.49.0 -- Ben Collins https://libjwt.io https://github.com/benmcollins -- 3EC9 7598 1672 961A 1139 173A 5D5A 57C7 242B 22CF
Quoted 6 lines · Ben Collins
On 64-bit QorIQ platforms like T4240, the CPU supports 40-bit addressing and memory configurations > 64GiB. The fsldma driver is limiting itself to only 64GiB in all Elo configurations.
Setup fsldma driver to make use of the full 40-bit addressing space, specifically on the e5500 and e6500 CPUs.
I don't think making the mask depend on a compile-time option is correct, e.g. when you build a combined 32-bit kernel for e500 and e5500, you set a different mask compared to an e500-only kernel.
The question here is whether the mask is a limitation of the IP block or the bus it's connected to, of if there is any limitation at all:
- The driver just writes the DMA address as a 64-bit register, so most likely the DMA device can in fact do wider addressing, and any limitation is either in the bus or the available memory
- SoCs that don't set a dma-ranges property in the parent bus are normally still capped to 32 bit DMA. I don't see those properties, so unless there is a special hack on those chips, you get 32 bit DMA regardless of what DMA mask the driver requests
- If there are chips that have more than 64GB of RAM installed but have a limitation in the way the DMA engine is wired up to 36 bits, that should be reflected in the dma-ranges property, not the device driver.
- If the limitation is indeed specific to the version of the IP block, this would normally need to be detected based on the compatible string of the DMA engine itself, not a compile time setting.
Arnd
Quoted 8 lines · Arnd Bergmann
Quoted 6 lines · Ben Collins
On 64-bit QorIQ platforms like T4240, the CPU supports 40-bit addressing and memory configurations > 64GiB. The fsldma driver is limiting itself to only 64GiB in all Elo configurations.
Setup fsldma driver to make use of the full 40-bit addressing space, specifically on the e5500 and e6500 CPUs.
...
Quoted 11 lines
- The driver just writes the DMA address as a 64-bit register, so most likely the DMA device can in fact do wider addressing, and any limitation is either in the bus or the available memory
- SoCs that don't set a dma-ranges property in the parent bus are normally still capped to 32 bit DMA. I don't see those properties, so unless there is a special hack on those chips, you get 32 bit DMA regardless of what DMA mask the driver requests
I've yet to see a dma-ranges property in any of the Freescale PowerPC device trees.
I'll check on this, but I think it's a seperate issue. The main thing is just to configure the dma hw correctly.
Quoted 9 lines
- If there are chips that have more than 64GB of RAM installed but have a limitation in the way the DMA engine is wired up to 36 bits, that should be reflected in the dma-ranges property, not the device driver.
- If the limitation is indeed specific to the version of the IP block, this would normally need to be detected based on the compatible string of the DMA engine itself, not a compile time setting.
So a little research shows that these 3 compatible strings in the fsldma are:
fsl,elo3-dma: 40-bit
fsl,eloplus-dma: 36-bit
fsl,elo-dma: 32-bit
I'll rework it so addressing is based on the compatible string.
Signature · 5 lines
Ben Collins https://libjwt.io https://github.com/benmcollins -- 3EC9 7598 1672 961A 1139 173A 5D5A 57C7 242B 22CF
Quoted 10 lines · Ben Collins
Quoted 6 lines · Arnd Bergmann
- SoCs that don't set a dma-ranges property in the parent bus are normally still capped to 32 bit DMA. I don't see those properties, so unless there is a special hack on those chips, you get 32 bit DMA regardless of what DMA mask the driver requests
I've yet to see a dma-ranges property in any of the Freescale PowerPC device trees.
Right, but this could just mean that they end up using SWIOTLB to bounce the high DMA pages or use an IOMMU rather than actually translating the physical address to a dma address.
The only special case I see for freescale powerpc chips is the PCI dma_set_mask() handler that does
static void fsl_pci_dma_set_mask(struct device *dev, u64 dma_mask)
{
/*
* Fix up PCI devices that are able to DMA to the large inbound
* mapping that allows addressing any RAM address from across PCI.
*/
if (dev_is_pci(dev) && dma_mask >= pci64_dma_offset * 2 - 1) {
dev->bus_dma_limit = 0;
dev->archdata.dma_offset = pci64_dma_offset;
}
}but that should not apply here because this is not a PCI device.
Quoted 2 lines
I'll check on this, but I think it's a seperate issue. The main thing is just to configure the dma hw correctly.
I think it's still important to check this before changing the
driver: if the larger mask doesn't actually have any effect now because the DT caps the DMA at 4GB, then it might break later when someone adds the correct dma-ranges properties.
Quoted 8 lines
So a little research shows that these 3 compatible strings in the fsldma are:
fsl,elo3-dma: 40-bit
fsl,eloplus-dma: 36-bit
fsl,elo-dma: 32-bitI'll rework it so addressing is based on the compatible string.
Sounds good, yes. Just to clarify: where did you find those limits? Are you sure those are not just the maximum addressable amounts of physical RAM on the chips that use the respective controllers?
Arnd
Quoted 9 lines · Arnd Bergmann
Quoted 8 lines · Ben Collins
Quoted 6 lines · Arnd Bergmann
- SoCs that don't set a dma-ranges property in the parent bus are normally still capped to 32 bit DMA. I don't see those properties, so unless there is a special hack on those chips, you get 32 bit DMA regardless of what DMA mask the driver requests
Quoted 6 lines
Quoted 2 lines
I've yet to see a dma-ranges property in any of the Freescale PowerPC device trees.
Right, but this could just mean that they end up using SWIOTLB to bounce the high DMA pages or use an IOMMU rather than actually translating the physical address to a dma address.
There's a few things going on. The Local Address Window can shift anywhere in the 64-bit address space and be as wide as the physical address (40-bit on T4240, 36-bit on P4080). I think this is mainly for IO to PCIe and RapidIO, though.
Quoted 15 lines
The only special case I see for freescale powerpc chips is the PCI
dma_set_mask()handler that doesstatic void
fsl_pci_dma_set_mask(struct device *dev, u64 dma_mask){ /* * Fix up PCI devices that are able to DMA to the large inbound * mapping that allows addressing any RAM address from across PCI. */ if (dev_is_pci(dev) && dma_mask >= pci64_dma_offset * 2 - 1) { dev->bus_dma_limit = 0; dev->archdata.dma_offset = pci64_dma_offset; } }
Quoted 1 line
but that should not apply here because this is not a PCI device.
Right.
Quoted 7 lines
Quoted 2 lines
I'll check on this, but I think it's a seperate issue. The main thing is just to configure the dma hw correctly.
I think it's still important to check this before changing the
driver: if the larger mask doesn't actually have any effect now because the DT caps the DMA at 4GB, then it might break later when someone adds the correct dma-ranges properties.
I'm adding dma-ranges to my dt for testing.
Quoted 7 lines
Quoted 7 lines
So a little research shows that these 3 compatible strings in the fsldma are:
fsl,elo3-dma: 40-bit
fsl,eloplus-dma: 36-bit
fsl,elo-dma: 32-bit
Quoted 6 lines
Quoted 1 line
I'll rework it so addressing is based on the compatible string.
Sounds good, yes. Just to clarify: where did you find those limits? Are you sure those are not just the maximum addressable amounts of physical RAM on the chips that use the respective controllers?
This is where things might be more interesting. The P4080RM and T4240RM is where I got this information. Register "cdar" in the fsldma code. This makes up 0x08 and 0x0c registers.
In the RM 0x08 is the extended address register. On P4080 it says this holds the top 4 bits of the 36-bit address, and on T4240 it says the top 8 bits of the 40-bit address. So the asynx_tx physical address needs to be masked to the 36-bit or 40-bit.
Signature · 5 lines
Ben Collins https://libjwt.io https://github.com/benmcollins -- 3EC9 7598 1672 961A 1139 173A 5D5A 57C7 242B 22CF
Quoted 10 lines · Ben Collins
Quoted 4 lines · Arnd Bergmann
Right, but this could just mean that they end up using SWIOTLB to bounce the high DMA pages or use an IOMMU rather than actually translating the physical address to a dma address.
There's a few things going on. The Local Address Window can shift anywhere in the 64-bit address space and be as wide as the physical address (40-bit on T4240, 36-bit on P4080). I think this is mainly for IO to PCIe and RapidIO, though.
There are usually two sets of registers, not sure which one the Local Address Window refers to:
- Translation of MMIO addresses (PCI BAR and device registers) when accessed from CPU and possibly from P2P DMA, these are represented by the 'ranges' property in DT.
- Translation of physical memory when accessed from a DMA bus master, represented by the 'dma-ranges' property.
The latter is what the dma-mapping API needs. This code has changed a lot over the years, but in the current version the idea is that the limit enforced by the driver through dma_set_mask() is independent of the limit enforced by the platform bus based on the dma-ranges property.
The bit that matters in the end is the intersection of both, so dma_map_single() etc only maps a page that is addressable by both the device and the bus.
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines
I'll check on this, but I think it's a seperate issue. The main thing is just to configure the dma hw correctly.
I think it's still important to check this before changing the
driver: if the larger mask doesn't actually have any effect now because the DT caps the DMA at 4GB, then it might break later when someone adds the correct dma-ranges properties.I'm adding dma-ranges to my dt for testing.
Ok. The other thing you can try is to printk() the dev->bus_dma_limit to see if it even tries to use >32bit addressing.
Quoted 14 lines
Quoted 7 lines
Quoted 7 lines
So a little research shows that these 3 compatible strings in the fsldma are:
fsl,elo3-dma: 40-bit
fsl,eloplus-dma: 36-bit
fsl,elo-dma: 32-bitQuoted 6 lines
Quoted 1 line
I'll rework it so addressing is based on the compatible string.
Sounds good, yes. Just to clarify: where did you find those limits? Are you sure those are not just the maximum addressable amounts of physical RAM on the chips that use the respective controllers?
Quoted 8 lines
This is where things might be more interesting. The P4080RM and T4240RM is where I got this information. Register "cdar" in the fsldma code. This makes up
0x08and0x0cregisters.In the RM
0x08is the extended address register. On P4080 it says this holds the top 4 bits of the 36-bit address, and on T4240 it says the top 8 bits of the 40-bit address. So theasynx_txphysical address needs to be masked to the 36-bit or 40-bit.
Ok, makes sense.
Arnd
Quoted 19 lines · Arnd Bergmann
Quoted 10 lines · Ben Collins
Quoted 4 lines · Arnd Bergmann
Right, but this could just mean that they end up using SWIOTLB to bounce the high DMA pages or use an IOMMU rather than actually translating the physical address to a dma address.
There's a few things going on. The Local Address Window can shift anywhere in the 64-bit address space and be as wide as the physical address (40-bit on T4240, 36-bit on P4080). I think this is mainly for IO to PCIe and RapidIO, though.
There are usually two sets of registers, not sure which one the Local Address Window refers to:
- Translation of MMIO addresses (PCI BAR and device registers) when accessed from CPU and possibly from P2P DMA, these are represented by the 'ranges' property in DT.
Quoted 8 lines
- Translation of physical memory when accessed from a DMA bus master, represented by the 'dma-ranges' property.
The latter is what the dma-mapping API needs. This code has changed a lot over the years, but in the current version the idea is that the limit enforced by the driver through
dma_set_mask()is independent of the limit enforced by the platform bus based on the dma-ranges property.
LAWs translate physical addresses to IOVA (PCIe/RapidIO/SoC resources) and are used for all master level translations (CPU, DMA, PCIe, DDR, RapidIO). This is at the interconnect level.
I believe LAWs cover both of these cases.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
I'll check on this, but I think it's a seperate issue. The main thing is just to configure the dma hw correctly.
I think it's still important to check this before changing the
driver: if the larger mask doesn't actually have any effect now because the DT caps the DMA at 4GB, then it might break later when someone adds the correct dma-ranges properties.
Quoted 4 lines
Quoted 1 line
I'm adding dma-ranges to my dt for testing.
Ok. The other thing you can try is to
printk()thedev->bus_dma_limitto see if it even tries to use >32bit addressing.
Did that. Every combination of IOMMU on/off and dma-ranges in my dt always showed bus_dma_limit as 0x0.
As an aside, if you could give this a quick check, I can send the revised patch. Appreciate the feedback.
https://github.com/benmcollins/linux/commit/2f2946b33294ebff2fdaae6d1eadc976147470d6
Signature · 5 lines
Ben Collins https://libjwt.io https://github.com/benmcollins -- 3EC9 7598 1672 961A 1139 173A 5D5A 57C7 242B 22CF
Quoted 11 lines · Ben Collins
Quoted 10 lines · Arnd Bergmann
Quoted 8 lines · Ben Collins
Quoted 7 lines
Quoted 2 lines
I'll check on this, but I think it's a seperate issue. The main thing is just to configure the dma hw correctly.
I think it's still important to check this before changing the
driver: if the larger mask doesn't actually have any effect now because the DT caps the DMA at 4GB, then it might break later when someone adds the correct dma-ranges properties.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
I'm adding dma-ranges to my dt for testing.
Ok. The other thing you can try is to
printk()thedev->bus_dma_limitto see if it even tries to use >32bit addressing.Did that. Every combination of IOMMU on/off and dma-ranges in my dt always showed
bus_dma_limitas0x0.
Strange, either something changed since I last looked at this code, or there is something on Freescale SoCs that avoids the default logic.
There was originally a hack for powerpc that allowed DMA to be done in the absence of a dma-ranges property in the bus node, but limit it to 32-bit addressing for backwards compatibility, while all other architectures should require either an empty dma-ranges to allow full addressing or a specific translation if there is a bus specific limit and/or offset.
Looking at the current code I don't see that any more, so it's possible that now any DMA is allowed even if there is no dma-ranges property at all.
Quoted 4 lines
As an aside, if you could give this a quick check, I can send the revised patch. Appreciate the feedback.
https://github.com/benmcollins/linux/commit/2f2946b33294ebff2fdaae6d1eadc976147470d6
This looks correct to me, but I would change two things:
- remove the debug message, which you probably left by accident
- instead of the explicit of_device_is_compatible(), change it to use the .data field of the of_device_id table instead.
Arnd
Quoted 27 lines · Arnd Bergmann
Quoted 11 lines · Ben Collins
Quoted 10 lines · Arnd Bergmann
Quoted 8 lines · Ben Collins
Quoted 7 lines
Quoted 2 lines
I'll check on this, but I think it's a seperate issue. The main thing is just to configure the dma hw correctly.
I think it's still important to check this before changing the
driver: if the larger mask doesn't actually have any effect now because the DT caps the DMA at 4GB, then it might break later when someone adds the correct dma-ranges properties.Quoted 7 lines
Quoted 4 lines
Quoted 1 line
I'm adding dma-ranges to my dt for testing.
Ok. The other thing you can try is to
printk()thedev->bus_dma_limitto see if it even tries to use >32bit addressing.Did that. Every combination of IOMMU on/off and dma-ranges in my dt always showed
bus_dma_limitas0x0.There was originally a hack for powerpc that allowed DMA to be done in the absence of a dma-ranges property in the bus node, but limit it to 32-bit addressing for backwards compatibility, while all other architectures should require either an empty dma-ranges to allow full addressing or a specific translation if there is a bus specific limit and/or offset.
Quoted 3 lines
Looking at the current code I don't see that any more, so it's possible that now any DMA is allowed even if there is no dma-ranges property at all.
It's still there. It hardcodes zone_dma_limit to 31-bits:
arch/powerpc/mm/mem.c: paging_init()
I'm digging into this more. I'll check back when I have a better understanding.
Quoted 10 lines
Quoted 4 lines
As an aside, if you could give this a quick check, I can send the revised patch. Appreciate the feedback.
https://github.com/benmcollins/linux/commit/2f2946b33294ebff2fdaae6d1eadc976147470d6
This looks correct to me, but I would change two things:
- remove the debug message, which you probably left by accident
- instead of the explicitof_device_is_compatible(), change it to use the .data field of theof_device_idtable instead.
Will do.
Signature · 5 lines
Ben Collins https://libjwt.io https://github.com/benmcollins -- 3EC9 7598 1672 961A 1139 173A 5D5A 57C7 242B 22CF
Quoted 11 lines · Ben Collins
Quoted 3 lines · Arnd Bergmann
Looking at the current code I don't see that any more, so it's possible that now any DMA is allowed even if there is no dma-ranges property at all.
It's still there. It hardcodes
zone_dma_limitto 31-bits:
arch/powerpc/mm/mem.c:paging_init()I'm digging into this more. I'll check back when I have a better understanding.
zone_dma_limit is the other side of this: you need a ZONE_DMA and/or ZONE_DMA32 memory zone that lets a driver allocate buffers from low addresses if the DMA mask is smaller than the available memory.
Arnd