pci.c 13 KB

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