addr-map.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * arch/arm/mach-orion/addr-map.c
  3. *
  4. * Address map functions for Marvell Orion System On Chip
  5. *
  6. * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/mbus.h>
  15. #include <asm/hardware.h>
  16. #include "common.h"
  17. /*
  18. * The Orion has fully programable address map. There's a separate address
  19. * map for each of the device _master_ interfaces, e.g. CPU, PCI, PCIE, USB,
  20. * Gigabit Ethernet, DMA/XOR engines, etc. Each interface has its own
  21. * address decode windows that allow it to access any of the Orion resources.
  22. *
  23. * CPU address decoding --
  24. * Linux assumes that it is the boot loader that already setup the access to
  25. * DDR and internal registers.
  26. * Setup access to PCI and PCI-E IO/MEM space is issued by core.c.
  27. * Setup access to various devices located on the device bus interface (e.g.
  28. * flashes, RTC, etc) should be issued by machine-setup.c according to
  29. * specific board population (by using orion_setup_cpu_win()).
  30. *
  31. * Non-CPU Masters address decoding --
  32. * Unlike the CPU, we setup the access from Orion's master interfaces to DDR
  33. * banks only (the typical use case).
  34. * Setup access for each master to DDR is issued by common.c.
  35. *
  36. * Note: although orion_setbits() and orion_clrbits() are not atomic
  37. * no locking is necessary here since code in this file is only called
  38. * at boot time when there is no concurrency issues.
  39. */
  40. /*
  41. * Generic Address Decode Windows bit settings
  42. */
  43. #define TARGET_DDR 0
  44. #define TARGET_PCI 3
  45. #define TARGET_PCIE 4
  46. #define TARGET_DEV_BUS 1
  47. #define ATTR_DDR_CS(n) (((n) ==0) ? 0xe : \
  48. ((n) == 1) ? 0xd : \
  49. ((n) == 2) ? 0xb : \
  50. ((n) == 3) ? 0x7 : 0xf)
  51. #define ATTR_PCIE_MEM 0x59
  52. #define ATTR_PCIE_IO 0x51
  53. #define ATTR_PCI_MEM 0x59
  54. #define ATTR_PCI_IO 0x51
  55. #define ATTR_DEV_CS0 0x1e
  56. #define ATTR_DEV_CS1 0x1d
  57. #define ATTR_DEV_CS2 0x1b
  58. #define ATTR_DEV_BOOT 0xf
  59. #define WIN_EN 1
  60. /*
  61. * Helpers to get DDR banks info
  62. */
  63. #define DDR_BASE_CS(n) ORION_DDR_REG(0x1500 + ((n) * 8))
  64. #define DDR_SIZE_CS(n) ORION_DDR_REG(0x1504 + ((n) * 8))
  65. #define DDR_MAX_CS 4
  66. #define DDR_REG_TO_SIZE(reg) (((reg) | 0xffffff) + 1)
  67. #define DDR_REG_TO_BASE(reg) ((reg) & 0xff000000)
  68. #define DDR_BANK_EN 1
  69. /*
  70. * CPU Address Decode Windows registers
  71. */
  72. #define CPU_WIN_CTRL(n) ORION_BRIDGE_REG(0x000 | ((n) << 4))
  73. #define CPU_WIN_BASE(n) ORION_BRIDGE_REG(0x004 | ((n) << 4))
  74. #define CPU_WIN_REMAP_LO(n) ORION_BRIDGE_REG(0x008 | ((n) << 4))
  75. #define CPU_WIN_REMAP_HI(n) ORION_BRIDGE_REG(0x00c | ((n) << 4))
  76. #define CPU_MAX_WIN 8
  77. /*
  78. * Use this CPU address decode windows allocation
  79. */
  80. #define CPU_WIN_PCIE_IO 0
  81. #define CPU_WIN_PCI_IO 1
  82. #define CPU_WIN_PCIE_MEM 2
  83. #define CPU_WIN_PCI_MEM 3
  84. #define CPU_WIN_DEV_BOOT 4
  85. #define CPU_WIN_DEV_CS0 5
  86. #define CPU_WIN_DEV_CS1 6
  87. #define CPU_WIN_DEV_CS2 7
  88. /*
  89. * Gigabit Ethernet Address Decode Windows registers
  90. */
  91. #define ETH_WIN_BASE(win) ORION_ETH_REG(0x200 + ((win) * 8))
  92. #define ETH_WIN_SIZE(win) ORION_ETH_REG(0x204 + ((win) * 8))
  93. #define ETH_WIN_REMAP(win) ORION_ETH_REG(0x280 + ((win) * 4))
  94. #define ETH_WIN_EN ORION_ETH_REG(0x290)
  95. #define ETH_WIN_PROT ORION_ETH_REG(0x294)
  96. #define ETH_MAX_WIN 6
  97. #define ETH_MAX_REMAP_WIN 4
  98. /*
  99. * SATA Address Decode Windows registers
  100. */
  101. #define SATA_WIN_CTRL(win) ORION_SATA_REG(0x30 + ((win) * 0x10))
  102. #define SATA_WIN_BASE(win) ORION_SATA_REG(0x34 + ((win) * 0x10))
  103. #define SATA_MAX_WIN 4
  104. struct mbus_dram_target_info orion_mbus_dram_info;
  105. static int __init orion_cpu_win_can_remap(u32 win)
  106. {
  107. u32 dev, rev;
  108. orion_pcie_id(&dev, &rev);
  109. if ((dev == MV88F5281_DEV_ID && win < 4)
  110. || (dev == MV88F5182_DEV_ID && win < 2)
  111. || (dev == MV88F5181_DEV_ID && win < 2))
  112. return 1;
  113. return 0;
  114. }
  115. void __init orion_setup_cpu_win(enum orion_target target, u32 base, u32 size, int remap)
  116. {
  117. u32 win, attr, ctrl;
  118. switch (target) {
  119. case ORION_PCIE_IO:
  120. target = TARGET_PCIE;
  121. attr = ATTR_PCIE_IO;
  122. win = CPU_WIN_PCIE_IO;
  123. break;
  124. case ORION_PCI_IO:
  125. target = TARGET_PCI;
  126. attr = ATTR_PCI_IO;
  127. win = CPU_WIN_PCI_IO;
  128. break;
  129. case ORION_PCIE_MEM:
  130. target = TARGET_PCIE;
  131. attr = ATTR_PCIE_MEM;
  132. win = CPU_WIN_PCIE_MEM;
  133. break;
  134. case ORION_PCI_MEM:
  135. target = TARGET_PCI;
  136. attr = ATTR_PCI_MEM;
  137. win = CPU_WIN_PCI_MEM;
  138. break;
  139. case ORION_DEV_BOOT:
  140. target = TARGET_DEV_BUS;
  141. attr = ATTR_DEV_BOOT;
  142. win = CPU_WIN_DEV_BOOT;
  143. break;
  144. case ORION_DEV0:
  145. target = TARGET_DEV_BUS;
  146. attr = ATTR_DEV_CS0;
  147. win = CPU_WIN_DEV_CS0;
  148. break;
  149. case ORION_DEV1:
  150. target = TARGET_DEV_BUS;
  151. attr = ATTR_DEV_CS1;
  152. win = CPU_WIN_DEV_CS1;
  153. break;
  154. case ORION_DEV2:
  155. target = TARGET_DEV_BUS;
  156. attr = ATTR_DEV_CS2;
  157. win = CPU_WIN_DEV_CS2;
  158. break;
  159. case ORION_DDR:
  160. case ORION_REGS:
  161. /*
  162. * Must be mapped by bootloader.
  163. */
  164. default:
  165. target = attr = win = -1;
  166. BUG();
  167. }
  168. base &= 0xffff0000;
  169. ctrl = (((size - 1) & 0xffff0000) | (attr << 8) |
  170. (target << 4) | WIN_EN);
  171. orion_write(CPU_WIN_BASE(win), base);
  172. orion_write(CPU_WIN_CTRL(win), ctrl);
  173. if (orion_cpu_win_can_remap(win)) {
  174. if (remap >= 0) {
  175. orion_write(CPU_WIN_REMAP_LO(win), remap & 0xffff0000);
  176. orion_write(CPU_WIN_REMAP_HI(win), 0);
  177. } else {
  178. orion_write(CPU_WIN_REMAP_LO(win), base);
  179. orion_write(CPU_WIN_REMAP_HI(win), 0);
  180. }
  181. }
  182. }
  183. void __init orion_setup_cpu_wins(void)
  184. {
  185. int i;
  186. int cs;
  187. /*
  188. * First, disable and clear windows
  189. */
  190. for (i = 0; i < CPU_MAX_WIN; i++) {
  191. orion_write(CPU_WIN_BASE(i), 0);
  192. orion_write(CPU_WIN_CTRL(i), 0);
  193. if (orion_cpu_win_can_remap(i)) {
  194. orion_write(CPU_WIN_REMAP_LO(i), 0);
  195. orion_write(CPU_WIN_REMAP_HI(i), 0);
  196. }
  197. }
  198. /*
  199. * Setup windows for PCI+PCIe IO+MEM space.
  200. */
  201. orion_setup_cpu_win(ORION_PCIE_IO, ORION_PCIE_IO_PHYS_BASE,
  202. ORION_PCIE_IO_SIZE, ORION_PCIE_IO_BUS_BASE);
  203. orion_setup_cpu_win(ORION_PCI_IO, ORION_PCI_IO_PHYS_BASE,
  204. ORION_PCI_IO_SIZE, ORION_PCI_IO_BUS_BASE);
  205. orion_setup_cpu_win(ORION_PCIE_MEM, ORION_PCIE_MEM_PHYS_BASE,
  206. ORION_PCIE_MEM_SIZE, -1);
  207. orion_setup_cpu_win(ORION_PCI_MEM, ORION_PCI_MEM_PHYS_BASE,
  208. ORION_PCI_MEM_SIZE, -1);
  209. /*
  210. * Setup MBUS dram target info.
  211. */
  212. orion_mbus_dram_info.mbus_dram_target_id = TARGET_DDR;
  213. for (i = 0, cs = 0; i < 4; i++) {
  214. u32 base = readl(DDR_BASE_CS(i));
  215. u32 size = readl(DDR_SIZE_CS(i));
  216. /*
  217. * Chip select enabled?
  218. */
  219. if (size & 1) {
  220. struct mbus_dram_window *w;
  221. w = &orion_mbus_dram_info.cs[cs++];
  222. w->cs_index = i;
  223. w->mbus_attr = 0xf & ~(1 << i);
  224. w->base = base & 0xff000000;
  225. w->size = (size | 0x00ffffff) + 1;
  226. }
  227. }
  228. orion_mbus_dram_info.num_cs = cs;
  229. }
  230. void __init orion_setup_eth_wins(void)
  231. {
  232. int i;
  233. /*
  234. * First, disable and clear windows
  235. */
  236. for (i = 0; i < ETH_MAX_WIN; i++) {
  237. orion_write(ETH_WIN_BASE(i), 0);
  238. orion_write(ETH_WIN_SIZE(i), 0);
  239. orion_setbits(ETH_WIN_EN, 1 << i);
  240. orion_clrbits(ETH_WIN_PROT, 0x3 << (i * 2));
  241. if (i < ETH_MAX_REMAP_WIN)
  242. orion_write(ETH_WIN_REMAP(i), 0);
  243. }
  244. /*
  245. * Setup windows for DDR banks.
  246. */
  247. for (i = 0; i < DDR_MAX_CS; i++) {
  248. u32 base, size;
  249. size = orion_read(DDR_SIZE_CS(i));
  250. base = orion_read(DDR_BASE_CS(i));
  251. if (size & DDR_BANK_EN) {
  252. base = DDR_REG_TO_BASE(base);
  253. size = DDR_REG_TO_SIZE(size);
  254. orion_write(ETH_WIN_SIZE(i), (size-1) & 0xffff0000);
  255. orion_write(ETH_WIN_BASE(i), (base & 0xffff0000) |
  256. (ATTR_DDR_CS(i) << 8) |
  257. TARGET_DDR);
  258. orion_clrbits(ETH_WIN_EN, 1 << i);
  259. orion_setbits(ETH_WIN_PROT, 0x3 << (i * 2));
  260. }
  261. }
  262. }
  263. void __init orion_setup_sata_wins(void)
  264. {
  265. int i;
  266. /*
  267. * First, disable and clear windows
  268. */
  269. for (i = 0; i < SATA_MAX_WIN; i++) {
  270. orion_write(SATA_WIN_BASE(i), 0);
  271. orion_write(SATA_WIN_CTRL(i), 0);
  272. }
  273. /*
  274. * Setup windows for DDR banks.
  275. */
  276. for (i = 0; i < DDR_MAX_CS; i++) {
  277. u32 base, size;
  278. size = orion_read(DDR_SIZE_CS(i));
  279. base = orion_read(DDR_BASE_CS(i));
  280. if (size & DDR_BANK_EN) {
  281. base = DDR_REG_TO_BASE(base);
  282. size = DDR_REG_TO_SIZE(size);
  283. orion_write(SATA_WIN_CTRL(i),
  284. ((size-1) & 0xffff0000) |
  285. (ATTR_DDR_CS(i) << 8) |
  286. (TARGET_DDR << 4) | WIN_EN);
  287. orion_write(SATA_WIN_BASE(i),
  288. base & 0xffff0000);
  289. }
  290. }
  291. }