15 #include <linux/kernel.h>
17 #include <linux/pci.h>
21 #include <linux/ptrace.h>
45 static struct cns3xxx_pcie *sysdata_to_cnspci(
void *sysdata)
54 return sysdata_to_cnspci(dev->
sysdata);
59 return sysdata_to_cnspci(bus->
sysdata);
63 unsigned int devfn,
int where)
73 if (!cnspci->
linked && (busno > 0 || slot > 0))
90 offset = ((busno & 0xf) << 20) | (devfn << 12) | (where & 0xffc);
95 static int cns3xxx_pci_read_config(
struct pci_bus *bus,
unsigned int devfn,
100 u32 mask = (0x1ull << (size * 8)) - 1;
101 int shift = (where % 4) * 8;
103 base = cns3xxx_pci_cfg_base(bus, devfn, where);
111 if (bus->
number == 0 && devfn == 0 &&
122 *val = (v >> shift) & mask;
127 static int cns3xxx_pci_write_config(
struct pci_bus *bus,
unsigned int devfn,
128 int where,
int size,
u32 val)
132 u32 mask = (0x1ull << (size * 8)) - 1;
133 int shift = (where % 4) * 8;
135 base = cns3xxx_pci_cfg_base(bus, devfn, where);
141 v &= ~(mask << shift);
142 v |= (val &
mask) << shift;
164 static struct pci_ops cns3xxx_pcie_ops = {
165 .read = cns3xxx_pci_read_config,
166 .write = cns3xxx_pci_write_config,
174 pr_info(
"PCIe map irq: %04d:%02x:%02x.%02x slot %d, pin %d, irq: %d\n",
204 .name =
"PCIe0 I/O space",
210 .name =
"PCIe0 non-prefetchable",
219 .ops = &cns3xxx_pcie_ops,
220 .setup = cns3xxx_pci_setup,
221 .map_irq = cns3xxx_pcie_map_irq,
246 .name =
"PCIe1 I/O space",
252 .name =
"PCIe1 non-prefetchable",
261 .ops = &cns3xxx_pcie_ops,
262 .setup = cns3xxx_pci_setup,
263 .map_irq = cns3xxx_pcie_map_irq,
268 static void __init cns3xxx_pcie_check_link(
struct cns3xxx_pcie *cnspci)
282 pr_info(
"PCIe: Port[%d] Enable PCIe LTSSM\n", port);
283 pr_info(
"PCIe: Port[%d] Check data link layer...", port);
293 pr_info(
"Device not found.\n");
299 static void __init cns3xxx_pcie_hw_init(
struct cns3xxx_pcie *cnspci)
301 int port = cnspci->
hw_pci.domain;
307 .ops = &cns3xxx_pcie_ops,
345 if (!(dc & (0x3 << 12)))
346 pr_info(
"PCIe: Set Device Max_Read_Request_Size to 128 byte\n");
352 static int cns3xxx_pcie_abort_handler(
unsigned long addr,
unsigned int fsr,
360 static int __init cns3xxx_pcie_init(
void)
368 "imprecise external abort");
370 for (i = 0; i <
ARRAY_SIZE(cns3xxx_pcie); i++) {
375 cns3xxx_pcie_check_link(&cns3xxx_pcie[i]);
376 cns3xxx_pcie_hw_init(&cns3xxx_pcie[i]);