pci.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  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. #include <common.h>
  24. #ifdef CONFIG_PCI
  25. #include <pci.h>
  26. #include <asm/m8260_pci.h>
  27. /*
  28. * Local->PCI map (from CPU) controlled by
  29. * MPC826x master window
  30. *
  31. * 0x80000000 - 0xBFFFFFFF Total CPU2PCI space PCIBR0
  32. *
  33. * 0x80000000 - 0x8FFFFFFF PCI Mem with prefetch (Outbound ATU #1)
  34. * 0x90000000 - 0x9FFFFFFF PCI Mem w/o prefetch (Outbound ATU #2)
  35. * 0xA0000000 - 0xAFFFFFFF 32-bit PCI IO (Outbound ATU #3)
  36. *
  37. * PCI->Local map (from PCI)
  38. * MPC826x slave window controlled by
  39. *
  40. * 0x00000000 - 0x07FFFFFF MPC826x local memory (Inbound ATU #1)
  41. */
  42. /*
  43. * Slave window that allows PCI masters to access MPC826x local memory.
  44. * This window is set up using the first set of Inbound ATU registers
  45. */
  46. #define PCI_SLV_MEM_LOCAL CFG_SDRAM_BASE /* Local base */
  47. #define PCI_SLV_MEM_BUS 0x00000000 /* PCI base */
  48. #define PICMR0_MASK_ATTRIB (PICMR_MASK_512MB | PICMR_ENABLE | \
  49. PICMR_PREFETCH_EN)
  50. /*
  51. * This is the window that allows the CPU to access PCI address space.
  52. * It will be setup with the SIU PCIBR0 register. All three PCI master
  53. * windows, which allow the CPU to access PCI prefetch, non prefetch,
  54. * and IO space (see below), must all fit within this window.
  55. */
  56. #define PCI_MSTR_LOCAL 0x80000000 /* Local base */
  57. #define PCIMSK0_MASK PCIMSK_1GB /* Size of window */
  58. /*
  59. * Master window that allows the CPU to access PCI Memory (prefetch).
  60. * This window will be setup with the first set of Outbound ATU registers
  61. * in the bridge.
  62. */
  63. #define PCI_MSTR_MEM_LOCAL 0x80000000 /* Local base */
  64. #define PCI_MSTR_MEM_BUS 0x80000000 /* PCI base */
  65. #define CPU_PCI_MEM_START PCI_MSTR_MEM_LOCAL
  66. #define PCI_MSTR_MEM_SIZE 0x10000000 /* 256MB */
  67. #define POCMR0_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PREFETCH_EN)
  68. /*
  69. * Master window that allows the CPU to access PCI Memory (non-prefetch).
  70. * This window will be setup with the second set of Outbound ATU registers
  71. * in the bridge.
  72. */
  73. #define PCI_MSTR_MEMIO_LOCAL 0x90000000 /* Local base */
  74. #define PCI_MSTR_MEMIO_BUS 0x90000000 /* PCI base */
  75. #define CPU_PCI_MEMIO_START PCI_MSTR_MEMIO_LOCAL
  76. #define PCI_MSTR_MEMIO_SIZE 0x10000000 /* 256MB */
  77. #define POCMR1_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE)
  78. /*
  79. * Master window that allows the CPU to access PCI IO space.
  80. * This window will be setup with the third set of Outbound ATU registers
  81. * in the bridge.
  82. */
  83. #define PCI_MSTR_IO_LOCAL 0xA0000000 /* Local base */
  84. #define PCI_MSTR_IO_BUS 0xA0000000 /* PCI base */
  85. #define CPU_PCI_IO_START PCI_MSTR_IO_LOCAL
  86. #define PCI_MSTR_IO_SIZE 0x10000000 /* 256MB */
  87. #define POCMR2_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PCI_IO)
  88. /* PCI bus configuration registers.
  89. */
  90. #define PCI_CLASS_BRIDGE_CTLR 0x06
  91. static inline void pci_outl(u32 addr, u32 data)
  92. {
  93. *(volatile u32 *) addr = cpu_to_le32(data);
  94. }
  95. void pci_mpc8250_init(struct pci_controller *hose)
  96. {
  97. u16 tempShort;
  98. u32 immr_addr = CFG_IMMR;
  99. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  100. pci_dev_t host_devno = PCI_BDF(0, 0, 0);
  101. pci_setup_indirect(hose, CFG_IMMR + PCI_CFG_ADDR_REG,
  102. CFG_IMMR + PCI_CFG_DATA_REG);
  103. /*
  104. * Setting required to enable IRQ1-IRQ7 (SIUMCR [DPPC]),
  105. * and local bus for PCI (SIUMCR [LBPC]).
  106. */
  107. immap->im_siu_conf.sc_siumcr = 0x00640000;
  108. /* Make PCI lowest priority */
  109. /* Each 4 bits is a device bus request and the MS 4bits
  110. is highest priority */
  111. /* Bus 4bit value
  112. --- ----------
  113. CPM high 0b0000
  114. CPM middle 0b0001
  115. CPM low 0b0010
  116. PCI reguest 0b0011
  117. Reserved 0b0100
  118. Reserved 0b0101
  119. Internal Core 0b0110
  120. External Master 1 0b0111
  121. External Master 2 0b1000
  122. External Master 3 0b1001
  123. The rest are reserved */
  124. immap->im_siu_conf.sc_ppc_alrh = 0x61207893;
  125. /* Park bus on core while modifying PCI Bus accesses */
  126. immap->im_siu_conf.sc_ppc_acr = 0x6;
  127. /*
  128. * Set up master window that allows the CPU to access PCI space. This
  129. * window is set up using the first SIU PCIBR registers.
  130. */
  131. *(volatile unsigned long*)(immr_addr + M8265_PCIMSK0) = PCIMSK0_MASK;
  132. *(volatile unsigned long*)(immr_addr + M8265_PCIBR0) =
  133. PCI_MSTR_LOCAL | PCIBR_ENABLE;
  134. /* Release PCI RST (by default the PCI RST signal is held low) */
  135. pci_outl (immr_addr | PCI_GCR_REG, PCIGCR_PCI_BUS_EN);
  136. /* give it some time */
  137. udelay(1000);
  138. /*
  139. * Set up master window that allows the CPU to access PCI Memory (prefetch)
  140. * space. This window is set up using the first set of Outbound ATU registers.
  141. */
  142. pci_outl (immr_addr | POTAR_REG0, PCI_MSTR_MEM_BUS >> 12); /* PCI base */
  143. pci_outl (immr_addr | POBAR_REG0, PCI_MSTR_MEM_LOCAL >> 12); /* Local base */
  144. pci_outl (immr_addr | POCMR_REG0, POCMR0_MASK_ATTRIB); /* Size & attribute */
  145. /*
  146. * Set up master window that allows the CPU to access PCI Memory (non-prefetch)
  147. * space. This window is set up using the second set of Outbound ATU registers.
  148. */
  149. pci_outl (immr_addr | POTAR_REG1, PCI_MSTR_MEMIO_BUS >> 12); /* PCI base */
  150. pci_outl (immr_addr | POBAR_REG1, PCI_MSTR_MEMIO_LOCAL >> 12); /* Local base */
  151. pci_outl (immr_addr | POCMR_REG1, POCMR1_MASK_ATTRIB); /* Size & attribute */
  152. /*
  153. * Set up master window that allows the CPU to access PCI IO space. This window
  154. * is set up using the third set of Outbound ATU registers.
  155. */
  156. pci_outl (immr_addr | POTAR_REG2, PCI_MSTR_IO_BUS >> 12); /* PCI base */
  157. pci_outl (immr_addr | POBAR_REG2, PCI_MSTR_IO_LOCAL >> 12); /* Local base */
  158. pci_outl (immr_addr | POCMR_REG2, POCMR2_MASK_ATTRIB); /* Size & attribute */
  159. /*
  160. * Set up slave window that allows PCI masters to access MPC826x local memory.
  161. * This window is set up using the first set of Inbound ATU registers
  162. */
  163. pci_outl (immr_addr | PITAR_REG0, PCI_SLV_MEM_LOCAL >> 12); /* Local base */
  164. pci_outl (immr_addr | PIBAR_REG0, PCI_SLV_MEM_BUS >> 12); /* PCI base */
  165. pci_outl (immr_addr | PICMR_REG0, PICMR0_MASK_ATTRIB); /* Size & attribute */
  166. /* See above for description - puts PCI request as highest priority */
  167. immap->im_siu_conf.sc_ppc_alrh = 0x03124567;
  168. /* Park the bus on the PCI */
  169. immap->im_siu_conf.sc_ppc_acr = PPC_ACR_BUS_PARK_PCI;
  170. /* Host mode - specify the bridge as a host-PCI bridge */
  171. pci_hose_write_config_byte(hose, host_devno, PCI_CLASS_CODE,
  172. PCI_CLASS_BRIDGE_CTLR);
  173. /* Enable the host bridge to be a master on the PCI bus, and to act as a PCI memory target */
  174. pci_hose_read_config_word(hose, host_devno, PCI_COMMAND, &tempShort);
  175. pci_hose_write_config_word(hose, host_devno, PCI_COMMAND,
  176. tempShort | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
  177. hose->first_busno = 0;
  178. hose->last_busno = 0xff;
  179. /* System memory space */
  180. pci_set_region(hose->regions + 0,
  181. CFG_SDRAM_BASE,
  182. CFG_SDRAM_BASE,
  183. 0x4000000,
  184. PCI_REGION_MEM | PCI_REGION_MEMORY);
  185. /* PCI memory space */
  186. pci_set_region(hose->regions + 1,
  187. PCI_MSTR_MEM_BUS,
  188. PCI_MSTR_MEM_LOCAL,
  189. PCI_MSTR_MEM_SIZE,
  190. PCI_REGION_MEM);
  191. /* PCI I/O space */
  192. pci_set_region(hose->regions + 2,
  193. PCI_MSTR_IO_BUS,
  194. PCI_MSTR_IO_LOCAL,
  195. PCI_MSTR_IO_SIZE,
  196. PCI_REGION_IO);
  197. hose->region_count = 3;
  198. pci_register_hose(hose);
  199. hose->last_busno = pci_hose_scan(hose);
  200. }
  201. #endif /* CONFIG_PCI */