Skip to contentSkip to conversation

lib: utils: Fix irqchip registration for PLIC and APLIC

PATCH New Anup Patel 4 participants 5 messages Dec 24, 2024 – Dec 25, 2024

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH 1/1 lib: utils: Fix irqchip registration for PLIC and APLIC

Currently, the same irqchip instance is registered for multiple PLIC and APLIC instances which causes the sbi_list_for_each_entry() loop in the sbi_irqchip_init() to hang at boot-time.

To address the above issue, register a separate irqchip instance for each PLIC and APLIC instance.

Fixes 2dd6eaf68055 ("lib: sbi_irqchip: Call driver warm_init from SBI core")
---
 include/sbi_utils/irqchip/aplic.h | 4 ++++
 include/sbi_utils/irqchip/plic.h  | 4 ++++
 lib/utils/irqchip/aplic.c         | 6 +-----
 lib/utils/irqchip/plic.c          | 8 ++------
 4 files changed, 11 insertions(+), 11 deletions(-)
include/sbi_utils/irqchip/aplic.h +4 -0
index 82682e8a..e31f48a4 100644
@@ -12,6 +12,7 @@
 #define __IRQCHIP_APLIC_H__
 
 #include <sbi/sbi_types.h>
+#include <sbi/sbi_irqchip.h>
 
 #define APLIC_MAX_DELEGATE	16
 
@@ -30,6 +31,9 @@ struct aplic_delegate_data {
 };
 
 struct aplic_data {
+	/* Private members */
+	struct sbi_irqchip_device irqchip;
+	/* Public members */
 	unsigned long addr;
 	unsigned long size;
 	unsigned long num_idc;
include/sbi_utils/irqchip/plic.h +4 -0
index a173871e..18aa7469 100644
@@ -11,8 +11,12 @@
 #define __IRQCHIP_PLIC_H__
 
 #include <sbi/sbi_types.h>
+#include <sbi/sbi_irqchip.h>
 
 struct plic_data {
+	/* Private members */
+	struct sbi_irqchip_device irqchip;
+	/* Public members */
 	unsigned long addr;
 	unsigned long size;
 	unsigned long num_src;
lib/utils/irqchip/aplic.c +1 -5
index 27371849..72906d5d 100644
@@ -12,7 +12,6 @@
 #include <sbi/sbi_console.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
-#include <sbi/sbi_irqchip.h>
 #include <sbi_utils/irqchip/aplic.h>
 
 #define APLIC_MAX_IDC			(1UL << 14)
@@ -166,9 +165,6 @@ static int aplic_check_msicfg(struct aplic_msicfg_data *msicfg)
 	return 0;
 }
 
-static struct sbi_irqchip_device aplic_device = {
-};
-
 int aplic_cold_irqchip_init(struct aplic_data *aplic)
 {
 	int rc;
@@ -280,7 +276,7 @@ int aplic_cold_irqchip_init(struct aplic_data *aplic)
 	}
 
 	/* Register irqchip device */
-	sbi_irqchip_add_device(&aplic_device);
+	sbi_irqchip_add_device(&aplic->irqchip);
 
 	return 0;
 }
lib/utils/irqchip/plic.c +2 -6
index 7761ae98..8b2190f8 100644
@@ -15,7 +15,6 @@
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_heap.h>
-#include <sbi/sbi_irqchip.h>
 #include <sbi/sbi_string.h>
 #include <sbi_utils/irqchip/plic.h>
 
@@ -221,10 +220,6 @@ static int plic_warm_irqchip_init(struct sbi_irqchip_device *dev)
 	return 0;
 }
 
-static struct sbi_irqchip_device plic_device = {
-	.warm_init	= plic_warm_irqchip_init,
-};
-
 int plic_cold_irqchip_init(struct plic_data *plic)
 {
 	int i, ret;
@@ -284,7 +279,8 @@ int plic_cold_irqchip_init(struct plic_data *plic)
 	}
 
 	/* Register irqchip device */
-	sbi_irqchip_add_device(&plic_device);
+	plic->irqchip.warm_init = plic_warm_irqchip_init;
+	sbi_irqchip_add_device(&plic->irqchip);
 
 	return 0;
 }
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/1 lib: utils: Fix irqchip registration for PLIC and APLIC

Quoted 126 lines · Anup Patel

Currently, the same irqchip instance is registered for multiple PLIC and APLIC instances which causes the sbi_list_for_each_entry() loop in the sbi_irqchip_init() to hang at boot-time.

