qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: "Sagar Karandikar" <sagark@eecs.berkeley.edu>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	"KONRAD Frederic" <frederic.konrad@adacore.com>,
	"Alistair Francis" <Alistair.Francis@wdc.com>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Subbaraya Sundeep" <sundeep.lkml@gmail.com>,
	qemu-block@nongnu.org, "Magnus Damm" <magnus.damm@gmail.com>,
	"Hervé Poussineau" <hpoussin@reactos.org>,
	"Joel Stanley" <joel@jms.id.au>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Aleksandar Rikalo" <aleksandar.rikalo@rt-rk.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Artyom Tarasenko" <atar4qemu@gmail.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Jean-Christophe Dubois" <jcd@tribudubois.net>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Fabien Chouteau" <chouteau@adacore.com>,
	qemu-arm@nongnu.org, "Peter Chubb" <peter.chubb@nicta.com.au>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Richard Henderson" <rth@twiddle.net>,
	"Kevin Wolf" <kwolf@redhat.com>,
	qemu-riscv@nongnu.org, "Igor Mitsyanko" <i.mitsyanko@gmail.com>,
	"Bastian Koppelmann" <kbastian@mail.uni-paderborn.de>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"Max Reitz" <mreitz@redhat.com>,
	"Michael Walle" <michael@walle.cc>,
	qemu-ppc@nongnu.org,
	"Aleksandar Markovic" <amarkovic@wavecomp.com>,
	"Aurelien Jarno" <aurelien@aurel32.net>
Subject: Re: [PATCH RESEND v2 18/32] hw/i386/pc_sysfw: Simplify using memory_region_init_alias()
Date: Tue, 25 Feb 2020 11:05:15 +0100	[thread overview]
Message-ID: <532522f3-fc33-4405-1819-fe89c3ed088e@redhat.com> (raw)
In-Reply-To: <20200224205533.23798-19-philmd@redhat.com>

On 2/24/20 9:55 PM, Philippe Mathieu-Daudé wrote:
> The scripts/coccinelle/memory-region-housekeeping.cocci reported:
> * TODO [[view:hw/i386/pc_sysfw.c::face=ovl-face1::linb=67::colb=4::cole=26][potential use of memory_region_init_rom*() in  hw/i386/pc_sysfw.c::67]]
> 
> pc_isa_bios_init() does a manual copy of a part of the BIOS,
> from a read-only region. We can simplify by directly aliasing
> the same part.
> 
> Before:
> 
>    (qemu) info mtree
>    memory-region: system
>      0000000000000000-ffffffffffffffff (prio 0, i/o): system
>        0000000000000000-0000000007ffffff (prio 0, ram): alias ram-below-4g @pc.ram 0000000000000000-0000000007ffffff
>        0000000000000000-ffffffffffffffff (prio -1, i/o): pci
>          00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem
>          00000000000c0000-00000000000dffff (prio 1, rom): pc.rom
>          00000000000e0000-00000000000fffff (prio 1, rom): isa-bios
>        ...
>        00000000fff00000-00000000ffffffff (prio 0, romd): system.flash0
> 
> After:
> 
>    (qemu) info mtree
>    memory-region: system
>      0000000000000000-ffffffffffffffff (prio 0, i/o): system
>        0000000000000000-0000000007ffffff (prio 0, ram): alias ram-below-4g @pc.ram 0000000000000000-0000000007ffffff
>        0000000000000000-ffffffffffffffff (prio -1, i/o): pci
>          00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem
>          00000000000c0000-00000000000dffff (prio 1, rom): pc.rom
>          00000000000e0000-00000000000fffff (prio 1, romd): alias isa-bios @system.flash0 00000000000e0000-00000000000fffff
>        ...
>        00000000fff00000-00000000ffffffff (prio 0, romd): system.flash0

IIUC migrating old -> new is OK, the previous ROM copy is discarded.

What about new -> old, does it require specific handling? Do we care?

> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>   hw/i386/pc_sysfw.c | 24 ++++++------------------
>   1 file changed, 6 insertions(+), 18 deletions(-)
> 
> diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
> index f5f3f466b0..e864c09ea8 100644
> --- a/hw/i386/pc_sysfw.c
> +++ b/hw/i386/pc_sysfw.c
> @@ -54,31 +54,19 @@ static void pc_isa_bios_init(MemoryRegion *rom_memory,
>                                MemoryRegion *flash_mem,
>                                int ram_size)
>   {
> -    int isa_bios_size;
> -    MemoryRegion *isa_bios;
> -    uint64_t flash_size;
> -    void *flash_ptr, *isa_bios_ptr;
> -
> -    flash_size = memory_region_size(flash_mem);
> +    uint64_t isa_bios_size;
> +    MemoryRegion *isa_bios = g_new(MemoryRegion, 1);
> +    uint64_t flash_size = memory_region_size(flash_mem);
>   
>       /* map the last 128KB of the BIOS in ISA space */
>       isa_bios_size = MIN(flash_size, 128 * KiB);
> -    isa_bios = g_malloc(sizeof(*isa_bios));
> -    memory_region_init_ram(isa_bios, NULL, "isa-bios", isa_bios_size,
> -                           &error_fatal);
> +    memory_region_init_alias(isa_bios, NULL, "isa-bios", flash_mem,
> +                             flash_size - isa_bios_size,
> +                             isa_bios_size);
>       memory_region_add_subregion_overlap(rom_memory,
>                                           0x100000 - isa_bios_size,
>                                           isa_bios,
>                                           1);
> -
> -    /* copy ISA rom image from top of flash memory */
> -    flash_ptr = memory_region_get_ram_ptr(flash_mem);
> -    isa_bios_ptr = memory_region_get_ram_ptr(isa_bios);
> -    memcpy(isa_bios_ptr,
> -           ((uint8_t*)flash_ptr) + (flash_size - isa_bios_size),
> -           isa_bios_size);
> -
> -    memory_region_set_readonly(isa_bios, true);
>   }
>   
>   static PFlashCFI01 *pc_pflash_create(PCMachineState *pcms,
> 



  reply	other threads:[~2020-02-25 10:06 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-24 20:55 [PATCH RESEND v2 00/32] hw: Sanitize various MemoryRegion calls Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 01/32] memory: Correctly return alias region type Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 02/32] memory: Simplify memory_region_init_rom_nomigrate() to ease review Philippe Mathieu-Daudé
