2022-05-12 08:08:33

by Serge Semin

[permalink] [raw]
Subject: [PATCH v3 06/23] ata: libahci_platform: Convert to using platform devm-ioremap methods

Currently the IOMEM AHCI registers space is mapped by means of the
two functions invocation: platform_get_resource() is used to get the very
first memory resource and devm_ioremap_resource() is called to remap that
resource. Device-managed kernel API provides a handy wrapper to perform
the same in single function call: devm_platform_ioremap_resource().

While at it seeing many AHCI platform drivers rely on having the AHCI CSR
space marked with "ahci" name let's first try to find and remap the CSR
IO-mem with that name and only if it fails fallback to getting the very
first registers space platform resource.

Signed-off-by: Serge Semin <[email protected]>

---

Changelog v2:
- Check whether there is "ahhi" reg resource before using the
devm_platform_ioremap_resource_byname() method in order to prevent a
false error message printed in the log (@Damien)
- Slightly update the patch title due to the change above and to be more
specific that the platform device managed methods are utilized.
---
drivers/ata/libahci_platform.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c
index f7f9bfcfc164..8c9fbcc3043b 100644
--- a/drivers/ata/libahci_platform.c
+++ b/drivers/ata/libahci_platform.c
@@ -404,8 +404,14 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,

devres_add(dev, hpriv);

- hpriv->mmio = devm_ioremap_resource(dev,
- platform_get_resource(pdev, IORESOURCE_MEM, 0));
+ /*
+ * If the DT provided an "ahci" named resource, use it. Otherwise,
+ * fallback to using the default first resource for the device node.
+ */
+ if (platform_get_resource_byname(pdev, IORESOURCE_MEM, "ahci"))
+ hpriv->mmio = devm_platform_ioremap_resource_byname(pdev, "ahci");
+ else
+ hpriv->mmio = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(hpriv->mmio)) {
rc = PTR_ERR(hpriv->mmio);
goto err_out;
--
2.35.1



2022-05-14 03:36:26

by Hannes Reinecke

[permalink] [raw]
Subject: Re: [PATCH v3 06/23] ata: libahci_platform: Convert to using platform devm-ioremap methods

On 5/12/22 01:17, Serge Semin wrote:
> Currently the IOMEM AHCI registers space is mapped by means of the
> two functions invocation: platform_get_resource() is used to get the very
> first memory resource and devm_ioremap_resource() is called to remap that
> resource. Device-managed kernel API provides a handy wrapper to perform
> the same in single function call: devm_platform_ioremap_resource().
>
> While at it seeing many AHCI platform drivers rely on having the AHCI CSR
> space marked with "ahci" name let's first try to find and remap the CSR
> IO-mem with that name and only if it fails fallback to getting the very
> first registers space platform resource.
>
> Signed-off-by: Serge Semin <[email protected]>
>
> ---
>
> Changelog v2:
> - Check whether there is "ahhi" reg resource before using the
> devm_platform_ioremap_resource_byname() method in order to prevent a
> false error message printed in the log (@Damien)
> - Slightly update the patch title due to the change above and to be more
> specific that the platform device managed methods are utilized.
> ---
> drivers/ata/libahci_platform.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c
> index f7f9bfcfc164..8c9fbcc3043b 100644
> --- a/drivers/ata/libahci_platform.c
> +++ b/drivers/ata/libahci_platform.c
> @@ -404,8 +404,14 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
>
> devres_add(dev, hpriv);
>
> - hpriv->mmio = devm_ioremap_resource(dev,
> - platform_get_resource(pdev, IORESOURCE_MEM, 0));
> + /*
> + * If the DT provided an "ahci" named resource, use it. Otherwise,
> + * fallback to using the default first resource for the device node.
> + */
> + if (platform_get_resource_byname(pdev, IORESOURCE_MEM, "ahci"))
> + hpriv->mmio = devm_platform_ioremap_resource_byname(pdev, "ahci");
> + else
> + hpriv->mmio = devm_platform_ioremap_resource(pdev, 0);
> if (IS_ERR(hpriv->mmio)) {
> rc = PTR_ERR(hpriv->mmio);
> goto err_out;

Reviewed-by: Hannes Reinecke <[email protected]>

Cheers,

Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
[email protected] +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer