From: Bjorn Helgaas <bhelgaas@google.com>
To: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Cc: jingoohan1@gmail.com, pratyush.anand@gmail.com,
linux-pci@vger.kernel.org, wangzhou1@hisilicon.com,
yuanzhichang@hisilicon.com, zhudacai@hisilicon.com,
zhangjukuo@huawei.com, qiuzhenfa@hisilicon.com,
liguozhu@hisilicon.com
Subject: Re: [PATCH v3 2/3] PCI: designware: change dw_pcie_cfg_write() and dw_pcie_cfg_read()
Date: Fri, 18 Sep 2015 15:53:01 -0500 [thread overview]
Message-ID: <20150918205301.GM25767@google.com> (raw)
In-Reply-To: <1441964307-126942-3-git-send-email-gabriele.paoloni@huawei.com>
On Fri, Sep 11, 2015 at 05:38:26PM +0800, Gabriele Paoloni wrote:
> From: gabriele paoloni <gabriele.paoloni@huawei.com>
>
> This patch changes the implementation of dw_pcie_cfg_read() and
> dw_pcie_cfg_write() to improve the function usage from the callers
> perspective.
> Currently the callers are obliged to pass the 32bit aligned address
> of the register that contains the field of the PCI header that they
> want to read/write; also they have to pass the offset of the field
> in that register. This is quite tricky to use as the callers are
> obliged to sum the PCI header base address to the field offset
> masked to retrieve the 32b aligned register address.
>
> With the new API the callers have to pass the base address of the
> PCI header and the offset corresponding to the field they intend to
> read/write.
>
> Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
> ---
> drivers/pci/host/pci-exynos.c | 5 ++---
> drivers/pci/host/pci-keystone-dw.c | 4 ++--
> drivers/pci/host/pcie-designware.c | 28 ++++++++++++++--------------
> drivers/pci/host/pcie-spear13xx.c | 26 ++++++++++++--------------
> 4 files changed, 30 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/pci/host/pci-exynos.c b/drivers/pci/host/pci-exynos.c
> index f9f468d..8b0e04b 100644
> --- a/drivers/pci/host/pci-exynos.c
> +++ b/drivers/pci/host/pci-exynos.c
> @@ -454,7 +454,7 @@ static int exynos_pcie_rd_own_conf(struct pcie_port *pp, int where, int size,
> int ret;
>
> exynos_pcie_sideband_dbi_r_mode(pp, true);
> - ret = dw_pcie_cfg_read(pp->dbi_base + (where & ~0x3), where, size, val);
> + ret = dw_pcie_cfg_read(pp->dbi_base, where, size, val);
> exynos_pcie_sideband_dbi_r_mode(pp, false);
> return ret;
> }
Is there really any value in keeping "addr" and "where" separate?
dw_pcie_cfg_write() clearly doesn't care; it just adds them together. I
don't think dw_pcie_cfg_read() needs to care either: it could round the
address down to a 32-bit boundary and use the difference to compute the
mask and shift.
So I'm proposing something like this:
int dw_pcie_cfg_read(void __iomem *addr, int size, u32 *val)
int dw_pcie_cfg_write(void __iomem *addr, int size, u32 val)
> int dw_pcie_cfg_read(void __iomem *addr, int where, int size, u32 *val)
> {
> + addr += (where & ~0x3);
> *val = readl(addr);
> + where &= 3;
>
> if (size == 1)
> - *val = (*val >> (8 * (where & 3))) & 0xff;
> + *val = (*val >> (8 * where)) & 0xff;
> else if (size == 2)
> - *val = (*val >> (8 * (where & 3))) & 0xffff;
> + *val = (*val >> (8 * where)) & 0xffff;
> else if (size != 4)
> return PCIBIOS_BAD_REGISTER_NUMBER;
>
> @@ -96,12 +98,14 @@ int dw_pcie_cfg_read(void __iomem *addr, int where, int size, u32 *val)
>
> int dw_pcie_cfg_write(void __iomem *addr, int where, int size, u32 val)
> {
> + addr += where;
> +
> if (size == 4)
> writel(val, addr);
> else if (size == 2)
> - writew(val, addr + (where & 2));
> + writew(val, addr);
> else if (size == 1)
> - writeb(val, addr + (where & 3));
> + writeb(val, addr);
> else
> return PCIBIOS_BAD_REGISTER_NUMBER;
next prev parent reply other threads:[~2015-09-18 20:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-11 9:38 [PATCH v3 0/3] PCI: designware: change dw_pcie_cfg_write() and dw_pcie_cfg_read() Gabriele Paoloni
2015-09-11 9:38 ` [PATCH v3 1/3] PCIe: SPEAr13xx: fix dw_pcie_cfg_read/write() usage Gabriele Paoloni
2015-09-11 9:38 ` [PATCH v3 2/3] PCI: designware: change dw_pcie_cfg_write() and dw_pcie_cfg_read() Gabriele Paoloni
2015-09-18 20:46 ` Bjorn Helgaas
2015-09-19 3:03 ` Pratyush Anand
2015-09-23 16:20 ` Gabriele Paoloni
2015-09-23 16:24 ` Bjorn Helgaas
2015-09-23 16:26 ` Gabriele Paoloni
2015-09-18 20:53 ` Bjorn Helgaas [this message]
2015-09-19 3:11 ` Pratyush Anand
2015-09-23 16:26 ` Gabriele Paoloni
2015-09-11 9:38 ` [PATCH v3 3/3] PCI: designware: add sanity checks on the header offset in dw_pcie_cfg_read and dw_pcie_cfg_write Gabriele Paoloni
2015-09-15 9:28 ` [PATCH v3 0/3] PCI: designware: change dw_pcie_cfg_write() and dw_pcie_cfg_read() Gabriele Paoloni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150918205301.GM25767@google.com \
--to=bhelgaas@google.com \
--cc=gabriele.paoloni@huawei.com \
--cc=jingoohan1@gmail.com \
--cc=liguozhu@hisilicon.com \
--cc=linux-pci@vger.kernel.org \
--cc=pratyush.anand@gmail.com \
--cc=qiuzhenfa@hisilicon.com \
--cc=wangzhou1@hisilicon.com \
--cc=yuanzhichang@hisilicon.com \
--cc=zhangjukuo@huawei.com \
--cc=zhudacai@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).