Skip to content

Commit 2c65d75

Browse files
committed
sh: pci: Support root complex config accesses on SH7786 PCIe.
The SH7786 PCIe is presently unable to enumerate itself in root complex mode, and has no visibility through either type 0 or type 1 accesses, despite having a mostly sensible extended config space for each port. Attempts to generate type 0 or type 1 config cycles result in completer aborts, so we're ultimately forced to use SuperHyway transactions instead. As each port has a single port <-> device mapping that resolves for any PCI_SLOT definition, we simply hijack devfn 0 for the SuperHyway transaction and bump up the devfn limit. With enumeration of the root complex now possible, we also need to insert an early fixup to hide the BARs from the kernel. With all of that done, it's now possible to use the pcieport services with all of the PCIe ports, which is the first step to power management support. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent cabdf8b commit 2c65d75

2 files changed

Lines changed: 55 additions & 9 deletions

File tree

‎arch/sh/drivers/pci/ops-sh7786.c‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,57 @@ static int sh7786_pcie_config_access(unsigned char access_type,
2525
struct pci_bus *bus, unsigned int devfn, int where, u32 *data)
2626
{
2727
struct pci_channel *chan = bus->sysdata;
28-
int dev, func, type;
28+
int dev, func, type, reg;
2929

3030
dev = PCI_SLOT(devfn);
3131
func = PCI_FUNC(devfn);
3232
type = !!bus->parent;
33+
reg = where & ~3;
3334

3435
if (bus->number > 255 || dev > 31 || func > 7)
3536
return PCIBIOS_FUNC_NOT_SUPPORTED;
36-
if (bus->parent == NULL && dev)
37-
return PCIBIOS_DEVICE_NOT_FOUND;
37+
38+
/*
39+
* While each channel has its own memory-mapped extended config
40+
* space, it's generally only accessible when in endpoint mode.
41+
* When in root complex mode, the controller is unable to target
42+
* itself with either type 0 or type 1 accesses, and indeed, any
43+
* controller initiated target transfer to its own config space
44+
* result in a completer abort.
45+
*
46+
* Each channel effectively only supports a single device, but as
47+
* the same channel <-> device access works for any PCI_SLOT()
48+
* value, we cheat a bit here and bind the controller's config
49+
* space to devfn 0 in order to enable self-enumeration. In this
50+
* case the regular PAR/PDR path is sidelined and the mangled
51+
* config access itself is initiated as a SuperHyway transaction.
52+
*/
53+
if (pci_is_root_bus(bus)) {
54+
if (dev == 0) {
55+
if (access_type == PCI_ACCESS_READ)
56+
*data = pci_read_reg(chan, PCI_REG(reg));
57+
else
58+
pci_write_reg(chan, *data, PCI_REG(reg));
59+
60+
return PCIBIOS_SUCCESSFUL;
61+
} else if (dev > 1)
62+
return PCIBIOS_DEVICE_NOT_FOUND;
63+
}
3864

3965
/* Clear errors */
4066
pci_write_reg(chan, pci_read_reg(chan, SH4A_PCIEERRFR), SH4A_PCIEERRFR);
4167

4268
/* Set the PIO address */
4369
pci_write_reg(chan, (bus->number << 24) | (dev << 19) |
44-
(func << 16) | (where & ~3), SH4A_PCIEPAR);
70+
(func << 16) | reg, SH4A_PCIEPAR);
4571

4672
/* Enable the configuration access */
4773
pci_write_reg(chan, (1 << 31) | (type << 8), SH4A_PCIEPCTLR);
4874

4975
/* Check for errors */
5076
if (pci_read_reg(chan, SH4A_PCIEERRFR) & 0x10)
5177
return PCIBIOS_DEVICE_NOT_FOUND;
78+
5279
/* Check for master and target aborts */
5380
if (pci_read_reg(chan, SH4A_PCIEPCICONF1) & ((1 << 29) | (1 << 28)))
5481
return PCIBIOS_DEVICE_NOT_FOUND;

‎arch/sh/drivers/pci/pcie-sh7786.c‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,24 @@ static struct pci_channel sh7786_pci_channels[] = {
121121
DEFINE_CONTROLLER(0xfcc00000, 2),
122122
};
123123

124+
static void __devinit sh7786_pci_fixup(struct pci_dev *dev)
125+
{
126+
/*
127+
* Prevent enumeration of root complex resources.
128+
*/
129+
if (pci_is_root_bus(dev->bus) && dev->devfn == 0) {
130+
int i;
131+
132+
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
133+
dev->resource[i].start = 0;
134+
dev->resource[i].end = 0;
135+
dev->resource[i].flags = 0;
136+
}
137+
}
138+
}
139+
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_RENESAS, PCI_DEVICE_ID_RENESAS_SH7786,
140+
sh7786_pci_fixup);
141+
124142
static int phy_wait_for_ack(struct pci_channel *chan)
125143
{
126144
unsigned int timeout = 100;
@@ -229,11 +247,12 @@ static int pcie_init(struct sh7786_pcie_port *port)
229247
/* Begin initialization */
230248
pcie_reset(port);
231249

232-
/* Initialize as type1. */
233-
data = pci_read_reg(chan, SH4A_PCIEPCICONF3);
234-
data &= ~(0x7f << 16);
235-
data |= PCI_HEADER_TYPE_BRIDGE << 16;
236-
pci_write_reg(chan, data, SH4A_PCIEPCICONF3);
250+
/*
251+
* Initial header for port config space is type 1, set the device
252+
* class to match. Hardware takes care of propagating the IDSETR
253+
* settings, so there is no need to bother with a quirk.
254+
*/
255+
pci_write_reg(chan, PCI_CLASS_BRIDGE_PCI << 16, SH4A_PCIEIDSETR1);
237256

238257
/* Initialize default capabilities. */
239258
data = pci_read_reg(chan, SH4A_PCIEEXPCAP0);

0 commit comments

Comments
 (0)