qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: mrolnik@gmail.com, philmd@linaro.org
Subject: Re: [PATCH v2 10/11] hw/avr: Prepare for TARGET_PAGE_SIZE > 256
Date: Wed, 26 Mar 2025 08:18:41 -0700	[thread overview]
Message-ID: <b5b28249-0548-48fc-9967-19a2f9e8d247@linaro.org> (raw)
In-Reply-To: <20250325224403.4011975-11-richard.henderson@linaro.org>

On 3/25/25 15:44, Richard Henderson wrote:
> If i/o does not cover the entire first page, allocate a portion
> of ram as an i/o device, so that the entire first page is i/o.
> 
> While memory_region_init_ram_device_ptr is happy to allocate
> the RAMBlock, it does not register the ram for migration.
> Do this by hand.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   hw/avr/atmega.h |  1 +
>   hw/avr/atmega.c | 39 ++++++++++++++++++++++++++++++++-------
>   2 files changed, 33 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/avr/atmega.h b/hw/avr/atmega.h
> index a99ee15c7e..9ac4678231 100644
> --- a/hw/avr/atmega.h
> +++ b/hw/avr/atmega.h
> @@ -41,6 +41,7 @@ struct AtmegaMcuState {
>       MemoryRegion flash;
>       MemoryRegion eeprom;
>       MemoryRegion sram;
> +    MemoryRegion sram_io;
>       DeviceState *io;
>       AVRMaskState pwr[POWER_MAX];
>       AVRUsartState usart[USART_MAX];
> diff --git a/hw/avr/atmega.c b/hw/avr/atmega.c
> index f6844bf118..11fab184de 100644
> --- a/hw/avr/atmega.c
> +++ b/hw/avr/atmega.c
> @@ -19,6 +19,7 @@
>   #include "hw/sysbus.h"
>   #include "qom/object.h"
>   #include "hw/misc/unimp.h"
> +#include "migration/vmstate.h"
>   #include "atmega.h"
>   
>   enum AtmegaPeripheral {
> @@ -224,8 +225,6 @@ static void atmega_realize(DeviceState *dev, Error **errp)
>       char *devname;
>       size_t i;
>   
> -    assert(mc->io_size <= 0x200);
> -
>       if (!s->xtal_freq_hz) {
>           error_setg(errp, "\"xtal-frequency-hz\" property must be provided.");
>           return;
> @@ -240,11 +239,37 @@ static void atmega_realize(DeviceState *dev, Error **errp)
>       qdev_realize(DEVICE(&s->cpu), NULL, &error_abort);
>       cpudev = DEVICE(&s->cpu);
>   
> -    /* SRAM */
> -    memory_region_init_ram(&s->sram, OBJECT(dev), "sram", mc->sram_size,
> -                           &error_abort);
> -    memory_region_add_subregion(get_system_memory(),
> -                                OFFSET_DATA + mc->io_size, &s->sram);
> +    /*
> +     * SRAM
> +     *
> +     * Softmmu is not able mix i/o and ram on the same page.
> +     * Therefore in all cases, the first page exclusively contains i/o.
> +     *
> +     * If the MCU's i/o region matches the page size, then we can simply
> +     * allocate all ram starting at the second page.  Otherwise, we must
> +     * allocate some ram as i/o to complete the first page.
> +     */
> +    assert(mc->io_size == 0x100 || mc->io_size == 0x200);
> +    if (mc->io_size >= TARGET_PAGE_SIZE) {
> +        memory_region_init_ram(&s->sram, OBJECT(dev), "sram", mc->sram_size,
> +                               &error_abort);
> +        memory_region_add_subregion(get_system_memory(),
> +                                    OFFSET_DATA + mc->io_size, &s->sram);
> +    } else {
> +        int sram_io_size = TARGET_PAGE_SIZE - mc->io_size;
> +        void *sram_io_mem = g_malloc0(sram_io_size);
> +
> +        memory_region_init_ram_device_ptr(&s->sram_io, OBJECT(dev), "sram-as-io",
> +                                          sram_io_size, sram_io_mem);
> +        memory_region_add_subregion(get_system_memory(),
> +                                    OFFSET_DATA + mc->io_size, &s->sram_io);
> +        vmstate_register_ram(&s->sram_io, dev);
> +
> +        memory_region_init_ram(&s->sram, OBJECT(dev), "sram",
> +                               mc->sram_size - sram_io_size, &error_abort);
> +        memory_region_add_subregion(get_system_memory(),
> +                                    OFFSET_DATA + TARGET_PAGE_SIZE, &s->sram);
> +    }
>   
>       /* Flash */
>       memory_region_init_rom(&s->flash, OBJECT(dev),

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>



  reply	other threads:[~2025-03-26 15:30 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-25 22:43 [PATCH v2 00/11] target/avr: Increase page size Richard Henderson
2025-03-25 22:43 ` [PATCH v2 01/11] target/avr: Fix buffer read in avr_print_insn Richard Henderson
2025-03-25 23:09   ` Philippe Mathieu-Daudé
2025-03-25 22:43 ` [PATCH v2 02/11] target/avr: Improve decode of LDS, STS Richard Henderson
2025-03-25 23:13   ` Philippe Mathieu-Daudé
2025-03-25 23:40     ` Richard Henderson
2025-03-25 22:43 ` [PATCH v2 03/11] hw/core/cpu: Use size_t for memory_rw_debug len argument Richard Henderson
2025-03-25 22:43 ` [PATCH v2 04/11] target/avr: Remove OFFSET_CPU_REGISTERS Richard Henderson
2025-03-25 22:43 ` [PATCH v2 05/11] target/avr: Remove NUMBER_OF_IO_REGISTERS Richard Henderson
2025-03-25 23:03   ` Philippe Mathieu-Daudé
2025-03-25 23:41     ` Richard Henderson
2025-03-26 15:14   ` Pierrick Bouvier
2025-03-25 22:43 ` [PATCH v2 06/11] target/avr: Add defines for i/o port registers Richard Henderson
2025-03-25 23:04   ` Philippe Mathieu-Daudé
2025-03-26 15:15   ` Pierrick Bouvier
2025-03-25 22:43 ` [PATCH v2 07/11] target/avr: Move cpu register accesses into system memory Richard Henderson
2025-03-26 15:16   ` Pierrick Bouvier
2025-03-25 22:44 ` [PATCH v2 08/11] target/avr: Use cpu_stb_mmuidx_ra in helper_fullwr Richard Henderson
2025-03-25 22:44 ` [PATCH v2 09/11] target/avr: Use do_stb in avr_cpu_do_interrupt Richard Henderson
2025-03-25 22:44 ` [PATCH v2 10/11] hw/avr: Prepare for TARGET_PAGE_SIZE > 256 Richard Henderson
2025-03-26 15:18   ` Pierrick Bouvier [this message]
2025-03-27 18:24   ` Philippe Mathieu-Daudé
2025-03-27 18:46     ` Richard Henderson
2025-03-25 22:44 ` [PATCH v2 11/11] target/avr: Increase TARGET_PAGE_BITS to 10 Richard Henderson
2025-03-26 15:16   ` Pierrick Bouvier
2025-03-31 18:48 ` [PATCH v2 00/11] target/avr: Increase page size Philippe Mathieu-Daudé
2025-03-31 18:51   ` 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=b5b28249-0548-48fc-9967-19a2f9e8d247@linaro.org \
    --to=pierrick.bouvier@linaro.org \
    --cc=mrolnik@gmail.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /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).