qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Sarah Harris" <S.E.Harris@kent.ac.uk>,
	"Pavel Dovgalyuk" <dovgaluk@ispras.ru>,
	"Thomas Huth" <huth@tuxfamily.org>,
	"Joaquin de Andres" <me@xcancerberox.com.ar>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-devel@nongnu.org, "Michael Rolnik" <mrolnik@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Aleksandar Markovic" <aleksandar.m.mail@gmail.com>
Subject: Re: [RFC PATCH 06/10] hw/avr: Add ATmega microcontrollers
Date: Fri, 20 Dec 2019 16:03:41 +0100	[thread overview]
Message-ID: <20191220160341.4c362d8d@redhat.com> (raw)
In-Reply-To: <c8361b39-478e-ceec-0ea1-cc3c9ce8d6c9@redhat.com>

On Fri, 20 Dec 2019 13:58:29 +0100
Philippe Mathieu-Daudé <philmd@redhat.com> wrote:

> Hi Igor,
> 
> On 12/20/19 11:09 AM, Igor Mammedov wrote:
> > On Thu, 28 Nov 2019 02:50:26 +0100
> > Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> >   
> >> Add famous ATmega MCUs:
> >>
> >> - middle range: ATmega168 and ATmega328
> >> - high range: ATmega1280 and ATmega2560
> >>
> >> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> >> ---
[...]
> >> +static void atmega_realize(DeviceState *dev, Error **errp)
> >> +{
> >> +    AtmegaState *s = ATMEGA(dev);
> >> +    AtmegaClass *bc = ATMEGA_GET_CLASS(dev);
> >> +    const AtmegaInfo *info = bc->info;
> >> +    DeviceState *cpudev;
> >> +    SysBusDevice *sbd;
> >> +    Error *err = NULL;
> >> +    char *devname;
> >> +    size_t i;
> >> +
> >> +    if (!s->xtal_freq_hz) {
> >> +        error_setg(errp, "\"xtal-frequency-hz\" property must be provided.");
> >> +        return;
> >> +    }
> >> +
> >> +    /* CPU */
> >> +    object_initialize_child(OBJECT(dev), "cpu", &s->cpu, sizeof(s->cpu),
> >> +                            info->cpu_type, &err, NULL);
> >> +    if (err) {
> >> +        error_propagate(errp, err);
> >> +        return;
> >> +    }
> >> +    object_property_set_bool(OBJECT(&s->cpu), true, "realized", &error_abort);
> >> +    cpudev = DEVICE(&s->cpu);
> >> +
> >> +    /* SRAM */
> >> +    memory_region_allocate_system_memory(&s->sram, OBJECT(dev),
> >> +                                         "sram", info->sram_size);  
> > with main RAM conversion to hostmem backend, this API will go away
> > and RAM memory region will be allocated by generic machine code
> > and shall be treated as backend. Users would be able to access it
> > via MachineState::ram memory region.
> > 
> > Meanwhile I'd suggest to move this line to arduino_machine_init()
> > and pass it to MCU as a link property.  
> 
> Thanks for reviewing this patch.
> 
> I think this MCU and few ARM SoC are good case for your RAM conversion.
> 
> These chipsets provide onboard RAM (SRAM). This amount of SRAM is enough 
> to run u-boot, FreeRTOS, ... Some ARM boards add DRAM, usually larger 
> than the SRAM amount.
> 
> The previous recomendation was to use 
> memory_region_allocate_system_memory() only once, but on the biggest 
> chunk of memory, for performance reasons.
that makes sense only if flexibility is necessary (mem-path, binding to numa nodes, prealloc, ...)
Do we really  care about it in non virt usecases.
 
> In the previous cases, the RAM is not added by the board/machine, but is 
> present in the MCU/SoC. This looks incorrect to me to allocate the RAM 
> in the board/machine and pass it to the MCU/SoC.
If it's not user specified value but a fixed memory embedded in SoC,
I'd for simplicity use memory_region_init_ram() directly
(which some boards do for built-in sram).
 
> You are saying the machine/board code will have to ask its children how 
> many ram they need, then allocate, then pass it to each?
machine code will use -m value (and that defaults to default_ram_size,
which board can override) or user provided memdev.

On board side, one could check if user provided backend is suitable and
refuse to start asking to correct CLI error.

So we are still talking about single backend RAM blob, which boards
could use as is or partition with aliases (x86) or map to some other
front-end devices. (point is not to mix device model with backend in this case)


> > Also use MachineState::ram_size and add check that it matches mc->default_ram_size.
> > Ex: https://github.com/imammedo/qemu/commit/241c65d506ccba1e0239a2bc0632d7dc9c3517c1
> >   
> >> +    memory_region_add_subregion(get_system_memory(),
> >> +                                OFFSET_DATA + 0x200, &s->sram);
> >> +
> >> +    /* Flash */
> >> +    memory_region_init_rom(&s->flash, OBJECT(dev),
> >> +                           "flash", info->flash_size, &error_fatal);
> >> +    memory_region_add_subregion(get_system_memory(), OFFSET_CODE, &s->flash);
> >> +
[...]



  reply	other threads:[~2019-12-20 15:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-28  1:50 [RFC PATCH 00/10] hw/avr: Introduce the Arduino board Philippe Mathieu-Daudé
2019-11-28  1:50 ` [NOTFORMERGE PATCH 01/10] hw/avr: Kludge to fix build failure Philippe Mathieu-Daudé
2019-11-28  1:50 ` [PATCH 02/10] target/avr: Remove unused include Philippe Mathieu-Daudé
2019-11-28  1:50 ` [PATCH 03/10] target/avr: Add missing definitions Philippe Mathieu-Daudé
2019-11-28  1:50 ` [NOTFORMERGE PATCH 04/10] target/avr: Fix IRQ count Philippe Mathieu-Daudé
2019-11-28  1:50 ` [RFC PATCH 05/10] hw/char/avr: Reduce USART I/O size Philippe Mathieu-Daudé
2019-11-28  1:50 ` [RFC PATCH 06/10] hw/avr: Add ATmega microcontrollers Philippe Mathieu-Daudé
2019-11-28  1:55   ` Philippe Mathieu-Daudé
2019-11-28  9:28   ` Aleksandar Markovic
2019-11-28  9:48     ` dovgaluk
2019-11-28 10:20       ` Aleksandar Markovic
2019-11-28 11:08         ` dovgaluk
2019-11-28 11:25           ` Aleksandar Markovic
2019-11-28 11:12         ` Philippe Mathieu-Daudé
2019-11-28 11:36     ` Philippe Mathieu-Daudé
2019-12-20 10:09   ` Igor Mammedov
2019-12-20 12:58     ` Philippe Mathieu-Daudé
2019-12-20 15:03       ` Igor Mammedov [this message]
2019-11-28  1:50 ` [RFC PATCH 07/10] hw/avr: Add few Arduino boards Philippe Mathieu-Daudé
2019-12-20 10:01   ` Igor Mammedov
2019-11-28  1:50 ` [PATCH 08/10] tests/acceptance: Keep multilines comment consistent with other tests Philippe Mathieu-Daudé
2019-11-28  1:50 ` [RFC PATCH 09/10] tests/acceptance: Use the ATmega2560 board Philippe Mathieu-Daudé
2019-11-28  1:50 ` [NOTFORMERGE PATCH 10/10] hw/avr: Remove the 'sample' board Philippe Mathieu-Daudé
2019-11-28 10:30 ` [RFC PATCH 00/10] hw/avr: Introduce the Arduino board Michael Rolnik

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=20191220160341.4c362d8d@redhat.com \
    --to=imammedo@redhat.com \
    --cc=S.E.Harris@kent.ac.uk \
    --cc=aleksandar.m.mail@gmail.com \
    --cc=dovgaluk@ispras.ru \
    --cc=f4bug@amsat.org \
    --cc=huth@tuxfamily.org \
    --cc=marcandre.lureau@redhat.com \
    --cc=me@xcancerberox.com.ar \
    --cc=mrolnik@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --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).