ip22-mc.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * ip22-mc.c: Routines for manipulating SGI Memory Controller.
  3. *
  4. * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
  5. * Copyright (C) 1999 Andrew R. Baker (andrewb@uab.edu) - Indigo2 changes
  6. * Copyright (C) 2003 Ladislav Michl (ladis@linux-mips.org)
  7. * Copyright (C) 2004 Peter Fuerst (pf@net.alphadv.de) - IP28
  8. */
  9. #include <linux/init.h>
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <asm/io.h>
  13. #include <asm/bootinfo.h>
  14. #include <asm/sgialib.h>
  15. #include <asm/sgi/mc.h>
  16. #include <asm/sgi/hpc3.h>
  17. #include <asm/sgi/ip22.h>
  18. struct sgimc_regs *sgimc;
  19. EXPORT_SYMBOL(sgimc);
  20. static inline unsigned long get_bank_addr(unsigned int memconfig)
  21. {
  22. return ((memconfig & SGIMC_MCONFIG_BASEADDR) <<
  23. ((sgimc->systemid & SGIMC_SYSID_MASKREV) >= 5 ? 24 : 22));
  24. }
  25. static inline unsigned long get_bank_size(unsigned int memconfig)
  26. {
  27. return ((memconfig & SGIMC_MCONFIG_RMASK) + 0x0100) <<
  28. ((sgimc->systemid & SGIMC_SYSID_MASKREV) >= 5 ? 16 : 14);
  29. }
  30. static inline unsigned int get_bank_config(int bank)
  31. {
  32. unsigned int res = bank > 1 ? sgimc->mconfig1 : sgimc->mconfig0;
  33. return bank % 2 ? res & 0xffff : res >> 16;
  34. }
  35. struct mem {
  36. unsigned long addr;
  37. unsigned long size;
  38. };
  39. /*
  40. * Detect installed memory, do some sanity checks and notify kernel about it
  41. */
  42. static void __init probe_memory(void)
  43. {
  44. int i, j, found, cnt = 0;
  45. struct mem bank[4];
  46. struct mem space[2] = {{SGIMC_SEG0_BADDR, 0}, {SGIMC_SEG1_BADDR, 0}};
  47. printk(KERN_INFO "MC: Probing memory configuration:\n");
  48. for (i = 0; i < ARRAY_SIZE(bank); i++) {
  49. unsigned int tmp = get_bank_config(i);
  50. if (!(tmp & SGIMC_MCONFIG_BVALID))
  51. continue;
  52. bank[cnt].size = get_bank_size(tmp);
  53. bank[cnt].addr = get_bank_addr(tmp);
  54. printk(KERN_INFO " bank%d: %3ldM @ %08lx\n",
  55. i, bank[cnt].size / 1024 / 1024, bank[cnt].addr);
  56. cnt++;
  57. }
  58. /* And you thought bubble sort is dead algorithm... */
  59. do {
  60. unsigned long addr, size;
  61. found = 0;
  62. for (i = 1; i < cnt; i++)
  63. if (bank[i-1].addr > bank[i].addr) {
  64. addr = bank[i].addr;
  65. size = bank[i].size;
  66. bank[i].addr = bank[i-1].addr;
  67. bank[i].size = bank[i-1].size;
  68. bank[i-1].addr = addr;
  69. bank[i-1].size = size;
  70. found = 1;
  71. }
  72. } while (found);
  73. /* Figure out how are memory banks mapped into spaces */
  74. for (i = 0; i < cnt; i++) {
  75. found = 0;
  76. for (j = 0; j < ARRAY_SIZE(space) && !found; j++)
  77. if (space[j].addr + space[j].size == bank[i].addr) {
  78. space[j].size += bank[i].size;
  79. found = 1;
  80. }
  81. /* There is either hole or overlapping memory */
  82. if (!found)
  83. printk(KERN_CRIT "MC: Memory configuration mismatch "
  84. "(%08lx), expect Bus Error soon\n",
  85. bank[i].addr);
  86. }
  87. for (i = 0; i < ARRAY_SIZE(space); i++)
  88. if (space[i].size)
  89. add_memory_region(space[i].addr, space[i].size,
  90. BOOT_MEM_RAM);
  91. }
  92. void __init sgimc_init(void)
  93. {
  94. u32 tmp;
  95. /* ioremap can't fail */
  96. sgimc = (struct sgimc_regs *)
  97. ioremap(SGIMC_BASE, sizeof(struct sgimc_regs));
  98. printk(KERN_INFO "MC: SGI memory controller Revision %d\n",
  99. (int) sgimc->systemid & SGIMC_SYSID_MASKREV);
  100. /* Place the MC into a known state. This must be done before
  101. * interrupts are first enabled etc.
  102. */
  103. /* Step 0: Make sure we turn off the watchdog in case it's
  104. * still running (which might be the case after a
  105. * soft reboot).
  106. */
  107. tmp = sgimc->cpuctrl0;
  108. tmp &= ~SGIMC_CCTRL0_WDOG;
  109. sgimc->cpuctrl0 = tmp;
  110. /* Step 1: The CPU/GIO error status registers will not latch
  111. * up a new error status until the register has been
  112. * cleared by the cpu. These status registers are
  113. * cleared by writing any value to them.
  114. */
  115. sgimc->cstat = sgimc->gstat = 0;
  116. /* Step 2: Enable all parity checking in cpu control register
  117. * zero.
  118. */
  119. /* don't touch parity settings for IP28 */
  120. tmp = sgimc->cpuctrl0;
  121. #ifndef CONFIG_SGI_IP28
  122. tmp |= SGIMC_CCTRL0_EPERRGIO | SGIMC_CCTRL0_EPERRMEM;
  123. #endif
  124. tmp |= SGIMC_CCTRL0_R4KNOCHKPARR;
  125. sgimc->cpuctrl0 = tmp;
  126. /* Step 3: Setup the MC write buffer depth, this is controlled
  127. * in cpu control register 1 in the lower 4 bits.
  128. */
  129. tmp = sgimc->cpuctrl1;
  130. tmp &= ~0xf;
  131. tmp |= 0xd;
  132. sgimc->cpuctrl1 = tmp;
  133. /* Step 4: Initialize the RPSS divider register to run as fast
  134. * as it can correctly operate. The register is laid
  135. * out as follows:
  136. *
  137. * ----------------------------------------
  138. * | RESERVED | INCREMENT | DIVIDER |
  139. * ----------------------------------------
  140. * 31 16 15 8 7 0
  141. *
  142. * DIVIDER determines how often a 'tick' happens,
  143. * INCREMENT determines by how the RPSS increment
  144. * registers value increases at each 'tick'. Thus,
  145. * for IP22 we get INCREMENT=1, DIVIDER=1 == 0x101
  146. */
  147. sgimc->divider = 0x101;
  148. /* Step 5: Initialize GIO64 arbitrator configuration register.
  149. *
  150. * NOTE: HPC init code in sgihpc_init() must run before us because
  151. * we need to know Guiness vs. FullHouse and the board
  152. * revision on this machine. You have been warned.
  153. */
  154. /* First the basic invariants across all GIO64 implementations. */
  155. tmp = sgimc->giopar & SGIMC_GIOPAR_GFX64; /* keep gfx 64bit settings */
  156. tmp |= SGIMC_GIOPAR_HPC64; /* All 1st HPC's interface at 64bits */
  157. tmp |= SGIMC_GIOPAR_ONEBUS; /* Only one physical GIO bus exists */
  158. if (ip22_is_fullhouse()) {
  159. /* Fullhouse specific settings. */
  160. if (SGIOC_SYSID_BOARDREV(sgioc->sysid) < 2) {
  161. tmp |= SGIMC_GIOPAR_HPC264; /* 2nd HPC at 64bits */
  162. tmp |= SGIMC_GIOPAR_PLINEEXP0; /* exp0 pipelines */
  163. tmp |= SGIMC_GIOPAR_MASTEREXP1; /* exp1 masters */
  164. tmp |= SGIMC_GIOPAR_RTIMEEXP0; /* exp0 is realtime */
  165. } else {
  166. tmp |= SGIMC_GIOPAR_HPC264; /* 2nd HPC 64bits */
  167. tmp |= SGIMC_GIOPAR_PLINEEXP0; /* exp[01] pipelined */
  168. tmp |= SGIMC_GIOPAR_PLINEEXP1;
  169. tmp |= SGIMC_GIOPAR_MASTEREISA; /* EISA masters */
  170. }
  171. } else {
  172. /* Guiness specific settings. */
  173. tmp |= SGIMC_GIOPAR_EISA64; /* MC talks to EISA at 64bits */
  174. tmp |= SGIMC_GIOPAR_MASTEREISA; /* EISA bus can act as master */
  175. }
  176. sgimc->giopar = tmp; /* poof */
  177. probe_memory();
  178. }
  179. void __init prom_meminit(void) {}
  180. void __init prom_free_prom_memory(void)
  181. {
  182. #ifdef CONFIG_SGI_IP28
  183. u32 mconfig1;
  184. unsigned long flags;
  185. spinlock_t lock;
  186. /*
  187. * because ARCS accesses memory uncached we wait until ARCS
  188. * isn't needed any longer, before we switch from slow to
  189. * normal mode
  190. */
  191. spin_lock_irqsave(&lock, flags);
  192. mconfig1 = sgimc->mconfig1;
  193. /* map ECC register */
  194. sgimc->mconfig1 = (mconfig1 & 0xffff0000) | 0x2060;
  195. iob();
  196. /* switch to normal mode */
  197. *(unsigned long *)PHYS_TO_XKSEG_UNCACHED(0x60000000) = 0;
  198. iob();
  199. /* reduce WR_COL */
  200. sgimc->cmacc = (sgimc->cmacc & ~0xf) | 4;
  201. iob();
  202. /* restore old config */
  203. sgimc->mconfig1 = mconfig1;
  204. iob();
  205. spin_unlock_irqrestore(&lock, flags);
  206. #endif
  207. }