addr-map.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * arch/arm/mach-mv78xx0/addr-map.c
  3. *
  4. * Address map functions for Marvell MV78xx0 SoCs
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/mbus.h>
  13. #include <linux/io.h>
  14. #include "common.h"
  15. /*
  16. * Generic Address Decode Windows bit settings
  17. */
  18. #define TARGET_DDR 0
  19. #define TARGET_DEV_BUS 1
  20. #define TARGET_PCIE0 4
  21. #define TARGET_PCIE1 8
  22. #define TARGET_PCIE(i) ((i) ? TARGET_PCIE1 : TARGET_PCIE0)
  23. #define ATTR_DEV_SPI_ROM 0x1f
  24. #define ATTR_DEV_BOOT 0x2f
  25. #define ATTR_DEV_CS3 0x37
  26. #define ATTR_DEV_CS2 0x3b
  27. #define ATTR_DEV_CS1 0x3d
  28. #define ATTR_DEV_CS0 0x3e
  29. #define ATTR_PCIE_IO(l) (0xf0 & ~(0x10 << (l)))
  30. #define ATTR_PCIE_MEM(l) (0xf8 & ~(0x10 << (l)))
  31. /*
  32. * Helpers to get DDR bank info
  33. */
  34. #define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3))
  35. #define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3))
  36. /*
  37. * CPU Address Decode Windows registers
  38. */
  39. #define WIN0_OFF(n) (BRIDGE_VIRT_BASE + 0x0000 + ((n) << 4))
  40. #define WIN8_OFF(n) (BRIDGE_VIRT_BASE + 0x0900 + (((n) - 8) << 4))
  41. #define WIN_CTRL_OFF 0x0000
  42. #define WIN_BASE_OFF 0x0004
  43. #define WIN_REMAP_LO_OFF 0x0008
  44. #define WIN_REMAP_HI_OFF 0x000c
  45. struct mbus_dram_target_info mv78xx0_mbus_dram_info;
  46. static void __init __iomem *win_cfg_base(int win)
  47. {
  48. /*
  49. * Find the control register base address for this window.
  50. *
  51. * BRIDGE_VIRT_BASE points to the right (CPU0's or CPU1's)
  52. * MBUS bridge depending on which CPU core we're running on,
  53. * so we don't need to take that into account here.
  54. */
  55. return (void __iomem *)((win < 8) ? WIN0_OFF(win) : WIN8_OFF(win));
  56. }
  57. static int __init cpu_win_can_remap(int win)
  58. {
  59. if (win < 8)
  60. return 1;
  61. return 0;
  62. }
  63. static void __init setup_cpu_win(int win, u32 base, u32 size,
  64. u8 target, u8 attr, int remap)
  65. {
  66. void __iomem *addr = win_cfg_base(win);
  67. u32 ctrl;
  68. base &= 0xffff0000;
  69. ctrl = ((size - 1) & 0xffff0000) | (attr << 8) | (target << 4) | 1;
  70. writel(base, addr + WIN_BASE_OFF);
  71. writel(ctrl, addr + WIN_CTRL_OFF);
  72. if (cpu_win_can_remap(win)) {
  73. if (remap < 0)
  74. remap = base;
  75. writel(remap & 0xffff0000, addr + WIN_REMAP_LO_OFF);
  76. writel(0, addr + WIN_REMAP_HI_OFF);
  77. }
  78. }
  79. void __init mv78xx0_setup_cpu_mbus(void)
  80. {
  81. void __iomem *addr;
  82. int i;
  83. int cs;
  84. /*
  85. * First, disable and clear windows.
  86. */
  87. for (i = 0; i < 14; i++) {
  88. addr = win_cfg_base(i);
  89. writel(0, addr + WIN_BASE_OFF);
  90. writel(0, addr + WIN_CTRL_OFF);
  91. if (cpu_win_can_remap(i)) {
  92. writel(0, addr + WIN_REMAP_LO_OFF);
  93. writel(0, addr + WIN_REMAP_HI_OFF);
  94. }
  95. }
  96. /*
  97. * Setup MBUS dram target info.
  98. */
  99. mv78xx0_mbus_dram_info.mbus_dram_target_id = TARGET_DDR;
  100. if (mv78xx0_core_index() == 0)
  101. addr = (void __iomem *)DDR_WINDOW_CPU0_BASE;
  102. else
  103. addr = (void __iomem *)DDR_WINDOW_CPU1_BASE;
  104. for (i = 0, cs = 0; i < 4; i++) {
  105. u32 base = readl(addr + DDR_BASE_CS_OFF(i));
  106. u32 size = readl(addr + DDR_SIZE_CS_OFF(i));
  107. /*
  108. * Chip select enabled?
  109. */
  110. if (size & 1) {
  111. struct mbus_dram_window *w;
  112. w = &mv78xx0_mbus_dram_info.cs[cs++];
  113. w->cs_index = i;
  114. w->mbus_attr = 0xf & ~(1 << i);
  115. w->base = base & 0xffff0000;
  116. w->size = (size | 0x0000ffff) + 1;
  117. }
  118. }
  119. mv78xx0_mbus_dram_info.num_cs = cs;
  120. }
  121. void __init mv78xx0_setup_pcie_io_win(int window, u32 base, u32 size,
  122. int maj, int min)
  123. {
  124. setup_cpu_win(window, base, size, TARGET_PCIE(maj),
  125. ATTR_PCIE_IO(min), -1);
  126. }
  127. void __init mv78xx0_setup_pcie_mem_win(int window, u32 base, u32 size,
  128. int maj, int min)
  129. {
  130. setup_cpu_win(window, base, size, TARGET_PCIE(maj),
  131. ATTR_PCIE_MEM(min), -1);
  132. }