pci.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright 2005 Freescale Semiconductor.
  3. * Ed Swarthout (ed.swarthout@freescale.com)
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * PEX Configuration space access support for PEX Bridge
  25. */
  26. #include <common.h>
  27. #include <pci.h>
  28. #if defined(CONFIG_PCI)
  29. void
  30. pci_mpc86xx_init(struct pci_controller *hose)
  31. {
  32. volatile immap_t *immap = (immap_t *)CFG_CCSRBAR;
  33. volatile ccsr_pex_t *pex1 = &immap->im_pex1;
  34. volatile ccsr_gur_t *gur = &immap->im_gur;
  35. uint host1_agent = (gur->porbmsr & MPC86xx_PORBMSR_HA) >> 17;
  36. uint pex1_host = (host1_agent == 2) || (host1_agent == 3);
  37. u16 reg16, reg16_1, reg16_2, reg16_3;
  38. u32 reg32, i;
  39. ulong addr, data;
  40. uint pex1_agent = (host1_agent == 0) || (host1_agent == 1);
  41. uint devdisr = gur->devdisr;
  42. uint io_sel = (gur->pordevsr & MPC86xx_PORDEVSR_IO_SEL) >> 16;
  43. if ((io_sel==2 || io_sel==3 || io_sel==5
  44. || io_sel==6 || io_sel==7 || io_sel==0xF )
  45. && !(devdisr & MPC86xx_DEVDISR_PCIEX1)){
  46. printf ("PCI-EXPRESS 1: Configured as %s \n",
  47. pex1_agent ? "Agent" : "Host");
  48. printf (" Scanning PCI bus");
  49. debug("0x%08x=0x%08x ", &pex1->pme_msg_det,pex1->pme_msg_det);
  50. if (pex1->pme_msg_det) {
  51. pex1->pme_msg_det = 0xffffffff;
  52. debug (" with errors. Clearing. Now 0x%08x",
  53. pex1->pme_msg_det);
  54. }
  55. debug ("\n");
  56. }
  57. hose->first_busno = 0;
  58. hose->last_busno = 0x7f;
  59. pci_set_region(hose->regions + 0,
  60. CFG_PCI1_MEM_BASE,
  61. CFG_PCI1_MEM_PHYS,
  62. CFG_PCI1_MEM_SIZE,
  63. PCI_REGION_MEM);
  64. pci_set_region(hose->regions + 1,
  65. CFG_PCI1_IO_BASE,
  66. CFG_PCI1_IO_PHYS,
  67. CFG_PCI1_IO_SIZE,
  68. PCI_REGION_IO);
  69. hose->region_count = 2;
  70. pci_setup_indirect(hose,
  71. (CFG_IMMR+0x8000),
  72. (CFG_IMMR+0x8004));
  73. /*
  74. * Hose scan.
  75. */
  76. pci_register_hose(hose);
  77. pci_read_config_word (PCI_BDF(0,0,0), PCI_VENDOR_ID, &reg16);
  78. debug("pex_mpc86xx_init: read %2x %4x\n",PCI_VENDOR_ID, reg16);
  79. pci_read_config_word (PCI_BDF(0,0,0), PCI_DEVICE_ID, &reg16);
  80. debug("pex_mpc86xx_init: read %2x %4x\n",PCI_DEVICE_ID, reg16);
  81. pci_read_config_word (PCI_BDF(0,0,0), PCI_COMMAND, &reg16);
  82. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY \
  83. | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  84. pci_write_config_word(PCI_BDF(0,0,0), PCI_COMMAND, reg16);
  85. pci_read_config_word (PCI_BDF(0,0,0), PCI_COMMAND, &reg16);
  86. debug("pex_mpc86xx_init: read %2x %4x\n",PCI_COMMAND, reg16);
  87. /*
  88. * Clear non-reserved bits in status register.
  89. */
  90. /*
  91. * pci_write_config_word(PCI_BDF(0,0,0), PCI_STATUS, 0xffff);
  92. * pci_write_config_byte(PCI_BDF(0,0,0), PCI_LATENCY_TIMER,0x80);
  93. */
  94. pex1->powbar1 = (CFG_PCI1_MEM_BASE >> 12) & 0x000fffff;
  95. pex1->powar1 = 0x8004401c; /* 512M MEM space */
  96. pex1->potar1 = (CFG_PCI1_MEM_BASE >> 12) & 0x000fffff;
  97. pex1->potear1 = 0x00000000;
  98. pex1->powbar2 = (CFG_PCI1_IO_BASE >> 12) & 0x000fffff;
  99. pex1->powar2 = 0x80088017; /* 16M IO space */
  100. pex1->potar2 = 0x00000000;
  101. pex1->potear2 = 0x00000000;
  102. if (!pex1->piwar1) {
  103. pex1->pitar1 = 0x00000000;
  104. pex1->piwbar1 = (0x80000000 >> 12 ) & 0x000fffff;
  105. pex1->piwar1 = 0xa0f5501e; /* Enable, Prefetch, Local Mem,
  106. * Snoop R/W, 2G */
  107. }
  108. pex1->pitar2 = 0x00000000;
  109. pex1->piwbar2 = (0xe2000000 >> 12 ) & 0x000fffff;
  110. pex1->piwar2 = 0xa0f5501e; /* Enable, Prefetch, Local Mem,
  111. * Snoop R/W, 2G */
  112. *(u32 *)(0xf8008000)= 0x80000000;
  113. debug("Received data for addr 0x%08lx is 0x%08lx\n",
  114. *(u32*)(0xf8008000), *(u32*)(0xf8008004));
  115. pci_write_config_byte(PCI_BDF(0,0,0), PCI_PRIMARY_BUS,0x20);
  116. pci_write_config_byte(PCI_BDF(0,0,0), PCI_SECONDARY_BUS,0x00);
  117. pci_write_config_byte(PCI_BDF(0,0,0), PCI_SUBORDINATE_BUS,0x1F);
  118. *(u32 *)(0xf8008000)= 0x80200000;
  119. debug("Received data for addr 0x%08lx is 0x%08lx\n",
  120. *(u32*)(0xf8008000), *(u32*)(0xf8008004));
  121. *(u32 *)(0xf8008000)= 0x80200000;
  122. debug("Received data for addr 0x%08lx is 0x%08lx\n",
  123. *(u32*)(0xf8008000), *(u32*)(0xf8008004));
  124. *(u32 *)(0xf8008000)= 0x80200000;
  125. debug("Received data for addr 0x%08lx is 0x%08lx\n",
  126. *(u32*)(0xf8008000), *(u32*)(0xf8008004));
  127. hose->last_busno = pci_hose_scan(hose);
  128. hose->last_busno = 0x21;
  129. debug("pex_mpc86xx_init: last_busno %x\n",hose->last_busno);
  130. debug("pex_mpc86xx init: current_busno %x\n ",hose->current_busno);
  131. printf("....PCI scan & enumeration done\n");
  132. }
  133. #endif /* CONFIG_PCI */