ip22-mc.c 5.7 KB

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