1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * This file is subject to the terms and conditions of the GNU General Public
3*4882a593Smuzhiyun * License. See the file "COPYING" in the main directory of this archive
4*4882a593Smuzhiyun * for more details.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 2005-2009 Cavium Networks
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun #include <linux/kernel.h>
9*4882a593Smuzhiyun #include <linux/init.h>
10*4882a593Smuzhiyun #include <linux/pci.h>
11*4882a593Smuzhiyun #include <linux/interrupt.h>
12*4882a593Smuzhiyun #include <linux/time.h>
13*4882a593Smuzhiyun #include <linux/delay.h>
14*4882a593Smuzhiyun #include <linux/platform_device.h>
15*4882a593Smuzhiyun #include <linux/swiotlb.h>
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #include <asm/time.h>
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun #include <asm/octeon/octeon.h>
20*4882a593Smuzhiyun #include <asm/octeon/cvmx-npi-defs.h>
21*4882a593Smuzhiyun #include <asm/octeon/cvmx-pci-defs.h>
22*4882a593Smuzhiyun #include <asm/octeon/pci-octeon.h>
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #define USE_OCTEON_INTERNAL_ARBITER
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun /*
27*4882a593Smuzhiyun * Octeon's PCI controller uses did=3, subdid=2 for PCI IO
28*4882a593Smuzhiyun * addresses. Use PCI endian swapping 1 so no address swapping is
29*4882a593Smuzhiyun * necessary. The Linux io routines will endian swap the data.
30*4882a593Smuzhiyun */
31*4882a593Smuzhiyun #define OCTEON_PCI_IOSPACE_BASE 0x80011a0400000000ull
32*4882a593Smuzhiyun #define OCTEON_PCI_IOSPACE_SIZE (1ull<<32)
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun /* Octeon't PCI controller uses did=3, subdid=3 for PCI memory. */
35*4882a593Smuzhiyun #define OCTEON_PCI_MEMSPACE_OFFSET (0x00011b0000000000ull)
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun u64 octeon_bar1_pci_phys;
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun /**
40*4882a593Smuzhiyun * This is the bit decoding used for the Octeon PCI controller addresses
41*4882a593Smuzhiyun */
42*4882a593Smuzhiyun union octeon_pci_address {
43*4882a593Smuzhiyun uint64_t u64;
44*4882a593Smuzhiyun struct {
45*4882a593Smuzhiyun uint64_t upper:2;
46*4882a593Smuzhiyun uint64_t reserved:13;
47*4882a593Smuzhiyun uint64_t io:1;
48*4882a593Smuzhiyun uint64_t did:5;
49*4882a593Smuzhiyun uint64_t subdid:3;
50*4882a593Smuzhiyun uint64_t reserved2:4;
51*4882a593Smuzhiyun uint64_t endian_swap:2;
52*4882a593Smuzhiyun uint64_t reserved3:10;
53*4882a593Smuzhiyun uint64_t bus:8;
54*4882a593Smuzhiyun uint64_t dev:5;
55*4882a593Smuzhiyun uint64_t func:3;
56*4882a593Smuzhiyun uint64_t reg:8;
57*4882a593Smuzhiyun } s;
58*4882a593Smuzhiyun };
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun int (*octeon_pcibios_map_irq)(const struct pci_dev *dev, u8 slot, u8 pin);
61*4882a593Smuzhiyun enum octeon_dma_bar_type octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_INVALID;
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun /**
64*4882a593Smuzhiyun * Map a PCI device to the appropriate interrupt line
65*4882a593Smuzhiyun *
66*4882a593Smuzhiyun * @dev: The Linux PCI device structure for the device to map
67*4882a593Smuzhiyun * @slot: The slot number for this device on __BUS 0__. Linux
68*4882a593Smuzhiyun * enumerates through all the bridges and figures out the
69*4882a593Smuzhiyun * slot on Bus 0 where this device eventually hooks to.
70*4882a593Smuzhiyun * @pin: The PCI interrupt pin read from the device, then swizzled
71*4882a593Smuzhiyun * as it goes through each bridge.
72*4882a593Smuzhiyun * Returns Interrupt number for the device
73*4882a593Smuzhiyun */
pcibios_map_irq(const struct pci_dev * dev,u8 slot,u8 pin)74*4882a593Smuzhiyun int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun if (octeon_pcibios_map_irq)
77*4882a593Smuzhiyun return octeon_pcibios_map_irq(dev, slot, pin);
78*4882a593Smuzhiyun else
79*4882a593Smuzhiyun panic("octeon_pcibios_map_irq not set.");
80*4882a593Smuzhiyun }
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun /*
84*4882a593Smuzhiyun * Called to perform platform specific PCI setup
85*4882a593Smuzhiyun */
pcibios_plat_dev_init(struct pci_dev * dev)86*4882a593Smuzhiyun int pcibios_plat_dev_init(struct pci_dev *dev)
87*4882a593Smuzhiyun {
88*4882a593Smuzhiyun uint16_t config;
89*4882a593Smuzhiyun uint32_t dconfig;
90*4882a593Smuzhiyun int pos;
91*4882a593Smuzhiyun /*
92*4882a593Smuzhiyun * Force the Cache line setting to 64 bytes. The standard
93*4882a593Smuzhiyun * Linux bus scan doesn't seem to set it. Octeon really has
94*4882a593Smuzhiyun * 128 byte lines, but Intel bridges get really upset if you
95*4882a593Smuzhiyun * try and set values above 64 bytes. Value is specified in
96*4882a593Smuzhiyun * 32bit words.
97*4882a593Smuzhiyun */
98*4882a593Smuzhiyun pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 64 / 4);
99*4882a593Smuzhiyun /* Set latency timers for all devices */
100*4882a593Smuzhiyun pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun /* Enable reporting System errors and parity errors on all devices */
103*4882a593Smuzhiyun /* Enable parity checking and error reporting */
104*4882a593Smuzhiyun pci_read_config_word(dev, PCI_COMMAND, &config);
105*4882a593Smuzhiyun config |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
106*4882a593Smuzhiyun pci_write_config_word(dev, PCI_COMMAND, config);
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun if (dev->subordinate) {
109*4882a593Smuzhiyun /* Set latency timers on sub bridges */
110*4882a593Smuzhiyun pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, 64);
111*4882a593Smuzhiyun /* More bridge error detection */
112*4882a593Smuzhiyun pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &config);
113*4882a593Smuzhiyun config |= PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR;
114*4882a593Smuzhiyun pci_write_config_word(dev, PCI_BRIDGE_CONTROL, config);
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun /* Enable the PCIe normal error reporting */
118*4882a593Smuzhiyun config = PCI_EXP_DEVCTL_CERE; /* Correctable Error Reporting */
119*4882a593Smuzhiyun config |= PCI_EXP_DEVCTL_NFERE; /* Non-Fatal Error Reporting */
120*4882a593Smuzhiyun config |= PCI_EXP_DEVCTL_FERE; /* Fatal Error Reporting */
121*4882a593Smuzhiyun config |= PCI_EXP_DEVCTL_URRE; /* Unsupported Request */
122*4882a593Smuzhiyun pcie_capability_set_word(dev, PCI_EXP_DEVCTL, config);
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun /* Find the Advanced Error Reporting capability */
125*4882a593Smuzhiyun pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
126*4882a593Smuzhiyun if (pos) {
127*4882a593Smuzhiyun /* Clear Uncorrectable Error Status */
128*4882a593Smuzhiyun pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,
129*4882a593Smuzhiyun &dconfig);
130*4882a593Smuzhiyun pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,
131*4882a593Smuzhiyun dconfig);
132*4882a593Smuzhiyun /* Enable reporting of all uncorrectable errors */
133*4882a593Smuzhiyun /* Uncorrectable Error Mask - turned on bits disable errors */
134*4882a593Smuzhiyun pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, 0);
135*4882a593Smuzhiyun /*
136*4882a593Smuzhiyun * Leave severity at HW default. This only controls if
137*4882a593Smuzhiyun * errors are reported as uncorrectable or
138*4882a593Smuzhiyun * correctable, not if the error is reported.
139*4882a593Smuzhiyun */
140*4882a593Smuzhiyun /* PCI_ERR_UNCOR_SEVER - Uncorrectable Error Severity */
141*4882a593Smuzhiyun /* Clear Correctable Error Status */
142*4882a593Smuzhiyun pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &dconfig);
143*4882a593Smuzhiyun pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, dconfig);
144*4882a593Smuzhiyun /* Enable reporting of all correctable errors */
145*4882a593Smuzhiyun /* Correctable Error Mask - turned on bits disable errors */
146*4882a593Smuzhiyun pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, 0);
147*4882a593Smuzhiyun /* Advanced Error Capabilities */
148*4882a593Smuzhiyun pci_read_config_dword(dev, pos + PCI_ERR_CAP, &dconfig);
149*4882a593Smuzhiyun /* ECRC Generation Enable */
150*4882a593Smuzhiyun if (config & PCI_ERR_CAP_ECRC_GENC)
151*4882a593Smuzhiyun config |= PCI_ERR_CAP_ECRC_GENE;
152*4882a593Smuzhiyun /* ECRC Check Enable */
153*4882a593Smuzhiyun if (config & PCI_ERR_CAP_ECRC_CHKC)
154*4882a593Smuzhiyun config |= PCI_ERR_CAP_ECRC_CHKE;
155*4882a593Smuzhiyun pci_write_config_dword(dev, pos + PCI_ERR_CAP, dconfig);
156*4882a593Smuzhiyun /* PCI_ERR_HEADER_LOG - Header Log Register (16 bytes) */
157*4882a593Smuzhiyun /* Report all errors to the root complex */
158*4882a593Smuzhiyun pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND,
159*4882a593Smuzhiyun PCI_ERR_ROOT_CMD_COR_EN |
160*4882a593Smuzhiyun PCI_ERR_ROOT_CMD_NONFATAL_EN |
161*4882a593Smuzhiyun PCI_ERR_ROOT_CMD_FATAL_EN);
162*4882a593Smuzhiyun /* Clear the Root status register */
163*4882a593Smuzhiyun pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &dconfig);
164*4882a593Smuzhiyun pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, dconfig);
165*4882a593Smuzhiyun }
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun return 0;
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun /**
171*4882a593Smuzhiyun * Return the mapping of PCI device number to IRQ line. Each
172*4882a593Smuzhiyun * character in the return string represents the interrupt
173*4882a593Smuzhiyun * line for the device at that position. Device 1 maps to the
174*4882a593Smuzhiyun * first character, etc. The characters A-D are used for PCI
175*4882a593Smuzhiyun * interrupts.
176*4882a593Smuzhiyun *
177*4882a593Smuzhiyun * Returns PCI interrupt mapping
178*4882a593Smuzhiyun */
octeon_get_pci_interrupts(void)179*4882a593Smuzhiyun const char *octeon_get_pci_interrupts(void)
180*4882a593Smuzhiyun {
181*4882a593Smuzhiyun /*
182*4882a593Smuzhiyun * Returning an empty string causes the interrupts to be
183*4882a593Smuzhiyun * routed based on the PCI specification. From the PCI spec:
184*4882a593Smuzhiyun *
185*4882a593Smuzhiyun * INTA# of Device Number 0 is connected to IRQW on the system
186*4882a593Smuzhiyun * board. (Device Number has no significance regarding being
187*4882a593Smuzhiyun * located on the system board or in a connector.) INTA# of
188*4882a593Smuzhiyun * Device Number 1 is connected to IRQX on the system
189*4882a593Smuzhiyun * board. INTA# of Device Number 2 is connected to IRQY on the
190*4882a593Smuzhiyun * system board. INTA# of Device Number 3 is connected to IRQZ
191*4882a593Smuzhiyun * on the system board. The table below describes how each
192*4882a593Smuzhiyun * agent's INTx# lines are connected to the system board
193*4882a593Smuzhiyun * interrupt lines. The following equation can be used to
194*4882a593Smuzhiyun * determine to which INTx# signal on the system board a given
195*4882a593Smuzhiyun * device's INTx# line(s) is connected.
196*4882a593Smuzhiyun *
197*4882a593Smuzhiyun * MB = (D + I) MOD 4 MB = System board Interrupt (IRQW = 0,
198*4882a593Smuzhiyun * IRQX = 1, IRQY = 2, and IRQZ = 3) D = Device Number I =
199*4882a593Smuzhiyun * Interrupt Number (INTA# = 0, INTB# = 1, INTC# = 2, and
200*4882a593Smuzhiyun * INTD# = 3)
201*4882a593Smuzhiyun */
202*4882a593Smuzhiyun if (of_machine_is_compatible("dlink,dsr-500n"))
203*4882a593Smuzhiyun return "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC";
204*4882a593Smuzhiyun switch (octeon_bootinfo->board_type) {
205*4882a593Smuzhiyun case CVMX_BOARD_TYPE_NAO38:
206*4882a593Smuzhiyun /* This is really the NAC38 */
207*4882a593Smuzhiyun return "AAAAADABAAAAAAAAAAAAAAAAAAAAAAAA";
208*4882a593Smuzhiyun case CVMX_BOARD_TYPE_EBH3100:
209*4882a593Smuzhiyun case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
210*4882a593Smuzhiyun case CVMX_BOARD_TYPE_CN3005_EVB_HS5:
211*4882a593Smuzhiyun return "AAABAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
212*4882a593Smuzhiyun case CVMX_BOARD_TYPE_BBGW_REF:
213*4882a593Smuzhiyun return "AABCD";
214*4882a593Smuzhiyun case CVMX_BOARD_TYPE_CUST_DSR1000N:
215*4882a593Smuzhiyun return "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC";
216*4882a593Smuzhiyun case CVMX_BOARD_TYPE_THUNDER:
217*4882a593Smuzhiyun case CVMX_BOARD_TYPE_EBH3000:
218*4882a593Smuzhiyun default:
219*4882a593Smuzhiyun return "";
220*4882a593Smuzhiyun }
221*4882a593Smuzhiyun }
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun /**
224*4882a593Smuzhiyun * Map a PCI device to the appropriate interrupt line
225*4882a593Smuzhiyun *
226*4882a593Smuzhiyun * @dev: The Linux PCI device structure for the device to map
227*4882a593Smuzhiyun * @slot: The slot number for this device on __BUS 0__. Linux
228*4882a593Smuzhiyun * enumerates through all the bridges and figures out the
229*4882a593Smuzhiyun * slot on Bus 0 where this device eventually hooks to.
230*4882a593Smuzhiyun * @pin: The PCI interrupt pin read from the device, then swizzled
231*4882a593Smuzhiyun * as it goes through each bridge.
232*4882a593Smuzhiyun * Returns Interrupt number for the device
233*4882a593Smuzhiyun */
octeon_pci_pcibios_map_irq(const struct pci_dev * dev,u8 slot,u8 pin)234*4882a593Smuzhiyun int __init octeon_pci_pcibios_map_irq(const struct pci_dev *dev,
235*4882a593Smuzhiyun u8 slot, u8 pin)
236*4882a593Smuzhiyun {
237*4882a593Smuzhiyun int irq_num;
238*4882a593Smuzhiyun const char *interrupts;
239*4882a593Smuzhiyun int dev_num;
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun /* Get the board specific interrupt mapping */
242*4882a593Smuzhiyun interrupts = octeon_get_pci_interrupts();
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun dev_num = dev->devfn >> 3;
245*4882a593Smuzhiyun if (dev_num < strlen(interrupts))
246*4882a593Smuzhiyun irq_num = ((interrupts[dev_num] - 'A' + pin - 1) & 3) +
247*4882a593Smuzhiyun OCTEON_IRQ_PCI_INT0;
248*4882a593Smuzhiyun else
249*4882a593Smuzhiyun irq_num = ((slot + pin - 3) & 3) + OCTEON_IRQ_PCI_INT0;
250*4882a593Smuzhiyun return irq_num;
251*4882a593Smuzhiyun }
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun /*
255*4882a593Smuzhiyun * Read a value from configuration space
256*4882a593Smuzhiyun */
octeon_read_config(struct pci_bus * bus,unsigned int devfn,int reg,int size,u32 * val)257*4882a593Smuzhiyun static int octeon_read_config(struct pci_bus *bus, unsigned int devfn,
258*4882a593Smuzhiyun int reg, int size, u32 *val)
259*4882a593Smuzhiyun {
260*4882a593Smuzhiyun union octeon_pci_address pci_addr;
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun pci_addr.u64 = 0;
263*4882a593Smuzhiyun pci_addr.s.upper = 2;
264*4882a593Smuzhiyun pci_addr.s.io = 1;
265*4882a593Smuzhiyun pci_addr.s.did = 3;
266*4882a593Smuzhiyun pci_addr.s.subdid = 1;
267*4882a593Smuzhiyun pci_addr.s.endian_swap = 1;
268*4882a593Smuzhiyun pci_addr.s.bus = bus->number;
269*4882a593Smuzhiyun pci_addr.s.dev = devfn >> 3;
270*4882a593Smuzhiyun pci_addr.s.func = devfn & 0x7;
271*4882a593Smuzhiyun pci_addr.s.reg = reg;
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun switch (size) {
274*4882a593Smuzhiyun case 4:
275*4882a593Smuzhiyun *val = le32_to_cpu(cvmx_read64_uint32(pci_addr.u64));
276*4882a593Smuzhiyun return PCIBIOS_SUCCESSFUL;
277*4882a593Smuzhiyun case 2:
278*4882a593Smuzhiyun *val = le16_to_cpu(cvmx_read64_uint16(pci_addr.u64));
279*4882a593Smuzhiyun return PCIBIOS_SUCCESSFUL;
280*4882a593Smuzhiyun case 1:
281*4882a593Smuzhiyun *val = cvmx_read64_uint8(pci_addr.u64);
282*4882a593Smuzhiyun return PCIBIOS_SUCCESSFUL;
283*4882a593Smuzhiyun }
284*4882a593Smuzhiyun return PCIBIOS_FUNC_NOT_SUPPORTED;
285*4882a593Smuzhiyun }
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun /*
289*4882a593Smuzhiyun * Write a value to PCI configuration space
290*4882a593Smuzhiyun */
octeon_write_config(struct pci_bus * bus,unsigned int devfn,int reg,int size,u32 val)291*4882a593Smuzhiyun static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
292*4882a593Smuzhiyun int reg, int size, u32 val)
293*4882a593Smuzhiyun {
294*4882a593Smuzhiyun union octeon_pci_address pci_addr;
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun pci_addr.u64 = 0;
297*4882a593Smuzhiyun pci_addr.s.upper = 2;
298*4882a593Smuzhiyun pci_addr.s.io = 1;
299*4882a593Smuzhiyun pci_addr.s.did = 3;
300*4882a593Smuzhiyun pci_addr.s.subdid = 1;
301*4882a593Smuzhiyun pci_addr.s.endian_swap = 1;
302*4882a593Smuzhiyun pci_addr.s.bus = bus->number;
303*4882a593Smuzhiyun pci_addr.s.dev = devfn >> 3;
304*4882a593Smuzhiyun pci_addr.s.func = devfn & 0x7;
305*4882a593Smuzhiyun pci_addr.s.reg = reg;
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun switch (size) {
308*4882a593Smuzhiyun case 4:
309*4882a593Smuzhiyun cvmx_write64_uint32(pci_addr.u64, cpu_to_le32(val));
310*4882a593Smuzhiyun return PCIBIOS_SUCCESSFUL;
311*4882a593Smuzhiyun case 2:
312*4882a593Smuzhiyun cvmx_write64_uint16(pci_addr.u64, cpu_to_le16(val));
313*4882a593Smuzhiyun return PCIBIOS_SUCCESSFUL;
314*4882a593Smuzhiyun case 1:
315*4882a593Smuzhiyun cvmx_write64_uint8(pci_addr.u64, val);
316*4882a593Smuzhiyun return PCIBIOS_SUCCESSFUL;
317*4882a593Smuzhiyun }
318*4882a593Smuzhiyun return PCIBIOS_FUNC_NOT_SUPPORTED;
319*4882a593Smuzhiyun }
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun static struct pci_ops octeon_pci_ops = {
323*4882a593Smuzhiyun .read = octeon_read_config,
324*4882a593Smuzhiyun .write = octeon_write_config,
325*4882a593Smuzhiyun };
326*4882a593Smuzhiyun
327*4882a593Smuzhiyun static struct resource octeon_pci_mem_resource = {
328*4882a593Smuzhiyun .start = 0,
329*4882a593Smuzhiyun .end = 0,
330*4882a593Smuzhiyun .name = "Octeon PCI MEM",
331*4882a593Smuzhiyun .flags = IORESOURCE_MEM,
332*4882a593Smuzhiyun };
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun /*
335*4882a593Smuzhiyun * PCI ports must be above 16KB so the ISA bus filtering in the PCI-X to PCI
336*4882a593Smuzhiyun * bridge
337*4882a593Smuzhiyun */
338*4882a593Smuzhiyun static struct resource octeon_pci_io_resource = {
339*4882a593Smuzhiyun .start = 0x4000,
340*4882a593Smuzhiyun .end = OCTEON_PCI_IOSPACE_SIZE - 1,
341*4882a593Smuzhiyun .name = "Octeon PCI IO",
342*4882a593Smuzhiyun .flags = IORESOURCE_IO,
343*4882a593Smuzhiyun };
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun static struct pci_controller octeon_pci_controller = {
346*4882a593Smuzhiyun .pci_ops = &octeon_pci_ops,
347*4882a593Smuzhiyun .mem_resource = &octeon_pci_mem_resource,
348*4882a593Smuzhiyun .mem_offset = OCTEON_PCI_MEMSPACE_OFFSET,
349*4882a593Smuzhiyun .io_resource = &octeon_pci_io_resource,
350*4882a593Smuzhiyun .io_offset = 0,
351*4882a593Smuzhiyun .io_map_base = OCTEON_PCI_IOSPACE_BASE,
352*4882a593Smuzhiyun };
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun
355*4882a593Smuzhiyun /*
356*4882a593Smuzhiyun * Low level initialize the Octeon PCI controller
357*4882a593Smuzhiyun */
octeon_pci_initialize(void)358*4882a593Smuzhiyun static void octeon_pci_initialize(void)
359*4882a593Smuzhiyun {
360*4882a593Smuzhiyun union cvmx_pci_cfg01 cfg01;
361*4882a593Smuzhiyun union cvmx_npi_ctl_status ctl_status;
362*4882a593Smuzhiyun union cvmx_pci_ctl_status_2 ctl_status_2;
363*4882a593Smuzhiyun union cvmx_pci_cfg19 cfg19;
364*4882a593Smuzhiyun union cvmx_pci_cfg16 cfg16;
365*4882a593Smuzhiyun union cvmx_pci_cfg22 cfg22;
366*4882a593Smuzhiyun union cvmx_pci_cfg56 cfg56;
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun /* Reset the PCI Bus */
369*4882a593Smuzhiyun cvmx_write_csr(CVMX_CIU_SOFT_PRST, 0x1);
370*4882a593Smuzhiyun cvmx_read_csr(CVMX_CIU_SOFT_PRST);
371*4882a593Smuzhiyun
372*4882a593Smuzhiyun udelay(2000); /* Hold PCI reset for 2 ms */
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun ctl_status.u64 = 0; /* cvmx_read_csr(CVMX_NPI_CTL_STATUS); */
375*4882a593Smuzhiyun ctl_status.s.max_word = 1;
376*4882a593Smuzhiyun ctl_status.s.timer = 1;
377*4882a593Smuzhiyun cvmx_write_csr(CVMX_NPI_CTL_STATUS, ctl_status.u64);
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun /* Deassert PCI reset and advertize PCX Host Mode Device Capability
380*4882a593Smuzhiyun (64b) */
381*4882a593Smuzhiyun cvmx_write_csr(CVMX_CIU_SOFT_PRST, 0x4);
382*4882a593Smuzhiyun cvmx_read_csr(CVMX_CIU_SOFT_PRST);
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun udelay(2000); /* Wait 2 ms after deasserting PCI reset */
385*4882a593Smuzhiyun
386*4882a593Smuzhiyun ctl_status_2.u32 = 0;
387*4882a593Smuzhiyun ctl_status_2.s.tsr_hwm = 1; /* Initializes to 0. Must be set
388*4882a593Smuzhiyun before any PCI reads. */
389*4882a593Smuzhiyun ctl_status_2.s.bar2pres = 1; /* Enable BAR2 */
390*4882a593Smuzhiyun ctl_status_2.s.bar2_enb = 1;
391*4882a593Smuzhiyun ctl_status_2.s.bar2_cax = 1; /* Don't use L2 */
392*4882a593Smuzhiyun ctl_status_2.s.bar2_esx = 1;
393*4882a593Smuzhiyun ctl_status_2.s.pmo_amod = 1; /* Round robin priority */
394*4882a593Smuzhiyun if (octeon_dma_bar_type == OCTEON_DMA_BAR_TYPE_BIG) {
395*4882a593Smuzhiyun /* BAR1 hole */
396*4882a593Smuzhiyun ctl_status_2.s.bb1_hole = OCTEON_PCI_BAR1_HOLE_BITS;
397*4882a593Smuzhiyun ctl_status_2.s.bb1_siz = 1; /* BAR1 is 2GB */
398*4882a593Smuzhiyun ctl_status_2.s.bb_ca = 1; /* Don't use L2 with big bars */
399*4882a593Smuzhiyun ctl_status_2.s.bb_es = 1; /* Big bar in byte swap mode */
400*4882a593Smuzhiyun ctl_status_2.s.bb1 = 1; /* BAR1 is big */
401*4882a593Smuzhiyun ctl_status_2.s.bb0 = 1; /* BAR0 is big */
402*4882a593Smuzhiyun }
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CTL_STATUS_2, ctl_status_2.u32);
405*4882a593Smuzhiyun udelay(2000); /* Wait 2 ms before doing PCI reads */
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun ctl_status_2.u32 = octeon_npi_read32(CVMX_NPI_PCI_CTL_STATUS_2);
408*4882a593Smuzhiyun pr_notice("PCI Status: %s %s-bit\n",
409*4882a593Smuzhiyun ctl_status_2.s.ap_pcix ? "PCI-X" : "PCI",
410*4882a593Smuzhiyun ctl_status_2.s.ap_64ad ? "64" : "32");
411*4882a593Smuzhiyun
412*4882a593Smuzhiyun if (OCTEON_IS_MODEL(OCTEON_CN58XX) || OCTEON_IS_MODEL(OCTEON_CN50XX)) {
413*4882a593Smuzhiyun union cvmx_pci_cnt_reg cnt_reg_start;
414*4882a593Smuzhiyun union cvmx_pci_cnt_reg cnt_reg_end;
415*4882a593Smuzhiyun unsigned long cycles, pci_clock;
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun cnt_reg_start.u64 = cvmx_read_csr(CVMX_NPI_PCI_CNT_REG);
418*4882a593Smuzhiyun cycles = read_c0_cvmcount();
419*4882a593Smuzhiyun udelay(1000);
420*4882a593Smuzhiyun cnt_reg_end.u64 = cvmx_read_csr(CVMX_NPI_PCI_CNT_REG);
421*4882a593Smuzhiyun cycles = read_c0_cvmcount() - cycles;
422*4882a593Smuzhiyun pci_clock = (cnt_reg_end.s.pcicnt - cnt_reg_start.s.pcicnt) /
423*4882a593Smuzhiyun (cycles / (mips_hpt_frequency / 1000000));
424*4882a593Smuzhiyun pr_notice("PCI Clock: %lu MHz\n", pci_clock);
425*4882a593Smuzhiyun }
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun /*
428*4882a593Smuzhiyun * TDOMC must be set to one in PCI mode. TDOMC should be set to 4
429*4882a593Smuzhiyun * in PCI-X mode to allow four outstanding splits. Otherwise,
430*4882a593Smuzhiyun * should not change from its reset value. Don't write PCI_CFG19
431*4882a593Smuzhiyun * in PCI mode (0x82000001 reset value), write it to 0x82000004
432*4882a593Smuzhiyun * after PCI-X mode is known. MRBCI,MDWE,MDRE -> must be zero.
433*4882a593Smuzhiyun * MRBCM -> must be one.
434*4882a593Smuzhiyun */
435*4882a593Smuzhiyun if (ctl_status_2.s.ap_pcix) {
436*4882a593Smuzhiyun cfg19.u32 = 0;
437*4882a593Smuzhiyun /*
438*4882a593Smuzhiyun * Target Delayed/Split request outstanding maximum
439*4882a593Smuzhiyun * count. [1..31] and 0=32. NOTE: If the user
440*4882a593Smuzhiyun * programs these bits beyond the Designed Maximum
441*4882a593Smuzhiyun * outstanding count, then the designed maximum table
442*4882a593Smuzhiyun * depth will be used instead. No additional
443*4882a593Smuzhiyun * Deferred/Split transactions will be accepted if
444*4882a593Smuzhiyun * this outstanding maximum count is
445*4882a593Smuzhiyun * reached. Furthermore, no additional deferred/split
446*4882a593Smuzhiyun * transactions will be accepted if the I/O delay/ I/O
447*4882a593Smuzhiyun * Split Request outstanding maximum is reached.
448*4882a593Smuzhiyun */
449*4882a593Smuzhiyun cfg19.s.tdomc = 4;
450*4882a593Smuzhiyun /*
451*4882a593Smuzhiyun * Master Deferred Read Request Outstanding Max Count
452*4882a593Smuzhiyun * (PCI only). CR4C[26:24] Max SAC cycles MAX DAC
453*4882a593Smuzhiyun * cycles 000 8 4 001 1 0 010 2 1 011 3 1 100 4 2 101
454*4882a593Smuzhiyun * 5 2 110 6 3 111 7 3 For example, if these bits are
455*4882a593Smuzhiyun * programmed to 100, the core can support 2 DAC
456*4882a593Smuzhiyun * cycles, 4 SAC cycles or a combination of 1 DAC and
457*4882a593Smuzhiyun * 2 SAC cycles. NOTE: For the PCI-X maximum
458*4882a593Smuzhiyun * outstanding split transactions, refer to
459*4882a593Smuzhiyun * CRE0[22:20].
460*4882a593Smuzhiyun */
461*4882a593Smuzhiyun cfg19.s.mdrrmc = 2;
462*4882a593Smuzhiyun /*
463*4882a593Smuzhiyun * Master Request (Memory Read) Byte Count/Byte Enable
464*4882a593Smuzhiyun * select. 0 = Byte Enables valid. In PCI mode, a
465*4882a593Smuzhiyun * burst transaction cannot be performed using Memory
466*4882a593Smuzhiyun * Read command=4?h6. 1 = DWORD Byte Count valid
467*4882a593Smuzhiyun * (default). In PCI Mode, the memory read byte
468*4882a593Smuzhiyun * enables are automatically generated by the
469*4882a593Smuzhiyun * core. Note: N3 Master Request transaction sizes are
470*4882a593Smuzhiyun * always determined through the
471*4882a593Smuzhiyun * am_attr[<35:32>|<7:0>] field.
472*4882a593Smuzhiyun */
473*4882a593Smuzhiyun cfg19.s.mrbcm = 1;
474*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG19, cfg19.u32);
475*4882a593Smuzhiyun }
476*4882a593Smuzhiyun
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun cfg01.u32 = 0;
479*4882a593Smuzhiyun cfg01.s.msae = 1; /* Memory Space Access Enable */
480*4882a593Smuzhiyun cfg01.s.me = 1; /* Master Enable */
481*4882a593Smuzhiyun cfg01.s.pee = 1; /* PERR# Enable */
482*4882a593Smuzhiyun cfg01.s.see = 1; /* System Error Enable */
483*4882a593Smuzhiyun cfg01.s.fbbe = 1; /* Fast Back to Back Transaction Enable */
484*4882a593Smuzhiyun
485*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG01, cfg01.u32);
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun #ifdef USE_OCTEON_INTERNAL_ARBITER
488*4882a593Smuzhiyun /*
489*4882a593Smuzhiyun * When OCTEON is a PCI host, most systems will use OCTEON's
490*4882a593Smuzhiyun * internal arbiter, so must enable it before any PCI/PCI-X
491*4882a593Smuzhiyun * traffic can occur.
492*4882a593Smuzhiyun */
493*4882a593Smuzhiyun {
494*4882a593Smuzhiyun union cvmx_npi_pci_int_arb_cfg pci_int_arb_cfg;
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun pci_int_arb_cfg.u64 = 0;
497*4882a593Smuzhiyun pci_int_arb_cfg.s.en = 1; /* Internal arbiter enable */
498*4882a593Smuzhiyun cvmx_write_csr(CVMX_NPI_PCI_INT_ARB_CFG, pci_int_arb_cfg.u64);
499*4882a593Smuzhiyun }
500*4882a593Smuzhiyun #endif /* USE_OCTEON_INTERNAL_ARBITER */
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun /*
503*4882a593Smuzhiyun * Preferably written to 1 to set MLTD. [RDSATI,TRTAE,
504*4882a593Smuzhiyun * TWTAE,TMAE,DPPMR -> must be zero. TILT -> must not be set to
505*4882a593Smuzhiyun * 1..7.
506*4882a593Smuzhiyun */
507*4882a593Smuzhiyun cfg16.u32 = 0;
508*4882a593Smuzhiyun cfg16.s.mltd = 1; /* Master Latency Timer Disable */
509*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG16, cfg16.u32);
510*4882a593Smuzhiyun
511*4882a593Smuzhiyun /*
512*4882a593Smuzhiyun * Should be written to 0x4ff00. MTTV -> must be zero.
513*4882a593Smuzhiyun * FLUSH -> must be 1. MRV -> should be 0xFF.
514*4882a593Smuzhiyun */
515*4882a593Smuzhiyun cfg22.u32 = 0;
516*4882a593Smuzhiyun /* Master Retry Value [1..255] and 0=infinite */
517*4882a593Smuzhiyun cfg22.s.mrv = 0xff;
518*4882a593Smuzhiyun /*
519*4882a593Smuzhiyun * AM_DO_FLUSH_I control NOTE: This bit MUST BE ONE for proper
520*4882a593Smuzhiyun * N3K operation.
521*4882a593Smuzhiyun */
522*4882a593Smuzhiyun cfg22.s.flush = 1;
523*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG22, cfg22.u32);
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun /*
526*4882a593Smuzhiyun * MOST Indicates the maximum number of outstanding splits (in -1
527*4882a593Smuzhiyun * notation) when OCTEON is in PCI-X mode. PCI-X performance is
528*4882a593Smuzhiyun * affected by the MOST selection. Should generally be written
529*4882a593Smuzhiyun * with one of 0x3be807, 0x2be807, 0x1be807, or 0x0be807,
530*4882a593Smuzhiyun * depending on the desired MOST of 3, 2, 1, or 0, respectively.
531*4882a593Smuzhiyun */
532*4882a593Smuzhiyun cfg56.u32 = 0;
533*4882a593Smuzhiyun cfg56.s.pxcid = 7; /* RO - PCI-X Capability ID */
534*4882a593Smuzhiyun cfg56.s.ncp = 0xe8; /* RO - Next Capability Pointer */
535*4882a593Smuzhiyun cfg56.s.dpere = 1; /* Data Parity Error Recovery Enable */
536*4882a593Smuzhiyun cfg56.s.roe = 1; /* Relaxed Ordering Enable */
537*4882a593Smuzhiyun cfg56.s.mmbc = 1; /* Maximum Memory Byte Count
538*4882a593Smuzhiyun [0=512B,1=1024B,2=2048B,3=4096B] */
539*4882a593Smuzhiyun cfg56.s.most = 3; /* Maximum outstanding Split transactions [0=1
540*4882a593Smuzhiyun .. 7=32] */
541*4882a593Smuzhiyun
542*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG56, cfg56.u32);
543*4882a593Smuzhiyun
544*4882a593Smuzhiyun /*
545*4882a593Smuzhiyun * Affects PCI performance when OCTEON services reads to its
546*4882a593Smuzhiyun * BAR1/BAR2. Refer to Section 10.6.1. The recommended values are
547*4882a593Smuzhiyun * 0x22, 0x33, and 0x33 for PCI_READ_CMD_6, PCI_READ_CMD_C, and
548*4882a593Smuzhiyun * PCI_READ_CMD_E, respectively. Unfortunately due to errata DDR-700,
549*4882a593Smuzhiyun * these values need to be changed so they won't possibly prefetch off
550*4882a593Smuzhiyun * of the end of memory if PCI is DMAing a buffer at the end of
551*4882a593Smuzhiyun * memory. Note that these values differ from their reset values.
552*4882a593Smuzhiyun */
553*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_READ_CMD_6, 0x21);
554*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_READ_CMD_C, 0x31);
555*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_READ_CMD_E, 0x31);
556*4882a593Smuzhiyun }
557*4882a593Smuzhiyun
558*4882a593Smuzhiyun
559*4882a593Smuzhiyun /*
560*4882a593Smuzhiyun * Initialize the Octeon PCI controller
561*4882a593Smuzhiyun */
octeon_pci_setup(void)562*4882a593Smuzhiyun static int __init octeon_pci_setup(void)
563*4882a593Smuzhiyun {
564*4882a593Smuzhiyun union cvmx_npi_mem_access_subidx mem_access;
565*4882a593Smuzhiyun int index;
566*4882a593Smuzhiyun
567*4882a593Smuzhiyun /* Only these chips have PCI */
568*4882a593Smuzhiyun if (octeon_has_feature(OCTEON_FEATURE_PCIE))
569*4882a593Smuzhiyun return 0;
570*4882a593Smuzhiyun
571*4882a593Smuzhiyun if (!octeon_is_pci_host()) {
572*4882a593Smuzhiyun pr_notice("Not in host mode, PCI Controller not initialized\n");
573*4882a593Smuzhiyun return 0;
574*4882a593Smuzhiyun }
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun /* Point pcibios_map_irq() to the PCI version of it */
577*4882a593Smuzhiyun octeon_pcibios_map_irq = octeon_pci_pcibios_map_irq;
578*4882a593Smuzhiyun
579*4882a593Smuzhiyun /* Only use the big bars on chips that support it */
580*4882a593Smuzhiyun if (OCTEON_IS_MODEL(OCTEON_CN31XX) ||
581*4882a593Smuzhiyun OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
582*4882a593Smuzhiyun OCTEON_IS_MODEL(OCTEON_CN38XX_PASS1))
583*4882a593Smuzhiyun octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_SMALL;
584*4882a593Smuzhiyun else
585*4882a593Smuzhiyun octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_BIG;
586*4882a593Smuzhiyun
587*4882a593Smuzhiyun /* PCI I/O and PCI MEM values */
588*4882a593Smuzhiyun set_io_port_base(OCTEON_PCI_IOSPACE_BASE);
589*4882a593Smuzhiyun ioport_resource.start = 0;
590*4882a593Smuzhiyun ioport_resource.end = OCTEON_PCI_IOSPACE_SIZE - 1;
591*4882a593Smuzhiyun
592*4882a593Smuzhiyun pr_notice("%s Octeon big bar support\n",
593*4882a593Smuzhiyun (octeon_dma_bar_type ==
594*4882a593Smuzhiyun OCTEON_DMA_BAR_TYPE_BIG) ? "Enabling" : "Disabling");
595*4882a593Smuzhiyun
596*4882a593Smuzhiyun octeon_pci_initialize();
597*4882a593Smuzhiyun
598*4882a593Smuzhiyun mem_access.u64 = 0;
599*4882a593Smuzhiyun mem_access.s.esr = 1; /* Endian-Swap on read. */
600*4882a593Smuzhiyun mem_access.s.esw = 1; /* Endian-Swap on write. */
601*4882a593Smuzhiyun mem_access.s.nsr = 0; /* No-Snoop on read. */
602*4882a593Smuzhiyun mem_access.s.nsw = 0; /* No-Snoop on write. */
603*4882a593Smuzhiyun mem_access.s.ror = 0; /* Relax Read on read. */
604*4882a593Smuzhiyun mem_access.s.row = 0; /* Relax Order on write. */
605*4882a593Smuzhiyun mem_access.s.ba = 0; /* PCI Address bits [63:36]. */
606*4882a593Smuzhiyun cvmx_write_csr(CVMX_NPI_MEM_ACCESS_SUBID3, mem_access.u64);
607*4882a593Smuzhiyun
608*4882a593Smuzhiyun /*
609*4882a593Smuzhiyun * Remap the Octeon BAR 2 above all 32 bit devices
610*4882a593Smuzhiyun * (0x8000000000ul). This is done here so it is remapped
611*4882a593Smuzhiyun * before the readl()'s below. We don't want BAR2 overlapping
612*4882a593Smuzhiyun * with BAR0/BAR1 during these reads.
613*4882a593Smuzhiyun */
614*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG08,
615*4882a593Smuzhiyun (u32)(OCTEON_BAR2_PCI_ADDRESS & 0xffffffffull));
616*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG09,
617*4882a593Smuzhiyun (u32)(OCTEON_BAR2_PCI_ADDRESS >> 32));
618*4882a593Smuzhiyun
619*4882a593Smuzhiyun if (octeon_dma_bar_type == OCTEON_DMA_BAR_TYPE_BIG) {
620*4882a593Smuzhiyun /* Remap the Octeon BAR 0 to 0-2GB */
621*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG04, 0);
622*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG05, 0);
623*4882a593Smuzhiyun
624*4882a593Smuzhiyun /*
625*4882a593Smuzhiyun * Remap the Octeon BAR 1 to map 2GB-4GB (minus the
626*4882a593Smuzhiyun * BAR 1 hole).
627*4882a593Smuzhiyun */
628*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG06, 2ul << 30);
629*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG07, 0);
630*4882a593Smuzhiyun
631*4882a593Smuzhiyun /* BAR1 movable mappings set for identity mapping */
632*4882a593Smuzhiyun octeon_bar1_pci_phys = 0x80000000ull;
633*4882a593Smuzhiyun for (index = 0; index < 32; index++) {
634*4882a593Smuzhiyun union cvmx_pci_bar1_indexx bar1_index;
635*4882a593Smuzhiyun
636*4882a593Smuzhiyun bar1_index.u32 = 0;
637*4882a593Smuzhiyun /* Address bits[35:22] sent to L2C */
638*4882a593Smuzhiyun bar1_index.s.addr_idx =
639*4882a593Smuzhiyun (octeon_bar1_pci_phys >> 22) + index;
640*4882a593Smuzhiyun /* Don't put PCI accesses in L2. */
641*4882a593Smuzhiyun bar1_index.s.ca = 1;
642*4882a593Smuzhiyun /* Endian Swap Mode */
643*4882a593Smuzhiyun bar1_index.s.end_swp = 1;
644*4882a593Smuzhiyun /* Set '1' when the selected address range is valid. */
645*4882a593Smuzhiyun bar1_index.s.addr_v = 1;
646*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_BAR1_INDEXX(index),
647*4882a593Smuzhiyun bar1_index.u32);
648*4882a593Smuzhiyun }
649*4882a593Smuzhiyun
650*4882a593Smuzhiyun /* Devices go after BAR1 */
651*4882a593Smuzhiyun octeon_pci_mem_resource.start =
652*4882a593Smuzhiyun OCTEON_PCI_MEMSPACE_OFFSET + (4ul << 30) -
653*4882a593Smuzhiyun (OCTEON_PCI_BAR1_HOLE_SIZE << 20);
654*4882a593Smuzhiyun octeon_pci_mem_resource.end =
655*4882a593Smuzhiyun octeon_pci_mem_resource.start + (1ul << 30);
656*4882a593Smuzhiyun } else {
657*4882a593Smuzhiyun /* Remap the Octeon BAR 0 to map 128MB-(128MB+4KB) */
658*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG04, 128ul << 20);
659*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG05, 0);
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun /* Remap the Octeon BAR 1 to map 0-128MB */
662*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG06, 0);
663*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_CFG07, 0);
664*4882a593Smuzhiyun
665*4882a593Smuzhiyun /* BAR1 movable regions contiguous to cover the swiotlb */
666*4882a593Smuzhiyun octeon_bar1_pci_phys =
667*4882a593Smuzhiyun virt_to_phys(octeon_swiotlb) & ~((1ull << 22) - 1);
668*4882a593Smuzhiyun
669*4882a593Smuzhiyun for (index = 0; index < 32; index++) {
670*4882a593Smuzhiyun union cvmx_pci_bar1_indexx bar1_index;
671*4882a593Smuzhiyun
672*4882a593Smuzhiyun bar1_index.u32 = 0;
673*4882a593Smuzhiyun /* Address bits[35:22] sent to L2C */
674*4882a593Smuzhiyun bar1_index.s.addr_idx =
675*4882a593Smuzhiyun (octeon_bar1_pci_phys >> 22) + index;
676*4882a593Smuzhiyun /* Don't put PCI accesses in L2. */
677*4882a593Smuzhiyun bar1_index.s.ca = 1;
678*4882a593Smuzhiyun /* Endian Swap Mode */
679*4882a593Smuzhiyun bar1_index.s.end_swp = 1;
680*4882a593Smuzhiyun /* Set '1' when the selected address range is valid. */
681*4882a593Smuzhiyun bar1_index.s.addr_v = 1;
682*4882a593Smuzhiyun octeon_npi_write32(CVMX_NPI_PCI_BAR1_INDEXX(index),
683*4882a593Smuzhiyun bar1_index.u32);
684*4882a593Smuzhiyun }
685*4882a593Smuzhiyun
686*4882a593Smuzhiyun /* Devices go after BAR0 */
687*4882a593Smuzhiyun octeon_pci_mem_resource.start =
688*4882a593Smuzhiyun OCTEON_PCI_MEMSPACE_OFFSET + (128ul << 20) +
689*4882a593Smuzhiyun (4ul << 10);
690*4882a593Smuzhiyun octeon_pci_mem_resource.end =
691*4882a593Smuzhiyun octeon_pci_mem_resource.start + (1ul << 30);
692*4882a593Smuzhiyun }
693*4882a593Smuzhiyun
694*4882a593Smuzhiyun register_pci_controller(&octeon_pci_controller);
695*4882a593Smuzhiyun
696*4882a593Smuzhiyun /*
697*4882a593Smuzhiyun * Clear any errors that might be pending from before the bus
698*4882a593Smuzhiyun * was setup properly.
699*4882a593Smuzhiyun */
700*4882a593Smuzhiyun cvmx_write_csr(CVMX_NPI_PCI_INT_SUM2, -1);
701*4882a593Smuzhiyun
702*4882a593Smuzhiyun if (IS_ERR(platform_device_register_simple("octeon_pci_edac",
703*4882a593Smuzhiyun -1, NULL, 0)))
704*4882a593Smuzhiyun pr_err("Registration of co_pci_edac failed!\n");
705*4882a593Smuzhiyun
706*4882a593Smuzhiyun octeon_pci_dma_init();
707*4882a593Smuzhiyun
708*4882a593Smuzhiyun return 0;
709*4882a593Smuzhiyun }
710*4882a593Smuzhiyun
711*4882a593Smuzhiyun arch_initcall(octeon_pci_setup);
712