pci.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Copyright (c) 2005 MontaVista Software, Inc.
  6. * Vitaly Bordug <vbordug@ru.mvista.com>
  7. * Added support for PCI bridge on MPC8272ADS
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #ifdef CONFIG_PCI
  29. #include <pci.h>
  30. #include <mpc8260.h>
  31. #include <asm/m8260_pci.h>
  32. #include <asm/io.h>
  33. /*
  34. * Local->PCI map (from CPU) controlled by
  35. * MPC826x master window
  36. *
  37. * 0x80000000 - 0xBFFFFFFF CPU2PCI space PCIBR0
  38. * 0xF4000000 - 0xF7FFFFFF CPU2PCI space PCIBR1
  39. *
  40. * 0x80000000 - 0x9FFFFFFF 0x80000000 - 0x9FFFFFFF (Outbound ATU #1)
  41. * PCI Mem with prefetch
  42. *
  43. * 0xA0000000 - 0xBFFFFFFF 0xA0000000 - 0xBFFFFFFF (Outbound ATU #2)
  44. * PCI Mem w/o prefetch
  45. *
  46. * 0xF4000000 - 0xF7FFFFFF 0x00000000 - 0x03FFFFFF (Outbound ATU #3)
  47. * 32-bit PCI IO
  48. *
  49. * PCI->Local map (from PCI)
  50. * MPC826x slave window controlled by
  51. *
  52. * 0x00000000 - 0x1FFFFFFF 0x00000000 - 0x1FFFFFFF (Inbound ATU #1)
  53. * MPC826x local memory
  54. */
  55. /*
  56. * Slave window that allows PCI masters to access MPC826x local memory.
  57. * This window is set up using the first set of Inbound ATU registers
  58. */
  59. #ifndef CFG_PCI_SLV_MEM_LOCAL
  60. #define PCI_SLV_MEM_LOCAL CFG_SDRAM_BASE /* Local base */
  61. #else
  62. #define PCI_SLV_MEM_LOCAL CFG_PCI_SLV_MEM_LOCAL
  63. #endif
  64. #ifndef CFG_PCI_SLV_MEM_BUS
  65. #define PCI_SLV_MEM_BUS 0x00000000 /* PCI base */
  66. #else
  67. #define PCI_SLV_MEM_BUS CFG_PCI_SLV_MEM_BUS
  68. #endif
  69. #ifndef CFG_PICMR0_MASK_ATTRIB
  70. #define PICMR0_MASK_ATTRIB (PICMR_MASK_512MB | PICMR_ENABLE | \
  71. PICMR_PREFETCH_EN)
  72. #else
  73. #define PICMR0_MASK_ATTRIB CFG_PICMR0_MASK_ATTRIB
  74. #endif
  75. /*
  76. * These are the windows that allow the CPU to access PCI address space.
  77. * All three PCI master windows, which allow the CPU to access PCI
  78. * prefetch, non prefetch, and IO space (see below), must all fit within
  79. * these windows.
  80. */
  81. /* PCIBR0 */
  82. #ifndef CFG_PCI_MSTR0_LOCAL
  83. #define PCI_MSTR0_LOCAL 0x80000000 /* Local base */
  84. #else
  85. #define PCI_MSTR0_LOCAL CFG_PCI_MSTR0_LOCAL
  86. #endif
  87. #ifndef CFG_PCIMSK0_MASK
  88. #define PCIMSK0_MASK PCIMSK_1GB /* Size of window */
  89. #else
  90. #define PCIMSK0_MASK CFG_PCIMSK0_MASK
  91. #endif
  92. /* PCIBR1 */
  93. #ifndef CFG_PCI_MSTR1_LOCAL
  94. #define PCI_MSTR1_LOCAL 0xF4000000 /* Local base */
  95. #else
  96. #define PCI_MSTR1_LOCAL CFG_PCI_MSTR1_LOCAL
  97. #endif
  98. #ifndef CFG_PCIMSK1_MASK
  99. #define PCIMSK1_MASK PCIMSK_64MB /* Size of window */
  100. #else
  101. #define PCIMSK1_MASK CFG_PCIMSK1_MASK
  102. #endif
  103. /*
  104. * Master window that allows the CPU to access PCI Memory (prefetch).
  105. * This window will be setup with the first set of Outbound ATU registers
  106. * in the bridge.
  107. */
  108. #ifndef CFG_PCI_MSTR_MEM_LOCAL
  109. #define PCI_MSTR_MEM_LOCAL 0x80000000 /* Local base */
  110. #else
  111. #define PCI_MSTR_MEM_LOCAL CFG_PCI_MSTR_MEM_LOCAL
  112. #endif
  113. #ifndef CFG_PCI_MSTR_MEM_BUS
  114. #define PCI_MSTR_MEM_BUS 0x80000000 /* PCI base */
  115. #else
  116. #define PCI_MSTR_MEM_BUS CFG_PCI_MSTR_MEM_BUS
  117. #endif
  118. #ifndef CFG_CPU_PCI_MEM_START
  119. #define CPU_PCI_MEM_START PCI_MSTR_MEM_LOCAL
  120. #else
  121. #define CPU_PCI_MEM_START CFG_CPU_PCI_MEM_START
  122. #endif
  123. #ifndef CFG_PCI_MSTR_MEM_SIZE
  124. #define PCI_MSTR_MEM_SIZE 0x10000000 /* 256MB */
  125. #else
  126. #define PCI_MSTR_MEM_SIZE CFG_PCI_MSTR_MEM_SIZE
  127. #endif
  128. #ifndef CFG_POCMR0_MASK_ATTRIB
  129. #define POCMR0_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PREFETCH_EN)
  130. #else
  131. #define POCMR0_MASK_ATTRIB CFG_POCMR0_MASK_ATTRIB
  132. #endif
  133. /*
  134. * Master window that allows the CPU to access PCI Memory (non-prefetch).
  135. * This window will be setup with the second set of Outbound ATU registers
  136. * in the bridge.
  137. */
  138. #ifndef CFG_PCI_MSTR_MEMIO_LOCAL
  139. #define PCI_MSTR_MEMIO_LOCAL 0x90000000 /* Local base */
  140. #else
  141. #define PCI_MSTR_MEMIO_LOCAL CFG_PCI_MSTR_MEMIO_LOCAL
  142. #endif
  143. #ifndef CFG_PCI_MSTR_MEMIO_BUS
  144. #define PCI_MSTR_MEMIO_BUS 0x90000000 /* PCI base */
  145. #else
  146. #define PCI_MSTR_MEMIO_BUS CFG_PCI_MSTR_MEMIO_BUS
  147. #endif
  148. #ifndef CFG_CPU_PCI_MEMIO_START
  149. #define CPU_PCI_MEMIO_START PCI_MSTR_MEMIO_LOCAL
  150. #else
  151. #define CPU_PCI_MEMIO_START CFG_CPU_PCI_MEMIO_START
  152. #endif
  153. #ifndef CFG_PCI_MSTR_MEMIO_SIZE
  154. #define PCI_MSTR_MEMIO_SIZE 0x10000000 /* 256 MB */
  155. #else
  156. #define PCI_MSTR_MEMIO_SIZE CFG_PCI_MSTR_MEMIO_SIZE
  157. #endif
  158. #ifndef CFG_POCMR1_MASK_ATTRIB
  159. #define POCMR1_MASK_ATTRIB (POCMR_MASK_512MB | POCMR_ENABLE)
  160. #else
  161. #define POCMR1_MASK_ATTRIB CFG_POCMR1_MASK_ATTRIB
  162. #endif
  163. /*
  164. * Master window that allows the CPU to access PCI IO space.
  165. * This window will be setup with the third set of Outbound ATU registers
  166. * in the bridge.
  167. */
  168. #ifndef CFG_PCI_MSTR_IO_LOCAL
  169. #define PCI_MSTR_IO_LOCAL 0xA0000000 /* Local base */
  170. #else
  171. #define PCI_MSTR_IO_LOCAL CFG_PCI_MSTR_IO_LOCAL
  172. #endif
  173. #ifndef CFG_PCI_MSTR_IO_BUS
  174. #define PCI_MSTR_IO_BUS 0xA0000000 /* PCI base */
  175. #else
  176. #define PCI_MSTR_IO_BUS CFG_PCI_MSTR_IO_BUS
  177. #endif
  178. #ifndef CFG_CPU_PCI_IO_START
  179. #define CPU_PCI_IO_START PCI_MSTR_IO_LOCAL
  180. #else
  181. #define CPU_PCI_IO_START CFG_CPU_PCI_IO_START
  182. #endif
  183. #ifndef CFG_PCI_MSTR_IO_SIZE
  184. #define PCI_MSTR_IO_SIZE 0x10000000 /* 256MB */
  185. #else
  186. #define PCI_MSTR_IO_SIZE CFG_PCI_MSTR_IO_SIZE
  187. #endif
  188. #ifndef CFG_POCMR2_MASK_ATTRIB
  189. #define POCMR2_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PCI_IO)
  190. #else
  191. #define POCMR2_MASK_ATTRIB CFG_POCMR2_MASK_ATTRIB
  192. #endif
  193. /* PCI bus configuration registers.
  194. */
  195. #define PCI_CLASS_BRIDGE_CTLR 0x06
  196. static inline void pci_outl (u32 addr, u32 data)
  197. {
  198. *(volatile u32 *) addr = cpu_to_le32 (data);
  199. }
  200. void pci_mpc8250_init (struct pci_controller *hose)
  201. {
  202. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
  203. DECLARE_GLOBAL_DATA_PTR;
  204. #endif
  205. u16 tempShort;
  206. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  207. pci_dev_t host_devno = PCI_BDF (0, 0, 0);
  208. pci_setup_indirect (hose, CFG_IMMR + PCI_CFG_ADDR_REG,
  209. CFG_IMMR + PCI_CFG_DATA_REG);
  210. /*
  211. * Setting required to enable local bus for PCI (SIUMCR [LBPC]).
  212. */
  213. #ifdef CONFIG_MPC8266ADS
  214. immap->im_siu_conf.sc_siumcr =
  215. (immap->im_siu_conf.sc_siumcr & ~SIUMCR_LBPC11)
  216. | SIUMCR_LBPC01;
  217. #elif defined CONFIG_MPC8272
  218. immap->im_siu_conf.sc_siumcr = (immap->im_siu_conf.sc_siumcr &
  219. ~SIUMCR_BBD &
  220. ~SIUMCR_ESE &
  221. ~SIUMCR_PBSE &
  222. ~SIUMCR_CDIS &
  223. ~SIUMCR_DPPC11 &
  224. ~SIUMCR_L2CPC11 &
  225. ~SIUMCR_LBPC11 &
  226. ~SIUMCR_APPC11 &
  227. ~SIUMCR_CS10PC11 &
  228. ~SIUMCR_BCTLC11 &
  229. ~SIUMCR_MMR11)
  230. | SIUMCR_DPPC11
  231. | SIUMCR_L2CPC01
  232. | SIUMCR_LBPC00
  233. | SIUMCR_APPC10
  234. | SIUMCR_CS10PC00
  235. | SIUMCR_BCTLC00
  236. | SIUMCR_MMR11;
  237. #else
  238. /*
  239. * Setting required to enable IRQ1-IRQ7 (SIUMCR [DPPC]),
  240. * and local bus for PCI (SIUMCR [LBPC]).
  241. */
  242. immap->im_siu_conf.sc_siumcr = (immap->im_siu_conf.sc_siumcr &
  243. ~SIUMCR_LBPC11 &
  244. ~SIUMCR_CS10PC11 &
  245. ~SIUMCR_LBPC11) |
  246. SIUMCR_LBPC01 |
  247. SIUMCR_CS10PC01 |
  248. SIUMCR_APPC10;
  249. #endif
  250. /* Make PCI lowest priority */
  251. /* Each 4 bits is a device bus request and the MS 4bits
  252. is highest priority */
  253. /* Bus 4bit value
  254. --- ----------
  255. CPM high 0b0000
  256. CPM middle 0b0001
  257. CPM low 0b0010
  258. PCI reguest 0b0011
  259. Reserved 0b0100
  260. Reserved 0b0101
  261. Internal Core 0b0110
  262. External Master 1 0b0111
  263. External Master 2 0b1000
  264. External Master 3 0b1001
  265. The rest are reserved */
  266. immap->im_siu_conf.sc_ppc_alrh = 0x61207893;
  267. /* Park bus on core while modifying PCI Bus accesses */
  268. immap->im_siu_conf.sc_ppc_acr = 0x6;
  269. /*
  270. * Set up master windows that allow the CPU to access PCI space. These
  271. * windows are set up using the two SIU PCIBR registers.
  272. */
  273. immap->im_memctl.memc_pcimsk0 = PCIMSK0_MASK;
  274. immap->im_memctl.memc_pcibr0 = PCI_MSTR0_LOCAL | PCIBR_ENABLE;
  275. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
  276. immap->im_memctl.memc_pcimsk1 = PCIMSK1_MASK;
  277. immap->im_memctl.memc_pcibr1 = PCI_MSTR1_LOCAL | PCIBR_ENABLE;
  278. #endif
  279. /* Release PCI RST (by default the PCI RST signal is held low) */
  280. immap->im_pci.pci_gcr = cpu_to_le32 (PCIGCR_PCI_BUS_EN);
  281. /* give it some time */
  282. {
  283. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
  284. /* Give the PCI cards more time to initialize before query
  285. This might be good for other boards also
  286. */
  287. int i;
  288. for (i = 0; i < 1000; ++i)
  289. #endif
  290. udelay (1000);
  291. }
  292. /*
  293. * Set up master window that allows the CPU to access PCI Memory (prefetch)
  294. * space. This window is set up using the first set of Outbound ATU registers.
  295. */
  296. immap->im_pci.pci_potar0 = cpu_to_le32 (PCI_MSTR_MEM_BUS >> 12); /* PCI base */
  297. immap->im_pci.pci_pobar0 = cpu_to_le32 (PCI_MSTR_MEM_LOCAL >> 12); /* Local base */
  298. immap->im_pci.pci_pocmr0 = cpu_to_le32 (POCMR0_MASK_ATTRIB); /* Size & attribute */
  299. /*
  300. * Set up master window that allows the CPU to access PCI Memory (non-prefetch)
  301. * space. This window is set up using the second set of Outbound ATU registers.
  302. */
  303. immap->im_pci.pci_potar1 = cpu_to_le32 (PCI_MSTR_MEMIO_BUS >> 12); /* PCI base */
  304. immap->im_pci.pci_pobar1 = cpu_to_le32 (PCI_MSTR_MEMIO_LOCAL >> 12); /* Local base */
  305. immap->im_pci.pci_pocmr1 = cpu_to_le32 (POCMR1_MASK_ATTRIB); /* Size & attribute */
  306. /*
  307. * Set up master window that allows the CPU to access PCI IO space. This window
  308. * is set up using the third set of Outbound ATU registers.
  309. */
  310. immap->im_pci.pci_potar2 = cpu_to_le32 (PCI_MSTR_IO_BUS >> 12); /* PCI base */
  311. immap->im_pci.pci_pobar2 = cpu_to_le32 (PCI_MSTR_IO_LOCAL >> 12); /* Local base */
  312. immap->im_pci.pci_pocmr2 = cpu_to_le32 (POCMR2_MASK_ATTRIB); /* Size & attribute */
  313. /*
  314. * Set up slave window that allows PCI masters to access MPC826x local memory.
  315. * This window is set up using the first set of Inbound ATU registers
  316. */
  317. immap->im_pci.pci_pitar0 = cpu_to_le32 (PCI_SLV_MEM_LOCAL >> 12); /* PCI base */
  318. immap->im_pci.pci_pibar0 = cpu_to_le32 (PCI_SLV_MEM_BUS >> 12); /* Local base */
  319. immap->im_pci.pci_picmr0 = cpu_to_le32 (PICMR0_MASK_ATTRIB); /* Size & attribute */
  320. /* See above for description - puts PCI request as highest priority */
  321. #ifdef CONFIG_MPC8272
  322. immap->im_siu_conf.sc_ppc_alrh = 0x01236745;
  323. #else
  324. immap->im_siu_conf.sc_ppc_alrh = 0x03124567;
  325. #endif
  326. /* Park the bus on the PCI */
  327. immap->im_siu_conf.sc_ppc_acr = PPC_ACR_BUS_PARK_PCI;
  328. /* Host mode - specify the bridge as a host-PCI bridge */
  329. pci_hose_write_config_byte (hose, host_devno, PCI_CLASS_CODE,
  330. PCI_CLASS_BRIDGE_CTLR);
  331. /* Enable the host bridge to be a master on the PCI bus, and to act as a PCI memory target */
  332. pci_hose_read_config_word (hose, host_devno, PCI_COMMAND, &tempShort);
  333. pci_hose_write_config_word (hose, host_devno, PCI_COMMAND,
  334. tempShort | PCI_COMMAND_MASTER |
  335. PCI_COMMAND_MEMORY);
  336. /* do some bridge init, should be done on all 8260 based bridges */
  337. pci_hose_write_config_byte (hose, host_devno, PCI_CACHE_LINE_SIZE,
  338. 0x08);
  339. pci_hose_write_config_byte (hose, host_devno, PCI_LATENCY_TIMER,
  340. 0xF8);
  341. hose->first_busno = 0;
  342. hose->last_busno = 0xff;
  343. /* System memory space */
  344. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
  345. pci_set_region (hose->regions + 0,
  346. PCI_SLV_MEM_BUS,
  347. PCI_SLV_MEM_LOCAL,
  348. gd->ram_size, PCI_REGION_MEM | PCI_REGION_MEMORY);
  349. #else
  350. pci_set_region (hose->regions + 0,
  351. CFG_SDRAM_BASE,
  352. CFG_SDRAM_BASE,
  353. 0x4000000, PCI_REGION_MEM | PCI_REGION_MEMORY);
  354. #endif
  355. /* PCI memory space */
  356. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
  357. pci_set_region (hose->regions + 1,
  358. PCI_MSTR_MEMIO_BUS,
  359. PCI_MSTR_MEMIO_LOCAL,
  360. PCI_MSTR_MEMIO_SIZE, PCI_REGION_MEM);
  361. #else
  362. pci_set_region (hose->regions + 1,
  363. PCI_MSTR_MEM_BUS,
  364. PCI_MSTR_MEM_LOCAL,
  365. PCI_MSTR_MEM_SIZE, PCI_REGION_MEM);
  366. #endif
  367. /* PCI I/O space */
  368. pci_set_region (hose->regions + 2,
  369. PCI_MSTR_IO_BUS,
  370. PCI_MSTR_IO_LOCAL, PCI_MSTR_IO_SIZE, PCI_REGION_IO);
  371. hose->region_count = 3;
  372. pci_register_hose (hose);
  373. /* Mask off master abort machine checks */
  374. immap->im_pci.pci_emr &= cpu_to_le32 (~PCI_ERROR_PCI_NO_RSP);
  375. eieio ();
  376. hose->last_busno = pci_hose_scan (hose);
  377. /* clear the error in the error status register */
  378. immap->im_pci.pci_esr = cpu_to_le32 (PCI_ERROR_PCI_NO_RSP);
  379. /* unmask master abort machine checks */
  380. immap->im_pci.pci_emr |= cpu_to_le32 (PCI_ERROR_PCI_NO_RSP);
  381. }
  382. #endif /* CONFIG_PCI */