pci.c 11 KB

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