cache_err_int.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /*
  7. The cache has an interrupt that can be raised as soon as an access to a cached
  8. region (flash) is done without the cache being enabled. We use that here
  9. to panic the CPU, which from a debugging perspective is better than grabbing bad
  10. data from the bus.
  11. */
  12. #include "esp_rom_sys.h"
  13. #include "esp_attr.h"
  14. #include "esp_log.h"
  15. #include "esp_intr_alloc.h"
  16. #include "soc/periph_defs.h"
  17. #include "riscv/interrupt.h"
  18. #include "hal/cache_ll.h"
  19. static const char *TAG = "CACHE_ERR";
  20. void esp_cache_err_int_init(void)
  21. {
  22. const uint32_t core_id = 0;
  23. /* Disable cache interrupts if enabled. */
  24. ESP_INTR_DISABLE(ETS_CACHEERR_INUM);
  25. /**
  26. * Bind all cache errors to ETS_CACHEERR_INUM interrupt. we will deal with
  27. * them in handler by different types
  28. * I) Cache access error
  29. * 1. dbus trying to write to icache
  30. * 2. dbus authentication fail
  31. * 3. cpu access icache while dbus is disabled [1]
  32. * 4. ibus authentication fail
  33. * 5. ibus trying to write icache
  34. * 6. cpu access icache while ibus is disabled
  35. * II) Cache illegal error
  36. * 1. dbus counter overflow
  37. * 2. ibus counter overflow
  38. * 3. mmu entry fault
  39. * 4. icache preload configurations fault
  40. * 5. icache sync configuration fault
  41. *
  42. * [1]: On ESP32-C2 boards, the caches are shared but buses are still
  43. * distinct. So, we have an ibus and a dbus sharing the same cache.
  44. * This error can occur if the dbus performs a request but the icache
  45. * (or simply cache) is disabled.
  46. */
  47. esp_rom_route_intr_matrix(core_id, ETS_CACHE_IA_INTR_SOURCE, ETS_CACHEERR_INUM);
  48. esp_rom_route_intr_matrix(core_id, ETS_CACHE_CORE0_ACS_INTR_SOURCE, ETS_CACHEERR_INUM);
  49. /* Set the type and priority to cache error interrupts. */
  50. esprv_intc_int_set_type(ETS_CACHEERR_INUM, INTR_TYPE_LEVEL);
  51. esprv_intc_int_set_priority(ETS_CACHEERR_INUM, SOC_INTERRUPT_LEVEL_MEDIUM);
  52. ESP_DRAM_LOGV(TAG, "access error intr clr & ena mask is: 0x%x", CACHE_LL_L1_ACCESS_EVENT_MASK);
  53. /* On the hardware side, start by clearing all the bits reponsible for cache access error */
  54. cache_ll_l1_clear_access_error_intr(0, CACHE_LL_L1_ACCESS_EVENT_MASK);
  55. /* Then enable cache access error interrupts. */
  56. cache_ll_l1_enable_access_error_intr(0, CACHE_LL_L1_ACCESS_EVENT_MASK);
  57. /* Same goes for cache illegal error: start by clearing the bits and then
  58. * set them back. */
  59. ESP_DRAM_LOGV(TAG, "illegal error intr clr & ena mask is: 0x%x", CACHE_LL_L1_ILG_EVENT_MASK);
  60. cache_ll_l1_clear_illegal_error_intr(0, CACHE_LL_L1_ILG_EVENT_MASK);
  61. cache_ll_l1_enable_illegal_error_intr(0, CACHE_LL_L1_ILG_EVENT_MASK);
  62. /* Enable the interrupts for cache error. */
  63. ESP_INTR_ENABLE(ETS_CACHEERR_INUM);
  64. }
  65. int esp_cache_err_get_cpuid(void)
  66. {
  67. return 0;
  68. }