[PATCH] fix pci device can't alloc irq from fdt

Xianglai Li posted 1 patch 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251111071436.1555402-1-lixianglai@loongson.cn
Maintainers: Song Gao <gaosong@loongson.cn>, Bibo Mao <maobibo@loongson.cn>, Jiaxun Yang <jiaxun.yang@flygoat.com>
There is a newer version of this series
hw/loongarch/virt-fdt-build.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] fix pci device can't alloc irq from fdt
Posted by Xianglai Li 1 month ago
When we use the -kernel parameter to start an elf format kernel relying on
fdt, we get the following error:

pcieport 0000:00:01.0: of_irq_parse_pci: failed with rc=-22
pcieport 0000:00:01.0: enabling device (0000 -> 0003)
pcieport 0000:00:01.0: PME: Signaling with IRQ 19
pcieport 0000:00:01.0: AER: enabled with IRQ 19
pcieport 0000:00:01.1: of_irq_parse_pci: failed with rc=-22
pcieport 0000:00:01.1: enabling device (0000 -> 0003)
pcieport 0000:00:01.1: PME: Signaling with IRQ 20
pcieport 0000:00:01.1: AER: enabled with IRQ 20
pcieport 0000:00:01.2: of_irq_parse_pci: failed with rc=-22
pcieport 0000:00:01.2: enabling device (0000 -> 0003)
pcieport 0000:00:01.2: PME: Signaling with IRQ 21
pcieport 0000:00:01.2: AER: enabled with IRQ 21
pcieport 0000:00:01.3: of_irq_parse_pci: failed with rc=-22
pcieport 0000:00:01.3: enabling device (0000 -> 0003)
pcieport 0000:00:01.3: PME: Signaling with IRQ 22
pcieport 0000:00:01.3: AER: enabled with IRQ 22
pcieport 0000:00:01.4: of_irq_parse_pci: failed with rc=-22

This is because the description of interrupt-cell size in the interrupt
controller pch_pic in our fdt is incorrect, and the description of
interrupt-cell is missing in the pcie irq map. Now it is corrected and
the correct interrupt-cell is added in th pcie irq map.

Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
---
Cc: Bibo Mao <maobibo@loongson.cn>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: Song Gao <gaosong@loongson.cn>

 hw/loongarch/virt-fdt-build.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/loongarch/virt-fdt-build.c b/hw/loongarch/virt-fdt-build.c
index 1f0ba01f71..f1f70ed3c3 100644
--- a/hw/loongarch/virt-fdt-build.c
+++ b/hw/loongarch/virt-fdt-build.c
@@ -272,7 +272,7 @@ static void fdt_add_pch_pic_node(LoongArchVirtMachineState *lvms,
     qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0,
                            pch_pic_base, 0, pch_pic_size);
     qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0);
-    qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 2);
+    qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 1);
     qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
                           *eiointc_phandle);
     qemu_fdt_setprop_cell(ms->fdt, nodename, "loongson,pic-base-vec", 0);
@@ -395,6 +395,8 @@ static void fdt_add_pcie_node(const LoongArchVirtMachineState *lvms,
                                  2, base_mmio, 2, size_mmio);
     qemu_fdt_setprop_cells(ms->fdt, nodename, "msi-map",
                            0, *pch_msi_phandle, 0, 0x10000);
+
+    qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 1);
     fdt_add_pcie_irq_map_node(lvms, nodename, pch_pic_phandle);
     g_free(nodename);
 }
-- 
2.39.1
Re: [PATCH] fix pci device can't alloc irq from fdt
Posted by Bibo Mao 1 month ago

On 2025/11/11 下午3:14, Xianglai Li wrote:
> When we use the -kernel parameter to start an elf format kernel relying on
> fdt, we get the following error:
> 
> pcieport 0000:00:01.0: of_irq_parse_pci: failed with rc=-22
> pcieport 0000:00:01.0: enabling device (0000 -> 0003)
> pcieport 0000:00:01.0: PME: Signaling with IRQ 19
> pcieport 0000:00:01.0: AER: enabled with IRQ 19
> pcieport 0000:00:01.1: of_irq_parse_pci: failed with rc=-22
> pcieport 0000:00:01.1: enabling device (0000 -> 0003)
> pcieport 0000:00:01.1: PME: Signaling with IRQ 20
> pcieport 0000:00:01.1: AER: enabled with IRQ 20
> pcieport 0000:00:01.2: of_irq_parse_pci: failed with rc=-22
> pcieport 0000:00:01.2: enabling device (0000 -> 0003)
> pcieport 0000:00:01.2: PME: Signaling with IRQ 21
> pcieport 0000:00:01.2: AER: enabled with IRQ 21
> pcieport 0000:00:01.3: of_irq_parse_pci: failed with rc=-22
> pcieport 0000:00:01.3: enabling device (0000 -> 0003)
> pcieport 0000:00:01.3: PME: Signaling with IRQ 22
> pcieport 0000:00:01.3: AER: enabled with IRQ 22
> pcieport 0000:00:01.4: of_irq_parse_pci: failed with rc=-22
> 
> This is because the description of interrupt-cell size in the interrupt
> controller pch_pic in our fdt is incorrect, and the description of
> interrupt-cell is missing in the pcie irq map. Now it is corrected and
> the correct interrupt-cell is added in th pcie irq map.
> 
> Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
> ---
> Cc: Bibo Mao <maobibo@loongson.cn>
> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
> Cc: Song Gao <gaosong@loongson.cn>
> 
>   hw/loongarch/virt-fdt-build.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/loongarch/virt-fdt-build.c b/hw/loongarch/virt-fdt-build.c
> index 1f0ba01f71..f1f70ed3c3 100644
> --- a/hw/loongarch/virt-fdt-build.c
> +++ b/hw/loongarch/virt-fdt-build.c
> @@ -272,7 +272,7 @@ static void fdt_add_pch_pic_node(LoongArchVirtMachineState *lvms,
>       qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0,
>                              pch_pic_base, 0, pch_pic_size);
>       qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0);
> -    qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 2);
> +    qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 1);
The pch_pic supports irq number and trigger level, value of 
#interrupt-cells should be 2.

