pci.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272 || defined CONFIG_PM826
  34. DECLARE_GLOBAL_DATA_PTR;
  35. #endif
  36. /*
  37. * Local->PCI map (from CPU) controlled by
  38. * MPC826x master window
  39. *
  40. * 0x80000000 - 0xBFFFFFFF CPU2PCI space PCIBR0
  41. * 0xF4000000 - 0xF7FFFFFF CPU2PCI space PCIBR1
  42. *
  43. * 0x80000000 - 0x9FFFFFFF 0x80000000 - 0x9FFFFFFF (Outbound ATU #1)
  44. * PCI Mem with prefetch
  45. *
  46. * 0xA0000000 - 0xBFFFFFFF 0xA0000000 - 0xBFFFFFFF (Outbound ATU #2)
  47. * PCI Mem w/o prefetch
  48. *
  49. * 0xF4000000 - 0xF7FFFFFF 0x00000000 - 0x03FFFFFF (Outbound ATU #3)
  50. * 32-bit PCI IO
  51. *
  52. * PCI->Local map (from PCI)
  53. * MPC826x slave window controlled by
  54. *
  55. * 0x00000000 - 0x1FFFFFFF 0x00000000 - 0x1FFFFFFF (Inbound ATU #1)
  56. * MPC826x local memory
  57. */
  58. /*
  59. * Slave window that allows PCI masters to access MPC826x local memory.
  60. * This window is set up using the first set of Inbound ATU registers
  61. */
  62. #ifndef CFG_PCI_SLV_MEM_LOCAL
  63. #define PCI_SLV_MEM_LOCAL CFG_SDRAM_BASE /* Local base */
  64. #else
  65. #define PCI_SLV_MEM_LOCAL CFG_PCI_SLV_MEM_LOCAL
  66. #endif
  67. #ifndef CFG_PCI_SLV_MEM_BUS
  68. #define PCI_SLV_MEM_BUS 0x00000000 /* PCI base */
  69. #else
  70. #define PCI_SLV_MEM_BUS CFG_PCI_SLV_MEM_BUS
  71. #endif
  72. #ifndef CFG_PICMR0_MASK_ATTRIB
  73. #define PICMR0_MASK_ATTRIB (PICMR_MASK_512MB | PICMR_ENABLE | \
  74. PICMR_PREFETCH_EN)
  75. #else
  76. #define PICMR0_MASK_ATTRIB CFG_PICMR0_MASK_ATTRIB
  77. #endif
  78. /*
  79. * These are the windows that allow the CPU to access PCI address space.
  80. * All three PCI master windows, which allow the CPU to access PCI
  81. * prefetch, non prefetch, and IO space (see below), must all fit within
  82. * these windows.
  83. */
  84. /* PCIBR0 */
  85. #ifndef CFG_PCI_MSTR0_LOCAL
  86. #define PCI_MSTR0_LOCAL 0x80000000 /* Local base */
  87. #else
  88. #define PCI_MSTR0_LOCAL CFG_PCI_MSTR0_LOCAL
  89. #endif
  90. #ifndef CFG_PCIMSK0_MASK
  91. #define PCIMSK0_MASK PCIMSK_1GB /* Size of window */
  92. #else
  93. #define PCIMSK0_MASK CFG_PCIMSK0_MASK
  94. #endif
  95. /* PCIBR1 */
  96. #ifndef CFG_PCI_MSTR1_LOCAL
  97. #define PCI_MSTR1_LOCAL 0xF4000000 /* Local base */
  98. #else
  99. #define PCI_MSTR1_LOCAL CFG_PCI_MSTR1_LOCAL
  100. #endif
  101. #ifndef CFG_PCIMSK1_MASK
  102. #define PCIMSK1_MASK PCIMSK_64MB /* Size of window */
  103. #else
  104. #define PCIMSK1_MASK CFG_PCIMSK1_MASK
  105. #endif
  106. /*
  107. * Master window that allows the CPU to access PCI Memory (prefetch).
  108. * This window will be setup with the first set of Outbound ATU registers
  109. * in the bridge.
  110. */
  111. #ifndef CFG_PCI_MSTR_MEM_LOCAL
  112. #define PCI_MSTR_MEM_LOCAL 0x80000000 /* Local base */
  113. #else
  114. #define PCI_MSTR_MEM_LOCAL CFG_PCI_MSTR_MEM_LOCAL
  115. #endif
  116. #ifndef CFG_PCI_MSTR_MEM_BUS
  117. #define PCI_MSTR_MEM_BUS 0x80000000 /* PCI base */
  118. #else
  119. #define PCI_MSTR_MEM_BUS CFG_PCI_MSTR_MEM_BUS
  120. #endif
  121. #ifndef CFG_CPU_PCI_MEM_START
  122. #define CPU_PCI_MEM_START PCI_MSTR_MEM_LOCAL
  123. #else
  124. #define CPU_PCI_MEM_START CFG_CPU_PCI_MEM_START
  125. #endif
  126. #ifndef CFG_PCI_MSTR_MEM_SIZE
  127. #define PCI_MSTR_MEM_SIZE 0x10000000 /* 256MB */
  128. #else
  129. #define PCI_MSTR_MEM_SIZE CFG_PCI_MSTR_MEM_SIZE
  130. #endif
  131. #ifndef CFG_POCMR0_MASK_ATTRIB
  132. #define POCMR0_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PREFETCH_EN)
  133. #else
  134. #define POCMR0_MASK_ATTRIB CFG_POCMR0_MASK_ATTRIB
  135. #endif
  136. /*
  137. * Master window that allows the CPU to access PCI Memory (non-prefetch).
  138. * This window will be setup with the second set of Outbound ATU registers
  139. * in the bridge.
  140. */
  141. #ifndef CFG_PCI_MSTR_MEMIO_LOCAL
  142. #define PCI_MSTR_MEMIO_LOCAL 0x90000000 /* Local base */
  143. #else
  144. #define PCI_MSTR_MEMIO_LOCAL CFG_PCI_MSTR_MEMIO_LOCAL
  145. #endif
  146. #ifndef CFG_PCI_MSTR_MEMIO_BUS
  147. #define PCI_MSTR_MEMIO_BUS 0x90000000 /* PCI base */
  148. #else
  149. #define PCI_MSTR_MEMIO_BUS CFG_PCI_MSTR_MEMIO_BUS
  150. #endif
  151. #ifndef CFG_CPU_PCI_MEMIO_START
  152. #define CPU_PCI_MEMIO_START PCI_MSTR_MEMIO_LOCAL
  153. #else
  154. #define CPU_PCI_MEMIO_START CFG_CPU_PCI_MEMIO_START
  155. #endif
  156. #ifndef CFG_PCI_MSTR_MEMIO_SIZE
  157. #define PCI_MSTR_MEMIO_SIZE 0x10000000 /* 256 MB */
  158. #else
  159. #define PCI_MSTR_MEMIO_SIZE CFG_PCI_MSTR_MEMIO_SIZE
  160. #endif
  161. #ifndef CFG_POCMR1_MASK_ATTRIB
  162. #define POCMR1_MASK_ATTRIB (POCMR_MASK_512MB | POCMR_ENABLE)
  163. #else
  164. #define POCMR1_MASK_ATTRIB CFG_POCMR1_MASK_ATTRIB
  165. #endif
  166. /*
  167. * Master window that allows the CPU to access PCI IO space.
  168. * This window will be setup with the third set of Outbound ATU registers
  169. * in the bridge.
  170. */
  171. #ifndef CFG_PCI_MSTR_IO_LOCAL
  172. #define PCI_MSTR_IO_LOCAL 0xA0000000 /* Local base */
  173. #else
  174. #define PCI_MSTR_IO_LOCAL CFG_PCI_MSTR_IO_LOCAL
  175. #endif
  176. #ifndef CFG_PCI_MSTR_IO_BUS
  177. #define PCI_MSTR_IO_BUS 0xA0000000 /* PCI base */
  178. #else
  179. #define PCI_MSTR_IO_BUS CFG_PCI_MSTR_IO_BUS
  180. #endif
  181. #ifndef CFG_CPU_PCI_IO_START
  182. #define CPU_PCI_IO_START PCI_MSTR_IO_LOCAL
  183. #else
  184. #define CPU_PCI_IO_START CFG_CPU_PCI_IO_START
  185. #endif
  186. #ifndef CFG_PCI_MSTR_IO_SIZE
  187. #define PCI_MSTR_IO_SIZE 0x10000000 /* 256MB */
  188. #else
  189. #define PCI_MSTR_IO_SIZE CFG_PCI_MSTR_IO_SIZE
  190. #endif
  191. #ifndef CFG_POCMR2_MASK_ATTRIB
  192. #define POCMR2_MASK_ATTRIB (POCMR_MASK_256MB | POCMR_ENABLE | POCMR_PCI_IO)
  193. #else
  194. #define POCMR2_MASK_ATTRIB CFG_POCMR2_MASK_ATTRIB
  195. #endif
  196. /* PCI bus configuration registers.
  197. */
  198. #define PCI_CLASS_BRIDGE_CTLR 0x06
  199. static inline void pci_outl (u32 addr, u32 data)
  200. {
  201. *(volatile u32 *) addr = cpu_to_le32 (data);
  202. }
  203. void pci_mpc8250_init (struct pci_controller *hose)
  204. {
  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. #elif defined(CONFIG_TQM8272)
  238. /* nothing to do for this Board here */
  239. #else
  240. /*
  241. * Setting required to enable IRQ1-IRQ7 (SIUMCR [DPPC]),
  242. * and local bus for PCI (SIUMCR [LBPC]).
  243. */
  244. immap->im_siu_conf.sc_siumcr = (immap->im_siu_conf.sc_siumcr &
  245. ~SIUMCR_LBPC11 &
  246. ~SIUMCR_CS10PC11 &
  247. ~SIUMCR_LBPC11) |
  248. SIUMCR_LBPC01 |
  249. SIUMCR_CS10PC01 |
  250. SIUMCR_APPC10;
  251. #endif
  252. /* Make PCI lowest priority */
  253. /* Each 4 bits is a device bus request and the MS 4bits
  254. is highest priority */
  255. /* Bus 4bit value
  256. --- ----------
  257. CPM high 0b0000
  258. CPM middle 0b0001
  259. CPM low 0b0010
  260. PCI reguest 0b0011
  261. Reserved 0b0100
  262. Reserved 0b0101
  263. Internal Core 0b0110
  264. External Master 1 0b0111
  265. External Master 2 0b1000
  266. External Master 3 0b1001
  267. The rest are reserved */
  268. immap->im_siu_conf.sc_ppc_alrh = 0x61207893;
  269. /* Park bus on core while modifying PCI Bus accesses */
  270. immap->im_siu_conf.sc_ppc_acr = 0x6;
  271. /*
  272. * Set up master windows that allow the CPU to access PCI space. These
  273. * windows are set up using the two SIU PCIBR registers.
  274. */
  275. immap->im_memctl.memc_pcimsk0 = PCIMSK0_MASK;
  276. immap->im_memctl.memc_pcibr0 = PCI_MSTR0_LOCAL | PCIBR_ENABLE;
  277. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
  278. immap->im_memctl.memc_pcimsk1 = PCIMSK1_MASK;
  279. immap->im_memctl.memc_pcibr1 = PCI_MSTR1_LOCAL | PCIBR_ENABLE;
  280. #endif
  281. /* Release PCI RST (by default the PCI RST signal is held low) */
  282. immap->im_pci.pci_gcr = cpu_to_le32 (PCIGCR_PCI_BUS_EN);
  283. /* give it some time */
  284. {
  285. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
  286. /* Give the PCI cards more time to initialize before query
  287. This might be good for other boards also
  288. */
  289. int i;
  290. for (i = 0; i < 1000; ++i)
  291. #endif
  292. udelay (1000);
  293. }
  294. /*
  295. * Set up master window that allows the CPU to access PCI Memory (prefetch)
  296. * space. This window is set up using the first set of Outbound ATU registers.
  297. */
  298. immap->im_pci.pci_potar0 = cpu_to_le32 (PCI_MSTR_MEM_BUS >> 12); /* PCI base */
  299. immap->im_pci.pci_pobar0 = cpu_to_le32 (PCI_MSTR_MEM_LOCAL >> 12); /* Local base */
  300. immap->im_pci.pci_pocmr0 = cpu_to_le32 (POCMR0_MASK_ATTRIB); /* Size & attribute */
  301. /*
  302. * Set up master window that allows the CPU to access PCI Memory (non-prefetch)
  303. * space. This window is set up using the second set of Outbound ATU registers.
  304. */
  305. immap->im_pci.pci_potar1 = cpu_to_le32 (PCI_MSTR_MEMIO_BUS >> 12); /* PCI base */
  306. immap->im_pci.pci_pobar1 = cpu_to_le32 (PCI_MSTR_MEMIO_LOCAL >> 12); /* Local base */
  307. immap->im_pci.pci_pocmr1 = cpu_to_le32 (POCMR1_MASK_ATTRIB); /* Size & attribute */
  308. /*
  309. * Set up master window that allows the CPU to access PCI IO space. This window
  310. * is set up using the third set of Outbound ATU registers.
  311. */
  312. immap->im_pci.pci_potar2 = cpu_to_le32 (PCI_MSTR_IO_BUS >> 12); /* PCI base */
  313. immap->im_pci.pci_pobar2 = cpu_to_le32 (PCI_MSTR_IO_LOCAL >> 12); /* Local base */
  314. immap->im_pci.pci_pocmr2 = cpu_to_le32 (POCMR2_MASK_ATTRIB); /* Size & attribute */
  315. /*
  316. * Set up slave window that allows PCI masters to access MPC826x local memory.
  317. * This window is set up using the first set of Inbound ATU registers
  318. */
  319. immap->im_pci.pci_pitar0 = cpu_to_le32 (PCI_SLV_MEM_LOCAL >> 12); /* PCI base */
  320. immap->im_pci.pci_pibar0 = cpu_to_le32 (PCI_SLV_MEM_BUS >> 12); /* Local base */
  321. immap->im_pci.pci_picmr0 = cpu_to_le32 (PICMR0_MASK_ATTRIB); /* Size & attribute */
  322. /* See above for description - puts PCI request as highest priority */
  323. #ifdef CONFIG_MPC8272
  324. immap->im_siu_conf.sc_ppc_alrh = 0x01236745;
  325. #else
  326. immap->im_siu_conf.sc_ppc_alrh = 0x03124567;
  327. #endif
  328. /* Park the bus on the PCI */
  329. immap->im_siu_conf.sc_ppc_acr = PPC_ACR_BUS_PARK_PCI;
  330. /* Host mode - specify the bridge as a host-PCI bridge */
  331. pci_hose_write_config_byte (hose, host_devno, PCI_CLASS_CODE,
  332. PCI_CLASS_BRIDGE_CTLR);
  333. /* Enable the host bridge to be a master on the PCI bus, and to act as a PCI memory target */
  334. pci_hose_read_config_word (hose, host_devno, PCI_COMMAND, &tempShort);
  335. pci_hose_write_config_word (hose, host_devno, PCI_COMMAND,
  336. tempShort | PCI_COMMAND_MASTER |
  337. PCI_COMMAND_MEMORY);
  338. /* do some bridge init, should be done on all 8260 based bridges */
  339. pci_hose_write_config_byte (hose, host_devno, PCI_CACHE_LINE_SIZE,
  340. 0x08);
  341. pci_hose_write_config_byte (hose, host_devno, PCI_LATENCY_TIMER,
  342. 0xF8);
  343. hose->first_busno = 0;
  344. hose->last_busno = 0xff;
  345. /* System memory space */
  346. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272 || defined CONFIG_PM826
  347. pci_set_region (hose->regions + 0,
  348. PCI_SLV_MEM_BUS,
  349. PCI_SLV_MEM_LOCAL,
  350. gd->ram_size, PCI_REGION_MEM | PCI_REGION_MEMORY);
  351. #else
  352. pci_set_region (hose->regions + 0,
  353. CFG_SDRAM_BASE,
  354. CFG_SDRAM_BASE,
  355. 0x4000000, PCI_REGION_MEM | PCI_REGION_MEMORY);
  356. #endif
  357. /* PCI memory space */
  358. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
  359. pci_set_region (hose->regions + 1,
  360. PCI_MSTR_MEMIO_BUS,
  361. PCI_MSTR_MEMIO_LOCAL,
  362. PCI_MSTR_MEMIO_SIZE, PCI_REGION_MEM);
  363. #else
  364. pci_set_region (hose->regions + 1,
  365. PCI_MSTR_MEM_BUS,
  366. PCI_MSTR_MEM_LOCAL,
  367. PCI_MSTR_MEM_SIZE, PCI_REGION_MEM);
  368. #endif
  369. /* PCI I/O space */
  370. pci_set_region (hose->regions + 2,
  371. PCI_MSTR_IO_BUS,
  372. PCI_MSTR_IO_LOCAL, PCI_MSTR_IO_SIZE, PCI_REGION_IO);
  373. hose->region_count = 3;
  374. pci_register_hose (hose);
  375. /* Mask off master abort machine checks */
  376. immap->im_pci.pci_emr &= cpu_to_le32 (~PCI_ERROR_PCI_NO_RSP);
  377. eieio ();
  378. hose->last_busno = pci_hose_scan (hose);
  379. /* clear the error in the error status register */
  380. immap->im_pci.pci_esr = cpu_to_le32 (PCI_ERROR_PCI_NO_RSP);
  381. /* unmask master abort machine checks */
  382. immap->im_pci.pci_emr |= cpu_to_le32 (PCI_ERROR_PCI_NO_RSP);
  383. }
  384. #endif /* CONFIG_PCI */