ip22-mc.c 6.6 KB

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