kernel: update linux 3.2 to 3.2.15
[openwrt.git] / target / linux / lantiq / patches-3.2 / 0054-MIPS-lantiq-pcie-add-pcie-driver.patch
1 From ab91bdfb7d8dbeebe4594b96cf81721f97012d24 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Thu, 8 Mar 2012 15:57:33 +0100
4 Subject: [PATCH 54/73]  MIPS: lantiq: pcie: add pcie driver
5
6 ---
7  arch/mips/Kconfig                 |    1 +
8  arch/mips/lantiq/Kconfig          |    4 -
9  arch/mips/lantiq/xway/Kconfig     |   21 +
10  arch/mips/pci/Makefile            |    2 +
11  arch/mips/pci/fixup-lantiq-pcie.c |   81 +++
12  arch/mips/pci/pci.c               |   25 +
13  arch/mips/pci/pcie-lantiq-msi.c   |  399 +++++++++++
14  arch/mips/pci/pcie-lantiq-phy.c   |  408 ++++++++++++
15  arch/mips/pci/pcie-lantiq.c       | 1146 ++++++++++++++++++++++++++++++++
16  arch/mips/pci/pcie-lantiq.h       | 1305 +++++++++++++++++++++++++++++++++++++
17  10 files changed, 3388 insertions(+), 4 deletions(-)
18  create mode 100644 arch/mips/pci/fixup-lantiq-pcie.c
19  create mode 100644 arch/mips/pci/pcie-lantiq-msi.c
20  create mode 100644 arch/mips/pci/pcie-lantiq-phy.c
21  create mode 100644 arch/mips/pci/pcie-lantiq.c
22  create mode 100644 arch/mips/pci/pcie-lantiq.h
23
24 --- a/arch/mips/Kconfig
25 +++ b/arch/mips/Kconfig
26 @@ -2353,6 +2353,7 @@ config PCI_DOMAINS
27         bool
28  
29  source "drivers/pci/Kconfig"
30 +source "drivers/pci/pcie/Kconfig"
31  
32  #
33  # ISA support is now enabled via select.  Too many systems still have the one
34 --- a/arch/mips/lantiq/Kconfig
35 +++ b/arch/mips/lantiq/Kconfig
36 @@ -22,10 +22,6 @@ config SOC_FALCON
37  
38  endchoice
39  
40 -config PCI_LANTIQ
41 -       bool "PCI Support"
42 -       depends on SOC_XWAY && PCI
43 -
44  source "arch/mips/lantiq/xway/Kconfig"
45  source "arch/mips/lantiq/falcon/Kconfig"
46  
47 --- a/arch/mips/lantiq/xway/Kconfig
48 +++ b/arch/mips/lantiq/xway/Kconfig
49 @@ -8,6 +8,27 @@ config LANTIQ_MACH_EASY50712
50  
51  endmenu
52  
53 +choice
54 +       prompt "PCI"
55 +       default PCI_LANTIQ_NONE
56 +
57 +config PCI_LANTIQ_NONE
58 +       bool "None"
59 +
60 +config PCI_LANTIQ
61 +       bool "PCI Support"
62 +       depends on PCI
63 +
64 +config PCIE_LANTIQ
65 +       bool "PCIE Support"
66 +       select ARCH_SUPPORTS_MSI
67 +
68 +endchoice
69 +
70 +config PCIE_LANTIQ_MSI
71 +       bool
72 +       depends on PCIE_LANTIQ && PCI_MSI
73 +       default y
74  endif
75  
76  if SOC_AMAZON_SE
77 --- a/arch/mips/pci/Makefile
78 +++ b/arch/mips/pci/Makefile
79 @@ -42,6 +42,8 @@ obj-$(CONFIG_SIBYTE_BCM1x80)  += pci-bcm1
80  obj-$(CONFIG_SNI_RM)           += fixup-sni.o ops-sni.o
81  obj-$(CONFIG_LANTIQ)           += fixup-lantiq.o
82  obj-$(CONFIG_PCI_LANTIQ)       += pci-lantiq.o ops-lantiq.o
83 +obj-$(CONFIG_PCIE_LANTIQ)      += pcie-lantiq-phy.o pcie-lantiq.o fixup-lantiq-pcie.o
84 +obj-$(CONFIG_PCIE_LANTIQ_MSI)  += pcie-lantiq-msi.o
85  obj-$(CONFIG_TANBAC_TB0219)    += fixup-tb0219.o
86  obj-$(CONFIG_TANBAC_TB0226)    += fixup-tb0226.o
87  obj-$(CONFIG_TANBAC_TB0287)    += fixup-tb0287.o
88 --- /dev/null
89 +++ b/arch/mips/pci/fixup-lantiq-pcie.c
90 @@ -0,0 +1,81 @@
91 +/******************************************************************************
92 +**
93 +** FILE NAME    : ifxmips_fixup_pcie.c
94 +** PROJECT      : IFX UEIP for VRX200
95 +** MODULES      : PCIe 
96 +**
97 +** DATE         : 02 Mar 2009
98 +** AUTHOR       : Lei Chuanhua
99 +** DESCRIPTION  : PCIe Root Complex Driver
100 +** COPYRIGHT    :       Copyright (c) 2009
101 +**                      Infineon Technologies AG
102 +**                      Am Campeon 1-12, 85579 Neubiberg, Germany
103 +**
104 +**    This program is free software; you can redistribute it and/or modify
105 +**    it under the terms of the GNU General Public License as published by
106 +**    the Free Software Foundation; either version 2 of the License, or
107 +**    (at your option) any later version.
108 +** HISTORY
109 +** $Version $Date        $Author         $Comment
110 +** 0.0.1    17 Mar,2009  Lei Chuanhua    Initial version
111 +*******************************************************************************/
112 +/*!
113 + \file ifxmips_fixup_pcie.c
114 + \ingroup IFX_PCIE  
115 + \brief PCIe Fixup functions source file
116 +*/
117 +#include <linux/pci.h>
118 +#include <linux/pci_regs.h>
119 +#include <linux/pci_ids.h>
120 +
121 +#include <lantiq_soc.h>
122 +
123 +#include "pcie-lantiq.h"
124 +
125 +#define PCI_VENDOR_ID_INFINEON         0x15D1
126 +#define PCI_DEVICE_ID_INFINEON_DANUBE  0x000F
127 +#define PCI_DEVICE_ID_INFINEON_PCIE    0x0011
128 +#define PCI_VENDOR_ID_LANTIQ        0x1BEF
129 +#define PCI_DEVICE_ID_LANTIQ_PCIE       0x0011
130 +
131 +
132 +
133 +static void __devinit
134 +ifx_pcie_fixup_resource(struct pci_dev *dev)
135 +{
136 +    u32 reg;
137 +
138 +    IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: enter\n", __func__, pci_name(dev));
139 +
140 +    IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s: fixup host controller %s (%04x:%04x)\n", 
141 +        __func__, pci_name(dev), dev->vendor, dev->device); 
142 +
143 +   /* Setup COMMAND register */
144 +    reg = PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER /* | 
145 +          PCI_COMMAND_INTX_DISABLE */| PCI_COMMAND_SERR;
146 +    pci_write_config_word(dev, PCI_COMMAND, reg);
147 +    IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: exit\n", __func__, pci_name(dev));
148 +}
149 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INFINEON, PCI_DEVICE_ID_INFINEON_PCIE, ifx_pcie_fixup_resource);
150 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_LANTIQ, PCI_VENDOR_ID_LANTIQ, ifx_pcie_fixup_resource);
151 +
152 +static void __devinit
153 +ifx_pcie_rc_class_early_fixup(struct pci_dev *dev)
154 +{
155 +    IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: enter\n", __func__, pci_name(dev));
156 +
157 +    if (dev->devfn == PCI_DEVFN(0, 0) &&
158 +        (dev->class >> 8) == PCI_CLASS_BRIDGE_HOST) {
159 +
160 +        dev->class = (PCI_CLASS_BRIDGE_PCI << 8) | (dev->class & 0xff);
161 +
162 +        printk(KERN_INFO "%s: fixed pcie host bridge to pci-pci bridge\n", __func__);
163 +    }
164 +    IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: exit\n", __func__, pci_name(dev));
165 +}
166 +
167 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INFINEON, PCI_DEVICE_ID_INFINEON_PCIE,
168 +     ifx_pcie_rc_class_early_fixup);
169 +
170 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_LANTIQ, PCI_DEVICE_ID_LANTIQ_PCIE,
171 +     ifx_pcie_rc_class_early_fixup);
172 --- a/arch/mips/pci/pci.c
173 +++ b/arch/mips/pci/pci.c
174 @@ -167,6 +167,31 @@ static int __init pcibios_init(void)
175  
176  subsys_initcall(pcibios_init);
177  
178 +int pcibios_host_nr(void)
179 +{
180 +    int count;
181 +    struct pci_controller *hose;
182 +    for (count = 0, hose = hose_head; hose; hose = hose->next, count++) {
183 +        ;
184 +    }
185 +    return count;
186 +}
187 +EXPORT_SYMBOL(pcibios_host_nr);
188 +
189 +int pcibios_1st_host_bus_nr(void)
190 +{
191 +    int bus_nr = 0;
192 +    struct pci_controller *hose = hose_head;
193 +
194 +    if (hose != NULL) {
195 +        if (hose->bus != NULL) {
196 +            bus_nr = hose->bus->subordinate + 1;
197 +        }
198 +    }
199 +    return bus_nr;
200 +}
201 +EXPORT_SYMBOL(pcibios_1st_host_bus_nr);
202 +
203  static int pcibios_enable_resources(struct pci_dev *dev, int mask)
204  {
205         u16 cmd, old_cmd;
206 --- /dev/null
207 +++ b/arch/mips/pci/pcie-lantiq-msi.c
208 @@ -0,0 +1,399 @@
209 +/******************************************************************************
210 +**
211 +** FILE NAME    : ifxmips_pcie_msi.c
212 +** PROJECT      : IFX UEIP for VRX200
213 +** MODULES      : PCI MSI sub module
214 +**
215 +** DATE         : 02 Mar 2009
216 +** AUTHOR       : Lei Chuanhua
217 +** DESCRIPTION  : PCIe MSI Driver
218 +** COPYRIGHT    :       Copyright (c) 2009
219 +**                      Infineon Technologies AG
220 +**                      Am Campeon 1-12, 85579 Neubiberg, Germany
221 +**
222 +**    This program is free software; you can redistribute it and/or modify
223 +**    it under the terms of the GNU General Public License as published by
224 +**    the Free Software Foundation; either version 2 of the License, or
225 +**    (at your option) any later version.
226 +** HISTORY
227 +** $Date        $Author         $Comment
228 +** 02 Mar,2009  Lei Chuanhua    Initial version
229 +*******************************************************************************/
230 +/*!
231 + \defgroup IFX_PCIE_MSI MSI OS APIs
232 + \ingroup IFX_PCIE
233 + \brief PCIe bus driver OS interface functions
234 +*/
235 +
236 +/*!
237 + \file ifxmips_pcie_msi.c
238 + \ingroup IFX_PCIE 
239 + \brief PCIe MSI OS interface file
240 +*/
241 +
242 +#include <linux/init.h>
243 +#include <linux/sched.h>
244 +#include <linux/slab.h>
245 +#include <linux/interrupt.h>
246 +#include <linux/kernel_stat.h>
247 +#include <linux/pci.h>
248 +#include <linux/msi.h>
249 +#include <linux/module.h>
250 +#include <asm/bootinfo.h>
251 +#include <asm/irq.h>
252 +#include <asm/traps.h>
253 +
254 +#include "pcie-lantiq.h"
255 +
256 +#define IFX_MSI_IRQ_NUM    16
257 +#define SM(_v, _f)             (((_v) << _f##_S) & (_f))
258 +
259 +#define IFX_MSI_PIC_REG_BASE                    (KSEG1 | 0x1F700000)
260 +#define IFX_PCIE_MSI_IR0                (INT_NUM_IM4_IRL0 + 27)
261 +#define IFX_PCIE_MSI_IR1                (INT_NUM_IM4_IRL0 + 28)
262 +#define IFX_PCIE_MSI_IR2                (INT_NUM_IM4_IRL0 + 29)
263 +#define IFX_PCIE_MSI_IR3                (INT_NUM_IM0_IRL0 + 30)
264 +
265 +#define IFX_MSI_PCI_INT_DISABLE                 0x80000000
266 +#define IFX_MSI_PIC_INT_LINE                    0x30000000
267 +#define IFX_MSI_PIC_MSG_ADDR                    0x0FFF0000
268 +#define IFX_MSI_PIC_MSG_DATA                    0x0000FFFF
269 +#define IFX_MSI_PIC_BIG_ENDIAN                  1
270 +#define IFX_MSI_PIC_INT_LINE_S                  28
271 +#define IFX_MSI_PIC_MSG_ADDR_S                  16
272 +#define IFX_MSI_PIC_MSG_DATA_S                  0x0
273 +
274 +enum {
275 +    IFX_PCIE_MSI_IDX0 = 0,
276 +    IFX_PCIE_MSI_IDX1,
277 +    IFX_PCIE_MSI_IDX2,
278 +    IFX_PCIE_MSI_IDX3,
279 +};
280 +
281 +typedef struct ifx_msi_irq_idx {
282 +    const int irq;
283 +    const int idx;
284 +}ifx_msi_irq_idx_t;
285 +
286 +struct ifx_msi_pic {
287 +    volatile u32  pic_table[IFX_MSI_IRQ_NUM];
288 +    volatile u32  pic_endian;    /* 0x40  */
289 +};
290 +typedef struct ifx_msi_pic *ifx_msi_pic_t;
291 +
292 +typedef struct ifx_msi_irq {
293 +    const volatile ifx_msi_pic_t msi_pic_p;
294 +    const u32 msi_phy_base;
295 +    const ifx_msi_irq_idx_t msi_irq_idx[IFX_MSI_IRQ_NUM];
296 +    /*
297 +     * Each bit in msi_free_irq_bitmask represents a MSI interrupt that is 
298 +     * in use.
299 +     */
300 +    u16 msi_free_irq_bitmask;
301 +
302 +    /*
303 +     * Each bit in msi_multiple_irq_bitmask tells that the device using 
304 +     * this bit in msi_free_irq_bitmask is also using the next bit. This 
305 +     * is used so we can disable all of the MSI interrupts when a device 
306 +     * uses multiple.
307 +     */
308 +    u16 msi_multiple_irq_bitmask;
309 +}ifx_msi_irq_t;
310 +
311 +static ifx_msi_irq_t msi_irqs[IFX_PCIE_CORE_NR] = {
312 +    {
313 +        .msi_pic_p = (const volatile ifx_msi_pic_t)IFX_MSI_PIC_REG_BASE,
314 +        .msi_phy_base = PCIE_MSI_PHY_BASE,
315 +        .msi_irq_idx = {
316 +            {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
317 +            {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
318 +            {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
319 +            {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
320 +            {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
321 +            {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
322 +            {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
323 +            {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
324 +        },
325 +        .msi_free_irq_bitmask = 0,
326 +        .msi_multiple_irq_bitmask= 0,
327 +    },
328 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
329 +    {
330 +        .msi_pic_p = (const volatile ifx_msi_pic_t)IFX_MSI1_PIC_REG_BASE,
331 +        .msi_phy_base = PCIE1_MSI_PHY_BASE,
332 +        .msi_irq_idx = {
333 +            {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
334 +            {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
335 +            {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
336 +            {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
337 +            {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
338 +            {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
339 +            {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
340 +            {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
341 +        },
342 +        .msi_free_irq_bitmask = 0,
343 +        .msi_multiple_irq_bitmask= 0,
344 +
345 +    },
346 +#endif /* CONFIG_IFX_PCIE_2ND_CORE */
347 +};
348 +
349 +/* 
350 + * This lock controls updates to msi_free_irq_bitmask, 
351 + * msi_multiple_irq_bitmask and pic register settting
352 + */ 
353 +static DEFINE_SPINLOCK(ifx_pcie_msi_lock);
354 +
355 +void pcie_msi_pic_init(int pcie_port)
356 +{
357 +    spin_lock(&ifx_pcie_msi_lock);
358 +    msi_irqs[pcie_port].msi_pic_p->pic_endian = IFX_MSI_PIC_BIG_ENDIAN;
359 +    spin_unlock(&ifx_pcie_msi_lock);
360 +}
361 +
362 +/** 
363 + * \fn int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
364 + * \brief Called when a driver request MSI interrupts instead of the 
365 + * legacy INT A-D. This routine will allocate multiple interrupts 
366 + * for MSI devices that support them. A device can override this by 
367 + * programming the MSI control bits [6:4] before calling 
368 + * pci_enable_msi(). 
369 + * 
370 + * \param[in] pdev   Device requesting MSI interrupts 
371 + * \param[in] desc   MSI descriptor 
372 + * 
373 + * \return   -EINVAL Invalid pcie root port or invalid msi bit
374 + * \return    0        OK
375 + * \ingroup IFX_PCIE_MSI
376 + */
377 +int 
378 +arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
379 +{
380 +    int  irq, pos;
381 +    u16  control;
382 +    int  irq_idx;
383 +    int  irq_step;
384 +    int configured_private_bits;
385 +    int request_private_bits;
386 +    struct msi_msg msg;
387 +    u16 search_mask;
388 +    struct ifx_pci_controller *ctrl = pdev->bus->sysdata;
389 +    int pcie_port = ctrl->port;
390 +
391 +    IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s %s enter\n", __func__, pci_name(pdev));
392 +
393 +    /* XXX, skip RC MSI itself */
394 +    if (pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) {
395 +        IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s RC itself doesn't use MSI interrupt\n", __func__);
396 +        return -EINVAL;
397 +    }
398 +
399 +    /*
400 +     * Read the MSI config to figure out how many IRQs this device 
401 +     * wants.  Most devices only want 1, which will give 
402 +     * configured_private_bits and request_private_bits equal 0. 
403 +     */
404 +    pci_read_config_word(pdev, desc->msi_attrib.pos + PCI_MSI_FLAGS, &control);
405 +
406 +    /*
407 +     * If the number of private bits has been configured then use 
408 +     * that value instead of the requested number. This gives the 
409 +     * driver the chance to override the number of interrupts 
410 +     * before calling pci_enable_msi(). 
411 +     */
412 +    configured_private_bits = (control & PCI_MSI_FLAGS_QSIZE) >> 4; 
413 +    if (configured_private_bits == 0) {
414 +        /* Nothing is configured, so use the hardware requested size */
415 +        request_private_bits = (control & PCI_MSI_FLAGS_QMASK) >> 1;
416 +    }
417 +    else {
418 +        /*
419 +         * Use the number of configured bits, assuming the 
420 +         * driver wanted to override the hardware request 
421 +         * value.
422 +         */
423 +        request_private_bits = configured_private_bits;
424 +    }
425 +
426 +    /*
427 +     * The PCI 2.3 spec mandates that there are at most 32
428 +     * interrupts. If this device asks for more, only give it one.
429 +     */
430 +    if (request_private_bits > 5) {
431 +        request_private_bits = 0;
432 +    }
433 +again:
434 +    /*
435 +     * The IRQs have to be aligned on a power of two based on the
436 +     * number being requested.
437 +     */
438 +    irq_step = (1 << request_private_bits);
439 +
440 +    /* Mask with one bit for each IRQ */
441 +    search_mask = (1 << irq_step) - 1;
442 +
443 +    /*
444 +     * We're going to search msi_free_irq_bitmask_lock for zero 
445 +     * bits. This represents an MSI interrupt number that isn't in 
446 +     * use.
447 +     */
448 +    spin_lock(&ifx_pcie_msi_lock);
449 +    for (pos = 0; pos < IFX_MSI_IRQ_NUM; pos += irq_step) {
450 +        if ((msi_irqs[pcie_port].msi_free_irq_bitmask & (search_mask << pos)) == 0) {
451 +            msi_irqs[pcie_port].msi_free_irq_bitmask |= search_mask << pos; 
452 +            msi_irqs[pcie_port].msi_multiple_irq_bitmask |= (search_mask >> 1) << pos;
453 +            break; 
454 +        }
455 +    }
456 +    spin_unlock(&ifx_pcie_msi_lock); 
457 +
458 +    /* Make sure the search for available interrupts didn't fail */ 
459 +    if (pos >= IFX_MSI_IRQ_NUM) {
460 +        if (request_private_bits) {
461 +            IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s: Unable to find %d free "
462 +                  "interrupts, trying just one", __func__, 1 << request_private_bits);
463 +            request_private_bits = 0;
464 +            goto again;
465 +        }
466 +        else {
467 +            printk(KERN_ERR "%s: Unable to find a free MSI interrupt\n", __func__);
468 +            return -EINVAL;
469 +        }
470 +    } 
471 +    irq = msi_irqs[pcie_port].msi_irq_idx[pos].irq;
472 +    irq_idx = msi_irqs[pcie_port].msi_irq_idx[pos].idx;
473 +
474 +    IFX_PCIE_PRINT(PCIE_MSG_MSI, "pos %d, irq %d irq_idx %d\n", pos, irq, irq_idx);
475 +
476 +    /*
477 +     * Initialize MSI. This has to match the memory-write endianess from the device 
478 +     * Address bits [23:12]
479 +     */
480 +    spin_lock(&ifx_pcie_msi_lock); 
481 +    msi_irqs[pcie_port].msi_pic_p->pic_table[pos] = SM(irq_idx, IFX_MSI_PIC_INT_LINE) |
482 +                    SM((msi_irqs[pcie_port].msi_phy_base >> 12), IFX_MSI_PIC_MSG_ADDR) |
483 +                    SM((1 << pos), IFX_MSI_PIC_MSG_DATA);
484 +
485 +    /* Enable this entry */
486 +    msi_irqs[pcie_port].msi_pic_p->pic_table[pos] &= ~IFX_MSI_PCI_INT_DISABLE;
487 +    spin_unlock(&ifx_pcie_msi_lock);
488 +
489 +    IFX_PCIE_PRINT(PCIE_MSG_MSI, "pic_table[%d]: 0x%08x\n",
490 +        pos, msi_irqs[pcie_port].msi_pic_p->pic_table[pos]);
491 +
492 +    /* Update the number of IRQs the device has available to it */
493 +    control &= ~PCI_MSI_FLAGS_QSIZE;
494 +    control |= (request_private_bits << 4);
495 +    pci_write_config_word(pdev, desc->msi_attrib.pos + PCI_MSI_FLAGS, control);
496 +
497 +    irq_set_msi_desc(irq, desc);
498 +    msg.address_hi = 0x0;
499 +    msg.address_lo = msi_irqs[pcie_port].msi_phy_base;
500 +    msg.data = SM((1 << pos), IFX_MSI_PIC_MSG_DATA);
501 +    IFX_PCIE_PRINT(PCIE_MSG_MSI, "msi_data: pos %d 0x%08x\n", pos, msg.data);
502 +
503 +    write_msi_msg(irq, &msg);
504 +    IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s exit\n", __func__);
505 +    return 0;
506 +}
507 +
508 +static int
509 +pcie_msi_irq_to_port(unsigned int irq, int *port)
510 +{
511 +    int ret = 0;
512 +
513 +    if (irq == IFX_PCIE_MSI_IR0 || irq == IFX_PCIE_MSI_IR1 ||
514 +        irq == IFX_PCIE_MSI_IR2 || irq == IFX_PCIE_MSI_IR3) {
515 +        *port = IFX_PCIE_PORT0;
516 +    }
517 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
518 +    else if (irq == IFX_PCIE1_MSI_IR0 || irq == IFX_PCIE1_MSI_IR1 ||
519 +        irq == IFX_PCIE1_MSI_IR2 || irq == IFX_PCIE1_MSI_IR3) {
520 +        *port = IFX_PCIE_PORT1;
521 +    }
522 +#endif /* CONFIG_IFX_PCIE_2ND_CORE */
523 +    else {
524 +        printk(KERN_ERR "%s: Attempted to teardown illegal " 
525 +            "MSI interrupt (%d)\n", __func__, irq);
526 +        ret = -EINVAL;
527 +    }
528 +    return ret;
529 +}
530 +
531 +/** 
532 + * \fn void arch_teardown_msi_irq(unsigned int irq)
533 + * \brief Called when a device no longer needs its MSI interrupts. All 
534 + * MSI interrupts for the device are freed. 
535 + * 
536 + * \param irq   The devices first irq number. There may be multple in sequence.
537 + * \return none
538 + * \ingroup IFX_PCIE_MSI
539 + */
540 +void 
541 +arch_teardown_msi_irq(unsigned int irq)
542 +{
543 +    int pos;
544 +    int number_irqs; 
545 +    u16 bitmask;
546 +    int pcie_port;
547 +
548 +    IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s enter\n", __func__);
549 +
550 +    BUG_ON(irq > (INT_NUM_IM4_IRL0 + 31));
551 +
552 +    if (pcie_msi_irq_to_port(irq, &pcie_port) != 0) {
553 +        return;
554 +    }
555 +
556 +    /* Shift the mask to the correct bit location, not always correct 
557 +     * Probally, the first match will be chosen.
558 +     */
559 +    for (pos = 0; pos < IFX_MSI_IRQ_NUM; pos++) {
560 +        if ((msi_irqs[pcie_port].msi_irq_idx[pos].irq == irq) 
561 +            && (msi_irqs[pcie_port].msi_free_irq_bitmask & ( 1 << pos))) {
562 +            break;
563 +        }
564 +    }
565 +    if (pos >= IFX_MSI_IRQ_NUM) {
566 +        printk(KERN_ERR "%s: Unable to find a matched MSI interrupt\n", __func__);
567 +        return;
568 +    }
569 +    spin_lock(&ifx_pcie_msi_lock);
570 +    /* Disable this entry */
571 +    msi_irqs[pcie_port].msi_pic_p->pic_table[pos] |= IFX_MSI_PCI_INT_DISABLE;
572 +    msi_irqs[pcie_port].msi_pic_p->pic_table[pos] &= ~(IFX_MSI_PIC_INT_LINE | IFX_MSI_PIC_MSG_ADDR | IFX_MSI_PIC_MSG_DATA);
573 +    spin_unlock(&ifx_pcie_msi_lock); 
574 +    /*
575 +     * Count the number of IRQs we need to free by looking at the
576 +     * msi_multiple_irq_bitmask. Each bit set means that the next
577 +     * IRQ is also owned by this device.
578 +     */ 
579 +    number_irqs = 0; 
580 +    while (((pos + number_irqs) < IFX_MSI_IRQ_NUM) && 
581 +        (msi_irqs[pcie_port].msi_multiple_irq_bitmask & (1 << (pos + number_irqs)))) {
582 +        number_irqs++;
583 +    }
584 +    number_irqs++;
585 +
586 +    /* Mask with one bit for each IRQ */
587 +    bitmask = (1 << number_irqs) - 1;
588 +
589 +    bitmask <<= pos;
590 +    if ((msi_irqs[pcie_port].msi_free_irq_bitmask & bitmask) != bitmask) {
591 +        printk(KERN_ERR "%s: Attempted to teardown MSI "
592 +             "interrupt (%d) not in use\n", __func__, irq);
593 +        return;
594 +    }
595 +    /* Checks are done, update the in use bitmask */
596 +    spin_lock(&ifx_pcie_msi_lock);
597 +    msi_irqs[pcie_port].msi_free_irq_bitmask &= ~bitmask;
598 +    msi_irqs[pcie_port].msi_multiple_irq_bitmask &= ~(bitmask >> 1);
599 +    spin_unlock(&ifx_pcie_msi_lock);
600 +    IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s exit\n", __func__);
601 +}
602 +
603 +MODULE_LICENSE("GPL");
604 +MODULE_AUTHOR("Chuanhua.Lei@infineon.com");
605 +MODULE_SUPPORTED_DEVICE("Infineon PCIe IP builtin MSI PIC module");
606 +MODULE_DESCRIPTION("Infineon PCIe IP builtin MSI PIC driver");
607 +
608 --- /dev/null
609 +++ b/arch/mips/pci/pcie-lantiq-phy.c
610 @@ -0,0 +1,408 @@
611 +/******************************************************************************
612 +**
613 +** FILE NAME    : ifxmips_pcie_phy.c
614 +** PROJECT      : IFX UEIP for VRX200
615 +** MODULES      : PCIe PHY sub module
616 +**
617 +** DATE         : 14 May 2009
618 +** AUTHOR       : Lei Chuanhua
619 +** DESCRIPTION  : PCIe Root Complex Driver
620 +** COPYRIGHT    :       Copyright (c) 2009
621 +**                      Infineon Technologies AG
622 +**                      Am Campeon 1-12, 85579 Neubiberg, Germany
623 +**
624 +**    This program is free software; you can redistribute it and/or modify
625 +**    it under the terms of the GNU General Public License as published by
626 +**    the Free Software Foundation; either version 2 of the License, or
627 +**    (at your option) any later version.
628 +** HISTORY
629 +** $Version $Date        $Author         $Comment
630 +** 0.0.1    14 May,2009  Lei Chuanhua    Initial version
631 +*******************************************************************************/
632 +/*!
633 + \file ifxmips_pcie_phy.c
634 + \ingroup IFX_PCIE  
635 + \brief PCIe PHY PLL register programming source file
636 +*/
637 +#include <linux/types.h>
638 +#include <linux/kernel.h>
639 +#include <asm/paccess.h>
640 +#include <linux/delay.h>
641 +
642 +#include "pcie-lantiq.h"
643 +
644 +/* PCIe PDI only supports 16 bit operation */
645 +
646 +#define IFX_PCIE_PHY_REG_WRITE16(__addr, __data) \
647 +    ((*(volatile u16 *) (__addr)) = (__data))
648 +    
649 +#define IFX_PCIE_PHY_REG_READ16(__addr)  \
650 +    (*(volatile u16 *) (__addr))
651 +
652 +#define IFX_PCIE_PHY_REG16(__addr)   \
653 +    (*(volatile u16 *) (__addr))
654 +
655 +#define IFX_PCIE_PHY_REG(__reg, __value, __mask) do { \
656 +    u16 read_data;                                    \
657 +    u16 write_data;                                   \
658 +    read_data = IFX_PCIE_PHY_REG_READ16((__reg));      \
659 +    write_data = (read_data & ((u16)~(__mask))) | (((u16)(__value)) & ((u16)(__mask)));\
660 +    IFX_PCIE_PHY_REG_WRITE16((__reg), write_data);               \
661 +} while (0)
662 +
663 +#define IFX_PCIE_PLL_TIMEOUT 1000 /* Tunnable */
664 +
665 +static void
666 +pcie_phy_comm_setup(int pcie_port)
667 +{
668 +   /* PLL Setting */
669 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL1(pcie_port), 0x120e, 0xFFFF);
670 +
671 +    /* increase the bias reference voltage */
672 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x39D7, 0xFFFF);
673 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x0900, 0xFFFF);
674 +
675 +    /* Endcnt */
676 +    IFX_PCIE_PHY_REG(PCIE_PHY_RX1_EI(pcie_port), 0x0004, 0xFFFF);
677 +    IFX_PCIE_PHY_REG(PCIE_PHY_RX1_A_CTRL(pcie_port), 0x6803, 0xFFFF);
678 +
679 +    /* force */
680 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0008, 0x0008);
681 +
682 +    /* predrv_ser_en */
683 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL2(pcie_port), 0x0706, 0xFFFF);
684 +
685 +    /* ctrl_lim */
686 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL3(pcie_port), 0x1FFF, 0xFFFF);
687 +
688 +    /* ctrl */
689 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL1(pcie_port), 0x0800, 0xFF00);
690 +
691 +    /* predrv_ser_en */
692 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4702, 0x7F00);
693 +
694 +    /* RTERM*/
695 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL2(pcie_port), 0x2e00, 0xFFFF);
696 +
697 +    /* Improved 100MHz clock output  */
698 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL2(pcie_port), 0x3096, 0xFFFF);
699 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4707, 0xFFFF);
700 +
701 +    /* Reduced CDR BW to avoid glitches */
702 +    IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CDR(pcie_port), 0x0235, 0xFFFF);
703 +}
704 +
705 +#ifdef CONFIG_IFX_PCIE_PHY_36MHZ_MODE
706 +static void 
707 +pcie_phy_36mhz_mode_setup(int pcie_port) 
708 +{
709 +    IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
710 +
711 +    /* en_ext_mmd_div_ratio */
712 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0002);
713 +
714 +    /* ext_mmd_div_ratio*/
715 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0070);
716 +
717 +    /* pll_ensdm */
718 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0200, 0x0200);
719 +
720 +    /* en_const_sdm */
721 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0100, 0x0100);
722 +
723 +    /* mmd */
724 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x2000, 0xe000);
725 +
726 +    /* lf_mode */
727 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x0000, 0x4000);
728 +
729 +    /* const_sdm */
730 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL1(pcie_port), 0x38e4, 0xFFFF);
731 +
732 +    /* const sdm */
733 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x00ee, 0x00FF);
734 +
735 +    /* pllmod */
736 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL7(pcie_port), 0x0002, 0xFFFF);
737 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL6(pcie_port), 0x3a04, 0xFFFF);
738 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL5(pcie_port), 0xfae3, 0xFFFF);
739 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL4(pcie_port), 0x1b72, 0xFFFF);
740 +
741 +    IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
742 +}
743 +#endif /* CONFIG_IFX_PCIE_PHY_36MHZ_MODE */
744 +
745 +#ifdef CONFIG_IFX_PCIE_PHY_36MHZ_SSC_MODE
746 +static void 
747 +pcie_phy_36mhz_ssc_mode_setup(int pcie_port) 
748 +{
749 +    IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
750 +
751 +    /* PLL Setting */
752 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL1(pcie_port), 0x120e, 0xFFFF);
753 +
754 +    /* Increase the bias reference voltage */
755 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x39D7, 0xFFFF);
756 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x0900, 0xFFFF);
757 +
758 +    /* Endcnt */
759 +    IFX_PCIE_PHY_REG(PCIE_PHY_RX1_EI(pcie_port), 0x0004, 0xFFFF);
760 +    IFX_PCIE_PHY_REG(PCIE_PHY_RX1_A_CTRL(pcie_port), 0x6803, 0xFFFF);
761 +
762 +    /* Force */
763 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0008, 0x0008);
764 +
765 +    /* Predrv_ser_en */
766 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL2(pcie_port), 0x0706, 0xFFFF);
767 +
768 +    /* ctrl_lim */
769 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL3(pcie_port), 0x1FFF, 0xFFFF);
770 +
771 +    /* ctrl */
772 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL1(pcie_port), 0x0800, 0xFF00);
773 +
774 +    /* predrv_ser_en */
775 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4702, 0x7F00);
776 +
777 +    /* RTERM*/
778 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL2(pcie_port), 0x2e00, 0xFFFF);
779 +
780 +    /* en_ext_mmd_div_ratio */
781 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0002);
782 +
783 +    /* ext_mmd_div_ratio*/
784 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0070);
785 +
786 +    /* pll_ensdm */
787 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0400, 0x0400);
788 +
789 +    /* en_const_sdm */
790 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0200, 0x0200);
791 +
792 +    /* mmd */
793 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x2000, 0xe000);
794 +
795 +    /* lf_mode */
796 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x0000, 0x4000);
797 +
798 +    /* const_sdm */
799 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL1(pcie_port), 0x38e4, 0xFFFF);
800 +
801 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0000, 0x0100);
802 +    /* const sdm */
803 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x00ee, 0x00FF);
804 +
805 +    /* pllmod */
806 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL7(pcie_port), 0x0002, 0xFFFF);
807 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL6(pcie_port), 0x3a04, 0xFFFF);
808 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL5(pcie_port), 0xfae3, 0xFFFF);
809 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL4(pcie_port), 0x1c72, 0xFFFF);
810 +
811 +    /* improved 100MHz clock output  */
812 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL2(pcie_port), 0x3096, 0xFFFF);
813 +    IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4707, 0xFFFF);
814 +
815 +    /* reduced CDR BW to avoid glitches */
816 +    IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CDR(pcie_port), 0x0235, 0xFFFF);
817 +    
818 +    IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
819 +}
820 +#endif /* CONFIG_IFX_PCIE_PHY_36MHZ_SSC_MODE */
821 +
822 +#ifdef CONFIG_IFX_PCIE_PHY_25MHZ_MODE
823 +static void 
824 +pcie_phy_25mhz_mode_setup(int pcie_port) 
825 +{
826 +    IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
827 +    /* en_const_sdm */
828 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0100, 0x0100);
829 +
830 +    /* pll_ensdm */    
831 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0000, 0x0200);
832 +
833 +    /* en_ext_mmd_div_ratio*/
834 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0002, 0x0002);
835 +
836 +    /* ext_mmd_div_ratio*/
837 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0040, 0x0070);
838 +
839 +    /* mmd */
840 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x6000, 0xe000);
841 +
842 +    /* lf_mode */
843 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x4000, 0x4000);
844 +
845 +    IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
846 +}
847 +#endif /* CONFIG_IFX_PCIE_PHY_25MHZ_MODE */
848 +
849 +#ifdef CONFIG_IFX_PCIE_PHY_100MHZ_MODE
850 +static void 
851 +pcie_phy_100mhz_mode_setup(int pcie_port) 
852 +{
853 +    IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
854 +    /* en_ext_mmd_div_ratio */
855 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0002);
856 +
857 +    /* ext_mmd_div_ratio*/
858 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0070);
859 +
860 +    /* pll_ensdm */
861 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0200, 0x0200);
862 +
863 +    /* en_const_sdm */
864 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0100, 0x0100);
865 +
866 +    /* mmd */
867 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x2000, 0xe000);
868 +
869 +    /* lf_mode */
870 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x0000, 0x4000);
871 +
872 +    /* const_sdm */
873 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL1(pcie_port), 0x38e4, 0xFFFF);
874 +
875 +    /* const sdm */
876 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x00ee, 0x00FF);
877 +
878 +    /* pllmod */
879 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL7(pcie_port), 0x0002, 0xFFFF);
880 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL6(pcie_port), 0x3a04, 0xFFFF);
881 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL5(pcie_port), 0xfae3, 0xFFFF);
882 +    IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL4(pcie_port), 0x1b72, 0xFFFF);
883 +
884 +    IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
885 +}
886 +#endif /* CONFIG_IFX_PCIE_PHY_100MHZ_MODE */
887 +
888 +static int
889 +pcie_phy_wait_startup_ready(int pcie_port)
890 +{
891 +    int i;
892 +
893 +    for (i = 0; i < IFX_PCIE_PLL_TIMEOUT; i++) {
894 +        if ((IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_STATUS(pcie_port)) & 0x0040) != 0) {
895 +            break;
896 +        }
897 +        udelay(10);
898 +    }
899 +    if (i >= IFX_PCIE_PLL_TIMEOUT) {
900 +        printk(KERN_ERR "%s PLL Link timeout\n", __func__);
901 +        return -1;
902 +    }
903 +    return 0;
904 +}
905 +
906 +static void 
907 +pcie_phy_load_enable(int pcie_port, int slice) 
908 +{
909 +    /* Set the load_en of tx/rx slice to '1' */
910 +    switch (slice) {
911 +        case 1:
912 +            IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0010, 0x0010);
913 +            break;
914 +        case 2:
915 +            IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL1(pcie_port), 0x0010, 0x0010);
916 +            break;
917 +        case 3:
918 +            IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CTRL1(pcie_port), 0x0002, 0x0002);
919 +            break;
920 +    }
921 +}
922 +
923 +static void 
924 +pcie_phy_load_disable(int pcie_port, int slice) 
925 +{ 
926 +    /* set the load_en of tx/rx slice to '0' */ 
927 +    switch (slice) {
928 +        case 1:
929 +            IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0000, 0x0010);
930 +            break;
931 +        case 2:
932 +            IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL1(pcie_port), 0x0000, 0x0010);
933 +            break;
934 +        case 3: 
935 +            IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CTRL1(pcie_port), 0x0000, 0x0002);
936 +            break;
937 +    }
938 +}
939 +
940 +static void pcie_phy_load_war(int pcie_port)
941 +{
942 +       int slice;
943 +
944 +       for (slice = 1; slice < 4; slice++) {
945 +               pcie_phy_load_enable(pcie_port, slice);
946 +               udelay(1);
947 +               pcie_phy_load_disable(pcie_port, slice);
948 +       }
949 +}
950 +
951 +static void pcie_phy_tx2_modulation(int pcie_port)
952 +{
953 +       IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD1(pcie_port), 0x1FFE, 0xFFFF);
954 +       IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD2(pcie_port), 0xFFFE, 0xFFFF);
955 +       IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD3(pcie_port), 0x0601, 0xFFFF);
956 +       mdelay(1);
957 +       IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD3(pcie_port), 0x0001, 0xFFFF);
958 +}
959 +
960 +static void pcie_phy_tx1_modulation(int pcie_port)
961 +{
962 +       IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD1(pcie_port), 0x1FFE, 0xFFFF);
963 +       IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD2(pcie_port), 0xFFFE, 0xFFFF);
964 +       IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD3(pcie_port), 0x0601, 0xFFFF);
965 +       mdelay(1);
966 +       IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD3(pcie_port), 0x0001, 0xFFFF);
967 +}
968 +
969 +static void pcie_phy_tx_modulation_war(int pcie_port)
970 +{
971 +       int i;
972 +#define PCIE_PHY_MODULATION_NUM 5
973 +       for (i = 0; i < PCIE_PHY_MODULATION_NUM; i++) {
974 +               pcie_phy_tx2_modulation(pcie_port);
975 +               pcie_phy_tx1_modulation(pcie_port);
976 +       }
977 +#undef PCIE_PHY_MODULATION_NUM
978 +}
979 +
980 +void pcie_phy_clock_mode_setup(int pcie_port)
981 +{
982 +       pcie_pdi_big_endian(pcie_port);
983 +
984 +       /* Enable PDI to access PCIe PHY register */
985 +       pcie_pdi_pmu_enable(pcie_port);
986 +
987 +       /* Configure PLL and PHY clock */
988 +       pcie_phy_comm_setup(pcie_port);
989 +
990 +#ifdef CONFIG_IFX_PCIE_PHY_36MHZ_MODE
991 +       pcie_phy_36mhz_mode_setup(pcie_port);
992 +#elif defined(CONFIG_IFX_PCIE_PHY_36MHZ_SSC_MODE)
993 +       pcie_phy_36mhz_ssc_mode_setup(pcie_port);
994 +#elif defined(CONFIG_IFX_PCIE_PHY_25MHZ_MODE)
995 +       pcie_phy_25mhz_mode_setup(pcie_port);
996 +#elif defined (CONFIG_IFX_PCIE_PHY_100MHZ_MODE)
997 +       pcie_phy_100mhz_mode_setup(pcie_port);
998 +#else
999 +       #error "PCIE PHY Clock Mode must be chosen first!!!!"
1000 +#endif /* CONFIG_IFX_PCIE_PHY_36MHZ_MODE */
1001 +
1002 +       /* Enable PCIe PHY and make PLL setting take effect */
1003 +       pcie_phy_pmu_enable(pcie_port);
1004 +
1005 +       /* Check if we are in startup_ready status */
1006 +       pcie_phy_wait_startup_ready(pcie_port);
1007 +
1008 +       pcie_phy_load_war(pcie_port);
1009 +
1010 +       /* Apply TX modulation workarounds */
1011 +       pcie_phy_tx_modulation_war(pcie_port);
1012 +
1013 +#ifdef IFX_PCI_PHY_REG_DUMP
1014 +       IFX_PCIE_PRINT(PCIE_MSG_PHY, "Modified PHY register dump\n");
1015 +       pcie_phy_reg_dump(pcie_port);
1016 +#endif
1017 +}
1018 +
1019 --- /dev/null
1020 +++ b/arch/mips/pci/pcie-lantiq.c
1021 @@ -0,0 +1,1146 @@
1022 +#include <linux/types.h>
1023 +#include <linux/module.h>
1024 +#include <linux/pci.h>
1025 +#include <linux/kernel.h>
1026 +#include <linux/init.h>
1027 +#include <linux/delay.h>
1028 +#include <linux/mm.h>
1029 +#include <asm/paccess.h>
1030 +#include <linux/pci.h>
1031 +#include <linux/pci_regs.h>
1032 +#include <linux/platform_device.h>
1033 +
1034 +#define CONFIG_IFX_PCIE_1ST_CORE
1035 +
1036 +#include "pcie-lantiq.h"
1037 +
1038 +#define IFX_PCIE_IR                     (INT_NUM_IM4_IRL0 + 25)
1039 +#define IFX_PCIE_INTA                   (INT_NUM_IM4_IRL0 + 8)
1040 +#define IFX_PCIE_INTB                   (INT_NUM_IM4_IRL0 + 9)
1041 +#define IFX_PCIE_INTC                   (INT_NUM_IM4_IRL0 + 10)
1042 +#define IFX_PCIE_INTD                   (INT_NUM_IM4_IRL0 + 11)
1043 +#define MS(_v, _f)  (((_v) & (_f)) >> _f##_S)
1044 +#define SM(_v, _f)  (((_v) << _f##_S) & (_f))
1045 +#define IFX_REG_SET_BIT(_f, _r) \
1046 +    IFX_REG_W32((IFX_REG_R32((_r)) &~ (_f)) | (_f), (_r))
1047 +#define IFX_PCIE_LTSSM_ENABLE_TIMEOUT 10
1048 +#define IFX_PCIE_PHY_LINK_UP_TIMEOUT  1000
1049 +#define IFX_PCIE_PHY_LOOP_CNT  5
1050 +
1051 +static DEFINE_SPINLOCK(ifx_pcie_lock);
1052 +
1053 +int pcibios_1st_host_bus_nr(void);
1054 +
1055 +unsigned int g_pcie_debug_flag = PCIE_MSG_ANY & (~PCIE_MSG_CFG);
1056 +
1057 +static ifx_pcie_irq_t pcie_irqs[IFX_PCIE_CORE_NR] = {
1058 +    {
1059 +        .ir_irq = {
1060 +            .irq  = IFX_PCIE_IR,
1061 +            .name = "ifx_pcie_rc0",
1062 +        },
1063 +
1064 +        .legacy_irq = {
1065 +            {
1066 +                .irq_bit = PCIE_IRN_INTA,
1067 +                .irq     = IFX_PCIE_INTA,
1068 +            },
1069 +            {
1070 +                .irq_bit = PCIE_IRN_INTB,
1071 +                .irq     = IFX_PCIE_INTB,
1072 +            },
1073 +            {
1074 +                .irq_bit = PCIE_IRN_INTC,
1075 +                .irq     = IFX_PCIE_INTC,
1076 +            },
1077 +            {
1078 +                .irq_bit = PCIE_IRN_INTD,
1079 +                .irq     = IFX_PCIE_INTD,
1080 +            },
1081 +        },
1082 +    },
1083 +};
1084 +
1085 +static inline int pcie_ltssm_enable(int pcie_port)
1086 +{
1087 +       int i;
1088 +
1089 +       IFX_REG_W32(PCIE_RC_CCR_LTSSM_ENABLE, PCIE_RC_CCR(pcie_port)); /* Enable LTSSM */
1090 +
1091 +       /* Wait for the link to come up */
1092 +       for (i = 0; i < IFX_PCIE_LTSSM_ENABLE_TIMEOUT; i++) {
1093 +               if (!(IFX_REG_R32(PCIE_LCTLSTS(pcie_port)) & PCIE_LCTLSTS_RETRAIN_PENDING)) {
1094 +                       break;
1095 +               }
1096 +               udelay(10);
1097 +       }
1098 +       if (i >= IFX_PCIE_LTSSM_ENABLE_TIMEOUT) {
1099 +               IFX_PCIE_PRINT(PCIE_MSG_INIT, "%s link timeout!!!!!\n", __func__);
1100 +               return -1;
1101 +       }
1102 +       return 0;
1103 +}
1104 +
1105 +static inline void pcie_status_register_clear(int pcie_port)
1106 +{
1107 +       IFX_REG_W32(0, PCIE_RC_DR(pcie_port));
1108 +       IFX_REG_W32(0, PCIE_PCICMDSTS(pcie_port));
1109 +       IFX_REG_W32(0, PCIE_DCTLSTS(pcie_port));
1110 +       IFX_REG_W32(0, PCIE_LCTLSTS(pcie_port));
1111 +       IFX_REG_W32(0, PCIE_SLCTLSTS(pcie_port));
1112 +       IFX_REG_W32(0, PCIE_RSTS(pcie_port));
1113 +       IFX_REG_W32(0, PCIE_UES_R(pcie_port));
1114 +       IFX_REG_W32(0, PCIE_UEMR(pcie_port));
1115 +       IFX_REG_W32(0, PCIE_UESR(pcie_port));
1116 +       IFX_REG_W32(0, PCIE_CESR(pcie_port));
1117 +       IFX_REG_W32(0, PCIE_CEMR(pcie_port));
1118 +       IFX_REG_W32(0, PCIE_RESR(pcie_port));
1119 +       IFX_REG_W32(0, PCIE_PVCCRSR(pcie_port));
1120 +       IFX_REG_W32(0, PCIE_VC0_RSR0(pcie_port));
1121 +       IFX_REG_W32(0, PCIE_TPFCS(pcie_port));
1122 +       IFX_REG_W32(0, PCIE_TNPFCS(pcie_port));
1123 +       IFX_REG_W32(0, PCIE_TCFCS(pcie_port));
1124 +       IFX_REG_W32(0, PCIE_QSR(pcie_port));
1125 +       IFX_REG_W32(0, PCIE_IOBLSECS(pcie_port));
1126 +}
1127 +
1128 +static inline int ifx_pcie_link_up(int pcie_port)
1129 +{
1130 +       return (IFX_REG_R32(PCIE_PHY_SR(pcie_port)) & PCIE_PHY_SR_PHY_LINK_UP) ? 1 : 0;
1131 +}
1132 +
1133 +static inline void pcie_mem_io_setup(int pcie_port)
1134 +{
1135 +       unsigned int reg;
1136 +       /*
1137 +        * BAR[0:1] readonly register 
1138 +        * RC contains only minimal BARs for packets mapped to this device 
1139 +        * Mem/IO filters defines a range of memory occupied by memory mapped IO devices that
1140 +        * reside on the downstream side fo the bridge.
1141 +        */
1142 +       reg = SM((PCIE_MEM_PHY_PORT_TO_END(pcie_port) >> 20), PCIE_MBML_MEM_LIMIT_ADDR)
1143 +               | SM((PCIE_MEM_PHY_PORT_TO_BASE(pcie_port) >> 20), PCIE_MBML_MEM_BASE_ADDR);
1144 +       IFX_REG_W32(reg, PCIE_MBML(pcie_port));
1145 +
1146 +       /* PCIe_PBML, same as MBML */
1147 +       IFX_REG_W32(IFX_REG_R32(PCIE_MBML(pcie_port)), PCIE_PMBL(pcie_port));
1148 +
1149 +       /* IO Address Range */
1150 +       reg = SM((PCIE_IO_PHY_PORT_TO_END(pcie_port) >> 12), PCIE_IOBLSECS_IO_LIMIT_ADDR)
1151 +               | SM((PCIE_IO_PHY_PORT_TO_BASE(pcie_port) >> 12), PCIE_IOBLSECS_IO_BASE_ADDR);
1152 +       reg |= PCIE_IOBLSECS_32BIT_IO_ADDR;
1153 +               IFX_REG_W32(reg, PCIE_IOBLSECS(pcie_port));
1154 +
1155 +       reg = SM((PCIE_IO_PHY_PORT_TO_END(pcie_port) >> 16), PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT)
1156 +               | SM((PCIE_IO_PHY_PORT_TO_BASE(pcie_port) >> 16), PCIE_IO_BANDL_UPPER_16BIT_IO_BASE);
1157 +       IFX_REG_W32(reg, PCIE_IO_BANDL(pcie_port));
1158 +}
1159 +
1160 +static inline void pcie_msi_setup(int pcie_port)
1161 +{
1162 +       unsigned int reg;
1163 +
1164 +       /* XXX, MSI stuff should only apply to EP */
1165 +       /* MSI Capability: Only enable 32-bit addresses */
1166 +       reg = IFX_REG_R32(PCIE_MCAPR(pcie_port));
1167 +       reg &= ~PCIE_MCAPR_ADDR64_CAP;
1168 +       reg |= PCIE_MCAPR_MSI_ENABLE;
1169 +
1170 +       /* Disable multiple message */
1171 +       reg &= ~(PCIE_MCAPR_MULTI_MSG_CAP | PCIE_MCAPR_MULTI_MSG_ENABLE);
1172 +       IFX_REG_W32(reg, PCIE_MCAPR(pcie_port));
1173 +}
1174 +
1175 +static inline void pcie_pm_setup(int pcie_port)
1176 +{
1177 +       unsigned int reg;
1178 +
1179 +       /* Enable PME, Soft reset enabled */
1180 +       reg = IFX_REG_R32(PCIE_PM_CSR(pcie_port));
1181 +       reg |= PCIE_PM_CSR_PME_ENABLE | PCIE_PM_CSR_SW_RST;
1182 +       IFX_REG_W32(reg, PCIE_PM_CSR(pcie_port));
1183 +}
1184 +
1185 +static inline void pcie_bus_setup(int pcie_port)
1186 +{
1187 +       unsigned int reg;
1188 +
1189 +       reg = SM(0, PCIE_BNR_PRIMARY_BUS_NUM) | SM(1, PCIE_PNR_SECONDARY_BUS_NUM) | SM(0xFF, PCIE_PNR_SUB_BUS_NUM);
1190 +       IFX_REG_W32(reg, PCIE_BNR(pcie_port));
1191 +}
1192 +
1193 +static inline void pcie_device_setup(int pcie_port)
1194 +{
1195 +       unsigned int reg;
1196 +
1197 +       /* Device capability register, set up Maximum payload size */
1198 +       reg = IFX_REG_R32(PCIE_DCAP(pcie_port));
1199 +       reg |= PCIE_DCAP_ROLE_BASE_ERR_REPORT;
1200 +       reg |= SM(PCIE_MAX_PAYLOAD_128, PCIE_DCAP_MAX_PAYLOAD_SIZE);
1201 +
1202 +       /* Only available for EP */
1203 +       reg &= ~(PCIE_DCAP_EP_L0S_LATENCY | PCIE_DCAP_EP_L1_LATENCY);
1204 +       IFX_REG_W32(reg, PCIE_DCAP(pcie_port));
1205 +
1206 +       /* Device control and status register */
1207 +       /* Set Maximum Read Request size for the device as a Requestor */
1208 +       reg = IFX_REG_R32(PCIE_DCTLSTS(pcie_port));
1209 +
1210 +       /* 
1211 +        * Request size can be larger than the MPS used, but the completions returned 
1212 +        * for the read will be bounded by the MPS size.
1213 +        * In our system, Max request size depends on AHB burst size. It is 64 bytes.
1214 +        * but we set it as 128 as minimum one.
1215 +        */
1216 +       reg |= SM(PCIE_MAX_PAYLOAD_128, PCIE_DCTLSTS_MAX_READ_SIZE)
1217 +               | SM(PCIE_MAX_PAYLOAD_128, PCIE_DCTLSTS_MAX_PAYLOAD_SIZE);
1218 +
1219 +       /* Enable relaxed ordering, no snoop, and all kinds of errors */
1220 +       reg |= PCIE_DCTLSTS_RELAXED_ORDERING_EN | PCIE_DCTLSTS_ERR_EN | PCIE_DCTLSTS_NO_SNOOP_EN;
1221 +
1222 +       IFX_REG_W32(reg, PCIE_DCTLSTS(pcie_port));
1223 +}
1224 +
1225 +static inline void pcie_link_setup(int pcie_port)
1226 +{
1227 +       unsigned int reg;
1228 +
1229 +       /*
1230 +        * XXX, Link capability register, bit 18 for EP CLKREQ# dynamic clock management for L1, L2/3 CPM 
1231 +        * L0s is reported during link training via TS1 order set by N_FTS
1232 +        */
1233 +       reg = IFX_REG_R32(PCIE_LCAP(pcie_port));
1234 +       reg &= ~PCIE_LCAP_L0S_EIXT_LATENCY;
1235 +       reg |= SM(3, PCIE_LCAP_L0S_EIXT_LATENCY);
1236 +       IFX_REG_W32(reg, PCIE_LCAP(pcie_port));
1237 +
1238 +       /* Link control and status register */
1239 +       reg = IFX_REG_R32(PCIE_LCTLSTS(pcie_port));
1240 +
1241 +       /* Link Enable, ASPM enabled  */
1242 +       reg &= ~PCIE_LCTLSTS_LINK_DISABLE;
1243 +
1244 +#ifdef CONFIG_PCIEASPM
1245 +       /*  
1246 +        * We use the same physical reference clock that the platform provides on the connector 
1247 +        * It paved the way for ASPM to calculate the new exit Latency
1248 +        */
1249 +       reg |= PCIE_LCTLSTS_SLOT_CLK_CFG;
1250 +       reg |= PCIE_LCTLSTS_COM_CLK_CFG;
1251 +       /*
1252 +        * We should disable ASPM by default except that we have dedicated power management support
1253 +        * Enable ASPM will cause the system hangup/instability, performance degration
1254 +        */
1255 +       reg |= PCIE_LCTLSTS_ASPM_ENABLE;
1256 +#else
1257 +       reg &= ~PCIE_LCTLSTS_ASPM_ENABLE;
1258 +#endif /* CONFIG_PCIEASPM */
1259 +
1260 +       /* 
1261 +        * The maximum size of any completion with data packet is bounded by the MPS setting 
1262 +        * in  device control register 
1263 +        */
1264 +       /* RCB may cause multiple split transactions, two options available, we use 64 byte RCB */
1265 +       reg &= ~ PCIE_LCTLSTS_RCB128;
1266 +       IFX_REG_W32(reg, PCIE_LCTLSTS(pcie_port));
1267 +}
1268 +
1269 +static inline void pcie_error_setup(int pcie_port)
1270 +{
1271 +       unsigned int reg;
1272 +
1273 +       /* 
1274 +        * Forward ERR_COR, ERR_NONFATAL, ERR_FATAL to the backbone 
1275 +        * Poisoned write TLPs and completions indicating poisoned TLPs will set the PCIe_PCICMDSTS.MDPE 
1276 +        */
1277 +       reg = IFX_REG_R32(PCIE_INTRBCTRL(pcie_port));
1278 +       reg |= PCIE_INTRBCTRL_SERR_ENABLE | PCIE_INTRBCTRL_PARITY_ERR_RESP_ENABLE;
1279 +
1280 +       IFX_REG_W32(reg, PCIE_INTRBCTRL(pcie_port));
1281 +
1282 +       /* Uncorrectable Error Mask Register, Unmask <enable> all bits in PCIE_UESR */
1283 +       reg = IFX_REG_R32(PCIE_UEMR(pcie_port));
1284 +       reg &= ~PCIE_ALL_UNCORRECTABLE_ERR;
1285 +       IFX_REG_W32(reg, PCIE_UEMR(pcie_port));
1286 +
1287 +       /* Uncorrectable Error Severity Register, ALL errors are FATAL */
1288 +       IFX_REG_W32(PCIE_ALL_UNCORRECTABLE_ERR, PCIE_UESR(pcie_port));
1289 +
1290 +       /* Correctable Error Mask Register, unmask <enable> all bits */
1291 +       reg = IFX_REG_R32(PCIE_CEMR(pcie_port));
1292 +       reg &= ~PCIE_CORRECTABLE_ERR;
1293 +       IFX_REG_W32(reg, PCIE_CEMR(pcie_port));
1294 +
1295 +       /* Advanced Error Capabilities and Control Registr */
1296 +       reg = IFX_REG_R32(PCIE_AECCR(pcie_port));
1297 +       reg |= PCIE_AECCR_ECRC_CHECK_EN | PCIE_AECCR_ECRC_GEN_EN;
1298 +       IFX_REG_W32(reg, PCIE_AECCR(pcie_port));
1299 +
1300 +       /* Root Error Command Register, Report all types of errors */
1301 +       reg = IFX_REG_R32(PCIE_RECR(pcie_port));
1302 +       reg |= PCIE_RECR_ERR_REPORT_EN;
1303 +       IFX_REG_W32(reg, PCIE_RECR(pcie_port));
1304 +
1305 +       /* Clear the Root status register */
1306 +       reg = IFX_REG_R32(PCIE_RESR(pcie_port));
1307 +       IFX_REG_W32(reg, PCIE_RESR(pcie_port));
1308 +}
1309 +
1310 +static inline void pcie_root_setup(int pcie_port)
1311 +{
1312 +       unsigned int reg;
1313 +
1314 +       /* Root control and capabilities register */
1315 +       reg = IFX_REG_R32(PCIE_RCTLCAP(pcie_port));
1316 +       reg |= PCIE_RCTLCAP_SERR_ENABLE | PCIE_RCTLCAP_PME_INT_EN;
1317 +       IFX_REG_W32(reg, PCIE_RCTLCAP(pcie_port));
1318 +}
1319 +
1320 +static inline void pcie_vc_setup(int pcie_port)
1321 +{
1322 +       unsigned int reg;
1323 +
1324 +       /* Port VC Capability Register 2 */
1325 +       reg = IFX_REG_R32(PCIE_PVC2(pcie_port));
1326 +       reg &= ~PCIE_PVC2_VC_ARB_WRR;
1327 +       reg |= PCIE_PVC2_VC_ARB_16P_FIXED_WRR;
1328 +       IFX_REG_W32(reg, PCIE_PVC2(pcie_port));
1329 +
1330 +       /* VC0 Resource Capability Register */
1331 +       reg = IFX_REG_R32(PCIE_VC0_RC(pcie_port));
1332 +       reg &= ~PCIE_VC0_RC_REJECT_SNOOP;
1333 +       IFX_REG_W32(reg, PCIE_VC0_RC(pcie_port));
1334 +}
1335 +
1336 +static inline void pcie_port_logic_setup(int pcie_port)
1337 +{
1338 +       unsigned int reg;
1339 +
1340 +       /* FTS number, default 12, increase to 63, may increase time from/to L0s to L0  */
1341 +       reg = IFX_REG_R32(PCIE_AFR(pcie_port));
1342 +       reg &= ~(PCIE_AFR_FTS_NUM | PCIE_AFR_COM_FTS_NUM);
1343 +       reg |= SM(PCIE_AFR_FTS_NUM_DEFAULT, PCIE_AFR_FTS_NUM)
1344 +               | SM(PCIE_AFR_FTS_NUM_DEFAULT, PCIE_AFR_COM_FTS_NUM);
1345 +       /* L0s and L1 entry latency */
1346 +       reg &= ~(PCIE_AFR_L0S_ENTRY_LATENCY | PCIE_AFR_L1_ENTRY_LATENCY);
1347 +       reg |= SM(PCIE_AFR_L0S_ENTRY_LATENCY_DEFAULT, PCIE_AFR_L0S_ENTRY_LATENCY)
1348 +               | SM(PCIE_AFR_L1_ENTRY_LATENCY_DEFAULT, PCIE_AFR_L1_ENTRY_LATENCY);
1349 +       IFX_REG_W32(reg, PCIE_AFR(pcie_port));
1350 +
1351 +       /* Port Link Control Register */
1352 +       reg = IFX_REG_R32(PCIE_PLCR(pcie_port));
1353 +       reg |= PCIE_PLCR_DLL_LINK_EN;  /* Enable the DLL link */
1354 +       IFX_REG_W32(reg, PCIE_PLCR(pcie_port));
1355 +
1356 +       /* Lane Skew Register */
1357 +       reg = IFX_REG_R32(PCIE_LSR(pcie_port));
1358 +       /* Enable ACK/NACK and FC */
1359 +       reg &= ~(PCIE_LSR_ACKNAK_DISABLE | PCIE_LSR_FC_DISABLE); 
1360 +       IFX_REG_W32(reg, PCIE_LSR(pcie_port));
1361 +
1362 +       /* Symbol Timer Register and Filter Mask Register 1 */
1363 +       reg = IFX_REG_R32(PCIE_STRFMR(pcie_port));
1364 +
1365 +       /* Default SKP interval is very accurate already, 5us */
1366 +       /* Enable IO/CFG transaction */
1367 +       reg |= PCIE_STRFMR_RX_CFG_TRANS_ENABLE | PCIE_STRFMR_RX_IO_TRANS_ENABLE;
1368 +       /* Disable FC WDT */
1369 +       reg &= ~PCIE_STRFMR_FC_WDT_DISABLE;
1370 +       IFX_REG_W32(reg, PCIE_STRFMR(pcie_port));
1371 +
1372 +       /* Filter Masker Register 2 */
1373 +       reg = IFX_REG_R32(PCIE_FMR2(pcie_port));
1374 +       reg |= PCIE_FMR2_VENDOR_MSG1_PASSED_TO_TRGT1 | PCIE_FMR2_VENDOR_MSG0_PASSED_TO_TRGT1;
1375 +       IFX_REG_W32(reg, PCIE_FMR2(pcie_port));
1376 +
1377 +       /* VC0 Completion Receive Queue Control Register */
1378 +       reg = IFX_REG_R32(PCIE_VC0_CRQCR(pcie_port));
1379 +       reg &= ~PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE;
1380 +       reg |= SM(PCIE_VC0_TLP_QUEUE_MODE_BYPASS, PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE);
1381 +       IFX_REG_W32(reg, PCIE_VC0_CRQCR(pcie_port));
1382 +}
1383 +
1384 +static inline void pcie_rc_cfg_reg_setup(int pcie_port)
1385 +{
1386 +       /* diable ltssm */
1387 +       IFX_REG_W32(0, PCIE_RC_CCR(pcie_port));
1388 +
1389 +       pcie_mem_io_setup(pcie_port);
1390 +       pcie_msi_setup(pcie_port);
1391 +       pcie_pm_setup(pcie_port);
1392 +       pcie_bus_setup(pcie_port);
1393 +       pcie_device_setup(pcie_port);
1394 +       pcie_link_setup(pcie_port);
1395 +       pcie_error_setup(pcie_port);
1396 +       pcie_root_setup(pcie_port);
1397 +       pcie_vc_setup(pcie_port);
1398 +       pcie_port_logic_setup(pcie_port);
1399 +}
1400 +
1401 +static int ifx_pcie_wait_phy_link_up(int pcie_port)
1402 +{
1403 +       int i;
1404 +
1405 +       /* Wait for PHY link is up */
1406 +       for (i = 0; i < IFX_PCIE_PHY_LINK_UP_TIMEOUT; i++) {
1407 +               if (ifx_pcie_link_up(pcie_port)) {
1408 +                       break;
1409 +               }
1410 +               udelay(100);
1411 +       }
1412 +       if (i >= IFX_PCIE_PHY_LINK_UP_TIMEOUT) {
1413 +               printk(KERN_ERR "%s timeout\n", __func__);
1414 +               return -1;
1415 +       }
1416 +
1417 +       /* Check data link up or not */
1418 +       if (!(IFX_REG_R32(PCIE_RC_DR(pcie_port)) & PCIE_RC_DR_DLL_UP)) {
1419 +               printk(KERN_ERR "%s DLL link is still down\n", __func__);
1420 +               return -1;
1421 +       }
1422 +
1423 +       /* Check Data link active or not */
1424 +       if (!(IFX_REG_R32(PCIE_LCTLSTS(pcie_port)) & PCIE_LCTLSTS_DLL_ACTIVE)) {
1425 +               printk(KERN_ERR "%s DLL is not active\n", __func__);
1426 +               return -1;
1427 +       }
1428 +       return 0;
1429 +}
1430 +
1431 +static inline int pcie_app_loigc_setup(int pcie_port)
1432 +{
1433 +       IFX_REG_W32(PCIE_AHB_CTRL_BUS_ERROR_SUPPRESS, PCIE_AHB_CTRL(pcie_port));
1434 +
1435 +       /* Pull PCIe EP out of reset */
1436 +       pcie_device_rst_deassert(pcie_port);
1437 +
1438 +       /* Start LTSSM training between RC and EP */
1439 +       pcie_ltssm_enable(pcie_port);
1440 +
1441 +       /* Check PHY status after enabling LTSSM */
1442 +       if (ifx_pcie_wait_phy_link_up(pcie_port) != 0) {
1443 +               return -1;
1444 +       }
1445 +       return 0;
1446 +}
1447 +
1448 +/* 
1449 + * Must be done after ltssm due to based on negotiated link 
1450 + * width and payload size
1451 + * Update the Replay Time Limit. Empirically, some PCIe 
1452 + * devices take a little longer to respond than expected under 
1453 + * load. As a workaround for this we configure the Replay Time 
1454 + * Limit to the value expected for a 512 byte MPS instead of 
1455 + * our actual 128 byte MPS. The numbers below are directly 
1456 + * from the PCIe spec table 3-4/5. 
1457 + */
1458 +static inline void pcie_replay_time_update(int pcie_port)
1459 +{
1460 +       unsigned int reg;
1461 +       int nlw;
1462 +       int rtl;
1463 +
1464 +       reg = IFX_REG_R32(PCIE_LCTLSTS(pcie_port));
1465 +
1466 +       nlw = MS(reg, PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH);
1467 +       switch (nlw) {
1468 +       case PCIE_MAX_LENGTH_WIDTH_X1:
1469 +               rtl = 1677;
1470 +               break;
1471 +       case PCIE_MAX_LENGTH_WIDTH_X2:
1472 +               rtl = 867;
1473 +               break;
1474 +       case PCIE_MAX_LENGTH_WIDTH_X4:
1475 +               rtl = 462;
1476 +               break;
1477 +       case PCIE_MAX_LENGTH_WIDTH_X8:
1478 +               rtl = 258;
1479 +               break;
1480 +       default:
1481 +               rtl = 1677;
1482 +               break;
1483 +       }
1484 +       reg = IFX_REG_R32(PCIE_ALTRT(pcie_port));
1485 +       reg &= ~PCIE_ALTRT_REPLAY_TIME_LIMIT;
1486 +       reg |= SM(rtl, PCIE_ALTRT_REPLAY_TIME_LIMIT);
1487 +       IFX_REG_W32(reg, PCIE_ALTRT(pcie_port));
1488 +
1489 +       IFX_PCIE_PRINT(PCIE_MSG_REG, "%s PCIE_ALTRT 0x%08x\n",
1490 +               __func__, IFX_REG_R32(PCIE_ALTRT(pcie_port)));
1491 +}
1492 +
1493 +/*
1494 + * Table 359 Enhanced Configuration Address Mapping1)
1495 + * 1) This table is defined in Table 7-1, page 341, PCI Express Base Specification v1.1
1496 + * Memory Address PCI Express Configuration Space
1497 + * A[(20+n-1):20] Bus Number 1 < n < 8
1498 + * A[19:15] Device Number
1499 + * A[14:12] Function Number
1500 + * A[11:8] Extended Register Number
1501 + * A[7:2] Register Number
1502 + * A[1:0] Along with size of the access, used to generate Byte Enables
1503 + * For VR9, only the address bits [22:0] are mapped to the configuration space:
1504 + * . Address bits [22:20] select the target bus (1-of-8)1)
1505 + * . Address bits [19:15] select the target device (1-of-32) on the bus
1506 + * . Address bits [14:12] select the target function (1-of-8) within the device.
1507 + * . Address bits [11:2] selects the target dword (1-of-1024) within the selected function.s configuration space
1508 + * . Address bits [1:0] define the start byte location within the selected dword.
1509 + */
1510 +static inline unsigned int pcie_bus_addr(u8 bus_num, u16 devfn, int where)
1511 +{
1512 +       unsigned int addr;
1513 +       u8  bus;
1514 +
1515 +       if (!bus_num) {
1516 +               /* type 0 */
1517 +               addr = ((PCI_SLOT(devfn) & 0x1F) << 15) | ((PCI_FUNC(devfn) & 0x7) << 12) | ((where & 0xFFF)& ~3);
1518 +       } else {
1519 +               bus = bus_num;
1520 +               /* type 1, only support 8 buses  */
1521 +               addr = ((bus & 0x7) << 20) | ((PCI_SLOT(devfn) & 0x1F) << 15) |
1522 +                       ((PCI_FUNC(devfn) & 0x7) << 12) | ((where & 0xFFF) & ~3);
1523 +       }
1524 +       IFX_PCIE_PRINT(PCIE_MSG_CFG, "%s: bus addr : %02x:%02x.%01x/%02x, addr=%08x\n",
1525 +               __func__, bus_num, PCI_SLOT(devfn), PCI_FUNC(devfn), where, addr);
1526 +       return addr;
1527 +}
1528 +
1529 +static int pcie_valid_config(int pcie_port, int bus, int dev)
1530 +{
1531 +       /* RC itself */
1532 +       if ((bus == 0) && (dev == 0))
1533 +               return 1;
1534 +
1535 +       /* No physical link */
1536 +       if (!ifx_pcie_link_up(pcie_port))
1537 +               return 0;
1538 +
1539 +       /* Bus zero only has RC itself
1540 +       * XXX, check if EP will be integrated 
1541 +       */
1542 +       if ((bus == 0) && (dev != 0))
1543 +               return 0;
1544 +
1545 +       /* Maximum 8 buses supported for VRX */
1546 +       if (bus > 9)
1547 +               return 0;
1548 +
1549 +       /* 
1550 +        * PCIe is PtP link, one bus only supports only one device 
1551 +        * except bus zero and PCIe switch which is virtual bus device
1552 +        * The following two conditions really depends on the system design
1553 +        * and attached the device.
1554 +        * XXX, how about more new switch
1555 +        */
1556 +       if ((bus == 1) && (dev != 0))
1557 +               return 0;
1558 +
1559 +       if ((bus >= 3) && (dev != 0))
1560 +               return 0;
1561 +       return 1;
1562 +}
1563 +
1564 +static inline unsigned int ifx_pcie_cfg_rd(int pcie_port, unsigned int reg)
1565 +{
1566 +       return IFX_REG_R32((volatile unsigned int *)(PCIE_CFG_PORT_TO_BASE(pcie_port) + reg));
1567 +}
1568 +
1569 +static inline void ifx_pcie_cfg_wr(int pcie_port, unsigned int reg, unsigned int val)
1570 +{
1571 +       IFX_REG_W32( val, (volatile unsigned int *)(PCIE_CFG_PORT_TO_BASE(pcie_port) + reg));
1572 +}
1573 +
1574 +static inline unsigned int ifx_pcie_rc_cfg_rd(int pcie_port, unsigned int reg)
1575 +{
1576 +       return IFX_REG_R32((volatile unsigned int *)(PCIE_RC_PORT_TO_BASE(pcie_port) + reg));
1577 +}
1578 +
1579 +static inline void ifx_pcie_rc_cfg_wr(int pcie_port, unsigned int reg, unsigned int val)
1580 +{
1581 +       IFX_REG_W32(val, (volatile unsigned int *)(PCIE_RC_PORT_TO_BASE(pcie_port) + reg));
1582 +}
1583 +
1584 +unsigned int ifx_pcie_bus_enum_read_hack(int where, unsigned int value)
1585 +{
1586 +       unsigned int tvalue = value;
1587 +
1588 +       if (where == PCI_PRIMARY_BUS) {
1589 +               u8 primary, secondary, subordinate;
1590 +
1591 +               primary = tvalue & 0xFF;
1592 +               secondary = (tvalue >> 8) & 0xFF;
1593 +               subordinate = (tvalue >> 16) & 0xFF;
1594 +               primary += pcibios_1st_host_bus_nr();
1595 +               secondary += pcibios_1st_host_bus_nr();
1596 +               subordinate += pcibios_1st_host_bus_nr();
1597 +               tvalue = (tvalue & 0xFF000000) | (unsigned int)primary | (unsigned int)(secondary << 8) | (unsigned int)(subordinate << 16);
1598 +       }
1599 +       return tvalue;
1600 +}
1601 +
1602 +unsigned int ifx_pcie_bus_enum_write_hack(int where, unsigned int value)
1603 +{
1604 +       unsigned int tvalue = value;
1605 +
1606 +       if (where == PCI_PRIMARY_BUS) {
1607 +               u8 primary, secondary, subordinate;
1608 +
1609 +               primary = tvalue & 0xFF;
1610 +               secondary = (tvalue >> 8) & 0xFF;
1611 +               subordinate = (tvalue >> 16) & 0xFF;
1612 +               if (primary > 0 && primary != 0xFF)
1613 +                       primary -= pcibios_1st_host_bus_nr();
1614 +               if (secondary > 0 && secondary != 0xFF)
1615 +                       secondary -= pcibios_1st_host_bus_nr();
1616 +               if (subordinate > 0 && subordinate != 0xFF)
1617 +                       subordinate -= pcibios_1st_host_bus_nr();
1618 +               tvalue = (tvalue & 0xFF000000) | (unsigned int)primary | (unsigned int)(secondary << 8) | (unsigned int)(subordinate << 16);
1619 +       } else if (where == PCI_SUBORDINATE_BUS) {
1620 +               u8 subordinate = tvalue & 0xFF;
1621 +               subordinate = subordinate > 0 ? subordinate - pcibios_1st_host_bus_nr() : 0;
1622 +               tvalue = subordinate;
1623 +       }
1624 +       return tvalue;
1625 +}
1626 +
1627 +/** 
1628 + * \fn static int ifx_pcie_read_config(struct pci_bus *bus, unsigned int devfn, 
1629 + *                   int where, int size, unsigned int *value)
1630 + * \brief Read a value from configuration space 
1631 + * 
1632 + * \param[in] bus    Pointer to pci bus
1633 + * \param[in] devfn  PCI device function number
1634 + * \param[in] where  PCI register number 
1635 + * \param[in] size   Register read size
1636 + * \param[out] value    Pointer to return value
1637 + * \return  PCIBIOS_BAD_REGISTER_NUMBER Invalid register number
1638 + * \return  PCIBIOS_FUNC_NOT_SUPPORTED  PCI function not supported
1639 + * \return  PCIBIOS_DEVICE_NOT_FOUND    PCI device not found
1640 + * \return  PCIBIOS_SUCCESSFUL          OK
1641 + * \ingroup IFX_PCIE_OS
1642 + */
1643 +static int ifx_pcie_read_config(struct pci_bus *bus, unsigned int devfn, int where, int size, unsigned int *value)
1644 +{
1645 +       unsigned int data = 0;
1646 +       int bus_number = bus->number;
1647 +       static const unsigned int mask[8] = {0, 0xff, 0xffff, 0, 0xffffffff, 0, 0, 0};
1648 +       int ret = PCIBIOS_SUCCESSFUL;
1649 +       struct ifx_pci_controller *ctrl = bus->sysdata;
1650 +       int pcie_port = ctrl->port;
1651 +
1652 +       if (unlikely(size != 1 && size != 2 && size != 4)){
1653 +               ret = PCIBIOS_BAD_REGISTER_NUMBER;
1654 +               goto out;
1655 +       }
1656 +
1657 +       /* Make sure the address is aligned to natural boundary */
1658 +       if (unlikely(((size - 1) & where))) {
1659 +               ret = PCIBIOS_BAD_REGISTER_NUMBER;
1660 +               goto out;
1661 +       }
1662 +
1663 +       /* 
1664 +        * If we are second controller, we have to cheat OS so that it assume 
1665 +        * its bus number starts from 0 in host controller
1666 +        */
1667 +       bus_number = ifx_pcie_bus_nr_deduct(bus_number, pcie_port);
1668 +
1669 +       /* 
1670 +        * We need to force the bus number to be zero on the root 
1671 +        * bus. Linux numbers the 2nd root bus to start after all 
1672 +        * busses on root 0. 
1673 +        */
1674 +       if (bus->parent == NULL)
1675 +               bus_number = 0;
1676 +
1677 +       /* 
1678 +        * PCIe only has a single device connected to it. It is 
1679 +        * always device ID 0. Don't bother doing reads for other 
1680 +        * device IDs on the first segment. 
1681 +        */
1682 +       if ((bus_number == 0) && (PCI_SLOT(devfn) != 0)) {
1683 +               ret = PCIBIOS_FUNC_NOT_SUPPORTED;
1684 +               goto out;
1685 +       }
1686 +
1687 +       if (pcie_valid_config(pcie_port, bus_number, PCI_SLOT(devfn)) == 0) {
1688 +               *value = 0xffffffff;
1689 +               ret = PCIBIOS_DEVICE_NOT_FOUND;
1690 +               goto out;
1691 +       }
1692 +
1693 +       IFX_PCIE_PRINT(PCIE_MSG_READ_CFG, "%s: %02x:%02x.%01x/%02x:%01d\n", __func__, bus_number,
1694 +               PCI_SLOT(devfn), PCI_FUNC(devfn), where, size);
1695 +
1696 +       PCIE_IRQ_LOCK(ifx_pcie_lock);
1697 +       if (bus_number == 0) { /* RC itself */
1698 +               unsigned int t;
1699 +
1700 +               t = (where & ~3);
1701 +               data = ifx_pcie_rc_cfg_rd(pcie_port, t);
1702 +               IFX_PCIE_PRINT(PCIE_MSG_READ_CFG, "%s: rd local cfg, offset:%08x, data:%08x\n",
1703 +                       __func__, t, data);
1704 +       } else {
1705 +               unsigned int addr = pcie_bus_addr(bus_number, devfn, where);
1706 +
1707 +               data = ifx_pcie_cfg_rd(pcie_port, addr);
1708 +               if (pcie_port == IFX_PCIE_PORT0) {
1709 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
1710 +                       data = le32_to_cpu(data);
1711 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
1712 +               } else {
1713 +#ifdef CONFIG_IFX_PCIE1_HW_SWAP
1714 +                       data = le32_to_cpu(data);
1715 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
1716 +               }
1717 +       }
1718 +       /* To get a correct PCI topology, we have to restore the bus number to OS */
1719 +       data = ifx_pcie_bus_enum_hack(bus, devfn, where, data, pcie_port, 1);
1720 +
1721 +       PCIE_IRQ_UNLOCK(ifx_pcie_lock);
1722 +       IFX_PCIE_PRINT(PCIE_MSG_READ_CFG, "%s: read config: data=%08x raw=%08x\n",
1723 +               __func__, (data >> (8 * (where & 3))) & mask[size & 7], data); 
1724 +
1725 +       *value = (data >> (8 * (where & 3))) & mask[size & 7];
1726 +out:
1727 +       return ret;
1728 +}
1729 +
1730 +static unsigned int ifx_pcie_size_to_value(int where, int size, unsigned int data, unsigned int value)
1731 +{
1732 +       unsigned int shift;
1733 +       unsigned int tdata = data;
1734 +
1735 +       switch (size) {
1736 +       case 1:
1737 +               shift = (where & 0x3) << 3;
1738 +               tdata &= ~(0xffU << shift);
1739 +               tdata |= ((value & 0xffU) << shift);
1740 +               break;
1741 +       case 2:
1742 +               shift = (where & 3) << 3;
1743 +               tdata &= ~(0xffffU << shift);
1744 +               tdata |= ((value & 0xffffU) << shift);
1745 +               break;
1746 +       case 4:
1747 +               tdata = value;
1748 +               break;
1749 +       }
1750 +       return tdata;
1751 +}
1752 +
1753 +/** 
1754 + * \fn static static int ifx_pcie_write_config(struct pci_bus *bus, unsigned int devfn,
1755 + *                 int where, int size, unsigned int value)
1756 + * \brief Write a value to PCI configuration space 
1757 + * 
1758 + * \param[in] bus    Pointer to pci bus
1759 + * \param[in] devfn  PCI device function number
1760 + * \param[in] where  PCI register number 
1761 + * \param[in] size   The register size to be written
1762 + * \param[in] value  The valule to be written
1763 + * \return PCIBIOS_BAD_REGISTER_NUMBER Invalid register number
1764 + * \return PCIBIOS_DEVICE_NOT_FOUND    PCI device not found
1765 + * \return PCIBIOS_SUCCESSFUL          OK
1766 + * \ingroup IFX_PCIE_OS
1767 + */
1768 +static int ifx_pcie_write_config(struct pci_bus *bus, unsigned int devfn, int where, int size, unsigned int value)
1769 +{
1770 +       int bus_number = bus->number;
1771 +       int ret = PCIBIOS_SUCCESSFUL;
1772 +       struct ifx_pci_controller *ctrl = bus->sysdata;
1773 +       int pcie_port = ctrl->port;
1774 +       unsigned int tvalue = value;
1775 +       unsigned int data;
1776 +
1777 +       /* Make sure the address is aligned to natural boundary */
1778 +       if (unlikely(((size - 1) & where))) {
1779 +               ret = PCIBIOS_BAD_REGISTER_NUMBER;
1780 +               goto out;
1781 +       }
1782 +       /* 
1783 +        * If we are second controller, we have to cheat OS so that it assume 
1784 +        * its bus number starts from 0 in host controller
1785 +        */
1786 +       bus_number = ifx_pcie_bus_nr_deduct(bus_number, pcie_port);
1787 +
1788 +       /* 
1789 +        * We need to force the bus number to be zero on the root 
1790 +        * bus. Linux numbers the 2nd root bus to start after all 
1791 +        * busses on root 0. 
1792 +        */
1793 +       if (bus->parent == NULL)
1794 +               bus_number = 0;
1795 +
1796 +       if (pcie_valid_config(pcie_port, bus_number, PCI_SLOT(devfn)) == 0) {
1797 +               ret = PCIBIOS_DEVICE_NOT_FOUND;
1798 +               goto out;
1799 +       }
1800 +
1801 +       IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG, "%s: %02x:%02x.%01x/%02x:%01d value=%08x\n", __func__,
1802 +               bus_number, PCI_SLOT(devfn), PCI_FUNC(devfn), where, size, value);
1803 +
1804 +       /* XXX, some PCIe device may need some delay */
1805 +       PCIE_IRQ_LOCK(ifx_pcie_lock);
1806 +
1807 +       /* 
1808 +        * To configure the correct bus topology using native way, we have to cheat Os so that
1809 +        * it can configure the PCIe hardware correctly.
1810 +        */
1811 +       tvalue = ifx_pcie_bus_enum_hack(bus, devfn, where, value, pcie_port, 0);
1812 +
1813 +       if (bus_number == 0) { /* RC itself */
1814 +               unsigned int t;
1815 +
1816 +               t = (where & ~3);
1817 +               IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG,"%s: wr local cfg, offset:%08x, fill:%08x\n", __func__, t, value);
1818 +               data = ifx_pcie_rc_cfg_rd(pcie_port, t);
1819 +               IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG,"%s: rd local cfg, offset:%08x, data:%08x\n", __func__, t, data);
1820 +
1821 +               data = ifx_pcie_size_to_value(where, size, data, tvalue);
1822 +
1823 +               IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG,"%s: wr local cfg, offset:%08x, value:%08x\n", __func__, t, data);
1824 +               ifx_pcie_rc_cfg_wr(pcie_port, t, data);
1825 +               IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG,"%s: rd local cfg, offset:%08x, value:%08x\n",
1826 +                       __func__, t, ifx_pcie_rc_cfg_rd(pcie_port, t));
1827 +       } else {
1828 +               unsigned int addr = pcie_bus_addr(bus_number, devfn, where);
1829 +
1830 +               IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG,"%s: wr cfg, offset:%08x, fill:%08x\n", __func__, addr, value);
1831 +               data = ifx_pcie_cfg_rd(pcie_port, addr);
1832 +               if (pcie_port == IFX_PCIE_PORT0) {
1833 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
1834 +                       data = le32_to_cpu(data);
1835 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
1836 +               } else {
1837 +#ifdef CONFIG_IFX_PCIE1_HW_SWAP
1838 +                       data = le32_to_cpu(data);
1839 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
1840 +               }
1841 +               IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG,"%s: rd cfg, offset:%08x, data:%08x\n", __func__, addr, data);
1842 +
1843 +               data = ifx_pcie_size_to_value(where, size, data, tvalue);
1844 +               if (pcie_port == IFX_PCIE_PORT0) {
1845 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
1846 +                       data = cpu_to_le32(data);
1847 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
1848 +               } else {
1849 +#ifdef CONFIG_IFX_PCIE1_HW_SWAP
1850 +                       data = cpu_to_le32(data);
1851 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
1852 +               }
1853 +               IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG, "%s: wr cfg, offset:%08x, value:%08x\n", __func__, addr, data);
1854 +               ifx_pcie_cfg_wr(pcie_port, addr, data);
1855 +               IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG, "%s: rd cfg, offset:%08x, value:%08x\n", 
1856 +                       __func__, addr, ifx_pcie_cfg_rd(pcie_port, addr));
1857 +       }
1858 +       PCIE_IRQ_UNLOCK(ifx_pcie_lock);
1859 +out:
1860 +       return ret;
1861 +}
1862 +
1863 +static struct resource ifx_pcie_io_resource = {
1864 +       .name  = "PCIe0 I/O space",
1865 +       .start = PCIE_IO_PHY_BASE,
1866 +       .end = PCIE_IO_PHY_END,
1867 +       .flags = IORESOURCE_IO,
1868 +};
1869 +
1870 +static struct resource ifx_pcie_mem_resource = {
1871 +       .name = "PCIe0 Memory space",
1872 +       .start = PCIE_MEM_PHY_BASE,
1873 +       .end = PCIE_MEM_PHY_END,
1874 +       .flags = IORESOURCE_MEM,
1875 +};
1876 +
1877 +static struct pci_ops ifx_pcie_ops = {
1878 +       .read = ifx_pcie_read_config,
1879 +       .write = ifx_pcie_write_config,
1880 +};
1881 +
1882 +static struct ifx_pci_controller ifx_pcie_controller[IFX_PCIE_CORE_NR] = {
1883 +       {
1884 +               .pcic = {
1885 +                       .pci_ops = &ifx_pcie_ops,
1886 +                       .mem_resource = &ifx_pcie_mem_resource,
1887 +                       .io_resource = &ifx_pcie_io_resource,
1888 +               },
1889 +               .port = IFX_PCIE_PORT0,
1890 +       },
1891 +};
1892 +
1893 +static inline void pcie_core_int_clear_all(int pcie_port)
1894 +{
1895 +       unsigned int reg;
1896 +       reg = IFX_REG_R32(PCIE_IRNCR(pcie_port));
1897 +       reg &= PCIE_RC_CORE_COMBINED_INT;
1898 +       IFX_REG_W32(reg, PCIE_IRNCR(pcie_port));
1899 +}
1900 +
1901 +static irqreturn_t pcie_rc_core_isr(int irq, void *dev_id)
1902 +{
1903 +       struct ifx_pci_controller *ctrl = (struct ifx_pci_controller *)dev_id;
1904 +       int pcie_port = ctrl->port;
1905 +
1906 +       IFX_PCIE_PRINT(PCIE_MSG_ISR, "PCIe RC error intr %d\n", irq);
1907 +       pcie_core_int_clear_all(pcie_port);
1908 +       return IRQ_HANDLED;
1909 +}
1910 +
1911 +static int pcie_rc_core_int_init(int pcie_port)
1912 +{
1913 +       int ret;
1914 +
1915 +       /* Enable core interrupt */
1916 +       IFX_REG_SET_BIT(PCIE_RC_CORE_COMBINED_INT, PCIE_IRNEN(pcie_port));
1917 +
1918 +       /* Clear it first */
1919 +       IFX_REG_SET_BIT(PCIE_RC_CORE_COMBINED_INT, PCIE_IRNCR(pcie_port));
1920 +       ret = request_irq(pcie_irqs[pcie_port].ir_irq.irq, pcie_rc_core_isr, IRQF_DISABLED,
1921 +       pcie_irqs[pcie_port].ir_irq.name, &ifx_pcie_controller[pcie_port]);
1922 +       if (ret)
1923 +               printk(KERN_ERR "%s request irq %d failed\n", __func__, IFX_PCIE_IR);
1924 +
1925 +       return ret;
1926 +}
1927 +
1928 +int ifx_pcie_bios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
1929 +{
1930 +       unsigned int irq_bit = 0;
1931 +       int irq = 0;
1932 +       struct ifx_pci_controller *ctrl = dev->bus->sysdata;
1933 +       int pcie_port = ctrl->port;
1934 +
1935 +       IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s port %d dev %s slot %d pin %d \n", __func__, pcie_port, pci_name(dev), slot, pin);
1936 +
1937 +       if ((pin == PCIE_LEGACY_DISABLE) || (pin > PCIE_LEGACY_INT_MAX)) {
1938 +               printk(KERN_WARNING "WARNING: dev %s: invalid interrupt pin %d\n", pci_name(dev), pin);
1939 +               return -1;
1940 +       }
1941 +       /* Pin index so minus one */
1942 +       irq_bit = pcie_irqs[pcie_port].legacy_irq[pin - 1].irq_bit;
1943 +       irq = pcie_irqs[pcie_port].legacy_irq[pin - 1].irq;
1944 +       IFX_REG_SET_BIT(irq_bit, PCIE_IRNEN(pcie_port));
1945 +       IFX_REG_SET_BIT(irq_bit, PCIE_IRNCR(pcie_port));
1946 +       IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s irq %d assigned\n", __func__, pci_name(dev), irq);
1947 +       return irq;
1948 +}
1949 +
1950 +/** 
1951 + * \fn int ifx_pcie_bios_plat_dev_init(struct pci_dev *dev)
1952 + * \brief Called to perform platform specific PCI setup 
1953 + * 
1954 + * \param[in] dev The Linux PCI device structure for the device to map
1955 + * \return OK
1956 + * \ingroup IFX_PCIE_OS
1957 + */ 
1958 +int ifx_pcie_bios_plat_dev_init(struct pci_dev *dev)
1959 +{
1960 +       u16 config;
1961 +       unsigned int dconfig;
1962 +       int pos;
1963 +       /* Enable reporting System errors and parity errors on all devices */ 
1964 +       /* Enable parity checking and error reporting */ 
1965 +       pci_read_config_word(dev, PCI_COMMAND, &config);
1966 +       config |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR /*| PCI_COMMAND_INVALIDATE |
1967 +       PCI_COMMAND_FAST_BACK*/;
1968 +       pci_write_config_word(dev, PCI_COMMAND, config);
1969 +
1970 +       if (dev->subordinate) {
1971 +               /* Set latency timers on sub bridges */
1972 +               pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, 0x40); /* XXX, */
1973 +               /* More bridge error detection */
1974 +               pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &config);
1975 +               config |= PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR;
1976 +               pci_write_config_word(dev, PCI_BRIDGE_CONTROL, config);
1977 +       }
1978 +       /* Enable the PCIe normal error reporting */
1979 +       pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
1980 +       if (pos) {
1981 +               /* Disable system error generation in response to error messages */
1982 +               pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &config);
1983 +               config &= ~(PCI_EXP_RTCTL_SECEE | PCI_EXP_RTCTL_SENFEE | PCI_EXP_RTCTL_SEFEE);
1984 +               pci_write_config_word(dev, pos + PCI_EXP_RTCTL, config);
1985 +
1986 +               /* Clear PCIE Capability's Device Status */
1987 +               pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &config);
1988 +               pci_write_config_word(dev, pos + PCI_EXP_DEVSTA, config);
1989 +
1990 +               /* Update Device Control */
1991 +               pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &config);
1992 +               /* Correctable Error Reporting */
1993 +               config |= PCI_EXP_DEVCTL_CERE;
1994 +               /* Non-Fatal Error Reporting */
1995 +               config |= PCI_EXP_DEVCTL_NFERE;
1996 +               /* Fatal Error Reporting */
1997 +               config |= PCI_EXP_DEVCTL_FERE;
1998 +               /* Unsupported Request */
1999 +               config |= PCI_EXP_DEVCTL_URRE;
2000 +               pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, config);
2001 +       }
2002 +
2003 +       /* Find the Advanced Error Reporting capability */
2004 +       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
2005 +       if (pos) {
2006 +               /* Clear Uncorrectable Error Status */
2007 +               pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &dconfig);
2008 +               pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, dconfig);
2009 +               /* Enable reporting of all uncorrectable errors */
2010 +               /* Uncorrectable Error Mask - turned on bits disable errors */
2011 +               pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, 0);
2012 +               /* 
2013 +                * Leave severity at HW default. This only controls if 
2014 +                * errors are reported as uncorrectable or 
2015 +                * correctable, not if the error is reported. 
2016 +                */
2017 +               /* PCI_ERR_UNCOR_SEVER - Uncorrectable Error Severity */
2018 +               /* Clear Correctable Error Status */
2019 +               pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &dconfig);
2020 +               pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, dconfig);
2021 +               /* Enable reporting of all correctable errors */
2022 +               /* Correctable Error Mask - turned on bits disable errors */
2023 +               pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, 0);
2024 +               /* Advanced Error Capabilities */
2025 +               pci_read_config_dword(dev, pos + PCI_ERR_CAP, &dconfig);
2026 +               /* ECRC Generation Enable */
2027 +               if (dconfig & PCI_ERR_CAP_ECRC_GENC)
2028 +                       dconfig |= PCI_ERR_CAP_ECRC_GENE;
2029 +               /* ECRC Check Enable */
2030 +               if (dconfig & PCI_ERR_CAP_ECRC_CHKC)
2031 +                       dconfig |= PCI_ERR_CAP_ECRC_CHKE;
2032 +               pci_write_config_dword(dev, pos + PCI_ERR_CAP, dconfig);
2033 +
2034 +               /* PCI_ERR_HEADER_LOG - Header Log Register (16 bytes) */
2035 +               /* Enable Root Port's interrupt in response to error messages */
2036 +               pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND,
2037 +                       PCI_ERR_ROOT_CMD_COR_EN |
2038 +                       PCI_ERR_ROOT_CMD_NONFATAL_EN |
2039 +                       PCI_ERR_ROOT_CMD_FATAL_EN);
2040 +               /* Clear the Root status register */
2041 +               pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &dconfig);
2042 +               pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, dconfig);
2043 +       }
2044 +       /* WAR, only 128 MRRS is supported, force all EPs to support this value */
2045 +       pcie_set_readrq(dev, 128);
2046 +       return 0;
2047 +}
2048 +
2049 +static void pcie_phy_rst(int pcie_port)
2050 +{
2051 +       pcie_phy_rst_assert(pcie_port);
2052 +       pcie_phy_rst_deassert(pcie_port);
2053 +       /* Make sure PHY PLL is stable */
2054 +       udelay(20);
2055 +}
2056 +
2057 +static int pcie_rc_initialize(int pcie_port)
2058 +{
2059 +       int i;
2060 +
2061 +       pcie_rcu_endian_setup(pcie_port);
2062 +
2063 +       pcie_ep_gpio_rst_init(pcie_port);
2064 +
2065 +       /* 
2066 +        * XXX, PCIe elastic buffer bug will cause not to be detected. One more 
2067 +        * reset PCIe PHY will solve this issue 
2068 +        */
2069 +       for (i = 0; i < IFX_PCIE_PHY_LOOP_CNT; i++) {
2070 +               /* Disable PCIe PHY Analog part for sanity check */
2071 +               pcie_phy_pmu_disable(pcie_port);
2072 +               pcie_phy_rst(pcie_port);
2073 +               /* PCIe Core reset enabled, low active, sw programmed */
2074 +               pcie_core_rst_assert(pcie_port);
2075 +               /* Put PCIe EP in reset status */
2076 +               pcie_device_rst_assert(pcie_port);
2077 +               /* PCI PHY & Core reset disabled, high active, sw programmed */
2078 +               pcie_core_rst_deassert(pcie_port);
2079 +               /* Already in a quiet state, program PLL, enable PHY, check ready bit */
2080 +               pcie_phy_clock_mode_setup(pcie_port);
2081 +               /* Enable PCIe PHY and Clock */
2082 +               pcie_core_pmu_setup(pcie_port);
2083 +               /* Clear status registers */
2084 +               pcie_status_register_clear(pcie_port);
2085 +#ifdef CONFIG_PCI_MSI
2086 +               pcie_msi_init(pcie_port);
2087 +#endif /* CONFIG_PCI_MSI */
2088 +               pcie_rc_cfg_reg_setup(pcie_port);
2089 +
2090 +               /* Once link is up, break out */
2091 +               if (pcie_app_loigc_setup(pcie_port) == 0)
2092 +                       break;
2093 +       }
2094 +       if (i >= IFX_PCIE_PHY_LOOP_CNT) {
2095 +               printk(KERN_ERR "%s link up failed!!!!!\n", __func__);
2096 +               return -EIO;
2097 +       }
2098 +       /* NB, don't increase ACK/NACK timer timeout value, which will cause a lot of COR errors */
2099 +       pcie_replay_time_update(pcie_port);
2100 +       return 0;
2101 +}
2102 +
2103 +static int inline ifx_pcie_startup_port_nr(void)
2104 +{
2105 +       int pcie_port = IFX_PCIE_PORT0;
2106 +
2107 +       pcie_port = IFX_PCIE_PORT0;
2108 +       return pcie_port;
2109 +}
2110 +
2111 +/** 
2112 + * \fn static int __init ifx_pcie_bios_init(void)
2113 + * \brief Initialize the IFX PCIe controllers
2114 + *
2115 + * \return -EIO    PCIe PHY link is not up
2116 + * \return -ENOMEM Configuration/IO space failed to map
2117 + * \return 0       OK
2118 + * \ingroup IFX_PCIE_OS
2119 + */ 
2120 +extern int (*ltqpci_plat_arch_init)(struct pci_dev *dev);
2121 +extern int (*ltqpci_map_irq)(const struct pci_dev *dev, u8 slot, u8 pin);
2122 +static int __devinit ltq_pcie_probe(struct platform_device *pdev)
2123 +{
2124 +       char ver_str[128] = {0};
2125 +       void __iomem *io_map_base;
2126 +       int pcie_port;
2127 +       int startup_port;
2128 +       ltqpci_map_irq = ifx_pcie_bios_map_irq;
2129 +       ltqpci_plat_arch_init = ifx_pcie_bios_plat_dev_init;
2130 +       /* Enable AHB Master/ Slave */
2131 +       pcie_ahb_pmu_setup();
2132 +
2133 +       startup_port = ifx_pcie_startup_port_nr();
2134 +
2135 +       ltq_gpio_request(&pdev->dev, IFX_PCIE_GPIO_RESET, 0, 1, "pcie-reset");
2136 +
2137 +       for (pcie_port = startup_port; pcie_port < IFX_PCIE_CORE_NR; pcie_port++){
2138 +               if (pcie_rc_initialize(pcie_port) == 0) {
2139 +                       /* Otherwise, warning will pop up */
2140 +                       io_map_base = ioremap(PCIE_IO_PHY_PORT_TO_BASE(pcie_port), PCIE_IO_SIZE);
2141 +                       if (io_map_base == NULL)
2142 +                               return -ENOMEM;
2143 +                       ifx_pcie_controller[pcie_port].pcic.io_map_base = (unsigned long)io_map_base;
2144 +                       register_pci_controller(&ifx_pcie_controller[pcie_port].pcic);
2145 +                       /* XXX, clear error status */
2146 +                       pcie_rc_core_int_init(pcie_port);
2147 +               }
2148 +       }
2149 +
2150 +       printk(KERN_INFO "%s", ver_str);
2151 +return 0;
2152 +}
2153 +
2154 +static struct platform_driver ltq_pcie_driver = {
2155 +       .probe = ltq_pcie_probe,
2156 +       .driver = {
2157 +               .name = "pcie-xway",
2158 +               .owner = THIS_MODULE,
2159 +       },
2160 +};
2161 +
2162 +int __init pciebios_init(void)
2163 +{
2164 +       return platform_driver_register(&ltq_pcie_driver);
2165 +}
2166 +
2167 +arch_initcall(pciebios_init);
2168 --- /dev/null
2169 +++ b/arch/mips/pci/pcie-lantiq.h
2170 @@ -0,0 +1,1305 @@
2171 +/******************************************************************************
2172 +**
2173 +** FILE NAME    : ifxmips_pcie_reg.h
2174 +** PROJECT      : IFX UEIP for VRX200
2175 +** MODULES      : PCIe module
2176 +**
2177 +** DATE         : 02 Mar 2009
2178 +** AUTHOR       : Lei Chuanhua
2179 +** DESCRIPTION  : PCIe Root Complex Driver
2180 +** COPYRIGHT    :       Copyright (c) 2009
2181 +**                      Infineon Technologies AG
2182 +**                      Am Campeon 1-12, 85579 Neubiberg, Germany
2183 +**
2184 +**    This program is free software; you can redistribute it and/or modify
2185 +**    it under the terms of the GNU General Public License as published by
2186 +**    the Free Software Foundation; either version 2 of the License, or
2187 +**    (at your option) any later version.
2188 +** HISTORY
2189 +** $Version $Date        $Author         $Comment
2190 +** 0.0.1    17 Mar,2009  Lei Chuanhua    Initial version
2191 +*******************************************************************************/
2192 +#ifndef IFXMIPS_PCIE_REG_H
2193 +#define IFXMIPS_PCIE_REG_H
2194 +#include <linux/version.h>
2195 +#include <linux/types.h>
2196 +#include <linux/pci.h>
2197 +#include <linux/interrupt.h>
2198 +/*!
2199 + \file ifxmips_pcie_reg.h
2200 + \ingroup IFX_PCIE  
2201 + \brief header file for PCIe module register definition
2202 +*/
2203 +/* PCIe Address Mapping Base */
2204 +#define PCIE_CFG_PHY_BASE        0x1D000000UL
2205 +#define PCIE_CFG_BASE           (KSEG1 + PCIE_CFG_PHY_BASE)
2206 +#define PCIE_CFG_SIZE           (8 * 1024 * 1024)
2207 +
2208 +#define PCIE_MEM_PHY_BASE        0x1C000000UL
2209 +#define PCIE_MEM_BASE           (KSEG1 + PCIE_MEM_PHY_BASE)
2210 +#define PCIE_MEM_SIZE           (16 * 1024 * 1024)
2211 +#define PCIE_MEM_PHY_END        (PCIE_MEM_PHY_BASE + PCIE_MEM_SIZE - 1)
2212 +
2213 +#define PCIE_IO_PHY_BASE         0x1D800000UL
2214 +#define PCIE_IO_BASE            (KSEG1 + PCIE_IO_PHY_BASE)
2215 +#define PCIE_IO_SIZE            (1 * 1024 * 1024)
2216 +#define PCIE_IO_PHY_END         (PCIE_IO_PHY_BASE + PCIE_IO_SIZE - 1)
2217 +
2218 +#define PCIE_RC_CFG_BASE        (KSEG1 + 0x1D900000)
2219 +#define PCIE_APP_LOGIC_REG      (KSEG1 + 0x1E100900)
2220 +#define PCIE_MSI_PHY_BASE        0x1F600000UL
2221 +
2222 +#define PCIE_PDI_PHY_BASE        0x1F106800UL
2223 +#define PCIE_PDI_BASE           (KSEG1 + PCIE_PDI_PHY_BASE)
2224 +#define PCIE_PDI_SIZE            0x400
2225 +
2226 +#define PCIE1_CFG_PHY_BASE        0x19000000UL
2227 +#define PCIE1_CFG_BASE           (KSEG1 + PCIE1_CFG_PHY_BASE)
2228 +#define PCIE1_CFG_SIZE           (8 * 1024 * 1024)
2229 +
2230 +#define PCIE1_MEM_PHY_BASE        0x18000000UL
2231 +#define PCIE1_MEM_BASE           (KSEG1 + PCIE1_MEM_PHY_BASE)
2232 +#define PCIE1_MEM_SIZE           (16 * 1024 * 1024)
2233 +#define PCIE1_MEM_PHY_END        (PCIE1_MEM_PHY_BASE + PCIE1_MEM_SIZE - 1)
2234 +
2235 +#define PCIE1_IO_PHY_BASE         0x19800000UL
2236 +#define PCIE1_IO_BASE            (KSEG1 + PCIE1_IO_PHY_BASE)
2237 +#define PCIE1_IO_SIZE            (1 * 1024 * 1024)
2238 +#define PCIE1_IO_PHY_END         (PCIE1_IO_PHY_BASE + PCIE1_IO_SIZE - 1)
2239 +
2240 +#define PCIE1_RC_CFG_BASE        (KSEG1 + 0x19900000)
2241 +#define PCIE1_APP_LOGIC_REG      (KSEG1 + 0x1E100700)
2242 +#define PCIE1_MSI_PHY_BASE        0x1F400000UL
2243 +
2244 +#define PCIE1_PDI_PHY_BASE        0x1F700400UL
2245 +#define PCIE1_PDI_BASE           (KSEG1 + PCIE1_PDI_PHY_BASE)
2246 +#define PCIE1_PDI_SIZE            0x400
2247 +
2248 +#define PCIE_CFG_PORT_TO_BASE(X)     ((X) > 0 ? (PCIE1_CFG_BASE) : (PCIE_CFG_BASE))
2249 +#define PCIE_MEM_PORT_TO_BASE(X)     ((X) > 0 ? (PCIE1_MEM_BASE) : (PCIE_MEM_BASE))
2250 +#define PCIE_IO_PORT_TO_BASE(X)      ((X) > 0 ? (PCIE1_IO_BASE) : (PCIE_IO_BASE))
2251 +#define PCIE_MEM_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_MEM_PHY_BASE) : (PCIE_MEM_PHY_BASE))
2252 +#define PCIE_MEM_PHY_PORT_TO_END(X)  ((X) > 0 ? (PCIE1_MEM_PHY_END) : (PCIE_MEM_PHY_END))
2253 +#define PCIE_IO_PHY_PORT_TO_BASE(X)  ((X) > 0 ? (PCIE1_IO_PHY_BASE) : (PCIE_IO_PHY_BASE))
2254 +#define PCIE_IO_PHY_PORT_TO_END(X)   ((X) > 0 ? (PCIE1_IO_PHY_END) : (PCIE_IO_PHY_END))
2255 +#define PCIE_APP_PORT_TO_BASE(X)     ((X) > 0 ? (PCIE1_APP_LOGIC_REG) : (PCIE_APP_LOGIC_REG))
2256 +#define PCIE_RC_PORT_TO_BASE(X)      ((X) > 0 ? (PCIE1_RC_CFG_BASE) : (PCIE_RC_CFG_BASE))
2257 +#define PCIE_PHY_PORT_TO_BASE(X)     ((X) > 0 ? (PCIE1_PDI_BASE) : (PCIE_PDI_BASE))
2258 +
2259 +/* PCIe Application Logic Register */
2260 +/* RC Core Control Register */
2261 +#define PCIE_RC_CCR(X)                      (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x10)
2262 +/* This should be enabled after initializing configuratin registers
2263 + * Also should check link status retraining bit
2264 + */
2265 +#define PCIE_RC_CCR_LTSSM_ENABLE             0x00000001    /* Enable LTSSM to continue link establishment */
2266 +
2267 +/* RC Core Debug Register */
2268 +#define PCIE_RC_DR(X)                       (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x14)
2269 +#define PCIE_RC_DR_DLL_UP                    0x00000001  /* Data Link Layer Up */
2270 +#define PCIE_RC_DR_CURRENT_POWER_STATE       0x0000000E  /* Current Power State */
2271 +#define PCIE_RC_DR_CURRENT_POWER_STATE_S     1
2272 +#define PCIE_RC_DR_CURRENT_LTSSM_STATE       0x000001F0  /* Current LTSSM State */
2273 +#define PCIE_RC_DR_CURRENT_LTSSM_STATE_S     4
2274 +
2275 +#define PCIE_RC_DR_PM_DEV_STATE              0x00000E00  /* Power Management D-State */
2276 +#define PCIE_RC_DR_PM_DEV_STATE_S            9
2277 +
2278 +#define PCIE_RC_DR_PM_ENABLED                0x00001000  /* Power Management State from PMU */
2279 +#define PCIE_RC_DR_PME_EVENT_ENABLED         0x00002000  /* Power Management Event Enable State */
2280 +#define PCIE_RC_DR_AUX_POWER_ENABLED         0x00004000  /* Auxiliary Power Enable */
2281 +
2282 +/* Current Power State Definition */
2283 +enum {
2284 +    PCIE_RC_DR_D0 = 0,
2285 +    PCIE_RC_DR_D1,   /* Not supported */
2286 +    PCIE_RC_DR_D2,   /* Not supported */
2287 +    PCIE_RC_DR_D3,
2288 +    PCIE_RC_DR_UN,
2289 +};
2290 +
2291 +/* PHY Link Status Register */
2292 +#define PCIE_PHY_SR(X)                      (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x18)
2293 +#define PCIE_PHY_SR_PHY_LINK_UP              0x00000001   /* PHY Link Up/Down Indicator */
2294 +
2295 +/* Electromechanical Control Register */
2296 +#define PCIE_EM_CR(X)                       (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x1C)
2297 +#define PCIE_EM_CR_CARD_IS_PRESENT           0x00000001  /* Card Presence Detect State */
2298 +#define PCIE_EM_CR_MRL_OPEN                  0x00000002  /* MRL Sensor State */
2299 +#define PCIE_EM_CR_POWER_FAULT_SET           0x00000004  /* Power Fault Detected */
2300 +#define PCIE_EM_CR_MRL_SENSOR_SET            0x00000008  /* MRL Sensor Changed */
2301 +#define PCIE_EM_CR_PRESENT_DETECT_SET        0x00000010  /* Card Presense Detect Changed */
2302 +#define PCIE_EM_CR_CMD_CPL_INT_SET           0x00000020  /* Command Complete Interrupt */
2303 +#define PCIE_EM_CR_SYS_INTERLOCK_SET         0x00000040  /* System Electromechanical IterLock Engaged */
2304 +#define PCIE_EM_CR_ATTENTION_BUTTON_SET      0x00000080  /* Attention Button Pressed */
2305 +
2306 +/* Interrupt Status Register */
2307 +#define PCIE_IR_SR(X)                       (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x20)
2308 +#define PCIE_IR_SR_PME_CAUSE_MSI             0x00000002  /* MSI caused by PME */
2309 +#define PCIE_IR_SR_HP_PME_WAKE_GEN           0x00000004  /* Hotplug PME Wake Generation */
2310 +#define PCIE_IR_SR_HP_MSI                    0x00000008  /* Hotplug MSI */
2311 +#define PCIE_IR_SR_AHB_LU_ERR                0x00000030  /* AHB Bridge Lookup Error Signals */
2312 +#define PCIE_IR_SR_AHB_LU_ERR_S              4
2313 +#define PCIE_IR_SR_INT_MSG_NUM               0x00003E00  /* Interrupt Message Number */
2314 +#define PCIE_IR_SR_INT_MSG_NUM_S             9
2315 +#define PCIE_IR_SR_AER_INT_MSG_NUM           0xF8000000  /* Advanced Error Interrupt Message Number */
2316 +#define PCIE_IR_SR_AER_INT_MSG_NUM_S         27
2317 +
2318 +/* Message Control Register */
2319 +#define PCIE_MSG_CR(X)                      (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x30)
2320 +#define PCIE_MSG_CR_GEN_PME_TURN_OFF_MSG     0x00000001  /* Generate PME Turn Off Message */
2321 +#define PCIE_MSG_CR_GEN_UNLOCK_MSG           0x00000002  /* Generate Unlock Message */
2322 +
2323 +#define PCIE_VDM_DR(X)                      (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x34)
2324 +
2325 +/* Vendor-Defined Message Requester ID Register */
2326 +#define PCIE_VDM_RID(X)                     (PCIE_APP_PORT_TO_BASE (X) + 0x38)
2327 +#define PCIE_VDM_RID_VENROR_MSG_REQ_ID       0x0000FFFF
2328 +#define PCIE_VDM_RID_VDMRID_S                0
2329 +
2330 +/* ASPM Control Register */
2331 +#define PCIE_ASPM_CR(X)                     (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x40)
2332 +#define PCIE_ASPM_CR_HOT_RST                 0x00000001  /* Hot Reset Request to the downstream device */
2333 +#define PCIE_ASPM_CR_REQ_EXIT_L1             0x00000002  /* Request to Exit L1 */
2334 +#define PCIE_ASPM_CR_REQ_ENTER_L1            0x00000004  /* Request to Enter L1 */
2335 +
2336 +/* Vendor Message DW0 Register */
2337 +#define PCIE_VM_MSG_DW0(X)                  (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x50)
2338 +#define PCIE_VM_MSG_DW0_TYPE                 0x0000001F  /* Message type */
2339 +#define PCIE_VM_MSG_DW0_TYPE_S               0
2340 +#define PCIE_VM_MSG_DW0_FORMAT               0x00000060  /* Format */
2341 +#define PCIE_VM_MSG_DW0_FORMAT_S             5
2342 +#define PCIE_VM_MSG_DW0_TC                   0x00007000  /* Traffic Class */
2343 +#define PCIE_VM_MSG_DW0_TC_S                 12
2344 +#define PCIE_VM_MSG_DW0_ATTR                 0x000C0000  /* Atrributes */
2345 +#define PCIE_VM_MSG_DW0_ATTR_S               18
2346 +#define PCIE_VM_MSG_DW0_EP_TLP               0x00100000  /* Poisoned TLP */
2347 +#define PCIE_VM_MSG_DW0_TD                   0x00200000  /* TLP Digest */
2348 +#define PCIE_VM_MSG_DW0_LEN                  0xFFC00000  /* Length */
2349 +#define PCIE_VM_MSG_DW0_LEN_S                22
2350 +
2351 +/* Format Definition */
2352 +enum {
2353 +    PCIE_VM_MSG_FORMAT_00 = 0,  /* 3DW Hdr, no data*/
2354 +    PCIE_VM_MSG_FORMAT_01,      /* 4DW Hdr, no data */
2355 +    PCIE_VM_MSG_FORMAT_10,      /* 3DW Hdr, with data */
2356 +    PCIE_VM_MSG_FORMAT_11,      /* 4DW Hdr, with data */
2357 +};
2358 +
2359 +/* Traffic Class Definition */
2360 +enum {
2361 +    PCIE_VM_MSG_TC0 = 0,
2362 +    PCIE_VM_MSG_TC1,
2363 +    PCIE_VM_MSG_TC2,
2364 +    PCIE_VM_MSG_TC3,
2365 +    PCIE_VM_MSG_TC4,
2366 +    PCIE_VM_MSG_TC5,
2367 +    PCIE_VM_MSG_TC6,
2368 +    PCIE_VM_MSG_TC7,
2369 +};
2370 +
2371 +/* Attributes Definition */
2372 +enum {
2373 +    PCIE_VM_MSG_ATTR_00 = 0,   /* RO and No Snoop cleared */
2374 +    PCIE_VM_MSG_ATTR_01,       /* RO cleared , No Snoop set */
2375 +    PCIE_VM_MSG_ATTR_10,       /* RO set, No Snoop cleared*/
2376 +    PCIE_VM_MSG_ATTR_11,       /* RO and No Snoop set */
2377 +};
2378 +
2379 +/* Payload Size Definition */
2380 +#define PCIE_VM_MSG_LEN_MIN  0
2381 +#define PCIE_VM_MSG_LEN_MAX  1024
2382 +
2383 +/* Vendor Message DW1 Register */
2384 +#define PCIE_VM_MSG_DW1(X)                 (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x54)
2385 +#define PCIE_VM_MSG_DW1_FUNC_NUM            0x00000070  /* Function Number */
2386 +#define PCIE_VM_MSG_DW1_FUNC_NUM_S          8
2387 +#define PCIE_VM_MSG_DW1_CODE                0x00FF0000  /* Message Code */
2388 +#define PCIE_VM_MSG_DW1_CODE_S              16
2389 +#define PCIE_VM_MSG_DW1_TAG                 0xFF000000  /* Tag */
2390 +#define PCIE_VM_MSG_DW1_TAG_S               24
2391 +
2392 +#define PCIE_VM_MSG_DW2(X)                  (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x58)
2393 +#define PCIE_VM_MSG_DW3(X)                  (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x5C)
2394 +
2395 +/* Vendor Message Request Register */
2396 +#define PCIE_VM_MSG_REQR(X)                 (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x60)
2397 +#define PCIE_VM_MSG_REQR_REQ                 0x00000001  /* Vendor Message Request */
2398 +
2399 +
2400 +/* AHB Slave Side Band Control Register */
2401 +#define PCIE_AHB_SSB(X)                     (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x70)
2402 +#define PCIE_AHB_SSB_REQ_BCM                0x00000001 /* Slave Reques BCM filed */
2403 +#define PCIE_AHB_SSB_REQ_EP                 0x00000002 /* Slave Reques EP filed */
2404 +#define PCIE_AHB_SSB_REQ_TD                 0x00000004 /* Slave Reques TD filed */
2405 +#define PCIE_AHB_SSB_REQ_ATTR               0x00000018 /* Slave Reques Attribute number */
2406 +#define PCIE_AHB_SSB_REQ_ATTR_S             3
2407 +#define PCIE_AHB_SSB_REQ_TC                 0x000000E0 /* Slave Request TC Field */
2408 +#define PCIE_AHB_SSB_REQ_TC_S               5
2409 +
2410 +/* AHB Master SideBand Ctrl Register */
2411 +#define PCIE_AHB_MSB(X)                     (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x74)
2412 +#define PCIE_AHB_MSB_RESP_ATTR               0x00000003 /* Master Response Attribute number */
2413 +#define PCIE_AHB_MSB_RESP_ATTR_S             0
2414 +#define PCIE_AHB_MSB_RESP_BAD_EOT            0x00000004 /* Master Response Badeot filed */
2415 +#define PCIE_AHB_MSB_RESP_BCM                0x00000008 /* Master Response BCM filed */
2416 +#define PCIE_AHB_MSB_RESP_EP                 0x00000010 /* Master Response EP filed */
2417 +#define PCIE_AHB_MSB_RESP_TD                 0x00000020 /* Master Response TD filed */
2418 +#define PCIE_AHB_MSB_RESP_FUN_NUM            0x000003C0 /* Master Response Function number */
2419 +#define PCIE_AHB_MSB_RESP_FUN_NUM_S          6
2420 +
2421 +/* AHB Control Register, fixed bus enumeration exception */
2422 +#define PCIE_AHB_CTRL(X)                     (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x78)
2423 +#define PCIE_AHB_CTRL_BUS_ERROR_SUPPRESS     0x00000001 
2424 +
2425 +/* Interrupt Enalbe Register */
2426 +#define PCIE_IRNEN(X)                        (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xF4)
2427 +#define PCIE_IRNCR(X)                        (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xF8)
2428 +#define PCIE_IRNICR(X)                       (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xFC)
2429 +
2430 +/* PCIe interrupt enable/control/capture register definition */
2431 +#define PCIE_IRN_AER_REPORT                 0x00000001  /* AER Interrupt */
2432 +#define PCIE_IRN_AER_MSIX                   0x00000002  /* Advanced Error MSI-X Interrupt */
2433 +#define PCIE_IRN_PME                        0x00000004  /* PME Interrupt */
2434 +#define PCIE_IRN_HOTPLUG                    0x00000008  /* Hotplug Interrupt */
2435 +#define PCIE_IRN_RX_VDM_MSG                 0x00000010  /* Vendor-Defined Message Interrupt */
2436 +#define PCIE_IRN_RX_CORRECTABLE_ERR_MSG     0x00000020  /* Correctable Error Message Interrupt */
2437 +#define PCIE_IRN_RX_NON_FATAL_ERR_MSG       0x00000040  /* Non-fatal Error Message */
2438 +#define PCIE_IRN_RX_FATAL_ERR_MSG           0x00000080  /* Fatal Error Message */
2439 +#define PCIE_IRN_RX_PME_MSG                 0x00000100  /* PME Message Interrupt */
2440 +#define PCIE_IRN_RX_PME_TURNOFF_ACK         0x00000200  /* PME Turnoff Ack Message Interrupt */
2441 +#define PCIE_IRN_AHB_BR_FATAL_ERR           0x00000400  /* AHB Fatal Error Interrupt */
2442 +#define PCIE_IRN_LINK_AUTO_BW_STATUS        0x00000800  /* Link Auto Bandwidth Status Interrupt */
2443 +#define PCIE_IRN_BW_MGT                     0x00001000  /* Bandwidth Managment Interrupt */
2444 +#define PCIE_IRN_INTA                       0x00002000  /* INTA */
2445 +#define PCIE_IRN_INTB                       0x00004000  /* INTB */
2446 +#define PCIE_IRN_INTC                       0x00008000  /* INTC */
2447 +#define PCIE_IRN_INTD                       0x00010000  /* INTD */
2448 +#define PCIE_IRN_WAKEUP                     0x00020000  /* Wake up Interrupt */
2449 +
2450 +#define PCIE_RC_CORE_COMBINED_INT    (PCIE_IRN_AER_REPORT |  PCIE_IRN_AER_MSIX | PCIE_IRN_PME | \
2451 +                                      PCIE_IRN_HOTPLUG | PCIE_IRN_RX_VDM_MSG | PCIE_IRN_RX_CORRECTABLE_ERR_MSG |\
2452 +                                      PCIE_IRN_RX_NON_FATAL_ERR_MSG | PCIE_IRN_RX_FATAL_ERR_MSG | \
2453 +                                      PCIE_IRN_RX_PME_MSG | PCIE_IRN_RX_PME_TURNOFF_ACK | PCIE_IRN_AHB_BR_FATAL_ERR | \
2454 +                                      PCIE_IRN_LINK_AUTO_BW_STATUS | PCIE_IRN_BW_MGT)
2455 +/* PCIe RC Configuration Register */
2456 +#define PCIE_VDID(X)                (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x00)
2457 +
2458 +/* Bit definition from pci_reg.h */
2459 +#define PCIE_PCICMDSTS(X)           (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x04)
2460 +#define PCIE_CCRID(X)               (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x08)
2461 +#define PCIE_CLSLTHTBR(X)           (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x0C) /* EP only */
2462 +/* BAR0, BAR1,Only necessary if the bridges implements a device-specific register set or memory buffer */
2463 +#define PCIE_BAR0(X)                (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x10) /* Not used*/
2464 +#define PCIE_BAR1(X)                (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x14) /* Not used */
2465 +
2466 +#define PCIE_BNR(X)                 (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x18) /* Mandatory */
2467 +/* Bus Number Register bits */
2468 +#define PCIE_BNR_PRIMARY_BUS_NUM             0x000000FF
2469 +#define PCIE_BNR_PRIMARY_BUS_NUM_S           0
2470 +#define PCIE_PNR_SECONDARY_BUS_NUM           0x0000FF00
2471 +#define PCIE_PNR_SECONDARY_BUS_NUM_S         8
2472 +#define PCIE_PNR_SUB_BUS_NUM                 0x00FF0000
2473 +#define PCIE_PNR_SUB_BUS_NUM_S               16
2474 +
2475 +/* IO Base/Limit Register bits */
2476 +#define PCIE_IOBLSECS(X)                       (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x1C)  /* RC only */
2477 +#define PCIE_IOBLSECS_32BIT_IO_ADDR             0x00000001
2478 +#define PCIE_IOBLSECS_IO_BASE_ADDR              0x000000F0
2479 +#define PCIE_IOBLSECS_IO_BASE_ADDR_S            4
2480 +#define PCIE_IOBLSECS_32BIT_IOLIMT              0x00000100
2481 +#define PCIE_IOBLSECS_IO_LIMIT_ADDR             0x0000F000
2482 +#define PCIE_IOBLSECS_IO_LIMIT_ADDR_S           12
2483 +
2484 +/* Non-prefetchable Memory Base/Limit Register bit */
2485 +#define PCIE_MBML(X)                           (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x20)  /* RC only */
2486 +#define PCIE_MBML_MEM_BASE_ADDR                 0x0000FFF0
2487 +#define PCIE_MBML_MEM_BASE_ADDR_S               4
2488 +#define PCIE_MBML_MEM_LIMIT_ADDR                0xFFF00000
2489 +#define PCIE_MBML_MEM_LIMIT_ADDR_S              20
2490 +
2491 +/* Prefetchable Memory Base/Limit Register bit */
2492 +#define PCIE_PMBL(X)                           (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x24)  /* RC only */
2493 +#define PCIE_PMBL_64BIT_ADDR                    0x00000001
2494 +#define PCIE_PMBL_UPPER_12BIT                   0x0000FFF0
2495 +#define PCIE_PMBL_UPPER_12BIT_S                 4
2496 +#define PCIE_PMBL_E64MA                         0x00010000
2497 +#define PCIE_PMBL_END_ADDR                      0xFFF00000
2498 +#define PCIE_PMBL_END_ADDR_S                    20
2499 +#define PCIE_PMBU32(X)                          (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x28)  /* RC only */
2500 +#define PCIE_PMLU32(X)                          (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x2C)  /* RC only */
2501 +
2502 +/* I/O Base/Limit Upper 16 bits register */
2503 +#define PCIE_IO_BANDL(X)                        (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x30)  /* RC only */
2504 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_BASE        0x0000FFFF
2505 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_BASE_S      0
2506 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT       0xFFFF0000
2507 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT_S     16
2508 +
2509 +#define PCIE_CPR(X)                            (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x34)
2510 +#define PCIE_EBBAR(X)                          (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x38)
2511 +
2512 +/* Interrupt and Secondary Bridge Control Register */
2513 +#define PCIE_INTRBCTRL(X)                      (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x3C)
2514 +
2515 +#define PCIE_INTRBCTRL_INT_LINE                 0x000000FF
2516 +#define PCIE_INTRBCTRL_INT_LINE_S               0
2517 +#define PCIE_INTRBCTRL_INT_PIN                  0x0000FF00
2518 +#define PCIE_INTRBCTRL_INT_PIN_S                8
2519 +#define PCIE_INTRBCTRL_PARITY_ERR_RESP_ENABLE   0x00010000    /* #PERR */
2520 +#define PCIE_INTRBCTRL_SERR_ENABLE              0x00020000    /* #SERR */
2521 +#define PCIE_INTRBCTRL_ISA_ENABLE               0x00040000    /* ISA enable, IO 64KB only */
2522 +#define PCIE_INTRBCTRL_VGA_ENABLE               0x00080000    /* VGA enable */
2523 +#define PCIE_INTRBCTRL_VGA_16BIT_DECODE         0x00100000    /* VGA 16bit decode */
2524 +#define PCIE_INTRBCTRL_RST_SECONDARY_BUS        0x00400000    /* Secondary bus rest, hot rest, 1ms */
2525 +/* Others are read only */
2526 +enum {
2527 +    PCIE_INTRBCTRL_INT_NON = 0,
2528 +    PCIE_INTRBCTRL_INTA,
2529 +    PCIE_INTRBCTRL_INTB,
2530 +    PCIE_INTRBCTRL_INTC,
2531 +    PCIE_INTRBCTRL_INTD,
2532 +};
2533 +
2534 +#define PCIE_PM_CAPR(X)                  (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x40)
2535 +
2536 +/* Power Management Control and Status Register */
2537 +#define PCIE_PM_CSR(X)                   (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x44)
2538 +
2539 +#define PCIE_PM_CSR_POWER_STATE           0x00000003   /* Power State */
2540 +#define PCIE_PM_CSR_POWER_STATE_S         0
2541 +#define PCIE_PM_CSR_SW_RST                0x00000008   /* Soft Reset Enabled */
2542 +#define PCIE_PM_CSR_PME_ENABLE            0x00000100   /* PME Enable */
2543 +#define PCIE_PM_CSR_PME_STATUS            0x00008000   /* PME status */
2544 +
2545 +/* MSI Capability Register for EP */
2546 +#define PCIE_MCAPR(X)                    (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x50)
2547 +
2548 +#define PCIE_MCAPR_MSI_CAP_ID             0x000000FF  /* MSI Capability ID */
2549 +#define PCIE_MCAPR_MSI_CAP_ID_S           0
2550 +#define PCIE_MCAPR_MSI_NEXT_CAP_PTR       0x0000FF00  /* Next Capability Pointer */
2551 +#define PCIE_MCAPR_MSI_NEXT_CAP_PTR_S     8
2552 +#define PCIE_MCAPR_MSI_ENABLE             0x00010000  /* MSI Enable */
2553 +#define PCIE_MCAPR_MULTI_MSG_CAP          0x000E0000  /* Multiple Message Capable */
2554 +#define PCIE_MCAPR_MULTI_MSG_CAP_S        17
2555 +#define PCIE_MCAPR_MULTI_MSG_ENABLE       0x00700000  /* Multiple Message Enable */
2556 +#define PCIE_MCAPR_MULTI_MSG_ENABLE_S     20
2557 +#define PCIE_MCAPR_ADDR64_CAP             0X00800000  /* 64-bit Address Capable */
2558 +
2559 +/* MSI Message Address Register */
2560 +#define PCIE_MA(X)                       (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x54)
2561 +
2562 +#define PCIE_MA_ADDR_MASK                 0xFFFFFFFC  /* Message Address */
2563 +
2564 +/* MSI Message Upper Address Register */
2565 +#define PCIE_MUA(X)                      (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x58)
2566 +
2567 +/* MSI Message Data Register */
2568 +#define PCIE_MD(X)                       (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x5C)
2569 +
2570 +#define PCIE_MD_DATA                      0x0000FFFF  /* Message Data */
2571 +#define PCIE_MD_DATA_S                    0
2572 +
2573 +/* PCI Express Capability Register */
2574 +#define PCIE_XCAP(X)                     (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x70)
2575 +
2576 +#define PCIE_XCAP_ID                      0x000000FF  /* PCI Express Capability ID */
2577 +#define PCIE_XCAP_ID_S                    0
2578 +#define PCIE_XCAP_NEXT_CAP                0x0000FF00  /* Next Capability Pointer */
2579 +#define PCIE_XCAP_NEXT_CAP_S              8
2580 +#define PCIE_XCAP_VER                     0x000F0000  /* PCI Express Capability Version */
2581 +#define PCIE_XCAP_VER_S                   16
2582 +#define PCIE_XCAP_DEV_PORT_TYPE           0x00F00000  /* Device Port Type */
2583 +#define PCIE_XCAP_DEV_PORT_TYPE_S         20
2584 +#define PCIE_XCAP_SLOT_IMPLEMENTED        0x01000000  /* Slot Implemented */
2585 +#define PCIE_XCAP_MSG_INT_NUM             0x3E000000  /* Interrupt Message Number */
2586 +#define PCIE_XCAP_MSG_INT_NUM_S           25
2587 +
2588 +/* Device Capability Register */
2589 +#define PCIE_DCAP(X)                     (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x74)
2590 +
2591 +#define PCIE_DCAP_MAX_PAYLOAD_SIZE        0x00000007   /* Max Payload size */
2592 +#define PCIE_DCAP_MAX_PAYLOAD_SIZE_S      0
2593 +#define PCIE_DCAP_PHANTOM_FUNC            0x00000018   /* Phanton Function, not supported */
2594 +#define PCIE_DCAP_PHANTOM_FUNC_S          3
2595 +#define PCIE_DCAP_EXT_TAG                 0x00000020   /* Extended Tag Field */
2596 +#define PCIE_DCAP_EP_L0S_LATENCY          0x000001C0   /* EP L0s latency only */
2597 +#define PCIE_DCAP_EP_L0S_LATENCY_S        6
2598 +#define PCIE_DCAP_EP_L1_LATENCY           0x00000E00   /* EP L1 latency only */
2599 +#define PCIE_DCAP_EP_L1_LATENCY_S         9
2600 +#define PCIE_DCAP_ROLE_BASE_ERR_REPORT    0x00008000   /* Role Based ERR */
2601 +
2602 +/* Maximum payload size supported */
2603 +enum {
2604 +    PCIE_MAX_PAYLOAD_128 = 0,
2605 +    PCIE_MAX_PAYLOAD_256,
2606 +    PCIE_MAX_PAYLOAD_512,
2607 +    PCIE_MAX_PAYLOAD_1024,
2608 +    PCIE_MAX_PAYLOAD_2048,
2609 +    PCIE_MAX_PAYLOAD_4096,
2610 +};
2611 +
2612 +/* Device Control and Status Register */
2613 +#define PCIE_DCTLSTS(X)                       (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x78)
2614 +
2615 +#define PCIE_DCTLSTS_CORRECTABLE_ERR_EN        0x00000001   /* COR-ERR */
2616 +#define PCIE_DCTLSTS_NONFATAL_ERR_EN           0x00000002   /* Non-fatal ERR */
2617 +#define PCIE_DCTLSTS_FATAL_ERR_EN              0x00000004   /* Fatal ERR */
2618 +#define PCIE_DCTLSYS_UR_REQ_EN                 0x00000008   /* UR ERR */
2619 +#define PCIE_DCTLSTS_RELAXED_ORDERING_EN       0x00000010   /* Enable relaxing ordering */
2620 +#define PCIE_DCTLSTS_MAX_PAYLOAD_SIZE          0x000000E0   /* Max payload mask */
2621 +#define PCIE_DCTLSTS_MAX_PAYLOAD_SIZE_S        5
2622 +#define PCIE_DCTLSTS_EXT_TAG_EN                0x00000100   /* Extended tag field */
2623 +#define PCIE_DCTLSTS_PHANTOM_FUNC_EN           0x00000200   /* Phantom Function Enable */
2624 +#define PCIE_DCTLSTS_AUX_PM_EN                 0x00000400   /* AUX Power PM Enable */
2625 +#define PCIE_DCTLSTS_NO_SNOOP_EN               0x00000800   /* Enable no snoop, except root port*/
2626 +#define PCIE_DCTLSTS_MAX_READ_SIZE             0x00007000   /* Max Read Request size*/
2627 +#define PCIE_DCTLSTS_MAX_READ_SIZE_S           12
2628 +#define PCIE_DCTLSTS_CORRECTABLE_ERR           0x00010000   /* COR-ERR Detected */
2629 +#define PCIE_DCTLSTS_NONFATAL_ERR              0x00020000   /* Non-Fatal ERR Detected */
2630 +#define PCIE_DCTLSTS_FATAL_ER                  0x00040000   /* Fatal ERR Detected */
2631 +#define PCIE_DCTLSTS_UNSUPPORTED_REQ           0x00080000   /* UR Detected */
2632 +#define PCIE_DCTLSTS_AUX_POWER                 0x00100000   /* Aux Power Detected */
2633 +#define PCIE_DCTLSTS_TRANSACT_PENDING          0x00200000   /* Transaction pending */
2634 +
2635 +#define PCIE_DCTLSTS_ERR_EN      (PCIE_DCTLSTS_CORRECTABLE_ERR_EN | \
2636 +                                  PCIE_DCTLSTS_NONFATAL_ERR_EN | PCIE_DCTLSTS_FATAL_ERR_EN | \
2637 +                                  PCIE_DCTLSYS_UR_REQ_EN)
2638 +
2639 +/* Link Capability Register */
2640 +#define PCIE_LCAP(X)                          (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7C)
2641 +#define PCIE_LCAP_MAX_LINK_SPEED               0x0000000F  /* Max link speed, 0x1 by default */
2642 +#define PCIE_LCAP_MAX_LINK_SPEED_S             0
2643 +#define PCIE_LCAP_MAX_LENGTH_WIDTH             0x000003F0  /* Maxium Length Width */
2644 +#define PCIE_LCAP_MAX_LENGTH_WIDTH_S           4
2645 +#define PCIE_LCAP_ASPM_LEVEL                   0x00000C00  /* Active State Link PM Support */
2646 +#define PCIE_LCAP_ASPM_LEVEL_S                 10
2647 +#define PCIE_LCAP_L0S_EIXT_LATENCY             0x00007000  /* L0s Exit Latency */
2648 +#define PCIE_LCAP_L0S_EIXT_LATENCY_S           12
2649 +#define PCIE_LCAP_L1_EXIT_LATENCY              0x00038000  /* L1 Exit Latency */
2650 +#define PCIE_LCAP_L1_EXIT_LATENCY_S            15
2651 +#define PCIE_LCAP_CLK_PM                       0x00040000  /* Clock Power Management */
2652 +#define PCIE_LCAP_SDER                         0x00080000  /* Surprise Down Error Reporting */
2653 +#define PCIE_LCAP_DLL_ACTIVE_REPROT            0x00100000  /* Data Link Layer Active Reporting Capable */
2654 +#define PCIE_LCAP_PORT_NUM                     0xFF0000000  /* Port number */
2655 +#define PCIE_LCAP_PORT_NUM_S                   24
2656 +
2657 +/* Maximum Length width definition */
2658 +#define PCIE_MAX_LENGTH_WIDTH_RES  0x00
2659 +#define PCIE_MAX_LENGTH_WIDTH_X1   0x01  /* Default */
2660 +#define PCIE_MAX_LENGTH_WIDTH_X2   0x02
2661 +#define PCIE_MAX_LENGTH_WIDTH_X4   0x04
2662 +#define PCIE_MAX_LENGTH_WIDTH_X8   0x08
2663 +#define PCIE_MAX_LENGTH_WIDTH_X12  0x0C
2664 +#define PCIE_MAX_LENGTH_WIDTH_X16  0x10
2665 +#define PCIE_MAX_LENGTH_WIDTH_X32  0x20
2666 +
2667 +/* Active State Link PM definition */
2668 +enum {
2669 +    PCIE_ASPM_RES0                = 0,
2670 +    PCIE_ASPM_L0S_ENTRY_SUPPORT,        /* L0s */
2671 +    PCIE_ASPM_RES1,
2672 +    PCIE_ASPM_L0S_L1_ENTRY_SUPPORT,     /* L0s and L1, default */
2673 +};
2674 +
2675 +/* L0s Exit Latency definition */
2676 +enum {
2677 +    PCIE_L0S_EIXT_LATENCY_L64NS    = 0, /* < 64 ns */
2678 +    PCIE_L0S_EIXT_LATENCY_B64A128,      /* > 64 ns < 128 ns */
2679 +    PCIE_L0S_EIXT_LATENCY_B128A256,     /* > 128 ns < 256 ns */
2680 +    PCIE_L0S_EIXT_LATENCY_B256A512,     /* > 256 ns < 512 ns */
2681 +    PCIE_L0S_EIXT_LATENCY_B512TO1U,     /* > 512 ns < 1 us */
2682 +    PCIE_L0S_EIXT_LATENCY_B1A2U,        /* > 1 us < 2 us */
2683 +    PCIE_L0S_EIXT_LATENCY_B2A4U,        /* > 2 us < 4 us */
2684 +    PCIE_L0S_EIXT_LATENCY_M4US,         /* > 4 us  */
2685 +};
2686 +
2687 +/* L1 Exit Latency definition */
2688 +enum {
2689 +    PCIE_L1_EXIT_LATENCY_L1US  = 0,  /* < 1 us */
2690 +    PCIE_L1_EXIT_LATENCY_B1A2,       /* > 1 us < 2 us */
2691 +    PCIE_L1_EXIT_LATENCY_B2A4,       /* > 2 us < 4 us */
2692 +    PCIE_L1_EXIT_LATENCY_B4A8,       /* > 4 us < 8 us */
2693 +    PCIE_L1_EXIT_LATENCY_B8A16,      /* > 8 us < 16 us */
2694 +    PCIE_L1_EXIT_LATENCY_B16A32,     /* > 16 us < 32 us */
2695 +    PCIE_L1_EXIT_LATENCY_B32A64,     /* > 32 us < 64 us */
2696 +    PCIE_L1_EXIT_LATENCY_M64US,      /* > 64 us */
2697 +};
2698 +
2699 +/* Link Control and Status Register */
2700 +#define PCIE_LCTLSTS(X)                     (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x80)
2701 +#define PCIE_LCTLSTS_ASPM_ENABLE            0x00000003  /* Active State Link PM Control */
2702 +#define PCIE_LCTLSTS_ASPM_ENABLE_S          0
2703 +#define PCIE_LCTLSTS_RCB128                 0x00000008  /* Read Completion Boundary 128*/
2704 +#define PCIE_LCTLSTS_LINK_DISABLE           0x00000010  /* Link Disable */
2705 +#define PCIE_LCTLSTS_RETRIAN_LINK           0x00000020  /* Retrain Link */
2706 +#define PCIE_LCTLSTS_COM_CLK_CFG            0x00000040  /* Common Clock Configuration */
2707 +#define PCIE_LCTLSTS_EXT_SYNC               0x00000080  /* Extended Synch */
2708 +#define PCIE_LCTLSTS_CLK_PM_EN              0x00000100  /* Enable Clock Powerm Management */
2709 +#define PCIE_LCTLSTS_LINK_SPEED             0x000F0000  /* Link Speed */
2710 +#define PCIE_LCTLSTS_LINK_SPEED_S           16
2711 +#define PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH  0x03F00000  /* Negotiated Link Width */
2712 +#define PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH_S 20
2713 +#define PCIE_LCTLSTS_RETRAIN_PENDING        0x08000000  /* Link training is ongoing */
2714 +#define PCIE_LCTLSTS_SLOT_CLK_CFG           0x10000000  /* Slot Clock Configuration */
2715 +#define PCIE_LCTLSTS_DLL_ACTIVE             0x20000000  /* Data Link Layer Active */
2716 +
2717 +/* Slot Capabilities Register */
2718 +#define PCIE_SLCAP(X)                       (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x84)
2719 +
2720 +/* Slot Capabilities */
2721 +#define PCIE_SLCTLSTS(X)                    (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x88)
2722 +
2723 +/* Root Control and Capability Register */
2724 +#define PCIE_RCTLCAP(X)                     (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x8C)
2725 +#define PCIE_RCTLCAP_SERR_ON_CORRECTABLE_ERR  0x00000001   /* #SERR on COR-ERR */
2726 +#define PCIE_RCTLCAP_SERR_ON_NONFATAL_ERR     0x00000002   /* #SERR on Non-Fatal ERR */
2727 +#define PCIE_RCTLCAP_SERR_ON_FATAL_ERR        0x00000004   /* #SERR on Fatal ERR */
2728 +#define PCIE_RCTLCAP_PME_INT_EN               0x00000008   /* PME Interrupt Enable */
2729 +#define PCIE_RCTLCAP_SERR_ENABLE    (PCIE_RCTLCAP_SERR_ON_CORRECTABLE_ERR | \
2730 +                                     PCIE_RCTLCAP_SERR_ON_NONFATAL_ERR | PCIE_RCTLCAP_SERR_ON_FATAL_ERR)
2731 +/* Root Status Register */
2732 +#define PCIE_RSTS(X)                          (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x90)
2733 +#define PCIE_RSTS_PME_REQ_ID                   0x0000FFFF   /* PME Request ID */
2734 +#define PCIE_RSTS_PME_REQ_ID_S                 0
2735 +#define PCIE_RSTS_PME_STATUS                   0x00010000   /* PME Status */
2736 +#define PCIE_RSTS_PME_PENDING                  0x00020000   /* PME Pending */
2737 +
2738 +/* PCI Express Enhanced Capability Header */
2739 +#define PCIE_ENHANCED_CAP(X)                (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x100)
2740 +#define PCIE_ENHANCED_CAP_ID                 0x0000FFFF  /* PCI Express Extended Capability ID */
2741 +#define PCIE_ENHANCED_CAP_ID_S               0
2742 +#define PCIE_ENHANCED_CAP_VER                0x000F0000  /* Capability Version */
2743 +#define PCIE_ENHANCED_CAP_VER_S              16
2744 +#define PCIE_ENHANCED_CAP_NEXT_OFFSET        0xFFF00000  /* Next Capability Offset */
2745 +#define PCIE_ENHANCED_CAP_NEXT_OFFSET_S      20
2746 +
2747 +/* Uncorrectable Error Status Register */
2748 +#define PCIE_UES_R(X)                       (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x104)
2749 +#define PCIE_DATA_LINK_PROTOCOL_ERR          0x00000010  /* Data Link Protocol Error Status */
2750 +#define PCIE_SURPRISE_DOWN_ERROR             0x00000020  /* Surprise Down Error Status */
2751 +#define PCIE_POISONED_TLP                    0x00001000  /* Poisoned TLP Status */
2752 +#define PCIE_FC_PROTOCOL_ERR                 0x00002000  /* Flow Control Protocol Error Status */
2753 +#define PCIE_COMPLETION_TIMEOUT              0x00004000  /* Completion Timeout Status */
2754 +#define PCIE_COMPLETOR_ABORT                 0x00008000  /* Completer Abort Error */
2755 +#define PCIE_UNEXPECTED_COMPLETION           0x00010000  /* Unexpected Completion Status */
2756 +#define PCIE_RECEIVER_OVERFLOW               0x00020000  /* Receive Overflow Status */
2757 +#define PCIE_MALFORNED_TLP                   0x00040000  /* Malformed TLP Stauts */
2758 +#define PCIE_ECRC_ERR                        0x00080000  /* ECRC Error Stauts */
2759 +#define PCIE_UR_REQ                          0x00100000  /* Unsupported Request Error Status */
2760 +#define PCIE_ALL_UNCORRECTABLE_ERR    (PCIE_DATA_LINK_PROTOCOL_ERR | PCIE_SURPRISE_DOWN_ERROR | \
2761 +                         PCIE_POISONED_TLP | PCIE_FC_PROTOCOL_ERR | PCIE_COMPLETION_TIMEOUT |   \
2762 +                         PCIE_COMPLETOR_ABORT | PCIE_UNEXPECTED_COMPLETION | PCIE_RECEIVER_OVERFLOW |\
2763 +                         PCIE_MALFORNED_TLP | PCIE_ECRC_ERR | PCIE_UR_REQ)
2764 +
2765 +/* Uncorrectable Error Mask Register, Mask means no report */
2766 +#define PCIE_UEMR(X)                        (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x108)
2767 +
2768 +/* Uncorrectable Error Severity Register */
2769 +#define PCIE_UESR(X)                        (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x10C)
2770 +
2771 +/* Correctable Error Status Register */
2772 +#define PCIE_CESR(X)                        (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x110)
2773 +#define PCIE_RX_ERR                          0x00000001  /* Receive Error Status */
2774 +#define PCIE_BAD_TLP                         0x00000040  /* Bad TLP Status */
2775 +#define PCIE_BAD_DLLP                        0x00000080  /* Bad DLLP Status */
2776 +#define PCIE_REPLAY_NUM_ROLLOVER             0x00000100  /* Replay Number Rollover Status */
2777 +#define PCIE_REPLAY_TIMER_TIMEOUT_ERR        0x00001000  /* Reply Timer Timeout Status */
2778 +#define PCIE_ADVISORY_NONFTAL_ERR            0x00002000  /* Advisory Non-Fatal Error Status */
2779 +#define PCIE_CORRECTABLE_ERR        (PCIE_RX_ERR | PCIE_BAD_TLP | PCIE_BAD_DLLP | PCIE_REPLAY_NUM_ROLLOVER |\
2780 +                                     PCIE_REPLAY_TIMER_TIMEOUT_ERR | PCIE_ADVISORY_NONFTAL_ERR)
2781 +
2782 +/* Correctable Error Mask Register */
2783 +#define PCIE_CEMR(X)                        (volatile u32*)(PCIE_RC_CFG_BASE + 0x114)
2784 +
2785 +/* Advanced Error Capabilities and Control Register */
2786 +#define PCIE_AECCR(X)                       (volatile u32*)(PCIE_RC_CFG_BASE + 0x118)
2787 +#define PCIE_AECCR_FIRST_ERR_PTR            0x0000001F  /* First Error Pointer */
2788 +#define PCIE_AECCR_FIRST_ERR_PTR_S          0
2789 +#define PCIE_AECCR_ECRC_GEN_CAP             0x00000020  /* ECRC Generation Capable */
2790 +#define PCIE_AECCR_ECRC_GEN_EN              0x00000040  /* ECRC Generation Enable */
2791 +#define PCIE_AECCR_ECRC_CHECK_CAP           0x00000080  /* ECRC Check Capable */
2792 +#define PCIE_AECCR_ECRC_CHECK_EN            0x00000100  /* ECRC Check Enable */
2793 +
2794 +/* Header Log Register 1 */
2795 +#define PCIE_HLR1(X)                        (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x11C)
2796 +
2797 +/* Header Log Register 2 */
2798 +#define PCIE_HLR2(X)                        (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x120)
2799 +
2800 +/* Header Log Register 3 */
2801 +#define PCIE_HLR3(X)                        (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x124)
2802 +
2803 +/* Header Log Register 4 */
2804 +#define PCIE_HLR4(X)                        (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x128)
2805 +
2806 +/* Root Error Command Register */
2807 +#define PCIE_RECR(X)                        (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x12C)
2808 +#define PCIE_RECR_CORRECTABLE_ERR_REPORT_EN  0x00000001 /* COR-ERR */
2809 +#define PCIE_RECR_NONFATAL_ERR_REPORT_EN     0x00000002 /* Non-Fatal ERR */
2810 +#define PCIE_RECR_FATAL_ERR_REPORT_EN        0x00000004 /* Fatal ERR */
2811 +#define PCIE_RECR_ERR_REPORT_EN  (PCIE_RECR_CORRECTABLE_ERR_REPORT_EN | \
2812 +                PCIE_RECR_NONFATAL_ERR_REPORT_EN | PCIE_RECR_FATAL_ERR_REPORT_EN)
2813 +
2814 +/* Root Error Status Register */
2815 +#define PCIE_RESR(X)                            (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x130)
2816 +#define PCIE_RESR_CORRECTABLE_ERR                0x00000001   /* COR-ERR Receveid */
2817 +#define PCIE_RESR_MULTI_CORRECTABLE_ERR          0x00000002   /* Multiple COR-ERR Received */
2818 +#define PCIE_RESR_FATAL_NOFATAL_ERR              0x00000004   /* ERR Fatal/Non-Fatal Received */
2819 +#define PCIE_RESR_MULTI_FATAL_NOFATAL_ERR        0x00000008   /* Multiple ERR Fatal/Non-Fatal Received */
2820 +#define PCIE_RESR_FIRST_UNCORRECTABLE_FATAL_ERR  0x00000010   /* First UN-COR Fatal */
2821 +#define PCIR_RESR_NON_FATAL_ERR                  0x00000020   /* Non-Fatal Error Message Received */
2822 +#define PCIE_RESR_FATAL_ERR                      0x00000040   /* Fatal Message Received */
2823 +#define PCIE_RESR_AER_INT_MSG_NUM                0xF8000000   /* Advanced Error Interrupt Message Number */
2824 +#define PCIE_RESR_AER_INT_MSG_NUM_S              27
2825 +
2826 +/* Error Source Indentification Register */
2827 +#define PCIE_ESIR(X)                            (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x134)
2828 +#define PCIE_ESIR_CORRECTABLE_ERR_SRC_ID         0x0000FFFF
2829 +#define PCIE_ESIR_CORRECTABLE_ERR_SRC_ID_S       0
2830 +#define PCIE_ESIR_FATAL_NON_FATAL_SRC_ID         0xFFFF0000
2831 +#define PCIE_ESIR_FATAL_NON_FATAL_SRC_ID_S       16
2832 +
2833 +/* VC Enhanced Capability Header */
2834 +#define PCIE_VC_ECH(X)                          (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x140)
2835 +
2836 +/* Port VC Capability Register */
2837 +#define PCIE_PVC1(X)                            (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x144)
2838 +#define PCIE_PVC1_EXT_VC_CNT                    0x00000007  /* Extended VC Count */
2839 +#define PCIE_PVC1_EXT_VC_CNT_S                  0
2840 +#define PCIE_PVC1_LOW_PRI_EXT_VC_CNT            0x00000070  /* Low Priority Extended VC Count */
2841 +#define PCIE_PVC1_LOW_PRI_EXT_VC_CNT_S          4
2842 +#define PCIE_PVC1_REF_CLK                       0x00000300  /* Reference Clock */
2843 +#define PCIE_PVC1_REF_CLK_S                     8
2844 +#define PCIE_PVC1_PORT_ARB_TAB_ENTRY_SIZE       0x00000C00  /* Port Arbitration Table Entry Size */
2845 +#define PCIE_PVC1_PORT_ARB_TAB_ENTRY_SIZE_S     10
2846 +
2847 +/* Extended Virtual Channel Count Defintion */
2848 +#define PCIE_EXT_VC_CNT_MIN   0
2849 +#define PCIE_EXT_VC_CNT_MAX   7
2850 +
2851 +/* Port Arbitration Table Entry Size Definition */
2852 +enum {
2853 +    PCIE_PORT_ARB_TAB_ENTRY_SIZE_S1BIT = 0,
2854 +    PCIE_PORT_ARB_TAB_ENTRY_SIZE_S2BIT,
2855 +    PCIE_PORT_ARB_TAB_ENTRY_SIZE_S4BIT,
2856 +    PCIE_PORT_ARB_TAB_ENTRY_SIZE_S8BIT,
2857 +};
2858 +
2859 +/* Port VC Capability Register 2 */
2860 +#define PCIE_PVC2(X)                        (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x148)
2861 +#define PCIE_PVC2_VC_ARB_16P_FIXED_WRR      0x00000001  /* HW Fixed arbitration, 16 phase WRR */
2862 +#define PCIE_PVC2_VC_ARB_32P_WRR            0x00000002  /* 32 phase WRR */
2863 +#define PCIE_PVC2_VC_ARB_64P_WRR            0x00000004  /* 64 phase WRR */
2864 +#define PCIE_PVC2_VC_ARB_128P_WRR           0x00000008  /* 128 phase WRR */
2865 +#define PCIE_PVC2_VC_ARB_WRR                0x0000000F
2866 +#define PCIE_PVC2_VC_ARB_TAB_OFFSET         0xFF000000  /* VC arbitration table offset, not support */
2867 +#define PCIE_PVC2_VC_ARB_TAB_OFFSET_S       24
2868 +
2869 +/* Port VC Control and Status Register */     
2870 +#define PCIE_PVCCRSR(X)                     (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x14C)
2871 +#define PCIE_PVCCRSR_LOAD_VC_ARB_TAB         0x00000001  /* Load VC Arbitration Table */
2872 +#define PCIE_PVCCRSR_VC_ARB_SEL              0x0000000E  /* VC Arbitration Select */
2873 +#define PCIE_PVCCRSR_VC_ARB_SEL_S            1
2874 +#define PCIE_PVCCRSR_VC_ARB_TAB_STATUS       0x00010000  /* Arbitration Status */
2875 +
2876 +/* VC0 Resource Capability Register */
2877 +#define PCIE_VC0_RC(X)                       (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x150)
2878 +#define PCIE_VC0_RC_PORT_ARB_HW_FIXED        0x00000001  /* HW Fixed arbitration */
2879 +#define PCIE_VC0_RC_PORT_ARB_32P_WRR         0x00000002  /* 32 phase WRR */
2880 +#define PCIE_VC0_RC_PORT_ARB_64P_WRR         0x00000004  /* 64 phase WRR */
2881 +#define PCIE_VC0_RC_PORT_ARB_128P_WRR        0x00000008  /* 128 phase WRR */
2882 +#define PCIE_VC0_RC_PORT_ARB_TM_128P_WRR     0x00000010  /* Time-based 128 phase WRR */
2883 +#define PCIE_VC0_RC_PORT_ARB_TM_256P_WRR     0x00000020  /* Time-based 256 phase WRR */
2884 +#define PCIE_VC0_RC_PORT_ARB          (PCIE_VC0_RC_PORT_ARB_HW_FIXED | PCIE_VC0_RC_PORT_ARB_32P_WRR |\
2885 +                        PCIE_VC0_RC_PORT_ARB_64P_WRR | PCIE_VC0_RC_PORT_ARB_128P_WRR | \
2886 +                        PCIE_VC0_RC_PORT_ARB_TM_128P_WRR | PCIE_VC0_RC_PORT_ARB_TM_256P_WRR)
2887 +
2888 +#define PCIE_VC0_RC_REJECT_SNOOP             0x00008000  /* Reject Snoop Transactioin */
2889 +#define PCIE_VC0_RC_MAX_TIMESLOTS            0x007F0000  /* Maximum time Slots */
2890 +#define PCIE_VC0_RC_MAX_TIMESLOTS_S          16
2891 +#define PCIE_VC0_RC_PORT_ARB_TAB_OFFSET      0xFF000000  /* Port Arbitration Table Offset */
2892 +#define PCIE_VC0_RC_PORT_ARB_TAB_OFFSET_S    24
2893 +
2894 +/* VC0 Resource Control Register */
2895 +#define PCIE_VC0_RC0(X)                      (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x154)
2896 +#define PCIE_VC0_RC0_TVM0                    0x00000001  /* TC0 and VC0 */
2897 +#define PCIE_VC0_RC0_TVM1                    0x00000002  /* TC1 and VC1 */
2898 +#define PCIE_VC0_RC0_TVM2                    0x00000004  /* TC2 and VC2 */
2899 +#define PCIE_VC0_RC0_TVM3                    0x00000008  /* TC3 and VC3 */
2900 +#define PCIE_VC0_RC0_TVM4                    0x00000010  /* TC4 and VC4 */
2901 +#define PCIE_VC0_RC0_TVM5                    0x00000020  /* TC5 and VC5 */
2902 +#define PCIE_VC0_RC0_TVM6                    0x00000040  /* TC6 and VC6 */
2903 +#define PCIE_VC0_RC0_TVM7                    0x00000080  /* TC7 and VC7 */
2904 +#define PCIE_VC0_RC0_TC_VC                   0x000000FF  /* TC/VC mask */
2905 +
2906 +#define PCIE_VC0_RC0_LOAD_PORT_ARB_TAB       0x00010000  /* Load Port Arbitration Table */
2907 +#define PCIE_VC0_RC0_PORT_ARB_SEL            0x000E0000  /* Port Arbitration Select */
2908 +#define PCIE_VC0_RC0_PORT_ARB_SEL_S          17
2909 +#define PCIE_VC0_RC0_VC_ID                   0x07000000  /* VC ID */
2910 +#define PCIE_VC0_RC0_VC_ID_S                 24
2911 +#define PCIE_VC0_RC0_VC_EN                   0x80000000  /* VC Enable */
2912 +
2913 +/* VC0 Resource Status Register */
2914 +#define PCIE_VC0_RSR0(X)                     (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x158)
2915 +#define PCIE_VC0_RSR0_PORT_ARB_TAB_STATUS    0x00010000  /* Port Arbitration Table Status,not used */
2916 +#define PCIE_VC0_RSR0_VC_NEG_PENDING         0x00020000  /* VC Negotiation Pending */
2917 +
2918 +/* Ack Latency Timer and Replay Timer Register */
2919 +#define PCIE_ALTRT(X)                         (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x700)
2920 +#define PCIE_ALTRT_ROUND_TRIP_LATENCY_LIMIT   0x0000FFFF  /* Round Trip Latency Time Limit */
2921 +#define PCIE_ALTRT_ROUND_TRIP_LATENCY_LIMIT_S 0
2922 +#define PCIE_ALTRT_REPLAY_TIME_LIMIT          0xFFFF0000  /* Replay Time Limit */
2923 +#define PCIE_ALTRT_REPLAY_TIME_LIMIT_S        16
2924 +
2925 +/* Other Message Register */
2926 +#define PCIE_OMR(X)                          (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x704)
2927 +
2928 +/* Port Force Link Register */
2929 +#define PCIE_PFLR(X)                         (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x708)
2930 +#define PCIE_PFLR_LINK_NUM                   0x000000FF  /* Link Number */
2931 +#define PCIE_PFLR_LINK_NUM_S                 0
2932 +#define PCIE_PFLR_FORCE_LINK                 0x00008000  /* Force link */
2933 +#define PCIE_PFLR_LINK_STATE                 0x003F0000  /* Link State */
2934 +#define PCIE_PFLR_LINK_STATE_S               16
2935 +#define PCIE_PFLR_LOW_POWER_ENTRY_CNT        0xFF000000  /* Low Power Entrance Count, only for EP */
2936 +#define PCIE_PFLR_LOW_POWER_ENTRY_CNT_S      24
2937 +
2938 +/* Ack Frequency Register */
2939 +#define PCIE_AFR(X)                          (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x70C)
2940 +#define PCIE_AFR_AF                          0x000000FF  /* Ack Frequency */
2941 +#define PCIE_AFR_AF_S                        0
2942 +#define PCIE_AFR_FTS_NUM                     0x0000FF00  /* The number of Fast Training Sequence from L0S to L0 */
2943 +#define PCIE_AFR_FTS_NUM_S                   8
2944 +#define PCIE_AFR_COM_FTS_NUM                 0x00FF0000  /* N_FTS; when common clock is used*/
2945 +#define PCIE_AFR_COM_FTS_NUM_S               16
2946 +#define PCIE_AFR_L0S_ENTRY_LATENCY           0x07000000  /* L0s Entrance Latency */
2947 +#define PCIE_AFR_L0S_ENTRY_LATENCY_S         24
2948 +#define PCIE_AFR_L1_ENTRY_LATENCY            0x38000000  /* L1 Entrance Latency */
2949 +#define PCIE_AFR_L1_ENTRY_LATENCY_S          27
2950 +#define PCIE_AFR_FTS_NUM_DEFAULT             32
2951 +#define PCIE_AFR_L0S_ENTRY_LATENCY_DEFAULT   7
2952 +#define PCIE_AFR_L1_ENTRY_LATENCY_DEFAULT    5
2953 +
2954 +/* Port Link Control Register */
2955 +#define PCIE_PLCR(X)                         (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x710)
2956 +#define PCIE_PLCR_OTHER_MSG_REQ              0x00000001  /* Other Message Request */
2957 +#define PCIE_PLCR_SCRAMBLE_DISABLE           0x00000002  /* Scramble Disable */  
2958 +#define PCIE_PLCR_LOOPBACK_EN                0x00000004  /* Loopback Enable */
2959 +#define PCIE_PLCR_LTSSM_HOT_RST              0x00000008  /* Force LTSSM to the hot reset */
2960 +#define PCIE_PLCR_DLL_LINK_EN                0x00000020  /* Enable Link initialization */
2961 +#define PCIE_PLCR_FAST_LINK_SIM_EN           0x00000080  /* Sets all internal timers to fast mode for simulation purposes */
2962 +#define PCIE_PLCR_LINK_MODE                  0x003F0000  /* Link Mode Enable Mask */
2963 +#define PCIE_PLCR_LINK_MODE_S                16
2964 +#define PCIE_PLCR_CORRUPTED_CRC_EN           0x02000000  /* Enabled Corrupt CRC */
2965 +
2966 +/* Lane Skew Register */
2967 +#define PCIE_LSR(X)                          (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x714)
2968 +#define PCIE_LSR_LANE_SKEW_NUM               0x00FFFFFF  /* Insert Lane Skew for Transmit, not applicable */
2969 +#define PCIE_LSR_LANE_SKEW_NUM_S             0
2970 +#define PCIE_LSR_FC_DISABLE                  0x01000000  /* Disable of Flow Control */
2971 +#define PCIE_LSR_ACKNAK_DISABLE              0x02000000  /* Disable of Ack/Nak */
2972 +#define PCIE_LSR_LANE_DESKEW_DISABLE         0x80000000  /* Disable of Lane-to-Lane Skew */
2973 +
2974 +/* Symbol Number Register */
2975 +#define PCIE_SNR(X)                          (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x718)
2976 +#define PCIE_SNR_TS                          0x0000000F  /* Number of TS Symbol */
2977 +#define PCIE_SNR_TS_S                        0
2978 +#define PCIE_SNR_SKP                         0x00000700  /* Number of SKP Symbol */
2979 +#define PCIE_SNR_SKP_S                       8
2980 +#define PCIE_SNR_REPLAY_TIMER                0x0007C000  /* Timer Modifier for Replay Timer */
2981 +#define PCIE_SNR_REPLAY_TIMER_S              14
2982 +#define PCIE_SNR_ACKNAK_LATENCY_TIMER        0x00F80000  /* Timer Modifier for Ack/Nak Latency Timer */
2983 +#define PCIE_SNR_ACKNAK_LATENCY_TIMER_S      19
2984 +#define PCIE_SNR_FC_TIMER                    0x1F000000  /* Timer Modifier for Flow Control Watchdog Timer */
2985 +#define PCIE_SNR_FC_TIMER_S                  28
2986 +
2987 +/* Symbol Timer Register and Filter Mask Register 1 */
2988 +#define PCIE_STRFMR(X)                      (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x71C)
2989 +#define PCIE_STRFMR_SKP_INTERVAL            0x000007FF  /* SKP lnterval Value */
2990 +#define PCIE_STRFMR_SKP_INTERVAL_S          0
2991 +#define PCIE_STRFMR_FC_WDT_DISABLE          0x00008000  /* Disable of FC Watchdog Timer */
2992 +#define PCIE_STRFMR_TLP_FUNC_MISMATCH_OK    0x00010000  /* Mask Function Mismatch Filtering for Incoming Requests */
2993 +#define PCIE_STRFMR_POISONED_TLP_OK         0x00020000  /* Mask Poisoned TLP Filtering */
2994 +#define PCIE_STRFMR_BAR_MATCH_OK            0x00040000  /* Mask BAR Match Filtering */
2995 +#define PCIE_STRFMR_TYPE1_CFG_REQ_OK        0x00080000  /* Mask Type 1 Configuration Request Filtering */
2996 +#define PCIE_STRFMR_LOCKED_REQ_OK           0x00100000  /* Mask Locked Request Filtering */
2997 +#define PCIE_STRFMR_CPL_TAG_ERR_RULES_OK    0x00200000  /* Mask Tag Error Rules for Received Completions */
2998 +#define PCIE_STRFMR_CPL_REQUESTOR_ID_MISMATCH_OK 0x00400000  /* Mask Requester ID Mismatch Error for Received Completions */
2999 +#define PCIE_STRFMR_CPL_FUNC_MISMATCH_OK         0x00800000  /* Mask Function Mismatch Error for Received Completions */
3000 +#define PCIE_STRFMR_CPL_TC_MISMATCH_OK           0x01000000  /* Mask Traffic Class Mismatch Error for Received Completions */
3001 +#define PCIE_STRFMR_CPL_ATTR_MISMATCH_OK         0x02000000  /* Mask Attribute Mismatch Error for Received Completions */
3002 +#define PCIE_STRFMR_CPL_LENGTH_MISMATCH_OK       0x04000000  /* Mask Length Mismatch Error for Received Completions */
3003 +#define PCIE_STRFMR_TLP_ECRC_ERR_OK              0x08000000  /* Mask ECRC Error Filtering */
3004 +#define PCIE_STRFMR_CPL_TLP_ECRC_OK              0x10000000  /* Mask ECRC Error Filtering for Completions */
3005 +#define PCIE_STRFMR_RX_TLP_MSG_NO_DROP           0x20000000  /* Send Message TLPs */
3006 +#define PCIE_STRFMR_RX_IO_TRANS_ENABLE           0x40000000  /* Mask Filtering of received I/O Requests */
3007 +#define PCIE_STRFMR_RX_CFG_TRANS_ENABLE          0x80000000  /* Mask Filtering of Received Configuration Requests */
3008 +
3009 +#define PCIE_DEF_SKP_INTERVAL    700             /* 1180 ~1538 , 125MHz * 2, 250MHz * 1 */
3010 +
3011 +/* Filter Masker Register 2 */
3012 +#define PCIE_FMR2(X)                             (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x720)
3013 +#define PCIE_FMR2_VENDOR_MSG0_PASSED_TO_TRGT1    0x00000001  /* Mask RADM Filtering and Error Handling Rules */
3014 +#define PCIE_FMR2_VENDOR_MSG1_PASSED_TO_TRGT1    0x00000002  /* Mask RADM Filtering and Error Handling Rules */
3015 +
3016 +/* Debug Register 0 */
3017 +#define PCIE_DBR0(X)                              (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x728)
3018 +
3019 +/* Debug Register 1 */
3020 +#define PCIE_DBR1(X)                              (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x72C)
3021 +
3022 +/* Transmit Posted FC Credit Status Register */
3023 +#define PCIE_TPFCS(X)                             (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x730)
3024 +#define PCIE_TPFCS_TX_P_DATA_FC_CREDITS           0x00000FFF /* Transmit Posted Data FC Credits */
3025 +#define PCIE_TPFCS_TX_P_DATA_FC_CREDITS_S         0
3026 +#define PCIE_TPFCS_TX_P_HDR_FC_CREDITS            0x000FF000 /* Transmit Posted Header FC Credits */
3027 +#define PCIE_TPFCS_TX_P_HDR_FC_CREDITS_S          12
3028 +
3029 +/* Transmit Non-Posted FC Credit Status */
3030 +#define PCIE_TNPFCS(X)                            (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x734)
3031 +#define PCIE_TNPFCS_TX_NP_DATA_FC_CREDITS         0x00000FFF /* Transmit Non-Posted Data FC Credits */
3032 +#define PCIE_TNPFCS_TX_NP_DATA_FC_CREDITS_S       0
3033 +#define PCIE_TNPFCS_TX_NP_HDR_FC_CREDITS          0x000FF000 /* Transmit Non-Posted Header FC Credits */
3034 +#define PCIE_TNPFCS_TX_NP_HDR_FC_CREDITS_S        12
3035 +
3036 +/* Transmit Complete FC Credit Status Register */
3037 +#define PCIE_TCFCS(X)                             (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x738)
3038 +#define PCIE_TCFCS_TX_CPL_DATA_FC_CREDITS         0x00000FFF /* Transmit Completion Data FC Credits */
3039 +#define PCIE_TCFCS_TX_CPL_DATA_FC_CREDITS_S       0
3040 +#define PCIE_TCFCS_TX_CPL_HDR_FC_CREDITS          0x000FF000 /* Transmit Completion Header FC Credits */
3041 +#define PCIE_TCFCS_TX_CPL_HDR_FC_CREDITS_S        12
3042 +
3043 +/* Queue Status Register */
3044 +#define PCIE_QSR(X)                              (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x73C)
3045 +#define PCIE_QSR_WAIT_UPDATE_FC_DLL               0x00000001 /* Received TLP FC Credits Not Returned */
3046 +#define PCIE_QSR_TX_RETRY_BUF_NOT_EMPTY           0x00000002 /* Transmit Retry Buffer Not Empty */
3047 +#define PCIE_QSR_RX_QUEUE_NOT_EMPTY               0x00000004 /* Received Queue Not Empty */
3048 +
3049 +/* VC Transmit Arbitration Register 1 */
3050 +#define PCIE_VCTAR1(X)                          (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x740)
3051 +#define PCIE_VCTAR1_WRR_WEIGHT_VC0               0x000000FF /* WRR Weight for VC0 */
3052 +#define PCIE_VCTAR1_WRR_WEIGHT_VC1               0x0000FF00 /* WRR Weight for VC1 */
3053 +#define PCIE_VCTAR1_WRR_WEIGHT_VC2               0x00FF0000 /* WRR Weight for VC2 */
3054 +#define PCIE_VCTAR1_WRR_WEIGHT_VC3               0xFF000000 /* WRR Weight for VC3 */
3055 +
3056 +/* VC Transmit Arbitration Register 2 */
3057 +#define PCIE_VCTAR2(X)                          (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x744)
3058 +#define PCIE_VCTAR2_WRR_WEIGHT_VC4               0x000000FF /* WRR Weight for VC4 */
3059 +#define PCIE_VCTAR2_WRR_WEIGHT_VC5               0x0000FF00 /* WRR Weight for VC5 */
3060 +#define PCIE_VCTAR2_WRR_WEIGHT_VC6               0x00FF0000 /* WRR Weight for VC6 */
3061 +#define PCIE_VCTAR2_WRR_WEIGHT_VC7               0xFF000000 /* WRR Weight for VC7 */
3062 +
3063 +/* VC0 Posted Receive Queue Control Register */
3064 +#define PCIE_VC0_PRQCR(X)                       (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x748)
3065 +#define PCIE_VC0_PRQCR_P_DATA_CREDITS            0x00000FFF /* VC0 Posted Data Credits */
3066 +#define PCIE_VC0_PRQCR_P_DATA_CREDITS_S          0
3067 +#define PCIE_VC0_PRQCR_P_HDR_CREDITS             0x000FF000 /* VC0 Posted Header Credits */
3068 +#define PCIE_VC0_PRQCR_P_HDR_CREDITS_S           12
3069 +#define PCIE_VC0_PRQCR_P_TLP_QUEUE_MODE          0x00E00000 /* VC0 Posted TLP Queue Mode */
3070 +#define PCIE_VC0_PRQCR_P_TLP_QUEUE_MODE_S        20
3071 +#define PCIE_VC0_PRQCR_TLP_RELAX_ORDER           0x40000000 /* TLP Type Ordering for VC0 */    
3072 +#define PCIE_VC0_PRQCR_VC_STRICT_ORDER           0x80000000 /* VC0 Ordering for Receive Queues */
3073 +
3074 +/* VC0 Non-Posted Receive Queue Control */
3075 +#define PCIE_VC0_NPRQCR(X)                      (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x74C)
3076 +#define PCIE_VC0_NPRQCR_NP_DATA_CREDITS          0x00000FFF /* VC0 Non-Posted Data Credits */
3077 +#define PCIE_VC0_NPRQCR_NP_DATA_CREDITS_S        0
3078 +#define PCIE_VC0_NPRQCR_NP_HDR_CREDITS           0x000FF000 /* VC0 Non-Posted Header Credits */
3079 +#define PCIE_VC0_NPRQCR_NP_HDR_CREDITS_S         12
3080 +#define PCIE_VC0_NPRQCR_NP_TLP_QUEUE_MODE        0x00E00000 /* VC0 Non-Posted TLP Queue Mode */
3081 +#define PCIE_VC0_NPRQCR_NP_TLP_QUEUE_MODE_S      20
3082 +
3083 +/* VC0 Completion Receive Queue Control */
3084 +#define PCIE_VC0_CRQCR(X)                       (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x750)
3085 +#define PCIE_VC0_CRQCR_CPL_DATA_CREDITS          0x00000FFF /* VC0 Completion TLP Queue Mode */
3086 +#define PCIE_VC0_CRQCR_CPL_DATA_CREDITS_S        0
3087 +#define PCIE_VC0_CRQCR_CPL_HDR_CREDITS           0x000FF000 /* VC0 Completion Header Credits */
3088 +#define PCIE_VC0_CRQCR_CPL_HDR_CREDITS_S         12
3089 +#define PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE        0x00E00000 /* VC0 Completion Data Credits */
3090 +#define PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE_S      21
3091 +
3092 +/* Applicable to the above three registers */
3093 +enum {
3094 +    PCIE_VC0_TLP_QUEUE_MODE_STORE_FORWARD = 1,
3095 +    PCIE_VC0_TLP_QUEUE_MODE_CUT_THROUGH   = 2,
3096 +    PCIE_VC0_TLP_QUEUE_MODE_BYPASS        = 4,
3097 +};
3098 +
3099 +/* VC0 Posted Buffer Depth Register */
3100 +#define PCIE_VC0_PBD(X)                        (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7A8)
3101 +#define PCIE_VC0_PBD_P_DATA_QUEUE_ENTRIES       0x00003FFF /* VC0 Posted Data Queue Depth */
3102 +#define PCIE_VC0_PBD_P_DATA_QUEUE_ENTRIES_S     0
3103 +#define PCIE_VC0_PBD_P_HDR_QUEUE_ENTRIES        0x03FF0000 /* VC0 Posted Header Queue Depth */
3104 +#define PCIE_VC0_PBD_P_HDR_QUEUE_ENTRIES_S      16
3105 +
3106 +/* VC0 Non-Posted Buffer Depth Register */
3107 +#define PCIE_VC0_NPBD(X)                       (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7AC)
3108 +#define PCIE_VC0_NPBD_NP_DATA_QUEUE_ENTRIES     0x00003FFF /* VC0 Non-Posted Data Queue Depth */
3109 +#define PCIE_VC0_NPBD_NP_DATA_QUEUE_ENTRIES_S   0
3110 +#define PCIE_VC0_NPBD_NP_HDR_QUEUE_ENTRIES      0x03FF0000 /* VC0 Non-Posted Header Queue Depth */
3111 +#define PCIE_VC0_NPBD_NP_HDR_QUEUE_ENTRIES_S    16
3112 +
3113 +/* VC0 Completion Buffer Depth Register */
3114 +#define PCIE_VC0_CBD(X)                        (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7B0)
3115 +#define PCIE_VC0_CBD_CPL_DATA_QUEUE_ENTRIES     0x00003FFF /* C0 Completion Data Queue Depth */
3116 +#define PCIE_VC0_CBD_CPL_DATA_QUEUE_ENTRIES_S   0
3117 +#define PCIE_VC0_CBD_CPL_HDR_QUEUE_ENTRIES      0x03FF0000 /* VC0 Completion Header Queue Depth */
3118 +#define PCIE_VC0_CBD_CPL_HDR_QUEUE_ENTRIES_S    16
3119 +
3120 +/* PHY Status Register, all zeros in VR9 */
3121 +#define PCIE_PHYSR(X)                           (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x810)
3122 +
3123 +/* PHY Control Register, all zeros in VR9 */
3124 +#define PCIE_PHYCR(X)                           (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x814)
3125 +
3126 +/* 
3127 + * PCIe PDI PHY register definition, suppose all the following 
3128 + * stuff is confidential. 
3129 + * XXX, detailed bit definition
3130 + */
3131 +#define        PCIE_PHY_PLL_CTRL1(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x22 << 1))
3132 +#define        PCIE_PHY_PLL_CTRL2(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x23 << 1))
3133 +#define        PCIE_PHY_PLL_CTRL3(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x24 << 1))
3134 +#define        PCIE_PHY_PLL_CTRL4(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x25 << 1))
3135 +#define        PCIE_PHY_PLL_CTRL5(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x26 << 1))
3136 +#define        PCIE_PHY_PLL_CTRL6(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x27 << 1))
3137 +#define        PCIE_PHY_PLL_CTRL7(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x28 << 1))
3138 +#define        PCIE_PHY_PLL_A_CTRL1(X)     (PCIE_PHY_PORT_TO_BASE(X) + (0x29 << 1))
3139 +#define        PCIE_PHY_PLL_A_CTRL2(X)     (PCIE_PHY_PORT_TO_BASE(X) + (0x2A << 1))
3140 +#define        PCIE_PHY_PLL_A_CTRL3(X)     (PCIE_PHY_PORT_TO_BASE(X) + (0x2B << 1))
3141 +#define        PCIE_PHY_PLL_STATUS(X)      (PCIE_PHY_PORT_TO_BASE(X) + (0x2C << 1))
3142
3143 +#define PCIE_PHY_TX1_CTRL1(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x30 << 1))
3144 +#define PCIE_PHY_TX1_CTRL2(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x31 << 1))
3145 +#define PCIE_PHY_TX1_CTRL3(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x32 << 1))
3146 +#define PCIE_PHY_TX1_A_CTRL1(X)     (PCIE_PHY_PORT_TO_BASE(X) + (0x33 << 1))
3147 +#define PCIE_PHY_TX1_A_CTRL2(X)     (PCIE_PHY_PORT_TO_BASE(X) + (0x34 << 1))
3148 +#define PCIE_PHY_TX1_MOD1(X)        (PCIE_PHY_PORT_TO_BASE(X) + (0x35 << 1))
3149 +#define PCIE_PHY_TX1_MOD2(X)        (PCIE_PHY_PORT_TO_BASE(X) + (0x36 << 1))
3150 +#define PCIE_PHY_TX1_MOD3(X)        (PCIE_PHY_PORT_TO_BASE(X) + (0x37 << 1))
3151 +
3152 +#define PCIE_PHY_TX2_CTRL1(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x38 << 1))
3153 +#define PCIE_PHY_TX2_CTRL2(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x39 << 1))
3154 +#define PCIE_PHY_TX2_A_CTRL1(X)     (PCIE_PHY_PORT_TO_BASE(X) + (0x3B << 1))
3155 +#define PCIE_PHY_TX2_A_CTRL2(X)     (PCIE_PHY_PORT_TO_BASE(X) + (0x3C << 1))
3156 +#define PCIE_PHY_TX2_MOD1(X)        (PCIE_PHY_PORT_TO_BASE(X) + (0x3D << 1))
3157 +#define PCIE_PHY_TX2_MOD2(X)        (PCIE_PHY_PORT_TO_BASE(X) + (0x3E << 1))
3158 +#define PCIE_PHY_TX2_MOD3(X)        (PCIE_PHY_PORT_TO_BASE(X) + (0x3F << 1))
3159 +
3160 +#define PCIE_PHY_RX1_CTRL1(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x50 << 1))
3161 +#define PCIE_PHY_RX1_CTRL2(X)       (PCIE_PHY_PORT_TO_BASE(X) + (0x51 << 1))
3162 +#define PCIE_PHY_RX1_CDR(X)         (PCIE_PHY_PORT_TO_BASE(X) + (0x52 << 1))
3163 +#define PCIE_PHY_RX1_EI(X)          (PCIE_PHY_PORT_TO_BASE(X) + (0x53 << 1))
3164 +#define PCIE_PHY_RX1_A_CTRL(X)      (PCIE_PHY_PORT_TO_BASE(X) + (0x55 << 1))
3165 +
3166 +/* Interrupt related stuff */
3167 +#define PCIE_LEGACY_DISABLE 0
3168 +#define PCIE_LEGACY_INTA  1
3169 +#define PCIE_LEGACY_INTB  2
3170 +#define PCIE_LEGACY_INTC  3
3171 +#define PCIE_LEGACY_INTD  4
3172 +#define PCIE_LEGACY_INT_MAX PCIE_LEGACY_INTD
3173 +
3174 +#define PCIE_IRQ_LOCK(lock) do {             \
3175 +    unsigned long flags;                     \
3176 +    spin_lock_irqsave(&(lock), flags);
3177 +#define PCIE_IRQ_UNLOCK(lock)                \
3178 +    spin_unlock_irqrestore(&(lock), flags);  \
3179 +} while (0)
3180 +
3181 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
3182 +#define IRQF_SHARED SA_SHIRQ
3183 +#endif
3184 +
3185 +#define PCIE_MSG_MSI        0x00000001
3186 +#define PCIE_MSG_ISR        0x00000002
3187 +#define PCIE_MSG_FIXUP      0x00000004
3188 +#define PCIE_MSG_READ_CFG   0x00000008
3189 +#define PCIE_MSG_WRITE_CFG  0x00000010
3190 +#define PCIE_MSG_CFG        (PCIE_MSG_READ_CFG | PCIE_MSG_WRITE_CFG)
3191 +#define PCIE_MSG_REG        0x00000020
3192 +#define PCIE_MSG_INIT       0x00000040
3193 +#define PCIE_MSG_ERR        0x00000080
3194 +#define PCIE_MSG_PHY        0x00000100
3195 +#define PCIE_MSG_ANY        0x000001ff
3196 +
3197 +#define IFX_PCIE_PORT0      0
3198 +#define IFX_PCIE_PORT1      1
3199 +
3200 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
3201 +#define IFX_PCIE_CORE_NR    2
3202 +#else
3203 +#define IFX_PCIE_CORE_NR    1
3204 +#endif
3205 +
3206 +//#define IFX_PCIE_ERROR_INT
3207 +
3208 +//#define IFX_PCIE_DBG
3209 +
3210 +#if defined(IFX_PCIE_DBG)
3211 +#define IFX_PCIE_PRINT(_m, _fmt, args...) do {   \
3212 +    if (g_pcie_debug_flag & (_m)) {              \
3213 +        ifx_pcie_debug((_fmt), ##args);          \
3214 +    }                                            \
3215 +} while (0)
3216 +
3217 +#define INLINE 
3218 +#else
3219 +#define IFX_PCIE_PRINT(_m, _fmt, args...)   \
3220 +    do {} while(0)
3221 +#define INLINE inline
3222 +#endif
3223 +
3224 +struct ifx_pci_controller {
3225 +       struct pci_controller   pcic;
3226 +    
3227 +       /* RC specific, per host bus information */
3228 +       u32   port;  /* Port index, 0 -- 1st core, 1 -- 2nd core */
3229 +};
3230 +
3231 +typedef struct ifx_pcie_ir_irq {
3232 +    const unsigned int irq;
3233 +    const char name[16];
3234 +}ifx_pcie_ir_irq_t;
3235 +
3236 +typedef struct ifx_pcie_legacy_irq{
3237 +    const u32 irq_bit;
3238 +    const int irq;
3239 +}ifx_pcie_legacy_irq_t;
3240 +
3241 +typedef struct ifx_pcie_irq {
3242 +    ifx_pcie_ir_irq_t ir_irq;
3243 +    ifx_pcie_legacy_irq_t legacy_irq[PCIE_LEGACY_INT_MAX];
3244 +}ifx_pcie_irq_t;
3245 +
3246 +extern u32 g_pcie_debug_flag;
3247 +extern void ifx_pcie_debug(const char *fmt, ...);
3248 +extern void pcie_phy_clock_mode_setup(int pcie_port);
3249 +extern void pcie_msi_pic_init(int pcie_port);
3250 +extern u32 ifx_pcie_bus_enum_read_hack(int where, u32 value);
3251 +extern u32 ifx_pcie_bus_enum_write_hack(int where, u32 value);
3252 +
3253 +
3254 +#include <linux/types.h>
3255 +#include <linux/delay.h>
3256 +#include <linux/gpio.h>
3257 +#include <linux/clk.h>
3258 +
3259 +#include <lantiq_soc.h>
3260 +
3261 +#define IFX_PCIE_GPIO_RESET  38
3262 +#define IFX_REG_R32    ltq_r32
3263 +#define IFX_REG_W32    ltq_w32
3264 +#define CONFIG_IFX_PCIE_HW_SWAP
3265 +#define IFX_RCU_AHB_ENDIAN                      ((volatile u32*)(IFX_RCU + 0x004C))
3266 +#define IFX_RCU_RST_REQ                         ((volatile u32*)(IFX_RCU + 0x0010))
3267 +#define IFX_RCU_AHB_BE_PCIE_PDI                  0x00000080  /* Configure PCIE PDI module in big endian*/
3268 +
3269 +#define IFX_RCU                                 (KSEG1 | 0x1F203000)
3270 +#define IFX_RCU_AHB_BE_PCIE_M                    0x00000001  /* Configure AHB master port that connects to PCIe RC in big endian */
3271 +#define IFX_RCU_AHB_BE_PCIE_S                    0x00000010  /* Configure AHB slave port that connects to PCIe RC in little endian */
3272 +#define IFX_RCU_AHB_BE_XBAR_M                    0x00000002  /* Configure AHB master port that connects to XBAR in big endian */
3273 +#define CONFIG_IFX_PCIE_PHY_36MHZ_MODE
3274 +
3275 +#define IFX_PMU1_MODULE_PCIE_PHY   (0)
3276 +#define IFX_PMU1_MODULE_PCIE_CTRL  (1)
3277 +#define IFX_PMU1_MODULE_PDI        (4)
3278 +#define IFX_PMU1_MODULE_MSI        (5)
3279 +
3280 +#define IFX_PMU_MODULE_PCIE_L0_CLK (31)
3281 +
3282 +
3283 +static inline void pcie_ep_gpio_rst_init(int pcie_port)
3284 +{
3285 +}
3286 +
3287 +static inline void pcie_ahb_pmu_setup(void)
3288 +{
3289 +       struct clk *clk;
3290 +       clk = clk_get_sys("ltq_pcie", "ahb");
3291 +       clk_enable(clk);
3292 +       //ltq_pmu_enable(PMU_AHBM | PMU_AHBS);
3293 +}
3294 +
3295 +static inline void pcie_rcu_endian_setup(int pcie_port)
3296 +{
3297 +    u32 reg;
3298 +
3299 +    reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
3300 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
3301 +    reg |= IFX_RCU_AHB_BE_PCIE_M;
3302 +    reg |= IFX_RCU_AHB_BE_PCIE_S;
3303 +    reg &= ~IFX_RCU_AHB_BE_XBAR_M;
3304 +#else 
3305 +    reg |= IFX_RCU_AHB_BE_PCIE_M;
3306 +    reg &= ~IFX_RCU_AHB_BE_PCIE_S;
3307 +    reg &= ~IFX_RCU_AHB_BE_XBAR_M;
3308 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
3309 +    IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
3310 +    IFX_PCIE_PRINT(PCIE_MSG_REG, "%s IFX_RCU_AHB_ENDIAN: 0x%08x\n", __func__, IFX_REG_R32(IFX_RCU_AHB_ENDIAN));
3311 +}
3312 +
3313 +static inline void pcie_phy_pmu_enable(int pcie_port)
3314 +{
3315 +       struct clk *clk;
3316 +       clk = clk_get_sys("ltq_pcie", "phy");
3317 +       clk_enable(clk);
3318 +       //ltq_pmu1_enable(1<<IFX_PMU1_MODULE_PCIE_PHY);
3319 +}
3320 +
3321 +static inline void pcie_phy_pmu_disable(int pcie_port)
3322 +{
3323 +       struct clk *clk;
3324 +       clk = clk_get_sys("ltq_pcie", "phy");
3325 +       clk_disable(clk);
3326 +       //ltq_pmu1_disable(1<<IFX_PMU1_MODULE_PCIE_PHY);
3327 +}
3328 +
3329 +static inline void pcie_pdi_big_endian(int pcie_port)
3330 +{
3331 +    u32 reg;
3332 +
3333 +    /* SRAM2PDI endianness control. */
3334 +    reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
3335 +    /* Config AHB->PCIe and PDI endianness */
3336 +    reg |= IFX_RCU_AHB_BE_PCIE_PDI;
3337 +    IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
3338 +}
3339 +
3340 +static inline void pcie_pdi_pmu_enable(int pcie_port)
3341 +{
3342 +       struct clk *clk;
3343 +       clk = clk_get_sys("ltq_pcie", "pdi");
3344 +       clk_enable(clk);
3345 +       //ltq_pmu1_enable(1<<IFX_PMU1_MODULE_PDI);
3346 +}
3347 +
3348 +static inline void pcie_core_rst_assert(int pcie_port)
3349 +{
3350 +    u32 reg;
3351 +
3352 +    reg = IFX_REG_R32(IFX_RCU_RST_REQ);
3353 +
3354 +    /* Reset PCIe PHY & Core, bit 22, bit 26 may be affected if write it directly  */
3355 +    reg |= 0x00400000;
3356 +    IFX_REG_W32(reg, IFX_RCU_RST_REQ);
3357 +}
3358 +
3359 +static inline void pcie_core_rst_deassert(int pcie_port)
3360 +{
3361 +    u32 reg;
3362 +
3363 +    /* Make sure one micro-second delay */
3364 +    udelay(1);
3365 +
3366 +    /* Reset PCIe PHY & Core, bit 22 */
3367 +    reg = IFX_REG_R32(IFX_RCU_RST_REQ);
3368 +    reg &= ~0x00400000;
3369 +    IFX_REG_W32(reg, IFX_RCU_RST_REQ);
3370 +}
3371 +
3372 +static inline void pcie_phy_rst_assert(int pcie_port)
3373 +{
3374 +    u32 reg;
3375 +
3376 +    reg = IFX_REG_R32(IFX_RCU_RST_REQ);
3377 +    reg |= 0x00001000; /* Bit 12 */
3378 +    IFX_REG_W32(reg, IFX_RCU_RST_REQ);
3379 +}
3380 +
3381 +static inline void pcie_phy_rst_deassert(int pcie_port)
3382 +{
3383 +    u32 reg;
3384 +
3385 +    /* Make sure one micro-second delay */
3386 +    udelay(1);
3387 +
3388 +    reg = IFX_REG_R32(IFX_RCU_RST_REQ);
3389 +    reg &= ~0x00001000; /* Bit 12 */
3390 +    IFX_REG_W32(reg, IFX_RCU_RST_REQ);
3391 +}
3392 +
3393 +static inline void pcie_device_rst_assert(int pcie_port)
3394 +{
3395 +       gpio_set_value(IFX_PCIE_GPIO_RESET, 0);
3396 +  //  ifx_gpio_output_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
3397 +}
3398 +
3399 +static inline void pcie_device_rst_deassert(int pcie_port)
3400 +{
3401 +    mdelay(100);
3402 +       gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
3403 +//    ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
3404 +}
3405 +
3406 +static inline void pcie_core_pmu_setup(int pcie_port)
3407 +{
3408 +       struct clk *clk;
3409 +       clk = clk_get_sys("ltq_pcie", "ctl");
3410 +       clk_enable(clk);
3411 +       clk = clk_get_sys("ltq_pcie", "bus");
3412 +       clk_enable(clk);
3413 +
3414 +       //ltq_pmu1_enable(1 << IFX_PMU1_MODULE_PCIE_CTRL);
3415 +       //ltq_pmu_enable(1 << IFX_PMU_MODULE_PCIE_L0_CLK);
3416 +}
3417 +
3418 +static inline void pcie_msi_init(int pcie_port)
3419 +{
3420 +       struct clk *clk;
3421 +    pcie_msi_pic_init(pcie_port);
3422 +       clk = clk_get_sys("ltq_pcie", "msi");
3423 +       clk_enable(clk);
3424 +       //ltq_pmu1_enable(1 << IFX_PMU1_MODULE_MSI);
3425 +}
3426 +
3427 +static inline u32
3428 +ifx_pcie_bus_nr_deduct(u32 bus_number, int pcie_port)
3429 +{
3430 +    u32 tbus_number = bus_number;
3431 +
3432 +#ifdef CONFIG_IFX_PCI
3433 +    if (pcibios_host_nr() > 1) {
3434 +        tbus_number -= pcibios_1st_host_bus_nr();
3435 +    }
3436 +#endif /* CONFIG_IFX_PCI */
3437 +    return tbus_number;
3438 +}
3439 +
3440 +static inline u32
3441 +ifx_pcie_bus_enum_hack(struct pci_bus *bus, u32 devfn, int where, u32 value, int pcie_port, int read)
3442 +{
3443 +    struct pci_dev *pdev;
3444 +    u32 tvalue = value;
3445 +
3446 +    /* Sanity check */
3447 +    pdev = pci_get_slot(bus, devfn);
3448 +    if (pdev == NULL) {
3449 +        return tvalue;
3450 +    }
3451 +
3452 +    /* Only care about PCI bridge */
3453 +    if (pdev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
3454 +        return tvalue;
3455 +    }
3456 +
3457 +    if (read) { /* Read hack */
3458 +    #ifdef CONFIG_IFX_PCI
3459 +        if (pcibios_host_nr() > 1) {
3460 +            tvalue = ifx_pcie_bus_enum_read_hack(where, tvalue);
3461 +        }
3462 +    #endif /* CONFIG_IFX_PCI */  
3463 +    }
3464 +    else { /* Write hack */
3465 +    #ifdef CONFIG_IFX_PCI    
3466 +        if (pcibios_host_nr() > 1) {
3467 +            tvalue = ifx_pcie_bus_enum_write_hack(where, tvalue);
3468 +        }
3469 +    #endif
3470 +    }
3471 +    return tvalue;
3472 +}
3473 +
3474 +#endif /* IFXMIPS_PCIE_VR9_H */
3475 +