2020-02-24 21:17   ` Alistair Francis
2020-02-24 20:55 ` [PATCH RESEND v2 03/32] scripts/cocci: Rename memory-region-{init-ram -> housekeeping} Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 04/32] scripts/cocci: Patch to replace memory_region_init_{ram, readonly -> rom} Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 05/32] hw/arm: Use memory_region_init_rom() with read-only regions Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 06/32] hw/display: " Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 07/32] hw/mips: " Philippe Mathieu-Daudé
2020-02-26 11:38   ` Aleksandar Markovic
2020-02-24 20:55 ` [PATCH RESEND v2 08/32] hw/m68k: " Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 09/32] hw/net: " Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 10/32] hw/pci-host: " Philippe Mathieu-Daudé
2020-02-25  0:23   ` David Gibson
2020-02-24 20:55 ` [PATCH RESEND v2 11/32] hw/ppc: " Philippe Mathieu-Daudé
2020-02-25  0:23   ` David Gibson
2020-02-24 20:55 ` [PATCH RESEND v2 12/32] hw/riscv: " Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 13/32] hw/sh4: " Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 14/32] hw/sparc: " Philippe Mathieu-Daudé
2020-02-25 10:32   ` KONRAD Frederic
2020-02-24 20:55 ` [PATCH RESEND v2 15/32] scripts/cocci: Patch to detect potential use of memory_region_init_rom Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 16/32] hw/arm/stm32: Use memory_region_init_rom() with read-only regions Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 17/32] hw/ppc/ppc405: " Philippe Mathieu-Daudé
2020-02-25  0:24   ` David Gibson
2020-02-24 20:55 ` [PATCH RESEND v2 18/32] hw/i386/pc_sysfw: Simplify using memory_region_init_alias() Philippe Mathieu-Daudé
2020-02-25 10:05   ` Philippe Mathieu-Daudé [this message]
2020-02-25 12:39     ` Paolo Bonzini
2020-02-24 20:55 ` [PATCH RESEND v2 19/32] hw/i386/pc_sysfw: Remove unused 'ram_size' argument Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 20/32] scripts/cocci: Patch to remove unnecessary memory_region_set_readonly() Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 21/32] hw/arm: Remove unnecessary memory_region_set_readonly() on ROM alias Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 22/32] scripts/cocci: Patch to let devices own their MemoryRegions Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 23/32] hw/arm: Let devices own the MemoryRegion they create Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 24/32] hw/char: " Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 25/32] hw/core: " Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 26/32] hw/display: " Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 27/32] hw/dma: " Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 28/32] hw/riscv: " Philippe Mathieu-Daudé
2020-02-24 20:55 ` [PATCH RESEND v2 29/32] hw/input/milkymist-softusb: Remove unused 'pmem_ptr' field Philippe Mathieu-Daudé
2020-02-24 20:55 ` [RFC PATCH RESEND v2 30/32] hw/input/milkymist-softusb: Let devices own the MemoryRegion they create Philippe Mathieu-Daudé
2020-02-24 20:55 ` [RFC PATCH RESEND v2 31/32] hw/net/milkymist-minimac2: " Philippe Mathieu-Daudé
2020-02-24 20:55 ` [RFC PATCH RESEND v2 32/32] hw/block/onenand: " Philippe Mathieu-Daudé

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=532522f3-fc33-4405-1819-fe89c3ed088e@redhat.com \
    --to=philmd@redhat.com \
    --cc=Alistair.Francis@wdc.com \
    --cc=aleksandar.rikalo@rt-rk.com \
    --cc=alistair@alistair23.me \
    --cc=amarkovic@wavecomp.com \
    --cc=atar4qemu@gmail.com \
    --cc=aurelien@aurel32.net \
    --cc=chouteau@adacore.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=dgilbert@redhat.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=ehabkost@redhat.com \
    --cc=frederic.konrad@adacore.com \
    --cc=hpoussin@reactos.org \
    --cc=i.mitsyanko@gmail.com \
    --cc=jasowang@redhat.com \
    --cc=jcd@tribudubois.net \
    --cc=joel@jms.id.au \
    --cc=kbastian@mail.uni-paderborn.de \
    --cc=kwolf@redhat.com \
    --cc=laurent@vivier.eu \
    --cc=magnus.damm@gmail.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=michael@walle.cc \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.chubb@nicta.com.au \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=sagark@eecs.berkeley.edu \
    --cc=sundeep.lkml@gmail.com \
    /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).