qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Xiaojuan Yang <yangxiaojuan@loongson.cn>,
	qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>
Cc: richard.henderson@linaro.org, gaosong@loongson.cn, maobibo@loongson.cn
Subject: Re: [PATCH v2] hw/loongarch: Add cfi01 pflash device
Date: Wed, 23 Nov 2022 11:07:33 +0100	[thread overview]
Message-ID: <b62401b2-3a12-e89d-6953-b40dd170b4ba@linaro.org> (raw)
In-Reply-To: <20221123012301.1258800-1-yangxiaojuan@loongson.cn>

On 23/11/22 02:23, Xiaojuan Yang wrote:
> Add cfi01 pflash device for LoongArch virt machine
> 
> Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
> ---
>   hw/loongarch/Kconfig        |  1 +
>   hw/loongarch/acpi-build.c   | 18 +++++++++
>   hw/loongarch/virt.c         | 80 ++++++++++++++++++++++++++++++++++++-
>   include/hw/loongarch/virt.h |  5 +++
>   4 files changed, 103 insertions(+), 1 deletion(-)

>   static void fdt_add_rtc_node(LoongArchMachineState *lams)
>   {
> @@ -593,9 +661,17 @@ static void loongarch_firmware_init(LoongArchMachineState *lams)
>   {
>       char *filename = MACHINE(lams)->firmware;
>       char *bios_name = NULL;
> -    int bios_size;
> +    int bios_size, i;
>   
>       lams->bios_loaded = false;
> +    /* Map legacy -drive if=pflash to machine properties */
> +    for (i = 0; i < ARRAY_SIZE(lams->flash); i++) {
> +        pflash_cfi01_legacy_drive(lams->flash[i],
> +                                  drive_get(IF_PFLASH, 0, i));

My understanding is we shouldn't use pflash_cfi01_legacy_drive()
anymore, besides I don't think you requires it (for the machine
property).

(Cc'ing Markus for commit 2d731dbd5e).

This is unfortunate we let the sbsa-ref and riscv-virt machines
use it.

> +    }
> +
> +    virt_flash_map(lams, get_system_memory());
> +
>       if (filename) {
>           bios_name = qemu_find_file(QEMU_FILE_TYPE_BIOS, filename);
>           if (!bios_name) {
> @@ -779,6 +855,7 @@ static void loongarch_init(MachineState *machine)
>               loongarch_direct_kernel_boot(lams);
>           }
>       }
> +    fdt_add_flash_node(lams);
>       /* register reset function */
>       for (i = 0; i < machine->smp.cpus; i++) {
>           lacpu = LOONGARCH_CPU(qemu_get_cpu(i));
> @@ -838,6 +915,7 @@ static void loongarch_machine_initfn(Object *obj)
>       lams->acpi = ON_OFF_AUTO_AUTO;
>       lams->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6);
>       lams->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8);
> +    virt_flash_create(lams);
>   }
>   
>   static bool memhp_type_supported(DeviceState *dev)
> diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
> index 45c383f5a7..94afc92850 100644
> --- a/include/hw/loongarch/virt.h
> +++ b/include/hw/loongarch/virt.h
> @@ -12,6 +12,7 @@
>   #include "hw/boards.h"
>   #include "qemu/queue.h"
>   #include "hw/intc/loongarch_ipi.h"
> +#include "hw/block/flash.h"
>   
>   #define LOONGARCH_MAX_VCPUS     4
>   
> @@ -20,6 +21,9 @@
>   #define VIRT_FWCFG_BASE         0x1e020000UL
>   #define VIRT_BIOS_BASE          0x1c000000UL
>   #define VIRT_BIOS_SIZE          (4 * MiB)
> +#define VIRT_FLASH_SECTOR_SIZE  (128 * KiB)
> +#define VIRT_FLASH0_BASE        (VIRT_BIOS_BASE + VIRT_BIOS_SIZE)

Do you really want the flash base addr to depend of the ROM size?
It could be safer/simpler to start with a fixed address, leaving
room for a bigger ROM if you think you might have to use one.

> +#define VIRT_FLASH0_SIZE        (4 * MiB)

The '0' index in the name is not really useful / needed.

Note, if you provide addr/size to build_flash_aml(), these
definitions can be restricted to hw/loongarch/virt.c.

>   #define VIRT_LOWMEM_BASE        0
>   #define VIRT_LOWMEM_SIZE        0x10000000
> @@ -48,6 +52,7 @@ struct LoongArchMachineState {
>       int          fdt_size;
>       DeviceState *platform_bus_dev;
>       PCIBus       *pci_bus;
> +    PFlashCFI01  *flash[1];

The array is not really needed.

>   };
>   
>   #define TYPE_LOONGARCH_MACHINE  MACHINE_TYPE_NAME("virt")



      reply	other threads:[~2022-11-23 10:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23  1:23 [PATCH v2] hw/loongarch: Add cfi01 pflash device Xiaojuan Yang
2022-11-23 10:07 ` Philippe Mathieu-Daudé [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b62401b2-3a12-e89d-6953-b40dd170b4ba@linaro.org \
    --to=philmd@linaro.org \
    --cc=armbru@redhat.com \
    --cc=gaosong@loongson.cn \
    --cc=maobibo@loongson.cn \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=yangxiaojuan@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).