ip22-mc.c 5.9 KB

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