ahci_platform: Provide for vendor specific init
Subsystems (2)
PATCH 1/1 ahci_platform: Provide for vendor specific init
From: Jassi Brar <[email protected]>
Some AHCI implementations may use Vendor Specific HBA[A0h, FFh] and/or Port[70h, 7Fh] registers to 'prepare' for initialization. For that, the platform needs memory mapped address of AHCI registers.
This patch adds the 'mmio' argument and reorders the call to platform init function.
--- drivers/ata/ahci_platform.c | 23 +++++++++++++---------- include/linux/ahci_platform.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-)
drivers/ata/ahci_platform.c +13 -10
@@ -54,19 +54,13 @@ static int __init ahci_probe(struct platform_device *pdev)return -EINVAL ; } -if (pdata && pdata->init) { - rc = pdata->init (dev); -if (rc) -return rc; - } -if (pdata && pdata->ata_port_info) pi = *pdata->ata_port_info; hpriv =devm_kzalloc (dev,sizeof (*hpriv),GFP_KERNEL );if (!hpriv) { - rc = -ENOMEM ; - goto err0; +dev_err (dev,"can't alloc ahci_host_priv\n" ); +return -ENOMEM ; } hpriv->flags |= (unsigned long )pi.private_data;
@@ -74,8 +68,17 @@ static int __init ahci_probe(struct platform_device *pdev) hpriv->mmio =devm_ioremap (dev, mem->start,resource_size (mem));if (!hpriv->mmio) {dev_err (dev,"can't map %pR\n" , mem); - rc = -ENOMEM ; - goto err0; +devm_kfree (dev, hpriv); +return -ENOMEM ; + } + +if (pdata && pdata->init) { + rc = pdata->init (dev, hpriv->mmio); +if (rc) { +devm_iounmap (dev, hpriv->mmio); +devm_kfree (dev, hpriv); +return rc; + } } ahci_save_initial_config(dev, hpriv,
include/linux/ahci_platform.h +1 -1
@@ -19,7 +19,7 @@ struct device;struct ata_port_info ;struct ahci_platform_data { -int (*init)(struct device *dev); +int (*init)(struct device *dev,void __iomem *addr);void (*exit)(struct device *dev);const struct ata_port_info *ata_port_info;unsigned int force_port_map;
Signature · 1 line
1.6.2.5
Quoted 6 lines · Jassi Brar
From: Jassi Brar<[email protected]>
Some AHCI implementations may use Vendor Specific HBA[A0h, FFh] and/or Port[70h, 7Fh] registers to 'prepare' for initialization. For that, the platform needs memory mapped address of AHCI registers.
Quoted 8 lines
This patch adds the 'mmio' argument and reorders the call to platform init function.
Signed-off-by Jassi Brar<[email protected]>--- drivers/ata/ahci_platform.c | 23 +++++++++++++---------- include/linux/ahci_platform.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-)
It is also possible that platforms may need the init to prep the MMIO area for use? Anton, does this patch work for you, or introduce such a problem?
Thanks,
Jeff
Quoted 11 lines · Jeff Garzik
Quoted 10 lines · Jassi Brar
From: Jassi Brar<[email protected]>
Some AHCI implementations may use Vendor Specific HBA[A0h, FFh] and/or Port[70h, 7Fh] registers to 'prepare' for initialization. For that, the platform needs memory mapped address of AHCI registers.
This patch adds the 'mmio' argument and reorders the call to platform init function.
Quoted 8 lines
Quoted 5 lines
Signed-off-by Jassi Brar<[email protected]>---
drivers/ata/ahci_platform.c | 23 +++++++++++++----------include/linux/ahci_platform.h| 2 +-2 files changed, 14 insertions(+), 11 deletions(-)It is also possible that platforms may need the init to prep the MMIO area for use? Anton, does this patch work for you, or introduce such a problem?
IMO platforms that need such prep(setup iommu ?) have the option to do it in earlier machine init code, but platforms that need to access vendor specific regs
have no way other than to duplicate ioremap.
Btw, I see no impact on CNS3XXX.
Thanks.
Quoted 16 lines · Jeff Garzik
Quoted 6 lines · Jassi Brar
From: Jassi Brar<[email protected]>
Some AHCI implementations may use Vendor Specific HBA[A0h, FFh] and/or Port[70h, 7Fh] registers to 'prepare' for initialization. For that, the platform needs memory mapped address of AHCI registers.
Quoted 8 lines
This patch adds the 'mmio' argument and reorders the call to platform init function.
Signed-off-by Jassi Brar<[email protected]>--- drivers/ata/ahci_platform.c | 23 +++++++++++++---------- include/linux/ahci_platform.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-)
Quoted 3 lines
It is also possible that platforms may need the init to prep the MMIO area for use? Anton, does this patch work for you, or introduce such a problem?
Currently it doesn't introduce such a problem, but you're right, platforms might need to, for example, turn on the clocks before the MMIO area becomes accessible (otherwise machine check exception might arrive).
There are two options: introduce a ->post_init() hook, or just make sure that ahci_platform driver won't start accessing the mmio region between ioremap() and pdata->init() calls. I think a simple comment in the code will suffice, so no need for the additional hook.
And if we ever need some hook before ioremap(), we can name it pre_init().
Thanks,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 10 lines · Jassi Brar
From: Jassi Brar <[email protected]>
Some AHCI implementations may use Vendor Specific HBA[A0h, FFh] and/or Port[70h, 7Fh] registers to 'prepare' for initialization. For that, the platform needs memory mapped address of AHCI registers.
This patch adds the 'mmio' argument and reorders the call to platform init function.
Signed-off-by Jassi Brar <[email protected]>
Thanks for the patch. Looks good, but see some comments below. (Plus some comments on Jeff's reply)
Quoted 9 lines
--- drivers/ata/ahci_platform.c | 23 +++++++++++++---------- include/linux/ahci_platform.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-)drivers/ata/ahci_platform.c +0
-0
[...]
drivers/ata/ahci_platform.c static int __init ahci_probe(struct platform_device *pdev) · line 71
Quoted 7 lines
drivers/ata/ahci_platform.c +1
-2@@ -74,8 +68,17 @@ static int __init ahci_probe(struct platform_device *pdev) hpriv->mmio =devm_ioremap (dev, mem->start,resource_size (mem));if (!hpriv->mmio) {dev_err (dev,"can't map %pR\n" , mem); - rc = -ENOMEM ; - goto err0; +devm_kfree (dev, hpriv);
You don't need to explicitly free devm_* resources.
drivers/ata/ahci_platform.c static int __init ahci_probe(struct platform_device *pdev) · line 79
Quoted 8 lines
drivers/ata/ahci_platform.c +8
-0+return -ENOMEM ; + } + +if (pdata && pdata->init) { + rc = pdata->init (dev, hpriv->mmio); +if (rc) { +devm_iounmap (dev, hpriv->mmio); +devm_kfree (dev, hpriv);
Ditto, no need for iounmap and kfree.
Quoted 10 lines
drivers/ata/ahci_platform.c +2
-0+return rc; + } } ahci_save_initial_config(dev, hpriv,include/linux/ahci_platform.h +0
-0
include/linux/ahci_platform.h struct device; · line 22
Quoted 5 lines
include/linux/ahci_platform.h +1
-1@@ -19,7 +19,7 @@ struct device;struct ata_port_info ;struct ahci_platform_data { -int (*init)(struct device *dev); +int (*init)(struct device *dev,void __iomem *addr);
Please include linux/compiler.h for __iomem.
include/linux/ahci_platform.h struct device; · line 25
Quoted 3 lines
include/linux/ahci_platform.h +0
-0void (*exit)(struct device *dev);const struct ata_port_info *ata_port_info;unsigned int force_port_map;
Thanks!
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 7 lines · Anton Vorontsov
Quoted 6 lines · Jassi Brar
From: Jassi Brar <[email protected]>
Some AHCI implementations may use Vendor Specific HBA[A0h, FFh] and/or Port[70h, 7Fh] registers to 'prepare' for initialization. For that, the platform needs memory mapped address of AHCI registers.
Quoted 7 lines
Quoted 4 lines
This patch adds the 'mmio' argument and reorders the call to platform init function.
Signed-off-by Jassi Brar <[email protected]>Thanks for the patch. Looks good, but see some comments below. (Plus some comments on Jeff's reply)
Ok, will resend. Thanks.