To address the above issue, register a separate irqchip instance for each PLIC and APLIC instance.

Fixes 2dd6eaf68055 ("lib: sbi_irqchip: Call driver warm_init from SBI core")

---

include/sbi_utils/irqchip/aplic.h | 4 ++++
include/sbi_utils/irqchip/plic.h  | 4 ++++
lib/utils/irqchip/aplic.c         | 6 +-----
lib/utils/irqchip/plic.c          | 8 ++------
4 files changed, 11 insertions(+), 11 deletions(-)
include/sbi_utils/irqchip/aplic.h +4 -0
index 82682e8a..e31f48a4 100644
@@ -12,6 +12,7 @@
 #define __IRQCHIP_APLIC_H__
 
 #include <sbi/sbi_types.h>
+#include <sbi/sbi_irqchip.h>
 
 #define APLIC_MAX_DELEGATE 16
 
@@ -30,6 +31,9 @@ struct aplic_delegate_data {
 };
 
 struct aplic_data {
+ /* Private members */
+ struct sbi_irqchip_device irqchip;
+ /* Public members */
 unsigned long addr;
 unsigned long size;
 unsigned long num_idc;
include/sbi_utils/irqchip/plic.h +4 -0
index a173871e..18aa7469 100644
@@ -11,8 +11,12 @@
 #define __IRQCHIP_PLIC_H__
 
 #include <sbi/sbi_types.h>
+#include <sbi/sbi_irqchip.h>
 
 struct plic_data {
+ /* Private members */
+ struct sbi_irqchip_device irqchip;
+ /* Public members */
 unsigned long addr;
 unsigned long size;
 unsigned long num_src;
lib/utils/irqchip/aplic.c +1 -5
index 27371849..72906d5d 100644
@@ -12,7 +12,6 @@
 #include <sbi/sbi_console.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
-#include <sbi/sbi_irqchip.h>
 #include <sbi_utils/irqchip/aplic.h>
 
 #define APLIC_MAX_IDC (1UL << 14)
@@ -166,9 +165,6 @@ static int aplic_check_msicfg(struct aplic_msicfg_data *msicfg)
 return 0;
 }
 
-static struct sbi_irqchip_device aplic_device = {
-};
-
 int aplic_cold_irqchip_init(struct aplic_data *aplic)
 {
 int rc;
@@ -280,7 +276,7 @@ int aplic_cold_irqchip_init(struct aplic_data *aplic)
 }
 
 /* Register irqchip device */
- sbi_irqchip_add_device(&aplic_device);
+ sbi_irqchip_add_device(&aplic->irqchip);
 
 return 0;
 }
lib/utils/irqchip/plic.c +2 -6
index 7761ae98..8b2190f8 100644
@@ -15,7 +15,6 @@
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_heap.h>
-#include <sbi/sbi_irqchip.h>
 #include <sbi/sbi_string.h>
 #include <sbi_utils/irqchip/plic.h>
 
@@ -221,10 +220,6 @@ static int plic_warm_irqchip_init(struct sbi_irqchip_device *dev)
 return 0;
 }
 
-static struct sbi_irqchip_device plic_device = {
- .warm_init = plic_warm_irqchip_init,
-};
-
 int plic_cold_irqchip_init(struct plic_data *plic)
 {
 int i, ret;
@@ -284,7 +279,8 @@ int plic_cold_irqchip_init(struct plic_data *plic)
 }
 
 /* Register irqchip device */
- sbi_irqchip_add_device(&plic_device);
+ plic->irqchip.warm_init = plic_warm_irqchip_init;
+ sbi_irqchip_add_device(&plic->irqchip);
 
 return 0;
 }
Signature · 1 line
2.43.0

Looks good. Thanks.

Reviewed-by Himanshu Chauhan <hchauhan at ventanamicro.com <mailto:[email protected]>>
Quoted 1 line
Applied
#2 lore raw

PATCH 1/1 lib: utils: Fix irqchip registration for PLIC and APLIC

In reply to Anup Patel
Quoted 11 lines · On Tue, Dec 24, 2024 at 1:58?PM Anup Patel <[email protected]> wrote:

Currently, the same irqchip instance is registered for multiple PLIC and APLIC instances which causes the sbi_list_for_each_entry() loop in the sbi_irqchip_init() to hang at boot-time.

To address the above issue, register a separate irqchip instance for each PLIC and APLIC instance.

