From: arnd@arndb.de (Arnd Bergmann)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH V6 02/17] ST SPEAr13xx: Added PCIe host controller base driver support.
Date: Tue, 1 Mar 2011 16:10:23 +0100 [thread overview]
Message-ID: <201103011610.24283.arnd@arndb.de> (raw)
In-Reply-To: <30b834e959889fb20404f45e7e66de78155874c2.1298977728.git.viresh.kumar@st.com>
On Tuesday 01 March 2011, Viresh Kumar wrote:
> From: Pratyush Anand <pratyush.anand@st.com>
Hi Viresh and Pratyush,
The code looks really nice, I have just a few comments, mostly
about pointer type conversion.
> SPEAr13xx family contains Synopsys designware PCIe version 3.30a. This
> patch adds support for this PCIe module for spear platform.
If this is a standard PCIe controller, why add it to the platform
code instead of a common place like arch/arch/common or arch/arm/kernel ?
> diff --git a/arch/arm/mach-spear13xx/include/mach/hardware.h b/arch/arm/mach-spear13xx/include/mach/hardware.h
> index fd8c2dc..c3fb454 100644
> --- a/arch/arm/mach-spear13xx/include/mach/hardware.h
> +++ b/arch/arm/mach-spear13xx/include/mach/hardware.h
> @@ -28,4 +28,11 @@
> /* typesafe io address */
> #define __io_address(n) __io(IO_ADDRESS(n))
I could not find the definition for __io() here, but I suspect this is
wrong. If __io_address() is what you use for accessing the direct-mapped
MMIO registers, it cannot also be what you use to access the PCIe PIO
ports, so most likely one of the two is broken. Can you explain?
> +#if defined(CONFIG_PCI)
> +#define PCIBIOS_MIN_IO 0
> +#define PCIBIOS_MIN_MEM 0
> +#define pcibios_assign_all_busses() 0
> +#endif
> +
No need for the #ifdef here, if you have no PCI, there won't be a conflict.
Better make PCIBIOS_MIN_IO 0x1000, in order to avoid stepping over
ISA port ranges.
> +static u32 spr_pcie_base[NUM_PCIE_PORTS] = {
> + SPEAR13XX_PCIE0_BASE,
> + SPEAR13XX_PCIE1_BASE,
> + SPEAR13XX_PCIE2_BASE,
> +};
> +static u32 spr_pcie_app_base[NUM_PCIE_PORTS] = {
> + SPEAR13XX_PCIE0_APP_BASE,
> + SPEAR13XX_PCIE1_APP_BASE,
> + SPEAR13XX_PCIE2_APP_BASE,
> +};
I think these should be __iomem pointers, not u32 tokens, since you
are listing virtual addresses. If you unroll the loop in
spear13xx_pcie_init() that uses these, you can actually get rid
of the two arrays, and simplify the code used there at the
same time.
> +#ifdef CONFIG_PCI_MSI
> +static DECLARE_BITMAP(msi_irq_in_use[NUM_PCIE_PORTS], SPEAR_NUM_MSI_IRQS);
> +static unsigned int spear_msi_data[NUM_PCIE_PORTS];
> +
> +static void spear13xx_msi_init(struct pcie_port *pp);
> +#endif
> +
> +static void spear_pcie_int_handler(unsigned int irq, struct irq_desc *desc);
It would be nice if you could avoid the forward declarations by reordering
the functions if possible.
> +static int __init spear13xx_pcie_setup(int nr, struct pci_sys_data *sys)
> +{
> + struct pcie_port *pp;
> + u32 val = 0;
> +
> + if (nr >= NUM_PCIE_PORTS)
> + return 0;
> +
> + if ((*pcie_port_is_host)(nr) != 1)
> + return 0;
> +
> + pp = &pcie_port[nr];
> + if (!spear13xx_pcie_link_up((void __iomem *)pp->va_app_base))
> + return 0;
No need for the cast, va_app_base is already (void __iomem *).
> +static void __init add_pcie_port(int port, u32 base, u32 app_base)
> +{
> + struct pcie_port *pp = &pcie_port[port];
> + struct pcie_app_reg *app_reg;
> +
> + pp->port = port;
> + pp->root_bus_nr = -1;
> + pp->base = (void __iomem *)base;
> + pp->app_base = (void __iomem *)app_base;
> + pp->va_app_base = (void __iomem *) ioremap(app_base, 0x200);
> + if (!pp->va_app_base) {
> + pr_err("error with ioremap in function %s\n", __func__);
> + return;
> + }
> + pp->va_dbi_base = (void __iomem *) ioremap(base, 0x2000);
> + if (!pp->va_dbi_base) {
> + pr_err("error with ioremap in function %s\n", __func__);
> + return;
> + }
Please remove all these casts. Some are unneeded, some can go away
after the things I mention above.
> + spin_lock_init(&pp->conf_lock);
> + memset(pp->res, 0, sizeof(pp->res));
> + pr_info("spear13xx PCIe port %d\n", port);
> + if (spear13xx_pcie_link_up((void __iomem *)pp->va_app_base)) {
> + pr_info("link up in bios\n");
> + } else {
> + pr_info("link down in bios\n");
> + spear13xx_pcie_host_init(pp);
> + spear13xx_int_init(pp);
> + app_reg = (struct pcie_app_reg *)pp->va_app_base;
This cast looks invalid, you cast from __iomem to a regular pointer,
> + pp->va_cfg0_base = (void __iomem *)
> + ioremap(app_reg->in_cfg0_addr_start, IN_CFG0_SIZE);
which breaks here when you pass the value to ioremap without doing a readl.
> +#ifdef CONFIG_PCI_MSI
> +/* MSI int handler
> + */
> +static void handle_msi(struct pcie_port *pp)
> +{
> + unsigned long val;
> + int i, pos;
> +
> + for (i = 0; i < 8; i++) {
> + spear_dbi_read_reg(pp, PCIE_MSI_INTR0_STATUS + i * 12, 4,
> + (u32 *)&val);
> + if (val) {
> + pos = 0;
> + while ((pos = find_next_bit(&val, 32, pos)) != 32) {
> + generic_handle_irq(SPEAR_MSI0_INT_BASE
> + + pp->port * SPEAR_NUM_MSI_IRQS
> + + (i * 32) + pos);
> + pos++;
> + }
> + }
> + spear_dbi_write_reg(pp, PCIE_MSI_INTR0_STATUS + i * 12, 4, val);
> + }
> +}
> +#else
> +static void handle_msi(struct pcie_port *pp)
> +{
> +}
> +#endif
The MSI code is not big, but I'd still recommend moving it to a separate
file, which gets compiled only when CONFIG_PCI_MSI is set. You can have
the #ifdef and inline NOP alternative in a header for this.
Arnd
next prev parent reply other threads:[~2011-03-01 15:10 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-01 11:27 [PATCH V6 00/17] Adding devices support for all spear machines Viresh Kumar
2011-03-01 11:27 ` [PATCH V6 01/17] ST SPEAr13xx: Added ARM PL061 GPIO Support Viresh Kumar
2011-03-01 11:27 ` [PATCH V6 02/17] ST SPEAr13xx: Added PCIe host controller base driver support Viresh Kumar
2011-03-01 15:10 ` Arnd Bergmann [this message]
2011-03-10 12:45 ` shiraz hashim
2011-03-10 14:38 ` Arnd Bergmann
2011-03-10 12:56 ` pratyush
2011-03-01 11:27 ` [PATCH V6 03/17] ST SPEAr: Adding PLGPIO driver for spear platform Viresh Kumar
2011-03-01 11:27 ` [PATCH V6 04/17] ST SPEAr3xx: Adding support for ST's PWM IP Viresh Kumar
2011-03-01 11:27 ` [PATCH V6 05/17] ST SPEAr: Adding Watchdog support on spear3xx & spear6xx machines Viresh Kumar
2011-03-01 11:27 ` [PATCH V6 06/17] ST SPEAr3xx: Adding RAS uart devices Viresh Kumar
2011-03-01 11:27 ` [PATCH V6 07/17] ST SPEAr320: Adding support for CAN Viresh Kumar
2011-03-01 11:27 ` [PATCH V6 08/17] ST SPEAr3xx: EMI (External Memory Interface) controller driver Viresh Kumar
2011-03-01 11:27 ` [PATCH V6 09/17] ST SPEAr: Adding machine support for rtc-spear Viresh Kumar
2011-03-01 11:30 ` [PATCH V6 10/17] ST SPEAr: adding support for synopsis i2c designware Viresh Kumar
2011-03-01 11:31 ` [PATCH V6 11/17] ST SPEAr: Adding machine support for USB host Viresh Kumar
2011-03-01 11:31 ` [PATCH V6 12/17] ST SPEAr: Adding machine support for keyboard Viresh Kumar
2011-03-01 11:31 ` [PATCH V6 13/17] ST SPEAr: Adding machine support for nand Viresh Kumar
2011-03-01 11:31 ` [PATCH V6 14/17] ST SPEAr: Adding support for SSP PL022 Viresh Kumar
2011-03-01 11:31 ` [PATCH V6 15/17] ST SPEAr: Adding support for SDHCI (SDIO) Viresh Kumar
2011-03-01 11:31 ` [PATCH V6 16/17] ST SPEAr Power Management: Added the support for Standby mode Viresh Kumar
2011-03-01 11:31 ` [PATCH V6 17/17] ST SPEAr: Updating defconfigs Viresh Kumar
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=201103011610.24283.arnd@arndb.de \
--to=arnd@arndb.de \
--cc=linux-arm-kernel@lists.infradead.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.