44x_mmu.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Modifications by Matt Porter (mporter@mvista.com) to support
  3. * PPC44x Book E processors.
  4. *
  5. * This file contains the routines for initializing the MMU
  6. * on the 4xx series of chips.
  7. * -- paulus
  8. *
  9. * Derived from arch/ppc/mm/init.c:
  10. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  11. *
  12. * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
  13. * and Cort Dougan (PReP) (cort@cs.nmt.edu)
  14. * Copyright (C) 1996 Paul Mackerras
  15. *
  16. * Derived from "arch/i386/mm/init.c"
  17. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License
  21. * as published by the Free Software Foundation; either version
  22. * 2 of the License, or (at your option) any later version.
  23. *
  24. */
  25. #include <linux/init.h>
  26. #include <asm/mmu.h>
  27. #include <asm/system.h>
  28. #include <asm/page.h>
  29. #include <asm/cacheflush.h>
  30. #include "mmu_decl.h"
  31. /* Used by the 44x TLB replacement exception handler.
  32. * Just needed it declared someplace.
  33. */
  34. unsigned int tlb_44x_index; /* = 0 */
  35. unsigned int tlb_44x_hwater = PPC44x_TLB_SIZE - 1 - PPC44x_EARLY_TLBS;
  36. int icache_44x_need_flush;
  37. static void __init ppc44x_update_tlb_hwater(void)
  38. {
  39. extern unsigned int tlb_44x_patch_hwater_D[];
  40. extern unsigned int tlb_44x_patch_hwater_I[];
  41. /* The TLB miss handlers hard codes the watermark in a cmpli
  42. * instruction to improve performances rather than loading it
  43. * from the global variable. Thus, we patch the instructions
  44. * in the 2 TLB miss handlers when updating the value
  45. */
  46. tlb_44x_patch_hwater_D[0] = (tlb_44x_patch_hwater_D[0] & 0xffff0000) |
  47. tlb_44x_hwater;
  48. flush_icache_range((unsigned long)&tlb_44x_patch_hwater_D[0],
  49. (unsigned long)&tlb_44x_patch_hwater_D[1]);
  50. tlb_44x_patch_hwater_I[0] = (tlb_44x_patch_hwater_I[0] & 0xffff0000) |
  51. tlb_44x_hwater;
  52. flush_icache_range((unsigned long)&tlb_44x_patch_hwater_I[0],
  53. (unsigned long)&tlb_44x_patch_hwater_I[1]);
  54. }
  55. /*
  56. * "Pins" a 256MB TLB entry in AS0 for kernel lowmem
  57. */
  58. static void __init ppc44x_pin_tlb(unsigned int virt, unsigned int phys)
  59. {
  60. unsigned int entry = tlb_44x_hwater--;
  61. ppc44x_update_tlb_hwater();
  62. __asm__ __volatile__(
  63. "tlbwe %2,%3,%4\n"
  64. "tlbwe %1,%3,%5\n"
  65. "tlbwe %0,%3,%6\n"
  66. :
  67. : "r" (PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G),
  68. "r" (phys),
  69. "r" (virt | PPC44x_TLB_VALID | PPC44x_TLB_256M),
  70. "r" (entry),
  71. "i" (PPC44x_TLB_PAGEID),
  72. "i" (PPC44x_TLB_XLAT),
  73. "i" (PPC44x_TLB_ATTRIB));
  74. }
  75. void __init MMU_init_hw(void)
  76. {
  77. ppc44x_update_tlb_hwater();
  78. flush_instruction_cache();
  79. }
  80. unsigned long __init mmu_mapin_ram(void)
  81. {
  82. unsigned long addr;
  83. /* Pin in enough TLBs to cover any lowmem not covered by the
  84. * initial 256M mapping established in head_44x.S */
  85. for (addr = PPC_PIN_SIZE; addr < lowmem_end_addr;
  86. addr += PPC_PIN_SIZE)
  87. ppc44x_pin_tlb(addr + PAGE_OFFSET, addr);
  88. return total_lowmem;
  89. }