nrd_ras_common.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) 2018-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <string.h>
  8. #include <bl31/interrupt_mgmt.h>
  9. #include <plat/common/platform.h>
  10. #include <platform_def.h>
  11. #include <nrd_ras.h>
  12. static struct plat_nrd_ras_config *nrd_ras_config;
  13. /*
  14. * Find event map for a given interrupt number. On success, returns pointer to
  15. * the event map. On error, returns NULL.
  16. */
  17. struct nrd_ras_ev_map *nrd_find_ras_event_map_by_intr(uint32_t intr_num)
  18. {
  19. struct nrd_ras_ev_map *map;
  20. int size;
  21. int i;
  22. if (nrd_ras_config == NULL) {
  23. ERROR("RAS config is NULL\n");
  24. return NULL;
  25. }
  26. map = nrd_ras_config->ev_map;
  27. size = nrd_ras_config->ev_map_size;
  28. for (i = 0; i < size; i++) {
  29. if (map->intr == intr_num)
  30. return map;
  31. map++;
  32. }
  33. return NULL;
  34. }
  35. /*
  36. * Programs GIC registers and configures interrupt ID's as Group0 EL3
  37. * interrupts. Current support is to register PPI and SPI interrupts.
  38. */
  39. static void nrd_ras_intr_configure(int intr, int intr_type)
  40. {
  41. plat_ic_set_interrupt_type(intr, INTR_TYPE_EL3);
  42. plat_ic_set_interrupt_priority(intr, PLAT_RAS_PRI);
  43. plat_ic_clear_interrupt_pending(intr);
  44. /* Routing mode option available only for SPI interrupts */
  45. if (intr_type == NRD_RAS_INTR_TYPE_SPI) {
  46. plat_ic_set_spi_routing(intr, INTR_ROUTING_MODE_ANY,
  47. (u_register_t)read_mpidr_el1());
  48. }
  49. plat_ic_enable_interrupt(intr);
  50. }
  51. /*
  52. * Initialization function for the framework.
  53. *
  54. * Registers RAS config provided by the platform and then configures and
  55. * enables interrupt for each registered error. On success, return 0.
  56. */
  57. int nrd_ras_platform_setup(struct plat_nrd_ras_config *config)
  58. {
  59. struct nrd_ras_ev_map *map;
  60. int size;
  61. int i;
  62. /* Check if parameter is valid. */
  63. if (config == NULL) {
  64. ERROR("NRD: Failed to register RAS config\n");
  65. return -1;
  66. }
  67. /*
  68. * Maintain a reference to the platform RAS config data for later
  69. * use.
  70. */
  71. nrd_ras_config = config;
  72. map = nrd_ras_config->ev_map;
  73. size = nrd_ras_config->ev_map_size;
  74. for (i = 0; i < size; i++) {
  75. nrd_ras_intr_configure(map->intr, map->intr_type);
  76. map++;
  77. }
  78. INFO("NRD: Platform RAS setup successful\n");
  79. return 0;
  80. }