pci.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (C) Freescale Semiconductor,Inc.
  3. * 2005, 2006. All rights reserved.
  4. *
  5. * Ed Swarthout (ed.swarthout@freescale.com)
  6. * Jason Jin (Jason.jin@freescale.com)
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  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.
  15. *
  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.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. /*
  27. * PCIE Configuration space access support for PCIE Bridge
  28. */
  29. #include <common.h>
  30. #include <pci.h>
  31. #if defined(CONFIG_PCI)
  32. void
  33. pci_mpc86xx_init(struct pci_controller *hose)
  34. {
  35. volatile immap_t *immap = (immap_t *)CFG_CCSRBAR;
  36. volatile ccsr_pex_t *pcie1 = &immap->im_pex1;
  37. u16 temp16;
  38. u32 temp32;
  39. volatile ccsr_gur_t *gur = &immap->im_gur;
  40. uint host1_agent = (gur->porbmsr & MPC86xx_PORBMSR_HA) >> 17;
  41. uint pcie1_host = (host1_agent == 2) || (host1_agent == 3);
  42. uint pcie1_agent = (host1_agent == 0) || (host1_agent == 1);
  43. uint devdisr = gur->devdisr;
  44. uint io_sel = (gur->pordevsr & MPC86xx_PORDEVSR_IO_SEL) >> 16;
  45. if ((io_sel ==2 || io_sel == 3 || io_sel == 5 || io_sel == 6 ||
  46. io_sel == 7 || io_sel == 0xf) && !(devdisr & MPC86xx_DEVDISR_PCIEX1)){
  47. printf ("PCI-EXPRESS 1: Configured as %s \n",
  48. pcie1_agent ? "Agent" : "Host");
  49. if(pcie1_agent) return; /*Don't scan bus when configured as agent*/
  50. printf (" Scanning PCIE bus");
  51. debug("0x%08x=0x%08x ", &pcie1->pme_msg_det,pcie1->pme_msg_det);
  52. if (pcie1->pme_msg_det) {
  53. pcie1->pme_msg_det = 0xffffffff;
  54. debug (" with errors. Clearing. Now 0x%08x",
  55. pcie1->pme_msg_det);
  56. }
  57. debug ("\n");
  58. }
  59. else{
  60. printf("PCI-EXPRESS 1 disabled!\n");
  61. return;
  62. }
  63. /*set first_bus=0 only skipped B0:D0:F0 which is
  64. * a reserved device in M1575, but make it easy for
  65. * most of the scan process.
  66. */
  67. hose->first_busno = 0x00;
  68. hose->last_busno = 0xfe;
  69. pcie_setup_indirect(hose,
  70. (CFG_IMMR+0x8000),
  71. (CFG_IMMR+0x8004));
  72. pci_hose_read_config_word(hose, PCI_BDF(0,0,0), PCI_COMMAND, &temp16);
  73. temp16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER |
  74. PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
  75. pci_hose_write_config_word(hose, PCI_BDF(0,0,0), PCI_COMMAND, temp16);
  76. pci_hose_write_config_word(hose,PCI_BDF(0,0,0), PCI_STATUS, 0xffff);
  77. pci_hose_write_config_byte(hose, PCI_BDF(0,0,0), PCI_LATENCY_TIMER, 0x80);
  78. pci_hose_read_config_dword(hose, PCI_BDF(0,0,0), PCI_PRIMARY_BUS, &temp32);
  79. temp32 = (temp32 & 0xff000000) | (0xff) | (0x0 << 8) | (0xfe << 16);
  80. pci_hose_write_config_dword(hose, PCI_BDF(0,0,0), PCI_PRIMARY_BUS, temp32);
  81. pcie1->powar1 = 0;
  82. pcie1->powar2 = 0;
  83. pcie1->piwar1 = 0;
  84. pcie1->piwar1 = 0;
  85. pcie1->powbar1 = (CFG_PCI1_MEM_BASE >> 12) & 0x000fffff;
  86. pcie1->powar1 = 0x8004401c; /* 512M MEM space */
  87. pcie1->potar1 = (CFG_PCI1_MEM_BASE >> 12) & 0x000fffff;
  88. pcie1->potear1 = 0x00000000;
  89. pcie1->powbar2 = (CFG_PCI1_IO_BASE >> 12) & 0x000fffff;
  90. pcie1->powar2 = 0x80088017; /* 16M IO space */
  91. pcie1->potar2 = 0x00000000;
  92. pcie1->potear2 = 0x00000000;
  93. pcie1->pitar1 = 0x00000000;
  94. pcie1->piwbar1 = 0x00000000;
  95. /* Enable, Prefetch, Local Mem, * Snoop R/W, 2G */
  96. pcie1->piwar1 = 0xa0f5501e;
  97. pci_set_region(hose->regions + 0,
  98. CFG_PCI_MEMORY_BUS,
  99. CFG_PCI_MEMORY_PHYS,
  100. CFG_PCI_MEMORY_SIZE,
  101. PCI_REGION_MEM | PCI_REGION_MEMORY);
  102. pci_set_region(hose->regions + 1,
  103. CFG_PCI1_MEM_BASE,
  104. CFG_PCI1_MEM_PHYS,
  105. CFG_PCI1_MEM_SIZE,
  106. PCI_REGION_MEM);
  107. pci_set_region(hose->regions + 2,
  108. CFG_PCI1_IO_BASE,
  109. CFG_PCI1_IO_PHYS,
  110. CFG_PCI1_IO_SIZE,
  111. PCI_REGION_IO);
  112. hose->region_count = 3;
  113. pci_register_hose(hose);
  114. hose->last_busno = pci_hose_scan(hose);
  115. debug("pcie_mpc86xx_init: last_busno %x\n",hose->last_busno);
  116. debug("pcie_mpc86xx init: current_busno %x\n ",hose->current_busno);
  117. printf("....PCIE1 scan & enumeration done\n");
  118. }
  119. #endif /* CONFIG_PCI */