>       qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
>                             *eiointc_phandle);
>       qemu_fdt_setprop_cell(ms->fdt, nodename, "loongson,pic-base-vec", 0);
> @@ -395,6 +395,8 @@ static void fdt_add_pcie_node(const LoongArchVirtMachineState *lvms,
>                                    2, base_mmio, 2, size_mmio);
>       qemu_fdt_setprop_cells(ms->fdt, nodename, "msi-map",
>                              0, *pch_msi_phandle, 0, 0x10000);
> +
> +    qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 1);
>       fdt_add_pcie_irq_map_node(lvms, nodename, pch_pic_phandle);
Here is error report:
   pcieport 0000:00:01.0: of_irq_parse_pci: failed with rc=-22

I think that we should support interrupt-map fdt table in function 
fdt_add_pcie_irq_map_node(), so that PCI trigger level is added in the 
map table.

Regards
Bibo Mao
>       g_free(nodename);
>   }
> 


Re: [PATCH] fix pci device can't alloc irq from fdt
Posted by Bibo Mao 1 month ago

On 2025/11/11 下午6:07, Bibo Mao wrote:
> 
> 
> On 2025/11/11 下午3:14, Xianglai Li wrote:
>> When we use the -kernel parameter to start an elf format kernel 
>> relying on
>> fdt, we get the following error:
>>
>> pcieport 0000:00:01.0: of_irq_parse_pci: failed with rc=-22
>> pcieport 0000:00:01.0: enabling device (0000 -> 0003)
>> pcieport 0000:00:01.0: PME: Signaling with IRQ 19
>> pcieport 0000:00:01.0: AER: enabled with IRQ 19
>> pcieport 0000:00:01.1: of_irq_parse_pci: failed with rc=-22
>> pcieport 0000:00:01.1: enabling device (0000 -> 0003)
>> pcieport 0000:00:01.1: PME: Signaling with IRQ 20
>> pcieport 0000:00:01.1: AER: enabled with IRQ 20
>> pcieport 0000:00:01.2: of_irq_parse_pci: failed with rc=-22
>> pcieport 0000:00:01.2: enabling device (0000 -> 0003)
>> pcieport 0000:00:01.2: PME: Signaling with IRQ 21
>> pcieport 0000:00:01.2: AER: enabled with IRQ 21
>> pcieport 0000:00:01.3: of_irq_parse_pci: failed with rc=-22
>> pcieport 0000:00:01.3: enabling device (0000 -> 0003)
>> pcieport 0000:00:01.3: PME: Signaling with IRQ 22
>> pcieport 0000:00:01.3: AER: enabled with IRQ 22
>> pcieport 0000:00:01.4: of_irq_parse_pci: failed with rc=-22
>>
>> This is because the description of interrupt-cell size in the interrupt
>> controller pch_pic in our fdt is incorrect, and the description of
>> interrupt-cell is missing in the pcie irq map. Now it is corrected and
>> the correct interrupt-cell is added in th pcie irq map.
>>
>> Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
>> ---
>> Cc: Bibo Mao <maobibo@loongson.cn>
>> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
>> Cc: Song Gao <gaosong@loongson.cn>
>>
>>   hw/loongarch/virt-fdt-build.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/loongarch/virt-fdt-build.c 
>> b/hw/loongarch/virt-fdt-build.c
>> index 1f0ba01f71..f1f70ed3c3 100644
>> --- a/hw/loongarch/virt-fdt-build.c
>> +++ b/hw/loongarch/virt-fdt-build.c
>> @@ -272,7 +272,7 @@ static void 
>> fdt_add_pch_pic_node(LoongArchVirtMachineState *lvms,
>>       qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0,
>>                              pch_pic_base, 0, pch_pic_size);
>>       qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", 
>> NULL, 0);
>> -    qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 2);
>> +    qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 1);
> The pch_pic supports irq number and trigger level, value of 
> #interrupt-cells should be 2.
> 
>>       qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
>>                             *eiointc_phandle);
>>       qemu_fdt_setprop_cell(ms->fdt, nodename, 
>> "loongson,pic-base-vec", 0);
>> @@ -395,6 +395,8 @@ static void fdt_add_pcie_node(const 
>> LoongArchVirtMachineState *lvms,
>>                                    2, base_mmio, 2, size_mmio);
>>       qemu_fdt_setprop_cells(ms->fdt, nodename, "msi-map",
>>                              0, *pch_msi_phandle, 0, 0x10000);
>> +
>> +    qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 1);
>>       fdt_add_pcie_irq_map_node(lvms, nodename, pch_pic_phandle);
> Here is error report:
>    pcieport 0000:00:01.0: of_irq_parse_pci: failed with rc=-22
irq parsing from FDT table with non-pci device should be good,
such as uart, it is interrupt cell field is 2: (irq, 0x4)
   qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts", irq, 0x4)

only pci legacy interrupt pin parsing has problem.

Regards
Bibo Mao
> 
> I think that we should support interrupt-map fdt table in function 
> fdt_add_pcie_irq_map_node(), so that PCI trigger level is added in the 
> map table.
> 
> Regards
> Bibo Mao
>>       g_free(nodename);
>>   }
>>
>