stm32mp_gic.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/bl_common.h>
  7. #include <common/debug.h>
  8. #include <common/fdt_wrappers.h>
  9. #include <drivers/arm/gicv2.h>
  10. #include <dt-bindings/interrupt-controller/arm-gic.h>
  11. #include <lib/utils.h>
  12. #include <libfdt.h>
  13. #include <plat/common/platform.h>
  14. #include <platform_def.h>
  15. struct stm32mp_gic_instance {
  16. uint32_t cells;
  17. uint32_t phandle_node;
  18. };
  19. /******************************************************************************
  20. * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
  21. * interrupts.
  22. *****************************************************************************/
  23. static const interrupt_prop_t stm32mp_interrupt_props[] = {
  24. PLATFORM_G1S_PROPS(GICV2_INTR_GROUP0),
  25. PLATFORM_G0_PROPS(GICV2_INTR_GROUP0)
  26. };
  27. /* Fix target_mask_array as secondary core is not able to initialize it */
  28. static unsigned int target_mask_array[PLATFORM_CORE_COUNT] = {1, 2};
  29. static gicv2_driver_data_t platform_gic_data = {
  30. .interrupt_props = stm32mp_interrupt_props,
  31. .interrupt_props_num = ARRAY_SIZE(stm32mp_interrupt_props),
  32. .target_masks = target_mask_array,
  33. .target_masks_num = ARRAY_SIZE(target_mask_array),
  34. };
  35. static struct stm32mp_gic_instance stm32mp_gic;
  36. void stm32mp_gic_init(void)
  37. {
  38. int node;
  39. void *fdt;
  40. const fdt32_t *cuint;
  41. uintptr_t addr;
  42. int err;
  43. if (fdt_get_address(&fdt) == 0) {
  44. panic();
  45. }
  46. node = fdt_node_offset_by_compatible(fdt, -1, "arm,cortex-a7-gic");
  47. if (node < 0) {
  48. panic();
  49. }
  50. err = fdt_get_reg_props_by_index(fdt, node, 0, &addr, NULL);
  51. if (err < 0) {
  52. panic();
  53. }
  54. platform_gic_data.gicd_base = addr;
  55. err = fdt_get_reg_props_by_index(fdt, node, 1, &addr, NULL);
  56. if (err < 0) {
  57. panic();
  58. }
  59. platform_gic_data.gicc_base = addr;
  60. cuint = fdt_getprop(fdt, node, "#interrupt-cells", NULL);
  61. if (cuint == NULL) {
  62. panic();
  63. }
  64. stm32mp_gic.cells = fdt32_to_cpu(*cuint);
  65. stm32mp_gic.phandle_node = fdt_get_phandle(fdt, node);
  66. if (stm32mp_gic.phandle_node == 0U) {
  67. panic();
  68. }
  69. gicv2_driver_init(&platform_gic_data);
  70. gicv2_distif_init();
  71. stm32mp_gic_pcpu_init();
  72. }
  73. void stm32mp_gic_pcpu_init(void)
  74. {
  75. gicv2_pcpu_distif_init();
  76. gicv2_set_pe_target_mask(plat_my_core_pos());
  77. gicv2_cpuif_enable();
  78. }