Fixes 2dd6eaf68055 ("lib: sbi_irqchip: Call driver warm_init from SBI core")

This fix is critical for OpenSBI v1.6 release hence merging it soon.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 113 lines
---
 include/sbi_utils/irqchip/aplic.h | 4 ++++
 include/sbi_utils/irqchip/plic.h  | 4 ++++
 lib/utils/irqchip/aplic.c         | 6 +-----
 lib/utils/irqchip/plic.c          | 8 ++------
 4 files changed, 11 insertions(+), 11 deletions(-)
include/sbi_utils/irqchip/aplic.h +4 -0
index 82682e8a..e31f48a4 100644
@@ -12,6 +12,7 @@
 #define __IRQCHIP_APLIC_H__
 
 #include <sbi/sbi_types.h>
+#include <sbi/sbi_irqchip.h>
 
 #define APLIC_MAX_DELEGATE     16
 
@@ -30,6 +31,9 @@ struct aplic_delegate_data {
 };
 
 struct aplic_data {
+       /* Private members */
+       struct sbi_irqchip_device irqchip;
+       /* Public members */
        unsigned long addr;
        unsigned long size;
        unsigned long num_idc;
include/sbi_utils/irqchip/plic.h +4 -0
index a173871e..18aa7469 100644
@@ -11,8 +11,12 @@
 #define __IRQCHIP_PLIC_H__
 
 #include <sbi/sbi_types.h>
+#include <sbi/sbi_irqchip.h>
 
 struct plic_data {
+       /* Private members */
+       struct sbi_irqchip_device irqchip;
+       /* Public members */
        unsigned long addr;
        unsigned long size;
        unsigned long num_src;
lib/utils/irqchip/aplic.c +1 -5
index 27371849..72906d5d 100644
@@ -12,7 +12,6 @@
 #include <sbi/sbi_console.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
-#include <sbi/sbi_irqchip.h>
 #include <sbi_utils/irqchip/aplic.h>
 
 #define APLIC_MAX_IDC                  (1UL << 14)
@@ -166,9 +165,6 @@ static int aplic_check_msicfg(struct aplic_msicfg_data *msicfg)
        return 0;
 }
 
-static struct sbi_irqchip_device aplic_device = {
-};
-
 int aplic_cold_irqchip_init(struct aplic_data *aplic)
 {
        int rc;
@@ -280,7 +276,7 @@ int aplic_cold_irqchip_init(struct aplic_data *aplic)
        }
 
        /* Register irqchip device */
-       sbi_irqchip_add_device(&aplic_device);
+       sbi_irqchip_add_device(&aplic->irqchip);
 
        return 0;
 }
lib/utils/irqchip/plic.c +2 -7
index 7761ae98..8b2190f8 100644
@@ -15,7 +15,6 @@
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_heap.h>
-#include <sbi/sbi_irqchip.h>
 #include <sbi/sbi_string.h>
 #include <sbi_utils/irqchip/plic.h>
 
@@ -221,10 +220,6 @@ static int plic_warm_irqchip_init(struct sbi_irqchip_device *dev)
        return 0;
 }
 
-static struct sbi_irqchip_device plic_device = {
-       .warm_init      = plic_warm_irqchip_init,
-};
-
 int plic_cold_irqchip_init(struct plic_data *plic)
 {
        int i, ret;
@@ -284,7 +279,8 @@ int plic_cold_irqchip_init(struct plic_data *plic)
        }
 
        /* Register irqchip device */
-       sbi_irqchip_add_device(&plic_device);
+       plic->irqchip.warm_init = plic_warm_irqchip_init;
+       sbi_irqchip_add_device(&plic->irqchip);
 
        return 0;
 }
--

2.43.0

#3 lore raw

PATCH 1/1 lib: utils: Fix irqchip registration for PLIC and APLIC

In reply to Anup Patel

? 2024-12-24?? 13:58 +0530?Anup Patel???

Quoted 3 lines

Currently, the same irqchip instance is registered for multiple PLIC and APLIC instances which causes the sbi_list_for_each_entry() loop in the sbi_irqchip_init() to hang at boot-time.

Missing imsic?
The same problem occurs if there are multiple imsic instances.

Regards,
Xiang W

Quoted 121 lines

To address the above issue, register a separate irqchip instance for each PLIC and APLIC instance.

Fixes 2dd6eaf68055 ("lib: sbi_irqchip: Call driver warm_init from SBI core")

---

