[PATCH] fw_cfg: Add support for LoongArch architecture

Huacai Chen posted 1 patch 1 day, 2 hours ago
Failed in applying to current master (apply log)
drivers/firmware/Kconfig       | 2 +-
drivers/firmware/qemu_fw_cfg.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
[PATCH] fw_cfg: Add support for LoongArch architecture
Posted by Huacai Chen 1 day, 2 hours ago
Qemu fw_cfg support was missing for LoongArch, which made some functions
unusable in virtual machines. So add the missing LoongArch defines.

Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
 drivers/firmware/Kconfig       | 2 +-
 drivers/firmware/qemu_fw_cfg.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index bbd2155d8483..9ec747716389 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -121,7 +121,7 @@ config RASPBERRYPI_FIRMWARE
 
 config FW_CFG_SYSFS
 	tristate "QEMU fw_cfg device support in sysfs"
-	depends on SYSFS && (ARM || ARM64 || PARISC || PPC_PMAC || RISCV || SPARC || X86)
+	depends on SYSFS && (ARM || ARM64 || LOONGARCH || PARISC || PPC_PMAC || RISCV || SPARC || X86)
 	depends on HAS_IOPORT_MAP
 	default n
 	help
diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
index 87a5421bc7d5..0c51a9df589f 100644
--- a/drivers/firmware/qemu_fw_cfg.c
+++ b/drivers/firmware/qemu_fw_cfg.c
@@ -211,7 +211,7 @@ static void fw_cfg_io_cleanup(void)
 
 /* arch-specific ctrl & data register offsets are not available in ACPI, DT */
 #if !(defined(FW_CFG_CTRL_OFF) && defined(FW_CFG_DATA_OFF))
-# if (defined(CONFIG_ARM) || defined(CONFIG_ARM64) || defined(CONFIG_RISCV))
+# if (defined(CONFIG_ARM) || defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH) || defined(CONFIG_RISCV))
 #  define FW_CFG_CTRL_OFF 0x08
 #  define FW_CFG_DATA_OFF 0x00
 #  define FW_CFG_DMA_OFF 0x10
-- 
2.52.0
Re: [PATCH] fw_cfg: Add support for LoongArch architecture
Posted by Peter Maydell 1 day, 1 hour ago
On Fri, 29 May 2026 at 15:42, Huacai Chen <chenhuacai@loongson.cn> wrote:
>
> Qemu fw_cfg support was missing for LoongArch, which made some functions
> unusable in virtual machines. So add the missing LoongArch defines.
>
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
>  drivers/firmware/Kconfig       | 2 +-
>  drivers/firmware/qemu_fw_cfg.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
> index bbd2155d8483..9ec747716389 100644
> --- a/drivers/firmware/Kconfig
> +++ b/drivers/firmware/Kconfig
> @@ -121,7 +121,7 @@ config RASPBERRYPI_FIRMWARE
>
>  config FW_CFG_SYSFS
>         tristate "QEMU fw_cfg device support in sysfs"
> -       depends on SYSFS && (ARM || ARM64 || PARISC || PPC_PMAC || RISCV || SPARC || X86)
> +       depends on SYSFS && (ARM || ARM64 || LOONGARCH || PARISC || PPC_PMAC || RISCV || SPARC || X86)
>         depends on HAS_IOPORT_MAP
>         default n
>         help
> diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
> index 87a5421bc7d5..0c51a9df589f 100644
> --- a/drivers/firmware/qemu_fw_cfg.c
> +++ b/drivers/firmware/qemu_fw_cfg.c
> @@ -211,7 +211,7 @@ static void fw_cfg_io_cleanup(void)
>
>  /* arch-specific ctrl & data register offsets are not available in ACPI, DT */
>  #if !(defined(FW_CFG_CTRL_OFF) && defined(FW_CFG_DATA_OFF))
> -# if (defined(CONFIG_ARM) || defined(CONFIG_ARM64) || defined(CONFIG_RISCV))
> +# if (defined(CONFIG_ARM) || defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH) || defined(CONFIG_RISCV))
>  #  define FW_CFG_CTRL_OFF 0x08
>  #  define FW_CFG_DATA_OFF 0x00
>  #  define FW_CFG_DMA_OFF 0x10

On the QEMU specification side we could probably nail this down
to "x86, sun, ppc, parisc have funny register layouts for
legacy reasons and all others have the 8-bytes-apart layout",
which might help to avoid having all this architecture-specific
ifdeffery changing for each new architecture, if that's
something people care about.

