idmap.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <linux/kernel.h>
  2. #include <asm/cputype.h>
  3. #include <asm/idmap.h>
  4. #include <asm/pgalloc.h>
  5. #include <asm/pgtable.h>
  6. #include <asm/sections.h>
  7. pgd_t *idmap_pgd;
  8. static void idmap_add_pmd(pud_t *pud, unsigned long addr, unsigned long end,
  9. unsigned long prot)
  10. {
  11. pmd_t *pmd = pmd_offset(pud, addr);
  12. addr = (addr & PMD_MASK) | prot;
  13. pmd[0] = __pmd(addr);
  14. addr += SECTION_SIZE;
  15. pmd[1] = __pmd(addr);
  16. flush_pmd_entry(pmd);
  17. }
  18. static void idmap_add_pud(pgd_t *pgd, unsigned long addr, unsigned long end,
  19. unsigned long prot)
  20. {
  21. pud_t *pud = pud_offset(pgd, addr);
  22. unsigned long next;
  23. do {
  24. next = pud_addr_end(addr, end);
  25. idmap_add_pmd(pud, addr, next, prot);
  26. } while (pud++, addr = next, addr != end);
  27. }
  28. static void identity_mapping_add(pgd_t *pgd, unsigned long addr, unsigned long end)
  29. {
  30. unsigned long prot, next;
  31. prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE;
  32. if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
  33. prot |= PMD_BIT4;
  34. pgd += pgd_index(addr);
  35. do {
  36. next = pgd_addr_end(addr, end);
  37. idmap_add_pud(pgd, addr, next, prot);
  38. } while (pgd++, addr = next, addr != end);
  39. }
  40. extern char __idmap_text_start[], __idmap_text_end[];
  41. static int __init init_static_idmap(void)
  42. {
  43. phys_addr_t idmap_start, idmap_end;
  44. idmap_pgd = pgd_alloc(&init_mm);
  45. if (!idmap_pgd)
  46. return -ENOMEM;
  47. /* Add an identity mapping for the physical address of the section. */
  48. idmap_start = virt_to_phys((void *)__idmap_text_start);
  49. idmap_end = virt_to_phys((void *)__idmap_text_end);
  50. pr_info("Setting up static identity map for 0x%llx - 0x%llx\n",
  51. (long long)idmap_start, (long long)idmap_end);
  52. identity_mapping_add(idmap_pgd, idmap_start, idmap_end);
  53. return 0;
  54. }
  55. early_initcall(init_static_idmap);
  56. /*
  57. * In order to soft-boot, we need to switch to a 1:1 mapping for the
  58. * cpu_reset functions. This will then ensure that we have predictable
  59. * results when turning off the mmu.
  60. */
  61. void setup_mm_for_reboot(void)
  62. {
  63. /* Clean and invalidate L1. */
  64. flush_cache_all();
  65. /* Switch to the identity mapping. */
  66. cpu_switch_mm(idmap_pgd, &init_mm);
  67. /* Flush the TLB. */
  68. local_flush_tlb_all();
  69. }