* [PATCH v2] [POWERPC] 4xx: Add endpoint support to 4xx PCIe driver
@ 2008-04-21 14:54 Stefan Roese
2008-04-21 21:16 ` Benjamin Herrenschmidt
2008-04-25 6:24 ` Benjamin Herrenschmidt
0 siblings, 2 replies; 8+ messages in thread
From: Stefan Roese @ 2008-04-21 14:54 UTC (permalink / raw)
To: linuxppc-dev
This patch adds basic endpoint support to the 4xx PCIe driver.
This is done by checking the device_type property of the PCIe
device node ("pci" for root-complex and "pci-endpoint" for endpoint
configuration).
Note: Currently we map a fixed 64MByte window to PLB address 0 (SDRAM).
This should probably be configurable via a dts property.
Signed-off-by: Stefan Roese <sr@denx.de>
---
Changes in v2:
--------------
- As suggested by Benjamin Herrenschmidt, don't determine endpoint mode
by looking at the already configured PCIe port state, but evaluate
the device_type property instead. This makes it possible for boards
without a previously run PCIe configuration (e.g. U-Boot) to configure
a port as endpoint as well.
- Don't map the big external config space upon endpoint configuration.
- Introduce "vendor-id" and "device-id" properties to be written to
the host bridge.
arch/powerpc/sysdev/ppc4xx_pci.c | 180 +++++++++++++++++++++++++++----------
1 files changed, 131 insertions(+), 49 deletions(-)
diff --git a/arch/powerpc/sysdev/ppc4xx_pci.c b/arch/powerpc/sysdev/ppc4xx_pci.c
index 1087196..acdc309 100644
--- a/arch/powerpc/sysdev/ppc4xx_pci.c
+++ b/arch/powerpc/sysdev/ppc4xx_pci.c
@@ -1390,28 +1390,59 @@ static void __init ppc4xx_configure_pciex_PIMs(struct ppc4xx_pciex_port *port,
resource_size_t size = res->end - res->start + 1;
u64 sa;
- /* Calculate window size */
- sa = (0xffffffffffffffffull << ilog2(size));;
- if (res->flags & IORESOURCE_PREFETCH)
- sa |= 0x8;
+ if (port->endpoint) {
+ resource_size_t ep_addr = 0;
+ resource_size_t ep_size = 32 << 20;
+
+ /* Currently we map a fixed 64MByte window to PLB address
+ * 0 (SDRAM). This should probably be configurable via a dts
+ * property.
+ */
+
+ /* Calculate window size */
+ sa = (0xffffffffffffffffull << ilog2(ep_size));;
+
+ /* Setup BAR0 */
+ out_le32(mbase + PECFG_BAR0HMPA, RES_TO_U32_HIGH(sa));
+ out_le32(mbase + PECFG_BAR0LMPA, RES_TO_U32_LOW(sa) |
+ PCI_BASE_ADDRESS_MEM_TYPE_64);
- out_le32(mbase + PECFG_BAR0HMPA, RES_TO_U32_HIGH(sa));
- out_le32(mbase + PECFG_BAR0LMPA, RES_TO_U32_LOW(sa));
+ /* Disable BAR1 & BAR2 */
+ out_le32(mbase + PECFG_BAR1MPA, 0);
+ out_le32(mbase + PECFG_BAR2HMPA, 0);
+ out_le32(mbase + PECFG_BAR2LMPA, 0);
- /* The setup of the split looks weird to me ... let's see if it works */
- out_le32(mbase + PECFG_PIM0LAL, 0x00000000);
- out_le32(mbase + PECFG_PIM0LAH, 0x00000000);
- out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
- out_le32(mbase + PECFG_PIM1LAH, 0x00000000);
- out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
- out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
+ out_le32(mbase + PECFG_PIM01SAH, RES_TO_U32_HIGH(sa));
+ out_le32(mbase + PECFG_PIM01SAL, RES_TO_U32_LOW(sa));
+
+ out_le32(mbase + PCI_BASE_ADDRESS_0, RES_TO_U32_LOW(ep_addr));
+ out_le32(mbase + PCI_BASE_ADDRESS_1, RES_TO_U32_HIGH(ep_addr));
+ } else {
+ /* Calculate window size */
+ sa = (0xffffffffffffffffull << ilog2(size));;
+ if (res->flags & IORESOURCE_PREFETCH)
+ sa |= 0x8;
+
+ out_le32(mbase + PECFG_BAR0HMPA, RES_TO_U32_HIGH(sa));
+ out_le32(mbase + PECFG_BAR0LMPA, RES_TO_U32_LOW(sa));
+
+ /* The setup of the split looks weird to me ... let's see
+ * if it works
+ */
+ out_le32(mbase + PECFG_PIM0LAL, 0x00000000);
+ out_le32(mbase + PECFG_PIM0LAH, 0x00000000);
+ out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
+ out_le32(mbase + PECFG_PIM1LAH, 0x00000000);
+ out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
+ out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
+
+ out_le32(mbase + PCI_BASE_ADDRESS_0, RES_TO_U32_LOW(res->start));
+ out_le32(mbase + PCI_BASE_ADDRESS_1, RES_TO_U32_HIGH(res->start));
+ }
/* Enable inbound mapping */
out_le32(mbase + PECFG_PIMEN, 0x1);
- out_le32(mbase + PCI_BASE_ADDRESS_0, RES_TO_U32_LOW(res->start));
- out_le32(mbase + PCI_BASE_ADDRESS_1, RES_TO_U32_HIGH(res->start));
-
/* Enable I/O, Mem, and Busmaster cycles */
out_le16(mbase + PCI_COMMAND,
in_le16(mbase + PCI_COMMAND) |
@@ -1425,13 +1456,8 @@ static void __init ppc4xx_pciex_port_setup_hose(struct ppc4xx_pciex_port *port)
const int *bus_range;
int primary = 0, busses;
void __iomem *mbase = NULL, *cfg_data = NULL;
-
- /* XXX FIXME: Handle endpoint mode properly */
- if (port->endpoint) {
- printk(KERN_WARNING "PCIE%d: Port in endpoint mode !\n",
- port->index);
- return;
- }
+ const u32 *pval;
+ u32 val;
/* Check if primary bridge */
if (of_get_property(port->node, "primary", NULL))
@@ -1465,21 +1491,30 @@ static void __init ppc4xx_pciex_port_setup_hose(struct ppc4xx_pciex_port *port)
hose->last_busno = hose->first_busno + busses;
}
- /* We map the external config space in cfg_data and the host config
- * space in cfg_addr. External space is 1M per bus, internal space
- * is 4K
+ if (!port->endpoint) {
+ /* Only map the external config space in cfg_data for
+ * PCIe root-complexes. External space is 1M per bus
+ */
+ cfg_data = ioremap(port->cfg_space.start +
+ (hose->first_busno + 1) * 0x100000,
+ busses * 0x100000);
+ if (cfg_data == NULL) {
+ printk(KERN_ERR "%s: Can't map external config space !",
+ port->node->full_name);
+ goto fail;
+ }
+ hose->cfg_data = cfg_data;
+ }
+
+ /* Always map the host config space in cfg_addr.
+ * Internal space is 4K
*/
- cfg_data = ioremap(port->cfg_space.start +
- (hose->first_busno + 1) * 0x100000,
- busses * 0x100000);
mbase = ioremap(port->cfg_space.start + 0x10000000, 0x1000);
- if (cfg_data == NULL || mbase == NULL) {
- printk(KERN_ERR "%s: Can't map config space !",
+ if (mbase == NULL) {
+ printk(KERN_ERR "%s: Can't map internal config space !",
port->node->full_name);
goto fail;
}
-
- hose->cfg_data = cfg_data;
hose->cfg_addr = mbase;
pr_debug("PCIE %s, bus %d..%d\n", port->node->full_name,
@@ -1492,12 +1527,14 @@ static void __init ppc4xx_pciex_port_setup_hose(struct ppc4xx_pciex_port *port)
port->hose = hose;
mbase = (void __iomem *)hose->cfg_addr;
- /*
- * Set bus numbers on our root port
- */
- out_8(mbase + PCI_PRIMARY_BUS, hose->first_busno);
- out_8(mbase + PCI_SECONDARY_BUS, hose->first_busno + 1);
- out_8(mbase + PCI_SUBORDINATE_BUS, hose->last_busno);
+ if (!port->endpoint) {
+ /*
+ * Set bus numbers on our root port
+ */
+ out_8(mbase + PCI_PRIMARY_BUS, hose->first_busno);
+ out_8(mbase + PCI_SECONDARY_BUS, hose->first_busno + 1);
+ out_8(mbase + PCI_SUBORDINATE_BUS, hose->last_busno);
+ }
/*
* OMRs are already reset, also disable PIMs
@@ -1518,17 +1555,49 @@ static void __init ppc4xx_pciex_port_setup_hose(struct ppc4xx_pciex_port *port)
ppc4xx_configure_pciex_PIMs(port, hose, mbase, &dma_window);
/* The root complex doesn't show up if we don't set some vendor
- * and device IDs into it. Those are the same bogus one that the
- * initial code in arch/ppc add. We might want to change that.
+ * and device IDs into it. The defaults below are the same bogus
+ * one that the initial code in arch/ppc had. This can be
+ * overwritten by setting the "vendor-id/device-id" properties
+ * in the pciex node.
*/
- out_le16(mbase + 0x200, 0xaaa0 + port->index);
- out_le16(mbase + 0x202, 0xbed0 + port->index);
- /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
- out_le32(mbase + 0x208, 0x06040001);
+ /* Get the (optional) vendor-/device-id from the device-tree */
+ pval = of_get_property(port->node, "vendor-id", NULL);
+ if (pval) {
+ val = *pval;
+ } else {
+ if (!port->endpoint)
+ val = 0xaaa0 + port->index;
+ else
+ val = 0xeee0 + port->index;
+ }
+ out_le16(mbase + 0x200, val);
+
+ pval = of_get_property(port->node, "device-id", NULL);
+ if (pval) {
+ val = *pval;
+ } else {
+ if (!port->endpoint)
+ val = 0xbed0 + port->index;
+ else
+ val = 0xfed0 + port->index;
+ }
+ out_le16(mbase + 0x202, val);
+
+ if (!port->endpoint) {
+ /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
+ out_le32(mbase + 0x208, 0x06040001);
+
+ printk(KERN_INFO "PCIE%d: successfully set as root-complex\n",
+ port->index);
+ } else {
+ /* Set Class Code to Processor/PPC */
+ out_le32(mbase + 0x208, 0x0b200001);
+
+ printk(KERN_INFO "PCIE%d: successfully set as endpoint\n",
+ port->index);
+ }
- printk(KERN_INFO "PCIE%d: successfully set as root-complex\n",
- port->index);
return;
fail:
if (hose)
@@ -1545,6 +1614,7 @@ static void __init ppc4xx_probe_pciex_bridge(struct device_node *np)
const u32 *pval;
int portno;
unsigned int dcrs;
+ const char *val;
/* First, proceed to core initialization as we assume there's
* only one PCIe core in the system
@@ -1576,8 +1646,20 @@ static void __init ppc4xx_probe_pciex_bridge(struct device_node *np)
}
port->sdr_base = *pval;
- /* XXX Currently, we only support root complex mode */
- port->endpoint = 0;
+ /* Check if device_type property is set to "pci" or "pci-endpoint".
+ * Resulting from this setup this PCIe port will be configured
+ * as root-complex or as endpoint.
+ */
+ val = of_get_property(port->node, "device_type", NULL);
+ if (!strcmp(val, "pci-endpoint")) {
+ port->endpoint = 1;
+ } else if (!strcmp(val, "pci")) {
+ port->endpoint = 0;
+ } else {
+ printk(KERN_ERR "PCIE: missing or incorrect device_type for %s\n",
+ np->full_name);
+ return;
+ }
/* Fetch config space registers address */
if (of_address_to_resource(np, 0, &port->cfg_space)) {
--
1.5.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2] [POWERPC] 4xx: Add endpoint support to 4xx PCIe driver
2008-04-21 14:54 [PATCH v2] [POWERPC] 4xx: Add endpoint support to 4xx PCIe driver Stefan Roese
@ 2008-04-21 21:16 ` Benjamin Herrenschmidt
2008-04-22 5:17 ` Stefan Roese
2008-04-25 6:24 ` Benjamin Herrenschmidt
1 sibling, 1 reply; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2008-04-21 21:16 UTC (permalink / raw)
To: Stefan Roese; +Cc: linuxppc-dev
On Mon, 2008-04-21 at 16:54 +0200, Stefan Roese wrote:
> --------------
> - As suggested by Benjamin Herrenschmidt, don't determine endpoint mode
> by looking at the already configured PCIe port state, but evaluate
> the device_type property instead. This makes it possible for boards
> without a previously run PCIe configuration (e.g. U-Boot) to configure
> a port as endpoint as well.
>
> - Don't map the big external config space upon endpoint configuration.
>
> - Introduce "vendor-id" and "device-id" properties to be written to
> the host bridge.
and class-code too ?
Appart from that, I'll have a quick look at the patch later today but at
first it looks good.
Cheers,
Ben.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] [POWERPC] 4xx: Add endpoint support to 4xx PCIe driver
2008-04-21 21:16 ` Benjamin Herrenschmidt
@ 2008-04-22 5:17 ` Stefan Roese
0 siblings, 0 replies; 8+ messages in thread
From: Stefan Roese @ 2008-04-22 5:17 UTC (permalink / raw)
To: benh; +Cc: linuxppc-dev
On Monday 21 April 2008, Benjamin Herrenschmidt wrote:
> On Mon, 2008-04-21 at 16:54 +0200, Stefan Roese wrote:
> > --------------
> > - As suggested by Benjamin Herrenschmidt, don't determine endpoint mode
> > by looking at the already configured PCIe port state, but evaluate
> > the device_type property instead. This makes it possible for boards
> > without a previously run PCIe configuration (e.g. U-Boot) to configure
> > a port as endpoint as well.
> >
> > - Don't map the big external config space upon endpoint configuration.
> >
> > - Introduce "vendor-id" and "device-id" properties to be written to
> > the host bridge.
>
> and class-code too ?
Sure, could be done. But this is not really endpoint/root-complex related. So
I suggest to add this later with an additional patch.
> Appart from that, I'll have a quick look at the patch later today but at
> first it looks good.
Thanks.
Best regards,
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] [POWERPC] 4xx: Add endpoint support to 4xx PCIe driver
2008-04-21 14:54 [PATCH v2] [POWERPC] 4xx: Add endpoint support to 4xx PCIe driver Stefan Roese
2008-04-21 21:16 ` Benjamin Herrenschmidt
@ 2008-04-25 6:24 ` Benjamin Herrenschmidt
2008-04-25 10:37 ` Josh Boyer
1 sibling, 1 reply; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2008-04-25 6:24 UTC (permalink / raw)
To: Stefan Roese; +Cc: linuxppc-dev, Paul Mackerras
On Mon, 2008-04-21 at 16:54 +0200, Stefan Roese wrote:
> This patch adds basic endpoint support to the 4xx PCIe driver.
>
> This is done by checking the device_type property of the PCIe
> device node ("pci" for root-complex and "pci-endpoint" for endpoint
> configuration).
>
> Note: Currently we map a fixed 64MByte window to PLB address 0 (SDRAM).
> This should probably be configurable via a dts property.
>
> Signed-off-by: Stefan Roese <sr@denx.de>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
Paul, I forgot to send that ack a while ago, this is .26 material, been
around for some time.
Cheers,
Ben.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] [POWERPC] 4xx: Add endpoint support to 4xx PCIe driver
2008-04-25 6:24 ` Benjamin Herrenschmidt
@ 2008-04-25 10:37 ` Josh Boyer
2008-04-25 12:58 ` Benjamin Herrenschmidt
0 siblings, 1 reply; 8+ messages in thread
From: Josh Boyer @ 2008-04-25 10:37 UTC (permalink / raw)
To: benh; +Cc: linuxppc-dev, Stefan Roese, Paul Mackerras
On Fri, 25 Apr 2008 16:24:01 +1000
Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:
>
> On Mon, 2008-04-21 at 16:54 +0200, Stefan Roese wrote:
> > This patch adds basic endpoint support to the 4xx PCIe driver.
> >
> > This is done by checking the device_type property of the PCIe
> > device node ("pci" for root-complex and "pci-endpoint" for endpoint
> > configuration).
> >
> > Note: Currently we map a fixed 64MByte window to PLB address 0 (SDRAM).
> > This should probably be configurable via a dts property.
> >
> > Signed-off-by: Stefan Roese <sr@denx.de>
>
> Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---
>
> Paul, I forgot to send that ack a while ago, this is .26 material, been
> around for some time.
I'll add it to my tree. And this version of the patch was only sent
out on Monday.
josh
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] [POWERPC] 4xx: Add endpoint support to 4xx PCIe driver
2008-04-25 10:37 ` Josh Boyer
@ 2008-04-25 12:58 ` Benjamin Herrenschmidt
2008-04-25 13:19 ` Josh Boyer
0 siblings, 1 reply; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2008-04-25 12:58 UTC (permalink / raw)
To: Josh Boyer; +Cc: linuxppc-dev, Stefan Roese, Paul Mackerras
On Fri, 2008-04-25 at 05:37 -0500, Josh Boyer wrote:
> On Fri, 25 Apr 2008 16:24:01 +1000
> Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:
>
> >
> > On Mon, 2008-04-21 at 16:54 +0200, Stefan Roese wrote:
> > > This patch adds basic endpoint support to the 4xx PCIe driver.
> > >
> > > This is done by checking the device_type property of the PCIe
> > > device node ("pci" for root-complex and "pci-endpoint" for endpoint
> > > configuration).
> > >
> > > Note: Currently we map a fixed 64MByte window to PLB address 0 (SDRAM).
> > > This should probably be configurable via a dts property.
> > >
> > > Signed-off-by: Stefan Roese <sr@denx.de>
> >
> > Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> > ---
> >
> > Paul, I forgot to send that ack a while ago, this is .26 material, been
> > around for some time.
>
> I'll add it to my tree. And this version of the patch was only sent
> out on Monday.
True but I'm to blame for waiting too long to review it...
Ben.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] [POWERPC] 4xx: Add endpoint support to 4xx PCIe driver
2008-04-25 12:58 ` Benjamin Herrenschmidt
@ 2008-04-25 13:19 ` Josh Boyer
2008-04-25 13:47 ` Kumar Gala
0 siblings, 1 reply; 8+ messages in thread
From: Josh Boyer @ 2008-04-25 13:19 UTC (permalink / raw)
To: benh; +Cc: linuxppc-dev, Stefan Roese, Paul Mackerras
On Fri, 25 Apr 2008 22:58:04 +1000
Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:
>
> On Fri, 2008-04-25 at 05:37 -0500, Josh Boyer wrote:
> > On Fri, 25 Apr 2008 16:24:01 +1000
> > Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:
> >
> > >
> > > On Mon, 2008-04-21 at 16:54 +0200, Stefan Roese wrote:
> > > > This patch adds basic endpoint support to the 4xx PCIe driver.
> > > >
> > > > This is done by checking the device_type property of the PCIe
> > > > device node ("pci" for root-complex and "pci-endpoint" for endpoint
> > > > configuration).
> > > >
> > > > Note: Currently we map a fixed 64MByte window to PLB address 0 (SDRAM).
> > > > This should probably be configurable via a dts property.
> > > >
> > > > Signed-off-by: Stefan Roese <sr@denx.de>
> > >
> > > Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> > > ---
> > >
> > > Paul, I forgot to send that ack a while ago, this is .26 material, been
> > > around for some time.
> >
> > I'll add it to my tree. And this version of the patch was only sent
> > out on Monday.
>
> True but I'm to blame for waiting too long to review it...
Oh, for sure. We blame you for all kinds of things. It's just easier
that way ;)
josh
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] [POWERPC] 4xx: Add endpoint support to 4xx PCIe driver
2008-04-25 13:19 ` Josh Boyer
@ 2008-04-25 13:47 ` Kumar Gala
0 siblings, 0 replies; 8+ messages in thread
From: Kumar Gala @ 2008-04-25 13:47 UTC (permalink / raw)
To: Josh Boyer; +Cc: Stefan Roese, Paul Mackerras, linuxppc-dev
On Apr 25, 2008, at 8:19 AM, Josh Boyer wrote:
> On Fri, 25 Apr 2008 22:58:04 +1000
> Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:
>
>>
>> On Fri, 2008-04-25 at 05:37 -0500, Josh Boyer wrote:
>>> On Fri, 25 Apr 2008 16:24:01 +1000
>>> Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:
>>>
>>>>
>>>> On Mon, 2008-04-21 at 16:54 +0200, Stefan Roese wrote:
>>>>> This patch adds basic endpoint support to the 4xx PCIe driver.
>>>>>
>>>>> This is done by checking the device_type property of the PCIe
>>>>> device node ("pci" for root-complex and "pci-endpoint" for
>>>>> endpoint
>>>>> configuration).
>>>>>
>>>>> Note: Currently we map a fixed 64MByte window to PLB address 0
>>>>> (SDRAM).
>>>>> This should probably be configurable via a dts property.
>>>>>
>>>>> Signed-off-by: Stefan Roese <sr@denx.de>
>>>>
>>>> Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>>>> ---
>>>>
>>>> Paul, I forgot to send that ack a while ago, this is .26
>>>> material, been
>>>> around for some time.
>>>
>>> I'll add it to my tree. And this version of the patch was only sent
>>> out on Monday.
>>
>> True but I'm to blame for waiting too long to review it...
>
> Oh, for sure. We blame you for all kinds of things. It's just easier
> that way ;)
Can we include an example of the device node in the commit message (or
some updates to docs/booting-with-of.txt)
- k
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2008-04-25 13:48 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-21 14:54 [PATCH v2] [POWERPC] 4xx: Add endpoint support to 4xx PCIe driver Stefan Roese
2008-04-21 21:16 ` Benjamin Herrenschmidt
2008-04-22 5:17 ` Stefan Roese
2008-04-25 6:24 ` Benjamin Herrenschmidt
2008-04-25 10:37 ` Josh Boyer
2008-04-25 12:58 ` Benjamin Herrenschmidt
2008-04-25 13:19 ` Josh Boyer
2008-04-25 13:47 ` Kumar Gala
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).