-- PMM
Re: [PATCH] fw_cfg: Add support for LoongArch architecture
Posted by Peter Maydell 23 hours ago
On Fri, 29 May 2026 at 16:52, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Fri, 29 May 2026 at 15:42, Huacai Chen <chenhuacai@loongson.cn> wrote:
> >
> > Qemu fw_cfg support was missing for LoongArch, which made some functions
> > unusable in virtual machines. So add the missing LoongArch defines.
> >
> > Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> > ---
> >  drivers/firmware/Kconfig       | 2 +-
> >  drivers/firmware/qemu_fw_cfg.c | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
> > index bbd2155d8483..9ec747716389 100644
> > --- a/drivers/firmware/Kconfig
> > +++ b/drivers/firmware/Kconfig
> > @@ -121,7 +121,7 @@ config RASPBERRYPI_FIRMWARE
> >
> >  config FW_CFG_SYSFS
> >         tristate "QEMU fw_cfg device support in sysfs"
> > -       depends on SYSFS && (ARM || ARM64 || PARISC || PPC_PMAC || RISCV || SPARC || X86)
> > +       depends on SYSFS && (ARM || ARM64 || LOONGARCH || PARISC || PPC_PMAC || RISCV || SPARC || X86)
> >         depends on HAS_IOPORT_MAP
> >         default n
> >         help
> > diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
> > index 87a5421bc7d5..0c51a9df589f 100644
> > --- a/drivers/firmware/qemu_fw_cfg.c
> > +++ b/drivers/firmware/qemu_fw_cfg.c
> > @@ -211,7 +211,7 @@ static void fw_cfg_io_cleanup(void)
> >
> >  /* arch-specific ctrl & data register offsets are not available in ACPI, DT */
> >  #if !(defined(FW_CFG_CTRL_OFF) && defined(FW_CFG_DATA_OFF))
> > -# if (defined(CONFIG_ARM) || defined(CONFIG_ARM64) || defined(CONFIG_RISCV))
> > +# if (defined(CONFIG_ARM) || defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH) || defined(CONFIG_RISCV))
> >  #  define FW_CFG_CTRL_OFF 0x08
> >  #  define FW_CFG_DATA_OFF 0x00
> >  #  define FW_CFG_DMA_OFF 0x10
>
> On the QEMU specification side we could probably nail this down
> to "x86, sun, ppc, parisc have funny register layouts for
> legacy reasons and all others have the 8-bytes-apart layout",
> which might help to avoid having all this architecture-specific
> ifdeffery changing for each new architecture, if that's
> something people care about.

I sent this QEMU patchset proposing that (and cleaning
up some of the implementation to make it less likely that
we add fw_cfg to any new board types with different layouts
from the arm/riscv/loongarch "standard" one):

https://lore.kernel.org/qemu-devel/20260529174639.451353-1-peter.maydell@linaro.org/

-- PMM
Re: [PATCH] fw_cfg: Add support for LoongArch architecture
Posted by Huacai Chen 9 hours ago
Hi, Peter,

On Sat, May 30, 2026 at 1:53 AM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Fri, 29 May 2026 at 16:52, Peter Maydell <peter.maydell@linaro.org> wrote:
> >
> > On Fri, 29 May 2026 at 15:42, Huacai Chen <chenhuacai@loongson.cn> wrote:
> > >
> > > Qemu fw_cfg support was missing for LoongArch, which made some functions
> > > unusable in virtual machines. So add the missing LoongArch defines.
> > >
> > > Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> > > ---
> > >  drivers/firmware/Kconfig       | 2 +-
> > >  drivers/firmware/qemu_fw_cfg.c | 2 +-
> > >  2 files changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
> > > index bbd2155d8483..9ec747716389 100644
> > > --- a/drivers/firmware/Kconfig
> > > +++ b/drivers/firmware/Kconfig
> > > @@ -121,7 +121,7 @@ config RASPBERRYPI_FIRMWARE
> > >
> > >  config FW_CFG_SYSFS
> > >         tristate "QEMU fw_cfg device support in sysfs"
> > > -       depends on SYSFS && (ARM || ARM64 || PARISC || PPC_PMAC || RISCV || SPARC || X86)
> > > +       depends on SYSFS && (ARM || ARM64 || LOONGARCH || PARISC || PPC_PMAC || RISCV || SPARC || X86)
> > >         depends on HAS_IOPORT_MAP
> > >         default n
> > >         help
> > > diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
> > > index 87a5421bc7d5..0c51a9df589f 100644
> > > --- a/drivers/firmware/qemu_fw_cfg.c
> > > +++ b/drivers/firmware/qemu_fw_cfg.c
> > > @@ -211,7 +211,7 @@ static void fw_cfg_io_cleanup(void)
> > >
> > >  /* arch-specific ctrl & data register offsets are not available in ACPI, DT */
> > >  #if !(defined(FW_CFG_CTRL_OFF) && defined(FW_CFG_DATA_OFF))
> > > -# if (defined(CONFIG_ARM) || defined(CONFIG_ARM64) || defined(CONFIG_RISCV))
> > > +# if (defined(CONFIG_ARM) || defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH) || defined(CONFIG_RISCV))
> > >  #  define FW_CFG_CTRL_OFF 0x08
> > >  #  define FW_CFG_DATA_OFF 0x00
> > >  #  define FW_CFG_DMA_OFF 0x10
> >
> > On the QEMU specification side we could probably nail this down
> > to "x86, sun, ppc, parisc have funny register layouts for
> > legacy reasons and all others have the 8-bytes-apart layout",
> > which might help to avoid having all this architecture-specific
> > ifdeffery changing for each new architecture, if that's
> > something people care about.
>
> I sent this QEMU patchset proposing that (and cleaning
> up some of the implementation to make it less likely that
> we add fw_cfg to any new board types with different layouts
> from the arm/riscv/loongarch "standard" one):
>
> https://lore.kernel.org/qemu-devel/20260529174639.451353-1-peter.maydell@linaro.org/
Thank you for your effort.

Huacai

>
> -- PMM