?include/sbi_utils/irqchip/aplic.h | 4 ++++
?include/sbi_utils/irqchip/plic.h? | 4 ++++
?lib/utils/irqchip/aplic.c???????? | 6 +-----
?lib/utils/irqchip/plic.c????????? | 8 ++------

?4 files changed, 11 insertions(+), 11 deletions(-)

include/sbi_utils/irqchip/aplic.h +0 -0
index 82682e8a..e31f48a4 100644
@@ -12,6 +12,7 @@

?#define __IRQCHIP_APLIC_H__
?
?#include <sbi/sbi_types.h>
+#include <sbi/sbi_irqchip.h>
?
?#define APLIC_MAX_DELEGATE 16
?

include/sbi_utils/irqchip/aplic.h +0 -0
@@ -30,6 +31,9 @@ struct aplic_delegate_data {
 ?};

?
?struct aplic_data {

include/sbi_utils/irqchip/aplic.h +3 -0
+	/* Private members */
+	struct sbi_irqchip_device irqchip;
+	/* Public members */

? unsigned long addr;
? unsigned long size;
? unsigned long num_idc;

include/sbi_utils/irqchip/plic.h +0 -0
index a173871e..18aa7469 100644
@@ -11,8 +11,12 @@

?#define __IRQCHIP_PLIC_H__
?
?#include <sbi/sbi_types.h>
+#include <sbi/sbi_irqchip.h>
?
?struct plic_data {

include/sbi_utils/irqchip/plic.h +3 -0
+	/* Private members */
+	struct sbi_irqchip_device irqchip;
+	/* Public members */

? unsigned long addr;
? unsigned long size;
? unsigned long num_src;

lib/utils/irqchip/aplic.c +0 -0
index 27371849..72906d5d 100644
@@ -12,7 +12,6 @@

?#include <sbi/sbi_console.h>
?#include <sbi/sbi_domain.h>
?#include <sbi/sbi_error.h>
-#include <sbi/sbi_irqchip.h>
?#include <sbi_utils/irqchip/aplic.h>
?
?#define APLIC_MAX_IDC (1UL << 14)

lib/utils/irqchip/aplic.c +0 -0
@@ -166,9 +165,6 @@ static int aplic_check_msicfg(struct aplic_msicfg_data *msicfg)
 ?	return 0;
 ?}

?

lib/utils/irqchip/aplic.c +0 -3
-static struct sbi_irqchip_device aplic_device = {
-};
-

?int aplic_cold_irqchip_init(struct aplic_data *aplic) ?{
? int rc;

lib/utils/irqchip/aplic.c +0 -0
@@ -280,7 +276,7 @@ int aplic_cold_irqchip_init(struct aplic_data *aplic)
 ?	}

?
? /* Register irqchip device */

lib/utils/irqchip/aplic.c +1 -1
-	sbi_irqchip_add_device(&aplic_device);
+	sbi_irqchip_add_device(&aplic->irqchip);

?
? return 0;
?}

lib/utils/irqchip/plic.c +0 -0
index 7761ae98..8b2190f8 100644
@@ -15,7 +15,6 @@

?#include <sbi/sbi_domain.h>
?#include <sbi/sbi_error.h>
?#include <sbi/sbi_heap.h>
-#include <sbi/sbi_irqchip.h>
?#include <sbi/sbi_string.h>
?#include <sbi_utils/irqchip/plic.h>
?

lib/utils/irqchip/plic.c +0 -0
@@ -221,10 +220,6 @@ static int plic_warm_irqchip_init(struct sbi_irqchip_device *dev)
 ?	return 0;
 ?}

?

lib/utils/irqchip/plic.c +0 -4
-static struct sbi_irqchip_device plic_device = {
-	.warm_init	= plic_warm_irqchip_init,
-};
-

?int plic_cold_irqchip_init(struct plic_data *plic) ?{
? int i, ret;

lib/utils/irqchip/plic.c +0 -0
@@ -284,7 +279,8 @@ int plic_cold_irqchip_init(struct plic_data *plic)
 ?	}

?
? /* Register irqchip device */

lib/utils/irqchip/plic.c +2 -1
-	sbi_irqchip_add_device(&plic_device);
+	plic->irqchip.warm_init = plic_warm_irqchip_init;
+	sbi_irqchip_add_device(&plic->irqchip);

?
? return 0;
?}

Signature · 1 line
2.43.0
author
#4 lore raw

PATCH 1/1 lib: utils: Fix irqchip registration for PLIC and APLIC

