44x_mmu.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. * Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk).
  16. *
  17. * Derived from "arch/i386/mm/init.c"
  18. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  19. *
  20. * This program is free software; you can redistribute it and/or
  21. * modify it under the terms of the GNU General Public License
  22. * as published by the Free Software Foundation; either version
  23. * 2 of the License, or (at your option) any later version.
  24. *
  25. */
  26. #include <linux/config.h>
  27. #include <linux/signal.h>
  28. #include <linux/sched.h>
  29. #include <linux/kernel.h>
  30. #include <linux/errno.h>
  31. #include <linux/string.h>
  32. #include <linux/types.h>
  33. #include <linux/ptrace.h>
  34. #include <linux/mman.h>
  35. #include <linux/mm.h>
  36. #include <linux/swap.h>
  37. #include <linux/stddef.h>
  38. #include <linux/vmalloc.h>
  39. #include <linux/init.h>
  40. #include <linux/delay.h>
  41. #include <linux/highmem.h>
  42. #include <asm/pgalloc.h>
  43. #include <asm/prom.h>
  44. #include <asm/io.h>
  45. #include <asm/mmu_context.h>
  46. #include <asm/pgtable.h>
  47. #include <asm/mmu.h>
  48. #include <asm/uaccess.h>
  49. #include <asm/smp.h>
  50. #include <asm/bootx.h>
  51. #include <asm/machdep.h>
  52. #include <asm/setup.h>
  53. #include "mmu_decl.h"
  54. extern char etext[], _stext[];
  55. /* Used by the 44x TLB replacement exception handler.
  56. * Just needed it declared someplace.
  57. */
  58. unsigned int tlb_44x_index = 0;
  59. unsigned int tlb_44x_hwater = 62;
  60. /*
  61. * "Pins" a 256MB TLB entry in AS0 for kernel lowmem
  62. */
  63. static void __init
  64. ppc44x_pin_tlb(int slot, unsigned int virt, unsigned int phys)
  65. {
  66. unsigned long attrib = 0;
  67. __asm__ __volatile__("\
  68. clrrwi %2,%2,10\n\
  69. ori %2,%2,%4\n\
  70. clrrwi %1,%1,10\n\
  71. li %0,0\n\
  72. ori %0,%0,%5\n\
  73. tlbwe %2,%3,%6\n\
  74. tlbwe %1,%3,%7\n\
  75. tlbwe %0,%3,%8"
  76. :
  77. : "r" (attrib), "r" (phys), "r" (virt), "r" (slot),
  78. "i" (PPC44x_TLB_VALID | PPC44x_TLB_256M),
  79. "i" (PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G),
  80. "i" (PPC44x_TLB_PAGEID),
  81. "i" (PPC44x_TLB_XLAT),
  82. "i" (PPC44x_TLB_ATTRIB));
  83. }
  84. /*
  85. * MMU_init_hw does the chip-specific initialization of the MMU hardware.
  86. */
  87. void __init MMU_init_hw(void)
  88. {
  89. flush_instruction_cache();
  90. }
  91. unsigned long __init mmu_mapin_ram(void)
  92. {
  93. unsigned int pinned_tlbs = 1;
  94. int i;
  95. /* Determine number of entries necessary to cover lowmem */
  96. pinned_tlbs = (unsigned int)
  97. (_ALIGN(total_lowmem, PPC44x_PIN_SIZE) >> PPC44x_PIN_SHIFT);
  98. /* Write upper watermark to save location */
  99. tlb_44x_hwater = PPC44x_LOW_SLOT - pinned_tlbs;
  100. /* If necessary, set additional pinned TLBs */
  101. if (pinned_tlbs > 1)
  102. for (i = (PPC44x_LOW_SLOT-(pinned_tlbs-1)); i < PPC44x_LOW_SLOT; i++) {
  103. unsigned int phys_addr = (PPC44x_LOW_SLOT-i) * PPC44x_PIN_SIZE;
  104. ppc44x_pin_tlb(i, phys_addr+PAGE_OFFSET, phys_addr);
  105. }
  106. return total_lowmem;
  107. }