mfd: mfd-core: inherit only valid dma_masks/flags from parent
RFC PATCH 1/1 mfd: mfd-core: inherit only valid dma_masks/flags from parent
Only copy the dma_masks and flags from the parent device, if the parent has a valid dma_mask/flags. Commit cdfee5623290 ("driver core:
initialize a default DMA mask for platform device") initialize the DMA masks of a platform device. But if the parent doesn't have a dma_mask set, for example if it's an I2C device, the dma_mask of the child platform device will be set to zero again. Which leads to many "DMA mask not set" warnings, if the MFD cell has the of_compatible property set.
[ 1.877937] sl28cpld-pwm sl28cpld-pwm: DMA mask not set [ 1.883282] sl28cpld-pwm sl28cpld-pwm.0: DMA mask not set [ 1.888795] sl28cpld-gpio sl28cpld-gpio: DMA mask not set
Thus a MFD child should just inherit valid dma_masks and keep the platform default otherwise.
---
Hi,
I don't know if that is the correct way of handling things. Maybe I'm also doing something wrong in my driver, I had a look at other I2C MFD drivers but couldn't find a clue why they shouldn't have the same problem.
There was also a thread [1] about this topic, but there seems to be no conclusion.
[1] https://www.spinics.net/lists/linux-renesas-soc/msg31581.html
drivers/mfd/mfd-core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/mfd/mfd-core.c +6 -3
@@ -139,9 +139,12 @@ static int mfd_add_device(struct device *parent, int id, pdev->dev.parent = parent; pdev->dev.type = &mfd_dev_type; - pdev->dev.dma_mask = parent->dma_mask; - pdev->dev.dma_parms = parent->dma_parms; - pdev->dev.coherent_dma_mask = parent->coherent_dma_mask; +if (parent->dma_mask) + pdev->dev.dma_mask = parent->dma_mask; +if (parent->dma_parms) + pdev->dev.dma_parms = parent->dma_parms; +if (parent->coherent_dma_mask) + pdev->dev.coherent_dma_mask = parent->coherent_dma_mask; ret = regulator_bulk_register_supply_alias( &pdev->dev, cell->parent_supplies,
Signature · 1 line
2.20.1
Quoted 42 lines · Michael Walle
Only copy the
dma_masksand flags from the parent device, if the parent has a valid dma_mask/flags. Commitcdfee5623290("driver core:
initialize a default DMA mask for platform device") initialize the DMA masks of a platform device. But if the parent doesn't have adma_maskset, for example if it's an I2C device, thedma_maskof the child platform device will be set to zero again. Which leads to many "DMA mask not set" warnings, if the MFD cell has theof_compatibleproperty set.[ 1.877937] sl28cpld-pwm sl28cpld-pwm: DMA mask not set [ 1.883282] sl28cpld-pwm sl28cpld-pwm.0: DMA mask not set [ 1.888795] sl28cpld-gpio sl28cpld-gpio: DMA mask not setThus a MFD child should just inherit valid
dma_masksand keep the platform default otherwise.Cc Christoph Hellwig <[email protected]>Cc Rob Herring <[email protected]>Cc Robin Murphy <[email protected]>Cc Russell King <[email protected]>Signed-off-by Michael Walle <[email protected]>---
Hi,
I don't know if that is the correct way of handling things. Maybe I'm also doing something wrong in my driver, I had a look at other I2C MFD drivers but couldn't find a clue why they shouldn't have the same problem.
There was also a thread [1] about this topic, but there seems to be no conclusion.
[1] https://www.spinics.net/lists/linux-renesas-soc/msg31581.html
drivers/mfd/mfd-core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/mfd/mfd-core.c +0
-0
drivers/mfd/mfd-core.c static int mfd_add_device(struct device *parent, int id, · line 145
Quoted 10 lines
drivers/mfd/mfd-core.c +4
-3@@ -139,9 +139,12 @@ static int mfd_add_device(struct device *parent, int id, pdev->dev.parent = parent; pdev->dev.type = &mfd_dev_type; - pdev->dev.dma_mask = parent->dma_mask; - pdev->dev.dma_parms = parent->dma_parms; - pdev->dev.coherent_dma_mask = parent->coherent_dma_mask; +if (parent->dma_mask) + pdev->dev.dma_mask = parent->dma_mask; +if (parent->dma_parms) + pdev->dev.dma_parms = parent->dma_parms;
Both of these are pointers, and we can't just share them. You need to allocate storage for them and the allocate the values over.
Am 2020-03-11 07:18, schrieb Christoph Hellwig:
Quoted 45 lines · Michael Walle
Quoted 44 lines
Only copy the
dma_masksand flags from the parent device, if the parent has a valid dma_mask/flags. Commitcdfee5623290("driver core:
initialize a default DMA mask for platform device") initialize the DMA masks of a platform device. But if the parent doesn't have adma_maskset, for example if it's an I2C device, thedma_maskof the child platform device will be set to zero again. Which leads to many "DMA mask not set" warnings, if the MFD cell has theof_compatibleproperty set.[ 1.877937] sl28cpld-pwm sl28cpld-pwm: DMA mask not set [ 1.883282] sl28cpld-pwm sl28cpld-pwm.0: DMA mask not set [ 1.888795] sl28cpld-gpio sl28cpld-gpio: DMA mask not setThus a MFD child should just inherit valid
dma_masksand keep the platform default otherwise.Cc Christoph Hellwig <[email protected]>Cc Rob Herring <[email protected]>Cc Robin Murphy <[email protected]>Cc Russell King <[email protected]>Signed-off-by Michael Walle <[email protected]>---
Hi,
I don't know if that is the correct way of handling things. Maybe I'm also doing something wrong in my driver, I had a look at other I2C MFD drivers but couldn't find a clue why they shouldn't have the same problem.
There was also a thread [1] about this topic, but there seems to be no conclusion.
[1] https://www.spinics.net/lists/linux-renesas-soc/msg31581.html
drivers/mfd/mfd-core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/mfd/mfd-core.c +0
-0@@ -139,9 +139,12 @@ static int mfd_add_device(struct device *parent, int id,
Quoted 12 lines
drivers/mfd/mfd-core.c static int mfd_add_device(struct device *parent, int id, · line 145
Quoted 9 lines
drivers/mfd/mfd-core.c +4
-3pdev->dev.parent = parent; pdev->dev.type = &mfd_dev_type; - pdev->dev.dma_mask = parent->dma_mask; - pdev->dev.dma_parms = parent->dma_parms; - pdev->dev.coherent_dma_mask = parent->coherent_dma_mask; +if (parent->dma_mask) + pdev->dev.dma_mask = parent->dma_mask; +if (parent->dma_parms) + pdev->dev.dma_parms = parent->dma_parms;Both of these are pointers, and we can't just share them. You need to allocate storage for them and the allocate the values over.
So they were alreay copied wrong before this patch? If so, should there be a fixes patch for it? The commit who introduced the copy dates back to 2013:
b018e1361bad3 mfd: core: Copy DMA mask and params from parent
-michael
Quoted 20 lines · Michael Walle
Only copy the
dma_masksand flags from the parent device, if the parent has a valid dma_mask/flags. Commitcdfee5623290("driver core:
initialize a default DMA mask for platform device") initialize the DMA masks of a platform device. But if the parent doesn't have adma_maskset, for example if it's an I2C device, thedma_maskof the child platform device will be set to zero again. Which leads to many "DMA mask not set" warnings, if the MFD cell has theof_compatibleproperty set.[ 1.877937] sl28cpld-pwm sl28cpld-pwm: DMA mask not set [ 1.883282] sl28cpld-pwm sl28cpld-pwm.0: DMA mask not set [ 1.888795] sl28cpld-gpio sl28cpld-gpio: DMA mask not setThus a MFD child should just inherit valid
dma_masksand keep the platform default otherwise.Cc Christoph Hellwig <[email protected]>Cc Rob Herring <[email protected]>Cc Robin Murphy <[email protected]>Cc Russell King <[email protected]>Signed-off-by Michael Walle <[email protected]>
Quoted 8 lines
---
Hi,
I don't know if that is the correct way of handling things. Maybe I'm also doing something wrong in my driver, I had a look at other I2C MFD drivers but couldn't find a clue why they shouldn't have the same problem.
The underlying issue is that about 99% of MFD children should not be going through dma_configure() at all because their parent 'real' device is not on a DMA-capable bus, but as they are platform devices we are forced to give them the benefit of the doubt. For DT systems the only vaguely-reasonable heuristic to distinguish between "platform" meaning "SoC memory-mapped device" and "platform" meaning "random crap made up by Linux" is whether the device has a populated OF node, but MFD's trick of hanging the parent device's OF node onto its synthesised children kicks a hole right through even that.
Modulo any other concerns with the existing code, does the change below make things work the way you want? It's still a bit of a bodge, but short of invasive large-scale changes with bus types I don't see a way to do the 'right' thing :/
Robin.
----->8-----
drivers/mfd/mfd-core.c +1 -1
@@ -138,7 +138,7 @@ static int mfd_add_device(struct device *parent, int id, pdev->dev.parent = parent; pdev->dev.type = &mfd_dev_type; - pdev->dev.dma_mask = parent->dma_mask; + pdev->dma_mask = parent->dma_mask ? *parent->dma_mask :0 ; pdev->dev.dma_parms = parent->dma_parms; pdev->dev.coherent_dma_mask = parent->coherent_dma_mask;
Am 2020-03-11 12:25, schrieb Robin Murphy:
Quoted 30 lines · Michael Walle
Quoted 20 lines
Only copy the
dma_masksand flags from the parent device, if the parent has a valid dma_mask/flags. Commitcdfee5623290("driver core:
initialize a default DMA mask for platform device") initialize the DMA masks of a platform device. But if the parent doesn't have adma_maskset, for example if it's an I2C device, thedma_maskof the child platform device will be set to zero again. Which leads to many "DMA mask not set" warnings, if the MFD cell has theof_compatibleproperty set.[ 1.877937] sl28cpld-pwm sl28cpld-pwm: DMA mask not set [ 1.883282] sl28cpld-pwm sl28cpld-pwm.0: DMA mask not set [ 1.888795] sl28cpld-gpio sl28cpld-gpio: DMA mask not setThus a MFD child should just inherit valid
dma_masksand keep the platform default otherwise.Cc Christoph Hellwig <[email protected]>Cc Rob Herring <[email protected]>Cc Robin Murphy <[email protected]>Cc Russell King <[email protected]>Signed-off-by Michael Walle <[email protected]>Quoted 8 lines
---
Hi,
I don't know if that is the correct way of handling things. Maybe I'm also doing something wrong in my driver, I had a look at other I2C MFD drivers but couldn't find a clue why they shouldn't have the same problem.
Quoted 9 lines
The underlying issue is that about 99% of MFD children should not be going through
dma_configure()at all because their parent 'real' device is not on a DMA-capable bus, but as they are platform devices we are forced to give them the benefit of the doubt. For DT systems the only vaguely-reasonable heuristic to distinguish between "platform" meaning "SoC memory-mapped device" and "platform" meaning "random crap made up by Linux" is whether the device has a populated OF node, but MFD's trick of hanging the parent device's OF node onto its synthesised children kicks a hole right through even that.
Thanks for the explanation.
Quoted 13 lines
Modulo any other concerns with the existing code, does the change below make things work the way you want? It's still a bit of a bodge, but short of invasive large-scale changes with bus types I don't see a way to do the 'right' thing :/
Robin.
----->8-----
drivers/mfd/mfd-core.c +0
-0
drivers/mfd/mfd-core.c static int mfd_add_device(struct device *parent, · line 142
Quoted 6 lines
drivers/mfd/mfd-core.c +1
-1@@ -138,7 +138,7 @@ static int mfd_add_device(struct device *parent,int id, pdev->dev.parent = parent; pdev->dev.type = &mfd_dev_type; - pdev->dev.dma_mask = parent->dma_mask; + pdev->dma_mask = parent->dma_mask ? *parent->dma_mask :0 ;
That works.
-michael
Quoted 2 lines
drivers/mfd/mfd-core.c +0
-0pdev->dev.dma_parms = parent->dma_parms; pdev->dev.coherent_dma_mask = parent->coherent_dma_mask;