2 * (C) Copyright 2006 - 2007
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * Copyright (c) 2005 Cisco Systems. All rights reserved.
6 * Roland Dreier <rolandd@cisco.com>
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
23 /* define DEBUG for debugging output (obviously ;-)) */
28 #include <asm/processor.h>
29 #include <asm-ppc/io.h>
34 #if (defined(CONFIG_440SPE) || defined(CONFIG_405EX)) && \
37 #include <asm/4xx_pcie.h>
41 PTYPE_LEGACY_ENDPOINT = 0x1,
42 PTYPE_ROOT_PORT = 0x4,
49 static int validate_endpoint(struct pci_controller *hose)
51 if (hose->cfg_data == (u8 *)CFG_PCIE0_CFGBASE)
52 return (is_end_point(0));
53 else if (hose->cfg_data == (u8 *)CFG_PCIE1_CFGBASE)
54 return (is_end_point(1));
55 #if CFG_PCIE_NR_PORTS > 2
56 else if (hose->cfg_data == (u8 *)CFG_PCIE2_CFGBASE)
57 return (is_end_point(2));
63 static u8* pcie_get_base(struct pci_controller *hose, unsigned int devfn)
65 u8 *base = (u8*)hose->cfg_data;
67 /* use local configuration space for the first bus */
68 if (PCI_BUS(devfn) == 0) {
69 if (hose->cfg_data == (u8*)CFG_PCIE0_CFGBASE)
70 base = (u8*)CFG_PCIE0_XCFGBASE;
71 if (hose->cfg_data == (u8*)CFG_PCIE1_CFGBASE)
72 base = (u8*)CFG_PCIE1_XCFGBASE;
73 #if CFG_PCIE_NR_PORTS > 2
74 if (hose->cfg_data == (u8*)CFG_PCIE2_CFGBASE)
75 base = (u8*)CFG_PCIE2_XCFGBASE;
82 static void pcie_dmer_disable(void)
84 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE),
85 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) | GPL_DMER_MASK_DISA);
86 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE),
87 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) | GPL_DMER_MASK_DISA);
88 #if CFG_PCIE_NR_PORTS > 2
89 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE),
90 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) | GPL_DMER_MASK_DISA);
94 static void pcie_dmer_enable(void)
96 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE0_BASE),
97 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) & ~GPL_DMER_MASK_DISA);
98 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE1_BASE),
99 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) & ~GPL_DMER_MASK_DISA);
100 #if CFG_PCIE_NR_PORTS > 2
101 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE2_BASE),
102 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) & ~GPL_DMER_MASK_DISA);
106 static int pcie_read_config(struct pci_controller *hose, unsigned int devfn,
107 int offset, int len, u32 *val) {
112 if (validate_endpoint(hose))
113 return 0; /* No upstream config access */
116 * Bus numbers are relative to hose->first_busno
118 devfn -= PCI_BDF(hose->first_busno, 0, 0);
121 * NOTICE: configuration space ranges are currenlty mapped only for
122 * the first 16 buses, so such limit must be imposed. In case more
123 * buses are required the TLB settings in board/amcc/<board>/init.S
124 * need to be altered accordingly (one bus takes 1 MB of memory space).
126 if (PCI_BUS(devfn) >= 16)
130 * Only single device/single function is supported for the primary and
131 * secondary buses of the 440SPe host bridge.
133 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
134 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
137 address = pcie_get_base(hose, devfn);
138 offset += devfn << 4;
141 * Reading from configuration space of non-existing device can
142 * generate transaction errors. For the read duration we suppress
143 * assertion of machine check exceptions to avoid those.
145 pcie_dmer_disable ();
147 debug("%s: cfg_data=%08x offset=%08x\n", __func__, hose->cfg_data, offset);
150 *val = in_8(hose->cfg_data + offset);
153 *val = in_le16((u16 *)(hose->cfg_data + offset));
156 *val = in_le32((u32*)(hose->cfg_data + offset));
165 static int pcie_write_config(struct pci_controller *hose, unsigned int devfn,
166 int offset, int len, u32 val) {
170 if (validate_endpoint(hose))
171 return 0; /* No upstream config access */
174 * Bus numbers are relative to hose->first_busno
176 devfn -= PCI_BDF(hose->first_busno, 0, 0);
179 * Same constraints as in pcie_read_config().
181 if (PCI_BUS(devfn) >= 16)
184 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
185 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
188 address = pcie_get_base(hose, devfn);
189 offset += devfn << 4;
192 * Suppress MCK exceptions, similar to pcie_read_config()
194 pcie_dmer_disable ();
198 out_8(hose->cfg_data + offset, val);
201 out_le16((u16 *)(hose->cfg_data + offset), val);
204 out_le32((u32 *)(hose->cfg_data + offset), val);
213 int pcie_read_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 *val)
218 rv = pcie_read_config(hose, dev, offset, 1, &v);
223 int pcie_read_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 *val)
228 rv = pcie_read_config(hose, dev, offset, 2, &v);
233 int pcie_read_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 *val)
238 rv = pcie_read_config(hose, dev, offset, 3, &v);
243 int pcie_write_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 val)
245 return pcie_write_config(hose,(u32)dev,offset,1,val);
248 int pcie_write_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 val)
250 return pcie_write_config(hose,(u32)dev,offset,2,(u32 )val);
253 int pcie_write_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 val)
255 return pcie_write_config(hose,(u32)dev,offset,3,(u32 )val);
258 #if defined(CONFIG_440SPE)
259 static void ppc4xx_setup_utl(u32 port) {
261 volatile void *utl_base = NULL;
268 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x0000000c);
269 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), 0x20000000);
270 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001);
271 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0x68782800);
275 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x0000000c);
276 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), 0x20001000);
277 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001);
278 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0x68782800);
282 mtdcr(DCRN_PEGPL_REGBAH(PCIE2), 0x0000000c);
283 mtdcr(DCRN_PEGPL_REGBAL(PCIE2), 0x20002000);
284 mtdcr(DCRN_PEGPL_REGMSK(PCIE2), 0x00007001);
285 mtdcr(DCRN_PEGPL_SPECIAL(PCIE2), 0x68782800);
288 utl_base = (unsigned int *)(CFG_PCIE_BASE + 0x1000 * port);
291 * Set buffer allocations and then assert VRB and TXE.
293 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
294 out_be32(utl_base + PEUTL_INTR, 0x02000000);
295 out_be32(utl_base + PEUTL_OPDBSZ, 0x10000000);
296 out_be32(utl_base + PEUTL_PBBSZ, 0x53000000);
297 out_be32(utl_base + PEUTL_IPHBSZ, 0x08000000);
298 out_be32(utl_base + PEUTL_IPDBSZ, 0x10000000);
299 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
300 out_be32(utl_base + PEUTL_PCTL, 0x80800066);
303 static int check_error(void)
305 u32 valPE0, valPE1, valPE2;
308 /* SDR0_PEGPLLLCT1 reset */
309 if (!(valPE0 = SDR_READ(PESDR0_PLLLCT1) & 0x01000000)) {
310 printf("PCIE: SDR0_PEGPLLLCT1 reset error 0x%x\n", valPE0);
313 valPE0 = SDR_READ(PESDR0_RCSSET);
314 valPE1 = SDR_READ(PESDR1_RCSSET);
315 valPE2 = SDR_READ(PESDR2_RCSSET);
317 /* SDR0_PExRCSSET rstgu */
318 if (!(valPE0 & 0x01000000) ||
319 !(valPE1 & 0x01000000) ||
320 !(valPE2 & 0x01000000)) {
321 printf("PCIE: SDR0_PExRCSSET rstgu error\n");
325 /* SDR0_PExRCSSET rstdl */
326 if (!(valPE0 & 0x00010000) ||
327 !(valPE1 & 0x00010000) ||
328 !(valPE2 & 0x00010000)) {
329 printf("PCIE: SDR0_PExRCSSET rstdl error\n");
333 /* SDR0_PExRCSSET rstpyn */
334 if ((valPE0 & 0x00001000) ||
335 (valPE1 & 0x00001000) ||
336 (valPE2 & 0x00001000)) {
337 printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
341 /* SDR0_PExRCSSET hldplb */
342 if ((valPE0 & 0x10000000) ||
343 (valPE1 & 0x10000000) ||
344 (valPE2 & 0x10000000)) {
345 printf("PCIE: SDR0_PExRCSSET hldplb error\n");
349 /* SDR0_PExRCSSET rdy */
350 if ((valPE0 & 0x00100000) ||
351 (valPE1 & 0x00100000) ||
352 (valPE2 & 0x00100000)) {
353 printf("PCIE: SDR0_PExRCSSET rdy error\n");
357 /* SDR0_PExRCSSET shutdown */
358 if ((valPE0 & 0x00000100) ||
359 (valPE1 & 0x00000100) ||
360 (valPE2 & 0x00000100)) {
361 printf("PCIE: SDR0_PExRCSSET shutdown error\n");
368 * Initialize PCI Express core
370 int ppc4xx_init_pcie(void)
374 /* Set PLL clock receiver to LVPECL */
375 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) | 1 << 28);
380 if (!(SDR_READ(PESDR0_PLLLCT2) & 0x10000))
382 printf("PCIE: PESDR_PLLCT2 resistance calibration failed (0x%08x)\n",
383 SDR_READ(PESDR0_PLLLCT2));
386 /* De-assert reset of PCIe PLL, wait for lock */
387 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) & ~(1 << 24));
391 if (!(SDR_READ(PESDR0_PLLLCT3) & 0x10000000)) {
398 printf("PCIE: VCO output not locked\n");
404 int ppc4xx_init_pcie(void)
407 * Nothing to do on 405EX
414 * Board-specific pcie initialization
415 * Platform code can reimplement ppc4xx_init_pcie_port_hw() if needed
419 * Initialize various parts of the PCI Express core for our port:
421 * - Set as a root port and enable max width
422 * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
423 * - Set up UTL configuration.
424 * - Increase SERDES drive strength to levels suggested by AMCC.
425 * - De-assert RSTPYN, RSTDL and RSTGU.
427 * NOTICE for 440SPE revB chip: PESDRn_UTLSET2 is not set - we leave it
428 * with default setting 0x11310000. The register has new fields,
429 * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
432 #if defined(CONFIG_440SPE)
433 int __ppc4xx_init_pcie_port_hw(int port, int rootport)
439 val = PTYPE_ROOT_PORT << 20;
440 utlset1 = 0x21222222;
442 val = PTYPE_LEGACY_ENDPOINT << 20;
443 utlset1 = 0x20222222;
447 val |= LNKW_X8 << 12;
449 val |= LNKW_X4 << 12;
451 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
452 SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
453 if (!ppc440spe_revB())
454 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x11000000);
455 SDR_WRITE(SDRN_PESDR_HSSL0SET1(port), 0x35000000);
456 SDR_WRITE(SDRN_PESDR_HSSL1SET1(port), 0x35000000);
457 SDR_WRITE(SDRN_PESDR_HSSL2SET1(port), 0x35000000);
458 SDR_WRITE(SDRN_PESDR_HSSL3SET1(port), 0x35000000);
460 SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
461 SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
462 SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
463 SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
465 SDR_WRITE(SDRN_PESDR_RCSSET(port), (SDR_READ(SDRN_PESDR_RCSSET(port)) &
466 ~(1 << 24 | 1 << 16)) | 1 << 12);
470 #endif /* CONFIG_440SPE */
472 #if defined(CONFIG_405EX)
473 int __ppc4xx_init_pcie_port_hw(int port, int rootport)
482 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
483 SDR_WRITE(SDRN_PESDR_UTLSET1(port), 0x00000000);
484 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01010000);
485 SDR_WRITE(SDRN_PESDR_PHYSET1(port), 0x720F0000);
486 SDR_WRITE(SDRN_PESDR_PHYSET2(port), 0x70600003);
488 /* Assert the PE0_PHY reset */
489 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01010000);
492 /* deassert the PE0_hotreset */
493 if (is_end_point(port))
494 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01111000);
496 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01101000);
498 /* poll for phy !reset */
499 while (!(SDR_READ(SDRN_PESDR_PHYSTA(port)) & 0x00001000))
502 /* deassert the PE0_gpl_utl_reset */
503 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x00101000);
506 mtdcr(DCRN_PEGPL_CFG(PCIE0), 0x10000000); /* guarded on */
508 mtdcr(DCRN_PEGPL_CFG(PCIE1), 0x10000000); /* guarded on */
512 #endif /* CONFIG_405EX */
514 int ppc4xx_init_pcie_port_hw(int port, int rootport)
515 __attribute__((weak, alias("__ppc4xx_init_pcie_port_hw")));
518 * We map PCI Express configuration access into the 512MB regions
520 * NOTICE: revB is very strict about PLB real addressess and ranges to
521 * be mapped for config space; it seems to only work with d_nnnn_nnnn
522 * range (hangs the core upon config transaction attempts when set
523 * otherwise) while revA uses c_nnnn_nnnn.
526 * PCIE0: 0xc_4000_0000
527 * PCIE1: 0xc_8000_0000
528 * PCIE2: 0xc_c000_0000
531 * PCIE0: 0xd_0000_0000
532 * PCIE1: 0xd_2000_0000
533 * PCIE2: 0xd_4000_0000
539 static inline u64 ppc4xx_get_cfgaddr(int port)
541 #if defined(CONFIG_405EX)
543 return (u64)CFG_PCIE0_CFGBASE;
545 return (u64)CFG_PCIE1_CFGBASE;
547 #if defined(CONFIG_440SPE)
548 if (ppc440spe_revB()) {
550 default: /* to satisfy compiler */
552 return 0x0000000d00000000ULL;
554 return 0x0000000d20000000ULL;
556 return 0x0000000d40000000ULL;
560 default: /* to satisfy compiler */
562 return 0x0000000c40000000ULL;
564 return 0x0000000c80000000ULL;
566 return 0x0000000cc0000000ULL;
573 * 4xx boards as end point and root point setup
575 * testing inbound and out bound windows
577 * 4xx boards can be plugged into another 4xx boards or you can get PCI-E
578 * cable which can be used to setup loop back from one port to another port.
579 * Please rememeber that unless there is a endpoint plugged in to root port it
580 * will not initialize. It is the same in case of endpoint , unless there is
581 * root port attached it will not initialize.
583 * In this release of software all the PCI-E ports are configured as either
584 * endpoint or rootpoint.In future we will have support for selective ports
585 * setup as endpoint and root point in single board.
587 * Once your board came up as root point , you can verify by reading
588 * /proc/bus/pci/devices. Where you can see the configuration registers
589 * of end point device attached to the port.
591 * Enpoint cofiguration can be verified by connecting 4xx board to any
592 * host or another 4xx board. Then try to scan the device. In case of
593 * linux use "lspci" or appripriate os command.
595 * How do I verify the inbound and out bound windows ? (4xx to 4xx)
596 * in this configuration inbound and outbound windows are setup to access
597 * sram memroy area. SRAM is at 0x4 0000 0000 , on PLB bus. This address
598 * is mapped at 0x90000000. From u-boot prompt write data 0xb000 0000,
599 * This is waere your POM(PLB out bound memory window) mapped. then
600 * read the data from other 4xx board's u-boot prompt at address
601 * 0x9000 0000(SRAM). Data should match.
602 * In case of inbound , write data to u-boot command prompt at 0xb000 0000
603 * which is mapped to 0x4 0000 0000. Now on rootpoint yucca u-boot prompt check
604 * data at 0x9000 0000(SRAM).Data should match.
606 int ppc4xx_init_pcie_port(int port, int rootport)
608 static int core_init;
609 volatile u32 val = 0;
615 if (ppc4xx_init_pcie())
621 * Initialize various parts of the PCI Express core for our port
623 ppc4xx_init_pcie_port_hw(port, rootport);
626 * Notice: the following delay has critical impact on device
627 * initialization - if too short (<50ms) the link doesn't get up.
631 val = SDR_READ(SDRN_PESDR_RCSSTS(port));
632 if (val & (1 << 20)) {
633 printf("PCIE%d: PGRST failed %08x\n", port, val);
640 val = SDR_READ(SDRN_PESDR_LOOP(port));
641 if (!(val & 0x00001000)) {
642 printf("PCIE%d: link is not up.\n", port);
646 #if defined(CONFIG_440SPE)
648 * Setup UTL registers - but only on revA!
649 * We use default settings for revB chip.
651 if (!ppc440spe_revB())
652 ppc4xx_setup_utl(port);
656 * We map PCI Express configuration access into the 512MB regions
658 addr = ppc4xx_get_cfgaddr(port);
659 low = U64_TO_U32_LOW(addr);
660 high = U64_TO_U32_HIGH(addr);
664 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high);
665 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low);
666 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
669 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high);
670 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low);
671 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
673 #if CFG_PCIE_NR_PORTS > 2
675 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high);
676 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low);
677 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
683 * Check for VC0 active and assert RDY.
686 while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 16))) {
688 printf("PCIE%d: VC0 not active\n", port);
693 SDR_WRITE(SDRN_PESDR_RCSSET(port),
694 SDR_READ(SDRN_PESDR_RCSSET(port)) | 1 << 20);
700 int ppc4xx_init_pcie_rootport(int port)
702 return ppc4xx_init_pcie_port(port, 1);
705 int ppc4xx_init_pcie_endport(int port)
707 return ppc4xx_init_pcie_port(port, 0);
710 void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port)
712 volatile void *mbase = NULL;
713 volatile void *rmbase = NULL;
716 pcie_read_config_byte,
717 pcie_read_config_word,
718 pcie_read_config_dword,
719 pcie_write_config_byte,
720 pcie_write_config_word,
721 pcie_write_config_dword);
725 mbase = (u32 *)CFG_PCIE0_XCFGBASE;
726 rmbase = (u32 *)CFG_PCIE0_CFGBASE;
727 hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
730 mbase = (u32 *)CFG_PCIE1_XCFGBASE;
731 rmbase = (u32 *)CFG_PCIE1_CFGBASE;
732 hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
734 #if CFG_PCIE_NR_PORTS > 2
736 mbase = (u32 *)CFG_PCIE2_XCFGBASE;
737 rmbase = (u32 *)CFG_PCIE2_CFGBASE;
738 hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
744 * Set bus numbers on our root port
746 out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0);
747 out_8((u8 *)mbase + PCI_SECONDARY_BUS, 1);
748 out_8((u8 *)mbase + PCI_SUBORDINATE_BUS, 1);
751 * Set up outbound translation to hose->mem_space from PLB
752 * addresses at an offset of 0xd_0000_0000. We set the low
753 * bits of the mask to 11 to turn off splitting into 8
754 * subregions and to enable the outbound translation.
756 out_le32(mbase + PECFG_POM0LAH, 0x00000000);
757 out_le32(mbase + PECFG_POM0LAL, CFG_PCIE_MEMBASE +
758 port * CFG_PCIE_MEMSIZE);
759 debug("PECFG_POM0LA=%08x.%08x\n", in_le32(mbase + PECFG_POM0LAH),
760 in_le32(mbase + PECFG_POM0LAL));
764 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CFG_PCIE_ADDR_HIGH);
765 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
766 port * CFG_PCIE_MEMSIZE);
767 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
768 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
769 ~(CFG_PCIE_MEMSIZE - 1) | 3);
770 debug("0:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
771 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE0)),
772 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE0)),
773 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE0)),
774 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE0)));
777 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CFG_PCIE_ADDR_HIGH);
778 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CFG_PCIE_MEMBASE +
779 port * CFG_PCIE_MEMSIZE);
780 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
781 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
782 ~(CFG_PCIE_MEMSIZE - 1) | 3);
783 debug("1:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
784 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE1)),
785 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE1)),
786 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE1)),
787 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE1)));
789 #if CFG_PCIE_NR_PORTS > 2
791 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CFG_PCIE_ADDR_HIGH);
792 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CFG_PCIE_MEMBASE +
793 port * CFG_PCIE_MEMSIZE);
794 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
795 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
796 ~(CFG_PCIE_MEMSIZE - 1) | 3);
797 debug("2:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
798 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE2)),
799 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE2)),
800 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE2)),
801 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE2)));
806 /* Set up 16GB inbound memory window at 0 */
807 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
808 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
809 out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffc);
810 out_le32(mbase + PECFG_BAR0LMPA, 0);
812 out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
813 out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
814 out_le32(mbase + PECFG_PIM0LAL, 0);
815 out_le32(mbase + PECFG_PIM0LAH, 0);
816 out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
817 out_le32(mbase + PECFG_PIM1LAH, 0x00000004);
818 out_le32(mbase + PECFG_PIMEN, 0x1);
820 /* Enable I/O, Mem, and Busmaster cycles */
821 out_le16((u16 *)(mbase + PCI_COMMAND),
822 in_le16((u16 *)(mbase + PCI_COMMAND)) |
823 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
825 /* Set Device and Vendor Id */
826 out_le16(mbase + 0x200, 0xaaa0 + port);
827 out_le16(mbase + 0x202, 0xbed0 + port);
829 /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
830 out_le32(mbase + 0x208, 0x06040001);
832 printf("PCIE%d: successfully set as root-complex\n", port);
835 int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port)
837 volatile void *mbase = NULL;
841 pcie_read_config_byte,
842 pcie_read_config_word,
843 pcie_read_config_dword,
844 pcie_write_config_byte,
845 pcie_write_config_word,
846 pcie_write_config_dword);
850 mbase = (u32 *)CFG_PCIE0_XCFGBASE;
851 hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
854 mbase = (u32 *)CFG_PCIE1_XCFGBASE;
855 hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
857 #if defined(CFG_PCIE2_CFGBASE)
859 mbase = (u32 *)CFG_PCIE2_XCFGBASE;
860 hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
866 * Set up outbound translation to hose->mem_space from PLB
867 * addresses at an offset of 0xd_0000_0000. We set the low
868 * bits of the mask to 11 to turn off splitting into 8
869 * subregions and to enable the outbound translation.
871 out_le32(mbase + PECFG_POM0LAH, 0x00001ff8);
872 out_le32(mbase + PECFG_POM0LAL, 0x00001000);
876 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CFG_PCIE_ADDR_HIGH);
877 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
878 port * CFG_PCIE_MEMSIZE);
879 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
880 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
881 ~(CFG_PCIE_MEMSIZE - 1) | 3);
884 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CFG_PCIE_ADDR_HIGH);
885 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CFG_PCIE_MEMBASE +
886 port * CFG_PCIE_MEMSIZE);
887 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
888 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
889 ~(CFG_PCIE_MEMSIZE - 1) | 3);
891 #if CFG_PCIE_NR_PORTS > 2
893 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CFG_PCIE_ADDR_HIGH);
894 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CFG_PCIE_MEMBASE +
895 port * CFG_PCIE_MEMSIZE);
896 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
897 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
898 ~(CFG_PCIE_MEMSIZE - 1) | 3);
903 /* Set up 64MB inbound memory window at 0 */
904 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
905 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
907 out_le32(mbase + PECFG_PIM01SAH, 0xffffffff);
908 out_le32(mbase + PECFG_PIM01SAL, 0xfc000000);
911 out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffff);
912 out_le32(mbase + PECFG_BAR0LMPA, 0xfc000000 | PCI_BASE_ADDRESS_MEM_TYPE_64);
914 /* Disable BAR1 & BAR2 */
915 out_le32(mbase + PECFG_BAR1MPA, 0);
916 out_le32(mbase + PECFG_BAR2HMPA, 0);
917 out_le32(mbase + PECFG_BAR2LMPA, 0);
919 out_le32(mbase + PECFG_PIM0LAL, U64_TO_U32_LOW(CFG_PCIE_INBOUND_BASE));
920 out_le32(mbase + PECFG_PIM0LAH, U64_TO_U32_HIGH(CFG_PCIE_INBOUND_BASE));
921 out_le32(mbase + PECFG_PIMEN, 0x1);
923 /* Enable I/O, Mem, and Busmaster cycles */
924 out_le16((u16 *)(mbase + PCI_COMMAND),
925 in_le16((u16 *)(mbase + PCI_COMMAND)) |
926 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
927 out_le16(mbase + 0x200, 0xcaad); /* Setting vendor ID */
928 out_le16(mbase + 0x202, 0xfeed); /* Setting device ID */
930 /* Set Class Code to Processor/PPC */
931 out_le32(mbase + 0x208, 0x0b200001);
934 while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 8))) {
936 printf("PCIE%d: BME not active\n", port);
942 printf("PCIE%d: successfully set as endpoint\n", port);
946 #endif /* CONFIG_440SPE && CONFIG_PCI */