2018-12-28 16:31:49 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2009-06-17 17:20:48 +08:00
|
|
|
/*
|
|
|
|
* Low-Level PCI Express Support for the SH7786
|
|
|
|
*
|
2011-01-18 18:56:04 +08:00
|
|
|
* Copyright (C) 2009 - 2011 Paul Mundt
|
2009-06-17 17:20:48 +08:00
|
|
|
*/
|
2011-01-18 18:56:04 +08:00
|
|
|
#define pr_fmt(fmt) "PCI: " fmt
|
|
|
|
|
2009-06-17 17:20:48 +08:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/io.h>
|
2011-01-18 18:56:04 +08:00
|
|
|
#include <linux/async.h>
|
2009-06-17 17:20:48 +08:00
|
|
|
#include <linux/delay.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2010-09-20 17:45:11 +08:00
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/sh_clk.h>
|
2012-05-18 16:42:29 +08:00
|
|
|
#include <linux/sh_intc.h>
|
2017-12-04 23:09:04 +08:00
|
|
|
#include <cpu/sh7786.h>
|
2009-06-17 17:20:48 +08:00
|
|
|
#include "pcie-sh7786.h"
|
2019-05-15 06:46:51 +08:00
|
|
|
#include <linux/sizes.h>
|
2009-06-17 17:20:48 +08:00
|
|
|
|
|
|
|
struct sh7786_pcie_port {
|
|
|
|
struct pci_channel *hose;
|
2010-09-20 17:45:11 +08:00
|
|
|
struct clk *fclk, phy_clk;
|
2009-06-17 17:20:48 +08:00
|
|
|
unsigned int index;
|
|
|
|
int endpoint;
|
|
|
|
int link;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct sh7786_pcie_port *sh7786_pcie_ports;
|
|
|
|
static unsigned int nr_ports;
|
2017-12-04 23:09:07 +08:00
|
|
|
static unsigned long dma_pfn_offset;
|
2009-06-17 17:20:48 +08:00
|
|
|
|
|
|
|
static struct sh7786_pcie_hwops {
|
|
|
|
int (*core_init)(void);
|
2013-03-13 04:59:14 +08:00
|
|
|
async_func_t port_init_hw;
|
2009-06-17 17:20:48 +08:00
|
|
|
} *sh7786_pcie_hwops;
|
|
|
|
|
2010-02-08 15:36:56 +08:00
|
|
|
static struct resource sh7786_pci0_resources[] = {
|
2009-06-17 17:20:48 +08:00
|
|
|
{
|
2017-12-04 23:09:05 +08:00
|
|
|
.name = "PCIe0 MEM 0",
|
2010-02-08 15:36:56 +08:00
|
|
|
.start = 0xfd000000,
|
|
|
|
.end = 0xfd000000 + SZ_8M - 1,
|
2017-12-04 23:09:05 +08:00
|
|
|
.flags = IORESOURCE_MEM,
|
2009-06-17 17:20:48 +08:00
|
|
|
}, {
|
2017-12-04 23:09:05 +08:00
|
|
|
.name = "PCIe0 MEM 1",
|
2010-02-08 15:36:56 +08:00
|
|
|
.start = 0xc0000000,
|
|
|
|
.end = 0xc0000000 + SZ_512M - 1,
|
|
|
|
.flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
|
2009-06-17 17:20:48 +08:00
|
|
|
}, {
|
2017-12-04 23:09:05 +08:00
|
|
|
.name = "PCIe0 MEM 2",
|
2010-02-08 15:36:56 +08:00
|
|
|
.start = 0x10000000,
|
|
|
|
.end = 0x10000000 + SZ_64M - 1,
|
2009-06-17 17:20:48 +08:00
|
|
|
.flags = IORESOURCE_MEM,
|
2010-02-08 15:36:56 +08:00
|
|
|
}, {
|
2017-12-04 23:09:05 +08:00
|
|
|
.name = "PCIe0 IO",
|
2010-02-08 15:36:56 +08:00
|
|
|
.start = 0xfe100000,
|
|
|
|
.end = 0xfe100000 + SZ_1M - 1,
|
2017-12-04 23:09:05 +08:00
|
|
|
.flags = IORESOURCE_IO,
|
2009-06-17 17:20:48 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2010-02-08 15:36:56 +08:00
|
|
|
static struct resource sh7786_pci1_resources[] = {
|
|
|
|
{
|
2017-12-04 23:09:05 +08:00
|
|
|
.name = "PCIe1 MEM 0",
|
2010-02-08 15:36:56 +08:00
|
|
|
.start = 0xfd800000,
|
|
|
|
.end = 0xfd800000 + SZ_8M - 1,
|
2017-12-04 23:09:05 +08:00
|
|
|
.flags = IORESOURCE_MEM,
|
2010-02-08 15:36:56 +08:00
|
|
|
}, {
|
2017-12-04 23:09:05 +08:00
|
|
|
.name = "PCIe1 MEM 1",
|
2010-02-08 15:36:56 +08:00
|
|
|
.start = 0xa0000000,
|
|
|
|
.end = 0xa0000000 + SZ_512M - 1,
|
|
|
|
.flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
|
|
|
|
}, {
|
2017-12-04 23:09:05 +08:00
|
|
|
.name = "PCIe1 MEM 2",
|
2010-02-08 15:36:56 +08:00
|
|
|
.start = 0x30000000,
|
|
|
|
.end = 0x30000000 + SZ_256M - 1,
|
|
|
|
.flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
|
|
|
|
}, {
|
2017-12-04 23:09:05 +08:00
|
|
|
.name = "PCIe1 IO",
|
2010-02-08 15:36:56 +08:00
|
|
|
.start = 0xfe300000,
|
|
|
|
.end = 0xfe300000 + SZ_1M - 1,
|
2017-12-04 23:09:05 +08:00
|
|
|
.flags = IORESOURCE_IO,
|
2010-02-08 15:36:56 +08:00
|
|
|
},
|
2009-06-17 17:20:48 +08:00
|
|
|
};
|
|
|
|
|
2010-02-08 15:36:56 +08:00
|
|
|
static struct resource sh7786_pci2_resources[] = {
|
2009-06-17 17:20:48 +08:00
|
|
|
{
|
2017-12-04 23:09:05 +08:00
|
|
|
.name = "PCIe2 MEM 0",
|
2010-02-08 15:36:56 +08:00
|
|
|
.start = 0xfc800000,
|
|
|
|
.end = 0xfc800000 + SZ_4M - 1,
|
2017-12-04 23:09:05 +08:00
|
|
|
.flags = IORESOURCE_MEM,
|
2009-06-17 17:20:48 +08:00
|
|
|
}, {
|
2017-12-04 23:09:05 +08:00
|
|
|
.name = "PCIe2 MEM 1",
|
2010-02-08 15:36:56 +08:00
|
|
|
.start = 0x80000000,
|
|
|
|
.end = 0x80000000 + SZ_512M - 1,
|
|
|
|
.flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
|
2009-06-17 17:20:48 +08:00
|
|
|
}, {
|
2017-12-04 23:09:05 +08:00
|
|
|
.name = "PCIe2 MEM 2",
|
2010-02-08 15:36:56 +08:00
|
|
|
.start = 0x20000000,
|
|
|
|
.end = 0x20000000 + SZ_256M - 1,
|
|
|
|
.flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
|
|
|
|
}, {
|
2017-12-04 23:09:05 +08:00
|
|
|
.name = "PCIe2 IO",
|
2010-02-08 15:36:56 +08:00
|
|
|
.start = 0xfcd00000,
|
|
|
|
.end = 0xfcd00000 + SZ_1M - 1,
|
2017-12-04 23:09:05 +08:00
|
|
|
.flags = IORESOURCE_IO,
|
2009-06-17 17:20:48 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct pci_ops sh7786_pci_ops;
|
|
|
|
|
2010-02-08 15:36:56 +08:00
|
|
|
#define DEFINE_CONTROLLER(start, idx) \
|
|
|
|
{ \
|
|
|
|
.pci_ops = &sh7786_pci_ops, \
|
|
|
|
.resources = sh7786_pci##idx##_resources, \
|
|
|
|
.nr_resources = ARRAY_SIZE(sh7786_pci##idx##_resources), \
|
|
|
|
.reg_base = start, \
|
|
|
|
.mem_offset = 0, \
|
|
|
|
.io_offset = 0, \
|
2009-06-17 17:20:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pci_channel sh7786_pci_channels[] = {
|
|
|
|
DEFINE_CONTROLLER(0xfe000000, 0),
|
|
|
|
DEFINE_CONTROLLER(0xfe200000, 1),
|
|
|
|
DEFINE_CONTROLLER(0xfcc00000, 2),
|
|
|
|
};
|
|
|
|
|
2010-09-20 17:45:11 +08:00
|
|
|
static struct clk fixed_pciexclkp = {
|
|
|
|
.rate = 100000000, /* 100 MHz reference clock */
|
|
|
|
};
|
|
|
|
|
2012-12-22 06:06:37 +08:00
|
|
|
static void sh7786_pci_fixup(struct pci_dev *dev)
|
2010-09-20 14:39:54 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Prevent enumeration of root complex resources.
|
|
|
|
*/
|
|
|
|
if (pci_is_root_bus(dev->bus) && dev->devfn == 0) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
|
|
|
|
dev->resource[i].start = 0;
|
|
|
|
dev->resource[i].end = 0;
|
|
|
|
dev->resource[i].flags = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_RENESAS, PCI_DEVICE_ID_RENESAS_SH7786,
|
|
|
|
sh7786_pci_fixup);
|
|
|
|
|
2010-09-20 17:45:11 +08:00
|
|
|
static int __init phy_wait_for_ack(struct pci_channel *chan)
|
2009-06-17 17:20:48 +08:00
|
|
|
{
|
|
|
|
unsigned int timeout = 100;
|
|
|
|
|
|
|
|
while (timeout--) {
|
|
|
|
if (pci_read_reg(chan, SH4A_PCIEPHYADRR) & (1 << BITS_ACK))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2010-09-20 17:45:11 +08:00
|
|
|
static int __init pci_wait_for_irq(struct pci_channel *chan, unsigned int mask)
|
2009-06-17 17:20:48 +08:00
|
|
|
{
|
|
|
|
unsigned int timeout = 100;
|
|
|
|
|
|
|
|
while (timeout--) {
|
|
|
|
if ((pci_read_reg(chan, SH4A_PCIEINTR) & mask) == mask)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2010-09-20 17:45:11 +08:00
|
|
|
static void __init phy_write_reg(struct pci_channel *chan, unsigned int addr,
|
|
|
|
unsigned int lane, unsigned int data)
|
2009-06-17 17:20:48 +08:00
|
|
|
{
|
2010-08-20 15:04:59 +08:00
|
|
|
unsigned long phyaddr;
|
2009-06-17 17:20:48 +08:00
|
|
|
|
|
|
|
phyaddr = (1 << BITS_CMD) + ((lane & 0xf) << BITS_LANE) +
|
|
|
|
((addr & 0xff) << BITS_ADR);
|
|
|
|
|
|
|
|
/* Set write data */
|
|
|
|
pci_write_reg(chan, data, SH4A_PCIEPHYDOUTR);
|
|
|
|
pci_write_reg(chan, phyaddr, SH4A_PCIEPHYADRR);
|
|
|
|
|
|
|
|
phy_wait_for_ack(chan);
|
|
|
|
|
|
|
|
/* Clear command */
|
2010-08-20 15:04:59 +08:00
|
|
|
pci_write_reg(chan, 0, SH4A_PCIEPHYDOUTR);
|
2009-06-17 17:20:48 +08:00
|
|
|
pci_write_reg(chan, 0, SH4A_PCIEPHYADRR);
|
|
|
|
|
|
|
|
phy_wait_for_ack(chan);
|
|
|
|
}
|
|
|
|
|
2010-09-20 17:45:11 +08:00
|
|
|
static int __init pcie_clk_init(struct sh7786_pcie_port *port)
|
|
|
|
{
|
|
|
|
struct pci_channel *chan = port->hose;
|
|
|
|
struct clk *clk;
|
|
|
|
char fclk_name[16];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First register the fixed clock
|
|
|
|
*/
|
|
|
|
ret = clk_register(&fixed_pciexclkp);
|
|
|
|
if (unlikely(ret != 0))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab the port's function clock, which the PHY clock depends
|
|
|
|
* on. clock lookups don't help us much at this point, since no
|
|
|
|
* dev_id is available this early. Lame.
|
|
|
|
*/
|
|
|
|
snprintf(fclk_name, sizeof(fclk_name), "pcie%d_fck", port->index);
|
|
|
|
|
|
|
|
port->fclk = clk_get(NULL, fclk_name);
|
|
|
|
if (IS_ERR(port->fclk)) {
|
|
|
|
ret = PTR_ERR(port->fclk);
|
|
|
|
goto err_fclk;
|
|
|
|
}
|
|
|
|
|
|
|
|
clk_enable(port->fclk);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* And now, set up the PHY clock
|
|
|
|
*/
|
|
|
|
clk = &port->phy_clk;
|
|
|
|
|
|
|
|
memset(clk, 0, sizeof(struct clk));
|
|
|
|
|
|
|
|
clk->parent = &fixed_pciexclkp;
|
|
|
|
clk->enable_reg = (void __iomem *)(chan->reg_base + SH4A_PCIEPHYCTLR);
|
|
|
|
clk->enable_bit = BITS_CKE;
|
|
|
|
|
2012-06-27 08:59:40 +08:00
|
|
|
ret = sh_clk_mstp_register(clk, 1);
|
2010-09-20 17:45:11 +08:00
|
|
|
if (unlikely(ret < 0))
|
|
|
|
goto err_phy;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_phy:
|
|
|
|
clk_disable(port->fclk);
|
|
|
|
clk_put(port->fclk);
|
|
|
|
err_fclk:
|
|
|
|
clk_unregister(&fixed_pciexclkp);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init phy_init(struct sh7786_pcie_port *port)
|
2009-06-17 17:20:48 +08:00
|
|
|
{
|
2010-09-20 17:45:11 +08:00
|
|
|
struct pci_channel *chan = port->hose;
|
2009-06-17 17:20:48 +08:00
|
|
|
unsigned int timeout = 100;
|
|
|
|
|
2010-09-20 17:45:11 +08:00
|
|
|
clk_enable(&port->phy_clk);
|
2010-08-20 15:04:59 +08:00
|
|
|
|
2009-06-17 17:20:48 +08:00
|
|
|
/* Initialize the phy */
|
|
|
|
phy_write_reg(chan, 0x60, 0xf, 0x004b008b);
|
|
|
|
phy_write_reg(chan, 0x61, 0xf, 0x00007b41);
|
|
|
|
phy_write_reg(chan, 0x64, 0xf, 0x00ff4f00);
|
|
|
|
phy_write_reg(chan, 0x65, 0xf, 0x09070907);
|
|
|
|
phy_write_reg(chan, 0x66, 0xf, 0x00000010);
|
|
|
|
phy_write_reg(chan, 0x74, 0xf, 0x0007001c);
|
|
|
|
phy_write_reg(chan, 0x79, 0xf, 0x01fc000d);
|
2010-08-20 15:04:59 +08:00
|
|
|
phy_write_reg(chan, 0xb0, 0xf, 0x00000610);
|
2009-06-17 17:20:48 +08:00
|
|
|
|
|
|
|
/* Deassert Standby */
|
2010-08-20 15:04:59 +08:00
|
|
|
phy_write_reg(chan, 0x67, 0x1, 0x00000400);
|
|
|
|
|
|
|
|
/* Disable clock */
|
2010-09-20 17:45:11 +08:00
|
|
|
clk_disable(&port->phy_clk);
|
2009-06-17 17:20:48 +08:00
|
|
|
|
|
|
|
while (timeout--) {
|
|
|
|
if (pci_read_reg(chan, SH4A_PCIEPHYSR))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2010-09-20 17:45:11 +08:00
|
|
|
static void __init pcie_reset(struct sh7786_pcie_port *port)
|
2010-09-07 15:11:04 +08:00
|
|
|
{
|
|
|
|
struct pci_channel *chan = port->hose;
|
|
|
|
|
|
|
|
pci_write_reg(chan, 1, SH4A_PCIESRSTR);
|
|
|
|
pci_write_reg(chan, 0, SH4A_PCIETCTLR);
|
|
|
|
pci_write_reg(chan, 0, SH4A_PCIESRSTR);
|
|
|
|
pci_write_reg(chan, 0, SH4A_PCIETXVC0SR);
|
|
|
|
}
|
|
|
|
|
2010-09-20 17:45:11 +08:00
|
|
|
static int __init pcie_init(struct sh7786_pcie_port *port)
|
2009-06-17 17:20:48 +08:00
|
|
|
{
|
|
|
|
struct pci_channel *chan = port->hose;
|
|
|
|
unsigned int data;
|
2017-12-04 23:09:06 +08:00
|
|
|
phys_addr_t memstart, memend;
|
2010-02-10 15:00:58 +08:00
|
|
|
size_t memsize;
|
2010-09-07 16:03:10 +08:00
|
|
|
int ret, i, win;
|
2009-06-17 17:20:48 +08:00
|
|
|
|
|
|
|
/* Begin initialization */
|
2010-09-07 15:11:04 +08:00
|
|
|
pcie_reset(port);
|
2009-06-17 17:20:48 +08:00
|
|
|
|
2010-09-20 14:39:54 +08:00
|
|
|
/*
|
|
|
|
* Initial header for port config space is type 1, set the device
|
|
|
|
* class to match. Hardware takes care of propagating the IDSETR
|
|
|
|
* settings, so there is no need to bother with a quirk.
|
|
|
|
*/
|
|
|
|
pci_write_reg(chan, PCI_CLASS_BRIDGE_PCI << 16, SH4A_PCIEIDSETR1);
|
2009-06-17 17:20:48 +08:00
|
|
|
|
|
|
|
/* Initialize default capabilities. */
|
|
|
|
data = pci_read_reg(chan, SH4A_PCIEEXPCAP0);
|
|
|
|
data &= ~(PCI_EXP_FLAGS_TYPE << 16);
|
|
|
|
|
|
|
|
if (port->endpoint)
|
|
|
|
data |= PCI_EXP_TYPE_ENDPOINT << 20;
|
|
|
|
else
|
|
|
|
data |= PCI_EXP_TYPE_ROOT_PORT << 20;
|
|
|
|
|
|
|
|
data |= PCI_CAP_ID_EXP;
|
|
|
|
pci_write_reg(chan, data, SH4A_PCIEEXPCAP0);
|
|
|
|
|
2010-02-10 15:00:58 +08:00
|
|
|
/* Enable data link layer active state reporting */
|
|
|
|
pci_write_reg(chan, PCI_EXP_LNKCAP_DLLLARC, SH4A_PCIEEXPCAP3);
|
|
|
|
|
|
|
|
/* Enable extended sync and ASPM L0s support */
|
2009-06-17 17:20:48 +08:00
|
|
|
data = pci_read_reg(chan, SH4A_PCIEEXPCAP4);
|
2010-02-10 15:00:58 +08:00
|
|
|
data &= ~PCI_EXP_LNKCTL_ASPMC;
|
|
|
|
data |= PCI_EXP_LNKCTL_ES | 1;
|
2009-06-17 17:20:48 +08:00
|
|
|
pci_write_reg(chan, data, SH4A_PCIEEXPCAP4);
|
|
|
|
|
2010-02-10 15:00:58 +08:00
|
|
|
/* Write out the physical slot number */
|
|
|
|
data = pci_read_reg(chan, SH4A_PCIEEXPCAP5);
|
|
|
|
data &= ~PCI_EXP_SLTCAP_PSN;
|
|
|
|
data |= (port->index + 1) << 19;
|
|
|
|
pci_write_reg(chan, data, SH4A_PCIEEXPCAP5);
|
|
|
|
|
2009-06-17 17:20:48 +08:00
|
|
|
/* Set the completion timer timeout to the maximum 32ms. */
|
|
|
|
data = pci_read_reg(chan, SH4A_PCIETLCTLR);
|
2010-02-10 15:00:58 +08:00
|
|
|
data &= ~0x3f00;
|
2009-06-17 17:20:48 +08:00
|
|
|
data |= 0x32 << 8;
|
|
|
|
pci_write_reg(chan, data, SH4A_PCIETLCTLR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set fast training sequences to the maximum 255,
|
|
|
|
* and enable MAC data scrambling.
|
|
|
|
*/
|
|
|
|
data = pci_read_reg(chan, SH4A_PCIEMACCTLR);
|
|
|
|
data &= ~PCIEMACCTLR_SCR_DIS;
|
|
|
|
data |= (0xff << 16);
|
|
|
|
pci_write_reg(chan, data, SH4A_PCIEMACCTLR);
|
|
|
|
|
2017-12-04 23:09:06 +08:00
|
|
|
memstart = __pa(memory_start);
|
|
|
|
memend = __pa(memory_end);
|
|
|
|
memsize = roundup_pow_of_two(memend - memstart);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The start address must be aligned on its size. So we round
|
|
|
|
* it down, and then recalculate the size so that it covers
|
|
|
|
* the entire memory.
|
|
|
|
*/
|
|
|
|
memstart = ALIGN_DOWN(memstart, memsize);
|
|
|
|
memsize = roundup_pow_of_two(memend - memstart);
|
2010-02-10 15:00:58 +08:00
|
|
|
|
2017-12-04 23:09:07 +08:00
|
|
|
dma_pfn_offset = memstart >> PAGE_SHIFT;
|
|
|
|
|
2010-02-10 15:00:58 +08:00
|
|
|
/*
|
|
|
|
* If there's more than 512MB of memory, we need to roll over to
|
|
|
|
* LAR1/LAMR1.
|
|
|
|
*/
|
|
|
|
if (memsize > SZ_512M) {
|
2017-12-04 23:09:06 +08:00
|
|
|
pci_write_reg(chan, memstart + SZ_512M, SH4A_PCIELAR1);
|
2010-09-20 16:10:02 +08:00
|
|
|
pci_write_reg(chan, ((memsize - SZ_512M) - SZ_256) | 1,
|
|
|
|
SH4A_PCIELAMR1);
|
2010-02-10 15:00:58 +08:00
|
|
|
memsize = SZ_512M;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Otherwise just zero it out and disable it.
|
|
|
|
*/
|
2010-09-20 16:10:02 +08:00
|
|
|
pci_write_reg(chan, 0, SH4A_PCIELAR1);
|
|
|
|
pci_write_reg(chan, 0, SH4A_PCIELAMR1);
|
2010-02-10 15:00:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LAR0/LAMR0 covers up to the first 512MB, which is enough to
|
|
|
|
* cover all of lowmem on most platforms.
|
|
|
|
*/
|
2017-12-04 23:09:06 +08:00
|
|
|
pci_write_reg(chan, memstart, SH4A_PCIELAR0);
|
2010-09-20 16:10:02 +08:00
|
|
|
pci_write_reg(chan, (memsize - SZ_256) | 1, SH4A_PCIELAMR0);
|
2010-02-10 15:00:58 +08:00
|
|
|
|
2009-06-17 17:20:48 +08:00
|
|
|
/* Finish initialization */
|
|
|
|
data = pci_read_reg(chan, SH4A_PCIETCTLR);
|
|
|
|
data |= 0x1;
|
|
|
|
pci_write_reg(chan, data, SH4A_PCIETCTLR);
|
|
|
|
|
2010-09-19 12:57:51 +08:00
|
|
|
/* Let things settle down a bit.. */
|
|
|
|
mdelay(100);
|
|
|
|
|
2009-06-17 17:20:48 +08:00
|
|
|
/* Enable DL_Active Interrupt generation */
|
|
|
|
data = pci_read_reg(chan, SH4A_PCIEDLINTENR);
|
|
|
|
data |= PCIEDLINTENR_DLL_ACT_ENABLE;
|
|
|
|
pci_write_reg(chan, data, SH4A_PCIEDLINTENR);
|
|
|
|
|
|
|
|
/* Disable MAC data scrambling. */
|
|
|
|
data = pci_read_reg(chan, SH4A_PCIEMACCTLR);
|
|
|
|
data |= PCIEMACCTLR_SCR_DIS | (0xff << 16);
|
|
|
|
pci_write_reg(chan, data, SH4A_PCIEMACCTLR);
|
|
|
|
|
2010-09-20 15:12:58 +08:00
|
|
|
/*
|
|
|
|
* This will timeout if we don't have a link, but we permit the
|
|
|
|
* port to register anyways in order to support hotplug on future
|
|
|
|
* hardware.
|
|
|
|
*/
|
2009-06-17 17:20:48 +08:00
|
|
|
ret = pci_wait_for_irq(chan, MASK_INT_TX_CTRL);
|
|
|
|
|
2010-02-10 15:00:58 +08:00
|
|
|
data = pci_read_reg(chan, SH4A_PCIEPCICONF1);
|
|
|
|
data &= ~(PCI_STATUS_DEVSEL_MASK << 16);
|
|
|
|
data |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
|
|
|
|
(PCI_STATUS_CAP_LIST | PCI_STATUS_DEVSEL_FAST) << 16;
|
|
|
|
pci_write_reg(chan, data, SH4A_PCIEPCICONF1);
|
|
|
|
|
2009-06-17 17:20:48 +08:00
|
|
|
pci_write_reg(chan, 0x80888000, SH4A_PCIETXVC0DCTLR);
|
|
|
|
pci_write_reg(chan, 0x00222000, SH4A_PCIERXVC0DCTLR);
|
|
|
|
|
|
|
|
wmb();
|
|
|
|
|
2010-09-20 15:12:58 +08:00
|
|
|
if (ret == 0) {
|
|
|
|
data = pci_read_reg(chan, SH4A_PCIEMACSR);
|
|
|
|
printk(KERN_NOTICE "PCI: PCIe#%d x%d link detected\n",
|
|
|
|
port->index, (data >> 20) & 0x3f);
|
|
|
|
} else
|
|
|
|
printk(KERN_NOTICE "PCI: PCIe#%d link down\n",
|
|
|
|
port->index);
|
2009-06-17 17:20:48 +08:00
|
|
|
|
2010-09-07 16:03:10 +08:00
|
|
|
for (i = win = 0; i < chan->nr_resources; i++) {
|
2010-02-10 15:00:58 +08:00
|
|
|
struct resource *res = chan->resources + i;
|
|
|
|
resource_size_t size;
|
2010-09-20 16:10:02 +08:00
|
|
|
u32 mask;
|
2010-02-10 15:00:58 +08:00
|
|
|
|
2010-09-07 16:03:10 +08:00
|
|
|
/*
|
|
|
|
* We can't use the 32-bit mode windows in legacy 29-bit
|
|
|
|
* mode, so just skip them entirely.
|
|
|
|
*/
|
|
|
|
if ((res->flags & IORESOURCE_MEM_32BIT) && __in_29bit_mode())
|
arch/sh: pcie-sh7786: mark unavailable PCI resource as disabled
Some PCI MEM resources are marked as IORESOURCE_MEM_32BIT, which means
they are only usable when the SH core runs in 32-bit mode. In 29-bit
mode, such memory regions are not usable.
The existing code for SH7786 properly skips such regions when
configuring the PCIe controller registers. However, because such
regions are still described in the resource array, the
pcibios_scanbus() function in the SuperH pci.c will register them to
the PCI core. Due to this, the PCI core will allocate MEM areas from
this resource, and assign BARs pointing to this area, even though it's
unusable.
In order to prevent this from happening, we mark such regions as
IORESOURCE_DISABLED, which tells the SuperH pci.c pcibios_scanbus()
function to skip them.
Note that we separate marking the region as disabled from skipping it,
because other regions will be marked as disabled in follow-up patches.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Rich Felker <dalias@libc.org>
2017-12-04 23:09:03 +08:00
|
|
|
res->flags |= IORESOURCE_DISABLED;
|
|
|
|
|
|
|
|
if (res->flags & IORESOURCE_DISABLED)
|
2010-09-07 16:03:10 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
pci_write_reg(chan, 0x00000000, SH4A_PCIEPTCTLR(win));
|
2010-02-10 15:00:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The PAMR mask is calculated in units of 256kB, which
|
|
|
|
* keeps things pretty simple.
|
|
|
|
*/
|
2010-09-20 16:10:02 +08:00
|
|
|
size = resource_size(res);
|
|
|
|
mask = (roundup_pow_of_two(size) / SZ_256K) - 1;
|
|
|
|
pci_write_reg(chan, mask << 18, SH4A_PCIEPAMR(win));
|
2010-02-10 15:00:58 +08:00
|
|
|
|
2010-10-15 05:15:56 +08:00
|
|
|
pci_write_reg(chan, upper_32_bits(res->start),
|
2010-09-20 16:10:02 +08:00
|
|
|
SH4A_PCIEPARH(win));
|
2010-10-15 05:15:56 +08:00
|
|
|
pci_write_reg(chan, lower_32_bits(res->start),
|
2010-09-20 16:10:02 +08:00
|
|
|
SH4A_PCIEPARL(win));
|
2010-02-10 15:00:58 +08:00
|
|
|
|
2010-09-20 16:10:02 +08:00
|
|
|
mask = MASK_PARE;
|
2010-02-10 15:00:58 +08:00
|
|
|
if (res->flags & IORESOURCE_IO)
|
2010-09-20 16:10:02 +08:00
|
|
|
mask |= MASK_SPC;
|
2010-02-10 15:00:58 +08:00
|
|
|
|
2010-09-20 16:10:02 +08:00
|
|
|
pci_write_reg(chan, mask, SH4A_PCIEPTCTLR(win));
|
2010-09-07 16:03:10 +08:00
|
|
|
|
|
|
|
win++;
|
2010-02-10 15:00:58 +08:00
|
|
|
}
|
2009-06-17 17:20:48 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-01 00:37:49 +08:00
|
|
|
int pcibios_map_platform_irq(const struct pci_dev *pdev, u8 slot, u8 pin)
|
2009-06-17 17:20:48 +08:00
|
|
|
{
|
2012-05-18 16:42:29 +08:00
|
|
|
return evt2irq(0xae0);
|
2009-06-17 17:20:48 +08:00
|
|
|
}
|
|
|
|
|
2017-12-04 23:09:07 +08:00
|
|
|
void pcibios_bus_add_device(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
pdev->dev.dma_pfn_offset = dma_pfn_offset;
|
|
|
|
}
|
|
|
|
|
2010-09-20 17:45:11 +08:00
|
|
|
static int __init sh7786_pcie_core_init(void)
|
2009-06-17 17:20:48 +08:00
|
|
|
{
|
|
|
|
/* Return the number of ports */
|
|
|
|
return test_mode_pin(MODE_PIN12) ? 3 : 2;
|
|
|
|
}
|
|
|
|
|
2011-01-18 18:56:04 +08:00
|
|
|
static void __init sh7786_pcie_init_hw(void *data, async_cookie_t cookie)
|
2009-06-17 17:20:48 +08:00
|
|
|
{
|
2011-01-18 18:56:04 +08:00
|
|
|
struct sh7786_pcie_port *port = data;
|
2009-06-17 17:20:48 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if we are configured in endpoint or root complex mode,
|
|
|
|
* this is a fixed pin setting that applies to all PCIe ports.
|
|
|
|
*/
|
|
|
|
port->endpoint = test_mode_pin(MODE_PIN11);
|
|
|
|
|
2010-09-20 17:45:11 +08:00
|
|
|
/*
|
|
|
|
* Setup clocks, needed both for PHY and PCIe registers.
|
|
|
|
*/
|
|
|
|
ret = pcie_clk_init(port);
|
2011-01-18 18:56:04 +08:00
|
|
|
if (unlikely(ret < 0)) {
|
|
|
|
pr_err("clock initialization failed for port#%d\n",
|
|
|
|
port->index);
|
|
|
|
return;
|
|
|
|
}
|
2010-09-20 17:45:11 +08:00
|
|
|
|
|
|
|
ret = phy_init(port);
|
2011-01-18 18:56:04 +08:00
|
|
|
if (unlikely(ret < 0)) {
|
|
|
|
pr_err("phy initialization failed for port#%d\n",
|
|
|
|
port->index);
|
|
|
|
return;
|
|
|
|
}
|
2010-09-20 17:45:11 +08:00
|
|
|
|
2009-06-17 17:20:48 +08:00
|
|
|
ret = pcie_init(port);
|
2011-01-18 18:56:04 +08:00
|
|
|
if (unlikely(ret < 0)) {
|
|
|
|
pr_err("core initialization failed for port#%d\n",
|
|
|
|
port->index);
|
|
|
|
return;
|
|
|
|
}
|
2009-06-17 17:20:48 +08:00
|
|
|
|
2011-01-18 18:56:04 +08:00
|
|
|
/* In the interest of preserving device ordering, synchronize */
|
|
|
|
async_synchronize_cookie(cookie);
|
|
|
|
|
|
|
|
register_pci_controller(port->hose);
|
2009-06-17 17:20:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct sh7786_pcie_hwops sh7786_65nm_pcie_hwops __initdata = {
|
|
|
|
.core_init = sh7786_pcie_core_init,
|
|
|
|
.port_init_hw = sh7786_pcie_init_hw,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init sh7786_pcie_init(void)
|
|
|
|
{
|
2010-10-14 07:44:55 +08:00
|
|
|
struct clk *platclk;
|
2017-12-04 23:09:04 +08:00
|
|
|
u32 mm_sel;
|
2011-01-18 18:56:04 +08:00
|
|
|
int i;
|
2009-06-17 17:20:48 +08:00
|
|
|
|
2010-06-19 07:01:03 +08:00
|
|
|
printk(KERN_NOTICE "PCI: Starting initialization.\n");
|
2009-06-17 17:20:48 +08:00
|
|
|
|
|
|
|
sh7786_pcie_hwops = &sh7786_65nm_pcie_hwops;
|
|
|
|
|
|
|
|
nr_ports = sh7786_pcie_hwops->core_init();
|
|
|
|
BUG_ON(nr_ports > ARRAY_SIZE(sh7786_pci_channels));
|
|
|
|
|
|
|
|
if (unlikely(nr_ports == 0))
|
|
|
|
return -ENODEV;
|
|
|
|
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:03:40 +08:00
|
|
|
sh7786_pcie_ports = kcalloc(nr_ports, sizeof(struct sh7786_pcie_port),
|
2009-06-17 17:20:48 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (unlikely(!sh7786_pcie_ports))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-10-14 07:44:55 +08:00
|
|
|
/*
|
|
|
|
* Fetch any optional platform clock associated with this block.
|
|
|
|
*
|
|
|
|
* This is a rather nasty hack for boards with spec-mocking FPGAs
|
|
|
|
* that have a secondary set of clocks outside of the on-chip
|
|
|
|
* ones that need to be accounted for before there is any chance
|
|
|
|
* of touching the existing MSTP bits or CPG clocks.
|
|
|
|
*/
|
|
|
|
platclk = clk_get(NULL, "pcie_plat_clk");
|
|
|
|
if (IS_ERR(platclk)) {
|
|
|
|
/* Sane hardware should probably get a WARN_ON.. */
|
|
|
|
platclk = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
clk_enable(platclk);
|
|
|
|
|
2017-12-04 23:09:04 +08:00
|
|
|
mm_sel = sh7786_mm_sel();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Depending on the MMSELR register value, the PCIe0 MEM 1
|
|
|
|
* area may not be available. See Table 13.11 of the SH7786
|
|
|
|
* datasheet.
|
|
|
|
*/
|
|
|
|
if (mm_sel != 1 && mm_sel != 2 && mm_sel != 5 && mm_sel != 6)
|
|
|
|
sh7786_pci0_resources[2].flags |= IORESOURCE_DISABLED;
|
|
|
|
|
2009-06-17 17:20:48 +08:00
|
|
|
printk(KERN_NOTICE "PCI: probing %d ports.\n", nr_ports);
|
|
|
|
|
|
|
|
for (i = 0; i < nr_ports; i++) {
|
|
|
|
struct sh7786_pcie_port *port = sh7786_pcie_ports + i;
|
|
|
|
|
|
|
|
port->index = i;
|
|
|
|
port->hose = sh7786_pci_channels + i;
|
2010-02-08 15:36:56 +08:00
|
|
|
port->hose->io_map_base = port->hose->resources[0].start;
|
2009-06-17 17:20:48 +08:00
|
|
|
|
2011-01-18 18:56:04 +08:00
|
|
|
async_schedule(sh7786_pcie_hwops->port_init_hw, port);
|
2010-10-14 07:44:55 +08:00
|
|
|
}
|
2009-06-17 17:20:48 +08:00
|
|
|
|
2011-01-28 14:14:08 +08:00
|
|
|
async_synchronize_full();
|
|
|
|
|
2009-06-17 17:20:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
arch_initcall(sh7786_pcie_init);
|