Quoted 8 lines · On Wed, Dec 25, 2024 at 2:58?PM Xiang W <[email protected]> wrote:

? 2024-12-24?? 13:58 +0530?Anup Patel???

Quoted 3 lines

Currently, the same irqchip instance is registered for multiple PLIC and APLIC instances which causes the sbi_list_for_each_entry() loop in the sbi_irqchip_init() to hang at boot-time.

Missing imsic?
The same problem occurs if there are multiple imsic instances.

This problem does not exist for IMSIC because we only have one M-mode IMSICs instance and one S-mode IMSICs instance.

OpenSBI only uses M-mode IMSICs instance and ignores the S-mode instance.

Regards,
Anup

Quoted 130 lines

Regards,
Xiang W

Quoted 118 lines

To address the above issue, register a separate irqchip instance for each PLIC and APLIC instance.

Fixes 2dd6eaf68055 ("lib: sbi_irqchip: Call driver warm_init from SBI core")
---
 include/sbi_utils/irqchip/aplic.h | 4 ++++
 include/sbi_utils/irqchip/plic.h  | 4 ++++
 lib/utils/irqchip/aplic.c         | 6 +-----
 lib/utils/irqchip/plic.c          | 8 ++------
 4 files changed, 11 insertions(+), 11 deletions(-)
include/sbi_utils/irqchip/aplic.h +4 -0
index 82682e8a..e31f48a4 100644
@@ -12,6 +12,7 @@
 #define __IRQCHIP_APLIC_H__
 
 #include <sbi/sbi_types.h>
+#include <sbi/sbi_irqchip.h>
 
 #define APLIC_MAX_DELEGATE   16
 
@@ -30,6 +31,9 @@ struct aplic_delegate_data {
 };
 
 struct aplic_data {
+     /* Private members */
+     struct sbi_irqchip_device irqchip;
+     /* Public members */
      unsigned long addr;
      unsigned long size;
      unsigned long num_idc;
include/sbi_utils/irqchip/plic.h +4 -0
index a173871e..18aa7469 100644
@@ -11,8 +11,12 @@
 #define __IRQCHIP_PLIC_H__
 
 #include <sbi/sbi_types.h>
+#include <sbi/sbi_irqchip.h>
 
 struct plic_data {
+     /* Private members */
+     struct sbi_irqchip_device irqchip;
+     /* Public members */
      unsigned long addr;
      unsigned long size;
      unsigned long num_src;
lib/utils/irqchip/aplic.c +1 -5
index 27371849..72906d5d 100644
@@ -12,7 +12,6 @@
 #include <sbi/sbi_console.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
-#include <sbi/sbi_irqchip.h>
 #include <sbi_utils/irqchip/aplic.h>
 
 #define APLIC_MAX_IDC                        (1UL << 14)
@@ -166,9 +165,6 @@ static int aplic_check_msicfg(struct aplic_msicfg_data *msicfg)
      return 0;
 }
 
-static struct sbi_irqchip_device aplic_device = {
-};
-
 int aplic_cold_irqchip_init(struct aplic_data *aplic)
 {
      int rc;
@@ -280,7 +276,7 @@ int aplic_cold_irqchip_init(struct aplic_data *aplic)
      }
 
      /* Register irqchip device */
-     sbi_irqchip_add_device(&aplic_device);
+     sbi_irqchip_add_device(&aplic->irqchip);
 
      return 0;
 }
lib/utils/irqchip/plic.c +2 -7
index 7761ae98..8b2190f8 100644
@@ -15,7 +15,6 @@
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_heap.h>
-#include <sbi/sbi_irqchip.h>
 #include <sbi/sbi_string.h>
 #include <sbi_utils/irqchip/plic.h>
 
@@ -221,10 +220,6 @@ static int plic_warm_irqchip_init(struct sbi_irqchip_device *dev)
      return 0;
 }
 
-static struct sbi_irqchip_device plic_device = {
-     .warm_init      = plic_warm_irqchip_init,
-};
-
 int plic_cold_irqchip_init(struct plic_data *plic)
 {
      int i, ret;
@@ -284,7 +279,8 @@ int plic_cold_irqchip_init(struct plic_data *plic)
      }
 
      /* Register irqchip device */
-     sbi_irqchip_add_device(&plic_device);
+     plic->irqchip.warm_init = plic_warm_irqchip_init;
+     sbi_irqchip_add_device(&plic->irqchip);
 
      return 0;
 }
--
Quoted 3 lines

2.43.0

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi