Browse Source

[DM/PIC] Config IPI by RT_MAX_IPI

Signed-off-by: GuEe-GUI <2991707448@qq.com>
GuEe-GUI 2 weeks ago
parent
commit
30ab08c7c9

+ 4 - 0
components/drivers/include/drivers/core/dm.h

@@ -27,6 +27,10 @@
 extern int rt_hw_cpu_id(void);
 #endif
 
+#ifndef RT_MAX_IPI
+#define RT_MAX_IPI 0
+#endif
+
 void rt_dm_secondary_cpu_init(void);
 
 /* ID Allocation */

+ 7 - 11
components/drivers/pic/pic-gic-common.c

@@ -62,20 +62,16 @@ void gic_common_init_quirk_hw(rt_uint32_t iidr, const struct gic_quirk *quirks,
 void gic_common_sgi_config(void *base, void *data, int irq_base)
 {
 #ifdef RT_USING_SMP
-    if (irq_base < 2)
+    if (irq_base < RT_MAX_IPI)
     {
         struct rt_pic_irq *pirq;
 
-#define DECLARE_GIC_IPI(ipi, hwirq)             \
-        rt_pic_config_ipi(data, ipi, hwirq);    \
-        pirq = rt_pic_find_ipi(data, ipi);      \
-        pirq->mode = RT_IRQ_MODE_EDGE_RISING;   \
-
-        DECLARE_GIC_IPI(RT_SCHEDULE_IPI, RT_SCHEDULE_IPI);
-        DECLARE_GIC_IPI(RT_STOP_IPI, RT_STOP_IPI);
-        DECLARE_GIC_IPI(RT_SMP_CALL_IPI, RT_SMP_CALL_IPI);
-
-#undef DECLARE_GIC_IPI
+        for (int ipi = 0; ipi < RT_MAX_IPI; ++ipi)
+        {
+            rt_pic_config_ipi(data, ipi, ipi);
+            pirq = rt_pic_find_ipi(data, ipi);
+            pirq->mode = RT_IRQ_MODE_EDGE_RISING;
+        }
     }
 #endif /* RT_USING_SMP */
 }

+ 3 - 12
components/drivers/pic/pic.c

@@ -28,17 +28,8 @@ struct irq_traps
     rt_bool_t (*handler)(void *);
 };
 
-static int _ipi_hash[] =
-{
-#ifdef RT_USING_SMP
-    [RT_SCHEDULE_IPI] = RT_SCHEDULE_IPI,
-    [RT_STOP_IPI] = RT_STOP_IPI,
-    [RT_SMP_CALL_IPI] = RT_SMP_CALL_IPI,
-#endif
-};
-
 /* reserved ipi */
-static int _pirq_hash_idx = RT_ARRAY_SIZE(_ipi_hash);
+static int _pirq_hash_idx = RT_MAX_IPI;
 static struct rt_pic_irq _pirq_hash[MAX_HANDLERS] =
 {
     [0 ... MAX_HANDLERS - 1] =
@@ -230,7 +221,7 @@ int rt_pic_config_ipi(struct rt_pic *pic, int ipi_index, int hwirq)
     int ipi = ipi_index;
     struct rt_pic_irq *pirq;
 
-    if (pic && ipi < RT_ARRAY_SIZE(_ipi_hash) && hwirq >= 0 && pic->ops->irq_send_ipi)
+    if (pic && ipi < RT_MAX_IPI && hwirq >= 0 && pic->ops->irq_send_ipi)
     {
         pirq = &_pirq_hash[ipi];
         config_pirq(pic, pirq, ipi, hwirq);
@@ -281,7 +272,7 @@ struct rt_pic_irq *rt_pic_find_ipi(struct rt_pic *pic, int ipi_index)
 {
     struct rt_pic_irq *pirq = &_pirq_hash[ipi_index];
 
-    RT_ASSERT(ipi_index < RT_ARRAY_SIZE(_ipi_hash));
+    RT_ASSERT(ipi_index < RT_MAX_IPI);
     RT_ASSERT(pirq->pic == pic);
 
     return pirq;