tlbex_32.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * TLB miss handler for SH with an MMU.
  3. *
  4. * Copyright (C) 1999 Niibe Yutaka
  5. * Copyright (C) 2003 - 2012 Paul Mundt
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/mm.h>
  13. #include <linux/kprobes.h>
  14. #include <linux/kdebug.h>
  15. #include <asm/mmu_context.h>
  16. #include <asm/thread_info.h>
  17. /*
  18. * Called with interrupts disabled.
  19. */
  20. asmlinkage int __kprobes
  21. handle_tlbmiss(struct pt_regs *regs, unsigned long error_code,
  22. unsigned long address)
  23. {
  24. pgd_t *pgd;
  25. pud_t *pud;
  26. pmd_t *pmd;
  27. pte_t *pte;
  28. pte_t entry;
  29. /*
  30. * We don't take page faults for P1, P2, and parts of P4, these
  31. * are always mapped, whether it be due to legacy behaviour in
  32. * 29-bit mode, or due to PMB configuration in 32-bit mode.
  33. */
  34. if (address >= P3SEG && address < P3_ADDR_MAX) {
  35. pgd = pgd_offset_k(address);
  36. } else {
  37. if (unlikely(address >= TASK_SIZE || !current->mm))
  38. return 1;
  39. pgd = pgd_offset(current->mm, address);
  40. }
  41. pud = pud_offset(pgd, address);
  42. if (pud_none_or_clear_bad(pud))
  43. return 1;
  44. pmd = pmd_offset(pud, address);
  45. if (pmd_none_or_clear_bad(pmd))
  46. return 1;
  47. pte = pte_offset_kernel(pmd, address);
  48. entry = *pte;
  49. if (unlikely(pte_none(entry) || pte_not_present(entry)))
  50. return 1;
  51. if (unlikely(error_code && !pte_write(entry)))
  52. return 1;
  53. if (error_code)
  54. entry = pte_mkdirty(entry);
  55. entry = pte_mkyoung(entry);
  56. set_pte(pte, entry);
  57. #if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SMP)
  58. /*
  59. * SH-4 does not set MMUCR.RC to the corresponding TLB entry in
  60. * the case of an initial page write exception, so we need to
  61. * flush it in order to avoid potential TLB entry duplication.
  62. */
  63. if (error_code == FAULT_CODE_INITIAL)
  64. local_flush_tlb_one(get_asid(), address & PAGE_MASK);
  65. #endif
  66. set_thread_fault_code(error_code);
  67. update_mmu_cache(NULL, address, pte);
  68. return 0;
  69. }