All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: Eduardo Habkost <eduardo@habkost.net>,
	Paolo Bonzini <pbonzini@redhat.com>,
	"Daniel P. Berrange" <berrange@redhat.com>,
	qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Subject: Re: Trying to understand QOM object creation and property linking
Date: Wed, 05 Jan 2022 21:02:25 +0000	[thread overview]
Message-ID: <87r19lj3l3.fsf@linaro.org> (raw)
In-Reply-To: <fbc66bb0-2c15-d789-bbaa-f9c3ba6f81e4@amsat.org>


Philippe Mathieu-Daudé <f4bug@amsat.org> writes:

> Hi Alex,
>
> On 5/1/22 19:03, Alex Bennée wrote:
>> Hi,
>> I'm having a hell of a time trying to create a new SoC+Board model
>> from
>> scratch. The problem comes down to trying to expose some properties to
>> the underlying CPU from my board model. So I have:
<snip>
>> static void pipico_machine_init(MachineState *machine)
>> {
>>      PiPicoMachineState *s = PIPICO_MACHINE(machine);
>>      ...
>>      MemoryRegion *system_memory = get_system_memory();

Hmm this memory is initialised by memory_region_init() so...

>>      ...
>>           /* initialize external Flash device */
>>      memory_region_init_rom(&s->flash, NULL,
>>                             "pico.flash0", 256 * KiB, &error_fatal);
>>      memory_region_add_subregion(system_memory, 0, &s->flash);
>>      /* Setup the SOC */
>>      object_initialize_child(OBJECT(machine), "soc", &s->soc, TYPE_RP2040);
>>      /* link properties from machine the SoC needs */
>>      object_property_set_link(OBJECT(&s->soc), "memory",
>>                               OBJECT(system_memory), &error_fatal);
>>      sysbus_realize(SYS_BUS_DEVICE(&s->soc), &error_fatal);
>> The initialisation of the SoC is simple because I can't do much
>> until
>> things are realised:
>> static void rp2040_init(Object *obj)
>> {
>>      RP2040State *s = RP2040(obj);
>>      int n;
>>      fprintf(stderr, "%s: %p\n", __func__, obj);
>>      for (n = 0; n < RP2040_NCPUS; n++) {
>>          object_initialize_child(obj, "cpu[*]", &s->armv7m[n], TYPE_ARMV7M);
>>          qdev_prop_set_string(DEVICE(&s->armv7m[n]), "cpu-type",
>>                               ARM_CPU_TYPE_NAME("cortex-m0"));
>
> Here for each core you need to initialize a MemoryRegion container, ...
>
>>      }
>> }
>> However when I get to realize the SoC itself:
>> static void rp2040_realize(DeviceState *dev, Error **errp)
>> {
>>      RP2040State *s = RP2040(dev);
>>      Object *obj = OBJECT(dev);
>>      int n;
>>      if (!s->board_memory) {
>>          error_setg(errp, "%s: memory property was not set", __func__);
>>          return;
>>      }
>>      /* initialize internal 16 KB internal ROM */
>>      memory_region_init_rom(&s->rom, obj, "rp2040.rom0", 16 * KiB, errp);
>>      memory_region_add_subregion(s->board_memory, 0, &s->rom);
>>      /* SRAM (Main 256k bank + two 4k banks)*/
>>      memory_region_init_ram(&s->sram03, obj, "rp2040.sram03", 256 * KiB, errp);
>>      memory_region_add_subregion(s->board_memory, RP2040_SRAM_BASE, &s->sram03);
>>      memory_region_init_ram(&s->sram4, obj, "rp2040.sram4", 4 * KiB,
>> errp);
>>      memory_region_add_subregion(s->board_memory, RP2040_SRAM4_BASE, &s->sram4);
>>      memory_region_init_ram(&s->sram5, obj, "rp2040.sram5", 4 * KiB,
>> errp);
>>      memory_region_add_subregion(s->board_memory, RP2040_SRAM5_BASE, &s->sram5);
>>      ...
>>      for (n = 0; n < RP2040_NCPUS; n++) {
>>          /* DeviceState *cpudev = DEVICE(&s->armv7m[i]); */
>>          Object *cpuobj = OBJECT(&s->armv7m[n]);
>
> then you add the board_memory in the per-CPU container as subregion,
> ...

Can't be added as a subregion to the container...

  qemu-system-arm: ../../softmmu/memory.c:2538: memory_region_add_subregion_common: Assertion `!subregion->container' failed.

>
>>          object_property_set_link(cpuobj, "memory",
>>                                   OBJECT(&s->board_memory), errp);
>
> and finally each CPU links its container as its memory bus.

So something like:

        object_property_set_link(cpuobj, "memory", OBJECT(s->cpu_mem[n]), errp);

so the CPU sees the container with whatever particular set of memory
regions you want to make visible to that CPU?

<snip>

>> Follow-up questions, does only creating the main memory aliases as
>> part
>> of the SoC make sense? My rational is most of the memory is part of the
>> SoC not the board. I assume later RP2040 based boards may have different
>> flash configs or even external memory.
>> The current (messy) state of my tree can be seen at:
>>    https://gitlab.com/stsquad/qemu/-/commits/arm/picopi-rfc
>> 


-- 
Alex Bennée


  reply	other threads:[~2022-01-05 21:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-05 18:03 Trying to understand QOM object creation and property linking Alex Bennée
2022-01-05 19:03 ` Philippe Mathieu-Daudé
2022-01-05 21:02   ` Alex Bennée [this message]
2022-01-06 11:16     ` Peter Maydell
2022-01-06 14:20       ` Alex Bennée
2022-01-06 15:04         ` Peter Maydell
2022-01-06 15:44           ` Alex Bennée
2022-01-06 15:52             ` Peter Maydell

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=87r19lj3l3.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=f4bug@amsat.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.