pci.c 13 KB

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