4xx_mmu.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * This file contains the routines for initializing the MMU
  3. * on the 4xx series of chips.
  4. * -- paulus
  5. *
  6. * Derived from arch/ppc/mm/init.c:
  7. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  8. *
  9. * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
  10. * and Cort Dougan (PReP) (cort@cs.nmt.edu)
  11. * Copyright (C) 1996 Paul Mackerras
  12. * Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk).
  13. *
  14. * Derived from "arch/i386/mm/init.c"
  15. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License
  19. * as published by the Free Software Foundation; either version
  20. * 2 of the License, or (at your option) any later version.
  21. *
  22. */
  23. #include <linux/signal.h>
  24. #include <linux/sched.h>
  25. #include <linux/kernel.h>
  26. #include <linux/errno.h>
  27. #include <linux/string.h>
  28. #include <linux/types.h>
  29. #include <linux/ptrace.h>
  30. #include <linux/mman.h>
  31. #include <linux/mm.h>
  32. #include <linux/swap.h>
  33. #include <linux/stddef.h>
  34. #include <linux/vmalloc.h>
  35. #include <linux/init.h>
  36. #include <linux/delay.h>
  37. #include <linux/highmem.h>
  38. #include <asm/pgalloc.h>
  39. #include <asm/prom.h>
  40. #include <asm/io.h>
  41. #include <asm/mmu_context.h>
  42. #include <asm/pgtable.h>
  43. #include <asm/mmu.h>
  44. #include <asm/uaccess.h>
  45. #include <asm/smp.h>
  46. #include <asm/bootx.h>
  47. #include <asm/machdep.h>
  48. #include <asm/setup.h>
  49. #include "mmu_decl.h"
  50. extern int __map_without_ltlbs;
  51. /*
  52. * MMU_init_hw does the chip-specific initialization of the MMU hardware.
  53. */
  54. void __init MMU_init_hw(void)
  55. {
  56. /*
  57. * The Zone Protection Register (ZPR) defines how protection will
  58. * be applied to every page which is a member of a given zone. At
  59. * present, we utilize only two of the 4xx's zones.
  60. * The zone index bits (of ZSEL) in the PTE are used for software
  61. * indicators, except the LSB. For user access, zone 1 is used,
  62. * for kernel access, zone 0 is used. We set all but zone 1
  63. * to zero, allowing only kernel access as indicated in the PTE.
  64. * For zone 1, we set a 01 binary (a value of 10 will not work)
  65. * to allow user access as indicated in the PTE. This also allows
  66. * kernel access as indicated in the PTE.
  67. */
  68. mtspr(SPRN_ZPR, 0x10000000);
  69. flush_instruction_cache();
  70. /*
  71. * Set up the real-mode cache parameters for the exception vector
  72. * handlers (which are run in real-mode).
  73. */
  74. mtspr(SPRN_DCWR, 0x00000000); /* All caching is write-back */
  75. /*
  76. * Cache instruction and data space where the exception
  77. * vectors and the kernel live in real-mode.
  78. */
  79. mtspr(SPRN_DCCR, 0xF0000000); /* 512 MB of data space at 0x0. */
  80. mtspr(SPRN_ICCR, 0xF0000000); /* 512 MB of instr. space at 0x0. */
  81. }
  82. #define LARGE_PAGE_SIZE_16M (1<<24)
  83. #define LARGE_PAGE_SIZE_4M (1<<22)
  84. unsigned long __init mmu_mapin_ram(void)
  85. {
  86. unsigned long v, s;
  87. phys_addr_t p;
  88. v = KERNELBASE;
  89. p = PPC_MEMSTART;
  90. s = 0;
  91. if (__map_without_ltlbs) {
  92. return s;
  93. }
  94. while (s <= (total_lowmem - LARGE_PAGE_SIZE_16M)) {
  95. pmd_t *pmdp;
  96. unsigned long val = p | _PMD_SIZE_16M | _PAGE_HWEXEC | _PAGE_HWWRITE;
  97. pmdp = pmd_offset(pgd_offset_k(v), v);
  98. pmd_val(*pmdp++) = val;
  99. pmd_val(*pmdp++) = val;
  100. pmd_val(*pmdp++) = val;
  101. pmd_val(*pmdp++) = val;
  102. v += LARGE_PAGE_SIZE_16M;
  103. p += LARGE_PAGE_SIZE_16M;
  104. s += LARGE_PAGE_SIZE_16M;
  105. }
  106. while (s <= (total_lowmem - LARGE_PAGE_SIZE_4M)) {
  107. pmd_t *pmdp;
  108. unsigned long val = p | _PMD_SIZE_4M | _PAGE_HWEXEC | _PAGE_HWWRITE;
  109. pmdp = pmd_offset(pgd_offset_k(v), v);
  110. pmd_val(*pmdp) = val;
  111. v += LARGE_PAGE_SIZE_4M;
  112. p += LARGE_PAGE_SIZE_4M;
  113. s += LARGE_PAGE_SIZE_4M;
  114. }
  115. return s;
  116. }