pci.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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_MPC8272
  222. immap->im_siu_conf.sc_siumcr = (immap->im_siu_conf.sc_siumcr &
  223. ~SIUMCR_BBD &
  224. ~SIUMCR_ESE &
  225. ~SIUMCR_PBSE &
  226. ~SIUMCR_CDIS &
  227. ~SIUMCR_DPPC11 &
  228. ~SIUMCR_L2CPC11 &
  229. ~SIUMCR_LBPC11 &
  230. ~SIUMCR_APPC11 &
  231. ~SIUMCR_CS10PC11 &
  232. ~SIUMCR_BCTLC11 &
  233. ~SIUMCR_MMR11)
  234. | SIUMCR_DPPC11
  235. | SIUMCR_L2CPC01
  236. | SIUMCR_LBPC00
  237. | SIUMCR_APPC10
  238. | SIUMCR_CS10PC00
  239. | SIUMCR_BCTLC00
  240. | SIUMCR_MMR11;
  241. #elif defined(CONFIG_TQM8272)
  242. /* nothing to do for this Board here */
  243. #else
  244. /*
  245. * Setting required to enable IRQ1-IRQ7 (SIUMCR [DPPC]),
  246. * and local bus for PCI (SIUMCR [LBPC]).
  247. */
  248. immap->im_siu_conf.sc_siumcr = (immap->im_siu_conf.sc_siumcr &
  249. ~SIUMCR_LBPC11 &
  250. ~SIUMCR_CS10PC11 &
  251. ~SIUMCR_LBPC11) |
  252. SIUMCR_LBPC01 |
  253. SIUMCR_CS10PC01 |
  254. SIUMCR_APPC10;
  255. #endif
  256. /* Make PCI lowest priority */
  257. /* Each 4 bits is a device bus request and the MS 4bits
  258. is highest priority */
  259. /* Bus 4bit value
  260. --- ----------
  261. CPM high 0b0000
  262. CPM middle 0b0001
  263. CPM low 0b0010
  264. PCI reguest 0b0011
  265. Reserved 0b0100
  266. Reserved 0b0101
  267. Internal Core 0b0110
  268. External Master 1 0b0111
  269. External Master 2 0b1000
  270. External Master 3 0b1001
  271. The rest are reserved */
  272. immap->im_siu_conf.sc_ppc_alrh = 0x61207893;
  273. /* Park bus on core while modifying PCI Bus accesses */
  274. immap->im_siu_conf.sc_ppc_acr = 0x6;
  275. /*
  276. * Set up master windows that allow the CPU to access PCI space. These
  277. * windows are set up using the two SIU PCIBR registers.
  278. */
  279. immap->im_memctl.memc_pcimsk0 = PCIMSK0_MASK;
  280. immap->im_memctl.memc_pcibr0 = PCI_MSTR0_LOCAL | PCIBR_ENABLE;
  281. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
  282. immap->im_memctl.memc_pcimsk1 = PCIMSK1_MASK;
  283. immap->im_memctl.memc_pcibr1 = PCI_MSTR1_LOCAL | PCIBR_ENABLE;
  284. #endif
  285. /* Release PCI RST (by default the PCI RST signal is held low) */
  286. immap->im_pci.pci_gcr = cpu_to_le32 (PCIGCR_PCI_BUS_EN);
  287. /* give it some time */
  288. {
  289. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
  290. /* Give the PCI cards more time to initialize before query
  291. This might be good for other boards also
  292. */
  293. int i;
  294. for (i = 0; i < 1000; ++i)
  295. #endif
  296. udelay (1000);
  297. }
  298. /*
  299. * Set up master window that allows the CPU to access PCI Memory (prefetch)
  300. * space. This window is set up using the first set of Outbound ATU registers.
  301. */
  302. immap->im_pci.pci_potar0 = cpu_to_le32 (PCI_MSTR_MEM_BUS >> 12); /* PCI base */
  303. immap->im_pci.pci_pobar0 = cpu_to_le32 (PCI_MSTR_MEM_LOCAL >> 12); /* Local base */
  304. immap->im_pci.pci_pocmr0 = cpu_to_le32 (POCMR0_MASK_ATTRIB); /* Size & attribute */
  305. /*
  306. * Set up master window that allows the CPU to access PCI Memory (non-prefetch)
  307. * space. This window is set up using the second set of Outbound ATU registers.
  308. */
  309. immap->im_pci.pci_potar1 = cpu_to_le32 (PCI_MSTR_MEMIO_BUS >> 12); /* PCI base */
  310. immap->im_pci.pci_pobar1 = cpu_to_le32 (PCI_MSTR_MEMIO_LOCAL >> 12); /* Local base */
  311. immap->im_pci.pci_pocmr1 = cpu_to_le32 (POCMR1_MASK_ATTRIB); /* Size & attribute */
  312. /*
  313. * Set up master window that allows the CPU to access PCI IO space. This window
  314. * is set up using the third set of Outbound ATU registers.
  315. */
  316. immap->im_pci.pci_potar2 = cpu_to_le32 (PCI_MSTR_IO_BUS >> 12); /* PCI base */
  317. immap->im_pci.pci_pobar2 = cpu_to_le32 (PCI_MSTR_IO_LOCAL >> 12); /* Local base */
  318. immap->im_pci.pci_pocmr2 = cpu_to_le32 (POCMR2_MASK_ATTRIB); /* Size & attribute */
  319. /*
  320. * Set up slave window that allows PCI masters to access MPC826x local memory.
  321. * This window is set up using the first set of Inbound ATU registers
  322. */
  323. immap->im_pci.pci_pitar0 = cpu_to_le32 (PCI_SLV_MEM_LOCAL >> 12); /* PCI base */
  324. immap->im_pci.pci_pibar0 = cpu_to_le32 (PCI_SLV_MEM_BUS >> 12); /* Local base */
  325. immap->im_pci.pci_picmr0 = cpu_to_le32 (PICMR0_MASK_ATTRIB); /* Size & attribute */
  326. /* See above for description - puts PCI request as highest priority */
  327. #ifdef CONFIG_MPC8272
  328. immap->im_siu_conf.sc_ppc_alrh = 0x01236745;
  329. #else
  330. immap->im_siu_conf.sc_ppc_alrh = 0x03124567;
  331. #endif
  332. /* Park the bus on the PCI */
  333. immap->im_siu_conf.sc_ppc_acr = PPC_ACR_BUS_PARK_PCI;
  334. /* Host mode - specify the bridge as a host-PCI bridge */
  335. pci_hose_write_config_byte (hose, host_devno, PCI_CLASS_CODE,
  336. PCI_CLASS_BRIDGE_CTLR);
  337. /* Enable the host bridge to be a master on the PCI bus, and to act as a PCI memory target */
  338. pci_hose_read_config_word (hose, host_devno, PCI_COMMAND, &tempShort);
  339. pci_hose_write_config_word (hose, host_devno, PCI_COMMAND,
  340. tempShort | PCI_COMMAND_MASTER |
  341. PCI_COMMAND_MEMORY);
  342. /* do some bridge init, should be done on all 8260 based bridges */
  343. pci_hose_write_config_byte (hose, host_devno, PCI_CACHE_LINE_SIZE,
  344. 0x08);
  345. pci_hose_write_config_byte (hose, host_devno, PCI_LATENCY_TIMER,
  346. 0xF8);
  347. hose->first_busno = 0;
  348. hose->last_busno = 0xff;
  349. /* System memory space */
  350. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272 || defined CONFIG_PM826
  351. pci_set_region (hose->regions + 0,
  352. PCI_SLV_MEM_BUS,
  353. PCI_SLV_MEM_LOCAL,
  354. gd->ram_size, PCI_REGION_MEM | PCI_REGION_MEMORY);
  355. #else
  356. pci_set_region (hose->regions + 0,
  357. CONFIG_SYS_SDRAM_BASE,
  358. CONFIG_SYS_SDRAM_BASE,
  359. 0x4000000, PCI_REGION_MEM | PCI_REGION_MEMORY);
  360. #endif
  361. /* PCI memory space */
  362. #if defined CONFIG_MPC8266ADS || defined CONFIG_MPC8272
  363. pci_set_region (hose->regions + 1,
  364. PCI_MSTR_MEMIO_BUS,
  365. PCI_MSTR_MEMIO_LOCAL,
  366. PCI_MSTR_MEMIO_SIZE, PCI_REGION_MEM);
  367. #else
  368. pci_set_region (hose->regions + 1,
  369. PCI_MSTR_MEM_BUS,
  370. PCI_MSTR_MEM_LOCAL,
  371. PCI_MSTR_MEM_SIZE, PCI_REGION_MEM);
  372. #endif
  373. /* PCI I/O space */
  374. pci_set_region (hose->regions + 2,
  375. PCI_MSTR_IO_BUS,
  376. PCI_MSTR_IO_LOCAL, PCI_MSTR_IO_SIZE, PCI_REGION_IO);
  377. hose->region_count = 3;
  378. pci_register_hose (hose);
  379. /* Mask off master abort machine checks */
  380. immap->im_pci.pci_emr &= cpu_to_le32 (~PCI_ERROR_PCI_NO_RSP);
  381. eieio ();
  382. hose->last_busno = pci_hose_scan (hose);
  383. /* clear the error in the error status register */
  384. immap->im_pci.pci_esr = cpu_to_le32 (PCI_ERROR_PCI_NO_RSP);
  385. /* unmask master abort machine checks */
  386. immap->im_pci.pci_emr |= cpu_to_le32 (PCI_ERROR_PCI_NO_RSP);
  387. }
  388. #if defined(CONFIG_OF_LIBFDT)
  389. void ft_pci_setup(void *blob, bd_t *bd)
  390. {
  391. do_fixup_by_prop_u32(blob, "device_type", "pci", 4,
  392. "clock-frequency", gd->pci_clk, 1);
  393. }
  394. #endif
  395. #endif /* CONFIG_PCI */