fault.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/cris/mm/fault.c
  4. *
  5. * Low level bus fault handler
  6. *
  7. *
  8. * Copyright (C) 2000-2007 Axis Communications AB
  9. *
  10. * Authors: Bjorn Wesen
  11. *
  12. */
  13. #include <linux/mm.h>
  14. #include <linux/uaccess.h>
  15. #include <asm/pgtable.h>
  16. #include <arch/svinto.h>
  17. #include <asm/mmu_context.h>
  18. /* debug of low-level TLB reload */
  19. #undef DEBUG
  20. #ifdef DEBUG
  21. #define D(x) x
  22. #else
  23. #define D(x)
  24. #endif
  25. extern const struct exception_table_entry
  26. *search_exception_tables(unsigned long addr);
  27. asmlinkage void do_page_fault(unsigned long address, struct pt_regs *regs,
  28. int protection, int writeaccess);
  29. /* fast TLB-fill fault handler
  30. * this is called from entry.S with interrupts disabled
  31. */
  32. void
  33. handle_mmu_bus_fault(struct pt_regs *regs)
  34. {
  35. int cause;
  36. int select;
  37. #ifdef DEBUG
  38. int index;
  39. int page_id;
  40. int acc, inv;
  41. #endif
  42. pgd_t* pgd = (pgd_t*)per_cpu(current_pgd, smp_processor_id());
  43. pmd_t *pmd;
  44. pte_t pte;
  45. int miss, we, writeac;
  46. unsigned long address;
  47. unsigned long flags;
  48. cause = *R_MMU_CAUSE;
  49. address = cause & PAGE_MASK; /* get faulting address */
  50. select = *R_TLB_SELECT;
  51. #ifdef DEBUG
  52. page_id = IO_EXTRACT(R_MMU_CAUSE, page_id, cause);
  53. acc = IO_EXTRACT(R_MMU_CAUSE, acc_excp, cause);
  54. inv = IO_EXTRACT(R_MMU_CAUSE, inv_excp, cause);
  55. index = IO_EXTRACT(R_TLB_SELECT, index, select);
  56. #endif
  57. miss = IO_EXTRACT(R_MMU_CAUSE, miss_excp, cause);
  58. we = IO_EXTRACT(R_MMU_CAUSE, we_excp, cause);
  59. writeac = IO_EXTRACT(R_MMU_CAUSE, wr_rd, cause);
  60. D(printk("bus_fault from IRP 0x%lx: addr 0x%lx, miss %d, inv %d, we %d, acc %d, dx %d pid %d\n",
  61. regs->irp, address, miss, inv, we, acc, index, page_id));
  62. /* leave it to the MM system fault handler */
  63. if (miss)
  64. do_page_fault(address, regs, 0, writeac);
  65. else
  66. do_page_fault(address, regs, 1, we);
  67. /* Reload TLB with new entry to avoid an extra miss exception.
  68. * do_page_fault may have flushed the TLB so we have to restore
  69. * the MMU registers.
  70. */
  71. local_irq_save(flags);
  72. pmd = (pmd_t *)(pgd + pgd_index(address));
  73. if (pmd_none(*pmd))
  74. goto exit;
  75. pte = *pte_offset_kernel(pmd, address);
  76. if (!pte_present(pte))
  77. goto exit;
  78. *R_TLB_SELECT = select;
  79. *R_TLB_HI = cause;
  80. *R_TLB_LO = pte_val(pte);
  81. exit:
  82. local_irq_restore(flags);
  83. }