pci.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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 <mpc8260.h>
  27. #include <asm/m8260_pci.h>
  28. /*
  29. * Local->PCI map (from CPU) controlled by
  30. * MPC826x master window
  31. *
  32. * 0x80000000 - 0xBFFFFFFF CPU2PCI space PCIBR0
  33. * 0xF4000000 - 0xF7FFFFFF CPU2PCI space PCIBR1
  34. *
  35. * 0x80000000 - 0x9FFFFFFF 0x80000000 - 0x9FFFFFFF (Outbound ATU #1)
  36. * PCI Mem with prefetch
  37. *
  38. * 0xA0000000 - 0xBFFFFFFF 0xA0000000 - 0xBFFFFFFF (Outbound ATU #2)
  39. * PCI Mem w/o prefetch
  40. *
  41. * 0xF4000000 - 0xF7FFFFFF 0x00000000 - 0x03FFFFFF (Outbound ATU #3)
  42. * 32-bit PCI IO
  43. *
  44. * PCI->Local map (from PCI)
  45. * MPC826x slave window controlled by
  46. *
  47. * 0x00000000 - 0x1FFFFFFF 0x00000000 - 0x1FFFFFFF (Inbound ATU #1)
  48. * MPC826x local memory
  49. */
  50. /*
  51. * Slave window that allows PCI masters to access MPC826x local memory.
  52. * This window is set up using the first set of Inbound ATU registers
  53. */
  54. #ifndef CFG_PCI_SLV_MEM_LOCAL
  55. #define PCI_SLV_MEM_LOCAL CFG_SDRAM_BASE /* Local base */
  56. #else
  57. #define PCI_SLV_MEM_LOCAL CFG_PCI_SLV_MEM_LOCAL
  58. #endif
  59. #ifndef CFG_PCI_SLV_MEM_BUS
  60. #define PCI_SLV_MEM_BUS 0x00000000 /* PCI base */
  61. #else
  62. #define PCI_SLV_MEM_BUS CFG_PCI_SLV_MEM_BUS
  63. #endif
  64. #ifndef CFG_PICMR0_MASK_ATTRIB
  65. #define PICMR0_MASK_ATTRIB (PICMR_MASK_512MB | PICMR_ENABLE | \
  66. PICMR_PREFETCH_EN)
  67. #else
  68. #define PICMR0_MASK_ATTRIB CFG_PICMR0_MASK_ATTRIB
  69. #endif
  70. /*
  71. * These are the windows that allow the CPU to access PCI address space.
  72. * All three PCI master windows, which allow the CPU to access PCI
  73. * prefetch, non prefetch, and IO space (see below), must all fit within
  74. * these windows.
  75. */
  76. /* PCIBR0 */
  77. #ifndef CFG_PCI_MSTR0_LOCAL
  78. #define PCI_MSTR0_LOCAL 0x80000000 /* Local base */
  79. #else
  80. #define PCI_MSTR0_LOCAL CFG_PCI_MSTR0_LOCAL
  81. #endif
  82. #ifndef CFG_PCIMSK0_MASK
  83. #define PCIMSK0_MASK PCIMSK_1GB /* Size of window */
  84. #else
  85. #define PCIMSK0_MASK CFG_PCIMSK0_MASK
  86. #endif
  87. /* PCIBR1 */
  88. #ifndef CFG_PCI_MSTR1_LOCAL
  89. #define PCI_MSTR1_LOCAL 0xF4000000 /* Local base */
  90. #else
  91. #define PCI_MSTR1_LOCAL CFG_PCI_MSTR1_LOCAL
  92. #endif
  93. #ifndef CFG_PCIMSK1_MASK
  94. #define PCIMSK1_MASK PCIMSK_64MB /* Size of window */
  95. #else
  96. #define PCIMSK1_MASK CFG_PCIMSK1_MASK
  97. #endif
  98. /*
  99. * Master window that allows the CPU to access PCI Memory (prefetch).
  100. * This window will be setup with the first set of Outbound ATU registers
  101. * in the bridge.
  102. */
  103. #ifndef CFG_PCI_MSTR_MEM_LOCAL
  104. #define PCI_MSTR_MEM_LOCAL 0x80000000 /* Local base */
  105. #else
  106. #define PCI_MSTR_MEM_LOCAL CFG_PCI_MSTR_MEM_LOCAL
  107. #endif
  108. #ifndef CFG_PCI_MSTR_MEM_BUS
  109. #define PCI_MSTR_MEM_BUS 0x80000000 /* PCI base */
  110. #else
  111. #define PCI_MSTR_MEM_BUS CFG_PCI_MSTR_MEM_BUS
  112. #endif
  113. #ifndef CFG_CPU_PCI_MEM_START
  114. #define CPU_PCI_MEM_START PCI_MSTR_MEM_LOCAL
  115. #else
  116. #define CPU_PCI_MEM_START CFG_CPU_PCI_MEM_START
  117. #endif
  118. #ifndef CFG_PCI_MSTR_MEM_SIZE
  119. #define PCI_MSTR_MEM_SIZE 0x10000000 /* 256MB */
  120. #else
  121. #define PCI_MSTR_MEM_SIZE CFG_PCI_MSTR_MEM_SIZE
  122. #endif
  123. #ifndef CFG_POCMR0_MASK_ATTRIB
  124. #define POCMR0_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PREFETCH_EN)
  125. #else
  126. #define POCMR0_MASK_ATTRIB CFG_POCMR0_MASK_ATTRIB
  127. #endif
  128. /*
  129. * Master window that allows the CPU to access PCI Memory (non-prefetch).
  130. * This window will be setup with the second set of Outbound ATU registers
  131. * in the bridge.
  132. */
  133. #ifndef CFG_PCI_MSTR_MEMIO_LOCAL
  134. #define PCI_MSTR_MEMIO_LOCAL 0x90000000 /* Local base */
  135. #else
  136. #define PCI_MSTR_MEMIO_LOCAL CFG_PCI_MSTR_MEMIO_LOCAL
  137. #endif
  138. #ifndef CFG_PCI_MSTR_MEMIO_BUS
  139. #define PCI_MSTR_MEMIO_BUS 0x90000000 /* PCI base */
  140. #else
  141. #define PCI_MSTR_MEMIO_BUS CFG_PCI_MSTR_MEMIO_BUS
  142. #endif
  143. #ifndef CFG_CPU_PCI_MEMIO_START
  144. #define CPU_PCI_MEMIO_START PCI_MSTR_MEMIO_LOCAL
  145. #else
  146. #define CPU_PCI_MEMIO_START CFG_CPU_PCI_MEMIO_START
  147. #endif
  148. #ifndef CFG_PCI_MSTR_MEMIO_SIZE
  149. #define PCI_MSTR_MEMIO_SIZE 0x10000000 /* 256 MB */
  150. #else
  151. #define PCI_MSTR_MEMIO_SIZE CFG_PCI_MSTR_MEMIO_SIZE
  152. #endif
  153. #ifndef CFG_POCMR1_MASK_ATTRIB
  154. #define POCMR1_MASK_ATTRIB (POCMR_MASK_512MB | POCMR_ENABLE)
  155. #else
  156. #define POCMR1_MASK_ATTRIB CFG_POCMR1_MASK_ATTRIB
  157. #endif
  158. /*
  159. * Master window that allows the CPU to access PCI IO space.
  160. * This window will be setup with the third set of Outbound ATU registers
  161. * in the bridge.
  162. */
  163. #ifndef CFG_PCI_MSTR_IO_LOCAL
  164. #define PCI_MSTR_IO_LOCAL 0xA0000000 /* Local base */
  165. #else
  166. #define PCI_MSTR_IO_LOCAL CFG_PCI_MSTR_IO_LOCAL
  167. #endif
  168. #ifndef CFG_PCI_MSTR_IO_BUS
  169. #define PCI_MSTR_IO_BUS 0xA0000000 /* PCI base */
  170. #else
  171. #define PCI_MSTR_IO_BUS CFG_PCI_MSTR_IO_BUS
  172. #endif
  173. #ifndef CFG_CPU_PCI_IO_START
  174. #define CPU_PCI_IO_START PCI_MSTR_IO_LOCAL
  175. #else
  176. #define CPU_PCI_IO_START CFG_CPU_PCI_IO_START
  177. #endif
  178. #ifndef CFG_PCI_MSTR_IO_SIZE
  179. #define PCI_MSTR_IO_SIZE 0x10000000 /* 256MB */
  180. #else
  181. #define PCI_MSTR_IO_SIZE CFG_PCI_MSTR_IO_SIZE
  182. #endif
  183. #ifndef CFG_POCMR2_MASK_ATTRIB
  184. #define POCMR2_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PCI_IO)
  185. #else
  186. #define POCMR2_MASK_ATTRIB CFG_POCMR2_MASK_ATTRIB
  187. #endif
  188. /* PCI bus configuration registers.
  189. */
  190. #define PCI_CLASS_BRIDGE_CTLR 0x06
  191. static inline void pci_outl(u32 addr, u32 data)
  192. {
  193. *(volatile u32 *) addr = cpu_to_le32(data);
  194. }
  195. void pci_mpc8250_init(struct pci_controller *hose)
  196. {
  197. #ifdef CONFIG_MPC8266ADS
  198. DECLARE_GLOBAL_DATA_PTR;
  199. #endif
  200. u16 tempShort;
  201. u32 immr_addr = CFG_IMMR;
  202. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  203. pci_dev_t host_devno = PCI_BDF(0, 0, 0);
  204. pci_setup_indirect(hose, CFG_IMMR + PCI_CFG_ADDR_REG,
  205. CFG_IMMR + PCI_CFG_DATA_REG);
  206. /*
  207. * Setting required to enable local bus for PCI (SIUMCR [LBPC]).
  208. */
  209. #ifdef CONFIG_MPC8266ADS
  210. immap->im_siu_conf.sc_siumcr = (immap->im_siu_conf.sc_siumcr & ~SIUMCR_LBPC11)
  211. | SIUMCR_LBPC01;
  212. #else
  213. /*
  214. * Setting required to enable IRQ1-IRQ7 (SIUMCR [DPPC]),
  215. * and local bus for PCI (SIUMCR [LBPC]).
  216. */
  217. immap->im_siu_conf.sc_siumcr = 0x00640000;
  218. #endif
  219. /* Make PCI lowest priority */
  220. /* Each 4 bits is a device bus request and the MS 4bits
  221. is highest priority */
  222. /* Bus 4bit value
  223. --- ----------
  224. CPM high 0b0000
  225. CPM middle 0b0001
  226. CPM low 0b0010
  227. PCI reguest 0b0011
  228. Reserved 0b0100
  229. Reserved 0b0101
  230. Internal Core 0b0110
  231. External Master 1 0b0111
  232. External Master 2 0b1000
  233. External Master 3 0b1001
  234. The rest are reserved */
  235. immap->im_siu_conf.sc_ppc_alrh = 0x61207893;
  236. /* Park bus on core while modifying PCI Bus accesses */
  237. immap->im_siu_conf.sc_ppc_acr = 0x6;
  238. /*
  239. * Set up master windows that allow the CPU to access PCI space. These
  240. * windows are set up using the two SIU PCIBR registers.
  241. */
  242. *(volatile unsigned long*)(immr_addr + M8265_PCIMSK0) = PCIMSK0_MASK;
  243. *(volatile unsigned long*)(immr_addr + M8265_PCIBR0) =
  244. PCI_MSTR0_LOCAL | PCIBR_ENABLE;
  245. #ifdef CONFIG_MPC8266ADS
  246. *(volatile unsigned long*)(immr_addr + M8265_PCIMSK1) = PCIMSK1_MASK;
  247. *(volatile unsigned long*)(immr_addr + M8265_PCIBR1) =
  248. PCI_MSTR1_LOCAL | PCIBR_ENABLE;
  249. #endif
  250. /* Release PCI RST (by default the PCI RST signal is held low) */
  251. pci_outl (immr_addr | PCI_GCR_REG, PCIGCR_PCI_BUS_EN);
  252. /* give it some time */
  253. {
  254. #ifdef CONFIG_MPC8266ADS
  255. /* Give the PCI cards more time to initialize before query
  256. This might be good for other boards also
  257. */
  258. int i;
  259. for (i = 0; i < 1000; ++i)
  260. #endif
  261. udelay(1000);
  262. }
  263. /*
  264. * Set up master window that allows the CPU to access PCI Memory (prefetch)
  265. * space. This window is set up using the first set of Outbound ATU registers.
  266. */
  267. pci_outl (immr_addr | POTAR_REG0, PCI_MSTR_MEM_BUS >> 12); /* PCI base */
  268. pci_outl (immr_addr | POBAR_REG0, PCI_MSTR_MEM_LOCAL >> 12); /* Local base */
  269. pci_outl (immr_addr | POCMR_REG0, POCMR0_MASK_ATTRIB); /* Size & attribute */
  270. /*
  271. * Set up master window that allows the CPU to access PCI Memory (non-prefetch)
  272. * space. This window is set up using the second set of Outbound ATU registers.
  273. */
  274. pci_outl (immr_addr | POTAR_REG1, PCI_MSTR_MEMIO_BUS >> 12); /* PCI base */
  275. pci_outl (immr_addr | POBAR_REG1, PCI_MSTR_MEMIO_LOCAL >> 12); /* Local base */
  276. pci_outl (immr_addr | POCMR_REG1, POCMR1_MASK_ATTRIB); /* Size & attribute */
  277. /*
  278. * Set up master window that allows the CPU to access PCI IO space. This window
  279. * is set up using the third set of Outbound ATU registers.
  280. */
  281. pci_outl (immr_addr | POTAR_REG2, PCI_MSTR_IO_BUS >> 12); /* PCI base */
  282. pci_outl (immr_addr | POBAR_REG2, PCI_MSTR_IO_LOCAL >> 12); /* Local base */
  283. pci_outl (immr_addr | POCMR_REG2, POCMR2_MASK_ATTRIB); /* Size & attribute */
  284. /*
  285. * Set up slave window that allows PCI masters to access MPC826x local memory.
  286. * This window is set up using the first set of Inbound ATU registers
  287. */
  288. pci_outl (immr_addr | PITAR_REG0, PCI_SLV_MEM_LOCAL >> 12); /* Local base */
  289. pci_outl (immr_addr | PIBAR_REG0, PCI_SLV_MEM_BUS >> 12); /* PCI base */
  290. pci_outl (immr_addr | PICMR_REG0, PICMR0_MASK_ATTRIB); /* Size & attribute */
  291. /* See above for description - puts PCI request as highest priority */
  292. immap->im_siu_conf.sc_ppc_alrh = 0x03124567;
  293. /* Park the bus on the PCI */
  294. immap->im_siu_conf.sc_ppc_acr = PPC_ACR_BUS_PARK_PCI;
  295. /* Host mode - specify the bridge as a host-PCI bridge */
  296. pci_hose_write_config_byte(hose, host_devno, PCI_CLASS_CODE,
  297. PCI_CLASS_BRIDGE_CTLR);
  298. /* Enable the host bridge to be a master on the PCI bus, and to act as a PCI memory target */
  299. pci_hose_read_config_word(hose, host_devno, PCI_COMMAND, &tempShort);
  300. pci_hose_write_config_word(hose, host_devno, PCI_COMMAND,
  301. tempShort | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
  302. #ifdef CONFIG_MPC8266ADS
  303. /* do some bridge init, should be done on all 8260 based bridges */
  304. pci_hose_write_config_byte(hose, host_devno, PCI_CACHE_LINE_SIZE, 0x08);
  305. pci_hose_write_config_byte(hose, host_devno, PCI_LATENCY_TIMER, 0xF8);
  306. #endif
  307. hose->first_busno = 0;
  308. hose->last_busno = 0xff;
  309. /* System memory space */
  310. #ifdef CONFIG_MPC8266ADS
  311. pci_set_region(hose->regions + 0,
  312. PCI_SLV_MEM_BUS,
  313. PCI_SLV_MEM_LOCAL,
  314. gd->ram_size,
  315. PCI_REGION_MEM | PCI_REGION_MEMORY);
  316. #else
  317. pci_set_region(hose->regions + 0,
  318. CFG_SDRAM_BASE,
  319. CFG_SDRAM_BASE,
  320. 0x4000000,
  321. PCI_REGION_MEM | PCI_REGION_MEMORY);
  322. #endif
  323. /* PCI memory space */
  324. #ifdef CONFIG_MPC8266ADS
  325. pci_set_region(hose->regions + 1,
  326. PCI_MSTR_MEMIO_BUS,
  327. PCI_MSTR_MEMIO_LOCAL,
  328. PCI_MSTR_MEMIO_SIZE,
  329. PCI_REGION_MEM);
  330. #else
  331. pci_set_region(hose->regions + 1,
  332. PCI_MSTR_MEM_BUS,
  333. PCI_MSTR_MEM_LOCAL,
  334. PCI_MSTR_MEM_SIZE,
  335. PCI_REGION_MEM);
  336. #endif
  337. /* PCI I/O space */
  338. pci_set_region(hose->regions + 2,
  339. PCI_MSTR_IO_BUS,
  340. PCI_MSTR_IO_LOCAL,
  341. PCI_MSTR_IO_SIZE,
  342. PCI_REGION_IO);
  343. hose->region_count = 3;
  344. pci_register_hose(hose);
  345. hose->last_busno = pci_hose_scan(hose);
  346. }
  347. #endif /* CONFIG_PCI */